ttp-agent-sdk 2.3.4 → 2.3.6

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 i=null;if(void 0!==o&&(i=""+o),void 0!==e.key&&(i=""+e.key),"key"in e)for(var r in o={},e)"key"!==r&&(o[r]=e[r]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:i,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,i={};function r(t,e,o){this.props=t,this.context=e,this.refs=i,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=i,this.updater=o||n}r.prototype.isReactComponent={},r.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")},r.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=r.prototype;var s=c.prototype=new a;s.constructor=c,o(s,r.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 i=e[o];if(void 0!==i)return i.exports;var r=e[o]={exports:{}};return t[o](r,r.exports,n),r.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 i(t){return i="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},i(t)}function r(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"!=i(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==i(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>rn,AudioPlayer:()=>Z,AudioRecorder:()=>V,EventEmitter:()=>c,TTPChatWidget:()=>An,TextChatSDK:()=>Te,VERSION:()=>Fn,VanillaVoiceButton:()=>Ye,VoiceButton:()=>Ne,VoiceSDK:()=>pt,VoiceSDK_v2:()=>ve,WebSocketManager:()=>B,default:()=>Rn});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&&r(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,i,r,a,c=[],s=!0,u=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw i}}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,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}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 r,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,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return h(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,h(d,"constructor",u),h(u,"constructor",s),s.displayName="GeneratorFunction",h(u,i,"GeneratorFunction"),h(d),h(d,i,"Generator"),h(d,o,function(){return this}),h(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:r,m:f}})()}function h(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}h=function(t,e,n,o){function r(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},h(t,e,n,o)}function v(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}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:(i=p().m(function t(e){var n,o,i=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(i.connections.has(e)){var o=i.connections.get(e);i.connectionCounts.set(e,(i.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){i.creatingConnections.delete(e),i.emit("open",t,e)}),o.addEventListener("close",function(t){i.creatingConnections.delete(e),i.connections.delete(e),i.connectionCounts.delete(e),i.emit("close",t,e)}),o.addEventListener("error",function(t){i.creatingConnections.delete(e),i.emit("error",t,e)}),o.addEventListener("message",function(t){i.emit("message",t,e)}),t.a(2,o)}},t,this)}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){v(r,n,o,a,c,"next",t)}function c(t){v(r,n,o,a,c,"throw",t)}a(void 0)})},function(t){return r.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),i=o[0],r=o[1];e[i]={readyState:r.readyState,subscribers:this.connectionCounts.get(i)||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,i,r}(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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return C(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,C(d,"constructor",u),C(u,"constructor",s),s.displayName="GeneratorFunction",C(u,i,"GeneratorFunction"),C(d),C(d,i,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(k=function(){return{w:r,m:f}})()}function C(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}C=function(t,e,n,o){function r(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},C(t,e,n,o)}function P(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}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,E(o.key),o)}}function E(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 T(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(T=function(){return!!t})()}function I(t){return I=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},I(t)}function j(t,e){return j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},j(t,e)}var B=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=I(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,T()?Reflect.construct(e,n||[],I(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&&j(t,e)}(e,t),n=e,o=[{key:"connect",value:(r=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 i=r.apply(t,e);function a(t){P(i,n,o,a,c,"next",t)}function c(t){P(i,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))},i=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",i),this.eventHandlers={open:e,close:n,error:o,message:i}}}},{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}}}],i=[{key:"getSingletonStatus",value:function(){return S.getAllConnections()}},{key:"clearAllConnections",value:function(){S.clearAll()}}],o&&O(n.prototype,o),i&&O(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a}(c);function D(t){return D="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},D(t)}function A(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return F(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(F(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,F(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,F(d,"constructor",u),F(u,"constructor",s),s.displayName="GeneratorFunction",F(u,i,"GeneratorFunction"),F(d),F(d,i,"Generator"),F(d,o,function(){return this}),F(d,"toString",function(){return"[object Generator]"}),(A=function(){return{w:r,m:f}})()}function F(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}F=function(t,e,n,o){function r(e,n){F(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},F(t,e,n,o)}function R(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function _(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){R(r,o,i,a,c,"next",t)}function c(t){R(r,o,i,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"!=D(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==D(e)?e:e+""}function N(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(N=function(){return!!t})()}function L(t){return L=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},L(t)}function H(t,e){return H=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},H(t,e)}var V=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"==D(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||[],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&&H(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,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}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 r,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,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}(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 i=n.substring(0,n.lastIndexOf("/"));return"".concat(i,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(r=_(A().m(function t(){var e,n,o=this;return A().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,i=e.data;"pcm_audio_data"===n&&o.emit("audioData",i)},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 r.apply(this,arguments)})},{key:"stop",value:(i=_(A().m(function t(){var e;return A().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 i.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,i,r}(c);function W(t){return W="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},W(t)}function K(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return G(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,G(d,"constructor",u),G(u,"constructor",s),s.displayName="GeneratorFunction",G(u,i,"GeneratorFunction"),G(d),G(d,i,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(K=function(){return{w:r,m:f}})()}function G(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}G=function(t,e,n,o){function r(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},G(t,e,n,o)}function Q(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}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"!=W(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=W(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==W(e)?e:e+""}function 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"==W(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,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:(i=K().m(function t(){var e,n,o,i,r,a,c,s,u,l=this;return K().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"!==(i=this.audioContext).state){t.n=3;break}return t.n=3,i.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return r=t.v,t.n=5,i.decodeAudioData(r);case 5:a=t.v,c=n&&!this.isPlaying&&null===this.currentSource,(s=i.createBufferSource()).buffer=a,s.connect(i.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]])}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){Q(r,n,o,a,c,"next",t)}function c(t){Q(r,n,o,a,c,"throw",t)}a(void 0)})},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)}}],o&&q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return nt(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,nt(d,"constructor",u),nt(u,"constructor",s),s.displayName="GeneratorFunction",nt(u,i,"GeneratorFunction"),nt(d),nt(d,i,"Generator"),nt(d,o,function(){return this}),nt(d,"toString",function(){return"[object Generator]"}),(et=function(){return{w:r,m:f}})()}function nt(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}nt=function(t,e,n,o){function r(e,n){nt(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},nt(t,e,n,o)}function ot(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function it(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ot(r,o,i,a,c,"next",t)}function c(t){ot(r,o,i,a,c,"throw",t)}a(void 0)})}}function rt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function at(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?rt(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=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 B(at(at({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new V(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),i=0;i<n.length;i++)o[i]=n.charCodeAt(i);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(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=it(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=it(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=it(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:(r=it(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 r.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(i=it(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 i.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,i,r,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 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 Tt(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 jt=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 i=16384;0===(t&i)&&e>0;e--,i>>=1);n=t>>e+3&15}return 85^(o|e<<4|n)}}])&&Tt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();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 Dt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return At(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(At(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,At(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,At(d,"constructor",u),At(u,"constructor",s),s.displayName="GeneratorFunction",At(u,i,"GeneratorFunction"),At(d),At(d,i,"Generator"),At(d,o,function(){return this}),At(d,"toString",function(){return"[object Generator]"}),(Dt=function(){return{w:r,m:f}})()}function At(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}At=function(t,e,n,o){function r(e,n){At(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},At(t,e,n,o)}function Ft(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Rt(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Ft(r,o,i,a,c,"next",t)}function c(t){Ft(r,o,i,a,c,"throw",t)}a(void 0)})}}function _t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Ut(o.key),o)}}function Ut(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+""}function Mt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Mt=function(){return!!t})()}function zt(t){return zt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},zt(t)}function Nt(t,e){return Nt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Nt(t,e)}var Lt=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=zt(e),function(t,e){if(e&&("object"==Bt(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,Mt()?Reflect.construct(e,n||[],zt(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.pcmChunkQueue=[],t.isProcessingPcmQueue=!1,t.codecs={pcm:new xt,pcmu:new Ot,pcma:new jt},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&&Nt(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(),i=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&i&&this.SUPPORTED_CONTAINERS.includes(o)&&this.SUPPORTED_ENCODINGS.includes(i)&&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:(a=Rt(Dt().m(function t(e){return Dt().w(function(t){for(;;)switch(t.n){case 0:this.pcmChunkQueue.push(e),this.isProcessingPcmQueue||this.processPcmQueue();case 1:return t.a(2)}},t,this)})),function(t){return a.apply(this,arguments)})},{key:"processPcmQueue",value:(r=Rt(Dt().m(function t(){var e,n,o,i,r,a,c,s,u,l,d,f,p,h,v,g,y,m,b,w,S=this;return Dt().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(i=o,o.byteLength%2!=0&&(console.warn("⚠️ Odd PCM chunk size, padding:",o.byteLength),(r=new Uint8Array(o.byteLength+1)).set(new Uint8Array(o),0),r[o.byteLength]=0,i=r.buffer),a=new Int16Array(i),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 r.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(),i=this.isWavFile(e);if(i&&console.log("🎵 AudioPlayer: Data has WAV header (RIFF)"),o&&i)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&&!i)console.log("🎵 AudioPlayer: Processing as RAW data (as negotiated)");else{if(n&&i)return console.log("✅ AudioPlayer: Processing as WAV file (matches negotiation)"),this.handleWavFile(e);if(n&&!i)return console.warn("⚠️ AudioPlayer: Negotiated WAV but data lacks WAV header. Attempting WAV processing anyway."),this.handleWavFile(e);if(!this.outputFormat&&i)return console.log("🎵 AudioPlayer: No format negotiated, auto-detecting WAV"),this.handleWavFile(e);this.outputFormat||i||(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),i=n.decode(o),r=this.createWavHeader(i.byteLength,e.sampleRate,e.channels,16);return new Blob([r,i],{type:"audio/wav"})}},{key:"handleRawData",value:function(t){var e,n,o=this.outputFormat.encoding.toLowerCase(),i=this.getCodec(o);if(!i)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 r=this.outputFormat.bitDepth||16;t.length,24===r?(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===r?(console.log("🔄 AudioPlayer: Converting 8-bit PCM to 16-bit PCM"),e=this.convert8BitTo16Bit(t),n=16):(e=t.buffer,n=r,console.log("✅ AudioPlayer: Using native ".concat(r,"-bit PCM (no conversion needed)")))}else e=i.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 i=t[3*o],r=t[3*o+1],a=t[3*o+2],c=i|r<<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 i=t[o];n[o]=256*(i-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 i=new ArrayBuffer(44),r=new DataView(i);return r.setUint32(0,1380533830,!1),r.setUint32(4,36+t,!0),r.setUint32(8,1463899717,!1),r.setUint32(12,1718449184,!1),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,n,!0),r.setUint32(24,e,!0),r.setUint32(28,e*n*o/8,!0),r.setUint16(32,n*o/8,!0),r.setUint16(34,o,!0),r.setUint32(36,1684108385,!1),r.setUint32(40,t,!0),i}},{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:"interactive"}),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:(i=Rt(Dt().m(function t(){var e,n,o,i,r,a,c,s=this;return Dt().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:i=t.v,r=n&&!this.isPlaying&&null===this.currentSource,(a=this.audioContext.createBufferSource()).buffer=i,a.connect(this.audioContext.destination),this.currentSource=a,this.isPlaying=!0,r&&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 i.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;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],this.pcmChunkQueue=[],this.isProcessingPcmQueue=!1,this.nextStartTime=0,this.scheduledBuffers=0,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",outputFormat:this.outputFormat}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.removeAllListeners()}}],o&&_t(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a}(mt);const Ht=Lt;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 Wt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Kt(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Kt(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,Kt(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Kt(d,"constructor",u),Kt(u,"constructor",s),s.displayName="GeneratorFunction",Kt(u,i,"GeneratorFunction"),Kt(d),Kt(d,i,"Generator"),Kt(d,o,function(){return this}),Kt(d,"toString",function(){return"[object Generator]"}),(Wt=function(){return{w:r,m:f}})()}function Kt(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Kt=function(t,e,n,o){function r(e,n){Kt(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Kt(t,e,n,o)}function Gt(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Qt(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Gt(r,o,i,a,c,"next",t)}function c(t){Gt(r,o,i,a,c,"throw",t)}a(void 0)})}}function qt(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 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,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+""}function $t(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return($t=function(){return!!t})()}function Xt(t){return Xt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Xt(t)}function Zt(t,e){return Zt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Zt(t,e)}var te=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=Xt(e),function(t,e){if(e&&("object"==Vt(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,$t()?Reflect.construct(e,n||[],Xt(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&&Zt(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 qt(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)?qt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}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 r,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,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}(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 i=n.substring(0,n.lastIndexOf("/"));return"".concat(i,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(r=Qt(Wt().m(function t(){var e,n,o=this;return Wt().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,i=e.data;"pcm_audio_data"===n&&o.emit("audioData",i)},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 r.apply(this,arguments)})},{key:"stop",value:(i=Qt(Wt().m(function t(){var e;return Wt().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 i.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&&Jt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(mt);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 ne(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 oe(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ne(Object(n),!0).forEach(function(e){fe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ne(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ie(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return re(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(re(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,re(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,re(d,"constructor",u),re(u,"constructor",s),s.displayName="GeneratorFunction",re(u,i,"GeneratorFunction"),re(d),re(d,i,"Generator"),re(d,o,function(){return this}),re(d,"toString",function(){return"[object Generator]"}),(ie=function(){return{w:r,m:f}})()}function re(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}re=function(t,e,n,o){function r(e,n){re(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},re(t,e,n,o)}function ae(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function ce(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ae(r,o,i,a,c,"next",t)}function c(t){ae(r,o,i,a,c,"throw",t)}a(void 0)})}}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,pe(o.key),o)}}function ue(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ue=function(){return!!t})()}function le(t){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},le(t)}function de(t,e){return de=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},de(t,e)}function fe(t,e,n){return(e=pe(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function pe(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+""}var he=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=le(e),function(t,e){if(e&&("object"==ee(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,ue()?Reflect.construct(e,n||[],le(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||200,outputCodec:n.outputCodec,agentSettingsOverride:n.agentSettingsOverride||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.websocket=null,t.audioPlayer=new Ht(t.config),t.audioRecorder=new te(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&&de(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 i=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();if(!i||!e.SUPPORTED_OUTPUT_ENCODINGS.includes(i))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 r=null===(o=t.container)||void 0===o?void 0:o.toLowerCase();return r&&e.SUPPORTED_OUTPUT_CONTAINERS.includes(r)?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&&t.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.sendMessage({t:"audio_stopped_playing"})}),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,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.sendMessage({t:"barge_in"})),t.emit("recordingStarted"),console.log("🎤 VoiceSDK v2: Recording started")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.isRecording&&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=ce(ie().m(function t(){var e,n,o=this;return ie().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 i={t:"hello",v:this.config.protocolVersion,inputFormat:t,requestedOutputFormat:e,outputFrameDurationMs:this.config.outputFrameDurationMs};this.config.agentSettingsOverride&&(i.agentSettingsOverride=this.config.agentSettingsOverride),console.log("📤 VoiceSDK v2: Sending hello:",{version:i.v,requestedFormat:i.requestedOutputFormat}),console.log("📤 VoiceSDK v2: Requested output format:",{container:i.requestedOutputFormat.container,encoding:i.requestedOutputFormat.encoding,sampleRate:i.requestedOutputFormat.sampleRate,bitDepth:i.requestedOutputFormat.bitDepth});try{this.sendMessage(i)}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),e.t){case"hello_ack":this.handleHelloAck(e);break;case"user_transcript":case"agent_response":case"error":this.emit("message",e);break;case"barge_in":this.emit("bargeIn",e),this.audioPlayer.stopImmediate();break;case"stop_playing":this.emit("stopPlaying",e),this.audioPlayer.stopImmediate();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:"handleHelloAck",value:function(t){if(console.log("📥 VoiceSDK v2: Received hello_ack:",{hasOutputFormat:!!t.outputAudioFormat,outputFormat:t.outputAudioFormat,messageType:t.t}),t.outputAudioFormat){this.outputAudioFormat=t.outputAudioFormat,this.audioPlayer.setOutputFormat(t.outputAudioFormat),console.log("✅ VoiceSDK v2: Format negotiated by server:",this.outputAudioFormat);var e={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},n={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},o=[];e.container!==n.container&&o.push('container: "'.concat(e.container,'" → "').concat(n.container,'"')),e.encoding!==n.encoding&&o.push('encoding: "'.concat(e.encoding,'" → "').concat(n.encoding,'"')),e.sampleRate!==n.sampleRate&&o.push("sampleRate: ".concat(e.sampleRate,"Hz → ").concat(n.sampleRate,"Hz")),e.bitDepth!==n.bitDepth&&o.push("bitDepth: ".concat(e.bitDepth,"-bit → ").concat(n.bitDepth,"-bit")),e.channels!==n.channels&&o.push("channels: ".concat(e.channels," → ").concat(n.channels)),o.length>0?(console.warn("⚠️ VoiceSDK v2: Format negotiation mismatch!"),console.warn(" Requested:",e),console.warn(" Negotiated:",n),console.warn(" Differences:",o.join(", ")),console.warn("⚠️ Backend is ignoring your format request and using its own format.")):console.log("✅ VoiceSDK v2: Format perfectly matched!",n),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 i={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=i,this.audioPlayer.setOutputFormat(i)}}},{key:"handleBinaryMessage",value:(s=ce(ie().m(function t(e){var n,o,i,r,a,c,s,u;return ie().w(function(t){for(;;)switch(t.n){case 0:if(!(e instanceof Blob)){t.n=2;break}return t.n=1,e.arrayBuffer();case 1:i=t.v,t.n=3;break;case 2:i=e;case 3:console.log("📥 VoiceSDK v2: Received audio:",i.byteLength,"bytes"),r=(null===(n=this.outputAudioFormat)||void 0===n?void 0:n.container)||this.config.outputContainer||"raw",a=((null===(o=this.outputAudioFormat)||void 0===o?void 0:o.encoding)||this.config.outputEncoding||"pcm").toLowerCase(),"raw"===r?(c=i,"pcm"!==a&&((s=this.audioPlayer.getCodec(a))?(u=s.decode(new Uint8Array(i)),c=u.buffer,console.log("🔄 VoiceSDK v2: Decoded ".concat(a.toUpperCase()," to PCM (").concat(u.byteLength," bytes)"))):console.warn("⚠️ VoiceSDK v2: No codec for ".concat(a,", treating as PCM"))),this.audioPlayer.playChunk(c)):this.audioPlayer.playAudio(i);case 4:return t.a(2)}},t,this)})),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.audioPlayer.stopImmediate(),this.websocket&&(this.websocket.close(),this.websocket=null),this.isConnected=!1)}},{key:"startRecording",value:(c=ce(ie().m(function t(){var e,n;return ie().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,this.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId()}),t.n=4,this.audioRecorder.start();case 4:return 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=ce(ie().m(function t(){var e;return ie().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.audioPlayer.stopImmediate(),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:(r=ce(ie().m(function t(){return ie().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 r.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(i=ce(ie().m(function t(){return ie().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 i.apply(this,arguments)})},{key:"getStatus",value:function(){return{version:this.version,isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying,outputFormat:this.outputAudioFormat,audioPlayer:this.audioPlayer.getStatus(),audioRecorder:this.audioRecorder.getStatus()}}},{key:"updateConfig",value:function(t){this.config=oe(oe({},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&&se(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a,c,s,u}(mt);fe(he,"SUPPORTED_INPUT_ENCODINGS",["pcm","pcmu","pcma"]),fe(he,"SUPPORTED_INPUT_SAMPLE_RATES",[8e3,16e3,24e3,48e3]),fe(he,"SUPPORTED_INPUT_BIT_DEPTHS",[8,16,24]),fe(he,"SUPPORTED_INPUT_CHANNELS",[1]),fe(he,"SUPPORTED_OUTPUT_ENCODINGS",["pcm","pcmu","pcma"]),fe(he,"SUPPORTED_OUTPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),fe(he,"SUPPORTED_OUTPUT_BIT_DEPTHS",[8,16,24]),fe(he,"SUPPORTED_OUTPUT_CHANNELS",[1]),fe(he,"SUPPORTED_OUTPUT_CONTAINERS",["raw","wav"]);const ve=he;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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return me(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,me(d,"constructor",u),me(u,"constructor",s),s.displayName="GeneratorFunction",me(u,i,"GeneratorFunction"),me(d),me(d,i,"Generator"),me(d,o,function(){return this}),me(d,"toString",function(){return"[object Generator]"}),(ye=function(){return{w:r,m:f}})()}function me(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}me=function(t,e,n,o){function r(e,n){me(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},me(t,e,n,o)}function be(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function we(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 Se(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?we(Object(n),!0).forEach(function(e){xe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):we(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function xe(t,e,n){return(e=Ce(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}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,Ce(o.key),o)}}function Ce(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+""}function Pe(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Pe=function(){return!!t})()}function Oe(t){return Oe=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Oe(t)}function Ee(t,e){return Ee=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ee(t,e)}var Te=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=Oe(e),function(t,e){if(e&&("object"==ge(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,Pe()?Reflect.construct(e,n||[],Oe(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=Se({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&&Ee(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:(i=ye().m(function t(e){var n=this;return ye().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 i={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(i):n.executeTask(i)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){be(r,n,o,a,c,"next",t)}function c(t){be(r,n,o,a,c,"throw",t)}a(void 0)})},function(t){return r.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,i=this.buildWebSocketUrl(this.config.baseWsUrl),r=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(r),c=!1,s=!1,u=null,l=function(n){if(!s)try{var o={message:t.text},i=e.config.forceConversationId||e.config.conversationId;i&&(o.conversationId=i,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=i,e.persistConversationId(i))),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 i=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",i)}catch(t){}if("hello"===i.type&&i.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",i.conversationId),e.config.conversationId=i.conversationId,e.persistConversationId(i.conversationId),e.emit&&e.emit("conversationIdChanged",i.conversationId),!s&&n&&1===n.readyState){if(u)try{clearTimeout(u)}catch(t){}l(n)}return}if(!e.config.conversationId&&i.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",i.conversationId),e.config.conversationId=i.conversationId,e.persistConversationId(i.conversationId)),"chunk"===i.type&&"string"==typeof i.content)e.fullResponseBuffer+=i.content,e.emit("chunk",i.content);else if("done"===i.type){try{var r=i.text||i.content||i.answer||i.message||"";r&&!e.fullResponseBuffer&&(e.fullResponseBuffer=r)}catch(t){}!e.config.conversationId&&i.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",i.conversationId),e.config.conversationId=i.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"===i.type){var a=new Error(i.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(i);h.onopen=d(h),h.onmessage=f(h),h.onerror=(o=h,function(n){if(!c){c=!0;try{o.close()}catch(t){}var i=new WebSocket(a);return i.onopen=d(i),i.onmessage=f(i),i.onerror=function(n){e.emit("error",n),t.reject(n)},void(i.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=Se(Se({},this.config),t)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&ke(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c),Ie=n(540),je=n(848);function Be(t){return Be="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},Be(t)}function De(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 Ae(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?De(Object(n),!0).forEach(function(e){Fe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):De(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Fe(t,e,n){return(e=function(t){var e=function(t){if("object"!=Be(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Be(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Be(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Re(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return _e(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(_e(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,_e(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,_e(d,"constructor",u),_e(u,"constructor",s),s.displayName="GeneratorFunction",_e(u,i,"GeneratorFunction"),_e(d),_e(d,i,"Generator"),_e(d,o,function(){return this}),_e(d,"toString",function(){return"[object Generator]"}),(Re=function(){return{w:r,m:f}})()}function _e(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}_e=function(t,e,n,o){function r(e,n){_e(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},_e(t,e,n,o)}function Ue(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Me(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,i,r,a,c=[],s=!0,u=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw i}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return ze(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)?ze(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 ze(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 Ne=function(t){var e=t.websocketUrl,n=t.agentId,o=t.appId,i=t.voice,r=void 0===i?"default":i,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,E=Me((0,Ie.useState)(!1),2),T=E[0],I=E[1],j=Me((0,Ie.useState)(!1),2),B=j[0],D=j[1],A=Me((0,Ie.useState)(!1),2),F=(A[0],A[1]),R=Me((0,Ie.useState)("Disconnected"),2),_=(R[0],R[1]),U=(0,Ie.useRef)(null);(0,Ie.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:r,language:c,autoReconnect:u,agentSettingsOverride:d});return t.on("connected",function(){I(!0),_("Connected"),null==f||f()}),t.on("disconnected",function(){I(!1),_("Disconnected"),null==p||p()}),t.on("recordingStarted",function(){D(!0),null==h||h()}),t.on("recordingStopped",function(){D(!1),null==v||v()}),t.on("playbackStarted",function(){F(!0),null==g||g()}),t.on("playbackStopped",function(){F(!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,r,c,d]);var M=function(){var t,e=(t=Re().m(function t(){var e;return Re().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,i){var r=t.apply(e,n);function a(t){Ue(r,o,i,a,c,"next",t)}function c(t){Ue(r,o,i,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),z=(0,je.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,je.jsx)("div",{style:{fontSize:"20px"},children:B?"🔴":"🎤"}),(0,je.jsx)("div",{children:B?"Stop Listening":"Start Listening"})]});return(0,je.jsx)("button",{className:"voice-button ".concat(B?"recording":""," ").concat(k),style:Ae({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:B?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},P),onClick:M,disabled:!T,children:O||z})};function Le(t){return Le="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},Le(t)}function He(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ve(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ve(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,Ve(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ve(d,"constructor",u),Ve(u,"constructor",s),s.displayName="GeneratorFunction",Ve(u,i,"GeneratorFunction"),Ve(d),Ve(d,i,"Generator"),Ve(d,o,function(){return this}),Ve(d,"toString",function(){return"[object Generator]"}),(He=function(){return{w:r,m:f}})()}function Ve(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Ve=function(t,e,n,o){function r(e,n){Ve(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Ve(t,e,n,o)}function We(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Ke(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){We(r,o,i,a,c,"next",t)}function c(t){We(r,o,i,a,c,"throw",t)}a(void 0)})}}function Ge(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 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 qe(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 Je(t){var e=function(t){if("object"!=Le(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Le(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Le(e)?e:e+""}var Ye=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?Ge(Object(n),!0).forEach(function(e){Qe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ge(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=Ke(He().m(function t(){var e;return He().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=Ke(He().m(function t(){var e;return He().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&&qe(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function $e(t){return $e="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},$e(t)}function Xe(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ze(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ze(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,Ze(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ze(d,"constructor",u),Ze(u,"constructor",s),s.displayName="GeneratorFunction",Ze(u,i,"GeneratorFunction"),Ze(d),Ze(d,i,"Generator"),Ze(d,o,function(){return this}),Ze(d,"toString",function(){return"[object Generator]"}),(Xe=function(){return{w:r,m:f}})()}function Ze(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Ze=function(t,e,n,o){function r(e,n){Ze(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Ze(t,e,n,o)}function tn(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function en(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){tn(r,o,i,a,c,"next",t)}function c(t){tn(r,o,i,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,on(o.key),o)}}function on(t){var e=function(t){if("object"!=$e(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=$e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==$e(e)?e:e+""}var rn=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=en(Xe().m(function t(e){var n,o=this;return Xe().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 pt({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en"}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(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)}),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.type){case"connected":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text);break;case"agent_response":case"barge_in":case"stop_playing":break;case"error":this.onError(new Error(t.message))}}},{key:"startListening",value:(n=en(Xe().m(function t(){var e;return Xe().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.webSocketManager.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],e&&nn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function an(t){return an="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},an(t)}function cn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return sn(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(sn(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,sn(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,sn(d,"constructor",u),sn(u,"constructor",s),s.displayName="GeneratorFunction",sn(u,i,"GeneratorFunction"),sn(d),sn(d,i,"Generator"),sn(d,o,function(){return this}),sn(d,"toString",function(){return"[object Generator]"}),(cn=function(){return{w:r,m:f}})()}function sn(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}sn=function(t,e,n,o){function r(e,n){sn(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},sn(t,e,n,o)}function un(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function ln(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){un(r,o,i,a,c,"next",t)}function c(t){un(r,o,i,a,c,"throw",t)}a(void 0)})}}function dn(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,fn(o.key),o)}}function fn(t){var e=function(t){if("object"!=an(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=an(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==an(e)?e:e+""}var pn=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 rn({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,variables:e.variables||{},language:e.language||"en"}),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",i=this.config.startCallButtonColor||"#667eea",r=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(i,";\n color: ").concat(r,";\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"),i=document.getElementById("muteBtn"),r=document.getElementById("speakerBtn");n&&(n.onclick=function(){return e.startVoiceCall()}),o&&(o.onclick=function(){return e.endVoiceCall()}),i&&(i.onclick=function(){return e.toggleMute()}),r&&(r.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=ln(cn().m(function t(){var e,n,o,i,r,a,c;return cn().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((i=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(i.statusText));case 4:return t.n=5,i.json();case 5:return r=t.v,t.a(2,r.signedUrl||r.wsUrl||r.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,i,r,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,i=35,r=11,a=9,c=32,s=45,u=42,l=48):e<=450?(d=7,o=110,i=55,r=15,a=11,c=38,s=58,u=52,l=58):e<=550?(d=8,o=140,i=70,r=16,a=12,c=42,s=68,u=56,l=64):e<=700?(d=10,o=130,i=65,r=18,a=13,c=46,s=85,u=60,l=70):(d=12,o=150,i=75,r=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(i,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(t){return t.style.fontSize="".concat(r,"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,r-4),"px"));var b=document.querySelector(".transcript-text");b&&(b.style.fontSize="".concat(Math.max(10,r-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 E=Math.max(22,.5*C);O.style.width="".concat(E,"px"),O.style.height="".concat(E,"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=ln(cn().m(function t(){var e,n,o,i,r,a,c,s,u,l=this;return cn().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 i=t.v,console.log("🔗 Got signed URL:",i),t.n=4,this.sdk.connect(i);case 4:r=t.v,console.log("✅ Connected to WebSocket, connected:",r),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 i=document.getElementById("voiceAvatarActive");i&&i.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&&dn(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 vn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return gn(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(gn(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,gn(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,gn(d,"constructor",u),gn(u,"constructor",s),s.displayName="GeneratorFunction",gn(u,i,"GeneratorFunction"),gn(d),gn(d,i,"Generator"),gn(d,o,function(){return this}),gn(d,"toString",function(){return"[object Generator]"}),(vn=function(){return{w:r,m:f}})()}function gn(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}gn=function(t,e,n,o){function r(e,n){gn(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},gn(t,e,n,o)}function yn(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function mn(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){yn(r,o,i,a,c,"next",t)}function c(t){yn(r,o,i,a,c,"throw",t)}a(void 0)})}}function bn(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,wn(o.key),o)}}function wn(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 Sn=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,i,r,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===(i=this.config.panel)||void 0===i||null===(i=i.sendButtonHint)||void 0===i?void 0:i.color)||"#6B7280","; font-size: ").concat((null===(r=this.config.sendButtonHint)||void 0===r?void 0:r.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,i,r,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===(i=this.config.panel)||void 0===i?void 0:i.inputBorderColor)||"#E5E7EB"),m=this.config.inputFocusColor||(null===(r=this.config.panel)||void 0===r?void 0:r.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 i=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",i),n.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey?"Enter"===e.key&&e.shiftKey&&setTimeout(i,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=mn(vn().m(function t(){return vn().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=mn(vn().m(function t(){var e,n,o;return vn().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 i=document.createElement("div"),r="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";i.className="message ".concat(t," ").concat(r);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,i.appendChild(a),i.appendChild(c),n.appendChild(i),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 i=document.createElement("div");i.className="message-bubble",i.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(i),t.appendChild(e),this.streamingEl=i,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 i=document.createElement("div");i.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",i.textContent=this.t("domainNotValidated");var r=document.createElement("div");r.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",r.textContent=this.t("domainErrorMessage"),o.appendChild(i),o.appendChild(r),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&&bn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();const xn={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 kn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Cn(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Cn(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,Cn(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Cn(d,"constructor",u),Cn(u,"constructor",s),s.displayName="GeneratorFunction",Cn(u,i,"GeneratorFunction"),Cn(d),Cn(d,i,"Generator"),Cn(d,o,function(){return this}),Cn(d,"toString",function(){return"[object Generator]"}),(kn=function(){return{w:r,m:f}})()}function Cn(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Cn=function(t,e,n,o){function r(e,n){Cn(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Cn(t,e,n,o)}function Pn(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function On(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Pn(r,o,i,a,c,"next",t)}function c(t){Pn(r,o,i,a,c,"throw",t)}a(void 0)})}}function En(t){return En="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},En(t)}function Tn(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){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Tn(Object(n),!0).forEach(function(e){jn(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function jn(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 Bn(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"!=En(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=En(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==En(e)?e:e+""}var An=function(){return t=function t(){var e,n,o=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(o),this.sdk=new Te(this.config),this.isOpen=!1,this.isActive=!1,this.translations=xn,this.currentView="landing";var i=In(In(In({},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});this.voiceInterface=new pn(i);var r=In(In(In({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new Sn(r,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var a=document.getElementById("text-chat-panel");a&&(this.isOpen=!0,a.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,i,r,a,c,s,u,l,d,f,p,h,v,g,y,m,b,w,S,x,k,C,P,O,E,T,I,j,B,D,A,F,R,_,U,M,z,N,L,H,V,W,K,G,Q,q,J,Y,$,X,Z,tt,et,nt,ot,it,rt,at,ct,st,ut,lt,dt,ft,pt,ht,vt,gt,yt,mt,bt,wt,St,xt,kt,Ct,Pt,Ot,Et,Tt,It,jt,Bt,Dt,At,Ft,Rt,_t,Ut,Mt,zt,Nt,Lt,Ht,Vt,Wt,Kt,Gt,Qt,qt,Jt,Yt,$t,Xt,Zt,te,ee,ne,oe,ie,re,ae,ce,se,ue,le,de,fe,pe,he,ve,ge,ye,me,be,we,Se,xe,ke,Ce,Pe,Oe,Ee=t.position||"bottom-right";if("string"==typeof Ee){var Te=Ee.split("-");Ee={vertical:Te[0]||"bottom",horizontal:Te[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var Ie=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",je=(null===(o=t.header)||void 0===o?void 0:o.backgroundColor)||(null===(i=t.button)||void 0===i?void 0:i.backgroundColor)||Ie;return In({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:In({type:(null===(r=t.icon)||void 0===r?void 0:r.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:In({vertical:Ee.vertical||"bottom",horizontal:Ee.horizontal||"right",offset:Ee.offset||{x:20,y:20}},"object"===En(t.position)?t.position:{}),button:In({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)||Ie,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)||Ie},t.button),panel:In({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:In({micButtonColor:(null===(O=t.voice)||void 0===O?void 0:O.micButtonColor)||(null===(E=t.panel)||void 0===E?void 0:E.micButtonColor)||Ie,micButtonActiveColor:(null===(T=t.voice)||void 0===T?void 0:T.micButtonActiveColor)||(null===(I=t.panel)||void 0===I?void 0:I.micButtonActiveColor)||"#EF4444",micButtonHint:In(In({text:(null===(j=t.voice)||void 0===j||null===(j=j.micButtonHint)||void 0===j?void 0:j.text)||(null===(B=t.panel)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.text)||"Click the button to start voice conversation",color:(null===(D=t.voice)||void 0===D||null===(D=D.micButtonHint)||void 0===D?void 0:D.color)||(null===(A=t.panel)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.color)||"#6B7280",fontSize:(null===(F=t.voice)||void 0===F||null===(F=F.micButtonHint)||void 0===F?void 0:F.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===(L=t.voice)||void 0===L?void 0:L.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(H=t.voice)||void 0===H?void 0:H.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(V=t.voice)||void 0===V?void 0:V.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(W=t.voice)||void 0===W?void 0:W.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(K=t.voice)||void 0===K?void 0:K.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:In({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===(it=t.text)||void 0===it?void 0:it.sendButtonText)||(null===(rt=t.panel)||void 0===rt?void 0:rt.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:In(In({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===(Et=t.panel)||void 0===Et?void 0:Et.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(Tt=t.text)||void 0===Tt?void 0:Tt.inputTextColor)||(null===(It=t.panel)||void 0===It?void 0:It.inputTextColor)||"#1F2937",inputFontSize:(null===(jt=t.text)||void 0===jt?void 0:jt.inputFontSize)||(null===(Bt=t.panel)||void 0===Bt?void 0:Bt.inputFontSize)||"14px",inputBorderRadius:(null===(Dt=t.text)||void 0===Dt?void 0:Dt.inputBorderRadius)||(null===(At=t.panel)||void 0===At?void 0:At.inputBorderRadius)||20,inputPadding:(null===(Ft=t.text)||void 0===Ft?void 0:Ft.inputPadding)||(null===(Rt=t.panel)||void 0===Rt?void 0:Rt.inputPadding)||"6px 14px"},t.text),landing:In({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===(Lt=t.landing)||void 0===Lt?void 0:Lt.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Ht=t.landing)||void 0===Ht?void 0:Ht.modeCardHoverBorderColor)||je,modeCardIconBackgroundColor:(null===(Vt=t.landing)||void 0===Vt?void 0:Vt.modeCardIconBackgroundColor)||je,modeCardTitleColor:(null===(Wt=t.landing)||void 0===Wt?void 0:Wt.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(Kt=t.landing)||void 0===Kt?void 0:Kt.voiceCardIcon)||"🎤",textCardIcon:(null===(Gt=t.landing)||void 0===Gt?void 0:Gt.textCardIcon)||"💬"},t.landing),header:In({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:In({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===(ie=t.tooltips)||void 0===ie?void 0:ie.endCall)||null},t.tooltips),messages:In({userBackgroundColor:(null===(re=t.messages)||void 0===re?void 0:re.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:In({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:In({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:In({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:Ie},"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),i=(this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),r={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(r),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,i,r),"\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,i,r,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===(i=this.config.landing)||void 0===i?void 0:i.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===(r=this.config.landing)||void 0===r?void 0:r.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",i="unified"===o,r="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()}),i?(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")),r&&(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()},i&&(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"),i=document.getElementById("newChatBtn");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),i&&(i.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 i=this.config.behavior.mode||"unified";n&&"unified"===i&&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"),i=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active");var r=this.config.behavior.mode||"unified";o&&"unified"===r&&o.classList.add("visible"),i&&(i.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:(r=On(kn().m(function t(){return kn().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 r.apply(this,arguments)})},{key:"sendMessage",value:(i=On(kn().m(function t(){return kn().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 i.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=On(kn().m(function t(){var e,n,o,i,r,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://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((i=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(i.statusText));case 4:return t.n=5,i.json();case 5:return r=t.v,t.a(2,r.signedUrl||r.wsUrl||r.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;console.log("🔄 updateConfig called",{newConfig:t,stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var o,i,r=In({},this.config);t.panel&&(r.panel=In(In({},this.config.panel),t.panel)),t.voice&&(r.voice=In(In({},this.config.voice),t.voice),t.voice.micButtonHint&&(r.voice.micButtonHint=In(In({},null===(o=this.config.voice)||void 0===o?void 0:o.micButtonHint),t.voice.micButtonHint))),t.text&&(r.text=In(In({},this.config.text),t.text),t.text.sendButtonHint&&(r.text.sendButtonHint=In(In({},null===(i=this.config.text)||void 0===i?void 0:i.sendButtonHint),t.text.sendButtonHint))),void 0!==t.language&&(r.language=t.language),void 0!==t.language&&(["he","ar"].includes(t.language)?r.direction="rtl":void 0===t.direction&&(r.direction="ltr")),t.translations&&(r.translations=t.translations,this.translations=t.translations),t.button&&(r.button=In(In({},this.config.button),t.button)),t.header&&(r.header=In(In({},this.config.header),t.header)),t.icon&&(r.icon=In(In({},this.config.icon),t.icon)),t.messages&&(r.messages=In(In({},this.config.messages),t.messages)),t.animation&&(r.animation=In(In({},this.config.animation),t.animation)),t.behavior&&(r.behavior=In(In({},this.config.behavior),t.behavior)),t.accessibility&&(r.accessibility=In(In({},this.config.accessibility),t.accessibility)),t.tooltips&&(r.tooltips=In(In({},this.config.tooltips),t.tooltips)),t.landing&&(r.landing=In(In({},this.config.landing),t.landing)),void 0!==t.direction&&void 0===r.direction&&(r.direction=t.direction),void 0!==t.primaryColor&&(r.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)||(r[e]=t[e])}),null===(e=this.config)||void 0===e||e.language,this.config=this.mergeWithDefaults(r);var a=this.config.language||"en",c=In(In(In({},this.config),this.config.voice),{},{language:a,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});this.voiceInterface=new pn(c);var s=In(In(In({},this.config),this.config.text),{},{language:a,translations:this.translations});this.textInterface=new Sn(s,this.sdk);var u=document.getElementById("text-chat-widget");u&&u.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=On(kn().m(function t(){return kn().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&&Bn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,i,r}(),Fn="2.0.0";const Rn={VoiceSDK:pt,VoiceSDK_v2:ve,TextChatSDK:Te,WebSocketManager:B,AudioRecorder:V,AudioPlayer:Z,EventEmitter:c,VoiceButton:Ne,VanillaVoiceButton:Ye,AgentSDK:rn,TTPChatWidget:An,VERSION:Fn};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 i=null;if(void 0!==o&&(i=""+o),void 0!==e.key&&(i=""+e.key),"key"in e)for(var r in o={},e)"key"!==r&&(o[r]=e[r]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:i,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,i={};function r(t,e,o){this.props=t,this.context=e,this.refs=i,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=i,this.updater=o||n}r.prototype.isReactComponent={},r.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")},r.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=r.prototype;var s=c.prototype=new a;s.constructor=c,o(s,r.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 i=e[o];if(void 0!==i)return i.exports;var r=e[o]={exports:{}};return t[o](r,r.exports,n),r.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 i(t){return i="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},i(t)}function r(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"!=i(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==i(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>rn,AudioPlayer:()=>Z,AudioRecorder:()=>V,EventEmitter:()=>c,TTPChatWidget:()=>An,TextChatSDK:()=>Te,VERSION:()=>Fn,VanillaVoiceButton:()=>Ye,VoiceButton:()=>Ne,VoiceSDK:()=>pt,VoiceSDK_v2:()=>ve,WebSocketManager:()=>B,default:()=>Rn});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&&r(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,i,r,a,c=[],s=!0,u=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw i}}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,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}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 r,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,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return h(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,h(d,"constructor",u),h(u,"constructor",s),s.displayName="GeneratorFunction",h(u,i,"GeneratorFunction"),h(d),h(d,i,"Generator"),h(d,o,function(){return this}),h(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:r,m:f}})()}function h(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}h=function(t,e,n,o){function r(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},h(t,e,n,o)}function v(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}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:(i=p().m(function t(e){var n,o,i=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(i.connections.has(e)){var o=i.connections.get(e);i.connectionCounts.set(e,(i.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){i.creatingConnections.delete(e),i.emit("open",t,e)}),o.addEventListener("close",function(t){i.creatingConnections.delete(e),i.connections.delete(e),i.connectionCounts.delete(e),i.emit("close",t,e)}),o.addEventListener("error",function(t){i.creatingConnections.delete(e),i.emit("error",t,e)}),o.addEventListener("message",function(t){i.emit("message",t,e)}),t.a(2,o)}},t,this)}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){v(r,n,o,a,c,"next",t)}function c(t){v(r,n,o,a,c,"throw",t)}a(void 0)})},function(t){return r.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),i=o[0],r=o[1];e[i]={readyState:r.readyState,subscribers:this.connectionCounts.get(i)||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,i,r}(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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return C(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,C(d,"constructor",u),C(u,"constructor",s),s.displayName="GeneratorFunction",C(u,i,"GeneratorFunction"),C(d),C(d,i,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(k=function(){return{w:r,m:f}})()}function C(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}C=function(t,e,n,o){function r(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},C(t,e,n,o)}function P(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}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,E(o.key),o)}}function E(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 T(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(T=function(){return!!t})()}function I(t){return I=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},I(t)}function j(t,e){return j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},j(t,e)}var B=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=I(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,T()?Reflect.construct(e,n||[],I(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&&j(t,e)}(e,t),n=e,o=[{key:"connect",value:(r=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 i=r.apply(t,e);function a(t){P(i,n,o,a,c,"next",t)}function c(t){P(i,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))},i=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",i),this.eventHandlers={open:e,close:n,error:o,message:i}}}},{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}}}],i=[{key:"getSingletonStatus",value:function(){return S.getAllConnections()}},{key:"clearAllConnections",value:function(){S.clearAll()}}],o&&O(n.prototype,o),i&&O(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a}(c);function D(t){return D="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},D(t)}function A(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return F(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(F(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,F(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,F(d,"constructor",u),F(u,"constructor",s),s.displayName="GeneratorFunction",F(u,i,"GeneratorFunction"),F(d),F(d,i,"Generator"),F(d,o,function(){return this}),F(d,"toString",function(){return"[object Generator]"}),(A=function(){return{w:r,m:f}})()}function F(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}F=function(t,e,n,o){function r(e,n){F(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},F(t,e,n,o)}function R(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function _(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){R(r,o,i,a,c,"next",t)}function c(t){R(r,o,i,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"!=D(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==D(e)?e:e+""}function N(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(N=function(){return!!t})()}function L(t){return L=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},L(t)}function H(t,e){return H=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},H(t,e)}var V=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"==D(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||[],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&&H(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,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}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 r,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,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}(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 i=n.substring(0,n.lastIndexOf("/"));return"".concat(i,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(r=_(A().m(function t(){var e,n,o=this;return A().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,i=e.data;"pcm_audio_data"===n&&o.emit("audioData",i)},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 r.apply(this,arguments)})},{key:"stop",value:(i=_(A().m(function t(){var e;return A().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 i.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,i,r}(c);function W(t){return W="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},W(t)}function K(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return G(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,G(d,"constructor",u),G(u,"constructor",s),s.displayName="GeneratorFunction",G(u,i,"GeneratorFunction"),G(d),G(d,i,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(K=function(){return{w:r,m:f}})()}function G(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}G=function(t,e,n,o){function r(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},G(t,e,n,o)}function Q(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}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"!=W(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=W(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==W(e)?e:e+""}function 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"==W(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,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:(i=K().m(function t(){var e,n,o,i,r,a,c,s,u,l=this;return K().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"!==(i=this.audioContext).state){t.n=3;break}return t.n=3,i.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return r=t.v,t.n=5,i.decodeAudioData(r);case 5:a=t.v,c=n&&!this.isPlaying&&null===this.currentSource,(s=i.createBufferSource()).buffer=a,s.connect(i.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]])}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){Q(r,n,o,a,c,"next",t)}function c(t){Q(r,n,o,a,c,"throw",t)}a(void 0)})},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)}}],o&&q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return nt(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,nt(d,"constructor",u),nt(u,"constructor",s),s.displayName="GeneratorFunction",nt(u,i,"GeneratorFunction"),nt(d),nt(d,i,"Generator"),nt(d,o,function(){return this}),nt(d,"toString",function(){return"[object Generator]"}),(et=function(){return{w:r,m:f}})()}function nt(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}nt=function(t,e,n,o){function r(e,n){nt(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},nt(t,e,n,o)}function ot(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function it(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ot(r,o,i,a,c,"next",t)}function c(t){ot(r,o,i,a,c,"throw",t)}a(void 0)})}}function rt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function at(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?rt(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=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 B(at(at({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new V(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),i=0;i<n.length;i++)o[i]=n.charCodeAt(i);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(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=it(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=it(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=it(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:(r=it(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 r.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(i=it(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 i.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,i,r,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 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 Tt(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 jt=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 i=16384;0===(t&i)&&e>0;e--,i>>=1);n=t>>e+3&15}return 85^(o|e<<4|n)}}])&&Tt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();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 Dt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return At(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(At(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,At(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,At(d,"constructor",u),At(u,"constructor",s),s.displayName="GeneratorFunction",At(u,i,"GeneratorFunction"),At(d),At(d,i,"Generator"),At(d,o,function(){return this}),At(d,"toString",function(){return"[object Generator]"}),(Dt=function(){return{w:r,m:f}})()}function At(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}At=function(t,e,n,o){function r(e,n){At(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},At(t,e,n,o)}function Ft(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Rt(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Ft(r,o,i,a,c,"next",t)}function c(t){Ft(r,o,i,a,c,"throw",t)}a(void 0)})}}function _t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Ut(o.key),o)}}function Ut(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+""}function Mt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Mt=function(){return!!t})()}function zt(t){return zt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},zt(t)}function Nt(t,e){return Nt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Nt(t,e)}var Lt=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=zt(e),function(t,e){if(e&&("object"==Bt(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,Mt()?Reflect.construct(e,n||[],zt(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.pcmChunkQueue=[],t.isProcessingPcmQueue=!1,t.codecs={pcm:new xt,pcmu:new Ot,pcma:new jt},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&&Nt(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(),i=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&i&&this.SUPPORTED_CONTAINERS.includes(o)&&this.SUPPORTED_ENCODINGS.includes(i)&&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:(a=Rt(Dt().m(function t(e){return Dt().w(function(t){for(;;)switch(t.n){case 0:this.pcmChunkQueue.push(e),this.isProcessingPcmQueue||this.processPcmQueue();case 1:return t.a(2)}},t,this)})),function(t){return a.apply(this,arguments)})},{key:"processPcmQueue",value:(r=Rt(Dt().m(function t(){var e,n,o,i,r,a,c,s,u,l,d,f,p,h,v,g,y,m,b,w,S=this;return Dt().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(i=o,o.byteLength%2!=0&&(console.warn("⚠️ Odd PCM chunk size, padding:",o.byteLength),(r=new Uint8Array(o.byteLength+1)).set(new Uint8Array(o),0),r[o.byteLength]=0,i=r.buffer),a=new Int16Array(i),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 r.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(),i=this.isWavFile(e);if(i&&console.log("🎵 AudioPlayer: Data has WAV header (RIFF)"),o&&i)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&&!i)console.log("🎵 AudioPlayer: Processing as RAW data (as negotiated)");else{if(n&&i)return console.log("✅ AudioPlayer: Processing as WAV file (matches negotiation)"),this.handleWavFile(e);if(n&&!i)return console.warn("⚠️ AudioPlayer: Negotiated WAV but data lacks WAV header. Attempting WAV processing anyway."),this.handleWavFile(e);if(!this.outputFormat&&i)return console.log("🎵 AudioPlayer: No format negotiated, auto-detecting WAV"),this.handleWavFile(e);this.outputFormat||i||(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),i=n.decode(o),r=this.createWavHeader(i.byteLength,e.sampleRate,e.channels,16);return new Blob([r,i],{type:"audio/wav"})}},{key:"handleRawData",value:function(t){var e,n,o=this.outputFormat.encoding.toLowerCase(),i=this.getCodec(o);if(!i)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 r=this.outputFormat.bitDepth||16;t.length,24===r?(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===r?(console.log("🔄 AudioPlayer: Converting 8-bit PCM to 16-bit PCM"),e=this.convert8BitTo16Bit(t),n=16):(e=t.buffer,n=r,console.log("✅ AudioPlayer: Using native ".concat(r,"-bit PCM (no conversion needed)")))}else e=i.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 i=t[3*o],r=t[3*o+1],a=t[3*o+2],c=i|r<<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 i=t[o];n[o]=256*(i-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 i=new ArrayBuffer(44),r=new DataView(i);return r.setUint32(0,1380533830,!1),r.setUint32(4,36+t,!0),r.setUint32(8,1463899717,!1),r.setUint32(12,1718449184,!1),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,n,!0),r.setUint32(24,e,!0),r.setUint32(28,e*n*o/8,!0),r.setUint16(32,n*o/8,!0),r.setUint16(34,o,!0),r.setUint32(36,1684108385,!1),r.setUint32(40,t,!0),i}},{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:(i=Rt(Dt().m(function t(){var e,n,o,i,r,a,c,s=this;return Dt().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:i=t.v,r=n&&!this.isPlaying&&null===this.currentSource,(a=this.audioContext.createBufferSource()).buffer=i,a.connect(this.audioContext.destination),this.currentSource=a,this.isPlaying=!0,r&&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 i.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;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],this.pcmChunkQueue=[],this.isProcessingPcmQueue=!1,this.nextStartTime=0,this.scheduledBuffers=0,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",outputFormat:this.outputFormat}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.removeAllListeners()}}],o&&_t(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a}(mt);const Ht=Lt;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 Wt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Kt(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Kt(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,Kt(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Kt(d,"constructor",u),Kt(u,"constructor",s),s.displayName="GeneratorFunction",Kt(u,i,"GeneratorFunction"),Kt(d),Kt(d,i,"Generator"),Kt(d,o,function(){return this}),Kt(d,"toString",function(){return"[object Generator]"}),(Wt=function(){return{w:r,m:f}})()}function Kt(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Kt=function(t,e,n,o){function r(e,n){Kt(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Kt(t,e,n,o)}function Gt(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Qt(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Gt(r,o,i,a,c,"next",t)}function c(t){Gt(r,o,i,a,c,"throw",t)}a(void 0)})}}function qt(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 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,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+""}function $t(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return($t=function(){return!!t})()}function Xt(t){return Xt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Xt(t)}function Zt(t,e){return Zt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Zt(t,e)}var te=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=Xt(e),function(t,e){if(e&&("object"==Vt(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,$t()?Reflect.construct(e,n||[],Xt(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&&Zt(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 qt(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)?qt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}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 r,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,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}(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 i=n.substring(0,n.lastIndexOf("/"));return"".concat(i,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(r=Qt(Wt().m(function t(){var e,n,o=this;return Wt().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,i=e.data;"pcm_audio_data"===n&&o.emit("audioData",i)},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 r.apply(this,arguments)})},{key:"stop",value:(i=Qt(Wt().m(function t(){var e;return Wt().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 i.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&&Jt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(mt);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 ne(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 oe(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ne(Object(n),!0).forEach(function(e){fe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ne(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ie(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return re(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(re(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,re(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,re(d,"constructor",u),re(u,"constructor",s),s.displayName="GeneratorFunction",re(u,i,"GeneratorFunction"),re(d),re(d,i,"Generator"),re(d,o,function(){return this}),re(d,"toString",function(){return"[object Generator]"}),(ie=function(){return{w:r,m:f}})()}function re(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}re=function(t,e,n,o){function r(e,n){re(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},re(t,e,n,o)}function ae(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function ce(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ae(r,o,i,a,c,"next",t)}function c(t){ae(r,o,i,a,c,"throw",t)}a(void 0)})}}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,pe(o.key),o)}}function ue(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ue=function(){return!!t})()}function le(t){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},le(t)}function de(t,e){return de=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},de(t,e)}function fe(t,e,n){return(e=pe(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function pe(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+""}var he=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=le(e),function(t,e){if(e&&("object"==ee(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,ue()?Reflect.construct(e,n||[],le(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||250,outputCodec:n.outputCodec,agentSettingsOverride:n.agentSettingsOverride||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.websocket=null,t.audioPlayer=new Ht(t.config),t.audioRecorder=new te(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&&de(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 i=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();if(!i||!e.SUPPORTED_OUTPUT_ENCODINGS.includes(i))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 r=null===(o=t.container)||void 0===o?void 0:o.toLowerCase();return r&&e.SUPPORTED_OUTPUT_CONTAINERS.includes(r)?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&&t.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.sendMessage({t:"audio_stopped_playing"})}),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,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.sendMessage({t:"barge_in"})),t.emit("recordingStarted"),console.log("🎤 VoiceSDK v2: Recording started")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.isRecording&&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=ce(ie().m(function t(){var e,n,o=this;return ie().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 i={t:"hello",v:this.config.protocolVersion,inputFormat:t,requestedOutputFormat:e,outputFrameDurationMs:this.config.outputFrameDurationMs};this.config.agentSettingsOverride&&(i.agentSettingsOverride=this.config.agentSettingsOverride),console.log("📤 VoiceSDK v2: Sending hello:",{version:i.v,requestedFormat:i.requestedOutputFormat}),console.log("📤 VoiceSDK v2: Requested output format:",{container:i.requestedOutputFormat.container,encoding:i.requestedOutputFormat.encoding,sampleRate:i.requestedOutputFormat.sampleRate,bitDepth:i.requestedOutputFormat.bitDepth});try{this.sendMessage(i)}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),e.t){case"hello_ack":this.handleHelloAck(e);break;case"user_transcript":case"agent_response":case"error":this.emit("message",e);break;case"barge_in":this.emit("bargeIn",e),this.audioPlayer.stopImmediate();break;case"stop_playing":this.emit("stopPlaying",e),this.audioPlayer.stopImmediate();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:"handleHelloAck",value:function(t){if(console.log("📥 VoiceSDK v2: Received hello_ack:",{hasOutputFormat:!!t.outputAudioFormat,outputFormat:t.outputAudioFormat,messageType:t.t}),t.outputAudioFormat){this.outputAudioFormat=t.outputAudioFormat,this.audioPlayer.setOutputFormat(t.outputAudioFormat),console.log("✅ VoiceSDK v2: Format negotiated by server:",this.outputAudioFormat);var e={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},n={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},o=[];e.container!==n.container&&o.push('container: "'.concat(e.container,'" → "').concat(n.container,'"')),e.encoding!==n.encoding&&o.push('encoding: "'.concat(e.encoding,'" → "').concat(n.encoding,'"')),e.sampleRate!==n.sampleRate&&o.push("sampleRate: ".concat(e.sampleRate,"Hz → ").concat(n.sampleRate,"Hz")),e.bitDepth!==n.bitDepth&&o.push("bitDepth: ".concat(e.bitDepth,"-bit → ").concat(n.bitDepth,"-bit")),e.channels!==n.channels&&o.push("channels: ".concat(e.channels," → ").concat(n.channels)),o.length>0?(console.warn("⚠️ VoiceSDK v2: Format negotiation mismatch!"),console.warn(" Requested:",e),console.warn(" Negotiated:",n),console.warn(" Differences:",o.join(", ")),console.warn("⚠️ Backend is ignoring your format request and using its own format.")):console.log("✅ VoiceSDK v2: Format perfectly matched!",n),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 i={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=i,this.audioPlayer.setOutputFormat(i)}}},{key:"handleBinaryMessage",value:(s=ce(ie().m(function t(e){var n,o,i,r,a,c,s,u;return ie().w(function(t){for(;;)switch(t.n){case 0:if(!(e instanceof Blob)){t.n=2;break}return t.n=1,e.arrayBuffer();case 1:i=t.v,t.n=3;break;case 2:i=e;case 3:console.log("📥 VoiceSDK v2: Received audio:",i.byteLength,"bytes"),r=(null===(n=this.outputAudioFormat)||void 0===n?void 0:n.container)||this.config.outputContainer||"raw",a=((null===(o=this.outputAudioFormat)||void 0===o?void 0:o.encoding)||this.config.outputEncoding||"pcm").toLowerCase(),"raw"===r?(c=i,"pcm"!==a&&((s=this.audioPlayer.getCodec(a))?(u=s.decode(new Uint8Array(i)),c=u.buffer,console.log("🔄 VoiceSDK v2: Decoded ".concat(a.toUpperCase()," to PCM (").concat(u.byteLength," bytes)"))):console.warn("⚠️ VoiceSDK v2: No codec for ".concat(a,", treating as PCM"))),this.audioPlayer.playChunk(c)):this.audioPlayer.playAudio(i);case 4:return t.a(2)}},t,this)})),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.audioPlayer.stopImmediate(),this.websocket&&(this.websocket.close(),this.websocket=null),this.isConnected=!1)}},{key:"startRecording",value:(c=ce(ie().m(function t(){var e,n;return ie().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,this.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId()}),t.n=4,this.audioRecorder.start();case 4:return 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=ce(ie().m(function t(){var e;return ie().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.audioPlayer.stopImmediate(),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:(r=ce(ie().m(function t(){return ie().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 r.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(i=ce(ie().m(function t(){return ie().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 i.apply(this,arguments)})},{key:"getStatus",value:function(){return{version:this.version,isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying,outputFormat:this.outputAudioFormat,audioPlayer:this.audioPlayer.getStatus(),audioRecorder:this.audioRecorder.getStatus()}}},{key:"updateConfig",value:function(t){this.config=oe(oe({},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&&se(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a,c,s,u}(mt);fe(he,"SUPPORTED_INPUT_ENCODINGS",["pcm","pcmu","pcma"]),fe(he,"SUPPORTED_INPUT_SAMPLE_RATES",[8e3,16e3,24e3,48e3]),fe(he,"SUPPORTED_INPUT_BIT_DEPTHS",[8,16,24]),fe(he,"SUPPORTED_INPUT_CHANNELS",[1]),fe(he,"SUPPORTED_OUTPUT_ENCODINGS",["pcm","pcmu","pcma"]),fe(he,"SUPPORTED_OUTPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),fe(he,"SUPPORTED_OUTPUT_BIT_DEPTHS",[8,16,24]),fe(he,"SUPPORTED_OUTPUT_CHANNELS",[1]),fe(he,"SUPPORTED_OUTPUT_CONTAINERS",["raw","wav"]);const ve=he;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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return me(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!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,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,me(d,"constructor",u),me(u,"constructor",s),s.displayName="GeneratorFunction",me(u,i,"GeneratorFunction"),me(d),me(d,i,"Generator"),me(d,o,function(){return this}),me(d,"toString",function(){return"[object Generator]"}),(ye=function(){return{w:r,m:f}})()}function me(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}me=function(t,e,n,o){function r(e,n){me(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},me(t,e,n,o)}function be(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function we(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 Se(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?we(Object(n),!0).forEach(function(e){xe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):we(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function xe(t,e,n){return(e=Ce(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}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,Ce(o.key),o)}}function Ce(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+""}function Pe(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Pe=function(){return!!t})()}function Oe(t){return Oe=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Oe(t)}function Ee(t,e){return Ee=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ee(t,e)}var Te=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=Oe(e),function(t,e){if(e&&("object"==ge(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,Pe()?Reflect.construct(e,n||[],Oe(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=Se({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&&Ee(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:(i=ye().m(function t(e){var n=this;return ye().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 i={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(i):n.executeTask(i)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){be(r,n,o,a,c,"next",t)}function c(t){be(r,n,o,a,c,"throw",t)}a(void 0)})},function(t){return r.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,i=this.buildWebSocketUrl(this.config.baseWsUrl),r=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(r),c=!1,s=!1,u=null,l=function(n){if(!s)try{var o={message:t.text},i=e.config.forceConversationId||e.config.conversationId;i&&(o.conversationId=i,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=i,e.persistConversationId(i))),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 i=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",i)}catch(t){}if("hello"===i.type&&i.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",i.conversationId),e.config.conversationId=i.conversationId,e.persistConversationId(i.conversationId),e.emit&&e.emit("conversationIdChanged",i.conversationId),!s&&n&&1===n.readyState){if(u)try{clearTimeout(u)}catch(t){}l(n)}return}if(!e.config.conversationId&&i.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",i.conversationId),e.config.conversationId=i.conversationId,e.persistConversationId(i.conversationId)),"chunk"===i.type&&"string"==typeof i.content)e.fullResponseBuffer+=i.content,e.emit("chunk",i.content);else if("done"===i.type){try{var r=i.text||i.content||i.answer||i.message||"";r&&!e.fullResponseBuffer&&(e.fullResponseBuffer=r)}catch(t){}!e.config.conversationId&&i.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",i.conversationId),e.config.conversationId=i.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"===i.type){var a=new Error(i.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(i);h.onopen=d(h),h.onmessage=f(h),h.onerror=(o=h,function(n){if(!c){c=!0;try{o.close()}catch(t){}var i=new WebSocket(a);return i.onopen=d(i),i.onmessage=f(i),i.onerror=function(n){e.emit("error",n),t.reject(n)},void(i.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=Se(Se({},this.config),t)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&ke(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c),Ie=n(540),je=n(848);function Be(t){return Be="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},Be(t)}function De(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 Ae(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?De(Object(n),!0).forEach(function(e){Fe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):De(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Fe(t,e,n){return(e=function(t){var e=function(t){if("object"!=Be(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Be(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Be(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Re(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return _e(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(_e(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,_e(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,_e(d,"constructor",u),_e(u,"constructor",s),s.displayName="GeneratorFunction",_e(u,i,"GeneratorFunction"),_e(d),_e(d,i,"Generator"),_e(d,o,function(){return this}),_e(d,"toString",function(){return"[object Generator]"}),(Re=function(){return{w:r,m:f}})()}function _e(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}_e=function(t,e,n,o){function r(e,n){_e(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},_e(t,e,n,o)}function Ue(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Me(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,i,r,a,c=[],s=!0,u=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw i}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return ze(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)?ze(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 ze(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 Ne=function(t){var e=t.websocketUrl,n=t.agentId,o=t.appId,i=t.voice,r=void 0===i?"default":i,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,E=Me((0,Ie.useState)(!1),2),T=E[0],I=E[1],j=Me((0,Ie.useState)(!1),2),B=j[0],D=j[1],A=Me((0,Ie.useState)(!1),2),F=(A[0],A[1]),R=Me((0,Ie.useState)("Disconnected"),2),_=(R[0],R[1]),U=(0,Ie.useRef)(null);(0,Ie.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:r,language:c,autoReconnect:u,agentSettingsOverride:d});return t.on("connected",function(){I(!0),_("Connected"),null==f||f()}),t.on("disconnected",function(){I(!1),_("Disconnected"),null==p||p()}),t.on("recordingStarted",function(){D(!0),null==h||h()}),t.on("recordingStopped",function(){D(!1),null==v||v()}),t.on("playbackStarted",function(){F(!0),null==g||g()}),t.on("playbackStopped",function(){F(!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,r,c,d]);var M=function(){var t,e=(t=Re().m(function t(){var e;return Re().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,i){var r=t.apply(e,n);function a(t){Ue(r,o,i,a,c,"next",t)}function c(t){Ue(r,o,i,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),z=(0,je.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,je.jsx)("div",{style:{fontSize:"20px"},children:B?"🔴":"🎤"}),(0,je.jsx)("div",{children:B?"Stop Listening":"Start Listening"})]});return(0,je.jsx)("button",{className:"voice-button ".concat(B?"recording":""," ").concat(k),style:Ae({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:B?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},P),onClick:M,disabled:!T,children:O||z})};function Le(t){return Le="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},Le(t)}function He(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ve(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ve(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,Ve(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ve(d,"constructor",u),Ve(u,"constructor",s),s.displayName="GeneratorFunction",Ve(u,i,"GeneratorFunction"),Ve(d),Ve(d,i,"Generator"),Ve(d,o,function(){return this}),Ve(d,"toString",function(){return"[object Generator]"}),(He=function(){return{w:r,m:f}})()}function Ve(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Ve=function(t,e,n,o){function r(e,n){Ve(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Ve(t,e,n,o)}function We(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Ke(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){We(r,o,i,a,c,"next",t)}function c(t){We(r,o,i,a,c,"throw",t)}a(void 0)})}}function Ge(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 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 qe(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 Je(t){var e=function(t){if("object"!=Le(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Le(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Le(e)?e:e+""}var Ye=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?Ge(Object(n),!0).forEach(function(e){Qe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ge(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=Ke(He().m(function t(){var e;return He().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=Ke(He().m(function t(){var e;return He().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&&qe(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function $e(t){return $e="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},$e(t)}function Xe(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ze(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ze(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,Ze(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ze(d,"constructor",u),Ze(u,"constructor",s),s.displayName="GeneratorFunction",Ze(u,i,"GeneratorFunction"),Ze(d),Ze(d,i,"Generator"),Ze(d,o,function(){return this}),Ze(d,"toString",function(){return"[object Generator]"}),(Xe=function(){return{w:r,m:f}})()}function Ze(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Ze=function(t,e,n,o){function r(e,n){Ze(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Ze(t,e,n,o)}function tn(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function en(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){tn(r,o,i,a,c,"next",t)}function c(t){tn(r,o,i,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,on(o.key),o)}}function on(t){var e=function(t){if("object"!=$e(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=$e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==$e(e)?e:e+""}var rn=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=en(Xe().m(function t(e){var n,o=this;return Xe().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 pt({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en"}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(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)}),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.type){case"connected":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text);break;case"agent_response":case"barge_in":case"stop_playing":break;case"error":this.onError(new Error(t.message))}}},{key:"startListening",value:(n=en(Xe().m(function t(){var e;return Xe().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.webSocketManager.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],e&&nn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function an(t){return an="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},an(t)}function cn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return sn(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(sn(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,sn(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,sn(d,"constructor",u),sn(u,"constructor",s),s.displayName="GeneratorFunction",sn(u,i,"GeneratorFunction"),sn(d),sn(d,i,"Generator"),sn(d,o,function(){return this}),sn(d,"toString",function(){return"[object Generator]"}),(cn=function(){return{w:r,m:f}})()}function sn(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}sn=function(t,e,n,o){function r(e,n){sn(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},sn(t,e,n,o)}function un(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function ln(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){un(r,o,i,a,c,"next",t)}function c(t){un(r,o,i,a,c,"throw",t)}a(void 0)})}}function dn(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,fn(o.key),o)}}function fn(t){var e=function(t){if("object"!=an(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=an(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==an(e)?e:e+""}var pn=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 rn({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,variables:e.variables||{},language:e.language||"en"}),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",i=this.config.startCallButtonColor||"#667eea",r=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(i,";\n color: ").concat(r,";\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"),i=document.getElementById("muteBtn"),r=document.getElementById("speakerBtn");n&&(n.onclick=function(){return e.startVoiceCall()}),o&&(o.onclick=function(){return e.endVoiceCall()}),i&&(i.onclick=function(){return e.toggleMute()}),r&&(r.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=ln(cn().m(function t(){var e,n,o,i,r,a,c;return cn().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((i=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(i.statusText));case 4:return t.n=5,i.json();case 5:return r=t.v,t.a(2,r.signedUrl||r.wsUrl||r.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,i,r,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,i=35,r=11,a=9,c=32,s=45,u=42,l=48):e<=450?(d=7,o=110,i=55,r=15,a=11,c=38,s=58,u=52,l=58):e<=550?(d=8,o=140,i=70,r=16,a=12,c=42,s=68,u=56,l=64):e<=700?(d=10,o=130,i=65,r=18,a=13,c=46,s=85,u=60,l=70):(d=12,o=150,i=75,r=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(i,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(t){return t.style.fontSize="".concat(r,"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,r-4),"px"));var b=document.querySelector(".transcript-text");b&&(b.style.fontSize="".concat(Math.max(10,r-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 E=Math.max(22,.5*C);O.style.width="".concat(E,"px"),O.style.height="".concat(E,"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=ln(cn().m(function t(){var e,n,o,i,r,a,c,s,u,l=this;return cn().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 i=t.v,console.log("🔗 Got signed URL:",i),t.n=4,this.sdk.connect(i);case 4:r=t.v,console.log("✅ Connected to WebSocket, connected:",r),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 i=document.getElementById("voiceAvatarActive");i&&i.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&&dn(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 vn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return gn(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(gn(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,gn(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,gn(d,"constructor",u),gn(u,"constructor",s),s.displayName="GeneratorFunction",gn(u,i,"GeneratorFunction"),gn(d),gn(d,i,"Generator"),gn(d,o,function(){return this}),gn(d,"toString",function(){return"[object Generator]"}),(vn=function(){return{w:r,m:f}})()}function gn(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}gn=function(t,e,n,o){function r(e,n){gn(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},gn(t,e,n,o)}function yn(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function mn(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){yn(r,o,i,a,c,"next",t)}function c(t){yn(r,o,i,a,c,"throw",t)}a(void 0)})}}function bn(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,wn(o.key),o)}}function wn(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 Sn=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,i,r,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===(i=this.config.panel)||void 0===i||null===(i=i.sendButtonHint)||void 0===i?void 0:i.color)||"#6B7280","; font-size: ").concat((null===(r=this.config.sendButtonHint)||void 0===r?void 0:r.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,i,r,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===(i=this.config.panel)||void 0===i?void 0:i.inputBorderColor)||"#E5E7EB"),m=this.config.inputFocusColor||(null===(r=this.config.panel)||void 0===r?void 0:r.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 i=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",i),n.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey?"Enter"===e.key&&e.shiftKey&&setTimeout(i,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=mn(vn().m(function t(){return vn().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=mn(vn().m(function t(){var e,n,o;return vn().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 i=document.createElement("div"),r="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";i.className="message ".concat(t," ").concat(r);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,i.appendChild(a),i.appendChild(c),n.appendChild(i),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 i=document.createElement("div");i.className="message-bubble",i.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(i),t.appendChild(e),this.streamingEl=i,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 i=document.createElement("div");i.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",i.textContent=this.t("domainNotValidated");var r=document.createElement("div");r.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",r.textContent=this.t("domainErrorMessage"),o.appendChild(i),o.appendChild(r),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&&bn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();const xn={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 kn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Cn(u,"_invoke",function(n,o,i){var r,c,s,u=0,l=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!i&&e<l.length;e++){var i,r=l[e],p=f.p,h=r[2];n>3?(i=h===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<h&&(i=n<3||r[0]>o||o>h)&&(r[4]=n,r[5]=o,f.n=h,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,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;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,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=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,i,r),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Cn(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,Cn(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Cn(d,"constructor",u),Cn(u,"constructor",s),s.displayName="GeneratorFunction",Cn(u,i,"GeneratorFunction"),Cn(d),Cn(d,i,"Generator"),Cn(d,o,function(){return this}),Cn(d,"toString",function(){return"[object Generator]"}),(kn=function(){return{w:r,m:f}})()}function Cn(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Cn=function(t,e,n,o){function r(e,n){Cn(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Cn(t,e,n,o)}function Pn(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function On(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Pn(r,o,i,a,c,"next",t)}function c(t){Pn(r,o,i,a,c,"throw",t)}a(void 0)})}}function En(t){return En="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},En(t)}function Tn(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){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Tn(Object(n),!0).forEach(function(e){jn(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function jn(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 Bn(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"!=En(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=En(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==En(e)?e:e+""}var An=function(){return t=function t(){var e,n,o=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(o),this.sdk=new Te(this.config),this.isOpen=!1,this.isActive=!1,this.translations=xn,this.currentView="landing";var i=In(In(In({},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});this.voiceInterface=new pn(i);var r=In(In(In({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new Sn(r,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var a=document.getElementById("text-chat-panel");a&&(this.isOpen=!0,a.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,i,r,a,c,s,u,l,d,f,p,h,v,g,y,m,b,w,S,x,k,C,P,O,E,T,I,j,B,D,A,F,R,_,U,M,z,N,L,H,V,W,K,G,Q,q,J,Y,$,X,Z,tt,et,nt,ot,it,rt,at,ct,st,ut,lt,dt,ft,pt,ht,vt,gt,yt,mt,bt,wt,St,xt,kt,Ct,Pt,Ot,Et,Tt,It,jt,Bt,Dt,At,Ft,Rt,_t,Ut,Mt,zt,Nt,Lt,Ht,Vt,Wt,Kt,Gt,Qt,qt,Jt,Yt,$t,Xt,Zt,te,ee,ne,oe,ie,re,ae,ce,se,ue,le,de,fe,pe,he,ve,ge,ye,me,be,we,Se,xe,ke,Ce,Pe,Oe,Ee=t.position||"bottom-right";if("string"==typeof Ee){var Te=Ee.split("-");Ee={vertical:Te[0]||"bottom",horizontal:Te[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var Ie=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",je=(null===(o=t.header)||void 0===o?void 0:o.backgroundColor)||(null===(i=t.button)||void 0===i?void 0:i.backgroundColor)||Ie;return In({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:In({type:(null===(r=t.icon)||void 0===r?void 0:r.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:In({vertical:Ee.vertical||"bottom",horizontal:Ee.horizontal||"right",offset:Ee.offset||{x:20,y:20}},"object"===En(t.position)?t.position:{}),button:In({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)||Ie,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)||Ie},t.button),panel:In({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:In({micButtonColor:(null===(O=t.voice)||void 0===O?void 0:O.micButtonColor)||(null===(E=t.panel)||void 0===E?void 0:E.micButtonColor)||Ie,micButtonActiveColor:(null===(T=t.voice)||void 0===T?void 0:T.micButtonActiveColor)||(null===(I=t.panel)||void 0===I?void 0:I.micButtonActiveColor)||"#EF4444",micButtonHint:In(In({text:(null===(j=t.voice)||void 0===j||null===(j=j.micButtonHint)||void 0===j?void 0:j.text)||(null===(B=t.panel)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.text)||"Click the button to start voice conversation",color:(null===(D=t.voice)||void 0===D||null===(D=D.micButtonHint)||void 0===D?void 0:D.color)||(null===(A=t.panel)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.color)||"#6B7280",fontSize:(null===(F=t.voice)||void 0===F||null===(F=F.micButtonHint)||void 0===F?void 0:F.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===(L=t.voice)||void 0===L?void 0:L.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(H=t.voice)||void 0===H?void 0:H.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(V=t.voice)||void 0===V?void 0:V.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(W=t.voice)||void 0===W?void 0:W.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(K=t.voice)||void 0===K?void 0:K.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:In({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===(it=t.text)||void 0===it?void 0:it.sendButtonText)||(null===(rt=t.panel)||void 0===rt?void 0:rt.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:In(In({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===(Et=t.panel)||void 0===Et?void 0:Et.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(Tt=t.text)||void 0===Tt?void 0:Tt.inputTextColor)||(null===(It=t.panel)||void 0===It?void 0:It.inputTextColor)||"#1F2937",inputFontSize:(null===(jt=t.text)||void 0===jt?void 0:jt.inputFontSize)||(null===(Bt=t.panel)||void 0===Bt?void 0:Bt.inputFontSize)||"14px",inputBorderRadius:(null===(Dt=t.text)||void 0===Dt?void 0:Dt.inputBorderRadius)||(null===(At=t.panel)||void 0===At?void 0:At.inputBorderRadius)||20,inputPadding:(null===(Ft=t.text)||void 0===Ft?void 0:Ft.inputPadding)||(null===(Rt=t.panel)||void 0===Rt?void 0:Rt.inputPadding)||"6px 14px"},t.text),landing:In({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===(Lt=t.landing)||void 0===Lt?void 0:Lt.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Ht=t.landing)||void 0===Ht?void 0:Ht.modeCardHoverBorderColor)||je,modeCardIconBackgroundColor:(null===(Vt=t.landing)||void 0===Vt?void 0:Vt.modeCardIconBackgroundColor)||je,modeCardTitleColor:(null===(Wt=t.landing)||void 0===Wt?void 0:Wt.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(Kt=t.landing)||void 0===Kt?void 0:Kt.voiceCardIcon)||"🎤",textCardIcon:(null===(Gt=t.landing)||void 0===Gt?void 0:Gt.textCardIcon)||"💬"},t.landing),header:In({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:In({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===(ie=t.tooltips)||void 0===ie?void 0:ie.endCall)||null},t.tooltips),messages:In({userBackgroundColor:(null===(re=t.messages)||void 0===re?void 0:re.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:In({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:In({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:In({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:Ie},"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),i=(this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),r={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(r),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,i,r),"\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,i,r,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===(i=this.config.landing)||void 0===i?void 0:i.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===(r=this.config.landing)||void 0===r?void 0:r.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",i="unified"===o,r="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()}),i?(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")),r&&(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()},i&&(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"),i=document.getElementById("newChatBtn");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),i&&(i.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 i=this.config.behavior.mode||"unified";n&&"unified"===i&&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"),i=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active");var r=this.config.behavior.mode||"unified";o&&"unified"===r&&o.classList.add("visible"),i&&(i.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:(r=On(kn().m(function t(){return kn().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 r.apply(this,arguments)})},{key:"sendMessage",value:(i=On(kn().m(function t(){return kn().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 i.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=On(kn().m(function t(){var e,n,o,i,r,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://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((i=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(i.statusText));case 4:return t.n=5,i.json();case 5:return r=t.v,t.a(2,r.signedUrl||r.wsUrl||r.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;console.log("🔄 updateConfig called",{newConfig:t,stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var o,i,r=In({},this.config);t.panel&&(r.panel=In(In({},this.config.panel),t.panel)),t.voice&&(r.voice=In(In({},this.config.voice),t.voice),t.voice.micButtonHint&&(r.voice.micButtonHint=In(In({},null===(o=this.config.voice)||void 0===o?void 0:o.micButtonHint),t.voice.micButtonHint))),t.text&&(r.text=In(In({},this.config.text),t.text),t.text.sendButtonHint&&(r.text.sendButtonHint=In(In({},null===(i=this.config.text)||void 0===i?void 0:i.sendButtonHint),t.text.sendButtonHint))),void 0!==t.language&&(r.language=t.language),void 0!==t.language&&(["he","ar"].includes(t.language)?r.direction="rtl":void 0===t.direction&&(r.direction="ltr")),t.translations&&(r.translations=t.translations,this.translations=t.translations),t.button&&(r.button=In(In({},this.config.button),t.button)),t.header&&(r.header=In(In({},this.config.header),t.header)),t.icon&&(r.icon=In(In({},this.config.icon),t.icon)),t.messages&&(r.messages=In(In({},this.config.messages),t.messages)),t.animation&&(r.animation=In(In({},this.config.animation),t.animation)),t.behavior&&(r.behavior=In(In({},this.config.behavior),t.behavior)),t.accessibility&&(r.accessibility=In(In({},this.config.accessibility),t.accessibility)),t.tooltips&&(r.tooltips=In(In({},this.config.tooltips),t.tooltips)),t.landing&&(r.landing=In(In({},this.config.landing),t.landing)),void 0!==t.direction&&void 0===r.direction&&(r.direction=t.direction),void 0!==t.primaryColor&&(r.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)||(r[e]=t[e])}),null===(e=this.config)||void 0===e||e.language,this.config=this.mergeWithDefaults(r);var a=this.config.language||"en",c=In(In(In({},this.config),this.config.voice),{},{language:a,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});this.voiceInterface=new pn(c);var s=In(In(In({},this.config),this.config.text),{},{language:a,translations:this.translations});this.textInterface=new Sn(s,this.sdk);var u=document.getElementById("text-chat-widget");u&&u.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=On(kn().m(function t(){return kn().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&&Bn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,i,r}(),Fn="2.0.0";const Rn={VoiceSDK:pt,VoiceSDK_v2:ve,TextChatSDK:Te,WebSocketManager:B,AudioRecorder:V,AudioPlayer:Z,EventEmitter:c,VoiceButton:Ne,VanillaVoiceButton:Ye,AgentSDK:rn,TTPChatWidget:An,VERSION:Fn};return o})());
3
3
  //# sourceMappingURL=agent-widget.js.map