ttp-agent-sdk 2.5.2 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-widget.js +1 -1
- package/dist/agent-widget.js.map +1 -1
- package/dist/demos/index.html +4 -4
- package/dist/demos/test-widget.html +486 -0
- package/dist/examples/test-index.html +4 -4
- package/dist/examples/test-widget.html +11 -2
- package/dist/shared/mic-permission-assets/address-bar-hint.svg +12 -8
- package/examples/test-index.html +4 -4
- package/examples/test-widget.html +11 -2
- package/package.json +1 -1
package/dist/agent-widget.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see agent-widget.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TTPAgentSDK=t():e.TTPAgentSDK=t()}(window,()=>(()=>{"use strict";var e={540:(e,t,n)=>{e.exports=n(869)},698:(e,t)=>{var n=Symbol.for("react.transitional.element");function o(e,t,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==t.key&&(r=""+t.key),"key"in t)for(var i in o={},t)"key"!==i&&(o[i]=t[i]);else o=t;return t=o.ref,{$$typeof:n,type:e,key:r,ref:void 0!==t?t:null,props:o}}Symbol.for("react.fragment"),t.jsx=o,t.jsxs=o},848:(e,t,n)=>{e.exports=n(698)},869:(e,t)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(e,t,o){this.props=e,this.context=t,this.refs=r,this.updater=o||n}function a(){}function c(e,t,o){this.props=e,this.context=t,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(e,t){if("object"!=typeof e&&"function"!=typeof e&&null!=e)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")},i.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")},a.prototype=i.prototype;var s=c.prototype=new a;s.constructor=c,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var l={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;t.useEffect=function(e,t){return l.H.useEffect(e,t)},t.useRef=function(e){return l.H.useRef(e)},t.useState=function(e){return l.H.useState(e)}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{AgentSDK:()=>Hn,AudioPlayer:()=>ne,AudioRecorder:()=>W,EventEmitter:()=>l,MicPermissionModals:()=>i,MicPermissionUtils:()=>r,TTPChatWidget:()=>Ro,TextChatSDK:()=>hn,VERSION:()=>Mo,VanillaVoiceButton:()=>Rn,VoiceButton:()=>En,VoiceSDK:()=>ve,VoiceSDK_v2:()=>en,WebSocketManager:()=>F,default:()=>Uo});var r={};n.r(r),n.d(r,{checkPermissionState:()=>Yn,getDeviceInfo:()=>Qn,getPermissionInstructions:()=>Jn,openSettings:()=>Xn});var i={};function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function c(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}function s(e){var t=function(e){if("object"!=a(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==a(t)?t:t+""}n.r(i),n.d(i,{showBlockedModal:()=>ao,showNoMicrophoneModal:()=>co,showPrePromptModal:()=>io});var l=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.events={}},t=[{key:"on",value:function(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}},{key:"off",value:function(e,t){this.events[e]&&(this.events[e]=this.events[e].filter(function(e){return e!==t}))}},{key:"emit",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];this.events[e]&&this.events[e].forEach(function(t){try{t.apply(void 0,n)}catch(t){console.error("Error in event listener for ".concat(e,":"),t)}})}},{key:"removeAllListeners",value:function(e){e?delete this.events[e]:this.events={}}}],t&&c(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,l=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==t);s=!0);}catch(e){l=!0,r=e}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw r}}return c}}(e,t)||f(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=f(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function f(e,t){if(e){if("string"==typeof e)return h(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?h(e,t):void 0}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function g(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return v(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(v(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,v(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,v(d,"constructor",l),v(l,"constructor",s),s.displayName="GeneratorFunction",v(l,r,"GeneratorFunction"),v(d),v(d,r,"Generator"),v(d,o,function(){return this}),v(d,"toString",function(){return"[object Generator]"}),(g=function(){return{w:i,m:p}})()}function v(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}v=function(e,t,n,o){function i(t,n){v(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},v(e,t,n,o)}function m(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function y(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,b(o.key),o)}}function b(e){var t=function(e){if("object"!=u(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=u(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==u(t)?t:t+""}function w(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(w=function(){return!!e})()}function S(e){return S=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},S(e)}function x(e,t){return x=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},x(e,t)}const k=new(function(e){function t(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=S(t),function(e,t){if(t&&("object"==u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,w()?Reflect.construct(t,n||[],S(e).constructor):t.apply(e,n))}(this,t)).connections=new Map,e.connectionCounts=new Map,e.creatingConnections=new Set,e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&x(e,t)}(t,e),n=t,o=[{key:"getConnection",value:(r=g().m(function e(t){var n,o,r=this;return g().w(function(e){for(;;)switch(e.n){case 0:if(!this.connections.has(t)){e.n=1;break}return n=this.connections.get(t),this.connectionCounts.set(t,(this.connectionCounts.get(t)||0)+1),e.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(t)){e.n=2;break}return e.a(2,new Promise(function(e){var n=function(){if(r.connections.has(t)){var o=r.connections.get(t);r.connectionCounts.set(t,(r.connectionCounts.get(t)||0)+1),e(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(t),o=new WebSocket(t),this.connections.set(t,o),this.connectionCounts.set(t,1),o.addEventListener("open",function(e){r.creatingConnections.delete(t),r.emit("open",e,t)}),o.addEventListener("close",function(e){r.creatingConnections.delete(t),r.connections.delete(t),r.connectionCounts.delete(t),r.emit("close",e,t)}),o.addEventListener("error",function(e){r.creatingConnections.delete(t),r.emit("error",e,t)}),o.addEventListener("message",function(e){r.emit("message",e,t)}),e.a(2,o)}},e,this)}),i=function(){var e=this,t=arguments;return new Promise(function(n,o){var i=r.apply(e,t);function a(e){m(i,n,o,a,c,"next",e)}function c(e){m(i,n,o,a,c,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(e){if(this.connections.has(e)){var t=this.connectionCounts.get(e)||0,n=Math.max(0,t-1);if(this.connectionCounts.set(e,n),0===n){var o=this.connections.get(e);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(e),this.connectionCounts.delete(e)}}}},{key:"forceClose",value:function(e){if(this.connections.has(e)){var t=this.connections.get(e);t&&t.readyState===WebSocket.OPEN&&t.close(1e3,"Force close"),this.connections.delete(e),this.connectionCounts.delete(e)}}},{key:"getConnectionStatus",value:function(e){return this.connections.has(e)?{exists:!0,readyState:this.connections.get(e).readyState,subscribers:this.connectionCounts.get(e)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var e,t={},n=p(this.connections.entries());try{for(n.s();!(e=n.n()).done;){var o=d(e.value,2),r=o[0],i=o[1];t[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(e){n.e(e)}finally{n.f()}return t}},{key:"clearAll",value:function(){var e,t=p(this.connections.entries());try{for(t.s();!(e=t.n()).done;){var n=d(e.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(e){t.e(e)}finally{t.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&y(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(l));function C(e){return C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},C(e)}function P(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return E(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(E(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,E(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,E(d,"constructor",l),E(l,"constructor",s),s.displayName="GeneratorFunction",E(l,r,"GeneratorFunction"),E(d),E(d,r,"Generator"),E(d,o,function(){return this}),E(d,"toString",function(){return"[object Generator]"}),(P=function(){return{w:i,m:p}})()}function E(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}E=function(e,t,n,o){function i(t,n){E(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},E(e,t,n,o)}function O(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function T(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,I(o.key),o)}}function I(e){var t=function(e){if("object"!=C(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=C(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==C(t)?t:t+""}function A(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(A=function(){return!!e})()}function j(e){return j=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},j(e)}function D(e,t){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},D(e,t)}var F=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=j(t),function(e,t){if(t&&("object"==C(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,A()?Reflect.construct(t,n||[],j(e).constructor):t.apply(e,n))}(this,t)).config=e,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&D(e,t)}(t,e),n=t,o=[{key:"connect",value:(i=P().m(function e(){var t=this;return P().w(function(e){for(;;)if(0===e.n)return e.a(2,new Promise(function(e,n){try{t.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),t.connectResolve=e,t.connectReject=n,k.getConnection(t.config.websocketUrl,t.config).then(function(n){t.ws=n,t.setupEventListeners(),n.readyState===WebSocket.OPEN&&(t.isConnected=!0,t.emit("connected"),e(),t.connectResolve=null,t.connectReject=null)}).catch(function(e){console.error("🔌 WebSocketManager: Connection failed ".concat(t.connectionId),e),n(e),t.connectResolve=null,t.connectReject=null})}catch(e){console.error("🔌 WebSocketManager: Connection error ".concat(t.connectionId),e),n(e),t.connectResolve=null,t.connectReject=null}}))},e)}),a=function(){var e=this,t=arguments;return new Promise(function(n,o){var r=i.apply(e,t);function a(e){O(r,n,o,a,c,"next",e)}function c(e){O(r,n,o,a,c,"throw",e)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var e=this;if(this.ws){var t=function(t,n){n===e.config.websocketUrl&&(e.isConnected=!0,e.emit("connected"),e.connectResolve&&(e.connectResolve(),e.connectResolve=null,e.connectReject=null))},n=function(t,n){n===e.config.websocketUrl&&(e.isConnected=!1,e.emit("disconnected",t))},o=function(t,n){n===e.config.websocketUrl&&(e.emit("error",t),e.connectReject&&(e.connectReject(t),e.connectResolve=null,e.connectReject=null))},r=function(t,n){n===e.config.websocketUrl&&e.handleMessage(t)};k.on("open",t),k.on("close",n),k.on("error",o),k.on("message",r),this.eventHandlers={open:t,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(k.off("open",this.eventHandlers.open),k.off("close",this.eventHandlers.close),k.off("error",this.eventHandlers.error),k.off("message",this.eventHandlers.message)),this.config.websocketUrl&&k.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(e){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(e))}catch(e){console.warn("🔌 WebSocketManager: Failed to send message:",e.message)}}},{key:"sendBinary",value:function(e){if(this.isConnected&&this.ws)try{this.ws.send(e)}catch(e){console.warn("🔌 WebSocketManager: Failed to send binary data:",e.message)}}},{key:"handleMessage",value:function(e){var t=this;if(e.data instanceof ArrayBuffer)this.emit("binaryAudio",e.data);else if(e.data instanceof Blob)e.data.arrayBuffer().then(function(e){t.emit("binaryAudio",e)}).catch(function(e){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",e)});else try{var n=JSON.parse(e.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(e){this.emit("error",e)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return k.getAllConnections()}},{key:"clearAllConnections",value:function(){k.clearAll()}}],o&&T(n.prototype,o),r&&T(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a}(l);function _(e){return _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_(e)}function B(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return R(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(R(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,R(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,R(d,"constructor",l),R(l,"constructor",s),s.displayName="GeneratorFunction",R(l,r,"GeneratorFunction"),R(d),R(d,r,"Generator"),R(d,o,function(){return this}),R(d,"toString",function(){return"[object Generator]"}),(B=function(){return{w:i,m:p}})()}function R(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}R=function(e,t,n,o){function i(t,n){R(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},R(e,t,n,o)}function M(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function U(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){M(i,o,r,a,c,"next",e)}function c(e){M(i,o,r,a,c,"throw",e)}a(void 0)})}}function N(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function L(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,z(o.key),o)}}function z(e){var t=function(e){if("object"!=_(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=_(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==_(t)?t:t+""}function V(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(V=function(){return!!e})()}function K(e){return K=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},K(e)}function H(e,t){return H=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},H(e,t)}var W=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=K(t),function(e,t){if(t&&("object"==_(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,V()?Reflect.construct(t,n||[],K(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&H(e,t)}(t,e),n=t,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var e,t=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return N(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?N(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(t.s();!(e=t.n()).done;){var n=e.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(e){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(e){t.e(e)}finally{t.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"checkPermissionState",value:function(){var e=U(B().m(function e(){var t;return B().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!navigator.permissions||!navigator.permissions.query){e.n=2;break}return e.n=1,navigator.permissions.query({name:"microphone"});case 1:return t=e.v,e.a(2,t.state);case 2:e.n=4;break;case 3:e.p=3,e.v,console.log("⚠️ AudioRecorder: Permissions API not available or not supported for microphone");case 4:return e.a(2,null)}},e,null,[[0,3]])}));return function(){return e.apply(this,arguments)}}()},{key:"start",value:(i=U(B().m(function e(){var t,n,o,r,i,a,c=this;return B().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,console.log("🎤 AudioRecorder: Requesting microphone access..."),e.n=1,this.checkPermissionState();case 1:return(t=e.v)&&(console.log("📋 AudioRecorder: Current permission state: ".concat(t)),"denied"===t&&console.warn('⚠️ AudioRecorder: Permission state is "denied" - browser may not show prompt. User may need to change in browser settings.')),e.n=2,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 2:if(this.mediaStream=e.v,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){e.n=3;break}return e.n=3,this.audioContext.resume();case 3:return n=this.getAudioProcessorPath(),e.n=4,this.audioContext.audioWorklet.addModule(n);case 4:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(e){var t=e.data,n=t.type,o=t.data;"pcm_audio_data"===n&&c.emit("audioData",o)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),console.log("✅ AudioRecorder: Microphone access granted"),this.isRecording=!0,this.emit("recordingStarted"),e.n=9;break;case 5:if(e.p=5,a=e.v,o=a.message,"NotAllowedError"!==a.name&&"PermissionDeniedError"!==a.name){e.n=7;break}return e.n=6,this.checkPermissionState();case 6:"denied"===(r=e.v)?(o='Microphone access was blocked. To enable it: 1) Click the lock icon (🔒) in your browser\'s address bar, 2) Find "Microphone" and change it to "Allow", 3) Refresh this page and try again.',console.error("❌ AudioRecorder: Permission explicitly denied. User must change in browser settings.")):"prompt"===r?(o='Microphone permission was denied. Click the "Voice Call" button again to see the permission prompt.',console.error('❌ AudioRecorder: Permission denied but state is "prompt" - user can try again.')):(o="Microphone permission was denied. Click the button again to retry, or enable microphone access in your browser settings (lock icon 🔒 in address bar).",console.error("❌ AudioRecorder: Permission denied. User can try again or change in browser settings.")),e.n=8;break;case 7:"NotFoundError"===a.name||"DevicesNotFoundError"===a.name?(o="No microphone found. Please connect a microphone and try again.",console.error("❌ AudioRecorder: No microphone device found.")):"NotReadableError"===a.name||"TrackStartError"===a.name?(o="Microphone is already in use by another application. Please close other apps using the microphone and try again.",console.error("❌ AudioRecorder: Microphone is busy or not readable.")):"SecurityError"!==a.name&&"PermissionDeniedError"!==a.name||(o="Microphone access blocked. On mobile devices, please tap the recording button directly (not from an iframe or popup).",console.error("❌ AudioRecorder: User agent blocked microphone access. This often happens on mobile when not called from direct user interaction."));case 8:throw(i=new Error(o)).name=a.name,i.originalError=a,this.emit("error",i),i;case 9:return e.a(2)}},e,this,[[0,5]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=U(B().m(function e(){var t;return B().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:if(e.p=1,!this.audioWorkletNode){e.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),e.n=2,new Promise(function(e){return setTimeout(e,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(e){return e.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){e.n=4;break}return e.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),e.n=6;break;case 5:throw e.p=5,t=e.v,this.emit("error",t),t;case 6:return e.a(2)}},e,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&L(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(l);function G(e){return G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},G(e)}function q(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Q(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Q(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Q(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Q(d,"constructor",l),Q(l,"constructor",s),s.displayName="GeneratorFunction",Q(l,r,"GeneratorFunction"),Q(d),Q(d,r,"Generator"),Q(d,o,function(){return this}),Q(d,"toString",function(){return"[object Generator]"}),(q=function(){return{w:i,m:p}})()}function Q(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Q=function(e,t,n,o){function i(t,n){Q(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Q(e,t,n,o)}function Y(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function $(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Y(i,o,r,a,c,"next",e)}function c(e){Y(i,o,r,a,c,"throw",e)}a(void 0)})}}function J(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,X(o.key),o)}}function X(e){var t=function(e){if("object"!=G(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=G(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==G(t)?t:t+""}function Z(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Z=function(){return!!e})()}function ee(e){return ee=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ee(e)}function te(e,t){return te=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},te(e,t)}var ne=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=ee(t),function(e,t){if(t&&("object"==G(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Z()?Reflect.construct(t,n||[],ee(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n.audioContextReady=!1,n.initializeAudioContext().catch(function(){}),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&te(e,t)}(t,e),n=t,o=[{key:"initializeAudioContext",value:(i=$(q().m(function e(){var t,n,o,r,i;return q().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.audioContext||"closed"===this.audioContext.state){e.n=1;break}return e.a(2);case 1:if(e.p=1,t=this.config.sampleRate?{sampleRate:this.config.sampleRate}:{},this.audioContext=new(window.AudioContext||window.webkitAudioContext)(t),"suspended"!==this.audioContext.state){e.n=2;break}return e.n=2,this.audioContext.resume();case 2:if("running"===this.audioContext.state)try{n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(1,.01*n,n),(r=this.audioContext.createBufferSource()).buffer=o,r.connect(this.audioContext.destination),r.start(0),r.stop(this.audioContext.currentTime+.01)}catch(e){console.debug("AudioPlayer: AudioContext warmup skipped:",e)}this.audioContextReady=!0,e.n=4;break;case 3:e.p=3,i=e.v,console.warn("AudioPlayer: Failed to pre-initialize AudioContext:",i),this.audioContextReady=!1;case 4:return e.a(2)}},e,this,[[1,3]])})),function(){return i.apply(this,arguments)})},{key:"playAudio",value:function(e){var t=this;try{var n=this.createAudioBlob(e);if(this.audioQueue.push(n),!this.isPlaying&&!this.isProcessingQueue&&!this.currentSource){var o=this.audioContextReady?0:50;setTimeout(function(){return t.processQueue()},o)}}catch(e){this.emit("playbackError",e)}}},{key:"createAudioBlob",value:function(e){var t=new Uint8Array(e);if(t.length>=4){if(82===t[0]&&73===t[1]&&70===t[2]&&70===t[3])return new Blob([e],{type:"audio/wav"});if(255===t[0]&&!(224&~t[1]))return new Blob([e],{type:"audio/mpeg"});if(79===t[0]&&103===t[1]&&103===t[2]&&83===t[3])return new Blob([e],{type:"audio/ogg"})}return new Blob([e],{type:"audio/wav"})}},{key:"processQueue",value:(r=$(q().m(function e(){var t,n,o,r,i,a,c,s,l=this;return q().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){e.n=1;break}return e.a(2);case 1:if(this.isProcessingQueue=!0,t=this.audioQueue.shift()){e.n=2;break}return this.isProcessingQueue=!1,e.a(2);case 2:if(e.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext&&"closed"!==this.audioContext.state){e.n=3;break}return e.n=3,this.initializeAudioContext();case 3:if("suspended"!==(o=this.audioContext).state){e.n=5;break}return e.n=4,o.resume();case 4:if(!n){e.n=5;break}return e.n=5,new Promise(function(e){return setTimeout(e,10)});case 5:if("running"===o.state){e.n=7;break}if(console.warn("AudioPlayer: AudioContext not in running state:",o.state),"suspended"!==o.state){e.n=7;break}return e.n=6,o.resume();case 6:return e.n=7,new Promise(function(e){return setTimeout(e,10)});case 7:return e.n=8,t.arrayBuffer();case 8:return r=e.v,e.n=9,o.decodeAudioData(r);case 9:i=e.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=i,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){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)},c.start(),e.n=11;break;case 10:e.p=10,s=e.v,this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 11:return e.a(2)}},e,this,[[2,10]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var e=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(e){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],e&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.audioContextReady=!1}}],o&&J(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(l);function oe(e){return oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},oe(e)}function re(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return ie(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(ie(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,ie(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,ie(d,"constructor",l),ie(l,"constructor",s),s.displayName="GeneratorFunction",ie(l,r,"GeneratorFunction"),ie(d),ie(d,r,"Generator"),ie(d,o,function(){return this}),ie(d,"toString",function(){return"[object Generator]"}),(re=function(){return{w:i,m:p}})()}function ie(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}ie=function(e,t,n,o){function i(t,n){ie(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},ie(e,t,n,o)}function ae(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function ce(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){ae(i,o,r,a,c,"next",e)}function c(e){ae(i,o,r,a,c,"throw",e)}a(void 0)})}}function se(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function le(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?se(Object(n),!0).forEach(function(t){ue(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):se(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ue(e,t,n){return(t=pe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function de(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,pe(o.key),o)}}function pe(e){var t=function(e){if("object"!=oe(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=oe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==oe(t)?t:t+""}function fe(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(fe=function(){return!!e})()}function he(e){return he=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},he(e)}function ge(e,t){return ge=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ge(e,t)}var ve=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=he(t),function(e,t){if(t&&("object"==oe(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,fe()?Reflect.construct(t,n||[],he(e).constructor):t.apply(e,n))}(this,t)).config=le({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,onStartConversation:n.onStartConversation||null,onEndConversation:n.onEndConversation||null},n),e.isConnected=!1,e.isRecording=!1,e.isPlaying=!1,e.isDestroyed=!1,e.conversationStarted=!1,e.webSocketManager=new F(le(le({},e.config),{},{autoReconnect:!1!==e.config.autoReconnect})),e.audioRecorder=new W(e.config),e.audioPlayer=new ne(e.config),e.setupEventHandlers(),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ge(e,t)}(t,e),n=t,o=[{key:"setupEventHandlers",value:function(){var e=this;this.webSocketManager.on("connected",function(){e.isConnected=!0,e.sendHelloMessage(),e.emit("connected")}),this.webSocketManager.on("disconnected",function(t){if(e.isConnected=!1,e.conversationStarted&&(e.conversationStarted=!1,console.log("🏁 VoiceSDK: Conversation ended (connection closed)"),e.emit("conversationEnded",{}),e.config.onEndConversation))try{e.config.onEndConversation({})}catch(e){console.error("VoiceSDK: Error in onEndConversation hook:",e)}if(t&&1008===t.code&&t.reason&&(t.reason.includes("Domain not whitelisted")||t.reason.includes("domain")||t.reason.includes("whitelist"))){var n=new Error("DOMAIN_NOT_WHITELISTED");n.reason=t.reason,n.code=t.code,e.emit("domainError",n),e.emit("error",n)}e.isRecording&&e.stopRecording().catch(function(e){console.error("VoiceSDK: Error stopping recording on disconnect:",e)}),e.emit("disconnected",t)}),this.webSocketManager.on("error",function(t){e.emit("error",t)}),this.webSocketManager.on("message",function(t){if(("hello_ack"===t.t||"hello_ack"===t.type)&&!e.conversationStarted&&(e.conversationStarted=!0,console.log("🎬 VoiceSDK: Conversation started"),e.emit("conversationStarted",{conversationId:t.conversationId}),e.config.onStartConversation))try{e.config.onStartConversation({conversationId:t.conversationId})}catch(e){console.error("VoiceSDK: Error in onStartConversation hook:",e)}if("greeting_audio"===t.t&&t.data)try{for(var n=atob(t.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);e.audioPlayer.playAudio(o),e.emit("greetingStarted")}catch(e){console.error("VoiceSDK: Error playing greeting audio:",e)}else e.emit("message",t)}),this.webSocketManager.on("binaryAudio",function(t){e.audioPlayer.playAudio(t)}),this.webSocketManager.on("bargeIn",function(t){e.emit("bargeIn",t)}),this.webSocketManager.on("stopPlaying",function(t){e.emit("stopPlaying",t),e.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){if(e.isRecording=!0,!e.conversationStarted&&(e.conversationStarted=!0,console.log("🎬 VoiceSDK: Conversation started (recording)"),e.emit("conversationStarted",{}),e.config.onStartConversation))try{e.config.onStartConversation({})}catch(e){console.error("VoiceSDK: Error in onStartConversation hook:",e)}e.isPlaying&&(e.audioPlayer.stopImmediate(),e.isConnected&&e.webSocketManager.sendMessage({t:"barge_in"})),e.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){e.isRecording=!1,e.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(t){e.isConnected&&e.webSocketManager.sendBinary(t)}),this.audioPlayer.on("playbackStarted",function(){e.isPlaying=!0,e.emit("playbackStarted"),e.isConnected&&e.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){e.isPlaying=!1,e.emit("playbackStopped"),e.isConnected&&e.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(t){e.emit("playbackError",t)})}},{key:"connect",value:(l=ce(re().m(function e(){var t,n;return re().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isDestroyed){e.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),e.a(2,!1);case 1:return e.p=1,t=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=t,e.n=2,this.webSocketManager.connect();case 2:return e.a(2,!0);case 3:return e.p=3,n=e.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),e.a(2,!1)}},e,this,[[1,3]])})),function(){return l.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var e=this.config.websocketUrl,t=new URLSearchParams;if(this.config.agentId&&t.append("agentId",this.config.agentId),this.config.appId&&t.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&t.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&t.append("language",this.config.language),t.toString()){var n=e.includes("?")?"&":"?";e+=n+t.toString()}return e}},{key:"disconnect",value:function(){if(!this.isDestroyed){if(this.conversationStarted&&(this.conversationStarted=!1,console.log("🏁 VoiceSDK: Conversation ended"),this.emit("conversationEnded",{}),this.config.onEndConversation))try{this.config.onEndConversation({})}catch(e){console.error("VoiceSDK: Error in onEndConversation hook:",e)}this.stopRecording(),this.webSocketManager.disconnect()}}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=ce(re().m(function e(){return re().w(function(e){for(;;)switch(e.n){case 0:if(!this.isDestroyed){e.n=1;break}return e.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),e.n=2,this.connect();case 2:return e.a(2,e.v)}},e,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(c=ce(re().m(function e(){var t,n;return re().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isConnected){e.n=1;break}throw new Error("Not connected to voice server");case 1:return e.p=1,console.log("🎤 VoiceSDK: Requesting microphone permission (mobile-friendly)..."),e.n=2,this.audioRecorder.start();case 2:return this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),e.a(2,!0);case 3:return e.p=3,n=e.v,console.error("❌ VoiceSDK: Failed to start recording:",n),"NotAllowedError"===n.name||"PermissionDeniedError"===n.name?((t=new Error("Microphone permission denied. Please allow microphone access in your browser settings and try again.")).name=n.name,t.originalError=n,this.emit("error",t)):this.emit("error",n),e.a(2,!1)}},e,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=ce(re().m(function e(){var t;return re().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:return e.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),e.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),e.a(2,!0);case 3:return e.p=3,t=e.v,this.emit("error",t),e.a(2,!1)}},e,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=ce(re().m(function e(){return re().w(function(e){for(;;)switch(e.n){case 0:if(!this.isRecording){e.n=2;break}return e.n=1,this.stopRecording();case 1:case 3:return e.a(2,e.v);case 2:return e.n=3,this.startRecording();case 4:return e.a(2)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=ce(re().m(function e(){return re().w(function(e){for(;;)switch(e.n){case 0:if(this.stopAudioPlayback(),this.isRecording){e.n=1;break}return e.n=1,this.startRecording();case 1:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(e){this.config=le(le({},this.config),e)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var e={t:"hello"};if(!this.config.appId){var t=new Error("appId is required for connection");return console.error("VoiceSDK: Failed to send hello message:",t),void this.emit("error",t)}e.appId=this.config.appId,this.config.agentSettingsOverride&&Object.keys(this.config.agentSettingsOverride).length>0&&(e.agentSettingsOverride=this.config.agentSettingsOverride,console.log("🔧 VoiceSDK: Sending agent settings override:",Object.keys(this.config.agentSettingsOverride)));try{this.webSocketManager.sendMessage(e)}catch(t){console.error("VoiceSDK: Failed to send hello message:",t),this.emit("error",t)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&de(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,l}(l);function me(e){return me="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},me(e)}function ye(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,be(o.key),o)}}function be(e){var t=function(e){if("object"!=me(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=me(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==me(t)?t:t+""}var we=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.events={}},t=[{key:"on",value:function(e,t){return this.events[e]||(this.events[e]=[]),this.events[e].push(t),this}},{key:"off",value:function(e,t){return this.events[e]?(this.events[e]=this.events[e].filter(function(e){return e!==t}),this):this}},{key:"emit",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return!!this.events[e]&&(this.events[e].forEach(function(e){e.apply(void 0,n)}),!0)}},{key:"once",value:function(e,t){var n=this,o=function(){t.apply(void 0,arguments),n.off(e,o)};return this.on(e,o)}},{key:"removeAllListeners",value:function(e){return e?delete this.events[e]:this.events={},this}}],t&&ye(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();const Se=we;function xe(e){return xe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},xe(e)}function ke(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ce(o.key),o)}}function Ce(e){var t=function(e){if("object"!=xe(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=xe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==xe(t)?t:t+""}const Pe=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name="PCM"},(t=[{key:"decode",value:function(e){if(e instanceof ArrayBuffer)return e;if(e instanceof Uint8Array)return e.buffer;throw new Error("Invalid PCM data type")}},{key:"encode",value:function(e){return e}}])&&ke(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function Ee(e){return Ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ee(e)}function Oe(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Te(o.key),o)}}function Te(e){var t=function(e){if("object"!=Ee(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ee(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ee(t)?t:t+""}const Ie=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name="PCMU"},(t=[{key:"decode",value:function(e){for(var t=e instanceof Uint8Array?e:new Uint8Array(e),n=new Int16Array(t.length),o=0;o<t.length;o++)n[o]=this.mulawToLinear(t[o]);return n.buffer}},{key:"encode",value:function(e){for(var t=e instanceof Int16Array?e:new Int16Array(e),n=new Uint8Array(t.length),o=0;o<t.length;o++)n[o]=this.linearToMulaw(t[o]);return n}},{key:"mulawToLinear",value:function(e){var t=1<<3+(e>>4&7);return(128&e?-1:1)*(132+(15&e)*t+(t>>1)-4)}},{key:"linearToMulaw",value:function(e){var t=e>>8&128;t&&(e=-e),e>32635&&(e=32635),e+=132;for(var n=7,o=16384;0===(e&o)&&n>0;n--,o>>=1);return 255&~(t|n<<4|e>>n+3&15)}}])&&Oe(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function Ae(e){return Ae="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ae(e)}function je(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,De(o.key),o)}}function De(e){var t=function(e){if("object"!=Ae(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ae(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ae(t)?t:t+""}const Fe=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name="PCMA"},(t=[{key:"decode",value:function(e){for(var t=e instanceof Uint8Array?e:new Uint8Array(e),n=new Int16Array(t.length),o=0;o<t.length;o++)n[o]=this.alawToLinear(t[o]);return n.buffer}},{key:"encode",value:function(e){for(var t=e instanceof Int16Array?e:new Int16Array(e),n=new Uint8Array(t.length),o=0;o<t.length;o++)n[o]=this.linearToAlaw(t[o]);return n}},{key:"alawToLinear",value:function(e){var t=(e^=85)>>4&7,n=15&e;return(128&e?-1:1)*(0===t?8+(n<<4):264+(n<<4)<<t-1)}},{key:"linearToAlaw",value:function(e){var t,n,o=e>>8&128;if(o&&(e=-e),e>32635&&(e=32635),e<256)t=0,n=e>>4;else{t=7;for(var r=16384;0===(e&r)&&t>0;t--,r>>=1);n=e>>t+3&15}return 85^(o|t<<4|n)}}])&&je(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function _e(e){return _e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_e(e)}function Be(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Re(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Re(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function Re(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function Me(e){if(null!=e){var t=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}throw new TypeError(_e(e)+" is not iterable")}function Ue(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Ne(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Ne(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Ne(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Ne(d,"constructor",l),Ne(l,"constructor",s),s.displayName="GeneratorFunction",Ne(l,r,"GeneratorFunction"),Ne(d),Ne(d,r,"Generator"),Ne(d,o,function(){return this}),Ne(d,"toString",function(){return"[object Generator]"}),(Ue=function(){return{w:i,m:p}})()}function Ne(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Ne=function(e,t,n,o){function i(t,n){Ne(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Ne(e,t,n,o)}function Le(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function ze(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Le(i,o,r,a,c,"next",e)}function c(e){Le(i,o,r,a,c,"throw",e)}a(void 0)})}}function Ve(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ke(o.key),o)}}function Ke(e){var t=function(e){if("object"!=_e(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=_e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==_e(t)?t:t+""}function He(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(He=function(){return!!e})()}function We(e){return We=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},We(e)}function Ge(e,t){return Ge=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ge(e,t)}var qe=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=We(t),function(e,t){if(t&&("object"==_e(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,He()?Reflect.construct(t,n||[],We(e).constructor):t.apply(e,n))}(this,t)).config=n,e.audioContext=null,e.audioQueue=[],e.isPlaying=!1,e.isProcessingQueue=!1,e.currentSource=null,e.outputFormat=null,e.nextStartTime=0,e.scheduledBuffers=0,e.scheduledSources=new Set,e.pcmChunkQueue=[],e.preparedBuffer=[],e.isProcessingPcmQueue=!1,e.isSchedulingFrames=!1,e.MAX_LOOKAHEAD_SECONDS=.02,e.pendingSentenceText=null,e.sentenceTimings=[],e.isCheckingTranscripts=!1,e.codecs={pcm:new Pe,pcmu:new Ie,pcma:new Fe},e.SUPPORTED_CONTAINERS=["wav","raw"],e.SUPPORTED_ENCODINGS=["pcm","pcmu","pcma"],e.SUPPORTED_SAMPLE_RATES=[8e3,16e3,22050,24e3,44100,48e3],e.SUPPORTED_BIT_DEPTHS=[8,16,24],e.SUPPORTED_CHANNELS=[1],console.log("🎵 AudioPlayer v2 initialized"),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Ge(e,t)}(t,e),n=t,o=[{key:"setOutputFormat",value:function(e){var t;this.validateFormat(e)||(console.warn("⚠️ AudioPlayer: Invalid format, using defaults:",e),e=this.getDefaultFormat());var n=null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate,o=e.sampleRate;this.outputFormat=e,console.log("✅ AudioPlayer v2: Format set:",e),this.audioContext&&n&&n!==o&&(console.warn("⚠️ AudioPlayer: Sample rate changed, recreating AudioContext"),console.warn(" Old: ".concat(n,"Hz → New: ").concat(o,"Hz")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null,console.log("ℹ️ AudioContext will be recreated on next audio chunk with correct sample rate")),this.audioContext||(this.initializeAudioContext(),this.audioContext&&"suspended"===this.audioContext.state&&this.audioContext.resume().then(function(){console.log("✅ AudioPlayer v2: AudioContext resumed and ready")}).catch(function(e){console.warn("⚠️ AudioPlayer v2: Could not resume AudioContext:",e)}))}},{key:"validateFormat",value:function(e){var t,n;if(!e)return!1;var o=null===(t=e.container)||void 0===t?void 0:t.toLowerCase(),r=null===(n=e.encoding)||void 0===n?void 0:n.toLowerCase();return o&&r&&this.SUPPORTED_CONTAINERS.includes(o)&&this.SUPPORTED_ENCODINGS.includes(r)&&this.SUPPORTED_SAMPLE_RATES.includes(e.sampleRate)&&this.SUPPORTED_BIT_DEPTHS.includes(e.bitDepth)&&(!e.channels||this.SUPPORTED_CHANNELS.includes(e.channels))}},{key:"getDefaultFormat",value:function(){return{container:"raw",encoding:"pcm",sampleRate:16e3,channels:1,bitDepth:16}}},{key:"playAudio",value:function(e){var t=this;try{var n=this.createAudioBlob(e);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return t.processQueue()},50)}catch(e){console.error("❌ AudioPlayer v2: Playback error:",e),this.emit("playbackError",e)}}},{key:"playChunk",value:(c=ze(Ue().m(function e(t){var n,o,r=this;return Ue().w(function(e){for(;;)switch(e.n){case 0:(n=this.prepareChunk(t))?(this.preparedBuffer.push(n),(this.preparedBuffer.length<=3||this.preparedBuffer.length%10==0)&&console.log("📥 AudioPlayer: Frame received, queued: ".concat(this.preparedBuffer.length,", scheduled: ").concat(this.scheduledBuffers,", isScheduling: ").concat(this.isSchedulingFrames)),this.isSchedulingFrames?setTimeout(function(){r.preparedBuffer.length>0&&!r.isSchedulingFrames&&r.schedulePreparedFrames()},5):this.schedulePreparedFrames(),this.pcmChunkQueue.length>0&&!this.isProcessingPcmQueue&&this.processPcmQueue()):(console.error("❌ AudioPlayer: playChunk failed - prepareChunk returned null"),console.error(" pcmData length:",(null==t?void 0:t.byteLength)||"undefined"),console.error(" outputFormat:",this.outputFormat),console.error(" audioContext:",this.audioContext?"initialized":"not initialized"),console.error(" audioContext state:",(null===(o=this.audioContext)||void 0===o?void 0:o.state)||"N/A"),this.emit("playbackError",new Error("Failed to prepare PCM chunk for playback")));case 1:return e.a(2)}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"prepareChunk",value:function(e){try{var t;if(!this.outputFormat)return console.error("❌ AudioPlayer: Cannot prepare chunk - outputFormat not set"),console.error(" Call setOutputFormat() before playing audio chunks"),null;if(this.audioContext||this.initializeAudioContext(),!this.audioContext)return console.error("❌ AudioPlayer: Cannot prepare chunk - AudioContext not available"),null;var n=e;if(e.byteLength%2!=0){console.warn("⚠️ Odd PCM chunk size, padding:",e.byteLength);var o=new Uint8Array(e.byteLength+1);o.set(new Uint8Array(e),0),o[e.byteLength]=0,n=o.buffer}for(var r=new Int16Array(n),i=new Float32Array(r.length),a=1/32768,c=r.length,s=0;s<c;s++)i[s]=r[s]*a;var l=(null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate)||this.audioContext.sampleRate,u=this.audioContext.sampleRate,d=this.audioContext.createBuffer(1,i.length,l);d.getChannelData(0).set(i);var p=d.duration,f=i.length,h=p;return u!==l&&(h=f/u),{buffer:d,duration:h,sampleRate:l,contextSampleRate:u}}catch(e){return console.error("❌ AudioPlayer: Error preparing chunk:",e),null}}},{key:"applyFadeOut",value:function(e){return e}},{key:"schedulePreparedFrames",value:(a=ze(Ue().m(function e(){var t,n,o,r,i,a=this;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isSchedulingFrames){e.n=1;break}return e.a(2);case 1:if(this.isSchedulingFrames=!0,t=this.preparedBuffer.length,0===(n=Math.min(t,5))&&t>0&&(n=1),e.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){e.n=3;break}return e.n=3,this.audioContext.resume();case 3:o=0,r=Ue().m(function e(){var t,n,r,i,c;return Ue().w(function(e){for(;;)switch(e.n){case 0:if(t=a.preparedBuffer.shift()){e.n=1;break}return e.a(2,1);case 1:(n=a.audioContext.createBufferSource()).buffer=t.buffer,n.connect(a.audioContext.destination),a.scheduledSources.add(n),r=a.audioContext.currentTime,0===a.scheduledBuffers?(a.nextStartTime<r&&(a.nextStartTime=r+a.MAX_LOOKAHEAD_SECONDS),console.log("🎵 Starting playback with minimal delay:",a.nextStartTime)):(i=r+a.MAX_LOOKAHEAD_SECONDS,a.nextStartTime<i&&(a.nextStartTime=i,console.warn("⚠️ AudioPlayer: Fell behind schedule, adjusting nextStartTime to ".concat(a.nextStartTime.toFixed(4),"s")))),a.pendingSentenceText&&(a.sentenceTimings.push({startTime:a.nextStartTime,text:a.pendingSentenceText,displayed:!1}),console.log("📝 AudioPlayer: Sentence scheduled at ".concat(a.nextStartTime.toFixed(3),'s: "').concat(a.pendingSentenceText.substring(0,40),'..."')),a.pendingSentenceText=null,a.isCheckingTranscripts||a.startTranscriptChecker()),n.start(a.nextStartTime),a.nextStartTime+=t.duration,a.nextStartTime=Math.round(1e6*a.nextStartTime)/1e6,c=a.nextStartTime-t.duration,a.scheduledBuffers<5&&(console.log("🎵 AudioPlayer: Scheduled frame ".concat(a.scheduledBuffers+1," at ").concat(c.toFixed(4),"s, next at ").concat(a.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(t.duration.toFixed(4),"s (").concat((1e3*t.duration).toFixed(2),"ms), Queued: ").concat(a.preparedBuffer.length,", Scheduled: ").concat(a.scheduledBuffers))),a.scheduledBuffers++,o++,n.onended=function(){if(a.scheduledSources.delete(n),a.scheduledBuffers--,0===a.scheduledBuffers&&0===a.preparedBuffer.length&&0===a.pcmChunkQueue.length)a.isPlaying=!1,a.isSchedulingFrames=!1,console.log("🛑 AudioPlayer: Emitting playbackStopped event (all buffers finished)"),a.emit("playbackStopped");else if(a.preparedBuffer.length>0)setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()},0);else if(a.scheduledBuffers>0){var e=function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(e,10)};setTimeout(e,10)}},a.isPlaying||(a.isPlaying=!0,console.log("🎵 AudioPlayer: Emitting playbackStarted event"),a.emit("playbackStarted"));case 2:return e.a(2)}},e)});case 4:if(!(this.preparedBuffer.length>0&&o<n)){e.n=7;break}return e.d(Me(r()),5);case 5:if(!e.v){e.n=6;break}return e.a(3,7);case 6:e.n=4;break;case 7:this.isSchedulingFrames=!1,this.preparedBuffer.length>0&&requestAnimationFrame(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()}),this.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0&&a.schedulePreparedFrames()},10)},10),e.n=9;break;case 8:e.p=8,i=e.v,console.error("❌ AudioPlayer v2: Error scheduling frames:",i),this.emit("playbackError",i),this.isSchedulingFrames=!1;case 9:return e.a(2)}},e,this,[[2,8]])})),function(){return a.apply(this,arguments)})},{key:"processPcmQueue",value:(i=ze(Ue().m(function e(){var t,n,o,r,i,a,c,s,l,u,d,p,f,h,g,v,m,y,b,w,S=this;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isProcessingPcmQueue){e.n=1;break}return e.a(2);case 1:if(this.isProcessingPcmQueue=!0,e.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){e.n=3;break}return e.n=3,this.audioContext.resume();case 3:if(!(this.pcmChunkQueue.length>0)){e.n=5;break}if(o=this.pcmChunkQueue.shift()){e.n=4;break}return e.a(3,3);case 4:for(r=o,o.byteLength%2!=0&&(console.warn("⚠️ Odd PCM chunk size, padding:",o.byteLength),(i=new Uint8Array(o.byteLength+1)).set(new Uint8Array(o),0),i[o.byteLength]=0,r=i.buffer),a=new Int16Array(r),c=new Float32Array(a.length),s=1/32768,l=a.length,u=0;u<l;u++)c[u]=a[u]*s;d=(null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate)||this.audioContext.sampleRate,p=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(p,"Hz)")):console.warn("⚠️ AudioPlayer: outputFormat.sampleRate not set! Using AudioContext sample rate:",p),(f=this.audioContext.createBuffer(1,c.length,d)).getChannelData(0).set(c),(h=this.audioContext.createBufferSource()).buffer=f,h.connect(this.audioContext.destination),g=this.audioContext.currentTime,this.nextStartTime<g&&(this.nextStartTime=g,0===this.scheduledBuffers&&console.log("🎵 Starting playback at current time:",g)),v=f.duration,m=c.length,y=v,p!==d&&(y=m/p,this.scheduledBuffers<3&&(console.log("🔄 Resampling detected: ".concat(d,"Hz → ").concat(p,"Hz")),console.log(" Buffer duration: ".concat(v.toFixed(4),"s, Calculated: ").concat(y.toFixed(4),"s")))),h.start(this.nextStartTime),this.nextStartTime+=y,this.nextStartTime=Math.round(1e6*this.nextStartTime)/1e6,this.scheduledBuffers<3&&(b=this.nextStartTime-y,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(y.toFixed(4),"s (").concat((1e3*y).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")),e.n=3;break;case 5:this.isProcessingPcmQueue=!1,e.n=7;break;case 6:e.p=6,w=e.v,console.error("❌ AudioPlayer v2: Error playing chunk:",w),this.emit("playbackError",w),this.isProcessingPcmQueue=!1;case 7:return e.a(2)}},e,this,[[2,6]])})),function(){return i.apply(this,arguments)})},{key:"createAudioBlob",value:function(e){var t=new Uint8Array(e);console.log("🎵 AudioPlayer: Processing ".concat(t.length," bytes")),console.log("🎵 AudioPlayer: Negotiated format:",this.outputFormat);var n=this.outputFormat&&this.outputFormat.container&&"wav"===this.outputFormat.container.toLowerCase(),o=this.outputFormat&&this.outputFormat.container&&"raw"===this.outputFormat.container.toLowerCase(),r=this.isWavFile(t);if(r&&console.log("🎵 AudioPlayer: Data has WAV header (RIFF)"),o&&r)return console.error("❌ AudioPlayer: CRITICAL MISMATCH!"),console.error(" Negotiated format: RAW"),console.error(" Actual data: WAV (RIFF header detected)"),console.error(" Backend is ignoring format request and sending WAV anyway."),console.warn("⚠️ AudioPlayer: Processing as WAV to avoid playback failure, but UI configuration was bypassed."),this.handleWavFile(t);if(o&&!r)console.log("🎵 AudioPlayer: Processing as RAW data (as negotiated)");else{if(n&&r)return console.log("✅ AudioPlayer: Processing as WAV file (matches negotiation)"),this.handleWavFile(t);if(n&&!r)return console.warn("⚠️ AudioPlayer: Negotiated WAV but data lacks WAV header. Attempting WAV processing anyway."),this.handleWavFile(t);if(!this.outputFormat&&r)return console.log("🎵 AudioPlayer: No format negotiated, auto-detecting WAV"),this.handleWavFile(t);this.outputFormat||r||(console.warn("⚠️ AudioPlayer: No format negotiated and data not WAV, using defaults"),this.outputFormat=this.getDefaultFormat())}return this.outputFormat||(console.warn("⚠️ AudioPlayer: No format set, using defaults"),this.outputFormat=this.getDefaultFormat()),console.log("🎵 AudioPlayer: Processing as RAW data with encoding:",this.outputFormat.encoding),this.handleRawData(t)}},{key:"isWavFile",value:function(e){return e.length>=44&&82===e[0]&&73===e[1]&&70===e[2]&&70===e[3]}},{key:"handleWavFile",value:function(e){var t=this.parseWavHeader(e);if(console.log("🎵 WAV file detected:",{format:t.audioFormat,encoding:this.getEncodingName(t.audioFormat),sampleRate:t.sampleRate,channels:t.channels,bitDepth:t.bitsPerSample}),1===t.audioFormat)return console.log("✅ PCM WAV - using directly"),new Blob([e],{type:"audio/wav"});var n=this.getCodecForWavFormat(t.audioFormat);if(!n)throw new Error("Unsupported WAV format code: ".concat(t.audioFormat));console.log("🔄 Non-PCM WAV - converting to PCM WAV");var o=e.slice(44),r=n.decode(o),i=this.createWavHeader(r.byteLength,t.sampleRate,t.channels,16);return new Blob([i,r],{type:"audio/wav"})}},{key:"handleRawData",value:function(e){var t,n,o=this.outputFormat.encoding.toLowerCase(),r=this.getCodec(o);if(!r)throw new Error("No codec found for encoding: ".concat(o));if(console.log("🎵 AudioPlayer: Decoding ".concat(o.toUpperCase()," to PCM")),console.log("🎵 AudioPlayer: Input format - bitDepth: ".concat(this.outputFormat.bitDepth,", sampleRate: ").concat(this.outputFormat.sampleRate)),"pcm"===o){var i=this.outputFormat.bitDepth||16;e.length,24===i?(console.warn("⚠️ AudioPlayer: Format says 24-bit PCM, but browser support is limited."),console.warn(" Treating as 16-bit PCM. If audio sounds wrong, backend should send 16-bit instead."),t=this.convert24BitTo16Bit(e),n=16):8===i?(console.log("🔄 AudioPlayer: Converting 8-bit PCM to 16-bit PCM"),t=this.convert8BitTo16Bit(e),n=16):(t=e.buffer,n=i,console.log("✅ AudioPlayer: Using native ".concat(i,"-bit PCM (no conversion needed)")))}else t=r.decode(e),n=16,console.log("🔄 AudioPlayer: Decoded ".concat(o.toUpperCase()," to 16-bit PCM"));var a=this.createWavHeader(t.byteLength,this.outputFormat.sampleRate,this.outputFormat.channels,n);return new Blob([a,t],{type:"audio/wav"})}},{key:"convert24BitTo16Bit",value:function(e){for(var t=Math.floor(e.length/3),n=new Int16Array(t),o=0;o<t;o++){var r=e[3*o],i=e[3*o+1],a=e[3*o+2],c=r|i<<8|(255&a)<<16;128&a&&(c|=4278190080),n[o]=Math.max(-32768,Math.min(32767,Math.round(c/256)))}return n.buffer}},{key:"convert8BitTo16Bit",value:function(e){for(var t=e.length,n=new Int16Array(t),o=0;o<t;o++){var r=e[o];n[o]=256*(r-128)}return n.buffer}},{key:"getCodec",value:function(e){var t={pcm:"pcm",linear:"pcm",l16:"pcm",pcmu:"pcmu",ulaw:"pcmu",mulaw:"pcmu",g711u:"pcmu",pcma:"pcma",alaw:"pcma",g711a:"pcma"}[e.toLowerCase()];return this.codecs[t]}},{key:"getCodecForWavFormat",value:function(e){switch(e){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(e){switch(e){case 1:return"PCM";case 6:return"A-law";case 7:return"μ-law";default:return"Unknown (".concat(e,")")}}},{key:"parseWavHeader",value:function(e){var t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{audioFormat:t.getUint16(20,!0),channels:t.getUint16(22,!0),sampleRate:t.getUint32(24,!0),byteRate:t.getUint32(28,!0),blockAlign:t.getUint16(32,!0),bitsPerSample:t.getUint16(34,!0)}}},{key:"createWavHeader",value:function(e,t,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+e,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,t,!0),i.setUint32(28,t*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,e,!0),r}},{key:"initializeAudioContext",value:function(){var e,t,n=(null===(e=this.outputFormat)||void 0===e?void 0:e.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===(t=this.outputFormat)||void 0===t?void 0:t.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(e){console.error("❌ Failed to create AudioContext:",e),this.audioContext=new(window.AudioContext||window.webkitAudioContext),console.log("ℹ️ Using browser default: ".concat(this.audioContext.sampleRate,"Hz"))}}},{key:"processQueue",value:(r=ze(Ue().m(function e(){var t,n,o,r,i,a,c,s,l=this;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){e.n=1;break}return e.a(2);case 1:if(this.isProcessingQueue=!0,t=this.audioQueue.shift()){e.n=2;break}return this.isProcessingQueue=!1,e.a(2);case 2:if(e.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||this.initializeAudioContext(),"suspended"!==(o=this.audioContext).state){e.n=4;break}return e.n=3,o.resume();case 3:if(!n){e.n=4;break}return e.n=4,new Promise(function(e){return setTimeout(e,50)});case 4:if("running"===o.state){e.n=8;break}if(console.warn("AudioPlayer v2: AudioContext not in running state:",o.state),"suspended"!==o.state){e.n=8;break}return e.n=5,o.resume();case 5:if(!n){e.n=7;break}return e.n=6,new Promise(function(e){return setTimeout(e,50)});case 6:e.n=8;break;case 7:return e.n=8,new Promise(function(e){return setTimeout(e,10)});case 8:return e.n=9,t.arrayBuffer();case 9:return r=e.v,e.n=10,o.decodeAudioData(r);case 10:i=e.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=i,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){l.currentSource=null,l.isProcessingQueue=!1,l.audioQueue.length>0?setTimeout(function(){return l.processQueue()},50):setTimeout(function(){0!==l.audioQueue.length||l.currentSource||(l.isPlaying=!1,l.emit("playbackStopped"))},100)},c.start(),e.n=12;break;case 11:e.p=11,s=e.v,console.error("❌ AudioPlayer v2: Error processing queue:",s),this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 12:return e.a(2)}},e,this,[[2,11]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"reset",value:function(){this.stop(),this.audioQueue=[],this.pcmChunkQueue=[]}},{key:"stopImmediate",value:function(){var e=this.isPlaying||null!==this.currentSource||this.scheduledSources.size>0;if(console.log("🛑 AudioPlayer.stopImmediate() called"),console.log(" isPlaying:",this.isPlaying),console.log(" currentSource:",null!==this.currentSource),console.log(" scheduledSources.size:",this.scheduledSources.size),console.log(" scheduledBuffers:",this.scheduledBuffers),this.currentSource){try{console.log(" Stopping currentSource..."),this.currentSource.stop()}catch(e){console.log(" currentSource already stopped or error:",e.message)}this.currentSource=null}if(this.scheduledSources.size>0){console.log(" Stopping ".concat(this.scheduledSources.size," scheduled sources..."));var t,n=0,o=Be(this.scheduledSources);try{for(o.s();!(t=o.n()).done;){var r=t.value;try{r.stop(),n++}catch(e){console.log(" Source already stopped or not started:",e.message)}}}catch(e){o.e(e)}finally{o.f()}console.log(" Stopped ".concat(n," sources")),this.scheduledSources.clear()}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],this.pcmChunkQueue=[],this.preparedBuffer=[],this.isProcessingPcmQueue=!1,this.isSchedulingFrames=!1,this.nextStartTime=0,this.scheduledBuffers=0,this.clearTranscriptState(),e&&(console.log("🛑 AudioPlayer: Emitting playbackStopped event (stopImmediate called)"),this.emit("playbackStopped"))}},{key:"markNewSentence",value:function(e){this.pendingSentenceText=e,console.log('📝 AudioPlayer: New sentence marked: "'.concat(e.substring(0,40),'..."'))}},{key:"startTranscriptChecker",value:function(){var e=this;if(!this.isCheckingTranscripts){this.isCheckingTranscripts=!0,console.log("📝 AudioPlayer: Transcript checker started");var t=function(){if(e.isCheckingTranscripts&&e.audioContext){var n,o=e.audioContext.currentTime,r=Be(e.sentenceTimings);try{for(r.s();!(n=r.n()).done;){var i=n.value;!i.displayed&&o>=i.startTime&&(i.displayed=!0,console.log("📝 AudioPlayer: Display transcript at ".concat(o.toFixed(3),'s: "').concat(i.text.substring(0,40),'..."')),e.emit("transcriptDisplay",{text:i.text}))}}catch(e){r.e(e)}finally{r.f()}e.isPlaying||e.scheduledBuffers>0?requestAnimationFrame(t):(e.isCheckingTranscripts=!1,console.log("📝 AudioPlayer: Transcript checker stopped"))}};requestAnimationFrame(t)}}},{key:"clearTranscriptState",value:function(){this.pendingSentenceText=null,this.sentenceTimings=[],this.isCheckingTranscripts=!1,console.log("📝 AudioPlayer: Transcript state cleared")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed",outputFormat:this.outputFormat,scheduledBuffers:this.scheduledBuffers,preparedBufferLength:this.preparedBuffer.length,scheduledSourcesCount:this.scheduledSources.size}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.removeAllListeners()}}],o&&Ve(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c}(Se);const Qe=qe;function Ye(e){return Ye="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ye(e)}function $e(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Je(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Je(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Je(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Je(d,"constructor",l),Je(l,"constructor",s),s.displayName="GeneratorFunction",Je(l,r,"GeneratorFunction"),Je(d),Je(d,r,"Generator"),Je(d,o,function(){return this}),Je(d,"toString",function(){return"[object Generator]"}),($e=function(){return{w:i,m:p}})()}function Je(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Je=function(e,t,n,o){function i(t,n){Je(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Je(e,t,n,o)}function Xe(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Ze(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Xe(i,o,r,a,c,"next",e)}function c(e){Xe(i,o,r,a,c,"throw",e)}a(void 0)})}}function et(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function tt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,nt(o.key),o)}}function nt(e){var t=function(e){if("object"!=Ye(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ye(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ye(t)?t:t+""}function ot(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ot=function(){return!!e})()}function rt(e){return rt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},rt(e)}function it(e,t){return it=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},it(e,t)}var at=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=rt(t),function(e,t){if(t&&("object"==Ye(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,ot()?Reflect.construct(t,n||[],rt(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&it(e,t)}(t,e),n=t,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var e,t=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return et(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?et(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(t.s();!(e=t.n()).done;){var n=e.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(e){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(e){t.e(e)}finally{t.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=Ze($e().m(function e(){var t,n,o,r,i,a,c=this;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,"https:"===location.protocol||"localhost"===location.hostname||"127.0.0.1"===location.hostname){e.n=1;break}throw t=new Error("Microphone access requires HTTPS. Please use https:// or test on localhost."),console.error("❌ AudioRecorder:",t.message),this.emit("error",t),t;case 1:if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){e.n=2;break}throw n=new Error("getUserMedia is not supported in this browser. Please use a modern browser."),console.error("❌ AudioRecorder:",n.message),this.emit("error",n),n;case 2:return console.log("🎤 AudioRecorder: Requesting microphone access..."),e.n=3,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 3:if(this.mediaStream=e.v,console.log("✅ AudioRecorder: Microphone access granted"),this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){e.n=4;break}return e.n=4,this.audioContext.resume();case 4:return o=this.getAudioProcessorPath(),e.n=5,this.audioContext.audioWorklet.addModule(o);case 5:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(e){var t=e.data,n=t.type,o=t.data;"pcm_audio_data"===n&&c.emit("audioData",o)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),e.n=7;break;case 6:throw e.p=6,a=e.v,r=a.message,"NotAllowedError"===a.name||"PermissionDeniedError"===a.name?(r="Microphone permission denied. Please allow microphone access in your browser settings and try again.",console.error("❌ AudioRecorder: Permission denied. User needs to grant microphone access.")):"NotFoundError"===a.name||"DevicesNotFoundError"===a.name?(r="No microphone found. Please connect a microphone and try again.",console.error("❌ AudioRecorder: No microphone device found.")):"NotReadableError"===a.name||"TrackStartError"===a.name?(r="Microphone is already in use by another application. Please close other apps using the microphone and try again.",console.error("❌ AudioRecorder: Microphone is busy or not readable.")):a.message&&a.message.includes("not allowed by the user agent")&&(r="Microphone access blocked. On mobile devices, please tap the recording button directly (not from an iframe or popup).",console.error("❌ AudioRecorder: User agent blocked microphone access. This often happens on mobile when not called from direct user interaction.")),(i=new Error(r)).name=a.name,i.originalError=a,console.error("❌ AudioRecorder: Failed to start recording:",i),this.emit("error",i),i;case 7:return e.a(2)}},e,this,[[0,6]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=Ze($e().m(function e(){var t;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:if(e.p=1,!this.audioWorkletNode){e.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),e.n=2,new Promise(function(e){return setTimeout(e,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(e){return e.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){e.n=4;break}return e.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),e.n=6;break;case 5:throw e.p=5,t=e.v,this.emit("error",t),t;case 6:return e.a(2)}},e,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&tt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(Se);function ct(e){return ct="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ct(e)}function st(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,lt(o.key),o)}}function lt(e){var t=function(e){if("object"!=ct(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=ct(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==ct(t)?t:t+""}const ut=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return t=e,n=[{key:"extractPcmFromWav",value:function(e){var t=e instanceof Uint8Array?e:new Uint8Array(e);if(t.length<44)throw new Error("WAV data too short (< 44 bytes)");if("RIFF"!==String.fromCharCode(t[0],t[1],t[2],t[3]))throw new Error("Not a valid WAV file - missing RIFF header");if("WAVE"!==String.fromCharCode(t[8],t[9],t[10],t[11]))throw new Error("Not a valid WAV file - missing WAVE format");for(var n=t[22]|t[23]<<8,o=t[24]|t[25]<<8|t[26]<<16|t[27]<<24,r=t[34]|t[35]<<8,i=-1,a=12;a<t.length-8;a+=4){if("data"===String.fromCharCode(t[a],t[a+1],t[a+2],t[a+3])){i=a;break}a+=4+(t[a+4]|t[a+5]<<8|t[a+6]<<16|t[a+7]<<24)}if(-1===i)throw new Error("No data chunk found in WAV");var c=t[i+4]|t[i+5]<<8|t[i+6]<<16|t[i+7]<<24,s=i+8,l=Math.min(c,t.length-s);return{pcmData:t.slice(s,s+l).buffer,format:{sampleRate:o,channels:n,bitDepth:r}}}},{key:"isWavFile",value:function(e){return e.length>=44&&82===e[0]&&73===e[1]&&70===e[2]&&70===e[3]}},{key:"createWavHeader",value:function(e,t,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+e,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,t,!0),i.setUint32(28,t*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,e,!0),r}},{key:"wrapPcmInWav",value:function(t,n){var o=e.createWavHeader(t.byteLength,n.sampleRate,n.channels||1,n.bitDepth||16),r=new Uint8Array(o.byteLength+t.byteLength);return r.set(new Uint8Array(o),0),r.set(new Uint8Array(t),o.byteLength),r.buffer}}],null&&st(t.prototype,null),n&&st(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();function dt(e){return dt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},dt(e)}function pt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ft(o.key),o)}}function ft(e){var t=function(e){if("object"!=dt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=dt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==dt(t)?t:t+""}const ht=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.codecs={pcm:new Pe,pcmu:new Ie,pcma:new Fe}},(t=[{key:"decodeToPcm",value:function(e,t){var n=null==t?void 0:t.toLowerCase();if(!n||"pcm"===n)return e instanceof ArrayBuffer?e:e instanceof Uint8Array?e.buffer:e;var o=this.codecs[n];if(!o)throw new Error("Unsupported encoding: ".concat(t));var r=e instanceof Uint8Array?e:new Uint8Array(e);return o.decode(r)}},{key:"encodeFromPcm",value:function(e,t){var n=null==t?void 0:t.toLowerCase();if(!n||"pcm"===n)return e;var o=this.codecs[n];if(!o)throw new Error("Unsupported target encoding: ".concat(t));var r=o.encode(e);return r instanceof Uint8Array?r.buffer:r}},{key:"getCodec",value:function(e){var t=null==e?void 0:e.toLowerCase();return this.codecs[t]||null}}])&&pt(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function gt(e){return gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},gt(e)}function vt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,mt(o.key),o)}}function mt(e){var t=function(e){if("object"!=gt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=gt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==gt(t)?t:t+""}const yt=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return t=e,n=[{key:"convert",value:function(t,n,o){if(n===o)return t;if(8===n)throw new Error("Source bit depth cannot be 8-bit (only 16-bit or 24-bit supported)");var r=n/8,i=o/8,a=t.byteLength/r;if(new ArrayBuffer(a*i),16===n&&16===o)return t;if(24===n&&16===o)return e.convert24To16(t);if(16===n&&24===o)return e.convert16To24(t);if(16===n&&8===o)return e.convert16To8(t);if(24===n&&8===o)return e.convert24To8(t);throw new Error("Unsupported bit depth conversion: ".concat(n,"-bit → ").concat(o,"-bit"))}},{key:"convert24To16",value:function(e){for(var t=new Uint8Array(e),n=Math.floor(t.length/3),o=new Int16Array(n),r=0;r<n;r++){var i=t[3*r],a=t[3*r+1],c=t[3*r+2],s=i|a<<8|(255&c)<<16;128&c&&(s|=4278190080),o[r]=Math.max(-32768,Math.min(32767,Math.round(s/256)))}return o.buffer}},{key:"convert16To24",value:function(e){for(var t=new Int16Array(e),n=new Uint8Array(3*t.length),o=0;o<t.length;o++){var r=256*t[o];n[3*o]=255&r,n[3*o+1]=r>>8&255,n[3*o+2]=r>>16&255}return n.buffer}},{key:"convert16To8",value:function(e){for(var t=new Int16Array(e),n=new Uint8Array(t.length),o=0;o<t.length;o++){var r=t[o];n[o]=Math.max(0,Math.min(255,Math.round(r/256+128)))}return n.buffer}},{key:"convert24To8",value:function(t){var n=e.convert24To16(t);return e.convert16To8(n)}}],null&&vt(t.prototype,null),n&&vt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();function bt(e){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},bt(e)}function wt(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return St(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(St(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,St(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,St(d,"constructor",l),St(l,"constructor",s),s.displayName="GeneratorFunction",St(l,r,"GeneratorFunction"),St(d),St(d,r,"Generator"),St(d,o,function(){return this}),St(d,"toString",function(){return"[object Generator]"}),(wt=function(){return{w:i,m:p}})()}function St(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}St=function(e,t,n,o){function i(t,n){St(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},St(e,t,n,o)}function xt(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function kt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ct(o.key),o)}}function Ct(e){var t=function(e){if("object"!=bt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==bt(t)?t:t+""}const Pt=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},t=[{key:"resample",value:(n=wt().m(function e(t,n,o){var r,i,a,c,s,l,u,d,p,f,h,g,v;return wt().w(function(e){for(;;)switch(e.n){case 0:if(n!==o){e.n=1;break}return e.a(2,t);case 1:for(r=new Int16Array(t),i=new Float32Array(r.length),a=1/32768,c=0;c<r.length;c++)i[c]=r[c]*a;return s=Math.ceil(i.length*o/n),l=new OfflineAudioContext(1,s,o),(u=l.createBuffer(1,i.length,n)).getChannelData(0).set(i),(d=l.createBufferSource()).buffer=u,d.connect(l.destination),d.start(),e.n=2,l.startRendering();case 2:for(p=e.v,f=p.getChannelData(0),h=new Int16Array(f.length),g=0;g<f.length;g++)v=Math.max(-1,Math.min(1,f[g])),h[g]=Math.round(32767*v);return e.a(2,h.buffer)}},e)}),o=function(){var e=this,t=arguments;return new Promise(function(o,r){var i=n.apply(e,t);function a(e){xt(i,o,r,a,c,"next",e)}function c(e){xt(i,o,r,a,c,"throw",e)}a(void 0)})},function(e,t,n){return o.apply(this,arguments)})}],t&&kt(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Et(e){return Et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Et(e)}function Ot(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Tt(o.key),o)}}function Tt(e){var t=function(e){if("object"!=Et(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Et(t)?t:t+""}const It=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return t=e,n=[{key:"convert",value:function(t,n,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(n===o)return t;if(1===n&&1===o)return t;if(1===n&&2===o)return e.monoToStereo(t,r);if(2===n&&1===o)return e.stereoToMono(t,r);throw new Error("Unsupported channel conversion: ".concat(n," → ").concat(o))}},{key:"monoToStereo",value:function(e,t){for(var n=t/8,o=e.byteLength/n,r=new ArrayBuffer(o*n*2),i=new Uint8Array(e),a=new Uint8Array(r),c=0;c<o;c++)for(var s=c*n,l=c*n*2,u=0;u<n;u++)a[l+u]=i[s+u],a[l+n+u]=i[s+u];return r}},{key:"stereoToMono",value:function(e,t){var n=t/8,o=e.byteLength/(2*n),r=new ArrayBuffer(o*n),i=new Uint8Array(e),a=new Uint8Array(r);if(16===t)for(var c=0;c<o;c++){var s=c*n*2,l=s+n,u=(i[s]|i[s+1]<<8)<<16>>16,d=(i[l]|i[l+1]<<8)<<16>>16,p=Math.round((u+d)/2),f=c*n;a[f]=255&p,a[f+1]=p>>8&255}else for(var h=0;h<o;h++)for(var g=h*n*2,v=h*n,m=0;m<n;m++)a[v+m]=i[g+m];return r}}],null&&Ot(t.prototype,null),n&&Ot(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();function At(e){return At="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},At(e)}function jt(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Dt(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Dt(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Dt(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Dt(d,"constructor",l),Dt(l,"constructor",s),s.displayName="GeneratorFunction",Dt(l,r,"GeneratorFunction"),Dt(d),Dt(d,r,"Generator"),Dt(d,o,function(){return this}),Dt(d,"toString",function(){return"[object Generator]"}),(jt=function(){return{w:i,m:p}})()}function Dt(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Dt=function(e,t,n,o){function i(t,n){Dt(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Dt(e,t,n,o)}function Ft(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function _t(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ft(Object(n),!0).forEach(function(t){Bt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ft(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Bt(e,t,n){return(t=Ut(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Rt(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Mt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ut(o.key),o)}}function Ut(e){var t=function(e){if("object"!=At(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=At(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==At(t)?t:t+""}const Nt=function(){return e=function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.requestedFormat=t,this.actualFormat=n,this.encodingConverter=new ht,this.conversionSteps=[],this._analyzeConversions()},t=[{key:"_analyzeConversions",value:function(){this.conversionSteps=[],this.actualFormat.container!==this.requestedFormat.container&&("wav"===this.actualFormat.container?this.conversionSteps.push("extract_wav"):"wav"===this.requestedFormat.container&&this.conversionSteps.push("wrap_wav")),this.actualFormat.encoding!==this.requestedFormat.encoding&&("pcm"!==this.actualFormat.encoding&&this.conversionSteps.push("decode_encoding"),"pcm"!==this.requestedFormat.encoding&&this.conversionSteps.push("encode_encoding")),this.actualFormat.sampleRate!==this.requestedFormat.sampleRate&&this.conversionSteps.push("resample"),this.actualFormat.bitDepth!==this.requestedFormat.bitDepth&&this.conversionSteps.push("convert_bitdepth"),this.actualFormat.channels!==this.requestedFormat.channels&&this.conversionSteps.push("convert_channels")}},{key:"needsConversion",value:function(){return this.conversionSteps.length>0}},{key:"getConversionSteps",value:function(){var e=[];return this.conversionSteps.includes("extract_wav")&&e.push("Extract PCM from WAV (".concat(this.actualFormat.container," → raw)")),this.conversionSteps.includes("decode_encoding")&&e.push("Decode ".concat(this.actualFormat.encoding.toUpperCase()," → PCM")),this.conversionSteps.includes("resample")&&e.push("Resample ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz")),this.conversionSteps.includes("convert_bitdepth")&&e.push("Convert bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit")),this.conversionSteps.includes("convert_channels")&&e.push("Convert channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels)),this.conversionSteps.includes("encode_encoding")&&e.push("Encode PCM → ".concat(this.requestedFormat.encoding.toUpperCase())),this.conversionSteps.includes("wrap_wav")&&e.push("Wrap in WAV container (raw → ".concat(this.requestedFormat.container,")")),e}},{key:"convert",value:(n=jt().m(function e(t){var n,o,r,i;return jt().w(function(e){for(;;)switch(e.n){case 0:if(this.needsConversion()){e.n=1;break}return e.a(2,t instanceof ArrayBuffer?t:t.buffer);case 1:if(n=t instanceof ArrayBuffer?t:t.buffer,o=_t({},this.actualFormat),this.conversionSteps.includes("extract_wav")&&(r=ut.extractPcmFromWav(n),n=r.pcmData,o=_t(_t({},o),{},{container:"raw",sampleRate:r.format.sampleRate,channels:r.format.channels,bitDepth:r.format.bitDepth}),console.log("🔄 AudioFormatConverter: Extracted PCM from WAV",r.format)),this.conversionSteps.includes("decode_encoding")&&(n=this.encodingConverter.decodeToPcm(n,o.encoding),o.encoding="pcm",o.bitDepth=16,console.log("🔄 AudioFormatConverter: Decoded ".concat(this.actualFormat.encoding.toUpperCase()," → PCM"))),24===o.bitDepth&&o.bitDepth!==this.requestedFormat.bitDepth&&(this.conversionSteps.includes("resample")||this.conversionSteps.includes("convert_channels")||24!==this.requestedFormat.bitDepth)&&(n=yt.convert(n,24,16),o.bitDepth=16,console.log("🔄 AudioFormatConverter: Normalized 24-bit → 16-bit PCM")),!this.conversionSteps.includes("resample")){e.n=3;break}return e.n=2,Pt.resample(n,o.sampleRate,this.requestedFormat.sampleRate);case 2:n=e.v,o.sampleRate=this.requestedFormat.sampleRate,console.log("🔄 AudioFormatConverter: Resampled ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz"));case 3:return this.conversionSteps.includes("convert_channels")&&(n=It.convert(n,o.channels,this.requestedFormat.channels,o.bitDepth),o.channels=this.requestedFormat.channels,console.log("🔄 AudioFormatConverter: Converted channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels))),this.conversionSteps.includes("convert_bitdepth")&&(n=yt.convert(n,o.bitDepth,this.requestedFormat.bitDepth),o.bitDepth=this.requestedFormat.bitDepth,console.log("🔄 AudioFormatConverter: Converted bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit"))),this.conversionSteps.includes("encode_encoding")&&(i=this.encodingConverter.encodeFromPcm(n,this.requestedFormat.encoding),n=i instanceof ArrayBuffer?i:i.buffer,o.encoding=this.requestedFormat.encoding,console.log("🔄 AudioFormatConverter: Encoded PCM → ".concat(this.requestedFormat.encoding.toUpperCase()))),this.conversionSteps.includes("wrap_wav")&&(n=ut.wrapPcmInWav(n,o),o.container="wav",console.log("🔄 AudioFormatConverter: Wrapped in WAV container")),console.log("✅ AudioFormatConverter: Conversion complete"),e.a(2,n)}},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(o,r){var i=n.apply(e,t);function a(e){Rt(i,o,r,a,c,"next",e)}function c(e){Rt(i,o,r,a,c,"throw",e)}a(void 0)})},function(e){return o.apply(this,arguments)})}],t&&Mt(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Lt(e){return Lt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Lt(e)}function zt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function Vt(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?zt(Object(n),!0).forEach(function(t){Jt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):zt(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Kt(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Ht(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Ht(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Ht(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Ht(d,"constructor",l),Ht(l,"constructor",s),s.displayName="GeneratorFunction",Ht(l,r,"GeneratorFunction"),Ht(d),Ht(d,r,"Generator"),Ht(d,o,function(){return this}),Ht(d,"toString",function(){return"[object Generator]"}),(Kt=function(){return{w:i,m:p}})()}function Ht(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Ht=function(e,t,n,o){function i(t,n){Ht(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Ht(e,t,n,o)}function Wt(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Gt(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Wt(i,o,r,a,c,"next",e)}function c(e){Wt(i,o,r,a,c,"throw",e)}a(void 0)})}}function qt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Xt(o.key),o)}}function Qt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Qt=function(){return!!e})()}function Yt(e){return Yt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Yt(e)}function $t(e,t){return $t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},$t(e,t)}function Jt(e,t,n){return(t=Xt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Xt(e){var t=function(e){if("object"!=Lt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Lt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Lt(t)?t:t+""}var Zt=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=Yt(t),function(e,t){if(t&&("object"==Lt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Qt()?Reflect.construct(t,n||[],Yt(e).constructor):t.apply(e,n))}(this,t)).version="2.0.0",e.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||e.getDefaultContainer(n),outputEncoding:n.outputEncoding||n.outputCodec||"pcm",outputSampleRate:n.outputSampleRate||16e3,outputChannels:n.outputChannels||1,outputBitDepth:n.outputBitDepth||16,outputFrameDurationMs:n.outputFrameDurationMs||600,outputCodec:n.outputCodec,agentSettingsOverride:n.agentSettingsOverride||null,variables:n.variables||null,autoReconnect:!1!==n.autoReconnect,protocolVersion:n.protocolVersion||2},e.isConnected=!1,e.hasEverConnected=!1,e.isRecording=!1,e.isPlaying=!1,e.isDestroyed=!1,e.outputAudioFormat=null,e.requestedOutputFormat=null,e.formatConverter=null,e.websocket=null,e.conversationId=null,e.transcriptQueue=[],e.currentPlayingSentenceId=null,e.audioFrameCount=0,e.audioPlayer=new Qe(e.config),e.audioRecorder=new at(e.config),e.setupAudioPlayerEvents(),e.setupAudioRecorderEvents(),e.validateConfig(),console.log("🎵 VoiceSDK v2 initialized:",{version:e.version,outputContainer:e.config.outputContainer,outputEncoding:e.config.outputEncoding,outputSampleRate:e.config.outputSampleRate}),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&$t(e,t)}(t,e),n=t,o=[{key:"getDefaultContainer",value:function(e){return"wav"===e.outputCodec?"wav":"raw"}},{key:"validateInputFormat",value:function(e){var n;if(!e)return"Input format is required";var o=null===(n=e.encoding)||void 0===n?void 0:n.toLowerCase();return o&&t.SUPPORTED_INPUT_ENCODINGS.includes(o)?e.sampleRate&&t.SUPPORTED_INPUT_SAMPLE_RATES.includes(e.sampleRate)?e.bitDepth&&t.SUPPORTED_INPUT_BIT_DEPTHS.includes(e.bitDepth)?e.channels&&t.SUPPORTED_INPUT_CHANNELS.includes(e.channels)?null:"Unsupported input channels: ".concat(e.channels,". Supported: ").concat(t.SUPPORTED_INPUT_CHANNELS.join(", ")):"Unsupported input bit depth: ".concat(e.bitDepth,". Supported: ").concat(t.SUPPORTED_INPUT_BIT_DEPTHS.join(", ")):"Unsupported input sample rate: ".concat(e.sampleRate,". Supported: ").concat(t.SUPPORTED_INPUT_SAMPLE_RATES.join(", ")):"Unsupported input encoding: ".concat(e.encoding,". Supported: ").concat(t.SUPPORTED_INPUT_ENCODINGS.join(", "))}},{key:"validateOutputFormat",value:function(e){var n,o;if(!e)return"Output format is required";var r=null===(n=e.encoding)||void 0===n?void 0:n.toLowerCase();if(!r||!t.SUPPORTED_OUTPUT_ENCODINGS.includes(r))return"Unsupported output encoding: ".concat(e.encoding,". Supported: ").concat(t.SUPPORTED_OUTPUT_ENCODINGS.join(", "));if(!e.sampleRate||!t.SUPPORTED_OUTPUT_SAMPLE_RATES.includes(e.sampleRate))return"Unsupported output sample rate: ".concat(e.sampleRate,". Supported: ").concat(t.SUPPORTED_OUTPUT_SAMPLE_RATES.join(", "));if(!e.bitDepth||!t.SUPPORTED_OUTPUT_BIT_DEPTHS.includes(e.bitDepth))return"Unsupported output bit depth: ".concat(e.bitDepth,". Supported: ").concat(t.SUPPORTED_OUTPUT_BIT_DEPTHS.join(", "));if(!e.channels||!t.SUPPORTED_OUTPUT_CHANNELS.includes(e.channels))return"Unsupported output channels: ".concat(e.channels,". Supported: ").concat(t.SUPPORTED_OUTPUT_CHANNELS.join(", "));var i=null===(o=e.container)||void 0===o?void 0:o.toLowerCase();return i&&t.SUPPORTED_OUTPUT_CONTAINERS.includes(i)?null:"Unsupported output container: ".concat(e.container,". Supported: ").concat(t.SUPPORTED_OUTPUT_CONTAINERS.join(", "))}},{key:"validateConfig",value:function(){var e={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},t=this.validateInputFormat(e);if(t)return console.error("❌ VoiceSDK v2: Invalid input format:",t),void this.emit("error",new Error(t));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 e=this;this.audioPlayer.on("playbackStarted",function(){e.isPlaying=!0,e.emit("playbackStarted"),e.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_started_playing message to server"),e.sendMessage({t:"audio_started_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_started_playing - not connected")}),this.audioPlayer.on("transcriptDisplay",function(t){var n=e.currentPlayingSentenceId?e.currentPlayingSentenceId+1:1;e.currentPlayingSentenceId=n;var o={text:t.text,role:"assistant",sentenceId:n,final:!0,timestamp:Date.now()};console.log("📝 VoiceSDK v2: Emitting synced transcriptDisplay from AudioPlayer:",o),e.emit("transcriptDisplay",o),e.emit("transcript",o)}),this.audioPlayer.on("playbackStopped",function(){e.isPlaying=!1,e.emit("playbackStopped"),e.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_stopped_playing message to server"),e.sendMessage({t:"audio_stopped_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_stopped_playing - not connected")}),this.audioPlayer.on("playbackError",function(t){e.emit("playbackError",t),e.emit("error",t)})}},{key:"setupAudioRecorderEvents",value:function(){var e=this;this.audioRecorder.on("recordingStarted",function(){e.isRecording=!0;var t=e.audioPlayer.getStatus(),n=t.scheduledBuffers&&t.scheduledBuffers>0||t.scheduledSourcesCount&&t.scheduledSourcesCount>0,o=e.isPlaying||t.isPlaying||n;console.log("🎤 VoiceSDK v2: Recording started - checking for barge-in..."),console.log(" VoiceSDK.isPlaying:",e.isPlaying),console.log(" AudioPlayer.isPlaying:",t.isPlaying),console.log(" scheduledBuffers:",t.scheduledBuffers||0),console.log(" scheduledSourcesCount:",t.scheduledSourcesCount||0),console.log(" preparedBufferLength:",t.preparedBufferLength||0),console.log(" isActuallyPlaying:",o),o?(console.log("🛑 VoiceSDK v2: Barge-in detected! Stopping audio playback..."),e.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),e.isConnected?(e.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")):console.warn("⚠️ VoiceSDK v2: Cannot send barge_in - not connected")):console.log("ℹ️ VoiceSDK v2: No audio playing, normal recording start"),e.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){e.isRecording&&(e.isRecording=!1,e._bargeInChecked=!1,e.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped (from audioRecorder event)"))}),this.audioRecorder.on("audioData",function(t){if(!e._bargeInChecked&&e.isRecording){e._bargeInChecked=!0;var n=e.audioPlayer.getStatus(),o=n.scheduledBuffers&&n.scheduledBuffers>0||n.scheduledSourcesCount&&n.scheduledSourcesCount>0;(e.isPlaying||n.isPlaying||o)&&(console.log("🛑 VoiceSDK v2: Barge-in detected on first audio data! Stopping audio playback..."),console.log(" VoiceSDK.isPlaying:",e.isPlaying),console.log(" AudioPlayer.isPlaying:",n.isPlaying),console.log(" scheduledBuffers:",n.scheduledBuffers||0),console.log(" scheduledSourcesCount:",n.scheduledSourcesCount||0),e.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),e.isConnected&&(e.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")))}e.isConnected&&e.sendBinary(t)}),this.audioRecorder.on("error",function(t){console.error("❌ AudioRecorder error:",t),e.emit("error",t)})}},{key:"buildWebSocketUrl",value:function(){var e=this.config.websocketUrl,t=new URLSearchParams;if(this.config.agentId&&t.append("agentId",this.config.agentId),this.config.appId&&t.append("appId",this.config.appId),t.toString()){var n=e.includes("?")?"&":"?";return"".concat(e).concat(n).concat(t.toString())}return e}},{key:"connect",value:(l=Gt(Kt().m(function e(){var t,n,o=this;return Kt().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isDestroyed){e.n=1;break}return console.warn("VoiceSDK v2: Cannot connect - SDK is destroyed"),e.a(2,!1);case 1:if(!this.isConnected){e.n=2;break}return console.warn("VoiceSDK v2: Already connected"),e.a(2,!0);case 2:return e.p=2,t=this.buildWebSocketUrl(),console.log("🔌 VoiceSDK v2: Connecting to",t),e.n=3,new Promise(function(e,n){o.websocket=new WebSocket(t),o.websocket.onopen=function(){console.log("✅ VoiceSDK v2: WebSocket connected"),o.isConnected=!0,o.hasEverConnected=!0,o.sendHelloMessage(),o.emit("connected"),e(!0)},o.websocket.onerror=function(e){console.error("❌ VoiceSDK v2: WebSocket error:",e),n(e)},o.websocket.onclose=function(e){console.log("🔌 VoiceSDK v2: WebSocket closed:",e.code,e.reason),o.isConnected=!1,o.isRecording&&o.stopRecording().catch(function(e){return console.error("Error stopping recording:",e)}),o.emit("disconnected",e),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(e){o.handleMessage(e)}});case 3:return e.a(2,e.v);case 4:return e.p=4,n=e.v,console.error("🔌 VoiceSDK v2: Connection failed:",n),this.emit("error",n),e.a(2,!1)}},e,this,[[2,4]])})),function(){return l.apply(this,arguments)})},{key:"sendHelloMessage",value:function(){if(this.isConnected){var e={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},t={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},n=this.validateInputFormat(e);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(t);if(o)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid output format:",o),void this.emit("error",new Error("Invalid output format: ".concat(o)));var r={t:"hello",v:this.config.protocolVersion,inputFormat:e,requestedOutputFormat:t,outputFrameDurationMs:this.config.outputFrameDurationMs};this.config.agentSettingsOverride&&(r.agentSettingsOverride=this.config.agentSettingsOverride),console.log("🔍 VoiceSDK v2: Checking variables:",{hasVariables:!!this.config.variables,variables:this.config.variables,keys:this.config.variables?Object.keys(this.config.variables):[]}),this.config.variables&&Object.keys(this.config.variables).length>0?(r.variables=this.config.variables,console.log("📝 VoiceSDK v2: Including variables in hello:",Object.keys(this.config.variables))):console.log("⚠️ VoiceSDK v2: Variables NOT included - condition failed"),console.log("📤 VoiceSDK v2: Sending hello:",{version:r.v,requestedFormat:r.requestedOutputFormat,variables:r.variables?Object.keys(r.variables):void 0}),console.log("📤 VoiceSDK v2: Requested output format:",{container:r.requestedOutputFormat.container,encoding:r.requestedOutputFormat.encoding,sampleRate:r.requestedOutputFormat.sampleRate,bitDepth:r.requestedOutputFormat.bitDepth}),console.log("📤 VoiceSDK v2: Full hello message being sent:",JSON.stringify(r,null,2));try{this.sendMessage(r)}catch(e){console.error("VoiceSDK v2: Failed to send hello:",e),this.emit("error",e)}}else console.warn("VoiceSDK v2: Cannot send hello - not connected")}},{key:"handleMessage",value:function(e){if(e.data instanceof ArrayBuffer||e.data instanceof Blob)this.handleBinaryMessage(e.data);else try{var t=JSON.parse(e.data);switch("audio"!==t.t&&console.log("📥 VoiceSDK v2: Received message type:",t.t,"Full message:",JSON.stringify(t).substring(0,200)),!this.conversationId&&t.conversationId&&(this.conversationId=t.conversationId,console.log("🔍 VoiceSDK v2: Captured conversationId from message:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),"audio"!==t.t&&console.log("📨 VoiceSDK v2: Received message type:",t.t,t),t.t){case"hello_ack":this.handleHelloAck(t);break;case"transcript":console.log("📝 VoiceSDK v2: Processing transcript message:",t),this.handleTranscript(t);break;case"user_transcript":console.log("📝 VoiceSDK v2: Received user_transcript:",t),this.emit("message",t);break;case"agent_response":if(console.log("📝 VoiceSDK v2: Received agent_response:",t),(t.text||t.transcript)&&(console.log("📝 VoiceSDK v2: agent_response contains transcript data:",t.text||t.transcript),t.sentenceId&&(t.text||t.transcript))){var n={t:"transcript",sentenceId:t.sentenceId,text:t.text||t.transcript,role:t.role||"assistant",final:!1!==t.final,timestamp:t.timestamp||Date.now()};console.log("📝 VoiceSDK v2: Converting agent_response to transcript:",n),this.handleTranscript(n)}this.emit("message",t);break;case"error":this.emit("message",t);break;case"barge_in":this.emit("bargeIn",t),this.stopAudioPlayback();break;case"stop_playing":this.emit("stopPlaying",t),this.stopAudioPlayback();break;case"audio_start":console.log("📝 VoiceSDK v2: Received audio_start with text:",t.text),t.text&&this.audioPlayer&&this.audioPlayer.markNewSentence(t.text),this.emit("message",t);break;default:if(console.log("VoiceSDK v2: Unknown message type:",t.t,"Full message:",JSON.stringify(t).substring(0,300)),(t.text||t.transcript||t.transcription)&&(console.log("📝 VoiceSDK v2: Unknown message contains transcript-like data:",{text:t.text,transcript:t.transcript,transcription:t.transcription,sentenceId:t.sentenceId,role:t.role}),t.sentenceId&&(t.text||t.transcript||t.transcription))){var o={t:"transcript",sentenceId:t.sentenceId,text:t.text||t.transcript||t.transcription,role:t.role||"assistant",final:!1!==t.final,timestamp:t.timestamp||Date.now()};console.log("📝 VoiceSDK v2: Attempting to process unknown message as transcript:",o),this.handleTranscript(o)}this.emit("message",t)}}catch(e){console.error("VoiceSDK v2: Error parsing message:",e)}}},{key:"handleHelloAck",value:function(e){if(console.log("📥 VoiceSDK v2: Received hello_ack:",{hasOutputFormat:!!e.outputAudioFormat,outputFormat:e.outputAudioFormat,hasConversationId:!!e.conversationId,messageType:e.t}),e.conversationId&&(this.conversationId=e.conversationId,console.log("🔍 VoiceSDK v2: Received conversationId:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),e.outputAudioFormat){this.outputAudioFormat=e.outputAudioFormat,this.audioPlayer.setOutputFormat(e.outputAudioFormat),console.log("✅ VoiceSDK v2: Format negotiated by server:",this.outputAudioFormat),this.requestedOutputFormat={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1};var t={container:this.outputAudioFormat.container||"unknown",encoding:this.outputAudioFormat.encoding||"unknown",sampleRate:this.outputAudioFormat.sampleRate||0,bitDepth:this.outputAudioFormat.bitDepth||0,channels:this.outputAudioFormat.channels||0},n=[];if(this.requestedOutputFormat.container!==t.container&&n.push('container: "'.concat(this.requestedOutputFormat.container,'" → "').concat(t.container,'"')),this.requestedOutputFormat.encoding!==t.encoding&&n.push('encoding: "'.concat(this.requestedOutputFormat.encoding,'" → "').concat(t.encoding,'"')),this.requestedOutputFormat.sampleRate!==t.sampleRate&&n.push("sampleRate: ".concat(this.requestedOutputFormat.sampleRate,"Hz → ").concat(t.sampleRate,"Hz")),this.requestedOutputFormat.bitDepth!==t.bitDepth&&n.push("bitDepth: ".concat(this.requestedOutputFormat.bitDepth,"-bit → ").concat(t.bitDepth,"-bit")),this.requestedOutputFormat.channels!==t.channels&&n.push("channels: ".concat(this.requestedOutputFormat.channels," → ").concat(t.channels)),n.length>0){console.warn("⚠️ VoiceSDK v2: Format negotiation mismatch!"),console.warn(" Requested:",this.requestedOutputFormat),console.warn(" Negotiated:",t),console.warn(" Differences:",n.join(", "));try{if(this.formatConverter=new Nt(this.requestedOutputFormat,t),this.formatConverter.needsConversion()){var o=this.formatConverter.getConversionSteps();console.log("🔄 VoiceSDK v2: Format conversion enabled"),console.log(" Conversion steps:",o.join(", ")),console.log(" Audio will be automatically converted to requested format")}}catch(e){console.error("❌ VoiceSDK v2: Failed to create format converter:",e),console.warn(" Will use backend format without conversion"),this.formatConverter=null}}else console.log("✅ VoiceSDK v2: Format perfectly matched!",t),this.formatConverter=null;this.emit("formatNegotiated",this.outputAudioFormat)}else{this.config.protocolVersion>=2?(console.warn("⚠️ VoiceSDK v2: hello_ack received but no outputAudioFormat in response."),console.warn(" This may happen if:"),console.warn(" 1. Backend is not sending outputAudioFormat (check backend logs)"),console.warn(" 2. Hello message missing v2 fields (v, inputFormat, requestedOutputFormat)"),console.warn(" 3. Backend validation failed (check backend error logs)"),console.warn(" Using default format from config...")):console.log("✅ VoiceSDK v2: Connected (v1 legacy mode)");var r={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,channels:this.config.outputChannels||1,bitDepth:this.config.outputBitDepth||16};this.outputAudioFormat=r,this.requestedOutputFormat=r,this.audioPlayer.setOutputFormat(r),this.formatConverter=null}}},{key:"handleTranscript",value:function(e){if(e.sentenceId&&e.text){var t=e.sentenceId,n={text:e.text,role:e.role||"assistant",sentenceId:t,final:!1!==e.final,timestamp:e.timestamp||Date.now()};this.transcriptQueue.push(n),console.log("📝 VoiceSDK v2: Received transcript for sentence",t,":",n.text),console.log(" Transcript queue length:",this.transcriptQueue.length),console.log(" Current playing sentence:",this.currentPlayingSentenceId),console.log("📝 VoiceSDK v2: Displaying transcript for completed sentence",t),this.emit("transcriptDisplay",n),this.currentPlayingSentenceId=t,this.emit("transcript",n)}else console.warn("⚠️ VoiceSDK v2: Invalid transcript message:",e)}},{key:"handleBinaryMessage",value:(s=Gt(Kt().m(function e(t){var n,o,r,i,a,c,s,l,u,d;return Kt().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!(t instanceof Blob)){e.n=2;break}return e.n=1,t.arrayBuffer();case 1:o=e.v,e.n=3;break;case 2:o=t;case 3:if(console.log("📥 VoiceSDK v2: Received audio:",o.byteLength,"bytes"),console.log(" Current outputFormat:",this.outputAudioFormat),console.log(" AudioPlayer outputFormat:",null===(n=this.audioPlayer)||void 0===n?void 0:n.outputFormat),console.log(" Format converter:",this.formatConverter?"active":"none"),r=o,!this.formatConverter||!this.formatConverter.needsConversion()){e.n=7;break}return e.p=4,e.n=5,this.formatConverter.convert(o);case 5:r=e.v,console.log("✅ VoiceSDK v2: Audio converted to requested format"),e.n=7;break;case 6:e.p=6,d=e.v,console.error("❌ VoiceSDK v2: Format conversion failed:",d),console.warn(" Using backend format without conversion"),r=o;case 7:i=this.formatConverter&&this.formatConverter.needsConversion()?this.requestedOutputFormat:this.outputAudioFormat||{container:this.config.outputContainer||"raw",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1},a=i.container||"raw",c=(i.encoding||"pcm").toLowerCase(),"raw"===a?(s=r,"pcm"!==c&&((l=this.audioPlayer.getCodec(c))?(u=l.decode(new Uint8Array(r)),s=u.buffer,console.log("🔄 VoiceSDK v2: Decoded ".concat(c.toUpperCase()," to PCM (").concat(u.byteLength," bytes)"))):console.warn("⚠️ VoiceSDK v2: No codec for ".concat(c,", treating as PCM"))),this.audioPlayer.outputFormat||(console.warn("⚠️ VoiceSDK v2: outputFormat not set on AudioPlayer, setting from playbackFormat"),this.audioPlayer.setOutputFormat(i)),this.audioFrameCount++,this.audioPlayer.playChunk(s)):(this.audioFrameCount++,this.audioPlayer.playAudio(r));case 8:return e.a(2)}},e,this,[[4,6]])})),function(e){return s.apply(this,arguments)})},{key:"sendMessage",value:function(e){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(e)),!0}catch(e){return console.error("VoiceSDK v2: Error sending message:",e),this.emit("error",e),!1}}},{key:"sendBinary",value:function(e){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send audio - not connected"),!1;try{return this.websocket.send(e),!0}catch(e){return console.error("VoiceSDK v2: Error sending audio:",e),this.emit("error",e),!1}}},{key:"disconnect",value:function(){this.isDestroyed||(console.log("🔌 VoiceSDK v2: Disconnecting..."),this.stopRecording(),this.audioPlayer&&this.stopAudioPlayback(),this.websocket&&(this.websocket.close(),this.websocket=null),this.isConnected=!1)}},{key:"startRecording",value:(c=Gt(Kt().m(function e(){var t,n,o;return Kt().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isConnected){e.n=1;break}throw t=new Error("Not connected to voice server"),this.emit("error",t),t;case 1:if(!this.isRecording){e.n=2;break}return console.warn("VoiceSDK v2: Already recording"),e.a(2,!0);case 2:return console.log("🎤 VoiceSDK v2: Starting recording..."),e.p=3,console.log("🎤 VoiceSDK v2: Requesting microphone permission (mobile-friendly)..."),e.n=4,this.audioRecorder.start();case 4:return this.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId()}),e.a(2,!0);case 5:return e.p=5,o=e.v,console.error("❌ VoiceSDK v2: Failed to start recording:",o),"NotAllowedError"===o.name||"PermissionDeniedError"===o.name?((n=new Error("Microphone permission denied. Please allow microphone access in your browser settings and try again.")).name=o.name,n.originalError=o,this.emit("error",n)):this.emit("error",o),e.a(2,!1)}},e,this,[[3,5]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=Gt(Kt().m(function e(){var t;return Kt().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return console.warn("VoiceSDK v2: Not recording"),e.a(2,!0);case 1:return console.log("🛑 VoiceSDK v2: Stopping recording..."),e.p=2,this.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),this.isRecording=!1,this._bargeInChecked=!1,this.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped (emitted before audioRecorder.stop())"),e.n=3,this.audioRecorder.stop();case 3:return this.stopAudioPlayback(),e.a(2,!0);case 4:return e.p=4,t=e.v,console.error("VoiceSDK v2: Error stopping recording:",t),this.emit("error",t),e.a(2,!1)}},e,this,[[2,4]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=Gt(Kt().m(function e(){return Kt().w(function(e){for(;;)switch(e.n){case 0:if(!this.isRecording){e.n=2;break}return e.n=1,this.stopRecording();case 1:case 3:return e.a(2,e.v);case 2:return e.n=3,this.startRecording();case 4:return e.a(2)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"clearTranscriptState",value:function(){this.currentPlayingSentenceId=null,console.log("📝 VoiceSDK v2: Cleared transcript state")}},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate(),this.clearTranscriptState()}},{key:"handleBargeIn",value:(r=Gt(Kt().m(function e(){return Kt().w(function(e){for(;;)switch(e.n){case 0:if(this.stopAudioPlayback(),this.isRecording){e.n=1;break}return e.n=1,this.startRecording();case 1:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{version:this.version,isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying,outputFormat:this.outputAudioFormat,conversationId:this.conversationId,audioPlayer:this.audioPlayer.getStatus(),audioRecorder:this.audioRecorder.getStatus()}}},{key:"updateConfig",value:function(e){this.config=Vt(Vt({},this.config),e)}},{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&&qt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,l}(Se);Jt(Zt,"SUPPORTED_INPUT_ENCODINGS",["pcm","pcmu","pcma"]),Jt(Zt,"SUPPORTED_INPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),Jt(Zt,"SUPPORTED_INPUT_BIT_DEPTHS",[8,16,24]),Jt(Zt,"SUPPORTED_INPUT_CHANNELS",[1]),Jt(Zt,"SUPPORTED_OUTPUT_ENCODINGS",["pcm","pcmu","pcma"]),Jt(Zt,"SUPPORTED_OUTPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),Jt(Zt,"SUPPORTED_OUTPUT_BIT_DEPTHS",[8,16,24]),Jt(Zt,"SUPPORTED_OUTPUT_CHANNELS",[1]),Jt(Zt,"SUPPORTED_OUTPUT_CONTAINERS",["raw","wav"]);const en=Zt;function tn(e){return tn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},tn(e)}function nn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return on(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(on(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,on(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,on(d,"constructor",l),on(l,"constructor",s),s.displayName="GeneratorFunction",on(l,r,"GeneratorFunction"),on(d),on(d,r,"Generator"),on(d,o,function(){return this}),on(d,"toString",function(){return"[object Generator]"}),(nn=function(){return{w:i,m:p}})()}function on(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}on=function(e,t,n,o){function i(t,n){on(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},on(e,t,n,o)}function rn(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function an(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function cn(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?an(Object(n),!0).forEach(function(t){sn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):an(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function sn(e,t,n){return(t=un(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ln(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,un(o.key),o)}}function un(e){var t=function(e){if("object"!=tn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=tn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==tn(t)?t:t+""}function dn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(dn=function(){return!!e})()}function pn(e){return pn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},pn(e)}function fn(e,t){return fn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},fn(e,t)}var hn=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=(e=function(e,t,n){return t=pn(t),function(e,t){if(t&&("object"==tn(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,dn()?Reflect.construct(t,n||[],pn(e).constructor):t.apply(e,n))}(this,t)).readScriptTagConfig();return e.config=cn({baseWsUrl:"wss://backend.talktopc.com/chat/websocket",appId:n.appId||o.appId,agentId:n.agentId||o.agentId,conversationId:void 0!==n.conversationId?n.conversationId:e.getPersistedConversationId(),forceConversationId:n.forceConversationId,queue:[],inFlight:!1},n),e.fullResponseBuffer="",e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&fn(e,t)}(t,e),n=t,o=[{key:"readScriptTagConfig",value:function(){try{var e=Array.from(document.getElementsByTagName("script")).reverse().find(function(e){return e.dataset&&(e.dataset.appId||e.dataset.agentId)||e.src&&e.src.includes("agent-widget")});return e?{appId:e.dataset.appId,agentId:e.dataset.agentId}:{}}catch(e){return{}}}},{key:"buildWebSocketUrl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,t=new URLSearchParams;return this.config.appId&&t.append("appId",this.config.appId),this.config.agentId&&t.append("agentId",this.config.agentId),this.config.conversationId&&t.append("conversationId",this.config.conversationId),"".concat(e,"?").concat(t.toString())}},{key:"sendMessage",value:(r=nn().m(function e(t){var n=this;return nn().w(function(e){for(;;)if(0===e.n)return e.a(2,new Promise(function(e,o){if(t&&t.trim())if(n.config.appId&&n.config.agentId){var r={text:t,resolve:e,reject:o};n.config.inFlight?n.config.queue.push(r):n.executeTask(r)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},e)}),i=function(){var e=this,t=arguments;return new Promise(function(n,o){var i=r.apply(e,t);function a(e){rn(i,n,o,a,c,"next",e)}function c(e){rn(i,n,o,a,c,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})},{key:"executeTask",value:function(e){var t=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,r=this.buildWebSocketUrl(this.config.baseWsUrl),i=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(i),c=!1,s=!1,l=null,u=function(n){if(!s)try{var o={message:e.text},r=t.config.forceConversationId||t.config.conversationId;r&&(o.conversationId=r,t.config.forceConversationId&&!t.config.conversationId&&(t.config.conversationId=r,t.persistConversationId(r))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",t.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){e.reject(o),t.emit("error",o);try{n.close()}catch(e){}}},d=function(e){return function(){t.config.conversationId?u(e):l=setTimeout(function(){return u(e)},200)}},p=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(e){}var r=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",r)}catch(e){}if("hello"===r.type&&r.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",r.conversationId),t.config.conversationId=r.conversationId,t.persistConversationId(r.conversationId),t.emit&&t.emit("conversationIdChanged",r.conversationId),!s&&n&&1===n.readyState){if(l)try{clearTimeout(l)}catch(e){}u(n)}return}if(!t.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",r.conversationId),t.config.conversationId=r.conversationId,t.persistConversationId(r.conversationId)),"chunk"===r.type&&"string"==typeof r.content)t.fullResponseBuffer+=r.content,t.emit("chunk",r.content);else if("done"===r.type){try{var i=r.text||r.content||r.answer||r.message||"";i&&!t.fullResponseBuffer&&(t.fullResponseBuffer=i)}catch(e){}!t.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",r.conversationId),t.config.conversationId=r.conversationId),t.persistConversationId(t.config.conversationId),t.emit("done",{text:t.fullResponseBuffer}),e.resolve({conversationId:t.config.conversationId,fullText:t.fullResponseBuffer});try{n.close()}catch(e){}}else if("error"===r.type){var a=new Error(r.message||"Server error");t.emit("error",a),e.reject(a);try{n.close()}catch(e){}}}catch(e){}}},f=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,t.emit("domainError",o),e.reject(o),t.config.inFlight=!1,void t.drainQueue()}t.config.inFlight=!1,t.drainQueue()},h=new WebSocket(r);h.onopen=d(h),h.onmessage=p(h),h.onerror=(o=h,function(n){if(!c){c=!0;try{o.close()}catch(e){}var r=new WebSocket(a);return r.onopen=d(r),r.onmessage=p(r),r.onerror=function(n){t.emit("error",n),e.reject(n)},void(r.onclose=f)}t.emit("error",n),e.reject(n)}),h.onclose=f}},{key:"drainQueue",value:function(){if(0!==this.config.queue.length&&!this.config.inFlight){var e=this.config.queue.shift();this.executeTask(e)}}},{key:"persistConversationId",value:function(e){try{e&&localStorage.setItem("ttp_text_chat_conversation_id",e)}catch(e){}}},{key:"getPersistedConversationId",value:function(){try{return localStorage.getItem("ttp_text_chat_conversation_id")||null}catch(e){return null}}},{key:"updateConfig",value:function(e){this.config=cn(cn({},this.config),e)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&ln(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(l),gn=n(540),vn=n(848);function mn(e){return mn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},mn(e)}function yn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function bn(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?yn(Object(n),!0).forEach(function(t){wn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):yn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function wn(e,t,n){return(t=function(e){var t=function(e){if("object"!=mn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=mn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==mn(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Sn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return xn(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(xn(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,xn(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,xn(d,"constructor",l),xn(l,"constructor",s),s.displayName="GeneratorFunction",xn(l,r,"GeneratorFunction"),xn(d),xn(d,r,"Generator"),xn(d,o,function(){return this}),xn(d,"toString",function(){return"[object Generator]"}),(Sn=function(){return{w:i,m:p}})()}function xn(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}xn=function(e,t,n,o){function i(t,n){xn(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},xn(e,t,n,o)}function kn(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Cn(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,l=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==t);s=!0);}catch(e){l=!0,r=e}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw r}}return c}}(e,t)||function(e,t){if(e){if("string"==typeof e)return Pn(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Pn(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Pn(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}const En=function(e){var t=e.websocketUrl,n=e.agentId,o=e.appId,r=e.voice,i=void 0===r?"default":r,a=e.language,c=void 0===a?"en":a,s=e.autoReconnect,l=void 0===s||s,u=e.agentSettingsOverride,d=void 0===u?null:u,p=e.onConnected,f=e.onDisconnected,h=e.onRecordingStarted,g=e.onRecordingStopped,v=e.onPlaybackStarted,m=e.onPlaybackStopped,y=e.onError,b=e.onMessage,w=e.onBargeIn,S=e.onStopPlaying,x=e.onStartConversation,k=e.onEndConversation,C=e.className,P=void 0===C?"":C,E=e.style,O=void 0===E?{}:E,T=e.children,I=Cn((0,gn.useState)(!1),2),A=I[0],j=I[1],D=Cn((0,gn.useState)(!1),2),F=D[0],_=D[1],B=Cn((0,gn.useState)(!1),2),R=(B[0],B[1]),M=Cn((0,gn.useState)("Disconnected"),2),U=(M[0],M[1]),N=(0,gn.useRef)(null);(0,gn.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(t)),N.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),N.current.destroy(),N.current=null);var e=new ve({websocketUrl:t,agentId:n,appId:o,voice:i,language:c,autoReconnect:l,agentSettingsOverride:d,onStartConversation:x,onEndConversation:k});return e.on("connected",function(){j(!0),U("Connected"),null==p||p()}),e.on("disconnected",function(){j(!1),U("Disconnected"),null==f||f()}),e.on("recordingStarted",function(){_(!0),null==h||h()}),e.on("recordingStopped",function(){_(!1),null==g||g()}),e.on("playbackStarted",function(){R(!0),null==v||v()}),e.on("playbackStopped",function(){R(!1),null==m||m()}),e.on("error",function(e){null==y||y(e)}),e.on("message",function(e){null==b||b(e)}),e.on("bargeIn",function(e){null==w||w(e)}),e.on("stopPlaying",function(e){null==S||S(e)}),N.current=e,e.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(t)),N.current&&(N.current.destroy(),N.current=null)}},[t,n,o,i,c,d]);var L=function(){var e,t=(e=Sn().m(function e(){var t;return Sn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(N.current){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,N.current.toggleRecording();case 2:e.n=4;break;case 3:e.p=3,t=e.v,console.error("Error toggling recording:",t);case 4:return e.a(2)}},e,null,[[1,3]])}),function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){kn(i,o,r,a,c,"next",e)}function c(e){kn(i,o,r,a,c,"throw",e)}a(void 0)})});return function(){return t.apply(this,arguments)}}(),z=(0,vn.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,vn.jsx)("div",{style:{fontSize:"20px"},children:F?"🔴":"🎤"}),(0,vn.jsx)("div",{children:F?"Stop Listening":"Start Listening"})]});return(0,vn.jsx)("button",{className:"voice-button ".concat(F?"recording":""," ").concat(P),style:bn({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:F?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},O),onClick:L,disabled:!A,children:T||z})};function On(e){return On="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},On(e)}function Tn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return In(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(In(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,In(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,In(d,"constructor",l),In(l,"constructor",s),s.displayName="GeneratorFunction",In(l,r,"GeneratorFunction"),In(d),In(d,r,"Generator"),In(d,o,function(){return this}),In(d,"toString",function(){return"[object Generator]"}),(Tn=function(){return{w:i,m:p}})()}function In(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}In=function(e,t,n,o){function i(t,n){In(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},In(e,t,n,o)}function An(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function jn(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){An(i,o,r,a,c,"next",e)}function c(e){An(i,o,r,a,c,"throw",e)}a(void 0)})}}function Dn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function Fn(e,t,n){return(t=Bn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Bn(o.key),o)}}function Bn(e){var t=function(e){if("object"!=On(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=On(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==On(t)?t:t+""}var Rn=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Dn(Object(n),!0).forEach(function(t){Fn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Dn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({websocketUrl:t.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:t.agentId,voice:t.voice||"default",language:t.language||"en",container:t.container||document.body,buttonText:t.buttonText||"Start Listening",buttonClass:t.buttonClass||"voice-button"},t),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new ve({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},t=[{key:"setupEventListeners",value:function(){var e=this;this.voiceSDK.on("connected",function(){var t,n;e.isConnected=!0,e.updateButton(),null===(t=(n=e.options).onConnected)||void 0===t||t.call(n)}),this.voiceSDK.on("disconnected",function(){var t,n;e.isConnected=!1,e.updateButton(),null===(t=(n=e.options).onDisconnected)||void 0===t||t.call(n)}),this.voiceSDK.on("recordingStarted",function(){var t,n;e.isRecording=!0,e.updateButton(),null===(t=(n=e.options).onRecordingStarted)||void 0===t||t.call(n)}),this.voiceSDK.on("recordingStopped",function(){var t,n;e.isRecording=!1,e.updateButton(),null===(t=(n=e.options).onRecordingStopped)||void 0===t||t.call(n)}),this.voiceSDK.on("playbackStarted",function(){var t,n;e.isPlaying=!0,null===(t=(n=e.options).onPlaybackStarted)||void 0===t||t.call(n)}),this.voiceSDK.on("playbackStopped",function(){var t,n;e.isPlaying=!1,null===(t=(n=e.options).onPlaybackStopped)||void 0===t||t.call(n)}),this.voiceSDK.on("error",function(t){var n,o;null===(n=(o=e.options).onError)||void 0===n||n.call(o,t)}),this.voiceSDK.on("message",function(t){var n,o;null===(n=(o=e.options).onMessage)||void 0===n||n.call(o,t)}),this.voiceSDK.on("bargeIn",function(t){var n,o;null===(n=(o=e.options).onBargeIn)||void 0===n||n.call(o,t)}),this.voiceSDK.on("stopPlaying",function(t){var n,o;null===(n=(o=e.options).onStopPlaying)||void 0===n||n.call(o,t)})}},{key:"createButton",value:function(){var e=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return e.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var e=this.isRecording?"🔴":"🎤",t=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(e,"</span>\n <span>").concat(t,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=jn(Tn().m(function e(){var t;return Tn().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,this.voiceSDK.connect();case 1:e.n=3;break;case 2:e.p=2,t=e.v,console.error("Failed to connect:",t);case 3:return e.a(2)}},e,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=jn(Tn().m(function e(){var t;return Tn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.voiceSDK){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,this.voiceSDK.toggleRecording();case 2:e.n=4;break;case 3:e.p=3,t=e.v,console.error("Error toggling recording:",t);case 4:return e.a(2)}},e,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(e){this.voiceSDK.updateConfig(e)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],t&&_n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Mn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Un(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Un(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Un(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Un(d,"constructor",l),Un(l,"constructor",s),s.displayName="GeneratorFunction",Un(l,r,"GeneratorFunction"),Un(d),Un(d,r,"Generator"),Un(d,o,function(){return this}),Un(d,"toString",function(){return"[object Generator]"}),(Mn=function(){return{w:i,m:p}})()}function Un(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Un=function(e,t,n,o){function i(t,n){Un(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Un(e,t,n,o)}function Nn(e){return Nn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Nn(e)}function Ln(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function zn(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Ln(i,o,r,a,c,"next",e)}function c(e){Ln(i,o,r,a,c,"throw",e)}a(void 0)})}}function Vn(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Kn(o.key),o)}}function Kn(e){var t=function(e){if("object"!=Nn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Nn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Nn(t)?t:t+""}var Hn=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),console.log("🚀 AgentSDK v2.1.8 initialized with config:",t),this.config=t,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.wasListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(e){return console.error("SDK Error:",e)},this.onTranscript=function(e){},this.onAgentSpeaking=function(e){},this.onConversationStart=t.onConversationStart||function(){},this.onConversationEnd=t.onConversationEnd||function(){},this.onBargeIn=t.onBargeIn||function(){},this.onAudioStartPlaying=t.onAudioStartPlaying||function(){},this.onAudioStoppedPlaying=t.onAudioStoppedPlaying||function(){},this.onSubtitleDisplay=t.onSubtitleDisplay||function(){}},t=[{key:"connect",value:(o=zn(Mn().m(function e(t){var n,o=this;return Mn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,t){e.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new en({websocketUrl:t,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en",protocolVersion:2,outputContainer:this.config.outputContainer||"raw",outputEncoding:this.config.outputEncoding||"pcm",outputSampleRate:this.config.outputSampleRate||44100,outputChannels:this.config.outputChannels||1,outputBitDepth:this.config.outputBitDepth||16}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(e){if(o.isConnected=!1,e&&1008===e.code&&e.reason&&(e.reason.includes("Domain not whitelisted")||e.reason.includes("domain")||e.reason.includes("whitelist"))){var t=new Error("DOMAIN_NOT_WHITELISTED");t.reason=e.reason,t.code=e.code,o.onError(t)}if((o.isListening||o.wasListening)&&(console.log("🎤 [AGENT SDK] disconnected event - calling onConversationEnd hook (isListening:",o.isListening,", wasListening:",o.wasListening,")"),o.onConversationEnd&&"function"==typeof o.onConversationEnd))try{o.onConversationEnd(),console.log("🎤 [AGENT SDK] ✅ onConversationEnd hook called from disconnected event"),o.wasListening=!1}catch(e){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationEnd from disconnected:",e)}o.onDisconnected()}),this.voiceSDK.on("domainError",function(e){o.onError(e)}),this.voiceSDK.on("error",function(e){o.onError(e)}),this.voiceSDK.on("message",function(e){o.handleWebSocketMessage(e)}),this.voiceSDK.on("recordingStarted",function(){if(o.isListening=!0,o.wasListening=!0,o.onConversationStart&&"function"==typeof o.onConversationStart)try{o.onConversationStart()}catch(e){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationStart:",e)}}),this.voiceSDK.on("recordingStopped",function(){console.log("🎤 [AGENT SDK] recordingStopped event received");var e=o.isListening;if(o.isListening=!1,e&&o.onConversationEnd&&"function"==typeof o.onConversationEnd)try{console.log("🎤 [AGENT SDK] ✅ Calling onConversationEnd hook from recordingStopped"),o.onConversationEnd(),console.log("🎤 [AGENT SDK] ✅ onConversationEnd hook called successfully"),o.wasListening=!1}catch(e){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationEnd:",e)}}),this.voiceSDK.on("playbackStarted",function(){o.onAgentSpeaking(!0),o.onAudioStartPlaying()}),this.voiceSDK.on("playbackStopped",function(){o.onAgentSpeaking(!1),o.onAudioStoppedPlaying()}),this.voiceSDK.on("bargeIn",function(e){o.onBargeIn(e)}),this.voiceSDK.on("transcriptDisplay",function(e){console.log("📝 [AGENT SDK] transcriptDisplay event received:",e),e&&e.text&&(console.log("📝 [AGENT SDK] Calling onTranscript with text:",e.text),o.onTranscript&&"function"==typeof o.onTranscript?o.onTranscript(e.text):console.warn("📝 [AGENT SDK] ⚠️ onTranscript is not a function!",Nn(o.onTranscript))),o.onSubtitleDisplay(e)}),e.n=2,this.voiceSDK.connect();case 2:e.n=4;break;case 3:throw e.p=3,n=e.v,this.onError(n),n;case 4:return e.a(2)}},e,this,[[0,3]])})),function(e){return o.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(e){switch(e.t||e.type){case"connected":case"hello_ack":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(e.user_transcription||e.text||e.transcript);break;case"agent_response":case"barge_in":case"stop_playing":default:break;case"error":this.onError(new Error(e.message||e.error||"Unknown error"))}}},{key:"startListening",value:(n=zn(Mn().m(function e(){var t;return Mn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){e.n=5;break}return e.p=1,console.log("🎤 AgentSDK: Starting recording..."),e.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),e.n=4;break;case 3:throw e.p=3,t=e.v,console.error("❌ AgentSDK: Failed to start recording:",t),t;case 4:e.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return e.a(2)}},e,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(e){this.voiceSDK&&this.isConnected&&this.voiceSDK.sendMessage({t:"update_variables",variables:e})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],t&&Vn(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Wn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Gn(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Gn(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Gn(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Gn(d,"constructor",l),Gn(l,"constructor",s),s.displayName="GeneratorFunction",Gn(l,r,"GeneratorFunction"),Gn(d),Gn(d,r,"Generator"),Gn(d,o,function(){return this}),Gn(d,"toString",function(){return"[object Generator]"}),(Wn=function(){return{w:i,m:p}})()}function Gn(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Gn=function(e,t,n,o){function i(t,n){Gn(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Gn(e,t,n,o)}function qn(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Qn(){var e=navigator.userAgent,t=/iPad|iPhone|iPod/.test(e)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,n=/Android/.test(e),o=/Mac/.test(e)&&!t,r=/Win/.test(e),i=/Chrome/.test(e)&&!/Edg|OPR/.test(e),a=/Safari/.test(e)&&!/Chrome/.test(e),c=/Firefox/.test(e),s=/Edg/.test(e),l=/SamsungBrowser/.test(e),u="unknown";t?u="safari":l?u="samsung":i?u="chrome":a?u="safari":c?u="firefox":s&&(u="edge");var d="unknown";return t?d="ios":n?d="android":o?d="mac":r&&(d="windows"),{platform:d,browser:u,isIOS:t,isAndroid:n,isMac:o,isWindows:r,isMobile:t||n,isDesktop:!t&&!n}}function Yn(){return $n.apply(this,arguments)}function $n(){var e;return e=Wn().m(function e(){var t;return Wn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!navigator.permissions||!navigator.permissions.query){e.n=2;break}return e.n=1,navigator.permissions.query({name:"microphone"});case 1:return t=e.v,e.a(2,t.state);case 2:e.n=4;break;case 3:e.p=3,e.v,console.log("⚠️ MicPermissionUtils: Permissions API not available or not supported for microphone");case 4:return e.a(2,"unknown")}},e,null,[[0,3]])}),$n=function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){qn(i,o,r,a,c,"next",e)}function c(e){qn(i,o,r,a,c,"throw",e)}a(void 0)})},$n.apply(this,arguments)}function Jn(e){var t=e.platform,n=e.browser,o={ios:{title:"Enable Microphone on iPhone/iPad",icon:"📱",steps:["Open the <strong>Settings</strong> app on your device","Scroll down and tap <strong>Safari</strong> (or your browser app)",'Tap <strong>Microphone</strong> under "Settings for Websites"',"Set it to <strong>Allow</strong> or <strong>Ask</strong>","Return to this page and refresh"],note:"On iOS, all browsers use Safari's permission system. You need to change this in your device Settings.",canOpenSettings:!0,settingsButtonText:"Open Settings App"},android_chrome:{title:"Enable Microphone in Chrome",icon:"🤖",steps:["Tap the <strong>lock icon 🔒</strong> in the address bar","Tap <strong>Permissions</strong>","Tap <strong>Microphone</strong>","Select <strong>Allow</strong>","The page will refresh automatically"],altTitle:"Alternative Method",altSteps:["Tap the <strong>⋮ menu</strong> (three dots)","Tap <strong>Settings → Site settings → Microphone</strong>","Find this website and set to <strong>Allow</strong>"],canOpenSettings:!0,settingsButtonText:"Open App Settings"},android_firefox:{title:"Enable Microphone in Firefox",icon:"🦊",steps:["Tap the <strong>lock icon 🔒</strong> in the address bar","Tap <strong>Edit Site Permissions</strong>","Toggle <strong>Microphone</strong> to enabled","Refresh the page"],canOpenSettings:!1},android_samsung:{title:"Enable Microphone in Samsung Browser",icon:"📱",steps:["Tap the <strong>menu icon</strong> (three lines)","Tap <strong>Settings → Sites and downloads</strong>","Tap <strong>Site permissions → Microphone</strong>","Find this website and set to <strong>Allow</strong>","Return and refresh the page"],canOpenSettings:!1},desktop_chrome:{title:"Enable Microphone in Chrome",icon:"🌐",steps:["Click the <strong>lock icon 🔒</strong> or <strong>information icon ℹ️</strong> in the address bar (left side)","Find <strong>Microphone</strong> in the dropdown menu",'Change it from "Block" to <strong>Allow</strong>',"Click the <strong>Refresh</strong> button or press F5"],showAddressBarHint:!0,canOpenSettings:!1},desktop_safari:{title:"Enable Microphone in Safari",icon:"🧭",steps:["Click <strong>Safari</strong> in the menu bar (top of screen)","Click <strong>Settings for This Website...</strong>","Find <strong>Microphone</strong> in the popup","Change it to <strong>Allow</strong>","Close settings and refresh the page"],canOpenSettings:!1},desktop_firefox:{title:"Enable Microphone in Firefox",icon:"🦊",steps:["Click the <strong>lock icon 🔒</strong> in the address bar",'Click the <strong>X</strong> next to "Blocked" for Microphone',"Refresh the page (press F5)","Click <strong>Allow</strong> when prompted again"],note:"Firefox requires you to clear the block and then re-allow on the next prompt.",showAddressBarHint:!0,canOpenSettings:!1},desktop_edge:{title:"Enable Microphone in Edge",icon:"🌐",steps:["Click the <strong>lock icon 🔒</strong> in the address bar","Find <strong>Microphone</strong> in the permissions list","Change it to <strong>Allow</strong>","Refresh the page"],showAddressBarHint:!0,canOpenSettings:!1},unknown:{title:"Enable Microphone Access",icon:"🎤",steps:["Look for a <strong>lock icon 🔒</strong>, <strong>information icon ℹ️</strong>, or <strong>settings icon</strong> in your browser's address bar","Find the <strong>Microphone</strong> permission setting","Change it to <strong>Allow</strong>","Refresh this page"],canOpenSettings:!1}};return"ios"===t?o.ios:"android"===t?o["android_".concat(n)]||o.android_chrome:o["desktop_".concat(n)]||o.desktop_chrome}function Xn(e){var t=e.isIOS,n=e.isAndroid,o=e.browser;if(t)try{return window.location.href="app-settings:",!0}catch(e){return console.warn("Could not open iOS settings:",e),!1}if(n&&"chrome"===o)try{return window.location.href="intent:#Intent;action=android.settings.APPLICATION_DETAILS_SETTINGS;data=package:com.android.chrome;end",!0}catch(e){return console.warn("Could not open Android settings:",e),!1}return!1}function Zn(e){return Zn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Zn(e)}function eo(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,to(o.key),o)}}function to(e){var t=function(e){if("object"!=Zn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Zn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Zn(t)?t:t+""}function no(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return oo(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?oo(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function oo(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}var ro=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.overlay=null,this.modal=null},(t=[{key:"createOverlay",value:function(){var e=document.createElement("div");return e.className="mic-permission-overlay",e.style.cssText="\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.6);\n backdrop-filter: blur(4px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10000;\n padding: 20px;\n animation: mic-fadeIn 0.2s ease-out;\n ",document.getElementById("mic-permission-styles")||this.injectStyles(),e}},{key:"injectStyles",value:function(){if(!document.getElementById("mic-permission-styles")){var e=document.createElement("style");e.id="mic-permission-styles",e.textContent="\n @keyframes mic-fadeIn {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n \n @keyframes mic-slideUp {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n \n @keyframes mic-bounce {\n 0%, 100% { transform: translateY(0); }\n 50% { transform: translateY(-5px); }\n }\n \n .mic-permission-overlay {\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.6);\n backdrop-filter: blur(4px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10000;\n padding: 20px;\n animation: mic-fadeIn 0.2s ease-out;\n }\n \n .mic-permission-modal {\n background: #ffffff;\n border-radius: 16px;\n box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);\n max-width: 480px;\n width: 100%;\n padding: 32px;\n position: relative;\n animation: mic-slideUp 0.3s ease-out;\n max-height: 90vh;\n overflow-y: auto;\n }\n \n .mic-permission-modal__close {\n position: absolute;\n top: 16px;\n right: 16px;\n background: none;\n border: none;\n font-size: 20px;\n cursor: pointer;\n color: #6b7280;\n width: 32px;\n height: 32px;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n }\n \n .mic-permission-modal__close:hover {\n background: #e5e7eb;\n }\n \n .mic-permission-modal__icon {\n font-size: 48px;\n text-align: center;\n margin-bottom: 16px;\n }\n \n .mic-permission-modal__title {\n font-size: 24px;\n font-weight: 700;\n color: #111827;\n margin: 0 0 12px;\n line-height: 1.3;\n text-align: center;\n }\n \n .mic-permission-modal__description {\n color: #6b7280;\n font-size: 16px;\n line-height: 1.6;\n margin: 0 0 20px;\n text-align: center;\n }\n \n .mic-permission-modal__highlight {\n display: flex;\n align-items: center;\n gap: 12px;\n background: linear-gradient(135deg, #dbeafe, #ede9fe);\n padding: 16px 20px;\n border-radius: 8px;\n margin-bottom: 20px;\n border: 1px solid #bfdbfe;\n }\n \n .mic-permission-modal__highlight-icon {\n font-size: 24px;\n animation: mic-bounce 1s infinite;\n }\n \n .mic-permission-modal__status {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n background: #fef2f2;\n color: #ef4444;\n padding: 12px 16px;\n border-radius: 8px;\n margin-bottom: 20px;\n font-weight: 500;\n }\n \n .mic-permission-modal__note {\n display: flex;\n align-items: flex-start;\n gap: 10px;\n background: #fffbeb;\n color: #92400e;\n padding: 12px 16px;\n border-radius: 8px;\n margin-bottom: 20px;\n font-size: 14px;\n line-height: 1.5;\n border: 1px solid #fde68a;\n }\n \n .mic-permission-modal__steps {\n margin-bottom: 20px;\n }\n \n .mic-permission-modal__steps h3 {\n font-size: 14px;\n font-weight: 600;\n color: #6b7280;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n margin: 0 0 12px;\n }\n \n .mic-permission-modal__steps ol {\n margin: 0;\n padding-left: 24px;\n counter-reset: step-counter;\n list-style: none;\n }\n \n .mic-permission-modal__steps li {\n position: relative;\n padding: 12px 0 12px 16px;\n border-left: 2px solid #e5e7eb;\n color: #111827;\n font-size: 15px;\n line-height: 1.5;\n counter-increment: step-counter;\n }\n \n .mic-permission-modal__steps li::before {\n content: counter(step-counter);\n position: absolute;\n left: -14px;\n top: 10px;\n width: 24px;\n height: 24px;\n background: #4f46e5;\n color: white;\n border-radius: 50%;\n font-size: 12px;\n font-weight: 600;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n \n .mic-permission-modal__steps li:last-child {\n border-left-color: transparent;\n }\n \n .mic-permission-modal__actions {\n display: flex;\n flex-direction: column;\n gap: 10px;\n margin-top: 24px;\n }\n \n .mic-permission-modal__btn {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n padding: 14px 24px;\n border-radius: 8px;\n font-size: 16px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s;\n border: none;\n width: 100%;\n }\n \n .mic-permission-modal__btn--primary {\n background: #4f46e5;\n color: white;\n }\n \n .mic-permission-modal__btn--primary:hover {\n background: #4338ca;\n transform: translateY(-1px);\n }\n \n .mic-permission-modal__btn--secondary {\n background: #e5e7eb;\n color: #111827;\n }\n \n .mic-permission-modal__btn--secondary:hover {\n background: #d1d5db;\n }\n \n .mic-permission-modal__footer {\n text-align: center;\n font-size: 13px;\n color: #6b7280;\n margin-top: 20px;\n margin-bottom: 0;\n }\n \n .mic-permission-modal__visual-guide {\n width: 100%;\n max-width: 380px;\n height: auto;\n margin: 20px auto;\n border-radius: 8px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);\n display: block;\n }\n \n .mic-permission-modal__visual-guide-container {\n text-align: center;\n margin: 20px 0;\n }\n \n @media (max-width: 480px) {\n .mic-permission-modal {\n padding: 24px 20px;\n margin: 10px;\n max-height: 85vh;\n }\n \n .mic-permission-modal__title {\n font-size: 20px;\n }\n \n .mic-permission-modal__icon {\n font-size: 40px;\n }\n \n .mic-permission-modal__visual-guide {\n max-width: 100%;\n }\n }\n ",document.head.appendChild(e)}}},{key:"close",value:function(){this.overlay&&this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=null,this.modal=null}},{key:"show",value:function(){this.overlay&&this.modal&&document.body.appendChild(this.overlay)}}])&&eo(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function io(e,t){var n=new ro,o=n.createOverlay(),r=Qn(),i=document.createElement("div");return i.className="mic-permission-modal",i.innerHTML='\n <div class="mic-permission-modal__icon">🎤</div>\n <h2 class="mic-permission-modal__title">Enable Your Microphone</h2>\n <p class="mic-permission-modal__description">\n To start a voice call with our agent, we need access to your microphone.\n </p>\n <div class="mic-permission-modal__highlight">\n <span class="mic-permission-modal__highlight-icon">👆</span>\n <span>Please click <strong>"Allow"</strong> on the next popup</span>\n </div>\n '.concat(r.isIOS?'\n <div class="mic-permission-modal__note">\n <span>ℹ️</span>\n <span>On iPhone/iPad, you may need to allow microphone access in your device Settings.</span>\n </div>\n ':"",'\n <div class="mic-permission-modal__actions">\n <button class="mic-permission-modal__btn mic-permission-modal__btn--primary" data-action="accept">\n Continue\n </button>\n <button class="mic-permission-modal__btn mic-permission-modal__btn--secondary" data-action="cancel">\n Not Now\n </button>\n </div>\n '),o.appendChild(i),n.overlay=o,n.modal=i,i.querySelector('[data-action="accept"]').addEventListener("click",function(){n.close(),e()}),i.querySelector('[data-action="cancel"]').addEventListener("click",function(){n.close(),t()}),o.addEventListener("click",function(e){e.target===o&&(n.close(),t())}),n.show(),n}function ao(e,t){var n,o,r,i=new ro,a=i.createOverlay(),c=Qn(),s=Jn(c),l=document.createElement("div");l.className="mic-permission-modal";var u="";s.altSteps&&s.altSteps.length>0&&(u='\n <div style="margin-top: 20px; border-top: 1px solid #e5e7eb; padding-top: 16px;">\n <button class="mic-permission-modal__alt-toggle" style="background: none; border: none; color: #4f46e5; font-size: 14px; font-weight: 500; cursor: pointer; padding: 0; margin-bottom: 12px;">\n ▼ '.concat(s.altTitle||"Alternative method",'\n </button>\n <ol style="margin: 0; padding-left: 20px; display: none;">\n ').concat(s.altSteps.map(function(e){return'<li style="padding: 8px 0; font-size: 14px; color: #6b7280;">'.concat(e,"</li>")}).join(""),"\n </ol>\n </div>\n "));var d=function(e){var t,n=e.platform,o=e.browser,r=document.getElementsByTagName("script"),i="",a=no(r);try{for(a.s();!(t=a.n()).done;){var c=t.value.src;if(c&&(c.includes("agent-widget.js")||c.includes("ttp-agent-sdk")||c.includes("ttp-sdk-front")))try{new URL(c),i=c.substring(0,c.lastIndexOf("/"));break}catch(e){var s=c.match(/^(.*\/)[^\/]+$/);if(s){i=s[1];break}}}}catch(e){a.e(e)}finally{a.f()}var l;if(l="ios"===n?"ios-settings.svg":"android"===n?"android-chrome.svg":"chrome"===o?"desktop-chrome.svg":"safari"===o?"desktop-safari.svg":"firefox"===o?"desktop-firefox.svg":"edge"===o?"desktop-edge.svg":"desktop-chrome.svg",!i||""===i||i.startsWith("/")){var u,d=no(r);try{for(d.s();!(u=d.n()).done;){var p=u.value.src;if(p&&(p.includes("cdn.talktopc.com")||p.includes("talktopc.com"))){if(p.includes("/ttp-agent-sdk/")||p.includes("/ttp-sdk-front/")){var f=p.match(/(https?:\/\/[^\/]+(?:\/[^\/]+)*)/);if(f){i=f[1].replace(/\/[^\/]+\.js$/,"");break}}if(!i&&(p.includes("cdn.talktopc.com")||p.includes("talktopc.com"))){i="https://cdn.talktopc.com/ttp-agent-sdk";break}}}}catch(e){d.e(e)}finally{d.f()}if(!i||""===i)if(window.location.hostname.includes("cdn.talktopc.com")||window.location.hostname.includes("talktopc.com"))i="https://cdn.talktopc.com/ttp-agent-sdk";else{var h=window.location.pathname.split("/");h.pop(),(i=window.location.origin+h.join("/"))&&i!==window.location.origin||(i=window.location.origin)}}i=i.replace(/\/$/,"");var g="".concat(i,"/shared/mic-permission-assets/").concat(l);return"undefined"!=typeof console&&console.log&&console.log("[MicPermission] Visual guide path:",g,"Base path:",i,"Platform:",n,"Browser:",o),g}(c);l.innerHTML='\n <button class="mic-permission-modal__close" data-action="close">✕</button>\n <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 20px;">\n <span style="font-size: 32px;">'.concat(s.icon,'</span>\n <h2 class="mic-permission-modal__title" style="text-align: left; margin: 0;">').concat(s.title,'</h2>\n </div>\n <div class="mic-permission-modal__status">\n <span>🚫</span>\n <span>Microphone access is currently blocked</span>\n </div>\n ').concat(s.note?'\n <div class="mic-permission-modal__note">\n <span>ℹ️</span>\n <span>'.concat(s.note,"</span>\n </div>\n "):"",'\n <div class="mic-permission-modal__visual-guide-container">\n <img src="').concat(d,'" alt="Visual guide for enabling microphone" class="mic-permission-modal__visual-guide" \n onerror="console.error(\'[MicPermission] Failed to load image:\', this.src); this.style.display=\'none\';" \n onload="console.log(\'[MicPermission] Image loaded successfully:\', this.src);" />\n </div>\n <div class="mic-permission-modal__steps">\n <h3>Follow these steps:</h3>\n <ol>\n ').concat(s.steps.map(function(e){return"<li>".concat(e,"</li>")}).join(""),"\n </ol>\n </div>\n ").concat(u,'\n <div class="mic-permission-modal__actions">\n ').concat(s.canOpenSettings?'\n <button class="mic-permission-modal__btn mic-permission-modal__btn--primary" data-action="open-settings">\n '.concat(s.settingsButtonText||"Open Settings","\n </button>\n "):"","\n ").concat(s.showAddressBarHint?'\n <button class="mic-permission-modal__btn mic-permission-modal__btn--primary" data-action="show-hint">\n Show Me Where\n </button>\n ':"",'\n <button class="mic-permission-modal__btn mic-permission-modal__btn--secondary" data-action="refresh">\n 🔄 Refresh Page\n </button>\n </div>\n <p class="mic-permission-modal__footer">\n After enabling microphone access, return here and click "Refresh Page"\n </p>\n '),a.appendChild(l),i.overlay=a,i.modal=l,null===(n=l.querySelector('[data-action="close"]'))||void 0===n||n.addEventListener("click",function(){i.close(),e()}),null===(o=l.querySelector('[data-action="open-settings"]'))||void 0===o||o.addEventListener("click",function(){Xn(c)}),null===(r=l.querySelector('[data-action="refresh"]'))||void 0===r||r.addEventListener("click",function(){window.location.reload()});var p=l.querySelector('[data-action="show-hint"]');p&&p.addEventListener("click",function(){i.close(),e(),function(){var e=document.getElementById("mic-address-bar-hint");e&&e.remove(),Qn();var t,n=document.getElementsByTagName("script"),o="",r=no(n);try{for(r.s();!(t=r.n()).done;){var i=t.value.src;if(i&&(i.includes("agent-widget.js")||i.includes("ttp-agent-sdk")||i.includes("ttp-sdk-front")))try{new URL(i),o=i.substring(0,i.lastIndexOf("/"));break}catch(e){var a=i.match(/^(.*\/)[^\/]+$/);if(a){o=a[1];break}}}}catch(e){r.e(e)}finally{r.f()}if(!o||""===o||o.startsWith("/")){var c,s=no(n);try{for(s.s();!(c=s.n()).done;){var l=c.value.src;if(l&&(l.includes("cdn.talktopc.com")||l.includes("talktopc.com"))){if(l.includes("/ttp-agent-sdk/")||l.includes("/ttp-sdk-front/")){var u=l.match(/(https?:\/\/[^\/]+(?:\/[^\/]+)*)/);if(u){o=u[1].replace(/\/[^\/]+\.js$/,"");break}}if(!o&&(l.includes("cdn.talktopc.com")||l.includes("talktopc.com"))){o="https://cdn.talktopc.com/ttp-agent-sdk";break}}}}catch(e){s.e(e)}finally{s.f()}if(!o||""===o)if(window.location.hostname.includes("cdn.talktopc.com")||window.location.hostname.includes("talktopc.com"))o="https://cdn.talktopc.com/ttp-agent-sdk";else{var d=window.location.pathname.split("/");d.pop(),(o=window.location.origin+d.join("/"))&&o!==window.location.origin||(o=window.location.origin)}}o=o.replace(/\/$/,"");var p="".concat(o,"/shared/mic-permission-assets/address-bar-hint.svg"),f=document.createElement("div");f.id="mic-address-bar-hint",f.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n z-index: 10001;\n padding: 10px 20px;\n pointer-events: none;\n animation: mic-fadeIn 0.3s ease-out;\n display: flex;\n justify-content: center;\n ";var h=document.createElement("div");h.style.cssText="\n display: flex;\n align-items: center;\n gap: 12px;\n background: #f59e0b;\n color: white;\n padding: 12px 20px;\n border-radius: 0 0 8px 8px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n pointer-events: all;\n animation: mic-slideDown 0.3s ease-out;\n max-width: 540px;\n ";var g=document.createElement("div");g.style.cssText="\n flex-shrink: 0;\n ";var v=document.createElement("img");v.src=p,v.alt="Address bar hint",v.style.cssText="\n width: auto;\n height: 80px;\n display: block;\n ",v.onerror=function(){g.style.display="none"},g.appendChild(v);var m=document.createElement("div");m.style.cssText="\n display: flex;\n flex-direction: column;\n gap: 4px;\n flex: 1;\n ";var y=document.createElement("div");y.style.cssText="\n font-size: 15px;\n font-weight: 500;\n ",y.innerHTML="Click the <strong>lock icon 🔒</strong> or <strong>information icon ℹ️</strong> in the address bar to enable microphone";var b=document.createElement("button");if(b.style.cssText="\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 28px;\n height: 28px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 14px;\n transition: background 0.2s;\n flex-shrink: 0;\n ",b.textContent="✕",b.addEventListener("click",function(){f.remove()}),b.addEventListener("mouseenter",function(){b.style.background="rgba(255, 255, 255, 0.3)"}),b.addEventListener("mouseleave",function(){b.style.background="rgba(255, 255, 255, 0.2)"}),!document.getElementById("mic-address-bar-hint-styles")){var w=document.createElement("style");w.id="mic-address-bar-hint-styles",w.textContent="\n @keyframes mic-slideDown {\n from {\n opacity: 0;\n transform: translateY(-100%);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n \n @keyframes mic-pointUp {\n 0%, 100% {\n transform: translate(0, 0);\n }\n 50% {\n transform: translate(-5px, -5px);\n }\n }\n ",document.head.appendChild(w)}m.appendChild(y),h.appendChild(g),h.appendChild(m),h.appendChild(b),f.appendChild(h),document.body.appendChild(f),setTimeout(function(){f.parentNode&&(f.style.opacity="0",f.style.transition="opacity 0.3s ease-out",setTimeout(function(){f.parentNode&&f.remove()},300))},1e4)}()});var f=l.querySelector(".mic-permission-modal__alt-toggle");if(f&&s.altSteps){var h=f.nextElementSibling;h&&(h.style.display="none",f.addEventListener("click",function(){"none"===h.style.display?(h.style.display="block",f.innerHTML="▼ ".concat(s.altTitle||"Alternative method")):(h.style.display="none",f.innerHTML="▶ ".concat(s.altTitle||"Alternative method"))}))}return a.addEventListener("click",function(t){t.target===a&&(i.close(),e())}),i.show(),i}function co(e){var t=new ro,n=t.createOverlay(),o=document.createElement("div");return o.className="mic-permission-modal",o.innerHTML='\n <div class="mic-permission-modal__icon">🎤❌</div>\n <h2 class="mic-permission-modal__title">No Microphone Found</h2>\n <p class="mic-permission-modal__description">\n We couldn\'t detect a microphone on your device. Please make sure:\n </p>\n <ul style="list-style: none; padding: 0; margin: 0 0 24px;">\n <li style="padding: 10px 0 10px 32px; position: relative; color: #111827; border-bottom: 1px solid #e5e7eb;">\n <span style="position: absolute; left: 0; font-size: 18px;">☐</span>\n Your microphone is properly connected\n </li>\n <li style="padding: 10px 0 10px 32px; position: relative; color: #111827; border-bottom: 1px solid #e5e7eb;">\n <span style="position: absolute; left: 0; font-size: 18px;">☐</span>\n Your microphone is not muted at the hardware level\n </li>\n <li style="padding: 10px 0 10px 32px; position: relative; color: #111827;">\n <span style="position: absolute; left: 0; font-size: 18px;">☐</span>\n No other app is exclusively using the microphone\n </li>\n </ul>\n <div class="mic-permission-modal__actions">\n <button class="mic-permission-modal__btn mic-permission-modal__btn--primary" data-action="retry">\n Retry\n </button>\n <button class="mic-permission-modal__btn mic-permission-modal__btn--secondary" data-action="close">\n Close\n </button>\n </div>\n ',n.appendChild(o),t.overlay=n,t.modal=o,o.querySelector('[data-action="retry"]').addEventListener("click",function(){window.location.reload()}),o.querySelector('[data-action="close"]').addEventListener("click",function(){t.close(),e()}),n.addEventListener("click",function(o){o.target===n&&(t.close(),e())}),t.show(),t}function so(e){return so="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},so(e)}function lo(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return uo(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(uo(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,uo(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,uo(d,"constructor",l),uo(l,"constructor",s),s.displayName="GeneratorFunction",uo(l,r,"GeneratorFunction"),uo(d),uo(d,r,"Generator"),uo(d,o,function(){return this}),uo(d,"toString",function(){return"[object Generator]"}),(lo=function(){return{w:i,m:p}})()}function uo(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}uo=function(e,t,n,o){function i(t,n){uo(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},uo(e,t,n,o)}function po(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function fo(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){po(i,o,r,a,c,"next",e)}function c(e){po(i,o,r,a,c,"throw",e)}a(void 0)})}}function ho(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,go(o.key),o)}}function go(e){var t=function(e){if("object"!=so(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=so(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==so(t)?t:t+""}var vo=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=t,this.audioStream=null,this.callStartTime=null,this.callTimerInterval=null,this.sdk=null,this.isActive=!1,this.sdk=new Hn({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,variables:t.variables||{},language:t.language||"en",outputContainer:t.outputContainer,outputEncoding:t.outputEncoding,outputSampleRate:t.outputSampleRate,outputChannels:t.outputChannels,outputBitDepth:t.outputBitDepth,onConversationStart:t.onConversationStart,onConversationEnd:t.onConversationEnd,onBargeIn:t.onBargeIn,onAudioStartPlaying:t.onAudioStartPlaying,onAudioStoppedPlaying:t.onAudioStoppedPlaying,onSubtitleDisplay:t.onSubtitleDisplay}),this.setupSDKEventHandlers()},t=[{key:"setupSDKEventHandlers",value:function(){var e=this;this.sdk.onTranscript=function(t){console.log("📝 [VOICE INTERFACE] onTranscript called with text:",t),e.updateTranscript(t)},this.sdk.onAgentSpeaking=function(e){var t=document.getElementById("voiceAvatarActive");t&&(e?t.classList.add("speaking"):t.classList.remove("speaking"))},this.sdk.onDisconnected=function(){console.log("🔌 WebSocket disconnected, hanging up call..."),e.isActive&&(e.isActive=!1,e.endVoiceCall())},this.sdk.onError=function(t){console.error("❌ Voice SDK Error:",t),t&&("DOMAIN_NOT_WHITELISTED"===t.message||t.message&&t.message.includes("Domain not whitelisted"))?e.showDomainError():e.showError(t.message||t)}}},{key:"t",value:function(e){var t,n,o=this.config.language||"en";return((null===(t=this.config.translations)||void 0===t?void 0:t[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[e]||e}},{key:"getTooltip",value:function(e){var t,n=null===(t=this.config.tooltips)||void 0===t?void 0:t[e];return null!=n?n:{mute:this.t("mute"),speaker:this.t("speaker"),endCall:this.t("endCall")}[e]||""}},{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 e=this.config.avatarBackgroundColor||"#667eea",t=this.config.avatarActiveBackgroundColor||this.config.avatarBackgroundColor||"#667eea",n=this.config.statusTitleColor||"#1e293b",o=this.config.statusSubtitleColor||"#64748b",r=this.config.startCallButtonColor||"#667eea",i=this.config.startCallButtonTextColor||"#FFFFFF",a=this.config.transcriptBackgroundColor||"#FFFFFF",c=this.config.transcriptTextColor||"#1e293b",s=this.config.transcriptLabelColor||"#94a3b8",l=this.config.controlButtonColor||"#FFFFFF",u=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(e," 0%, ").concat(t," 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: clamp(40px, 9vh, 80px);\n margin: 0;\n box-shadow: 0 8px 30px rgba(102, 126, 234, 0.3);\n transition: all 0.3s ease;\n flex-shrink: 1;\n position: relative;\n }\n \n .voice-avatar-active {\n animation: avatarPulse 2s ease-in-out infinite;\n }\n \n @keyframes avatarPulse {\n 0%, 100% { \n transform: scale(1);\n }\n 50% { \n transform: scale(1.05);\n }\n }\n \n .voice-avatar-active.speaking {\n animation: avatarSpeak 0.5s ease-in-out infinite;\n }\n \n @keyframes avatarSpeak {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.08); }\n }\n \n /* Voice Rings Animation */\n .voice-rings {\n position: absolute;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n }\n \n .voice-ring {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n border: 2px solid rgba(102, 126, 234, 0.3);\n border-radius: 50%;\n opacity: 0;\n animation: ringExpand 2s ease-out infinite;\n }\n \n .voice-ring:nth-child(2) { animation-delay: 0.5s; }\n .voice-ring:nth-child(3) { animation-delay: 1s; }\n \n @keyframes ringExpand {\n 0% {\n width: 100%;\n height: 100%;\n opacity: 0.6;\n }\n 100% {\n width: 160%;\n height: 160%;\n opacity: 0;\n }\n }\n \n /* Voice Status - Scales with container */\n .voice-status {\n text-align: center;\n margin: 0;\n flex-shrink: 1;\n min-height: 0;\n }\n \n .voice-status-title {\n font-size: clamp(12px, 3vh, 20px);\n font-weight: 600;\n color: ").concat(n,";\n margin-bottom: clamp(2px, 0.5vh, 4px);\n line-height: 1.2;\n }\n \n .voice-status-subtitle {\n font-size: clamp(10px, 2vh, 14px);\n color: ").concat(o,";\n line-height: 1.2;\n }\n \n /* Start Call Button - Scales with container */\n .start-call-btn {\n margin: 0;\n width: min(280px, 70vw);\n height: clamp(48px, 8vh, 64px);\n border-radius: clamp(24px, 4vh, 32px);\n border: none;\n background: ").concat(r,";\n color: ").concat(i,";\n font-size: clamp(14px, 2.5vh, 18px);\n font-weight: 600;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: clamp(8px, 1.5vh, 12px);\n box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);\n transition: all 0.3s ease;\n flex-shrink: 0;\n }\n \n .start-call-btn svg {\n width: clamp(22px, 4vh, 32px);\n height: clamp(22px, 4vh, 32px);\n }\n \n .start-call-btn:hover {\n transform: translateY(-2px);\n box-shadow: 0 12px 28px rgba(102, 126, 234, 0.5);\n }\n \n .start-call-btn:active {\n transform: translateY(-1px);\n }\n \n /* Voice Transcript - Scales with container */\n .voice-transcript {\n background: ").concat(a,";\n padding: clamp(6px, 1.5vh, 12px);\n border-radius: 10px;\n width: min(360px, calc(100% - 40px));\n margin: 0;\n min-height: clamp(100px, 18vh, 140px);\n max-height: clamp(120px, 22vh, 160px);\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(l,";\n color: ").concat(u,";\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(e){var t=this,n=document.getElementById("startCallBtn"),o=document.getElementById("endCallBtn"),r=document.getElementById("muteBtn"),i=document.getElementById("speakerBtn");n&&(n.onclick=function(){return t.startVoiceCall()}),o&&(o.onclick=function(){return t.endVoiceCall()}),r&&(r.onclick=function(){return t.toggleMute()}),i&&(i.onclick=function(){return t.toggleSpeaker()});var a=function(){var e=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",e+1,")"),t.adjustSizesForContainer(),0===e&&setTimeout(function(){return t.adjustSizesForContainer()},500)):e<15?(console.log("⏳ Interface not ready yet (height:",null==n?void 0:n.clientHeight,"), retrying... (attempt",e+1,")"),setTimeout(function(){return a(e+1)},250)):(console.warn("⚠️ Interface never became fully ready, adjusting sizes anyway"),t.adjustSizesForContainer())};setTimeout(function(){return a()},200),window.addEventListener("resize",function(){console.log("🔄 Window resized, re-adjusting sizes"),t.adjustSizesForContainer()})}},{key:"getSignedUrl",value:(r=fo(lo().m(function e(){var t,n,o,r,i,a,c;return lo().w(function(e){for(;;)switch(e.n){case 0:if(this.config.getSessionUrl){e.n=2;break}if(this.config.agentId){e.n=1;break}throw new Error("agentId is required");case 1:return t=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"),e.a(2,"".concat(t,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){e.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),e.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=e.v).ok){e.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return e.n=5,r.json();case 5:return i=e.v,e.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){e.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),e.n=7,this.config.getSessionUrl(a);case 7:return c=e.v,e.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 e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"adjustSizesForContainer",value:function(){var e=document.getElementById("voiceInterface");if(e){var t=e.clientHeight,n=e.clientWidth;console.log("📏 Container size:",t,"x",n);var o,r,i,a,c,s,l,u,d,p=document.getElementById("voiceIdleState"),f=document.getElementById("voiceActiveState"),h=p&&"none"!==p.style.display,g=f&&"none"!==f.style.display;console.log("👁️ Visible state - Idle:",h,"Active:",g),t<=350?(d=5,o=70,r=35,i=11,a=9,c=32,s=100,l=42,u=48):t<=450?(d=7,o=110,r=55,i=15,a=11,c=38,s=110,l=52,u=58):t<=550?(d=8,o=140,r=70,i=16,a=12,c=42,s=120,l=56,u=64):t<=700?(d=10,o=130,r=65,i=18,a=13,c=46,s=130,l=60,u=70):(d=12,o=150,r=75,i=20,a=14,c=50,s=140,l=66,u=76),document.querySelectorAll("#voiceIdleState, #voiceActiveState").forEach(function(e){e.style.gap="".concat(d,"px")});var v=document.querySelectorAll(".voice-avatar, .voice-avatar-active");console.log("🤖 Found",v.length,"avatars, setting size to",o,"px"),v.forEach(function(e){e.style.width="".concat(o,"px"),e.style.height="".concat(o,"px"),e.style.fontSize="".concat(r,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(e){return e.style.fontSize="".concat(i,"px")}),document.querySelectorAll(".voice-status-subtitle").forEach(function(e){return e.style.fontSize="".concat(a,"px")});var m=document.querySelector(".voice-transcript");m&&(m.style.minHeight="".concat(s,"px"),m.style.maxHeight="".concat(s,"px"),m.style.height="".concat(s,"px"),m.style.width="min(360px, ".concat(n-40,"px)"),m.style.boxSizing="border-box");var y=document.querySelector(".transcript-label");y&&(y.style.fontSize="".concat(Math.max(8,i-4),"px"));var b=document.querySelector(".transcript-text");b&&(b.style.fontSize="".concat(Math.max(10,i-2),"px")),document.querySelectorAll(".voice-control-btn.secondary").forEach(function(e){e.style.width="".concat(l,"px"),e.style.height="".concat(l,"px");var t=e.querySelector("svg");if(t){var n=.65*l;t.style.setProperty("width","".concat(n,"px"),"important"),t.style.setProperty("height","".concat(n,"px"),"important"),t.style.setProperty("min-width","".concat(n,"px"),"important"),t.style.setProperty("min-height","".concat(n,"px"),"important")}});var w=document.querySelector(".voice-control-btn.primary");if(w){w.style.width="".concat(u,"px"),w.style.height="".concat(u,"px");var S=w.querySelector("svg");if(S){var x=.7*u;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;t<=350?(C=48,P=14):t<=450?(C=52,P=15):t<=550?(C=58,P=17):t<=700?(C=62,P=18):(C=64,P=18),k.style.height="".concat(C,"px"),k.style.fontSize="".concat(P,"px");var E=k.querySelector("svg");if(E){var O=Math.max(22,.5*C);E.style.width="".concat(O,"px"),E.style.height="".concat(O,"px")}}console.log("✅ Sizes adjusted - Avatar:",o,"Status:",c,"Transcript:",s,"Buttons:",l)}else console.warn("⚠️ voiceInterface not found, skipping size adjustment")}},{key:"startVoiceCall",value:(o=fo(lo().m(function e(){var t,n=this;return lo().w(function(e){for(;;)switch(e.n){case 0:if(!this.isActive){e.n=1;break}return console.log("⚠️ Voice call already active"),e.a(2);case 1:return console.log("🎤 Starting voice call..."),e.n=2,Yn();case 2:if(t=e.v,console.log("📋 Current permission state: ".concat(t)),"denied"!==t){e.n=3;break}return console.log("🚫 Permission is denied, showing blocked modal..."),Qn(),ao(function(){console.log("Blocked modal closed")}),e.a(2);case 3:if("prompt"!==t&&"unknown"!==t){e.n=4;break}return console.log("📋 Permission is in prompt state, showing pre-prompt modal..."),e.a(2,new Promise(function(e){io(fo(lo().m(function t(){return lo().w(function(t){for(;;)switch(t.n){case 0:return console.log("✅ Pre-prompt accepted, proceeding with voice call..."),t.n=1,n.proceedWithVoiceCall();case 1:e();case 2:return t.a(2)}},t)})),function(){console.log("❌ Pre-prompt cancelled"),e()})}));case 4:return e.n=5,this.proceedWithVoiceCall();case 5:return e.a(2)}},e,this)})),function(){return o.apply(this,arguments)})},{key:"proceedWithVoiceCall",value:(n=fo(lo().m(function e(){var t,n,o,r,i,a,c,s,l=this;return lo().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,t=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState"),o=document.getElementById("voiceInterface"),t&&(t.style.display="none"),n&&(n.style.display="flex"),setTimeout(function(){return l.adjustSizesForContainer()},50),o&&(o.scrollTop=0),e.n=1,this.getSignedUrl();case 1:if(r=e.v,console.log("🔗 Got signed URL:",r),!this.sdk||!this.sdk.isConnected){e.n=5;break}return console.log("🔄 SDK already connected, disconnecting for clean retry..."),e.p=2,this.sdk.disconnect(),e.n=3,new Promise(function(e){return setTimeout(e,100)});case 3:e.n=5;break;case 4:e.p=4,c=e.v,console.warn("Warning: Error disconnecting existing connection:",c);case 5:return e.n=6,this.sdk.connect(r);case 6:i=e.v,console.log("✅ Connected to WebSocket, connected:",i),a=0;case 7:if(this.sdk.isConnected||!(a<50)){e.n=9;break}return e.n=8,new Promise(function(e){return setTimeout(e,100)});case 8:a++,e.n=7;break;case 9:if(!this.sdk.isConnected){e.n=11;break}return console.log("✅ WebSocket ready, starting listening..."),e.n=10,this.sdk.startListening();case 10:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var e=Date.now()-l.callStartTime,t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(t.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3),e.n=13;break;case 11:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),e.n=12,this.sdk.startListening();case 12:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var e=Date.now()-l.callStartTime,t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(t.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3);case 13:console.log("✅ Voice call started successfully"),e.n=15;break;case 14:if(e.p=14,s=e.v,console.error("❌ Error starting voice call:",s),this.isActive=!1,this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&this.sdk.isConnected)try{this.sdk.disconnect()}catch(e){console.warn("Error disconnecting SDK on error:",e)}"NotAllowedError"===s.name||"PermissionDeniedError"===s.name?(Qn(),ao(function(){l.resetUIState()})):"NotFoundError"===s.name||"DevicesNotFoundError"===s.name?co(function(){l.resetUIState()}):(this.showError(s.message||s),this.resetUIState());case 15:return e.a(2)}},e,this,[[2,4],[0,14]])})),function(){return n.apply(this,arguments)})},{key:"resetUIState",value:function(){var e=document.getElementById("voiceIdleState"),t=document.getElementById("voiceActiveState");e&&(e.style.display="flex"),t&&(t.style.display="none")}},{key:"endVoiceCall",value:function(){var e=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(e){return e.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null);var t=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState");t&&(t.style.display="flex"),n&&(n.style.display="none"),setTimeout(function(){return e.adjustSizesForContainer()},50);var o=document.getElementById("transcriptText");o&&(o.textContent=this.t("transcriptWillAppear"),o.classList.add("empty"));var r=document.getElementById("voiceAvatarActive");r&&r.classList.remove("speaking"),console.log("✅ Voice call ended")}},{key:"updateTranscript",value:function(e){console.log("📝 [VOICE INTERFACE] updateTranscript called with text:",e);var t=document.getElementById("transcriptText");t?(console.log("📝 [VOICE INTERFACE] Found transcript element, updating text"),t.textContent=e,t.classList.remove("empty")):console.warn("📝 [VOICE INTERFACE] ⚠️ transcriptText element not found!")}},{key:"showError",value:function(e){var t=document.getElementById("transcriptText");t&&(t.textContent="".concat(this.t("error"),": ").concat(e),t.classList.remove("empty"))}},{key:"showDomainError",value:function(){var e=document.getElementById("transcriptText");if(e){var t=this.t("domainNotValidated"),n=this.t("domainErrorMessage");e.innerHTML='<div style="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;">'.concat(t,'</div><div style="font-size: 14px; color: #991B1B; line-height: 1.5;">').concat(n,"</div>"),e.classList.remove("empty")}}},{key:"toggleMute",value:function(){if(this.sdk&&this.isActive){var e=null;if(this.sdk.voiceSDK&&this.sdk.voiceSDK.audioRecorder&&this.sdk.voiceSDK.audioRecorder.mediaStream&&(e=this.sdk.voiceSDK.audioRecorder.mediaStream.getAudioTracks()[0]),!e&&this.audioStream&&(e=this.audioStream.getAudioTracks()[0]),e){e.enabled=!e.enabled;var t=document.getElementById("muteBtn"),n=null==t?void 0:t.querySelector(".mute-icon"),o=null==t?void 0:t.querySelector(".mute-cross");t&&n&&o&&(e.enabled?(n.style.stroke="",o.style.display="none",t.classList.remove("muted")):(n.style.stroke="#9ca3af",o.style.display="block",t.classList.add("muted"))),console.log(e.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(e){return e.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&(this.sdk.disconnect(),this.sdk=null)}}],t&&ho(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o,r}();function mo(e){return mo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},mo(e)}function yo(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return bo(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(bo(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,bo(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,bo(d,"constructor",l),bo(l,"constructor",s),s.displayName="GeneratorFunction",bo(l,r,"GeneratorFunction"),bo(d),bo(d,r,"Generator"),bo(d,o,function(){return this}),bo(d,"toString",function(){return"[object Generator]"}),(yo=function(){return{w:i,m:p}})()}function bo(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}bo=function(e,t,n,o){function i(t,n){bo(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},bo(e,t,n,o)}function wo(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function So(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){wo(i,o,r,a,c,"next",e)}function c(e){wo(i,o,r,a,c,"throw",e)}a(void 0)})}}function xo(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ko(o.key),o)}}function ko(e){var t=function(e){if("object"!=mo(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=mo(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==mo(t)?t:t+""}var Co=function(){return e=function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=t,this.sdk=n,this.streamingEl=null,this.hasStartedStreaming=!1,this.isActive=!1,this.eventHandlers={autoResize:null,keydown:null},this.eventHandlersSetup=!1},t=[{key:"t",value:function(e){var t,n,o=this.config.language||"en";return((null===(t=this.config.translations)||void 0===t?void 0:t[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[e]||e}},{key:"generateHTML",value:function(){var e,t,n,o,r,i,a,c,s,l=this.config.inputPlaceholder||(null===(e=this.config.panel)||void 0===e?void 0:e.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(l,'" 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!==(t=this.config.sendButtonHint)&&void 0!==t&&t.text||null!==(n=this.config.panel)&&void 0!==n&&null!==(n=n.sendButtonHint)&&void 0!==n&&n.text?'\n <div class="send-button-hint" style="color: '.concat((null===(o=this.config.sendButtonHint)||void 0===o?void 0:o.color)||(null===(r=this.config.panel)||void 0===r||null===(r=r.sendButtonHint)||void 0===r?void 0:r.color)||"#6B7280","; font-size: ").concat((null===(i=this.config.sendButtonHint)||void 0===i?void 0:i.fontSize)||(null===(a=this.config.panel)||void 0===a||null===(a=a.sendButtonHint)||void 0===a?void 0:a.fontSize)||"12px",'; text-align: center; margin-top: 4px;">\n ').concat((null===(c=this.config.sendButtonHint)||void 0===c?void 0:c.text)||(null===(s=this.config.panel)||void 0===s||null===(s=s.sendButtonHint)||void 0===s?void 0:s.text),"\n </div>\n "):"","\n </div>\n </div>")}},{key:"generateCSS",value:function(){var e,t,n,o,r,i,a,c,s,l,u,d,p,f=this.config.messages,h=(this.config.panel,this.config.animation,this.config.sendButtonColor||(null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonColor)||"#7C3AED"),g=this.config.sendButtonHoverColor||(null===(t=this.config.panel)||void 0===t?void 0:t.sendButtonHoverColor)||"#6D28D9",v=this.config.sendButtonTextColor||(null===(n=this.config.panel)||void 0===n?void 0:n.sendButtonTextColor)||"#FFFFFF",m=(this.config.inputPlaceholder||null===(o=this.config.panel)||void 0===o||o.inputPlaceholder,this.config.inputBorderColor||(null===(r=this.config.panel)||void 0===r?void 0:r.inputBorderColor)||"#E5E7EB"),y=this.config.inputFocusColor||(null===(i=this.config.panel)||void 0===i?void 0:i.inputFocusColor)||"#7C3AED",b=this.config.inputBackgroundColor||(null===(a=this.config.panel)||void 0===a?void 0:a.inputBackgroundColor)||"#FFFFFF",w=this.config.inputTextColor||(null===(c=this.config.panel)||void 0===c?void 0:c.inputTextColor)||"#1F2937",S=this.config.inputFontSize||(null===(s=this.config.panel)||void 0===s?void 0:s.inputFontSize)||"14px",x=this.config.inputBorderRadius||(null===(l=this.config.panel)||void 0===l?void 0:l.inputBorderRadius)||20,k=this.config.inputPadding||(null===(u=this.config.panel)||void 0===u?void 0:u.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(f.borderRadius,"px; \n max-width: 80%; \n font-size: ").concat(f.fontSize,"; \n color: ").concat(f.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(f.userBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-start":"flex-end","; \n }\n .message.agent { \n background: ").concat(f.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(f.systemBackgroundColor,";\n align-self: flex-start;\n }\n .message.error {\n background: ").concat(f.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(m,";\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(y,";\n background: ").concat("#FFFFFF"===b?"#FFFFFF":b,";\n box-shadow: 0 0 0 3px ").concat(y,"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(v,";\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===(p=this.config.panel)||void 0===p?void 0:p.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(g,";\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(f.errorBackgroundColor,";\n border-radius: ").concat(f.borderRadius,"px;\n color: #991B1B;\n font-size: ").concat(f.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 e=this,t=document.getElementById("sendButton"),n=document.getElementById("messageInput"),o=document.getElementById("newChatBtn");if(t&&(t.onclick=function(){return e.sendMessage()}),o&&(o.onclick=function(){return e.startNewChat()}),this.updateInputAttributes(),n){n.style.height="32px",n.style.overflow="hidden";var r=function(){n.style.height="auto";var e=Math.min(n.scrollHeight,120);n.style.height=e+"px",n.style.overflowY=e>=120?"auto":"hidden",e>=120&&setTimeout(function(){n.scrollTop=n.scrollHeight},0)};n.addEventListener("input",r),n.addEventListener("keydown",function(t){"Enter"!==t.key||t.shiftKey?"Enter"===t.key&&t.shiftKey&&setTimeout(r,0):(t.preventDefault(),e.sendMessage())})}}},{key:"startNewChat",value:function(){try{localStorage.removeItem("ttp_text_chat_conversation_id")}catch(e){}this.sdk&&(this.sdk.config.conversationId=null);var e=document.getElementById("messagesContainer");e&&(e.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 t=document.getElementById("messageInput");t&&t.focus()}},{key:"updateInputAttributes",value:function(){var e=document.getElementById("messageInput");if(e){var t,n=this.config.inputPlaceholder||(null===(t=this.config.panel)||void 0===t?void 0:t.inputPlaceholder)||this.t("typeMessage")||"Type your message...";e.placeholder=n,e.dir=this.config.direction||"ltr",e.style.textAlign="rtl"===this.config.direction?"right":"left"}}},{key:"show",value:function(){var e=document.getElementById("textInterface");e&&e.classList.add("active"),setTimeout(function(){var e=document.getElementById("messageInput");e&&e.focus()},50)}},{key:"hide",value:function(){var e=document.getElementById("textInterface");e&&e.classList.remove("active")}},{key:"startChat",value:(o=So(yo().m(function e(){return yo().w(function(e){for(;;)switch(e.n){case 0:this.isActive=!0,this.updateSendButtonState();case 1:return e.a(2)}},e,this)})),function(){return o.apply(this,arguments)})},{key:"sendMessage",value:(n=So(yo().m(function e(){var t,n,o;return yo().w(function(e){for(;;)switch(e.p=e.n){case 0:if(t=document.getElementById("messageInput"),n=t.value.trim()){e.n=1;break}return e.a(2);case 1:if(this.isActive){e.n=2;break}return e.n=2,this.startChat();case 2:return this.addMessage("user",n),t.value="",t.style.height="32px",t.style.overflow="hidden",e.p=3,this.beginStreaming(),e.n=4,this.sdk.sendMessage(n);case 4:e.n=6;break;case 5:e.p=5,o=e.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 e.a(2)}},e,this,[[3,5]])})),function(){return n.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var e=document.getElementById("sendButton");e&&(e.disabled=!this.isActive)}},{key:"addMessage",value:function(e,t){var n=document.getElementById("messagesContainer");if(n){var o=n.querySelector(".empty-state");o&&o.remove();var r=document.createElement("div"),i="rtl"===this.config.direction?"user"===e?"edge-left":"edge-right":"user"===e?"edge-right":"edge-left";r.className="message ".concat(e," ").concat(i);var a=document.createElement("div");a.className="message-avatar ".concat(e),a.textContent="user"===e?"👤":"🤖";var c=document.createElement("div");c.className="message-bubble",c.textContent=t,r.appendChild(a),r.appendChild(c),n.appendChild(r),n.scrollTop=n.scrollHeight}}},{key:"beginStreaming",value:function(){var e=document.getElementById("messagesContainer");if(e){this.stopStreamingState();var t=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";t.className="message agent ".concat(n),t.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var r=document.createElement("div");r.className="message-bubble",r.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',t.appendChild(o),t.appendChild(r),e.appendChild(t),this.streamingEl=r,this.hasStartedStreaming=!1,e.scrollTop=e.scrollHeight}}},{key:"appendStreamingChunk",value:function(e){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=e;var t=document.getElementById("messagesContainer");t&&(t.scrollTop=t.scrollHeight)}}},{key:"finalizeStreaming",value:function(e){if(this.streamingEl){this.streamingEl.textContent=e||this.streamingEl.textContent;var t=document.getElementById("agent-streaming");t&&(t.id=""),this.streamingEl=null}this.updateSendButtonState()}},{key:"stopStreamingState",value:function(){var e=document.getElementById("agent-streaming");e&&e.remove(),this.streamingEl=null,this.hasStartedStreaming=!1}},{key:"showError",value:function(e){var t=document.getElementById("messagesContainer");if(t){if(e&&("DOMAIN_NOT_WHITELISTED"===e.message||"string"==typeof e&&e.includes("DOMAIN_NOT_WHITELISTED")||e.message&&e.message.includes("Domain not whitelisted")||"string"==typeof e&&e.includes("Domain not whitelisted"))){var n,o=document.createElement("div");o.className="error-message",o.style.cssText="padding: 16px; margin: 12px; border-radius: 8px; background: "+((null===(n=this.config.messages)||void 0===n?void 0:n.errorBackgroundColor)||"#FEE2E2")+";";var r=document.createElement("div");r.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",r.textContent=this.t("domainNotValidated");var i=document.createElement("div");i.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",i.textContent=this.t("domainErrorMessage"),o.appendChild(r),o.appendChild(i),t.appendChild(o)}else{var a=document.createElement("div");a.className="error-message",a.textContent="string"==typeof e?e:(null==e?void 0:e.message)||e,t.appendChild(a)}t.scrollTop=t.scrollHeight}}},{key:"setActive",value:function(e){this.isActive=e,this.updateSendButtonState()}}],t&&xo(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();const Po={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 Eo(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Oo(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Oo(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Oo(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Oo(d,"constructor",l),Oo(l,"constructor",s),s.displayName="GeneratorFunction",Oo(l,r,"GeneratorFunction"),Oo(d),Oo(d,r,"Generator"),Oo(d,o,function(){return this}),Oo(d,"toString",function(){return"[object Generator]"}),(Eo=function(){return{w:i,m:p}})()}function Oo(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Oo=function(e,t,n,o){function i(t,n){Oo(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Oo(e,t,n,o)}function To(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Io(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){To(i,o,r,a,c,"next",e)}function c(e){To(i,o,r,a,c,"throw",e)}a(void 0)})}}function Ao(e){return Ao="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ao(e)}function jo(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function Do(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?jo(Object(n),!0).forEach(function(t){Fo(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):jo(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Fo(e,t,n){return(t=Bo(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Bo(o.key),o)}}function Bo(e){var t=function(e){if("object"!=Ao(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ao(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ao(t)?t:t+""}var Ro=function(){return e=function e(){var t,n,o,r,i,a,c,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=this.mergeWithDefaults(s),this.sdk=new hn(this.config),this.isOpen=!1,this.isActive=!1,this.translations=Po,this.currentView="landing";var l=Do(Do(Do({},this.config),this.config.voice),{},{language:(null===(t=this.config.voice)||void 0===t?void 0:t.language)||this.config.language||"en",websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16,onConversationStart:this.config.onConversationStart,onConversationEnd:this.config.onConversationEnd,onBargeIn:this.config.onBargeIn,onAudioStartPlaying:this.config.onAudioStartPlaying,onAudioStoppedPlaying:this.config.onAudioStoppedPlaying,onSubtitleDisplay:this.config.onSubtitleDisplay});this.voiceInterface=new vo(l);var u=Do(Do(Do({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new Co(u,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var d=document.getElementById("text-chat-panel");d&&(this.isOpen=!0,d.classList.add("open"))}},t=[{key:"mergeWithDefaults",value:function(e){var t,n,o,r,i,a,c,s,l,u,d,p,f,h,g,v,m,y,b,w,S,x,k,C,P,E,O,T,I,A,j,D,F,_,B,R,M,U,N,L,z,V,K,H,W,G,q,Q,Y,$,J,X,Z,ee,te,ne,oe,re,ie,ae,ce,se,le,ue,de,pe,fe,he,ge,ve,me,ye,be,we,Se,xe,ke,Ce,Pe,Ee,Oe,Te,Ie,Ae,je,De,Fe,_e,Be,Re,Me,Ue,Ne,Le,ze,Ve,Ke,He,We,Ge,qe,Qe,Ye,$e,Je,Xe,Ze,et,tt,nt,ot,rt,it,at,ct,st,lt,ut,dt,pt,ft,ht,gt,vt,mt,yt,bt,wt,St,xt,kt,Ct,Pt,Et,Ot=e.position||"bottom-right";if("string"==typeof Ot){var Tt=Ot.split("-");Ot={vertical:Tt[0]||"bottom",horizontal:Tt[1]||"right",offset:e.positionOffset||{x:20,y:20}}}var It=e.primaryColor||(null===(t=e.button)||void 0===t?void 0:t.primaryColor)||(null===(n=e.button)||void 0===n?void 0:n.backgroundColor)||"#7C3AED",At=(null===(o=e.header)||void 0===o?void 0:o.backgroundColor)||(null===(r=e.button)||void 0===r?void 0:r.backgroundColor)||It;return Do({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,demo:!1!==e.demo,direction:e.direction||"ltr",language:e.language||"en",icon:Do({type:(null===(i=e.icon)||void 0===i?void 0:i.type)||"custom",customImage:(null===(a=e.icon)||void 0===a?void 0:a.customImage)||"https://talktopc.com/logo192.png",emoji:(null===(c=e.icon)||void 0===c?void 0:c.emoji)||"🎤",text:(null===(s=e.icon)||void 0===s?void 0:s.text)||"AI",size:(null===(l=e.icon)||void 0===l?void 0:l.size)||"medium",backgroundColor:(null===(u=e.icon)||void 0===u?void 0:u.backgroundColor)||"#FFFFFF"},e.icon),position:Do({vertical:Ot.vertical||"bottom",horizontal:Ot.horizontal||"right",offset:Ot.offset||{x:20,y:20}},"object"===Ao(e.position)?e.position:{}),button:Do({size:(null===(d=e.button)||void 0===d?void 0:d.size)||"medium",shape:(null===(p=e.button)||void 0===p?void 0:p.shape)||"circle",backgroundColor:(null===(f=e.button)||void 0===f?void 0:f.backgroundColor)||(null===(h=e.icon)||void 0===h?void 0:h.backgroundColor)||It,hoverColor:(null===(g=e.button)||void 0===g?void 0:g.hoverColor)||"#7C3AED",shadow:!1!==(null===(v=e.button)||void 0===v?void 0:v.shadow),shadowColor:(null===(m=e.button)||void 0===m?void 0:m.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(y=e.button)||void 0===y?void 0:y.backgroundColor)||(null===(b=e.icon)||void 0===b?void 0:b.backgroundColor)||It},e.button),panel:Do({width:(null===(w=e.panel)||void 0===w?void 0:w.width)||350,height:(null===(S=e.panel)||void 0===S?void 0:S.height)||500,borderRadius:(null===(x=e.panel)||void 0===x?void 0:x.borderRadius)||12,backgroundColor:(null===(k=e.panel)||void 0===k?void 0:k.backgroundColor)||"#FFFFFF",backdropFilter:(null===(C=e.panel)||void 0===C?void 0:C.backdropFilter)||null,border:(null===(P=e.panel)||void 0===P?void 0:P.border)||"1px solid rgba(0,0,0,0.1)"},e.panel),voice:Do({micButtonColor:(null===(E=e.voice)||void 0===E?void 0:E.micButtonColor)||(null===(O=e.panel)||void 0===O?void 0:O.micButtonColor)||It,micButtonActiveColor:(null===(T=e.voice)||void 0===T?void 0:T.micButtonActiveColor)||(null===(I=e.panel)||void 0===I?void 0:I.micButtonActiveColor)||"#EF4444",micButtonHint:Do(Do({text:(null===(A=e.voice)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.text)||(null===(j=e.panel)||void 0===j||null===(j=j.micButtonHint)||void 0===j?void 0:j.text)||"Click the button to start voice conversation",color:(null===(D=e.voice)||void 0===D||null===(D=D.micButtonHint)||void 0===D?void 0:D.color)||(null===(F=e.panel)||void 0===F||null===(F=F.micButtonHint)||void 0===F?void 0:F.color)||"#6B7280",fontSize:(null===(_=e.voice)||void 0===_||null===(_=_.micButtonHint)||void 0===_?void 0:_.fontSize)||(null===(B=e.panel)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.fontSize)||"12px"},null===(R=e.voice)||void 0===R?void 0:R.micButtonHint),null===(M=e.panel)||void 0===M?void 0:M.micButtonHint),avatarBackgroundColor:(null===(U=e.voice)||void 0===U?void 0:U.avatarBackgroundColor)||"#667eea",avatarActiveBackgroundColor:(null===(N=e.voice)||void 0===N?void 0:N.avatarActiveBackgroundColor)||"#667eea",statusTitleColor:(null===(L=e.voice)||void 0===L?void 0:L.statusTitleColor)||"#1e293b",statusSubtitleColor:(null===(z=e.voice)||void 0===z?void 0:z.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(V=e.voice)||void 0===V?void 0:V.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(K=e.voice)||void 0===K?void 0:K.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(H=e.voice)||void 0===H?void 0:H.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(W=e.voice)||void 0===W?void 0:W.transcriptTextColor)||"#1e293b",transcriptLabelColor:(null===(G=e.voice)||void 0===G?void 0:G.transcriptLabelColor)||"#94a3b8",controlButtonColor:(null===(q=e.voice)||void 0===q?void 0:q.controlButtonColor)||"#FFFFFF",controlButtonSecondaryColor:(null===(Q=e.voice)||void 0===Q?void 0:Q.controlButtonSecondaryColor)||"#64748b",endCallButtonColor:(null===(Y=e.voice)||void 0===Y?void 0:Y.endCallButtonColor)||"#ef4444",language:(null===($=e.voice)||void 0===$?void 0:$.language)||e.language||"en",websocketUrl:(null===(J=e.voice)||void 0===J?void 0:J.websocketUrl)||e.websocketUrl},e.voice),text:Do({sendButtonColor:(null===(X=e.text)||void 0===X?void 0:X.sendButtonColor)||(null===(Z=e.panel)||void 0===Z?void 0:Z.sendButtonColor)||"#7C3AED",sendButtonHoverColor:(null===(ee=e.text)||void 0===ee?void 0:ee.sendButtonHoverColor)||(null===(te=e.panel)||void 0===te?void 0:te.sendButtonHoverColor)||"#6D28D9",sendButtonActiveColor:(null===(ne=e.text)||void 0===ne?void 0:ne.sendButtonActiveColor)||(null===(oe=e.panel)||void 0===oe?void 0:oe.sendButtonActiveColor)||"#6D28D9",sendButtonText:(null===(re=e.text)||void 0===re?void 0:re.sendButtonText)||(null===(ie=e.panel)||void 0===ie?void 0:ie.sendButtonText)||"➤",sendButtonTextColor:(null===(ae=e.text)||void 0===ae?void 0:ae.sendButtonTextColor)||(null===(ce=e.panel)||void 0===ce?void 0:ce.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(se=e.text)||void 0===se?void 0:se.sendButtonFontSize)||(null===(le=e.panel)||void 0===le?void 0:le.sendButtonFontSize)||"18px",sendButtonFontWeight:(null===(ue=e.text)||void 0===ue?void 0:ue.sendButtonFontWeight)||(null===(de=e.panel)||void 0===de?void 0:de.sendButtonFontWeight)||"500",sendButtonHint:Do(Do({text:(null===(pe=e.text)||void 0===pe||null===(pe=pe.sendButtonHint)||void 0===pe?void 0:pe.text)||(null===(fe=e.panel)||void 0===fe||null===(fe=fe.sendButtonHint)||void 0===fe?void 0:fe.text)||"",color:(null===(he=e.text)||void 0===he||null===(he=he.sendButtonHint)||void 0===he?void 0:he.color)||(null===(ge=e.panel)||void 0===ge||null===(ge=ge.sendButtonHint)||void 0===ge?void 0:ge.color)||"#6B7280",fontSize:(null===(ve=e.text)||void 0===ve||null===(ve=ve.sendButtonHint)||void 0===ve?void 0:ve.fontSize)||(null===(me=e.panel)||void 0===me||null===(me=me.sendButtonHint)||void 0===me?void 0:me.fontSize)||"12px"},null===(ye=e.text)||void 0===ye?void 0:ye.sendButtonHint),null===(be=e.panel)||void 0===be?void 0:be.sendButtonHint),inputPlaceholder:(null===(we=e.text)||void 0===we?void 0:we.inputPlaceholder)||(null===(Se=e.panel)||void 0===Se?void 0:Se.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(xe=e.text)||void 0===xe?void 0:xe.inputBorderColor)||(null===(ke=e.panel)||void 0===ke?void 0:ke.inputBorderColor)||"#E5E7EB",inputFocusColor:(null===(Ce=e.text)||void 0===Ce?void 0:Ce.inputFocusColor)||(null===(Pe=e.panel)||void 0===Pe?void 0:Pe.inputFocusColor)||"#7C3AED",inputBackgroundColor:(null===(Ee=e.text)||void 0===Ee?void 0:Ee.inputBackgroundColor)||(null===(Oe=e.panel)||void 0===Oe?void 0:Oe.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(Te=e.text)||void 0===Te?void 0:Te.inputTextColor)||(null===(Ie=e.panel)||void 0===Ie?void 0:Ie.inputTextColor)||"#1F2937",inputFontSize:(null===(Ae=e.text)||void 0===Ae?void 0:Ae.inputFontSize)||(null===(je=e.panel)||void 0===je?void 0:je.inputFontSize)||"14px",inputBorderRadius:(null===(De=e.text)||void 0===De?void 0:De.inputBorderRadius)||(null===(Fe=e.panel)||void 0===Fe?void 0:Fe.inputBorderRadius)||20,inputPadding:(null===(_e=e.text)||void 0===_e?void 0:_e.inputPadding)||(null===(Be=e.panel)||void 0===Be?void 0:Be.inputPadding)||"6px 14px"},e.text),landing:Do({backgroundColor:(null===(Re=e.landing)||void 0===Re?void 0:Re.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)",logo:(null===(Me=e.landing)||void 0===Me?void 0:Me.logo)||"🤖",title:(null===(Ue=e.landing)||void 0===Ue?void 0:Ue.title)||null,titleColor:(null===(Ne=e.landing)||void 0===Ne?void 0:Ne.titleColor)||"#1e293b",modeCardBackgroundColor:(null===(Le=e.landing)||void 0===Le?void 0:Le.modeCardBackgroundColor)||"#FFFFFF",modeCardBorderColor:(null===(ze=e.landing)||void 0===ze?void 0:ze.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Ve=e.landing)||void 0===Ve?void 0:Ve.modeCardHoverBorderColor)||At,modeCardIconBackgroundColor:(null===(Ke=e.landing)||void 0===Ke?void 0:Ke.modeCardIconBackgroundColor)||At,modeCardTitleColor:(null===(He=e.landing)||void 0===He?void 0:He.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(We=e.landing)||void 0===We?void 0:We.voiceCardIcon)||"🎤",textCardIcon:(null===(Ge=e.landing)||void 0===Ge?void 0:Ge.textCardIcon)||"💬"},e.landing),header:Do({title:(null===(qe=e.header)||void 0===qe?void 0:qe.title)||"Chat Assistant",showTitle:!1!==(null===(Qe=e.header)||void 0===Qe?void 0:Qe.showTitle),backgroundColor:(null===(Ye=e.header)||void 0===Ye?void 0:Ye.backgroundColor)||(null===($e=e.button)||void 0===$e?void 0:$e.backgroundColor)||"#7C3AED",textColor:(null===(Je=e.header)||void 0===Je?void 0:Je.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(Xe=e.header)||void 0===Xe?void 0:Xe.showCloseButton)},e.header),tooltips:Do({newChat:(null===(Ze=e.tooltips)||void 0===Ze?void 0:Ze.newChat)||null,back:(null===(et=e.tooltips)||void 0===et?void 0:et.back)||null,close:(null===(tt=e.tooltips)||void 0===tt?void 0:tt.close)||null,mute:(null===(nt=e.tooltips)||void 0===nt?void 0:nt.mute)||null,speaker:(null===(ot=e.tooltips)||void 0===ot?void 0:ot.speaker)||null,endCall:(null===(rt=e.tooltips)||void 0===rt?void 0:rt.endCall)||null},e.tooltips),messages:Do({userBackgroundColor:(null===(it=e.messages)||void 0===it?void 0:it.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(at=e.messages)||void 0===at?void 0:at.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(ct=e.messages)||void 0===ct?void 0:ct.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(st=e.messages)||void 0===st?void 0:st.errorBackgroundColor)||"#FEE2E2",textColor:(null===(lt=e.messages)||void 0===lt?void 0:lt.textColor)||"#1F2937",fontSize:(null===(ut=e.messages)||void 0===ut?void 0:ut.fontSize)||"14px",borderRadius:(null===(dt=e.messages)||void 0===dt?void 0:dt.borderRadius)||8},e.messages),animation:Do({enableHover:!1!==(null===(pt=e.animation)||void 0===pt?void 0:pt.enableHover),enablePulse:!1!==(null===(ft=e.animation)||void 0===ft?void 0:ft.enablePulse),enableSlide:!1!==(null===(ht=e.animation)||void 0===ht?void 0:ht.enableSlide),duration:(null===(gt=e.animation)||void 0===gt?void 0:gt.duration)||.3},e.animation),behavior:Do({autoOpen:(null===(vt=e.behavior)||void 0===vt?void 0:vt.autoOpen)||!1,startOpen:(null===(mt=e.behavior)||void 0===mt?void 0:mt.startOpen)||!1,hidden:(null===(yt=e.behavior)||void 0===yt?void 0:yt.hidden)||!1,autoConnect:(null===(bt=e.behavior)||void 0===bt?void 0:bt.autoConnect)||!1,showWelcomeMessage:!1!==(null===(wt=e.behavior)||void 0===wt?void 0:wt.showWelcomeMessage),welcomeMessage:(null===(St=e.behavior)||void 0===St?void 0:St.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:void 0===(null===(xt=e.behavior)||void 0===xt?void 0:xt.enableVoiceMode)||e.behavior.enableVoiceMode,mode:(null===(kt=e.behavior)||void 0===kt?void 0:kt.mode)||"unified"},e.behavior),accessibility:Do({ariaLabel:(null===(Ct=e.accessibility)||void 0===Ct?void 0:Ct.ariaLabel)||"Chat Assistant",ariaDescription:(null===(Pt=e.accessibility)||void 0===Pt?void 0:Pt.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(Et=e.accessibility)||void 0===Et?void 0:Et.keyboardNavigation)},e.accessibility),customStyles:e.customStyles||"",variables:e.variables||{},forceConversationId:e.forceConversationId,onConversationStart:e.onConversationStart,onConversationEnd:e.onConversationEnd,onBargeIn:e.onBargeIn,onAudioStartPlaying:e.onAudioStartPlaying,onAudioStoppedPlaying:e.onAudioStoppedPlaying,onSubtitleDisplay:e.onSubtitleDisplay,primaryColor:It},"string"==typeof e.position?{positionString:e.position}:{})}},{key:"setupEventHandlers",value:function(){var e=this;this.sdk.on("domainError",function(t){e.textInterface.showError(t),e.textInterface.stopStreamingState()}),this.sdk.on("error",function(t){t&&("DOMAIN_NOT_WHITELISTED"===t.message||t.message&&t.message.includes("Domain not whitelisted"))||(e.textInterface.showError(t.message||t),e.textInterface.stopStreamingState())}),this.sdk.on("chunk",function(t){e.textInterface.appendStreamingChunk(t)}),this.sdk.on("done",function(t){var n=t.text;e.textInterface.finalizeStreaming(n)})}},{key:"createWidget",value:function(){var e=document.getElementById("text-chat-widget");e&&e.remove();var t=document.createElement("div");if(t.id="text-chat-widget",t.innerHTML=this.generateWidgetHTML(),document.body.appendChild(t),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 e=this,t=(this.config.position,this.config.button),n=this.config.icon,o=(this.config.panel,this.config.header),r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[t.size]||60),i={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i),s=this.config.behavior.mode||"unified",l="unified"===s,u="unified"===s||"voice-only"===s,d="unified"===s||"text-only"===s,p=function(t){var n=e.config.language||"en";return(e.translations[n]||e.translations.en)[t]||t},f=function(t){var n,o=null===(n=e.config.tooltips)||void 0===n?void 0:n[t];return null!=o?o:{newChat:p("newChat"),back:p("back"),close:p("close"),mute:p("mute"),speaker:p("speaker"),endCall:p("endCall")}[t]||""};return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header" style="background: ').concat(o.backgroundColor,"; color: ").concat(o.textColor,';">\n <div>\n ').concat(o.showTitle?'<div class="header-title">'.concat(o.title,"</div>"):"",'\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat(p("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(f("newChat"),'" style="').concat(l?"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(f("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="'+f("close")+'"><span style="font-size: 18px; font-weight: bold;">×</span></button>':"","\n </div>\n </div>\n\n ").concat(l?'\n <div class="landing-screen" id="landingScreen">\n <div class="landing-logo">🤖</div>\n <div class="landing-title">'.concat(p("landingTitle"),'</div>\n <div class="mode-selection">\n ').concat(u?'<div class="mode-card voice" id="mode-card-voice">\n <div class="mode-card-icon">🎤</div>\n <div class="mode-card-title">'.concat(p("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(p("textChat"),"</div>\n </div>"):"","\n </div>\n </div>"):"","\n\n ").concat(u?this.voiceInterface.generateHTML():"","\n ").concat(d?this.textInterface.generateHTML():"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var e=this.config.position,t=e.offset||{x:20,y:20},n="";return"top"===e.vertical?n+="top: ".concat(t.y,"px;"):"bottom"===e.vertical?n+="bottom: ".concat(t.y,"px;"):"center"===e.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===e.horizontal?n+="left: ".concat(t.x,"px;"):"right"===e.horizontal?n+="right: ".concat(t.x,"px;"):"center"===e.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(e){var t=this.config.icon;switch(t.type){case"custom":return'<img src="'.concat(t.customImage,'" alt="Chat Assistant" style="width: ').concat(e,"px; height: ").concat(e,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(e,'px; line-height: 1;">').concat(t.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*e),'px; font-weight: bold; color: white;">').concat(t.text,"</span>");case"microphone":default:return'<svg viewBox="0 0 24 24" style="width: '.concat(e,"px; height: ").concat(e,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>');case"chat":return'<svg viewBox="0 0 24 24" style="width: '.concat(e,"px; height: ").concat(e,'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(e,t,n){var o,r,i,a,c,s,l,u=this.config.button,d=this.config.icon,p=this.config.panel,f=this.config.header,h=(this.config.messages,this.config.animation),g=this.config.behavior.mode||"unified",v="unified"===g||"voice-only"===g,m="unified"===g||"text-only"===g,y=f.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(e,"\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(t,"px;\n height: ").concat(t,"px;\n border-radius: ").concat("circle"===u.shape?"50%":"square"===u.shape?"0":"12px",";\n background: ").concat(u.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(t,"px + 20px);\n ").concat("right"===this.config.position.horizontal?"right: 20px;":"left: 20px;","\n width: ").concat(p.width,"px;\n max-width: calc(100vw - 40px);\n height: ").concat(p.height,"px;\n max-height: calc(100vh - ").concat(t,"px - 40px);\n background: transparent;\n border-radius: ").concat(p.borderRadius,"px;\n border: none;\n flex-direction: column;\n overflow: hidden;\n ").concat(p.backdropFilter?"backdrop-filter: ".concat(p.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(p.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(p.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(p.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(p.borderRadius,"px;\n border-top-right-radius: ").concat(p.borderRadius,"px;\n flex-shrink: 0;\n min-height: 60px;\n box-sizing: border-box;\n }\n #text-chat-panel .header-title { font-size: 16px; font-weight: 600; }\n #text-chat-panel .header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.9; }\n #text-chat-panel .status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }\n @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n /* Header icon buttons */\n .header-icon {\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 36px;\n height: 36px;\n min-width: 36px;\n min-height: 36px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n flex-shrink: 0;\n font-size: 16px;\n padding: 0;\n box-sizing: border-box;\n }\n \n .header-icon:hover {\n background: rgba(255, 255, 255, 0.3);\n }\n \n .header-icon svg {\n pointer-events: none;\n stroke: white;\n fill: none;\n }\n \n .back-btn.visible {\n display: flex !important;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { \n display: none; \n flex: 1; \n padding: 20px; \n background: ").concat((null===(o=this.config.landing)||void 0===o?void 0:o.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)","; \n align-items: center; \n justify-content: flex-start; \n flex-direction: column; \n gap: 16px; \n overflow-y: auto; \n min-height: 0; \n }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { \n font-size: 20px; \n color: ").concat((null===(r=this.config.landing)||void 0===r?void 0:r.titleColor)||"#1e293b","; \n font-weight: 700; \n margin-bottom: 20px; \n text-align: center;\n width: 100%;\n }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { \n flex: 1; \n max-width: 180px; \n background: ").concat((null===(i=this.config.landing)||void 0===i?void 0:i.modeCardBackgroundColor)||"#FFFFFF","; \n border: 2px solid ").concat((null===(a=this.config.landing)||void 0===a?void 0:a.modeCardBorderColor)||"#E2E8F0","; \n border-radius: 20px; \n padding: 20px 12px; \n cursor: pointer; \n display: flex; \n flex-direction: column; \n align-items: center; \n gap: 8px; \n transition: transform ").concat(h.duration,"s ease, box-shadow ").concat(h.duration,"s ease, border-color ").concat(h.duration,"s ease; \n box-shadow: 0 4px 12px rgba(0,0,0,0.05); \n }\n .mode-card:hover { \n transform: translateY(-6px); \n box-shadow: 0 12px 24px rgba(102, 126, 234, 0.2); \n border-color: ").concat((null===(c=this.config.landing)||void 0===c?void 0:c.modeCardHoverBorderColor)||y,"; \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)||y,"; \n color: #fff; \n font-size: 32px; \n }\n .mode-card-title { \n color: ").concat((null===(l=this.config.landing)||void 0===l?void 0:l.modeCardTitleColor)||"#111827","; \n font-weight: 600; \n text-align: center;\n width: 100%;\n }\n\n ").concat(v?this.voiceInterface.generateCSS():"","\n ").concat(m?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 e=this,t=document.getElementById("text-chat-button");t&&(t.onclick=function(){return e.togglePanel()});var n=document.getElementById("closeBtn");n&&(n.onclick=function(){return e.togglePanel()});var o=this.config.behavior.mode||"unified",r="unified"===o,i="unified"===o||"voice-only"===o,a="unified"===o||"text-only"===o,c=document.getElementById("backBtn"),s=document.getElementById("landingScreen"),l=document.getElementById("mode-card-voice"),u=document.getElementById("mode-card-text"),d=document.getElementById("textInterface"),p=document.getElementById("voiceInterface");c&&(c.onclick=function(){return e.showLanding()}),r?(l&&(l.onclick=function(){return e.showVoice()}),u&&(u.onclick=function(){return e.showText()}),"text"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.add("active"),p&&p.classList.remove("active"),c&&"unified"===o&&c.classList.add("visible"),f&&(f.style.display="")):"voice"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.remove("active"),p&&p.classList.add("active"),c&&"unified"===o&&c.classList.add("visible"),f&&(f.style.display="none")):(this.currentView="landing",s&&s.classList.add("active"),d&&d.classList.remove("active"),p&&p.classList.remove("active"),c&&"unified"===o&&c.classList.remove("visible"))):"voice-only"===o?(p&&p.classList.add("active"),d&&d.classList.remove("active"),s&&s.classList.remove("active")):"text-only"===o&&(d&&d.classList.add("active"),p&&p.classList.remove("active"),s&&s.classList.remove("active")),i&&(console.log("⚙️ Setting up voice interface event handlers"),this.voiceInterface.setupEventHandlers()),a&&(console.log("⚙️ Setting up text interface event handlers"),this.textInterface.setupEventHandlers());var f=document.getElementById("newChatBtn");f&&(f.onclick=function(){return e.textInterface.startNewChat()},r&&(f.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 e=document.getElementById("landingScreen"),t=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");e&&e.classList.add("active"),t&&t.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),r&&(r.style.display="none")}}},{key:"showText",value:function(){this.currentView="text";var e=document.getElementById("landingScreen"),t=document.getElementById("voiceInterface"),n=document.getElementById("backBtn"),o=document.getElementById("newChatBtn");e&&e.classList.remove("active"),t&&t.classList.remove("active"),this.textInterface.show();var r=this.config.behavior.mode||"unified";n&&"unified"===r&&n.classList.add("visible"),o&&(o.style.display="")}},{key:"showVoice",value:function(){this.currentView="voice";var e=document.getElementById("landingScreen"),t=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");e&&e.classList.remove("active"),t&&t.classList.remove("active"),n&&n.classList.add("active");var i=this.config.behavior.mode||"unified";o&&"unified"===i&&o.classList.add("visible"),r&&(r.style.display="none")}},{key:"setupKeyboardNavigation",value:function(){var e=this;document.addEventListener("keydown",function(t){"Escape"===t.key&&e.isOpen&&e.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("text-chat-panel").classList.toggle("open"),this.isOpen&&setTimeout(function(){var e=document.getElementById("messageInput");e&&e.focus()},100),this.isOpen&&!this.isActive&&this.config.behavior.autoConnect&&this.startChat()}},{key:"startChat",value:(i=Io(Eo().m(function e(){return Eo().w(function(e){for(;;)switch(e.n){case 0:this.isActive=!0,this.textInterface.setActive(!0);case 1:return e.a(2)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"sendMessage",value:(r=Io(Eo().m(function e(){return Eo().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.textInterface.sendMessage();case 1:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=Io(Eo().m(function e(){var t,n,o,r,i,a,c;return Eo().w(function(e){for(;;)switch(e.n){case 0:if(this.config.getSessionUrl){e.n=2;break}if(this.config.agentId){e.n=1;break}throw new Error("agentId is required");case 1:return t=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"),e.a(2,"".concat(t,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){e.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),e.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=e.v).ok){e.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return e.n=5,r.json();case 5:return i=e.v,e.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){e.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),e.n=7,this.config.getSessionUrl(a);case 7:return c=e.v,e.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 e.a(2)}},e,this)})),function(){return o.apply(this,arguments)})},{key:"addMessage",value:function(e,t){this.textInterface.addMessage(e,t)}},{key:"beginStreaming",value:function(){this.textInterface.beginStreaming()}},{key:"appendStreamingChunk",value:function(e){this.textInterface.appendStreamingChunk(e)}},{key:"finalizeStreaming",value:function(e){this.textInterface.finalizeStreaming(e)}},{key:"stopStreamingState",value:function(){this.textInterface.stopStreamingState()}},{key:"showError",value:function(e){this.textInterface.showError(e)}},{key:"updateStatus",value:function(e){}},{key:"updateConfig",value:function(e){var t,n,o,r,i,a,c,s,l,u=Do({},this.config);e.panel&&(u.panel=Do(Do({},this.config.panel),e.panel)),e.voice&&(u.voice=Do(Do({},this.config.voice),e.voice),e.voice.micButtonHint&&(u.voice.micButtonHint=Do(Do({},null===(s=this.config.voice)||void 0===s?void 0:s.micButtonHint),e.voice.micButtonHint))),e.text&&(u.text=Do(Do({},this.config.text),e.text),e.text.sendButtonHint&&(u.text.sendButtonHint=Do(Do({},null===(l=this.config.text)||void 0===l?void 0:l.sendButtonHint),e.text.sendButtonHint))),void 0!==e.language&&(u.language=e.language),void 0!==e.language&&(["he","ar"].includes(e.language)?u.direction="rtl":void 0===e.direction&&(u.direction="ltr")),e.translations&&(u.translations=e.translations,this.translations=e.translations),e.button&&(u.button=Do(Do({},this.config.button),e.button)),e.header&&(u.header=Do(Do({},this.config.header),e.header)),e.icon&&(u.icon=Do(Do({},this.config.icon),e.icon)),e.messages&&(u.messages=Do(Do({},this.config.messages),e.messages)),e.animation&&(u.animation=Do(Do({},this.config.animation),e.animation)),e.behavior&&(u.behavior=Do(Do({},this.config.behavior),e.behavior)),e.accessibility&&(u.accessibility=Do(Do({},this.config.accessibility),e.accessibility)),e.tooltips&&(u.tooltips=Do(Do({},this.config.tooltips),e.tooltips)),e.landing&&(u.landing=Do(Do({},this.config.landing),e.landing)),void 0!==e.direction&&void 0===u.direction&&(u.direction=e.direction),void 0!==e.primaryColor&&(u.primaryColor=e.primaryColor),u.onConversationStart=void 0!==e.onConversationStart?e.onConversationStart:this.config.onConversationStart,u.onConversationEnd=void 0!==e.onConversationEnd?e.onConversationEnd:this.config.onConversationEnd,u.onBargeIn=void 0!==e.onBargeIn?e.onBargeIn:this.config.onBargeIn,u.onAudioStartPlaying=void 0!==e.onAudioStartPlaying?e.onAudioStartPlaying:this.config.onAudioStartPlaying,u.onAudioStoppedPlaying=void 0!==e.onAudioStoppedPlaying?e.onAudioStoppedPlaying:this.config.onAudioStoppedPlaying,u.onSubtitleDisplay=void 0!==e.onSubtitleDisplay?e.onSubtitleDisplay:this.config.onSubtitleDisplay,Object.keys(e).forEach(function(t){["panel","button","header","icon","messages","direction","voice","text","animation","behavior","accessibility","language","tooltips","landing","primaryColor","onConversationStart","onConversationEnd","onBargeIn","onAudioStartPlaying","onAudioStoppedPlaying","onSubtitleDisplay"].includes(t)||(u[t]=e[t])}),null===(t=this.config)||void 0===t||t.language,this.config=this.mergeWithDefaults(u);var d=this.config.language||"en",p=Do(Do(Do({},this.config),this.config.voice),{},{language:d,websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16,onConversationStart:this.config.onConversationStart,onConversationEnd:this.config.onConversationEnd,onBargeIn:this.config.onBargeIn,onAudioStartPlaying:this.config.onAudioStartPlaying,onAudioStoppedPlaying:this.config.onAudioStoppedPlaying,onSubtitleDisplay:this.config.onSubtitleDisplay});this.voiceInterface=new vo(p);var f=Do(Do(Do({},this.config),this.config.text),{},{language:d,translations:this.translations});this.textInterface=new Co(f,this.sdk);var h=document.getElementById("text-chat-widget");h&&h.remove(),this.createWidget(),this.textInterface&&this.textInterface.updateInputAttributes&&this.textInterface.updateInputAttributes()}},{key:"destroy",value:function(){var e=document.getElementById("text-chat-widget");e&&e.remove(),this.sdk&&this.sdk.destroy(),this.voiceInterface&&this.voiceInterface.destroy()}},{key:"startVoiceCall",value:(n=Io(Eo().m(function e(){return Eo().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.voiceInterface.startVoiceCall();case 1:return e.a(2)}},e,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()}}],t&&_o(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o,r,i}(),Mo="2.4.24";const Uo={VoiceSDK:ve,VoiceSDK_v2:en,TextChatSDK:hn,WebSocketManager:F,AudioRecorder:W,AudioPlayer:ne,EventEmitter:l,VoiceButton:En,VanillaVoiceButton:Rn,AgentSDK:Hn,TTPChatWidget:Ro,VERSION:Mo};return o})());
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TTPAgentSDK=t():e.TTPAgentSDK=t()}(window,()=>(()=>{"use strict";var e={540:(e,t,n)=>{e.exports=n(869)},698:(e,t)=>{var n=Symbol.for("react.transitional.element");function o(e,t,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==t.key&&(r=""+t.key),"key"in t)for(var i in o={},t)"key"!==i&&(o[i]=t[i]);else o=t;return t=o.ref,{$$typeof:n,type:e,key:r,ref:void 0!==t?t:null,props:o}}Symbol.for("react.fragment"),t.jsx=o,t.jsxs=o},848:(e,t,n)=>{e.exports=n(698)},869:(e,t)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(e,t,o){this.props=e,this.context=t,this.refs=r,this.updater=o||n}function a(){}function c(e,t,o){this.props=e,this.context=t,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(e,t){if("object"!=typeof e&&"function"!=typeof e&&null!=e)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")},i.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")},a.prototype=i.prototype;var s=c.prototype=new a;s.constructor=c,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var l={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;t.useEffect=function(e,t){return l.H.useEffect(e,t)},t.useRef=function(e){return l.H.useRef(e)},t.useState=function(e){return l.H.useState(e)}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{AgentSDK:()=>Hn,AudioPlayer:()=>ne,AudioRecorder:()=>W,EventEmitter:()=>l,MicPermissionModals:()=>i,MicPermissionUtils:()=>r,TTPChatWidget:()=>Ro,TextChatSDK:()=>hn,VERSION:()=>Mo,VanillaVoiceButton:()=>Rn,VoiceButton:()=>En,VoiceSDK:()=>ve,VoiceSDK_v2:()=>en,WebSocketManager:()=>F,default:()=>Uo});var r={};n.r(r),n.d(r,{checkPermissionState:()=>Yn,getDeviceInfo:()=>Qn,getPermissionInstructions:()=>Jn,openSettings:()=>Xn});var i={};function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function c(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}function s(e){var t=function(e){if("object"!=a(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==a(t)?t:t+""}n.r(i),n.d(i,{showBlockedModal:()=>ao,showNoMicrophoneModal:()=>co,showPrePromptModal:()=>io});var l=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.events={}},t=[{key:"on",value:function(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}},{key:"off",value:function(e,t){this.events[e]&&(this.events[e]=this.events[e].filter(function(e){return e!==t}))}},{key:"emit",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];this.events[e]&&this.events[e].forEach(function(t){try{t.apply(void 0,n)}catch(t){console.error("Error in event listener for ".concat(e,":"),t)}})}},{key:"removeAllListeners",value:function(e){e?delete this.events[e]:this.events={}}}],t&&c(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,l=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==t);s=!0);}catch(e){l=!0,r=e}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw r}}return c}}(e,t)||f(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=f(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function f(e,t){if(e){if("string"==typeof e)return h(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?h(e,t):void 0}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function g(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return v(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(v(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,v(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,v(d,"constructor",l),v(l,"constructor",s),s.displayName="GeneratorFunction",v(l,r,"GeneratorFunction"),v(d),v(d,r,"Generator"),v(d,o,function(){return this}),v(d,"toString",function(){return"[object Generator]"}),(g=function(){return{w:i,m:p}})()}function v(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}v=function(e,t,n,o){function i(t,n){v(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},v(e,t,n,o)}function m(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function y(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,b(o.key),o)}}function b(e){var t=function(e){if("object"!=u(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=u(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==u(t)?t:t+""}function w(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(w=function(){return!!e})()}function S(e){return S=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},S(e)}function x(e,t){return x=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},x(e,t)}const k=new(function(e){function t(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=S(t),function(e,t){if(t&&("object"==u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,w()?Reflect.construct(t,n||[],S(e).constructor):t.apply(e,n))}(this,t)).connections=new Map,e.connectionCounts=new Map,e.creatingConnections=new Set,e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&x(e,t)}(t,e),n=t,o=[{key:"getConnection",value:(r=g().m(function e(t){var n,o,r=this;return g().w(function(e){for(;;)switch(e.n){case 0:if(!this.connections.has(t)){e.n=1;break}return n=this.connections.get(t),this.connectionCounts.set(t,(this.connectionCounts.get(t)||0)+1),e.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(t)){e.n=2;break}return e.a(2,new Promise(function(e){var n=function(){if(r.connections.has(t)){var o=r.connections.get(t);r.connectionCounts.set(t,(r.connectionCounts.get(t)||0)+1),e(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(t),o=new WebSocket(t),this.connections.set(t,o),this.connectionCounts.set(t,1),o.addEventListener("open",function(e){r.creatingConnections.delete(t),r.emit("open",e,t)}),o.addEventListener("close",function(e){r.creatingConnections.delete(t),r.connections.delete(t),r.connectionCounts.delete(t),r.emit("close",e,t)}),o.addEventListener("error",function(e){r.creatingConnections.delete(t),r.emit("error",e,t)}),o.addEventListener("message",function(e){r.emit("message",e,t)}),e.a(2,o)}},e,this)}),i=function(){var e=this,t=arguments;return new Promise(function(n,o){var i=r.apply(e,t);function a(e){m(i,n,o,a,c,"next",e)}function c(e){m(i,n,o,a,c,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(e){if(this.connections.has(e)){var t=this.connectionCounts.get(e)||0,n=Math.max(0,t-1);if(this.connectionCounts.set(e,n),0===n){var o=this.connections.get(e);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(e),this.connectionCounts.delete(e)}}}},{key:"forceClose",value:function(e){if(this.connections.has(e)){var t=this.connections.get(e);t&&t.readyState===WebSocket.OPEN&&t.close(1e3,"Force close"),this.connections.delete(e),this.connectionCounts.delete(e)}}},{key:"getConnectionStatus",value:function(e){return this.connections.has(e)?{exists:!0,readyState:this.connections.get(e).readyState,subscribers:this.connectionCounts.get(e)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var e,t={},n=p(this.connections.entries());try{for(n.s();!(e=n.n()).done;){var o=d(e.value,2),r=o[0],i=o[1];t[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(e){n.e(e)}finally{n.f()}return t}},{key:"clearAll",value:function(){var e,t=p(this.connections.entries());try{for(t.s();!(e=t.n()).done;){var n=d(e.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(e){t.e(e)}finally{t.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&y(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(l));function C(e){return C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},C(e)}function P(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return E(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(E(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,E(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,E(d,"constructor",l),E(l,"constructor",s),s.displayName="GeneratorFunction",E(l,r,"GeneratorFunction"),E(d),E(d,r,"Generator"),E(d,o,function(){return this}),E(d,"toString",function(){return"[object Generator]"}),(P=function(){return{w:i,m:p}})()}function E(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}E=function(e,t,n,o){function i(t,n){E(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},E(e,t,n,o)}function T(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function O(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,A(o.key),o)}}function A(e){var t=function(e){if("object"!=C(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=C(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==C(t)?t:t+""}function I(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(I=function(){return!!e})()}function j(e){return j=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},j(e)}function D(e,t){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},D(e,t)}var F=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=j(t),function(e,t){if(t&&("object"==C(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,I()?Reflect.construct(t,n||[],j(e).constructor):t.apply(e,n))}(this,t)).config=e,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&D(e,t)}(t,e),n=t,o=[{key:"connect",value:(i=P().m(function e(){var t=this;return P().w(function(e){for(;;)if(0===e.n)return e.a(2,new Promise(function(e,n){try{t.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),t.connectResolve=e,t.connectReject=n,k.getConnection(t.config.websocketUrl,t.config).then(function(n){t.ws=n,t.setupEventListeners(),n.readyState===WebSocket.OPEN&&(t.isConnected=!0,t.emit("connected"),e(),t.connectResolve=null,t.connectReject=null)}).catch(function(e){console.error("🔌 WebSocketManager: Connection failed ".concat(t.connectionId),e),n(e),t.connectResolve=null,t.connectReject=null})}catch(e){console.error("🔌 WebSocketManager: Connection error ".concat(t.connectionId),e),n(e),t.connectResolve=null,t.connectReject=null}}))},e)}),a=function(){var e=this,t=arguments;return new Promise(function(n,o){var r=i.apply(e,t);function a(e){T(r,n,o,a,c,"next",e)}function c(e){T(r,n,o,a,c,"throw",e)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var e=this;if(this.ws){var t=function(t,n){n===e.config.websocketUrl&&(e.isConnected=!0,e.emit("connected"),e.connectResolve&&(e.connectResolve(),e.connectResolve=null,e.connectReject=null))},n=function(t,n){n===e.config.websocketUrl&&(e.isConnected=!1,e.emit("disconnected",t))},o=function(t,n){n===e.config.websocketUrl&&(e.emit("error",t),e.connectReject&&(e.connectReject(t),e.connectResolve=null,e.connectReject=null))},r=function(t,n){n===e.config.websocketUrl&&e.handleMessage(t)};k.on("open",t),k.on("close",n),k.on("error",o),k.on("message",r),this.eventHandlers={open:t,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(k.off("open",this.eventHandlers.open),k.off("close",this.eventHandlers.close),k.off("error",this.eventHandlers.error),k.off("message",this.eventHandlers.message)),this.config.websocketUrl&&k.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(e){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(e))}catch(e){console.warn("🔌 WebSocketManager: Failed to send message:",e.message)}}},{key:"sendBinary",value:function(e){if(this.isConnected&&this.ws)try{this.ws.send(e)}catch(e){console.warn("🔌 WebSocketManager: Failed to send binary data:",e.message)}}},{key:"handleMessage",value:function(e){var t=this;if(e.data instanceof ArrayBuffer)this.emit("binaryAudio",e.data);else if(e.data instanceof Blob)e.data.arrayBuffer().then(function(e){t.emit("binaryAudio",e)}).catch(function(e){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",e)});else try{var n=JSON.parse(e.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(e){this.emit("error",e)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return k.getAllConnections()}},{key:"clearAllConnections",value:function(){k.clearAll()}}],o&&O(n.prototype,o),r&&O(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a}(l);function _(e){return _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_(e)}function B(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return R(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(R(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,R(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,R(d,"constructor",l),R(l,"constructor",s),s.displayName="GeneratorFunction",R(l,r,"GeneratorFunction"),R(d),R(d,r,"Generator"),R(d,o,function(){return this}),R(d,"toString",function(){return"[object Generator]"}),(B=function(){return{w:i,m:p}})()}function R(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}R=function(e,t,n,o){function i(t,n){R(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},R(e,t,n,o)}function M(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function U(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){M(i,o,r,a,c,"next",e)}function c(e){M(i,o,r,a,c,"throw",e)}a(void 0)})}}function N(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function L(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,z(o.key),o)}}function z(e){var t=function(e){if("object"!=_(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=_(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==_(t)?t:t+""}function V(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(V=function(){return!!e})()}function K(e){return K=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},K(e)}function H(e,t){return H=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},H(e,t)}var W=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=K(t),function(e,t){if(t&&("object"==_(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,V()?Reflect.construct(t,n||[],K(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&H(e,t)}(t,e),n=t,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var e,t=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return N(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?N(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(t.s();!(e=t.n()).done;){var n=e.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(e){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(e){t.e(e)}finally{t.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"checkPermissionState",value:function(){var e=U(B().m(function e(){var t;return B().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!navigator.permissions||!navigator.permissions.query){e.n=2;break}return e.n=1,navigator.permissions.query({name:"microphone"});case 1:return t=e.v,e.a(2,t.state);case 2:e.n=4;break;case 3:e.p=3,e.v,console.log("⚠️ AudioRecorder: Permissions API not available or not supported for microphone");case 4:return e.a(2,null)}},e,null,[[0,3]])}));return function(){return e.apply(this,arguments)}}()},{key:"start",value:(i=U(B().m(function e(){var t,n,o,r,i,a,c=this;return B().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,console.log("🎤 AudioRecorder: Requesting microphone access..."),e.n=1,this.checkPermissionState();case 1:return(t=e.v)&&(console.log("📋 AudioRecorder: Current permission state: ".concat(t)),"denied"===t&&console.warn('⚠️ AudioRecorder: Permission state is "denied" - browser may not show prompt. User may need to change in browser settings.')),e.n=2,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 2:if(this.mediaStream=e.v,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){e.n=3;break}return e.n=3,this.audioContext.resume();case 3:return n=this.getAudioProcessorPath(),e.n=4,this.audioContext.audioWorklet.addModule(n);case 4:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(e){var t=e.data,n=t.type,o=t.data;"pcm_audio_data"===n&&c.emit("audioData",o)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),console.log("✅ AudioRecorder: Microphone access granted"),this.isRecording=!0,this.emit("recordingStarted"),e.n=9;break;case 5:if(e.p=5,a=e.v,o=a.message,"NotAllowedError"!==a.name&&"PermissionDeniedError"!==a.name){e.n=7;break}return e.n=6,this.checkPermissionState();case 6:"denied"===(r=e.v)?(o='Microphone access was blocked. To enable it: 1) Click the lock icon (🔒) in your browser\'s address bar, 2) Find "Microphone" and change it to "Allow", 3) Refresh this page and try again.',console.error("❌ AudioRecorder: Permission explicitly denied. User must change in browser settings.")):"prompt"===r?(o='Microphone permission was denied. Click the "Voice Call" button again to see the permission prompt.',console.error('❌ AudioRecorder: Permission denied but state is "prompt" - user can try again.')):(o="Microphone permission was denied. Click the button again to retry, or enable microphone access in your browser settings (lock icon 🔒 in address bar).",console.error("❌ AudioRecorder: Permission denied. User can try again or change in browser settings.")),e.n=8;break;case 7:"NotFoundError"===a.name||"DevicesNotFoundError"===a.name?(o="No microphone found. Please connect a microphone and try again.",console.error("❌ AudioRecorder: No microphone device found.")):"NotReadableError"===a.name||"TrackStartError"===a.name?(o="Microphone is already in use by another application. Please close other apps using the microphone and try again.",console.error("❌ AudioRecorder: Microphone is busy or not readable.")):"SecurityError"!==a.name&&"PermissionDeniedError"!==a.name||(o="Microphone access blocked. On mobile devices, please tap the recording button directly (not from an iframe or popup).",console.error("❌ AudioRecorder: User agent blocked microphone access. This often happens on mobile when not called from direct user interaction."));case 8:throw(i=new Error(o)).name=a.name,i.originalError=a,this.emit("error",i),i;case 9:return e.a(2)}},e,this,[[0,5]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=U(B().m(function e(){var t;return B().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:if(e.p=1,!this.audioWorkletNode){e.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),e.n=2,new Promise(function(e){return setTimeout(e,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(e){return e.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){e.n=4;break}return e.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),e.n=6;break;case 5:throw e.p=5,t=e.v,this.emit("error",t),t;case 6:return e.a(2)}},e,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&L(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(l);function G(e){return G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},G(e)}function q(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Q(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Q(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Q(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Q(d,"constructor",l),Q(l,"constructor",s),s.displayName="GeneratorFunction",Q(l,r,"GeneratorFunction"),Q(d),Q(d,r,"Generator"),Q(d,o,function(){return this}),Q(d,"toString",function(){return"[object Generator]"}),(q=function(){return{w:i,m:p}})()}function Q(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Q=function(e,t,n,o){function i(t,n){Q(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Q(e,t,n,o)}function Y(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function $(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Y(i,o,r,a,c,"next",e)}function c(e){Y(i,o,r,a,c,"throw",e)}a(void 0)})}}function J(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,X(o.key),o)}}function X(e){var t=function(e){if("object"!=G(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=G(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==G(t)?t:t+""}function Z(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Z=function(){return!!e})()}function ee(e){return ee=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ee(e)}function te(e,t){return te=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},te(e,t)}var ne=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=ee(t),function(e,t){if(t&&("object"==G(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Z()?Reflect.construct(t,n||[],ee(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n.audioContextReady=!1,n.initializeAudioContext().catch(function(){}),n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&te(e,t)}(t,e),n=t,o=[{key:"initializeAudioContext",value:(i=$(q().m(function e(){var t,n,o,r,i;return q().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.audioContext||"closed"===this.audioContext.state){e.n=1;break}return e.a(2);case 1:if(e.p=1,t=this.config.sampleRate?{sampleRate:this.config.sampleRate}:{},this.audioContext=new(window.AudioContext||window.webkitAudioContext)(t),"suspended"!==this.audioContext.state){e.n=2;break}return e.n=2,this.audioContext.resume();case 2:if("running"===this.audioContext.state)try{n=this.audioContext.sampleRate,o=this.audioContext.createBuffer(1,.01*n,n),(r=this.audioContext.createBufferSource()).buffer=o,r.connect(this.audioContext.destination),r.start(0),r.stop(this.audioContext.currentTime+.01)}catch(e){console.debug("AudioPlayer: AudioContext warmup skipped:",e)}this.audioContextReady=!0,e.n=4;break;case 3:e.p=3,i=e.v,console.warn("AudioPlayer: Failed to pre-initialize AudioContext:",i),this.audioContextReady=!1;case 4:return e.a(2)}},e,this,[[1,3]])})),function(){return i.apply(this,arguments)})},{key:"playAudio",value:function(e){var t=this;try{var n=this.createAudioBlob(e);if(this.audioQueue.push(n),!this.isPlaying&&!this.isProcessingQueue&&!this.currentSource){var o=this.audioContextReady?0:50;setTimeout(function(){return t.processQueue()},o)}}catch(e){this.emit("playbackError",e)}}},{key:"createAudioBlob",value:function(e){var t=new Uint8Array(e);if(t.length>=4){if(82===t[0]&&73===t[1]&&70===t[2]&&70===t[3])return new Blob([e],{type:"audio/wav"});if(255===t[0]&&!(224&~t[1]))return new Blob([e],{type:"audio/mpeg"});if(79===t[0]&&103===t[1]&&103===t[2]&&83===t[3])return new Blob([e],{type:"audio/ogg"})}return new Blob([e],{type:"audio/wav"})}},{key:"processQueue",value:(r=$(q().m(function e(){var t,n,o,r,i,a,c,s,l=this;return q().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){e.n=1;break}return e.a(2);case 1:if(this.isProcessingQueue=!0,t=this.audioQueue.shift()){e.n=2;break}return this.isProcessingQueue=!1,e.a(2);case 2:if(e.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext&&"closed"!==this.audioContext.state){e.n=3;break}return e.n=3,this.initializeAudioContext();case 3:if("suspended"!==(o=this.audioContext).state){e.n=5;break}return e.n=4,o.resume();case 4:if(!n){e.n=5;break}return e.n=5,new Promise(function(e){return setTimeout(e,10)});case 5:if("running"===o.state){e.n=7;break}if(console.warn("AudioPlayer: AudioContext not in running state:",o.state),"suspended"!==o.state){e.n=7;break}return e.n=6,o.resume();case 6:return e.n=7,new Promise(function(e){return setTimeout(e,10)});case 7:return e.n=8,t.arrayBuffer();case 8:return r=e.v,e.n=9,o.decodeAudioData(r);case 9:i=e.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=i,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){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)},c.start(),e.n=11;break;case 10:e.p=10,s=e.v,this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 11:return e.a(2)}},e,this,[[2,10]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var e=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(e){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],e&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.audioContextReady=!1}}],o&&J(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(l);function oe(e){return oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},oe(e)}function re(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return ie(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(ie(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,ie(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,ie(d,"constructor",l),ie(l,"constructor",s),s.displayName="GeneratorFunction",ie(l,r,"GeneratorFunction"),ie(d),ie(d,r,"Generator"),ie(d,o,function(){return this}),ie(d,"toString",function(){return"[object Generator]"}),(re=function(){return{w:i,m:p}})()}function ie(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}ie=function(e,t,n,o){function i(t,n){ie(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},ie(e,t,n,o)}function ae(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function ce(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){ae(i,o,r,a,c,"next",e)}function c(e){ae(i,o,r,a,c,"throw",e)}a(void 0)})}}function se(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function le(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?se(Object(n),!0).forEach(function(t){ue(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):se(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ue(e,t,n){return(t=pe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function de(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,pe(o.key),o)}}function pe(e){var t=function(e){if("object"!=oe(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=oe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==oe(t)?t:t+""}function fe(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(fe=function(){return!!e})()}function he(e){return he=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},he(e)}function ge(e,t){return ge=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ge(e,t)}var ve=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=he(t),function(e,t){if(t&&("object"==oe(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,fe()?Reflect.construct(t,n||[],he(e).constructor):t.apply(e,n))}(this,t)).config=le({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,onStartConversation:n.onStartConversation||null,onEndConversation:n.onEndConversation||null},n),e.isConnected=!1,e.isRecording=!1,e.isPlaying=!1,e.isDestroyed=!1,e.conversationStarted=!1,e.webSocketManager=new F(le(le({},e.config),{},{autoReconnect:!1!==e.config.autoReconnect})),e.audioRecorder=new W(e.config),e.audioPlayer=new ne(e.config),e.setupEventHandlers(),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ge(e,t)}(t,e),n=t,o=[{key:"setupEventHandlers",value:function(){var e=this;this.webSocketManager.on("connected",function(){e.isConnected=!0,e.sendHelloMessage(),e.emit("connected")}),this.webSocketManager.on("disconnected",function(t){if(e.isConnected=!1,e.conversationStarted&&(e.conversationStarted=!1,console.log("🏁 VoiceSDK: Conversation ended (connection closed)"),e.emit("conversationEnded",{}),e.config.onEndConversation))try{e.config.onEndConversation({})}catch(e){console.error("VoiceSDK: Error in onEndConversation hook:",e)}if(t&&1008===t.code&&t.reason&&(t.reason.includes("Domain not whitelisted")||t.reason.includes("domain")||t.reason.includes("whitelist"))){var n=new Error("DOMAIN_NOT_WHITELISTED");n.reason=t.reason,n.code=t.code,e.emit("domainError",n),e.emit("error",n)}e.isRecording&&e.stopRecording().catch(function(e){console.error("VoiceSDK: Error stopping recording on disconnect:",e)}),e.emit("disconnected",t)}),this.webSocketManager.on("error",function(t){e.emit("error",t)}),this.webSocketManager.on("message",function(t){if(("hello_ack"===t.t||"hello_ack"===t.type)&&!e.conversationStarted&&(e.conversationStarted=!0,console.log("🎬 VoiceSDK: Conversation started"),e.emit("conversationStarted",{conversationId:t.conversationId}),e.config.onStartConversation))try{e.config.onStartConversation({conversationId:t.conversationId})}catch(e){console.error("VoiceSDK: Error in onStartConversation hook:",e)}if("greeting_audio"===t.t&&t.data)try{for(var n=atob(t.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);e.audioPlayer.playAudio(o),e.emit("greetingStarted")}catch(e){console.error("VoiceSDK: Error playing greeting audio:",e)}else e.emit("message",t)}),this.webSocketManager.on("binaryAudio",function(t){e.audioPlayer.playAudio(t)}),this.webSocketManager.on("bargeIn",function(t){e.emit("bargeIn",t)}),this.webSocketManager.on("stopPlaying",function(t){e.emit("stopPlaying",t),e.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){if(e.isRecording=!0,!e.conversationStarted&&(e.conversationStarted=!0,console.log("🎬 VoiceSDK: Conversation started (recording)"),e.emit("conversationStarted",{}),e.config.onStartConversation))try{e.config.onStartConversation({})}catch(e){console.error("VoiceSDK: Error in onStartConversation hook:",e)}e.isPlaying&&(e.audioPlayer.stopImmediate(),e.isConnected&&e.webSocketManager.sendMessage({t:"barge_in"})),e.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){e.isRecording=!1,e.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(t){e.isConnected&&e.webSocketManager.sendBinary(t)}),this.audioPlayer.on("playbackStarted",function(){e.isPlaying=!0,e.emit("playbackStarted"),e.isConnected&&e.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){e.isPlaying=!1,e.emit("playbackStopped"),e.isConnected&&e.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(t){e.emit("playbackError",t)})}},{key:"connect",value:(l=ce(re().m(function e(){var t,n;return re().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isDestroyed){e.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),e.a(2,!1);case 1:return e.p=1,t=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=t,e.n=2,this.webSocketManager.connect();case 2:return e.a(2,!0);case 3:return e.p=3,n=e.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),e.a(2,!1)}},e,this,[[1,3]])})),function(){return l.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var e=this.config.websocketUrl,t=new URLSearchParams;if(this.config.agentId&&t.append("agentId",this.config.agentId),this.config.appId&&t.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&t.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&t.append("language",this.config.language),t.toString()){var n=e.includes("?")?"&":"?";e+=n+t.toString()}return e}},{key:"disconnect",value:function(){if(!this.isDestroyed){if(this.conversationStarted&&(this.conversationStarted=!1,console.log("🏁 VoiceSDK: Conversation ended"),this.emit("conversationEnded",{}),this.config.onEndConversation))try{this.config.onEndConversation({})}catch(e){console.error("VoiceSDK: Error in onEndConversation hook:",e)}this.stopRecording(),this.webSocketManager.disconnect()}}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=ce(re().m(function e(){return re().w(function(e){for(;;)switch(e.n){case 0:if(!this.isDestroyed){e.n=1;break}return e.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),e.n=2,this.connect();case 2:return e.a(2,e.v)}},e,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(c=ce(re().m(function e(){var t,n;return re().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isConnected){e.n=1;break}throw new Error("Not connected to voice server");case 1:return e.p=1,console.log("🎤 VoiceSDK: Requesting microphone permission (mobile-friendly)..."),e.n=2,this.audioRecorder.start();case 2:return this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),e.a(2,!0);case 3:return e.p=3,n=e.v,console.error("❌ VoiceSDK: Failed to start recording:",n),"NotAllowedError"===n.name||"PermissionDeniedError"===n.name?((t=new Error("Microphone permission denied. Please allow microphone access in your browser settings and try again.")).name=n.name,t.originalError=n,this.emit("error",t)):this.emit("error",n),e.a(2,!1)}},e,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=ce(re().m(function e(){var t;return re().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:return e.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),e.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),e.a(2,!0);case 3:return e.p=3,t=e.v,this.emit("error",t),e.a(2,!1)}},e,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=ce(re().m(function e(){return re().w(function(e){for(;;)switch(e.n){case 0:if(!this.isRecording){e.n=2;break}return e.n=1,this.stopRecording();case 1:case 3:return e.a(2,e.v);case 2:return e.n=3,this.startRecording();case 4:return e.a(2)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=ce(re().m(function e(){return re().w(function(e){for(;;)switch(e.n){case 0:if(this.stopAudioPlayback(),this.isRecording){e.n=1;break}return e.n=1,this.startRecording();case 1:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(e){this.config=le(le({},this.config),e)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var e={t:"hello"};if(!this.config.appId){var t=new Error("appId is required for connection");return console.error("VoiceSDK: Failed to send hello message:",t),void this.emit("error",t)}e.appId=this.config.appId,this.config.agentSettingsOverride&&Object.keys(this.config.agentSettingsOverride).length>0&&(e.agentSettingsOverride=this.config.agentSettingsOverride,console.log("🔧 VoiceSDK: Sending agent settings override:",Object.keys(this.config.agentSettingsOverride)));try{this.webSocketManager.sendMessage(e)}catch(t){console.error("VoiceSDK: Failed to send hello message:",t),this.emit("error",t)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&de(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,l}(l);function me(e){return me="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},me(e)}function ye(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,be(o.key),o)}}function be(e){var t=function(e){if("object"!=me(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=me(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==me(t)?t:t+""}var we=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.events={}},t=[{key:"on",value:function(e,t){return this.events[e]||(this.events[e]=[]),this.events[e].push(t),this}},{key:"off",value:function(e,t){return this.events[e]?(this.events[e]=this.events[e].filter(function(e){return e!==t}),this):this}},{key:"emit",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return!!this.events[e]&&(this.events[e].forEach(function(e){e.apply(void 0,n)}),!0)}},{key:"once",value:function(e,t){var n=this,o=function(){t.apply(void 0,arguments),n.off(e,o)};return this.on(e,o)}},{key:"removeAllListeners",value:function(e){return e?delete this.events[e]:this.events={},this}}],t&&ye(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();const Se=we;function xe(e){return xe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},xe(e)}function ke(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ce(o.key),o)}}function Ce(e){var t=function(e){if("object"!=xe(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=xe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==xe(t)?t:t+""}const Pe=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name="PCM"},(t=[{key:"decode",value:function(e){if(e instanceof ArrayBuffer)return e;if(e instanceof Uint8Array)return e.buffer;throw new Error("Invalid PCM data type")}},{key:"encode",value:function(e){return e}}])&&ke(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function Ee(e){return Ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ee(e)}function Te(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Oe(o.key),o)}}function Oe(e){var t=function(e){if("object"!=Ee(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ee(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ee(t)?t:t+""}const Ae=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name="PCMU"},(t=[{key:"decode",value:function(e){for(var t=e instanceof Uint8Array?e:new Uint8Array(e),n=new Int16Array(t.length),o=0;o<t.length;o++)n[o]=this.mulawToLinear(t[o]);return n.buffer}},{key:"encode",value:function(e){for(var t=e instanceof Int16Array?e:new Int16Array(e),n=new Uint8Array(t.length),o=0;o<t.length;o++)n[o]=this.linearToMulaw(t[o]);return n}},{key:"mulawToLinear",value:function(e){var t=1<<3+(e>>4&7);return(128&e?-1:1)*(132+(15&e)*t+(t>>1)-4)}},{key:"linearToMulaw",value:function(e){var t=e>>8&128;t&&(e=-e),e>32635&&(e=32635),e+=132;for(var n=7,o=16384;0===(e&o)&&n>0;n--,o>>=1);return 255&~(t|n<<4|e>>n+3&15)}}])&&Te(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function Ie(e){return Ie="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ie(e)}function je(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,De(o.key),o)}}function De(e){var t=function(e){if("object"!=Ie(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ie(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ie(t)?t:t+""}const Fe=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.name="PCMA"},(t=[{key:"decode",value:function(e){for(var t=e instanceof Uint8Array?e:new Uint8Array(e),n=new Int16Array(t.length),o=0;o<t.length;o++)n[o]=this.alawToLinear(t[o]);return n.buffer}},{key:"encode",value:function(e){for(var t=e instanceof Int16Array?e:new Int16Array(e),n=new Uint8Array(t.length),o=0;o<t.length;o++)n[o]=this.linearToAlaw(t[o]);return n}},{key:"alawToLinear",value:function(e){var t=(e^=85)>>4&7,n=15&e;return(128&e?-1:1)*(0===t?8+(n<<4):264+(n<<4)<<t-1)}},{key:"linearToAlaw",value:function(e){var t,n,o=e>>8&128;if(o&&(e=-e),e>32635&&(e=32635),e<256)t=0,n=e>>4;else{t=7;for(var r=16384;0===(e&r)&&t>0;t--,r>>=1);n=e>>t+3&15}return 85^(o|t<<4|n)}}])&&je(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function _e(e){return _e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_e(e)}function Be(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Re(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Re(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function Re(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function Me(e){if(null!=e){var t=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}throw new TypeError(_e(e)+" is not iterable")}function Ue(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Ne(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Ne(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Ne(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Ne(d,"constructor",l),Ne(l,"constructor",s),s.displayName="GeneratorFunction",Ne(l,r,"GeneratorFunction"),Ne(d),Ne(d,r,"Generator"),Ne(d,o,function(){return this}),Ne(d,"toString",function(){return"[object Generator]"}),(Ue=function(){return{w:i,m:p}})()}function Ne(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Ne=function(e,t,n,o){function i(t,n){Ne(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Ne(e,t,n,o)}function Le(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function ze(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Le(i,o,r,a,c,"next",e)}function c(e){Le(i,o,r,a,c,"throw",e)}a(void 0)})}}function Ve(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ke(o.key),o)}}function Ke(e){var t=function(e){if("object"!=_e(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=_e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==_e(t)?t:t+""}function He(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(He=function(){return!!e})()}function We(e){return We=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},We(e)}function Ge(e,t){return Ge=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ge(e,t)}var qe=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=We(t),function(e,t){if(t&&("object"==_e(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,He()?Reflect.construct(t,n||[],We(e).constructor):t.apply(e,n))}(this,t)).config=n,e.audioContext=null,e.audioQueue=[],e.isPlaying=!1,e.isProcessingQueue=!1,e.currentSource=null,e.outputFormat=null,e.nextStartTime=0,e.scheduledBuffers=0,e.scheduledSources=new Set,e.pcmChunkQueue=[],e.preparedBuffer=[],e.isProcessingPcmQueue=!1,e.isSchedulingFrames=!1,e.MAX_LOOKAHEAD_SECONDS=.02,e.pendingSentenceText=null,e.sentenceTimings=[],e.isCheckingTranscripts=!1,e.codecs={pcm:new Pe,pcmu:new Ae,pcma:new Fe},e.SUPPORTED_CONTAINERS=["wav","raw"],e.SUPPORTED_ENCODINGS=["pcm","pcmu","pcma"],e.SUPPORTED_SAMPLE_RATES=[8e3,16e3,22050,24e3,44100,48e3],e.SUPPORTED_BIT_DEPTHS=[8,16,24],e.SUPPORTED_CHANNELS=[1],console.log("🎵 AudioPlayer v2 initialized"),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Ge(e,t)}(t,e),n=t,o=[{key:"setOutputFormat",value:function(e){var t;this.validateFormat(e)||(console.warn("⚠️ AudioPlayer: Invalid format, using defaults:",e),e=this.getDefaultFormat());var n=null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate,o=e.sampleRate;this.outputFormat=e,console.log("✅ AudioPlayer v2: Format set:",e),this.audioContext&&n&&n!==o&&(console.warn("⚠️ AudioPlayer: Sample rate changed, recreating AudioContext"),console.warn(" Old: ".concat(n,"Hz → New: ").concat(o,"Hz")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null,console.log("ℹ️ AudioContext will be recreated on next audio chunk with correct sample rate")),this.audioContext||(this.initializeAudioContext(),this.audioContext&&"suspended"===this.audioContext.state&&this.audioContext.resume().then(function(){console.log("✅ AudioPlayer v2: AudioContext resumed and ready")}).catch(function(e){console.warn("⚠️ AudioPlayer v2: Could not resume AudioContext:",e)}))}},{key:"validateFormat",value:function(e){var t,n;if(!e)return!1;var o=null===(t=e.container)||void 0===t?void 0:t.toLowerCase(),r=null===(n=e.encoding)||void 0===n?void 0:n.toLowerCase();return o&&r&&this.SUPPORTED_CONTAINERS.includes(o)&&this.SUPPORTED_ENCODINGS.includes(r)&&this.SUPPORTED_SAMPLE_RATES.includes(e.sampleRate)&&this.SUPPORTED_BIT_DEPTHS.includes(e.bitDepth)&&(!e.channels||this.SUPPORTED_CHANNELS.includes(e.channels))}},{key:"getDefaultFormat",value:function(){return{container:"raw",encoding:"pcm",sampleRate:16e3,channels:1,bitDepth:16}}},{key:"playAudio",value:function(e){var t=this;try{var n=this.createAudioBlob(e);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return t.processQueue()},50)}catch(e){console.error("❌ AudioPlayer v2: Playback error:",e),this.emit("playbackError",e)}}},{key:"playChunk",value:(c=ze(Ue().m(function e(t){var n,o,r=this;return Ue().w(function(e){for(;;)switch(e.n){case 0:(n=this.prepareChunk(t))?(this.preparedBuffer.push(n),(this.preparedBuffer.length<=3||this.preparedBuffer.length%10==0)&&console.log("📥 AudioPlayer: Frame received, queued: ".concat(this.preparedBuffer.length,", scheduled: ").concat(this.scheduledBuffers,", isScheduling: ").concat(this.isSchedulingFrames)),this.isSchedulingFrames?setTimeout(function(){r.preparedBuffer.length>0&&!r.isSchedulingFrames&&r.schedulePreparedFrames()},5):this.schedulePreparedFrames(),this.pcmChunkQueue.length>0&&!this.isProcessingPcmQueue&&this.processPcmQueue()):(console.error("❌ AudioPlayer: playChunk failed - prepareChunk returned null"),console.error(" pcmData length:",(null==t?void 0:t.byteLength)||"undefined"),console.error(" outputFormat:",this.outputFormat),console.error(" audioContext:",this.audioContext?"initialized":"not initialized"),console.error(" audioContext state:",(null===(o=this.audioContext)||void 0===o?void 0:o.state)||"N/A"),this.emit("playbackError",new Error("Failed to prepare PCM chunk for playback")));case 1:return e.a(2)}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"prepareChunk",value:function(e){try{var t;if(!this.outputFormat)return console.error("❌ AudioPlayer: Cannot prepare chunk - outputFormat not set"),console.error(" Call setOutputFormat() before playing audio chunks"),null;if(this.audioContext||this.initializeAudioContext(),!this.audioContext)return console.error("❌ AudioPlayer: Cannot prepare chunk - AudioContext not available"),null;var n=e;if(e.byteLength%2!=0){console.warn("⚠️ Odd PCM chunk size, padding:",e.byteLength);var o=new Uint8Array(e.byteLength+1);o.set(new Uint8Array(e),0),o[e.byteLength]=0,n=o.buffer}for(var r=new Int16Array(n),i=new Float32Array(r.length),a=1/32768,c=r.length,s=0;s<c;s++)i[s]=r[s]*a;var l=(null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate)||this.audioContext.sampleRate,u=this.audioContext.sampleRate,d=this.audioContext.createBuffer(1,i.length,l);d.getChannelData(0).set(i);var p=d.duration,f=i.length,h=p;return u!==l&&(h=f/u),{buffer:d,duration:h,sampleRate:l,contextSampleRate:u}}catch(e){return console.error("❌ AudioPlayer: Error preparing chunk:",e),null}}},{key:"applyFadeOut",value:function(e){return e}},{key:"schedulePreparedFrames",value:(a=ze(Ue().m(function e(){var t,n,o,r,i,a,c=this;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isSchedulingFrames){e.n=1;break}return e.a(2);case 1:if(this.isSchedulingFrames=!0,t=this.preparedBuffer.length,0===(n=Math.min(t,5))&&t>0&&(n=1),e.p=2,this.audioContext||this.initializeAudioContext(),o=0===this.scheduledBuffers&&!this.isPlaying,"suspended"!==this.audioContext.state){e.n=4;break}return e.n=3,this.audioContext.resume();case 3:if(!o){e.n=4;break}return e.n=4,new Promise(function(e){return setTimeout(e,50)});case 4:if("running"===this.audioContext.state){e.n=8;break}if(console.warn("AudioPlayer v2: AudioContext not in running state:",this.audioContext.state),"suspended"!==this.audioContext.state){e.n=8;break}return e.n=5,this.audioContext.resume();case 5:if(!o){e.n=7;break}return e.n=6,new Promise(function(e){return setTimeout(e,50)});case 6:e.n=8;break;case 7:return e.n=8,new Promise(function(e){return setTimeout(e,10)});case 8:r=0,i=Ue().m(function e(){var t,n,o,i,a;return Ue().w(function(e){for(;;)switch(e.n){case 0:if(t=c.preparedBuffer.shift()){e.n=1;break}return e.a(2,1);case 1:(n=c.audioContext.createBufferSource()).buffer=t.buffer,n.connect(c.audioContext.destination),c.scheduledSources.add(n),o=c.audioContext.currentTime,0===c.scheduledBuffers?(c.nextStartTime<o&&(c.nextStartTime=o+c.MAX_LOOKAHEAD_SECONDS),console.log("🎵 Starting playback with minimal delay:",c.nextStartTime)):(i=o+c.MAX_LOOKAHEAD_SECONDS,c.nextStartTime<i&&(c.nextStartTime=i,console.warn("⚠️ AudioPlayer: Fell behind schedule, adjusting nextStartTime to ".concat(c.nextStartTime.toFixed(4),"s")))),c.pendingSentenceText&&(c.sentenceTimings.push({startTime:c.nextStartTime,text:c.pendingSentenceText,displayed:!1}),console.log("📝 AudioPlayer: Sentence scheduled at ".concat(c.nextStartTime.toFixed(3),'s: "').concat(c.pendingSentenceText.substring(0,40),'..."')),c.pendingSentenceText=null,c.isCheckingTranscripts||c.startTranscriptChecker()),n.start(c.nextStartTime),c.nextStartTime+=t.duration,c.nextStartTime=Math.round(1e6*c.nextStartTime)/1e6,a=c.nextStartTime-t.duration,c.scheduledBuffers<5&&(console.log("🎵 AudioPlayer: Scheduled frame ".concat(c.scheduledBuffers+1," at ").concat(a.toFixed(4),"s, next at ").concat(c.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(t.duration.toFixed(4),"s (").concat((1e3*t.duration).toFixed(2),"ms), Queued: ").concat(c.preparedBuffer.length,", Scheduled: ").concat(c.scheduledBuffers))),c.scheduledBuffers++,r++,n.onended=function(){if(c.scheduledSources.delete(n),c.scheduledBuffers--,0===c.scheduledBuffers&&0===c.preparedBuffer.length&&0===c.pcmChunkQueue.length)c.isPlaying=!1,c.isSchedulingFrames=!1,console.log("🛑 AudioPlayer: Emitting playbackStopped event (all buffers finished)"),c.emit("playbackStopped");else if(c.preparedBuffer.length>0)setTimeout(function(){c.preparedBuffer.length>0&&!c.isSchedulingFrames&&c.schedulePreparedFrames()},0);else if(c.scheduledBuffers>0){var e=function(){c.preparedBuffer.length>0&&!c.isSchedulingFrames&&c.scheduledBuffers>0?c.schedulePreparedFrames():c.scheduledBuffers>0&&setTimeout(e,10)};setTimeout(e,10)}},c.isPlaying||(c.isPlaying=!0,console.log("🎵 AudioPlayer: Emitting playbackStarted event"),c.emit("playbackStarted"));case 2:return e.a(2)}},e)});case 9:if(!(this.preparedBuffer.length>0&&r<n)){e.n=12;break}return e.d(Me(i()),10);case 10:if(!e.v){e.n=11;break}return e.a(3,12);case 11:e.n=9;break;case 12:this.isSchedulingFrames=!1,this.preparedBuffer.length>0&&requestAnimationFrame(function(){c.preparedBuffer.length>0&&!c.isSchedulingFrames&&c.schedulePreparedFrames()}),this.scheduledBuffers>0&&setTimeout(function(){c.preparedBuffer.length>0&&!c.isSchedulingFrames&&c.scheduledBuffers>0?c.schedulePreparedFrames():c.scheduledBuffers>0&&setTimeout(function(){c.preparedBuffer.length>0&&!c.isSchedulingFrames&&c.scheduledBuffers>0&&c.schedulePreparedFrames()},10)},10),e.n=14;break;case 13:e.p=13,a=e.v,console.error("❌ AudioPlayer v2: Error scheduling frames:",a),this.emit("playbackError",a),this.isSchedulingFrames=!1;case 14:return e.a(2)}},e,this,[[2,13]])})),function(){return a.apply(this,arguments)})},{key:"processPcmQueue",value:(i=ze(Ue().m(function e(){var t,n,o,r,i,a,c,s,l,u,d,p,f,h,g,v,m,y,b,w,S,x=this;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isProcessingPcmQueue){e.n=1;break}return e.a(2);case 1:if(this.isProcessingPcmQueue=!0,e.p=2,this.audioContext||this.initializeAudioContext(),t=0===this.scheduledBuffers&&!this.isPlaying,"suspended"!==this.audioContext.state){e.n=4;break}return e.n=3,this.audioContext.resume();case 3:if(!t){e.n=4;break}return e.n=4,new Promise(function(e){return setTimeout(e,50)});case 4:if("running"===this.audioContext.state){e.n=8;break}if(console.warn("AudioPlayer v2: AudioContext not in running state:",this.audioContext.state),"suspended"!==this.audioContext.state){e.n=8;break}return e.n=5,this.audioContext.resume();case 5:if(!t){e.n=7;break}return e.n=6,new Promise(function(e){return setTimeout(e,50)});case 6:e.n=8;break;case 7:return e.n=8,new Promise(function(e){return setTimeout(e,10)});case 8:if(!(this.pcmChunkQueue.length>0)){e.n=10;break}if(r=this.pcmChunkQueue.shift()){e.n=9;break}return e.a(3,8);case 9:for(i=r,r.byteLength%2!=0&&(console.warn("⚠️ Odd PCM chunk size, padding:",r.byteLength),(a=new Uint8Array(r.byteLength+1)).set(new Uint8Array(r),0),a[r.byteLength]=0,i=a.buffer),c=new Int16Array(i),s=new Float32Array(c.length),l=1/32768,u=c.length,d=0;d<u;d++)s[d]=c[d]*l;p=(null===(n=this.outputFormat)||void 0===n?void 0:n.sampleRate)||this.audioContext.sampleRate,f=this.audioContext.sampleRate,null!==(o=this.outputFormat)&&void 0!==o&&o.sampleRate?this.scheduledBuffers<3&&console.log("🎵 AudioPlayer: Creating buffer at ".concat(p,"Hz (AudioContext: ").concat(f,"Hz)")):console.warn("⚠️ AudioPlayer: outputFormat.sampleRate not set! Using AudioContext sample rate:",f),(h=this.audioContext.createBuffer(1,s.length,p)).getChannelData(0).set(s),(g=this.audioContext.createBufferSource()).buffer=h,g.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)),m=h.duration,y=s.length,b=m,f!==p&&(b=y/f,this.scheduledBuffers<3&&(console.log("🔄 Resampling detected: ".concat(p,"Hz → ").concat(f,"Hz")),console.log(" Buffer duration: ".concat(m.toFixed(4),"s, Calculated: ").concat(b.toFixed(4),"s")))),g.start(this.nextStartTime),this.nextStartTime+=b,this.nextStartTime=Math.round(1e6*this.nextStartTime)/1e6,this.scheduledBuffers<3&&(w=this.nextStartTime-b,console.log("🎵 AudioPlayer: Scheduled chunk ".concat(this.scheduledBuffers+1," at ").concat(w.toFixed(4),"s, next at ").concat(this.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(b.toFixed(4),"s (").concat((1e3*b).toFixed(2),"ms)"))),this.scheduledBuffers++,g.onended=function(){x.scheduledBuffers--,0===x.scheduledBuffers&&0===x.pcmChunkQueue.length&&(x.isPlaying=!1,x.isProcessingPcmQueue=!1,x.emit("playbackStopped"))},this.isPlaying||(this.isPlaying=!0,this.emit("playbackStarted")),e.n=8;break;case 10:this.isProcessingPcmQueue=!1,e.n=12;break;case 11:e.p=11,S=e.v,console.error("❌ AudioPlayer v2: Error playing chunk:",S),this.emit("playbackError",S),this.isProcessingPcmQueue=!1;case 12:return e.a(2)}},e,this,[[2,11]])})),function(){return i.apply(this,arguments)})},{key:"createAudioBlob",value:function(e){var t=new Uint8Array(e);console.log("🎵 AudioPlayer: Processing ".concat(t.length," bytes")),console.log("🎵 AudioPlayer: Negotiated format:",this.outputFormat);var n=this.outputFormat&&this.outputFormat.container&&"wav"===this.outputFormat.container.toLowerCase(),o=this.outputFormat&&this.outputFormat.container&&"raw"===this.outputFormat.container.toLowerCase(),r=this.isWavFile(t);if(r&&console.log("🎵 AudioPlayer: Data has WAV header (RIFF)"),o&&r)return console.error("❌ AudioPlayer: CRITICAL MISMATCH!"),console.error(" Negotiated format: RAW"),console.error(" Actual data: WAV (RIFF header detected)"),console.error(" Backend is ignoring format request and sending WAV anyway."),console.warn("⚠️ AudioPlayer: Processing as WAV to avoid playback failure, but UI configuration was bypassed."),this.handleWavFile(t);if(o&&!r)console.log("🎵 AudioPlayer: Processing as RAW data (as negotiated)");else{if(n&&r)return console.log("✅ AudioPlayer: Processing as WAV file (matches negotiation)"),this.handleWavFile(t);if(n&&!r)return console.warn("⚠️ AudioPlayer: Negotiated WAV but data lacks WAV header. Attempting WAV processing anyway."),this.handleWavFile(t);if(!this.outputFormat&&r)return console.log("🎵 AudioPlayer: No format negotiated, auto-detecting WAV"),this.handleWavFile(t);this.outputFormat||r||(console.warn("⚠️ AudioPlayer: No format negotiated and data not WAV, using defaults"),this.outputFormat=this.getDefaultFormat())}return this.outputFormat||(console.warn("⚠️ AudioPlayer: No format set, using defaults"),this.outputFormat=this.getDefaultFormat()),console.log("🎵 AudioPlayer: Processing as RAW data with encoding:",this.outputFormat.encoding),this.handleRawData(t)}},{key:"isWavFile",value:function(e){return e.length>=44&&82===e[0]&&73===e[1]&&70===e[2]&&70===e[3]}},{key:"handleWavFile",value:function(e){var t=this.parseWavHeader(e);if(console.log("🎵 WAV file detected:",{format:t.audioFormat,encoding:this.getEncodingName(t.audioFormat),sampleRate:t.sampleRate,channels:t.channels,bitDepth:t.bitsPerSample}),1===t.audioFormat)return console.log("✅ PCM WAV - using directly"),new Blob([e],{type:"audio/wav"});var n=this.getCodecForWavFormat(t.audioFormat);if(!n)throw new Error("Unsupported WAV format code: ".concat(t.audioFormat));console.log("🔄 Non-PCM WAV - converting to PCM WAV");var o=e.slice(44),r=n.decode(o),i=this.createWavHeader(r.byteLength,t.sampleRate,t.channels,16);return new Blob([i,r],{type:"audio/wav"})}},{key:"handleRawData",value:function(e){var t,n,o=this.outputFormat.encoding.toLowerCase(),r=this.getCodec(o);if(!r)throw new Error("No codec found for encoding: ".concat(o));if(console.log("🎵 AudioPlayer: Decoding ".concat(o.toUpperCase()," to PCM")),console.log("🎵 AudioPlayer: Input format - bitDepth: ".concat(this.outputFormat.bitDepth,", sampleRate: ").concat(this.outputFormat.sampleRate)),"pcm"===o){var i=this.outputFormat.bitDepth||16;e.length,24===i?(console.warn("⚠️ AudioPlayer: Format says 24-bit PCM, but browser support is limited."),console.warn(" Treating as 16-bit PCM. If audio sounds wrong, backend should send 16-bit instead."),t=this.convert24BitTo16Bit(e),n=16):8===i?(console.log("🔄 AudioPlayer: Converting 8-bit PCM to 16-bit PCM"),t=this.convert8BitTo16Bit(e),n=16):(t=e.buffer,n=i,console.log("✅ AudioPlayer: Using native ".concat(i,"-bit PCM (no conversion needed)")))}else t=r.decode(e),n=16,console.log("🔄 AudioPlayer: Decoded ".concat(o.toUpperCase()," to 16-bit PCM"));var a=this.createWavHeader(t.byteLength,this.outputFormat.sampleRate,this.outputFormat.channels,n);return new Blob([a,t],{type:"audio/wav"})}},{key:"convert24BitTo16Bit",value:function(e){for(var t=Math.floor(e.length/3),n=new Int16Array(t),o=0;o<t;o++){var r=e[3*o],i=e[3*o+1],a=e[3*o+2],c=r|i<<8|(255&a)<<16;128&a&&(c|=4278190080),n[o]=Math.max(-32768,Math.min(32767,Math.round(c/256)))}return n.buffer}},{key:"convert8BitTo16Bit",value:function(e){for(var t=e.length,n=new Int16Array(t),o=0;o<t;o++){var r=e[o];n[o]=256*(r-128)}return n.buffer}},{key:"getCodec",value:function(e){var t={pcm:"pcm",linear:"pcm",l16:"pcm",pcmu:"pcmu",ulaw:"pcmu",mulaw:"pcmu",g711u:"pcmu",pcma:"pcma",alaw:"pcma",g711a:"pcma"}[e.toLowerCase()];return this.codecs[t]}},{key:"getCodecForWavFormat",value:function(e){switch(e){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(e){switch(e){case 1:return"PCM";case 6:return"A-law";case 7:return"μ-law";default:return"Unknown (".concat(e,")")}}},{key:"parseWavHeader",value:function(e){var t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{audioFormat:t.getUint16(20,!0),channels:t.getUint16(22,!0),sampleRate:t.getUint32(24,!0),byteRate:t.getUint32(28,!0),blockAlign:t.getUint16(32,!0),bitsPerSample:t.getUint16(34,!0)}}},{key:"createWavHeader",value:function(e,t,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+e,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,t,!0),i.setUint32(28,t*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,e,!0),r}},{key:"initializeAudioContext",value:function(){var e,t,n=(null===(e=this.outputFormat)||void 0===e?void 0:e.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===(t=this.outputFormat)||void 0===t?void 0:t.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(e){console.error("❌ Failed to create AudioContext:",e),this.audioContext=new(window.AudioContext||window.webkitAudioContext),console.log("ℹ️ Using browser default: ".concat(this.audioContext.sampleRate,"Hz"))}}},{key:"processQueue",value:(r=ze(Ue().m(function e(){var t,n,o,r,i,a,c,s,l=this;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){e.n=1;break}return e.a(2);case 1:if(this.isProcessingQueue=!0,t=this.audioQueue.shift()){e.n=2;break}return this.isProcessingQueue=!1,e.a(2);case 2:if(e.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||this.initializeAudioContext(),"suspended"!==(o=this.audioContext).state){e.n=4;break}return e.n=3,o.resume();case 3:if(!n){e.n=4;break}return e.n=4,new Promise(function(e){return setTimeout(e,50)});case 4:if("running"===o.state){e.n=8;break}if(console.warn("AudioPlayer v2: AudioContext not in running state:",o.state),"suspended"!==o.state){e.n=8;break}return e.n=5,o.resume();case 5:if(!n){e.n=7;break}return e.n=6,new Promise(function(e){return setTimeout(e,50)});case 6:e.n=8;break;case 7:return e.n=8,new Promise(function(e){return setTimeout(e,10)});case 8:return e.n=9,t.arrayBuffer();case 9:return r=e.v,e.n=10,o.decodeAudioData(r);case 10:i=e.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=i,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){l.currentSource=null,l.isProcessingQueue=!1,l.audioQueue.length>0?setTimeout(function(){return l.processQueue()},50):setTimeout(function(){0!==l.audioQueue.length||l.currentSource||(l.isPlaying=!1,l.emit("playbackStopped"))},100)},c.start(),e.n=12;break;case 11:e.p=11,s=e.v,console.error("❌ AudioPlayer v2: Error processing queue:",s),this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 12:return e.a(2)}},e,this,[[2,11]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"reset",value:function(){this.stop(),this.audioQueue=[],this.pcmChunkQueue=[]}},{key:"stopImmediate",value:function(){var e=this.isPlaying||null!==this.currentSource||this.scheduledSources.size>0;if(console.log("🛑 AudioPlayer.stopImmediate() called"),console.log(" isPlaying:",this.isPlaying),console.log(" currentSource:",null!==this.currentSource),console.log(" scheduledSources.size:",this.scheduledSources.size),console.log(" scheduledBuffers:",this.scheduledBuffers),this.currentSource){try{console.log(" Stopping currentSource..."),this.currentSource.stop()}catch(e){console.log(" currentSource already stopped or error:",e.message)}this.currentSource=null}if(this.scheduledSources.size>0){console.log(" Stopping ".concat(this.scheduledSources.size," scheduled sources..."));var t,n=0,o=Be(this.scheduledSources);try{for(o.s();!(t=o.n()).done;){var r=t.value;try{r.stop(),n++}catch(e){console.log(" Source already stopped or not started:",e.message)}}}catch(e){o.e(e)}finally{o.f()}console.log(" Stopped ".concat(n," sources")),this.scheduledSources.clear()}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],this.pcmChunkQueue=[],this.preparedBuffer=[],this.isProcessingPcmQueue=!1,this.isSchedulingFrames=!1,this.nextStartTime=0,this.scheduledBuffers=0,this.clearTranscriptState(),e&&(console.log("🛑 AudioPlayer: Emitting playbackStopped event (stopImmediate called)"),this.emit("playbackStopped"))}},{key:"markNewSentence",value:function(e){this.pendingSentenceText=e,console.log('📝 AudioPlayer: New sentence marked: "'.concat(e.substring(0,40),'..."'))}},{key:"startTranscriptChecker",value:function(){var e=this;if(!this.isCheckingTranscripts){this.isCheckingTranscripts=!0,console.log("📝 AudioPlayer: Transcript checker started");var t=function(){if(e.isCheckingTranscripts&&e.audioContext){var n,o=e.audioContext.currentTime,r=Be(e.sentenceTimings);try{for(r.s();!(n=r.n()).done;){var i=n.value;!i.displayed&&o>=i.startTime&&(i.displayed=!0,console.log("📝 AudioPlayer: Display transcript at ".concat(o.toFixed(3),'s: "').concat(i.text.substring(0,40),'..."')),e.emit("transcriptDisplay",{text:i.text}))}}catch(e){r.e(e)}finally{r.f()}e.isPlaying||e.scheduledBuffers>0?requestAnimationFrame(t):(e.isCheckingTranscripts=!1,console.log("📝 AudioPlayer: Transcript checker stopped"))}};requestAnimationFrame(t)}}},{key:"clearTranscriptState",value:function(){this.pendingSentenceText=null,this.sentenceTimings=[],this.isCheckingTranscripts=!1,console.log("📝 AudioPlayer: Transcript state cleared")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed",outputFormat:this.outputFormat,scheduledBuffers:this.scheduledBuffers,preparedBufferLength:this.preparedBuffer.length,scheduledSourcesCount:this.scheduledSources.size}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null),this.removeAllListeners()}}],o&&Ve(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c}(Se);const Qe=qe;function Ye(e){return Ye="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ye(e)}function $e(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Je(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Je(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Je(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Je(d,"constructor",l),Je(l,"constructor",s),s.displayName="GeneratorFunction",Je(l,r,"GeneratorFunction"),Je(d),Je(d,r,"Generator"),Je(d,o,function(){return this}),Je(d,"toString",function(){return"[object Generator]"}),($e=function(){return{w:i,m:p}})()}function Je(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Je=function(e,t,n,o){function i(t,n){Je(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Je(e,t,n,o)}function Xe(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Ze(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Xe(i,o,r,a,c,"next",e)}function c(e){Xe(i,o,r,a,c,"throw",e)}a(void 0)})}}function et(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function tt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,nt(o.key),o)}}function nt(e){var t=function(e){if("object"!=Ye(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ye(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ye(t)?t:t+""}function ot(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ot=function(){return!!e})()}function rt(e){return rt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},rt(e)}function it(e,t){return it=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},it(e,t)}var at=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=rt(t),function(e,t){if(t&&("object"==Ye(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,ot()?Reflect.construct(t,n||[],rt(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&it(e,t)}(t,e),n=t,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var e,t=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return et(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?et(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(t.s();!(e=t.n()).done;){var n=e.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(e){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(e){t.e(e)}finally{t.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=Ze($e().m(function e(){var t,n,o,r,i,a,c=this;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,"https:"===location.protocol||"localhost"===location.hostname||"127.0.0.1"===location.hostname){e.n=1;break}throw t=new Error("Microphone access requires HTTPS. Please use https:// or test on localhost."),console.error("❌ AudioRecorder:",t.message),this.emit("error",t),t;case 1:if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){e.n=2;break}throw n=new Error("getUserMedia is not supported in this browser. Please use a modern browser."),console.error("❌ AudioRecorder:",n.message),this.emit("error",n),n;case 2:return console.log("🎤 AudioRecorder: Requesting microphone access..."),e.n=3,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 3:if(this.mediaStream=e.v,console.log("✅ AudioRecorder: Microphone access granted"),this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){e.n=4;break}return e.n=4,this.audioContext.resume();case 4:return o=this.getAudioProcessorPath(),e.n=5,this.audioContext.audioWorklet.addModule(o);case 5:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(e){var t=e.data,n=t.type,o=t.data;"pcm_audio_data"===n&&c.emit("audioData",o)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),e.n=7;break;case 6:throw e.p=6,a=e.v,r=a.message,"NotAllowedError"===a.name||"PermissionDeniedError"===a.name?(r="Microphone permission denied. Please allow microphone access in your browser settings and try again.",console.error("❌ AudioRecorder: Permission denied. User needs to grant microphone access.")):"NotFoundError"===a.name||"DevicesNotFoundError"===a.name?(r="No microphone found. Please connect a microphone and try again.",console.error("❌ AudioRecorder: No microphone device found.")):"NotReadableError"===a.name||"TrackStartError"===a.name?(r="Microphone is already in use by another application. Please close other apps using the microphone and try again.",console.error("❌ AudioRecorder: Microphone is busy or not readable.")):a.message&&a.message.includes("not allowed by the user agent")&&(r="Microphone access blocked. On mobile devices, please tap the recording button directly (not from an iframe or popup).",console.error("❌ AudioRecorder: User agent blocked microphone access. This often happens on mobile when not called from direct user interaction.")),(i=new Error(r)).name=a.name,i.originalError=a,console.error("❌ AudioRecorder: Failed to start recording:",i),this.emit("error",i),i;case 7:return e.a(2)}},e,this,[[0,6]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=Ze($e().m(function e(){var t;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:if(e.p=1,!this.audioWorkletNode){e.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),e.n=2,new Promise(function(e){return setTimeout(e,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(e){return e.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){e.n=4;break}return e.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),e.n=6;break;case 5:throw e.p=5,t=e.v,this.emit("error",t),t;case 6:return e.a(2)}},e,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&tt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(Se);function ct(e){return ct="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ct(e)}function st(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,lt(o.key),o)}}function lt(e){var t=function(e){if("object"!=ct(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=ct(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==ct(t)?t:t+""}const ut=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return t=e,n=[{key:"extractPcmFromWav",value:function(e){var t=e instanceof Uint8Array?e:new Uint8Array(e);if(t.length<44)throw new Error("WAV data too short (< 44 bytes)");if("RIFF"!==String.fromCharCode(t[0],t[1],t[2],t[3]))throw new Error("Not a valid WAV file - missing RIFF header");if("WAVE"!==String.fromCharCode(t[8],t[9],t[10],t[11]))throw new Error("Not a valid WAV file - missing WAVE format");for(var n=t[22]|t[23]<<8,o=t[24]|t[25]<<8|t[26]<<16|t[27]<<24,r=t[34]|t[35]<<8,i=-1,a=12;a<t.length-8;a+=4){if("data"===String.fromCharCode(t[a],t[a+1],t[a+2],t[a+3])){i=a;break}a+=4+(t[a+4]|t[a+5]<<8|t[a+6]<<16|t[a+7]<<24)}if(-1===i)throw new Error("No data chunk found in WAV");var c=t[i+4]|t[i+5]<<8|t[i+6]<<16|t[i+7]<<24,s=i+8,l=Math.min(c,t.length-s);return{pcmData:t.slice(s,s+l).buffer,format:{sampleRate:o,channels:n,bitDepth:r}}}},{key:"isWavFile",value:function(e){return e.length>=44&&82===e[0]&&73===e[1]&&70===e[2]&&70===e[3]}},{key:"createWavHeader",value:function(e,t,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+e,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,t,!0),i.setUint32(28,t*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,e,!0),r}},{key:"wrapPcmInWav",value:function(t,n){var o=e.createWavHeader(t.byteLength,n.sampleRate,n.channels||1,n.bitDepth||16),r=new Uint8Array(o.byteLength+t.byteLength);return r.set(new Uint8Array(o),0),r.set(new Uint8Array(t),o.byteLength),r.buffer}}],null&&st(t.prototype,null),n&&st(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();function dt(e){return dt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},dt(e)}function pt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ft(o.key),o)}}function ft(e){var t=function(e){if("object"!=dt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=dt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==dt(t)?t:t+""}const ht=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.codecs={pcm:new Pe,pcmu:new Ae,pcma:new Fe}},(t=[{key:"decodeToPcm",value:function(e,t){var n=null==t?void 0:t.toLowerCase();if(!n||"pcm"===n)return e instanceof ArrayBuffer?e:e instanceof Uint8Array?e.buffer:e;var o=this.codecs[n];if(!o)throw new Error("Unsupported encoding: ".concat(t));var r=e instanceof Uint8Array?e:new Uint8Array(e);return o.decode(r)}},{key:"encodeFromPcm",value:function(e,t){var n=null==t?void 0:t.toLowerCase();if(!n||"pcm"===n)return e;var o=this.codecs[n];if(!o)throw new Error("Unsupported target encoding: ".concat(t));var r=o.encode(e);return r instanceof Uint8Array?r.buffer:r}},{key:"getCodec",value:function(e){var t=null==e?void 0:e.toLowerCase();return this.codecs[t]||null}}])&&pt(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function gt(e){return gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},gt(e)}function vt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,mt(o.key),o)}}function mt(e){var t=function(e){if("object"!=gt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=gt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==gt(t)?t:t+""}const yt=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return t=e,n=[{key:"convert",value:function(t,n,o){if(n===o)return t;if(8===n)throw new Error("Source bit depth cannot be 8-bit (only 16-bit or 24-bit supported)");var r=n/8,i=o/8,a=t.byteLength/r;if(new ArrayBuffer(a*i),16===n&&16===o)return t;if(24===n&&16===o)return e.convert24To16(t);if(16===n&&24===o)return e.convert16To24(t);if(16===n&&8===o)return e.convert16To8(t);if(24===n&&8===o)return e.convert24To8(t);throw new Error("Unsupported bit depth conversion: ".concat(n,"-bit → ").concat(o,"-bit"))}},{key:"convert24To16",value:function(e){for(var t=new Uint8Array(e),n=Math.floor(t.length/3),o=new Int16Array(n),r=0;r<n;r++){var i=t[3*r],a=t[3*r+1],c=t[3*r+2],s=i|a<<8|(255&c)<<16;128&c&&(s|=4278190080),o[r]=Math.max(-32768,Math.min(32767,Math.round(s/256)))}return o.buffer}},{key:"convert16To24",value:function(e){for(var t=new Int16Array(e),n=new Uint8Array(3*t.length),o=0;o<t.length;o++){var r=256*t[o];n[3*o]=255&r,n[3*o+1]=r>>8&255,n[3*o+2]=r>>16&255}return n.buffer}},{key:"convert16To8",value:function(e){for(var t=new Int16Array(e),n=new Uint8Array(t.length),o=0;o<t.length;o++){var r=t[o];n[o]=Math.max(0,Math.min(255,Math.round(r/256+128)))}return n.buffer}},{key:"convert24To8",value:function(t){var n=e.convert24To16(t);return e.convert16To8(n)}}],null&&vt(t.prototype,null),n&&vt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();function bt(e){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},bt(e)}function wt(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return St(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(St(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,St(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,St(d,"constructor",l),St(l,"constructor",s),s.displayName="GeneratorFunction",St(l,r,"GeneratorFunction"),St(d),St(d,r,"Generator"),St(d,o,function(){return this}),St(d,"toString",function(){return"[object Generator]"}),(wt=function(){return{w:i,m:p}})()}function St(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}St=function(e,t,n,o){function i(t,n){St(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},St(e,t,n,o)}function xt(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function kt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ct(o.key),o)}}function Ct(e){var t=function(e){if("object"!=bt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==bt(t)?t:t+""}const Pt=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},t=[{key:"resample",value:(n=wt().m(function e(t,n,o){var r,i,a,c,s,l,u,d,p,f,h,g,v;return wt().w(function(e){for(;;)switch(e.n){case 0:if(n!==o){e.n=1;break}return e.a(2,t);case 1:for(r=new Int16Array(t),i=new Float32Array(r.length),a=1/32768,c=0;c<r.length;c++)i[c]=r[c]*a;return s=Math.ceil(i.length*o/n),l=new OfflineAudioContext(1,s,o),(u=l.createBuffer(1,i.length,n)).getChannelData(0).set(i),(d=l.createBufferSource()).buffer=u,d.connect(l.destination),d.start(),e.n=2,l.startRendering();case 2:for(p=e.v,f=p.getChannelData(0),h=new Int16Array(f.length),g=0;g<f.length;g++)v=Math.max(-1,Math.min(1,f[g])),h[g]=Math.round(32767*v);return e.a(2,h.buffer)}},e)}),o=function(){var e=this,t=arguments;return new Promise(function(o,r){var i=n.apply(e,t);function a(e){xt(i,o,r,a,c,"next",e)}function c(e){xt(i,o,r,a,c,"throw",e)}a(void 0)})},function(e,t,n){return o.apply(this,arguments)})}],t&&kt(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Et(e){return Et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Et(e)}function Tt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ot(o.key),o)}}function Ot(e){var t=function(e){if("object"!=Et(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Et(t)?t:t+""}const At=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return t=e,n=[{key:"convert",value:function(t,n,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(n===o)return t;if(1===n&&1===o)return t;if(1===n&&2===o)return e.monoToStereo(t,r);if(2===n&&1===o)return e.stereoToMono(t,r);throw new Error("Unsupported channel conversion: ".concat(n," → ").concat(o))}},{key:"monoToStereo",value:function(e,t){for(var n=t/8,o=e.byteLength/n,r=new ArrayBuffer(o*n*2),i=new Uint8Array(e),a=new Uint8Array(r),c=0;c<o;c++)for(var s=c*n,l=c*n*2,u=0;u<n;u++)a[l+u]=i[s+u],a[l+n+u]=i[s+u];return r}},{key:"stereoToMono",value:function(e,t){var n=t/8,o=e.byteLength/(2*n),r=new ArrayBuffer(o*n),i=new Uint8Array(e),a=new Uint8Array(r);if(16===t)for(var c=0;c<o;c++){var s=c*n*2,l=s+n,u=(i[s]|i[s+1]<<8)<<16>>16,d=(i[l]|i[l+1]<<8)<<16>>16,p=Math.round((u+d)/2),f=c*n;a[f]=255&p,a[f+1]=p>>8&255}else for(var h=0;h<o;h++)for(var g=h*n*2,v=h*n,m=0;m<n;m++)a[v+m]=i[g+m];return r}}],null&&Tt(t.prototype,null),n&&Tt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();function It(e){return It="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},It(e)}function jt(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Dt(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Dt(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Dt(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Dt(d,"constructor",l),Dt(l,"constructor",s),s.displayName="GeneratorFunction",Dt(l,r,"GeneratorFunction"),Dt(d),Dt(d,r,"Generator"),Dt(d,o,function(){return this}),Dt(d,"toString",function(){return"[object Generator]"}),(jt=function(){return{w:i,m:p}})()}function Dt(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Dt=function(e,t,n,o){function i(t,n){Dt(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Dt(e,t,n,o)}function Ft(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function _t(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ft(Object(n),!0).forEach(function(t){Bt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ft(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Bt(e,t,n){return(t=Ut(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Rt(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Mt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Ut(o.key),o)}}function Ut(e){var t=function(e){if("object"!=It(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=It(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==It(t)?t:t+""}const Nt=function(){return e=function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.requestedFormat=t,this.actualFormat=n,this.encodingConverter=new ht,this.conversionSteps=[],this._analyzeConversions()},t=[{key:"_analyzeConversions",value:function(){this.conversionSteps=[],this.actualFormat.container!==this.requestedFormat.container&&("wav"===this.actualFormat.container?this.conversionSteps.push("extract_wav"):"wav"===this.requestedFormat.container&&this.conversionSteps.push("wrap_wav")),this.actualFormat.encoding!==this.requestedFormat.encoding&&("pcm"!==this.actualFormat.encoding&&this.conversionSteps.push("decode_encoding"),"pcm"!==this.requestedFormat.encoding&&this.conversionSteps.push("encode_encoding")),this.actualFormat.sampleRate!==this.requestedFormat.sampleRate&&this.conversionSteps.push("resample"),this.actualFormat.bitDepth!==this.requestedFormat.bitDepth&&this.conversionSteps.push("convert_bitdepth"),this.actualFormat.channels!==this.requestedFormat.channels&&this.conversionSteps.push("convert_channels")}},{key:"needsConversion",value:function(){return this.conversionSteps.length>0}},{key:"getConversionSteps",value:function(){var e=[];return this.conversionSteps.includes("extract_wav")&&e.push("Extract PCM from WAV (".concat(this.actualFormat.container," → raw)")),this.conversionSteps.includes("decode_encoding")&&e.push("Decode ".concat(this.actualFormat.encoding.toUpperCase()," → PCM")),this.conversionSteps.includes("resample")&&e.push("Resample ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz")),this.conversionSteps.includes("convert_bitdepth")&&e.push("Convert bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit")),this.conversionSteps.includes("convert_channels")&&e.push("Convert channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels)),this.conversionSteps.includes("encode_encoding")&&e.push("Encode PCM → ".concat(this.requestedFormat.encoding.toUpperCase())),this.conversionSteps.includes("wrap_wav")&&e.push("Wrap in WAV container (raw → ".concat(this.requestedFormat.container,")")),e}},{key:"convert",value:(n=jt().m(function e(t){var n,o,r,i;return jt().w(function(e){for(;;)switch(e.n){case 0:if(this.needsConversion()){e.n=1;break}return e.a(2,t instanceof ArrayBuffer?t:t.buffer);case 1:if(n=t instanceof ArrayBuffer?t:t.buffer,o=_t({},this.actualFormat),this.conversionSteps.includes("extract_wav")&&(r=ut.extractPcmFromWav(n),n=r.pcmData,o=_t(_t({},o),{},{container:"raw",sampleRate:r.format.sampleRate,channels:r.format.channels,bitDepth:r.format.bitDepth}),console.log("🔄 AudioFormatConverter: Extracted PCM from WAV",r.format)),this.conversionSteps.includes("decode_encoding")&&(n=this.encodingConverter.decodeToPcm(n,o.encoding),o.encoding="pcm",o.bitDepth=16,console.log("🔄 AudioFormatConverter: Decoded ".concat(this.actualFormat.encoding.toUpperCase()," → PCM"))),24===o.bitDepth&&o.bitDepth!==this.requestedFormat.bitDepth&&(this.conversionSteps.includes("resample")||this.conversionSteps.includes("convert_channels")||24!==this.requestedFormat.bitDepth)&&(n=yt.convert(n,24,16),o.bitDepth=16,console.log("🔄 AudioFormatConverter: Normalized 24-bit → 16-bit PCM")),!this.conversionSteps.includes("resample")){e.n=3;break}return e.n=2,Pt.resample(n,o.sampleRate,this.requestedFormat.sampleRate);case 2:n=e.v,o.sampleRate=this.requestedFormat.sampleRate,console.log("🔄 AudioFormatConverter: Resampled ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz"));case 3:return this.conversionSteps.includes("convert_channels")&&(n=At.convert(n,o.channels,this.requestedFormat.channels,o.bitDepth),o.channels=this.requestedFormat.channels,console.log("🔄 AudioFormatConverter: Converted channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels))),this.conversionSteps.includes("convert_bitdepth")&&(n=yt.convert(n,o.bitDepth,this.requestedFormat.bitDepth),o.bitDepth=this.requestedFormat.bitDepth,console.log("🔄 AudioFormatConverter: Converted bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit"))),this.conversionSteps.includes("encode_encoding")&&(i=this.encodingConverter.encodeFromPcm(n,this.requestedFormat.encoding),n=i instanceof ArrayBuffer?i:i.buffer,o.encoding=this.requestedFormat.encoding,console.log("🔄 AudioFormatConverter: Encoded PCM → ".concat(this.requestedFormat.encoding.toUpperCase()))),this.conversionSteps.includes("wrap_wav")&&(n=ut.wrapPcmInWav(n,o),o.container="wav",console.log("🔄 AudioFormatConverter: Wrapped in WAV container")),console.log("✅ AudioFormatConverter: Conversion complete"),e.a(2,n)}},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(o,r){var i=n.apply(e,t);function a(e){Rt(i,o,r,a,c,"next",e)}function c(e){Rt(i,o,r,a,c,"throw",e)}a(void 0)})},function(e){return o.apply(this,arguments)})}],t&&Mt(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Lt(e){return Lt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Lt(e)}function zt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function Vt(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?zt(Object(n),!0).forEach(function(t){Jt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):zt(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Kt(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Ht(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Ht(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Ht(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Ht(d,"constructor",l),Ht(l,"constructor",s),s.displayName="GeneratorFunction",Ht(l,r,"GeneratorFunction"),Ht(d),Ht(d,r,"Generator"),Ht(d,o,function(){return this}),Ht(d,"toString",function(){return"[object Generator]"}),(Kt=function(){return{w:i,m:p}})()}function Ht(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Ht=function(e,t,n,o){function i(t,n){Ht(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Ht(e,t,n,o)}function Wt(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Gt(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Wt(i,o,r,a,c,"next",e)}function c(e){Wt(i,o,r,a,c,"throw",e)}a(void 0)})}}function qt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Xt(o.key),o)}}function Qt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Qt=function(){return!!e})()}function Yt(e){return Yt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Yt(e)}function $t(e,t){return $t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},$t(e,t)}function Jt(e,t,n){return(t=Xt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Xt(e){var t=function(e){if("object"!=Lt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Lt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Lt(t)?t:t+""}var Zt=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=Yt(t),function(e,t){if(t&&("object"==Lt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Qt()?Reflect.construct(t,n||[],Yt(e).constructor):t.apply(e,n))}(this,t)).version="2.0.0",e.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||e.getDefaultContainer(n),outputEncoding:n.outputEncoding||n.outputCodec||"pcm",outputSampleRate:n.outputSampleRate||16e3,outputChannels:n.outputChannels||1,outputBitDepth:n.outputBitDepth||16,outputFrameDurationMs:n.outputFrameDurationMs||600,outputCodec:n.outputCodec,agentSettingsOverride:n.agentSettingsOverride||null,variables:n.variables||null,autoReconnect:!1!==n.autoReconnect,protocolVersion:n.protocolVersion||2},e.isConnected=!1,e.hasEverConnected=!1,e.isRecording=!1,e.isPlaying=!1,e.isDestroyed=!1,e.outputAudioFormat=null,e.requestedOutputFormat=null,e.formatConverter=null,e.websocket=null,e.conversationId=null,e.transcriptQueue=[],e.currentPlayingSentenceId=null,e.audioFrameCount=0,e.hasRecordedWhileAudioPlaying=!1,e.audioPlayer=new Qe(e.config),e.audioRecorder=new at(e.config),e.setupAudioPlayerEvents(),e.setupAudioRecorderEvents(),e.validateConfig(),console.log("🎵 VoiceSDK v2 initialized:",{version:e.version,outputContainer:e.config.outputContainer,outputEncoding:e.config.outputEncoding,outputSampleRate:e.config.outputSampleRate}),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&$t(e,t)}(t,e),n=t,o=[{key:"getDefaultContainer",value:function(e){return"wav"===e.outputCodec?"wav":"raw"}},{key:"validateInputFormat",value:function(e){var n;if(!e)return"Input format is required";var o=null===(n=e.encoding)||void 0===n?void 0:n.toLowerCase();return o&&t.SUPPORTED_INPUT_ENCODINGS.includes(o)?e.sampleRate&&t.SUPPORTED_INPUT_SAMPLE_RATES.includes(e.sampleRate)?e.bitDepth&&t.SUPPORTED_INPUT_BIT_DEPTHS.includes(e.bitDepth)?e.channels&&t.SUPPORTED_INPUT_CHANNELS.includes(e.channels)?null:"Unsupported input channels: ".concat(e.channels,". Supported: ").concat(t.SUPPORTED_INPUT_CHANNELS.join(", ")):"Unsupported input bit depth: ".concat(e.bitDepth,". Supported: ").concat(t.SUPPORTED_INPUT_BIT_DEPTHS.join(", ")):"Unsupported input sample rate: ".concat(e.sampleRate,". Supported: ").concat(t.SUPPORTED_INPUT_SAMPLE_RATES.join(", ")):"Unsupported input encoding: ".concat(e.encoding,". Supported: ").concat(t.SUPPORTED_INPUT_ENCODINGS.join(", "))}},{key:"validateOutputFormat",value:function(e){var n,o;if(!e)return"Output format is required";var r=null===(n=e.encoding)||void 0===n?void 0:n.toLowerCase();if(!r||!t.SUPPORTED_OUTPUT_ENCODINGS.includes(r))return"Unsupported output encoding: ".concat(e.encoding,". Supported: ").concat(t.SUPPORTED_OUTPUT_ENCODINGS.join(", "));if(!e.sampleRate||!t.SUPPORTED_OUTPUT_SAMPLE_RATES.includes(e.sampleRate))return"Unsupported output sample rate: ".concat(e.sampleRate,". Supported: ").concat(t.SUPPORTED_OUTPUT_SAMPLE_RATES.join(", "));if(!e.bitDepth||!t.SUPPORTED_OUTPUT_BIT_DEPTHS.includes(e.bitDepth))return"Unsupported output bit depth: ".concat(e.bitDepth,". Supported: ").concat(t.SUPPORTED_OUTPUT_BIT_DEPTHS.join(", "));if(!e.channels||!t.SUPPORTED_OUTPUT_CHANNELS.includes(e.channels))return"Unsupported output channels: ".concat(e.channels,". Supported: ").concat(t.SUPPORTED_OUTPUT_CHANNELS.join(", "));var i=null===(o=e.container)||void 0===o?void 0:o.toLowerCase();return i&&t.SUPPORTED_OUTPUT_CONTAINERS.includes(i)?null:"Unsupported output container: ".concat(e.container,". Supported: ").concat(t.SUPPORTED_OUTPUT_CONTAINERS.join(", "))}},{key:"validateConfig",value:function(){var e={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},t=this.validateInputFormat(e);if(t)return console.error("❌ VoiceSDK v2: Invalid input format:",t),void this.emit("error",new Error(t));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 e=this;this.audioPlayer.on("playbackStarted",function(){e.isPlaying=!0,e.emit("playbackStarted"),e.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_started_playing message to server"),e.sendMessage({t:"audio_started_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_started_playing - not connected")}),this.audioPlayer.on("transcriptDisplay",function(t){var n=e.currentPlayingSentenceId?e.currentPlayingSentenceId+1:1;e.currentPlayingSentenceId=n;var o={text:t.text,role:"assistant",sentenceId:n,final:!0,timestamp:Date.now()};console.log("📝 VoiceSDK v2: Emitting synced transcriptDisplay from AudioPlayer:",o),e.emit("transcriptDisplay",o),e.emit("transcript",o)}),this.audioPlayer.on("playbackStopped",function(){e.isPlaying=!1,e.emit("playbackStopped"),e.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_stopped_playing message to server"),e.sendMessage({t:"audio_stopped_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_stopped_playing - not connected")}),this.audioPlayer.on("playbackError",function(t){e.emit("playbackError",t),e.emit("error",t)})}},{key:"setupAudioRecorderEvents",value:function(){var e=this;this.audioRecorder.on("recordingStarted",function(){e.isRecording=!0;var t=e.audioPlayer.getStatus(),n=t.scheduledBuffers&&t.scheduledBuffers>0||t.scheduledSourcesCount&&t.scheduledSourcesCount>0,o=e.isPlaying||t.isPlaying||n;console.log("🎤 VoiceSDK v2: Recording started - checking for barge-in..."),console.log(" VoiceSDK.isPlaying:",e.isPlaying),console.log(" AudioPlayer.isPlaying:",t.isPlaying),console.log(" scheduledBuffers:",t.scheduledBuffers||0),console.log(" scheduledSourcesCount:",t.scheduledSourcesCount||0),console.log(" preparedBufferLength:",t.preparedBufferLength||0),console.log(" isActuallyPlaying:",o),console.log(" hasRecordedWhileAudioPlaying:",e.hasRecordedWhileAudioPlaying),o&&e.hasRecordedWhileAudioPlaying?(console.log("🛑 VoiceSDK v2: Barge-in detected! Stopping audio playback..."),e.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),e.isConnected?(e.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")):console.warn("⚠️ VoiceSDK v2: Cannot send barge_in - not connected")):o&&!e.hasEverRecorded?console.log("ℹ️ VoiceSDK v2: Recording started while audio playing, but this is first recording - skipping barge-in (permission grant scenario)"):console.log("ℹ️ VoiceSDK v2: No audio playing, normal recording start"),e.hasEverRecorded=!0,e.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){e.isRecording&&(e.isRecording=!1,e._bargeInChecked=!1,e.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped (from audioRecorder event)"))}),this.audioRecorder.on("audioData",function(t){if(!e._bargeInChecked&&e.isRecording){e._bargeInChecked=!0;var n=e.audioPlayer.getStatus(),o=n.scheduledBuffers&&n.scheduledBuffers>0||n.scheduledSourcesCount&&n.scheduledSourcesCount>0,r=e.isPlaying||n.isPlaying||o;console.log("🎤 VoiceSDK v2: First audio data received - checking for barge-in..."),console.log(" isActuallyPlaying:",r),console.log(" hasRecordedWhileAudioPlaying:",e.hasRecordedWhileAudioPlaying),r&&e.hasRecordedWhileAudioPlaying?(console.log("🛑 VoiceSDK v2: Barge-in detected on first audio data! Stopping audio playback..."),console.log(" VoiceSDK.isPlaying:",e.isPlaying),console.log(" AudioPlayer.isPlaying:",n.isPlaying),console.log(" scheduledBuffers:",n.scheduledBuffers||0),console.log(" scheduledSourcesCount:",n.scheduledSourcesCount||0),e.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),e.isConnected&&(e.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server"))):r&&!e.hasRecordedWhileAudioPlaying&&(console.log("ℹ️ VoiceSDK v2: First audio data received while audio playing, but this is first time - skipping barge-in (permission grant scenario)"),e.hasRecordedWhileAudioPlaying=!0)}e.isConnected&&e.sendBinary(t)}),this.audioRecorder.on("error",function(t){console.error("❌ AudioRecorder error:",t),e.emit("error",t)})}},{key:"buildWebSocketUrl",value:function(){var e=this.config.websocketUrl,t=new URLSearchParams;if(this.config.agentId&&t.append("agentId",this.config.agentId),this.config.appId&&t.append("appId",this.config.appId),t.toString()){var n=e.includes("?")?"&":"?";return"".concat(e).concat(n).concat(t.toString())}return e}},{key:"connect",value:(l=Gt(Kt().m(function e(){var t,n,o=this;return Kt().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isDestroyed){e.n=1;break}return console.warn("VoiceSDK v2: Cannot connect - SDK is destroyed"),e.a(2,!1);case 1:if(!this.isConnected){e.n=2;break}return console.warn("VoiceSDK v2: Already connected"),e.a(2,!0);case 2:return e.p=2,t=this.buildWebSocketUrl(),console.log("🔌 VoiceSDK v2: Connecting to",t),e.n=3,new Promise(function(e,n){o.websocket=new WebSocket(t),o.websocket.onopen=function(){console.log("✅ VoiceSDK v2: WebSocket connected"),o.isConnected=!0,o.hasEverConnected=!0,o.sendHelloMessage(),o.emit("connected"),e(!0)},o.websocket.onerror=function(e){console.error("❌ VoiceSDK v2: WebSocket error:",e),n(e)},o.websocket.onclose=function(e){console.log("🔌 VoiceSDK v2: WebSocket closed:",e.code,e.reason),o.isConnected=!1,o.isRecording&&o.stopRecording().catch(function(e){return console.error("Error stopping recording:",e)}),o.emit("disconnected",e),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(e){o.handleMessage(e)}});case 3:return e.a(2,e.v);case 4:return e.p=4,n=e.v,console.error("🔌 VoiceSDK v2: Connection failed:",n),this.emit("error",n),e.a(2,!1)}},e,this,[[2,4]])})),function(){return l.apply(this,arguments)})},{key:"sendHelloMessage",value:function(){if(this.isConnected){var e={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},t={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},n=this.validateInputFormat(e);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(t);if(o)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid output format:",o),void this.emit("error",new Error("Invalid output format: ".concat(o)));var r={t:"hello",v:this.config.protocolVersion,inputFormat:e,requestedOutputFormat:t,outputFrameDurationMs:this.config.outputFrameDurationMs};this.config.agentSettingsOverride&&(r.agentSettingsOverride=this.config.agentSettingsOverride),console.log("🔍 VoiceSDK v2: Checking variables:",{hasVariables:!!this.config.variables,variables:this.config.variables,keys:this.config.variables?Object.keys(this.config.variables):[]}),this.config.variables&&Object.keys(this.config.variables).length>0?(r.variables=this.config.variables,console.log("📝 VoiceSDK v2: Including variables in hello:",Object.keys(this.config.variables))):console.log("⚠️ VoiceSDK v2: Variables NOT included - condition failed"),console.log("📤 VoiceSDK v2: Sending hello:",{version:r.v,requestedFormat:r.requestedOutputFormat,variables:r.variables?Object.keys(r.variables):void 0}),console.log("📤 VoiceSDK v2: Requested output format:",{container:r.requestedOutputFormat.container,encoding:r.requestedOutputFormat.encoding,sampleRate:r.requestedOutputFormat.sampleRate,bitDepth:r.requestedOutputFormat.bitDepth}),console.log("📤 VoiceSDK v2: Full hello message being sent:",JSON.stringify(r,null,2));try{this.sendMessage(r)}catch(e){console.error("VoiceSDK v2: Failed to send hello:",e),this.emit("error",e)}}else console.warn("VoiceSDK v2: Cannot send hello - not connected")}},{key:"handleMessage",value:function(e){if(e.data instanceof ArrayBuffer||e.data instanceof Blob)this.handleBinaryMessage(e.data);else try{var t=JSON.parse(e.data);switch("audio"!==t.t&&console.log("📥 VoiceSDK v2: Received message type:",t.t,"Full message:",JSON.stringify(t).substring(0,200)),!this.conversationId&&t.conversationId&&(this.conversationId=t.conversationId,console.log("🔍 VoiceSDK v2: Captured conversationId from message:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),"audio"!==t.t&&console.log("📨 VoiceSDK v2: Received message type:",t.t,t),t.t){case"hello_ack":this.handleHelloAck(t);break;case"transcript":console.log("📝 VoiceSDK v2: Processing transcript message:",t),this.handleTranscript(t);break;case"user_transcript":console.log("📝 VoiceSDK v2: Received user_transcript:",t),this.emit("message",t);break;case"agent_response":if(console.log("📝 VoiceSDK v2: Received agent_response:",t),(t.text||t.transcript)&&(console.log("📝 VoiceSDK v2: agent_response contains transcript data:",t.text||t.transcript),t.sentenceId&&(t.text||t.transcript))){var n={t:"transcript",sentenceId:t.sentenceId,text:t.text||t.transcript,role:t.role||"assistant",final:!1!==t.final,timestamp:t.timestamp||Date.now()};console.log("📝 VoiceSDK v2: Converting agent_response to transcript:",n),this.handleTranscript(n)}this.emit("message",t);break;case"error":this.emit("message",t);break;case"barge_in":this.emit("bargeIn",t),this.stopAudioPlayback();break;case"stop_playing":this.emit("stopPlaying",t),this.stopAudioPlayback();break;case"audio_start":console.log("📝 VoiceSDK v2: Received audio_start with text:",t.text),t.text&&this.audioPlayer&&this.audioPlayer.markNewSentence(t.text),this.emit("message",t);break;default:if(console.log("VoiceSDK v2: Unknown message type:",t.t,"Full message:",JSON.stringify(t).substring(0,300)),(t.text||t.transcript||t.transcription)&&(console.log("📝 VoiceSDK v2: Unknown message contains transcript-like data:",{text:t.text,transcript:t.transcript,transcription:t.transcription,sentenceId:t.sentenceId,role:t.role}),t.sentenceId&&(t.text||t.transcript||t.transcription))){var o={t:"transcript",sentenceId:t.sentenceId,text:t.text||t.transcript||t.transcription,role:t.role||"assistant",final:!1!==t.final,timestamp:t.timestamp||Date.now()};console.log("📝 VoiceSDK v2: Attempting to process unknown message as transcript:",o),this.handleTranscript(o)}this.emit("message",t)}}catch(e){console.error("VoiceSDK v2: Error parsing message:",e)}}},{key:"handleHelloAck",value:function(e){if(console.log("📥 VoiceSDK v2: Received hello_ack:",{hasOutputFormat:!!e.outputAudioFormat,outputFormat:e.outputAudioFormat,hasConversationId:!!e.conversationId,messageType:e.t}),e.conversationId&&(this.conversationId=e.conversationId,console.log("🔍 VoiceSDK v2: Received conversationId:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),e.outputAudioFormat){this.outputAudioFormat=e.outputAudioFormat,this.audioPlayer.setOutputFormat(e.outputAudioFormat),console.log("✅ VoiceSDK v2: Format negotiated by server:",this.outputAudioFormat),this.requestedOutputFormat={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1};var t={container:this.outputAudioFormat.container||"unknown",encoding:this.outputAudioFormat.encoding||"unknown",sampleRate:this.outputAudioFormat.sampleRate||0,bitDepth:this.outputAudioFormat.bitDepth||0,channels:this.outputAudioFormat.channels||0},n=[];if(this.requestedOutputFormat.container!==t.container&&n.push('container: "'.concat(this.requestedOutputFormat.container,'" → "').concat(t.container,'"')),this.requestedOutputFormat.encoding!==t.encoding&&n.push('encoding: "'.concat(this.requestedOutputFormat.encoding,'" → "').concat(t.encoding,'"')),this.requestedOutputFormat.sampleRate!==t.sampleRate&&n.push("sampleRate: ".concat(this.requestedOutputFormat.sampleRate,"Hz → ").concat(t.sampleRate,"Hz")),this.requestedOutputFormat.bitDepth!==t.bitDepth&&n.push("bitDepth: ".concat(this.requestedOutputFormat.bitDepth,"-bit → ").concat(t.bitDepth,"-bit")),this.requestedOutputFormat.channels!==t.channels&&n.push("channels: ".concat(this.requestedOutputFormat.channels," → ").concat(t.channels)),n.length>0){console.warn("⚠️ VoiceSDK v2: Format negotiation mismatch!"),console.warn(" Requested:",this.requestedOutputFormat),console.warn(" Negotiated:",t),console.warn(" Differences:",n.join(", "));try{if(this.formatConverter=new Nt(this.requestedOutputFormat,t),this.formatConverter.needsConversion()){var o=this.formatConverter.getConversionSteps();console.log("🔄 VoiceSDK v2: Format conversion enabled"),console.log(" Conversion steps:",o.join(", ")),console.log(" Audio will be automatically converted to requested format")}}catch(e){console.error("❌ VoiceSDK v2: Failed to create format converter:",e),console.warn(" Will use backend format without conversion"),this.formatConverter=null}}else console.log("✅ VoiceSDK v2: Format perfectly matched!",t),this.formatConverter=null;this.emit("formatNegotiated",this.outputAudioFormat)}else{this.config.protocolVersion>=2?(console.warn("⚠️ VoiceSDK v2: hello_ack received but no outputAudioFormat in response."),console.warn(" This may happen if:"),console.warn(" 1. Backend is not sending outputAudioFormat (check backend logs)"),console.warn(" 2. Hello message missing v2 fields (v, inputFormat, requestedOutputFormat)"),console.warn(" 3. Backend validation failed (check backend error logs)"),console.warn(" Using default format from config...")):console.log("✅ VoiceSDK v2: Connected (v1 legacy mode)");var r={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,channels:this.config.outputChannels||1,bitDepth:this.config.outputBitDepth||16};this.outputAudioFormat=r,this.requestedOutputFormat=r,this.audioPlayer.setOutputFormat(r),this.formatConverter=null}}},{key:"handleTranscript",value:function(e){if(e.sentenceId&&e.text){var t=e.sentenceId,n={text:e.text,role:e.role||"assistant",sentenceId:t,final:!1!==e.final,timestamp:e.timestamp||Date.now()};this.transcriptQueue.push(n),console.log("📝 VoiceSDK v2: Received transcript for sentence",t,":",n.text),console.log(" Transcript queue length:",this.transcriptQueue.length),console.log(" Current playing sentence:",this.currentPlayingSentenceId),console.log("📝 VoiceSDK v2: Displaying transcript for completed sentence",t),this.emit("transcriptDisplay",n),this.currentPlayingSentenceId=t,this.emit("transcript",n)}else console.warn("⚠️ VoiceSDK v2: Invalid transcript message:",e)}},{key:"handleBinaryMessage",value:(s=Gt(Kt().m(function e(t){var n,o,r,i,a,c,s,l,u,d;return Kt().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!(t instanceof Blob)){e.n=2;break}return e.n=1,t.arrayBuffer();case 1:o=e.v,e.n=3;break;case 2:o=t;case 3:if(console.log("📥 VoiceSDK v2: Received audio:",o.byteLength,"bytes"),console.log(" Current outputFormat:",this.outputAudioFormat),console.log(" AudioPlayer outputFormat:",null===(n=this.audioPlayer)||void 0===n?void 0:n.outputFormat),console.log(" Format converter:",this.formatConverter?"active":"none"),r=o,!this.formatConverter||!this.formatConverter.needsConversion()){e.n=7;break}return e.p=4,e.n=5,this.formatConverter.convert(o);case 5:r=e.v,console.log("✅ VoiceSDK v2: Audio converted to requested format"),e.n=7;break;case 6:e.p=6,d=e.v,console.error("❌ VoiceSDK v2: Format conversion failed:",d),console.warn(" Using backend format without conversion"),r=o;case 7:i=this.formatConverter&&this.formatConverter.needsConversion()?this.requestedOutputFormat:this.outputAudioFormat||{container:this.config.outputContainer||"raw",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1},a=i.container||"raw",c=(i.encoding||"pcm").toLowerCase(),"raw"===a?(s=r,"pcm"!==c&&((l=this.audioPlayer.getCodec(c))?(u=l.decode(new Uint8Array(r)),s=u.buffer,console.log("🔄 VoiceSDK v2: Decoded ".concat(c.toUpperCase()," to PCM (").concat(u.byteLength," bytes)"))):console.warn("⚠️ VoiceSDK v2: No codec for ".concat(c,", treating as PCM"))),this.audioPlayer.outputFormat||(console.warn("⚠️ VoiceSDK v2: outputFormat not set on AudioPlayer, setting from playbackFormat"),this.audioPlayer.setOutputFormat(i)),this.audioFrameCount++,this.audioPlayer.playChunk(s)):(this.audioFrameCount++,this.audioPlayer.playAudio(r));case 8:return e.a(2)}},e,this,[[4,6]])})),function(e){return s.apply(this,arguments)})},{key:"sendMessage",value:function(e){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(e)),!0}catch(e){return console.error("VoiceSDK v2: Error sending message:",e),this.emit("error",e),!1}}},{key:"sendBinary",value:function(e){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send audio - not connected"),!1;try{return this.websocket.send(e),!0}catch(e){return console.error("VoiceSDK v2: Error sending audio:",e),this.emit("error",e),!1}}},{key:"disconnect",value:function(){this.isDestroyed||(console.log("🔌 VoiceSDK v2: Disconnecting..."),this.stopRecording(),this.audioPlayer&&this.stopAudioPlayback(),this.websocket&&(this.websocket.close(),this.websocket=null),this.isConnected=!1,this.hasRecordedWhileAudioPlaying=!1)}},{key:"startRecording",value:(c=Gt(Kt().m(function e(){var t,n,o;return Kt().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isConnected){e.n=1;break}throw t=new Error("Not connected to voice server"),this.emit("error",t),t;case 1:if(!this.isRecording){e.n=2;break}return console.warn("VoiceSDK v2: Already recording"),e.a(2,!0);case 2:return console.log("🎤 VoiceSDK v2: Starting recording..."),e.p=3,console.log("🎤 VoiceSDK v2: Requesting microphone permission (mobile-friendly)..."),e.n=4,this.audioRecorder.start();case 4:return this.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId()}),e.a(2,!0);case 5:return e.p=5,o=e.v,console.error("❌ VoiceSDK v2: Failed to start recording:",o),"NotAllowedError"===o.name||"PermissionDeniedError"===o.name?((n=new Error("Microphone permission denied. Please allow microphone access in your browser settings and try again.")).name=o.name,n.originalError=o,this.emit("error",n)):this.emit("error",o),e.a(2,!1)}},e,this,[[3,5]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=Gt(Kt().m(function e(){var t;return Kt().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return console.warn("VoiceSDK v2: Not recording"),e.a(2,!0);case 1:return console.log("🛑 VoiceSDK v2: Stopping recording..."),e.p=2,this.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),this.isRecording=!1,this._bargeInChecked=!1,this.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped (emitted before audioRecorder.stop())"),e.n=3,this.audioRecorder.stop();case 3:return this.stopAudioPlayback(),e.a(2,!0);case 4:return e.p=4,t=e.v,console.error("VoiceSDK v2: Error stopping recording:",t),this.emit("error",t),e.a(2,!1)}},e,this,[[2,4]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=Gt(Kt().m(function e(){return Kt().w(function(e){for(;;)switch(e.n){case 0:if(!this.isRecording){e.n=2;break}return e.n=1,this.stopRecording();case 1:case 3:return e.a(2,e.v);case 2:return e.n=3,this.startRecording();case 4:return e.a(2)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"clearTranscriptState",value:function(){this.currentPlayingSentenceId=null,console.log("📝 VoiceSDK v2: Cleared transcript state")}},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate(),this.clearTranscriptState()}},{key:"handleBargeIn",value:(r=Gt(Kt().m(function e(){return Kt().w(function(e){for(;;)switch(e.n){case 0:if(this.stopAudioPlayback(),this.isRecording){e.n=1;break}return e.n=1,this.startRecording();case 1:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{version:this.version,isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying,outputFormat:this.outputAudioFormat,conversationId:this.conversationId,audioPlayer:this.audioPlayer.getStatus(),audioRecorder:this.audioRecorder.getStatus()}}},{key:"updateConfig",value:function(e){this.config=Vt(Vt({},this.config),e)}},{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&&qt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,l}(Se);Jt(Zt,"SUPPORTED_INPUT_ENCODINGS",["pcm","pcmu","pcma"]),Jt(Zt,"SUPPORTED_INPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),Jt(Zt,"SUPPORTED_INPUT_BIT_DEPTHS",[8,16,24]),Jt(Zt,"SUPPORTED_INPUT_CHANNELS",[1]),Jt(Zt,"SUPPORTED_OUTPUT_ENCODINGS",["pcm","pcmu","pcma"]),Jt(Zt,"SUPPORTED_OUTPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),Jt(Zt,"SUPPORTED_OUTPUT_BIT_DEPTHS",[8,16,24]),Jt(Zt,"SUPPORTED_OUTPUT_CHANNELS",[1]),Jt(Zt,"SUPPORTED_OUTPUT_CONTAINERS",["raw","wav"]);const en=Zt;function tn(e){return tn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},tn(e)}function nn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return on(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(on(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,on(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,on(d,"constructor",l),on(l,"constructor",s),s.displayName="GeneratorFunction",on(l,r,"GeneratorFunction"),on(d),on(d,r,"Generator"),on(d,o,function(){return this}),on(d,"toString",function(){return"[object Generator]"}),(nn=function(){return{w:i,m:p}})()}function on(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}on=function(e,t,n,o){function i(t,n){on(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},on(e,t,n,o)}function rn(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function an(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function cn(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?an(Object(n),!0).forEach(function(t){sn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):an(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function sn(e,t,n){return(t=un(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ln(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,un(o.key),o)}}function un(e){var t=function(e){if("object"!=tn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=tn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==tn(t)?t:t+""}function dn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(dn=function(){return!!e})()}function pn(e){return pn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},pn(e)}function fn(e,t){return fn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},fn(e,t)}var hn=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=(e=function(e,t,n){return t=pn(t),function(e,t){if(t&&("object"==tn(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,dn()?Reflect.construct(t,n||[],pn(e).constructor):t.apply(e,n))}(this,t)).readScriptTagConfig();return e.config=cn({baseWsUrl:"wss://backend.talktopc.com/chat/websocket",appId:n.appId||o.appId,agentId:n.agentId||o.agentId,conversationId:void 0!==n.conversationId?n.conversationId:e.getPersistedConversationId(),forceConversationId:n.forceConversationId,queue:[],inFlight:!1},n),e.fullResponseBuffer="",e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&fn(e,t)}(t,e),n=t,o=[{key:"readScriptTagConfig",value:function(){try{var e=Array.from(document.getElementsByTagName("script")).reverse().find(function(e){return e.dataset&&(e.dataset.appId||e.dataset.agentId)||e.src&&e.src.includes("agent-widget")});return e?{appId:e.dataset.appId,agentId:e.dataset.agentId}:{}}catch(e){return{}}}},{key:"buildWebSocketUrl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,t=new URLSearchParams;return this.config.appId&&t.append("appId",this.config.appId),this.config.agentId&&t.append("agentId",this.config.agentId),this.config.conversationId&&t.append("conversationId",this.config.conversationId),"".concat(e,"?").concat(t.toString())}},{key:"sendMessage",value:(r=nn().m(function e(t){var n=this;return nn().w(function(e){for(;;)if(0===e.n)return e.a(2,new Promise(function(e,o){if(t&&t.trim())if(n.config.appId&&n.config.agentId){var r={text:t,resolve:e,reject:o};n.config.inFlight?n.config.queue.push(r):n.executeTask(r)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},e)}),i=function(){var e=this,t=arguments;return new Promise(function(n,o){var i=r.apply(e,t);function a(e){rn(i,n,o,a,c,"next",e)}function c(e){rn(i,n,o,a,c,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})},{key:"executeTask",value:function(e){var t=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,r=this.buildWebSocketUrl(this.config.baseWsUrl),i=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(i),c=!1,s=!1,l=null,u=function(n){if(!s)try{var o={message:e.text},r=t.config.forceConversationId||t.config.conversationId;r&&(o.conversationId=r,t.config.forceConversationId&&!t.config.conversationId&&(t.config.conversationId=r,t.persistConversationId(r))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",t.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){e.reject(o),t.emit("error",o);try{n.close()}catch(e){}}},d=function(e){return function(){t.config.conversationId?u(e):l=setTimeout(function(){return u(e)},200)}},p=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(e){}var r=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",r)}catch(e){}if("hello"===r.type&&r.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",r.conversationId),t.config.conversationId=r.conversationId,t.persistConversationId(r.conversationId),t.emit&&t.emit("conversationIdChanged",r.conversationId),!s&&n&&1===n.readyState){if(l)try{clearTimeout(l)}catch(e){}u(n)}return}if(!t.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",r.conversationId),t.config.conversationId=r.conversationId,t.persistConversationId(r.conversationId)),"chunk"===r.type&&"string"==typeof r.content)t.fullResponseBuffer+=r.content,t.emit("chunk",r.content);else if("done"===r.type){try{var i=r.text||r.content||r.answer||r.message||"";i&&!t.fullResponseBuffer&&(t.fullResponseBuffer=i)}catch(e){}!t.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",r.conversationId),t.config.conversationId=r.conversationId),t.persistConversationId(t.config.conversationId),t.emit("done",{text:t.fullResponseBuffer}),e.resolve({conversationId:t.config.conversationId,fullText:t.fullResponseBuffer});try{n.close()}catch(e){}}else if("error"===r.type){var a=new Error(r.message||"Server error");t.emit("error",a),e.reject(a);try{n.close()}catch(e){}}}catch(e){}}},f=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,t.emit("domainError",o),e.reject(o),t.config.inFlight=!1,void t.drainQueue()}t.config.inFlight=!1,t.drainQueue()},h=new WebSocket(r);h.onopen=d(h),h.onmessage=p(h),h.onerror=(o=h,function(n){if(!c){c=!0;try{o.close()}catch(e){}var r=new WebSocket(a);return r.onopen=d(r),r.onmessage=p(r),r.onerror=function(n){t.emit("error",n),e.reject(n)},void(r.onclose=f)}t.emit("error",n),e.reject(n)}),h.onclose=f}},{key:"drainQueue",value:function(){if(0!==this.config.queue.length&&!this.config.inFlight){var e=this.config.queue.shift();this.executeTask(e)}}},{key:"persistConversationId",value:function(e){try{e&&localStorage.setItem("ttp_text_chat_conversation_id",e)}catch(e){}}},{key:"getPersistedConversationId",value:function(){try{return localStorage.getItem("ttp_text_chat_conversation_id")||null}catch(e){return null}}},{key:"updateConfig",value:function(e){this.config=cn(cn({},this.config),e)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&ln(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(l),gn=n(540),vn=n(848);function mn(e){return mn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},mn(e)}function yn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function bn(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?yn(Object(n),!0).forEach(function(t){wn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):yn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function wn(e,t,n){return(t=function(e){var t=function(e){if("object"!=mn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=mn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==mn(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Sn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return xn(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(xn(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,xn(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,xn(d,"constructor",l),xn(l,"constructor",s),s.displayName="GeneratorFunction",xn(l,r,"GeneratorFunction"),xn(d),xn(d,r,"Generator"),xn(d,o,function(){return this}),xn(d,"toString",function(){return"[object Generator]"}),(Sn=function(){return{w:i,m:p}})()}function xn(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}xn=function(e,t,n,o){function i(t,n){xn(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},xn(e,t,n,o)}function kn(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Cn(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,l=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==t);s=!0);}catch(e){l=!0,r=e}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw r}}return c}}(e,t)||function(e,t){if(e){if("string"==typeof e)return Pn(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Pn(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Pn(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}const En=function(e){var t=e.websocketUrl,n=e.agentId,o=e.appId,r=e.voice,i=void 0===r?"default":r,a=e.language,c=void 0===a?"en":a,s=e.autoReconnect,l=void 0===s||s,u=e.agentSettingsOverride,d=void 0===u?null:u,p=e.onConnected,f=e.onDisconnected,h=e.onRecordingStarted,g=e.onRecordingStopped,v=e.onPlaybackStarted,m=e.onPlaybackStopped,y=e.onError,b=e.onMessage,w=e.onBargeIn,S=e.onStopPlaying,x=e.onStartConversation,k=e.onEndConversation,C=e.className,P=void 0===C?"":C,E=e.style,T=void 0===E?{}:E,O=e.children,A=Cn((0,gn.useState)(!1),2),I=A[0],j=A[1],D=Cn((0,gn.useState)(!1),2),F=D[0],_=D[1],B=Cn((0,gn.useState)(!1),2),R=(B[0],B[1]),M=Cn((0,gn.useState)("Disconnected"),2),U=(M[0],M[1]),N=(0,gn.useRef)(null);(0,gn.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(t)),N.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),N.current.destroy(),N.current=null);var e=new ve({websocketUrl:t,agentId:n,appId:o,voice:i,language:c,autoReconnect:l,agentSettingsOverride:d,onStartConversation:x,onEndConversation:k});return e.on("connected",function(){j(!0),U("Connected"),null==p||p()}),e.on("disconnected",function(){j(!1),U("Disconnected"),null==f||f()}),e.on("recordingStarted",function(){_(!0),null==h||h()}),e.on("recordingStopped",function(){_(!1),null==g||g()}),e.on("playbackStarted",function(){R(!0),null==v||v()}),e.on("playbackStopped",function(){R(!1),null==m||m()}),e.on("error",function(e){null==y||y(e)}),e.on("message",function(e){null==b||b(e)}),e.on("bargeIn",function(e){null==w||w(e)}),e.on("stopPlaying",function(e){null==S||S(e)}),N.current=e,e.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(t)),N.current&&(N.current.destroy(),N.current=null)}},[t,n,o,i,c,d]);var L=function(){var e,t=(e=Sn().m(function e(){var t;return Sn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(N.current){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,N.current.toggleRecording();case 2:e.n=4;break;case 3:e.p=3,t=e.v,console.error("Error toggling recording:",t);case 4:return e.a(2)}},e,null,[[1,3]])}),function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){kn(i,o,r,a,c,"next",e)}function c(e){kn(i,o,r,a,c,"throw",e)}a(void 0)})});return function(){return t.apply(this,arguments)}}(),z=(0,vn.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,vn.jsx)("div",{style:{fontSize:"20px"},children:F?"🔴":"🎤"}),(0,vn.jsx)("div",{children:F?"Stop Listening":"Start Listening"})]});return(0,vn.jsx)("button",{className:"voice-button ".concat(F?"recording":""," ").concat(P),style:bn({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:F?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},T),onClick:L,disabled:!I,children:O||z})};function Tn(e){return Tn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Tn(e)}function On(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return An(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(An(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,An(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,An(d,"constructor",l),An(l,"constructor",s),s.displayName="GeneratorFunction",An(l,r,"GeneratorFunction"),An(d),An(d,r,"Generator"),An(d,o,function(){return this}),An(d,"toString",function(){return"[object Generator]"}),(On=function(){return{w:i,m:p}})()}function An(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}An=function(e,t,n,o){function i(t,n){An(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},An(e,t,n,o)}function In(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function jn(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){In(i,o,r,a,c,"next",e)}function c(e){In(i,o,r,a,c,"throw",e)}a(void 0)})}}function Dn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function Fn(e,t,n){return(t=Bn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Bn(o.key),o)}}function Bn(e){var t=function(e){if("object"!=Tn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Tn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Tn(t)?t:t+""}var Rn=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Dn(Object(n),!0).forEach(function(t){Fn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Dn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({websocketUrl:t.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:t.agentId,voice:t.voice||"default",language:t.language||"en",container:t.container||document.body,buttonText:t.buttonText||"Start Listening",buttonClass:t.buttonClass||"voice-button"},t),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new ve({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},t=[{key:"setupEventListeners",value:function(){var e=this;this.voiceSDK.on("connected",function(){var t,n;e.isConnected=!0,e.updateButton(),null===(t=(n=e.options).onConnected)||void 0===t||t.call(n)}),this.voiceSDK.on("disconnected",function(){var t,n;e.isConnected=!1,e.updateButton(),null===(t=(n=e.options).onDisconnected)||void 0===t||t.call(n)}),this.voiceSDK.on("recordingStarted",function(){var t,n;e.isRecording=!0,e.updateButton(),null===(t=(n=e.options).onRecordingStarted)||void 0===t||t.call(n)}),this.voiceSDK.on("recordingStopped",function(){var t,n;e.isRecording=!1,e.updateButton(),null===(t=(n=e.options).onRecordingStopped)||void 0===t||t.call(n)}),this.voiceSDK.on("playbackStarted",function(){var t,n;e.isPlaying=!0,null===(t=(n=e.options).onPlaybackStarted)||void 0===t||t.call(n)}),this.voiceSDK.on("playbackStopped",function(){var t,n;e.isPlaying=!1,null===(t=(n=e.options).onPlaybackStopped)||void 0===t||t.call(n)}),this.voiceSDK.on("error",function(t){var n,o;null===(n=(o=e.options).onError)||void 0===n||n.call(o,t)}),this.voiceSDK.on("message",function(t){var n,o;null===(n=(o=e.options).onMessage)||void 0===n||n.call(o,t)}),this.voiceSDK.on("bargeIn",function(t){var n,o;null===(n=(o=e.options).onBargeIn)||void 0===n||n.call(o,t)}),this.voiceSDK.on("stopPlaying",function(t){var n,o;null===(n=(o=e.options).onStopPlaying)||void 0===n||n.call(o,t)})}},{key:"createButton",value:function(){var e=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return e.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var e=this.isRecording?"🔴":"🎤",t=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(e,"</span>\n <span>").concat(t,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=jn(On().m(function e(){var t;return On().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,this.voiceSDK.connect();case 1:e.n=3;break;case 2:e.p=2,t=e.v,console.error("Failed to connect:",t);case 3:return e.a(2)}},e,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=jn(On().m(function e(){var t;return On().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.voiceSDK){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,this.voiceSDK.toggleRecording();case 2:e.n=4;break;case 3:e.p=3,t=e.v,console.error("Error toggling recording:",t);case 4:return e.a(2)}},e,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(e){this.voiceSDK.updateConfig(e)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],t&&_n(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Mn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Un(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Un(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Un(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Un(d,"constructor",l),Un(l,"constructor",s),s.displayName="GeneratorFunction",Un(l,r,"GeneratorFunction"),Un(d),Un(d,r,"Generator"),Un(d,o,function(){return this}),Un(d,"toString",function(){return"[object Generator]"}),(Mn=function(){return{w:i,m:p}})()}function Un(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Un=function(e,t,n,o){function i(t,n){Un(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Un(e,t,n,o)}function Nn(e){return Nn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Nn(e)}function Ln(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function zn(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Ln(i,o,r,a,c,"next",e)}function c(e){Ln(i,o,r,a,c,"throw",e)}a(void 0)})}}function Vn(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Kn(o.key),o)}}function Kn(e){var t=function(e){if("object"!=Nn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Nn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Nn(t)?t:t+""}var Hn=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),console.log("🚀 AgentSDK v2.1.8 initialized with config:",t),this.config=t,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.wasListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(e){return console.error("SDK Error:",e)},this.onTranscript=function(e){},this.onAgentSpeaking=function(e){},this.onConversationStart=t.onConversationStart||function(){},this.onConversationEnd=t.onConversationEnd||function(){},this.onBargeIn=t.onBargeIn||function(){},this.onAudioStartPlaying=t.onAudioStartPlaying||function(){},this.onAudioStoppedPlaying=t.onAudioStoppedPlaying||function(){},this.onSubtitleDisplay=t.onSubtitleDisplay||function(){}},t=[{key:"connect",value:(o=zn(Mn().m(function e(t){var n,o=this;return Mn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,t){e.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new en({websocketUrl:t,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en",protocolVersion:2,outputContainer:this.config.outputContainer||"raw",outputEncoding:this.config.outputEncoding||"pcm",outputSampleRate:this.config.outputSampleRate||44100,outputChannels:this.config.outputChannels||1,outputBitDepth:this.config.outputBitDepth||16}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(e){if(o.isConnected=!1,e&&1008===e.code&&e.reason&&(e.reason.includes("Domain not whitelisted")||e.reason.includes("domain")||e.reason.includes("whitelist"))){var t=new Error("DOMAIN_NOT_WHITELISTED");t.reason=e.reason,t.code=e.code,o.onError(t)}if((o.isListening||o.wasListening)&&(console.log("🎤 [AGENT SDK] disconnected event - calling onConversationEnd hook (isListening:",o.isListening,", wasListening:",o.wasListening,")"),o.onConversationEnd&&"function"==typeof o.onConversationEnd))try{o.onConversationEnd(),console.log("🎤 [AGENT SDK] ✅ onConversationEnd hook called from disconnected event"),o.wasListening=!1}catch(e){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationEnd from disconnected:",e)}o.onDisconnected()}),this.voiceSDK.on("domainError",function(e){o.onError(e)}),this.voiceSDK.on("error",function(e){o.onError(e)}),this.voiceSDK.on("message",function(e){o.handleWebSocketMessage(e)}),this.voiceSDK.on("recordingStarted",function(){if(o.isListening=!0,o.wasListening=!0,o.onConversationStart&&"function"==typeof o.onConversationStart)try{o.onConversationStart()}catch(e){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationStart:",e)}}),this.voiceSDK.on("recordingStopped",function(){console.log("🎤 [AGENT SDK] recordingStopped event received");var e=o.isListening;if(o.isListening=!1,e&&o.onConversationEnd&&"function"==typeof o.onConversationEnd)try{console.log("🎤 [AGENT SDK] ✅ Calling onConversationEnd hook from recordingStopped"),o.onConversationEnd(),console.log("🎤 [AGENT SDK] ✅ onConversationEnd hook called successfully"),o.wasListening=!1}catch(e){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationEnd:",e)}}),this.voiceSDK.on("playbackStarted",function(){o.onAgentSpeaking(!0),o.onAudioStartPlaying()}),this.voiceSDK.on("playbackStopped",function(){o.onAgentSpeaking(!1),o.onAudioStoppedPlaying()}),this.voiceSDK.on("bargeIn",function(e){o.onBargeIn(e)}),this.voiceSDK.on("transcriptDisplay",function(e){console.log("📝 [AGENT SDK] transcriptDisplay event received:",e),e&&e.text&&(console.log("📝 [AGENT SDK] Calling onTranscript with text:",e.text),o.onTranscript&&"function"==typeof o.onTranscript?o.onTranscript(e.text):console.warn("📝 [AGENT SDK] ⚠️ onTranscript is not a function!",Nn(o.onTranscript))),o.onSubtitleDisplay(e)}),e.n=2,this.voiceSDK.connect();case 2:e.n=4;break;case 3:throw e.p=3,n=e.v,this.onError(n),n;case 4:return e.a(2)}},e,this,[[0,3]])})),function(e){return o.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(e){switch(e.t||e.type){case"connected":case"hello_ack":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(e.user_transcription||e.text||e.transcript);break;case"agent_response":case"barge_in":case"stop_playing":default:break;case"error":this.onError(new Error(e.message||e.error||"Unknown error"))}}},{key:"startListening",value:(n=zn(Mn().m(function e(){var t;return Mn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){e.n=5;break}return e.p=1,console.log("🎤 AgentSDK: Starting recording..."),e.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),e.n=4;break;case 3:throw e.p=3,t=e.v,console.error("❌ AgentSDK: Failed to start recording:",t),t;case 4:e.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return e.a(2)}},e,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(e){this.voiceSDK&&this.isConnected&&this.voiceSDK.sendMessage({t:"update_variables",variables:e})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],t&&Vn(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Wn(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Gn(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(Gn(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,Gn(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,Gn(d,"constructor",l),Gn(l,"constructor",s),s.displayName="GeneratorFunction",Gn(l,r,"GeneratorFunction"),Gn(d),Gn(d,r,"Generator"),Gn(d,o,function(){return this}),Gn(d,"toString",function(){return"[object Generator]"}),(Wn=function(){return{w:i,m:p}})()}function Gn(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Gn=function(e,t,n,o){function i(t,n){Gn(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Gn(e,t,n,o)}function qn(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Qn(){var e=navigator.userAgent,t=/iPad|iPhone|iPod/.test(e)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,n=/Android/.test(e),o=/Mac/.test(e)&&!t,r=/Win/.test(e),i=/Chrome/.test(e)&&!/Edg|OPR/.test(e),a=/Safari/.test(e)&&!/Chrome/.test(e),c=/Firefox/.test(e),s=/Edg/.test(e),l=/SamsungBrowser/.test(e),u="unknown";t?u="safari":l?u="samsung":i?u="chrome":a?u="safari":c?u="firefox":s&&(u="edge");var d="unknown";return t?d="ios":n?d="android":o?d="mac":r&&(d="windows"),{platform:d,browser:u,isIOS:t,isAndroid:n,isMac:o,isWindows:r,isMobile:t||n,isDesktop:!t&&!n}}function Yn(){return $n.apply(this,arguments)}function $n(){var e;return e=Wn().m(function e(){var t;return Wn().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!navigator.permissions||!navigator.permissions.query){e.n=2;break}return e.n=1,navigator.permissions.query({name:"microphone"});case 1:return t=e.v,e.a(2,t.state);case 2:e.n=4;break;case 3:e.p=3,e.v,console.log("⚠️ MicPermissionUtils: Permissions API not available or not supported for microphone");case 4:return e.a(2,"unknown")}},e,null,[[0,3]])}),$n=function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){qn(i,o,r,a,c,"next",e)}function c(e){qn(i,o,r,a,c,"throw",e)}a(void 0)})},$n.apply(this,arguments)}function Jn(e){var t=e.platform,n=e.browser,o={ios:{title:"Enable Microphone on iPhone/iPad",icon:"📱",steps:["Tap the <strong>lock icon 🔒</strong>, <strong>information icon ℹ️</strong>, or <strong>AA icon</strong> in the address bar","Tap <strong>Website Settings</strong> or <strong>Permissions</strong>","Find <strong>Microphone</strong> and set it to <strong>Allow</strong>","Return to this page and refresh"],altTitle:"Alternative Method",altSteps:["Open the <strong>Settings</strong> app on your device","Scroll down and tap <strong>Safari</strong> (or your browser app)",'Tap <strong>Microphone</strong> under "Settings for Websites"',"Set it to <strong>Allow</strong> or <strong>Ask</strong>","Return to this page and refresh"],note:"On iOS, you can also change permissions in the browser address bar or in device Settings.",canOpenSettings:!0,settingsButtonText:"Open Settings App"},android_chrome:{title:"Enable Microphone in Chrome",icon:"🤖",steps:["Tap the <strong>lock icon 🔒</strong>, <strong>information icon ℹ️</strong>, or <strong>settings icon ⋮</strong> in the address bar","Tap <strong>Permissions</strong>","Tap <strong>Microphone</strong>","Select <strong>Allow</strong>","The page will refresh automatically"],altTitle:"Alternative Method",altSteps:["Tap the <strong>⋮ menu</strong> (three dots)","Tap <strong>Settings → Site settings → Microphone</strong>","Find this website and set to <strong>Allow</strong>"],canOpenSettings:!0,settingsButtonText:"Open App Settings"},android_firefox:{title:"Enable Microphone in Firefox",icon:"🦊",steps:["Tap the <strong>lock icon 🔒</strong> or <strong>information icon ℹ️</strong> in the address bar","Tap <strong>Edit Site Permissions</strong>","Toggle <strong>Microphone</strong> to enabled","Refresh the page"],canOpenSettings:!1},android_samsung:{title:"Enable Microphone in Samsung Browser",icon:"📱",steps:["Tap the <strong>menu icon</strong> (three lines)","Tap <strong>Settings → Sites and downloads</strong>","Tap <strong>Site permissions → Microphone</strong>","Find this website and set to <strong>Allow</strong>","Return and refresh the page"],canOpenSettings:!1},desktop_chrome:{title:"Enable Microphone in Chrome",icon:"🌐",steps:["Click the <strong>lock icon 🔒</strong> or <strong>information icon ℹ️</strong> in the address bar (left side)","Find <strong>Microphone</strong> in the dropdown menu",'Change it from "Block" to <strong>Allow</strong>',"Click the <strong>Refresh</strong> button or press F5"],showAddressBarHint:!0,canOpenSettings:!1},desktop_safari:{title:"Enable Microphone in Safari",icon:"🧭",steps:["Click <strong>Safari</strong> in the menu bar (top of screen)","Click <strong>Settings for This Website...</strong>","Find <strong>Microphone</strong> in the popup","Change it to <strong>Allow</strong>","Close settings and refresh the page"],canOpenSettings:!1},desktop_firefox:{title:"Enable Microphone in Firefox",icon:"🦊",steps:["Click the <strong>lock icon 🔒</strong> in the address bar",'Click the <strong>X</strong> next to "Blocked" for Microphone',"Refresh the page (press F5)","Click <strong>Allow</strong> when prompted again"],note:"Firefox requires you to clear the block and then re-allow on the next prompt.",showAddressBarHint:!0,canOpenSettings:!1},desktop_edge:{title:"Enable Microphone in Edge",icon:"🌐",steps:["Click the <strong>lock icon 🔒</strong> in the address bar","Find <strong>Microphone</strong> in the permissions list","Change it to <strong>Allow</strong>","Refresh the page"],showAddressBarHint:!0,canOpenSettings:!1},unknown:{title:"Enable Microphone Access",icon:"🎤",steps:["Look for a <strong>lock icon 🔒</strong>, <strong>information icon ℹ️</strong>, or <strong>settings icon</strong> in your browser's address bar","Find the <strong>Microphone</strong> permission setting","Change it to <strong>Allow</strong>","Refresh this page"],canOpenSettings:!1}};return"ios"===t?o.ios:"android"===t?o["android_".concat(n)]||o.android_chrome:o["desktop_".concat(n)]||o.desktop_chrome}function Xn(e){var t=e.isIOS,n=e.isAndroid,o=e.browser;if(t)try{return window.location.href="app-settings:",!0}catch(e){return console.warn("Could not open iOS settings:",e),!1}if(n&&"chrome"===o)try{return window.location.href="intent:#Intent;action=android.settings.APPLICATION_DETAILS_SETTINGS;data=package:com.android.chrome;end",!0}catch(e){return console.warn("Could not open Android settings:",e),!1}return!1}function Zn(e){return Zn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Zn(e)}function eo(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,to(o.key),o)}}function to(e){var t=function(e){if("object"!=Zn(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Zn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Zn(t)?t:t+""}function no(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return oo(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?oo(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function oo(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}var ro=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.overlay=null,this.modal=null},(t=[{key:"createOverlay",value:function(){var e=document.createElement("div");return e.className="mic-permission-overlay",e.style.cssText="\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.6);\n backdrop-filter: blur(4px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10000;\n padding: 20px;\n animation: mic-fadeIn 0.2s ease-out;\n ",document.getElementById("mic-permission-styles")||this.injectStyles(),e}},{key:"injectStyles",value:function(){if(!document.getElementById("mic-permission-styles")){var e=document.createElement("style");e.id="mic-permission-styles",e.textContent="\n @keyframes mic-fadeIn {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n \n @keyframes mic-slideUp {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n \n @keyframes mic-bounce {\n 0%, 100% { transform: translateY(0); }\n 50% { transform: translateY(-5px); }\n }\n \n .mic-permission-overlay {\n position: fixed;\n inset: 0;\n background: rgba(0, 0, 0, 0.6);\n backdrop-filter: blur(4px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10000;\n padding: 20px;\n animation: mic-fadeIn 0.2s ease-out;\n }\n \n .mic-permission-modal {\n background: #ffffff;\n border-radius: 16px;\n box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);\n max-width: 480px;\n width: 100%;\n padding: 32px;\n position: relative;\n animation: mic-slideUp 0.3s ease-out;\n max-height: 90vh;\n overflow-y: auto;\n }\n \n .mic-permission-modal__close {\n position: absolute;\n top: 16px;\n right: 16px;\n background: none;\n border: none;\n font-size: 20px;\n cursor: pointer;\n color: #6b7280;\n width: 32px;\n height: 32px;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n }\n \n .mic-permission-modal__close:hover {\n background: #e5e7eb;\n }\n \n .mic-permission-modal__icon {\n font-size: 48px;\n text-align: center;\n margin-bottom: 16px;\n }\n \n .mic-permission-modal__title {\n font-size: 24px;\n font-weight: 700;\n color: #111827;\n margin: 0 0 12px;\n line-height: 1.3;\n text-align: center;\n }\n \n .mic-permission-modal__description {\n color: #6b7280;\n font-size: 16px;\n line-height: 1.6;\n margin: 0 0 20px;\n text-align: center;\n }\n \n .mic-permission-modal__highlight {\n display: flex;\n align-items: center;\n gap: 12px;\n background: linear-gradient(135deg, #dbeafe, #ede9fe);\n padding: 16px 20px;\n border-radius: 8px;\n margin-bottom: 20px;\n border: 1px solid #bfdbfe;\n }\n \n .mic-permission-modal__highlight-icon {\n font-size: 24px;\n animation: mic-bounce 1s infinite;\n }\n \n .mic-permission-modal__status {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n background: #fef2f2;\n color: #ef4444;\n padding: 12px 16px;\n border-radius: 8px;\n margin-bottom: 20px;\n font-weight: 500;\n }\n \n .mic-permission-modal__note {\n display: flex;\n align-items: flex-start;\n gap: 10px;\n background: #fffbeb;\n color: #92400e;\n padding: 12px 16px;\n border-radius: 8px;\n margin-bottom: 20px;\n font-size: 14px;\n line-height: 1.5;\n border: 1px solid #fde68a;\n }\n \n .mic-permission-modal__steps {\n margin-bottom: 20px;\n }\n \n .mic-permission-modal__steps h3 {\n font-size: 14px;\n font-weight: 600;\n color: #6b7280;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n margin: 0 0 12px;\n }\n \n .mic-permission-modal__steps ol {\n margin: 0;\n padding-left: 24px;\n counter-reset: step-counter;\n list-style: none;\n }\n \n .mic-permission-modal__steps li {\n position: relative;\n padding: 12px 0 12px 16px;\n border-left: 2px solid #e5e7eb;\n color: #111827;\n font-size: 15px;\n line-height: 1.5;\n counter-increment: step-counter;\n }\n \n .mic-permission-modal__steps li::before {\n content: counter(step-counter);\n position: absolute;\n left: -14px;\n top: 10px;\n width: 24px;\n height: 24px;\n background: #4f46e5;\n color: white;\n border-radius: 50%;\n font-size: 12px;\n font-weight: 600;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n \n .mic-permission-modal__steps li:last-child {\n border-left-color: transparent;\n }\n \n .mic-permission-modal__actions {\n display: flex;\n flex-direction: column;\n gap: 10px;\n margin-top: 24px;\n }\n \n .mic-permission-modal__btn {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n padding: 14px 24px;\n border-radius: 8px;\n font-size: 16px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s;\n border: none;\n width: 100%;\n }\n \n .mic-permission-modal__btn--primary {\n background: #4f46e5;\n color: white;\n }\n \n .mic-permission-modal__btn--primary:hover {\n background: #4338ca;\n transform: translateY(-1px);\n }\n \n .mic-permission-modal__btn--secondary {\n background: #e5e7eb;\n color: #111827;\n }\n \n .mic-permission-modal__btn--secondary:hover {\n background: #d1d5db;\n }\n \n .mic-permission-modal__footer {\n text-align: center;\n font-size: 13px;\n color: #6b7280;\n margin-top: 20px;\n margin-bottom: 0;\n }\n \n .mic-permission-modal__visual-guide {\n width: 100%;\n max-width: 380px;\n height: auto;\n margin: 20px auto;\n border-radius: 8px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);\n display: block;\n }\n \n .mic-permission-modal__visual-guide-container {\n text-align: center;\n margin: 20px 0;\n }\n \n @media (max-width: 480px) {\n .mic-permission-modal {\n padding: 24px 20px;\n margin: 10px;\n max-height: 85vh;\n }\n \n .mic-permission-modal__title {\n font-size: 20px;\n }\n \n .mic-permission-modal__icon {\n font-size: 40px;\n }\n \n .mic-permission-modal__visual-guide {\n max-width: 100%;\n }\n }\n ",document.head.appendChild(e)}}},{key:"close",value:function(){this.overlay&&this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=null,this.modal=null}},{key:"show",value:function(){this.overlay&&this.modal&&document.body.appendChild(this.overlay)}}])&&eo(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function io(e,t){var n=new ro,o=n.createOverlay(),r=Qn(),i=document.createElement("div");return i.className="mic-permission-modal",i.innerHTML='\n <div class="mic-permission-modal__icon">🎤</div>\n <h2 class="mic-permission-modal__title">Enable Your Microphone</h2>\n <p class="mic-permission-modal__description">\n To start a voice call with our agent, we need access to your microphone.\n </p>\n <div class="mic-permission-modal__highlight">\n <span class="mic-permission-modal__highlight-icon">👆</span>\n <span>Please click <strong>"Allow"</strong> on the next popup</span>\n </div>\n '.concat(r.isIOS?'\n <div class="mic-permission-modal__note">\n <span>ℹ️</span>\n <span>On iPhone/iPad, you may need to allow microphone access in your device Settings.</span>\n </div>\n ':"",'\n <div class="mic-permission-modal__actions">\n <button class="mic-permission-modal__btn mic-permission-modal__btn--primary" data-action="accept">\n Continue\n </button>\n <button class="mic-permission-modal__btn mic-permission-modal__btn--secondary" data-action="cancel">\n Not Now\n </button>\n </div>\n '),o.appendChild(i),n.overlay=o,n.modal=i,i.querySelector('[data-action="accept"]').addEventListener("click",function(){n.close(),e()}),i.querySelector('[data-action="cancel"]').addEventListener("click",function(){n.close(),t()}),o.addEventListener("click",function(e){e.target===o&&(n.close(),t())}),n.show(),n}function ao(e,t){var n,o,r,i=new ro,a=i.createOverlay(),c=Qn(),s=Jn(c),l=document.createElement("div");l.className="mic-permission-modal";var u="";s.altSteps&&s.altSteps.length>0&&(u='\n <div style="margin-top: 20px; border-top: 1px solid #e5e7eb; padding-top: 16px;">\n <button class="mic-permission-modal__alt-toggle" style="background: none; border: none; color: #4f46e5; font-size: 14px; font-weight: 500; cursor: pointer; padding: 0; margin-bottom: 12px;">\n ▼ '.concat(s.altTitle||"Alternative method",'\n </button>\n <ol style="margin: 0; padding-left: 20px; display: none;">\n ').concat(s.altSteps.map(function(e){return'<li style="padding: 8px 0; font-size: 14px; color: #6b7280;">'.concat(e,"</li>")}).join(""),"\n </ol>\n </div>\n "));var d=function(e){var t,n=e.platform,o=e.browser,r=document.getElementsByTagName("script"),i="",a=no(r);try{for(a.s();!(t=a.n()).done;){var c=t.value.src;if(c&&(c.includes("agent-widget.js")||c.includes("ttp-agent-sdk")||c.includes("ttp-sdk-front")))try{new URL(c),i=c.substring(0,c.lastIndexOf("/"));break}catch(e){var s=c.match(/^(.*\/)[^\/]+$/);if(s){i=s[1];break}}}}catch(e){a.e(e)}finally{a.f()}var l;if(l="ios"===n?"ios-settings.svg":"android"===n?"android-chrome.svg":"chrome"===o?"desktop-chrome.svg":"safari"===o?"desktop-safari.svg":"firefox"===o?"desktop-firefox.svg":"edge"===o?"desktop-edge.svg":"desktop-chrome.svg",!i||""===i||i.startsWith("/")){var u,d=no(r);try{for(d.s();!(u=d.n()).done;){var p=u.value.src;if(p&&(p.includes("cdn.talktopc.com")||p.includes("talktopc.com"))){if(p.includes("/ttp-agent-sdk/")||p.includes("/ttp-sdk-front/")){var f=p.match(/(https?:\/\/[^\/]+(?:\/[^\/]+)*)/);if(f){i=f[1].replace(/\/[^\/]+\.js$/,"");break}}if(!i&&(p.includes("cdn.talktopc.com")||p.includes("talktopc.com"))){i="https://cdn.talktopc.com/ttp-agent-sdk";break}}}}catch(e){d.e(e)}finally{d.f()}if(!i||""===i)if(window.location.hostname.includes("cdn.talktopc.com")||window.location.hostname.includes("talktopc.com"))i="https://cdn.talktopc.com/ttp-agent-sdk";else{var h=window.location.pathname.split("/");h.pop(),(i=window.location.origin+h.join("/"))&&i!==window.location.origin||(i=window.location.origin)}}i=i.replace(/\/$/,"");var g="".concat(i,"/shared/mic-permission-assets/").concat(l);return"undefined"!=typeof console&&console.log&&console.log("[MicPermission] Visual guide path:",g,"Base path:",i,"Platform:",n,"Browser:",o),g}(c);l.innerHTML='\n <button class="mic-permission-modal__close" data-action="close">✕</button>\n <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 20px;">\n <span style="font-size: 32px;">'.concat(s.icon,'</span>\n <h2 class="mic-permission-modal__title" style="text-align: left; margin: 0;">').concat(s.title,'</h2>\n </div>\n <div class="mic-permission-modal__status">\n <span>🚫</span>\n <span>Microphone access is currently blocked</span>\n </div>\n ').concat(s.note?'\n <div class="mic-permission-modal__note">\n <span>ℹ️</span>\n <span>'.concat(s.note,"</span>\n </div>\n "):"",'\n <div class="mic-permission-modal__visual-guide-container">\n <img src="').concat(d,'" alt="Visual guide for enabling microphone" class="mic-permission-modal__visual-guide" \n onerror="console.error(\'[MicPermission] Failed to load image:\', this.src); this.style.display=\'none\';" \n onload="console.log(\'[MicPermission] Image loaded successfully:\', this.src);" />\n </div>\n <div class="mic-permission-modal__steps">\n <h3>Follow these steps:</h3>\n <ol>\n ').concat(s.steps.map(function(e){return"<li>".concat(e,"</li>")}).join(""),"\n </ol>\n </div>\n ").concat(u,'\n <div class="mic-permission-modal__actions">\n ').concat(s.canOpenSettings?'\n <button class="mic-permission-modal__btn mic-permission-modal__btn--primary" data-action="open-settings">\n '.concat(s.settingsButtonText||"Open Settings","\n </button>\n "):"","\n ").concat(s.showAddressBarHint?'\n <button class="mic-permission-modal__btn mic-permission-modal__btn--primary" data-action="show-hint">\n Show Me Where\n </button>\n ':"",'\n <button class="mic-permission-modal__btn mic-permission-modal__btn--secondary" data-action="refresh">\n 🔄 Refresh Page\n </button>\n </div>\n <p class="mic-permission-modal__footer">\n After enabling microphone access, return here and click "Refresh Page"\n </p>\n '),a.appendChild(l),i.overlay=a,i.modal=l,null===(n=l.querySelector('[data-action="close"]'))||void 0===n||n.addEventListener("click",function(){i.close(),e()}),null===(o=l.querySelector('[data-action="open-settings"]'))||void 0===o||o.addEventListener("click",function(){Xn(c)}),null===(r=l.querySelector('[data-action="refresh"]'))||void 0===r||r.addEventListener("click",function(){window.location.reload()});var p=l.querySelector('[data-action="show-hint"]');p&&p.addEventListener("click",function(){i.close(),e(),function(){var e=document.getElementById("mic-address-bar-hint");e&&e.remove(),Qn();var t,n=document.getElementsByTagName("script"),o="",r=no(n);try{for(r.s();!(t=r.n()).done;){var i=t.value.src;if(i&&(i.includes("agent-widget.js")||i.includes("ttp-agent-sdk")||i.includes("ttp-sdk-front")))try{new URL(i),o=i.substring(0,i.lastIndexOf("/"));break}catch(e){var a=i.match(/^(.*\/)[^\/]+$/);if(a){o=a[1];break}}}}catch(e){r.e(e)}finally{r.f()}if(!o||""===o||o.startsWith("/")){var c,s=no(n);try{for(s.s();!(c=s.n()).done;){var l=c.value.src;if(l&&(l.includes("cdn.talktopc.com")||l.includes("talktopc.com"))){if(l.includes("/ttp-agent-sdk/")||l.includes("/ttp-sdk-front/")){var u=l.match(/(https?:\/\/[^\/]+(?:\/[^\/]+)*)/);if(u){o=u[1].replace(/\/[^\/]+\.js$/,"");break}}if(!o&&(l.includes("cdn.talktopc.com")||l.includes("talktopc.com"))){o="https://cdn.talktopc.com/ttp-agent-sdk";break}}}}catch(e){s.e(e)}finally{s.f()}if(!o||""===o)if(window.location.hostname.includes("cdn.talktopc.com")||window.location.hostname.includes("talktopc.com"))o="https://cdn.talktopc.com/ttp-agent-sdk";else{var d=window.location.pathname.split("/");d.pop(),(o=window.location.origin+d.join("/"))&&o!==window.location.origin||(o=window.location.origin)}}o=o.replace(/\/$/,"");var p="".concat(o,"/shared/mic-permission-assets/address-bar-hint.svg"),f=document.createElement("div");f.id="mic-address-bar-hint",f.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n z-index: 10001;\n padding: 10px 20px;\n pointer-events: none;\n animation: mic-fadeIn 0.3s ease-out;\n display: flex;\n justify-content: center;\n ";var h=document.createElement("div");h.style.cssText="\n display: flex;\n align-items: center;\n gap: 12px;\n background: #f59e0b;\n color: white;\n padding: 12px 20px;\n border-radius: 0 0 8px 8px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n pointer-events: all;\n animation: mic-slideDown 0.3s ease-out;\n max-width: 540px;\n ";var g=document.createElement("div");g.style.cssText="\n flex-shrink: 0;\n ";var v=document.createElement("img");v.src=p,v.alt="Address bar hint",v.style.cssText="\n width: auto;\n height: 80px;\n display: block;\n ",v.onerror=function(){g.style.display="none"},g.appendChild(v);var m=document.createElement("div");m.style.cssText="\n display: flex;\n flex-direction: column;\n gap: 4px;\n flex: 1;\n ";var y=document.createElement("div");y.style.cssText="\n font-size: 15px;\n font-weight: 500;\n ",y.innerHTML="Click the <strong>lock icon 🔒</strong>, <strong>information icon ℹ️</strong>, or <strong>settings icon ⋮</strong> in the address bar to enable microphone";var b=document.createElement("button");if(b.style.cssText="\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 28px;\n height: 28px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 14px;\n transition: background 0.2s;\n flex-shrink: 0;\n ",b.textContent="✕",b.addEventListener("click",function(){f.remove()}),b.addEventListener("mouseenter",function(){b.style.background="rgba(255, 255, 255, 0.3)"}),b.addEventListener("mouseleave",function(){b.style.background="rgba(255, 255, 255, 0.2)"}),!document.getElementById("mic-address-bar-hint-styles")){var w=document.createElement("style");w.id="mic-address-bar-hint-styles",w.textContent="\n @keyframes mic-slideDown {\n from {\n opacity: 0;\n transform: translateY(-100%);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n \n @keyframes mic-pointUp {\n 0%, 100% {\n transform: translate(0, 0);\n }\n 50% {\n transform: translate(-5px, -5px);\n }\n }\n ",document.head.appendChild(w)}m.appendChild(y),h.appendChild(g),h.appendChild(m),h.appendChild(b),f.appendChild(h),document.body.appendChild(f),setTimeout(function(){f.parentNode&&(f.style.opacity="0",f.style.transition="opacity 0.3s ease-out",setTimeout(function(){f.parentNode&&f.remove()},300))},1e4)}()});var f=l.querySelector(".mic-permission-modal__alt-toggle");if(f&&s.altSteps){var h=f.nextElementSibling;h&&(h.style.display="none",f.addEventListener("click",function(){"none"===h.style.display?(h.style.display="block",f.innerHTML="▼ ".concat(s.altTitle||"Alternative method")):(h.style.display="none",f.innerHTML="▶ ".concat(s.altTitle||"Alternative method"))}))}return a.addEventListener("click",function(t){t.target===a&&(i.close(),e())}),i.show(),i}function co(e){var t=new ro,n=t.createOverlay(),o=document.createElement("div");return o.className="mic-permission-modal",o.innerHTML='\n <div class="mic-permission-modal__icon">🎤❌</div>\n <h2 class="mic-permission-modal__title">No Microphone Found</h2>\n <p class="mic-permission-modal__description">\n We couldn\'t detect a microphone on your device. Please make sure:\n </p>\n <ul style="list-style: none; padding: 0; margin: 0 0 24px;">\n <li style="padding: 10px 0 10px 32px; position: relative; color: #111827; border-bottom: 1px solid #e5e7eb;">\n <span style="position: absolute; left: 0; font-size: 18px;">☐</span>\n Your microphone is properly connected\n </li>\n <li style="padding: 10px 0 10px 32px; position: relative; color: #111827; border-bottom: 1px solid #e5e7eb;">\n <span style="position: absolute; left: 0; font-size: 18px;">☐</span>\n Your microphone is not muted at the hardware level\n </li>\n <li style="padding: 10px 0 10px 32px; position: relative; color: #111827;">\n <span style="position: absolute; left: 0; font-size: 18px;">☐</span>\n No other app is exclusively using the microphone\n </li>\n </ul>\n <div class="mic-permission-modal__actions">\n <button class="mic-permission-modal__btn mic-permission-modal__btn--primary" data-action="retry">\n Retry\n </button>\n <button class="mic-permission-modal__btn mic-permission-modal__btn--secondary" data-action="close">\n Close\n </button>\n </div>\n ',n.appendChild(o),t.overlay=n,t.modal=o,o.querySelector('[data-action="retry"]').addEventListener("click",function(){window.location.reload()}),o.querySelector('[data-action="close"]').addEventListener("click",function(){t.close(),e()}),n.addEventListener("click",function(o){o.target===n&&(t.close(),e())}),t.show(),t}function so(e){return so="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},so(e)}function lo(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return uo(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(uo(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,uo(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,uo(d,"constructor",l),uo(l,"constructor",s),s.displayName="GeneratorFunction",uo(l,r,"GeneratorFunction"),uo(d),uo(d,r,"Generator"),uo(d,o,function(){return this}),uo(d,"toString",function(){return"[object Generator]"}),(lo=function(){return{w:i,m:p}})()}function uo(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}uo=function(e,t,n,o){function i(t,n){uo(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},uo(e,t,n,o)}function po(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function fo(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){po(i,o,r,a,c,"next",e)}function c(e){po(i,o,r,a,c,"throw",e)}a(void 0)})}}function ho(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,go(o.key),o)}}function go(e){var t=function(e){if("object"!=so(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=so(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==so(t)?t:t+""}var vo=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=t,this.audioStream=null,this.callStartTime=null,this.callTimerInterval=null,this.sdk=null,this.isActive=!1,this.sdk=new Hn({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,variables:t.variables||{},language:t.language||"en",outputContainer:t.outputContainer,outputEncoding:t.outputEncoding,outputSampleRate:t.outputSampleRate,outputChannels:t.outputChannels,outputBitDepth:t.outputBitDepth,onConversationStart:t.onConversationStart,onConversationEnd:t.onConversationEnd,onBargeIn:t.onBargeIn,onAudioStartPlaying:t.onAudioStartPlaying,onAudioStoppedPlaying:t.onAudioStoppedPlaying,onSubtitleDisplay:t.onSubtitleDisplay}),this.setupSDKEventHandlers()},t=[{key:"setupSDKEventHandlers",value:function(){var e=this;this.sdk.onTranscript=function(t){console.log("📝 [VOICE INTERFACE] onTranscript called with text:",t),e.updateTranscript(t)},this.sdk.onAgentSpeaking=function(e){var t=document.getElementById("voiceAvatarActive");t&&(e?t.classList.add("speaking"):t.classList.remove("speaking"))},this.sdk.onDisconnected=function(){console.log("🔌 WebSocket disconnected, hanging up call..."),e.isActive&&(e.isActive=!1,e.endVoiceCall())},this.sdk.onError=function(t){console.error("❌ Voice SDK Error:",t),t&&("DOMAIN_NOT_WHITELISTED"===t.message||t.message&&t.message.includes("Domain not whitelisted"))?e.showDomainError():e.showError(t.message||t)}}},{key:"t",value:function(e){var t,n,o=this.config.language||"en";return((null===(t=this.config.translations)||void 0===t?void 0:t[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[e]||e}},{key:"getTooltip",value:function(e){var t,n=null===(t=this.config.tooltips)||void 0===t?void 0:t[e];return null!=n?n:{mute:this.t("mute"),speaker:this.t("speaker"),endCall:this.t("endCall")}[e]||""}},{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 e=this.config.avatarBackgroundColor||"#667eea",t=this.config.avatarActiveBackgroundColor||this.config.avatarBackgroundColor||"#667eea",n=this.config.statusTitleColor||"#1e293b",o=this.config.statusSubtitleColor||"#64748b",r=this.config.startCallButtonColor||"#667eea",i=this.config.startCallButtonTextColor||"#FFFFFF",a=this.config.transcriptBackgroundColor||"#FFFFFF",c=this.config.transcriptTextColor||"#1e293b",s=this.config.transcriptLabelColor||"#94a3b8",l=this.config.controlButtonColor||"#FFFFFF",u=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(e," 0%, ").concat(t," 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: clamp(40px, 9vh, 80px);\n margin: 0;\n box-shadow: 0 8px 30px rgba(102, 126, 234, 0.3);\n transition: all 0.3s ease;\n flex-shrink: 1;\n position: relative;\n }\n \n .voice-avatar-active {\n animation: avatarPulse 2s ease-in-out infinite;\n }\n \n @keyframes avatarPulse {\n 0%, 100% { \n transform: scale(1);\n }\n 50% { \n transform: scale(1.05);\n }\n }\n \n .voice-avatar-active.speaking {\n animation: avatarSpeak 0.5s ease-in-out infinite;\n }\n \n @keyframes avatarSpeak {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.08); }\n }\n \n /* Voice Rings Animation */\n .voice-rings {\n position: absolute;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n }\n \n .voice-ring {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n border: 2px solid rgba(102, 126, 234, 0.3);\n border-radius: 50%;\n opacity: 0;\n animation: ringExpand 2s ease-out infinite;\n }\n \n .voice-ring:nth-child(2) { animation-delay: 0.5s; }\n .voice-ring:nth-child(3) { animation-delay: 1s; }\n \n @keyframes ringExpand {\n 0% {\n width: 100%;\n height: 100%;\n opacity: 0.6;\n }\n 100% {\n width: 160%;\n height: 160%;\n opacity: 0;\n }\n }\n \n /* Voice Status - Scales with container */\n .voice-status {\n text-align: center;\n margin: 0;\n flex-shrink: 1;\n min-height: 0;\n }\n \n .voice-status-title {\n font-size: clamp(12px, 3vh, 20px);\n font-weight: 600;\n color: ").concat(n,";\n margin-bottom: clamp(2px, 0.5vh, 4px);\n line-height: 1.2;\n }\n \n .voice-status-subtitle {\n font-size: clamp(10px, 2vh, 14px);\n color: ").concat(o,";\n line-height: 1.2;\n }\n \n /* Start Call Button - Scales with container */\n .start-call-btn {\n margin: 0;\n width: min(280px, 70vw);\n height: clamp(48px, 8vh, 64px);\n border-radius: clamp(24px, 4vh, 32px);\n border: none;\n background: ").concat(r,";\n color: ").concat(i,";\n font-size: clamp(14px, 2.5vh, 18px);\n font-weight: 600;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: clamp(8px, 1.5vh, 12px);\n box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);\n transition: all 0.3s ease;\n flex-shrink: 0;\n }\n \n .start-call-btn svg {\n width: clamp(22px, 4vh, 32px);\n height: clamp(22px, 4vh, 32px);\n }\n \n .start-call-btn:hover {\n transform: translateY(-2px);\n box-shadow: 0 12px 28px rgba(102, 126, 234, 0.5);\n }\n \n .start-call-btn:active {\n transform: translateY(-1px);\n }\n \n /* Voice Transcript - Scales with container */\n .voice-transcript {\n background: ").concat(a,";\n padding: clamp(6px, 1.5vh, 12px);\n border-radius: 10px;\n width: min(360px, calc(100% - 40px));\n margin: 0;\n min-height: clamp(100px, 18vh, 140px);\n max-height: clamp(120px, 22vh, 160px);\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(l,";\n color: ").concat(u,";\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(e){var t=this,n=document.getElementById("startCallBtn"),o=document.getElementById("endCallBtn"),r=document.getElementById("muteBtn"),i=document.getElementById("speakerBtn");n&&(n.onclick=function(){return t.startVoiceCall()}),o&&(o.onclick=function(){return t.endVoiceCall()}),r&&(r.onclick=function(){return t.toggleMute()}),i&&(i.onclick=function(){return t.toggleSpeaker()});var a=function(){var e=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",e+1,")"),t.adjustSizesForContainer(),0===e&&setTimeout(function(){return t.adjustSizesForContainer()},500)):e<15?(console.log("⏳ Interface not ready yet (height:",null==n?void 0:n.clientHeight,"), retrying... (attempt",e+1,")"),setTimeout(function(){return a(e+1)},250)):(console.warn("⚠️ Interface never became fully ready, adjusting sizes anyway"),t.adjustSizesForContainer())};setTimeout(function(){return a()},200),window.addEventListener("resize",function(){console.log("🔄 Window resized, re-adjusting sizes"),t.adjustSizesForContainer()})}},{key:"getSignedUrl",value:(r=fo(lo().m(function e(){var t,n,o,r,i,a,c;return lo().w(function(e){for(;;)switch(e.n){case 0:if(this.config.getSessionUrl){e.n=2;break}if(this.config.agentId){e.n=1;break}throw new Error("agentId is required");case 1:return t=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"),e.a(2,"".concat(t,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){e.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),e.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=e.v).ok){e.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return e.n=5,r.json();case 5:return i=e.v,e.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){e.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),e.n=7,this.config.getSessionUrl(a);case 7:return c=e.v,e.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 e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"adjustSizesForContainer",value:function(){var e=document.getElementById("voiceInterface");if(e){var t=e.clientHeight,n=e.clientWidth;console.log("📏 Container size:",t,"x",n);var o,r,i,a,c,s,l,u,d,p=document.getElementById("voiceIdleState"),f=document.getElementById("voiceActiveState"),h=p&&"none"!==p.style.display,g=f&&"none"!==f.style.display;console.log("👁️ Visible state - Idle:",h,"Active:",g),t<=350?(d=5,o=70,r=35,i=11,a=9,c=32,s=100,l=42,u=48):t<=450?(d=7,o=110,r=55,i=15,a=11,c=38,s=110,l=52,u=58):t<=550?(d=8,o=140,r=70,i=16,a=12,c=42,s=120,l=56,u=64):t<=700?(d=10,o=130,r=65,i=18,a=13,c=46,s=130,l=60,u=70):(d=12,o=150,r=75,i=20,a=14,c=50,s=140,l=66,u=76),document.querySelectorAll("#voiceIdleState, #voiceActiveState").forEach(function(e){e.style.gap="".concat(d,"px")});var v=document.querySelectorAll(".voice-avatar, .voice-avatar-active");console.log("🤖 Found",v.length,"avatars, setting size to",o,"px"),v.forEach(function(e){e.style.width="".concat(o,"px"),e.style.height="".concat(o,"px"),e.style.fontSize="".concat(r,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(e){return e.style.fontSize="".concat(i,"px")}),document.querySelectorAll(".voice-status-subtitle").forEach(function(e){return e.style.fontSize="".concat(a,"px")});var m=document.querySelector(".voice-transcript");m&&(m.style.minHeight="".concat(s,"px"),m.style.maxHeight="".concat(s,"px"),m.style.height="".concat(s,"px"),m.style.width="min(360px, ".concat(n-40,"px)"),m.style.boxSizing="border-box");var y=document.querySelector(".transcript-label");y&&(y.style.fontSize="".concat(Math.max(8,i-4),"px"));var b=document.querySelector(".transcript-text");b&&(b.style.fontSize="".concat(Math.max(10,i-2),"px")),document.querySelectorAll(".voice-control-btn.secondary").forEach(function(e){e.style.width="".concat(l,"px"),e.style.height="".concat(l,"px");var t=e.querySelector("svg");if(t){var n=.65*l;t.style.setProperty("width","".concat(n,"px"),"important"),t.style.setProperty("height","".concat(n,"px"),"important"),t.style.setProperty("min-width","".concat(n,"px"),"important"),t.style.setProperty("min-height","".concat(n,"px"),"important")}});var w=document.querySelector(".voice-control-btn.primary");if(w){w.style.width="".concat(u,"px"),w.style.height="".concat(u,"px");var S=w.querySelector("svg");if(S){var x=.7*u;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;t<=350?(C=48,P=14):t<=450?(C=52,P=15):t<=550?(C=58,P=17):t<=700?(C=62,P=18):(C=64,P=18),k.style.height="".concat(C,"px"),k.style.fontSize="".concat(P,"px");var E=k.querySelector("svg");if(E){var T=Math.max(22,.5*C);E.style.width="".concat(T,"px"),E.style.height="".concat(T,"px")}}console.log("✅ Sizes adjusted - Avatar:",o,"Status:",c,"Transcript:",s,"Buttons:",l)}else console.warn("⚠️ voiceInterface not found, skipping size adjustment")}},{key:"startVoiceCall",value:(o=fo(lo().m(function e(){var t,n=this;return lo().w(function(e){for(;;)switch(e.n){case 0:if(!this.isActive){e.n=1;break}return console.log("⚠️ Voice call already active"),e.a(2);case 1:return console.log("🎤 Starting voice call..."),e.n=2,Yn();case 2:if(t=e.v,console.log("📋 Current permission state: ".concat(t)),"denied"!==t){e.n=3;break}return console.log("🚫 Permission is denied, showing blocked modal..."),Qn(),ao(function(){console.log("Blocked modal closed")}),e.a(2);case 3:if("prompt"!==t&&"unknown"!==t){e.n=4;break}return console.log("📋 Permission is in prompt state, showing pre-prompt modal..."),e.a(2,new Promise(function(e){io(fo(lo().m(function t(){return lo().w(function(t){for(;;)switch(t.n){case 0:return console.log("✅ Pre-prompt accepted, proceeding with voice call..."),t.n=1,n.proceedWithVoiceCall();case 1:e();case 2:return t.a(2)}},t)})),function(){console.log("❌ Pre-prompt cancelled"),e()})}));case 4:return e.n=5,this.proceedWithVoiceCall();case 5:return e.a(2)}},e,this)})),function(){return o.apply(this,arguments)})},{key:"proceedWithVoiceCall",value:(n=fo(lo().m(function e(){var t,n,o,r,i,a,c,s,l=this;return lo().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,t=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState"),o=document.getElementById("voiceInterface"),t&&(t.style.display="none"),n&&(n.style.display="flex"),setTimeout(function(){return l.adjustSizesForContainer()},50),o&&(o.scrollTop=0),e.n=1,this.getSignedUrl();case 1:if(r=e.v,console.log("🔗 Got signed URL:",r),!this.sdk||!this.sdk.isConnected){e.n=5;break}return console.log("🔄 SDK already connected, disconnecting for clean retry..."),e.p=2,this.sdk.disconnect(),e.n=3,new Promise(function(e){return setTimeout(e,100)});case 3:e.n=5;break;case 4:e.p=4,c=e.v,console.warn("Warning: Error disconnecting existing connection:",c);case 5:return e.n=6,this.sdk.connect(r);case 6:i=e.v,console.log("✅ Connected to WebSocket, connected:",i),a=0;case 7:if(this.sdk.isConnected||!(a<50)){e.n=9;break}return e.n=8,new Promise(function(e){return setTimeout(e,100)});case 8:a++,e.n=7;break;case 9:if(!this.sdk.isConnected){e.n=11;break}return console.log("✅ WebSocket ready, starting listening..."),e.n=10,this.sdk.startListening();case 10:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var e=Date.now()-l.callStartTime,t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(t.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3),e.n=13;break;case 11:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),e.n=12,this.sdk.startListening();case 12:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var e=Date.now()-l.callStartTime,t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(t.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3);case 13:console.log("✅ Voice call started successfully"),e.n=15;break;case 14:if(e.p=14,s=e.v,console.error("❌ Error starting voice call:",s),this.isActive=!1,this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&this.sdk.isConnected)try{this.sdk.disconnect()}catch(e){console.warn("Error disconnecting SDK on error:",e)}"NotAllowedError"===s.name||"PermissionDeniedError"===s.name?(Qn(),ao(function(){l.resetUIState()})):"NotFoundError"===s.name||"DevicesNotFoundError"===s.name?co(function(){l.resetUIState()}):(this.showError(s.message||s),this.resetUIState());case 15:return e.a(2)}},e,this,[[2,4],[0,14]])})),function(){return n.apply(this,arguments)})},{key:"resetUIState",value:function(){var e=document.getElementById("voiceIdleState"),t=document.getElementById("voiceActiveState");e&&(e.style.display="flex"),t&&(t.style.display="none")}},{key:"endVoiceCall",value:function(){var e=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(e){return e.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null);var t=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState");t&&(t.style.display="flex"),n&&(n.style.display="none"),setTimeout(function(){return e.adjustSizesForContainer()},50);var o=document.getElementById("transcriptText");o&&(o.textContent=this.t("transcriptWillAppear"),o.classList.add("empty"));var r=document.getElementById("voiceAvatarActive");r&&r.classList.remove("speaking"),console.log("✅ Voice call ended")}},{key:"updateTranscript",value:function(e){console.log("📝 [VOICE INTERFACE] updateTranscript called with text:",e);var t=document.getElementById("transcriptText");t?(console.log("📝 [VOICE INTERFACE] Found transcript element, updating text"),t.textContent=e,t.classList.remove("empty")):console.warn("📝 [VOICE INTERFACE] ⚠️ transcriptText element not found!")}},{key:"showError",value:function(e){var t=document.getElementById("transcriptText");t&&(t.textContent="".concat(this.t("error"),": ").concat(e),t.classList.remove("empty"))}},{key:"showDomainError",value:function(){var e=document.getElementById("transcriptText");if(e){var t=this.t("domainNotValidated"),n=this.t("domainErrorMessage");e.innerHTML='<div style="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;">'.concat(t,'</div><div style="font-size: 14px; color: #991B1B; line-height: 1.5;">').concat(n,"</div>"),e.classList.remove("empty")}}},{key:"toggleMute",value:function(){if(this.sdk&&this.isActive){var e=null;if(this.sdk.voiceSDK&&this.sdk.voiceSDK.audioRecorder&&this.sdk.voiceSDK.audioRecorder.mediaStream&&(e=this.sdk.voiceSDK.audioRecorder.mediaStream.getAudioTracks()[0]),!e&&this.audioStream&&(e=this.audioStream.getAudioTracks()[0]),e){e.enabled=!e.enabled;var t=document.getElementById("muteBtn"),n=null==t?void 0:t.querySelector(".mute-icon"),o=null==t?void 0:t.querySelector(".mute-cross");t&&n&&o&&(e.enabled?(n.style.stroke="",o.style.display="none",t.classList.remove("muted")):(n.style.stroke="#9ca3af",o.style.display="block",t.classList.add("muted"))),console.log(e.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(e){return e.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&(this.sdk.disconnect(),this.sdk=null)}}],t&&ho(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o,r}();function mo(e){return mo="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},mo(e)}function yo(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return bo(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(bo(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,bo(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,bo(d,"constructor",l),bo(l,"constructor",s),s.displayName="GeneratorFunction",bo(l,r,"GeneratorFunction"),bo(d),bo(d,r,"Generator"),bo(d,o,function(){return this}),bo(d,"toString",function(){return"[object Generator]"}),(yo=function(){return{w:i,m:p}})()}function bo(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}bo=function(e,t,n,o){function i(t,n){bo(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},bo(e,t,n,o)}function wo(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function So(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){wo(i,o,r,a,c,"next",e)}function c(e){wo(i,o,r,a,c,"throw",e)}a(void 0)})}}function xo(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ko(o.key),o)}}function ko(e){var t=function(e){if("object"!=mo(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=mo(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==mo(t)?t:t+""}var Co=function(){return e=function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=t,this.sdk=n,this.streamingEl=null,this.hasStartedStreaming=!1,this.isActive=!1,this.eventHandlers={autoResize:null,keydown:null},this.eventHandlersSetup=!1},t=[{key:"t",value:function(e){var t,n,o=this.config.language||"en";return((null===(t=this.config.translations)||void 0===t?void 0:t[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[e]||e}},{key:"generateHTML",value:function(){var e,t,n,o,r,i,a,c,s,l=this.config.inputPlaceholder||(null===(e=this.config.panel)||void 0===e?void 0:e.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(l,'" 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!==(t=this.config.sendButtonHint)&&void 0!==t&&t.text||null!==(n=this.config.panel)&&void 0!==n&&null!==(n=n.sendButtonHint)&&void 0!==n&&n.text?'\n <div class="send-button-hint" style="color: '.concat((null===(o=this.config.sendButtonHint)||void 0===o?void 0:o.color)||(null===(r=this.config.panel)||void 0===r||null===(r=r.sendButtonHint)||void 0===r?void 0:r.color)||"#6B7280","; font-size: ").concat((null===(i=this.config.sendButtonHint)||void 0===i?void 0:i.fontSize)||(null===(a=this.config.panel)||void 0===a||null===(a=a.sendButtonHint)||void 0===a?void 0:a.fontSize)||"12px",'; text-align: center; margin-top: 4px;">\n ').concat((null===(c=this.config.sendButtonHint)||void 0===c?void 0:c.text)||(null===(s=this.config.panel)||void 0===s||null===(s=s.sendButtonHint)||void 0===s?void 0:s.text),"\n </div>\n "):"","\n </div>\n </div>")}},{key:"generateCSS",value:function(){var e,t,n,o,r,i,a,c,s,l,u,d,p,f=this.config.messages,h=(this.config.panel,this.config.animation,this.config.sendButtonColor||(null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonColor)||"#7C3AED"),g=this.config.sendButtonHoverColor||(null===(t=this.config.panel)||void 0===t?void 0:t.sendButtonHoverColor)||"#6D28D9",v=this.config.sendButtonTextColor||(null===(n=this.config.panel)||void 0===n?void 0:n.sendButtonTextColor)||"#FFFFFF",m=(this.config.inputPlaceholder||null===(o=this.config.panel)||void 0===o||o.inputPlaceholder,this.config.inputBorderColor||(null===(r=this.config.panel)||void 0===r?void 0:r.inputBorderColor)||"#E5E7EB"),y=this.config.inputFocusColor||(null===(i=this.config.panel)||void 0===i?void 0:i.inputFocusColor)||"#7C3AED",b=this.config.inputBackgroundColor||(null===(a=this.config.panel)||void 0===a?void 0:a.inputBackgroundColor)||"#FFFFFF",w=this.config.inputTextColor||(null===(c=this.config.panel)||void 0===c?void 0:c.inputTextColor)||"#1F2937",S=this.config.inputFontSize||(null===(s=this.config.panel)||void 0===s?void 0:s.inputFontSize)||"14px",x=this.config.inputBorderRadius||(null===(l=this.config.panel)||void 0===l?void 0:l.inputBorderRadius)||20,k=this.config.inputPadding||(null===(u=this.config.panel)||void 0===u?void 0:u.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(f.borderRadius,"px; \n max-width: 80%; \n font-size: ").concat(f.fontSize,"; \n color: ").concat(f.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(f.userBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-start":"flex-end","; \n }\n .message.agent { \n background: ").concat(f.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(f.systemBackgroundColor,";\n align-self: flex-start;\n }\n .message.error {\n background: ").concat(f.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(m,";\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(y,";\n background: ").concat("#FFFFFF"===b?"#FFFFFF":b,";\n box-shadow: 0 0 0 3px ").concat(y,"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(v,";\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===(p=this.config.panel)||void 0===p?void 0:p.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(g,";\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(f.errorBackgroundColor,";\n border-radius: ").concat(f.borderRadius,"px;\n color: #991B1B;\n font-size: ").concat(f.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 e=this,t=document.getElementById("sendButton"),n=document.getElementById("messageInput"),o=document.getElementById("newChatBtn");if(t&&(t.onclick=function(){return e.sendMessage()}),o&&(o.onclick=function(){return e.startNewChat()}),this.updateInputAttributes(),n){n.style.height="32px",n.style.overflow="hidden";var r=function(){n.style.height="auto";var e=Math.min(n.scrollHeight,120);n.style.height=e+"px",n.style.overflowY=e>=120?"auto":"hidden",e>=120&&setTimeout(function(){n.scrollTop=n.scrollHeight},0)};n.addEventListener("input",r),n.addEventListener("keydown",function(t){"Enter"!==t.key||t.shiftKey?"Enter"===t.key&&t.shiftKey&&setTimeout(r,0):(t.preventDefault(),e.sendMessage())})}}},{key:"startNewChat",value:function(){try{localStorage.removeItem("ttp_text_chat_conversation_id")}catch(e){}this.sdk&&(this.sdk.config.conversationId=null);var e=document.getElementById("messagesContainer");e&&(e.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 t=document.getElementById("messageInput");t&&t.focus()}},{key:"updateInputAttributes",value:function(){var e=document.getElementById("messageInput");if(e){var t,n=this.config.inputPlaceholder||(null===(t=this.config.panel)||void 0===t?void 0:t.inputPlaceholder)||this.t("typeMessage")||"Type your message...";e.placeholder=n,e.dir=this.config.direction||"ltr",e.style.textAlign="rtl"===this.config.direction?"right":"left"}}},{key:"show",value:function(){var e=document.getElementById("textInterface");e&&e.classList.add("active"),setTimeout(function(){var e=document.getElementById("messageInput");e&&e.focus()},50)}},{key:"hide",value:function(){var e=document.getElementById("textInterface");e&&e.classList.remove("active")}},{key:"startChat",value:(o=So(yo().m(function e(){return yo().w(function(e){for(;;)switch(e.n){case 0:this.isActive=!0,this.updateSendButtonState();case 1:return e.a(2)}},e,this)})),function(){return o.apply(this,arguments)})},{key:"sendMessage",value:(n=So(yo().m(function e(){var t,n,o;return yo().w(function(e){for(;;)switch(e.p=e.n){case 0:if(t=document.getElementById("messageInput"),n=t.value.trim()){e.n=1;break}return e.a(2);case 1:if(this.isActive){e.n=2;break}return e.n=2,this.startChat();case 2:return this.addMessage("user",n),t.value="",t.style.height="32px",t.style.overflow="hidden",e.p=3,this.beginStreaming(),e.n=4,this.sdk.sendMessage(n);case 4:e.n=6;break;case 5:e.p=5,o=e.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 e.a(2)}},e,this,[[3,5]])})),function(){return n.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var e=document.getElementById("sendButton");e&&(e.disabled=!this.isActive)}},{key:"addMessage",value:function(e,t){var n=document.getElementById("messagesContainer");if(n){var o=n.querySelector(".empty-state");o&&o.remove();var r=document.createElement("div"),i="rtl"===this.config.direction?"user"===e?"edge-left":"edge-right":"user"===e?"edge-right":"edge-left";r.className="message ".concat(e," ").concat(i);var a=document.createElement("div");a.className="message-avatar ".concat(e),a.textContent="user"===e?"👤":"🤖";var c=document.createElement("div");c.className="message-bubble",c.textContent=t,r.appendChild(a),r.appendChild(c),n.appendChild(r),n.scrollTop=n.scrollHeight}}},{key:"beginStreaming",value:function(){var e=document.getElementById("messagesContainer");if(e){this.stopStreamingState();var t=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";t.className="message agent ".concat(n),t.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var r=document.createElement("div");r.className="message-bubble",r.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',t.appendChild(o),t.appendChild(r),e.appendChild(t),this.streamingEl=r,this.hasStartedStreaming=!1,e.scrollTop=e.scrollHeight}}},{key:"appendStreamingChunk",value:function(e){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=e;var t=document.getElementById("messagesContainer");t&&(t.scrollTop=t.scrollHeight)}}},{key:"finalizeStreaming",value:function(e){if(this.streamingEl){this.streamingEl.textContent=e||this.streamingEl.textContent;var t=document.getElementById("agent-streaming");t&&(t.id=""),this.streamingEl=null}this.updateSendButtonState()}},{key:"stopStreamingState",value:function(){var e=document.getElementById("agent-streaming");e&&e.remove(),this.streamingEl=null,this.hasStartedStreaming=!1}},{key:"showError",value:function(e){var t=document.getElementById("messagesContainer");if(t){if(e&&("DOMAIN_NOT_WHITELISTED"===e.message||"string"==typeof e&&e.includes("DOMAIN_NOT_WHITELISTED")||e.message&&e.message.includes("Domain not whitelisted")||"string"==typeof e&&e.includes("Domain not whitelisted"))){var n,o=document.createElement("div");o.className="error-message",o.style.cssText="padding: 16px; margin: 12px; border-radius: 8px; background: "+((null===(n=this.config.messages)||void 0===n?void 0:n.errorBackgroundColor)||"#FEE2E2")+";";var r=document.createElement("div");r.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",r.textContent=this.t("domainNotValidated");var i=document.createElement("div");i.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",i.textContent=this.t("domainErrorMessage"),o.appendChild(r),o.appendChild(i),t.appendChild(o)}else{var a=document.createElement("div");a.className="error-message",a.textContent="string"==typeof e?e:(null==e?void 0:e.message)||e,t.appendChild(a)}t.scrollTop=t.scrollHeight}}},{key:"setActive",value:function(e){this.isActive=e,this.updateSendButtonState()}}],t&&xo(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();const Po={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 Eo(){var e,t,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return To(l,"_invoke",function(n,o,r){var i,c,s,l=0,u=r||[],d=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return i=t,c=0,s=e,p.n=n,a}};function f(n,o){for(c=n,s=o,t=0;!d&&l&&!r&&t<u.length;t++){var r,i=u[t],f=p.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=f&&((r=n<2&&f<i[1])?(c=0,p.v=o,p.n=i[1]):f<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,p.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&f(u,h),c=u,s=h;(t=c<2?e:s)||!d;){i||(c?c<3?(c>1&&(p.n=-1),f(c,s)):p.n=s:p.v=s);try{if(l=2,i){if(c||(r="next"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=e}else if((t=(d=p.n<0)?s:n.call(o,p))!==a)break}catch(t){i=e,c=1,s=t}finally{l=1}}return{value:t,done:d}}}(n,r,i),!0),l}var a={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var u=[][o]?t(t([][o]())):(To(t={},o,function(){return this}),t),d=l.prototype=c.prototype=Object.create(u);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,To(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,To(d,"constructor",l),To(l,"constructor",s),s.displayName="GeneratorFunction",To(l,r,"GeneratorFunction"),To(d),To(d,r,"Generator"),To(d,o,function(){return this}),To(d,"toString",function(){return"[object Generator]"}),(Eo=function(){return{w:i,m:p}})()}function To(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}To=function(e,t,n,o){function i(t,n){To(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},To(e,t,n,o)}function Oo(e,t,n,o,r,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(o,r)}function Ao(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function a(e){Oo(i,o,r,a,c,"next",e)}function c(e){Oo(i,o,r,a,c,"throw",e)}a(void 0)})}}function Io(e){return Io="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Io(e)}function jo(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function Do(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?jo(Object(n),!0).forEach(function(t){Fo(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):jo(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Fo(e,t,n){return(t=Bo(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Bo(o.key),o)}}function Bo(e){var t=function(e){if("object"!=Io(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Io(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Io(t)?t:t+""}var Ro=function(){return e=function e(){var t,n,o,r,i,a,c,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=this.mergeWithDefaults(s),this.sdk=new hn(this.config),this.isOpen=!1,this.isActive=!1,this.translations=Po,this.currentView="landing";var l=Do(Do(Do({},this.config),this.config.voice),{},{language:(null===(t=this.config.voice)||void 0===t?void 0:t.language)||this.config.language||"en",websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16,onConversationStart:this.config.onConversationStart,onConversationEnd:this.config.onConversationEnd,onBargeIn:this.config.onBargeIn,onAudioStartPlaying:this.config.onAudioStartPlaying,onAudioStoppedPlaying:this.config.onAudioStoppedPlaying,onSubtitleDisplay:this.config.onSubtitleDisplay});this.voiceInterface=new vo(l);var u=Do(Do(Do({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new Co(u,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var d=document.getElementById("text-chat-panel");d&&(this.isOpen=!0,d.classList.add("open"))}},t=[{key:"mergeWithDefaults",value:function(e){var t,n,o,r,i,a,c,s,l,u,d,p,f,h,g,v,m,y,b,w,S,x,k,C,P,E,T,O,A,I,j,D,F,_,B,R,M,U,N,L,z,V,K,H,W,G,q,Q,Y,$,J,X,Z,ee,te,ne,oe,re,ie,ae,ce,se,le,ue,de,pe,fe,he,ge,ve,me,ye,be,we,Se,xe,ke,Ce,Pe,Ee,Te,Oe,Ae,Ie,je,De,Fe,_e,Be,Re,Me,Ue,Ne,Le,ze,Ve,Ke,He,We,Ge,qe,Qe,Ye,$e,Je,Xe,Ze,et,tt,nt,ot,rt,it,at,ct,st,lt,ut,dt,pt,ft,ht,gt,vt,mt,yt,bt,wt,St,xt,kt,Ct,Pt,Et,Tt=e.position||"bottom-right";if("string"==typeof Tt){var Ot=Tt.split("-");Tt={vertical:Ot[0]||"bottom",horizontal:Ot[1]||"right",offset:e.positionOffset||{x:20,y:20}}}var At=e.primaryColor||(null===(t=e.button)||void 0===t?void 0:t.primaryColor)||(null===(n=e.button)||void 0===n?void 0:n.backgroundColor)||"#7C3AED",It=(null===(o=e.header)||void 0===o?void 0:o.backgroundColor)||(null===(r=e.button)||void 0===r?void 0:r.backgroundColor)||At;return Do({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,demo:!1!==e.demo,direction:e.direction||"ltr",language:e.language||"en",icon:Do({type:(null===(i=e.icon)||void 0===i?void 0:i.type)||"custom",customImage:(null===(a=e.icon)||void 0===a?void 0:a.customImage)||"https://talktopc.com/logo192.png",emoji:(null===(c=e.icon)||void 0===c?void 0:c.emoji)||"🎤",text:(null===(s=e.icon)||void 0===s?void 0:s.text)||"AI",size:(null===(l=e.icon)||void 0===l?void 0:l.size)||"medium",backgroundColor:(null===(u=e.icon)||void 0===u?void 0:u.backgroundColor)||"#FFFFFF"},e.icon),position:Do({vertical:Tt.vertical||"bottom",horizontal:Tt.horizontal||"right",offset:Tt.offset||{x:20,y:20}},"object"===Io(e.position)?e.position:{}),button:Do({size:(null===(d=e.button)||void 0===d?void 0:d.size)||"medium",shape:(null===(p=e.button)||void 0===p?void 0:p.shape)||"circle",backgroundColor:(null===(f=e.button)||void 0===f?void 0:f.backgroundColor)||(null===(h=e.icon)||void 0===h?void 0:h.backgroundColor)||At,hoverColor:(null===(g=e.button)||void 0===g?void 0:g.hoverColor)||"#7C3AED",shadow:!1!==(null===(v=e.button)||void 0===v?void 0:v.shadow),shadowColor:(null===(m=e.button)||void 0===m?void 0:m.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(y=e.button)||void 0===y?void 0:y.backgroundColor)||(null===(b=e.icon)||void 0===b?void 0:b.backgroundColor)||At},e.button),panel:Do({width:(null===(w=e.panel)||void 0===w?void 0:w.width)||350,height:(null===(S=e.panel)||void 0===S?void 0:S.height)||500,borderRadius:(null===(x=e.panel)||void 0===x?void 0:x.borderRadius)||12,backgroundColor:(null===(k=e.panel)||void 0===k?void 0:k.backgroundColor)||"#FFFFFF",backdropFilter:(null===(C=e.panel)||void 0===C?void 0:C.backdropFilter)||null,border:(null===(P=e.panel)||void 0===P?void 0:P.border)||"1px solid rgba(0,0,0,0.1)"},e.panel),voice:Do({micButtonColor:(null===(E=e.voice)||void 0===E?void 0:E.micButtonColor)||(null===(T=e.panel)||void 0===T?void 0:T.micButtonColor)||At,micButtonActiveColor:(null===(O=e.voice)||void 0===O?void 0:O.micButtonActiveColor)||(null===(A=e.panel)||void 0===A?void 0:A.micButtonActiveColor)||"#EF4444",micButtonHint:Do(Do({text:(null===(I=e.voice)||void 0===I||null===(I=I.micButtonHint)||void 0===I?void 0:I.text)||(null===(j=e.panel)||void 0===j||null===(j=j.micButtonHint)||void 0===j?void 0:j.text)||"Click the button to start voice conversation",color:(null===(D=e.voice)||void 0===D||null===(D=D.micButtonHint)||void 0===D?void 0:D.color)||(null===(F=e.panel)||void 0===F||null===(F=F.micButtonHint)||void 0===F?void 0:F.color)||"#6B7280",fontSize:(null===(_=e.voice)||void 0===_||null===(_=_.micButtonHint)||void 0===_?void 0:_.fontSize)||(null===(B=e.panel)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.fontSize)||"12px"},null===(R=e.voice)||void 0===R?void 0:R.micButtonHint),null===(M=e.panel)||void 0===M?void 0:M.micButtonHint),avatarBackgroundColor:(null===(U=e.voice)||void 0===U?void 0:U.avatarBackgroundColor)||"#667eea",avatarActiveBackgroundColor:(null===(N=e.voice)||void 0===N?void 0:N.avatarActiveBackgroundColor)||"#667eea",statusTitleColor:(null===(L=e.voice)||void 0===L?void 0:L.statusTitleColor)||"#1e293b",statusSubtitleColor:(null===(z=e.voice)||void 0===z?void 0:z.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(V=e.voice)||void 0===V?void 0:V.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(K=e.voice)||void 0===K?void 0:K.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(H=e.voice)||void 0===H?void 0:H.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(W=e.voice)||void 0===W?void 0:W.transcriptTextColor)||"#1e293b",transcriptLabelColor:(null===(G=e.voice)||void 0===G?void 0:G.transcriptLabelColor)||"#94a3b8",controlButtonColor:(null===(q=e.voice)||void 0===q?void 0:q.controlButtonColor)||"#FFFFFF",controlButtonSecondaryColor:(null===(Q=e.voice)||void 0===Q?void 0:Q.controlButtonSecondaryColor)||"#64748b",endCallButtonColor:(null===(Y=e.voice)||void 0===Y?void 0:Y.endCallButtonColor)||"#ef4444",language:(null===($=e.voice)||void 0===$?void 0:$.language)||e.language||"en",websocketUrl:(null===(J=e.voice)||void 0===J?void 0:J.websocketUrl)||e.websocketUrl},e.voice),text:Do({sendButtonColor:(null===(X=e.text)||void 0===X?void 0:X.sendButtonColor)||(null===(Z=e.panel)||void 0===Z?void 0:Z.sendButtonColor)||"#7C3AED",sendButtonHoverColor:(null===(ee=e.text)||void 0===ee?void 0:ee.sendButtonHoverColor)||(null===(te=e.panel)||void 0===te?void 0:te.sendButtonHoverColor)||"#6D28D9",sendButtonActiveColor:(null===(ne=e.text)||void 0===ne?void 0:ne.sendButtonActiveColor)||(null===(oe=e.panel)||void 0===oe?void 0:oe.sendButtonActiveColor)||"#6D28D9",sendButtonText:(null===(re=e.text)||void 0===re?void 0:re.sendButtonText)||(null===(ie=e.panel)||void 0===ie?void 0:ie.sendButtonText)||"➤",sendButtonTextColor:(null===(ae=e.text)||void 0===ae?void 0:ae.sendButtonTextColor)||(null===(ce=e.panel)||void 0===ce?void 0:ce.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(se=e.text)||void 0===se?void 0:se.sendButtonFontSize)||(null===(le=e.panel)||void 0===le?void 0:le.sendButtonFontSize)||"18px",sendButtonFontWeight:(null===(ue=e.text)||void 0===ue?void 0:ue.sendButtonFontWeight)||(null===(de=e.panel)||void 0===de?void 0:de.sendButtonFontWeight)||"500",sendButtonHint:Do(Do({text:(null===(pe=e.text)||void 0===pe||null===(pe=pe.sendButtonHint)||void 0===pe?void 0:pe.text)||(null===(fe=e.panel)||void 0===fe||null===(fe=fe.sendButtonHint)||void 0===fe?void 0:fe.text)||"",color:(null===(he=e.text)||void 0===he||null===(he=he.sendButtonHint)||void 0===he?void 0:he.color)||(null===(ge=e.panel)||void 0===ge||null===(ge=ge.sendButtonHint)||void 0===ge?void 0:ge.color)||"#6B7280",fontSize:(null===(ve=e.text)||void 0===ve||null===(ve=ve.sendButtonHint)||void 0===ve?void 0:ve.fontSize)||(null===(me=e.panel)||void 0===me||null===(me=me.sendButtonHint)||void 0===me?void 0:me.fontSize)||"12px"},null===(ye=e.text)||void 0===ye?void 0:ye.sendButtonHint),null===(be=e.panel)||void 0===be?void 0:be.sendButtonHint),inputPlaceholder:(null===(we=e.text)||void 0===we?void 0:we.inputPlaceholder)||(null===(Se=e.panel)||void 0===Se?void 0:Se.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(xe=e.text)||void 0===xe?void 0:xe.inputBorderColor)||(null===(ke=e.panel)||void 0===ke?void 0:ke.inputBorderColor)||"#E5E7EB",inputFocusColor:(null===(Ce=e.text)||void 0===Ce?void 0:Ce.inputFocusColor)||(null===(Pe=e.panel)||void 0===Pe?void 0:Pe.inputFocusColor)||"#7C3AED",inputBackgroundColor:(null===(Ee=e.text)||void 0===Ee?void 0:Ee.inputBackgroundColor)||(null===(Te=e.panel)||void 0===Te?void 0:Te.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(Oe=e.text)||void 0===Oe?void 0:Oe.inputTextColor)||(null===(Ae=e.panel)||void 0===Ae?void 0:Ae.inputTextColor)||"#1F2937",inputFontSize:(null===(Ie=e.text)||void 0===Ie?void 0:Ie.inputFontSize)||(null===(je=e.panel)||void 0===je?void 0:je.inputFontSize)||"14px",inputBorderRadius:(null===(De=e.text)||void 0===De?void 0:De.inputBorderRadius)||(null===(Fe=e.panel)||void 0===Fe?void 0:Fe.inputBorderRadius)||20,inputPadding:(null===(_e=e.text)||void 0===_e?void 0:_e.inputPadding)||(null===(Be=e.panel)||void 0===Be?void 0:Be.inputPadding)||"6px 14px"},e.text),landing:Do({backgroundColor:(null===(Re=e.landing)||void 0===Re?void 0:Re.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)",logo:(null===(Me=e.landing)||void 0===Me?void 0:Me.logo)||"🤖",title:(null===(Ue=e.landing)||void 0===Ue?void 0:Ue.title)||null,titleColor:(null===(Ne=e.landing)||void 0===Ne?void 0:Ne.titleColor)||"#1e293b",modeCardBackgroundColor:(null===(Le=e.landing)||void 0===Le?void 0:Le.modeCardBackgroundColor)||"#FFFFFF",modeCardBorderColor:(null===(ze=e.landing)||void 0===ze?void 0:ze.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Ve=e.landing)||void 0===Ve?void 0:Ve.modeCardHoverBorderColor)||It,modeCardIconBackgroundColor:(null===(Ke=e.landing)||void 0===Ke?void 0:Ke.modeCardIconBackgroundColor)||It,modeCardTitleColor:(null===(He=e.landing)||void 0===He?void 0:He.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(We=e.landing)||void 0===We?void 0:We.voiceCardIcon)||"🎤",textCardIcon:(null===(Ge=e.landing)||void 0===Ge?void 0:Ge.textCardIcon)||"💬"},e.landing),header:Do({title:(null===(qe=e.header)||void 0===qe?void 0:qe.title)||"Chat Assistant",showTitle:!1!==(null===(Qe=e.header)||void 0===Qe?void 0:Qe.showTitle),backgroundColor:(null===(Ye=e.header)||void 0===Ye?void 0:Ye.backgroundColor)||(null===($e=e.button)||void 0===$e?void 0:$e.backgroundColor)||"#7C3AED",textColor:(null===(Je=e.header)||void 0===Je?void 0:Je.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(Xe=e.header)||void 0===Xe?void 0:Xe.showCloseButton)},e.header),tooltips:Do({newChat:(null===(Ze=e.tooltips)||void 0===Ze?void 0:Ze.newChat)||null,back:(null===(et=e.tooltips)||void 0===et?void 0:et.back)||null,close:(null===(tt=e.tooltips)||void 0===tt?void 0:tt.close)||null,mute:(null===(nt=e.tooltips)||void 0===nt?void 0:nt.mute)||null,speaker:(null===(ot=e.tooltips)||void 0===ot?void 0:ot.speaker)||null,endCall:(null===(rt=e.tooltips)||void 0===rt?void 0:rt.endCall)||null},e.tooltips),messages:Do({userBackgroundColor:(null===(it=e.messages)||void 0===it?void 0:it.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(at=e.messages)||void 0===at?void 0:at.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(ct=e.messages)||void 0===ct?void 0:ct.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(st=e.messages)||void 0===st?void 0:st.errorBackgroundColor)||"#FEE2E2",textColor:(null===(lt=e.messages)||void 0===lt?void 0:lt.textColor)||"#1F2937",fontSize:(null===(ut=e.messages)||void 0===ut?void 0:ut.fontSize)||"14px",borderRadius:(null===(dt=e.messages)||void 0===dt?void 0:dt.borderRadius)||8},e.messages),animation:Do({enableHover:!1!==(null===(pt=e.animation)||void 0===pt?void 0:pt.enableHover),enablePulse:!1!==(null===(ft=e.animation)||void 0===ft?void 0:ft.enablePulse),enableSlide:!1!==(null===(ht=e.animation)||void 0===ht?void 0:ht.enableSlide),duration:(null===(gt=e.animation)||void 0===gt?void 0:gt.duration)||.3},e.animation),behavior:Do({autoOpen:(null===(vt=e.behavior)||void 0===vt?void 0:vt.autoOpen)||!1,startOpen:(null===(mt=e.behavior)||void 0===mt?void 0:mt.startOpen)||!1,hidden:(null===(yt=e.behavior)||void 0===yt?void 0:yt.hidden)||!1,autoConnect:(null===(bt=e.behavior)||void 0===bt?void 0:bt.autoConnect)||!1,showWelcomeMessage:!1!==(null===(wt=e.behavior)||void 0===wt?void 0:wt.showWelcomeMessage),welcomeMessage:(null===(St=e.behavior)||void 0===St?void 0:St.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:void 0===(null===(xt=e.behavior)||void 0===xt?void 0:xt.enableVoiceMode)||e.behavior.enableVoiceMode,mode:(null===(kt=e.behavior)||void 0===kt?void 0:kt.mode)||"unified"},e.behavior),accessibility:Do({ariaLabel:(null===(Ct=e.accessibility)||void 0===Ct?void 0:Ct.ariaLabel)||"Chat Assistant",ariaDescription:(null===(Pt=e.accessibility)||void 0===Pt?void 0:Pt.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(Et=e.accessibility)||void 0===Et?void 0:Et.keyboardNavigation)},e.accessibility),customStyles:e.customStyles||"",variables:e.variables||{},forceConversationId:e.forceConversationId,onConversationStart:e.onConversationStart,onConversationEnd:e.onConversationEnd,onBargeIn:e.onBargeIn,onAudioStartPlaying:e.onAudioStartPlaying,onAudioStoppedPlaying:e.onAudioStoppedPlaying,onSubtitleDisplay:e.onSubtitleDisplay,primaryColor:At},"string"==typeof e.position?{positionString:e.position}:{})}},{key:"setupEventHandlers",value:function(){var e=this;this.sdk.on("domainError",function(t){e.textInterface.showError(t),e.textInterface.stopStreamingState()}),this.sdk.on("error",function(t){t&&("DOMAIN_NOT_WHITELISTED"===t.message||t.message&&t.message.includes("Domain not whitelisted"))||(e.textInterface.showError(t.message||t),e.textInterface.stopStreamingState())}),this.sdk.on("chunk",function(t){e.textInterface.appendStreamingChunk(t)}),this.sdk.on("done",function(t){var n=t.text;e.textInterface.finalizeStreaming(n)})}},{key:"createWidget",value:function(){var e=document.getElementById("text-chat-widget");e&&e.remove();var t=document.createElement("div");if(t.id="text-chat-widget",t.innerHTML=this.generateWidgetHTML(),document.body.appendChild(t),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 e=this,t=(this.config.position,this.config.button),n=this.config.icon,o=(this.config.panel,this.config.header),r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[t.size]||60),i={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i),s=this.config.behavior.mode||"unified",l="unified"===s,u="unified"===s||"voice-only"===s,d="unified"===s||"text-only"===s,p=function(t){var n=e.config.language||"en";return(e.translations[n]||e.translations.en)[t]||t},f=function(t){var n,o=null===(n=e.config.tooltips)||void 0===n?void 0:n[t];return null!=o?o:{newChat:p("newChat"),back:p("back"),close:p("close"),mute:p("mute"),speaker:p("speaker"),endCall:p("endCall")}[t]||""};return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header" style="background: ').concat(o.backgroundColor,"; color: ").concat(o.textColor,';">\n <div>\n ').concat(o.showTitle?'<div class="header-title">'.concat(o.title,"</div>"):"",'\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat(p("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(f("newChat"),'" style="').concat(l?"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(f("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="'+f("close")+'"><span style="font-size: 18px; font-weight: bold;">×</span></button>':"","\n </div>\n </div>\n\n ").concat(l?'\n <div class="landing-screen" id="landingScreen">\n <div class="landing-logo">🤖</div>\n <div class="landing-title">'.concat(p("landingTitle"),'</div>\n <div class="mode-selection">\n ').concat(u?'<div class="mode-card voice" id="mode-card-voice">\n <div class="mode-card-icon">🎤</div>\n <div class="mode-card-title">'.concat(p("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(p("textChat"),"</div>\n </div>"):"","\n </div>\n </div>"):"","\n\n ").concat(u?this.voiceInterface.generateHTML():"","\n ").concat(d?this.textInterface.generateHTML():"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var e=this.config.position,t=e.offset||{x:20,y:20},n="";return"top"===e.vertical?n+="top: ".concat(t.y,"px;"):"bottom"===e.vertical?n+="bottom: ".concat(t.y,"px;"):"center"===e.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===e.horizontal?n+="left: ".concat(t.x,"px;"):"right"===e.horizontal?n+="right: ".concat(t.x,"px;"):"center"===e.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(e){var t=this.config.icon;switch(t.type){case"custom":return'<img src="'.concat(t.customImage,'" alt="Chat Assistant" style="width: ').concat(e,"px; height: ").concat(e,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(e,'px; line-height: 1;">').concat(t.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*e),'px; font-weight: bold; color: white;">').concat(t.text,"</span>");case"microphone":default:return'<svg viewBox="0 0 24 24" style="width: '.concat(e,"px; height: ").concat(e,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>');case"chat":return'<svg viewBox="0 0 24 24" style="width: '.concat(e,"px; height: ").concat(e,'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(e,t,n){var o,r,i,a,c,s,l,u=this.config.button,d=this.config.icon,p=this.config.panel,f=this.config.header,h=(this.config.messages,this.config.animation),g=this.config.behavior.mode||"unified",v="unified"===g||"voice-only"===g,m="unified"===g||"text-only"===g,y=f.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(e,"\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(t,"px;\n height: ").concat(t,"px;\n border-radius: ").concat("circle"===u.shape?"50%":"square"===u.shape?"0":"12px",";\n background: ").concat(u.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(t,"px + 20px);\n ").concat("right"===this.config.position.horizontal?"right: 20px;":"left: 20px;","\n width: ").concat(p.width,"px;\n max-width: calc(100vw - 40px);\n height: ").concat(p.height,"px;\n max-height: calc(100vh - ").concat(t,"px - 40px);\n background: transparent;\n border-radius: ").concat(p.borderRadius,"px;\n border: none;\n flex-direction: column;\n overflow: hidden;\n ").concat(p.backdropFilter?"backdrop-filter: ".concat(p.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(p.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(p.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(p.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(p.borderRadius,"px;\n border-top-right-radius: ").concat(p.borderRadius,"px;\n flex-shrink: 0;\n min-height: 60px;\n box-sizing: border-box;\n }\n #text-chat-panel .header-title { font-size: 16px; font-weight: 600; }\n #text-chat-panel .header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.9; }\n #text-chat-panel .status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }\n @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n /* Header icon buttons */\n .header-icon {\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 36px;\n height: 36px;\n min-width: 36px;\n min-height: 36px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n flex-shrink: 0;\n font-size: 16px;\n padding: 0;\n box-sizing: border-box;\n }\n \n .header-icon:hover {\n background: rgba(255, 255, 255, 0.3);\n }\n \n .header-icon svg {\n pointer-events: none;\n stroke: white;\n fill: none;\n }\n \n .back-btn.visible {\n display: flex !important;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { \n display: none; \n flex: 1; \n padding: 20px; \n background: ").concat((null===(o=this.config.landing)||void 0===o?void 0:o.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)","; \n align-items: center; \n justify-content: flex-start; \n flex-direction: column; \n gap: 16px; \n overflow-y: auto; \n min-height: 0; \n }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { \n font-size: 20px; \n color: ").concat((null===(r=this.config.landing)||void 0===r?void 0:r.titleColor)||"#1e293b","; \n font-weight: 700; \n margin-bottom: 20px; \n text-align: center;\n width: 100%;\n }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { \n flex: 1; \n max-width: 180px; \n background: ").concat((null===(i=this.config.landing)||void 0===i?void 0:i.modeCardBackgroundColor)||"#FFFFFF","; \n border: 2px solid ").concat((null===(a=this.config.landing)||void 0===a?void 0:a.modeCardBorderColor)||"#E2E8F0","; \n border-radius: 20px; \n padding: 20px 12px; \n cursor: pointer; \n display: flex; \n flex-direction: column; \n align-items: center; \n gap: 8px; \n transition: transform ").concat(h.duration,"s ease, box-shadow ").concat(h.duration,"s ease, border-color ").concat(h.duration,"s ease; \n box-shadow: 0 4px 12px rgba(0,0,0,0.05); \n }\n .mode-card:hover { \n transform: translateY(-6px); \n box-shadow: 0 12px 24px rgba(102, 126, 234, 0.2); \n border-color: ").concat((null===(c=this.config.landing)||void 0===c?void 0:c.modeCardHoverBorderColor)||y,"; \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)||y,"; \n color: #fff; \n font-size: 32px; \n }\n .mode-card-title { \n color: ").concat((null===(l=this.config.landing)||void 0===l?void 0:l.modeCardTitleColor)||"#111827","; \n font-weight: 600; \n text-align: center;\n width: 100%;\n }\n\n ").concat(v?this.voiceInterface.generateCSS():"","\n ").concat(m?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 e=this,t=document.getElementById("text-chat-button");t&&(t.onclick=function(){return e.togglePanel()});var n=document.getElementById("closeBtn");n&&(n.onclick=function(){return e.togglePanel()});var o=this.config.behavior.mode||"unified",r="unified"===o,i="unified"===o||"voice-only"===o,a="unified"===o||"text-only"===o,c=document.getElementById("backBtn"),s=document.getElementById("landingScreen"),l=document.getElementById("mode-card-voice"),u=document.getElementById("mode-card-text"),d=document.getElementById("textInterface"),p=document.getElementById("voiceInterface");c&&(c.onclick=function(){return e.showLanding()}),r?(l&&(l.onclick=function(){return e.showVoice()}),u&&(u.onclick=function(){return e.showText()}),"text"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.add("active"),p&&p.classList.remove("active"),c&&"unified"===o&&c.classList.add("visible"),f&&(f.style.display="")):"voice"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.remove("active"),p&&p.classList.add("active"),c&&"unified"===o&&c.classList.add("visible"),f&&(f.style.display="none")):(this.currentView="landing",s&&s.classList.add("active"),d&&d.classList.remove("active"),p&&p.classList.remove("active"),c&&"unified"===o&&c.classList.remove("visible"))):"voice-only"===o?(p&&p.classList.add("active"),d&&d.classList.remove("active"),s&&s.classList.remove("active")):"text-only"===o&&(d&&d.classList.add("active"),p&&p.classList.remove("active"),s&&s.classList.remove("active")),i&&(console.log("⚙️ Setting up voice interface event handlers"),this.voiceInterface.setupEventHandlers()),a&&(console.log("⚙️ Setting up text interface event handlers"),this.textInterface.setupEventHandlers());var f=document.getElementById("newChatBtn");f&&(f.onclick=function(){return e.textInterface.startNewChat()},r&&(f.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 e=document.getElementById("landingScreen"),t=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");e&&e.classList.add("active"),t&&t.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),r&&(r.style.display="none")}}},{key:"showText",value:function(){this.currentView="text";var e=document.getElementById("landingScreen"),t=document.getElementById("voiceInterface"),n=document.getElementById("backBtn"),o=document.getElementById("newChatBtn");e&&e.classList.remove("active"),t&&t.classList.remove("active"),this.textInterface.show();var r=this.config.behavior.mode||"unified";n&&"unified"===r&&n.classList.add("visible"),o&&(o.style.display="")}},{key:"showVoice",value:function(){this.currentView="voice";var e=document.getElementById("landingScreen"),t=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");e&&e.classList.remove("active"),t&&t.classList.remove("active"),n&&n.classList.add("active");var i=this.config.behavior.mode||"unified";o&&"unified"===i&&o.classList.add("visible"),r&&(r.style.display="none")}},{key:"setupKeyboardNavigation",value:function(){var e=this;document.addEventListener("keydown",function(t){"Escape"===t.key&&e.isOpen&&e.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("text-chat-panel").classList.toggle("open"),this.isOpen&&setTimeout(function(){var e=document.getElementById("messageInput");e&&e.focus()},100),this.isOpen&&!this.isActive&&this.config.behavior.autoConnect&&this.startChat()}},{key:"startChat",value:(i=Ao(Eo().m(function e(){return Eo().w(function(e){for(;;)switch(e.n){case 0:this.isActive=!0,this.textInterface.setActive(!0);case 1:return e.a(2)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"sendMessage",value:(r=Ao(Eo().m(function e(){return Eo().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.textInterface.sendMessage();case 1:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=Ao(Eo().m(function e(){var t,n,o,r,i,a,c;return Eo().w(function(e){for(;;)switch(e.n){case 0:if(this.config.getSessionUrl){e.n=2;break}if(this.config.agentId){e.n=1;break}throw new Error("agentId is required");case 1:return t=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"),e.a(2,"".concat(t,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){e.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),e.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=e.v).ok){e.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return e.n=5,r.json();case 5:return i=e.v,e.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){e.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),e.n=7,this.config.getSessionUrl(a);case 7:return c=e.v,e.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 e.a(2)}},e,this)})),function(){return o.apply(this,arguments)})},{key:"addMessage",value:function(e,t){this.textInterface.addMessage(e,t)}},{key:"beginStreaming",value:function(){this.textInterface.beginStreaming()}},{key:"appendStreamingChunk",value:function(e){this.textInterface.appendStreamingChunk(e)}},{key:"finalizeStreaming",value:function(e){this.textInterface.finalizeStreaming(e)}},{key:"stopStreamingState",value:function(){this.textInterface.stopStreamingState()}},{key:"showError",value:function(e){this.textInterface.showError(e)}},{key:"updateStatus",value:function(e){}},{key:"updateConfig",value:function(e){var t,n,o,r,i,a,c,s,l,u=Do({},this.config);e.panel&&(u.panel=Do(Do({},this.config.panel),e.panel)),e.voice&&(u.voice=Do(Do({},this.config.voice),e.voice),e.voice.micButtonHint&&(u.voice.micButtonHint=Do(Do({},null===(s=this.config.voice)||void 0===s?void 0:s.micButtonHint),e.voice.micButtonHint))),e.text&&(u.text=Do(Do({},this.config.text),e.text),e.text.sendButtonHint&&(u.text.sendButtonHint=Do(Do({},null===(l=this.config.text)||void 0===l?void 0:l.sendButtonHint),e.text.sendButtonHint))),void 0!==e.language&&(u.language=e.language),void 0!==e.language&&(["he","ar"].includes(e.language)?u.direction="rtl":void 0===e.direction&&(u.direction="ltr")),e.translations&&(u.translations=e.translations,this.translations=e.translations),e.button&&(u.button=Do(Do({},this.config.button),e.button)),e.header&&(u.header=Do(Do({},this.config.header),e.header)),e.icon&&(u.icon=Do(Do({},this.config.icon),e.icon)),e.messages&&(u.messages=Do(Do({},this.config.messages),e.messages)),e.animation&&(u.animation=Do(Do({},this.config.animation),e.animation)),e.behavior&&(u.behavior=Do(Do({},this.config.behavior),e.behavior)),e.accessibility&&(u.accessibility=Do(Do({},this.config.accessibility),e.accessibility)),e.tooltips&&(u.tooltips=Do(Do({},this.config.tooltips),e.tooltips)),e.landing&&(u.landing=Do(Do({},this.config.landing),e.landing)),void 0!==e.direction&&void 0===u.direction&&(u.direction=e.direction),void 0!==e.primaryColor&&(u.primaryColor=e.primaryColor),u.onConversationStart=void 0!==e.onConversationStart?e.onConversationStart:this.config.onConversationStart,u.onConversationEnd=void 0!==e.onConversationEnd?e.onConversationEnd:this.config.onConversationEnd,u.onBargeIn=void 0!==e.onBargeIn?e.onBargeIn:this.config.onBargeIn,u.onAudioStartPlaying=void 0!==e.onAudioStartPlaying?e.onAudioStartPlaying:this.config.onAudioStartPlaying,u.onAudioStoppedPlaying=void 0!==e.onAudioStoppedPlaying?e.onAudioStoppedPlaying:this.config.onAudioStoppedPlaying,u.onSubtitleDisplay=void 0!==e.onSubtitleDisplay?e.onSubtitleDisplay:this.config.onSubtitleDisplay,Object.keys(e).forEach(function(t){["panel","button","header","icon","messages","direction","voice","text","animation","behavior","accessibility","language","tooltips","landing","primaryColor","onConversationStart","onConversationEnd","onBargeIn","onAudioStartPlaying","onAudioStoppedPlaying","onSubtitleDisplay"].includes(t)||(u[t]=e[t])}),null===(t=this.config)||void 0===t||t.language,this.config=this.mergeWithDefaults(u);var d=this.config.language||"en",p=Do(Do(Do({},this.config),this.config.voice),{},{language:d,websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16,onConversationStart:this.config.onConversationStart,onConversationEnd:this.config.onConversationEnd,onBargeIn:this.config.onBargeIn,onAudioStartPlaying:this.config.onAudioStartPlaying,onAudioStoppedPlaying:this.config.onAudioStoppedPlaying,onSubtitleDisplay:this.config.onSubtitleDisplay});this.voiceInterface=new vo(p);var f=Do(Do(Do({},this.config),this.config.text),{},{language:d,translations:this.translations});this.textInterface=new Co(f,this.sdk);var h=document.getElementById("text-chat-widget");h&&h.remove(),this.createWidget(),this.textInterface&&this.textInterface.updateInputAttributes&&this.textInterface.updateInputAttributes()}},{key:"destroy",value:function(){var e=document.getElementById("text-chat-widget");e&&e.remove(),this.sdk&&this.sdk.destroy(),this.voiceInterface&&this.voiceInterface.destroy()}},{key:"startVoiceCall",value:(n=Ao(Eo().m(function e(){return Eo().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.voiceInterface.startVoiceCall();case 1:return e.a(2)}},e,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()}}],t&&_o(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o,r,i}(),Mo="2.4.24";const Uo={VoiceSDK:ve,VoiceSDK_v2:en,TextChatSDK:hn,WebSocketManager:F,AudioRecorder:W,AudioPlayer:ne,EventEmitter:l,VoiceButton:En,VanillaVoiceButton:Rn,AgentSDK:Hn,TTPChatWidget:Ro,VERSION:Mo};return o})());
|
|
3
3
|
//# sourceMappingURL=agent-widget.js.map
|