ttp-agent-sdk 2.3.26 → 2.3.28

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(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==e.key&&(r=""+e.key),"key"in e)for(var i in o={},e)"key"!==i&&(o[i]=e[i]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:r,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},i.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=i.prototype;var s=c.prototype=new a;s.constructor=c,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var u={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return u.H.useEffect(t,e)},e.useRef=function(t){return u.H.useRef(t)},e.useState=function(t){return u.H.useState(t)}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>Ln,AudioPlayer:()=>Z,AudioRecorder:()=>H,EventEmitter:()=>c,TTPChatWidget:()=>go,TextChatSDK:()=>dn,VERSION:()=>yo,VanillaVoiceButton:()=>Bn,VoiceButton:()=>kn,VoiceSDK:()=>pt,VoiceSDK_v2:()=>$e,WebSocketManager:()=>F,default:()=>mo});var c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||d(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=d(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function d(t,e){if(t){if("string"==typeof t)return f(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return h(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(h(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,h(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,h(d,"constructor",u),h(u,"constructor",s),s.displayName="GeneratorFunction",h(u,r,"GeneratorFunction"),h(d),h(d,r,"Generator"),h(d,o,function(){return this}),h(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:f}})()}function h(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}h=function(t,e,n,o){function i(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},h(t,e,n,o)}function v(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,y(o.key),o)}}function y(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(m=function(){return!!t})()}function b(t){return b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},b(t)}function w(t,e){return w=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},w(t,e)}const S=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=b(e),function(t,e){if(e&&("object"==s(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,m()?Reflect.construct(e,n||[],b(t).constructor):e.apply(t,n))}(this,e)).connections=new Map,t.connectionCounts=new Map,t.creatingConnections=new Set,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&w(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=p().m(function t(e){var n,o,r=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(r.connections.has(e)){var o=r.connections.get(e);r.connectionCounts.set(e,(r.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){r.creatingConnections.delete(e),r.emit("error",t,e)}),o.addEventListener("message",function(t){r.emit("message",t,e)}),t.a(2,o)}},t,this)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){v(i,n,o,a,c,"next",t)}function c(t){v(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=l(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=u(t.value,2),r=o[0],i=o[1];e[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c));function x(t){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},x(t)}function k(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return C(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(C(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,C(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,C(d,"constructor",u),C(u,"constructor",s),s.displayName="GeneratorFunction",C(u,r,"GeneratorFunction"),C(d),C(d,r,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(k=function(){return{w:i,m:f}})()}function C(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}C=function(t,e,n,o){function i(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},C(t,e,n,o)}function P(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,T(o.key),o)}}function T(t){var e=function(t){if("object"!=x(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=x(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==x(e)?e:e+""}function E(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(E=function(){return!!t})()}function j(t){return j=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},j(t)}function I(t,e){return I=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},I(t,e)}var F=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=j(e),function(t,e){if(e&&("object"==x(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,E()?Reflect.construct(e,n||[],j(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&I(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=k().m(function t(){var e=this;return k().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,S.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t(),e.connectResolve=null,e.connectReject=null)}).catch(function(t){console.error("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null})}catch(t){console.error("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null}}))},t)}),a=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){P(r,n,o,a,c,"next",t)}function c(t){P(r,n,o,a,c,"throw",t)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};S.on("open",e),S.on("close",n),S.on("error",o),S.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(S.off("open",this.eventHandlers.open),S.off("close",this.eventHandlers.close),S.off("error",this.eventHandlers.error),S.off("message",this.eventHandlers.message)),this.config.websocketUrl&&S.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(t))}catch(t){console.warn("🔌 WebSocketManager: Failed to send message:",t.message)}}},{key:"sendBinary",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(t)}catch(t){console.warn("🔌 WebSocketManager: Failed to send binary data:",t.message)}}},{key:"handleMessage",value:function(t){var e=this;if(t.data instanceof ArrayBuffer)this.emit("binaryAudio",t.data);else if(t.data instanceof Blob)t.data.arrayBuffer().then(function(t){e.emit("binaryAudio",t)}).catch(function(t){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return S.getAllConnections()}},{key:"clearAllConnections",value:function(){S.clearAll()}}],o&&O(n.prototype,o),r&&O(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a}(c);function A(t){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},A(t)}function B(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return D(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(D(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,D(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,D(d,"constructor",u),D(u,"constructor",s),s.displayName="GeneratorFunction",D(u,r,"GeneratorFunction"),D(d),D(d,r,"Generator"),D(d,o,function(){return this}),D(d,"toString",function(){return"[object Generator]"}),(B=function(){return{w:i,m:f}})()}function D(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}D=function(t,e,n,o){function i(e,n){D(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},D(t,e,n,o)}function R(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function _(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){R(i,o,r,a,c,"next",t)}function c(t){R(i,o,r,a,c,"throw",t)}a(void 0)})}}function U(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function M(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,N(o.key),o)}}function N(t){var e=function(t){if("object"!=A(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=A(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==A(e)?e:e+""}function z(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(z=function(){return!!t})()}function L(t){return L=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},L(t)}function V(t,e){return V=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},V(t,e)}var H=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=L(e),function(t,e){if(e&&("object"==A(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,z()?Reflect.construct(e,n||[],L(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&V(t,e)}(e,t),n=e,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var t,e=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return U(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?U(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{new URL(n);var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=_(B().m(function t(){var e,n,o=this;return B().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 1:if(this.mediaStream=t.v,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=2;break}return t.n=2,this.audioContext.resume();case 2:return e=this.getAudioProcessorPath(),t.n=3,this.audioContext.audioWorklet.addModule(e);case 3:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,n=e.type,r=e.data;"pcm_audio_data"===n&&o.emit("audioData",r)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,n=t.v,this.emit("error",n),n;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=_(B().m(function t(){var e;return B().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&M(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function K(t){return K="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},K(t)}function W(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return G(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(G(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,G(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,G(d,"constructor",u),G(u,"constructor",s),s.displayName="GeneratorFunction",G(u,r,"GeneratorFunction"),G(d),G(d,r,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(W=function(){return{w:i,m:f}})()}function G(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}G=function(t,e,n,o){function i(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},G(t,e,n,o)}function q(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Q(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,J(o.key),o)}}function J(t){var e=function(t){if("object"!=K(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=K(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==K(e)?e:e+""}function Y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Y=function(){return!!t})()}function $(t){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},$(t)}function X(t,e){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},X(t,e)}var Z=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=$(e),function(t,e){if(e&&("object"==K(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Y()?Reflect.construct(e,n||[],$(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&X(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(r=W().m(function t(){var e,n,o,r,i,a,c,s,u,l=this;return W().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||(o=this.config.sampleRate?{sampleRate:this.config.sampleRate}:{},this.audioContext=new(window.AudioContext||window.webkitAudioContext)(o)),"suspended"!==(r=this.audioContext).state){t.n=3;break}return t.n=3,r.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return i=t.v,t.n=5,r.decodeAudioData(i);case 5:a=t.v,c=n&&!this.isPlaying&&null===this.currentSource,(s=r.createBufferSource()).buffer=a,s.connect(r.destination),this.currentSource=s,this.isPlaying=!0,c&&this.emit("playbackStarted"),s.onended=function(){l.currentSource=null,l.isProcessingQueue=!1,l.audioQueue.length>0?setTimeout(function(){return l.processQueue()},0):setTimeout(function(){0!==l.audioQueue.length||l.currentSource||(l.isPlaying=!1,l.emit("playbackStopped"))},100)},s.start(),t.n=7;break;case 6:t.p=6,u=t.v,this.currentSource=null,this.emit("playbackError",u),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){q(i,n,o,a,c,"next",t)}function c(t){q(i,n,o,a,c,"throw",t)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&Q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function tt(t){return tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tt(t)}function et(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return nt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(nt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,nt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,nt(d,"constructor",u),nt(u,"constructor",s),s.displayName="GeneratorFunction",nt(u,r,"GeneratorFunction"),nt(d),nt(d,r,"Generator"),nt(d,o,function(){return this}),nt(d,"toString",function(){return"[object Generator]"}),(et=function(){return{w:i,m:f}})()}function nt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}nt=function(t,e,n,o){function i(e,n){nt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},nt(t,e,n,o)}function ot(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function rt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){ot(i,o,r,a,c,"next",t)}function c(t){ot(i,o,r,a,c,"throw",t)}a(void 0)})}}function it(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function at(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?it(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):it(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=ut(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function st(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ut(o.key),o)}}function ut(t){var e=function(t){if("object"!=tt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==tt(e)?e:e+""}function lt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(lt=function(){return!!t})()}function dt(t){return dt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},dt(t)}function ft(t,e){return ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ft(t,e)}var pt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=dt(e),function(t,e){if(e&&("object"==tt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,lt()?Reflect.construct(e,n||[],dt(t).constructor):e.apply(t,n))}(this,e)).config=at({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,agentSettingsOverride:n.agentSettingsOverride||null},n),t.isConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.webSocketManager=new F(at(at({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new H(t.config),t.audioPlayer=new Z(t.config),t.setupEventHandlers(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ft(t,e)}(e,t),n=e,o=[{key:"setupEventHandlers",value:function(){var t=this;this.webSocketManager.on("connected",function(){t.isConnected=!0,t.sendHelloMessage(),t.emit("connected")}),this.webSocketManager.on("disconnected",function(e){if(t.isConnected=!1,e&&1008===e.code&&e.reason&&(e.reason.includes("Domain not whitelisted")||e.reason.includes("domain")||e.reason.includes("whitelist"))){var n=new Error("DOMAIN_NOT_WHITELISTED");n.reason=e.reason,n.code=e.code,t.emit("domainError",n),t.emit("error",n)}t.isRecording&&t.stopRecording().catch(function(t){console.error("VoiceSDK: Error stopping recording on disconnect:",t)}),t.emit("disconnected",e)}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){if("greeting_audio"===e.t&&e.data)try{for(var n=atob(e.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(u=rt(et().m(function t(){var e,n;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isDestroyed){t.n=1;break}return t.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),t.n=2,this.connect();case 2:return t.a(2,t.v)}},t,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(c=rt(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw new Error("Not connected to voice server");case 1:return t.p=1,this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),t.n=2,this.audioRecorder.start();case 2:return t.a(2,!0);case 3:return t.p=3,e=t.v,console.error("❌ VoiceSDK: Failed to start recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=rt(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=at(at({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={t:"hello"};if(!this.config.appId){var e=new Error("appId is required for connection");return console.error("VoiceSDK: Failed to send hello message:",e),void this.emit("error",e)}t.appId=this.config.appId,this.config.agentSettingsOverride&&Object.keys(this.config.agentSettingsOverride).length>0&&(t.agentSettingsOverride=this.config.agentSettingsOverride,console.log("🔧 VoiceSDK: Sending agent settings override:",Object.keys(this.config.agentSettingsOverride)));try{this.webSocketManager.sendMessage(t)}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||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&st(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(c);function ht(t){return ht="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ht(t)}function vt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,gt(o.key),o)}}function gt(t){var e=function(t){if("object"!=ht(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ht(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ht(e)?e:e+""}var yt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){return this.events[t]||(this.events[t]=[]),this.events[t].push(e),this}},{key:"off",value:function(t,e){return this.events[t]?(this.events[t]=this.events[t].filter(function(t){return t!==e}),this):this}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];return!!this.events[t]&&(this.events[t].forEach(function(t){t.apply(void 0,n)}),!0)}},{key:"once",value:function(t,e){var n=this,o=function(){e.apply(void 0,arguments),n.off(t,o)};return this.on(t,o)}},{key:"removeAllListeners",value:function(t){return t?delete this.events[t]:this.events={},this}}],e&&vt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();const mt=yt;function bt(t){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},bt(t)}function wt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,St(o.key),o)}}function St(t){var e=function(t){if("object"!=bt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==bt(e)?e:e+""}const xt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCM"},(e=[{key:"decode",value:function(t){if(t instanceof ArrayBuffer)return t;if(t instanceof Uint8Array)return t.buffer;throw new Error("Invalid PCM data type")}},{key:"encode",value:function(t){return t}}])&&wt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function kt(t){return kt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},kt(t)}function Ct(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Pt(o.key),o)}}function Pt(t){var e=function(t){if("object"!=kt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=kt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==kt(e)?e:e+""}const Ot=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCMU"},(e=[{key:"decode",value:function(t){for(var e=t instanceof Uint8Array?t:new Uint8Array(t),n=new Int16Array(e.length),o=0;o<e.length;o++)n[o]=this.mulawToLinear(e[o]);return n.buffer}},{key:"encode",value:function(t){for(var e=t instanceof Int16Array?t:new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++)n[o]=this.linearToMulaw(e[o]);return n}},{key:"mulawToLinear",value:function(t){var e=1<<3+(t>>4&7);return(128&t?-1:1)*(132+(15&t)*e+(e>>1)-4)}},{key:"linearToMulaw",value:function(t){var e=t>>8&128;e&&(t=-t),t>32635&&(t=32635),t+=132;for(var n=7,o=16384;0===(t&o)&&n>0;n--,o>>=1);return 255&~(e|n<<4|t>>n+3&15)}}])&&Ct(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Tt(t){return Tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Tt(t)}function Et(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,jt(o.key),o)}}function jt(t){var e=function(t){if("object"!=Tt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Tt(e)?e:e+""}const It=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCMA"},(e=[{key:"decode",value:function(t){for(var e=t instanceof Uint8Array?t:new Uint8Array(t),n=new Int16Array(e.length),o=0;o<e.length;o++)n[o]=this.alawToLinear(e[o]);return n.buffer}},{key:"encode",value:function(t){for(var e=t instanceof Int16Array?t:new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++)n[o]=this.linearToAlaw(e[o]);return n}},{key:"alawToLinear",value:function(t){var e=(t^=85)>>4&7,n=15&t;return(128&t?-1:1)*(0===e?8+(n<<4):264+(n<<4)<<e-1)}},{key:"linearToAlaw",value:function(t){var e,n,o=t>>8&128;if(o&&(t=-t),t>32635&&(t=32635),t<256)e=0,n=t>>4;else{e=7;for(var r=16384;0===(t&r)&&e>0;e--,r>>=1);n=t>>e+3&15}return 85^(o|e<<4|n)}}])&&Et(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Ft(t){return Ft="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ft(t)}function At(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Bt(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Bt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function Bt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function Dt(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(Ft(t)+" is not iterable")}function Rt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return _t(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(_t(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,_t(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,_t(d,"constructor",u),_t(u,"constructor",s),s.displayName="GeneratorFunction",_t(u,r,"GeneratorFunction"),_t(d),_t(d,r,"Generator"),_t(d,o,function(){return this}),_t(d,"toString",function(){return"[object Generator]"}),(Rt=function(){return{w:i,m:f}})()}function _t(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}_t=function(t,e,n,o){function i(e,n){_t(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},_t(t,e,n,o)}function Ut(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Mt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Ut(i,o,r,a,c,"next",t)}function c(t){Ut(i,o,r,a,c,"throw",t)}a(void 0)})}}function Nt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,zt(o.key),o)}}function zt(t){var e=function(t){if("object"!=Ft(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ft(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ft(e)?e:e+""}function Lt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Lt=function(){return!!t})()}function Vt(t){return Vt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Vt(t)}function Ht(t,e){return Ht=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ht(t,e)}var Kt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=Vt(e),function(t,e){if(e&&("object"==Ft(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Lt()?Reflect.construct(e,n||[],Vt(t).constructor):e.apply(t,n))}(this,e)).config=n,t.audioContext=null,t.audioQueue=[],t.isPlaying=!1,t.isProcessingQueue=!1,t.currentSource=null,t.outputFormat=null,t.nextStartTime=0,t.scheduledBuffers=0,t.scheduledSources=new Set,t.pcmChunkQueue=[],t.preparedBuffer=[],t.isProcessingPcmQueue=!1,t.isSchedulingFrames=!1,t.MAX_LOOKAHEAD_SECONDS=.02,t.pendingSentenceText=null,t.sentenceTimings=[],t.isCheckingTranscripts=!1,t.codecs={pcm:new xt,pcmu:new Ot,pcma:new It},t.SUPPORTED_CONTAINERS=["wav","raw"],t.SUPPORTED_ENCODINGS=["pcm","pcmu","pcma"],t.SUPPORTED_SAMPLE_RATES=[8e3,16e3,22050,24e3,44100,48e3],t.SUPPORTED_BIT_DEPTHS=[8,16,24],t.SUPPORTED_CHANNELS=[1],console.log("🎵 AudioPlayer v2 initialized"),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Ht(t,e)}(e,t),n=e,o=[{key:"setOutputFormat",value:function(t){var e;this.validateFormat(t)||(console.warn("⚠️ AudioPlayer: Invalid format, using defaults:",t),t=this.getDefaultFormat());var n=null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate,o=t.sampleRate;this.outputFormat=t,console.log("✅ AudioPlayer v2: Format set:",t),this.audioContext&&n&&n!==o&&(console.warn("⚠️ AudioPlayer: Sample rate changed, recreating AudioContext"),console.warn(" Old: ".concat(n,"Hz → New: ").concat(o,"Hz")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null,console.log("ℹ️ AudioContext will be recreated on next audio chunk with correct sample rate"))}},{key:"validateFormat",value:function(t){var e,n;if(!t)return!1;var o=null===(e=t.container)||void 0===e?void 0:e.toLowerCase(),r=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&r&&this.SUPPORTED_CONTAINERS.includes(o)&&this.SUPPORTED_ENCODINGS.includes(r)&&this.SUPPORTED_SAMPLE_RATES.includes(t.sampleRate)&&this.SUPPORTED_BIT_DEPTHS.includes(t.bitDepth)&&(!t.channels||this.SUPPORTED_CHANNELS.includes(t.channels))}},{key:"getDefaultFormat",value:function(){return{container:"raw",encoding:"pcm",sampleRate:16e3,channels:1,bitDepth:16}}},{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){console.error("❌ AudioPlayer v2: Playback error:",t),this.emit("playbackError",t)}}},{key:"playChunk",value:(c=Mt(Rt().m(function t(e){var n,o,r=this;return Rt().w(function(t){for(;;)switch(t.n){case 0:(n=this.prepareChunk(e))?(this.preparedBuffer.push(n),(this.preparedBuffer.length<=3||this.preparedBuffer.length%10==0)&&console.log("📥 AudioPlayer: Frame received, queued: ".concat(this.preparedBuffer.length,", scheduled: ").concat(this.scheduledBuffers,", isScheduling: ").concat(this.isSchedulingFrames)),this.isSchedulingFrames?setTimeout(function(){r.preparedBuffer.length>0&&!r.isSchedulingFrames&&r.schedulePreparedFrames()},5):this.schedulePreparedFrames(),this.pcmChunkQueue.length>0&&!this.isProcessingPcmQueue&&this.processPcmQueue()):(console.error("❌ AudioPlayer: playChunk failed - prepareChunk returned null"),console.error(" pcmData length:",(null==e?void 0:e.byteLength)||"undefined"),console.error(" outputFormat:",this.outputFormat),console.error(" audioContext:",this.audioContext?"initialized":"not initialized"),console.error(" audioContext state:",(null===(o=this.audioContext)||void 0===o?void 0:o.state)||"N/A"),this.emit("playbackError",new Error("Failed to prepare PCM chunk for playback")));case 1:return t.a(2)}},t,this)})),function(t){return c.apply(this,arguments)})},{key:"prepareChunk",value:function(t){try{var e;if(!this.outputFormat)return console.error("❌ AudioPlayer: Cannot prepare chunk - outputFormat not set"),console.error(" Call setOutputFormat() before playing audio chunks"),null;if(this.audioContext||this.initializeAudioContext(),!this.audioContext)return console.error("❌ AudioPlayer: Cannot prepare chunk - AudioContext not available"),null;var n=t;if(t.byteLength%2!=0){console.warn("⚠️ Odd PCM chunk size, padding:",t.byteLength);var o=new Uint8Array(t.byteLength+1);o.set(new Uint8Array(t),0),o[t.byteLength]=0,n=o.buffer}for(var r=new Int16Array(n),i=new Float32Array(r.length),a=1/32768,c=r.length,s=0;s<c;s++)i[s]=r[s]*a;var u=(null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||this.audioContext.sampleRate,l=this.audioContext.sampleRate,d=this.audioContext.createBuffer(1,i.length,u);d.getChannelData(0).set(i);var f=d.duration,p=i.length,h=f;return l!==u&&(h=p/l),{buffer:d,duration:h,sampleRate:u,contextSampleRate:l}}catch(t){return console.error("❌ AudioPlayer: Error preparing chunk:",t),null}}},{key:"applyFadeOut",value:function(t){return t}},{key:"schedulePreparedFrames",value:(a=Mt(Rt().m(function t(){var e,n,o,r,i,a=this;return Rt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isSchedulingFrames){t.n=1;break}return t.a(2);case 1:if(this.isSchedulingFrames=!0,e=this.preparedBuffer.length,0===(n=Math.min(e,5))&&e>0&&(n=1),t.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:o=0,r=Rt().m(function t(){var e,n,r,i,c;return Rt().w(function(t){for(;;)switch(t.n){case 0:if(e=a.preparedBuffer.shift()){t.n=1;break}return t.a(2,1);case 1:(n=a.audioContext.createBufferSource()).buffer=e.buffer,n.connect(a.audioContext.destination),a.scheduledSources.add(n),r=a.audioContext.currentTime,0===a.scheduledBuffers?(a.nextStartTime<r&&(a.nextStartTime=r+a.MAX_LOOKAHEAD_SECONDS),console.log("🎵 Starting playback with minimal delay:",a.nextStartTime)):(i=r+a.MAX_LOOKAHEAD_SECONDS,a.nextStartTime<i&&(a.nextStartTime=i,console.warn("⚠️ AudioPlayer: Fell behind schedule, adjusting nextStartTime to ".concat(a.nextStartTime.toFixed(4),"s")))),a.pendingSentenceText&&(a.sentenceTimings.push({startTime:a.nextStartTime,text:a.pendingSentenceText,displayed:!1}),console.log("📝 AudioPlayer: Sentence scheduled at ".concat(a.nextStartTime.toFixed(3),'s: "').concat(a.pendingSentenceText.substring(0,40),'..."')),a.pendingSentenceText=null,a.isCheckingTranscripts||a.startTranscriptChecker()),n.start(a.nextStartTime),a.nextStartTime+=e.duration,a.nextStartTime=Math.round(1e6*a.nextStartTime)/1e6,c=a.nextStartTime-e.duration,a.scheduledBuffers<5&&(console.log("🎵 AudioPlayer: Scheduled frame ".concat(a.scheduledBuffers+1," at ").concat(c.toFixed(4),"s, next at ").concat(a.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(e.duration.toFixed(4),"s (").concat((1e3*e.duration).toFixed(2),"ms), Queued: ").concat(a.preparedBuffer.length,", Scheduled: ").concat(a.scheduledBuffers))),a.scheduledBuffers++,o++,n.onended=function(){if(a.scheduledSources.delete(n),a.scheduledBuffers--,0===a.scheduledBuffers&&0===a.preparedBuffer.length&&0===a.pcmChunkQueue.length)a.isPlaying=!1,a.isSchedulingFrames=!1,console.log("🛑 AudioPlayer: Emitting playbackStopped event (all buffers finished)"),a.emit("playbackStopped");else if(a.preparedBuffer.length>0)setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()},0);else if(a.scheduledBuffers>0){var t=function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(t,10)};setTimeout(t,10)}},a.isPlaying||(a.isPlaying=!0,console.log("🎵 AudioPlayer: Emitting playbackStarted event"),a.emit("playbackStarted"));case 2:return t.a(2)}},t)});case 4:if(!(this.preparedBuffer.length>0&&o<n)){t.n=7;break}return t.d(Dt(r()),5);case 5:if(!t.v){t.n=6;break}return t.a(3,7);case 6:t.n=4;break;case 7:this.isSchedulingFrames=!1,this.preparedBuffer.length>0&&requestAnimationFrame(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()}),this.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0&&a.schedulePreparedFrames()},10)},10),t.n=9;break;case 8:t.p=8,i=t.v,console.error("❌ AudioPlayer v2: Error scheduling frames:",i),this.emit("playbackError",i),this.isSchedulingFrames=!1;case 9:return t.a(2)}},t,this,[[2,8]])})),function(){return a.apply(this,arguments)})},{key:"processPcmQueue",value:(i=Mt(Rt().m(function t(){var e,n,o,r,i,a,c,s,u,l,d,f,p,h,v,g,y,m,b,w,S=this;return Rt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingPcmQueue){t.n=1;break}return t.a(2);case 1:if(this.isProcessingPcmQueue=!0,t.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:if(!(this.pcmChunkQueue.length>0)){t.n=5;break}if(o=this.pcmChunkQueue.shift()){t.n=4;break}return t.a(3,3);case 4:for(r=o,o.byteLength%2!=0&&(console.warn("⚠️ Odd PCM chunk size, padding:",o.byteLength),(i=new Uint8Array(o.byteLength+1)).set(new Uint8Array(o),0),i[o.byteLength]=0,r=i.buffer),a=new Int16Array(r),c=new Float32Array(a.length),s=1/32768,u=a.length,l=0;l<u;l++)c[l]=a[l]*s;d=(null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||this.audioContext.sampleRate,f=this.audioContext.sampleRate,null!==(n=this.outputFormat)&&void 0!==n&&n.sampleRate?this.scheduledBuffers<3&&console.log("🎵 AudioPlayer: Creating buffer at ".concat(d,"Hz (AudioContext: ").concat(f,"Hz)")):console.warn("⚠️ AudioPlayer: outputFormat.sampleRate not set! Using AudioContext sample rate:",f),(p=this.audioContext.createBuffer(1,c.length,d)).getChannelData(0).set(c),(h=this.audioContext.createBufferSource()).buffer=p,h.connect(this.audioContext.destination),v=this.audioContext.currentTime,this.nextStartTime<v&&(this.nextStartTime=v,0===this.scheduledBuffers&&console.log("🎵 Starting playback at current time:",v)),g=p.duration,y=c.length,m=g,f!==d&&(m=y/f,this.scheduledBuffers<3&&(console.log("🔄 Resampling detected: ".concat(d,"Hz → ").concat(f,"Hz")),console.log(" Buffer duration: ".concat(g.toFixed(4),"s, Calculated: ").concat(m.toFixed(4),"s")))),h.start(this.nextStartTime),this.nextStartTime+=m,this.nextStartTime=Math.round(1e6*this.nextStartTime)/1e6,this.scheduledBuffers<3&&(b=this.nextStartTime-m,console.log("🎵 AudioPlayer: Scheduled chunk ".concat(this.scheduledBuffers+1," at ").concat(b.toFixed(4),"s, next at ").concat(this.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(m.toFixed(4),"s (").concat((1e3*m).toFixed(2),"ms)"))),this.scheduledBuffers++,h.onended=function(){S.scheduledBuffers--,0===S.scheduledBuffers&&0===S.pcmChunkQueue.length&&(S.isPlaying=!1,S.isProcessingPcmQueue=!1,S.emit("playbackStopped"))},this.isPlaying||(this.isPlaying=!0,this.emit("playbackStarted")),t.n=3;break;case 5:this.isProcessingPcmQueue=!1,t.n=7;break;case 6:t.p=6,w=t.v,console.error("❌ AudioPlayer v2: Error playing chunk:",w),this.emit("playbackError",w),this.isProcessingPcmQueue=!1;case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return i.apply(this,arguments)})},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);console.log("🎵 AudioPlayer: Processing ".concat(e.length," bytes")),console.log("🎵 AudioPlayer: Negotiated format:",this.outputFormat);var n=this.outputFormat&&this.outputFormat.container&&"wav"===this.outputFormat.container.toLowerCase(),o=this.outputFormat&&this.outputFormat.container&&"raw"===this.outputFormat.container.toLowerCase(),r=this.isWavFile(e);if(r&&console.log("🎵 AudioPlayer: Data has WAV header (RIFF)"),o&&r)return console.error("❌ AudioPlayer: CRITICAL MISMATCH!"),console.error(" Negotiated format: RAW"),console.error(" Actual data: WAV (RIFF header detected)"),console.error(" Backend is ignoring format request and sending WAV anyway."),console.warn("⚠️ AudioPlayer: Processing as WAV to avoid playback failure, but UI configuration was bypassed."),this.handleWavFile(e);if(o&&!r)console.log("🎵 AudioPlayer: Processing as RAW data (as negotiated)");else{if(n&&r)return console.log("✅ AudioPlayer: Processing as WAV file (matches negotiation)"),this.handleWavFile(e);if(n&&!r)return console.warn("⚠️ AudioPlayer: Negotiated WAV but data lacks WAV header. Attempting WAV processing anyway."),this.handleWavFile(e);if(!this.outputFormat&&r)return console.log("🎵 AudioPlayer: No format negotiated, auto-detecting WAV"),this.handleWavFile(e);this.outputFormat||r||(console.warn("⚠️ AudioPlayer: No format negotiated and data not WAV, using defaults"),this.outputFormat=this.getDefaultFormat())}return this.outputFormat||(console.warn("⚠️ AudioPlayer: No format set, using defaults"),this.outputFormat=this.getDefaultFormat()),console.log("🎵 AudioPlayer: Processing as RAW data with encoding:",this.outputFormat.encoding),this.handleRawData(e)}},{key:"isWavFile",value:function(t){return t.length>=44&&82===t[0]&&73===t[1]&&70===t[2]&&70===t[3]}},{key:"handleWavFile",value:function(t){var e=this.parseWavHeader(t);if(console.log("🎵 WAV file detected:",{format:e.audioFormat,encoding:this.getEncodingName(e.audioFormat),sampleRate:e.sampleRate,channels:e.channels,bitDepth:e.bitsPerSample}),1===e.audioFormat)return console.log("✅ PCM WAV - using directly"),new Blob([t],{type:"audio/wav"});var n=this.getCodecForWavFormat(e.audioFormat);if(!n)throw new Error("Unsupported WAV format code: ".concat(e.audioFormat));console.log("🔄 Non-PCM WAV - converting to PCM WAV");var o=t.slice(44),r=n.decode(o),i=this.createWavHeader(r.byteLength,e.sampleRate,e.channels,16);return new Blob([i,r],{type:"audio/wav"})}},{key:"handleRawData",value:function(t){var e,n,o=this.outputFormat.encoding.toLowerCase(),r=this.getCodec(o);if(!r)throw new Error("No codec found for encoding: ".concat(o));if(console.log("🎵 AudioPlayer: Decoding ".concat(o.toUpperCase()," to PCM")),console.log("🎵 AudioPlayer: Input format - bitDepth: ".concat(this.outputFormat.bitDepth,", sampleRate: ").concat(this.outputFormat.sampleRate)),"pcm"===o){var i=this.outputFormat.bitDepth||16;t.length,24===i?(console.warn("⚠️ AudioPlayer: Format says 24-bit PCM, but browser support is limited."),console.warn(" Treating as 16-bit PCM. If audio sounds wrong, backend should send 16-bit instead."),e=this.convert24BitTo16Bit(t),n=16):8===i?(console.log("🔄 AudioPlayer: Converting 8-bit PCM to 16-bit PCM"),e=this.convert8BitTo16Bit(t),n=16):(e=t.buffer,n=i,console.log("✅ AudioPlayer: Using native ".concat(i,"-bit PCM (no conversion needed)")))}else e=r.decode(t),n=16,console.log("🔄 AudioPlayer: Decoded ".concat(o.toUpperCase()," to 16-bit PCM"));var a=this.createWavHeader(e.byteLength,this.outputFormat.sampleRate,this.outputFormat.channels,n);return new Blob([a,e],{type:"audio/wav"})}},{key:"convert24BitTo16Bit",value:function(t){for(var e=Math.floor(t.length/3),n=new Int16Array(e),o=0;o<e;o++){var r=t[3*o],i=t[3*o+1],a=t[3*o+2],c=r|i<<8|(255&a)<<16;128&a&&(c|=4278190080),n[o]=Math.max(-32768,Math.min(32767,Math.round(c/256)))}return n.buffer}},{key:"convert8BitTo16Bit",value:function(t){for(var e=t.length,n=new Int16Array(e),o=0;o<e;o++){var r=t[o];n[o]=256*(r-128)}return n.buffer}},{key:"getCodec",value:function(t){var e={pcm:"pcm",linear:"pcm",l16:"pcm",pcmu:"pcmu",ulaw:"pcmu",mulaw:"pcmu",g711u:"pcmu",pcma:"pcma",alaw:"pcma",g711a:"pcma"}[t.toLowerCase()];return this.codecs[e]}},{key:"getCodecForWavFormat",value:function(t){switch(t){case 1:return this.codecs.pcm;case 6:return this.codecs.pcma;case 7:return this.codecs.pcmu;default:return null}}},{key:"getEncodingName",value:function(t){switch(t){case 1:return"PCM";case 6:return"A-law";case 7:return"μ-law";default:return"Unknown (".concat(t,")")}}},{key:"parseWavHeader",value:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{audioFormat:e.getUint16(20,!0),channels:e.getUint16(22,!0),sampleRate:e.getUint32(24,!0),byteRate:e.getUint32(28,!0),blockAlign:e.getUint16(32,!0),bitsPerSample:e.getUint16(34,!0)}}},{key:"createWavHeader",value:function(t,e,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+t,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,e,!0),i.setUint32(28,e*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0),r}},{key:"initializeAudioContext",value:function(){var t,e,n=(null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate)||48e3;if(48e3!==n&&44100!==n&&(console.log("ℹ️ AudioPlayer: Backend requested ".concat(n,"Hz, but browser may resample to 48kHz")),console.log(" Consider requesting 48kHz from backend to avoid resampling and improve quality")),this.audioContext){var o=this.audioContext.sampleRate;if(!(Math.abs(o-n)>100))return;console.warn("⚠️ AudioPlayer: AudioContext sample rate (".concat(o,"Hz) doesn't match format (").concat(n,"Hz), recreating...")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null}console.log("🎵 AudioPlayer: Creating AudioContext at ".concat(n,"Hz (from outputFormat: ").concat((null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||"not set",")"));try{this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n,latencyHint:"playback"}),console.log("✅ AudioContext created at ".concat(this.audioContext.sampleRate,"Hz (requested: ").concat(n,"Hz)")),Math.abs(this.audioContext.sampleRate-n)>100?(console.error("❌ CRITICAL: Browser sample rate mismatch!"),console.error(" Requested: ".concat(n,"Hz")),console.error(" Got: ".concat(this.audioContext.sampleRate,"Hz")),console.error(" This WILL cause audio distortion/noise!"),console.error(" Solution: Backend should send ".concat(this.audioContext.sampleRate,"Hz audio instead"))):this.audioContext.sampleRate!==n&&(console.warn("⚠️ Browser adjusted sample rate: ".concat(n,"Hz → ").concat(this.audioContext.sampleRate,"Hz")),console.warn(" Browser will automatically resample audio."))}catch(t){console.error("❌ Failed to create AudioContext:",t),this.audioContext=new(window.AudioContext||window.webkitAudioContext),console.log("ℹ️ Using browser default: ".concat(this.audioContext.sampleRate,"Hz"))}}},{key:"processQueue",value:(r=Mt(Rt().m(function t(){var e,n,o,r,i,a,c,s=this;return Rt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return o=t.v,t.n=5,this.audioContext.decodeAudioData(o);case 5:r=t.v,i=n&&!this.isPlaying&&null===this.currentSource,(a=this.audioContext.createBufferSource()).buffer=r,a.connect(this.audioContext.destination),this.currentSource=a,this.isPlaying=!0,i&&this.emit("playbackStarted"),a.onended=function(){s.currentSource=null,s.isProcessingQueue=!1,s.audioQueue.length>0?setTimeout(function(){return s.processQueue()},50):setTimeout(function(){0!==s.audioQueue.length||s.currentSource||(s.isPlaying=!1,s.emit("playbackStopped"))},100)},a.start(),t.n=7;break;case 6:t.p=6,c=t.v,console.error("❌ AudioPlayer v2: Error processing queue:",c),this.currentSource=null,this.emit("playbackError",c),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return s.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"reset",value:function(){this.stop(),this.audioQueue=[],this.pcmChunkQueue=[]}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource||this.scheduledSources.size>0;if(console.log("🛑 AudioPlayer.stopImmediate() called"),console.log(" isPlaying:",this.isPlaying),console.log(" currentSource:",null!==this.currentSource),console.log(" scheduledSources.size:",this.scheduledSources.size),console.log(" scheduledBuffers:",this.scheduledBuffers),this.currentSource){try{console.log(" Stopping currentSource..."),this.currentSource.stop()}catch(t){console.log(" currentSource already stopped or error:",t.message)}this.currentSource=null}if(this.scheduledSources.size>0){console.log(" Stopping ".concat(this.scheduledSources.size," scheduled sources..."));var e,n=0,o=At(this.scheduledSources);try{for(o.s();!(e=o.n()).done;){var r=e.value;try{r.stop(),n++}catch(t){console.log(" Source already stopped or not started:",t.message)}}}catch(t){o.e(t)}finally{o.f()}console.log(" Stopped ".concat(n," sources")),this.scheduledSources.clear()}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],this.pcmChunkQueue=[],this.preparedBuffer=[],this.isProcessingPcmQueue=!1,this.isSchedulingFrames=!1,this.nextStartTime=0,this.scheduledBuffers=0,this.clearTranscriptState(),t&&(console.log("🛑 AudioPlayer: Emitting playbackStopped event (stopImmediate called)"),this.emit("playbackStopped"))}},{key:"markNewSentence",value:function(t){this.pendingSentenceText=t,console.log('📝 AudioPlayer: New sentence marked: "'.concat(t.substring(0,40),'..."'))}},{key:"startTranscriptChecker",value:function(){var t=this;if(!this.isCheckingTranscripts){this.isCheckingTranscripts=!0,console.log("📝 AudioPlayer: Transcript checker started");var e=function(){if(t.isCheckingTranscripts&&t.audioContext){var n,o=t.audioContext.currentTime,r=At(t.sentenceTimings);try{for(r.s();!(n=r.n()).done;){var i=n.value;!i.displayed&&o>=i.startTime&&(i.displayed=!0,console.log("📝 AudioPlayer: Display transcript at ".concat(o.toFixed(3),'s: "').concat(i.text.substring(0,40),'..."')),t.emit("transcriptDisplay",{text:i.text}))}}catch(t){r.e(t)}finally{r.f()}t.isPlaying||t.scheduledBuffers>0?requestAnimationFrame(e):(t.isCheckingTranscripts=!1,console.log("📝 AudioPlayer: Transcript checker stopped"))}};requestAnimationFrame(e)}}},{key:"clearTranscriptState",value:function(){this.pendingSentenceText=null,this.sentenceTimings=[],this.isCheckingTranscripts=!1,console.log("📝 AudioPlayer: Transcript state cleared")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed",outputFormat:this.outputFormat,scheduledBuffers:this.scheduledBuffers,preparedBufferLength:this.preparedBuffer.length,scheduledSourcesCount:this.scheduledSources.size}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.removeAllListeners()}}],o&&Nt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c}(mt);const Wt=Kt;function Gt(t){return Gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Gt(t)}function qt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Qt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Qt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Qt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Qt(d,"constructor",u),Qt(u,"constructor",s),s.displayName="GeneratorFunction",Qt(u,r,"GeneratorFunction"),Qt(d),Qt(d,r,"Generator"),Qt(d,o,function(){return this}),Qt(d,"toString",function(){return"[object Generator]"}),(qt=function(){return{w:i,m:f}})()}function Qt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Qt=function(t,e,n,o){function i(e,n){Qt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Qt(t,e,n,o)}function Jt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Yt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Jt(i,o,r,a,c,"next",t)}function c(t){Jt(i,o,r,a,c,"throw",t)}a(void 0)})}}function $t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function Xt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Zt(o.key),o)}}function Zt(t){var e=function(t){if("object"!=Gt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Gt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Gt(e)?e:e+""}function te(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(te=function(){return!!t})()}function ee(t){return ee=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ee(t)}function ne(t,e){return ne=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ne(t,e)}var oe=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=ee(e),function(t,e){if(e&&("object"==Gt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,te()?Reflect.construct(e,n||[],ee(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ne(t,e)}(e,t),n=e,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var t,e=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return $t(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?$t(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=Yt(qt().m(function t(){var e,n,o,r,i,a,c=this;return qt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,"https:"===location.protocol||"localhost"===location.hostname||"127.0.0.1"===location.hostname){t.n=1;break}throw e=new Error("Microphone access requires HTTPS. Please use https:// or test on localhost."),console.error("❌ AudioRecorder:",e.message),this.emit("error",e),e;case 1:if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){t.n=2;break}throw n=new Error("getUserMedia is not supported in this browser. Please use a modern browser."),console.error("❌ AudioRecorder:",n.message),this.emit("error",n),n;case 2:return console.log("🎤 AudioRecorder: Requesting microphone access..."),t.n=3,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 3:if(this.mediaStream=t.v,console.log("✅ AudioRecorder: Microphone access granted"),this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=4;break}return t.n=4,this.audioContext.resume();case 4:return o=this.getAudioProcessorPath(),t.n=5,this.audioContext.audioWorklet.addModule(o);case 5:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,n=e.type,o=e.data;"pcm_audio_data"===n&&c.emit("audioData",o)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=7;break;case 6:throw t.p=6,a=t.v,r=a.message,"NotAllowedError"===a.name||"PermissionDeniedError"===a.name?(r="Microphone permission denied. Please allow microphone access in your browser settings and try again.",console.error("❌ AudioRecorder: Permission denied. User needs to grant microphone access.")):"NotFoundError"===a.name||"DevicesNotFoundError"===a.name?(r="No microphone found. Please connect a microphone and try again.",console.error("❌ AudioRecorder: No microphone device found.")):"NotReadableError"===a.name||"TrackStartError"===a.name?(r="Microphone is already in use by another application. Please close other apps using the microphone and try again.",console.error("❌ AudioRecorder: Microphone is busy or not readable.")):a.message&&a.message.includes("not allowed by the user agent")&&(r="Microphone access blocked. On mobile devices, please tap the recording button directly (not from an iframe or popup).",console.error("❌ AudioRecorder: User agent blocked microphone access. This often happens on mobile when not called from direct user interaction.")),(i=new Error(r)).name=a.name,i.originalError=a,console.error("❌ AudioRecorder: Failed to start recording:",i),this.emit("error",i),i;case 7:return t.a(2)}},t,this,[[0,6]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=Yt(qt().m(function t(){var e;return qt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&Xt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(mt);function re(t){return re="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},re(t)}function ie(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ae(o.key),o)}}function ae(t){var e=function(t){if("object"!=re(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=re(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==re(e)?e:e+""}const ce=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"extractPcmFromWav",value:function(t){var e=t instanceof Uint8Array?t:new Uint8Array(t);if(e.length<44)throw new Error("WAV data too short (< 44 bytes)");if("RIFF"!==String.fromCharCode(e[0],e[1],e[2],e[3]))throw new Error("Not a valid WAV file - missing RIFF header");if("WAVE"!==String.fromCharCode(e[8],e[9],e[10],e[11]))throw new Error("Not a valid WAV file - missing WAVE format");for(var n=e[22]|e[23]<<8,o=e[24]|e[25]<<8|e[26]<<16|e[27]<<24,r=e[34]|e[35]<<8,i=-1,a=12;a<e.length-8;a+=4){if("data"===String.fromCharCode(e[a],e[a+1],e[a+2],e[a+3])){i=a;break}a+=4+(e[a+4]|e[a+5]<<8|e[a+6]<<16|e[a+7]<<24)}if(-1===i)throw new Error("No data chunk found in WAV");var c=e[i+4]|e[i+5]<<8|e[i+6]<<16|e[i+7]<<24,s=i+8,u=Math.min(c,e.length-s);return{pcmData:e.slice(s,s+u).buffer,format:{sampleRate:o,channels:n,bitDepth:r}}}},{key:"isWavFile",value:function(t){return t.length>=44&&82===t[0]&&73===t[1]&&70===t[2]&&70===t[3]}},{key:"createWavHeader",value:function(t,e,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+t,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,e,!0),i.setUint32(28,e*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0),r}},{key:"wrapPcmInWav",value:function(e,n){var o=t.createWavHeader(e.byteLength,n.sampleRate,n.channels||1,n.bitDepth||16),r=new Uint8Array(o.byteLength+e.byteLength);return r.set(new Uint8Array(o),0),r.set(new Uint8Array(e),o.byteLength),r.buffer}}],null&&ie(e.prototype,null),n&&ie(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function se(t){return se="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},se(t)}function ue(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,le(o.key),o)}}function le(t){var e=function(t){if("object"!=se(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=se(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==se(e)?e:e+""}const de=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.codecs={pcm:new xt,pcmu:new Ot,pcma:new It}},(e=[{key:"decodeToPcm",value:function(t,e){var n=null==e?void 0:e.toLowerCase();if(!n||"pcm"===n)return t instanceof ArrayBuffer?t:t instanceof Uint8Array?t.buffer:t;var o=this.codecs[n];if(!o)throw new Error("Unsupported encoding: ".concat(e));var r=t instanceof Uint8Array?t:new Uint8Array(t);return o.decode(r)}},{key:"encodeFromPcm",value:function(t,e){var n=null==e?void 0:e.toLowerCase();if(!n||"pcm"===n)return t;var o=this.codecs[n];if(!o)throw new Error("Unsupported target encoding: ".concat(e));var r=o.encode(t);return r instanceof Uint8Array?r.buffer:r}},{key:"getCodec",value:function(t){var e=null==t?void 0:t.toLowerCase();return this.codecs[e]||null}}])&&ue(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function fe(t){return fe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},fe(t)}function pe(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,he(o.key),o)}}function he(t){var e=function(t){if("object"!=fe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=fe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==fe(e)?e:e+""}const ve=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"convert",value:function(e,n,o){if(n===o)return e;if(8===n)throw new Error("Source bit depth cannot be 8-bit (only 16-bit or 24-bit supported)");var r=n/8,i=o/8,a=e.byteLength/r;if(new ArrayBuffer(a*i),16===n&&16===o)return e;if(24===n&&16===o)return t.convert24To16(e);if(16===n&&24===o)return t.convert16To24(e);if(16===n&&8===o)return t.convert16To8(e);if(24===n&&8===o)return t.convert24To8(e);throw new Error("Unsupported bit depth conversion: ".concat(n,"-bit → ").concat(o,"-bit"))}},{key:"convert24To16",value:function(t){for(var e=new Uint8Array(t),n=Math.floor(e.length/3),o=new Int16Array(n),r=0;r<n;r++){var i=e[3*r],a=e[3*r+1],c=e[3*r+2],s=i|a<<8|(255&c)<<16;128&c&&(s|=4278190080),o[r]=Math.max(-32768,Math.min(32767,Math.round(s/256)))}return o.buffer}},{key:"convert16To24",value:function(t){for(var e=new Int16Array(t),n=new Uint8Array(3*e.length),o=0;o<e.length;o++){var r=256*e[o];n[3*o]=255&r,n[3*o+1]=r>>8&255,n[3*o+2]=r>>16&255}return n.buffer}},{key:"convert16To8",value:function(t){for(var e=new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++){var r=e[o];n[o]=Math.max(0,Math.min(255,Math.round(r/256+128)))}return n.buffer}},{key:"convert24To8",value:function(e){var n=t.convert24To16(e);return t.convert16To8(n)}}],null&&pe(e.prototype,null),n&&pe(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function ge(t){return ge="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ge(t)}function ye(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return me(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(me(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,me(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,me(d,"constructor",u),me(u,"constructor",s),s.displayName="GeneratorFunction",me(u,r,"GeneratorFunction"),me(d),me(d,r,"Generator"),me(d,o,function(){return this}),me(d,"toString",function(){return"[object Generator]"}),(ye=function(){return{w:i,m:f}})()}function me(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}me=function(t,e,n,o){function i(e,n){me(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},me(t,e,n,o)}function be(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function we(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Se(o.key),o)}}function Se(t){var e=function(t){if("object"!=ge(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ge(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ge(e)?e:e+""}const xe=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"resample",value:(n=ye().m(function t(e,n,o){var r,i,a,c,s,u,l,d,f,p,h,v,g;return ye().w(function(t){for(;;)switch(t.n){case 0:if(n!==o){t.n=1;break}return t.a(2,e);case 1:for(r=new Int16Array(e),i=new Float32Array(r.length),a=1/32768,c=0;c<r.length;c++)i[c]=r[c]*a;return s=Math.ceil(i.length*o/n),u=new OfflineAudioContext(1,s,o),(l=u.createBuffer(1,i.length,n)).getChannelData(0).set(i),(d=u.createBufferSource()).buffer=l,d.connect(u.destination),d.start(),t.n=2,u.startRendering();case 2:for(f=t.v,p=f.getChannelData(0),h=new Int16Array(p.length),v=0;v<p.length;v++)g=Math.max(-1,Math.min(1,p[v])),h[v]=Math.round(32767*g);return t.a(2,h.buffer)}},t)}),o=function(){var t=this,e=arguments;return new Promise(function(o,r){var i=n.apply(t,e);function a(t){be(i,o,r,a,c,"next",t)}function c(t){be(i,o,r,a,c,"throw",t)}a(void 0)})},function(t,e,n){return o.apply(this,arguments)})}],e&&we(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function ke(t){return ke="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ke(t)}function Ce(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Pe(o.key),o)}}function Pe(t){var e=function(t){if("object"!=ke(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ke(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ke(e)?e:e+""}const Oe=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"convert",value:function(e,n,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(n===o)return e;if(1===n&&1===o)return e;if(1===n&&2===o)return t.monoToStereo(e,r);if(2===n&&1===o)return t.stereoToMono(e,r);throw new Error("Unsupported channel conversion: ".concat(n," → ").concat(o))}},{key:"monoToStereo",value:function(t,e){for(var n=e/8,o=t.byteLength/n,r=new ArrayBuffer(o*n*2),i=new Uint8Array(t),a=new Uint8Array(r),c=0;c<o;c++)for(var s=c*n,u=c*n*2,l=0;l<n;l++)a[u+l]=i[s+l],a[u+n+l]=i[s+l];return r}},{key:"stereoToMono",value:function(t,e){var n=e/8,o=t.byteLength/(2*n),r=new ArrayBuffer(o*n),i=new Uint8Array(t),a=new Uint8Array(r);if(16===e)for(var c=0;c<o;c++){var s=c*n*2,u=s+n,l=(i[s]|i[s+1]<<8)<<16>>16,d=(i[u]|i[u+1]<<8)<<16>>16,f=Math.round((l+d)/2),p=c*n;a[p]=255&f,a[p+1]=f>>8&255}else for(var h=0;h<o;h++)for(var v=h*n*2,g=h*n,y=0;y<n;y++)a[g+y]=i[v+y];return r}}],null&&Ce(e.prototype,null),n&&Ce(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function Te(t){return Te="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Te(t)}function Ee(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return je(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(je(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,je(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,je(d,"constructor",u),je(u,"constructor",s),s.displayName="GeneratorFunction",je(u,r,"GeneratorFunction"),je(d),je(d,r,"Generator"),je(d,o,function(){return this}),je(d,"toString",function(){return"[object Generator]"}),(Ee=function(){return{w:i,m:f}})()}function je(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}je=function(t,e,n,o){function i(e,n){je(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},je(t,e,n,o)}function Ie(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Fe(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ie(Object(n),!0).forEach(function(e){Ae(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ie(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ae(t,e,n){return(e=Re(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Be(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function De(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Re(o.key),o)}}function Re(t){var e=function(t){if("object"!=Te(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Te(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Te(e)?e:e+""}const _e=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.requestedFormat=e,this.actualFormat=n,this.encodingConverter=new de,this.conversionSteps=[],this._analyzeConversions()},e=[{key:"_analyzeConversions",value:function(){this.conversionSteps=[],this.actualFormat.container!==this.requestedFormat.container&&("wav"===this.actualFormat.container?this.conversionSteps.push("extract_wav"):"wav"===this.requestedFormat.container&&this.conversionSteps.push("wrap_wav")),this.actualFormat.encoding!==this.requestedFormat.encoding&&("pcm"!==this.actualFormat.encoding&&this.conversionSteps.push("decode_encoding"),"pcm"!==this.requestedFormat.encoding&&this.conversionSteps.push("encode_encoding")),this.actualFormat.sampleRate!==this.requestedFormat.sampleRate&&this.conversionSteps.push("resample"),this.actualFormat.bitDepth!==this.requestedFormat.bitDepth&&this.conversionSteps.push("convert_bitdepth"),this.actualFormat.channels!==this.requestedFormat.channels&&this.conversionSteps.push("convert_channels")}},{key:"needsConversion",value:function(){return this.conversionSteps.length>0}},{key:"getConversionSteps",value:function(){var t=[];return this.conversionSteps.includes("extract_wav")&&t.push("Extract PCM from WAV (".concat(this.actualFormat.container," → raw)")),this.conversionSteps.includes("decode_encoding")&&t.push("Decode ".concat(this.actualFormat.encoding.toUpperCase()," → PCM")),this.conversionSteps.includes("resample")&&t.push("Resample ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz")),this.conversionSteps.includes("convert_bitdepth")&&t.push("Convert bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit")),this.conversionSteps.includes("convert_channels")&&t.push("Convert channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels)),this.conversionSteps.includes("encode_encoding")&&t.push("Encode PCM → ".concat(this.requestedFormat.encoding.toUpperCase())),this.conversionSteps.includes("wrap_wav")&&t.push("Wrap in WAV container (raw → ".concat(this.requestedFormat.container,")")),t}},{key:"convert",value:(n=Ee().m(function t(e){var n,o,r,i;return Ee().w(function(t){for(;;)switch(t.n){case 0:if(this.needsConversion()){t.n=1;break}return t.a(2,e instanceof ArrayBuffer?e:e.buffer);case 1:if(n=e instanceof ArrayBuffer?e:e.buffer,o=Fe({},this.actualFormat),this.conversionSteps.includes("extract_wav")&&(r=ce.extractPcmFromWav(n),n=r.pcmData,o=Fe(Fe({},o),{},{container:"raw",sampleRate:r.format.sampleRate,channels:r.format.channels,bitDepth:r.format.bitDepth}),console.log("🔄 AudioFormatConverter: Extracted PCM from WAV",r.format)),this.conversionSteps.includes("decode_encoding")&&(n=this.encodingConverter.decodeToPcm(n,o.encoding),o.encoding="pcm",o.bitDepth=16,console.log("🔄 AudioFormatConverter: Decoded ".concat(this.actualFormat.encoding.toUpperCase()," → PCM"))),24===o.bitDepth&&o.bitDepth!==this.requestedFormat.bitDepth&&(this.conversionSteps.includes("resample")||this.conversionSteps.includes("convert_channels")||24!==this.requestedFormat.bitDepth)&&(n=ve.convert(n,24,16),o.bitDepth=16,console.log("🔄 AudioFormatConverter: Normalized 24-bit → 16-bit PCM")),!this.conversionSteps.includes("resample")){t.n=3;break}return t.n=2,xe.resample(n,o.sampleRate,this.requestedFormat.sampleRate);case 2:n=t.v,o.sampleRate=this.requestedFormat.sampleRate,console.log("🔄 AudioFormatConverter: Resampled ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz"));case 3:return this.conversionSteps.includes("convert_channels")&&(n=Oe.convert(n,o.channels,this.requestedFormat.channels,o.bitDepth),o.channels=this.requestedFormat.channels,console.log("🔄 AudioFormatConverter: Converted channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels))),this.conversionSteps.includes("convert_bitdepth")&&(n=ve.convert(n,o.bitDepth,this.requestedFormat.bitDepth),o.bitDepth=this.requestedFormat.bitDepth,console.log("🔄 AudioFormatConverter: Converted bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit"))),this.conversionSteps.includes("encode_encoding")&&(i=this.encodingConverter.encodeFromPcm(n,this.requestedFormat.encoding),n=i instanceof ArrayBuffer?i:i.buffer,o.encoding=this.requestedFormat.encoding,console.log("🔄 AudioFormatConverter: Encoded PCM → ".concat(this.requestedFormat.encoding.toUpperCase()))),this.conversionSteps.includes("wrap_wav")&&(n=ce.wrapPcmInWav(n,o),o.container="wav",console.log("🔄 AudioFormatConverter: Wrapped in WAV container")),console.log("✅ AudioFormatConverter: Conversion complete"),t.a(2,n)}},t,this)}),o=function(){var t=this,e=arguments;return new Promise(function(o,r){var i=n.apply(t,e);function a(t){Be(i,o,r,a,c,"next",t)}function c(t){Be(i,o,r,a,c,"throw",t)}a(void 0)})},function(t){return o.apply(this,arguments)})}],e&&De(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Ue(t){return Ue="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ue(t)}function Me(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Ne(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Me(Object(n),!0).forEach(function(e){Qe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Me(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ze(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Le(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Le(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Le(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Le(d,"constructor",u),Le(u,"constructor",s),s.displayName="GeneratorFunction",Le(u,r,"GeneratorFunction"),Le(d),Le(d,r,"Generator"),Le(d,o,function(){return this}),Le(d,"toString",function(){return"[object Generator]"}),(ze=function(){return{w:i,m:f}})()}function Le(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Le=function(t,e,n,o){function i(e,n){Le(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Le(t,e,n,o)}function Ve(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function He(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Ve(i,o,r,a,c,"next",t)}function c(t){Ve(i,o,r,a,c,"throw",t)}a(void 0)})}}function Ke(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Je(o.key),o)}}function We(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(We=function(){return!!t})()}function Ge(t){return Ge=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Ge(t)}function qe(t,e){return qe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},qe(t,e)}function Qe(t,e,n){return(e=Je(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Je(t){var e=function(t){if("object"!=Ue(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ue(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ue(e)?e:e+""}var Ye=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=Ge(e),function(t,e){if(e&&("object"==Ue(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,We()?Reflect.construct(e,n||[],Ge(t).constructor):e.apply(t,n))}(this,e)).version="2.0.0",t.config={websocketUrl:n.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:n.agentId,appId:n.appId,sampleRate:n.sampleRate||16e3,channels:n.channels||1,bitDepth:n.bitDepth||16,audioProcessorPath:n.audioProcessorPath,outputContainer:n.outputContainer||t.getDefaultContainer(n),outputEncoding:n.outputEncoding||n.outputCodec||"pcm",outputSampleRate:n.outputSampleRate||16e3,outputChannels:n.outputChannels||1,outputBitDepth:n.outputBitDepth||16,outputFrameDurationMs:n.outputFrameDurationMs||600,outputCodec:n.outputCodec,agentSettingsOverride:n.agentSettingsOverride||null,variables:n.variables||null,autoReconnect:!1!==n.autoReconnect,protocolVersion:n.protocolVersion||2},t.isConnected=!1,t.hasEverConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.outputAudioFormat=null,t.requestedOutputFormat=null,t.formatConverter=null,t.websocket=null,t.conversationId=null,t.audioPlayer=new Wt(t.config),t.audioRecorder=new oe(t.config),t.setupAudioPlayerEvents(),t.setupAudioRecorderEvents(),t.validateConfig(),console.log("🎵 VoiceSDK v2 initialized:",{version:t.version,outputContainer:t.config.outputContainer,outputEncoding:t.config.outputEncoding,outputSampleRate:t.config.outputSampleRate}),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&qe(t,e)}(e,t),n=e,o=[{key:"getDefaultContainer",value:function(t){return"wav"===t.outputCodec?"wav":"raw"}},{key:"validateInputFormat",value:function(t){var n;if(!t)return"Input format is required";var o=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&e.SUPPORTED_INPUT_ENCODINGS.includes(o)?t.sampleRate&&e.SUPPORTED_INPUT_SAMPLE_RATES.includes(t.sampleRate)?t.bitDepth&&e.SUPPORTED_INPUT_BIT_DEPTHS.includes(t.bitDepth)?t.channels&&e.SUPPORTED_INPUT_CHANNELS.includes(t.channels)?null:"Unsupported input channels: ".concat(t.channels,". Supported: ").concat(e.SUPPORTED_INPUT_CHANNELS.join(", ")):"Unsupported input bit depth: ".concat(t.bitDepth,". Supported: ").concat(e.SUPPORTED_INPUT_BIT_DEPTHS.join(", ")):"Unsupported input sample rate: ".concat(t.sampleRate,". Supported: ").concat(e.SUPPORTED_INPUT_SAMPLE_RATES.join(", ")):"Unsupported input encoding: ".concat(t.encoding,". Supported: ").concat(e.SUPPORTED_INPUT_ENCODINGS.join(", "))}},{key:"validateOutputFormat",value:function(t){var n,o;if(!t)return"Output format is required";var r=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();if(!r||!e.SUPPORTED_OUTPUT_ENCODINGS.includes(r))return"Unsupported output encoding: ".concat(t.encoding,". Supported: ").concat(e.SUPPORTED_OUTPUT_ENCODINGS.join(", "));if(!t.sampleRate||!e.SUPPORTED_OUTPUT_SAMPLE_RATES.includes(t.sampleRate))return"Unsupported output sample rate: ".concat(t.sampleRate,". Supported: ").concat(e.SUPPORTED_OUTPUT_SAMPLE_RATES.join(", "));if(!t.bitDepth||!e.SUPPORTED_OUTPUT_BIT_DEPTHS.includes(t.bitDepth))return"Unsupported output bit depth: ".concat(t.bitDepth,". Supported: ").concat(e.SUPPORTED_OUTPUT_BIT_DEPTHS.join(", "));if(!t.channels||!e.SUPPORTED_OUTPUT_CHANNELS.includes(t.channels))return"Unsupported output channels: ".concat(t.channels,". Supported: ").concat(e.SUPPORTED_OUTPUT_CHANNELS.join(", "));var i=null===(o=t.container)||void 0===o?void 0:o.toLowerCase();return i&&e.SUPPORTED_OUTPUT_CONTAINERS.includes(i)?null:"Unsupported output container: ".concat(t.container,". Supported: ").concat(e.SUPPORTED_OUTPUT_CONTAINERS.join(", "))}},{key:"validateConfig",value:function(){var t={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},e=this.validateInputFormat(t);if(e)return console.error("❌ VoiceSDK v2: Invalid input format:",e),void this.emit("error",new Error(e));var n={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},o=this.validateOutputFormat(n);if(o)return console.error("❌ VoiceSDK v2: Invalid output format:",o),void this.emit("error",new Error(o));console.log("✅ VoiceSDK v2: Format validation passed")}},{key:"setupAudioPlayerEvents",value:function(){var t=this;this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_started_playing message to server"),t.sendMessage({t:"audio_started_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_started_playing - not connected")}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_stopped_playing message to server"),t.sendMessage({t:"audio_stopped_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_stopped_playing - not connected")}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)}),this.audioPlayer.on("transcriptDisplay",function(e){t.emit("transcriptDisplay",{text:e.text,role:"assistant",final:!0,timestamp:Date.now()})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e),t.emit("error",e)})}},{key:"setupAudioRecorderEvents",value:function(){var t=this;this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0;var e=t.audioPlayer.getStatus(),n=e.scheduledBuffers&&e.scheduledBuffers>0||e.scheduledSourcesCount&&e.scheduledSourcesCount>0,o=t.isPlaying||e.isPlaying||n;console.log("🎤 VoiceSDK v2: Recording started - checking for barge-in..."),console.log(" VoiceSDK.isPlaying:",t.isPlaying),console.log(" AudioPlayer.isPlaying:",e.isPlaying),console.log(" scheduledBuffers:",e.scheduledBuffers||0),console.log(" scheduledSourcesCount:",e.scheduledSourcesCount||0),console.log(" preparedBufferLength:",e.preparedBufferLength||0),console.log(" isActuallyPlaying:",o),o?(console.log("🛑 VoiceSDK v2: Barge-in detected! Stopping audio playback..."),t.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),t.isConnected?(t.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")):console.warn("⚠️ VoiceSDK v2: Cannot send barge_in - not connected")):console.log("ℹ️ VoiceSDK v2: No audio playing, normal recording start"),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t._bargeInChecked=!1,t.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped")}),this.audioRecorder.on("audioData",function(e){if(!t._bargeInChecked&&t.isRecording){t._bargeInChecked=!0;var n=t.audioPlayer.getStatus(),o=n.scheduledBuffers&&n.scheduledBuffers>0||n.scheduledSourcesCount&&n.scheduledSourcesCount>0;(t.isPlaying||n.isPlaying||o)&&(console.log("🛑 VoiceSDK v2: Barge-in detected on first audio data! Stopping audio playback..."),console.log(" VoiceSDK.isPlaying:",t.isPlaying),console.log(" AudioPlayer.isPlaying:",n.isPlaying),console.log(" scheduledBuffers:",n.scheduledBuffers||0),console.log(" scheduledSourcesCount:",n.scheduledSourcesCount||0),t.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),t.isConnected&&(t.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")))}t.isConnected&&t.sendBinary(e)}),this.audioRecorder.on("error",function(e){console.error("❌ AudioRecorder error:",e),t.emit("error",e)})}},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),e.toString()){var n=t.includes("?")?"&":"?";return"".concat(t).concat(n).concat(e.toString())}return t}},{key:"connect",value:(u=He(ze().m(function t(){var e,n,o=this;return ze().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK v2: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:if(!this.isConnected){t.n=2;break}return console.warn("VoiceSDK v2: Already connected"),t.a(2,!0);case 2:return t.p=2,e=this.buildWebSocketUrl(),console.log("🔌 VoiceSDK v2: Connecting to",e),t.n=3,new Promise(function(t,n){o.websocket=new WebSocket(e),o.websocket.onopen=function(){console.log("✅ VoiceSDK v2: WebSocket connected"),o.isConnected=!0,o.hasEverConnected=!0,o.sendHelloMessage(),o.emit("connected"),t(!0)},o.websocket.onerror=function(t){console.error("❌ VoiceSDK v2: WebSocket error:",t),n(t)},o.websocket.onclose=function(t){console.log("🔌 VoiceSDK v2: WebSocket closed:",t.code,t.reason),o.isConnected=!1,o.isRecording&&o.stopRecording().catch(function(t){return console.error("Error stopping recording:",t)}),o.emit("disconnected",t),o.config.autoReconnect&&!o.isDestroyed&&o.hasEverConnected?(console.log("🔄 VoiceSDK v2: Auto-reconnecting in 3s..."),setTimeout(function(){o.isDestroyed||o.isConnected||o.connect()},3e3)):o.config.autoReconnect&&!o.hasEverConnected&&console.log("⚠️ VoiceSDK v2: Initial connection failed. Auto-reconnect disabled to prevent retry loop.")},o.websocket.onmessage=function(t){o.handleMessage(t)}});case 3:return t.a(2,t.v);case 4:return t.p=4,n=t.v,console.error("🔌 VoiceSDK v2: Connection failed:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[2,4]])})),function(){return u.apply(this,arguments)})},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},e={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},n=this.validateInputFormat(t);if(n)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid input format:",n),void this.emit("error",new Error("Invalid input format: ".concat(n)));var o=this.validateOutputFormat(e);if(o)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid output format:",o),void this.emit("error",new Error("Invalid output format: ".concat(o)));var r={t:"hello",v:this.config.protocolVersion,inputFormat:t,requestedOutputFormat:e,outputFrameDurationMs:this.config.outputFrameDurationMs};this.config.agentSettingsOverride&&(r.agentSettingsOverride=this.config.agentSettingsOverride),console.log("🔍 VoiceSDK v2: Checking variables:",{hasVariables:!!this.config.variables,variables:this.config.variables,keys:this.config.variables?Object.keys(this.config.variables):[]}),this.config.variables&&Object.keys(this.config.variables).length>0?(r.variables=this.config.variables,console.log("📝 VoiceSDK v2: Including variables in hello:",Object.keys(this.config.variables))):console.log("⚠️ VoiceSDK v2: Variables NOT included - condition failed"),console.log("📤 VoiceSDK v2: Sending hello:",{version:r.v,requestedFormat:r.requestedOutputFormat,variables:r.variables?Object.keys(r.variables):void 0}),console.log("📤 VoiceSDK v2: Requested output format:",{container:r.requestedOutputFormat.container,encoding:r.requestedOutputFormat.encoding,sampleRate:r.requestedOutputFormat.sampleRate,bitDepth:r.requestedOutputFormat.bitDepth}),console.log("📤 VoiceSDK v2: Full hello message being sent:",JSON.stringify(r,null,2));try{this.sendMessage(r)}catch(t){console.error("VoiceSDK v2: Failed to send hello:",t),this.emit("error",t)}}else console.warn("VoiceSDK v2: Cannot send hello - not connected")}},{key:"handleMessage",value:function(t){if(t.data instanceof ArrayBuffer||t.data instanceof Blob)this.handleBinaryMessage(t.data);else try{var e=JSON.parse(t.data);switch(console.log("📥 VoiceSDK v2: Received message:",e.t),!this.conversationId&&e.conversationId&&(this.conversationId=e.conversationId,console.log("🔍 VoiceSDK v2: Captured conversationId from message:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),e.t){case"hello_ack":this.handleHelloAck(e);break;case"pong":this.handlePong(e);break;case"audio_start":this.handleAudioStart(e);break;case"transcript":this.handleTranscript(e);break;case"user_transcript":case"agent_response":case"error":this.emit("message",e);break;case"barge_in":this.emit("bargeIn",e),this.stopAudioPlayback();break;case"stop_playing":this.emit("stopPlaying",e),this.stopAudioPlayback();break;default:console.log("VoiceSDK v2: Unknown message type:",e.t),this.emit("message",e)}}catch(t){console.error("VoiceSDK v2: Error parsing message:",t)}}},{key:"handleAudioStart",value:function(t){var e=t.text||"";console.log('▶️ VoiceSDK v2: audio_start "'.concat(e.substring(0,40),'..."')),this.emit("transcript",{text:e,role:"assistant",final:!0,timestamp:Date.now()}),this.audioPlayer.markNewSentence(e)}},{key:"handleHelloAck",value:function(t){if(console.log("📥 VoiceSDK v2: Received hello_ack:",{hasOutputFormat:!!t.outputAudioFormat,outputFormat:t.outputAudioFormat,hasConversationId:!!t.conversationId,messageType:t.t}),t.conversationId&&(this.conversationId=t.conversationId,console.log("🔍 VoiceSDK v2: Received conversationId:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),t.outputAudioFormat){this.outputAudioFormat=t.outputAudioFormat,this.audioPlayer.setOutputFormat(t.outputAudioFormat),console.log("✅ VoiceSDK v2: Format negotiated by server:",this.outputAudioFormat),this.requestedOutputFormat={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1};var e={container:this.outputAudioFormat.container||"unknown",encoding:this.outputAudioFormat.encoding||"unknown",sampleRate:this.outputAudioFormat.sampleRate||0,bitDepth:this.outputAudioFormat.bitDepth||0,channels:this.outputAudioFormat.channels||0},n=[];if(this.requestedOutputFormat.container!==e.container&&n.push('container: "'.concat(this.requestedOutputFormat.container,'" → "').concat(e.container,'"')),this.requestedOutputFormat.encoding!==e.encoding&&n.push('encoding: "'.concat(this.requestedOutputFormat.encoding,'" → "').concat(e.encoding,'"')),this.requestedOutputFormat.sampleRate!==e.sampleRate&&n.push("sampleRate: ".concat(this.requestedOutputFormat.sampleRate,"Hz → ").concat(e.sampleRate,"Hz")),this.requestedOutputFormat.bitDepth!==e.bitDepth&&n.push("bitDepth: ".concat(this.requestedOutputFormat.bitDepth,"-bit → ").concat(e.bitDepth,"-bit")),this.requestedOutputFormat.channels!==e.channels&&n.push("channels: ".concat(this.requestedOutputFormat.channels," → ").concat(e.channels)),n.length>0){console.warn("⚠️ VoiceSDK v2: Format negotiation mismatch!"),console.warn(" Requested:",this.requestedOutputFormat),console.warn(" Negotiated:",e),console.warn(" Differences:",n.join(", "));try{if(this.formatConverter=new _e(this.requestedOutputFormat,e),this.formatConverter.needsConversion()){var o=this.formatConverter.getConversionSteps();console.log("🔄 VoiceSDK v2: Format conversion enabled"),console.log(" Conversion steps:",o.join(", ")),console.log(" Audio will be automatically converted to requested format")}}catch(t){console.error("❌ VoiceSDK v2: Failed to create format converter:",t),console.warn(" Will use backend format without conversion"),this.formatConverter=null}}else console.log("✅ VoiceSDK v2: Format perfectly matched!",e),this.formatConverter=null;this.emit("formatNegotiated",this.outputAudioFormat)}else{this.config.protocolVersion>=2?(console.warn("⚠️ VoiceSDK v2: hello_ack received but no outputAudioFormat in response."),console.warn(" This may happen if:"),console.warn(" 1. Backend is not sending outputAudioFormat (check backend logs)"),console.warn(" 2. Hello message missing v2 fields (v, inputFormat, requestedOutputFormat)"),console.warn(" 3. Backend validation failed (check backend error logs)"),console.warn(" Using default format from config...")):console.log("✅ VoiceSDK v2: Connected (v1 legacy mode)");var r={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,channels:this.config.outputChannels||1,bitDepth:this.config.outputBitDepth||16};this.outputAudioFormat=r,this.requestedOutputFormat=r,this.audioPlayer.setOutputFormat(r),this.formatConverter=null}}},{key:"handleTranscript",value:function(t){var e={text:t.text||"",role:t.role||"assistant",sentenceId:t.sentenceId||null,final:!1!==t.final,timestamp:t.timestamp||Date.now()};e.text?(console.log("📝 VoiceSDK v2: [".concat(e.role,'] "').concat(e.text.substring(0,50),'..."')),this.emit("transcript",e)):console.warn("⚠️ VoiceSDK v2: Empty transcript received")}},{key:"handleBinaryMessage",value:(s=He(ze().m(function t(e){var n,o,r,i,a,c,s,u,l,d;return ze().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!(e instanceof Blob)){t.n=2;break}return t.n=1,e.arrayBuffer();case 1:o=t.v,t.n=3;break;case 2:o=e;case 3:if(console.log("📥 VoiceSDK v2: Received audio:",o.byteLength,"bytes"),console.log(" Current outputFormat:",this.outputAudioFormat),console.log(" AudioPlayer outputFormat:",null===(n=this.audioPlayer)||void 0===n?void 0:n.outputFormat),console.log(" Format converter:",this.formatConverter?"active":"none"),r=o,!this.formatConverter||!this.formatConverter.needsConversion()){t.n=7;break}return t.p=4,t.n=5,this.formatConverter.convert(o);case 5:r=t.v,console.log("✅ VoiceSDK v2: Audio converted to requested format"),t.n=7;break;case 6:t.p=6,d=t.v,console.error("❌ VoiceSDK v2: Format conversion failed:",d),console.warn(" Using backend format without conversion"),r=o;case 7:i=this.formatConverter&&this.formatConverter.needsConversion()?this.requestedOutputFormat:this.outputAudioFormat||{container:this.config.outputContainer||"raw",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1},a=i.container||"raw",c=(i.encoding||"pcm").toLowerCase(),"raw"===a?(s=r,"pcm"!==c&&((u=this.audioPlayer.getCodec(c))?(l=u.decode(new Uint8Array(r)),s=l.buffer,console.log("🔄 VoiceSDK v2: Decoded ".concat(c.toUpperCase()," to PCM (").concat(l.byteLength," bytes)"))):console.warn("⚠️ VoiceSDK v2: No codec for ".concat(c,", treating as PCM"))),this.audioPlayer.outputFormat||(console.warn("⚠️ VoiceSDK v2: outputFormat not set on AudioPlayer, setting from playbackFormat"),this.audioPlayer.setOutputFormat(i)),this.audioPlayer.playChunk(s)):this.audioPlayer.playAudio(r);case 8:return t.a(2)}},t,this,[[4,6]])})),function(t){return s.apply(this,arguments)})},{key:"sendMessage",value:function(t){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send message - not connected"),!1;try{return this.websocket.send(JSON.stringify(t)),!0}catch(t){return console.error("VoiceSDK v2: Error sending message:",t),this.emit("error",t),!1}}},{key:"sendBinary",value:function(t){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send audio - not connected"),!1;try{return this.websocket.send(t),!0}catch(t){return console.error("VoiceSDK v2: Error sending audio:",t),this.emit("error",t),!1}}},{key:"disconnect",value:function(){this.isDestroyed||(console.log("🔌 VoiceSDK v2: Disconnecting..."),this.stopRecording(),this.audioPlayer&&this.stopAudioPlayback(),this.websocket&&(this.websocket.close(),this.websocket=null),this.isConnected=!1)}},{key:"startRecording",value:(c=He(ze().m(function t(){var e,n;return ze().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw e=new Error("Not connected to voice server"),this.emit("error",e),e;case 1:if(!this.isRecording){t.n=2;break}return console.warn("VoiceSDK v2: Already recording"),t.a(2,!0);case 2:return console.log("🎤 VoiceSDK v2: Starting recording..."),t.p=3,console.log("🎤 VoiceSDK v2: Requesting microphone permission (mobile-friendly)..."),t.n=4,this.audioRecorder.start();case 4:return this.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId()}),t.a(2,!0);case 5:return t.p=5,n=t.v,console.error("❌ VoiceSDK v2: Failed to start recording:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[3,5]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=He(ze().m(function t(){var e;return ze().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return console.warn("VoiceSDK v2: Not recording"),t.a(2,!0);case 1:return console.log("🛑 VoiceSDK v2: Stopping recording..."),t.p=2,this.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=3,this.audioRecorder.stop();case 3:return this.stopAudioPlayback(),t.a(2,!0);case 4:return t.p=4,e=t.v,console.error("VoiceSDK v2: Error stopping recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[2,4]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=He(ze().m(function t(){return ze().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"clearTranscriptState",value:function(){this.audioPlayer&&this.audioPlayer.clearTranscriptState(),console.log("📝 VoiceSDK v2: Transcript state cleared")}},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate(),this.clearTranscriptState()}},{key:"handleBargeIn",value:(r=He(ze().m(function t(){return ze().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{version:this.version,isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying,outputFormat:this.outputAudioFormat,conversationId:this.conversationId,audioPlayer:this.audioPlayer.getStatus(),audioRecorder:this.audioRecorder.getStatus()}}},{key:"updateConfig",value:function(t){this.config=Ne(Ne({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"destroy",value:function(){this.isDestroyed||(console.log("🗑️ VoiceSDK v2: Destroying..."),this.disconnect(),this.isDestroyed=!0,this.audioPlayer&&this.audioPlayer.destroy(),this.audioRecorder&&this.audioRecorder.destroy(),this.removeAllListeners())}}],o&&Ke(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(mt);Qe(Ye,"SUPPORTED_INPUT_ENCODINGS",["pcm","pcmu","pcma"]),Qe(Ye,"SUPPORTED_INPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),Qe(Ye,"SUPPORTED_INPUT_BIT_DEPTHS",[8,16,24]),Qe(Ye,"SUPPORTED_INPUT_CHANNELS",[1]),Qe(Ye,"SUPPORTED_OUTPUT_ENCODINGS",["pcm","pcmu","pcma"]),Qe(Ye,"SUPPORTED_OUTPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),Qe(Ye,"SUPPORTED_OUTPUT_BIT_DEPTHS",[8,16,24]),Qe(Ye,"SUPPORTED_OUTPUT_CHANNELS",[1]),Qe(Ye,"SUPPORTED_OUTPUT_CONTAINERS",["raw","wav"]);const $e=Ye;function Xe(t){return Xe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Xe(t)}function Ze(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return tn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(tn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,tn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,tn(d,"constructor",u),tn(u,"constructor",s),s.displayName="GeneratorFunction",tn(u,r,"GeneratorFunction"),tn(d),tn(d,r,"Generator"),tn(d,o,function(){return this}),tn(d,"toString",function(){return"[object Generator]"}),(Ze=function(){return{w:i,m:f}})()}function tn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}tn=function(t,e,n,o){function i(e,n){tn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},tn(t,e,n,o)}function en(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function nn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function on(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?nn(Object(n),!0).forEach(function(e){rn(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):nn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function rn(t,e,n){return(e=cn(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function an(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,cn(o.key),o)}}function cn(t){var e=function(t){if("object"!=Xe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Xe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Xe(e)?e:e+""}function sn(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(sn=function(){return!!t})()}function un(t){return un=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},un(t)}function ln(t,e){return ln=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ln(t,e)}var dn=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=(t=function(t,e,n){return e=un(e),function(t,e){if(e&&("object"==Xe(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,sn()?Reflect.construct(e,n||[],un(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=on({baseWsUrl:"wss://backend.talktopc.com/chat/websocket",appId:n.appId||o.appId,agentId:n.agentId||o.agentId,conversationId:void 0!==n.conversationId?n.conversationId:t.getPersistedConversationId(),forceConversationId:n.forceConversationId,queue:[],inFlight:!1},n),t.fullResponseBuffer="",t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ln(t,e)}(e,t),n=e,o=[{key:"readScriptTagConfig",value:function(){try{var t=Array.from(document.getElementsByTagName("script")).reverse().find(function(t){return t.dataset&&(t.dataset.appId||t.dataset.agentId)||t.src&&t.src.includes("agent-widget")});return t?{appId:t.dataset.appId,agentId:t.dataset.agentId}:{}}catch(t){return{}}}},{key:"buildWebSocketUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,e=new URLSearchParams;return this.config.appId&&e.append("appId",this.config.appId),this.config.agentId&&e.append("agentId",this.config.agentId),this.config.conversationId&&e.append("conversationId",this.config.conversationId),"".concat(t,"?").concat(e.toString())}},{key:"sendMessage",value:(r=Ze().m(function t(e){var n=this;return Ze().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,o){if(e&&e.trim())if(n.config.appId&&n.config.agentId){var r={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(r):n.executeTask(r)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){en(i,n,o,a,c,"next",t)}function c(t){en(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"executeTask",value:function(t){var e=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,r=this.buildWebSocketUrl(this.config.baseWsUrl),i=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(i),c=!1,s=!1,u=null,l=function(n){if(!s)try{var o={message:t.text},r=e.config.forceConversationId||e.config.conversationId;r&&(o.conversationId=r,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=r,e.persistConversationId(r))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",e.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){t.reject(o),e.emit("error",o);try{n.close()}catch(t){}}},d=function(t){return function(){e.config.conversationId?l(t):u=setTimeout(function(){return l(t)},200)}},f=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(t){}var r=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",r)}catch(t){}if("hello"===r.type&&r.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId),e.emit&&e.emit("conversationIdChanged",r.conversationId),!s&&n&&1===n.readyState){if(u)try{clearTimeout(u)}catch(t){}l(n)}return}if(!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId)),"chunk"===r.type&&"string"==typeof r.content)e.fullResponseBuffer+=r.content,e.emit("chunk",r.content);else if("done"===r.type){try{var i=r.text||r.content||r.answer||r.message||"";i&&!e.fullResponseBuffer&&(e.fullResponseBuffer=i)}catch(t){}!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",r.conversationId),e.config.conversationId=r.conversationId),e.persistConversationId(e.config.conversationId),e.emit("done",{text:e.fullResponseBuffer}),t.resolve({conversationId:e.config.conversationId,fullText:e.fullResponseBuffer});try{n.close()}catch(t){}}else if("error"===r.type){var a=new Error(r.message||"Server error");e.emit("error",a),t.reject(a);try{n.close()}catch(t){}}}catch(t){}}},p=function(n){if(1008===n.code&&n.reason&&(n.reason.includes("Domain not whitelisted")||n.reason.includes("domain")||n.reason.includes("whitelist"))){var o=new Error("DOMAIN_NOT_WHITELISTED");return o.reason=n.reason,o.code=n.code,e.emit("domainError",o),t.reject(o),e.config.inFlight=!1,void e.drainQueue()}e.config.inFlight=!1,e.drainQueue()},h=new WebSocket(r);h.onopen=d(h),h.onmessage=f(h),h.onerror=(o=h,function(n){if(!c){c=!0;try{o.close()}catch(t){}var r=new WebSocket(a);return r.onopen=d(r),r.onmessage=f(r),r.onerror=function(n){e.emit("error",n),t.reject(n)},void(r.onclose=p)}e.emit("error",n),t.reject(n)}),h.onclose=p}},{key:"drainQueue",value:function(){if(0!==this.config.queue.length&&!this.config.inFlight){var t=this.config.queue.shift();this.executeTask(t)}}},{key:"persistConversationId",value:function(t){try{t&&localStorage.setItem("ttp_text_chat_conversation_id",t)}catch(t){}}},{key:"getPersistedConversationId",value:function(){try{return localStorage.getItem("ttp_text_chat_conversation_id")||null}catch(t){return null}}},{key:"updateConfig",value:function(t){this.config=on(on({},this.config),t)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&an(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c),fn=n(540),pn=n(848);function hn(t){return hn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},hn(t)}function vn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function gn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?vn(Object(n),!0).forEach(function(e){yn(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):vn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function yn(t,e,n){return(e=function(t){var e=function(t){if("object"!=hn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=hn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==hn(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function mn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return bn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(bn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,bn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,bn(d,"constructor",u),bn(u,"constructor",s),s.displayName="GeneratorFunction",bn(u,r,"GeneratorFunction"),bn(d),bn(d,r,"Generator"),bn(d,o,function(){return this}),bn(d,"toString",function(){return"[object Generator]"}),(mn=function(){return{w:i,m:f}})()}function bn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}bn=function(t,e,n,o){function i(e,n){bn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},bn(t,e,n,o)}function wn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Sn(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return xn(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?xn(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function xn(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}const kn=function(t){var e=t.websocketUrl,n=t.agentId,o=t.appId,r=t.voice,i=void 0===r?"default":r,a=t.language,c=void 0===a?"en":a,s=t.autoReconnect,u=void 0===s||s,l=t.agentSettingsOverride,d=void 0===l?null:l,f=t.onConnected,p=t.onDisconnected,h=t.onRecordingStarted,v=t.onRecordingStopped,g=t.onPlaybackStarted,y=t.onPlaybackStopped,m=t.onError,b=t.onMessage,w=t.onBargeIn,S=t.onStopPlaying,x=t.className,k=void 0===x?"":x,C=t.style,P=void 0===C?{}:C,O=t.children,T=Sn((0,fn.useState)(!1),2),E=T[0],j=T[1],I=Sn((0,fn.useState)(!1),2),F=I[0],A=I[1],B=Sn((0,fn.useState)(!1),2),D=(B[0],B[1]),R=Sn((0,fn.useState)("Disconnected"),2),_=(R[0],R[1]),U=(0,fn.useRef)(null);(0,fn.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),U.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),U.current.destroy(),U.current=null);var t=new pt({websocketUrl:e,agentId:n,appId:o,voice:i,language:c,autoReconnect:u,agentSettingsOverride:d});return t.on("connected",function(){j(!0),_("Connected"),null==f||f()}),t.on("disconnected",function(){j(!1),_("Disconnected"),null==p||p()}),t.on("recordingStarted",function(){A(!0),null==h||h()}),t.on("recordingStopped",function(){A(!1),null==v||v()}),t.on("playbackStarted",function(){D(!0),null==g||g()}),t.on("playbackStopped",function(){D(!1),null==y||y()}),t.on("error",function(t){null==m||m(t)}),t.on("message",function(t){null==b||b(t)}),t.on("bargeIn",function(t){null==w||w(t)}),t.on("stopPlaying",function(t){null==S||S(t)}),U.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),U.current&&(U.current.destroy(),U.current=null)}},[e,n,o,i,c,d]);var M=function(){var t,e=(t=mn().m(function t(){var e;return mn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(U.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,U.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){wn(i,o,r,a,c,"next",t)}function c(t){wn(i,o,r,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),N=(0,pn.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,pn.jsx)("div",{style:{fontSize:"20px"},children:F?"🔴":"🎤"}),(0,pn.jsx)("div",{children:F?"Stop Listening":"Start Listening"})]});return(0,pn.jsx)("button",{className:"voice-button ".concat(F?"recording":""," ").concat(k),style:gn({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:F?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},P),onClick:M,disabled:!E,children:O||N})};function Cn(t){return Cn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Cn(t)}function Pn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return On(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(On(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,On(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,On(d,"constructor",u),On(u,"constructor",s),s.displayName="GeneratorFunction",On(u,r,"GeneratorFunction"),On(d),On(d,r,"Generator"),On(d,o,function(){return this}),On(d,"toString",function(){return"[object Generator]"}),(Pn=function(){return{w:i,m:f}})()}function On(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}On=function(t,e,n,o){function i(e,n){On(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},On(t,e,n,o)}function Tn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function En(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Tn(i,o,r,a,c,"next",t)}function c(t){Tn(i,o,r,a,c,"throw",t)}a(void 0)})}}function jn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function In(t,e,n){return(e=An(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Fn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,An(o.key),o)}}function An(t){var e=function(t){if("object"!=Cn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Cn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Cn(e)?e:e+""}var Bn=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?jn(Object(n),!0).forEach(function(e){In(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):jn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({websocketUrl:e.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:e.agentId,voice:e.voice||"default",language:e.language||"en",container:e.container||document.body,buttonText:e.buttonText||"Start Listening",buttonClass:e.buttonClass||"voice-button"},e),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new pt({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},e=[{key:"setupEventListeners",value:function(){var t=this;this.voiceSDK.on("connected",function(){var e,n;t.isConnected=!0,t.updateButton(),null===(e=(n=t.options).onConnected)||void 0===e||e.call(n)}),this.voiceSDK.on("disconnected",function(){var e,n;t.isConnected=!1,t.updateButton(),null===(e=(n=t.options).onDisconnected)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStarted",function(){var e,n;t.isRecording=!0,t.updateButton(),null===(e=(n=t.options).onRecordingStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStopped",function(){var e,n;t.isRecording=!1,t.updateButton(),null===(e=(n=t.options).onRecordingStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStarted",function(){var e,n;t.isPlaying=!0,null===(e=(n=t.options).onPlaybackStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStopped",function(){var e,n;t.isPlaying=!1,null===(e=(n=t.options).onPlaybackStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("error",function(e){var n,o;null===(n=(o=t.options).onError)||void 0===n||n.call(o,e)}),this.voiceSDK.on("message",function(e){var n,o;null===(n=(o=t.options).onMessage)||void 0===n||n.call(o,e)}),this.voiceSDK.on("bargeIn",function(e){var n,o;null===(n=(o=t.options).onBargeIn)||void 0===n||n.call(o,e)}),this.voiceSDK.on("stopPlaying",function(e){var n,o;null===(n=(o=t.options).onStopPlaying)||void 0===n||n.call(o,e)})}},{key:"createButton",value:function(){var t=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return t.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var t=this.isRecording?"🔴":"🎤",e=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(t,"</span>\n <span>").concat(e,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=En(Pn().m(function t(){var e;return Pn().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.voiceSDK.connect();case 1:t.n=3;break;case 2:t.p=2,e=t.v,console.error("Failed to connect:",e);case 3:return t.a(2)}},t,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=En(Pn().m(function t(){var e;return Pn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.voiceSDK){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,this.voiceSDK.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.voiceSDK.updateConfig(t)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],e&&Fn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Dn(t){return Dn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Dn(t)}function Rn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return _n(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(_n(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,_n(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,_n(d,"constructor",u),_n(u,"constructor",s),s.displayName="GeneratorFunction",_n(u,r,"GeneratorFunction"),_n(d),_n(d,r,"Generator"),_n(d,o,function(){return this}),_n(d,"toString",function(){return"[object Generator]"}),(Rn=function(){return{w:i,m:f}})()}function _n(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}_n=function(t,e,n,o){function i(e,n){_n(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},_n(t,e,n,o)}function Un(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Mn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Un(i,o,r,a,c,"next",t)}function c(t){Un(i,o,r,a,c,"throw",t)}a(void 0)})}}function Nn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,zn(o.key),o)}}function zn(t){var e=function(t){if("object"!=Dn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Dn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Dn(e)?e:e+""}var Ln=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),console.log("🚀 AgentSDK v2.1.8 initialized with config:",e),this.config=e,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(t){return console.error("SDK Error:",t)},this.onTranscript=function(t){},this.onAgentSpeaking=function(t){}},e=[{key:"connect",value:(o=Mn(Rn().m(function t(e){var n,o=this;return Rn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,e){t.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new $e({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en",protocolVersion:2,outputContainer:this.config.outputContainer||"raw",outputEncoding:this.config.outputEncoding||"pcm",outputSampleRate:this.config.outputSampleRate||44100,outputChannels:this.config.outputChannels||1,outputBitDepth:this.config.outputBitDepth||16}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(t){if(o.isConnected=!1,t&&1008===t.code&&t.reason&&(t.reason.includes("Domain not whitelisted")||t.reason.includes("domain")||t.reason.includes("whitelist"))){var e=new Error("DOMAIN_NOT_WHITELISTED");e.reason=t.reason,e.code=t.code,o.onError(e)}o.onDisconnected()}),this.voiceSDK.on("domainError",function(t){o.onError(t)}),this.voiceSDK.on("error",function(t){o.onError(t)}),this.voiceSDK.on("message",function(t){o.handleWebSocketMessage(t)}),this.voiceSDK.on("recordingStarted",function(){o.isListening=!0}),this.voiceSDK.on("recordingStopped",function(){o.isListening=!1}),this.voiceSDK.on("playbackStarted",function(){o.onAgentSpeaking(!0)}),this.voiceSDK.on("playbackStopped",function(){o.onAgentSpeaking(!1)}),this.voiceSDK.on("transcriptDisplay",function(t){t&&t.text&&o.onTranscript(t.text)}),t.n=2,this.voiceSDK.connect();case 2:t.n=4;break;case 3:throw t.p=3,n=t.v,this.onError(n),n;case 4:return t.a(2)}},t,this,[[0,3]])})),function(t){return o.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(t){switch(t.t||t.type){case"connected":case"hello_ack":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text||t.transcript);break;case"agent_response":case"barge_in":case"stop_playing":default:break;case"error":this.onError(new Error(t.message||t.error||"Unknown error"))}}},{key:"startListening",value:(n=Mn(Rn().m(function t(){var e;return Rn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){t.n=5;break}return t.p=1,console.log("🎤 AgentSDK: Starting recording..."),t.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),t.n=4;break;case 3:throw t.p=3,e=t.v,console.error("❌ AgentSDK: Failed to start recording:",e),e;case 4:t.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(t){this.voiceSDK&&this.isConnected&&this.voiceSDK.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],e&&Nn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Vn(t){return Vn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Vn(t)}function Hn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Kn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Kn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Kn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Kn(d,"constructor",u),Kn(u,"constructor",s),s.displayName="GeneratorFunction",Kn(u,r,"GeneratorFunction"),Kn(d),Kn(d,r,"Generator"),Kn(d,o,function(){return this}),Kn(d,"toString",function(){return"[object Generator]"}),(Hn=function(){return{w:i,m:f}})()}function Kn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Kn=function(t,e,n,o){function i(e,n){Kn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Kn(t,e,n,o)}function Wn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Gn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Wn(i,o,r,a,c,"next",t)}function c(t){Wn(i,o,r,a,c,"throw",t)}a(void 0)})}}function qn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Qn(o.key),o)}}function Qn(t){var e=function(t){if("object"!=Vn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Vn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Vn(e)?e:e+""}var Jn=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.audioStream=null,this.callStartTime=null,this.callTimerInterval=null,this.sdk=null,this.isActive=!1,this.sdk=new Ln({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,variables:e.variables||{},language:e.language||"en",outputContainer:e.outputContainer,outputEncoding:e.outputEncoding,outputSampleRate:e.outputSampleRate,outputChannels:e.outputChannels,outputBitDepth:e.outputBitDepth}),this.setupSDKEventHandlers()},e=[{key:"setupSDKEventHandlers",value:function(){var t=this;this.sdk.onTranscript=function(e){t.updateTranscript(e)},this.sdk.onAgentSpeaking=function(t){var e=document.getElementById("voiceAvatarActive");e&&(t?e.classList.add("speaking"):e.classList.remove("speaking"))},this.sdk.onDisconnected=function(){console.log("🔌 WebSocket disconnected, hanging up call..."),t.isActive&&(t.isActive=!1,t.endVoiceCall())},this.sdk.onError=function(e){console.error("❌ Voice SDK Error:",e),e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))?t.showDomainError():t.showError(e.message||e)}}},{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"getTooltip",value:function(t){var e,n=null===(e=this.config.tooltips)||void 0===e?void 0:e[t];return null!=n?n:{mute:this.t("mute"),speaker:this.t("speaker"),endCall:this.t("endCall")}[t]||""}},{key:"generateHTML",value:function(){return'<div class="voice-interface" id="voiceInterface">\n \x3c!-- Before Call State --\x3e\n <div id="voiceIdleState">\n <div class="voice-avatar" id="voiceAvatar">🤖</div>\n <div class="voice-status">\n <div class="voice-status-title">'.concat(this.t("clickToStartCall"),'</div>\n <div class="voice-status-subtitle">').concat(this.t("realTimeVoice"),'</div>\n </div>\n <button class="start-call-btn" id="startCallBtn">\n <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">\n <path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56-.35-.12-.74-.03-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"/>\n </svg>\n <span>').concat(this.t("startCall"),'</span>\n </button>\n </div>\n \x3c!-- During Call State --\x3e\n <div id="voiceActiveState" style="display: none;">\n <div class="voice-avatar-active" id="voiceAvatarActive">\n <div class="voice-rings">\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n </div>\n 🤖\n </div>\n <div class="voice-status">\n <div class="voice-status-title" id="voiceStatusTitleActive">').concat(this.t("listening"),'</div>\n <div class="voice-status-subtitle" id="voiceStatusSubtitleActive">').concat(this.t("speakFreely"),'</div>\n </div>\n <div class="voice-transcript">\n <div class="transcript-label">').concat(this.t("liveTranscript"),'</div>\n <div class="transcript-text empty" id="transcriptText">\n ').concat(this.t("transcriptWillAppear"),'\n </div>\n </div>\n <div class="voice-controls">\n <button class="voice-control-btn secondary" id="muteBtn" title="').concat(this.getTooltip("mute"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="mute-icon">\n <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>\n <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>\n <line x1="12" y1="19" x2="12" y2="23"/>\n <line x1="8" y1="23" x2="16" y2="23"/>\n <line x1="2" y1="2" x2="22" y2="22" class="mute-cross" style="display: none; stroke: #ef4444; stroke-width: 3.5;"/>\n </svg>\n </button>\n <button class="voice-control-btn primary active" id="endCallBtn" title="').concat(this.getTooltip("endCall"),'">\n <svg width="56" height="56" viewBox="0 0 24 24" fill="#ef4444">\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n </svg>\n <div class="voice-timer" id="voiceTimer">00:00</div>\n </button>\n <button class="voice-control-btn secondary" id="speakerBtn" title="').concat(this.getTooltip("speaker"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">\n <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/>\n <path d="M19.07 4.93a10 10 0 0 1 0 14.14"/>\n <path d="M15.54 8.46a5 5 0 0 1 0 7.07"/>\n </svg>\n </button>\n </div>\n </div>\n </div>')}},{key:"generateCSS",value:function(){var t=this.config.avatarBackgroundColor||"#667eea",e=this.config.avatarActiveBackgroundColor||this.config.avatarBackgroundColor||"#667eea",n=this.config.statusTitleColor||"#1e293b",o=this.config.statusSubtitleColor||"#64748b",r=this.config.startCallButtonColor||"#667eea",i=this.config.startCallButtonTextColor||"#FFFFFF",a=this.config.transcriptBackgroundColor||"#FFFFFF",c=this.config.transcriptTextColor||"#1e293b",s=this.config.transcriptLabelColor||"#94a3b8",u=this.config.controlButtonColor||"#FFFFFF",l=this.config.controlButtonSecondaryColor||"#64748b";return this.config.endCallButtonColor,'\n /* Voice Interface Styles - Ultra-compact for Wix iframes */\n .voice-interface { \n display: none; \n flex: 1; \n flex-direction: column;\n align-items: center; \n justify-content: center; \n padding: 6px 10px 6px 10px; \n background: linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%);\n overflow: hidden;\n min-height: 0;\n height: 100%;\n width: 100%;\n box-sizing: border-box;\n }\n .voice-interface.active { display: flex; }\n \n /* Voice States - Better scaling gaps */\n #voiceIdleState,\n #voiceActiveState {\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n height: 100%;\n min-height: 0;\n justify-content: center;\n overflow: hidden;\n flex: 1;\n box-sizing: border-box;\n gap: clamp(6px, 1.5vh, 12px);\n }\n \n #voiceActiveState[style*="display: none"] {\n display: none !important;\n }\n \n /* Voice Avatar - Scales better from small to large */\n .voice-avatar,\n .voice-avatar-active {\n width: clamp(80px, 18vh, 160px);\n height: clamp(80px, 18vh, 160px);\n aspect-ratio: 1;\n border-radius: 50%;\n background: linear-gradient(135deg, '.concat(t," 0%, ").concat(e," 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: clamp(40px, 9vh, 80px);\n margin: 0;\n box-shadow: 0 8px 30px rgba(102, 126, 234, 0.3);\n transition: all 0.3s ease;\n flex-shrink: 1;\n position: relative;\n }\n \n .voice-avatar-active {\n animation: avatarPulse 2s ease-in-out infinite;\n }\n \n @keyframes avatarPulse {\n 0%, 100% { \n transform: scale(1);\n }\n 50% { \n transform: scale(1.05);\n }\n }\n \n .voice-avatar-active.speaking {\n animation: avatarSpeak 0.5s ease-in-out infinite;\n }\n \n @keyframes avatarSpeak {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.08); }\n }\n \n /* Voice Rings Animation */\n .voice-rings {\n position: absolute;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n }\n \n .voice-ring {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n border: 2px solid rgba(102, 126, 234, 0.3);\n border-radius: 50%;\n opacity: 0;\n animation: ringExpand 2s ease-out infinite;\n }\n \n .voice-ring:nth-child(2) { animation-delay: 0.5s; }\n .voice-ring:nth-child(3) { animation-delay: 1s; }\n \n @keyframes ringExpand {\n 0% {\n width: 100%;\n height: 100%;\n opacity: 0.6;\n }\n 100% {\n width: 160%;\n height: 160%;\n opacity: 0;\n }\n }\n \n /* Voice Status - Scales with container */\n .voice-status {\n text-align: center;\n margin: 0;\n flex-shrink: 1;\n min-height: 0;\n }\n \n .voice-status-title {\n font-size: clamp(12px, 3vh, 20px);\n font-weight: 600;\n color: ").concat(n,";\n margin-bottom: clamp(2px, 0.5vh, 4px);\n line-height: 1.2;\n }\n \n .voice-status-subtitle {\n font-size: clamp(10px, 2vh, 14px);\n color: ").concat(o,";\n line-height: 1.2;\n }\n \n /* Start Call Button - Scales with container */\n .start-call-btn {\n margin: 0;\n width: min(280px, 70vw);\n height: clamp(48px, 8vh, 64px);\n border-radius: clamp(24px, 4vh, 32px);\n border: none;\n background: ").concat(r,";\n color: ").concat(i,";\n font-size: clamp(14px, 2.5vh, 18px);\n font-weight: 600;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: clamp(8px, 1.5vh, 12px);\n box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);\n transition: all 0.3s ease;\n flex-shrink: 0;\n }\n \n .start-call-btn svg {\n width: clamp(22px, 4vh, 32px);\n height: clamp(22px, 4vh, 32px);\n }\n \n .start-call-btn:hover {\n transform: translateY(-2px);\n box-shadow: 0 12px 28px rgba(102, 126, 234, 0.5);\n }\n \n .start-call-btn:active {\n transform: translateY(-1px);\n }\n \n /* Voice Transcript - Scales with container */\n .voice-transcript {\n background: ").concat(a,";\n padding: clamp(6px, 1.5vh, 12px);\n border-radius: 10px;\n width: min(360px, calc(100% - 40px));\n margin: 0;\n min-height: clamp(45px, 10vh, 80px);\n max-height: clamp(70px, 16vh, 110px);\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n flex-shrink: 1;\n overflow-y: auto;\n overflow-x: hidden;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n \n .transcript-label {\n font-size: clamp(8px, 1.4vh, 11px);\n color: ").concat(s,";\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.3px;\n margin-bottom: clamp(3px, 0.6vh, 6px);\n flex-shrink: 0;\n word-wrap: break-word;\n }\n \n .transcript-text {\n font-size: clamp(11px, 2vh, 15px);\n color: ").concat(c,";\n line-height: 1.4;\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n word-wrap: break-word;\n overflow-wrap: break-word;\n }\n \n .transcript-text.empty {\n color: #cbd5e1;\n font-style: italic;\n }\n \n /* Voice Controls - Scales with container */\n .voice-controls {\n display: flex;\n gap: clamp(8px, 1.8vh, 14px);\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n margin: 0;\n padding-top: clamp(5px, 1.2vh, 10px);\n }\n \n .voice-control-btn {\n width: clamp(48px, 9vh, 72px);\n height: clamp(48px, 9vh, 72px);\n aspect-ratio: 1;\n border-radius: 50%;\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n position: relative;\n flex-shrink: 0;\n }\n \n .voice-control-btn svg {\n width: 48%;\n height: 48%;\n }\n \n .voice-control-btn.primary {\n width: clamp(54px, 10vh, 80px);\n height: clamp(54px, 10vh, 80px);\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n box-shadow: 0 6px 18px rgba(102, 126, 234, 0.4);\n }\n \n .voice-control-btn.primary:hover {\n transform: scale(1.05);\n }\n \n .voice-control-btn.primary.active {\n background: white;\n animation: recordingPulse 1.5s ease-in-out infinite;\n }\n \n @keyframes recordingPulse {\n 0%, 100% { \n box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);\n }\n 50% { \n box-shadow: 0 6px 24px rgba(239, 68, 68, 0.7);\n }\n }\n \n .voice-control-btn.secondary {\n background: ").concat(u,";\n color: ").concat(l,";\n box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);\n }\n \n .voice-control-btn.secondary:hover {\n background: #f8fafc;\n transform: scale(1.05);\n }\n \n .voice-control-btn.secondary.muted {\n background: #f3f4f6;\n }\n \n .voice-control-btn.secondary.muted .mute-icon {\n stroke: #9ca3af !important;\n }\n \n .voice-timer {\n position: absolute;\n bottom: clamp(-18px, -3vh, -24px);\n font-size: clamp(9px, 1.6vh, 12px);\n color: #64748b;\n font-weight: 500;\n white-space: nowrap;\n }\n \n /* Mobile optimization */\n @media (max-width: 768px) {\n .voice-interface {\n padding: 6px 10px;\n }\n }\n \n @media (max-width: 480px) {\n .voice-interface {\n padding: 5px 8px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(t){var e=this,n=document.getElementById("startCallBtn"),o=document.getElementById("endCallBtn"),r=document.getElementById("muteBtn"),i=document.getElementById("speakerBtn");n&&(n.onclick=function(){return e.startVoiceCall()}),o&&(o.onclick=function(){return e.endVoiceCall()}),r&&(r.onclick=function(){return e.toggleMute()}),i&&(i.onclick=function(){return e.toggleSpeaker()});var a=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=document.getElementById("voiceInterface");n&&n.classList.contains("active")&&n.clientHeight>100?(console.log("✅ Interface is active and has proper dimensions, adjusting sizes (attempt",t+1,")"),e.adjustSizesForContainer(),0===t&&setTimeout(function(){return e.adjustSizesForContainer()},500)):t<15?(console.log("⏳ Interface not ready yet (height:",null==n?void 0:n.clientHeight,"), retrying... (attempt",t+1,")"),setTimeout(function(){return a(t+1)},250)):(console.warn("⚠️ Interface never became fully ready, adjusting sizes anyway"),e.adjustSizesForContainer())};setTimeout(function(){return a()},200),window.addEventListener("resize",function(){console.log("🔄 Window resized, re-adjusting sizes"),e.adjustSizesForContainer()})}},{key:"getSignedUrl",value:(o=Gn(Hn().m(function t(){var e,n,o,r,i,a,c;return Hn().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"adjustSizesForContainer",value:function(){var t=document.getElementById("voiceInterface");if(t){var e=t.clientHeight,n=t.clientWidth;console.log("📏 Container size:",e,"x",n);var o,r,i,a,c,s,u,l,d,f=document.getElementById("voiceIdleState"),p=document.getElementById("voiceActiveState"),h=f&&"none"!==f.style.display,v=p&&"none"!==p.style.display;console.log("👁️ Visible state - Idle:",h,"Active:",v),e<=350?(d=5,o=70,r=35,i=11,a=9,c=32,s=45,u=42,l=48):e<=450?(d=7,o=110,r=55,i=15,a=11,c=38,s=58,u=52,l=58):e<=550?(d=8,o=140,r=70,i=16,a=12,c=42,s=68,u=56,l=64):e<=700?(d=10,o=130,r=65,i=18,a=13,c=46,s=85,u=60,l=70):(d=12,o=150,r=75,i=20,a=14,c=50,s=100,u=66,l=76),document.querySelectorAll("#voiceIdleState, #voiceActiveState").forEach(function(t){t.style.gap="".concat(d,"px")});var g=document.querySelectorAll(".voice-avatar, .voice-avatar-active");console.log("🤖 Found",g.length,"avatars, setting size to",o,"px"),g.forEach(function(t){t.style.width="".concat(o,"px"),t.style.height="".concat(o,"px"),t.style.fontSize="".concat(r,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(t){return t.style.fontSize="".concat(i,"px")}),document.querySelectorAll(".voice-status-subtitle").forEach(function(t){return t.style.fontSize="".concat(a,"px")});var y=document.querySelector(".voice-transcript");y&&(y.style.minHeight="".concat(s,"px"),y.style.maxHeight="".concat(s,"px"),y.style.height="".concat(s,"px"),y.style.width="min(360px, ".concat(n-40,"px)"),y.style.boxSizing="border-box");var m=document.querySelector(".transcript-label");m&&(m.style.fontSize="".concat(Math.max(8,i-4),"px"));var b=document.querySelector(".transcript-text");b&&(b.style.fontSize="".concat(Math.max(10,i-2),"px")),document.querySelectorAll(".voice-control-btn.secondary").forEach(function(t){t.style.width="".concat(u,"px"),t.style.height="".concat(u,"px");var e=t.querySelector("svg");if(e){var n=.65*u;e.style.setProperty("width","".concat(n,"px"),"important"),e.style.setProperty("height","".concat(n,"px"),"important"),e.style.setProperty("min-width","".concat(n,"px"),"important"),e.style.setProperty("min-height","".concat(n,"px"),"important")}});var w=document.querySelector(".voice-control-btn.primary");if(w){w.style.width="".concat(l,"px"),w.style.height="".concat(l,"px");var S=w.querySelector("svg");if(S){var x=.7*l;S.style.setProperty("width","".concat(x,"px"),"important"),S.style.setProperty("height","".concat(x,"px"),"important"),S.style.setProperty("min-width","".concat(x,"px"),"important"),S.style.setProperty("min-height","".concat(x,"px"),"important")}}var k=document.querySelector(".start-call-btn");if(k){var C,P;e<=350?(C=48,P=14):e<=450?(C=52,P=15):e<=550?(C=58,P=17):e<=700?(C=62,P=18):(C=64,P=18),k.style.height="".concat(C,"px"),k.style.fontSize="".concat(P,"px");var O=k.querySelector("svg");if(O){var T=Math.max(22,.5*C);O.style.width="".concat(T,"px"),O.style.height="".concat(T,"px")}}console.log("✅ Sizes adjusted - Avatar:",o,"Status:",c,"Transcript:",s,"Buttons:",u)}else console.warn("⚠️ voiceInterface not found, skipping size adjustment")}},{key:"startVoiceCall",value:(n=Gn(Hn().m(function t(){var e,n,o,r,i,a,c,s,u,l=this;return Hn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isActive){t.n=1;break}return console.log("⚠️ Voice call already active"),t.a(2);case 1:return console.log("🎤 Starting voice call..."),t.p=2,e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState"),o=document.getElementById("voiceInterface"),e&&(e.style.display="none"),n&&(n.style.display="flex"),setTimeout(function(){return l.adjustSizesForContainer()},50),o&&(o.scrollTop=0),t.n=3,this.getSignedUrl();case 3:return r=t.v,console.log("🔗 Got signed URL:",r),t.n=4,this.sdk.connect(r);case 4:i=t.v,console.log("✅ Connected to WebSocket, connected:",i),a=0;case 5:if(this.sdk.isConnected||!(a<50)){t.n=7;break}return t.n=6,new Promise(function(t){return setTimeout(t,100)});case 6:a++,t.n=5;break;case 7:if(!this.sdk.isConnected){t.n=9;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=8,this.sdk.startListening();case 8:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-l.callStartTime,e=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(e.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3),t.n=11;break;case 9:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),t.n=10,this.sdk.startListening();case 10:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-l.callStartTime,e=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(e.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3);case 11:console.log("✅ Voice call started successfully"),t.n=13;break;case 12:t.p=12,u=t.v,console.error("❌ Error starting voice call:",u),this.showError(u.message||u),c=document.getElementById("voiceIdleState"),s=document.getElementById("voiceActiveState"),c&&(c.style.display="flex"),s&&(s.style.display="none");case 13:return t.a(2)}},t,this,[[2,12]])})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){var t=this;console.log("🔴 Ending voice call..."),this.sdk&&this.isActive&&(this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null);var e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState");e&&(e.style.display="flex"),n&&(n.style.display="none"),setTimeout(function(){return t.adjustSizesForContainer()},50);var o=document.getElementById("transcriptText");o&&(o.textContent=this.t("transcriptWillAppear"),o.classList.add("empty"));var r=document.getElementById("voiceAvatarActive");r&&r.classList.remove("speaking"),console.log("✅ Voice call ended")}},{key:"updateTranscript",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent=t,e.classList.remove("empty"))}},{key:"showError",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent="".concat(this.t("error"),": ").concat(t),e.classList.remove("empty"))}},{key:"showDomainError",value:function(){var t=document.getElementById("transcriptText");if(t){var e=this.t("domainNotValidated"),n=this.t("domainErrorMessage");t.innerHTML='<div style="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;">'.concat(e,'</div><div style="font-size: 14px; color: #991B1B; line-height: 1.5;">').concat(n,"</div>"),t.classList.remove("empty")}}},{key:"toggleMute",value:function(){if(this.sdk&&this.isActive){var t=null;if(this.sdk.voiceSDK&&this.sdk.voiceSDK.audioRecorder&&this.sdk.voiceSDK.audioRecorder.mediaStream&&(t=this.sdk.voiceSDK.audioRecorder.mediaStream.getAudioTracks()[0]),!t&&this.audioStream&&(t=this.audioStream.getAudioTracks()[0]),t){t.enabled=!t.enabled;var e=document.getElementById("muteBtn"),n=null==e?void 0:e.querySelector(".mute-icon"),o=null==e?void 0:e.querySelector(".mute-cross");e&&n&&o&&(t.enabled?(n.style.stroke="",o.style.display="none",e.classList.remove("muted")):(n.style.stroke="#9ca3af",o.style.display="block",e.classList.add("muted"))),console.log(t.enabled?"🔊 Unmuted":"🔇 Muted")}else console.warn("⚠️ No audio track available for mute toggle")}}},{key:"toggleSpeaker",value:function(){console.log("🔊 Speaker toggle")}},{key:"destroy",value:function(){this.isActive&&this.endVoiceCall(),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&(this.sdk.disconnect(),this.sdk=null)}}],e&&qn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Yn(t){return Yn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Yn(t)}function $n(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Xn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Xn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Xn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Xn(d,"constructor",u),Xn(u,"constructor",s),s.displayName="GeneratorFunction",Xn(u,r,"GeneratorFunction"),Xn(d),Xn(d,r,"Generator"),Xn(d,o,function(){return this}),Xn(d,"toString",function(){return"[object Generator]"}),($n=function(){return{w:i,m:f}})()}function Xn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Xn=function(t,e,n,o){function i(e,n){Xn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Xn(t,e,n,o)}function Zn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function to(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Zn(i,o,r,a,c,"next",t)}function c(t){Zn(i,o,r,a,c,"throw",t)}a(void 0)})}}function eo(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,no(o.key),o)}}function no(t){var e=function(t){if("object"!=Yn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Yn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Yn(e)?e:e+""}var oo=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.sdk=n,this.streamingEl=null,this.hasStartedStreaming=!1,this.isActive=!1,this.eventHandlers={autoResize:null,keydown:null},this.eventHandlersSetup=!1},e=[{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"generateHTML",value:function(){var t,e,n,o,r,i,a,c,s,u=this.config.inputPlaceholder||(null===(t=this.config.panel)||void 0===t?void 0:t.inputPlaceholder)||this.t("typeMessage")||"Type your message...";return'<div class="text-interface" id="textInterface">\n <div class="messages-container" id="messagesContainer">\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),'</div>\n </div>\n </div>\n <div class="input-container">\n <div class="input-wrapper" style="flex:1;">\n <textarea class="message-input" id="messageInput" placeholder="').concat(u,'" rows="1" dir="').concat(this.config.direction||"ltr",'"></textarea>\n </div>\n <button class="send-button" id="sendButton" aria-label="').concat(this.t("sendMessageAria"),'">').concat(this.config.sendButtonText||"➤","</button>\n ").concat(null!==(e=this.config.sendButtonHint)&&void 0!==e&&e.text||null!==(n=this.config.panel)&&void 0!==n&&null!==(n=n.sendButtonHint)&&void 0!==n&&n.text?'\n <div class="send-button-hint" style="color: '.concat((null===(o=this.config.sendButtonHint)||void 0===o?void 0:o.color)||(null===(r=this.config.panel)||void 0===r||null===(r=r.sendButtonHint)||void 0===r?void 0:r.color)||"#6B7280","; font-size: ").concat((null===(i=this.config.sendButtonHint)||void 0===i?void 0:i.fontSize)||(null===(a=this.config.panel)||void 0===a||null===(a=a.sendButtonHint)||void 0===a?void 0:a.fontSize)||"12px",'; text-align: center; margin-top: 4px;">\n ').concat((null===(c=this.config.sendButtonHint)||void 0===c?void 0:c.text)||(null===(s=this.config.panel)||void 0===s||null===(s=s.sendButtonHint)||void 0===s?void 0:s.text),"\n </div>\n "):"","\n </div>\n </div>")}},{key:"generateCSS",value:function(){var t,e,n,o,r,i,a,c,s,u,l,d,f,p=this.config.messages,h=(this.config.panel,this.config.animation,this.config.sendButtonColor||(null===(t=this.config.panel)||void 0===t?void 0:t.sendButtonColor)||"#7C3AED"),v=this.config.sendButtonHoverColor||(null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonHoverColor)||"#6D28D9",g=this.config.sendButtonTextColor||(null===(n=this.config.panel)||void 0===n?void 0:n.sendButtonTextColor)||"#FFFFFF",y=(this.config.inputPlaceholder||null===(o=this.config.panel)||void 0===o||o.inputPlaceholder,this.config.inputBorderColor||(null===(r=this.config.panel)||void 0===r?void 0:r.inputBorderColor)||"#E5E7EB"),m=this.config.inputFocusColor||(null===(i=this.config.panel)||void 0===i?void 0:i.inputFocusColor)||"#7C3AED",b=this.config.inputBackgroundColor||(null===(a=this.config.panel)||void 0===a?void 0:a.inputBackgroundColor)||"#FFFFFF",w=this.config.inputTextColor||(null===(c=this.config.panel)||void 0===c?void 0:c.inputTextColor)||"#1F2937",S=this.config.inputFontSize||(null===(s=this.config.panel)||void 0===s?void 0:s.inputFontSize)||"14px",x=this.config.inputBorderRadius||(null===(u=this.config.panel)||void 0===u?void 0:u.inputBorderRadius)||20,k=this.config.inputPadding||(null===(l=this.config.panel)||void 0===l?void 0:l.inputPadding)||"6px 14px";return"\n /* Messages container using new classes */\n #messagesContainer { \n flex: 1; \n overflow-y: auto; \n overflow-x: hidden; \n padding: 20px; \n background: #f8fafc; \n display: flex; \n flex-direction: column; \n gap: 16px; \n min-height: 0; \n }\n .empty-state { \n flex: 1; \n display: flex; \n flex-direction: column; \n align-items: center; \n justify-content: center; \n gap: 12px; \n color: #64748b; \n text-align: center; \n padding: 20px; \n }\n .empty-state-icon { font-size: 48px; opacity: 0.3; }\n .empty-state-title { font-size: 20px; font-weight: 700; color: #334155; }\n .empty-state-text { font-size: 13px; max-width: 280px; }\n\n .text-interface { \n display: none; \n flex: 1; \n flex-direction: column; \n min-height: 0; \n overflow: hidden; \n }\n .text-interface.active { display: flex; }\n \n .message { \n display: flex; \n gap: 8px; \n padding: 4px 0; \n max-width: 100%; \n align-items: center; \n }\n .message.edge-left { flex-direction: row; }\n .message.edge-right { flex-direction: row-reverse; }\n .message-bubble { \n padding: 12px; \n border-radius: ".concat(p.borderRadius,"px; \n max-width: 80%; \n font-size: ").concat(p.fontSize,"; \n color: ").concat(p.textColor,"; \n word-wrap: break-word; \n text-align: ").concat("rtl"===this.config.direction?"right":"left","; \n direction: ").concat(this.config.direction||"ltr",";\n }\n .message.user { \n background: ").concat(p.userBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-start":"flex-end","; \n }\n .message.agent { \n background: ").concat(p.agentBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-end":"flex-start","; \n }\n .message .message-bubble { \n text-align: ").concat("rtl"===this.config.direction?"right":"left"," !important; \n }\n ").concat("rtl"===this.config.direction?"\n .message-bubble {\n text-align: right !important;\n }\n ":"","\n .message-avatar { \n width: 20px; \n height: 20px; \n display: flex; \n align-items: center; \n justify-content: center; \n flex-shrink: 0; \n color: inherit; \n font-size: 18px; \n line-height: 1; \n background: transparent; \n border: none; \n }\n .message-avatar.user { background: transparent; }\n .message-avatar.agent { background: transparent; }\n \n .message.system {\n background: ").concat(p.systemBackgroundColor,";\n align-self: flex-start;\n }\n .message.error {\n background: ").concat(p.errorBackgroundColor,";\n align-self: flex-start;\n }\n \n .input-container {\n display: flex;\n gap: 8px;\n padding: 12px 16px;\n background: #FFFFFF;\n border-top: 1px solid #E5E7EB;\n align-items: center;\n flex-shrink: 0;\n flex-direction: ").concat("rtl"===this.config.direction?"row-reverse":"row",";\n }\n \n .input-wrapper {\n position: relative;\n display: flex;\n align-items: center;\n }\n \n .message-input {\n width: 100%;\n min-height: 32px;\n max-height: 120px;\n padding: ").concat(k,";\n border: 1px solid ").concat(y,";\n border-radius: ").concat(x,"px;\n font-size: ").concat(S,";\n font-family: inherit;\n line-height: 1.3;\n resize: none;\n overflow-y: auto;\n background: ").concat(b,";\n color: ").concat(w,";\n vertical-align: top;\n margin: 0;\n display: block;\n white-space: pre-wrap;\n word-wrap: break-word;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n direction: ").concat(this.config.direction||"ltr",";\n -webkit-appearance: none;\n appearance: none;\n box-sizing: border-box;\n }\n \n .message-input:focus {\n outline: none;\n border-color: ").concat(m,";\n background: ").concat("#FFFFFF"===b?"#FFFFFF":b,";\n box-shadow: 0 0 0 3px ").concat(m,"33;\n }\n \n .message-input::placeholder {\n color: #9CA3AF;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n }\n \n .send-button {\n width: 40px;\n height: 40px;\n border-radius: 50%;\n border: none;\n background: ").concat(h,";\n color: ").concat(g,";\n font-size: ").concat(this.config.sendButtonFontSize||(null===(d=this.config.panel)||void 0===d?void 0:d.sendButtonFontSize)||"18px",";\n font-weight: ").concat(this.config.sendButtonFontWeight||(null===(f=this.config.panel)||void 0===f?void 0:f.sendButtonFontWeight)||"500",";\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n transition: all 0.2s ease;\n box-shadow: 0 4px 12px rgba(124, 60, 237, 0.3);\n }\n \n .send-button:hover:not(:disabled) {\n background: ").concat(v,";\n transform: scale(1.05);\n box-shadow: 0 6px 16px rgba(124, 60, 237, 0.4);\n }\n \n .send-button-hint {\n width: 100%;\n text-align: center;\n margin-top: 4px;\n }\n \n .send-button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n \n .typing-indicator {\n display: inline-flex;\n gap: 4px;\n align-items: center;\n }\n \n .typing-dot {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: #64748b;\n animation: typingDot 1.4s ease-in-out infinite;\n }\n \n .typing-dot:nth-child(2) { animation-delay: 0.2s; }\n .typing-dot:nth-child(3) { animation-delay: 0.4s; }\n \n @keyframes typingDot {\n 0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }\n 30% { transform: translateY(-8px); opacity: 1; }\n }\n \n .error-message {\n padding: 12px;\n background: ").concat(p.errorBackgroundColor,";\n border-radius: ").concat(p.borderRadius,"px;\n color: #991B1B;\n font-size: ").concat(p.fontSize,";\n margin: 8px 0;\n }\n \n @media (max-width: 768px) {\n #messagesContainer {\n padding: 12px;\n gap: 12px;\n }\n \n .message-bubble {\n max-width: 85%;\n font-size: 14px;\n padding: 10px;\n }\n \n .text-input-container {\n padding: 10px;\n gap: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 10px 14px;\n min-height: 44px;\n }\n \n #text-chat-send {\n min-width: 56px;\n min-height: 44px;\n width: 56px;\n height: 44px;\n }\n \n .empty-state-icon {\n font-size: 40px;\n }\n \n .empty-state-title {\n font-size: 18px;\n }\n \n .empty-state-text {\n font-size: 12px;\n }\n }\n \n @media (max-width: 480px) {\n #messagesContainer {\n padding: 10px;\n gap: 10px;\n }\n \n .message-bubble {\n max-width: 90%;\n font-size: 13px;\n padding: 8px;\n }\n \n .text-input-container {\n padding: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important;\n padding: 8px 12px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(){var t=this,e=document.getElementById("sendButton"),n=document.getElementById("messageInput"),o=document.getElementById("newChatBtn");if(e&&(e.onclick=function(){return t.sendMessage()}),o&&(o.onclick=function(){return t.startNewChat()}),this.updateInputAttributes(),n){n.style.height="32px",n.style.overflow="hidden";var r=function(){n.style.height="auto";var t=Math.min(n.scrollHeight,120);n.style.height=t+"px",n.style.overflowY=t>=120?"auto":"hidden",t>=120&&setTimeout(function(){n.scrollTop=n.scrollHeight},0)};n.addEventListener("input",r),n.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey?"Enter"===e.key&&e.shiftKey&&setTimeout(r,0):(e.preventDefault(),t.sendMessage())})}}},{key:"startNewChat",value:function(){try{localStorage.removeItem("ttp_text_chat_conversation_id")}catch(t){}this.sdk&&(this.sdk.config.conversationId=null);var t=document.getElementById("messagesContainer");t&&(t.innerHTML='\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),"</div>\n </div>"));var e=document.getElementById("messageInput");e&&e.focus()}},{key:"updateInputAttributes",value:function(){var t=document.getElementById("messageInput");if(t){var e,n=this.config.inputPlaceholder||(null===(e=this.config.panel)||void 0===e?void 0:e.inputPlaceholder)||this.t("typeMessage")||"Type your message...";t.placeholder=n,t.dir=this.config.direction||"ltr",t.style.textAlign="rtl"===this.config.direction?"right":"left"}}},{key:"show",value:function(){var t=document.getElementById("textInterface");t&&t.classList.add("active"),setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},50)}},{key:"hide",value:function(){var t=document.getElementById("textInterface");t&&t.classList.remove("active")}},{key:"startChat",value:(o=to($n().m(function t(){return $n().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.updateSendButtonState();case 1:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"sendMessage",value:(n=to($n().m(function t(){var e,n,o;return $n().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("messageInput"),n=e.value.trim()){t.n=1;break}return t.a(2);case 1:if(this.isActive){t.n=2;break}return t.n=2,this.startChat();case 2:return this.addMessage("user",n),e.value="",e.style.height="32px",e.style.overflow="hidden",t.p=3,this.beginStreaming(),t.n=4,this.sdk.sendMessage(n);case 4:t.n=6;break;case 5:t.p=5,o=t.v,console.error("❌ Failed to send message:",o),o&&("DOMAIN_NOT_WHITELISTED"===o.message||o.message&&o.message.includes("Domain not whitelisted"))||this.showError(o),this.stopStreamingState();case 6:return t.a(2)}},t,this,[[3,5]])})),function(){return n.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var t=document.getElementById("sendButton");t&&(t.disabled=!this.isActive)}},{key:"addMessage",value:function(t,e){var n=document.getElementById("messagesContainer");if(n){var o=n.querySelector(".empty-state");o&&o.remove();var r=document.createElement("div"),i="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";r.className="message ".concat(t," ").concat(i);var a=document.createElement("div");a.className="message-avatar ".concat(t),a.textContent="user"===t?"👤":"🤖";var c=document.createElement("div");c.className="message-bubble",c.textContent=e,r.appendChild(a),r.appendChild(c),n.appendChild(r),n.scrollTop=n.scrollHeight}}},{key:"beginStreaming",value:function(){var t=document.getElementById("messagesContainer");if(t){this.stopStreamingState();var e=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";e.className="message agent ".concat(n),e.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var r=document.createElement("div");r.className="message-bubble",r.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',e.appendChild(o),e.appendChild(r),t.appendChild(e),this.streamingEl=r,this.hasStartedStreaming=!1,t.scrollTop=t.scrollHeight}}},{key:"appendStreamingChunk",value:function(t){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=t;var e=document.getElementById("messagesContainer");e&&(e.scrollTop=e.scrollHeight)}}},{key:"finalizeStreaming",value:function(t){if(this.streamingEl){this.streamingEl.textContent=t||this.streamingEl.textContent;var e=document.getElementById("agent-streaming");e&&(e.id=""),this.streamingEl=null}this.updateSendButtonState()}},{key:"stopStreamingState",value:function(){var t=document.getElementById("agent-streaming");t&&t.remove(),this.streamingEl=null,this.hasStartedStreaming=!1}},{key:"showError",value:function(t){var e=document.getElementById("messagesContainer");if(e){if(t&&("DOMAIN_NOT_WHITELISTED"===t.message||"string"==typeof t&&t.includes("DOMAIN_NOT_WHITELISTED")||t.message&&t.message.includes("Domain not whitelisted")||"string"==typeof t&&t.includes("Domain not whitelisted"))){var n,o=document.createElement("div");o.className="error-message",o.style.cssText="padding: 16px; margin: 12px; border-radius: 8px; background: "+((null===(n=this.config.messages)||void 0===n?void 0:n.errorBackgroundColor)||"#FEE2E2")+";";var r=document.createElement("div");r.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",r.textContent=this.t("domainNotValidated");var i=document.createElement("div");i.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",i.textContent=this.t("domainErrorMessage"),o.appendChild(r),o.appendChild(i),e.appendChild(o)}else{var a=document.createElement("div");a.className="error-message",a.textContent="string"==typeof t?t:(null==t?void 0:t.message)||t,e.appendChild(a)}e.scrollTop=e.scrollHeight}}},{key:"setActive",value:function(t){this.isActive=t,this.updateSendButtonState()}}],e&&eo(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();const ro={en:{landingTitle:"How would you like to communicate?",voiceCall:"Voice Call",textChat:"Text Chat",clickToStartCall:"Click to Start Call",realTimeVoice:"Real-time voice conversation",startCall:"Start Call",listening:"Listening...",speakFreely:"Speak freely",liveTranscript:"Live Transcript",transcriptWillAppear:"Transcript will appear here during the call...",mute:"Mute",speaker:"Speaker",endCall:"End Call",hello:"Hello! How can I help?",sendMessage:"Send a message to get started",online:"Online",newChat:"New Chat",back:"Back",close:"Close",error:"Error",typeMessage:"Type your message...",sendMessageAria:"Send message",domainNotValidated:"Domain not validated",domainErrorMessage:"This domain is not whitelisted. Please contact the administrator to whitelist your website URL."},he:{landingTitle:"איך תרצה לתקשר?",voiceCall:"שיחה קולית",textChat:"צ'אט טקסט",clickToStartCall:"לחץ להתחלת שיחה",realTimeVoice:"שיחה קולית בזמן אמת",startCall:"התחל שיחה",listening:"מקשיב...",speakFreely:"דבר בחופשיות",liveTranscript:"תמלול בזמן אמת",transcriptWillAppear:"התמלול יופיע כאן במהלך השיחה...",mute:"השתק",speaker:"רמקול",endCall:"סיים שיחה",hello:"שלום! איך אפשר לעזור?",sendMessage:"שלח הודעה או עבור למצב קולי לשיחה בזמן אמת",online:"מקוון",newChat:"צ'אט חדש",back:"חזור",close:"סגור",error:"שגיאה",typeMessage:"הקלד הודעה...",sendMessageAria:"שלח הודעה",domainNotValidated:"דומיין לא מאומת",domainErrorMessage:"דומיין זה לא ברשימת המורשים. אנא פנה למנהל המערכת כדי להוסיף את כתובת האתר שלך לרשימה."},ar:{landingTitle:"كيف تريد التواصل؟",voiceCall:"مكالمة صوتية",textChat:"دردشة نصية",clickToStartCall:"انقر لبدء المكالمة",realTimeVoice:"محادثة صوتية في الوقت الفعلي",startCall:"ابدأ المكالمة",listening:"الاستماع...",speakFreely:"تكلم بحرية",liveTranscript:"نص مباشر",transcriptWillAppear:"سيظهر النص هنا أثناء المكالمة...",mute:"كتم الصوت",speaker:"مكبر الصوت",endCall:"إنهاء المكالمة",hello:"مرحبا! كيف يمكنني المساعدة؟",sendMessage:"أرسل رسالة للبدء",online:"متصل",newChat:"محادثة جديدة",back:"رجوع",close:"إغلاق",error:"خطأ",typeMessage:"اكتب رسالة...",sendMessageAria:"إرسال رسالة",domainNotValidated:"النطاق غير معتمد",domainErrorMessage:"هذا النطاق غير مسموح به. يرجى الاتصال بالمسؤول لإضافة عنوان موقع الويب الخاص بك إلى القائمة."},ru:{landingTitle:"Как вы хотите общаться?",voiceCall:"Голосовой звонок",textChat:"Текстовый чат",clickToStartCall:"Нажмите, чтобы начать звонок",realTimeVoice:"Голосовой разговор в реальном времени",startCall:"Начать звонок",listening:"Слушаю...",speakFreely:"Говорите свободно",liveTranscript:"Живая транскрипция",transcriptWillAppear:"Транскрипция появится здесь во время звонка...",mute:"Отключить звук",speaker:"Динамик",endCall:"Завершить звонок",hello:"Привет! Как я могу помочь?",sendMessage:"Отправьте сообщение для начала",online:"В сети",newChat:"Новый чат",back:"Назад",close:"Закрыть",error:"Ошибка",typeMessage:"Введите сообщение...",sendMessageAria:"Отправить сообщение",domainNotValidated:"Домен не проверен",domainErrorMessage:"Этот домен не в белом списке. Пожалуйста, свяжитесь с администратором, чтобы добавить URL вашего веб-сайта в список."},es:{landingTitle:"¿Cómo te gustaría comunicarte?",voiceCall:"Llamada de voz",textChat:"Chat de texto",clickToStartCall:"Haz clic para iniciar la llamada",realTimeVoice:"Conversación de voz en tiempo real",startCall:"Iniciar llamada",listening:"Escuchando...",speakFreely:"Habla libremente",liveTranscript:"Transcripción en vivo",transcriptWillAppear:"La transcripción aparecerá aquí durante la llamada...",mute:"Silenciar",speaker:"Altavoz",endCall:"Terminar llamada",hello:"¡Hola! ¿Cómo puedo ayudarte?",sendMessage:"Envía un mensaje para comenzar",online:"En línea",newChat:"Nuevo chat",back:"Atrás",close:"Cerrar",error:"Error",typeMessage:"Escribe un mensaje...",sendMessageAria:"Enviar mensaje",domainNotValidated:"Dominio no validado",domainErrorMessage:"Este dominio no está en la lista blanca. Por favor, contacte al administrador para agregar la URL de su sitio web a la lista."},fr:{landingTitle:"Comment souhaitez-vous communiquer?",voiceCall:"Appel vocal",textChat:"Chat texte",clickToStartCall:"Cliquez pour démarrer l'appel",realTimeVoice:"Conversation vocale en temps réel",startCall:"Démarrer l'appel",listening:"Écoute...",speakFreely:"Parlez librement",liveTranscript:"Transcripción en direct",transcriptWillAppear:"La transcription apparaîtra ici pendant l'appel...",mute:"Muet",speaker:"Haut-parleur",endCall:"Terminer l'appel",hello:"Bonjour! Comment puis-je vous aider?",sendMessage:"Envoyez un message pour commencer",online:"En ligne",newChat:"Nouveau chat",back:"Retour",close:"Fermer",error:"Erreur",typeMessage:"Tapez votre message...",sendMessageAria:"Envoyer un message",domainNotValidated:"Domaine non validé",domainErrorMessage:"Ce domaine n'est pas sur la liste blanche. Veuillez contacter l'administrateur pour ajouter l'URL de votre site Web à la liste."},de:{landingTitle:"Wie möchten Sie kommunizieren?",voiceCall:"Sprachanruf",textChat:"Text-Chat",clickToStartCall:"Klicken Sie, um den Anruf zu starten",realTimeVoice:"Sprachanruf in Echtzeit",startCall:"Anruf starten",listening:"Hören...",speakFreely:"Sprechen Sie frei",liveTranscript:"Live-Transkription",transcriptWillAppear:"Die Transkription erscheint hier während des Anrufs...",mute:"Stumm",speaker:"Lautsprecher",endCall:"Anruf beenden",hello:"Hallo! Wie kann ich helfen?",sendMessage:"Senden Sie eine Nachricht zum Starten",online:"Online",newChat:"Neuer Chat",back:"Zurück",close:"Schließen",error:"Fehler",typeMessage:"Geben Sie eine Nachricht ein...",sendMessageAria:"Nachricht senden",domainNotValidated:"Domain nicht validiert",domainErrorMessage:"Diese Domain steht nicht auf der Whitelist. Bitte kontaktieren Sie den Administrator, um die URL Ihrer Website zur Liste hinzuzufügen."}};function io(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ao(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ao(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ao(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ao(d,"constructor",u),ao(u,"constructor",s),s.displayName="GeneratorFunction",ao(u,r,"GeneratorFunction"),ao(d),ao(d,r,"Generator"),ao(d,o,function(){return this}),ao(d,"toString",function(){return"[object Generator]"}),(io=function(){return{w:i,m:f}})()}function ao(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ao=function(t,e,n,o){function i(e,n){ao(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ao(t,e,n,o)}function co(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function so(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){co(i,o,r,a,c,"next",t)}function c(t){co(i,o,r,a,c,"throw",t)}a(void 0)})}}function uo(t){return uo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},uo(t)}function lo(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function fo(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?lo(Object(n),!0).forEach(function(e){po(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):lo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function po(t,e,n){return(e=vo(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ho(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,vo(o.key),o)}}function vo(t){var e=function(t){if("object"!=uo(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=uo(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==uo(e)?e:e+""}var go=function(){return t=function t(){var e,n,o,r,i,a,c,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=this.mergeWithDefaults(s),this.sdk=new dn(this.config),this.isOpen=!1,this.isActive=!1,this.translations=ro,this.currentView="landing";var u=fo(fo(fo({},this.config),this.config.voice),{},{language:(null===(e=this.config.voice)||void 0===e?void 0:e.language)||this.config.language||"en",websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16});this.voiceInterface=new Jn(u);var l=fo(fo(fo({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new oo(l,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var d=document.getElementById("text-chat-panel");d&&(this.isOpen=!0,d.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,a,c,s,u,l,d,f,p,h,v,g,y,m,b,w,S,x,k,C,P,O,T,E,j,I,F,A,B,D,R,_,U,M,N,z,L,V,H,K,W,G,q,Q,J,Y,$,X,Z,tt,et,nt,ot,rt,it,at,ct,st,ut,lt,dt,ft,pt,ht,vt,gt,yt,mt,bt,wt,St,xt,kt,Ct,Pt,Ot,Tt,Et,jt,It,Ft,At,Bt,Dt,Rt,_t,Ut,Mt,Nt,zt,Lt,Vt,Ht,Kt,Wt,Gt,qt,Qt,Jt,Yt,$t,Xt,Zt,te,ee,ne,oe,re,ie,ae,ce,se,ue,le,de,fe,pe,he,ve,ge,ye,me,be,we,Se,xe,ke,Ce,Pe,Oe,Te=t.position||"bottom-right";if("string"==typeof Te){var Ee=Te.split("-");Te={vertical:Ee[0]||"bottom",horizontal:Ee[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var je=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||(null===(n=t.button)||void 0===n?void 0:n.backgroundColor)||"#7C3AED",Ie=(null===(o=t.header)||void 0===o?void 0:o.backgroundColor)||(null===(r=t.button)||void 0===r?void 0:r.backgroundColor)||je;return fo({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",language:t.language||"en",icon:fo({type:(null===(i=t.icon)||void 0===i?void 0:i.type)||"custom",customImage:(null===(a=t.icon)||void 0===a?void 0:a.customImage)||"https://talktopc.com/logo192.png",emoji:(null===(c=t.icon)||void 0===c?void 0:c.emoji)||"🎤",text:(null===(s=t.icon)||void 0===s?void 0:s.text)||"AI",size:(null===(u=t.icon)||void 0===u?void 0:u.size)||"medium",backgroundColor:(null===(l=t.icon)||void 0===l?void 0:l.backgroundColor)||"#FFFFFF"},t.icon),position:fo({vertical:Te.vertical||"bottom",horizontal:Te.horizontal||"right",offset:Te.offset||{x:20,y:20}},"object"===uo(t.position)?t.position:{}),button:fo({size:(null===(d=t.button)||void 0===d?void 0:d.size)||"medium",shape:(null===(f=t.button)||void 0===f?void 0:f.shape)||"circle",backgroundColor:(null===(p=t.button)||void 0===p?void 0:p.backgroundColor)||(null===(h=t.icon)||void 0===h?void 0:h.backgroundColor)||je,hoverColor:(null===(v=t.button)||void 0===v?void 0:v.hoverColor)||"#7C3AED",shadow:!1!==(null===(g=t.button)||void 0===g?void 0:g.shadow),shadowColor:(null===(y=t.button)||void 0===y?void 0:y.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(m=t.button)||void 0===m?void 0:m.backgroundColor)||(null===(b=t.icon)||void 0===b?void 0:b.backgroundColor)||je},t.button),panel:fo({width:(null===(w=t.panel)||void 0===w?void 0:w.width)||350,height:(null===(S=t.panel)||void 0===S?void 0:S.height)||500,borderRadius:(null===(x=t.panel)||void 0===x?void 0:x.borderRadius)||12,backgroundColor:(null===(k=t.panel)||void 0===k?void 0:k.backgroundColor)||"#FFFFFF",backdropFilter:(null===(C=t.panel)||void 0===C?void 0:C.backdropFilter)||null,border:(null===(P=t.panel)||void 0===P?void 0:P.border)||"1px solid rgba(0,0,0,0.1)"},t.panel),voice:fo({micButtonColor:(null===(O=t.voice)||void 0===O?void 0:O.micButtonColor)||(null===(T=t.panel)||void 0===T?void 0:T.micButtonColor)||je,micButtonActiveColor:(null===(E=t.voice)||void 0===E?void 0:E.micButtonActiveColor)||(null===(j=t.panel)||void 0===j?void 0:j.micButtonActiveColor)||"#EF4444",micButtonHint:fo(fo({text:(null===(I=t.voice)||void 0===I||null===(I=I.micButtonHint)||void 0===I?void 0:I.text)||(null===(F=t.panel)||void 0===F||null===(F=F.micButtonHint)||void 0===F?void 0:F.text)||"Click the button to start voice conversation",color:(null===(A=t.voice)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.color)||(null===(B=t.panel)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.color)||"#6B7280",fontSize:(null===(D=t.voice)||void 0===D||null===(D=D.micButtonHint)||void 0===D?void 0:D.fontSize)||(null===(R=t.panel)||void 0===R||null===(R=R.micButtonHint)||void 0===R?void 0:R.fontSize)||"12px"},null===(_=t.voice)||void 0===_?void 0:_.micButtonHint),null===(U=t.panel)||void 0===U?void 0:U.micButtonHint),avatarBackgroundColor:(null===(M=t.voice)||void 0===M?void 0:M.avatarBackgroundColor)||"#667eea",avatarActiveBackgroundColor:(null===(N=t.voice)||void 0===N?void 0:N.avatarActiveBackgroundColor)||"#667eea",statusTitleColor:(null===(z=t.voice)||void 0===z?void 0:z.statusTitleColor)||"#1e293b",statusSubtitleColor:(null===(L=t.voice)||void 0===L?void 0:L.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(V=t.voice)||void 0===V?void 0:V.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(H=t.voice)||void 0===H?void 0:H.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(K=t.voice)||void 0===K?void 0:K.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(W=t.voice)||void 0===W?void 0:W.transcriptTextColor)||"#1e293b",transcriptLabelColor:(null===(G=t.voice)||void 0===G?void 0:G.transcriptLabelColor)||"#94a3b8",controlButtonColor:(null===(q=t.voice)||void 0===q?void 0:q.controlButtonColor)||"#FFFFFF",controlButtonSecondaryColor:(null===(Q=t.voice)||void 0===Q?void 0:Q.controlButtonSecondaryColor)||"#64748b",endCallButtonColor:(null===(J=t.voice)||void 0===J?void 0:J.endCallButtonColor)||"#ef4444",language:(null===(Y=t.voice)||void 0===Y?void 0:Y.language)||t.language||"en",websocketUrl:(null===($=t.voice)||void 0===$?void 0:$.websocketUrl)||t.websocketUrl},t.voice),text:fo({sendButtonColor:(null===(X=t.text)||void 0===X?void 0:X.sendButtonColor)||(null===(Z=t.panel)||void 0===Z?void 0:Z.sendButtonColor)||"#7C3AED",sendButtonHoverColor:(null===(tt=t.text)||void 0===tt?void 0:tt.sendButtonHoverColor)||(null===(et=t.panel)||void 0===et?void 0:et.sendButtonHoverColor)||"#6D28D9",sendButtonActiveColor:(null===(nt=t.text)||void 0===nt?void 0:nt.sendButtonActiveColor)||(null===(ot=t.panel)||void 0===ot?void 0:ot.sendButtonActiveColor)||"#6D28D9",sendButtonText:(null===(rt=t.text)||void 0===rt?void 0:rt.sendButtonText)||(null===(it=t.panel)||void 0===it?void 0:it.sendButtonText)||"➤",sendButtonTextColor:(null===(at=t.text)||void 0===at?void 0:at.sendButtonTextColor)||(null===(ct=t.panel)||void 0===ct?void 0:ct.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(st=t.text)||void 0===st?void 0:st.sendButtonFontSize)||(null===(ut=t.panel)||void 0===ut?void 0:ut.sendButtonFontSize)||"18px",sendButtonFontWeight:(null===(lt=t.text)||void 0===lt?void 0:lt.sendButtonFontWeight)||(null===(dt=t.panel)||void 0===dt?void 0:dt.sendButtonFontWeight)||"500",sendButtonHint:fo(fo({text:(null===(ft=t.text)||void 0===ft||null===(ft=ft.sendButtonHint)||void 0===ft?void 0:ft.text)||(null===(pt=t.panel)||void 0===pt||null===(pt=pt.sendButtonHint)||void 0===pt?void 0:pt.text)||"",color:(null===(ht=t.text)||void 0===ht||null===(ht=ht.sendButtonHint)||void 0===ht?void 0:ht.color)||(null===(vt=t.panel)||void 0===vt||null===(vt=vt.sendButtonHint)||void 0===vt?void 0:vt.color)||"#6B7280",fontSize:(null===(gt=t.text)||void 0===gt||null===(gt=gt.sendButtonHint)||void 0===gt?void 0:gt.fontSize)||(null===(yt=t.panel)||void 0===yt||null===(yt=yt.sendButtonHint)||void 0===yt?void 0:yt.fontSize)||"12px"},null===(mt=t.text)||void 0===mt?void 0:mt.sendButtonHint),null===(bt=t.panel)||void 0===bt?void 0:bt.sendButtonHint),inputPlaceholder:(null===(wt=t.text)||void 0===wt?void 0:wt.inputPlaceholder)||(null===(St=t.panel)||void 0===St?void 0:St.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(xt=t.text)||void 0===xt?void 0:xt.inputBorderColor)||(null===(kt=t.panel)||void 0===kt?void 0:kt.inputBorderColor)||"#E5E7EB",inputFocusColor:(null===(Ct=t.text)||void 0===Ct?void 0:Ct.inputFocusColor)||(null===(Pt=t.panel)||void 0===Pt?void 0:Pt.inputFocusColor)||"#7C3AED",inputBackgroundColor:(null===(Ot=t.text)||void 0===Ot?void 0:Ot.inputBackgroundColor)||(null===(Tt=t.panel)||void 0===Tt?void 0:Tt.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(Et=t.text)||void 0===Et?void 0:Et.inputTextColor)||(null===(jt=t.panel)||void 0===jt?void 0:jt.inputTextColor)||"#1F2937",inputFontSize:(null===(It=t.text)||void 0===It?void 0:It.inputFontSize)||(null===(Ft=t.panel)||void 0===Ft?void 0:Ft.inputFontSize)||"14px",inputBorderRadius:(null===(At=t.text)||void 0===At?void 0:At.inputBorderRadius)||(null===(Bt=t.panel)||void 0===Bt?void 0:Bt.inputBorderRadius)||20,inputPadding:(null===(Dt=t.text)||void 0===Dt?void 0:Dt.inputPadding)||(null===(Rt=t.panel)||void 0===Rt?void 0:Rt.inputPadding)||"6px 14px"},t.text),landing:fo({backgroundColor:(null===(_t=t.landing)||void 0===_t?void 0:_t.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)",logo:(null===(Ut=t.landing)||void 0===Ut?void 0:Ut.logo)||"🤖",title:(null===(Mt=t.landing)||void 0===Mt?void 0:Mt.title)||null,titleColor:(null===(Nt=t.landing)||void 0===Nt?void 0:Nt.titleColor)||"#1e293b",modeCardBackgroundColor:(null===(zt=t.landing)||void 0===zt?void 0:zt.modeCardBackgroundColor)||"#FFFFFF",modeCardBorderColor:(null===(Lt=t.landing)||void 0===Lt?void 0:Lt.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Vt=t.landing)||void 0===Vt?void 0:Vt.modeCardHoverBorderColor)||Ie,modeCardIconBackgroundColor:(null===(Ht=t.landing)||void 0===Ht?void 0:Ht.modeCardIconBackgroundColor)||Ie,modeCardTitleColor:(null===(Kt=t.landing)||void 0===Kt?void 0:Kt.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(Wt=t.landing)||void 0===Wt?void 0:Wt.voiceCardIcon)||"🎤",textCardIcon:(null===(Gt=t.landing)||void 0===Gt?void 0:Gt.textCardIcon)||"💬"},t.landing),header:fo({title:(null===(qt=t.header)||void 0===qt?void 0:qt.title)||"Chat Assistant",showTitle:!1!==(null===(Qt=t.header)||void 0===Qt?void 0:Qt.showTitle),backgroundColor:(null===(Jt=t.header)||void 0===Jt?void 0:Jt.backgroundColor)||(null===(Yt=t.button)||void 0===Yt?void 0:Yt.backgroundColor)||"#7C3AED",textColor:(null===($t=t.header)||void 0===$t?void 0:$t.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(Xt=t.header)||void 0===Xt?void 0:Xt.showCloseButton)},t.header),tooltips:fo({newChat:(null===(Zt=t.tooltips)||void 0===Zt?void 0:Zt.newChat)||null,back:(null===(te=t.tooltips)||void 0===te?void 0:te.back)||null,close:(null===(ee=t.tooltips)||void 0===ee?void 0:ee.close)||null,mute:(null===(ne=t.tooltips)||void 0===ne?void 0:ne.mute)||null,speaker:(null===(oe=t.tooltips)||void 0===oe?void 0:oe.speaker)||null,endCall:(null===(re=t.tooltips)||void 0===re?void 0:re.endCall)||null},t.tooltips),messages:fo({userBackgroundColor:(null===(ie=t.messages)||void 0===ie?void 0:ie.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(ae=t.messages)||void 0===ae?void 0:ae.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(ce=t.messages)||void 0===ce?void 0:ce.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(se=t.messages)||void 0===se?void 0:se.errorBackgroundColor)||"#FEE2E2",textColor:(null===(ue=t.messages)||void 0===ue?void 0:ue.textColor)||"#1F2937",fontSize:(null===(le=t.messages)||void 0===le?void 0:le.fontSize)||"14px",borderRadius:(null===(de=t.messages)||void 0===de?void 0:de.borderRadius)||8},t.messages),animation:fo({enableHover:!1!==(null===(fe=t.animation)||void 0===fe?void 0:fe.enableHover),enablePulse:!1!==(null===(pe=t.animation)||void 0===pe?void 0:pe.enablePulse),enableSlide:!1!==(null===(he=t.animation)||void 0===he?void 0:he.enableSlide),duration:(null===(ve=t.animation)||void 0===ve?void 0:ve.duration)||.3},t.animation),behavior:fo({autoOpen:(null===(ge=t.behavior)||void 0===ge?void 0:ge.autoOpen)||!1,startOpen:(null===(ye=t.behavior)||void 0===ye?void 0:ye.startOpen)||!1,hidden:(null===(me=t.behavior)||void 0===me?void 0:me.hidden)||!1,autoConnect:(null===(be=t.behavior)||void 0===be?void 0:be.autoConnect)||!1,showWelcomeMessage:!1!==(null===(we=t.behavior)||void 0===we?void 0:we.showWelcomeMessage),welcomeMessage:(null===(Se=t.behavior)||void 0===Se?void 0:Se.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:void 0===(null===(xe=t.behavior)||void 0===xe?void 0:xe.enableVoiceMode)||t.behavior.enableVoiceMode,mode:(null===(ke=t.behavior)||void 0===ke?void 0:ke.mode)||"unified"},t.behavior),accessibility:fo({ariaLabel:(null===(Ce=t.accessibility)||void 0===Ce?void 0:Ce.ariaLabel)||"Chat Assistant",ariaDescription:(null===(Pe=t.accessibility)||void 0===Pe?void 0:Pe.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(Oe=t.accessibility)||void 0===Oe?void 0:Oe.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},forceConversationId:t.forceConversationId,primaryColor:je},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.on("domainError",function(e){t.textInterface.showError(e),t.textInterface.stopStreamingState()}),this.sdk.on("error",function(e){e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))||(t.textInterface.showError(e.message||e),t.textInterface.stopStreamingState())}),this.sdk.on("chunk",function(e){t.textInterface.appendStreamingChunk(e)}),this.sdk.on("done",function(e){var n=e.text;t.textInterface.finalizeStreaming(n)})}},{key:"createWidget",value:function(){console.log("🏗️ createWidget called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var t=document.getElementById("text-chat-widget");t&&t.remove();var e=document.createElement("div");if(e.id="text-chat-widget",e.innerHTML=this.generateWidgetHTML(),document.body.appendChild(e),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("text-chat-panel");n&&(this.isOpen=!0,n.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){var t=this,e=(this.config.position,this.config.button),n=this.config.icon,o=(this.config.panel,this.config.header),r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),i={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i),s=this.config.behavior.mode||"unified",u="unified"===s,l="unified"===s||"voice-only"===s,d="unified"===s||"text-only"===s,f=function(e){var n=t.config.language||"en";return(t.translations[n]||t.translations.en)[e]||e},p=function(e){var n,o=null===(n=t.config.tooltips)||void 0===n?void 0:n[e];return null!=o?o:{newChat:f("newChat"),back:f("back"),close:f("close"),mute:f("mute"),speaker:f("speaker"),endCall:f("endCall")}[e]||""};return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header" style="background: ').concat(o.backgroundColor,"; color: ").concat(o.textColor,';">\n <div>\n ').concat(o.showTitle?'<div class="header-title">'.concat(o.title,"</div>"):"",'\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat(f("online"),'</span>\n </div>\n </div>\n \n <div style="display: flex; gap: 12px; align-items: center;">\n \x3c!-- New Chat Button (hide on landing screen, show otherwise) --\x3e\n <button class="header-icon new-chat-btn" id="newChatBtn" title="').concat(p("newChat"),'" style="').concat(u?"display: none;":"",'">\n <span style="font-size: 18px; font-weight: bold;">+</span>\n </button>\n \n \x3c!-- Back Button (only show in unified mode) --\x3e\n ').concat("unified"===s?'<button class="header-icon back-btn" id="backBtn" title="'.concat(p("back"),'" style="display: none;">\n <span style="font-size: 16px;">‹</span>\n </button>'):"","\n \n \x3c!-- Close Button --\x3e\n ").concat(o.showCloseButton?'<button class="header-icon close-btn" id="closeBtn" title="'+p("close")+'"><span style="font-size: 18px; font-weight: bold;">×</span></button>':"","\n </div>\n </div>\n\n ").concat(u?'\n <div class="landing-screen" id="landingScreen">\n <div class="landing-logo">🤖</div>\n <div class="landing-title">'.concat(f("landingTitle"),'</div>\n <div class="mode-selection">\n ').concat(l?'<div class="mode-card voice" id="mode-card-voice">\n <div class="mode-card-icon">🎤</div>\n <div class="mode-card-title">'.concat(f("voiceCall"),"</div>\n </div>"):"","\n ").concat(d?'<div class="mode-card text" id="mode-card-text">\n <div class="mode-card-icon">💬</div>\n <div class="mode-card-title">'.concat(f("textChat"),"</div>\n </div>"):"","\n </div>\n </div>"):"","\n\n ").concat(l?this.voiceInterface.generateHTML():"","\n ").concat(d?this.textInterface.generateHTML():"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var t=this.config.position,e=t.offset||{x:20,y:20},n="";return"top"===t.vertical?n+="top: ".concat(e.y,"px;"):"bottom"===t.vertical?n+="bottom: ".concat(e.y,"px;"):"center"===t.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===t.horizontal?n+="left: ".concat(e.x,"px;"):"right"===t.horizontal?n+="right: ".concat(e.x,"px;"):"center"===t.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(t){var e=this.config.icon;switch(e.type){case"custom":return'<img src="'.concat(e.customImage,'" alt="Chat Assistant" style="width: ').concat(t,"px; height: ").concat(t,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(t,'px; line-height: 1;">').concat(e.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*t),'px; font-weight: bold; color: white;">').concat(e.text,"</span>");case"microphone":default:return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>');case"chat":return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/>\n </svg>')}}},{key:"generateCSS",value:function(t,e,n){var o,r,i,a,c,s,u,l=this.config.button,d=this.config.icon,f=this.config.panel,p=this.config.header,h=(this.config.messages,this.config.animation),v=this.config.behavior.mode||"unified",g="unified"===v||"voice-only"===v,y="unified"===v||"text-only"===v,m=p.backgroundColor;return'\n /* MOBILE FIRST - Default styles for all devices */\n #text-chat-widget {\n position: fixed !important;\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n /* Mobile defaults */\n right: 10px;\n bottom: 10px;\n left: auto;\n top: auto;\n }\n \n /* Desktop positioning (only on larger screens) */\n @media (min-width: 769px) {\n #text-chat-widget {\n '.concat(t,"\n right: ").concat("right"===this.config.position.horizontal?"20px":"auto",";\n left: ").concat("left"===this.config.position.horizontal?"20px":"auto",";\n bottom: ").concat("bottom"===this.config.position.vertical?"20px":"auto",";\n top: ").concat("top"===this.config.position.vertical?"20px":"auto",";\n }\n }\n \n /* Mobile override (force mobile positioning) */\n @media (max-width: 768px) {\n #text-chat-widget {\n right: 10px !important;\n bottom: 10px !important;\n left: auto !important;\n top: auto !important;\n transform: none !important;\n }\n }\n \n @media (max-width: 480px) {\n #text-chat-widget {\n right: 8px !important;\n bottom: 8px !important;\n left: auto !important;\n top: auto !important;\n }\n }\n \n #text-chat-button {\n width: ").concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===l.shape?"50%":"square"===l.shape?"0":"12px",";\n background: ").concat(l.backgroundColor||d.backgroundColor||"#7C3AED",";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(h.duration,"s ease;\n box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);\n touch-action: manipulation;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n user-select: none;\n min-width: 44px;\n min-height: 44px;\n }\n \n @media (max-width: 768px) {\n #text-chat-widget {\n right: 10px !important;\n bottom: 10px !important;\n left: auto !important;\n top: auto !important;\n transform: none !important;\n }\n \n #text-chat-button {\n width: 56px !important;\n height: 56px !important;\n min-width: 56px !important;\n min-height: 56px !important;\n max-width: 56px !important;\n max-height: 56px !important;\n }\n \n #text-chat-panel {\n position: fixed !important;\n left: 10px !important;\n right: 10px !important;\n bottom: 76px !important; /* 56px button + 20px gap */\n top: 60px !important; /* Add top spacing */\n width: auto !important;\n max-width: none !important;\n height: auto !important; /* Change from max-height to auto */\n max-height: none !important; /* Remove max-height */\n transform: none !important;\n margin: 0 !important;\n }\n \n #text-chat-panel .widget-header {\n padding: 10px 14px;\n min-height: 56px;\n }\n \n #text-chat-panel .header-title {\n font-size: 15px;\n }\n \n #text-chat-panel .header-icon {\n width: 40px;\n height: 40px;\n min-width: 40px;\n min-height: 40px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 12px 16px !important;\n min-height: 48px !important;\n }\n \n #text-chat-send {\n min-width: 48px !important;\n min-height: 48px !important;\n width: 48px !important;\n height: 48px !important;\n }\n \n .landing-screen {\n padding: 16px;\n }\n \n .landing-logo {\n font-size: 40px;\n }\n \n .landing-title {\n font-size: 18px;\n margin-bottom: 16px;\n }\n \n .mode-selection {\n flex-direction: column;\n gap: 12px;\n align-items: center;\n }\n \n .mode-card {\n max-width: 100%;\n width: 100%;\n padding: 16px;\n }\n \n .mode-card-icon {\n width: 50px;\n height: 50px;\n font-size: 28px;\n }\n \n .mode-card-title {\n font-size: 14px;\n }\n }\n \n @media (max-width: 480px) {\n #text-chat-widget {\n right: 8px !important;\n bottom: 8px !important;\n left: auto !important;\n top: auto !important;\n }\n \n #text-chat-button {\n width: 54px !important;\n height: 54px !important;\n min-width: 54px !important;\n min-height: 54px !important;\n }\n \n #text-chat-panel {\n left: 8px !important;\n right: 8px !important;\n bottom: 70px !important;\n top: 50px !important; /* Add top spacing for very small screens */\n height: auto !important;\n max-height: none !important;\n }\n \n #text-chat-panel .widget-header {\n padding: 8px 12px;\n min-height: 52px;\n }\n \n #text-chat-panel .header-title {\n font-size: 14px;\n }\n \n .landing-logo {\n font-size: 36px;\n }\n \n .landing-title {\n font-size: 16px;\n }\n }\n \n ").concat(h.enableHover?"\n #text-chat-button:hover {\n background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);\n transform: scale(1.05);\n box-shadow: 0 8px 20px rgba(102, 126, 234, 0.5);\n }\n ":"","\n \n #text-chat-panel {\n display: none;\n position: fixed;\n bottom: calc(").concat(e,"px + 20px);\n ").concat("right"===this.config.position.horizontal?"right: 20px;":"left: 20px;","\n width: ").concat(f.width,"px;\n max-width: calc(100vw - 40px);\n height: ").concat(f.height,"px;\n max-height: calc(100vh - ").concat(e,"px - 40px);\n background: transparent;\n border-radius: ").concat(f.borderRadius,"px;\n border: none;\n flex-direction: column;\n overflow: hidden;\n ").concat(f.backdropFilter?"backdrop-filter: ".concat(f.backdropFilter,";"):"","\n ").concat(h.enableSlide?"transition: all ".concat(h.duration,"s ease;"):"","\n box-sizing: border-box;\n }\n \n #text-chat-panel.open {\n display: flex;\n ").concat(h.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n\n /* Shell for gradient border/background */\n .widget-shell { width: 100%; height: 100%; padding: 0; border-radius: ").concat(f.borderRadius,"px; background: transparent; box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; display: flex; flex-direction: column; box-sizing: border-box; }\n .panel-inner { width: 100%; height: 100%; background: #ffffff; border-radius: ").concat(f.borderRadius,"px; overflow: hidden; display:flex; flex-direction: column; padding: 0; box-sizing: border-box; max-width: 100%; }\n\n /* New structure styles matching provided design */\n #text-chat-panel .widget-container {\n width: 100%; height: 100%; min-height: 0; background: #FFFFFF; overflow: hidden; display: flex; flex-direction: column; border-radius: ").concat(f.borderRadius,"px;\n container-type: size;\n }\n \n /* Ensure content areas can scroll when height is constrained */\n #text-chat-panel .widget-container > .landing-screen,\n #text-chat-panel .widget-container > .voice-interface,\n #text-chat-panel .widget-container > .text-interface {\n flex: 1;\n min-height: 0;\n overflow-y: auto;\n overflow-x: hidden;\n }\n \n /* Header should not scroll */\n #text-chat-panel .widget-header {\n padding: 12px 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-top-left-radius: ").concat(f.borderRadius,"px;\n border-top-right-radius: ").concat(f.borderRadius,"px;\n flex-shrink: 0;\n min-height: 60px;\n box-sizing: border-box;\n }\n #text-chat-panel .header-title { font-size: 16px; font-weight: 600; }\n #text-chat-panel .header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.9; }\n #text-chat-panel .status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }\n @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n /* Header icon buttons */\n .header-icon {\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 36px;\n height: 36px;\n min-width: 36px;\n min-height: 36px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n flex-shrink: 0;\n font-size: 16px;\n padding: 0;\n box-sizing: border-box;\n }\n \n .header-icon:hover {\n background: rgba(255, 255, 255, 0.3);\n }\n \n .header-icon svg {\n pointer-events: none;\n stroke: white;\n fill: none;\n }\n \n .back-btn.visible {\n display: flex !important;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { \n display: none; \n flex: 1; \n padding: 20px; \n background: ").concat((null===(o=this.config.landing)||void 0===o?void 0:o.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)","; \n align-items: center; \n justify-content: flex-start; \n flex-direction: column; \n gap: 16px; \n overflow-y: auto; \n min-height: 0; \n }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { \n font-size: 20px; \n color: ").concat((null===(r=this.config.landing)||void 0===r?void 0:r.titleColor)||"#1e293b","; \n font-weight: 700; \n margin-bottom: 20px; \n text-align: center;\n width: 100%;\n }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { \n flex: 1; \n max-width: 180px; \n background: ").concat((null===(i=this.config.landing)||void 0===i?void 0:i.modeCardBackgroundColor)||"#FFFFFF","; \n border: 2px solid ").concat((null===(a=this.config.landing)||void 0===a?void 0:a.modeCardBorderColor)||"#E2E8F0","; \n border-radius: 20px; \n padding: 20px 12px; \n cursor: pointer; \n display: flex; \n flex-direction: column; \n align-items: center; \n gap: 8px; \n transition: transform ").concat(h.duration,"s ease, box-shadow ").concat(h.duration,"s ease, border-color ").concat(h.duration,"s ease; \n box-shadow: 0 4px 12px rgba(0,0,0,0.05); \n }\n .mode-card:hover { \n transform: translateY(-6px); \n box-shadow: 0 12px 24px rgba(102, 126, 234, 0.2); \n border-color: ").concat((null===(c=this.config.landing)||void 0===c?void 0:c.modeCardHoverBorderColor)||m,"; \n }\n .mode-card-icon { \n width: 60px; \n height: 60px; \n display: flex; \n align-items: center; \n justify-content: center; \n border-radius: 50%; \n background: ").concat((null===(s=this.config.landing)||void 0===s?void 0:s.modeCardIconBackgroundColor)||m,"; \n color: #fff; \n font-size: 32px; \n }\n .mode-card-title { \n color: ").concat((null===(u=this.config.landing)||void 0===u?void 0:u.modeCardTitleColor)||"#111827","; \n font-weight: 600; \n text-align: center;\n width: 100%;\n }\n\n ").concat(g?this.voiceInterface.generateCSS():"","\n ").concat(y?this.textInterface.generateCSS():"","\n \n #text-chat-send-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this;console.log("⚙️ setupWidgetEvents called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n"),currentView:this.currentView});var e=document.getElementById("text-chat-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("closeBtn");n&&(n.onclick=function(){return t.togglePanel()});var o=this.config.behavior.mode||"unified",r="unified"===o,i="unified"===o||"voice-only"===o,a="unified"===o||"text-only"===o,c=document.getElementById("backBtn"),s=document.getElementById("landingScreen"),u=document.getElementById("mode-card-voice"),l=document.getElementById("mode-card-text"),d=document.getElementById("textInterface"),f=document.getElementById("voiceInterface");c&&(c.onclick=function(){return t.showLanding()}),r?(u&&(u.onclick=function(){return t.showVoice()}),l&&(l.onclick=function(){return t.showText()}),"text"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.add("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="")):"voice"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.remove("active"),f&&f.classList.add("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="none")):(this.currentView="landing",s&&s.classList.add("active"),d&&d.classList.remove("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.remove("visible"))):"voice-only"===o?(f&&f.classList.add("active"),d&&d.classList.remove("active"),s&&s.classList.remove("active")):"text-only"===o&&(d&&d.classList.add("active"),f&&f.classList.remove("active"),s&&s.classList.remove("active")),i&&(console.log("⚙️ Setting up voice interface event handlers"),this.voiceInterface.setupEventHandlers()),a&&(console.log("⚙️ Setting up text interface event handlers"),this.textInterface.setupEventHandlers());var p=document.getElementById("newChatBtn");p&&(p.onclick=function(){return t.textInterface.startNewChat()},r&&(p.style.display="none")),this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"startNewChat",value:function(){this.textInterface.startNewChat()}},{key:"showLanding",value:function(){if("unified"===(this.config.behavior.mode||"unified")){this.currentView="landing";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),r&&(r.style.display="none")}}},{key:"showText",value:function(){this.currentView="text";var t=document.getElementById("landingScreen"),e=document.getElementById("voiceInterface"),n=document.getElementById("backBtn"),o=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),this.textInterface.show();var r=this.config.behavior.mode||"unified";n&&"unified"===r&&n.classList.add("visible"),o&&(o.style.display="")}},{key:"showVoice",value:function(){this.currentView="voice";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active");var i=this.config.behavior.mode||"unified";o&&"unified"===i&&o.classList.add("visible"),r&&(r.style.display="none")}},{key:"setupKeyboardNavigation",value:function(){var t=this;document.addEventListener("keydown",function(e){"Escape"===e.key&&t.isOpen&&t.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("text-chat-panel").classList.toggle("open"),this.isOpen&&setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},100),this.isOpen&&!this.isActive&&this.config.behavior.autoConnect&&this.startChat()}},{key:"startChat",value:(i=so(io().m(function t(){return io().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.textInterface.setActive(!0);case 1:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"sendMessage",value:(r=so(io().m(function t(){return io().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.textInterface.sendMessage();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=so(io().m(function t(){var e,n,o,r,i,a,c;return io().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://backend.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"addMessage",value:function(t,e){this.textInterface.addMessage(t,e)}},{key:"beginStreaming",value:function(){this.textInterface.beginStreaming()}},{key:"appendStreamingChunk",value:function(t){this.textInterface.appendStreamingChunk(t)}},{key:"finalizeStreaming",value:function(t){this.textInterface.finalizeStreaming(t)}},{key:"stopStreamingState",value:function(){this.textInterface.stopStreamingState()}},{key:"showError",value:function(t){this.textInterface.showError(t)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n,o,r,i,a,c;console.log("🔄 updateConfig called",{newConfig:t,stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var s,u,l=fo({},this.config);t.panel&&(l.panel=fo(fo({},this.config.panel),t.panel)),t.voice&&(l.voice=fo(fo({},this.config.voice),t.voice),t.voice.micButtonHint&&(l.voice.micButtonHint=fo(fo({},null===(s=this.config.voice)||void 0===s?void 0:s.micButtonHint),t.voice.micButtonHint))),t.text&&(l.text=fo(fo({},this.config.text),t.text),t.text.sendButtonHint&&(l.text.sendButtonHint=fo(fo({},null===(u=this.config.text)||void 0===u?void 0:u.sendButtonHint),t.text.sendButtonHint))),void 0!==t.language&&(l.language=t.language),void 0!==t.language&&(["he","ar"].includes(t.language)?l.direction="rtl":void 0===t.direction&&(l.direction="ltr")),t.translations&&(l.translations=t.translations,this.translations=t.translations),t.button&&(l.button=fo(fo({},this.config.button),t.button)),t.header&&(l.header=fo(fo({},this.config.header),t.header)),t.icon&&(l.icon=fo(fo({},this.config.icon),t.icon)),t.messages&&(l.messages=fo(fo({},this.config.messages),t.messages)),t.animation&&(l.animation=fo(fo({},this.config.animation),t.animation)),t.behavior&&(l.behavior=fo(fo({},this.config.behavior),t.behavior)),t.accessibility&&(l.accessibility=fo(fo({},this.config.accessibility),t.accessibility)),t.tooltips&&(l.tooltips=fo(fo({},this.config.tooltips),t.tooltips)),t.landing&&(l.landing=fo(fo({},this.config.landing),t.landing)),void 0!==t.direction&&void 0===l.direction&&(l.direction=t.direction),void 0!==t.primaryColor&&(l.primaryColor=t.primaryColor),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction","voice","text","animation","behavior","accessibility","language","tooltips","landing","primaryColor"].includes(e)||(l[e]=t[e])}),null===(e=this.config)||void 0===e||e.language,this.config=this.mergeWithDefaults(l);var d=this.config.language||"en",f=fo(fo(fo({},this.config),this.config.voice),{},{language:d,websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16});this.voiceInterface=new Jn(f);var p=fo(fo(fo({},this.config),this.config.text),{},{language:d,translations:this.translations});this.textInterface=new oo(p,this.sdk);var h=document.getElementById("text-chat-widget");h&&h.remove(),this.createWidget(),this.textInterface&&this.textInterface.updateInputAttributes&&this.textInterface.updateInputAttributes()}},{key:"destroy",value:function(){var t=document.getElementById("text-chat-widget");t&&t.remove(),this.sdk&&this.sdk.destroy(),this.voiceInterface&&this.voiceInterface.destroy()}},{key:"startVoiceCall",value:(n=so(io().m(function t(){return io().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.voiceInterface.startVoiceCall();case 1:return t.a(2)}},t,this)})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){this.voiceInterface.endVoiceCall()}},{key:"toggleMute",value:function(){this.voiceInterface.toggleMute()}},{key:"toggleSpeaker",value:function(){this.voiceInterface.toggleSpeaker()}}],e&&ho(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,r,i}(),yo="2.0.0";const mo={VoiceSDK:pt,VoiceSDK_v2:$e,TextChatSDK:dn,WebSocketManager:F,AudioRecorder:H,AudioPlayer:Z,EventEmitter:c,VoiceButton:kn,VanillaVoiceButton:Bn,AgentSDK:Ln,TTPChatWidget:go,VERSION:yo};return o})());
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==e.key&&(r=""+e.key),"key"in e)for(var i in o={},e)"key"!==i&&(o[i]=e[i]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:r,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},i.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=i.prototype;var s=c.prototype=new a;s.constructor=c,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var u={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return u.H.useEffect(t,e)},e.useRef=function(t){return u.H.useRef(t)},e.useState=function(t){return u.H.useState(t)}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>Ln,AudioPlayer:()=>tt,AudioRecorder:()=>H,EventEmitter:()=>c,TTPChatWidget:()=>yo,TextChatSDK:()=>fn,VERSION:()=>mo,VanillaVoiceButton:()=>Bn,VoiceButton:()=>Cn,VoiceSDK:()=>ht,VoiceSDK_v2:()=>Xe,WebSocketManager:()=>A,default:()=>bo});var c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||d(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=d(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function d(t,e){if(t){if("string"==typeof t)return f(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return h(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(h(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,h(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,h(d,"constructor",u),h(u,"constructor",s),s.displayName="GeneratorFunction",h(u,r,"GeneratorFunction"),h(d),h(d,r,"Generator"),h(d,o,function(){return this}),h(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:f}})()}function h(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}h=function(t,e,n,o){function i(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},h(t,e,n,o)}function v(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,y(o.key),o)}}function y(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(m=function(){return!!t})()}function b(t){return b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},b(t)}function w(t,e){return w=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},w(t,e)}const S=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=b(e),function(t,e){if(e&&("object"==s(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,m()?Reflect.construct(e,n||[],b(t).constructor):e.apply(t,n))}(this,e)).connections=new Map,t.connectionCounts=new Map,t.creatingConnections=new Set,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&w(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=p().m(function t(e){var n,o,r=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(r.connections.has(e)){var o=r.connections.get(e);r.connectionCounts.set(e,(r.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){r.creatingConnections.delete(e),r.emit("error",t,e)}),o.addEventListener("message",function(t){r.emit("message",t,e)}),t.a(2,o)}},t,this)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){v(i,n,o,a,c,"next",t)}function c(t){v(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=l(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=u(t.value,2),r=o[0],i=o[1];e[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c));function x(t){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},x(t)}function k(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return C(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(C(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,C(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,C(d,"constructor",u),C(u,"constructor",s),s.displayName="GeneratorFunction",C(u,r,"GeneratorFunction"),C(d),C(d,r,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(k=function(){return{w:i,m:f}})()}function C(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}C=function(t,e,n,o){function i(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},C(t,e,n,o)}function P(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,T(o.key),o)}}function T(t){var e=function(t){if("object"!=x(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=x(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==x(e)?e:e+""}function E(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(E=function(){return!!t})()}function j(t){return j=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},j(t)}function I(t,e){return I=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},I(t,e)}var A=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=j(e),function(t,e){if(e&&("object"==x(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,E()?Reflect.construct(e,n||[],j(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&I(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=k().m(function t(){var e=this;return k().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,S.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t(),e.connectResolve=null,e.connectReject=null)}).catch(function(t){console.error("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null})}catch(t){console.error("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null}}))},t)}),a=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){P(r,n,o,a,c,"next",t)}function c(t){P(r,n,o,a,c,"throw",t)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};S.on("open",e),S.on("close",n),S.on("error",o),S.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(S.off("open",this.eventHandlers.open),S.off("close",this.eventHandlers.close),S.off("error",this.eventHandlers.error),S.off("message",this.eventHandlers.message)),this.config.websocketUrl&&S.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(t))}catch(t){console.warn("🔌 WebSocketManager: Failed to send message:",t.message)}}},{key:"sendBinary",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(t)}catch(t){console.warn("🔌 WebSocketManager: Failed to send binary data:",t.message)}}},{key:"handleMessage",value:function(t){var e=this;if(t.data instanceof ArrayBuffer)this.emit("binaryAudio",t.data);else if(t.data instanceof Blob)t.data.arrayBuffer().then(function(t){e.emit("binaryAudio",t)}).catch(function(t){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return S.getAllConnections()}},{key:"clearAllConnections",value:function(){S.clearAll()}}],o&&O(n.prototype,o),r&&O(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a}(c);function F(t){return F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},F(t)}function D(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return B(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(B(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,B(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,B(d,"constructor",u),B(u,"constructor",s),s.displayName="GeneratorFunction",B(u,r,"GeneratorFunction"),B(d),B(d,r,"Generator"),B(d,o,function(){return this}),B(d,"toString",function(){return"[object Generator]"}),(D=function(){return{w:i,m:f}})()}function B(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}B=function(t,e,n,o){function i(e,n){B(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},B(t,e,n,o)}function R(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function _(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){R(i,o,r,a,c,"next",t)}function c(t){R(i,o,r,a,c,"throw",t)}a(void 0)})}}function U(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function M(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,z(o.key),o)}}function z(t){var e=function(t){if("object"!=F(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=F(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==F(e)?e:e+""}function N(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(N=function(){return!!t})()}function V(t){return V=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},V(t)}function L(t,e){return L=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},L(t,e)}var H=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=V(e),function(t,e){if(e&&("object"==F(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,N()?Reflect.construct(e,n||[],V(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&L(t,e)}(e,t),n=e,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var t,e=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return U(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?U(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{new URL(n);var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=_(D().m(function t(){var e,n,o=this;return D().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 1:if(this.mediaStream=t.v,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=2;break}return t.n=2,this.audioContext.resume();case 2:return e=this.getAudioProcessorPath(),t.n=3,this.audioContext.audioWorklet.addModule(e);case 3:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,n=e.type,r=e.data;"pcm_audio_data"===n&&o.emit("audioData",r)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,n=t.v,this.emit("error",n),n;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=_(D().m(function t(){var e;return D().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&M(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function K(t){return K="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},K(t)}function W(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return G(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(G(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,G(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,G(d,"constructor",u),G(u,"constructor",s),s.displayName="GeneratorFunction",G(u,r,"GeneratorFunction"),G(d),G(d,r,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(W=function(){return{w:i,m:f}})()}function G(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}G=function(t,e,n,o){function i(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},G(t,e,n,o)}function q(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Q(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){q(i,o,r,a,c,"next",t)}function c(t){q(i,o,r,a,c,"throw",t)}a(void 0)})}}function J(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Y(o.key),o)}}function Y(t){var e=function(t){if("object"!=K(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=K(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==K(e)?e:e+""}function $(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return($=function(){return!!t})()}function X(t){return X=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},X(t)}function Z(t,e){return Z=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Z(t,e)}var tt=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=X(e),function(t,e){if(e&&("object"==K(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,$()?Reflect.construct(e,n||[],X(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n.audioContextReady=!1,n.initializeAudioContext().catch(function(){}),n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Z(t,e)}(e,t),n=e,o=[{key:"initializeAudioContext",value:(i=Q(W().m(function t(){var e,n,o,r,i;return W().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.audioContext||"closed"===this.audioContext.state){t.n=1;break}return t.a(2);case 1:if(t.p=1,e=this.config.sampleRate?{sampleRate:this.config.sampleRate}:{},this.audioContext=new(window.AudioContext||window.webkitAudioContext)(e),"suspended"!==this.audioContext.state){t.n=2;break}return t.n=2,this.audioContext.resume();case 2:if("running"===this.audioContext.state)try{n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(1,.01*n,n),(r=this.audioContext.createBufferSource()).buffer=o,r.connect(this.audioContext.destination),r.start(0),r.stop(this.audioContext.currentTime+.01)}catch(t){console.debug("AudioPlayer: AudioContext warmup skipped:",t)}this.audioContextReady=!0,t.n=4;break;case 3:t.p=3,i=t.v,console.warn("AudioPlayer: Failed to pre-initialize AudioContext:",i),this.audioContextReady=!1;case 4:return t.a(2)}},t,this,[[1,3]])})),function(){return i.apply(this,arguments)})},{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);if(this.audioQueue.push(n),!this.isPlaying&&!this.isProcessingQueue&&!this.currentSource){var o=this.audioContextReady?0:50;setTimeout(function(){return e.processQueue()},o)}}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(r=Q(W().m(function t(){var e,n,o,r,i,a,c,s,u=this;return W().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext&&"closed"!==this.audioContext.state){t.n=3;break}return t.n=3,this.initializeAudioContext();case 3:if("suspended"!==(o=this.audioContext).state){t.n=5;break}return t.n=4,o.resume();case 4:if(!n){t.n=5;break}return t.n=5,new Promise(function(t){return setTimeout(t,10)});case 5:if("running"===o.state){t.n=7;break}if(console.warn("AudioPlayer: AudioContext not in running state:",o.state),"suspended"!==o.state){t.n=7;break}return t.n=6,o.resume();case 6:return t.n=7,new Promise(function(t){return setTimeout(t,10)});case 7:return t.n=8,e.arrayBuffer();case 8:return r=t.v,t.n=9,o.decodeAudioData(r);case 9:i=t.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=i,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){u.currentSource=null,u.isProcessingQueue=!1,u.audioQueue.length>0?setTimeout(function(){return u.processQueue()},0):setTimeout(function(){0!==u.audioQueue.length||u.currentSource||(u.isPlaying=!1,u.emit("playbackStopped"))},100)},c.start(),t.n=11;break;case 10:t.p=10,s=t.v,this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return u.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 11:return t.a(2)}},t,this,[[2,10]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.audioContextReady=!1}}],o&&J(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function et(t){return et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},et(t)}function nt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ot(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ot(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ot(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ot(d,"constructor",u),ot(u,"constructor",s),s.displayName="GeneratorFunction",ot(u,r,"GeneratorFunction"),ot(d),ot(d,r,"Generator"),ot(d,o,function(){return this}),ot(d,"toString",function(){return"[object Generator]"}),(nt=function(){return{w:i,m:f}})()}function ot(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ot=function(t,e,n,o){function i(e,n){ot(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ot(t,e,n,o)}function rt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function it(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){rt(i,o,r,a,c,"next",t)}function c(t){rt(i,o,r,a,c,"throw",t)}a(void 0)})}}function at(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function ct(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?at(Object(n),!0).forEach(function(e){st(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):at(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function st(t,e,n){return(e=lt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ut(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,lt(o.key),o)}}function lt(t){var e=function(t){if("object"!=et(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==et(e)?e:e+""}function dt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(dt=function(){return!!t})()}function ft(t){return ft=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ft(t)}function pt(t,e){return pt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},pt(t,e)}var ht=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=ft(e),function(t,e){if(e&&("object"==et(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,dt()?Reflect.construct(e,n||[],ft(t).constructor):e.apply(t,n))}(this,e)).config=ct({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,agentSettingsOverride:n.agentSettingsOverride||null},n),t.isConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.webSocketManager=new A(ct(ct({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new H(t.config),t.audioPlayer=new tt(t.config),t.setupEventHandlers(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&pt(t,e)}(e,t),n=e,o=[{key:"setupEventHandlers",value:function(){var t=this;this.webSocketManager.on("connected",function(){t.isConnected=!0,t.sendHelloMessage(),t.emit("connected")}),this.webSocketManager.on("disconnected",function(e){if(t.isConnected=!1,e&&1008===e.code&&e.reason&&(e.reason.includes("Domain not whitelisted")||e.reason.includes("domain")||e.reason.includes("whitelist"))){var n=new Error("DOMAIN_NOT_WHITELISTED");n.reason=e.reason,n.code=e.code,t.emit("domainError",n),t.emit("error",n)}t.isRecording&&t.stopRecording().catch(function(t){console.error("VoiceSDK: Error stopping recording on disconnect:",t)}),t.emit("disconnected",e)}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){if("greeting_audio"===e.t&&e.data)try{for(var n=atob(e.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(u=it(nt().m(function t(){var e,n;return nt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=it(nt().m(function t(){return nt().w(function(t){for(;;)switch(t.n){case 0:if(!this.isDestroyed){t.n=1;break}return t.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),t.n=2,this.connect();case 2:return t.a(2,t.v)}},t,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(c=it(nt().m(function t(){var e;return nt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw new Error("Not connected to voice server");case 1:return t.p=1,this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),t.n=2,this.audioRecorder.start();case 2:return t.a(2,!0);case 3:return t.p=3,e=t.v,console.error("❌ VoiceSDK: Failed to start recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=it(nt().m(function t(){var e;return nt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=it(nt().m(function t(){return nt().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=it(nt().m(function t(){return nt().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=ct(ct({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={t:"hello"};if(!this.config.appId){var e=new Error("appId is required for connection");return console.error("VoiceSDK: Failed to send hello message:",e),void this.emit("error",e)}t.appId=this.config.appId,this.config.agentSettingsOverride&&Object.keys(this.config.agentSettingsOverride).length>0&&(t.agentSettingsOverride=this.config.agentSettingsOverride,console.log("🔧 VoiceSDK: Sending agent settings override:",Object.keys(this.config.agentSettingsOverride)));try{this.webSocketManager.sendMessage(t)}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||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&ut(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(c);function vt(t){return vt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},vt(t)}function gt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,yt(o.key),o)}}function yt(t){var e=function(t){if("object"!=vt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=vt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==vt(e)?e:e+""}var mt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){return this.events[t]||(this.events[t]=[]),this.events[t].push(e),this}},{key:"off",value:function(t,e){return this.events[t]?(this.events[t]=this.events[t].filter(function(t){return t!==e}),this):this}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];return!!this.events[t]&&(this.events[t].forEach(function(t){t.apply(void 0,n)}),!0)}},{key:"once",value:function(t,e){var n=this,o=function(){e.apply(void 0,arguments),n.off(t,o)};return this.on(t,o)}},{key:"removeAllListeners",value:function(t){return t?delete this.events[t]:this.events={},this}}],e&&gt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();const bt=mt;function wt(t){return wt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},wt(t)}function St(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,xt(o.key),o)}}function xt(t){var e=function(t){if("object"!=wt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=wt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==wt(e)?e:e+""}const kt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCM"},(e=[{key:"decode",value:function(t){if(t instanceof ArrayBuffer)return t;if(t instanceof Uint8Array)return t.buffer;throw new Error("Invalid PCM data type")}},{key:"encode",value:function(t){return t}}])&&St(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Ct(t){return Ct="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ct(t)}function Pt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Ot(o.key),o)}}function Ot(t){var e=function(t){if("object"!=Ct(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ct(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ct(e)?e:e+""}const Tt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCMU"},(e=[{key:"decode",value:function(t){for(var e=t instanceof Uint8Array?t:new Uint8Array(t),n=new Int16Array(e.length),o=0;o<e.length;o++)n[o]=this.mulawToLinear(e[o]);return n.buffer}},{key:"encode",value:function(t){for(var e=t instanceof Int16Array?t:new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++)n[o]=this.linearToMulaw(e[o]);return n}},{key:"mulawToLinear",value:function(t){var e=1<<3+(t>>4&7);return(128&t?-1:1)*(132+(15&t)*e+(e>>1)-4)}},{key:"linearToMulaw",value:function(t){var e=t>>8&128;e&&(t=-t),t>32635&&(t=32635),t+=132;for(var n=7,o=16384;0===(t&o)&&n>0;n--,o>>=1);return 255&~(e|n<<4|t>>n+3&15)}}])&&Pt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Et(t){return Et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Et(t)}function jt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,It(o.key),o)}}function It(t){var e=function(t){if("object"!=Et(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Et(e)?e:e+""}const At=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCMA"},(e=[{key:"decode",value:function(t){for(var e=t instanceof Uint8Array?t:new Uint8Array(t),n=new Int16Array(e.length),o=0;o<e.length;o++)n[o]=this.alawToLinear(e[o]);return n.buffer}},{key:"encode",value:function(t){for(var e=t instanceof Int16Array?t:new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++)n[o]=this.linearToAlaw(e[o]);return n}},{key:"alawToLinear",value:function(t){var e=(t^=85)>>4&7,n=15&t;return(128&t?-1:1)*(0===e?8+(n<<4):264+(n<<4)<<e-1)}},{key:"linearToAlaw",value:function(t){var e,n,o=t>>8&128;if(o&&(t=-t),t>32635&&(t=32635),t<256)e=0,n=t>>4;else{e=7;for(var r=16384;0===(t&r)&&e>0;e--,r>>=1);n=t>>e+3&15}return 85^(o|e<<4|n)}}])&&jt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Ft(t){return Ft="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ft(t)}function Dt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Bt(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Bt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function Bt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function Rt(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(Ft(t)+" is not iterable")}function _t(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ut(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ut(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Ut(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ut(d,"constructor",u),Ut(u,"constructor",s),s.displayName="GeneratorFunction",Ut(u,r,"GeneratorFunction"),Ut(d),Ut(d,r,"Generator"),Ut(d,o,function(){return this}),Ut(d,"toString",function(){return"[object Generator]"}),(_t=function(){return{w:i,m:f}})()}function Ut(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Ut=function(t,e,n,o){function i(e,n){Ut(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Ut(t,e,n,o)}function Mt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function zt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Mt(i,o,r,a,c,"next",t)}function c(t){Mt(i,o,r,a,c,"throw",t)}a(void 0)})}}function Nt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Vt(o.key),o)}}function Vt(t){var e=function(t){if("object"!=Ft(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ft(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ft(e)?e:e+""}function Lt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Lt=function(){return!!t})()}function Ht(t){return Ht=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Ht(t)}function Kt(t,e){return Kt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Kt(t,e)}var Wt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=Ht(e),function(t,e){if(e&&("object"==Ft(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Lt()?Reflect.construct(e,n||[],Ht(t).constructor):e.apply(t,n))}(this,e)).config=n,t.audioContext=null,t.audioQueue=[],t.isPlaying=!1,t.isProcessingQueue=!1,t.currentSource=null,t.outputFormat=null,t.nextStartTime=0,t.scheduledBuffers=0,t.scheduledSources=new Set,t.pcmChunkQueue=[],t.preparedBuffer=[],t.isProcessingPcmQueue=!1,t.isSchedulingFrames=!1,t.MAX_LOOKAHEAD_SECONDS=.02,t.pendingSentenceText=null,t.sentenceTimings=[],t.isCheckingTranscripts=!1,t.codecs={pcm:new kt,pcmu:new Tt,pcma:new At},t.SUPPORTED_CONTAINERS=["wav","raw"],t.SUPPORTED_ENCODINGS=["pcm","pcmu","pcma"],t.SUPPORTED_SAMPLE_RATES=[8e3,16e3,22050,24e3,44100,48e3],t.SUPPORTED_BIT_DEPTHS=[8,16,24],t.SUPPORTED_CHANNELS=[1],console.log("🎵 AudioPlayer v2 initialized"),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Kt(t,e)}(e,t),n=e,o=[{key:"setOutputFormat",value:function(t){var e;this.validateFormat(t)||(console.warn("⚠️ AudioPlayer: Invalid format, using defaults:",t),t=this.getDefaultFormat());var n=null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate,o=t.sampleRate;this.outputFormat=t,console.log("✅ AudioPlayer v2: Format set:",t),this.audioContext&&n&&n!==o&&(console.warn("⚠️ AudioPlayer: Sample rate changed, recreating AudioContext"),console.warn(" Old: ".concat(n,"Hz → New: ").concat(o,"Hz")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null,console.log("ℹ️ AudioContext will be recreated on next audio chunk with correct sample rate")),this.audioContext||(this.initializeAudioContext(),this.audioContext&&"suspended"===this.audioContext.state&&this.audioContext.resume().then(function(){console.log("✅ AudioPlayer v2: AudioContext resumed and ready")}).catch(function(t){console.warn("⚠️ AudioPlayer v2: Could not resume AudioContext:",t)}))}},{key:"validateFormat",value:function(t){var e,n;if(!t)return!1;var o=null===(e=t.container)||void 0===e?void 0:e.toLowerCase(),r=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&r&&this.SUPPORTED_CONTAINERS.includes(o)&&this.SUPPORTED_ENCODINGS.includes(r)&&this.SUPPORTED_SAMPLE_RATES.includes(t.sampleRate)&&this.SUPPORTED_BIT_DEPTHS.includes(t.bitDepth)&&(!t.channels||this.SUPPORTED_CHANNELS.includes(t.channels))}},{key:"getDefaultFormat",value:function(){return{container:"raw",encoding:"pcm",sampleRate:16e3,channels:1,bitDepth:16}}},{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){console.error("❌ AudioPlayer v2: Playback error:",t),this.emit("playbackError",t)}}},{key:"playChunk",value:(c=zt(_t().m(function t(e){var n,o,r=this;return _t().w(function(t){for(;;)switch(t.n){case 0:(n=this.prepareChunk(e))?(this.preparedBuffer.push(n),(this.preparedBuffer.length<=3||this.preparedBuffer.length%10==0)&&console.log("📥 AudioPlayer: Frame received, queued: ".concat(this.preparedBuffer.length,", scheduled: ").concat(this.scheduledBuffers,", isScheduling: ").concat(this.isSchedulingFrames)),this.isSchedulingFrames?setTimeout(function(){r.preparedBuffer.length>0&&!r.isSchedulingFrames&&r.schedulePreparedFrames()},5):this.schedulePreparedFrames(),this.pcmChunkQueue.length>0&&!this.isProcessingPcmQueue&&this.processPcmQueue()):(console.error("❌ AudioPlayer: playChunk failed - prepareChunk returned null"),console.error(" pcmData length:",(null==e?void 0:e.byteLength)||"undefined"),console.error(" outputFormat:",this.outputFormat),console.error(" audioContext:",this.audioContext?"initialized":"not initialized"),console.error(" audioContext state:",(null===(o=this.audioContext)||void 0===o?void 0:o.state)||"N/A"),this.emit("playbackError",new Error("Failed to prepare PCM chunk for playback")));case 1:return t.a(2)}},t,this)})),function(t){return c.apply(this,arguments)})},{key:"prepareChunk",value:function(t){try{var e;if(!this.outputFormat)return console.error("❌ AudioPlayer: Cannot prepare chunk - outputFormat not set"),console.error(" Call setOutputFormat() before playing audio chunks"),null;if(this.audioContext||this.initializeAudioContext(),!this.audioContext)return console.error("❌ AudioPlayer: Cannot prepare chunk - AudioContext not available"),null;var n=t;if(t.byteLength%2!=0){console.warn("⚠️ Odd PCM chunk size, padding:",t.byteLength);var o=new Uint8Array(t.byteLength+1);o.set(new Uint8Array(t),0),o[t.byteLength]=0,n=o.buffer}for(var r=new Int16Array(n),i=new Float32Array(r.length),a=1/32768,c=r.length,s=0;s<c;s++)i[s]=r[s]*a;var u=(null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||this.audioContext.sampleRate,l=this.audioContext.sampleRate,d=this.audioContext.createBuffer(1,i.length,u);d.getChannelData(0).set(i);var f=d.duration,p=i.length,h=f;return l!==u&&(h=p/l),{buffer:d,duration:h,sampleRate:u,contextSampleRate:l}}catch(t){return console.error("❌ AudioPlayer: Error preparing chunk:",t),null}}},{key:"applyFadeOut",value:function(t){return t}},{key:"schedulePreparedFrames",value:(a=zt(_t().m(function t(){var e,n,o,r,i,a=this;return _t().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isSchedulingFrames){t.n=1;break}return t.a(2);case 1:if(this.isSchedulingFrames=!0,e=this.preparedBuffer.length,0===(n=Math.min(e,5))&&e>0&&(n=1),t.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:o=0,r=_t().m(function t(){var e,n,r,i,c;return _t().w(function(t){for(;;)switch(t.n){case 0:if(e=a.preparedBuffer.shift()){t.n=1;break}return t.a(2,1);case 1:(n=a.audioContext.createBufferSource()).buffer=e.buffer,n.connect(a.audioContext.destination),a.scheduledSources.add(n),r=a.audioContext.currentTime,0===a.scheduledBuffers?(a.nextStartTime<r&&(a.nextStartTime=r+a.MAX_LOOKAHEAD_SECONDS),console.log("🎵 Starting playback with minimal delay:",a.nextStartTime)):(i=r+a.MAX_LOOKAHEAD_SECONDS,a.nextStartTime<i&&(a.nextStartTime=i,console.warn("⚠️ AudioPlayer: Fell behind schedule, adjusting nextStartTime to ".concat(a.nextStartTime.toFixed(4),"s")))),a.pendingSentenceText&&(a.sentenceTimings.push({startTime:a.nextStartTime,text:a.pendingSentenceText,displayed:!1}),console.log("📝 AudioPlayer: Sentence scheduled at ".concat(a.nextStartTime.toFixed(3),'s: "').concat(a.pendingSentenceText.substring(0,40),'..."')),a.pendingSentenceText=null,a.isCheckingTranscripts||a.startTranscriptChecker()),n.start(a.nextStartTime),a.nextStartTime+=e.duration,a.nextStartTime=Math.round(1e6*a.nextStartTime)/1e6,c=a.nextStartTime-e.duration,a.scheduledBuffers<5&&(console.log("🎵 AudioPlayer: Scheduled frame ".concat(a.scheduledBuffers+1," at ").concat(c.toFixed(4),"s, next at ").concat(a.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(e.duration.toFixed(4),"s (").concat((1e3*e.duration).toFixed(2),"ms), Queued: ").concat(a.preparedBuffer.length,", Scheduled: ").concat(a.scheduledBuffers))),a.scheduledBuffers++,o++,n.onended=function(){if(a.scheduledSources.delete(n),a.scheduledBuffers--,0===a.scheduledBuffers&&0===a.preparedBuffer.length&&0===a.pcmChunkQueue.length)a.isPlaying=!1,a.isSchedulingFrames=!1,console.log("🛑 AudioPlayer: Emitting playbackStopped event (all buffers finished)"),a.emit("playbackStopped");else if(a.preparedBuffer.length>0)setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()},0);else if(a.scheduledBuffers>0){var t=function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(t,10)};setTimeout(t,10)}},a.isPlaying||(a.isPlaying=!0,console.log("🎵 AudioPlayer: Emitting playbackStarted event"),a.emit("playbackStarted"));case 2:return t.a(2)}},t)});case 4:if(!(this.preparedBuffer.length>0&&o<n)){t.n=7;break}return t.d(Rt(r()),5);case 5:if(!t.v){t.n=6;break}return t.a(3,7);case 6:t.n=4;break;case 7:this.isSchedulingFrames=!1,this.preparedBuffer.length>0&&requestAnimationFrame(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()}),this.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0&&a.schedulePreparedFrames()},10)},10),t.n=9;break;case 8:t.p=8,i=t.v,console.error("❌ AudioPlayer v2: Error scheduling frames:",i),this.emit("playbackError",i),this.isSchedulingFrames=!1;case 9:return t.a(2)}},t,this,[[2,8]])})),function(){return a.apply(this,arguments)})},{key:"processPcmQueue",value:(i=zt(_t().m(function t(){var e,n,o,r,i,a,c,s,u,l,d,f,p,h,v,g,y,m,b,w,S=this;return _t().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingPcmQueue){t.n=1;break}return t.a(2);case 1:if(this.isProcessingPcmQueue=!0,t.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:if(!(this.pcmChunkQueue.length>0)){t.n=5;break}if(o=this.pcmChunkQueue.shift()){t.n=4;break}return t.a(3,3);case 4:for(r=o,o.byteLength%2!=0&&(console.warn("⚠️ Odd PCM chunk size, padding:",o.byteLength),(i=new Uint8Array(o.byteLength+1)).set(new Uint8Array(o),0),i[o.byteLength]=0,r=i.buffer),a=new Int16Array(r),c=new Float32Array(a.length),s=1/32768,u=a.length,l=0;l<u;l++)c[l]=a[l]*s;d=(null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||this.audioContext.sampleRate,f=this.audioContext.sampleRate,null!==(n=this.outputFormat)&&void 0!==n&&n.sampleRate?this.scheduledBuffers<3&&console.log("🎵 AudioPlayer: Creating buffer at ".concat(d,"Hz (AudioContext: ").concat(f,"Hz)")):console.warn("⚠️ AudioPlayer: outputFormat.sampleRate not set! Using AudioContext sample rate:",f),(p=this.audioContext.createBuffer(1,c.length,d)).getChannelData(0).set(c),(h=this.audioContext.createBufferSource()).buffer=p,h.connect(this.audioContext.destination),v=this.audioContext.currentTime,this.nextStartTime<v&&(this.nextStartTime=v,0===this.scheduledBuffers&&console.log("🎵 Starting playback at current time:",v)),g=p.duration,y=c.length,m=g,f!==d&&(m=y/f,this.scheduledBuffers<3&&(console.log("🔄 Resampling detected: ".concat(d,"Hz → ").concat(f,"Hz")),console.log(" Buffer duration: ".concat(g.toFixed(4),"s, Calculated: ").concat(m.toFixed(4),"s")))),h.start(this.nextStartTime),this.nextStartTime+=m,this.nextStartTime=Math.round(1e6*this.nextStartTime)/1e6,this.scheduledBuffers<3&&(b=this.nextStartTime-m,console.log("🎵 AudioPlayer: Scheduled chunk ".concat(this.scheduledBuffers+1," at ").concat(b.toFixed(4),"s, next at ").concat(this.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(m.toFixed(4),"s (").concat((1e3*m).toFixed(2),"ms)"))),this.scheduledBuffers++,h.onended=function(){S.scheduledBuffers--,0===S.scheduledBuffers&&0===S.pcmChunkQueue.length&&(S.isPlaying=!1,S.isProcessingPcmQueue=!1,S.emit("playbackStopped"))},this.isPlaying||(this.isPlaying=!0,this.emit("playbackStarted")),t.n=3;break;case 5:this.isProcessingPcmQueue=!1,t.n=7;break;case 6:t.p=6,w=t.v,console.error("❌ AudioPlayer v2: Error playing chunk:",w),this.emit("playbackError",w),this.isProcessingPcmQueue=!1;case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return i.apply(this,arguments)})},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);console.log("🎵 AudioPlayer: Processing ".concat(e.length," bytes")),console.log("🎵 AudioPlayer: Negotiated format:",this.outputFormat);var n=this.outputFormat&&this.outputFormat.container&&"wav"===this.outputFormat.container.toLowerCase(),o=this.outputFormat&&this.outputFormat.container&&"raw"===this.outputFormat.container.toLowerCase(),r=this.isWavFile(e);if(r&&console.log("🎵 AudioPlayer: Data has WAV header (RIFF)"),o&&r)return console.error("❌ AudioPlayer: CRITICAL MISMATCH!"),console.error(" Negotiated format: RAW"),console.error(" Actual data: WAV (RIFF header detected)"),console.error(" Backend is ignoring format request and sending WAV anyway."),console.warn("⚠️ AudioPlayer: Processing as WAV to avoid playback failure, but UI configuration was bypassed."),this.handleWavFile(e);if(o&&!r)console.log("🎵 AudioPlayer: Processing as RAW data (as negotiated)");else{if(n&&r)return console.log("✅ AudioPlayer: Processing as WAV file (matches negotiation)"),this.handleWavFile(e);if(n&&!r)return console.warn("⚠️ AudioPlayer: Negotiated WAV but data lacks WAV header. Attempting WAV processing anyway."),this.handleWavFile(e);if(!this.outputFormat&&r)return console.log("🎵 AudioPlayer: No format negotiated, auto-detecting WAV"),this.handleWavFile(e);this.outputFormat||r||(console.warn("⚠️ AudioPlayer: No format negotiated and data not WAV, using defaults"),this.outputFormat=this.getDefaultFormat())}return this.outputFormat||(console.warn("⚠️ AudioPlayer: No format set, using defaults"),this.outputFormat=this.getDefaultFormat()),console.log("🎵 AudioPlayer: Processing as RAW data with encoding:",this.outputFormat.encoding),this.handleRawData(e)}},{key:"isWavFile",value:function(t){return t.length>=44&&82===t[0]&&73===t[1]&&70===t[2]&&70===t[3]}},{key:"handleWavFile",value:function(t){var e=this.parseWavHeader(t);if(console.log("🎵 WAV file detected:",{format:e.audioFormat,encoding:this.getEncodingName(e.audioFormat),sampleRate:e.sampleRate,channels:e.channels,bitDepth:e.bitsPerSample}),1===e.audioFormat)return console.log("✅ PCM WAV - using directly"),new Blob([t],{type:"audio/wav"});var n=this.getCodecForWavFormat(e.audioFormat);if(!n)throw new Error("Unsupported WAV format code: ".concat(e.audioFormat));console.log("🔄 Non-PCM WAV - converting to PCM WAV");var o=t.slice(44),r=n.decode(o),i=this.createWavHeader(r.byteLength,e.sampleRate,e.channels,16);return new Blob([i,r],{type:"audio/wav"})}},{key:"handleRawData",value:function(t){var e,n,o=this.outputFormat.encoding.toLowerCase(),r=this.getCodec(o);if(!r)throw new Error("No codec found for encoding: ".concat(o));if(console.log("🎵 AudioPlayer: Decoding ".concat(o.toUpperCase()," to PCM")),console.log("🎵 AudioPlayer: Input format - bitDepth: ".concat(this.outputFormat.bitDepth,", sampleRate: ").concat(this.outputFormat.sampleRate)),"pcm"===o){var i=this.outputFormat.bitDepth||16;t.length,24===i?(console.warn("⚠️ AudioPlayer: Format says 24-bit PCM, but browser support is limited."),console.warn(" Treating as 16-bit PCM. If audio sounds wrong, backend should send 16-bit instead."),e=this.convert24BitTo16Bit(t),n=16):8===i?(console.log("🔄 AudioPlayer: Converting 8-bit PCM to 16-bit PCM"),e=this.convert8BitTo16Bit(t),n=16):(e=t.buffer,n=i,console.log("✅ AudioPlayer: Using native ".concat(i,"-bit PCM (no conversion needed)")))}else e=r.decode(t),n=16,console.log("🔄 AudioPlayer: Decoded ".concat(o.toUpperCase()," to 16-bit PCM"));var a=this.createWavHeader(e.byteLength,this.outputFormat.sampleRate,this.outputFormat.channels,n);return new Blob([a,e],{type:"audio/wav"})}},{key:"convert24BitTo16Bit",value:function(t){for(var e=Math.floor(t.length/3),n=new Int16Array(e),o=0;o<e;o++){var r=t[3*o],i=t[3*o+1],a=t[3*o+2],c=r|i<<8|(255&a)<<16;128&a&&(c|=4278190080),n[o]=Math.max(-32768,Math.min(32767,Math.round(c/256)))}return n.buffer}},{key:"convert8BitTo16Bit",value:function(t){for(var e=t.length,n=new Int16Array(e),o=0;o<e;o++){var r=t[o];n[o]=256*(r-128)}return n.buffer}},{key:"getCodec",value:function(t){var e={pcm:"pcm",linear:"pcm",l16:"pcm",pcmu:"pcmu",ulaw:"pcmu",mulaw:"pcmu",g711u:"pcmu",pcma:"pcma",alaw:"pcma",g711a:"pcma"}[t.toLowerCase()];return this.codecs[e]}},{key:"getCodecForWavFormat",value:function(t){switch(t){case 1:return this.codecs.pcm;case 6:return this.codecs.pcma;case 7:return this.codecs.pcmu;default:return null}}},{key:"getEncodingName",value:function(t){switch(t){case 1:return"PCM";case 6:return"A-law";case 7:return"μ-law";default:return"Unknown (".concat(t,")")}}},{key:"parseWavHeader",value:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{audioFormat:e.getUint16(20,!0),channels:e.getUint16(22,!0),sampleRate:e.getUint32(24,!0),byteRate:e.getUint32(28,!0),blockAlign:e.getUint16(32,!0),bitsPerSample:e.getUint16(34,!0)}}},{key:"createWavHeader",value:function(t,e,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+t,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,e,!0),i.setUint32(28,e*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0),r}},{key:"initializeAudioContext",value:function(){var t,e,n=(null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate)||48e3;if(48e3!==n&&44100!==n&&(console.log("ℹ️ AudioPlayer: Backend requested ".concat(n,"Hz, but browser may resample to 48kHz")),console.log(" Consider requesting 48kHz from backend to avoid resampling and improve quality")),this.audioContext){var o=this.audioContext.sampleRate;if(!(Math.abs(o-n)>100))return;console.warn("⚠️ AudioPlayer: AudioContext sample rate (".concat(o,"Hz) doesn't match format (").concat(n,"Hz), recreating...")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null}console.log("🎵 AudioPlayer: Creating AudioContext at ".concat(n,"Hz (from outputFormat: ").concat((null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||"not set",")"));try{this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n,latencyHint:"playback"}),console.log("✅ AudioContext created at ".concat(this.audioContext.sampleRate,"Hz (requested: ").concat(n,"Hz)")),Math.abs(this.audioContext.sampleRate-n)>100?(console.error("❌ CRITICAL: Browser sample rate mismatch!"),console.error(" Requested: ".concat(n,"Hz")),console.error(" Got: ".concat(this.audioContext.sampleRate,"Hz")),console.error(" This WILL cause audio distortion/noise!"),console.error(" Solution: Backend should send ".concat(this.audioContext.sampleRate,"Hz audio instead"))):this.audioContext.sampleRate!==n&&(console.warn("⚠️ Browser adjusted sample rate: ".concat(n,"Hz → ").concat(this.audioContext.sampleRate,"Hz")),console.warn(" Browser will automatically resample audio."))}catch(t){console.error("❌ Failed to create AudioContext:",t),this.audioContext=new(window.AudioContext||window.webkitAudioContext),console.log("ℹ️ Using browser default: ".concat(this.audioContext.sampleRate,"Hz"))}}},{key:"processQueue",value:(r=zt(_t().m(function t(){var e,n,o,r,i,a,c,s,u=this;return _t().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||this.initializeAudioContext(),"suspended"!==(o=this.audioContext).state){t.n=4;break}return t.n=3,o.resume();case 3:if(!n){t.n=4;break}return t.n=4,new Promise(function(t){return setTimeout(t,50)});case 4:if("running"===o.state){t.n=8;break}if(console.warn("AudioPlayer v2: AudioContext not in running state:",o.state),"suspended"!==o.state){t.n=8;break}return t.n=5,o.resume();case 5:if(!n){t.n=7;break}return t.n=6,new Promise(function(t){return setTimeout(t,50)});case 6:t.n=8;break;case 7:return t.n=8,new Promise(function(t){return setTimeout(t,10)});case 8:return t.n=9,e.arrayBuffer();case 9:return r=t.v,t.n=10,o.decodeAudioData(r);case 10:i=t.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=i,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){u.currentSource=null,u.isProcessingQueue=!1,u.audioQueue.length>0?setTimeout(function(){return u.processQueue()},50):setTimeout(function(){0!==u.audioQueue.length||u.currentSource||(u.isPlaying=!1,u.emit("playbackStopped"))},100)},c.start(),t.n=12;break;case 11:t.p=11,s=t.v,console.error("❌ AudioPlayer v2: Error processing queue:",s),this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return u.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 12:return t.a(2)}},t,this,[[2,11]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"reset",value:function(){this.stop(),this.audioQueue=[],this.pcmChunkQueue=[]}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource||this.scheduledSources.size>0;if(console.log("🛑 AudioPlayer.stopImmediate() called"),console.log(" isPlaying:",this.isPlaying),console.log(" currentSource:",null!==this.currentSource),console.log(" scheduledSources.size:",this.scheduledSources.size),console.log(" scheduledBuffers:",this.scheduledBuffers),this.currentSource){try{console.log(" Stopping currentSource..."),this.currentSource.stop()}catch(t){console.log(" currentSource already stopped or error:",t.message)}this.currentSource=null}if(this.scheduledSources.size>0){console.log(" Stopping ".concat(this.scheduledSources.size," scheduled sources..."));var e,n=0,o=Dt(this.scheduledSources);try{for(o.s();!(e=o.n()).done;){var r=e.value;try{r.stop(),n++}catch(t){console.log(" Source already stopped or not started:",t.message)}}}catch(t){o.e(t)}finally{o.f()}console.log(" Stopped ".concat(n," sources")),this.scheduledSources.clear()}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],this.pcmChunkQueue=[],this.preparedBuffer=[],this.isProcessingPcmQueue=!1,this.isSchedulingFrames=!1,this.nextStartTime=0,this.scheduledBuffers=0,this.clearTranscriptState(),t&&(console.log("🛑 AudioPlayer: Emitting playbackStopped event (stopImmediate called)"),this.emit("playbackStopped"))}},{key:"markNewSentence",value:function(t){this.pendingSentenceText=t,console.log('📝 AudioPlayer: New sentence marked: "'.concat(t.substring(0,40),'..."'))}},{key:"startTranscriptChecker",value:function(){var t=this;if(!this.isCheckingTranscripts){this.isCheckingTranscripts=!0,console.log("📝 AudioPlayer: Transcript checker started");var e=function(){if(t.isCheckingTranscripts&&t.audioContext){var n,o=t.audioContext.currentTime,r=Dt(t.sentenceTimings);try{for(r.s();!(n=r.n()).done;){var i=n.value;!i.displayed&&o>=i.startTime&&(i.displayed=!0,console.log("📝 AudioPlayer: Display transcript at ".concat(o.toFixed(3),'s: "').concat(i.text.substring(0,40),'..."')),t.emit("transcriptDisplay",{text:i.text}))}}catch(t){r.e(t)}finally{r.f()}t.isPlaying||t.scheduledBuffers>0?requestAnimationFrame(e):(t.isCheckingTranscripts=!1,console.log("📝 AudioPlayer: Transcript checker stopped"))}};requestAnimationFrame(e)}}},{key:"clearTranscriptState",value:function(){this.pendingSentenceText=null,this.sentenceTimings=[],this.isCheckingTranscripts=!1,console.log("📝 AudioPlayer: Transcript state cleared")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed",outputFormat:this.outputFormat,scheduledBuffers:this.scheduledBuffers,preparedBufferLength:this.preparedBuffer.length,scheduledSourcesCount:this.scheduledSources.size}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.removeAllListeners()}}],o&&Nt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c}(bt);const Gt=Wt;function qt(t){return qt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},qt(t)}function Qt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Jt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Jt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Jt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Jt(d,"constructor",u),Jt(u,"constructor",s),s.displayName="GeneratorFunction",Jt(u,r,"GeneratorFunction"),Jt(d),Jt(d,r,"Generator"),Jt(d,o,function(){return this}),Jt(d,"toString",function(){return"[object Generator]"}),(Qt=function(){return{w:i,m:f}})()}function Jt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Jt=function(t,e,n,o){function i(e,n){Jt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Jt(t,e,n,o)}function Yt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function $t(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Yt(i,o,r,a,c,"next",t)}function c(t){Yt(i,o,r,a,c,"throw",t)}a(void 0)})}}function Xt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function Zt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,te(o.key),o)}}function te(t){var e=function(t){if("object"!=qt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=qt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==qt(e)?e:e+""}function ee(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ee=function(){return!!t})()}function ne(t){return ne=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ne(t)}function oe(t,e){return oe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},oe(t,e)}var re=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=ne(e),function(t,e){if(e&&("object"==qt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ee()?Reflect.construct(e,n||[],ne(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&oe(t,e)}(e,t),n=e,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var t,e=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Xt(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Xt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=$t(Qt().m(function t(){var e,n,o,r,i,a,c=this;return Qt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,"https:"===location.protocol||"localhost"===location.hostname||"127.0.0.1"===location.hostname){t.n=1;break}throw e=new Error("Microphone access requires HTTPS. Please use https:// or test on localhost."),console.error("❌ AudioRecorder:",e.message),this.emit("error",e),e;case 1:if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){t.n=2;break}throw n=new Error("getUserMedia is not supported in this browser. Please use a modern browser."),console.error("❌ AudioRecorder:",n.message),this.emit("error",n),n;case 2:return console.log("🎤 AudioRecorder: Requesting microphone access..."),t.n=3,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 3:if(this.mediaStream=t.v,console.log("✅ AudioRecorder: Microphone access granted"),this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=4;break}return t.n=4,this.audioContext.resume();case 4:return o=this.getAudioProcessorPath(),t.n=5,this.audioContext.audioWorklet.addModule(o);case 5:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,n=e.type,o=e.data;"pcm_audio_data"===n&&c.emit("audioData",o)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=7;break;case 6:throw t.p=6,a=t.v,r=a.message,"NotAllowedError"===a.name||"PermissionDeniedError"===a.name?(r="Microphone permission denied. Please allow microphone access in your browser settings and try again.",console.error("❌ AudioRecorder: Permission denied. User needs to grant microphone access.")):"NotFoundError"===a.name||"DevicesNotFoundError"===a.name?(r="No microphone found. Please connect a microphone and try again.",console.error("❌ AudioRecorder: No microphone device found.")):"NotReadableError"===a.name||"TrackStartError"===a.name?(r="Microphone is already in use by another application. Please close other apps using the microphone and try again.",console.error("❌ AudioRecorder: Microphone is busy or not readable.")):a.message&&a.message.includes("not allowed by the user agent")&&(r="Microphone access blocked. On mobile devices, please tap the recording button directly (not from an iframe or popup).",console.error("❌ AudioRecorder: User agent blocked microphone access. This often happens on mobile when not called from direct user interaction.")),(i=new Error(r)).name=a.name,i.originalError=a,console.error("❌ AudioRecorder: Failed to start recording:",i),this.emit("error",i),i;case 7:return t.a(2)}},t,this,[[0,6]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=$t(Qt().m(function t(){var e;return Qt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&Zt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(bt);function ie(t){return ie="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ie(t)}function ae(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ce(o.key),o)}}function ce(t){var e=function(t){if("object"!=ie(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ie(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ie(e)?e:e+""}const se=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"extractPcmFromWav",value:function(t){var e=t instanceof Uint8Array?t:new Uint8Array(t);if(e.length<44)throw new Error("WAV data too short (< 44 bytes)");if("RIFF"!==String.fromCharCode(e[0],e[1],e[2],e[3]))throw new Error("Not a valid WAV file - missing RIFF header");if("WAVE"!==String.fromCharCode(e[8],e[9],e[10],e[11]))throw new Error("Not a valid WAV file - missing WAVE format");for(var n=e[22]|e[23]<<8,o=e[24]|e[25]<<8|e[26]<<16|e[27]<<24,r=e[34]|e[35]<<8,i=-1,a=12;a<e.length-8;a+=4){if("data"===String.fromCharCode(e[a],e[a+1],e[a+2],e[a+3])){i=a;break}a+=4+(e[a+4]|e[a+5]<<8|e[a+6]<<16|e[a+7]<<24)}if(-1===i)throw new Error("No data chunk found in WAV");var c=e[i+4]|e[i+5]<<8|e[i+6]<<16|e[i+7]<<24,s=i+8,u=Math.min(c,e.length-s);return{pcmData:e.slice(s,s+u).buffer,format:{sampleRate:o,channels:n,bitDepth:r}}}},{key:"isWavFile",value:function(t){return t.length>=44&&82===t[0]&&73===t[1]&&70===t[2]&&70===t[3]}},{key:"createWavHeader",value:function(t,e,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+t,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,e,!0),i.setUint32(28,e*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0),r}},{key:"wrapPcmInWav",value:function(e,n){var o=t.createWavHeader(e.byteLength,n.sampleRate,n.channels||1,n.bitDepth||16),r=new Uint8Array(o.byteLength+e.byteLength);return r.set(new Uint8Array(o),0),r.set(new Uint8Array(e),o.byteLength),r.buffer}}],null&&ae(e.prototype,null),n&&ae(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function ue(t){return ue="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ue(t)}function le(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,de(o.key),o)}}function de(t){var e=function(t){if("object"!=ue(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ue(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ue(e)?e:e+""}const fe=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.codecs={pcm:new kt,pcmu:new Tt,pcma:new At}},(e=[{key:"decodeToPcm",value:function(t,e){var n=null==e?void 0:e.toLowerCase();if(!n||"pcm"===n)return t instanceof ArrayBuffer?t:t instanceof Uint8Array?t.buffer:t;var o=this.codecs[n];if(!o)throw new Error("Unsupported encoding: ".concat(e));var r=t instanceof Uint8Array?t:new Uint8Array(t);return o.decode(r)}},{key:"encodeFromPcm",value:function(t,e){var n=null==e?void 0:e.toLowerCase();if(!n||"pcm"===n)return t;var o=this.codecs[n];if(!o)throw new Error("Unsupported target encoding: ".concat(e));var r=o.encode(t);return r instanceof Uint8Array?r.buffer:r}},{key:"getCodec",value:function(t){var e=null==t?void 0:t.toLowerCase();return this.codecs[e]||null}}])&&le(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function pe(t){return pe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},pe(t)}function he(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ve(o.key),o)}}function ve(t){var e=function(t){if("object"!=pe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=pe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==pe(e)?e:e+""}const ge=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"convert",value:function(e,n,o){if(n===o)return e;if(8===n)throw new Error("Source bit depth cannot be 8-bit (only 16-bit or 24-bit supported)");var r=n/8,i=o/8,a=e.byteLength/r;if(new ArrayBuffer(a*i),16===n&&16===o)return e;if(24===n&&16===o)return t.convert24To16(e);if(16===n&&24===o)return t.convert16To24(e);if(16===n&&8===o)return t.convert16To8(e);if(24===n&&8===o)return t.convert24To8(e);throw new Error("Unsupported bit depth conversion: ".concat(n,"-bit → ").concat(o,"-bit"))}},{key:"convert24To16",value:function(t){for(var e=new Uint8Array(t),n=Math.floor(e.length/3),o=new Int16Array(n),r=0;r<n;r++){var i=e[3*r],a=e[3*r+1],c=e[3*r+2],s=i|a<<8|(255&c)<<16;128&c&&(s|=4278190080),o[r]=Math.max(-32768,Math.min(32767,Math.round(s/256)))}return o.buffer}},{key:"convert16To24",value:function(t){for(var e=new Int16Array(t),n=new Uint8Array(3*e.length),o=0;o<e.length;o++){var r=256*e[o];n[3*o]=255&r,n[3*o+1]=r>>8&255,n[3*o+2]=r>>16&255}return n.buffer}},{key:"convert16To8",value:function(t){for(var e=new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++){var r=e[o];n[o]=Math.max(0,Math.min(255,Math.round(r/256+128)))}return n.buffer}},{key:"convert24To8",value:function(e){var n=t.convert24To16(e);return t.convert16To8(n)}}],null&&he(e.prototype,null),n&&he(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function ye(t){return ye="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ye(t)}function me(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return be(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(be(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,be(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,be(d,"constructor",u),be(u,"constructor",s),s.displayName="GeneratorFunction",be(u,r,"GeneratorFunction"),be(d),be(d,r,"Generator"),be(d,o,function(){return this}),be(d,"toString",function(){return"[object Generator]"}),(me=function(){return{w:i,m:f}})()}function be(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}be=function(t,e,n,o){function i(e,n){be(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},be(t,e,n,o)}function we(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Se(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,xe(o.key),o)}}function xe(t){var e=function(t){if("object"!=ye(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ye(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ye(e)?e:e+""}const ke=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"resample",value:(n=me().m(function t(e,n,o){var r,i,a,c,s,u,l,d,f,p,h,v,g;return me().w(function(t){for(;;)switch(t.n){case 0:if(n!==o){t.n=1;break}return t.a(2,e);case 1:for(r=new Int16Array(e),i=new Float32Array(r.length),a=1/32768,c=0;c<r.length;c++)i[c]=r[c]*a;return s=Math.ceil(i.length*o/n),u=new OfflineAudioContext(1,s,o),(l=u.createBuffer(1,i.length,n)).getChannelData(0).set(i),(d=u.createBufferSource()).buffer=l,d.connect(u.destination),d.start(),t.n=2,u.startRendering();case 2:for(f=t.v,p=f.getChannelData(0),h=new Int16Array(p.length),v=0;v<p.length;v++)g=Math.max(-1,Math.min(1,p[v])),h[v]=Math.round(32767*g);return t.a(2,h.buffer)}},t)}),o=function(){var t=this,e=arguments;return new Promise(function(o,r){var i=n.apply(t,e);function a(t){we(i,o,r,a,c,"next",t)}function c(t){we(i,o,r,a,c,"throw",t)}a(void 0)})},function(t,e,n){return o.apply(this,arguments)})}],e&&Se(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Ce(t){return Ce="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ce(t)}function Pe(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Oe(o.key),o)}}function Oe(t){var e=function(t){if("object"!=Ce(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ce(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ce(e)?e:e+""}const Te=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"convert",value:function(e,n,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(n===o)return e;if(1===n&&1===o)return e;if(1===n&&2===o)return t.monoToStereo(e,r);if(2===n&&1===o)return t.stereoToMono(e,r);throw new Error("Unsupported channel conversion: ".concat(n," → ").concat(o))}},{key:"monoToStereo",value:function(t,e){for(var n=e/8,o=t.byteLength/n,r=new ArrayBuffer(o*n*2),i=new Uint8Array(t),a=new Uint8Array(r),c=0;c<o;c++)for(var s=c*n,u=c*n*2,l=0;l<n;l++)a[u+l]=i[s+l],a[u+n+l]=i[s+l];return r}},{key:"stereoToMono",value:function(t,e){var n=e/8,o=t.byteLength/(2*n),r=new ArrayBuffer(o*n),i=new Uint8Array(t),a=new Uint8Array(r);if(16===e)for(var c=0;c<o;c++){var s=c*n*2,u=s+n,l=(i[s]|i[s+1]<<8)<<16>>16,d=(i[u]|i[u+1]<<8)<<16>>16,f=Math.round((l+d)/2),p=c*n;a[p]=255&f,a[p+1]=f>>8&255}else for(var h=0;h<o;h++)for(var v=h*n*2,g=h*n,y=0;y<n;y++)a[g+y]=i[v+y];return r}}],null&&Pe(e.prototype,null),n&&Pe(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function Ee(t){return Ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ee(t)}function je(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ie(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ie(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Ie(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ie(d,"constructor",u),Ie(u,"constructor",s),s.displayName="GeneratorFunction",Ie(u,r,"GeneratorFunction"),Ie(d),Ie(d,r,"Generator"),Ie(d,o,function(){return this}),Ie(d,"toString",function(){return"[object Generator]"}),(je=function(){return{w:i,m:f}})()}function Ie(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Ie=function(t,e,n,o){function i(e,n){Ie(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Ie(t,e,n,o)}function Ae(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Fe(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ae(Object(n),!0).forEach(function(e){De(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ae(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function De(t,e,n){return(e=_e(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Be(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Re(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,_e(o.key),o)}}function _e(t){var e=function(t){if("object"!=Ee(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ee(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ee(e)?e:e+""}const Ue=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.requestedFormat=e,this.actualFormat=n,this.encodingConverter=new fe,this.conversionSteps=[],this._analyzeConversions()},e=[{key:"_analyzeConversions",value:function(){this.conversionSteps=[],this.actualFormat.container!==this.requestedFormat.container&&("wav"===this.actualFormat.container?this.conversionSteps.push("extract_wav"):"wav"===this.requestedFormat.container&&this.conversionSteps.push("wrap_wav")),this.actualFormat.encoding!==this.requestedFormat.encoding&&("pcm"!==this.actualFormat.encoding&&this.conversionSteps.push("decode_encoding"),"pcm"!==this.requestedFormat.encoding&&this.conversionSteps.push("encode_encoding")),this.actualFormat.sampleRate!==this.requestedFormat.sampleRate&&this.conversionSteps.push("resample"),this.actualFormat.bitDepth!==this.requestedFormat.bitDepth&&this.conversionSteps.push("convert_bitdepth"),this.actualFormat.channels!==this.requestedFormat.channels&&this.conversionSteps.push("convert_channels")}},{key:"needsConversion",value:function(){return this.conversionSteps.length>0}},{key:"getConversionSteps",value:function(){var t=[];return this.conversionSteps.includes("extract_wav")&&t.push("Extract PCM from WAV (".concat(this.actualFormat.container," → raw)")),this.conversionSteps.includes("decode_encoding")&&t.push("Decode ".concat(this.actualFormat.encoding.toUpperCase()," → PCM")),this.conversionSteps.includes("resample")&&t.push("Resample ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz")),this.conversionSteps.includes("convert_bitdepth")&&t.push("Convert bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit")),this.conversionSteps.includes("convert_channels")&&t.push("Convert channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels)),this.conversionSteps.includes("encode_encoding")&&t.push("Encode PCM → ".concat(this.requestedFormat.encoding.toUpperCase())),this.conversionSteps.includes("wrap_wav")&&t.push("Wrap in WAV container (raw → ".concat(this.requestedFormat.container,")")),t}},{key:"convert",value:(n=je().m(function t(e){var n,o,r,i;return je().w(function(t){for(;;)switch(t.n){case 0:if(this.needsConversion()){t.n=1;break}return t.a(2,e instanceof ArrayBuffer?e:e.buffer);case 1:if(n=e instanceof ArrayBuffer?e:e.buffer,o=Fe({},this.actualFormat),this.conversionSteps.includes("extract_wav")&&(r=se.extractPcmFromWav(n),n=r.pcmData,o=Fe(Fe({},o),{},{container:"raw",sampleRate:r.format.sampleRate,channels:r.format.channels,bitDepth:r.format.bitDepth}),console.log("🔄 AudioFormatConverter: Extracted PCM from WAV",r.format)),this.conversionSteps.includes("decode_encoding")&&(n=this.encodingConverter.decodeToPcm(n,o.encoding),o.encoding="pcm",o.bitDepth=16,console.log("🔄 AudioFormatConverter: Decoded ".concat(this.actualFormat.encoding.toUpperCase()," → PCM"))),24===o.bitDepth&&o.bitDepth!==this.requestedFormat.bitDepth&&(this.conversionSteps.includes("resample")||this.conversionSteps.includes("convert_channels")||24!==this.requestedFormat.bitDepth)&&(n=ge.convert(n,24,16),o.bitDepth=16,console.log("🔄 AudioFormatConverter: Normalized 24-bit → 16-bit PCM")),!this.conversionSteps.includes("resample")){t.n=3;break}return t.n=2,ke.resample(n,o.sampleRate,this.requestedFormat.sampleRate);case 2:n=t.v,o.sampleRate=this.requestedFormat.sampleRate,console.log("🔄 AudioFormatConverter: Resampled ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz"));case 3:return this.conversionSteps.includes("convert_channels")&&(n=Te.convert(n,o.channels,this.requestedFormat.channels,o.bitDepth),o.channels=this.requestedFormat.channels,console.log("🔄 AudioFormatConverter: Converted channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels))),this.conversionSteps.includes("convert_bitdepth")&&(n=ge.convert(n,o.bitDepth,this.requestedFormat.bitDepth),o.bitDepth=this.requestedFormat.bitDepth,console.log("🔄 AudioFormatConverter: Converted bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit"))),this.conversionSteps.includes("encode_encoding")&&(i=this.encodingConverter.encodeFromPcm(n,this.requestedFormat.encoding),n=i instanceof ArrayBuffer?i:i.buffer,o.encoding=this.requestedFormat.encoding,console.log("🔄 AudioFormatConverter: Encoded PCM → ".concat(this.requestedFormat.encoding.toUpperCase()))),this.conversionSteps.includes("wrap_wav")&&(n=se.wrapPcmInWav(n,o),o.container="wav",console.log("🔄 AudioFormatConverter: Wrapped in WAV container")),console.log("✅ AudioFormatConverter: Conversion complete"),t.a(2,n)}},t,this)}),o=function(){var t=this,e=arguments;return new Promise(function(o,r){var i=n.apply(t,e);function a(t){Be(i,o,r,a,c,"next",t)}function c(t){Be(i,o,r,a,c,"throw",t)}a(void 0)})},function(t){return o.apply(this,arguments)})}],e&&Re(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Me(t){return Me="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Me(t)}function ze(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Ne(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ze(Object(n),!0).forEach(function(e){Je(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ze(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ve(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Le(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Le(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Le(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Le(d,"constructor",u),Le(u,"constructor",s),s.displayName="GeneratorFunction",Le(u,r,"GeneratorFunction"),Le(d),Le(d,r,"Generator"),Le(d,o,function(){return this}),Le(d,"toString",function(){return"[object Generator]"}),(Ve=function(){return{w:i,m:f}})()}function Le(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Le=function(t,e,n,o){function i(e,n){Le(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Le(t,e,n,o)}function He(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Ke(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){He(i,o,r,a,c,"next",t)}function c(t){He(i,o,r,a,c,"throw",t)}a(void 0)})}}function We(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Ye(o.key),o)}}function Ge(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Ge=function(){return!!t})()}function qe(t){return qe=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},qe(t)}function Qe(t,e){return Qe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Qe(t,e)}function Je(t,e,n){return(e=Ye(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Ye(t){var e=function(t){if("object"!=Me(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Me(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Me(e)?e:e+""}var $e=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=qe(e),function(t,e){if(e&&("object"==Me(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Ge()?Reflect.construct(e,n||[],qe(t).constructor):e.apply(t,n))}(this,e)).version="2.0.0",t.config={websocketUrl:n.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:n.agentId,appId:n.appId,sampleRate:n.sampleRate||16e3,channels:n.channels||1,bitDepth:n.bitDepth||16,audioProcessorPath:n.audioProcessorPath,outputContainer:n.outputContainer||t.getDefaultContainer(n),outputEncoding:n.outputEncoding||n.outputCodec||"pcm",outputSampleRate:n.outputSampleRate||16e3,outputChannels:n.outputChannels||1,outputBitDepth:n.outputBitDepth||16,outputFrameDurationMs:n.outputFrameDurationMs||600,outputCodec:n.outputCodec,agentSettingsOverride:n.agentSettingsOverride||null,variables:n.variables||null,autoReconnect:!1!==n.autoReconnect,protocolVersion:n.protocolVersion||2},t.isConnected=!1,t.hasEverConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.outputAudioFormat=null,t.requestedOutputFormat=null,t.formatConverter=null,t.websocket=null,t.conversationId=null,t.audioPlayer=new Gt(t.config),t.audioRecorder=new re(t.config),t.setupAudioPlayerEvents(),t.setupAudioRecorderEvents(),t.validateConfig(),console.log("🎵 VoiceSDK v2 initialized:",{version:t.version,outputContainer:t.config.outputContainer,outputEncoding:t.config.outputEncoding,outputSampleRate:t.config.outputSampleRate}),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Qe(t,e)}(e,t),n=e,o=[{key:"getDefaultContainer",value:function(t){return"wav"===t.outputCodec?"wav":"raw"}},{key:"validateInputFormat",value:function(t){var n;if(!t)return"Input format is required";var o=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&e.SUPPORTED_INPUT_ENCODINGS.includes(o)?t.sampleRate&&e.SUPPORTED_INPUT_SAMPLE_RATES.includes(t.sampleRate)?t.bitDepth&&e.SUPPORTED_INPUT_BIT_DEPTHS.includes(t.bitDepth)?t.channels&&e.SUPPORTED_INPUT_CHANNELS.includes(t.channels)?null:"Unsupported input channels: ".concat(t.channels,". Supported: ").concat(e.SUPPORTED_INPUT_CHANNELS.join(", ")):"Unsupported input bit depth: ".concat(t.bitDepth,". Supported: ").concat(e.SUPPORTED_INPUT_BIT_DEPTHS.join(", ")):"Unsupported input sample rate: ".concat(t.sampleRate,". Supported: ").concat(e.SUPPORTED_INPUT_SAMPLE_RATES.join(", ")):"Unsupported input encoding: ".concat(t.encoding,". Supported: ").concat(e.SUPPORTED_INPUT_ENCODINGS.join(", "))}},{key:"validateOutputFormat",value:function(t){var n,o;if(!t)return"Output format is required";var r=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();if(!r||!e.SUPPORTED_OUTPUT_ENCODINGS.includes(r))return"Unsupported output encoding: ".concat(t.encoding,". Supported: ").concat(e.SUPPORTED_OUTPUT_ENCODINGS.join(", "));if(!t.sampleRate||!e.SUPPORTED_OUTPUT_SAMPLE_RATES.includes(t.sampleRate))return"Unsupported output sample rate: ".concat(t.sampleRate,". Supported: ").concat(e.SUPPORTED_OUTPUT_SAMPLE_RATES.join(", "));if(!t.bitDepth||!e.SUPPORTED_OUTPUT_BIT_DEPTHS.includes(t.bitDepth))return"Unsupported output bit depth: ".concat(t.bitDepth,". Supported: ").concat(e.SUPPORTED_OUTPUT_BIT_DEPTHS.join(", "));if(!t.channels||!e.SUPPORTED_OUTPUT_CHANNELS.includes(t.channels))return"Unsupported output channels: ".concat(t.channels,". Supported: ").concat(e.SUPPORTED_OUTPUT_CHANNELS.join(", "));var i=null===(o=t.container)||void 0===o?void 0:o.toLowerCase();return i&&e.SUPPORTED_OUTPUT_CONTAINERS.includes(i)?null:"Unsupported output container: ".concat(t.container,". Supported: ").concat(e.SUPPORTED_OUTPUT_CONTAINERS.join(", "))}},{key:"validateConfig",value:function(){var t={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},e=this.validateInputFormat(t);if(e)return console.error("❌ VoiceSDK v2: Invalid input format:",e),void this.emit("error",new Error(e));var n={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},o=this.validateOutputFormat(n);if(o)return console.error("❌ VoiceSDK v2: Invalid output format:",o),void this.emit("error",new Error(o));console.log("✅ VoiceSDK v2: Format validation passed")}},{key:"setupAudioPlayerEvents",value:function(){var t=this;this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_started_playing message to server"),t.sendMessage({t:"audio_started_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_started_playing - not connected")}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_stopped_playing message to server"),t.sendMessage({t:"audio_stopped_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_stopped_playing - not connected")}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)}),this.audioPlayer.on("transcriptDisplay",function(e){t.emit("transcriptDisplay",{text:e.text,role:"assistant",final:!0,timestamp:Date.now()})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e),t.emit("error",e)})}},{key:"setupAudioRecorderEvents",value:function(){var t=this;this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0;var e=t.audioPlayer.getStatus(),n=e.scheduledBuffers&&e.scheduledBuffers>0||e.scheduledSourcesCount&&e.scheduledSourcesCount>0,o=t.isPlaying||e.isPlaying||n;console.log("🎤 VoiceSDK v2: Recording started - checking for barge-in..."),console.log(" VoiceSDK.isPlaying:",t.isPlaying),console.log(" AudioPlayer.isPlaying:",e.isPlaying),console.log(" scheduledBuffers:",e.scheduledBuffers||0),console.log(" scheduledSourcesCount:",e.scheduledSourcesCount||0),console.log(" preparedBufferLength:",e.preparedBufferLength||0),console.log(" isActuallyPlaying:",o),o?(console.log("🛑 VoiceSDK v2: Barge-in detected! Stopping audio playback..."),t.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),t.isConnected?(t.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")):console.warn("⚠️ VoiceSDK v2: Cannot send barge_in - not connected")):console.log("ℹ️ VoiceSDK v2: No audio playing, normal recording start"),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t._bargeInChecked=!1,t.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped")}),this.audioRecorder.on("audioData",function(e){if(!t._bargeInChecked&&t.isRecording){t._bargeInChecked=!0;var n=t.audioPlayer.getStatus(),o=n.scheduledBuffers&&n.scheduledBuffers>0||n.scheduledSourcesCount&&n.scheduledSourcesCount>0;(t.isPlaying||n.isPlaying||o)&&(console.log("🛑 VoiceSDK v2: Barge-in detected on first audio data! Stopping audio playback..."),console.log(" VoiceSDK.isPlaying:",t.isPlaying),console.log(" AudioPlayer.isPlaying:",n.isPlaying),console.log(" scheduledBuffers:",n.scheduledBuffers||0),console.log(" scheduledSourcesCount:",n.scheduledSourcesCount||0),t.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),t.isConnected&&(t.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")))}t.isConnected&&t.sendBinary(e)}),this.audioRecorder.on("error",function(e){console.error("❌ AudioRecorder error:",e),t.emit("error",e)})}},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),e.toString()){var n=t.includes("?")?"&":"?";return"".concat(t).concat(n).concat(e.toString())}return t}},{key:"connect",value:(u=Ke(Ve().m(function t(){var e,n,o=this;return Ve().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK v2: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:if(!this.isConnected){t.n=2;break}return console.warn("VoiceSDK v2: Already connected"),t.a(2,!0);case 2:return t.p=2,e=this.buildWebSocketUrl(),console.log("🔌 VoiceSDK v2: Connecting to",e),t.n=3,new Promise(function(t,n){o.websocket=new WebSocket(e),o.websocket.onopen=function(){console.log("✅ VoiceSDK v2: WebSocket connected"),o.isConnected=!0,o.hasEverConnected=!0,o.sendHelloMessage(),o.emit("connected"),t(!0)},o.websocket.onerror=function(t){console.error("❌ VoiceSDK v2: WebSocket error:",t),n(t)},o.websocket.onclose=function(t){console.log("🔌 VoiceSDK v2: WebSocket closed:",t.code,t.reason),o.isConnected=!1,o.isRecording&&o.stopRecording().catch(function(t){return console.error("Error stopping recording:",t)}),o.emit("disconnected",t),o.config.autoReconnect&&!o.isDestroyed&&o.hasEverConnected?(console.log("🔄 VoiceSDK v2: Auto-reconnecting in 3s..."),setTimeout(function(){o.isDestroyed||o.isConnected||o.connect()},3e3)):o.config.autoReconnect&&!o.hasEverConnected&&console.log("⚠️ VoiceSDK v2: Initial connection failed. Auto-reconnect disabled to prevent retry loop.")},o.websocket.onmessage=function(t){o.handleMessage(t)}});case 3:return t.a(2,t.v);case 4:return t.p=4,n=t.v,console.error("🔌 VoiceSDK v2: Connection failed:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[2,4]])})),function(){return u.apply(this,arguments)})},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},e={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},n=this.validateInputFormat(t);if(n)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid input format:",n),void this.emit("error",new Error("Invalid input format: ".concat(n)));var o=this.validateOutputFormat(e);if(o)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid output format:",o),void this.emit("error",new Error("Invalid output format: ".concat(o)));var r={t:"hello",v:this.config.protocolVersion,inputFormat:t,requestedOutputFormat:e,outputFrameDurationMs:this.config.outputFrameDurationMs};this.config.agentSettingsOverride&&(r.agentSettingsOverride=this.config.agentSettingsOverride),console.log("🔍 VoiceSDK v2: Checking variables:",{hasVariables:!!this.config.variables,variables:this.config.variables,keys:this.config.variables?Object.keys(this.config.variables):[]}),this.config.variables&&Object.keys(this.config.variables).length>0?(r.variables=this.config.variables,console.log("📝 VoiceSDK v2: Including variables in hello:",Object.keys(this.config.variables))):console.log("⚠️ VoiceSDK v2: Variables NOT included - condition failed"),console.log("📤 VoiceSDK v2: Sending hello:",{version:r.v,requestedFormat:r.requestedOutputFormat,variables:r.variables?Object.keys(r.variables):void 0}),console.log("📤 VoiceSDK v2: Requested output format:",{container:r.requestedOutputFormat.container,encoding:r.requestedOutputFormat.encoding,sampleRate:r.requestedOutputFormat.sampleRate,bitDepth:r.requestedOutputFormat.bitDepth}),console.log("📤 VoiceSDK v2: Full hello message being sent:",JSON.stringify(r,null,2));try{this.sendMessage(r)}catch(t){console.error("VoiceSDK v2: Failed to send hello:",t),this.emit("error",t)}}else console.warn("VoiceSDK v2: Cannot send hello - not connected")}},{key:"handleMessage",value:function(t){if(t.data instanceof ArrayBuffer||t.data instanceof Blob)this.handleBinaryMessage(t.data);else try{var e=JSON.parse(t.data);switch(console.log("📥 VoiceSDK v2: Received message:",e.t,"Full message:",e),!this.conversationId&&e.conversationId&&(this.conversationId=e.conversationId,console.log("🔍 VoiceSDK v2: Captured conversationId from message:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),e.t){case"hello_ack":this.handleHelloAck(e);break;case"pong":this.handlePong(e);break;case"audio_start":this.handleAudioStart(e);break;case"transcript":this.handleTranscript(e);break;case"user_transcript":case"agent_response":case"error":this.emit("message",e);break;case"barge_in":this.emit("bargeIn",e),this.stopAudioPlayback();break;case"stop_playing":this.emit("stopPlaying",e),this.stopAudioPlayback();break;default:console.log("VoiceSDK v2: Unknown message type:",e.t,"Full message:",e),this.emit("message",e)}}catch(t){console.error("VoiceSDK v2: Error parsing message:",t)}}},{key:"handleAudioStart",value:function(t){var e=t.text||"";console.log('▶️ VoiceSDK v2: audio_start "'.concat(e.substring(0,40),'..."')),this.emit("transcript",{text:e,role:"assistant",final:!0,timestamp:Date.now()}),this.audioPlayer.markNewSentence(e)}},{key:"handleHelloAck",value:function(t){if(console.log("📥 VoiceSDK v2: Received hello_ack:",{hasOutputFormat:!!t.outputAudioFormat,outputFormat:t.outputAudioFormat,hasConversationId:!!t.conversationId,messageType:t.t}),t.conversationId&&(this.conversationId=t.conversationId,console.log("🔍 VoiceSDK v2: Received conversationId:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),t.outputAudioFormat){this.outputAudioFormat=t.outputAudioFormat,this.audioPlayer.setOutputFormat(t.outputAudioFormat),console.log("✅ VoiceSDK v2: Format negotiated by server:",this.outputAudioFormat),this.requestedOutputFormat={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1};var e={container:this.outputAudioFormat.container||"unknown",encoding:this.outputAudioFormat.encoding||"unknown",sampleRate:this.outputAudioFormat.sampleRate||0,bitDepth:this.outputAudioFormat.bitDepth||0,channels:this.outputAudioFormat.channels||0},n=[];if(this.requestedOutputFormat.container!==e.container&&n.push('container: "'.concat(this.requestedOutputFormat.container,'" → "').concat(e.container,'"')),this.requestedOutputFormat.encoding!==e.encoding&&n.push('encoding: "'.concat(this.requestedOutputFormat.encoding,'" → "').concat(e.encoding,'"')),this.requestedOutputFormat.sampleRate!==e.sampleRate&&n.push("sampleRate: ".concat(this.requestedOutputFormat.sampleRate,"Hz → ").concat(e.sampleRate,"Hz")),this.requestedOutputFormat.bitDepth!==e.bitDepth&&n.push("bitDepth: ".concat(this.requestedOutputFormat.bitDepth,"-bit → ").concat(e.bitDepth,"-bit")),this.requestedOutputFormat.channels!==e.channels&&n.push("channels: ".concat(this.requestedOutputFormat.channels," → ").concat(e.channels)),n.length>0){console.warn("⚠️ VoiceSDK v2: Format negotiation mismatch!"),console.warn(" Requested:",this.requestedOutputFormat),console.warn(" Negotiated:",e),console.warn(" Differences:",n.join(", "));try{if(this.formatConverter=new Ue(this.requestedOutputFormat,e),this.formatConverter.needsConversion()){var o=this.formatConverter.getConversionSteps();console.log("🔄 VoiceSDK v2: Format conversion enabled"),console.log(" Conversion steps:",o.join(", ")),console.log(" Audio will be automatically converted to requested format")}}catch(t){console.error("❌ VoiceSDK v2: Failed to create format converter:",t),console.warn(" Will use backend format without conversion"),this.formatConverter=null}}else console.log("✅ VoiceSDK v2: Format perfectly matched!",e),this.formatConverter=null;this.emit("formatNegotiated",this.outputAudioFormat)}else{this.config.protocolVersion>=2?(console.warn("⚠️ VoiceSDK v2: hello_ack received but no outputAudioFormat in response."),console.warn(" This may happen if:"),console.warn(" 1. Backend is not sending outputAudioFormat (check backend logs)"),console.warn(" 2. Hello message missing v2 fields (v, inputFormat, requestedOutputFormat)"),console.warn(" 3. Backend validation failed (check backend error logs)"),console.warn(" Using default format from config...")):console.log("✅ VoiceSDK v2: Connected (v1 legacy mode)");var r={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,channels:this.config.outputChannels||1,bitDepth:this.config.outputBitDepth||16};this.outputAudioFormat=r,this.requestedOutputFormat=r,this.audioPlayer.setOutputFormat(r),this.formatConverter=null}}},{key:"handleTranscript",value:function(t){var e={text:t.text||"",role:t.role||"assistant",sentenceId:t.sentenceId||null,final:!1!==t.final,timestamp:t.timestamp||Date.now()};e.text?(console.log("📝 VoiceSDK v2: [".concat(e.role,'] "').concat(e.text.substring(0,50),'..."')),this.emit("transcript",e)):console.warn("⚠️ VoiceSDK v2: Empty transcript received")}},{key:"handleBinaryMessage",value:(s=Ke(Ve().m(function t(e){var n,o,r,i,a,c,s,u,l,d;return Ve().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!(e instanceof Blob)){t.n=2;break}return t.n=1,e.arrayBuffer();case 1:o=t.v,t.n=3;break;case 2:o=e;case 3:if(console.log("📥 VoiceSDK v2: Received audio:",o.byteLength,"bytes"),console.log(" Current outputFormat:",this.outputAudioFormat),console.log(" AudioPlayer outputFormat:",null===(n=this.audioPlayer)||void 0===n?void 0:n.outputFormat),console.log(" Format converter:",this.formatConverter?"active":"none"),r=o,!this.formatConverter||!this.formatConverter.needsConversion()){t.n=7;break}return t.p=4,t.n=5,this.formatConverter.convert(o);case 5:r=t.v,console.log("✅ VoiceSDK v2: Audio converted to requested format"),t.n=7;break;case 6:t.p=6,d=t.v,console.error("❌ VoiceSDK v2: Format conversion failed:",d),console.warn(" Using backend format without conversion"),r=o;case 7:i=this.formatConverter&&this.formatConverter.needsConversion()?this.requestedOutputFormat:this.outputAudioFormat||{container:this.config.outputContainer||"raw",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1},a=i.container||"raw",c=(i.encoding||"pcm").toLowerCase(),"raw"===a?(s=r,"pcm"!==c&&((u=this.audioPlayer.getCodec(c))?(l=u.decode(new Uint8Array(r)),s=l.buffer,console.log("🔄 VoiceSDK v2: Decoded ".concat(c.toUpperCase()," to PCM (").concat(l.byteLength," bytes)"))):console.warn("⚠️ VoiceSDK v2: No codec for ".concat(c,", treating as PCM"))),this.audioPlayer.outputFormat||(console.warn("⚠️ VoiceSDK v2: outputFormat not set on AudioPlayer, setting from playbackFormat"),this.audioPlayer.setOutputFormat(i)),this.audioPlayer.playChunk(s)):this.audioPlayer.playAudio(r);case 8:return t.a(2)}},t,this,[[4,6]])})),function(t){return s.apply(this,arguments)})},{key:"sendMessage",value:function(t){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send message - not connected"),!1;try{return this.websocket.send(JSON.stringify(t)),!0}catch(t){return console.error("VoiceSDK v2: Error sending message:",t),this.emit("error",t),!1}}},{key:"sendBinary",value:function(t){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send audio - not connected"),!1;try{return this.websocket.send(t),!0}catch(t){return console.error("VoiceSDK v2: Error sending audio:",t),this.emit("error",t),!1}}},{key:"disconnect",value:function(){this.isDestroyed||(console.log("🔌 VoiceSDK v2: Disconnecting..."),this.stopRecording(),this.audioPlayer&&this.stopAudioPlayback(),this.websocket&&(this.websocket.close(),this.websocket=null),this.isConnected=!1)}},{key:"startRecording",value:(c=Ke(Ve().m(function t(){var e,n;return Ve().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw e=new Error("Not connected to voice server"),this.emit("error",e),e;case 1:if(!this.isRecording){t.n=2;break}return console.warn("VoiceSDK v2: Already recording"),t.a(2,!0);case 2:return console.log("🎤 VoiceSDK v2: Starting recording..."),t.p=3,console.log("🎤 VoiceSDK v2: Requesting microphone permission (mobile-friendly)..."),t.n=4,this.audioRecorder.start();case 4:return this.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId()}),t.a(2,!0);case 5:return t.p=5,n=t.v,console.error("❌ VoiceSDK v2: Failed to start recording:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[3,5]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=Ke(Ve().m(function t(){var e;return Ve().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return console.warn("VoiceSDK v2: Not recording"),t.a(2,!0);case 1:return console.log("🛑 VoiceSDK v2: Stopping recording..."),t.p=2,this.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=3,this.audioRecorder.stop();case 3:return this.stopAudioPlayback(),t.a(2,!0);case 4:return t.p=4,e=t.v,console.error("VoiceSDK v2: Error stopping recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[2,4]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=Ke(Ve().m(function t(){return Ve().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"clearTranscriptState",value:function(){this.audioPlayer&&this.audioPlayer.clearTranscriptState(),console.log("📝 VoiceSDK v2: Transcript state cleared")}},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate(),this.clearTranscriptState()}},{key:"handleBargeIn",value:(r=Ke(Ve().m(function t(){return Ve().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{version:this.version,isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying,outputFormat:this.outputAudioFormat,conversationId:this.conversationId,audioPlayer:this.audioPlayer.getStatus(),audioRecorder:this.audioRecorder.getStatus()}}},{key:"updateConfig",value:function(t){this.config=Ne(Ne({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"destroy",value:function(){this.isDestroyed||(console.log("🗑️ VoiceSDK v2: Destroying..."),this.disconnect(),this.isDestroyed=!0,this.audioPlayer&&this.audioPlayer.destroy(),this.audioRecorder&&this.audioRecorder.destroy(),this.removeAllListeners())}}],o&&We(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(bt);Je($e,"SUPPORTED_INPUT_ENCODINGS",["pcm","pcmu","pcma"]),Je($e,"SUPPORTED_INPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),Je($e,"SUPPORTED_INPUT_BIT_DEPTHS",[8,16,24]),Je($e,"SUPPORTED_INPUT_CHANNELS",[1]),Je($e,"SUPPORTED_OUTPUT_ENCODINGS",["pcm","pcmu","pcma"]),Je($e,"SUPPORTED_OUTPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),Je($e,"SUPPORTED_OUTPUT_BIT_DEPTHS",[8,16,24]),Je($e,"SUPPORTED_OUTPUT_CHANNELS",[1]),Je($e,"SUPPORTED_OUTPUT_CONTAINERS",["raw","wav"]);const Xe=$e;function Ze(t){return Ze="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ze(t)}function tn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return en(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(en(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,en(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,en(d,"constructor",u),en(u,"constructor",s),s.displayName="GeneratorFunction",en(u,r,"GeneratorFunction"),en(d),en(d,r,"Generator"),en(d,o,function(){return this}),en(d,"toString",function(){return"[object Generator]"}),(tn=function(){return{w:i,m:f}})()}function en(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}en=function(t,e,n,o){function i(e,n){en(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},en(t,e,n,o)}function nn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function on(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function rn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?on(Object(n),!0).forEach(function(e){an(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):on(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function an(t,e,n){return(e=sn(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function cn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,sn(o.key),o)}}function sn(t){var e=function(t){if("object"!=Ze(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ze(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ze(e)?e:e+""}function un(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(un=function(){return!!t})()}function ln(t){return ln=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ln(t)}function dn(t,e){return dn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},dn(t,e)}var fn=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=(t=function(t,e,n){return e=ln(e),function(t,e){if(e&&("object"==Ze(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,un()?Reflect.construct(e,n||[],ln(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=rn({baseWsUrl:"wss://backend.talktopc.com/chat/websocket",appId:n.appId||o.appId,agentId:n.agentId||o.agentId,conversationId:void 0!==n.conversationId?n.conversationId:t.getPersistedConversationId(),forceConversationId:n.forceConversationId,queue:[],inFlight:!1},n),t.fullResponseBuffer="",t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&dn(t,e)}(e,t),n=e,o=[{key:"readScriptTagConfig",value:function(){try{var t=Array.from(document.getElementsByTagName("script")).reverse().find(function(t){return t.dataset&&(t.dataset.appId||t.dataset.agentId)||t.src&&t.src.includes("agent-widget")});return t?{appId:t.dataset.appId,agentId:t.dataset.agentId}:{}}catch(t){return{}}}},{key:"buildWebSocketUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,e=new URLSearchParams;return this.config.appId&&e.append("appId",this.config.appId),this.config.agentId&&e.append("agentId",this.config.agentId),this.config.conversationId&&e.append("conversationId",this.config.conversationId),"".concat(t,"?").concat(e.toString())}},{key:"sendMessage",value:(r=tn().m(function t(e){var n=this;return tn().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,o){if(e&&e.trim())if(n.config.appId&&n.config.agentId){var r={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(r):n.executeTask(r)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){nn(i,n,o,a,c,"next",t)}function c(t){nn(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"executeTask",value:function(t){var e=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,r=this.buildWebSocketUrl(this.config.baseWsUrl),i=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(i),c=!1,s=!1,u=null,l=function(n){if(!s)try{var o={message:t.text},r=e.config.forceConversationId||e.config.conversationId;r&&(o.conversationId=r,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=r,e.persistConversationId(r))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",e.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){t.reject(o),e.emit("error",o);try{n.close()}catch(t){}}},d=function(t){return function(){e.config.conversationId?l(t):u=setTimeout(function(){return l(t)},200)}},f=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(t){}var r=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",r)}catch(t){}if("hello"===r.type&&r.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId),e.emit&&e.emit("conversationIdChanged",r.conversationId),!s&&n&&1===n.readyState){if(u)try{clearTimeout(u)}catch(t){}l(n)}return}if(!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId)),"chunk"===r.type&&"string"==typeof r.content)e.fullResponseBuffer+=r.content,e.emit("chunk",r.content);else if("done"===r.type){try{var i=r.text||r.content||r.answer||r.message||"";i&&!e.fullResponseBuffer&&(e.fullResponseBuffer=i)}catch(t){}!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",r.conversationId),e.config.conversationId=r.conversationId),e.persistConversationId(e.config.conversationId),e.emit("done",{text:e.fullResponseBuffer}),t.resolve({conversationId:e.config.conversationId,fullText:e.fullResponseBuffer});try{n.close()}catch(t){}}else if("error"===r.type){var a=new Error(r.message||"Server error");e.emit("error",a),t.reject(a);try{n.close()}catch(t){}}}catch(t){}}},p=function(n){if(1008===n.code&&n.reason&&(n.reason.includes("Domain not whitelisted")||n.reason.includes("domain")||n.reason.includes("whitelist"))){var o=new Error("DOMAIN_NOT_WHITELISTED");return o.reason=n.reason,o.code=n.code,e.emit("domainError",o),t.reject(o),e.config.inFlight=!1,void e.drainQueue()}e.config.inFlight=!1,e.drainQueue()},h=new WebSocket(r);h.onopen=d(h),h.onmessage=f(h),h.onerror=(o=h,function(n){if(!c){c=!0;try{o.close()}catch(t){}var r=new WebSocket(a);return r.onopen=d(r),r.onmessage=f(r),r.onerror=function(n){e.emit("error",n),t.reject(n)},void(r.onclose=p)}e.emit("error",n),t.reject(n)}),h.onclose=p}},{key:"drainQueue",value:function(){if(0!==this.config.queue.length&&!this.config.inFlight){var t=this.config.queue.shift();this.executeTask(t)}}},{key:"persistConversationId",value:function(t){try{t&&localStorage.setItem("ttp_text_chat_conversation_id",t)}catch(t){}}},{key:"getPersistedConversationId",value:function(){try{return localStorage.getItem("ttp_text_chat_conversation_id")||null}catch(t){return null}}},{key:"updateConfig",value:function(t){this.config=rn(rn({},this.config),t)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&cn(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c),pn=n(540),hn=n(848);function vn(t){return vn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},vn(t)}function gn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function yn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?gn(Object(n),!0).forEach(function(e){mn(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function mn(t,e,n){return(e=function(t){var e=function(t){if("object"!=vn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=vn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==vn(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function bn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return wn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(wn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,wn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,wn(d,"constructor",u),wn(u,"constructor",s),s.displayName="GeneratorFunction",wn(u,r,"GeneratorFunction"),wn(d),wn(d,r,"Generator"),wn(d,o,function(){return this}),wn(d,"toString",function(){return"[object Generator]"}),(bn=function(){return{w:i,m:f}})()}function wn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}wn=function(t,e,n,o){function i(e,n){wn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},wn(t,e,n,o)}function Sn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function xn(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return kn(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?kn(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function kn(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}const Cn=function(t){var e=t.websocketUrl,n=t.agentId,o=t.appId,r=t.voice,i=void 0===r?"default":r,a=t.language,c=void 0===a?"en":a,s=t.autoReconnect,u=void 0===s||s,l=t.agentSettingsOverride,d=void 0===l?null:l,f=t.onConnected,p=t.onDisconnected,h=t.onRecordingStarted,v=t.onRecordingStopped,g=t.onPlaybackStarted,y=t.onPlaybackStopped,m=t.onError,b=t.onMessage,w=t.onBargeIn,S=t.onStopPlaying,x=t.className,k=void 0===x?"":x,C=t.style,P=void 0===C?{}:C,O=t.children,T=xn((0,pn.useState)(!1),2),E=T[0],j=T[1],I=xn((0,pn.useState)(!1),2),A=I[0],F=I[1],D=xn((0,pn.useState)(!1),2),B=(D[0],D[1]),R=xn((0,pn.useState)("Disconnected"),2),_=(R[0],R[1]),U=(0,pn.useRef)(null);(0,pn.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),U.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),U.current.destroy(),U.current=null);var t=new ht({websocketUrl:e,agentId:n,appId:o,voice:i,language:c,autoReconnect:u,agentSettingsOverride:d});return t.on("connected",function(){j(!0),_("Connected"),null==f||f()}),t.on("disconnected",function(){j(!1),_("Disconnected"),null==p||p()}),t.on("recordingStarted",function(){F(!0),null==h||h()}),t.on("recordingStopped",function(){F(!1),null==v||v()}),t.on("playbackStarted",function(){B(!0),null==g||g()}),t.on("playbackStopped",function(){B(!1),null==y||y()}),t.on("error",function(t){null==m||m(t)}),t.on("message",function(t){null==b||b(t)}),t.on("bargeIn",function(t){null==w||w(t)}),t.on("stopPlaying",function(t){null==S||S(t)}),U.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),U.current&&(U.current.destroy(),U.current=null)}},[e,n,o,i,c,d]);var M=function(){var t,e=(t=bn().m(function t(){var e;return bn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(U.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,U.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Sn(i,o,r,a,c,"next",t)}function c(t){Sn(i,o,r,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),z=(0,hn.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,hn.jsx)("div",{style:{fontSize:"20px"},children:A?"🔴":"🎤"}),(0,hn.jsx)("div",{children:A?"Stop Listening":"Start Listening"})]});return(0,hn.jsx)("button",{className:"voice-button ".concat(A?"recording":""," ").concat(k),style:yn({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:A?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},P),onClick:M,disabled:!E,children:O||z})};function Pn(t){return Pn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Pn(t)}function On(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Tn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Tn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Tn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Tn(d,"constructor",u),Tn(u,"constructor",s),s.displayName="GeneratorFunction",Tn(u,r,"GeneratorFunction"),Tn(d),Tn(d,r,"Generator"),Tn(d,o,function(){return this}),Tn(d,"toString",function(){return"[object Generator]"}),(On=function(){return{w:i,m:f}})()}function Tn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Tn=function(t,e,n,o){function i(e,n){Tn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Tn(t,e,n,o)}function En(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function jn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){En(i,o,r,a,c,"next",t)}function c(t){En(i,o,r,a,c,"throw",t)}a(void 0)})}}function In(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function An(t,e,n){return(e=Dn(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Fn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Dn(o.key),o)}}function Dn(t){var e=function(t){if("object"!=Pn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Pn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Pn(e)?e:e+""}var Bn=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?In(Object(n),!0).forEach(function(e){An(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):In(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({websocketUrl:e.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:e.agentId,voice:e.voice||"default",language:e.language||"en",container:e.container||document.body,buttonText:e.buttonText||"Start Listening",buttonClass:e.buttonClass||"voice-button"},e),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new ht({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},e=[{key:"setupEventListeners",value:function(){var t=this;this.voiceSDK.on("connected",function(){var e,n;t.isConnected=!0,t.updateButton(),null===(e=(n=t.options).onConnected)||void 0===e||e.call(n)}),this.voiceSDK.on("disconnected",function(){var e,n;t.isConnected=!1,t.updateButton(),null===(e=(n=t.options).onDisconnected)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStarted",function(){var e,n;t.isRecording=!0,t.updateButton(),null===(e=(n=t.options).onRecordingStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStopped",function(){var e,n;t.isRecording=!1,t.updateButton(),null===(e=(n=t.options).onRecordingStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStarted",function(){var e,n;t.isPlaying=!0,null===(e=(n=t.options).onPlaybackStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStopped",function(){var e,n;t.isPlaying=!1,null===(e=(n=t.options).onPlaybackStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("error",function(e){var n,o;null===(n=(o=t.options).onError)||void 0===n||n.call(o,e)}),this.voiceSDK.on("message",function(e){var n,o;null===(n=(o=t.options).onMessage)||void 0===n||n.call(o,e)}),this.voiceSDK.on("bargeIn",function(e){var n,o;null===(n=(o=t.options).onBargeIn)||void 0===n||n.call(o,e)}),this.voiceSDK.on("stopPlaying",function(e){var n,o;null===(n=(o=t.options).onStopPlaying)||void 0===n||n.call(o,e)})}},{key:"createButton",value:function(){var t=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return t.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var t=this.isRecording?"🔴":"🎤",e=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(t,"</span>\n <span>").concat(e,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=jn(On().m(function t(){var e;return On().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.voiceSDK.connect();case 1:t.n=3;break;case 2:t.p=2,e=t.v,console.error("Failed to connect:",e);case 3:return t.a(2)}},t,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=jn(On().m(function t(){var e;return On().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.voiceSDK){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,this.voiceSDK.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.voiceSDK.updateConfig(t)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],e&&Fn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Rn(t){return Rn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Rn(t)}function _n(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Un(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Un(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Un(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Un(d,"constructor",u),Un(u,"constructor",s),s.displayName="GeneratorFunction",Un(u,r,"GeneratorFunction"),Un(d),Un(d,r,"Generator"),Un(d,o,function(){return this}),Un(d,"toString",function(){return"[object Generator]"}),(_n=function(){return{w:i,m:f}})()}function Un(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Un=function(t,e,n,o){function i(e,n){Un(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Un(t,e,n,o)}function Mn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function zn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Mn(i,o,r,a,c,"next",t)}function c(t){Mn(i,o,r,a,c,"throw",t)}a(void 0)})}}function Nn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Vn(o.key),o)}}function Vn(t){var e=function(t){if("object"!=Rn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Rn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Rn(e)?e:e+""}var Ln=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),console.log("🚀 AgentSDK v2.1.8 initialized with config:",e),this.config=e,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(t){return console.error("SDK Error:",t)},this.onTranscript=function(t){},this.onAgentSpeaking=function(t){}},e=[{key:"connect",value:(o=zn(_n().m(function t(e){var n,o=this;return _n().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,e){t.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new Xe({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en",protocolVersion:2,outputContainer:this.config.outputContainer||"raw",outputEncoding:this.config.outputEncoding||"pcm",outputSampleRate:this.config.outputSampleRate||44100,outputChannels:this.config.outputChannels||1,outputBitDepth:this.config.outputBitDepth||16}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(t){if(o.isConnected=!1,t&&1008===t.code&&t.reason&&(t.reason.includes("Domain not whitelisted")||t.reason.includes("domain")||t.reason.includes("whitelist"))){var e=new Error("DOMAIN_NOT_WHITELISTED");e.reason=t.reason,e.code=t.code,o.onError(e)}o.onDisconnected()}),this.voiceSDK.on("domainError",function(t){o.onError(t)}),this.voiceSDK.on("error",function(t){o.onError(t)}),this.voiceSDK.on("message",function(t){o.handleWebSocketMessage(t)}),this.voiceSDK.on("recordingStarted",function(){o.isListening=!0}),this.voiceSDK.on("recordingStopped",function(){o.isListening=!1}),this.voiceSDK.on("playbackStarted",function(){o.onAgentSpeaking(!0)}),this.voiceSDK.on("playbackStopped",function(){o.onAgentSpeaking(!1)}),this.voiceSDK.on("transcriptDisplay",function(t){console.log("📝 AgentSDK: Received transcriptDisplay event:",t),t&&t.text?(console.log("📝 AgentSDK: Calling onTranscript with text:",t.text.substring(0,50)),o.onTranscript(t.text)):console.warn("⚠️ AgentSDK: transcriptDisplay event missing text:",t)}),this.voiceSDK.on("transcript",function(t){console.log("📝 AgentSDK: Received transcript event (for logging):",t)}),t.n=2,this.voiceSDK.connect();case 2:t.n=4;break;case 3:throw t.p=3,n=t.v,this.onError(n),n;case 4:return t.a(2)}},t,this,[[0,3]])})),function(t){return o.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(t){switch(t.t||t.type){case"connected":case"hello_ack":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text||t.transcript);break;case"agent_response":case"barge_in":case"stop_playing":default:break;case"error":this.onError(new Error(t.message||t.error||"Unknown error"))}}},{key:"startListening",value:(n=zn(_n().m(function t(){var e;return _n().w(function(t){for(;;)switch(t.p=t.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){t.n=5;break}return t.p=1,console.log("🎤 AgentSDK: Starting recording..."),t.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),t.n=4;break;case 3:throw t.p=3,e=t.v,console.error("❌ AgentSDK: Failed to start recording:",e),e;case 4:t.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(t){this.voiceSDK&&this.isConnected&&this.voiceSDK.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],e&&Nn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Hn(t){return Hn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Hn(t)}function Kn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Wn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Wn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Wn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Wn(d,"constructor",u),Wn(u,"constructor",s),s.displayName="GeneratorFunction",Wn(u,r,"GeneratorFunction"),Wn(d),Wn(d,r,"Generator"),Wn(d,o,function(){return this}),Wn(d,"toString",function(){return"[object Generator]"}),(Kn=function(){return{w:i,m:f}})()}function Wn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Wn=function(t,e,n,o){function i(e,n){Wn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Wn(t,e,n,o)}function Gn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function qn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Gn(i,o,r,a,c,"next",t)}function c(t){Gn(i,o,r,a,c,"throw",t)}a(void 0)})}}function Qn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Jn(o.key),o)}}function Jn(t){var e=function(t){if("object"!=Hn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Hn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Hn(e)?e:e+""}var Yn=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.audioStream=null,this.callStartTime=null,this.callTimerInterval=null,this.sdk=null,this.isActive=!1,this.sdk=new Ln({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,variables:e.variables||{},language:e.language||"en",outputContainer:e.outputContainer,outputEncoding:e.outputEncoding,outputSampleRate:e.outputSampleRate,outputChannels:e.outputChannels,outputBitDepth:e.outputBitDepth}),this.setupSDKEventHandlers()},e=[{key:"setupSDKEventHandlers",value:function(){var t=this;this.sdk.onTranscript=function(e){t.updateTranscript(e)},this.sdk.onAgentSpeaking=function(t){var e=document.getElementById("voiceAvatarActive");e&&(t?e.classList.add("speaking"):e.classList.remove("speaking"))},this.sdk.onDisconnected=function(){console.log("🔌 WebSocket disconnected, hanging up call..."),t.isActive&&(t.isActive=!1,t.endVoiceCall())},this.sdk.onError=function(e){console.error("❌ Voice SDK Error:",e),e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))?t.showDomainError():t.showError(e.message||e)}}},{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"getTooltip",value:function(t){var e,n=null===(e=this.config.tooltips)||void 0===e?void 0:e[t];return null!=n?n:{mute:this.t("mute"),speaker:this.t("speaker"),endCall:this.t("endCall")}[t]||""}},{key:"generateHTML",value:function(){return'<div class="voice-interface" id="voiceInterface">\n \x3c!-- Before Call State --\x3e\n <div id="voiceIdleState">\n <div class="voice-avatar" id="voiceAvatar">🤖</div>\n <div class="voice-status">\n <div class="voice-status-title">'.concat(this.t("clickToStartCall"),'</div>\n <div class="voice-status-subtitle">').concat(this.t("realTimeVoice"),'</div>\n </div>\n <button class="start-call-btn" id="startCallBtn">\n <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">\n <path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56-.35-.12-.74-.03-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"/>\n </svg>\n <span>').concat(this.t("startCall"),'</span>\n </button>\n </div>\n \x3c!-- During Call State --\x3e\n <div id="voiceActiveState" style="display: none;">\n <div class="voice-avatar-active" id="voiceAvatarActive">\n <div class="voice-rings">\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n </div>\n 🤖\n </div>\n <div class="voice-status">\n <div class="voice-status-title" id="voiceStatusTitleActive">').concat(this.t("listening"),'</div>\n <div class="voice-status-subtitle" id="voiceStatusSubtitleActive">').concat(this.t("speakFreely"),'</div>\n </div>\n <div class="voice-transcript">\n <div class="transcript-label">').concat(this.t("liveTranscript"),'</div>\n <div class="transcript-text empty" id="transcriptText">\n ').concat(this.t("transcriptWillAppear"),'\n </div>\n </div>\n <div class="voice-controls">\n <button class="voice-control-btn secondary" id="muteBtn" title="').concat(this.getTooltip("mute"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="mute-icon">\n <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>\n <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>\n <line x1="12" y1="19" x2="12" y2="23"/>\n <line x1="8" y1="23" x2="16" y2="23"/>\n <line x1="2" y1="2" x2="22" y2="22" class="mute-cross" style="display: none; stroke: #ef4444; stroke-width: 3.5;"/>\n </svg>\n </button>\n <button class="voice-control-btn primary active" id="endCallBtn" title="').concat(this.getTooltip("endCall"),'">\n <svg width="56" height="56" viewBox="0 0 24 24" fill="#ef4444">\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n </svg>\n <div class="voice-timer" id="voiceTimer">00:00</div>\n </button>\n <button class="voice-control-btn secondary" id="speakerBtn" title="').concat(this.getTooltip("speaker"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">\n <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/>\n <path d="M19.07 4.93a10 10 0 0 1 0 14.14"/>\n <path d="M15.54 8.46a5 5 0 0 1 0 7.07"/>\n </svg>\n </button>\n </div>\n </div>\n </div>')}},{key:"generateCSS",value:function(){var t=this.config.avatarBackgroundColor||"#667eea",e=this.config.avatarActiveBackgroundColor||this.config.avatarBackgroundColor||"#667eea",n=this.config.statusTitleColor||"#1e293b",o=this.config.statusSubtitleColor||"#64748b",r=this.config.startCallButtonColor||"#667eea",i=this.config.startCallButtonTextColor||"#FFFFFF",a=this.config.transcriptBackgroundColor||"#FFFFFF",c=this.config.transcriptTextColor||"#1e293b",s=this.config.transcriptLabelColor||"#94a3b8",u=this.config.controlButtonColor||"#FFFFFF",l=this.config.controlButtonSecondaryColor||"#64748b";return this.config.endCallButtonColor,'\n /* Voice Interface Styles - Ultra-compact for Wix iframes */\n .voice-interface { \n display: none; \n flex: 1; \n flex-direction: column;\n align-items: center; \n justify-content: center; \n padding: 6px 10px 6px 10px; \n background: linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%);\n overflow: hidden;\n min-height: 0;\n height: 100%;\n width: 100%;\n box-sizing: border-box;\n }\n .voice-interface.active { display: flex; }\n \n /* Voice States - Better scaling gaps */\n #voiceIdleState,\n #voiceActiveState {\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n height: 100%;\n min-height: 0;\n justify-content: center;\n overflow: hidden;\n flex: 1;\n box-sizing: border-box;\n gap: clamp(6px, 1.5vh, 12px);\n }\n \n #voiceActiveState[style*="display: none"] {\n display: none !important;\n }\n \n /* Voice Avatar - Scales better from small to large */\n .voice-avatar,\n .voice-avatar-active {\n width: clamp(80px, 18vh, 160px);\n height: clamp(80px, 18vh, 160px);\n aspect-ratio: 1;\n border-radius: 50%;\n background: linear-gradient(135deg, '.concat(t," 0%, ").concat(e," 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: clamp(40px, 9vh, 80px);\n margin: 0;\n box-shadow: 0 8px 30px rgba(102, 126, 234, 0.3);\n transition: all 0.3s ease;\n flex-shrink: 1;\n position: relative;\n }\n \n .voice-avatar-active {\n animation: avatarPulse 2s ease-in-out infinite;\n }\n \n @keyframes avatarPulse {\n 0%, 100% { \n transform: scale(1);\n }\n 50% { \n transform: scale(1.05);\n }\n }\n \n .voice-avatar-active.speaking {\n animation: avatarSpeak 0.5s ease-in-out infinite;\n }\n \n @keyframes avatarSpeak {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.08); }\n }\n \n /* Voice Rings Animation */\n .voice-rings {\n position: absolute;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n }\n \n .voice-ring {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n border: 2px solid rgba(102, 126, 234, 0.3);\n border-radius: 50%;\n opacity: 0;\n animation: ringExpand 2s ease-out infinite;\n }\n \n .voice-ring:nth-child(2) { animation-delay: 0.5s; }\n .voice-ring:nth-child(3) { animation-delay: 1s; }\n \n @keyframes ringExpand {\n 0% {\n width: 100%;\n height: 100%;\n opacity: 0.6;\n }\n 100% {\n width: 160%;\n height: 160%;\n opacity: 0;\n }\n }\n \n /* Voice Status - Scales with container */\n .voice-status {\n text-align: center;\n margin: 0;\n flex-shrink: 1;\n min-height: 0;\n }\n \n .voice-status-title {\n font-size: clamp(12px, 3vh, 20px);\n font-weight: 600;\n color: ").concat(n,";\n margin-bottom: clamp(2px, 0.5vh, 4px);\n line-height: 1.2;\n }\n \n .voice-status-subtitle {\n font-size: clamp(10px, 2vh, 14px);\n color: ").concat(o,";\n line-height: 1.2;\n }\n \n /* Start Call Button - Scales with container */\n .start-call-btn {\n margin: 0;\n width: min(280px, 70vw);\n height: clamp(48px, 8vh, 64px);\n border-radius: clamp(24px, 4vh, 32px);\n border: none;\n background: ").concat(r,";\n color: ").concat(i,";\n font-size: clamp(14px, 2.5vh, 18px);\n font-weight: 600;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: clamp(8px, 1.5vh, 12px);\n box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);\n transition: all 0.3s ease;\n flex-shrink: 0;\n }\n \n .start-call-btn svg {\n width: clamp(22px, 4vh, 32px);\n height: clamp(22px, 4vh, 32px);\n }\n \n .start-call-btn:hover {\n transform: translateY(-2px);\n box-shadow: 0 12px 28px rgba(102, 126, 234, 0.5);\n }\n \n .start-call-btn:active {\n transform: translateY(-1px);\n }\n \n /* Voice Transcript - Scales with container */\n .voice-transcript {\n background: ").concat(a,";\n padding: clamp(6px, 1.5vh, 12px);\n border-radius: 10px;\n width: min(360px, calc(100% - 40px));\n margin: 0;\n min-height: clamp(70px, 12vh, 120px);\n max-height: clamp(120px, 20vh, 180px);\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n flex-shrink: 1;\n overflow-y: auto;\n overflow-x: hidden;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n \n .transcript-label {\n font-size: clamp(8px, 1.4vh, 11px);\n color: ").concat(s,";\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.3px;\n margin-bottom: clamp(3px, 0.6vh, 6px);\n flex-shrink: 0;\n word-wrap: break-word;\n text-align: start; /* Will be overridden by direction */\n }\n \n .transcript-text {\n font-size: clamp(11px, 2vh, 15px);\n color: ").concat(c,";\n line-height: 1.4;\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n word-wrap: break-word;\n overflow-wrap: break-word;\n text-align: start; /* Will be overridden by direction */\n }\n \n .transcript-text.empty {\n color: #cbd5e1;\n font-style: italic;\n }\n \n /* Voice Controls - Scales with container */\n .voice-controls {\n display: flex;\n gap: clamp(8px, 1.8vh, 14px);\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n margin: 0;\n padding-top: clamp(5px, 1.2vh, 10px);\n }\n \n .voice-control-btn {\n width: clamp(48px, 9vh, 72px);\n height: clamp(48px, 9vh, 72px);\n aspect-ratio: 1;\n border-radius: 50%;\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n position: relative;\n flex-shrink: 0;\n }\n \n .voice-control-btn svg {\n width: 48%;\n height: 48%;\n }\n \n .voice-control-btn.primary {\n width: clamp(54px, 10vh, 80px);\n height: clamp(54px, 10vh, 80px);\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n box-shadow: 0 6px 18px rgba(102, 126, 234, 0.4);\n }\n \n .voice-control-btn.primary:hover {\n transform: scale(1.05);\n }\n \n .voice-control-btn.primary.active {\n background: white;\n animation: recordingPulse 1.5s ease-in-out infinite;\n }\n \n @keyframes recordingPulse {\n 0%, 100% { \n box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);\n }\n 50% { \n box-shadow: 0 6px 24px rgba(239, 68, 68, 0.7);\n }\n }\n \n .voice-control-btn.secondary {\n background: ").concat(u,";\n color: ").concat(l,";\n box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);\n }\n \n .voice-control-btn.secondary:hover {\n background: #f8fafc;\n transform: scale(1.05);\n }\n \n .voice-control-btn.secondary.muted {\n background: #f3f4f6;\n }\n \n .voice-control-btn.secondary.muted .mute-icon {\n stroke: #9ca3af !important;\n }\n \n .voice-timer {\n position: absolute;\n bottom: clamp(-18px, -3vh, -24px);\n font-size: clamp(9px, 1.6vh, 12px);\n color: #64748b;\n font-weight: 500;\n white-space: nowrap;\n }\n \n /* Mobile optimization */\n @media (max-width: 768px) {\n .voice-interface {\n padding: 6px 10px;\n }\n }\n \n @media (max-width: 480px) {\n .voice-interface {\n padding: 5px 8px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(t){var e=this,n=document.getElementById("startCallBtn"),o=document.getElementById("endCallBtn"),r=document.getElementById("muteBtn"),i=document.getElementById("speakerBtn");n&&(n.onclick=function(){return e.startVoiceCall()}),o&&(o.onclick=function(){return e.endVoiceCall()}),r&&(r.onclick=function(){return e.toggleMute()}),i&&(i.onclick=function(){return e.toggleSpeaker()});var a=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=document.getElementById("voiceInterface");n&&n.classList.contains("active")&&n.clientHeight>100?(console.log("✅ Interface is active and has proper dimensions, adjusting sizes (attempt",t+1,")"),e.adjustSizesForContainer(),0===t&&setTimeout(function(){return e.adjustSizesForContainer()},500)):t<15?(console.log("⏳ Interface not ready yet (height:",null==n?void 0:n.clientHeight,"), retrying... (attempt",t+1,")"),setTimeout(function(){return a(t+1)},250)):(console.warn("⚠️ Interface never became fully ready, adjusting sizes anyway"),e.adjustSizesForContainer())};setTimeout(function(){return a()},200),window.addEventListener("resize",function(){console.log("🔄 Window resized, re-adjusting sizes"),e.adjustSizesForContainer()})}},{key:"getSignedUrl",value:(o=qn(Kn().m(function t(){var e,n,o,r,i,a,c;return Kn().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"adjustSizesForContainer",value:function(){var t=document.getElementById("voiceInterface");if(t){var e=t.clientHeight,n=t.clientWidth;console.log("📏 Container size:",e,"x",n);var o,r,i,a,c,s,u,l,d,f=document.getElementById("voiceIdleState"),p=document.getElementById("voiceActiveState"),h=f&&"none"!==f.style.display,v=p&&"none"!==p.style.display;console.log("👁️ Visible state - Idle:",h,"Active:",v),e<=350?(d=5,o=70,r=35,i=11,a=9,c=32,s=70,u=42,l=48):e<=450?(d=7,o=110,r=55,i=15,a=11,c=38,s=90,u=52,l=58):e<=550?(d=8,o=140,r=70,i=16,a=12,c=42,s=110,u=56,l=64):e<=700?(d=10,o=130,r=65,i=18,a=13,c=46,s=130,u=60,l=70):(d=12,o=150,r=75,i=20,a=14,c=50,s=150,u=66,l=76),document.querySelectorAll("#voiceIdleState, #voiceActiveState").forEach(function(t){t.style.gap="".concat(d,"px")});var g=document.querySelectorAll(".voice-avatar, .voice-avatar-active");console.log("🤖 Found",g.length,"avatars, setting size to",o,"px"),g.forEach(function(t){t.style.width="".concat(o,"px"),t.style.height="".concat(o,"px"),t.style.fontSize="".concat(r,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(t){return t.style.fontSize="".concat(i,"px")}),document.querySelectorAll(".voice-status-subtitle").forEach(function(t){return t.style.fontSize="".concat(a,"px")});var y=document.querySelector(".voice-transcript");if(y){y.style.minHeight="".concat(s,"px"),y.style.maxHeight="".concat(s,"px"),y.style.height="".concat(s,"px"),y.style.width="min(360px, ".concat(n-40,"px)"),y.style.boxSizing="border-box";var m=this.getTranscriptDirection();y.style.direction=m,y.setAttribute("dir",m)}var b=document.querySelector(".transcript-label");if(b){b.style.fontSize="".concat(Math.max(8,i-4),"px");var w=this.getTranscriptDirection();b.style.direction=w,b.style.textAlign="rtl"===w?"right":"left",b.setAttribute("dir",w)}var S=document.querySelector(".transcript-text");if(S){S.style.fontSize="".concat(Math.max(10,i-2),"px");var x=this.getTranscriptDirection();S.style.direction=x,S.style.textAlign="rtl"===x?"right":"left",S.setAttribute("dir",x)}document.querySelectorAll(".voice-control-btn.secondary").forEach(function(t){t.style.width="".concat(u,"px"),t.style.height="".concat(u,"px");var e=t.querySelector("svg");if(e){var n=.65*u;e.style.setProperty("width","".concat(n,"px"),"important"),e.style.setProperty("height","".concat(n,"px"),"important"),e.style.setProperty("min-width","".concat(n,"px"),"important"),e.style.setProperty("min-height","".concat(n,"px"),"important")}});var k=document.querySelector(".voice-control-btn.primary");if(k){k.style.width="".concat(l,"px"),k.style.height="".concat(l,"px");var C=k.querySelector("svg");if(C){var P=.7*l;C.style.setProperty("width","".concat(P,"px"),"important"),C.style.setProperty("height","".concat(P,"px"),"important"),C.style.setProperty("min-width","".concat(P,"px"),"important"),C.style.setProperty("min-height","".concat(P,"px"),"important")}}var O=document.querySelector(".start-call-btn");if(O){var T,E;e<=350?(T=48,E=14):e<=450?(T=52,E=15):e<=550?(T=58,E=17):e<=700?(T=62,E=18):(T=64,E=18),O.style.height="".concat(T,"px"),O.style.fontSize="".concat(E,"px");var j=O.querySelector("svg");if(j){var I=Math.max(22,.5*T);j.style.width="".concat(I,"px"),j.style.height="".concat(I,"px")}}console.log("✅ Sizes adjusted - Avatar:",o,"Status:",c,"Transcript:",s,"Buttons:",u)}else console.warn("⚠️ voiceInterface not found, skipping size adjustment")}},{key:"startVoiceCall",value:(n=qn(Kn().m(function t(){var e,n,o,r,i,a,c,s,u,l=this;return Kn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isActive){t.n=1;break}return console.log("⚠️ Voice call already active"),t.a(2);case 1:return console.log("🎤 Starting voice call..."),t.p=2,e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState"),o=document.getElementById("voiceInterface"),e&&(e.style.display="none"),n&&(n.style.display="flex"),setTimeout(function(){return l.adjustSizesForContainer()},50),o&&(o.scrollTop=0),t.n=3,this.getSignedUrl();case 3:return r=t.v,console.log("🔗 Got signed URL:",r),t.n=4,this.sdk.connect(r);case 4:i=t.v,console.log("✅ Connected to WebSocket, connected:",i),a=0;case 5:if(this.sdk.isConnected||!(a<50)){t.n=7;break}return t.n=6,new Promise(function(t){return setTimeout(t,100)});case 6:a++,t.n=5;break;case 7:if(!this.sdk.isConnected){t.n=9;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=8,this.sdk.startListening();case 8:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-l.callStartTime,e=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(e.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3),t.n=11;break;case 9:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),t.n=10,this.sdk.startListening();case 10:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-l.callStartTime,e=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(e.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3);case 11:console.log("✅ Voice call started successfully"),t.n=13;break;case 12:t.p=12,u=t.v,console.error("❌ Error starting voice call:",u),this.showError(u.message||u),c=document.getElementById("voiceIdleState"),s=document.getElementById("voiceActiveState"),c&&(c.style.display="flex"),s&&(s.style.display="none");case 13:return t.a(2)}},t,this,[[2,12]])})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){var t=this;console.log("🔴 Ending voice call..."),this.sdk&&this.isActive&&(this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null);var e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState");e&&(e.style.display="flex"),n&&(n.style.display="none"),setTimeout(function(){return t.adjustSizesForContainer()},50);var o=document.getElementById("transcriptText");if(o){o.textContent=this.t("transcriptWillAppear"),o.classList.add("empty");var r=this.getTranscriptDirection();o.style.direction=r,o.style.textAlign="rtl"===r?"right":"left",o.setAttribute("dir",r)}var i=document.querySelector(".transcript-label");if(i){var a=this.getTranscriptDirection();i.style.direction=a,i.style.textAlign="rtl"===a?"right":"left",i.setAttribute("dir",a)}var c=document.getElementById("voiceAvatarActive");c&&c.classList.remove("speaking"),console.log("✅ Voice call ended")}},{key:"getTranscriptDirection",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=this.config.language||"en";if(["he","ar","he-IL","ar-SA","ar-EG","ar-AE"].includes(e))return"rtl";var n,o=t||((n=document.getElementById("transcriptText"))?n.textContent:null);return o&&/[\u0590-\u05FF\u0600-\u06FF]/.test(o)?"rtl":"ltr"}},{key:"updateTranscript",value:function(t){console.log("📝 VoiceInterface: updateTranscript called with text:",null==t?void 0:t.substring(0,50));var e=document.getElementById("transcriptText");if(e){e.textContent=t,e.classList.remove("empty");var n=this.getTranscriptDirection(t);e.style.direction=n,e.style.textAlign="rtl"===n?"right":"left",e.setAttribute("dir",n);var o=document.querySelector(".voice-transcript");o&&(o.style.direction=n,o.setAttribute("dir",n));var r=document.querySelector(".transcript-label");r&&(r.style.direction=n,r.style.textAlign="rtl"===n?"right":"left",r.setAttribute("dir",n)),console.log("✅ VoiceInterface: Transcript updated in DOM with direction:",n)}else console.warn("⚠️ VoiceInterface: transcriptText element not found in DOM")}},{key:"showError",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent="".concat(this.t("error"),": ").concat(t),e.classList.remove("empty"))}},{key:"showDomainError",value:function(){var t=document.getElementById("transcriptText");if(t){var e=this.t("domainNotValidated"),n=this.t("domainErrorMessage");t.innerHTML='<div style="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;">'.concat(e,'</div><div style="font-size: 14px; color: #991B1B; line-height: 1.5;">').concat(n,"</div>"),t.classList.remove("empty")}}},{key:"toggleMute",value:function(){if(this.sdk&&this.isActive){var t=null;if(this.sdk.voiceSDK&&this.sdk.voiceSDK.audioRecorder&&this.sdk.voiceSDK.audioRecorder.mediaStream&&(t=this.sdk.voiceSDK.audioRecorder.mediaStream.getAudioTracks()[0]),!t&&this.audioStream&&(t=this.audioStream.getAudioTracks()[0]),t){t.enabled=!t.enabled;var e=document.getElementById("muteBtn"),n=null==e?void 0:e.querySelector(".mute-icon"),o=null==e?void 0:e.querySelector(".mute-cross");e&&n&&o&&(t.enabled?(n.style.stroke="",o.style.display="none",e.classList.remove("muted")):(n.style.stroke="#9ca3af",o.style.display="block",e.classList.add("muted"))),console.log(t.enabled?"🔊 Unmuted":"🔇 Muted")}else console.warn("⚠️ No audio track available for mute toggle")}}},{key:"toggleSpeaker",value:function(){console.log("🔊 Speaker toggle")}},{key:"destroy",value:function(){this.isActive&&this.endVoiceCall(),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&(this.sdk.disconnect(),this.sdk=null)}}],e&&Qn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function $n(t){return $n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},$n(t)}function Xn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Zn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Zn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Zn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Zn(d,"constructor",u),Zn(u,"constructor",s),s.displayName="GeneratorFunction",Zn(u,r,"GeneratorFunction"),Zn(d),Zn(d,r,"Generator"),Zn(d,o,function(){return this}),Zn(d,"toString",function(){return"[object Generator]"}),(Xn=function(){return{w:i,m:f}})()}function Zn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Zn=function(t,e,n,o){function i(e,n){Zn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Zn(t,e,n,o)}function to(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function eo(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){to(i,o,r,a,c,"next",t)}function c(t){to(i,o,r,a,c,"throw",t)}a(void 0)})}}function no(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,oo(o.key),o)}}function oo(t){var e=function(t){if("object"!=$n(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=$n(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==$n(e)?e:e+""}var ro=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.sdk=n,this.streamingEl=null,this.hasStartedStreaming=!1,this.isActive=!1,this.eventHandlers={autoResize:null,keydown:null},this.eventHandlersSetup=!1},e=[{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"generateHTML",value:function(){var t,e,n,o,r,i,a,c,s,u=this.config.inputPlaceholder||(null===(t=this.config.panel)||void 0===t?void 0:t.inputPlaceholder)||this.t("typeMessage")||"Type your message...";return'<div class="text-interface" id="textInterface">\n <div class="messages-container" id="messagesContainer">\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),'</div>\n </div>\n </div>\n <div class="input-container">\n <div class="input-wrapper" style="flex:1;">\n <textarea class="message-input" id="messageInput" placeholder="').concat(u,'" rows="1" dir="').concat(this.config.direction||"ltr",'"></textarea>\n </div>\n <button class="send-button" id="sendButton" aria-label="').concat(this.t("sendMessageAria"),'">').concat(this.config.sendButtonText||"➤","</button>\n ").concat(null!==(e=this.config.sendButtonHint)&&void 0!==e&&e.text||null!==(n=this.config.panel)&&void 0!==n&&null!==(n=n.sendButtonHint)&&void 0!==n&&n.text?'\n <div class="send-button-hint" style="color: '.concat((null===(o=this.config.sendButtonHint)||void 0===o?void 0:o.color)||(null===(r=this.config.panel)||void 0===r||null===(r=r.sendButtonHint)||void 0===r?void 0:r.color)||"#6B7280","; font-size: ").concat((null===(i=this.config.sendButtonHint)||void 0===i?void 0:i.fontSize)||(null===(a=this.config.panel)||void 0===a||null===(a=a.sendButtonHint)||void 0===a?void 0:a.fontSize)||"12px",'; text-align: center; margin-top: 4px;">\n ').concat((null===(c=this.config.sendButtonHint)||void 0===c?void 0:c.text)||(null===(s=this.config.panel)||void 0===s||null===(s=s.sendButtonHint)||void 0===s?void 0:s.text),"\n </div>\n "):"","\n </div>\n </div>")}},{key:"generateCSS",value:function(){var t,e,n,o,r,i,a,c,s,u,l,d,f,p=this.config.messages,h=(this.config.panel,this.config.animation,this.config.sendButtonColor||(null===(t=this.config.panel)||void 0===t?void 0:t.sendButtonColor)||"#7C3AED"),v=this.config.sendButtonHoverColor||(null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonHoverColor)||"#6D28D9",g=this.config.sendButtonTextColor||(null===(n=this.config.panel)||void 0===n?void 0:n.sendButtonTextColor)||"#FFFFFF",y=(this.config.inputPlaceholder||null===(o=this.config.panel)||void 0===o||o.inputPlaceholder,this.config.inputBorderColor||(null===(r=this.config.panel)||void 0===r?void 0:r.inputBorderColor)||"#E5E7EB"),m=this.config.inputFocusColor||(null===(i=this.config.panel)||void 0===i?void 0:i.inputFocusColor)||"#7C3AED",b=this.config.inputBackgroundColor||(null===(a=this.config.panel)||void 0===a?void 0:a.inputBackgroundColor)||"#FFFFFF",w=this.config.inputTextColor||(null===(c=this.config.panel)||void 0===c?void 0:c.inputTextColor)||"#1F2937",S=this.config.inputFontSize||(null===(s=this.config.panel)||void 0===s?void 0:s.inputFontSize)||"14px",x=this.config.inputBorderRadius||(null===(u=this.config.panel)||void 0===u?void 0:u.inputBorderRadius)||20,k=this.config.inputPadding||(null===(l=this.config.panel)||void 0===l?void 0:l.inputPadding)||"6px 14px";return"\n /* Messages container using new classes */\n #messagesContainer { \n flex: 1; \n overflow-y: auto; \n overflow-x: hidden; \n padding: 20px; \n background: #f8fafc; \n display: flex; \n flex-direction: column; \n gap: 16px; \n min-height: 0; \n }\n .empty-state { \n flex: 1; \n display: flex; \n flex-direction: column; \n align-items: center; \n justify-content: center; \n gap: 12px; \n color: #64748b; \n text-align: center; \n padding: 20px; \n }\n .empty-state-icon { font-size: 48px; opacity: 0.3; }\n .empty-state-title { font-size: 20px; font-weight: 700; color: #334155; }\n .empty-state-text { font-size: 13px; max-width: 280px; }\n\n .text-interface { \n display: none; \n flex: 1; \n flex-direction: column; \n min-height: 0; \n overflow: hidden; \n }\n .text-interface.active { display: flex; }\n \n .message { \n display: flex; \n gap: 8px; \n padding: 4px 0; \n max-width: 100%; \n align-items: center; \n }\n .message.edge-left { flex-direction: row; }\n .message.edge-right { flex-direction: row-reverse; }\n .message-bubble { \n padding: 12px; \n border-radius: ".concat(p.borderRadius,"px; \n max-width: 80%; \n font-size: ").concat(p.fontSize,"; \n color: ").concat(p.textColor,"; \n word-wrap: break-word; \n text-align: ").concat("rtl"===this.config.direction?"right":"left","; \n direction: ").concat(this.config.direction||"ltr",";\n }\n .message.user { \n background: ").concat(p.userBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-start":"flex-end","; \n }\n .message.agent { \n background: ").concat(p.agentBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-end":"flex-start","; \n }\n .message .message-bubble { \n text-align: ").concat("rtl"===this.config.direction?"right":"left"," !important; \n }\n ").concat("rtl"===this.config.direction?"\n .message-bubble {\n text-align: right !important;\n }\n ":"","\n .message-avatar { \n width: 20px; \n height: 20px; \n display: flex; \n align-items: center; \n justify-content: center; \n flex-shrink: 0; \n color: inherit; \n font-size: 18px; \n line-height: 1; \n background: transparent; \n border: none; \n }\n .message-avatar.user { background: transparent; }\n .message-avatar.agent { background: transparent; }\n \n .message.system {\n background: ").concat(p.systemBackgroundColor,";\n align-self: flex-start;\n }\n .message.error {\n background: ").concat(p.errorBackgroundColor,";\n align-self: flex-start;\n }\n \n .input-container {\n display: flex;\n gap: 8px;\n padding: 12px 16px;\n background: #FFFFFF;\n border-top: 1px solid #E5E7EB;\n align-items: center;\n flex-shrink: 0;\n flex-direction: ").concat("rtl"===this.config.direction?"row-reverse":"row",";\n }\n \n .input-wrapper {\n position: relative;\n display: flex;\n align-items: center;\n }\n \n .message-input {\n width: 100%;\n min-height: 32px;\n max-height: 120px;\n padding: ").concat(k,";\n border: 1px solid ").concat(y,";\n border-radius: ").concat(x,"px;\n font-size: ").concat(S,";\n font-family: inherit;\n line-height: 1.3;\n resize: none;\n overflow-y: auto;\n background: ").concat(b,";\n color: ").concat(w,";\n vertical-align: top;\n margin: 0;\n display: block;\n white-space: pre-wrap;\n word-wrap: break-word;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n direction: ").concat(this.config.direction||"ltr",";\n -webkit-appearance: none;\n appearance: none;\n box-sizing: border-box;\n }\n \n .message-input:focus {\n outline: none;\n border-color: ").concat(m,";\n background: ").concat("#FFFFFF"===b?"#FFFFFF":b,";\n box-shadow: 0 0 0 3px ").concat(m,"33;\n }\n \n .message-input::placeholder {\n color: #9CA3AF;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n }\n \n .send-button {\n width: 40px;\n height: 40px;\n border-radius: 50%;\n border: none;\n background: ").concat(h,";\n color: ").concat(g,";\n font-size: ").concat(this.config.sendButtonFontSize||(null===(d=this.config.panel)||void 0===d?void 0:d.sendButtonFontSize)||"18px",";\n font-weight: ").concat(this.config.sendButtonFontWeight||(null===(f=this.config.panel)||void 0===f?void 0:f.sendButtonFontWeight)||"500",";\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n transition: all 0.2s ease;\n box-shadow: 0 4px 12px rgba(124, 60, 237, 0.3);\n }\n \n .send-button:hover:not(:disabled) {\n background: ").concat(v,";\n transform: scale(1.05);\n box-shadow: 0 6px 16px rgba(124, 60, 237, 0.4);\n }\n \n .send-button-hint {\n width: 100%;\n text-align: center;\n margin-top: 4px;\n }\n \n .send-button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n \n .typing-indicator {\n display: inline-flex;\n gap: 4px;\n align-items: center;\n }\n \n .typing-dot {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: #64748b;\n animation: typingDot 1.4s ease-in-out infinite;\n }\n \n .typing-dot:nth-child(2) { animation-delay: 0.2s; }\n .typing-dot:nth-child(3) { animation-delay: 0.4s; }\n \n @keyframes typingDot {\n 0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }\n 30% { transform: translateY(-8px); opacity: 1; }\n }\n \n .error-message {\n padding: 12px;\n background: ").concat(p.errorBackgroundColor,";\n border-radius: ").concat(p.borderRadius,"px;\n color: #991B1B;\n font-size: ").concat(p.fontSize,";\n margin: 8px 0;\n }\n \n @media (max-width: 768px) {\n #messagesContainer {\n padding: 12px;\n gap: 12px;\n }\n \n .message-bubble {\n max-width: 85%;\n font-size: 14px;\n padding: 10px;\n }\n \n .text-input-container {\n padding: 10px;\n gap: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 10px 14px;\n min-height: 44px;\n }\n \n #text-chat-send {\n min-width: 56px;\n min-height: 44px;\n width: 56px;\n height: 44px;\n }\n \n .empty-state-icon {\n font-size: 40px;\n }\n \n .empty-state-title {\n font-size: 18px;\n }\n \n .empty-state-text {\n font-size: 12px;\n }\n }\n \n @media (max-width: 480px) {\n #messagesContainer {\n padding: 10px;\n gap: 10px;\n }\n \n .message-bubble {\n max-width: 90%;\n font-size: 13px;\n padding: 8px;\n }\n \n .text-input-container {\n padding: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important;\n padding: 8px 12px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(){var t=this,e=document.getElementById("sendButton"),n=document.getElementById("messageInput"),o=document.getElementById("newChatBtn");if(e&&(e.onclick=function(){return t.sendMessage()}),o&&(o.onclick=function(){return t.startNewChat()}),this.updateInputAttributes(),n){n.style.height="32px",n.style.overflow="hidden";var r=function(){n.style.height="auto";var t=Math.min(n.scrollHeight,120);n.style.height=t+"px",n.style.overflowY=t>=120?"auto":"hidden",t>=120&&setTimeout(function(){n.scrollTop=n.scrollHeight},0)};n.addEventListener("input",r),n.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey?"Enter"===e.key&&e.shiftKey&&setTimeout(r,0):(e.preventDefault(),t.sendMessage())})}}},{key:"startNewChat",value:function(){try{localStorage.removeItem("ttp_text_chat_conversation_id")}catch(t){}this.sdk&&(this.sdk.config.conversationId=null);var t=document.getElementById("messagesContainer");t&&(t.innerHTML='\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),"</div>\n </div>"));var e=document.getElementById("messageInput");e&&e.focus()}},{key:"updateInputAttributes",value:function(){var t=document.getElementById("messageInput");if(t){var e,n=this.config.inputPlaceholder||(null===(e=this.config.panel)||void 0===e?void 0:e.inputPlaceholder)||this.t("typeMessage")||"Type your message...";t.placeholder=n,t.dir=this.config.direction||"ltr",t.style.textAlign="rtl"===this.config.direction?"right":"left"}}},{key:"show",value:function(){var t=document.getElementById("textInterface");t&&t.classList.add("active"),setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},50)}},{key:"hide",value:function(){var t=document.getElementById("textInterface");t&&t.classList.remove("active")}},{key:"startChat",value:(o=eo(Xn().m(function t(){return Xn().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.updateSendButtonState();case 1:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"sendMessage",value:(n=eo(Xn().m(function t(){var e,n,o;return Xn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("messageInput"),n=e.value.trim()){t.n=1;break}return t.a(2);case 1:if(this.isActive){t.n=2;break}return t.n=2,this.startChat();case 2:return this.addMessage("user",n),e.value="",e.style.height="32px",e.style.overflow="hidden",t.p=3,this.beginStreaming(),t.n=4,this.sdk.sendMessage(n);case 4:t.n=6;break;case 5:t.p=5,o=t.v,console.error("❌ Failed to send message:",o),o&&("DOMAIN_NOT_WHITELISTED"===o.message||o.message&&o.message.includes("Domain not whitelisted"))||this.showError(o),this.stopStreamingState();case 6:return t.a(2)}},t,this,[[3,5]])})),function(){return n.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var t=document.getElementById("sendButton");t&&(t.disabled=!this.isActive)}},{key:"addMessage",value:function(t,e){var n=document.getElementById("messagesContainer");if(n){var o=n.querySelector(".empty-state");o&&o.remove();var r=document.createElement("div"),i="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";r.className="message ".concat(t," ").concat(i);var a=document.createElement("div");a.className="message-avatar ".concat(t),a.textContent="user"===t?"👤":"🤖";var c=document.createElement("div");c.className="message-bubble",c.textContent=e,r.appendChild(a),r.appendChild(c),n.appendChild(r),n.scrollTop=n.scrollHeight}}},{key:"beginStreaming",value:function(){var t=document.getElementById("messagesContainer");if(t){this.stopStreamingState();var e=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";e.className="message agent ".concat(n),e.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var r=document.createElement("div");r.className="message-bubble",r.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',e.appendChild(o),e.appendChild(r),t.appendChild(e),this.streamingEl=r,this.hasStartedStreaming=!1,t.scrollTop=t.scrollHeight}}},{key:"appendStreamingChunk",value:function(t){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=t;var e=document.getElementById("messagesContainer");e&&(e.scrollTop=e.scrollHeight)}}},{key:"finalizeStreaming",value:function(t){if(this.streamingEl){this.streamingEl.textContent=t||this.streamingEl.textContent;var e=document.getElementById("agent-streaming");e&&(e.id=""),this.streamingEl=null}this.updateSendButtonState()}},{key:"stopStreamingState",value:function(){var t=document.getElementById("agent-streaming");t&&t.remove(),this.streamingEl=null,this.hasStartedStreaming=!1}},{key:"showError",value:function(t){var e=document.getElementById("messagesContainer");if(e){if(t&&("DOMAIN_NOT_WHITELISTED"===t.message||"string"==typeof t&&t.includes("DOMAIN_NOT_WHITELISTED")||t.message&&t.message.includes("Domain not whitelisted")||"string"==typeof t&&t.includes("Domain not whitelisted"))){var n,o=document.createElement("div");o.className="error-message",o.style.cssText="padding: 16px; margin: 12px; border-radius: 8px; background: "+((null===(n=this.config.messages)||void 0===n?void 0:n.errorBackgroundColor)||"#FEE2E2")+";";var r=document.createElement("div");r.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",r.textContent=this.t("domainNotValidated");var i=document.createElement("div");i.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",i.textContent=this.t("domainErrorMessage"),o.appendChild(r),o.appendChild(i),e.appendChild(o)}else{var a=document.createElement("div");a.className="error-message",a.textContent="string"==typeof t?t:(null==t?void 0:t.message)||t,e.appendChild(a)}e.scrollTop=e.scrollHeight}}},{key:"setActive",value:function(t){this.isActive=t,this.updateSendButtonState()}}],e&&no(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();const io={en:{landingTitle:"How would you like to communicate?",voiceCall:"Voice Call",textChat:"Text Chat",clickToStartCall:"Click to Start Call",realTimeVoice:"Real-time voice conversation",startCall:"Start Call",listening:"Listening...",speakFreely:"Speak freely",liveTranscript:"Live Transcript",transcriptWillAppear:"Transcript will appear here during the call...",mute:"Mute",speaker:"Speaker",endCall:"End Call",hello:"Hello! How can I help?",sendMessage:"Send a message to get started",online:"Online",newChat:"New Chat",back:"Back",close:"Close",error:"Error",typeMessage:"Type your message...",sendMessageAria:"Send message",domainNotValidated:"Domain not validated",domainErrorMessage:"This domain is not whitelisted. Please contact the administrator to whitelist your website URL."},he:{landingTitle:"איך תרצה לתקשר?",voiceCall:"שיחה קולית",textChat:"צ'אט טקסט",clickToStartCall:"לחץ להתחלת שיחה",realTimeVoice:"שיחה קולית בזמן אמת",startCall:"התחל שיחה",listening:"מקשיב...",speakFreely:"דבר בחופשיות",liveTranscript:"תמלול בזמן אמת",transcriptWillAppear:"התמלול יופיע כאן במהלך השיחה...",mute:"השתק",speaker:"רמקול",endCall:"סיים שיחה",hello:"שלום! איך אפשר לעזור?",sendMessage:"שלח הודעה או עבור למצב קולי לשיחה בזמן אמת",online:"מקוון",newChat:"צ'אט חדש",back:"חזור",close:"סגור",error:"שגיאה",typeMessage:"הקלד הודעה...",sendMessageAria:"שלח הודעה",domainNotValidated:"דומיין לא מאומת",domainErrorMessage:"דומיין זה לא ברשימת המורשים. אנא פנה למנהל המערכת כדי להוסיף את כתובת האתר שלך לרשימה."},ar:{landingTitle:"كيف تريد التواصل؟",voiceCall:"مكالمة صوتية",textChat:"دردشة نصية",clickToStartCall:"انقر لبدء المكالمة",realTimeVoice:"محادثة صوتية في الوقت الفعلي",startCall:"ابدأ المكالمة",listening:"الاستماع...",speakFreely:"تكلم بحرية",liveTranscript:"نص مباشر",transcriptWillAppear:"سيظهر النص هنا أثناء المكالمة...",mute:"كتم الصوت",speaker:"مكبر الصوت",endCall:"إنهاء المكالمة",hello:"مرحبا! كيف يمكنني المساعدة؟",sendMessage:"أرسل رسالة للبدء",online:"متصل",newChat:"محادثة جديدة",back:"رجوع",close:"إغلاق",error:"خطأ",typeMessage:"اكتب رسالة...",sendMessageAria:"إرسال رسالة",domainNotValidated:"النطاق غير معتمد",domainErrorMessage:"هذا النطاق غير مسموح به. يرجى الاتصال بالمسؤول لإضافة عنوان موقع الويب الخاص بك إلى القائمة."},ru:{landingTitle:"Как вы хотите общаться?",voiceCall:"Голосовой звонок",textChat:"Текстовый чат",clickToStartCall:"Нажмите, чтобы начать звонок",realTimeVoice:"Голосовой разговор в реальном времени",startCall:"Начать звонок",listening:"Слушаю...",speakFreely:"Говорите свободно",liveTranscript:"Живая транскрипция",transcriptWillAppear:"Транскрипция появится здесь во время звонка...",mute:"Отключить звук",speaker:"Динамик",endCall:"Завершить звонок",hello:"Привет! Как я могу помочь?",sendMessage:"Отправьте сообщение для начала",online:"В сети",newChat:"Новый чат",back:"Назад",close:"Закрыть",error:"Ошибка",typeMessage:"Введите сообщение...",sendMessageAria:"Отправить сообщение",domainNotValidated:"Домен не проверен",domainErrorMessage:"Этот домен не в белом списке. Пожалуйста, свяжитесь с администратором, чтобы добавить URL вашего веб-сайта в список."},es:{landingTitle:"¿Cómo te gustaría comunicarte?",voiceCall:"Llamada de voz",textChat:"Chat de texto",clickToStartCall:"Haz clic para iniciar la llamada",realTimeVoice:"Conversación de voz en tiempo real",startCall:"Iniciar llamada",listening:"Escuchando...",speakFreely:"Habla libremente",liveTranscript:"Transcripción en vivo",transcriptWillAppear:"La transcripción aparecerá aquí durante la llamada...",mute:"Silenciar",speaker:"Altavoz",endCall:"Terminar llamada",hello:"¡Hola! ¿Cómo puedo ayudarte?",sendMessage:"Envía un mensaje para comenzar",online:"En línea",newChat:"Nuevo chat",back:"Atrás",close:"Cerrar",error:"Error",typeMessage:"Escribe un mensaje...",sendMessageAria:"Enviar mensaje",domainNotValidated:"Dominio no validado",domainErrorMessage:"Este dominio no está en la lista blanca. Por favor, contacte al administrador para agregar la URL de su sitio web a la lista."},fr:{landingTitle:"Comment souhaitez-vous communiquer?",voiceCall:"Appel vocal",textChat:"Chat texte",clickToStartCall:"Cliquez pour démarrer l'appel",realTimeVoice:"Conversation vocale en temps réel",startCall:"Démarrer l'appel",listening:"Écoute...",speakFreely:"Parlez librement",liveTranscript:"Transcripción en direct",transcriptWillAppear:"La transcription apparaîtra ici pendant l'appel...",mute:"Muet",speaker:"Haut-parleur",endCall:"Terminer l'appel",hello:"Bonjour! Comment puis-je vous aider?",sendMessage:"Envoyez un message pour commencer",online:"En ligne",newChat:"Nouveau chat",back:"Retour",close:"Fermer",error:"Erreur",typeMessage:"Tapez votre message...",sendMessageAria:"Envoyer un message",domainNotValidated:"Domaine non validé",domainErrorMessage:"Ce domaine n'est pas sur la liste blanche. Veuillez contacter l'administrateur pour ajouter l'URL de votre site Web à la liste."},de:{landingTitle:"Wie möchten Sie kommunizieren?",voiceCall:"Sprachanruf",textChat:"Text-Chat",clickToStartCall:"Klicken Sie, um den Anruf zu starten",realTimeVoice:"Sprachanruf in Echtzeit",startCall:"Anruf starten",listening:"Hören...",speakFreely:"Sprechen Sie frei",liveTranscript:"Live-Transkription",transcriptWillAppear:"Die Transkription erscheint hier während des Anrufs...",mute:"Stumm",speaker:"Lautsprecher",endCall:"Anruf beenden",hello:"Hallo! Wie kann ich helfen?",sendMessage:"Senden Sie eine Nachricht zum Starten",online:"Online",newChat:"Neuer Chat",back:"Zurück",close:"Schließen",error:"Fehler",typeMessage:"Geben Sie eine Nachricht ein...",sendMessageAria:"Nachricht senden",domainNotValidated:"Domain nicht validiert",domainErrorMessage:"Diese Domain steht nicht auf der Whitelist. Bitte kontaktieren Sie den Administrator, um die URL Ihrer Website zur Liste hinzuzufügen."}};function ao(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return co(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(co(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,co(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,co(d,"constructor",u),co(u,"constructor",s),s.displayName="GeneratorFunction",co(u,r,"GeneratorFunction"),co(d),co(d,r,"Generator"),co(d,o,function(){return this}),co(d,"toString",function(){return"[object Generator]"}),(ao=function(){return{w:i,m:f}})()}function co(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}co=function(t,e,n,o){function i(e,n){co(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},co(t,e,n,o)}function so(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function uo(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){so(i,o,r,a,c,"next",t)}function c(t){so(i,o,r,a,c,"throw",t)}a(void 0)})}}function lo(t){return lo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},lo(t)}function fo(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function po(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?fo(Object(n),!0).forEach(function(e){ho(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):fo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ho(t,e,n){return(e=go(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function vo(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,go(o.key),o)}}function go(t){var e=function(t){if("object"!=lo(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=lo(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==lo(e)?e:e+""}var yo=function(){return t=function t(){var e,n,o,r,i,a,c,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=this.mergeWithDefaults(s),this.sdk=new fn(this.config),this.isOpen=!1,this.isActive=!1,this.translations=io,this.currentView="landing";var u=po(po(po({},this.config),this.config.voice),{},{language:(null===(e=this.config.voice)||void 0===e?void 0:e.language)||this.config.language||"en",websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16});this.voiceInterface=new Yn(u);var l=po(po(po({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new ro(l,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var d=document.getElementById("text-chat-panel");d&&(this.isOpen=!0,d.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,a,c,s,u,l,d,f,p,h,v,g,y,m,b,w,S,x,k,C,P,O,T,E,j,I,A,F,D,B,R,_,U,M,z,N,V,L,H,K,W,G,q,Q,J,Y,$,X,Z,tt,et,nt,ot,rt,it,at,ct,st,ut,lt,dt,ft,pt,ht,vt,gt,yt,mt,bt,wt,St,xt,kt,Ct,Pt,Ot,Tt,Et,jt,It,At,Ft,Dt,Bt,Rt,_t,Ut,Mt,zt,Nt,Vt,Lt,Ht,Kt,Wt,Gt,qt,Qt,Jt,Yt,$t,Xt,Zt,te,ee,ne,oe,re,ie,ae,ce,se,ue,le,de,fe,pe,he,ve,ge,ye,me,be,we,Se,xe,ke,Ce,Pe,Oe,Te=t.position||"bottom-right";if("string"==typeof Te){var Ee=Te.split("-");Te={vertical:Ee[0]||"bottom",horizontal:Ee[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var je=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||(null===(n=t.button)||void 0===n?void 0:n.backgroundColor)||"#7C3AED",Ie=(null===(o=t.header)||void 0===o?void 0:o.backgroundColor)||(null===(r=t.button)||void 0===r?void 0:r.backgroundColor)||je;return po({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",language:t.language||"en",icon:po({type:(null===(i=t.icon)||void 0===i?void 0:i.type)||"custom",customImage:(null===(a=t.icon)||void 0===a?void 0:a.customImage)||"https://talktopc.com/logo192.png",emoji:(null===(c=t.icon)||void 0===c?void 0:c.emoji)||"🎤",text:(null===(s=t.icon)||void 0===s?void 0:s.text)||"AI",size:(null===(u=t.icon)||void 0===u?void 0:u.size)||"medium",backgroundColor:(null===(l=t.icon)||void 0===l?void 0:l.backgroundColor)||"#FFFFFF"},t.icon),position:po({vertical:Te.vertical||"bottom",horizontal:Te.horizontal||"right",offset:Te.offset||{x:20,y:20}},"object"===lo(t.position)?t.position:{}),button:po({size:(null===(d=t.button)||void 0===d?void 0:d.size)||"medium",shape:(null===(f=t.button)||void 0===f?void 0:f.shape)||"circle",backgroundColor:(null===(p=t.button)||void 0===p?void 0:p.backgroundColor)||(null===(h=t.icon)||void 0===h?void 0:h.backgroundColor)||je,hoverColor:(null===(v=t.button)||void 0===v?void 0:v.hoverColor)||"#7C3AED",shadow:!1!==(null===(g=t.button)||void 0===g?void 0:g.shadow),shadowColor:(null===(y=t.button)||void 0===y?void 0:y.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(m=t.button)||void 0===m?void 0:m.backgroundColor)||(null===(b=t.icon)||void 0===b?void 0:b.backgroundColor)||je},t.button),panel:po({width:(null===(w=t.panel)||void 0===w?void 0:w.width)||350,height:(null===(S=t.panel)||void 0===S?void 0:S.height)||500,borderRadius:(null===(x=t.panel)||void 0===x?void 0:x.borderRadius)||12,backgroundColor:(null===(k=t.panel)||void 0===k?void 0:k.backgroundColor)||"#FFFFFF",backdropFilter:(null===(C=t.panel)||void 0===C?void 0:C.backdropFilter)||null,border:(null===(P=t.panel)||void 0===P?void 0:P.border)||"1px solid rgba(0,0,0,0.1)"},t.panel),voice:po({micButtonColor:(null===(O=t.voice)||void 0===O?void 0:O.micButtonColor)||(null===(T=t.panel)||void 0===T?void 0:T.micButtonColor)||je,micButtonActiveColor:(null===(E=t.voice)||void 0===E?void 0:E.micButtonActiveColor)||(null===(j=t.panel)||void 0===j?void 0:j.micButtonActiveColor)||"#EF4444",micButtonHint:po(po({text:(null===(I=t.voice)||void 0===I||null===(I=I.micButtonHint)||void 0===I?void 0:I.text)||(null===(A=t.panel)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.text)||"Click the button to start voice conversation",color:(null===(F=t.voice)||void 0===F||null===(F=F.micButtonHint)||void 0===F?void 0:F.color)||(null===(D=t.panel)||void 0===D||null===(D=D.micButtonHint)||void 0===D?void 0:D.color)||"#6B7280",fontSize:(null===(B=t.voice)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.fontSize)||(null===(R=t.panel)||void 0===R||null===(R=R.micButtonHint)||void 0===R?void 0:R.fontSize)||"12px"},null===(_=t.voice)||void 0===_?void 0:_.micButtonHint),null===(U=t.panel)||void 0===U?void 0:U.micButtonHint),avatarBackgroundColor:(null===(M=t.voice)||void 0===M?void 0:M.avatarBackgroundColor)||"#667eea",avatarActiveBackgroundColor:(null===(z=t.voice)||void 0===z?void 0:z.avatarActiveBackgroundColor)||"#667eea",statusTitleColor:(null===(N=t.voice)||void 0===N?void 0:N.statusTitleColor)||"#1e293b",statusSubtitleColor:(null===(V=t.voice)||void 0===V?void 0:V.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(L=t.voice)||void 0===L?void 0:L.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(H=t.voice)||void 0===H?void 0:H.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(K=t.voice)||void 0===K?void 0:K.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(W=t.voice)||void 0===W?void 0:W.transcriptTextColor)||"#1e293b",transcriptLabelColor:(null===(G=t.voice)||void 0===G?void 0:G.transcriptLabelColor)||"#94a3b8",controlButtonColor:(null===(q=t.voice)||void 0===q?void 0:q.controlButtonColor)||"#FFFFFF",controlButtonSecondaryColor:(null===(Q=t.voice)||void 0===Q?void 0:Q.controlButtonSecondaryColor)||"#64748b",endCallButtonColor:(null===(J=t.voice)||void 0===J?void 0:J.endCallButtonColor)||"#ef4444",language:(null===(Y=t.voice)||void 0===Y?void 0:Y.language)||t.language||"en",websocketUrl:(null===($=t.voice)||void 0===$?void 0:$.websocketUrl)||t.websocketUrl},t.voice),text:po({sendButtonColor:(null===(X=t.text)||void 0===X?void 0:X.sendButtonColor)||(null===(Z=t.panel)||void 0===Z?void 0:Z.sendButtonColor)||"#7C3AED",sendButtonHoverColor:(null===(tt=t.text)||void 0===tt?void 0:tt.sendButtonHoverColor)||(null===(et=t.panel)||void 0===et?void 0:et.sendButtonHoverColor)||"#6D28D9",sendButtonActiveColor:(null===(nt=t.text)||void 0===nt?void 0:nt.sendButtonActiveColor)||(null===(ot=t.panel)||void 0===ot?void 0:ot.sendButtonActiveColor)||"#6D28D9",sendButtonText:(null===(rt=t.text)||void 0===rt?void 0:rt.sendButtonText)||(null===(it=t.panel)||void 0===it?void 0:it.sendButtonText)||"➤",sendButtonTextColor:(null===(at=t.text)||void 0===at?void 0:at.sendButtonTextColor)||(null===(ct=t.panel)||void 0===ct?void 0:ct.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(st=t.text)||void 0===st?void 0:st.sendButtonFontSize)||(null===(ut=t.panel)||void 0===ut?void 0:ut.sendButtonFontSize)||"18px",sendButtonFontWeight:(null===(lt=t.text)||void 0===lt?void 0:lt.sendButtonFontWeight)||(null===(dt=t.panel)||void 0===dt?void 0:dt.sendButtonFontWeight)||"500",sendButtonHint:po(po({text:(null===(ft=t.text)||void 0===ft||null===(ft=ft.sendButtonHint)||void 0===ft?void 0:ft.text)||(null===(pt=t.panel)||void 0===pt||null===(pt=pt.sendButtonHint)||void 0===pt?void 0:pt.text)||"",color:(null===(ht=t.text)||void 0===ht||null===(ht=ht.sendButtonHint)||void 0===ht?void 0:ht.color)||(null===(vt=t.panel)||void 0===vt||null===(vt=vt.sendButtonHint)||void 0===vt?void 0:vt.color)||"#6B7280",fontSize:(null===(gt=t.text)||void 0===gt||null===(gt=gt.sendButtonHint)||void 0===gt?void 0:gt.fontSize)||(null===(yt=t.panel)||void 0===yt||null===(yt=yt.sendButtonHint)||void 0===yt?void 0:yt.fontSize)||"12px"},null===(mt=t.text)||void 0===mt?void 0:mt.sendButtonHint),null===(bt=t.panel)||void 0===bt?void 0:bt.sendButtonHint),inputPlaceholder:(null===(wt=t.text)||void 0===wt?void 0:wt.inputPlaceholder)||(null===(St=t.panel)||void 0===St?void 0:St.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(xt=t.text)||void 0===xt?void 0:xt.inputBorderColor)||(null===(kt=t.panel)||void 0===kt?void 0:kt.inputBorderColor)||"#E5E7EB",inputFocusColor:(null===(Ct=t.text)||void 0===Ct?void 0:Ct.inputFocusColor)||(null===(Pt=t.panel)||void 0===Pt?void 0:Pt.inputFocusColor)||"#7C3AED",inputBackgroundColor:(null===(Ot=t.text)||void 0===Ot?void 0:Ot.inputBackgroundColor)||(null===(Tt=t.panel)||void 0===Tt?void 0:Tt.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(Et=t.text)||void 0===Et?void 0:Et.inputTextColor)||(null===(jt=t.panel)||void 0===jt?void 0:jt.inputTextColor)||"#1F2937",inputFontSize:(null===(It=t.text)||void 0===It?void 0:It.inputFontSize)||(null===(At=t.panel)||void 0===At?void 0:At.inputFontSize)||"14px",inputBorderRadius:(null===(Ft=t.text)||void 0===Ft?void 0:Ft.inputBorderRadius)||(null===(Dt=t.panel)||void 0===Dt?void 0:Dt.inputBorderRadius)||20,inputPadding:(null===(Bt=t.text)||void 0===Bt?void 0:Bt.inputPadding)||(null===(Rt=t.panel)||void 0===Rt?void 0:Rt.inputPadding)||"6px 14px"},t.text),landing:po({backgroundColor:(null===(_t=t.landing)||void 0===_t?void 0:_t.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)",logo:(null===(Ut=t.landing)||void 0===Ut?void 0:Ut.logo)||"🤖",title:(null===(Mt=t.landing)||void 0===Mt?void 0:Mt.title)||null,titleColor:(null===(zt=t.landing)||void 0===zt?void 0:zt.titleColor)||"#1e293b",modeCardBackgroundColor:(null===(Nt=t.landing)||void 0===Nt?void 0:Nt.modeCardBackgroundColor)||"#FFFFFF",modeCardBorderColor:(null===(Vt=t.landing)||void 0===Vt?void 0:Vt.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Lt=t.landing)||void 0===Lt?void 0:Lt.modeCardHoverBorderColor)||Ie,modeCardIconBackgroundColor:(null===(Ht=t.landing)||void 0===Ht?void 0:Ht.modeCardIconBackgroundColor)||Ie,modeCardTitleColor:(null===(Kt=t.landing)||void 0===Kt?void 0:Kt.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(Wt=t.landing)||void 0===Wt?void 0:Wt.voiceCardIcon)||"🎤",textCardIcon:(null===(Gt=t.landing)||void 0===Gt?void 0:Gt.textCardIcon)||"💬"},t.landing),header:po({title:(null===(qt=t.header)||void 0===qt?void 0:qt.title)||"Chat Assistant",showTitle:!1!==(null===(Qt=t.header)||void 0===Qt?void 0:Qt.showTitle),backgroundColor:(null===(Jt=t.header)||void 0===Jt?void 0:Jt.backgroundColor)||(null===(Yt=t.button)||void 0===Yt?void 0:Yt.backgroundColor)||"#7C3AED",textColor:(null===($t=t.header)||void 0===$t?void 0:$t.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(Xt=t.header)||void 0===Xt?void 0:Xt.showCloseButton)},t.header),tooltips:po({newChat:(null===(Zt=t.tooltips)||void 0===Zt?void 0:Zt.newChat)||null,back:(null===(te=t.tooltips)||void 0===te?void 0:te.back)||null,close:(null===(ee=t.tooltips)||void 0===ee?void 0:ee.close)||null,mute:(null===(ne=t.tooltips)||void 0===ne?void 0:ne.mute)||null,speaker:(null===(oe=t.tooltips)||void 0===oe?void 0:oe.speaker)||null,endCall:(null===(re=t.tooltips)||void 0===re?void 0:re.endCall)||null},t.tooltips),messages:po({userBackgroundColor:(null===(ie=t.messages)||void 0===ie?void 0:ie.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(ae=t.messages)||void 0===ae?void 0:ae.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(ce=t.messages)||void 0===ce?void 0:ce.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(se=t.messages)||void 0===se?void 0:se.errorBackgroundColor)||"#FEE2E2",textColor:(null===(ue=t.messages)||void 0===ue?void 0:ue.textColor)||"#1F2937",fontSize:(null===(le=t.messages)||void 0===le?void 0:le.fontSize)||"14px",borderRadius:(null===(de=t.messages)||void 0===de?void 0:de.borderRadius)||8},t.messages),animation:po({enableHover:!1!==(null===(fe=t.animation)||void 0===fe?void 0:fe.enableHover),enablePulse:!1!==(null===(pe=t.animation)||void 0===pe?void 0:pe.enablePulse),enableSlide:!1!==(null===(he=t.animation)||void 0===he?void 0:he.enableSlide),duration:(null===(ve=t.animation)||void 0===ve?void 0:ve.duration)||.3},t.animation),behavior:po({autoOpen:(null===(ge=t.behavior)||void 0===ge?void 0:ge.autoOpen)||!1,startOpen:(null===(ye=t.behavior)||void 0===ye?void 0:ye.startOpen)||!1,hidden:(null===(me=t.behavior)||void 0===me?void 0:me.hidden)||!1,autoConnect:(null===(be=t.behavior)||void 0===be?void 0:be.autoConnect)||!1,showWelcomeMessage:!1!==(null===(we=t.behavior)||void 0===we?void 0:we.showWelcomeMessage),welcomeMessage:(null===(Se=t.behavior)||void 0===Se?void 0:Se.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:void 0===(null===(xe=t.behavior)||void 0===xe?void 0:xe.enableVoiceMode)||t.behavior.enableVoiceMode,mode:(null===(ke=t.behavior)||void 0===ke?void 0:ke.mode)||"unified"},t.behavior),accessibility:po({ariaLabel:(null===(Ce=t.accessibility)||void 0===Ce?void 0:Ce.ariaLabel)||"Chat Assistant",ariaDescription:(null===(Pe=t.accessibility)||void 0===Pe?void 0:Pe.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(Oe=t.accessibility)||void 0===Oe?void 0:Oe.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},forceConversationId:t.forceConversationId,primaryColor:je},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.on("domainError",function(e){t.textInterface.showError(e),t.textInterface.stopStreamingState()}),this.sdk.on("error",function(e){e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))||(t.textInterface.showError(e.message||e),t.textInterface.stopStreamingState())}),this.sdk.on("chunk",function(e){t.textInterface.appendStreamingChunk(e)}),this.sdk.on("done",function(e){var n=e.text;t.textInterface.finalizeStreaming(n)})}},{key:"createWidget",value:function(){console.log("🏗️ createWidget called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var t=document.getElementById("text-chat-widget");t&&t.remove();var e=document.createElement("div");if(e.id="text-chat-widget",e.innerHTML=this.generateWidgetHTML(),document.body.appendChild(e),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("text-chat-panel");n&&(this.isOpen=!0,n.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){var t=this,e=(this.config.position,this.config.button),n=this.config.icon,o=(this.config.panel,this.config.header),r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),i={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i),s=this.config.behavior.mode||"unified",u="unified"===s,l="unified"===s||"voice-only"===s,d="unified"===s||"text-only"===s,f=function(e){var n=t.config.language||"en";return(t.translations[n]||t.translations.en)[e]||e},p=function(e){var n,o=null===(n=t.config.tooltips)||void 0===n?void 0:n[e];return null!=o?o:{newChat:f("newChat"),back:f("back"),close:f("close"),mute:f("mute"),speaker:f("speaker"),endCall:f("endCall")}[e]||""};return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header" style="background: ').concat(o.backgroundColor,"; color: ").concat(o.textColor,';">\n <div>\n ').concat(o.showTitle?'<div class="header-title">'.concat(o.title,"</div>"):"",'\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat(f("online"),'</span>\n </div>\n </div>\n \n <div style="display: flex; gap: 12px; align-items: center;">\n \x3c!-- New Chat Button (hide on landing screen, show otherwise) --\x3e\n <button class="header-icon new-chat-btn" id="newChatBtn" title="').concat(p("newChat"),'" style="').concat(u?"display: none;":"",'">\n <span style="font-size: 18px; font-weight: bold;">+</span>\n </button>\n \n \x3c!-- Back Button (only show in unified mode) --\x3e\n ').concat("unified"===s?'<button class="header-icon back-btn" id="backBtn" title="'.concat(p("back"),'" style="display: none;">\n <span style="font-size: 16px;">‹</span>\n </button>'):"","\n \n \x3c!-- Close Button --\x3e\n ").concat(o.showCloseButton?'<button class="header-icon close-btn" id="closeBtn" title="'+p("close")+'"><span style="font-size: 18px; font-weight: bold;">×</span></button>':"","\n </div>\n </div>\n\n ").concat(u?'\n <div class="landing-screen" id="landingScreen">\n <div class="landing-logo">🤖</div>\n <div class="landing-title">'.concat(f("landingTitle"),'</div>\n <div class="mode-selection">\n ').concat(l?'<div class="mode-card voice" id="mode-card-voice">\n <div class="mode-card-icon">🎤</div>\n <div class="mode-card-title">'.concat(f("voiceCall"),"</div>\n </div>"):"","\n ").concat(d?'<div class="mode-card text" id="mode-card-text">\n <div class="mode-card-icon">💬</div>\n <div class="mode-card-title">'.concat(f("textChat"),"</div>\n </div>"):"","\n </div>\n </div>"):"","\n\n ").concat(l?this.voiceInterface.generateHTML():"","\n ").concat(d?this.textInterface.generateHTML():"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var t=this.config.position,e=t.offset||{x:20,y:20},n="";return"top"===t.vertical?n+="top: ".concat(e.y,"px;"):"bottom"===t.vertical?n+="bottom: ".concat(e.y,"px;"):"center"===t.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===t.horizontal?n+="left: ".concat(e.x,"px;"):"right"===t.horizontal?n+="right: ".concat(e.x,"px;"):"center"===t.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(t){var e=this.config.icon;switch(e.type){case"custom":return'<img src="'.concat(e.customImage,'" alt="Chat Assistant" style="width: ').concat(t,"px; height: ").concat(t,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(t,'px; line-height: 1;">').concat(e.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*t),'px; font-weight: bold; color: white;">').concat(e.text,"</span>");case"microphone":default:return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>');case"chat":return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/>\n </svg>')}}},{key:"generateCSS",value:function(t,e,n){var o,r,i,a,c,s,u,l=this.config.button,d=this.config.icon,f=this.config.panel,p=this.config.header,h=(this.config.messages,this.config.animation),v=this.config.behavior.mode||"unified",g="unified"===v||"voice-only"===v,y="unified"===v||"text-only"===v,m=p.backgroundColor;return'\n /* MOBILE FIRST - Default styles for all devices */\n #text-chat-widget {\n position: fixed !important;\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n /* Mobile defaults */\n right: 10px;\n bottom: 10px;\n left: auto;\n top: auto;\n }\n \n /* Desktop positioning (only on larger screens) */\n @media (min-width: 769px) {\n #text-chat-widget {\n '.concat(t,"\n right: ").concat("right"===this.config.position.horizontal?"20px":"auto",";\n left: ").concat("left"===this.config.position.horizontal?"20px":"auto",";\n bottom: ").concat("bottom"===this.config.position.vertical?"20px":"auto",";\n top: ").concat("top"===this.config.position.vertical?"20px":"auto",";\n }\n }\n \n /* Mobile override (force mobile positioning) */\n @media (max-width: 768px) {\n #text-chat-widget {\n right: 10px !important;\n bottom: 10px !important;\n left: auto !important;\n top: auto !important;\n transform: none !important;\n }\n }\n \n @media (max-width: 480px) {\n #text-chat-widget {\n right: 8px !important;\n bottom: 8px !important;\n left: auto !important;\n top: auto !important;\n }\n }\n \n #text-chat-button {\n width: ").concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===l.shape?"50%":"square"===l.shape?"0":"12px",";\n background: ").concat(l.backgroundColor||d.backgroundColor||"#7C3AED",";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(h.duration,"s ease;\n box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);\n touch-action: manipulation;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n user-select: none;\n min-width: 44px;\n min-height: 44px;\n }\n \n @media (max-width: 768px) {\n #text-chat-widget {\n right: 10px !important;\n bottom: 10px !important;\n left: auto !important;\n top: auto !important;\n transform: none !important;\n }\n \n #text-chat-button {\n width: 56px !important;\n height: 56px !important;\n min-width: 56px !important;\n min-height: 56px !important;\n max-width: 56px !important;\n max-height: 56px !important;\n }\n \n #text-chat-panel {\n position: fixed !important;\n left: 10px !important;\n right: 10px !important;\n bottom: 76px !important; /* 56px button + 20px gap */\n top: 60px !important; /* Add top spacing */\n width: auto !important;\n max-width: none !important;\n height: auto !important; /* Change from max-height to auto */\n max-height: none !important; /* Remove max-height */\n transform: none !important;\n margin: 0 !important;\n }\n \n #text-chat-panel .widget-header {\n padding: 10px 14px;\n min-height: 56px;\n }\n \n #text-chat-panel .header-title {\n font-size: 15px;\n }\n \n #text-chat-panel .header-icon {\n width: 40px;\n height: 40px;\n min-width: 40px;\n min-height: 40px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 12px 16px !important;\n min-height: 48px !important;\n }\n \n #text-chat-send {\n min-width: 48px !important;\n min-height: 48px !important;\n width: 48px !important;\n height: 48px !important;\n }\n \n .landing-screen {\n padding: 16px;\n }\n \n .landing-logo {\n font-size: 40px;\n }\n \n .landing-title {\n font-size: 18px;\n margin-bottom: 16px;\n }\n \n .mode-selection {\n flex-direction: column;\n gap: 12px;\n align-items: center;\n }\n \n .mode-card {\n max-width: 100%;\n width: 100%;\n padding: 16px;\n }\n \n .mode-card-icon {\n width: 50px;\n height: 50px;\n font-size: 28px;\n }\n \n .mode-card-title {\n font-size: 14px;\n }\n }\n \n @media (max-width: 480px) {\n #text-chat-widget {\n right: 8px !important;\n bottom: 8px !important;\n left: auto !important;\n top: auto !important;\n }\n \n #text-chat-button {\n width: 54px !important;\n height: 54px !important;\n min-width: 54px !important;\n min-height: 54px !important;\n }\n \n #text-chat-panel {\n left: 8px !important;\n right: 8px !important;\n bottom: 70px !important;\n top: 50px !important; /* Add top spacing for very small screens */\n height: auto !important;\n max-height: none !important;\n }\n \n #text-chat-panel .widget-header {\n padding: 8px 12px;\n min-height: 52px;\n }\n \n #text-chat-panel .header-title {\n font-size: 14px;\n }\n \n .landing-logo {\n font-size: 36px;\n }\n \n .landing-title {\n font-size: 16px;\n }\n }\n \n ").concat(h.enableHover?"\n #text-chat-button:hover {\n background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);\n transform: scale(1.05);\n box-shadow: 0 8px 20px rgba(102, 126, 234, 0.5);\n }\n ":"","\n \n #text-chat-panel {\n display: none;\n position: fixed;\n bottom: calc(").concat(e,"px + 20px);\n ").concat("right"===this.config.position.horizontal?"right: 20px;":"left: 20px;","\n width: ").concat(f.width,"px;\n max-width: calc(100vw - 40px);\n height: ").concat(f.height,"px;\n max-height: calc(100vh - ").concat(e,"px - 40px);\n background: transparent;\n border-radius: ").concat(f.borderRadius,"px;\n border: none;\n flex-direction: column;\n overflow: hidden;\n ").concat(f.backdropFilter?"backdrop-filter: ".concat(f.backdropFilter,";"):"","\n ").concat(h.enableSlide?"transition: all ".concat(h.duration,"s ease;"):"","\n box-sizing: border-box;\n }\n \n #text-chat-panel.open {\n display: flex;\n ").concat(h.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n\n /* Shell for gradient border/background */\n .widget-shell { width: 100%; height: 100%; padding: 0; border-radius: ").concat(f.borderRadius,"px; background: transparent; box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; display: flex; flex-direction: column; box-sizing: border-box; }\n .panel-inner { width: 100%; height: 100%; background: #ffffff; border-radius: ").concat(f.borderRadius,"px; overflow: hidden; display:flex; flex-direction: column; padding: 0; box-sizing: border-box; max-width: 100%; }\n\n /* New structure styles matching provided design */\n #text-chat-panel .widget-container {\n width: 100%; height: 100%; min-height: 0; background: #FFFFFF; overflow: hidden; display: flex; flex-direction: column; border-radius: ").concat(f.borderRadius,"px;\n container-type: size;\n }\n \n /* Ensure content areas can scroll when height is constrained */\n #text-chat-panel .widget-container > .landing-screen,\n #text-chat-panel .widget-container > .voice-interface,\n #text-chat-panel .widget-container > .text-interface {\n flex: 1;\n min-height: 0;\n overflow-y: auto;\n overflow-x: hidden;\n }\n \n /* Header should not scroll */\n #text-chat-panel .widget-header {\n padding: 12px 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-top-left-radius: ").concat(f.borderRadius,"px;\n border-top-right-radius: ").concat(f.borderRadius,"px;\n flex-shrink: 0;\n min-height: 60px;\n box-sizing: border-box;\n }\n #text-chat-panel .header-title { font-size: 16px; font-weight: 600; }\n #text-chat-panel .header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.9; }\n #text-chat-panel .status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }\n @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n /* Header icon buttons */\n .header-icon {\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 36px;\n height: 36px;\n min-width: 36px;\n min-height: 36px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n flex-shrink: 0;\n font-size: 16px;\n padding: 0;\n box-sizing: border-box;\n }\n \n .header-icon:hover {\n background: rgba(255, 255, 255, 0.3);\n }\n \n .header-icon svg {\n pointer-events: none;\n stroke: white;\n fill: none;\n }\n \n .back-btn.visible {\n display: flex !important;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { \n display: none; \n flex: 1; \n padding: 20px; \n background: ").concat((null===(o=this.config.landing)||void 0===o?void 0:o.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)","; \n align-items: center; \n justify-content: flex-start; \n flex-direction: column; \n gap: 16px; \n overflow-y: auto; \n min-height: 0; \n }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { \n font-size: 20px; \n color: ").concat((null===(r=this.config.landing)||void 0===r?void 0:r.titleColor)||"#1e293b","; \n font-weight: 700; \n margin-bottom: 20px; \n text-align: center;\n width: 100%;\n }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { \n flex: 1; \n max-width: 180px; \n background: ").concat((null===(i=this.config.landing)||void 0===i?void 0:i.modeCardBackgroundColor)||"#FFFFFF","; \n border: 2px solid ").concat((null===(a=this.config.landing)||void 0===a?void 0:a.modeCardBorderColor)||"#E2E8F0","; \n border-radius: 20px; \n padding: 20px 12px; \n cursor: pointer; \n display: flex; \n flex-direction: column; \n align-items: center; \n gap: 8px; \n transition: transform ").concat(h.duration,"s ease, box-shadow ").concat(h.duration,"s ease, border-color ").concat(h.duration,"s ease; \n box-shadow: 0 4px 12px rgba(0,0,0,0.05); \n }\n .mode-card:hover { \n transform: translateY(-6px); \n box-shadow: 0 12px 24px rgba(102, 126, 234, 0.2); \n border-color: ").concat((null===(c=this.config.landing)||void 0===c?void 0:c.modeCardHoverBorderColor)||m,"; \n }\n .mode-card-icon { \n width: 60px; \n height: 60px; \n display: flex; \n align-items: center; \n justify-content: center; \n border-radius: 50%; \n background: ").concat((null===(s=this.config.landing)||void 0===s?void 0:s.modeCardIconBackgroundColor)||m,"; \n color: #fff; \n font-size: 32px; \n }\n .mode-card-title { \n color: ").concat((null===(u=this.config.landing)||void 0===u?void 0:u.modeCardTitleColor)||"#111827","; \n font-weight: 600; \n text-align: center;\n width: 100%;\n }\n\n ").concat(g?this.voiceInterface.generateCSS():"","\n ").concat(y?this.textInterface.generateCSS():"","\n \n #text-chat-send-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this;console.log("⚙️ setupWidgetEvents called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n"),currentView:this.currentView});var e=document.getElementById("text-chat-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("closeBtn");n&&(n.onclick=function(){return t.togglePanel()});var o=this.config.behavior.mode||"unified",r="unified"===o,i="unified"===o||"voice-only"===o,a="unified"===o||"text-only"===o,c=document.getElementById("backBtn"),s=document.getElementById("landingScreen"),u=document.getElementById("mode-card-voice"),l=document.getElementById("mode-card-text"),d=document.getElementById("textInterface"),f=document.getElementById("voiceInterface");c&&(c.onclick=function(){return t.showLanding()}),r?(u&&(u.onclick=function(){return t.showVoice()}),l&&(l.onclick=function(){return t.showText()}),"text"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.add("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="")):"voice"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.remove("active"),f&&f.classList.add("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="none")):(this.currentView="landing",s&&s.classList.add("active"),d&&d.classList.remove("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.remove("visible"))):"voice-only"===o?(f&&f.classList.add("active"),d&&d.classList.remove("active"),s&&s.classList.remove("active")):"text-only"===o&&(d&&d.classList.add("active"),f&&f.classList.remove("active"),s&&s.classList.remove("active")),i&&(console.log("⚙️ Setting up voice interface event handlers"),this.voiceInterface.setupEventHandlers()),a&&(console.log("⚙️ Setting up text interface event handlers"),this.textInterface.setupEventHandlers());var p=document.getElementById("newChatBtn");p&&(p.onclick=function(){return t.textInterface.startNewChat()},r&&(p.style.display="none")),this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"startNewChat",value:function(){this.textInterface.startNewChat()}},{key:"showLanding",value:function(){if("unified"===(this.config.behavior.mode||"unified")){this.currentView="landing";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),r&&(r.style.display="none")}}},{key:"showText",value:function(){this.currentView="text";var t=document.getElementById("landingScreen"),e=document.getElementById("voiceInterface"),n=document.getElementById("backBtn"),o=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),this.textInterface.show();var r=this.config.behavior.mode||"unified";n&&"unified"===r&&n.classList.add("visible"),o&&(o.style.display="")}},{key:"showVoice",value:function(){this.currentView="voice";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active");var i=this.config.behavior.mode||"unified";o&&"unified"===i&&o.classList.add("visible"),r&&(r.style.display="none")}},{key:"setupKeyboardNavigation",value:function(){var t=this;document.addEventListener("keydown",function(e){"Escape"===e.key&&t.isOpen&&t.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("text-chat-panel").classList.toggle("open"),this.isOpen&&setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},100),this.isOpen&&!this.isActive&&this.config.behavior.autoConnect&&this.startChat()}},{key:"startChat",value:(i=uo(ao().m(function t(){return ao().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.textInterface.setActive(!0);case 1:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"sendMessage",value:(r=uo(ao().m(function t(){return ao().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.textInterface.sendMessage();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=uo(ao().m(function t(){var e,n,o,r,i,a,c;return ao().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://backend.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"addMessage",value:function(t,e){this.textInterface.addMessage(t,e)}},{key:"beginStreaming",value:function(){this.textInterface.beginStreaming()}},{key:"appendStreamingChunk",value:function(t){this.textInterface.appendStreamingChunk(t)}},{key:"finalizeStreaming",value:function(t){this.textInterface.finalizeStreaming(t)}},{key:"stopStreamingState",value:function(){this.textInterface.stopStreamingState()}},{key:"showError",value:function(t){this.textInterface.showError(t)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n,o,r,i,a,c;console.log("🔄 updateConfig called",{newConfig:t,stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var s,u,l=po({},this.config);t.panel&&(l.panel=po(po({},this.config.panel),t.panel)),t.voice&&(l.voice=po(po({},this.config.voice),t.voice),t.voice.micButtonHint&&(l.voice.micButtonHint=po(po({},null===(s=this.config.voice)||void 0===s?void 0:s.micButtonHint),t.voice.micButtonHint))),t.text&&(l.text=po(po({},this.config.text),t.text),t.text.sendButtonHint&&(l.text.sendButtonHint=po(po({},null===(u=this.config.text)||void 0===u?void 0:u.sendButtonHint),t.text.sendButtonHint))),void 0!==t.language&&(l.language=t.language),void 0!==t.language&&(["he","ar"].includes(t.language)?l.direction="rtl":void 0===t.direction&&(l.direction="ltr")),t.translations&&(l.translations=t.translations,this.translations=t.translations),t.button&&(l.button=po(po({},this.config.button),t.button)),t.header&&(l.header=po(po({},this.config.header),t.header)),t.icon&&(l.icon=po(po({},this.config.icon),t.icon)),t.messages&&(l.messages=po(po({},this.config.messages),t.messages)),t.animation&&(l.animation=po(po({},this.config.animation),t.animation)),t.behavior&&(l.behavior=po(po({},this.config.behavior),t.behavior)),t.accessibility&&(l.accessibility=po(po({},this.config.accessibility),t.accessibility)),t.tooltips&&(l.tooltips=po(po({},this.config.tooltips),t.tooltips)),t.landing&&(l.landing=po(po({},this.config.landing),t.landing)),void 0!==t.direction&&void 0===l.direction&&(l.direction=t.direction),void 0!==t.primaryColor&&(l.primaryColor=t.primaryColor),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction","voice","text","animation","behavior","accessibility","language","tooltips","landing","primaryColor"].includes(e)||(l[e]=t[e])}),null===(e=this.config)||void 0===e||e.language,this.config=this.mergeWithDefaults(l);var d=this.config.language||"en",f=po(po(po({},this.config),this.config.voice),{},{language:d,websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16});this.voiceInterface=new Yn(f);var p=po(po(po({},this.config),this.config.text),{},{language:d,translations:this.translations});this.textInterface=new ro(p,this.sdk);var h=document.getElementById("text-chat-widget");h&&h.remove(),this.createWidget(),this.textInterface&&this.textInterface.updateInputAttributes&&this.textInterface.updateInputAttributes()}},{key:"destroy",value:function(){var t=document.getElementById("text-chat-widget");t&&t.remove(),this.sdk&&this.sdk.destroy(),this.voiceInterface&&this.voiceInterface.destroy()}},{key:"startVoiceCall",value:(n=uo(ao().m(function t(){return ao().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.voiceInterface.startVoiceCall();case 1:return t.a(2)}},t,this)})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){this.voiceInterface.endVoiceCall()}},{key:"toggleMute",value:function(){this.voiceInterface.toggleMute()}},{key:"toggleSpeaker",value:function(){this.voiceInterface.toggleSpeaker()}}],e&&vo(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,r,i}(),mo="2.0.0";const bo={VoiceSDK:ht,VoiceSDK_v2:Xe,TextChatSDK:fn,WebSocketManager:A,AudioRecorder:H,AudioPlayer:tt,EventEmitter:c,VoiceButton:Cn,VanillaVoiceButton:Bn,AgentSDK:Ln,TTPChatWidget:yo,VERSION:mo};return o})());
3
3
  //# sourceMappingURL=agent-widget.js.map