ttp-agent-sdk 2.4.2 → 2.4.4
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/package.json +1 -1
package/dist/agent-widget.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see agent-widget.js.LICENSE.txt */
|
|
2
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==e.key&&(r=""+e.key),"key"in e)for(var i in o={},e)"key"!==i&&(o[i]=e[i]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:r,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},i.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=i.prototype;var s=c.prototype=new a;s.constructor=c,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var u={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return u.H.useEffect(t,e)},e.useRef=function(t){return u.H.useRef(t)},e.useState=function(t){return u.H.useState(t)}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>zn,AudioPlayer:()=>Z,AudioRecorder:()=>K,EventEmitter:()=>c,TTPChatWidget:()=>vo,TextChatSDK:()=>ln,VERSION:()=>go,VanillaVoiceButton:()=>Fn,VoiceButton:()=>xn,VoiceSDK:()=>pt,VoiceSDK_v2:()=>Ye,WebSocketManager:()=>A,default:()=>yo});var c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||d(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=d(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function d(t,e){if(t){if("string"==typeof t)return f(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return h(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(h(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,h(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,h(d,"constructor",u),h(u,"constructor",s),s.displayName="GeneratorFunction",h(u,r,"GeneratorFunction"),h(d),h(d,r,"Generator"),h(d,o,function(){return this}),h(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:f}})()}function h(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}h=function(t,e,n,o){function i(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},h(t,e,n,o)}function v(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,y(o.key),o)}}function y(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(m=function(){return!!t})()}function b(t){return b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},b(t)}function S(t,e){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},S(t,e)}const w=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=b(e),function(t,e){if(e&&("object"==s(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,m()?Reflect.construct(e,n||[],b(t).constructor):e.apply(t,n))}(this,e)).connections=new Map,t.connectionCounts=new Map,t.creatingConnections=new Set,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&S(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=p().m(function t(e){var n,o,r=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(r.connections.has(e)){var o=r.connections.get(e);r.connectionCounts.set(e,(r.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){r.creatingConnections.delete(e),r.emit("error",t,e)}),o.addEventListener("message",function(t){r.emit("message",t,e)}),t.a(2,o)}},t,this)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){v(i,n,o,a,c,"next",t)}function c(t){v(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=l(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=u(t.value,2),r=o[0],i=o[1];e[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c));function x(t){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},x(t)}function k(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return C(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(C(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,C(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,C(d,"constructor",u),C(u,"constructor",s),s.displayName="GeneratorFunction",C(u,r,"GeneratorFunction"),C(d),C(d,r,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(k=function(){return{w:i,m:f}})()}function C(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}C=function(t,e,n,o){function i(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},C(t,e,n,o)}function P(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,E(o.key),o)}}function E(t){var e=function(t){if("object"!=x(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=x(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==x(e)?e:e+""}function T(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(T=function(){return!!t})()}function I(t){return I=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},I(t)}function j(t,e){return j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},j(t,e)}var A=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=I(e),function(t,e){if(e&&("object"==x(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,T()?Reflect.construct(e,n||[],I(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&j(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=k().m(function t(){var e=this;return k().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,w.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t(),e.connectResolve=null,e.connectReject=null)}).catch(function(t){console.error("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null})}catch(t){console.error("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null}}))},t)}),a=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){P(r,n,o,a,c,"next",t)}function c(t){P(r,n,o,a,c,"throw",t)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};w.on("open",e),w.on("close",n),w.on("error",o),w.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(w.off("open",this.eventHandlers.open),w.off("close",this.eventHandlers.close),w.off("error",this.eventHandlers.error),w.off("message",this.eventHandlers.message)),this.config.websocketUrl&&w.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(t))}catch(t){console.warn("🔌 WebSocketManager: Failed to send message:",t.message)}}},{key:"sendBinary",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(t)}catch(t){console.warn("🔌 WebSocketManager: Failed to send binary data:",t.message)}}},{key:"handleMessage",value:function(t){var e=this;if(t.data instanceof ArrayBuffer)this.emit("binaryAudio",t.data);else if(t.data instanceof Blob)t.data.arrayBuffer().then(function(t){e.emit("binaryAudio",t)}).catch(function(t){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return w.getAllConnections()}},{key:"clearAllConnections",value:function(){w.clearAll()}}],o&&O(n.prototype,o),r&&O(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a}(c);function F(t){return F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},F(t)}function D(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return B(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(B(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,B(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,B(d,"constructor",u),B(u,"constructor",s),s.displayName="GeneratorFunction",B(u,r,"GeneratorFunction"),B(d),B(d,r,"Generator"),B(d,o,function(){return this}),B(d,"toString",function(){return"[object Generator]"}),(D=function(){return{w:i,m:f}})()}function B(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}B=function(t,e,n,o){function i(e,n){B(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},B(t,e,n,o)}function R(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function _(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){R(i,o,r,a,c,"next",t)}function c(t){R(i,o,r,a,c,"throw",t)}a(void 0)})}}function U(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function M(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,N(o.key),o)}}function N(t){var e=function(t){if("object"!=F(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=F(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==F(e)?e:e+""}function z(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(z=function(){return!!t})()}function L(t){return L=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},L(t)}function V(t,e){return V=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},V(t,e)}var K=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=L(e),function(t,e){if(e&&("object"==F(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,z()?Reflect.construct(e,n||[],L(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&V(t,e)}(e,t),n=e,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var t,e=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return U(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?U(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{new URL(n);var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=_(D().m(function t(){var e,n,o=this;return D().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 1:if(this.mediaStream=t.v,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=2;break}return t.n=2,this.audioContext.resume();case 2:return e=this.getAudioProcessorPath(),t.n=3,this.audioContext.audioWorklet.addModule(e);case 3:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,n=e.type,r=e.data;"pcm_audio_data"===n&&o.emit("audioData",r)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,n=t.v,this.emit("error",n),n;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=_(D().m(function t(){var e;return D().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&M(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function H(t){return H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},H(t)}function W(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return G(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(G(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,G(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,G(d,"constructor",u),G(u,"constructor",s),s.displayName="GeneratorFunction",G(u,r,"GeneratorFunction"),G(d),G(d,r,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(W=function(){return{w:i,m:f}})()}function G(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}G=function(t,e,n,o){function i(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},G(t,e,n,o)}function q(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Q(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,J(o.key),o)}}function J(t){var e=function(t){if("object"!=H(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=H(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==H(e)?e:e+""}function Y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Y=function(){return!!t})()}function $(t){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},$(t)}function X(t,e){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},X(t,e)}var Z=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=$(e),function(t,e){if(e&&("object"==H(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Y()?Reflect.construct(e,n||[],$(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&X(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(r=W().m(function t(){var e,n,o,r,i,a,c,s,u,l=this;return W().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||(o=this.config.sampleRate?{sampleRate:this.config.sampleRate}:{},this.audioContext=new(window.AudioContext||window.webkitAudioContext)(o)),"suspended"!==(r=this.audioContext).state){t.n=3;break}return t.n=3,r.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return i=t.v,t.n=5,r.decodeAudioData(i);case 5:a=t.v,c=n&&!this.isPlaying&&null===this.currentSource,(s=r.createBufferSource()).buffer=a,s.connect(r.destination),this.currentSource=s,this.isPlaying=!0,c&&this.emit("playbackStarted"),s.onended=function(){l.currentSource=null,l.isProcessingQueue=!1,l.audioQueue.length>0?setTimeout(function(){return l.processQueue()},0):setTimeout(function(){0!==l.audioQueue.length||l.currentSource||(l.isPlaying=!1,l.emit("playbackStopped"))},100)},s.start(),t.n=7;break;case 6:t.p=6,u=t.v,this.currentSource=null,this.emit("playbackError",u),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){q(i,n,o,a,c,"next",t)}function c(t){q(i,n,o,a,c,"throw",t)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&Q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function tt(t){return tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tt(t)}function et(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return nt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(nt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,nt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,nt(d,"constructor",u),nt(u,"constructor",s),s.displayName="GeneratorFunction",nt(u,r,"GeneratorFunction"),nt(d),nt(d,r,"Generator"),nt(d,o,function(){return this}),nt(d,"toString",function(){return"[object Generator]"}),(et=function(){return{w:i,m:f}})()}function nt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}nt=function(t,e,n,o){function i(e,n){nt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},nt(t,e,n,o)}function ot(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function rt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){ot(i,o,r,a,c,"next",t)}function c(t){ot(i,o,r,a,c,"throw",t)}a(void 0)})}}function it(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function at(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?it(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):it(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=ut(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function st(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ut(o.key),o)}}function ut(t){var e=function(t){if("object"!=tt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==tt(e)?e:e+""}function lt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(lt=function(){return!!t})()}function dt(t){return dt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},dt(t)}function ft(t,e){return ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ft(t,e)}var pt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=dt(e),function(t,e){if(e&&("object"==tt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,lt()?Reflect.construct(e,n||[],dt(t).constructor):e.apply(t,n))}(this,e)).config=at({websocketUrl:n.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:n.agentId,appId:n.appId,ttpId:n.ttpId,voice:n.voice||"default",language:n.language||"en",sampleRate:n.sampleRate||16e3,agentSettingsOverride:n.agentSettingsOverride||null},n),t.isConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.webSocketManager=new A(at(at({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new K(t.config),t.audioPlayer=new Z(t.config),t.setupEventHandlers(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ft(t,e)}(e,t),n=e,o=[{key:"setupEventHandlers",value:function(){var t=this;this.webSocketManager.on("connected",function(){t.isConnected=!0,t.sendHelloMessage(),t.emit("connected")}),this.webSocketManager.on("disconnected",function(e){if(t.isConnected=!1,e&&1008===e.code&&e.reason&&(e.reason.includes("Domain not whitelisted")||e.reason.includes("domain")||e.reason.includes("whitelist"))){var n=new Error("DOMAIN_NOT_WHITELISTED");n.reason=e.reason,n.code=e.code,t.emit("domainError",n),t.emit("error",n)}t.isRecording&&t.stopRecording().catch(function(t){console.error("VoiceSDK: Error stopping recording on disconnect:",t)}),t.emit("disconnected",e)}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){if("greeting_audio"===e.t&&e.data)try{for(var n=atob(e.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(u=rt(et().m(function t(){var e,n;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isDestroyed){t.n=1;break}return t.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),t.n=2,this.connect();case 2:return t.a(2,t.v)}},t,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(c=rt(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw new Error("Not connected to voice server");case 1:return t.p=1,this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),t.n=2,this.audioRecorder.start();case 2:return t.a(2,!0);case 3:return t.p=3,e=t.v,console.error("❌ VoiceSDK: Failed to start recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=rt(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=at(at({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={t:"hello"};if(!this.config.appId){var e=new Error("appId is required for connection");return console.error("VoiceSDK: Failed to send hello message:",e),void this.emit("error",e)}t.appId=this.config.appId,this.config.agentSettingsOverride&&Object.keys(this.config.agentSettingsOverride).length>0&&(t.agentSettingsOverride=this.config.agentSettingsOverride,console.log("🔧 VoiceSDK: Sending agent settings override:",Object.keys(this.config.agentSettingsOverride)));try{this.webSocketManager.sendMessage(t)}catch(e){console.error("VoiceSDK: Failed to send hello message:",e),this.emit("error",e)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&st(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(c);function ht(t){return ht="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ht(t)}function vt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,gt(o.key),o)}}function gt(t){var e=function(t){if("object"!=ht(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ht(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ht(e)?e:e+""}var yt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){return this.events[t]||(this.events[t]=[]),this.events[t].push(e),this}},{key:"off",value:function(t,e){return this.events[t]?(this.events[t]=this.events[t].filter(function(t){return t!==e}),this):this}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];return!!this.events[t]&&(this.events[t].forEach(function(t){t.apply(void 0,n)}),!0)}},{key:"once",value:function(t,e){var n=this,o=function(){e.apply(void 0,arguments),n.off(t,o)};return this.on(t,o)}},{key:"removeAllListeners",value:function(t){return t?delete this.events[t]:this.events={},this}}],e&&vt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();const mt=yt;function bt(t){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},bt(t)}function St(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,wt(o.key),o)}}function wt(t){var e=function(t){if("object"!=bt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==bt(e)?e:e+""}const xt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCM"},(e=[{key:"decode",value:function(t){if(t instanceof ArrayBuffer)return t;if(t instanceof Uint8Array)return t.buffer;throw new Error("Invalid PCM data type")}},{key:"encode",value:function(t){return t}}])&&St(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function kt(t){return kt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},kt(t)}function Ct(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Pt(o.key),o)}}function Pt(t){var e=function(t){if("object"!=kt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=kt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==kt(e)?e:e+""}const Ot=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCMU"},(e=[{key:"decode",value:function(t){for(var e=t instanceof Uint8Array?t:new Uint8Array(t),n=new Int16Array(e.length),o=0;o<e.length;o++)n[o]=this.mulawToLinear(e[o]);return n.buffer}},{key:"encode",value:function(t){for(var e=t instanceof Int16Array?t:new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++)n[o]=this.linearToMulaw(e[o]);return n}},{key:"mulawToLinear",value:function(t){var e=1<<3+(t>>4&7);return(128&t?-1:1)*(132+(15&t)*e+(e>>1)-4)}},{key:"linearToMulaw",value:function(t){var e=t>>8&128;e&&(t=-t),t>32635&&(t=32635),t+=132;for(var n=7,o=16384;0===(t&o)&&n>0;n--,o>>=1);return 255&~(e|n<<4|t>>n+3&15)}}])&&Ct(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Et(t){return Et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Et(t)}function Tt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,It(o.key),o)}}function It(t){var e=function(t){if("object"!=Et(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Et(e)?e:e+""}const jt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCMA"},(e=[{key:"decode",value:function(t){for(var e=t instanceof Uint8Array?t:new Uint8Array(t),n=new Int16Array(e.length),o=0;o<e.length;o++)n[o]=this.alawToLinear(e[o]);return n.buffer}},{key:"encode",value:function(t){for(var e=t instanceof Int16Array?t:new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++)n[o]=this.linearToAlaw(e[o]);return n}},{key:"alawToLinear",value:function(t){var e=(t^=85)>>4&7,n=15&t;return(128&t?-1:1)*(0===e?8+(n<<4):264+(n<<4)<<e-1)}},{key:"linearToAlaw",value:function(t){var e,n,o=t>>8&128;if(o&&(t=-t),t>32635&&(t=32635),t<256)e=0,n=t>>4;else{e=7;for(var r=16384;0===(t&r)&&e>0;e--,r>>=1);n=t>>e+3&15}return 85^(o|e<<4|n)}}])&&Tt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function At(t){return At="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},At(t)}function Ft(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function Dt(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(At(t)+" is not iterable")}function Bt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Rt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Rt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Rt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Rt(d,"constructor",u),Rt(u,"constructor",s),s.displayName="GeneratorFunction",Rt(u,r,"GeneratorFunction"),Rt(d),Rt(d,r,"Generator"),Rt(d,o,function(){return this}),Rt(d,"toString",function(){return"[object Generator]"}),(Bt=function(){return{w:i,m:f}})()}function Rt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Rt=function(t,e,n,o){function i(e,n){Rt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Rt(t,e,n,o)}function _t(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Ut(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){_t(i,o,r,a,c,"next",t)}function c(t){_t(i,o,r,a,c,"throw",t)}a(void 0)})}}function Mt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Nt(o.key),o)}}function Nt(t){var e=function(t){if("object"!=At(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=At(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==At(e)?e:e+""}function zt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(zt=function(){return!!t})()}function Lt(t){return Lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Lt(t)}function Vt(t,e){return Vt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Vt(t,e)}var Kt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=Lt(e),function(t,e){if(e&&("object"==At(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,zt()?Reflect.construct(e,n||[],Lt(t).constructor):e.apply(t,n))}(this,e)).config=n,t.audioContext=null,t.audioQueue=[],t.isPlaying=!1,t.isProcessingQueue=!1,t.currentSource=null,t.outputFormat=null,t.nextStartTime=0,t.scheduledBuffers=0,t.scheduledSources=new Set,t.pcmChunkQueue=[],t.preparedBuffer=[],t.isProcessingPcmQueue=!1,t.isSchedulingFrames=!1,t.MAX_LOOKAHEAD_SECONDS=.02,t.codecs={pcm:new xt,pcmu:new Ot,pcma:new jt},t.SUPPORTED_CONTAINERS=["wav","raw"],t.SUPPORTED_ENCODINGS=["pcm","pcmu","pcma"],t.SUPPORTED_SAMPLE_RATES=[8e3,16e3,22050,24e3,44100,48e3],t.SUPPORTED_BIT_DEPTHS=[8,16,24],t.SUPPORTED_CHANNELS=[1],console.log("🎵 AudioPlayer v2 initialized"),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Vt(t,e)}(e,t),n=e,o=[{key:"setOutputFormat",value:function(t){var e;this.validateFormat(t)||(console.warn("⚠️ AudioPlayer: Invalid format, using defaults:",t),t=this.getDefaultFormat());var n=null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate,o=t.sampleRate;this.outputFormat=t,console.log("✅ AudioPlayer v2: Format set:",t),this.audioContext&&n&&n!==o&&(console.warn("⚠️ AudioPlayer: Sample rate changed, recreating AudioContext"),console.warn(" Old: ".concat(n,"Hz → New: ").concat(o,"Hz")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null,console.log("ℹ️ AudioContext will be recreated on next audio chunk with correct sample rate"))}},{key:"validateFormat",value:function(t){var e,n;if(!t)return!1;var o=null===(e=t.container)||void 0===e?void 0:e.toLowerCase(),r=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&r&&this.SUPPORTED_CONTAINERS.includes(o)&&this.SUPPORTED_ENCODINGS.includes(r)&&this.SUPPORTED_SAMPLE_RATES.includes(t.sampleRate)&&this.SUPPORTED_BIT_DEPTHS.includes(t.bitDepth)&&(!t.channels||this.SUPPORTED_CHANNELS.includes(t.channels))}},{key:"getDefaultFormat",value:function(){return{container:"raw",encoding:"pcm",sampleRate:16e3,channels:1,bitDepth:16}}},{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){console.error("❌ AudioPlayer v2: Playback error:",t),this.emit("playbackError",t)}}},{key:"playChunk",value:(c=Ut(Bt().m(function t(e){var n,o,r=this;return Bt().w(function(t){for(;;)switch(t.n){case 0:(n=this.prepareChunk(e))?(this.preparedBuffer.push(n),(this.preparedBuffer.length<=3||this.preparedBuffer.length%10==0)&&console.log("📥 AudioPlayer: Frame received, queued: ".concat(this.preparedBuffer.length,", scheduled: ").concat(this.scheduledBuffers,", isScheduling: ").concat(this.isSchedulingFrames)),this.isSchedulingFrames?setTimeout(function(){r.preparedBuffer.length>0&&!r.isSchedulingFrames&&r.schedulePreparedFrames()},5):this.schedulePreparedFrames(),this.pcmChunkQueue.length>0&&!this.isProcessingPcmQueue&&this.processPcmQueue()):(console.error("❌ AudioPlayer: playChunk failed - prepareChunk returned null"),console.error(" pcmData length:",(null==e?void 0:e.byteLength)||"undefined"),console.error(" outputFormat:",this.outputFormat),console.error(" audioContext:",this.audioContext?"initialized":"not initialized"),console.error(" audioContext state:",(null===(o=this.audioContext)||void 0===o?void 0:o.state)||"N/A"),this.emit("playbackError",new Error("Failed to prepare PCM chunk for playback")));case 1:return t.a(2)}},t,this)})),function(t){return c.apply(this,arguments)})},{key:"prepareChunk",value:function(t){try{var e;if(!this.outputFormat)return console.error("❌ AudioPlayer: Cannot prepare chunk - outputFormat not set"),console.error(" Call setOutputFormat() before playing audio chunks"),null;if(this.audioContext||this.initializeAudioContext(),!this.audioContext)return console.error("❌ AudioPlayer: Cannot prepare chunk - AudioContext not available"),null;var n=t;if(t.byteLength%2!=0){console.warn("⚠️ Odd PCM chunk size, padding:",t.byteLength);var o=new Uint8Array(t.byteLength+1);o.set(new Uint8Array(t),0),o[t.byteLength]=0,n=o.buffer}for(var r=new Int16Array(n),i=new Float32Array(r.length),a=1/32768,c=r.length,s=0;s<c;s++)i[s]=r[s]*a;var u=(null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||this.audioContext.sampleRate,l=this.audioContext.sampleRate,d=this.audioContext.createBuffer(1,i.length,u);d.getChannelData(0).set(i);var f=d.duration,p=i.length,h=f;return l!==u&&(h=p/l),{buffer:d,duration:h,sampleRate:u,contextSampleRate:l}}catch(t){return console.error("❌ AudioPlayer: Error preparing chunk:",t),null}}},{key:"applyFadeOut",value:function(t){return t}},{key:"schedulePreparedFrames",value:(a=Ut(Bt().m(function t(){var e,n,o,r,i,a=this;return Bt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isSchedulingFrames){t.n=1;break}return t.a(2);case 1:if(this.isSchedulingFrames=!0,e=this.preparedBuffer.length,0===(n=Math.min(e,5))&&e>0&&(n=1),t.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:o=0,r=Bt().m(function t(){var e,n,r,i,c;return Bt().w(function(t){for(;;)switch(t.n){case 0:if(e=a.preparedBuffer.shift()){t.n=1;break}return t.a(2,1);case 1:(n=a.audioContext.createBufferSource()).buffer=e.buffer,n.connect(a.audioContext.destination),a.scheduledSources.add(n),r=a.audioContext.currentTime,0===a.scheduledBuffers?(a.nextStartTime<r&&(a.nextStartTime=r+a.MAX_LOOKAHEAD_SECONDS),console.log("🎵 Starting playback with minimal delay:",a.nextStartTime)):(i=r+a.MAX_LOOKAHEAD_SECONDS,a.nextStartTime<i&&(a.nextStartTime=i,console.warn("⚠️ AudioPlayer: Fell behind schedule, adjusting nextStartTime to ".concat(a.nextStartTime.toFixed(4),"s")))),n.start(a.nextStartTime),a.nextStartTime+=e.duration,a.nextStartTime=Math.round(1e6*a.nextStartTime)/1e6,c=a.nextStartTime-e.duration,a.scheduledBuffers<5&&(console.log("🎵 AudioPlayer: Scheduled frame ".concat(a.scheduledBuffers+1," at ").concat(c.toFixed(4),"s, next at ").concat(a.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(e.duration.toFixed(4),"s (").concat((1e3*e.duration).toFixed(2),"ms), Queued: ").concat(a.preparedBuffer.length,", Scheduled: ").concat(a.scheduledBuffers))),a.scheduledBuffers++,o++,n.onended=function(){if(a.scheduledSources.delete(n),a.scheduledBuffers--,0===a.scheduledBuffers&&0===a.preparedBuffer.length&&0===a.pcmChunkQueue.length)a.isPlaying=!1,a.isSchedulingFrames=!1,console.log("🛑 AudioPlayer: Emitting playbackStopped event (all buffers finished)"),a.emit("playbackStopped");else if(a.preparedBuffer.length>0)setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()},0);else if(a.scheduledBuffers>0){var t=function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(t,10)};setTimeout(t,10)}},a.isPlaying||(a.isPlaying=!0,console.log("🎵 AudioPlayer: Emitting playbackStarted event"),a.emit("playbackStarted"));case 2:return t.a(2)}},t)});case 4:if(!(this.preparedBuffer.length>0&&o<n)){t.n=7;break}return t.d(Dt(r()),5);case 5:if(!t.v){t.n=6;break}return t.a(3,7);case 6:t.n=4;break;case 7:this.isSchedulingFrames=!1,this.preparedBuffer.length>0&&requestAnimationFrame(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()}),this.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0&&a.schedulePreparedFrames()},10)},10),t.n=9;break;case 8:t.p=8,i=t.v,console.error("❌ AudioPlayer v2: Error scheduling frames:",i),this.emit("playbackError",i),this.isSchedulingFrames=!1;case 9:return t.a(2)}},t,this,[[2,8]])})),function(){return a.apply(this,arguments)})},{key:"processPcmQueue",value:(i=Ut(Bt().m(function t(){var e,n,o,r,i,a,c,s,u,l,d,f,p,h,v,g,y,m,b,S,w=this;return Bt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingPcmQueue){t.n=1;break}return t.a(2);case 1:if(this.isProcessingPcmQueue=!0,t.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:if(!(this.pcmChunkQueue.length>0)){t.n=5;break}if(o=this.pcmChunkQueue.shift()){t.n=4;break}return t.a(3,3);case 4:for(r=o,o.byteLength%2!=0&&(console.warn("⚠️ Odd PCM chunk size, padding:",o.byteLength),(i=new Uint8Array(o.byteLength+1)).set(new Uint8Array(o),0),i[o.byteLength]=0,r=i.buffer),a=new Int16Array(r),c=new Float32Array(a.length),s=1/32768,u=a.length,l=0;l<u;l++)c[l]=a[l]*s;d=(null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||this.audioContext.sampleRate,f=this.audioContext.sampleRate,null!==(n=this.outputFormat)&&void 0!==n&&n.sampleRate?this.scheduledBuffers<3&&console.log("🎵 AudioPlayer: Creating buffer at ".concat(d,"Hz (AudioContext: ").concat(f,"Hz)")):console.warn("⚠️ AudioPlayer: outputFormat.sampleRate not set! Using AudioContext sample rate:",f),(p=this.audioContext.createBuffer(1,c.length,d)).getChannelData(0).set(c),(h=this.audioContext.createBufferSource()).buffer=p,h.connect(this.audioContext.destination),v=this.audioContext.currentTime,this.nextStartTime<v&&(this.nextStartTime=v,0===this.scheduledBuffers&&console.log("🎵 Starting playback at current time:",v)),g=p.duration,y=c.length,m=g,f!==d&&(m=y/f,this.scheduledBuffers<3&&(console.log("🔄 Resampling detected: ".concat(d,"Hz → ").concat(f,"Hz")),console.log(" Buffer duration: ".concat(g.toFixed(4),"s, Calculated: ").concat(m.toFixed(4),"s")))),h.start(this.nextStartTime),this.nextStartTime+=m,this.nextStartTime=Math.round(1e6*this.nextStartTime)/1e6,this.scheduledBuffers<3&&(b=this.nextStartTime-m,console.log("🎵 AudioPlayer: Scheduled chunk ".concat(this.scheduledBuffers+1," at ").concat(b.toFixed(4),"s, next at ").concat(this.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(m.toFixed(4),"s (").concat((1e3*m).toFixed(2),"ms)"))),this.scheduledBuffers++,h.onended=function(){w.scheduledBuffers--,0===w.scheduledBuffers&&0===w.pcmChunkQueue.length&&(w.isPlaying=!1,w.isProcessingPcmQueue=!1,w.emit("playbackStopped"))},this.isPlaying||(this.isPlaying=!0,this.emit("playbackStarted")),t.n=3;break;case 5:this.isProcessingPcmQueue=!1,t.n=7;break;case 6:t.p=6,S=t.v,console.error("❌ AudioPlayer v2: Error playing chunk:",S),this.emit("playbackError",S),this.isProcessingPcmQueue=!1;case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return i.apply(this,arguments)})},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);console.log("🎵 AudioPlayer: Processing ".concat(e.length," bytes")),console.log("🎵 AudioPlayer: Negotiated format:",this.outputFormat);var n=this.outputFormat&&this.outputFormat.container&&"wav"===this.outputFormat.container.toLowerCase(),o=this.outputFormat&&this.outputFormat.container&&"raw"===this.outputFormat.container.toLowerCase(),r=this.isWavFile(e);if(r&&console.log("🎵 AudioPlayer: Data has WAV header (RIFF)"),o&&r)return console.error("❌ AudioPlayer: CRITICAL MISMATCH!"),console.error(" Negotiated format: RAW"),console.error(" Actual data: WAV (RIFF header detected)"),console.error(" Backend is ignoring format request and sending WAV anyway."),console.warn("⚠️ AudioPlayer: Processing as WAV to avoid playback failure, but UI configuration was bypassed."),this.handleWavFile(e);if(o&&!r)console.log("🎵 AudioPlayer: Processing as RAW data (as negotiated)");else{if(n&&r)return console.log("✅ AudioPlayer: Processing as WAV file (matches negotiation)"),this.handleWavFile(e);if(n&&!r)return console.warn("⚠️ AudioPlayer: Negotiated WAV but data lacks WAV header. Attempting WAV processing anyway."),this.handleWavFile(e);if(!this.outputFormat&&r)return console.log("🎵 AudioPlayer: No format negotiated, auto-detecting WAV"),this.handleWavFile(e);this.outputFormat||r||(console.warn("⚠️ AudioPlayer: No format negotiated and data not WAV, using defaults"),this.outputFormat=this.getDefaultFormat())}return this.outputFormat||(console.warn("⚠️ AudioPlayer: No format set, using defaults"),this.outputFormat=this.getDefaultFormat()),console.log("🎵 AudioPlayer: Processing as RAW data with encoding:",this.outputFormat.encoding),this.handleRawData(e)}},{key:"isWavFile",value:function(t){return t.length>=44&&82===t[0]&&73===t[1]&&70===t[2]&&70===t[3]}},{key:"handleWavFile",value:function(t){var e=this.parseWavHeader(t);if(console.log("🎵 WAV file detected:",{format:e.audioFormat,encoding:this.getEncodingName(e.audioFormat),sampleRate:e.sampleRate,channels:e.channels,bitDepth:e.bitsPerSample}),1===e.audioFormat)return console.log("✅ PCM WAV - using directly"),new Blob([t],{type:"audio/wav"});var n=this.getCodecForWavFormat(e.audioFormat);if(!n)throw new Error("Unsupported WAV format code: ".concat(e.audioFormat));console.log("🔄 Non-PCM WAV - converting to PCM WAV");var o=t.slice(44),r=n.decode(o),i=this.createWavHeader(r.byteLength,e.sampleRate,e.channels,16);return new Blob([i,r],{type:"audio/wav"})}},{key:"handleRawData",value:function(t){var e,n,o=this.outputFormat.encoding.toLowerCase(),r=this.getCodec(o);if(!r)throw new Error("No codec found for encoding: ".concat(o));if(console.log("🎵 AudioPlayer: Decoding ".concat(o.toUpperCase()," to PCM")),console.log("🎵 AudioPlayer: Input format - bitDepth: ".concat(this.outputFormat.bitDepth,", sampleRate: ").concat(this.outputFormat.sampleRate)),"pcm"===o){var i=this.outputFormat.bitDepth||16;t.length,24===i?(console.warn("⚠️ AudioPlayer: Format says 24-bit PCM, but browser support is limited."),console.warn(" Treating as 16-bit PCM. If audio sounds wrong, backend should send 16-bit instead."),e=this.convert24BitTo16Bit(t),n=16):8===i?(console.log("🔄 AudioPlayer: Converting 8-bit PCM to 16-bit PCM"),e=this.convert8BitTo16Bit(t),n=16):(e=t.buffer,n=i,console.log("✅ AudioPlayer: Using native ".concat(i,"-bit PCM (no conversion needed)")))}else e=r.decode(t),n=16,console.log("🔄 AudioPlayer: Decoded ".concat(o.toUpperCase()," to 16-bit PCM"));var a=this.createWavHeader(e.byteLength,this.outputFormat.sampleRate,this.outputFormat.channels,n);return new Blob([a,e],{type:"audio/wav"})}},{key:"convert24BitTo16Bit",value:function(t){for(var e=Math.floor(t.length/3),n=new Int16Array(e),o=0;o<e;o++){var r=t[3*o],i=t[3*o+1],a=t[3*o+2],c=r|i<<8|(255&a)<<16;128&a&&(c|=4278190080),n[o]=Math.max(-32768,Math.min(32767,Math.round(c/256)))}return n.buffer}},{key:"convert8BitTo16Bit",value:function(t){for(var e=t.length,n=new Int16Array(e),o=0;o<e;o++){var r=t[o];n[o]=256*(r-128)}return n.buffer}},{key:"getCodec",value:function(t){var e={pcm:"pcm",linear:"pcm",l16:"pcm",pcmu:"pcmu",ulaw:"pcmu",mulaw:"pcmu",g711u:"pcmu",pcma:"pcma",alaw:"pcma",g711a:"pcma"}[t.toLowerCase()];return this.codecs[e]}},{key:"getCodecForWavFormat",value:function(t){switch(t){case 1:return this.codecs.pcm;case 6:return this.codecs.pcma;case 7:return this.codecs.pcmu;default:return null}}},{key:"getEncodingName",value:function(t){switch(t){case 1:return"PCM";case 6:return"A-law";case 7:return"μ-law";default:return"Unknown (".concat(t,")")}}},{key:"parseWavHeader",value:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{audioFormat:e.getUint16(20,!0),channels:e.getUint16(22,!0),sampleRate:e.getUint32(24,!0),byteRate:e.getUint32(28,!0),blockAlign:e.getUint16(32,!0),bitsPerSample:e.getUint16(34,!0)}}},{key:"createWavHeader",value:function(t,e,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+t,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,e,!0),i.setUint32(28,e*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0),r}},{key:"initializeAudioContext",value:function(){var t,e,n=(null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate)||48e3;if(48e3!==n&&44100!==n&&(console.log("ℹ️ AudioPlayer: Backend requested ".concat(n,"Hz, but browser may resample to 48kHz")),console.log(" Consider requesting 48kHz from backend to avoid resampling and improve quality")),this.audioContext){var o=this.audioContext.sampleRate;if(!(Math.abs(o-n)>100))return;console.warn("⚠️ AudioPlayer: AudioContext sample rate (".concat(o,"Hz) doesn't match format (").concat(n,"Hz), recreating...")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null}console.log("🎵 AudioPlayer: Creating AudioContext at ".concat(n,"Hz (from outputFormat: ").concat((null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||"not set",")"));try{this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n,latencyHint:"playback"}),console.log("✅ AudioContext created at ".concat(this.audioContext.sampleRate,"Hz (requested: ").concat(n,"Hz)")),Math.abs(this.audioContext.sampleRate-n)>100?(console.error("❌ CRITICAL: Browser sample rate mismatch!"),console.error(" Requested: ".concat(n,"Hz")),console.error(" Got: ".concat(this.audioContext.sampleRate,"Hz")),console.error(" This WILL cause audio distortion/noise!"),console.error(" Solution: Backend should send ".concat(this.audioContext.sampleRate,"Hz audio instead"))):this.audioContext.sampleRate!==n&&(console.warn("⚠️ Browser adjusted sample rate: ".concat(n,"Hz → ").concat(this.audioContext.sampleRate,"Hz")),console.warn(" Browser will automatically resample audio."))}catch(t){console.error("❌ Failed to create AudioContext:",t),this.audioContext=new(window.AudioContext||window.webkitAudioContext),console.log("ℹ️ Using browser default: ".concat(this.audioContext.sampleRate,"Hz"))}}},{key:"processQueue",value:(r=Ut(Bt().m(function t(){var e,n,o,r,i,a,c,s=this;return Bt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return o=t.v,t.n=5,this.audioContext.decodeAudioData(o);case 5:r=t.v,i=n&&!this.isPlaying&&null===this.currentSource,(a=this.audioContext.createBufferSource()).buffer=r,a.connect(this.audioContext.destination),this.currentSource=a,this.isPlaying=!0,i&&this.emit("playbackStarted"),a.onended=function(){s.currentSource=null,s.isProcessingQueue=!1,s.audioQueue.length>0?setTimeout(function(){return s.processQueue()},50):setTimeout(function(){0!==s.audioQueue.length||s.currentSource||(s.isPlaying=!1,s.emit("playbackStopped"))},100)},a.start(),t.n=7;break;case 6:t.p=6,c=t.v,console.error("❌ AudioPlayer v2: Error processing queue:",c),this.currentSource=null,this.emit("playbackError",c),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return s.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"reset",value:function(){this.stop(),this.audioQueue=[],this.pcmChunkQueue=[]}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource||this.scheduledSources.size>0;if(console.log("🛑 AudioPlayer.stopImmediate() called"),console.log(" isPlaying:",this.isPlaying),console.log(" currentSource:",null!==this.currentSource),console.log(" scheduledSources.size:",this.scheduledSources.size),console.log(" scheduledBuffers:",this.scheduledBuffers),this.currentSource){try{console.log(" Stopping currentSource..."),this.currentSource.stop()}catch(t){console.log(" currentSource already stopped or error:",t.message)}this.currentSource=null}if(this.scheduledSources.size>0){console.log(" Stopping ".concat(this.scheduledSources.size," scheduled sources..."));var e,n=0,o=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Ft(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ft(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(this.scheduledSources);try{for(o.s();!(e=o.n()).done;){var r=e.value;try{r.stop(),n++}catch(t){console.log(" Source already stopped or not started:",t.message)}}}catch(t){o.e(t)}finally{o.f()}console.log(" Stopped ".concat(n," sources")),this.scheduledSources.clear()}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],this.pcmChunkQueue=[],this.preparedBuffer=[],this.isProcessingPcmQueue=!1,this.isSchedulingFrames=!1,this.nextStartTime=0,this.scheduledBuffers=0,t&&(console.log("🛑 AudioPlayer: Emitting playbackStopped event (stopImmediate called)"),this.emit("playbackStopped"))}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed",outputFormat:this.outputFormat,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&&Mt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c}(mt);const Ht=Kt;function Wt(t){return Wt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Wt(t)}function Gt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return qt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(qt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,qt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,qt(d,"constructor",u),qt(u,"constructor",s),s.displayName="GeneratorFunction",qt(u,r,"GeneratorFunction"),qt(d),qt(d,r,"Generator"),qt(d,o,function(){return this}),qt(d,"toString",function(){return"[object Generator]"}),(Gt=function(){return{w:i,m:f}})()}function qt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}qt=function(t,e,n,o){function i(e,n){qt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},qt(t,e,n,o)}function Qt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Jt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Qt(i,o,r,a,c,"next",t)}function c(t){Qt(i,o,r,a,c,"throw",t)}a(void 0)})}}function Yt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function $t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Xt(o.key),o)}}function Xt(t){var e=function(t){if("object"!=Wt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Wt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Wt(e)?e:e+""}function Zt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Zt=function(){return!!t})()}function te(t){return te=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},te(t)}function ee(t,e){return ee=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ee(t,e)}var ne=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=te(e),function(t,e){if(e&&("object"==Wt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Zt()?Reflect.construct(e,n||[],te(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ee(t,e)}(e,t),n=e,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var t,e=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Yt(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Yt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=Jt(Gt().m(function t(){var e,n,o,r,i,a,c=this;return Gt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,"https:"===location.protocol||"localhost"===location.hostname||"127.0.0.1"===location.hostname){t.n=1;break}throw e=new Error("Microphone access requires HTTPS. Please use https:// or test on localhost."),console.error("❌ AudioRecorder:",e.message),this.emit("error",e),e;case 1:if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){t.n=2;break}throw n=new Error("getUserMedia is not supported in this browser. Please use a modern browser."),console.error("❌ AudioRecorder:",n.message),this.emit("error",n),n;case 2:return console.log("🎤 AudioRecorder: Requesting microphone access..."),t.n=3,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 3:if(this.mediaStream=t.v,console.log("✅ AudioRecorder: Microphone access granted"),this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=4;break}return t.n=4,this.audioContext.resume();case 4:return o=this.getAudioProcessorPath(),t.n=5,this.audioContext.audioWorklet.addModule(o);case 5:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,n=e.type,o=e.data;"pcm_audio_data"===n&&c.emit("audioData",o)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=7;break;case 6:throw t.p=6,a=t.v,r=a.message,"NotAllowedError"===a.name||"PermissionDeniedError"===a.name?(r="Microphone permission denied. Please allow microphone access in your browser settings and try again.",console.error("❌ AudioRecorder: Permission denied. User needs to grant microphone access.")):"NotFoundError"===a.name||"DevicesNotFoundError"===a.name?(r="No microphone found. Please connect a microphone and try again.",console.error("❌ AudioRecorder: No microphone device found.")):"NotReadableError"===a.name||"TrackStartError"===a.name?(r="Microphone is already in use by another application. Please close other apps using the microphone and try again.",console.error("❌ AudioRecorder: Microphone is busy or not readable.")):a.message&&a.message.includes("not allowed by the user agent")&&(r="Microphone access blocked. On mobile devices, please tap the recording button directly (not from an iframe or popup).",console.error("❌ AudioRecorder: User agent blocked microphone access. This often happens on mobile when not called from direct user interaction.")),(i=new Error(r)).name=a.name,i.originalError=a,console.error("❌ AudioRecorder: Failed to start recording:",i),this.emit("error",i),i;case 7:return t.a(2)}},t,this,[[0,6]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=Jt(Gt().m(function t(){var e;return Gt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&$t(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(mt);function oe(t){return oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},oe(t)}function re(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ie(o.key),o)}}function ie(t){var e=function(t){if("object"!=oe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=oe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==oe(e)?e:e+""}const ae=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"extractPcmFromWav",value:function(t){var e=t instanceof Uint8Array?t:new Uint8Array(t);if(e.length<44)throw new Error("WAV data too short (< 44 bytes)");if("RIFF"!==String.fromCharCode(e[0],e[1],e[2],e[3]))throw new Error("Not a valid WAV file - missing RIFF header");if("WAVE"!==String.fromCharCode(e[8],e[9],e[10],e[11]))throw new Error("Not a valid WAV file - missing WAVE format");for(var n=e[22]|e[23]<<8,o=e[24]|e[25]<<8|e[26]<<16|e[27]<<24,r=e[34]|e[35]<<8,i=-1,a=12;a<e.length-8;a+=4){if("data"===String.fromCharCode(e[a],e[a+1],e[a+2],e[a+3])){i=a;break}a+=4+(e[a+4]|e[a+5]<<8|e[a+6]<<16|e[a+7]<<24)}if(-1===i)throw new Error("No data chunk found in WAV");var c=e[i+4]|e[i+5]<<8|e[i+6]<<16|e[i+7]<<24,s=i+8,u=Math.min(c,e.length-s);return{pcmData:e.slice(s,s+u).buffer,format:{sampleRate:o,channels:n,bitDepth:r}}}},{key:"isWavFile",value:function(t){return t.length>=44&&82===t[0]&&73===t[1]&&70===t[2]&&70===t[3]}},{key:"createWavHeader",value:function(t,e,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+t,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,e,!0),i.setUint32(28,e*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0),r}},{key:"wrapPcmInWav",value:function(e,n){var o=t.createWavHeader(e.byteLength,n.sampleRate,n.channels||1,n.bitDepth||16),r=new Uint8Array(o.byteLength+e.byteLength);return r.set(new Uint8Array(o),0),r.set(new Uint8Array(e),o.byteLength),r.buffer}}],null&&re(e.prototype,null),n&&re(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function ce(t){return ce="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ce(t)}function se(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ue(o.key),o)}}function ue(t){var e=function(t){if("object"!=ce(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ce(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ce(e)?e:e+""}const le=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.codecs={pcm:new xt,pcmu:new Ot,pcma:new jt}},(e=[{key:"decodeToPcm",value:function(t,e){var n=null==e?void 0:e.toLowerCase();if(!n||"pcm"===n)return t instanceof ArrayBuffer?t:t instanceof Uint8Array?t.buffer:t;var o=this.codecs[n];if(!o)throw new Error("Unsupported encoding: ".concat(e));var r=t instanceof Uint8Array?t:new Uint8Array(t);return o.decode(r)}},{key:"encodeFromPcm",value:function(t,e){var n=null==e?void 0:e.toLowerCase();if(!n||"pcm"===n)return t;var o=this.codecs[n];if(!o)throw new Error("Unsupported target encoding: ".concat(e));var r=o.encode(t);return r instanceof Uint8Array?r.buffer:r}},{key:"getCodec",value:function(t){var e=null==t?void 0:t.toLowerCase();return this.codecs[e]||null}}])&&se(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function de(t){return de="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},de(t)}function fe(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,pe(o.key),o)}}function pe(t){var e=function(t){if("object"!=de(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=de(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==de(e)?e:e+""}const he=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"convert",value:function(e,n,o){if(n===o)return e;if(8===n)throw new Error("Source bit depth cannot be 8-bit (only 16-bit or 24-bit supported)");var r=n/8,i=o/8,a=e.byteLength/r;if(new ArrayBuffer(a*i),16===n&&16===o)return e;if(24===n&&16===o)return t.convert24To16(e);if(16===n&&24===o)return t.convert16To24(e);if(16===n&&8===o)return t.convert16To8(e);if(24===n&&8===o)return t.convert24To8(e);throw new Error("Unsupported bit depth conversion: ".concat(n,"-bit → ").concat(o,"-bit"))}},{key:"convert24To16",value:function(t){for(var e=new Uint8Array(t),n=Math.floor(e.length/3),o=new Int16Array(n),r=0;r<n;r++){var i=e[3*r],a=e[3*r+1],c=e[3*r+2],s=i|a<<8|(255&c)<<16;128&c&&(s|=4278190080),o[r]=Math.max(-32768,Math.min(32767,Math.round(s/256)))}return o.buffer}},{key:"convert16To24",value:function(t){for(var e=new Int16Array(t),n=new Uint8Array(3*e.length),o=0;o<e.length;o++){var r=256*e[o];n[3*o]=255&r,n[3*o+1]=r>>8&255,n[3*o+2]=r>>16&255}return n.buffer}},{key:"convert16To8",value:function(t){for(var e=new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++){var r=e[o];n[o]=Math.max(0,Math.min(255,Math.round(r/256+128)))}return n.buffer}},{key:"convert24To8",value:function(e){var n=t.convert24To16(e);return t.convert16To8(n)}}],null&&fe(e.prototype,null),n&&fe(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function ve(t){return ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ve(t)}function ge(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ye(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ye(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ye(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ye(d,"constructor",u),ye(u,"constructor",s),s.displayName="GeneratorFunction",ye(u,r,"GeneratorFunction"),ye(d),ye(d,r,"Generator"),ye(d,o,function(){return this}),ye(d,"toString",function(){return"[object Generator]"}),(ge=function(){return{w:i,m:f}})()}function ye(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ye=function(t,e,n,o){function i(e,n){ye(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ye(t,e,n,o)}function me(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function be(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Se(o.key),o)}}function Se(t){var e=function(t){if("object"!=ve(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ve(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ve(e)?e:e+""}const we=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"resample",value:(n=ge().m(function t(e,n,o){var r,i,a,c,s,u,l,d,f,p,h,v,g;return ge().w(function(t){for(;;)switch(t.n){case 0:if(n!==o){t.n=1;break}return t.a(2,e);case 1:for(r=new Int16Array(e),i=new Float32Array(r.length),a=1/32768,c=0;c<r.length;c++)i[c]=r[c]*a;return s=Math.ceil(i.length*o/n),u=new OfflineAudioContext(1,s,o),(l=u.createBuffer(1,i.length,n)).getChannelData(0).set(i),(d=u.createBufferSource()).buffer=l,d.connect(u.destination),d.start(),t.n=2,u.startRendering();case 2:for(f=t.v,p=f.getChannelData(0),h=new Int16Array(p.length),v=0;v<p.length;v++)g=Math.max(-1,Math.min(1,p[v])),h[v]=Math.round(32767*g);return t.a(2,h.buffer)}},t)}),o=function(){var t=this,e=arguments;return new Promise(function(o,r){var i=n.apply(t,e);function a(t){me(i,o,r,a,c,"next",t)}function c(t){me(i,o,r,a,c,"throw",t)}a(void 0)})},function(t,e,n){return o.apply(this,arguments)})}],e&&be(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function xe(t){return xe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},xe(t)}function ke(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Ce(o.key),o)}}function Ce(t){var e=function(t){if("object"!=xe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=xe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==xe(e)?e:e+""}const Pe=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"convert",value:function(e,n,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(n===o)return e;if(1===n&&1===o)return e;if(1===n&&2===o)return t.monoToStereo(e,r);if(2===n&&1===o)return t.stereoToMono(e,r);throw new Error("Unsupported channel conversion: ".concat(n," → ").concat(o))}},{key:"monoToStereo",value:function(t,e){for(var n=e/8,o=t.byteLength/n,r=new ArrayBuffer(o*n*2),i=new Uint8Array(t),a=new Uint8Array(r),c=0;c<o;c++)for(var s=c*n,u=c*n*2,l=0;l<n;l++)a[u+l]=i[s+l],a[u+n+l]=i[s+l];return r}},{key:"stereoToMono",value:function(t,e){var n=e/8,o=t.byteLength/(2*n),r=new ArrayBuffer(o*n),i=new Uint8Array(t),a=new Uint8Array(r);if(16===e)for(var c=0;c<o;c++){var s=c*n*2,u=s+n,l=(i[s]|i[s+1]<<8)<<16>>16,d=(i[u]|i[u+1]<<8)<<16>>16,f=Math.round((l+d)/2),p=c*n;a[p]=255&f,a[p+1]=f>>8&255}else for(var h=0;h<o;h++)for(var v=h*n*2,g=h*n,y=0;y<n;y++)a[g+y]=i[v+y];return r}}],null&&ke(e.prototype,null),n&&ke(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function Oe(t){return Oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Oe(t)}function Ee(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Te(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Te(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Te(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Te(d,"constructor",u),Te(u,"constructor",s),s.displayName="GeneratorFunction",Te(u,r,"GeneratorFunction"),Te(d),Te(d,r,"Generator"),Te(d,o,function(){return this}),Te(d,"toString",function(){return"[object Generator]"}),(Ee=function(){return{w:i,m:f}})()}function Te(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Te=function(t,e,n,o){function i(e,n){Te(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Te(t,e,n,o)}function Ie(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function je(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ie(Object(n),!0).forEach(function(e){Ae(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ie(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ae(t,e,n){return(e=Be(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Fe(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function De(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Be(o.key),o)}}function Be(t){var e=function(t){if("object"!=Oe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Oe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Oe(e)?e:e+""}const Re=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.requestedFormat=e,this.actualFormat=n,this.encodingConverter=new le,this.conversionSteps=[],this._analyzeConversions()},e=[{key:"_analyzeConversions",value:function(){this.conversionSteps=[],this.actualFormat.container!==this.requestedFormat.container&&("wav"===this.actualFormat.container?this.conversionSteps.push("extract_wav"):"wav"===this.requestedFormat.container&&this.conversionSteps.push("wrap_wav")),this.actualFormat.encoding!==this.requestedFormat.encoding&&("pcm"!==this.actualFormat.encoding&&this.conversionSteps.push("decode_encoding"),"pcm"!==this.requestedFormat.encoding&&this.conversionSteps.push("encode_encoding")),this.actualFormat.sampleRate!==this.requestedFormat.sampleRate&&this.conversionSteps.push("resample"),this.actualFormat.bitDepth!==this.requestedFormat.bitDepth&&this.conversionSteps.push("convert_bitdepth"),this.actualFormat.channels!==this.requestedFormat.channels&&this.conversionSteps.push("convert_channels")}},{key:"needsConversion",value:function(){return this.conversionSteps.length>0}},{key:"getConversionSteps",value:function(){var t=[];return this.conversionSteps.includes("extract_wav")&&t.push("Extract PCM from WAV (".concat(this.actualFormat.container," → raw)")),this.conversionSteps.includes("decode_encoding")&&t.push("Decode ".concat(this.actualFormat.encoding.toUpperCase()," → PCM")),this.conversionSteps.includes("resample")&&t.push("Resample ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz")),this.conversionSteps.includes("convert_bitdepth")&&t.push("Convert bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit")),this.conversionSteps.includes("convert_channels")&&t.push("Convert channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels)),this.conversionSteps.includes("encode_encoding")&&t.push("Encode PCM → ".concat(this.requestedFormat.encoding.toUpperCase())),this.conversionSteps.includes("wrap_wav")&&t.push("Wrap in WAV container (raw → ".concat(this.requestedFormat.container,")")),t}},{key:"convert",value:(n=Ee().m(function t(e){var n,o,r,i;return Ee().w(function(t){for(;;)switch(t.n){case 0:if(this.needsConversion()){t.n=1;break}return t.a(2,e instanceof ArrayBuffer?e:e.buffer);case 1:if(n=e instanceof ArrayBuffer?e:e.buffer,o=je({},this.actualFormat),this.conversionSteps.includes("extract_wav")&&(r=ae.extractPcmFromWav(n),n=r.pcmData,o=je(je({},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=he.convert(n,24,16),o.bitDepth=16,console.log("🔄 AudioFormatConverter: Normalized 24-bit → 16-bit PCM")),!this.conversionSteps.includes("resample")){t.n=3;break}return t.n=2,we.resample(n,o.sampleRate,this.requestedFormat.sampleRate);case 2:n=t.v,o.sampleRate=this.requestedFormat.sampleRate,console.log("🔄 AudioFormatConverter: Resampled ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz"));case 3:return this.conversionSteps.includes("convert_channels")&&(n=Pe.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=he.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=ae.wrapPcmInWav(n,o),o.container="wav",console.log("🔄 AudioFormatConverter: Wrapped in WAV container")),console.log("✅ AudioFormatConverter: Conversion complete"),t.a(2,n)}},t,this)}),o=function(){var t=this,e=arguments;return new Promise(function(o,r){var i=n.apply(t,e);function a(t){Fe(i,o,r,a,c,"next",t)}function c(t){Fe(i,o,r,a,c,"throw",t)}a(void 0)})},function(t){return o.apply(this,arguments)})}],e&&De(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function _e(t){return _e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_e(t)}function Ue(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Me(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ue(Object(n),!0).forEach(function(e){qe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ue(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ne(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ze(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ze(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ze(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ze(d,"constructor",u),ze(u,"constructor",s),s.displayName="GeneratorFunction",ze(u,r,"GeneratorFunction"),ze(d),ze(d,r,"Generator"),ze(d,o,function(){return this}),ze(d,"toString",function(){return"[object Generator]"}),(Ne=function(){return{w:i,m:f}})()}function ze(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ze=function(t,e,n,o){function i(e,n){ze(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ze(t,e,n,o)}function Le(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Ve(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Le(i,o,r,a,c,"next",t)}function c(t){Le(i,o,r,a,c,"throw",t)}a(void 0)})}}function Ke(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Qe(o.key),o)}}function He(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(He=function(){return!!t})()}function We(t){return We=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},We(t)}function Ge(t,e){return Ge=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ge(t,e)}function qe(t,e,n){return(e=Qe(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Qe(t){var e=function(t){if("object"!=_e(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=_e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==_e(e)?e:e+""}var Je=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=We(e),function(t,e){if(e&&("object"==_e(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,He()?Reflect.construct(e,n||[],We(t).constructor):e.apply(t,n))}(this,e)).version="2.0.0",t.config={websocketUrl:n.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:n.agentId,appId:n.appId,sampleRate:n.sampleRate||16e3,channels:n.channels||1,bitDepth:n.bitDepth||16,audioProcessorPath:n.audioProcessorPath,outputContainer:n.outputContainer||t.getDefaultContainer(n),outputEncoding:n.outputEncoding||n.outputCodec||"pcm",outputSampleRate:n.outputSampleRate||16e3,outputChannels:n.outputChannels||1,outputBitDepth:n.outputBitDepth||16,outputFrameDurationMs:n.outputFrameDurationMs||600,outputCodec:n.outputCodec,agentSettingsOverride:n.agentSettingsOverride||null,variables:n.variables||null,autoReconnect:!1!==n.autoReconnect,protocolVersion:n.protocolVersion||2},t.isConnected=!1,t.hasEverConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.outputAudioFormat=null,t.requestedOutputFormat=null,t.formatConverter=null,t.websocket=null,t.conversationId=null,t.transcriptQueue=[],t.currentPlayingSentenceId=null,t.audioFrameCount=0,t.audioPlayer=new Ht(t.config),t.audioRecorder=new ne(t.config),t.setupAudioPlayerEvents(),t.setupAudioRecorderEvents(),t.validateConfig(),console.log("🎵 VoiceSDK v2 initialized:",{version:t.version,outputContainer:t.config.outputContainer,outputEncoding:t.config.outputEncoding,outputSampleRate:t.config.outputSampleRate}),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Ge(t,e)}(e,t),n=e,o=[{key:"getDefaultContainer",value:function(t){return"wav"===t.outputCodec?"wav":"raw"}},{key:"validateInputFormat",value:function(t){var n;if(!t)return"Input format is required";var o=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&e.SUPPORTED_INPUT_ENCODINGS.includes(o)?t.sampleRate&&e.SUPPORTED_INPUT_SAMPLE_RATES.includes(t.sampleRate)?t.bitDepth&&e.SUPPORTED_INPUT_BIT_DEPTHS.includes(t.bitDepth)?t.channels&&e.SUPPORTED_INPUT_CHANNELS.includes(t.channels)?null:"Unsupported input channels: ".concat(t.channels,". Supported: ").concat(e.SUPPORTED_INPUT_CHANNELS.join(", ")):"Unsupported input bit depth: ".concat(t.bitDepth,". Supported: ").concat(e.SUPPORTED_INPUT_BIT_DEPTHS.join(", ")):"Unsupported input sample rate: ".concat(t.sampleRate,". Supported: ").concat(e.SUPPORTED_INPUT_SAMPLE_RATES.join(", ")):"Unsupported input encoding: ".concat(t.encoding,". Supported: ").concat(e.SUPPORTED_INPUT_ENCODINGS.join(", "))}},{key:"validateOutputFormat",value:function(t){var n,o;if(!t)return"Output format is required";var r=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();if(!r||!e.SUPPORTED_OUTPUT_ENCODINGS.includes(r))return"Unsupported output encoding: ".concat(t.encoding,". Supported: ").concat(e.SUPPORTED_OUTPUT_ENCODINGS.join(", "));if(!t.sampleRate||!e.SUPPORTED_OUTPUT_SAMPLE_RATES.includes(t.sampleRate))return"Unsupported output sample rate: ".concat(t.sampleRate,". Supported: ").concat(e.SUPPORTED_OUTPUT_SAMPLE_RATES.join(", "));if(!t.bitDepth||!e.SUPPORTED_OUTPUT_BIT_DEPTHS.includes(t.bitDepth))return"Unsupported output bit depth: ".concat(t.bitDepth,". Supported: ").concat(e.SUPPORTED_OUTPUT_BIT_DEPTHS.join(", "));if(!t.channels||!e.SUPPORTED_OUTPUT_CHANNELS.includes(t.channels))return"Unsupported output channels: ".concat(t.channels,". Supported: ").concat(e.SUPPORTED_OUTPUT_CHANNELS.join(", "));var i=null===(o=t.container)||void 0===o?void 0:o.toLowerCase();return i&&e.SUPPORTED_OUTPUT_CONTAINERS.includes(i)?null:"Unsupported output container: ".concat(t.container,". Supported: ").concat(e.SUPPORTED_OUTPUT_CONTAINERS.join(", "))}},{key:"validateConfig",value:function(){var t={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},e=this.validateInputFormat(t);if(e)return console.error("❌ VoiceSDK v2: Invalid input format:",e),void this.emit("error",new Error(e));var n={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},o=this.validateOutputFormat(n);if(o)return console.error("❌ VoiceSDK v2: Invalid output format:",o),void this.emit("error",new Error(o));console.log("✅ VoiceSDK v2: Format validation passed")}},{key:"setupAudioPlayerEvents",value:function(){var t=this;this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_started_playing message to server"),t.sendMessage({t:"audio_started_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_started_playing - not connected")}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_stopped_playing message to server"),t.sendMessage({t:"audio_stopped_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_stopped_playing - not connected")}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e),t.emit("error",e)})}},{key:"setupAudioRecorderEvents",value:function(){var t=this;this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0;var e=t.audioPlayer.getStatus(),n=e.scheduledBuffers&&e.scheduledBuffers>0||e.scheduledSourcesCount&&e.scheduledSourcesCount>0,o=t.isPlaying||e.isPlaying||n;console.log("🎤 VoiceSDK v2: Recording started - checking for barge-in..."),console.log(" VoiceSDK.isPlaying:",t.isPlaying),console.log(" AudioPlayer.isPlaying:",e.isPlaying),console.log(" scheduledBuffers:",e.scheduledBuffers||0),console.log(" scheduledSourcesCount:",e.scheduledSourcesCount||0),console.log(" preparedBufferLength:",e.preparedBufferLength||0),console.log(" isActuallyPlaying:",o),o?(console.log("🛑 VoiceSDK v2: Barge-in detected! Stopping audio playback..."),t.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),t.isConnected?(t.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")):console.warn("⚠️ VoiceSDK v2: Cannot send barge_in - not connected")):console.log("ℹ️ VoiceSDK v2: No audio playing, normal recording start"),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t._bargeInChecked=!1,t.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped")}),this.audioRecorder.on("audioData",function(e){if(!t._bargeInChecked&&t.isRecording){t._bargeInChecked=!0;var n=t.audioPlayer.getStatus(),o=n.scheduledBuffers&&n.scheduledBuffers>0||n.scheduledSourcesCount&&n.scheduledSourcesCount>0;(t.isPlaying||n.isPlaying||o)&&(console.log("🛑 VoiceSDK v2: Barge-in detected on first audio data! Stopping audio playback..."),console.log(" VoiceSDK.isPlaying:",t.isPlaying),console.log(" AudioPlayer.isPlaying:",n.isPlaying),console.log(" scheduledBuffers:",n.scheduledBuffers||0),console.log(" scheduledSourcesCount:",n.scheduledSourcesCount||0),t.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),t.isConnected&&(t.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")))}t.isConnected&&t.sendBinary(e)}),this.audioRecorder.on("error",function(e){console.error("❌ AudioRecorder error:",e),t.emit("error",e)})}},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),e.toString()){var n=t.includes("?")?"&":"?";return"".concat(t).concat(n).concat(e.toString())}return t}},{key:"connect",value:(u=Ve(Ne().m(function t(){var e,n,o=this;return Ne().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK v2: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:if(!this.isConnected){t.n=2;break}return console.warn("VoiceSDK v2: Already connected"),t.a(2,!0);case 2:return t.p=2,e=this.buildWebSocketUrl(),console.log("🔌 VoiceSDK v2: Connecting to",e),t.n=3,new Promise(function(t,n){o.websocket=new WebSocket(e),o.websocket.onopen=function(){console.log("✅ VoiceSDK v2: WebSocket connected"),o.isConnected=!0,o.hasEverConnected=!0,o.sendHelloMessage(),o.emit("connected"),t(!0)},o.websocket.onerror=function(t){console.error("❌ VoiceSDK v2: WebSocket error:",t),n(t)},o.websocket.onclose=function(t){console.log("🔌 VoiceSDK v2: WebSocket closed:",t.code,t.reason),o.isConnected=!1,o.isRecording&&o.stopRecording().catch(function(t){return console.error("Error stopping recording:",t)}),o.emit("disconnected",t),o.config.autoReconnect&&!o.isDestroyed&&o.hasEverConnected?(console.log("🔄 VoiceSDK v2: Auto-reconnecting in 3s..."),setTimeout(function(){o.isDestroyed||o.isConnected||o.connect()},3e3)):o.config.autoReconnect&&!o.hasEverConnected&&console.log("⚠️ VoiceSDK v2: Initial connection failed. Auto-reconnect disabled to prevent retry loop.")},o.websocket.onmessage=function(t){o.handleMessage(t)}});case 3:return t.a(2,t.v);case 4:return t.p=4,n=t.v,console.error("🔌 VoiceSDK v2: Connection failed:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[2,4]])})),function(){return u.apply(this,arguments)})},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},e={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},n=this.validateInputFormat(t);if(n)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid input format:",n),void this.emit("error",new Error("Invalid input format: ".concat(n)));var o=this.validateOutputFormat(e);if(o)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid output format:",o),void this.emit("error",new Error("Invalid output format: ".concat(o)));var r={t:"hello",v:this.config.protocolVersion,inputFormat:t,requestedOutputFormat:e,outputFrameDurationMs:this.config.outputFrameDurationMs};this.config.agentSettingsOverride&&(r.agentSettingsOverride=this.config.agentSettingsOverride),console.log("🔍 VoiceSDK v2: Checking variables:",{hasVariables:!!this.config.variables,variables:this.config.variables,keys:this.config.variables?Object.keys(this.config.variables):[]}),this.config.variables&&Object.keys(this.config.variables).length>0?(r.variables=this.config.variables,console.log("📝 VoiceSDK v2: Including variables in hello:",Object.keys(this.config.variables))):console.log("⚠️ VoiceSDK v2: Variables NOT included - condition failed"),console.log("📤 VoiceSDK v2: Sending hello:",{version:r.v,requestedFormat:r.requestedOutputFormat,variables:r.variables?Object.keys(r.variables):void 0}),console.log("📤 VoiceSDK v2: Requested output format:",{container:r.requestedOutputFormat.container,encoding:r.requestedOutputFormat.encoding,sampleRate:r.requestedOutputFormat.sampleRate,bitDepth:r.requestedOutputFormat.bitDepth}),console.log("📤 VoiceSDK v2: Full hello message being sent:",JSON.stringify(r,null,2));try{this.sendMessage(r)}catch(t){console.error("VoiceSDK v2: Failed to send hello:",t),this.emit("error",t)}}else console.warn("VoiceSDK v2: Cannot send hello - not connected")}},{key:"handleMessage",value:function(t){if(t.data instanceof ArrayBuffer||t.data instanceof Blob)this.handleBinaryMessage(t.data);else try{var e=JSON.parse(t.data);switch(console.log("📥 VoiceSDK v2: Received message:",e.t),!this.conversationId&&e.conversationId&&(this.conversationId=e.conversationId,console.log("🔍 VoiceSDK v2: Captured conversationId from message:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),e.t){case"hello_ack":this.handleHelloAck(e);break;case"transcript":this.handleTranscript(e);break;case"user_transcript":case"agent_response":case"error":this.emit("message",e);break;case"barge_in":this.emit("bargeIn",e),this.stopAudioPlayback();break;case"stop_playing":this.emit("stopPlaying",e),this.stopAudioPlayback();break;default:console.log("VoiceSDK v2: Unknown message type:",e.t),this.emit("message",e)}}catch(t){console.error("VoiceSDK v2: Error parsing message:",t)}}},{key:"handleHelloAck",value:function(t){if(console.log("📥 VoiceSDK v2: Received hello_ack:",{hasOutputFormat:!!t.outputAudioFormat,outputFormat:t.outputAudioFormat,hasConversationId:!!t.conversationId,messageType:t.t}),t.conversationId&&(this.conversationId=t.conversationId,console.log("🔍 VoiceSDK v2: Received conversationId:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),t.outputAudioFormat){this.outputAudioFormat=t.outputAudioFormat,this.audioPlayer.setOutputFormat(t.outputAudioFormat),console.log("✅ VoiceSDK v2: Format negotiated by server:",this.outputAudioFormat),this.requestedOutputFormat={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1};var e={container:this.outputAudioFormat.container||"unknown",encoding:this.outputAudioFormat.encoding||"unknown",sampleRate:this.outputAudioFormat.sampleRate||0,bitDepth:this.outputAudioFormat.bitDepth||0,channels:this.outputAudioFormat.channels||0},n=[];if(this.requestedOutputFormat.container!==e.container&&n.push('container: "'.concat(this.requestedOutputFormat.container,'" → "').concat(e.container,'"')),this.requestedOutputFormat.encoding!==e.encoding&&n.push('encoding: "'.concat(this.requestedOutputFormat.encoding,'" → "').concat(e.encoding,'"')),this.requestedOutputFormat.sampleRate!==e.sampleRate&&n.push("sampleRate: ".concat(this.requestedOutputFormat.sampleRate,"Hz → ").concat(e.sampleRate,"Hz")),this.requestedOutputFormat.bitDepth!==e.bitDepth&&n.push("bitDepth: ".concat(this.requestedOutputFormat.bitDepth,"-bit → ").concat(e.bitDepth,"-bit")),this.requestedOutputFormat.channels!==e.channels&&n.push("channels: ".concat(this.requestedOutputFormat.channels," → ").concat(e.channels)),n.length>0){console.warn("⚠️ VoiceSDK v2: Format negotiation mismatch!"),console.warn(" Requested:",this.requestedOutputFormat),console.warn(" Negotiated:",e),console.warn(" Differences:",n.join(", "));try{if(this.formatConverter=new Re(this.requestedOutputFormat,e),this.formatConverter.needsConversion()){var o=this.formatConverter.getConversionSteps();console.log("🔄 VoiceSDK v2: Format conversion enabled"),console.log(" Conversion steps:",o.join(", ")),console.log(" Audio will be automatically converted to requested format")}}catch(t){console.error("❌ VoiceSDK v2: Failed to create format converter:",t),console.warn(" Will use backend format without conversion"),this.formatConverter=null}}else console.log("✅ VoiceSDK v2: Format perfectly matched!",e),this.formatConverter=null;this.emit("formatNegotiated",this.outputAudioFormat)}else{this.config.protocolVersion>=2?(console.warn("⚠️ VoiceSDK v2: hello_ack received but no outputAudioFormat in response."),console.warn(" This may happen if:"),console.warn(" 1. Backend is not sending outputAudioFormat (check backend logs)"),console.warn(" 2. Hello message missing v2 fields (v, inputFormat, requestedOutputFormat)"),console.warn(" 3. Backend validation failed (check backend error logs)"),console.warn(" Using default format from config...")):console.log("✅ VoiceSDK v2: Connected (v1 legacy mode)");var r={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,channels:this.config.outputChannels||1,bitDepth:this.config.outputBitDepth||16};this.outputAudioFormat=r,this.requestedOutputFormat=r,this.audioPlayer.setOutputFormat(r),this.formatConverter=null}}},{key:"handleTranscript",value:function(t){if(t.sentenceId&&t.text){var e=t.sentenceId,n={text:t.text,role:t.role||"assistant",sentenceId:e,final:!1!==t.final,timestamp:t.timestamp||Date.now()};this.transcriptQueue.push(n),console.log("📝 VoiceSDK v2: Received transcript for sentence",e,":",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",e),this.emit("transcriptDisplay",n),this.currentPlayingSentenceId=e,this.emit("transcript",n)}else console.warn("⚠️ VoiceSDK v2: Invalid transcript message:",t)}},{key:"handleBinaryMessage",value:(s=Ve(Ne().m(function t(e){var n,o,r,i,a,c,s,u,l,d;return Ne().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!(e instanceof Blob)){t.n=2;break}return t.n=1,e.arrayBuffer();case 1:o=t.v,t.n=3;break;case 2:o=e;case 3:if(console.log("📥 VoiceSDK v2: Received audio:",o.byteLength,"bytes"),console.log(" Current outputFormat:",this.outputAudioFormat),console.log(" AudioPlayer outputFormat:",null===(n=this.audioPlayer)||void 0===n?void 0:n.outputFormat),console.log(" Format converter:",this.formatConverter?"active":"none"),r=o,!this.formatConverter||!this.formatConverter.needsConversion()){t.n=7;break}return t.p=4,t.n=5,this.formatConverter.convert(o);case 5:r=t.v,console.log("✅ VoiceSDK v2: Audio converted to requested format"),t.n=7;break;case 6:t.p=6,d=t.v,console.error("❌ VoiceSDK v2: Format conversion failed:",d),console.warn(" Using backend format without conversion"),r=o;case 7:i=this.formatConverter&&this.formatConverter.needsConversion()?this.requestedOutputFormat:this.outputAudioFormat||{container:this.config.outputContainer||"raw",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1},a=i.container||"raw",c=(i.encoding||"pcm").toLowerCase(),"raw"===a?(s=r,"pcm"!==c&&((u=this.audioPlayer.getCodec(c))?(l=u.decode(new Uint8Array(r)),s=l.buffer,console.log("🔄 VoiceSDK v2: Decoded ".concat(c.toUpperCase()," to PCM (").concat(l.byteLength," bytes)"))):console.warn("⚠️ VoiceSDK v2: No codec for ".concat(c,", treating as PCM"))),this.audioPlayer.outputFormat||(console.warn("⚠️ VoiceSDK v2: outputFormat not set on AudioPlayer, setting from playbackFormat"),this.audioPlayer.setOutputFormat(i)),this.audioFrameCount++,this.audioPlayer.playChunk(s)):(this.audioFrameCount++,this.audioPlayer.playAudio(r));case 8:return t.a(2)}},t,this,[[4,6]])})),function(t){return s.apply(this,arguments)})},{key:"sendMessage",value:function(t){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send message - not connected"),!1;try{return this.websocket.send(JSON.stringify(t)),!0}catch(t){return console.error("VoiceSDK v2: Error sending message:",t),this.emit("error",t),!1}}},{key:"sendBinary",value:function(t){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send audio - not connected"),!1;try{return this.websocket.send(t),!0}catch(t){return console.error("VoiceSDK v2: Error sending audio:",t),this.emit("error",t),!1}}},{key:"disconnect",value:function(){this.isDestroyed||(console.log("🔌 VoiceSDK v2: Disconnecting..."),this.stopRecording(),this.audioPlayer&&this.stopAudioPlayback(),this.websocket&&(this.websocket.close(),this.websocket=null),this.isConnected=!1)}},{key:"startRecording",value:(c=Ve(Ne().m(function t(){var e,n;return Ne().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw e=new Error("Not connected to voice server"),this.emit("error",e),e;case 1:if(!this.isRecording){t.n=2;break}return console.warn("VoiceSDK v2: Already recording"),t.a(2,!0);case 2:return console.log("🎤 VoiceSDK v2: Starting recording..."),t.p=3,console.log("🎤 VoiceSDK v2: Requesting microphone permission (mobile-friendly)..."),t.n=4,this.audioRecorder.start();case 4:return this.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId()}),t.a(2,!0);case 5:return t.p=5,n=t.v,console.error("❌ VoiceSDK v2: Failed to start recording:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[3,5]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=Ve(Ne().m(function t(){var e;return Ne().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return console.warn("VoiceSDK v2: Not recording"),t.a(2,!0);case 1:return console.log("🛑 VoiceSDK v2: Stopping recording..."),t.p=2,this.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=3,this.audioRecorder.stop();case 3:return this.stopAudioPlayback(),t.a(2,!0);case 4:return t.p=4,e=t.v,console.error("VoiceSDK v2: Error stopping recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[2,4]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=Ve(Ne().m(function t(){return Ne().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"clearTranscriptState",value:function(){this.currentPlayingSentenceId=null,console.log("📝 VoiceSDK v2: Cleared transcript state")}},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate(),this.clearTranscriptState()}},{key:"handleBargeIn",value:(r=Ve(Ne().m(function t(){return Ne().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{version:this.version,isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying,outputFormat:this.outputAudioFormat,conversationId:this.conversationId,audioPlayer:this.audioPlayer.getStatus(),audioRecorder:this.audioRecorder.getStatus()}}},{key:"updateConfig",value:function(t){this.config=Me(Me({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"destroy",value:function(){this.isDestroyed||(console.log("🗑️ VoiceSDK v2: Destroying..."),this.disconnect(),this.isDestroyed=!0,this.audioPlayer&&this.audioPlayer.destroy(),this.audioRecorder&&this.audioRecorder.destroy(),this.removeAllListeners())}}],o&&Ke(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(mt);qe(Je,"SUPPORTED_INPUT_ENCODINGS",["pcm","pcmu","pcma"]),qe(Je,"SUPPORTED_INPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),qe(Je,"SUPPORTED_INPUT_BIT_DEPTHS",[8,16,24]),qe(Je,"SUPPORTED_INPUT_CHANNELS",[1]),qe(Je,"SUPPORTED_OUTPUT_ENCODINGS",["pcm","pcmu","pcma"]),qe(Je,"SUPPORTED_OUTPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),qe(Je,"SUPPORTED_OUTPUT_BIT_DEPTHS",[8,16,24]),qe(Je,"SUPPORTED_OUTPUT_CHANNELS",[1]),qe(Je,"SUPPORTED_OUTPUT_CONTAINERS",["raw","wav"]);const Ye=Je;function $e(t){return $e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},$e(t)}function Xe(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ze(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ze(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Ze(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ze(d,"constructor",u),Ze(u,"constructor",s),s.displayName="GeneratorFunction",Ze(u,r,"GeneratorFunction"),Ze(d),Ze(d,r,"Generator"),Ze(d,o,function(){return this}),Ze(d,"toString",function(){return"[object Generator]"}),(Xe=function(){return{w:i,m:f}})()}function Ze(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Ze=function(t,e,n,o){function i(e,n){Ze(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Ze(t,e,n,o)}function tn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function en(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function nn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?en(Object(n),!0).forEach(function(e){on(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):en(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function on(t,e,n){return(e=an(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function rn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,an(o.key),o)}}function an(t){var e=function(t){if("object"!=$e(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=$e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==$e(e)?e:e+""}function cn(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(cn=function(){return!!t})()}function sn(t){return sn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},sn(t)}function un(t,e){return un=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},un(t,e)}var ln=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=(t=function(t,e,n){return e=sn(e),function(t,e){if(e&&("object"==$e(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,cn()?Reflect.construct(e,n||[],sn(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=nn({baseWsUrl:"wss://backend.talktopc.com/chat/websocket",appId:n.appId||o.appId,agentId:n.agentId||o.agentId,conversationId:void 0!==n.conversationId?n.conversationId:t.getPersistedConversationId(),forceConversationId:n.forceConversationId,queue:[],inFlight:!1},n),t.fullResponseBuffer="",t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&un(t,e)}(e,t),n=e,o=[{key:"readScriptTagConfig",value:function(){try{var t=Array.from(document.getElementsByTagName("script")).reverse().find(function(t){return t.dataset&&(t.dataset.appId||t.dataset.agentId)||t.src&&t.src.includes("agent-widget")});return t?{appId:t.dataset.appId,agentId:t.dataset.agentId}:{}}catch(t){return{}}}},{key:"buildWebSocketUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,e=new URLSearchParams;return this.config.appId&&e.append("appId",this.config.appId),this.config.agentId&&e.append("agentId",this.config.agentId),this.config.conversationId&&e.append("conversationId",this.config.conversationId),"".concat(t,"?").concat(e.toString())}},{key:"sendMessage",value:(r=Xe().m(function t(e){var n=this;return Xe().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,o){if(e&&e.trim())if(n.config.appId&&n.config.agentId){var r={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(r):n.executeTask(r)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){tn(i,n,o,a,c,"next",t)}function c(t){tn(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"executeTask",value:function(t){var e=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,r=this.buildWebSocketUrl(this.config.baseWsUrl),i=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(i),c=!1,s=!1,u=null,l=function(n){if(!s)try{var o={message:t.text},r=e.config.forceConversationId||e.config.conversationId;r&&(o.conversationId=r,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=r,e.persistConversationId(r))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",e.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){t.reject(o),e.emit("error",o);try{n.close()}catch(t){}}},d=function(t){return function(){e.config.conversationId?l(t):u=setTimeout(function(){return l(t)},200)}},f=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(t){}var r=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",r)}catch(t){}if("hello"===r.type&&r.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId),e.emit&&e.emit("conversationIdChanged",r.conversationId),!s&&n&&1===n.readyState){if(u)try{clearTimeout(u)}catch(t){}l(n)}return}if(!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId)),"chunk"===r.type&&"string"==typeof r.content)e.fullResponseBuffer+=r.content,e.emit("chunk",r.content);else if("done"===r.type){try{var i=r.text||r.content||r.answer||r.message||"";i&&!e.fullResponseBuffer&&(e.fullResponseBuffer=i)}catch(t){}!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",r.conversationId),e.config.conversationId=r.conversationId),e.persistConversationId(e.config.conversationId),e.emit("done",{text:e.fullResponseBuffer}),t.resolve({conversationId:e.config.conversationId,fullText:e.fullResponseBuffer});try{n.close()}catch(t){}}else if("error"===r.type){var a=new Error(r.message||"Server error");e.emit("error",a),t.reject(a);try{n.close()}catch(t){}}}catch(t){}}},p=function(n){if(1008===n.code&&n.reason&&(n.reason.includes("Domain not whitelisted")||n.reason.includes("domain")||n.reason.includes("whitelist"))){var o=new Error("DOMAIN_NOT_WHITELISTED");return o.reason=n.reason,o.code=n.code,e.emit("domainError",o),t.reject(o),e.config.inFlight=!1,void e.drainQueue()}e.config.inFlight=!1,e.drainQueue()},h=new WebSocket(r);h.onopen=d(h),h.onmessage=f(h),h.onerror=(o=h,function(n){if(!c){c=!0;try{o.close()}catch(t){}var r=new WebSocket(a);return r.onopen=d(r),r.onmessage=f(r),r.onerror=function(n){e.emit("error",n),t.reject(n)},void(r.onclose=p)}e.emit("error",n),t.reject(n)}),h.onclose=p}},{key:"drainQueue",value:function(){if(0!==this.config.queue.length&&!this.config.inFlight){var t=this.config.queue.shift();this.executeTask(t)}}},{key:"persistConversationId",value:function(t){try{t&&localStorage.setItem("ttp_text_chat_conversation_id",t)}catch(t){}}},{key:"getPersistedConversationId",value:function(){try{return localStorage.getItem("ttp_text_chat_conversation_id")||null}catch(t){return null}}},{key:"updateConfig",value:function(t){this.config=nn(nn({},this.config),t)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&rn(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c),dn=n(540),fn=n(848);function pn(t){return pn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},pn(t)}function hn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function vn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?hn(Object(n),!0).forEach(function(e){gn(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):hn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function gn(t,e,n){return(e=function(t){var e=function(t){if("object"!=pn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=pn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==pn(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function yn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return mn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(mn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,mn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,mn(d,"constructor",u),mn(u,"constructor",s),s.displayName="GeneratorFunction",mn(u,r,"GeneratorFunction"),mn(d),mn(d,r,"Generator"),mn(d,o,function(){return this}),mn(d,"toString",function(){return"[object Generator]"}),(yn=function(){return{w:i,m:f}})()}function mn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}mn=function(t,e,n,o){function i(e,n){mn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},mn(t,e,n,o)}function bn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Sn(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return wn(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?wn(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function wn(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}const xn=function(t){var e=t.websocketUrl,n=t.agentId,o=t.appId,r=t.voice,i=void 0===r?"default":r,a=t.language,c=void 0===a?"en":a,s=t.autoReconnect,u=void 0===s||s,l=t.agentSettingsOverride,d=void 0===l?null:l,f=t.onConnected,p=t.onDisconnected,h=t.onRecordingStarted,v=t.onRecordingStopped,g=t.onPlaybackStarted,y=t.onPlaybackStopped,m=t.onError,b=t.onMessage,S=t.onBargeIn,w=t.onStopPlaying,x=t.className,k=void 0===x?"":x,C=t.style,P=void 0===C?{}:C,O=t.children,E=Sn((0,dn.useState)(!1),2),T=E[0],I=E[1],j=Sn((0,dn.useState)(!1),2),A=j[0],F=j[1],D=Sn((0,dn.useState)(!1),2),B=(D[0],D[1]),R=Sn((0,dn.useState)("Disconnected"),2),_=(R[0],R[1]),U=(0,dn.useRef)(null);(0,dn.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),U.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),U.current.destroy(),U.current=null);var t=new pt({websocketUrl:e,agentId:n,appId:o,voice:i,language:c,autoReconnect:u,agentSettingsOverride:d});return t.on("connected",function(){I(!0),_("Connected"),null==f||f()}),t.on("disconnected",function(){I(!1),_("Disconnected"),null==p||p()}),t.on("recordingStarted",function(){F(!0),null==h||h()}),t.on("recordingStopped",function(){F(!1),null==v||v()}),t.on("playbackStarted",function(){B(!0),null==g||g()}),t.on("playbackStopped",function(){B(!1),null==y||y()}),t.on("error",function(t){null==m||m(t)}),t.on("message",function(t){null==b||b(t)}),t.on("bargeIn",function(t){null==S||S(t)}),t.on("stopPlaying",function(t){null==w||w(t)}),U.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),U.current&&(U.current.destroy(),U.current=null)}},[e,n,o,i,c,d]);var M=function(){var t,e=(t=yn().m(function t(){var e;return yn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(U.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,U.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){bn(i,o,r,a,c,"next",t)}function c(t){bn(i,o,r,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),N=(0,fn.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,fn.jsx)("div",{style:{fontSize:"20px"},children:A?"🔴":"🎤"}),(0,fn.jsx)("div",{children:A?"Stop Listening":"Start Listening"})]});return(0,fn.jsx)("button",{className:"voice-button ".concat(A?"recording":""," ").concat(k),style:vn({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:A?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},P),onClick:M,disabled:!T,children:O||N})};function kn(t){return kn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},kn(t)}function Cn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Pn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Pn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Pn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Pn(d,"constructor",u),Pn(u,"constructor",s),s.displayName="GeneratorFunction",Pn(u,r,"GeneratorFunction"),Pn(d),Pn(d,r,"Generator"),Pn(d,o,function(){return this}),Pn(d,"toString",function(){return"[object Generator]"}),(Cn=function(){return{w:i,m:f}})()}function Pn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Pn=function(t,e,n,o){function i(e,n){Pn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Pn(t,e,n,o)}function On(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function En(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){On(i,o,r,a,c,"next",t)}function c(t){On(i,o,r,a,c,"throw",t)}a(void 0)})}}function Tn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function In(t,e,n){return(e=An(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function jn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,An(o.key),o)}}function An(t){var e=function(t){if("object"!=kn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=kn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==kn(e)?e:e+""}var Fn=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Tn(Object(n),!0).forEach(function(e){In(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({websocketUrl:e.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:e.agentId,voice:e.voice||"default",language:e.language||"en",container:e.container||document.body,buttonText:e.buttonText||"Start Listening",buttonClass:e.buttonClass||"voice-button"},e),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new pt({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},e=[{key:"setupEventListeners",value:function(){var t=this;this.voiceSDK.on("connected",function(){var e,n;t.isConnected=!0,t.updateButton(),null===(e=(n=t.options).onConnected)||void 0===e||e.call(n)}),this.voiceSDK.on("disconnected",function(){var e,n;t.isConnected=!1,t.updateButton(),null===(e=(n=t.options).onDisconnected)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStarted",function(){var e,n;t.isRecording=!0,t.updateButton(),null===(e=(n=t.options).onRecordingStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStopped",function(){var e,n;t.isRecording=!1,t.updateButton(),null===(e=(n=t.options).onRecordingStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStarted",function(){var e,n;t.isPlaying=!0,null===(e=(n=t.options).onPlaybackStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStopped",function(){var e,n;t.isPlaying=!1,null===(e=(n=t.options).onPlaybackStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("error",function(e){var n,o;null===(n=(o=t.options).onError)||void 0===n||n.call(o,e)}),this.voiceSDK.on("message",function(e){var n,o;null===(n=(o=t.options).onMessage)||void 0===n||n.call(o,e)}),this.voiceSDK.on("bargeIn",function(e){var n,o;null===(n=(o=t.options).onBargeIn)||void 0===n||n.call(o,e)}),this.voiceSDK.on("stopPlaying",function(e){var n,o;null===(n=(o=t.options).onStopPlaying)||void 0===n||n.call(o,e)})}},{key:"createButton",value:function(){var t=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return t.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var t=this.isRecording?"🔴":"🎤",e=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(t,"</span>\n <span>").concat(e,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=En(Cn().m(function t(){var e;return Cn().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.voiceSDK.connect();case 1:t.n=3;break;case 2:t.p=2,e=t.v,console.error("Failed to connect:",e);case 3:return t.a(2)}},t,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=En(Cn().m(function t(){var e;return Cn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.voiceSDK){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,this.voiceSDK.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.voiceSDK.updateConfig(t)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],e&&jn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Dn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Bn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Bn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Bn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Bn(d,"constructor",u),Bn(u,"constructor",s),s.displayName="GeneratorFunction",Bn(u,r,"GeneratorFunction"),Bn(d),Bn(d,r,"Generator"),Bn(d,o,function(){return this}),Bn(d,"toString",function(){return"[object Generator]"}),(Dn=function(){return{w:i,m:f}})()}function Bn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Bn=function(t,e,n,o){function i(e,n){Bn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Bn(t,e,n,o)}function Rn(t){return Rn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Rn(t)}function _n(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Un(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){_n(i,o,r,a,c,"next",t)}function c(t){_n(i,o,r,a,c,"throw",t)}a(void 0)})}}function Mn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Nn(o.key),o)}}function Nn(t){var e=function(t){if("object"!=Rn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Rn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Rn(e)?e:e+""}var zn=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),console.log("🚀 AgentSDK v2.1.8 initialized with config:",e),this.config=e,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(t){return console.error("SDK Error:",t)},this.onTranscript=function(t){},this.onAgentSpeaking=function(t){},this.onConversationStart=e.onConversationStart||function(){},this.onConversationEnd=e.onConversationEnd||function(){},this.onBargeIn=e.onBargeIn||function(){},this.onAudioStartPlaying=e.onAudioStartPlaying||function(){},this.onAudioStoppedPlaying=e.onAudioStoppedPlaying||function(){},this.onSubtitleDisplay=e.onSubtitleDisplay||function(){}},e=[{key:"connect",value:(o=Un(Dn().m(function t(e){var n,o=this;return Dn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,e){t.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new Ye({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en",protocolVersion:2,outputContainer:this.config.outputContainer||"raw",outputEncoding:this.config.outputEncoding||"pcm",outputSampleRate:this.config.outputSampleRate||44100,outputChannels:this.config.outputChannels||1,outputBitDepth:this.config.outputBitDepth||16}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(t){if(o.isConnected=!1,t&&1008===t.code&&t.reason&&(t.reason.includes("Domain not whitelisted")||t.reason.includes("domain")||t.reason.includes("whitelist"))){var e=new Error("DOMAIN_NOT_WHITELISTED");e.reason=t.reason,e.code=t.code,o.onError(e)}o.isListening&&o.onConversationEnd(),o.onDisconnected()}),this.voiceSDK.on("domainError",function(t){o.onError(t)}),this.voiceSDK.on("error",function(t){o.onError(t)}),this.voiceSDK.on("message",function(t){o.handleWebSocketMessage(t)}),this.voiceSDK.on("recordingStarted",function(){if(o.isListening=!0,console.log("🎤 [AGENT SDK] recordingStarted event fired, calling onConversationStart hook"),console.log("🎤 [AGENT SDK] onConversationStart type:",Rn(o.onConversationStart)),o.onConversationStart&&"function"==typeof o.onConversationStart)try{o.onConversationStart(),console.log("🎤 [AGENT SDK] ✅ onConversationStart hook called successfully")}catch(t){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationStart:",t)}else console.warn("🎤 [AGENT SDK] ⚠️ onConversationStart is not a function:",o.onConversationStart)}),this.voiceSDK.on("recordingStopped",function(){if(o.isListening=!1,console.log("🎤 [AGENT SDK] recordingStopped event fired, calling onConversationEnd hook"),console.log("🎤 [AGENT SDK] onConversationEnd type:",Rn(o.onConversationEnd)),o.onConversationEnd&&"function"==typeof o.onConversationEnd)try{o.onConversationEnd(),console.log("🎤 [AGENT SDK] ✅ onConversationEnd hook called successfully")}catch(t){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationEnd:",t)}else console.warn("🎤 [AGENT SDK] ⚠️ onConversationEnd is not a function:",o.onConversationEnd)}),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(t){o.onBargeIn(t)}),this.voiceSDK.on("transcriptDisplay",function(t){t&&t.text&&o.onTranscript(t.text),o.onSubtitleDisplay(t)}),t.n=2,this.voiceSDK.connect();case 2:t.n=4;break;case 3:throw t.p=3,n=t.v,this.onError(n),n;case 4:return t.a(2)}},t,this,[[0,3]])})),function(t){return o.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(t){switch(t.t||t.type){case"connected":case"hello_ack":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text||t.transcript);break;case"agent_response":case"barge_in":case"stop_playing":default:break;case"error":this.onError(new Error(t.message||t.error||"Unknown error"))}}},{key:"startListening",value:(n=Un(Dn().m(function t(){var e;return Dn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){t.n=5;break}return t.p=1,console.log("🎤 AgentSDK: Starting recording..."),t.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),t.n=4;break;case 3:throw t.p=3,e=t.v,console.error("❌ AgentSDK: Failed to start recording:",e),e;case 4:t.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(t){this.voiceSDK&&this.isConnected&&this.voiceSDK.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],e&&Mn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Ln(t){return Ln="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ln(t)}function Vn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Kn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Kn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Kn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Kn(d,"constructor",u),Kn(u,"constructor",s),s.displayName="GeneratorFunction",Kn(u,r,"GeneratorFunction"),Kn(d),Kn(d,r,"Generator"),Kn(d,o,function(){return this}),Kn(d,"toString",function(){return"[object Generator]"}),(Vn=function(){return{w:i,m:f}})()}function Kn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Kn=function(t,e,n,o){function i(e,n){Kn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Kn(t,e,n,o)}function Hn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Wn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Hn(i,o,r,a,c,"next",t)}function c(t){Hn(i,o,r,a,c,"throw",t)}a(void 0)})}}function Gn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,qn(o.key),o)}}function qn(t){var e=function(t){if("object"!=Ln(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ln(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ln(e)?e:e+""}var Qn=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.audioStream=null,this.callStartTime=null,this.callTimerInterval=null,this.sdk=null,this.isActive=!1,this.sdk=new zn({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,variables:e.variables||{},language:e.language||"en",outputContainer:e.outputContainer,outputEncoding:e.outputEncoding,outputSampleRate:e.outputSampleRate,outputChannels:e.outputChannels,outputBitDepth:e.outputBitDepth,onConversationStart:e.onConversationStart,onConversationEnd:e.onConversationEnd,onBargeIn:e.onBargeIn,onAudioStartPlaying:e.onAudioStartPlaying,onAudioStoppedPlaying:e.onAudioStoppedPlaying,onSubtitleDisplay:e.onSubtitleDisplay}),this.setupSDKEventHandlers()},e=[{key:"setupSDKEventHandlers",value:function(){var t=this;this.sdk.onTranscript=function(e){t.updateTranscript(e)},this.sdk.onAgentSpeaking=function(t){var e=document.getElementById("voiceAvatarActive");e&&(t?e.classList.add("speaking"):e.classList.remove("speaking"))},this.sdk.onDisconnected=function(){console.log("🔌 WebSocket disconnected, hanging up call..."),t.isActive&&(t.isActive=!1,t.endVoiceCall())},this.sdk.onError=function(e){console.error("❌ Voice SDK Error:",e),e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))?t.showDomainError():t.showError(e.message||e)}}},{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"getTooltip",value:function(t){var e,n=null===(e=this.config.tooltips)||void 0===e?void 0:e[t];return null!=n?n:{mute:this.t("mute"),speaker:this.t("speaker"),endCall:this.t("endCall")}[t]||""}},{key:"generateHTML",value:function(){return'<div class="voice-interface" id="voiceInterface">\n \x3c!-- Before Call State --\x3e\n <div id="voiceIdleState">\n <div class="voice-avatar" id="voiceAvatar">🤖</div>\n <div class="voice-status">\n <div class="voice-status-title">'.concat(this.t("clickToStartCall"),'</div>\n <div class="voice-status-subtitle">').concat(this.t("realTimeVoice"),'</div>\n </div>\n <button class="start-call-btn" id="startCallBtn">\n <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">\n <path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56-.35-.12-.74-.03-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"/>\n </svg>\n <span>').concat(this.t("startCall"),'</span>\n </button>\n </div>\n \x3c!-- During Call State --\x3e\n <div id="voiceActiveState" style="display: none;">\n <div class="voice-avatar-active" id="voiceAvatarActive">\n <div class="voice-rings">\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n </div>\n 🤖\n </div>\n <div class="voice-status">\n <div class="voice-status-title" id="voiceStatusTitleActive">').concat(this.t("listening"),'</div>\n <div class="voice-status-subtitle" id="voiceStatusSubtitleActive">').concat(this.t("speakFreely"),'</div>\n </div>\n <div class="voice-transcript">\n <div class="transcript-label">').concat(this.t("liveTranscript"),'</div>\n <div class="transcript-text empty" id="transcriptText">\n ').concat(this.t("transcriptWillAppear"),'\n </div>\n </div>\n <div class="voice-controls">\n <button class="voice-control-btn secondary" id="muteBtn" title="').concat(this.getTooltip("mute"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="mute-icon">\n <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>\n <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>\n <line x1="12" y1="19" x2="12" y2="23"/>\n <line x1="8" y1="23" x2="16" y2="23"/>\n <line x1="2" y1="2" x2="22" y2="22" class="mute-cross" style="display: none; stroke: #ef4444; stroke-width: 3.5;"/>\n </svg>\n </button>\n <button class="voice-control-btn primary active" id="endCallBtn" title="').concat(this.getTooltip("endCall"),'">\n <svg width="56" height="56" viewBox="0 0 24 24" fill="#ef4444">\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n </svg>\n <div class="voice-timer" id="voiceTimer">00:00</div>\n </button>\n <button class="voice-control-btn secondary" id="speakerBtn" title="').concat(this.getTooltip("speaker"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">\n <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/>\n <path d="M19.07 4.93a10 10 0 0 1 0 14.14"/>\n <path d="M15.54 8.46a5 5 0 0 1 0 7.07"/>\n </svg>\n </button>\n </div>\n </div>\n </div>')}},{key:"generateCSS",value:function(){var t=this.config.avatarBackgroundColor||"#667eea",e=this.config.avatarActiveBackgroundColor||this.config.avatarBackgroundColor||"#667eea",n=this.config.statusTitleColor||"#1e293b",o=this.config.statusSubtitleColor||"#64748b",r=this.config.startCallButtonColor||"#667eea",i=this.config.startCallButtonTextColor||"#FFFFFF",a=this.config.transcriptBackgroundColor||"#FFFFFF",c=this.config.transcriptTextColor||"#1e293b",s=this.config.transcriptLabelColor||"#94a3b8",u=this.config.controlButtonColor||"#FFFFFF",l=this.config.controlButtonSecondaryColor||"#64748b";return this.config.endCallButtonColor,'\n /* Voice Interface Styles - Ultra-compact for Wix iframes */\n .voice-interface { \n display: none; \n flex: 1; \n flex-direction: column;\n align-items: center; \n justify-content: center; \n padding: 6px 10px 6px 10px; \n background: linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%);\n overflow: hidden;\n min-height: 0;\n height: 100%;\n width: 100%;\n box-sizing: border-box;\n }\n .voice-interface.active { display: flex; }\n \n /* Voice States - Better scaling gaps */\n #voiceIdleState,\n #voiceActiveState {\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n height: 100%;\n min-height: 0;\n justify-content: center;\n overflow: hidden;\n flex: 1;\n box-sizing: border-box;\n gap: clamp(6px, 1.5vh, 12px);\n }\n \n #voiceActiveState[style*="display: none"] {\n display: none !important;\n }\n \n /* Voice Avatar - Scales better from small to large */\n .voice-avatar,\n .voice-avatar-active {\n width: clamp(80px, 18vh, 160px);\n height: clamp(80px, 18vh, 160px);\n aspect-ratio: 1;\n border-radius: 50%;\n background: linear-gradient(135deg, '.concat(t," 0%, ").concat(e," 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: clamp(40px, 9vh, 80px);\n margin: 0;\n box-shadow: 0 8px 30px rgba(102, 126, 234, 0.3);\n transition: all 0.3s ease;\n flex-shrink: 1;\n position: relative;\n }\n \n .voice-avatar-active {\n animation: avatarPulse 2s ease-in-out infinite;\n }\n \n @keyframes avatarPulse {\n 0%, 100% { \n transform: scale(1);\n }\n 50% { \n transform: scale(1.05);\n }\n }\n \n .voice-avatar-active.speaking {\n animation: avatarSpeak 0.5s ease-in-out infinite;\n }\n \n @keyframes avatarSpeak {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.08); }\n }\n \n /* Voice Rings Animation */\n .voice-rings {\n position: absolute;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n }\n \n .voice-ring {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n border: 2px solid rgba(102, 126, 234, 0.3);\n border-radius: 50%;\n opacity: 0;\n animation: ringExpand 2s ease-out infinite;\n }\n \n .voice-ring:nth-child(2) { animation-delay: 0.5s; }\n .voice-ring:nth-child(3) { animation-delay: 1s; }\n \n @keyframes ringExpand {\n 0% {\n width: 100%;\n height: 100%;\n opacity: 0.6;\n }\n 100% {\n width: 160%;\n height: 160%;\n opacity: 0;\n }\n }\n \n /* Voice Status - Scales with container */\n .voice-status {\n text-align: center;\n margin: 0;\n flex-shrink: 1;\n min-height: 0;\n }\n \n .voice-status-title {\n font-size: clamp(12px, 3vh, 20px);\n font-weight: 600;\n color: ").concat(n,";\n margin-bottom: clamp(2px, 0.5vh, 4px);\n line-height: 1.2;\n }\n \n .voice-status-subtitle {\n font-size: clamp(10px, 2vh, 14px);\n color: ").concat(o,";\n line-height: 1.2;\n }\n \n /* Start Call Button - Scales with container */\n .start-call-btn {\n margin: 0;\n width: min(280px, 70vw);\n height: clamp(48px, 8vh, 64px);\n border-radius: clamp(24px, 4vh, 32px);\n border: none;\n background: ").concat(r,";\n color: ").concat(i,";\n font-size: clamp(14px, 2.5vh, 18px);\n font-weight: 600;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: clamp(8px, 1.5vh, 12px);\n box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);\n transition: all 0.3s ease;\n flex-shrink: 0;\n }\n \n .start-call-btn svg {\n width: clamp(22px, 4vh, 32px);\n height: clamp(22px, 4vh, 32px);\n }\n \n .start-call-btn:hover {\n transform: translateY(-2px);\n box-shadow: 0 12px 28px rgba(102, 126, 234, 0.5);\n }\n \n .start-call-btn:active {\n transform: translateY(-1px);\n }\n \n /* Voice Transcript - Scales with container */\n .voice-transcript {\n background: ").concat(a,";\n padding: clamp(6px, 1.5vh, 12px);\n border-radius: 10px;\n width: min(360px, calc(100% - 40px));\n margin: 0;\n min-height: clamp(45px, 10vh, 80px);\n max-height: clamp(70px, 16vh, 110px);\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n flex-shrink: 1;\n overflow-y: auto;\n overflow-x: hidden;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n \n .transcript-label {\n font-size: clamp(8px, 1.4vh, 11px);\n color: ").concat(s,";\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.3px;\n margin-bottom: clamp(3px, 0.6vh, 6px);\n flex-shrink: 0;\n word-wrap: break-word;\n }\n \n .transcript-text {\n font-size: clamp(11px, 2vh, 15px);\n color: ").concat(c,";\n line-height: 1.4;\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n word-wrap: break-word;\n overflow-wrap: break-word;\n }\n \n .transcript-text.empty {\n color: #cbd5e1;\n font-style: italic;\n }\n \n /* Voice Controls - Scales with container */\n .voice-controls {\n display: flex;\n gap: clamp(8px, 1.8vh, 14px);\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n margin: 0;\n padding-top: clamp(5px, 1.2vh, 10px);\n }\n \n .voice-control-btn {\n width: clamp(48px, 9vh, 72px);\n height: clamp(48px, 9vh, 72px);\n aspect-ratio: 1;\n border-radius: 50%;\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n position: relative;\n flex-shrink: 0;\n }\n \n .voice-control-btn svg {\n width: 48%;\n height: 48%;\n }\n \n .voice-control-btn.primary {\n width: clamp(54px, 10vh, 80px);\n height: clamp(54px, 10vh, 80px);\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n box-shadow: 0 6px 18px rgba(102, 126, 234, 0.4);\n }\n \n .voice-control-btn.primary:hover {\n transform: scale(1.05);\n }\n \n .voice-control-btn.primary.active {\n background: white;\n animation: recordingPulse 1.5s ease-in-out infinite;\n }\n \n @keyframes recordingPulse {\n 0%, 100% { \n box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);\n }\n 50% { \n box-shadow: 0 6px 24px rgba(239, 68, 68, 0.7);\n }\n }\n \n .voice-control-btn.secondary {\n background: ").concat(u,";\n color: ").concat(l,";\n box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);\n }\n \n .voice-control-btn.secondary:hover {\n background: #f8fafc;\n transform: scale(1.05);\n }\n \n .voice-control-btn.secondary.muted {\n background: #f3f4f6;\n }\n \n .voice-control-btn.secondary.muted .mute-icon {\n stroke: #9ca3af !important;\n }\n \n .voice-timer {\n position: absolute;\n bottom: clamp(-18px, -3vh, -24px);\n font-size: clamp(9px, 1.6vh, 12px);\n color: #64748b;\n font-weight: 500;\n white-space: nowrap;\n }\n \n /* Mobile optimization */\n @media (max-width: 768px) {\n .voice-interface {\n padding: 6px 10px;\n }\n }\n \n @media (max-width: 480px) {\n .voice-interface {\n padding: 5px 8px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(t){var e=this,n=document.getElementById("startCallBtn"),o=document.getElementById("endCallBtn"),r=document.getElementById("muteBtn"),i=document.getElementById("speakerBtn");n&&(n.onclick=function(){return e.startVoiceCall()}),o&&(o.onclick=function(){return e.endVoiceCall()}),r&&(r.onclick=function(){return e.toggleMute()}),i&&(i.onclick=function(){return e.toggleSpeaker()});var a=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=document.getElementById("voiceInterface");n&&n.classList.contains("active")&&n.clientHeight>100?(console.log("✅ Interface is active and has proper dimensions, adjusting sizes (attempt",t+1,")"),e.adjustSizesForContainer(),0===t&&setTimeout(function(){return e.adjustSizesForContainer()},500)):t<15?(console.log("⏳ Interface not ready yet (height:",null==n?void 0:n.clientHeight,"), retrying... (attempt",t+1,")"),setTimeout(function(){return a(t+1)},250)):(console.warn("⚠️ Interface never became fully ready, adjusting sizes anyway"),e.adjustSizesForContainer())};setTimeout(function(){return a()},200),window.addEventListener("resize",function(){console.log("🔄 Window resized, re-adjusting sizes"),e.adjustSizesForContainer()})}},{key:"getSignedUrl",value:(o=Wn(Vn().m(function t(){var e,n,o,r,i,a,c;return Vn().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"adjustSizesForContainer",value:function(){var t=document.getElementById("voiceInterface");if(t){var e=t.clientHeight,n=t.clientWidth;console.log("📏 Container size:",e,"x",n);var o,r,i,a,c,s,u,l,d,f=document.getElementById("voiceIdleState"),p=document.getElementById("voiceActiveState"),h=f&&"none"!==f.style.display,v=p&&"none"!==p.style.display;console.log("👁️ Visible state - Idle:",h,"Active:",v),e<=350?(d=5,o=70,r=35,i=11,a=9,c=32,s=45,u=42,l=48):e<=450?(d=7,o=110,r=55,i=15,a=11,c=38,s=58,u=52,l=58):e<=550?(d=8,o=140,r=70,i=16,a=12,c=42,s=68,u=56,l=64):e<=700?(d=10,o=130,r=65,i=18,a=13,c=46,s=85,u=60,l=70):(d=12,o=150,r=75,i=20,a=14,c=50,s=100,u=66,l=76),document.querySelectorAll("#voiceIdleState, #voiceActiveState").forEach(function(t){t.style.gap="".concat(d,"px")});var g=document.querySelectorAll(".voice-avatar, .voice-avatar-active");console.log("🤖 Found",g.length,"avatars, setting size to",o,"px"),g.forEach(function(t){t.style.width="".concat(o,"px"),t.style.height="".concat(o,"px"),t.style.fontSize="".concat(r,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(t){return t.style.fontSize="".concat(i,"px")}),document.querySelectorAll(".voice-status-subtitle").forEach(function(t){return t.style.fontSize="".concat(a,"px")});var y=document.querySelector(".voice-transcript");y&&(y.style.minHeight="".concat(s,"px"),y.style.maxHeight="".concat(s,"px"),y.style.height="".concat(s,"px"),y.style.width="min(360px, ".concat(n-40,"px)"),y.style.boxSizing="border-box");var m=document.querySelector(".transcript-label");m&&(m.style.fontSize="".concat(Math.max(8,i-4),"px"));var b=document.querySelector(".transcript-text");b&&(b.style.fontSize="".concat(Math.max(10,i-2),"px")),document.querySelectorAll(".voice-control-btn.secondary").forEach(function(t){t.style.width="".concat(u,"px"),t.style.height="".concat(u,"px");var e=t.querySelector("svg");if(e){var n=.65*u;e.style.setProperty("width","".concat(n,"px"),"important"),e.style.setProperty("height","".concat(n,"px"),"important"),e.style.setProperty("min-width","".concat(n,"px"),"important"),e.style.setProperty("min-height","".concat(n,"px"),"important")}});var S=document.querySelector(".voice-control-btn.primary");if(S){S.style.width="".concat(l,"px"),S.style.height="".concat(l,"px");var w=S.querySelector("svg");if(w){var x=.7*l;w.style.setProperty("width","".concat(x,"px"),"important"),w.style.setProperty("height","".concat(x,"px"),"important"),w.style.setProperty("min-width","".concat(x,"px"),"important"),w.style.setProperty("min-height","".concat(x,"px"),"important")}}var k=document.querySelector(".start-call-btn");if(k){var C,P;e<=350?(C=48,P=14):e<=450?(C=52,P=15):e<=550?(C=58,P=17):e<=700?(C=62,P=18):(C=64,P=18),k.style.height="".concat(C,"px"),k.style.fontSize="".concat(P,"px");var O=k.querySelector("svg");if(O){var E=Math.max(22,.5*C);O.style.width="".concat(E,"px"),O.style.height="".concat(E,"px")}}console.log("✅ Sizes adjusted - Avatar:",o,"Status:",c,"Transcript:",s,"Buttons:",u)}else console.warn("⚠️ voiceInterface not found, skipping size adjustment")}},{key:"startVoiceCall",value:(n=Wn(Vn().m(function t(){var e,n,o,r,i,a,c,s,u,l=this;return Vn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isActive){t.n=1;break}return console.log("⚠️ Voice call already active"),t.a(2);case 1:return console.log("🎤 Starting voice call..."),t.p=2,e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState"),o=document.getElementById("voiceInterface"),e&&(e.style.display="none"),n&&(n.style.display="flex"),setTimeout(function(){return l.adjustSizesForContainer()},50),o&&(o.scrollTop=0),t.n=3,this.getSignedUrl();case 3:return r=t.v,console.log("🔗 Got signed URL:",r),t.n=4,this.sdk.connect(r);case 4:i=t.v,console.log("✅ Connected to WebSocket, connected:",i),a=0;case 5:if(this.sdk.isConnected||!(a<50)){t.n=7;break}return t.n=6,new Promise(function(t){return setTimeout(t,100)});case 6:a++,t.n=5;break;case 7:if(!this.sdk.isConnected){t.n=9;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=8,this.sdk.startListening();case 8:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-l.callStartTime,e=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(e.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3),t.n=11;break;case 9:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),t.n=10,this.sdk.startListening();case 10:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-l.callStartTime,e=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(e.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3);case 11:console.log("✅ Voice call started successfully"),t.n=13;break;case 12:t.p=12,u=t.v,console.error("❌ Error starting voice call:",u),this.showError(u.message||u),c=document.getElementById("voiceIdleState"),s=document.getElementById("voiceActiveState"),c&&(c.style.display="flex"),s&&(s.style.display="none");case 13:return t.a(2)}},t,this,[[2,12]])})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){var t=this;console.log("🔴 Ending voice call..."),this.sdk&&this.isActive&&(this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null);var e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState");e&&(e.style.display="flex"),n&&(n.style.display="none"),setTimeout(function(){return t.adjustSizesForContainer()},50);var o=document.getElementById("transcriptText");o&&(o.textContent=this.t("transcriptWillAppear"),o.classList.add("empty"));var r=document.getElementById("voiceAvatarActive");r&&r.classList.remove("speaking"),console.log("✅ Voice call ended")}},{key:"updateTranscript",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent=t,e.classList.remove("empty"))}},{key:"showError",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent="".concat(this.t("error"),": ").concat(t),e.classList.remove("empty"))}},{key:"showDomainError",value:function(){var t=document.getElementById("transcriptText");if(t){var e=this.t("domainNotValidated"),n=this.t("domainErrorMessage");t.innerHTML='<div style="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;">'.concat(e,'</div><div style="font-size: 14px; color: #991B1B; line-height: 1.5;">').concat(n,"</div>"),t.classList.remove("empty")}}},{key:"toggleMute",value:function(){if(this.sdk&&this.isActive){var t=null;if(this.sdk.voiceSDK&&this.sdk.voiceSDK.audioRecorder&&this.sdk.voiceSDK.audioRecorder.mediaStream&&(t=this.sdk.voiceSDK.audioRecorder.mediaStream.getAudioTracks()[0]),!t&&this.audioStream&&(t=this.audioStream.getAudioTracks()[0]),t){t.enabled=!t.enabled;var e=document.getElementById("muteBtn"),n=null==e?void 0:e.querySelector(".mute-icon"),o=null==e?void 0:e.querySelector(".mute-cross");e&&n&&o&&(t.enabled?(n.style.stroke="",o.style.display="none",e.classList.remove("muted")):(n.style.stroke="#9ca3af",o.style.display="block",e.classList.add("muted"))),console.log(t.enabled?"🔊 Unmuted":"🔇 Muted")}else console.warn("⚠️ No audio track available for mute toggle")}}},{key:"toggleSpeaker",value:function(){console.log("🔊 Speaker toggle")}},{key:"destroy",value:function(){this.isActive&&this.endVoiceCall(),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&(this.sdk.disconnect(),this.sdk=null)}}],e&&Gn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Jn(t){return Jn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Jn(t)}function Yn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return $n(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):($n(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,$n(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,$n(d,"constructor",u),$n(u,"constructor",s),s.displayName="GeneratorFunction",$n(u,r,"GeneratorFunction"),$n(d),$n(d,r,"Generator"),$n(d,o,function(){return this}),$n(d,"toString",function(){return"[object Generator]"}),(Yn=function(){return{w:i,m:f}})()}function $n(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}$n=function(t,e,n,o){function i(e,n){$n(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},$n(t,e,n,o)}function Xn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Zn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Xn(i,o,r,a,c,"next",t)}function c(t){Xn(i,o,r,a,c,"throw",t)}a(void 0)})}}function to(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,eo(o.key),o)}}function eo(t){var e=function(t){if("object"!=Jn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Jn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Jn(e)?e:e+""}var no=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.sdk=n,this.streamingEl=null,this.hasStartedStreaming=!1,this.isActive=!1,this.eventHandlers={autoResize:null,keydown:null},this.eventHandlersSetup=!1},e=[{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"generateHTML",value:function(){var t,e,n,o,r,i,a,c,s,u=this.config.inputPlaceholder||(null===(t=this.config.panel)||void 0===t?void 0:t.inputPlaceholder)||this.t("typeMessage")||"Type your message...";return'<div class="text-interface" id="textInterface">\n <div class="messages-container" id="messagesContainer">\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),'</div>\n </div>\n </div>\n <div class="input-container">\n <div class="input-wrapper" style="flex:1;">\n <textarea class="message-input" id="messageInput" placeholder="').concat(u,'" rows="1" dir="').concat(this.config.direction||"ltr",'"></textarea>\n </div>\n <button class="send-button" id="sendButton" aria-label="').concat(this.t("sendMessageAria"),'">').concat(this.config.sendButtonText||"➤","</button>\n ").concat(null!==(e=this.config.sendButtonHint)&&void 0!==e&&e.text||null!==(n=this.config.panel)&&void 0!==n&&null!==(n=n.sendButtonHint)&&void 0!==n&&n.text?'\n <div class="send-button-hint" style="color: '.concat((null===(o=this.config.sendButtonHint)||void 0===o?void 0:o.color)||(null===(r=this.config.panel)||void 0===r||null===(r=r.sendButtonHint)||void 0===r?void 0:r.color)||"#6B7280","; font-size: ").concat((null===(i=this.config.sendButtonHint)||void 0===i?void 0:i.fontSize)||(null===(a=this.config.panel)||void 0===a||null===(a=a.sendButtonHint)||void 0===a?void 0:a.fontSize)||"12px",'; text-align: center; margin-top: 4px;">\n ').concat((null===(c=this.config.sendButtonHint)||void 0===c?void 0:c.text)||(null===(s=this.config.panel)||void 0===s||null===(s=s.sendButtonHint)||void 0===s?void 0:s.text),"\n </div>\n "):"","\n </div>\n </div>")}},{key:"generateCSS",value:function(){var t,e,n,o,r,i,a,c,s,u,l,d,f,p=this.config.messages,h=(this.config.panel,this.config.animation,this.config.sendButtonColor||(null===(t=this.config.panel)||void 0===t?void 0:t.sendButtonColor)||"#7C3AED"),v=this.config.sendButtonHoverColor||(null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonHoverColor)||"#6D28D9",g=this.config.sendButtonTextColor||(null===(n=this.config.panel)||void 0===n?void 0:n.sendButtonTextColor)||"#FFFFFF",y=(this.config.inputPlaceholder||null===(o=this.config.panel)||void 0===o||o.inputPlaceholder,this.config.inputBorderColor||(null===(r=this.config.panel)||void 0===r?void 0:r.inputBorderColor)||"#E5E7EB"),m=this.config.inputFocusColor||(null===(i=this.config.panel)||void 0===i?void 0:i.inputFocusColor)||"#7C3AED",b=this.config.inputBackgroundColor||(null===(a=this.config.panel)||void 0===a?void 0:a.inputBackgroundColor)||"#FFFFFF",S=this.config.inputTextColor||(null===(c=this.config.panel)||void 0===c?void 0:c.inputTextColor)||"#1F2937",w=this.config.inputFontSize||(null===(s=this.config.panel)||void 0===s?void 0:s.inputFontSize)||"14px",x=this.config.inputBorderRadius||(null===(u=this.config.panel)||void 0===u?void 0:u.inputBorderRadius)||20,k=this.config.inputPadding||(null===(l=this.config.panel)||void 0===l?void 0:l.inputPadding)||"6px 14px";return"\n /* Messages container using new classes */\n #messagesContainer { \n flex: 1; \n overflow-y: auto; \n overflow-x: hidden; \n padding: 20px; \n background: #f8fafc; \n display: flex; \n flex-direction: column; \n gap: 16px; \n min-height: 0; \n }\n .empty-state { \n flex: 1; \n display: flex; \n flex-direction: column; \n align-items: center; \n justify-content: center; \n gap: 12px; \n color: #64748b; \n text-align: center; \n padding: 20px; \n }\n .empty-state-icon { font-size: 48px; opacity: 0.3; }\n .empty-state-title { font-size: 20px; font-weight: 700; color: #334155; }\n .empty-state-text { font-size: 13px; max-width: 280px; }\n\n .text-interface { \n display: none; \n flex: 1; \n flex-direction: column; \n min-height: 0; \n overflow: hidden; \n }\n .text-interface.active { display: flex; }\n \n .message { \n display: flex; \n gap: 8px; \n padding: 4px 0; \n max-width: 100%; \n align-items: center; \n }\n .message.edge-left { flex-direction: row; }\n .message.edge-right { flex-direction: row-reverse; }\n .message-bubble { \n padding: 12px; \n border-radius: ".concat(p.borderRadius,"px; \n max-width: 80%; \n font-size: ").concat(p.fontSize,"; \n color: ").concat(p.textColor,"; \n word-wrap: break-word; \n text-align: ").concat("rtl"===this.config.direction?"right":"left","; \n direction: ").concat(this.config.direction||"ltr",";\n }\n .message.user { \n background: ").concat(p.userBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-start":"flex-end","; \n }\n .message.agent { \n background: ").concat(p.agentBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-end":"flex-start","; \n }\n .message .message-bubble { \n text-align: ").concat("rtl"===this.config.direction?"right":"left"," !important; \n }\n ").concat("rtl"===this.config.direction?"\n .message-bubble {\n text-align: right !important;\n }\n ":"","\n .message-avatar { \n width: 20px; \n height: 20px; \n display: flex; \n align-items: center; \n justify-content: center; \n flex-shrink: 0; \n color: inherit; \n font-size: 18px; \n line-height: 1; \n background: transparent; \n border: none; \n }\n .message-avatar.user { background: transparent; }\n .message-avatar.agent { background: transparent; }\n \n .message.system {\n background: ").concat(p.systemBackgroundColor,";\n align-self: flex-start;\n }\n .message.error {\n background: ").concat(p.errorBackgroundColor,";\n align-self: flex-start;\n }\n \n .input-container {\n display: flex;\n gap: 8px;\n padding: 12px 16px;\n background: #FFFFFF;\n border-top: 1px solid #E5E7EB;\n align-items: center;\n flex-shrink: 0;\n flex-direction: ").concat("rtl"===this.config.direction?"row-reverse":"row",";\n }\n \n .input-wrapper {\n position: relative;\n display: flex;\n align-items: center;\n }\n \n .message-input {\n width: 100%;\n min-height: 32px;\n max-height: 120px;\n padding: ").concat(k,";\n border: 1px solid ").concat(y,";\n border-radius: ").concat(x,"px;\n font-size: ").concat(w,";\n font-family: inherit;\n line-height: 1.3;\n resize: none;\n overflow-y: auto;\n background: ").concat(b,";\n color: ").concat(S,";\n vertical-align: top;\n margin: 0;\n display: block;\n white-space: pre-wrap;\n word-wrap: break-word;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n direction: ").concat(this.config.direction||"ltr",";\n -webkit-appearance: none;\n appearance: none;\n box-sizing: border-box;\n }\n \n .message-input:focus {\n outline: none;\n border-color: ").concat(m,";\n background: ").concat("#FFFFFF"===b?"#FFFFFF":b,";\n box-shadow: 0 0 0 3px ").concat(m,"33;\n }\n \n .message-input::placeholder {\n color: #9CA3AF;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n }\n \n .send-button {\n width: 40px;\n height: 40px;\n border-radius: 50%;\n border: none;\n background: ").concat(h,";\n color: ").concat(g,";\n font-size: ").concat(this.config.sendButtonFontSize||(null===(d=this.config.panel)||void 0===d?void 0:d.sendButtonFontSize)||"18px",";\n font-weight: ").concat(this.config.sendButtonFontWeight||(null===(f=this.config.panel)||void 0===f?void 0:f.sendButtonFontWeight)||"500",";\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n transition: all 0.2s ease;\n box-shadow: 0 4px 12px rgba(124, 60, 237, 0.3);\n }\n \n .send-button:hover:not(:disabled) {\n background: ").concat(v,";\n transform: scale(1.05);\n box-shadow: 0 6px 16px rgba(124, 60, 237, 0.4);\n }\n \n .send-button-hint {\n width: 100%;\n text-align: center;\n margin-top: 4px;\n }\n \n .send-button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n \n .typing-indicator {\n display: inline-flex;\n gap: 4px;\n align-items: center;\n }\n \n .typing-dot {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: #64748b;\n animation: typingDot 1.4s ease-in-out infinite;\n }\n \n .typing-dot:nth-child(2) { animation-delay: 0.2s; }\n .typing-dot:nth-child(3) { animation-delay: 0.4s; }\n \n @keyframes typingDot {\n 0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }\n 30% { transform: translateY(-8px); opacity: 1; }\n }\n \n .error-message {\n padding: 12px;\n background: ").concat(p.errorBackgroundColor,";\n border-radius: ").concat(p.borderRadius,"px;\n color: #991B1B;\n font-size: ").concat(p.fontSize,";\n margin: 8px 0;\n }\n \n @media (max-width: 768px) {\n #messagesContainer {\n padding: 12px;\n gap: 12px;\n }\n \n .message-bubble {\n max-width: 85%;\n font-size: 14px;\n padding: 10px;\n }\n \n .text-input-container {\n padding: 10px;\n gap: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 10px 14px;\n min-height: 44px;\n }\n \n #text-chat-send {\n min-width: 56px;\n min-height: 44px;\n width: 56px;\n height: 44px;\n }\n \n .empty-state-icon {\n font-size: 40px;\n }\n \n .empty-state-title {\n font-size: 18px;\n }\n \n .empty-state-text {\n font-size: 12px;\n }\n }\n \n @media (max-width: 480px) {\n #messagesContainer {\n padding: 10px;\n gap: 10px;\n }\n \n .message-bubble {\n max-width: 90%;\n font-size: 13px;\n padding: 8px;\n }\n \n .text-input-container {\n padding: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important;\n padding: 8px 12px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(){var t=this,e=document.getElementById("sendButton"),n=document.getElementById("messageInput"),o=document.getElementById("newChatBtn");if(e&&(e.onclick=function(){return t.sendMessage()}),o&&(o.onclick=function(){return t.startNewChat()}),this.updateInputAttributes(),n){n.style.height="32px",n.style.overflow="hidden";var r=function(){n.style.height="auto";var t=Math.min(n.scrollHeight,120);n.style.height=t+"px",n.style.overflowY=t>=120?"auto":"hidden",t>=120&&setTimeout(function(){n.scrollTop=n.scrollHeight},0)};n.addEventListener("input",r),n.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey?"Enter"===e.key&&e.shiftKey&&setTimeout(r,0):(e.preventDefault(),t.sendMessage())})}}},{key:"startNewChat",value:function(){try{localStorage.removeItem("ttp_text_chat_conversation_id")}catch(t){}this.sdk&&(this.sdk.config.conversationId=null);var t=document.getElementById("messagesContainer");t&&(t.innerHTML='\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),"</div>\n </div>"));var e=document.getElementById("messageInput");e&&e.focus()}},{key:"updateInputAttributes",value:function(){var t=document.getElementById("messageInput");if(t){var e,n=this.config.inputPlaceholder||(null===(e=this.config.panel)||void 0===e?void 0:e.inputPlaceholder)||this.t("typeMessage")||"Type your message...";t.placeholder=n,t.dir=this.config.direction||"ltr",t.style.textAlign="rtl"===this.config.direction?"right":"left"}}},{key:"show",value:function(){var t=document.getElementById("textInterface");t&&t.classList.add("active"),setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},50)}},{key:"hide",value:function(){var t=document.getElementById("textInterface");t&&t.classList.remove("active")}},{key:"startChat",value:(o=Zn(Yn().m(function t(){return Yn().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.updateSendButtonState();case 1:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"sendMessage",value:(n=Zn(Yn().m(function t(){var e,n,o;return Yn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("messageInput"),n=e.value.trim()){t.n=1;break}return t.a(2);case 1:if(this.isActive){t.n=2;break}return t.n=2,this.startChat();case 2:return this.addMessage("user",n),e.value="",e.style.height="32px",e.style.overflow="hidden",t.p=3,this.beginStreaming(),t.n=4,this.sdk.sendMessage(n);case 4:t.n=6;break;case 5:t.p=5,o=t.v,console.error("❌ Failed to send message:",o),o&&("DOMAIN_NOT_WHITELISTED"===o.message||o.message&&o.message.includes("Domain not whitelisted"))||this.showError(o),this.stopStreamingState();case 6:return t.a(2)}},t,this,[[3,5]])})),function(){return n.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var t=document.getElementById("sendButton");t&&(t.disabled=!this.isActive)}},{key:"addMessage",value:function(t,e){var n=document.getElementById("messagesContainer");if(n){var o=n.querySelector(".empty-state");o&&o.remove();var r=document.createElement("div"),i="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";r.className="message ".concat(t," ").concat(i);var a=document.createElement("div");a.className="message-avatar ".concat(t),a.textContent="user"===t?"👤":"🤖";var c=document.createElement("div");c.className="message-bubble",c.textContent=e,r.appendChild(a),r.appendChild(c),n.appendChild(r),n.scrollTop=n.scrollHeight}}},{key:"beginStreaming",value:function(){var t=document.getElementById("messagesContainer");if(t){this.stopStreamingState();var e=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";e.className="message agent ".concat(n),e.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var r=document.createElement("div");r.className="message-bubble",r.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',e.appendChild(o),e.appendChild(r),t.appendChild(e),this.streamingEl=r,this.hasStartedStreaming=!1,t.scrollTop=t.scrollHeight}}},{key:"appendStreamingChunk",value:function(t){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=t;var e=document.getElementById("messagesContainer");e&&(e.scrollTop=e.scrollHeight)}}},{key:"finalizeStreaming",value:function(t){if(this.streamingEl){this.streamingEl.textContent=t||this.streamingEl.textContent;var e=document.getElementById("agent-streaming");e&&(e.id=""),this.streamingEl=null}this.updateSendButtonState()}},{key:"stopStreamingState",value:function(){var t=document.getElementById("agent-streaming");t&&t.remove(),this.streamingEl=null,this.hasStartedStreaming=!1}},{key:"showError",value:function(t){var e=document.getElementById("messagesContainer");if(e){if(t&&("DOMAIN_NOT_WHITELISTED"===t.message||"string"==typeof t&&t.includes("DOMAIN_NOT_WHITELISTED")||t.message&&t.message.includes("Domain not whitelisted")||"string"==typeof t&&t.includes("Domain not whitelisted"))){var n,o=document.createElement("div");o.className="error-message",o.style.cssText="padding: 16px; margin: 12px; border-radius: 8px; background: "+((null===(n=this.config.messages)||void 0===n?void 0:n.errorBackgroundColor)||"#FEE2E2")+";";var r=document.createElement("div");r.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",r.textContent=this.t("domainNotValidated");var i=document.createElement("div");i.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",i.textContent=this.t("domainErrorMessage"),o.appendChild(r),o.appendChild(i),e.appendChild(o)}else{var a=document.createElement("div");a.className="error-message",a.textContent="string"==typeof t?t:(null==t?void 0:t.message)||t,e.appendChild(a)}e.scrollTop=e.scrollHeight}}},{key:"setActive",value:function(t){this.isActive=t,this.updateSendButtonState()}}],e&&to(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();const oo={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 ro(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return io(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(io(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,io(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,io(d,"constructor",u),io(u,"constructor",s),s.displayName="GeneratorFunction",io(u,r,"GeneratorFunction"),io(d),io(d,r,"Generator"),io(d,o,function(){return this}),io(d,"toString",function(){return"[object Generator]"}),(ro=function(){return{w:i,m:f}})()}function io(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}io=function(t,e,n,o){function i(e,n){io(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},io(t,e,n,o)}function ao(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function co(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){ao(i,o,r,a,c,"next",t)}function c(t){ao(i,o,r,a,c,"throw",t)}a(void 0)})}}function so(t){return so="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},so(t)}function uo(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function lo(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?uo(Object(n),!0).forEach(function(e){fo(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):uo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function fo(t,e,n){return(e=ho(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function po(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ho(o.key),o)}}function ho(t){var e=function(t){if("object"!=so(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=so(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==so(e)?e:e+""}var vo=function(){return t=function t(){var e,n,o,r,i,a,c,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=this.mergeWithDefaults(s),this.sdk=new ln(this.config),this.isOpen=!1,this.isActive=!1,this.translations=oo,this.currentView="landing";var u=lo(lo(lo({},this.config),this.config.voice),{},{language:(null===(e=this.config.voice)||void 0===e?void 0:e.language)||this.config.language||"en",websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16,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 Qn(u);var l=lo(lo(lo({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new no(l,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var d=document.getElementById("text-chat-panel");d&&(this.isOpen=!0,d.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,a,c,s,u,l,d,f,p,h,v,g,y,m,b,S,w,x,k,C,P,O,E,T,I,j,A,F,D,B,R,_,U,M,N,z,L,V,K,H,W,G,q,Q,J,Y,$,X,Z,tt,et,nt,ot,rt,it,at,ct,st,ut,lt,dt,ft,pt,ht,vt,gt,yt,mt,bt,St,wt,xt,kt,Ct,Pt,Ot,Et,Tt,It,jt,At,Ft,Dt,Bt,Rt,_t,Ut,Mt,Nt,zt,Lt,Vt,Kt,Ht,Wt,Gt,qt,Qt,Jt,Yt,$t,Xt,Zt,te,ee,ne,oe,re,ie,ae,ce,se,ue,le,de,fe,pe,he,ve,ge,ye,me,be,Se,we,xe,ke,Ce,Pe,Oe,Ee=t.position||"bottom-right";if("string"==typeof Ee){var Te=Ee.split("-");Ee={vertical:Te[0]||"bottom",horizontal:Te[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var Ie=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||(null===(n=t.button)||void 0===n?void 0:n.backgroundColor)||"#7C3AED",je=(null===(o=t.header)||void 0===o?void 0:o.backgroundColor)||(null===(r=t.button)||void 0===r?void 0:r.backgroundColor)||Ie;return lo({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",language:t.language||"en",icon:lo({type:(null===(i=t.icon)||void 0===i?void 0:i.type)||"custom",customImage:(null===(a=t.icon)||void 0===a?void 0:a.customImage)||"https://talktopc.com/logo192.png",emoji:(null===(c=t.icon)||void 0===c?void 0:c.emoji)||"🎤",text:(null===(s=t.icon)||void 0===s?void 0:s.text)||"AI",size:(null===(u=t.icon)||void 0===u?void 0:u.size)||"medium",backgroundColor:(null===(l=t.icon)||void 0===l?void 0:l.backgroundColor)||"#FFFFFF"},t.icon),position:lo({vertical:Ee.vertical||"bottom",horizontal:Ee.horizontal||"right",offset:Ee.offset||{x:20,y:20}},"object"===so(t.position)?t.position:{}),button:lo({size:(null===(d=t.button)||void 0===d?void 0:d.size)||"medium",shape:(null===(f=t.button)||void 0===f?void 0:f.shape)||"circle",backgroundColor:(null===(p=t.button)||void 0===p?void 0:p.backgroundColor)||(null===(h=t.icon)||void 0===h?void 0:h.backgroundColor)||Ie,hoverColor:(null===(v=t.button)||void 0===v?void 0:v.hoverColor)||"#7C3AED",shadow:!1!==(null===(g=t.button)||void 0===g?void 0:g.shadow),shadowColor:(null===(y=t.button)||void 0===y?void 0:y.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(m=t.button)||void 0===m?void 0:m.backgroundColor)||(null===(b=t.icon)||void 0===b?void 0:b.backgroundColor)||Ie},t.button),panel:lo({width:(null===(S=t.panel)||void 0===S?void 0:S.width)||350,height:(null===(w=t.panel)||void 0===w?void 0:w.height)||500,borderRadius:(null===(x=t.panel)||void 0===x?void 0:x.borderRadius)||12,backgroundColor:(null===(k=t.panel)||void 0===k?void 0:k.backgroundColor)||"#FFFFFF",backdropFilter:(null===(C=t.panel)||void 0===C?void 0:C.backdropFilter)||null,border:(null===(P=t.panel)||void 0===P?void 0:P.border)||"1px solid rgba(0,0,0,0.1)"},t.panel),voice:lo({micButtonColor:(null===(O=t.voice)||void 0===O?void 0:O.micButtonColor)||(null===(E=t.panel)||void 0===E?void 0:E.micButtonColor)||Ie,micButtonActiveColor:(null===(T=t.voice)||void 0===T?void 0:T.micButtonActiveColor)||(null===(I=t.panel)||void 0===I?void 0:I.micButtonActiveColor)||"#EF4444",micButtonHint:lo(lo({text:(null===(j=t.voice)||void 0===j||null===(j=j.micButtonHint)||void 0===j?void 0:j.text)||(null===(A=t.panel)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.text)||"Click the button to start voice conversation",color:(null===(F=t.voice)||void 0===F||null===(F=F.micButtonHint)||void 0===F?void 0:F.color)||(null===(D=t.panel)||void 0===D||null===(D=D.micButtonHint)||void 0===D?void 0:D.color)||"#6B7280",fontSize:(null===(B=t.voice)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.fontSize)||(null===(R=t.panel)||void 0===R||null===(R=R.micButtonHint)||void 0===R?void 0:R.fontSize)||"12px"},null===(_=t.voice)||void 0===_?void 0:_.micButtonHint),null===(U=t.panel)||void 0===U?void 0:U.micButtonHint),avatarBackgroundColor:(null===(M=t.voice)||void 0===M?void 0:M.avatarBackgroundColor)||"#667eea",avatarActiveBackgroundColor:(null===(N=t.voice)||void 0===N?void 0:N.avatarActiveBackgroundColor)||"#667eea",statusTitleColor:(null===(z=t.voice)||void 0===z?void 0:z.statusTitleColor)||"#1e293b",statusSubtitleColor:(null===(L=t.voice)||void 0===L?void 0:L.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(V=t.voice)||void 0===V?void 0:V.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(K=t.voice)||void 0===K?void 0:K.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(H=t.voice)||void 0===H?void 0:H.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(W=t.voice)||void 0===W?void 0:W.transcriptTextColor)||"#1e293b",transcriptLabelColor:(null===(G=t.voice)||void 0===G?void 0:G.transcriptLabelColor)||"#94a3b8",controlButtonColor:(null===(q=t.voice)||void 0===q?void 0:q.controlButtonColor)||"#FFFFFF",controlButtonSecondaryColor:(null===(Q=t.voice)||void 0===Q?void 0:Q.controlButtonSecondaryColor)||"#64748b",endCallButtonColor:(null===(J=t.voice)||void 0===J?void 0:J.endCallButtonColor)||"#ef4444",language:(null===(Y=t.voice)||void 0===Y?void 0:Y.language)||t.language||"en",websocketUrl:(null===($=t.voice)||void 0===$?void 0:$.websocketUrl)||t.websocketUrl},t.voice),text:lo({sendButtonColor:(null===(X=t.text)||void 0===X?void 0:X.sendButtonColor)||(null===(Z=t.panel)||void 0===Z?void 0:Z.sendButtonColor)||"#7C3AED",sendButtonHoverColor:(null===(tt=t.text)||void 0===tt?void 0:tt.sendButtonHoverColor)||(null===(et=t.panel)||void 0===et?void 0:et.sendButtonHoverColor)||"#6D28D9",sendButtonActiveColor:(null===(nt=t.text)||void 0===nt?void 0:nt.sendButtonActiveColor)||(null===(ot=t.panel)||void 0===ot?void 0:ot.sendButtonActiveColor)||"#6D28D9",sendButtonText:(null===(rt=t.text)||void 0===rt?void 0:rt.sendButtonText)||(null===(it=t.panel)||void 0===it?void 0:it.sendButtonText)||"➤",sendButtonTextColor:(null===(at=t.text)||void 0===at?void 0:at.sendButtonTextColor)||(null===(ct=t.panel)||void 0===ct?void 0:ct.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(st=t.text)||void 0===st?void 0:st.sendButtonFontSize)||(null===(ut=t.panel)||void 0===ut?void 0:ut.sendButtonFontSize)||"18px",sendButtonFontWeight:(null===(lt=t.text)||void 0===lt?void 0:lt.sendButtonFontWeight)||(null===(dt=t.panel)||void 0===dt?void 0:dt.sendButtonFontWeight)||"500",sendButtonHint:lo(lo({text:(null===(ft=t.text)||void 0===ft||null===(ft=ft.sendButtonHint)||void 0===ft?void 0:ft.text)||(null===(pt=t.panel)||void 0===pt||null===(pt=pt.sendButtonHint)||void 0===pt?void 0:pt.text)||"",color:(null===(ht=t.text)||void 0===ht||null===(ht=ht.sendButtonHint)||void 0===ht?void 0:ht.color)||(null===(vt=t.panel)||void 0===vt||null===(vt=vt.sendButtonHint)||void 0===vt?void 0:vt.color)||"#6B7280",fontSize:(null===(gt=t.text)||void 0===gt||null===(gt=gt.sendButtonHint)||void 0===gt?void 0:gt.fontSize)||(null===(yt=t.panel)||void 0===yt||null===(yt=yt.sendButtonHint)||void 0===yt?void 0:yt.fontSize)||"12px"},null===(mt=t.text)||void 0===mt?void 0:mt.sendButtonHint),null===(bt=t.panel)||void 0===bt?void 0:bt.sendButtonHint),inputPlaceholder:(null===(St=t.text)||void 0===St?void 0:St.inputPlaceholder)||(null===(wt=t.panel)||void 0===wt?void 0:wt.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(xt=t.text)||void 0===xt?void 0:xt.inputBorderColor)||(null===(kt=t.panel)||void 0===kt?void 0:kt.inputBorderColor)||"#E5E7EB",inputFocusColor:(null===(Ct=t.text)||void 0===Ct?void 0:Ct.inputFocusColor)||(null===(Pt=t.panel)||void 0===Pt?void 0:Pt.inputFocusColor)||"#7C3AED",inputBackgroundColor:(null===(Ot=t.text)||void 0===Ot?void 0:Ot.inputBackgroundColor)||(null===(Et=t.panel)||void 0===Et?void 0:Et.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(Tt=t.text)||void 0===Tt?void 0:Tt.inputTextColor)||(null===(It=t.panel)||void 0===It?void 0:It.inputTextColor)||"#1F2937",inputFontSize:(null===(jt=t.text)||void 0===jt?void 0:jt.inputFontSize)||(null===(At=t.panel)||void 0===At?void 0:At.inputFontSize)||"14px",inputBorderRadius:(null===(Ft=t.text)||void 0===Ft?void 0:Ft.inputBorderRadius)||(null===(Dt=t.panel)||void 0===Dt?void 0:Dt.inputBorderRadius)||20,inputPadding:(null===(Bt=t.text)||void 0===Bt?void 0:Bt.inputPadding)||(null===(Rt=t.panel)||void 0===Rt?void 0:Rt.inputPadding)||"6px 14px"},t.text),landing:lo({backgroundColor:(null===(_t=t.landing)||void 0===_t?void 0:_t.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)",logo:(null===(Ut=t.landing)||void 0===Ut?void 0:Ut.logo)||"🤖",title:(null===(Mt=t.landing)||void 0===Mt?void 0:Mt.title)||null,titleColor:(null===(Nt=t.landing)||void 0===Nt?void 0:Nt.titleColor)||"#1e293b",modeCardBackgroundColor:(null===(zt=t.landing)||void 0===zt?void 0:zt.modeCardBackgroundColor)||"#FFFFFF",modeCardBorderColor:(null===(Lt=t.landing)||void 0===Lt?void 0:Lt.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Vt=t.landing)||void 0===Vt?void 0:Vt.modeCardHoverBorderColor)||je,modeCardIconBackgroundColor:(null===(Kt=t.landing)||void 0===Kt?void 0:Kt.modeCardIconBackgroundColor)||je,modeCardTitleColor:(null===(Ht=t.landing)||void 0===Ht?void 0:Ht.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(Wt=t.landing)||void 0===Wt?void 0:Wt.voiceCardIcon)||"🎤",textCardIcon:(null===(Gt=t.landing)||void 0===Gt?void 0:Gt.textCardIcon)||"💬"},t.landing),header:lo({title:(null===(qt=t.header)||void 0===qt?void 0:qt.title)||"Chat Assistant",showTitle:!1!==(null===(Qt=t.header)||void 0===Qt?void 0:Qt.showTitle),backgroundColor:(null===(Jt=t.header)||void 0===Jt?void 0:Jt.backgroundColor)||(null===(Yt=t.button)||void 0===Yt?void 0:Yt.backgroundColor)||"#7C3AED",textColor:(null===($t=t.header)||void 0===$t?void 0:$t.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(Xt=t.header)||void 0===Xt?void 0:Xt.showCloseButton)},t.header),tooltips:lo({newChat:(null===(Zt=t.tooltips)||void 0===Zt?void 0:Zt.newChat)||null,back:(null===(te=t.tooltips)||void 0===te?void 0:te.back)||null,close:(null===(ee=t.tooltips)||void 0===ee?void 0:ee.close)||null,mute:(null===(ne=t.tooltips)||void 0===ne?void 0:ne.mute)||null,speaker:(null===(oe=t.tooltips)||void 0===oe?void 0:oe.speaker)||null,endCall:(null===(re=t.tooltips)||void 0===re?void 0:re.endCall)||null},t.tooltips),messages:lo({userBackgroundColor:(null===(ie=t.messages)||void 0===ie?void 0:ie.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(ae=t.messages)||void 0===ae?void 0:ae.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(ce=t.messages)||void 0===ce?void 0:ce.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(se=t.messages)||void 0===se?void 0:se.errorBackgroundColor)||"#FEE2E2",textColor:(null===(ue=t.messages)||void 0===ue?void 0:ue.textColor)||"#1F2937",fontSize:(null===(le=t.messages)||void 0===le?void 0:le.fontSize)||"14px",borderRadius:(null===(de=t.messages)||void 0===de?void 0:de.borderRadius)||8},t.messages),animation:lo({enableHover:!1!==(null===(fe=t.animation)||void 0===fe?void 0:fe.enableHover),enablePulse:!1!==(null===(pe=t.animation)||void 0===pe?void 0:pe.enablePulse),enableSlide:!1!==(null===(he=t.animation)||void 0===he?void 0:he.enableSlide),duration:(null===(ve=t.animation)||void 0===ve?void 0:ve.duration)||.3},t.animation),behavior:lo({autoOpen:(null===(ge=t.behavior)||void 0===ge?void 0:ge.autoOpen)||!1,startOpen:(null===(ye=t.behavior)||void 0===ye?void 0:ye.startOpen)||!1,hidden:(null===(me=t.behavior)||void 0===me?void 0:me.hidden)||!1,autoConnect:(null===(be=t.behavior)||void 0===be?void 0:be.autoConnect)||!1,showWelcomeMessage:!1!==(null===(Se=t.behavior)||void 0===Se?void 0:Se.showWelcomeMessage),welcomeMessage:(null===(we=t.behavior)||void 0===we?void 0:we.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:void 0===(null===(xe=t.behavior)||void 0===xe?void 0:xe.enableVoiceMode)||t.behavior.enableVoiceMode,mode:(null===(ke=t.behavior)||void 0===ke?void 0:ke.mode)||"unified"},t.behavior),accessibility:lo({ariaLabel:(null===(Ce=t.accessibility)||void 0===Ce?void 0:Ce.ariaLabel)||"Chat Assistant",ariaDescription:(null===(Pe=t.accessibility)||void 0===Pe?void 0:Pe.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(Oe=t.accessibility)||void 0===Oe?void 0:Oe.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},forceConversationId:t.forceConversationId,onConversationStart:t.onConversationStart,onConversationEnd:t.onConversationEnd,onBargeIn:t.onBargeIn,onAudioStartPlaying:t.onAudioStartPlaying,onAudioStoppedPlaying:t.onAudioStoppedPlaying,onSubtitleDisplay:t.onSubtitleDisplay,primaryColor:Ie},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.on("domainError",function(e){t.textInterface.showError(e),t.textInterface.stopStreamingState()}),this.sdk.on("error",function(e){e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))||(t.textInterface.showError(e.message||e),t.textInterface.stopStreamingState())}),this.sdk.on("chunk",function(e){t.textInterface.appendStreamingChunk(e)}),this.sdk.on("done",function(e){var n=e.text;t.textInterface.finalizeStreaming(n)})}},{key:"createWidget",value:function(){console.log("🏗️ createWidget called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var t=document.getElementById("text-chat-widget");t&&t.remove();var e=document.createElement("div");if(e.id="text-chat-widget",e.innerHTML=this.generateWidgetHTML(),document.body.appendChild(e),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("text-chat-panel");n&&(this.isOpen=!0,n.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){var t=this,e=(this.config.position,this.config.button),n=this.config.icon,o=(this.config.panel,this.config.header),r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),i={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i),s=this.config.behavior.mode||"unified",u="unified"===s,l="unified"===s||"voice-only"===s,d="unified"===s||"text-only"===s,f=function(e){var n=t.config.language||"en";return(t.translations[n]||t.translations.en)[e]||e},p=function(e){var n,o=null===(n=t.config.tooltips)||void 0===n?void 0:n[e];return null!=o?o:{newChat:f("newChat"),back:f("back"),close:f("close"),mute:f("mute"),speaker:f("speaker"),endCall:f("endCall")}[e]||""};return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header" style="background: ').concat(o.backgroundColor,"; color: ").concat(o.textColor,';">\n <div>\n ').concat(o.showTitle?'<div class="header-title">'.concat(o.title,"</div>"):"",'\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat(f("online"),'</span>\n </div>\n </div>\n \n <div style="display: flex; gap: 12px; align-items: center;">\n \x3c!-- New Chat Button (hide on landing screen, show otherwise) --\x3e\n <button class="header-icon new-chat-btn" id="newChatBtn" title="').concat(p("newChat"),'" style="').concat(u?"display: none;":"",'">\n <span style="font-size: 18px; font-weight: bold;">+</span>\n </button>\n \n \x3c!-- Back Button (only show in unified mode) --\x3e\n ').concat("unified"===s?'<button class="header-icon back-btn" id="backBtn" title="'.concat(p("back"),'" style="display: none;">\n <span style="font-size: 16px;">‹</span>\n </button>'):"","\n \n \x3c!-- Close Button --\x3e\n ").concat(o.showCloseButton?'<button class="header-icon close-btn" id="closeBtn" title="'+p("close")+'"><span style="font-size: 18px; font-weight: bold;">×</span></button>':"","\n </div>\n </div>\n\n ").concat(u?'\n <div class="landing-screen" id="landingScreen">\n <div class="landing-logo">🤖</div>\n <div class="landing-title">'.concat(f("landingTitle"),'</div>\n <div class="mode-selection">\n ').concat(l?'<div class="mode-card voice" id="mode-card-voice">\n <div class="mode-card-icon">🎤</div>\n <div class="mode-card-title">'.concat(f("voiceCall"),"</div>\n </div>"):"","\n ").concat(d?'<div class="mode-card text" id="mode-card-text">\n <div class="mode-card-icon">💬</div>\n <div class="mode-card-title">'.concat(f("textChat"),"</div>\n </div>"):"","\n </div>\n </div>"):"","\n\n ").concat(l?this.voiceInterface.generateHTML():"","\n ").concat(d?this.textInterface.generateHTML():"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var t=this.config.position,e=t.offset||{x:20,y:20},n="";return"top"===t.vertical?n+="top: ".concat(e.y,"px;"):"bottom"===t.vertical?n+="bottom: ".concat(e.y,"px;"):"center"===t.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===t.horizontal?n+="left: ".concat(e.x,"px;"):"right"===t.horizontal?n+="right: ".concat(e.x,"px;"):"center"===t.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(t){var e=this.config.icon;switch(e.type){case"custom":return'<img src="'.concat(e.customImage,'" alt="Chat Assistant" style="width: ').concat(t,"px; height: ").concat(t,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(t,'px; line-height: 1;">').concat(e.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*t),'px; font-weight: bold; color: white;">').concat(e.text,"</span>");case"microphone":default:return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>');case"chat":return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/>\n </svg>')}}},{key:"generateCSS",value:function(t,e,n){var o,r,i,a,c,s,u,l=this.config.button,d=this.config.icon,f=this.config.panel,p=this.config.header,h=(this.config.messages,this.config.animation),v=this.config.behavior.mode||"unified",g="unified"===v||"voice-only"===v,y="unified"===v||"text-only"===v,m=p.backgroundColor;return'\n /* MOBILE FIRST - Default styles for all devices */\n #text-chat-widget {\n position: fixed !important;\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n /* Mobile defaults */\n right: 10px;\n bottom: 10px;\n left: auto;\n top: auto;\n }\n \n /* Desktop positioning (only on larger screens) */\n @media (min-width: 769px) {\n #text-chat-widget {\n '.concat(t,"\n right: ").concat("right"===this.config.position.horizontal?"20px":"auto",";\n left: ").concat("left"===this.config.position.horizontal?"20px":"auto",";\n bottom: ").concat("bottom"===this.config.position.vertical?"20px":"auto",";\n top: ").concat("top"===this.config.position.vertical?"20px":"auto",";\n }\n }\n \n /* Mobile override (force mobile positioning) */\n @media (max-width: 768px) {\n #text-chat-widget {\n right: 10px !important;\n bottom: 10px !important;\n left: auto !important;\n top: auto !important;\n transform: none !important;\n }\n }\n \n @media (max-width: 480px) {\n #text-chat-widget {\n right: 8px !important;\n bottom: 8px !important;\n left: auto !important;\n top: auto !important;\n }\n }\n \n #text-chat-button {\n width: ").concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===l.shape?"50%":"square"===l.shape?"0":"12px",";\n background: ").concat(l.backgroundColor||d.backgroundColor||"#7C3AED",";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(h.duration,"s ease;\n box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);\n touch-action: manipulation;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n user-select: none;\n min-width: 44px;\n min-height: 44px;\n }\n \n @media (max-width: 768px) {\n #text-chat-widget {\n right: 10px !important;\n bottom: 10px !important;\n left: auto !important;\n top: auto !important;\n transform: none !important;\n }\n \n #text-chat-button {\n width: 56px !important;\n height: 56px !important;\n min-width: 56px !important;\n min-height: 56px !important;\n max-width: 56px !important;\n max-height: 56px !important;\n }\n \n #text-chat-panel {\n position: fixed !important;\n left: 10px !important;\n right: 10px !important;\n bottom: 76px !important; /* 56px button + 20px gap */\n top: 60px !important; /* Add top spacing */\n width: auto !important;\n max-width: none !important;\n height: auto !important; /* Change from max-height to auto */\n max-height: none !important; /* Remove max-height */\n transform: none !important;\n margin: 0 !important;\n }\n \n #text-chat-panel .widget-header {\n padding: 10px 14px;\n min-height: 56px;\n }\n \n #text-chat-panel .header-title {\n font-size: 15px;\n }\n \n #text-chat-panel .header-icon {\n width: 40px;\n height: 40px;\n min-width: 40px;\n min-height: 40px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 12px 16px !important;\n min-height: 48px !important;\n }\n \n #text-chat-send {\n min-width: 48px !important;\n min-height: 48px !important;\n width: 48px !important;\n height: 48px !important;\n }\n \n .landing-screen {\n padding: 16px;\n }\n \n .landing-logo {\n font-size: 40px;\n }\n \n .landing-title {\n font-size: 18px;\n margin-bottom: 16px;\n }\n \n .mode-selection {\n flex-direction: column;\n gap: 12px;\n align-items: center;\n }\n \n .mode-card {\n max-width: 100%;\n width: 100%;\n padding: 16px;\n }\n \n .mode-card-icon {\n width: 50px;\n height: 50px;\n font-size: 28px;\n }\n \n .mode-card-title {\n font-size: 14px;\n }\n }\n \n @media (max-width: 480px) {\n #text-chat-widget {\n right: 8px !important;\n bottom: 8px !important;\n left: auto !important;\n top: auto !important;\n }\n \n #text-chat-button {\n width: 54px !important;\n height: 54px !important;\n min-width: 54px !important;\n min-height: 54px !important;\n }\n \n #text-chat-panel {\n left: 8px !important;\n right: 8px !important;\n bottom: 70px !important;\n top: 50px !important; /* Add top spacing for very small screens */\n height: auto !important;\n max-height: none !important;\n }\n \n #text-chat-panel .widget-header {\n padding: 8px 12px;\n min-height: 52px;\n }\n \n #text-chat-panel .header-title {\n font-size: 14px;\n }\n \n .landing-logo {\n font-size: 36px;\n }\n \n .landing-title {\n font-size: 16px;\n }\n }\n \n ").concat(h.enableHover?"\n #text-chat-button:hover {\n background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);\n transform: scale(1.05);\n box-shadow: 0 8px 20px rgba(102, 126, 234, 0.5);\n }\n ":"","\n \n #text-chat-panel {\n display: none;\n position: fixed;\n bottom: calc(").concat(e,"px + 20px);\n ").concat("right"===this.config.position.horizontal?"right: 20px;":"left: 20px;","\n width: ").concat(f.width,"px;\n max-width: calc(100vw - 40px);\n height: ").concat(f.height,"px;\n max-height: calc(100vh - ").concat(e,"px - 40px);\n background: transparent;\n border-radius: ").concat(f.borderRadius,"px;\n border: none;\n flex-direction: column;\n overflow: hidden;\n ").concat(f.backdropFilter?"backdrop-filter: ".concat(f.backdropFilter,";"):"","\n ").concat(h.enableSlide?"transition: all ".concat(h.duration,"s ease;"):"","\n box-sizing: border-box;\n }\n \n #text-chat-panel.open {\n display: flex;\n ").concat(h.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n\n /* Shell for gradient border/background */\n .widget-shell { width: 100%; height: 100%; padding: 0; border-radius: ").concat(f.borderRadius,"px; background: transparent; box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; display: flex; flex-direction: column; box-sizing: border-box; }\n .panel-inner { width: 100%; height: 100%; background: #ffffff; border-radius: ").concat(f.borderRadius,"px; overflow: hidden; display:flex; flex-direction: column; padding: 0; box-sizing: border-box; max-width: 100%; }\n\n /* New structure styles matching provided design */\n #text-chat-panel .widget-container {\n width: 100%; height: 100%; min-height: 0; background: #FFFFFF; overflow: hidden; display: flex; flex-direction: column; border-radius: ").concat(f.borderRadius,"px;\n container-type: size;\n }\n \n /* Ensure content areas can scroll when height is constrained */\n #text-chat-panel .widget-container > .landing-screen,\n #text-chat-panel .widget-container > .voice-interface,\n #text-chat-panel .widget-container > .text-interface {\n flex: 1;\n min-height: 0;\n overflow-y: auto;\n overflow-x: hidden;\n }\n \n /* Header should not scroll */\n #text-chat-panel .widget-header {\n padding: 12px 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-top-left-radius: ").concat(f.borderRadius,"px;\n border-top-right-radius: ").concat(f.borderRadius,"px;\n flex-shrink: 0;\n min-height: 60px;\n box-sizing: border-box;\n }\n #text-chat-panel .header-title { font-size: 16px; font-weight: 600; }\n #text-chat-panel .header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.9; }\n #text-chat-panel .status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }\n @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n /* Header icon buttons */\n .header-icon {\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 36px;\n height: 36px;\n min-width: 36px;\n min-height: 36px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n flex-shrink: 0;\n font-size: 16px;\n padding: 0;\n box-sizing: border-box;\n }\n \n .header-icon:hover {\n background: rgba(255, 255, 255, 0.3);\n }\n \n .header-icon svg {\n pointer-events: none;\n stroke: white;\n fill: none;\n }\n \n .back-btn.visible {\n display: flex !important;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { \n display: none; \n flex: 1; \n padding: 20px; \n background: ").concat((null===(o=this.config.landing)||void 0===o?void 0:o.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)","; \n align-items: center; \n justify-content: flex-start; \n flex-direction: column; \n gap: 16px; \n overflow-y: auto; \n min-height: 0; \n }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { \n font-size: 20px; \n color: ").concat((null===(r=this.config.landing)||void 0===r?void 0:r.titleColor)||"#1e293b","; \n font-weight: 700; \n margin-bottom: 20px; \n text-align: center;\n width: 100%;\n }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { \n flex: 1; \n max-width: 180px; \n background: ").concat((null===(i=this.config.landing)||void 0===i?void 0:i.modeCardBackgroundColor)||"#FFFFFF","; \n border: 2px solid ").concat((null===(a=this.config.landing)||void 0===a?void 0:a.modeCardBorderColor)||"#E2E8F0","; \n border-radius: 20px; \n padding: 20px 12px; \n cursor: pointer; \n display: flex; \n flex-direction: column; \n align-items: center; \n gap: 8px; \n transition: transform ").concat(h.duration,"s ease, box-shadow ").concat(h.duration,"s ease, border-color ").concat(h.duration,"s ease; \n box-shadow: 0 4px 12px rgba(0,0,0,0.05); \n }\n .mode-card:hover { \n transform: translateY(-6px); \n box-shadow: 0 12px 24px rgba(102, 126, 234, 0.2); \n border-color: ").concat((null===(c=this.config.landing)||void 0===c?void 0:c.modeCardHoverBorderColor)||m,"; \n }\n .mode-card-icon { \n width: 60px; \n height: 60px; \n display: flex; \n align-items: center; \n justify-content: center; \n border-radius: 50%; \n background: ").concat((null===(s=this.config.landing)||void 0===s?void 0:s.modeCardIconBackgroundColor)||m,"; \n color: #fff; \n font-size: 32px; \n }\n .mode-card-title { \n color: ").concat((null===(u=this.config.landing)||void 0===u?void 0:u.modeCardTitleColor)||"#111827","; \n font-weight: 600; \n text-align: center;\n width: 100%;\n }\n\n ").concat(g?this.voiceInterface.generateCSS():"","\n ").concat(y?this.textInterface.generateCSS():"","\n \n #text-chat-send-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this;console.log("⚙️ setupWidgetEvents called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n"),currentView:this.currentView});var e=document.getElementById("text-chat-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("closeBtn");n&&(n.onclick=function(){return t.togglePanel()});var o=this.config.behavior.mode||"unified",r="unified"===o,i="unified"===o||"voice-only"===o,a="unified"===o||"text-only"===o,c=document.getElementById("backBtn"),s=document.getElementById("landingScreen"),u=document.getElementById("mode-card-voice"),l=document.getElementById("mode-card-text"),d=document.getElementById("textInterface"),f=document.getElementById("voiceInterface");c&&(c.onclick=function(){return t.showLanding()}),r?(u&&(u.onclick=function(){return t.showVoice()}),l&&(l.onclick=function(){return t.showText()}),"text"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.add("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="")):"voice"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.remove("active"),f&&f.classList.add("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="none")):(this.currentView="landing",s&&s.classList.add("active"),d&&d.classList.remove("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.remove("visible"))):"voice-only"===o?(f&&f.classList.add("active"),d&&d.classList.remove("active"),s&&s.classList.remove("active")):"text-only"===o&&(d&&d.classList.add("active"),f&&f.classList.remove("active"),s&&s.classList.remove("active")),i&&(console.log("⚙️ Setting up voice interface event handlers"),this.voiceInterface.setupEventHandlers()),a&&(console.log("⚙️ Setting up text interface event handlers"),this.textInterface.setupEventHandlers());var p=document.getElementById("newChatBtn");p&&(p.onclick=function(){return t.textInterface.startNewChat()},r&&(p.style.display="none")),this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"startNewChat",value:function(){this.textInterface.startNewChat()}},{key:"showLanding",value:function(){if("unified"===(this.config.behavior.mode||"unified")){this.currentView="landing";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),r&&(r.style.display="none")}}},{key:"showText",value:function(){this.currentView="text";var t=document.getElementById("landingScreen"),e=document.getElementById("voiceInterface"),n=document.getElementById("backBtn"),o=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),this.textInterface.show();var r=this.config.behavior.mode||"unified";n&&"unified"===r&&n.classList.add("visible"),o&&(o.style.display="")}},{key:"showVoice",value:function(){this.currentView="voice";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active");var i=this.config.behavior.mode||"unified";o&&"unified"===i&&o.classList.add("visible"),r&&(r.style.display="none")}},{key:"setupKeyboardNavigation",value:function(){var t=this;document.addEventListener("keydown",function(e){"Escape"===e.key&&t.isOpen&&t.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("text-chat-panel").classList.toggle("open"),this.isOpen&&setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},100),this.isOpen&&!this.isActive&&this.config.behavior.autoConnect&&this.startChat()}},{key:"startChat",value:(i=co(ro().m(function t(){return ro().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.textInterface.setActive(!0);case 1:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"sendMessage",value:(r=co(ro().m(function t(){return ro().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.textInterface.sendMessage();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=co(ro().m(function t(){var e,n,o,r,i,a,c;return ro().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://backend.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"addMessage",value:function(t,e){this.textInterface.addMessage(t,e)}},{key:"beginStreaming",value:function(){this.textInterface.beginStreaming()}},{key:"appendStreamingChunk",value:function(t){this.textInterface.appendStreamingChunk(t)}},{key:"finalizeStreaming",value:function(t){this.textInterface.finalizeStreaming(t)}},{key:"stopStreamingState",value:function(){this.textInterface.stopStreamingState()}},{key:"showError",value:function(t){this.textInterface.showError(t)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n,o,r,i,a,c;console.log("🔄 updateConfig called",{newConfig:t,stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var s,u,l=lo({},this.config);t.panel&&(l.panel=lo(lo({},this.config.panel),t.panel)),t.voice&&(l.voice=lo(lo({},this.config.voice),t.voice),t.voice.micButtonHint&&(l.voice.micButtonHint=lo(lo({},null===(s=this.config.voice)||void 0===s?void 0:s.micButtonHint),t.voice.micButtonHint))),t.text&&(l.text=lo(lo({},this.config.text),t.text),t.text.sendButtonHint&&(l.text.sendButtonHint=lo(lo({},null===(u=this.config.text)||void 0===u?void 0:u.sendButtonHint),t.text.sendButtonHint))),void 0!==t.language&&(l.language=t.language),void 0!==t.language&&(["he","ar"].includes(t.language)?l.direction="rtl":void 0===t.direction&&(l.direction="ltr")),t.translations&&(l.translations=t.translations,this.translations=t.translations),t.button&&(l.button=lo(lo({},this.config.button),t.button)),t.header&&(l.header=lo(lo({},this.config.header),t.header)),t.icon&&(l.icon=lo(lo({},this.config.icon),t.icon)),t.messages&&(l.messages=lo(lo({},this.config.messages),t.messages)),t.animation&&(l.animation=lo(lo({},this.config.animation),t.animation)),t.behavior&&(l.behavior=lo(lo({},this.config.behavior),t.behavior)),t.accessibility&&(l.accessibility=lo(lo({},this.config.accessibility),t.accessibility)),t.tooltips&&(l.tooltips=lo(lo({},this.config.tooltips),t.tooltips)),t.landing&&(l.landing=lo(lo({},this.config.landing),t.landing)),void 0!==t.direction&&void 0===l.direction&&(l.direction=t.direction),void 0!==t.primaryColor&&(l.primaryColor=t.primaryColor),void 0!==t.onConversationStart&&(l.onConversationStart=t.onConversationStart),void 0!==t.onConversationEnd&&(l.onConversationEnd=t.onConversationEnd),void 0!==t.onBargeIn&&(l.onBargeIn=t.onBargeIn),void 0!==t.onAudioStartPlaying&&(l.onAudioStartPlaying=t.onAudioStartPlaying),void 0!==t.onAudioStoppedPlaying&&(l.onAudioStoppedPlaying=t.onAudioStoppedPlaying),void 0!==t.onSubtitleDisplay&&(l.onSubtitleDisplay=t.onSubtitleDisplay),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction","voice","text","animation","behavior","accessibility","language","tooltips","landing","primaryColor","onConversationStart","onConversationEnd","onBargeIn","onAudioStartPlaying","onAudioStoppedPlaying","onSubtitleDisplay"].includes(e)||(l[e]=t[e])}),null===(e=this.config)||void 0===e||e.language,this.config=this.mergeWithDefaults(l);var d=this.config.language||"en",f=lo(lo(lo({},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 Qn(f);var p=lo(lo(lo({},this.config),this.config.text),{},{language:d,translations:this.translations});this.textInterface=new no(p,this.sdk);var h=document.getElementById("text-chat-widget");h&&h.remove(),this.createWidget(),this.textInterface&&this.textInterface.updateInputAttributes&&this.textInterface.updateInputAttributes()}},{key:"destroy",value:function(){var t=document.getElementById("text-chat-widget");t&&t.remove(),this.sdk&&this.sdk.destroy(),this.voiceInterface&&this.voiceInterface.destroy()}},{key:"startVoiceCall",value:(n=co(ro().m(function t(){return ro().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.voiceInterface.startVoiceCall();case 1:return t.a(2)}},t,this)})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){this.voiceInterface.endVoiceCall()}},{key:"toggleMute",value:function(){this.voiceInterface.toggleMute()}},{key:"toggleSpeaker",value:function(){this.voiceInterface.toggleSpeaker()}}],e&&po(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,r,i}(),go="2.4.2";const yo={VoiceSDK:pt,VoiceSDK_v2:Ye,TextChatSDK:ln,WebSocketManager:A,AudioRecorder:K,AudioPlayer:Z,EventEmitter:c,VoiceButton:xn,VanillaVoiceButton:Fn,AgentSDK:zn,TTPChatWidget:vo,VERSION:go};return o})());
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==e.key&&(r=""+e.key),"key"in e)for(var i in o={},e)"key"!==i&&(o[i]=e[i]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:r,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},i.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=i.prototype;var s=c.prototype=new a;s.constructor=c,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var u={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return u.H.useEffect(t,e)},e.useRef=function(t){return u.H.useRef(t)},e.useState=function(t){return u.H.useState(t)}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>zn,AudioPlayer:()=>Z,AudioRecorder:()=>K,EventEmitter:()=>c,TTPChatWidget:()=>vo,TextChatSDK:()=>ln,VERSION:()=>go,VanillaVoiceButton:()=>Dn,VoiceButton:()=>xn,VoiceSDK:()=>pt,VoiceSDK_v2:()=>Ye,WebSocketManager:()=>A,default:()=>yo});var c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||d(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=d(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function d(t,e){if(t){if("string"==typeof t)return f(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return h(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(h(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,h(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,h(d,"constructor",u),h(u,"constructor",s),s.displayName="GeneratorFunction",h(u,r,"GeneratorFunction"),h(d),h(d,r,"Generator"),h(d,o,function(){return this}),h(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:f}})()}function h(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}h=function(t,e,n,o){function i(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},h(t,e,n,o)}function v(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,y(o.key),o)}}function y(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(m=function(){return!!t})()}function b(t){return b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},b(t)}function S(t,e){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},S(t,e)}const w=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=b(e),function(t,e){if(e&&("object"==s(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,m()?Reflect.construct(e,n||[],b(t).constructor):e.apply(t,n))}(this,e)).connections=new Map,t.connectionCounts=new Map,t.creatingConnections=new Set,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&S(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=p().m(function t(e){var n,o,r=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(r.connections.has(e)){var o=r.connections.get(e);r.connectionCounts.set(e,(r.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){r.creatingConnections.delete(e),r.emit("error",t,e)}),o.addEventListener("message",function(t){r.emit("message",t,e)}),t.a(2,o)}},t,this)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){v(i,n,o,a,c,"next",t)}function c(t){v(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=l(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=u(t.value,2),r=o[0],i=o[1];e[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c));function x(t){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},x(t)}function k(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return C(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(C(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,C(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,C(d,"constructor",u),C(u,"constructor",s),s.displayName="GeneratorFunction",C(u,r,"GeneratorFunction"),C(d),C(d,r,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(k=function(){return{w:i,m:f}})()}function C(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}C=function(t,e,n,o){function i(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},C(t,e,n,o)}function P(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,E(o.key),o)}}function E(t){var e=function(t){if("object"!=x(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=x(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==x(e)?e:e+""}function T(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(T=function(){return!!t})()}function I(t){return I=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},I(t)}function j(t,e){return j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},j(t,e)}var A=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=I(e),function(t,e){if(e&&("object"==x(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,T()?Reflect.construct(e,n||[],I(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&j(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=k().m(function t(){var e=this;return k().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,w.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t(),e.connectResolve=null,e.connectReject=null)}).catch(function(t){console.error("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null})}catch(t){console.error("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null}}))},t)}),a=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){P(r,n,o,a,c,"next",t)}function c(t){P(r,n,o,a,c,"throw",t)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};w.on("open",e),w.on("close",n),w.on("error",o),w.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(w.off("open",this.eventHandlers.open),w.off("close",this.eventHandlers.close),w.off("error",this.eventHandlers.error),w.off("message",this.eventHandlers.message)),this.config.websocketUrl&&w.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(t))}catch(t){console.warn("🔌 WebSocketManager: Failed to send message:",t.message)}}},{key:"sendBinary",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(t)}catch(t){console.warn("🔌 WebSocketManager: Failed to send binary data:",t.message)}}},{key:"handleMessage",value:function(t){var e=this;if(t.data instanceof ArrayBuffer)this.emit("binaryAudio",t.data);else if(t.data instanceof Blob)t.data.arrayBuffer().then(function(t){e.emit("binaryAudio",t)}).catch(function(t){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return w.getAllConnections()}},{key:"clearAllConnections",value:function(){w.clearAll()}}],o&&O(n.prototype,o),r&&O(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a}(c);function D(t){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},D(t)}function F(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return B(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(B(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,B(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,B(d,"constructor",u),B(u,"constructor",s),s.displayName="GeneratorFunction",B(u,r,"GeneratorFunction"),B(d),B(d,r,"Generator"),B(d,o,function(){return this}),B(d,"toString",function(){return"[object Generator]"}),(F=function(){return{w:i,m:f}})()}function B(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}B=function(t,e,n,o){function i(e,n){B(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},B(t,e,n,o)}function R(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function _(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){R(i,o,r,a,c,"next",t)}function c(t){R(i,o,r,a,c,"throw",t)}a(void 0)})}}function U(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function M(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,N(o.key),o)}}function N(t){var e=function(t){if("object"!=D(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==D(e)?e:e+""}function z(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(z=function(){return!!t})()}function L(t){return L=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},L(t)}function V(t,e){return V=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},V(t,e)}var K=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=L(e),function(t,e){if(e&&("object"==D(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,z()?Reflect.construct(e,n||[],L(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&V(t,e)}(e,t),n=e,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var t,e=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return U(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?U(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{new URL(n);var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=_(F().m(function t(){var e,n,o=this;return F().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 1:if(this.mediaStream=t.v,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=2;break}return t.n=2,this.audioContext.resume();case 2:return e=this.getAudioProcessorPath(),t.n=3,this.audioContext.audioWorklet.addModule(e);case 3:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,n=e.type,r=e.data;"pcm_audio_data"===n&&o.emit("audioData",r)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,n=t.v,this.emit("error",n),n;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=_(F().m(function t(){var e;return F().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&M(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function H(t){return H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},H(t)}function W(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return G(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(G(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,G(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,G(d,"constructor",u),G(u,"constructor",s),s.displayName="GeneratorFunction",G(u,r,"GeneratorFunction"),G(d),G(d,r,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(W=function(){return{w:i,m:f}})()}function G(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}G=function(t,e,n,o){function i(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},G(t,e,n,o)}function q(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Q(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,J(o.key),o)}}function J(t){var e=function(t){if("object"!=H(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=H(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==H(e)?e:e+""}function Y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Y=function(){return!!t})()}function $(t){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},$(t)}function X(t,e){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},X(t,e)}var Z=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=$(e),function(t,e){if(e&&("object"==H(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Y()?Reflect.construct(e,n||[],$(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&X(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(r=W().m(function t(){var e,n,o,r,i,a,c,s,u,l=this;return W().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||(o=this.config.sampleRate?{sampleRate:this.config.sampleRate}:{},this.audioContext=new(window.AudioContext||window.webkitAudioContext)(o)),"suspended"!==(r=this.audioContext).state){t.n=3;break}return t.n=3,r.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return i=t.v,t.n=5,r.decodeAudioData(i);case 5:a=t.v,c=n&&!this.isPlaying&&null===this.currentSource,(s=r.createBufferSource()).buffer=a,s.connect(r.destination),this.currentSource=s,this.isPlaying=!0,c&&this.emit("playbackStarted"),s.onended=function(){l.currentSource=null,l.isProcessingQueue=!1,l.audioQueue.length>0?setTimeout(function(){return l.processQueue()},0):setTimeout(function(){0!==l.audioQueue.length||l.currentSource||(l.isPlaying=!1,l.emit("playbackStopped"))},100)},s.start(),t.n=7;break;case 6:t.p=6,u=t.v,this.currentSource=null,this.emit("playbackError",u),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){q(i,n,o,a,c,"next",t)}function c(t){q(i,n,o,a,c,"throw",t)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&Q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function tt(t){return tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tt(t)}function et(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return nt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(nt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,nt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,nt(d,"constructor",u),nt(u,"constructor",s),s.displayName="GeneratorFunction",nt(u,r,"GeneratorFunction"),nt(d),nt(d,r,"Generator"),nt(d,o,function(){return this}),nt(d,"toString",function(){return"[object Generator]"}),(et=function(){return{w:i,m:f}})()}function nt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}nt=function(t,e,n,o){function i(e,n){nt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},nt(t,e,n,o)}function ot(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function rt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){ot(i,o,r,a,c,"next",t)}function c(t){ot(i,o,r,a,c,"throw",t)}a(void 0)})}}function it(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function at(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?it(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):it(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=ut(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function st(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ut(o.key),o)}}function ut(t){var e=function(t){if("object"!=tt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==tt(e)?e:e+""}function lt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(lt=function(){return!!t})()}function dt(t){return dt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},dt(t)}function ft(t,e){return ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ft(t,e)}var pt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=dt(e),function(t,e){if(e&&("object"==tt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,lt()?Reflect.construct(e,n||[],dt(t).constructor):e.apply(t,n))}(this,e)).config=at({websocketUrl:n.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:n.agentId,appId:n.appId,ttpId:n.ttpId,voice:n.voice||"default",language:n.language||"en",sampleRate:n.sampleRate||16e3,agentSettingsOverride:n.agentSettingsOverride||null},n),t.isConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.webSocketManager=new A(at(at({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new K(t.config),t.audioPlayer=new Z(t.config),t.setupEventHandlers(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ft(t,e)}(e,t),n=e,o=[{key:"setupEventHandlers",value:function(){var t=this;this.webSocketManager.on("connected",function(){t.isConnected=!0,t.sendHelloMessage(),t.emit("connected")}),this.webSocketManager.on("disconnected",function(e){if(t.isConnected=!1,e&&1008===e.code&&e.reason&&(e.reason.includes("Domain not whitelisted")||e.reason.includes("domain")||e.reason.includes("whitelist"))){var n=new Error("DOMAIN_NOT_WHITELISTED");n.reason=e.reason,n.code=e.code,t.emit("domainError",n),t.emit("error",n)}t.isRecording&&t.stopRecording().catch(function(t){console.error("VoiceSDK: Error stopping recording on disconnect:",t)}),t.emit("disconnected",e)}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){if("greeting_audio"===e.t&&e.data)try{for(var n=atob(e.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(u=rt(et().m(function t(){var e,n;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isDestroyed){t.n=1;break}return t.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),t.n=2,this.connect();case 2:return t.a(2,t.v)}},t,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(c=rt(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw new Error("Not connected to voice server");case 1:return t.p=1,this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),t.n=2,this.audioRecorder.start();case 2:return t.a(2,!0);case 3:return t.p=3,e=t.v,console.error("❌ VoiceSDK: Failed to start recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=rt(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=rt(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=at(at({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={t:"hello"};if(!this.config.appId){var e=new Error("appId is required for connection");return console.error("VoiceSDK: Failed to send hello message:",e),void this.emit("error",e)}t.appId=this.config.appId,this.config.agentSettingsOverride&&Object.keys(this.config.agentSettingsOverride).length>0&&(t.agentSettingsOverride=this.config.agentSettingsOverride,console.log("🔧 VoiceSDK: Sending agent settings override:",Object.keys(this.config.agentSettingsOverride)));try{this.webSocketManager.sendMessage(t)}catch(e){console.error("VoiceSDK: Failed to send hello message:",e),this.emit("error",e)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&st(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(c);function ht(t){return ht="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ht(t)}function vt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,gt(o.key),o)}}function gt(t){var e=function(t){if("object"!=ht(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ht(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ht(e)?e:e+""}var yt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){return this.events[t]||(this.events[t]=[]),this.events[t].push(e),this}},{key:"off",value:function(t,e){return this.events[t]?(this.events[t]=this.events[t].filter(function(t){return t!==e}),this):this}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];return!!this.events[t]&&(this.events[t].forEach(function(t){t.apply(void 0,n)}),!0)}},{key:"once",value:function(t,e){var n=this,o=function(){e.apply(void 0,arguments),n.off(t,o)};return this.on(t,o)}},{key:"removeAllListeners",value:function(t){return t?delete this.events[t]:this.events={},this}}],e&&vt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();const mt=yt;function bt(t){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},bt(t)}function St(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,wt(o.key),o)}}function wt(t){var e=function(t){if("object"!=bt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==bt(e)?e:e+""}const xt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCM"},(e=[{key:"decode",value:function(t){if(t instanceof ArrayBuffer)return t;if(t instanceof Uint8Array)return t.buffer;throw new Error("Invalid PCM data type")}},{key:"encode",value:function(t){return t}}])&&St(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function kt(t){return kt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},kt(t)}function Ct(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Pt(o.key),o)}}function Pt(t){var e=function(t){if("object"!=kt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=kt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==kt(e)?e:e+""}const Ot=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCMU"},(e=[{key:"decode",value:function(t){for(var e=t instanceof Uint8Array?t:new Uint8Array(t),n=new Int16Array(e.length),o=0;o<e.length;o++)n[o]=this.mulawToLinear(e[o]);return n.buffer}},{key:"encode",value:function(t){for(var e=t instanceof Int16Array?t:new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++)n[o]=this.linearToMulaw(e[o]);return n}},{key:"mulawToLinear",value:function(t){var e=1<<3+(t>>4&7);return(128&t?-1:1)*(132+(15&t)*e+(e>>1)-4)}},{key:"linearToMulaw",value:function(t){var e=t>>8&128;e&&(t=-t),t>32635&&(t=32635),t+=132;for(var n=7,o=16384;0===(t&o)&&n>0;n--,o>>=1);return 255&~(e|n<<4|t>>n+3&15)}}])&&Ct(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function Et(t){return Et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Et(t)}function Tt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,It(o.key),o)}}function It(t){var e=function(t){if("object"!=Et(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Et(e)?e:e+""}const jt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name="PCMA"},(e=[{key:"decode",value:function(t){for(var e=t instanceof Uint8Array?t:new Uint8Array(t),n=new Int16Array(e.length),o=0;o<e.length;o++)n[o]=this.alawToLinear(e[o]);return n.buffer}},{key:"encode",value:function(t){for(var e=t instanceof Int16Array?t:new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++)n[o]=this.linearToAlaw(e[o]);return n}},{key:"alawToLinear",value:function(t){var e=(t^=85)>>4&7,n=15&t;return(128&t?-1:1)*(0===e?8+(n<<4):264+(n<<4)<<e-1)}},{key:"linearToAlaw",value:function(t){var e,n,o=t>>8&128;if(o&&(t=-t),t>32635&&(t=32635),t<256)e=0,n=t>>4;else{e=7;for(var r=16384;0===(t&r)&&e>0;e--,r>>=1);n=t>>e+3&15}return 85^(o|e<<4|n)}}])&&Tt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function At(t){return At="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},At(t)}function Dt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function Ft(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(At(t)+" is not iterable")}function Bt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Rt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Rt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Rt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Rt(d,"constructor",u),Rt(u,"constructor",s),s.displayName="GeneratorFunction",Rt(u,r,"GeneratorFunction"),Rt(d),Rt(d,r,"Generator"),Rt(d,o,function(){return this}),Rt(d,"toString",function(){return"[object Generator]"}),(Bt=function(){return{w:i,m:f}})()}function Rt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Rt=function(t,e,n,o){function i(e,n){Rt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Rt(t,e,n,o)}function _t(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Ut(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){_t(i,o,r,a,c,"next",t)}function c(t){_t(i,o,r,a,c,"throw",t)}a(void 0)})}}function Mt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Nt(o.key),o)}}function Nt(t){var e=function(t){if("object"!=At(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=At(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==At(e)?e:e+""}function zt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(zt=function(){return!!t})()}function Lt(t){return Lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Lt(t)}function Vt(t,e){return Vt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Vt(t,e)}var Kt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=Lt(e),function(t,e){if(e&&("object"==At(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,zt()?Reflect.construct(e,n||[],Lt(t).constructor):e.apply(t,n))}(this,e)).config=n,t.audioContext=null,t.audioQueue=[],t.isPlaying=!1,t.isProcessingQueue=!1,t.currentSource=null,t.outputFormat=null,t.nextStartTime=0,t.scheduledBuffers=0,t.scheduledSources=new Set,t.pcmChunkQueue=[],t.preparedBuffer=[],t.isProcessingPcmQueue=!1,t.isSchedulingFrames=!1,t.MAX_LOOKAHEAD_SECONDS=.02,t.codecs={pcm:new xt,pcmu:new Ot,pcma:new jt},t.SUPPORTED_CONTAINERS=["wav","raw"],t.SUPPORTED_ENCODINGS=["pcm","pcmu","pcma"],t.SUPPORTED_SAMPLE_RATES=[8e3,16e3,22050,24e3,44100,48e3],t.SUPPORTED_BIT_DEPTHS=[8,16,24],t.SUPPORTED_CHANNELS=[1],console.log("🎵 AudioPlayer v2 initialized"),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Vt(t,e)}(e,t),n=e,o=[{key:"setOutputFormat",value:function(t){var e;this.validateFormat(t)||(console.warn("⚠️ AudioPlayer: Invalid format, using defaults:",t),t=this.getDefaultFormat());var n=null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate,o=t.sampleRate;this.outputFormat=t,console.log("✅ AudioPlayer v2: Format set:",t),this.audioContext&&n&&n!==o&&(console.warn("⚠️ AudioPlayer: Sample rate changed, recreating AudioContext"),console.warn(" Old: ".concat(n,"Hz → New: ").concat(o,"Hz")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null,console.log("ℹ️ AudioContext will be recreated on next audio chunk with correct sample rate"))}},{key:"validateFormat",value:function(t){var e,n;if(!t)return!1;var o=null===(e=t.container)||void 0===e?void 0:e.toLowerCase(),r=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&r&&this.SUPPORTED_CONTAINERS.includes(o)&&this.SUPPORTED_ENCODINGS.includes(r)&&this.SUPPORTED_SAMPLE_RATES.includes(t.sampleRate)&&this.SUPPORTED_BIT_DEPTHS.includes(t.bitDepth)&&(!t.channels||this.SUPPORTED_CHANNELS.includes(t.channels))}},{key:"getDefaultFormat",value:function(){return{container:"raw",encoding:"pcm",sampleRate:16e3,channels:1,bitDepth:16}}},{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){console.error("❌ AudioPlayer v2: Playback error:",t),this.emit("playbackError",t)}}},{key:"playChunk",value:(c=Ut(Bt().m(function t(e){var n,o,r=this;return Bt().w(function(t){for(;;)switch(t.n){case 0:(n=this.prepareChunk(e))?(this.preparedBuffer.push(n),(this.preparedBuffer.length<=3||this.preparedBuffer.length%10==0)&&console.log("📥 AudioPlayer: Frame received, queued: ".concat(this.preparedBuffer.length,", scheduled: ").concat(this.scheduledBuffers,", isScheduling: ").concat(this.isSchedulingFrames)),this.isSchedulingFrames?setTimeout(function(){r.preparedBuffer.length>0&&!r.isSchedulingFrames&&r.schedulePreparedFrames()},5):this.schedulePreparedFrames(),this.pcmChunkQueue.length>0&&!this.isProcessingPcmQueue&&this.processPcmQueue()):(console.error("❌ AudioPlayer: playChunk failed - prepareChunk returned null"),console.error(" pcmData length:",(null==e?void 0:e.byteLength)||"undefined"),console.error(" outputFormat:",this.outputFormat),console.error(" audioContext:",this.audioContext?"initialized":"not initialized"),console.error(" audioContext state:",(null===(o=this.audioContext)||void 0===o?void 0:o.state)||"N/A"),this.emit("playbackError",new Error("Failed to prepare PCM chunk for playback")));case 1:return t.a(2)}},t,this)})),function(t){return c.apply(this,arguments)})},{key:"prepareChunk",value:function(t){try{var e;if(!this.outputFormat)return console.error("❌ AudioPlayer: Cannot prepare chunk - outputFormat not set"),console.error(" Call setOutputFormat() before playing audio chunks"),null;if(this.audioContext||this.initializeAudioContext(),!this.audioContext)return console.error("❌ AudioPlayer: Cannot prepare chunk - AudioContext not available"),null;var n=t;if(t.byteLength%2!=0){console.warn("⚠️ Odd PCM chunk size, padding:",t.byteLength);var o=new Uint8Array(t.byteLength+1);o.set(new Uint8Array(t),0),o[t.byteLength]=0,n=o.buffer}for(var r=new Int16Array(n),i=new Float32Array(r.length),a=1/32768,c=r.length,s=0;s<c;s++)i[s]=r[s]*a;var u=(null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||this.audioContext.sampleRate,l=this.audioContext.sampleRate,d=this.audioContext.createBuffer(1,i.length,u);d.getChannelData(0).set(i);var f=d.duration,p=i.length,h=f;return l!==u&&(h=p/l),{buffer:d,duration:h,sampleRate:u,contextSampleRate:l}}catch(t){return console.error("❌ AudioPlayer: Error preparing chunk:",t),null}}},{key:"applyFadeOut",value:function(t){return t}},{key:"schedulePreparedFrames",value:(a=Ut(Bt().m(function t(){var e,n,o,r,i,a=this;return Bt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isSchedulingFrames){t.n=1;break}return t.a(2);case 1:if(this.isSchedulingFrames=!0,e=this.preparedBuffer.length,0===(n=Math.min(e,5))&&e>0&&(n=1),t.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:o=0,r=Bt().m(function t(){var e,n,r,i,c;return Bt().w(function(t){for(;;)switch(t.n){case 0:if(e=a.preparedBuffer.shift()){t.n=1;break}return t.a(2,1);case 1:(n=a.audioContext.createBufferSource()).buffer=e.buffer,n.connect(a.audioContext.destination),a.scheduledSources.add(n),r=a.audioContext.currentTime,0===a.scheduledBuffers?(a.nextStartTime<r&&(a.nextStartTime=r+a.MAX_LOOKAHEAD_SECONDS),console.log("🎵 Starting playback with minimal delay:",a.nextStartTime)):(i=r+a.MAX_LOOKAHEAD_SECONDS,a.nextStartTime<i&&(a.nextStartTime=i,console.warn("⚠️ AudioPlayer: Fell behind schedule, adjusting nextStartTime to ".concat(a.nextStartTime.toFixed(4),"s")))),n.start(a.nextStartTime),a.nextStartTime+=e.duration,a.nextStartTime=Math.round(1e6*a.nextStartTime)/1e6,c=a.nextStartTime-e.duration,a.scheduledBuffers<5&&(console.log("🎵 AudioPlayer: Scheduled frame ".concat(a.scheduledBuffers+1," at ").concat(c.toFixed(4),"s, next at ").concat(a.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(e.duration.toFixed(4),"s (").concat((1e3*e.duration).toFixed(2),"ms), Queued: ").concat(a.preparedBuffer.length,", Scheduled: ").concat(a.scheduledBuffers))),a.scheduledBuffers++,o++,n.onended=function(){if(a.scheduledSources.delete(n),a.scheduledBuffers--,0===a.scheduledBuffers&&0===a.preparedBuffer.length&&0===a.pcmChunkQueue.length)a.isPlaying=!1,a.isSchedulingFrames=!1,console.log("🛑 AudioPlayer: Emitting playbackStopped event (all buffers finished)"),a.emit("playbackStopped");else if(a.preparedBuffer.length>0)setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()},0);else if(a.scheduledBuffers>0){var t=function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(t,10)};setTimeout(t,10)}},a.isPlaying||(a.isPlaying=!0,console.log("🎵 AudioPlayer: Emitting playbackStarted event"),a.emit("playbackStarted"));case 2:return t.a(2)}},t)});case 4:if(!(this.preparedBuffer.length>0&&o<n)){t.n=7;break}return t.d(Ft(r()),5);case 5:if(!t.v){t.n=6;break}return t.a(3,7);case 6:t.n=4;break;case 7:this.isSchedulingFrames=!1,this.preparedBuffer.length>0&&requestAnimationFrame(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.schedulePreparedFrames()}),this.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0?a.schedulePreparedFrames():a.scheduledBuffers>0&&setTimeout(function(){a.preparedBuffer.length>0&&!a.isSchedulingFrames&&a.scheduledBuffers>0&&a.schedulePreparedFrames()},10)},10),t.n=9;break;case 8:t.p=8,i=t.v,console.error("❌ AudioPlayer v2: Error scheduling frames:",i),this.emit("playbackError",i),this.isSchedulingFrames=!1;case 9:return t.a(2)}},t,this,[[2,8]])})),function(){return a.apply(this,arguments)})},{key:"processPcmQueue",value:(i=Ut(Bt().m(function t(){var e,n,o,r,i,a,c,s,u,l,d,f,p,h,v,g,y,m,b,S,w=this;return Bt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingPcmQueue){t.n=1;break}return t.a(2);case 1:if(this.isProcessingPcmQueue=!0,t.p=2,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:if(!(this.pcmChunkQueue.length>0)){t.n=5;break}if(o=this.pcmChunkQueue.shift()){t.n=4;break}return t.a(3,3);case 4:for(r=o,o.byteLength%2!=0&&(console.warn("⚠️ Odd PCM chunk size, padding:",o.byteLength),(i=new Uint8Array(o.byteLength+1)).set(new Uint8Array(o),0),i[o.byteLength]=0,r=i.buffer),a=new Int16Array(r),c=new Float32Array(a.length),s=1/32768,u=a.length,l=0;l<u;l++)c[l]=a[l]*s;d=(null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||this.audioContext.sampleRate,f=this.audioContext.sampleRate,null!==(n=this.outputFormat)&&void 0!==n&&n.sampleRate?this.scheduledBuffers<3&&console.log("🎵 AudioPlayer: Creating buffer at ".concat(d,"Hz (AudioContext: ").concat(f,"Hz)")):console.warn("⚠️ AudioPlayer: outputFormat.sampleRate not set! Using AudioContext sample rate:",f),(p=this.audioContext.createBuffer(1,c.length,d)).getChannelData(0).set(c),(h=this.audioContext.createBufferSource()).buffer=p,h.connect(this.audioContext.destination),v=this.audioContext.currentTime,this.nextStartTime<v&&(this.nextStartTime=v,0===this.scheduledBuffers&&console.log("🎵 Starting playback at current time:",v)),g=p.duration,y=c.length,m=g,f!==d&&(m=y/f,this.scheduledBuffers<3&&(console.log("🔄 Resampling detected: ".concat(d,"Hz → ").concat(f,"Hz")),console.log(" Buffer duration: ".concat(g.toFixed(4),"s, Calculated: ").concat(m.toFixed(4),"s")))),h.start(this.nextStartTime),this.nextStartTime+=m,this.nextStartTime=Math.round(1e6*this.nextStartTime)/1e6,this.scheduledBuffers<3&&(b=this.nextStartTime-m,console.log("🎵 AudioPlayer: Scheduled chunk ".concat(this.scheduledBuffers+1," at ").concat(b.toFixed(4),"s, next at ").concat(this.nextStartTime.toFixed(4),"s")),console.log(" Duration: ".concat(m.toFixed(4),"s (").concat((1e3*m).toFixed(2),"ms)"))),this.scheduledBuffers++,h.onended=function(){w.scheduledBuffers--,0===w.scheduledBuffers&&0===w.pcmChunkQueue.length&&(w.isPlaying=!1,w.isProcessingPcmQueue=!1,w.emit("playbackStopped"))},this.isPlaying||(this.isPlaying=!0,this.emit("playbackStarted")),t.n=3;break;case 5:this.isProcessingPcmQueue=!1,t.n=7;break;case 6:t.p=6,S=t.v,console.error("❌ AudioPlayer v2: Error playing chunk:",S),this.emit("playbackError",S),this.isProcessingPcmQueue=!1;case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return i.apply(this,arguments)})},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);console.log("🎵 AudioPlayer: Processing ".concat(e.length," bytes")),console.log("🎵 AudioPlayer: Negotiated format:",this.outputFormat);var n=this.outputFormat&&this.outputFormat.container&&"wav"===this.outputFormat.container.toLowerCase(),o=this.outputFormat&&this.outputFormat.container&&"raw"===this.outputFormat.container.toLowerCase(),r=this.isWavFile(e);if(r&&console.log("🎵 AudioPlayer: Data has WAV header (RIFF)"),o&&r)return console.error("❌ AudioPlayer: CRITICAL MISMATCH!"),console.error(" Negotiated format: RAW"),console.error(" Actual data: WAV (RIFF header detected)"),console.error(" Backend is ignoring format request and sending WAV anyway."),console.warn("⚠️ AudioPlayer: Processing as WAV to avoid playback failure, but UI configuration was bypassed."),this.handleWavFile(e);if(o&&!r)console.log("🎵 AudioPlayer: Processing as RAW data (as negotiated)");else{if(n&&r)return console.log("✅ AudioPlayer: Processing as WAV file (matches negotiation)"),this.handleWavFile(e);if(n&&!r)return console.warn("⚠️ AudioPlayer: Negotiated WAV but data lacks WAV header. Attempting WAV processing anyway."),this.handleWavFile(e);if(!this.outputFormat&&r)return console.log("🎵 AudioPlayer: No format negotiated, auto-detecting WAV"),this.handleWavFile(e);this.outputFormat||r||(console.warn("⚠️ AudioPlayer: No format negotiated and data not WAV, using defaults"),this.outputFormat=this.getDefaultFormat())}return this.outputFormat||(console.warn("⚠️ AudioPlayer: No format set, using defaults"),this.outputFormat=this.getDefaultFormat()),console.log("🎵 AudioPlayer: Processing as RAW data with encoding:",this.outputFormat.encoding),this.handleRawData(e)}},{key:"isWavFile",value:function(t){return t.length>=44&&82===t[0]&&73===t[1]&&70===t[2]&&70===t[3]}},{key:"handleWavFile",value:function(t){var e=this.parseWavHeader(t);if(console.log("🎵 WAV file detected:",{format:e.audioFormat,encoding:this.getEncodingName(e.audioFormat),sampleRate:e.sampleRate,channels:e.channels,bitDepth:e.bitsPerSample}),1===e.audioFormat)return console.log("✅ PCM WAV - using directly"),new Blob([t],{type:"audio/wav"});var n=this.getCodecForWavFormat(e.audioFormat);if(!n)throw new Error("Unsupported WAV format code: ".concat(e.audioFormat));console.log("🔄 Non-PCM WAV - converting to PCM WAV");var o=t.slice(44),r=n.decode(o),i=this.createWavHeader(r.byteLength,e.sampleRate,e.channels,16);return new Blob([i,r],{type:"audio/wav"})}},{key:"handleRawData",value:function(t){var e,n,o=this.outputFormat.encoding.toLowerCase(),r=this.getCodec(o);if(!r)throw new Error("No codec found for encoding: ".concat(o));if(console.log("🎵 AudioPlayer: Decoding ".concat(o.toUpperCase()," to PCM")),console.log("🎵 AudioPlayer: Input format - bitDepth: ".concat(this.outputFormat.bitDepth,", sampleRate: ").concat(this.outputFormat.sampleRate)),"pcm"===o){var i=this.outputFormat.bitDepth||16;t.length,24===i?(console.warn("⚠️ AudioPlayer: Format says 24-bit PCM, but browser support is limited."),console.warn(" Treating as 16-bit PCM. If audio sounds wrong, backend should send 16-bit instead."),e=this.convert24BitTo16Bit(t),n=16):8===i?(console.log("🔄 AudioPlayer: Converting 8-bit PCM to 16-bit PCM"),e=this.convert8BitTo16Bit(t),n=16):(e=t.buffer,n=i,console.log("✅ AudioPlayer: Using native ".concat(i,"-bit PCM (no conversion needed)")))}else e=r.decode(t),n=16,console.log("🔄 AudioPlayer: Decoded ".concat(o.toUpperCase()," to 16-bit PCM"));var a=this.createWavHeader(e.byteLength,this.outputFormat.sampleRate,this.outputFormat.channels,n);return new Blob([a,e],{type:"audio/wav"})}},{key:"convert24BitTo16Bit",value:function(t){for(var e=Math.floor(t.length/3),n=new Int16Array(e),o=0;o<e;o++){var r=t[3*o],i=t[3*o+1],a=t[3*o+2],c=r|i<<8|(255&a)<<16;128&a&&(c|=4278190080),n[o]=Math.max(-32768,Math.min(32767,Math.round(c/256)))}return n.buffer}},{key:"convert8BitTo16Bit",value:function(t){for(var e=t.length,n=new Int16Array(e),o=0;o<e;o++){var r=t[o];n[o]=256*(r-128)}return n.buffer}},{key:"getCodec",value:function(t){var e={pcm:"pcm",linear:"pcm",l16:"pcm",pcmu:"pcmu",ulaw:"pcmu",mulaw:"pcmu",g711u:"pcmu",pcma:"pcma",alaw:"pcma",g711a:"pcma"}[t.toLowerCase()];return this.codecs[e]}},{key:"getCodecForWavFormat",value:function(t){switch(t){case 1:return this.codecs.pcm;case 6:return this.codecs.pcma;case 7:return this.codecs.pcmu;default:return null}}},{key:"getEncodingName",value:function(t){switch(t){case 1:return"PCM";case 6:return"A-law";case 7:return"μ-law";default:return"Unknown (".concat(t,")")}}},{key:"parseWavHeader",value:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{audioFormat:e.getUint16(20,!0),channels:e.getUint16(22,!0),sampleRate:e.getUint32(24,!0),byteRate:e.getUint32(28,!0),blockAlign:e.getUint16(32,!0),bitsPerSample:e.getUint16(34,!0)}}},{key:"createWavHeader",value:function(t,e,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+t,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,e,!0),i.setUint32(28,e*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0),r}},{key:"initializeAudioContext",value:function(){var t,e,n=(null===(t=this.outputFormat)||void 0===t?void 0:t.sampleRate)||48e3;if(48e3!==n&&44100!==n&&(console.log("ℹ️ AudioPlayer: Backend requested ".concat(n,"Hz, but browser may resample to 48kHz")),console.log(" Consider requesting 48kHz from backend to avoid resampling and improve quality")),this.audioContext){var o=this.audioContext.sampleRate;if(!(Math.abs(o-n)>100))return;console.warn("⚠️ AudioPlayer: AudioContext sample rate (".concat(o,"Hz) doesn't match format (").concat(n,"Hz), recreating...")),this.stopImmediate(),"closed"!==this.audioContext.state&&this.audioContext.close(),this.audioContext=null}console.log("🎵 AudioPlayer: Creating AudioContext at ".concat(n,"Hz (from outputFormat: ").concat((null===(e=this.outputFormat)||void 0===e?void 0:e.sampleRate)||"not set",")"));try{this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n,latencyHint:"playback"}),console.log("✅ AudioContext created at ".concat(this.audioContext.sampleRate,"Hz (requested: ").concat(n,"Hz)")),Math.abs(this.audioContext.sampleRate-n)>100?(console.error("❌ CRITICAL: Browser sample rate mismatch!"),console.error(" Requested: ".concat(n,"Hz")),console.error(" Got: ".concat(this.audioContext.sampleRate,"Hz")),console.error(" This WILL cause audio distortion/noise!"),console.error(" Solution: Backend should send ".concat(this.audioContext.sampleRate,"Hz audio instead"))):this.audioContext.sampleRate!==n&&(console.warn("⚠️ Browser adjusted sample rate: ".concat(n,"Hz → ").concat(this.audioContext.sampleRate,"Hz")),console.warn(" Browser will automatically resample audio."))}catch(t){console.error("❌ Failed to create AudioContext:",t),this.audioContext=new(window.AudioContext||window.webkitAudioContext),console.log("ℹ️ Using browser default: ".concat(this.audioContext.sampleRate,"Hz"))}}},{key:"processQueue",value:(r=Ut(Bt().m(function t(){var e,n,o,r,i,a,c,s=this;return Bt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||this.initializeAudioContext(),"suspended"!==this.audioContext.state){t.n=3;break}return t.n=3,this.audioContext.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return o=t.v,t.n=5,this.audioContext.decodeAudioData(o);case 5:r=t.v,i=n&&!this.isPlaying&&null===this.currentSource,(a=this.audioContext.createBufferSource()).buffer=r,a.connect(this.audioContext.destination),this.currentSource=a,this.isPlaying=!0,i&&this.emit("playbackStarted"),a.onended=function(){s.currentSource=null,s.isProcessingQueue=!1,s.audioQueue.length>0?setTimeout(function(){return s.processQueue()},50):setTimeout(function(){0!==s.audioQueue.length||s.currentSource||(s.isPlaying=!1,s.emit("playbackStopped"))},100)},a.start(),t.n=7;break;case 6:t.p=6,c=t.v,console.error("❌ AudioPlayer v2: Error processing queue:",c),this.currentSource=null,this.emit("playbackError",c),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return s.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"reset",value:function(){this.stop(),this.audioQueue=[],this.pcmChunkQueue=[]}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource||this.scheduledSources.size>0;if(console.log("🛑 AudioPlayer.stopImmediate() called"),console.log(" isPlaying:",this.isPlaying),console.log(" currentSource:",null!==this.currentSource),console.log(" scheduledSources.size:",this.scheduledSources.size),console.log(" scheduledBuffers:",this.scheduledBuffers),this.currentSource){try{console.log(" Stopping currentSource..."),this.currentSource.stop()}catch(t){console.log(" currentSource already stopped or error:",t.message)}this.currentSource=null}if(this.scheduledSources.size>0){console.log(" Stopping ".concat(this.scheduledSources.size," scheduled sources..."));var e,n=0,o=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Dt(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Dt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(this.scheduledSources);try{for(o.s();!(e=o.n()).done;){var r=e.value;try{r.stop(),n++}catch(t){console.log(" Source already stopped or not started:",t.message)}}}catch(t){o.e(t)}finally{o.f()}console.log(" Stopped ".concat(n," sources")),this.scheduledSources.clear()}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],this.pcmChunkQueue=[],this.preparedBuffer=[],this.isProcessingPcmQueue=!1,this.isSchedulingFrames=!1,this.nextStartTime=0,this.scheduledBuffers=0,t&&(console.log("🛑 AudioPlayer: Emitting playbackStopped event (stopImmediate called)"),this.emit("playbackStopped"))}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed",outputFormat:this.outputFormat,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&&Mt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c}(mt);const Ht=Kt;function Wt(t){return Wt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Wt(t)}function Gt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return qt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(qt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,qt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,qt(d,"constructor",u),qt(u,"constructor",s),s.displayName="GeneratorFunction",qt(u,r,"GeneratorFunction"),qt(d),qt(d,r,"Generator"),qt(d,o,function(){return this}),qt(d,"toString",function(){return"[object Generator]"}),(Gt=function(){return{w:i,m:f}})()}function qt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}qt=function(t,e,n,o){function i(e,n){qt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},qt(t,e,n,o)}function Qt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Jt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Qt(i,o,r,a,c,"next",t)}function c(t){Qt(i,o,r,a,c,"throw",t)}a(void 0)})}}function Yt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function $t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Xt(o.key),o)}}function Xt(t){var e=function(t){if("object"!=Wt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Wt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Wt(e)?e:e+""}function Zt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Zt=function(){return!!t})()}function te(t){return te=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},te(t)}function ee(t,e){return ee=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ee(t,e)}var ne=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=te(e),function(t,e){if(e&&("object"==Wt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Zt()?Reflect.construct(e,n||[],te(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ee(t,e)}(e,t),n=e,o=[{key:"getAudioProcessorPath",value:function(){if(this.config.audioProcessorPath)return this.config.audioProcessorPath;var t,e=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Yt(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Yt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var r=n.substring(0,n.lastIndexOf("/"));return"".concat(r,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(i=Jt(Gt().m(function t(){var e,n,o,r,i,a,c=this;return Gt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,"https:"===location.protocol||"localhost"===location.hostname||"127.0.0.1"===location.hostname){t.n=1;break}throw e=new Error("Microphone access requires HTTPS. Please use https:// or test on localhost."),console.error("❌ AudioRecorder:",e.message),this.emit("error",e),e;case 1:if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){t.n=2;break}throw n=new Error("getUserMedia is not supported in this browser. Please use a modern browser."),console.error("❌ AudioRecorder:",n.message),this.emit("error",n),n;case 2:return console.log("🎤 AudioRecorder: Requesting microphone access..."),t.n=3,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 3:if(this.mediaStream=t.v,console.log("✅ AudioRecorder: Microphone access granted"),this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=4;break}return t.n=4,this.audioContext.resume();case 4:return o=this.getAudioProcessorPath(),t.n=5,this.audioContext.audioWorklet.addModule(o);case 5:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,n=e.type,o=e.data;"pcm_audio_data"===n&&c.emit("audioData",o)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=7;break;case 6:throw t.p=6,a=t.v,r=a.message,"NotAllowedError"===a.name||"PermissionDeniedError"===a.name?(r="Microphone permission denied. Please allow microphone access in your browser settings and try again.",console.error("❌ AudioRecorder: Permission denied. User needs to grant microphone access.")):"NotFoundError"===a.name||"DevicesNotFoundError"===a.name?(r="No microphone found. Please connect a microphone and try again.",console.error("❌ AudioRecorder: No microphone device found.")):"NotReadableError"===a.name||"TrackStartError"===a.name?(r="Microphone is already in use by another application. Please close other apps using the microphone and try again.",console.error("❌ AudioRecorder: Microphone is busy or not readable.")):a.message&&a.message.includes("not allowed by the user agent")&&(r="Microphone access blocked. On mobile devices, please tap the recording button directly (not from an iframe or popup).",console.error("❌ AudioRecorder: User agent blocked microphone access. This often happens on mobile when not called from direct user interaction.")),(i=new Error(r)).name=a.name,i.originalError=a,console.error("❌ AudioRecorder: Failed to start recording:",i),this.emit("error",i),i;case 7:return t.a(2)}},t,this,[[0,6]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=Jt(Gt().m(function t(){var e;return Gt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&$t(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(mt);function oe(t){return oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},oe(t)}function re(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ie(o.key),o)}}function ie(t){var e=function(t){if("object"!=oe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=oe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==oe(e)?e:e+""}const ae=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"extractPcmFromWav",value:function(t){var e=t instanceof Uint8Array?t:new Uint8Array(t);if(e.length<44)throw new Error("WAV data too short (< 44 bytes)");if("RIFF"!==String.fromCharCode(e[0],e[1],e[2],e[3]))throw new Error("Not a valid WAV file - missing RIFF header");if("WAVE"!==String.fromCharCode(e[8],e[9],e[10],e[11]))throw new Error("Not a valid WAV file - missing WAVE format");for(var n=e[22]|e[23]<<8,o=e[24]|e[25]<<8|e[26]<<16|e[27]<<24,r=e[34]|e[35]<<8,i=-1,a=12;a<e.length-8;a+=4){if("data"===String.fromCharCode(e[a],e[a+1],e[a+2],e[a+3])){i=a;break}a+=4+(e[a+4]|e[a+5]<<8|e[a+6]<<16|e[a+7]<<24)}if(-1===i)throw new Error("No data chunk found in WAV");var c=e[i+4]|e[i+5]<<8|e[i+6]<<16|e[i+7]<<24,s=i+8,u=Math.min(c,e.length-s);return{pcmData:e.slice(s,s+u).buffer,format:{sampleRate:o,channels:n,bitDepth:r}}}},{key:"isWavFile",value:function(t){return t.length>=44&&82===t[0]&&73===t[1]&&70===t[2]&&70===t[3]}},{key:"createWavHeader",value:function(t,e,n,o){var r=new ArrayBuffer(44),i=new DataView(r);return i.setUint32(0,1380533830,!1),i.setUint32(4,36+t,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,n,!0),i.setUint32(24,e,!0),i.setUint32(28,e*n*o/8,!0),i.setUint16(32,n*o/8,!0),i.setUint16(34,o,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0),r}},{key:"wrapPcmInWav",value:function(e,n){var o=t.createWavHeader(e.byteLength,n.sampleRate,n.channels||1,n.bitDepth||16),r=new Uint8Array(o.byteLength+e.byteLength);return r.set(new Uint8Array(o),0),r.set(new Uint8Array(e),o.byteLength),r.buffer}}],null&&re(e.prototype,null),n&&re(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function ce(t){return ce="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ce(t)}function se(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ue(o.key),o)}}function ue(t){var e=function(t){if("object"!=ce(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ce(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ce(e)?e:e+""}const le=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.codecs={pcm:new xt,pcmu:new Ot,pcma:new jt}},(e=[{key:"decodeToPcm",value:function(t,e){var n=null==e?void 0:e.toLowerCase();if(!n||"pcm"===n)return t instanceof ArrayBuffer?t:t instanceof Uint8Array?t.buffer:t;var o=this.codecs[n];if(!o)throw new Error("Unsupported encoding: ".concat(e));var r=t instanceof Uint8Array?t:new Uint8Array(t);return o.decode(r)}},{key:"encodeFromPcm",value:function(t,e){var n=null==e?void 0:e.toLowerCase();if(!n||"pcm"===n)return t;var o=this.codecs[n];if(!o)throw new Error("Unsupported target encoding: ".concat(e));var r=o.encode(t);return r instanceof Uint8Array?r.buffer:r}},{key:"getCodec",value:function(t){var e=null==t?void 0:t.toLowerCase();return this.codecs[e]||null}}])&&se(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function de(t){return de="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},de(t)}function fe(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,pe(o.key),o)}}function pe(t){var e=function(t){if("object"!=de(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=de(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==de(e)?e:e+""}const he=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"convert",value:function(e,n,o){if(n===o)return e;if(8===n)throw new Error("Source bit depth cannot be 8-bit (only 16-bit or 24-bit supported)");var r=n/8,i=o/8,a=e.byteLength/r;if(new ArrayBuffer(a*i),16===n&&16===o)return e;if(24===n&&16===o)return t.convert24To16(e);if(16===n&&24===o)return t.convert16To24(e);if(16===n&&8===o)return t.convert16To8(e);if(24===n&&8===o)return t.convert24To8(e);throw new Error("Unsupported bit depth conversion: ".concat(n,"-bit → ").concat(o,"-bit"))}},{key:"convert24To16",value:function(t){for(var e=new Uint8Array(t),n=Math.floor(e.length/3),o=new Int16Array(n),r=0;r<n;r++){var i=e[3*r],a=e[3*r+1],c=e[3*r+2],s=i|a<<8|(255&c)<<16;128&c&&(s|=4278190080),o[r]=Math.max(-32768,Math.min(32767,Math.round(s/256)))}return o.buffer}},{key:"convert16To24",value:function(t){for(var e=new Int16Array(t),n=new Uint8Array(3*e.length),o=0;o<e.length;o++){var r=256*e[o];n[3*o]=255&r,n[3*o+1]=r>>8&255,n[3*o+2]=r>>16&255}return n.buffer}},{key:"convert16To8",value:function(t){for(var e=new Int16Array(t),n=new Uint8Array(e.length),o=0;o<e.length;o++){var r=e[o];n[o]=Math.max(0,Math.min(255,Math.round(r/256+128)))}return n.buffer}},{key:"convert24To8",value:function(e){var n=t.convert24To16(e);return t.convert16To8(n)}}],null&&fe(e.prototype,null),n&&fe(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function ve(t){return ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ve(t)}function ge(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ye(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ye(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ye(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ye(d,"constructor",u),ye(u,"constructor",s),s.displayName="GeneratorFunction",ye(u,r,"GeneratorFunction"),ye(d),ye(d,r,"Generator"),ye(d,o,function(){return this}),ye(d,"toString",function(){return"[object Generator]"}),(ge=function(){return{w:i,m:f}})()}function ye(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ye=function(t,e,n,o){function i(e,n){ye(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ye(t,e,n,o)}function me(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function be(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Se(o.key),o)}}function Se(t){var e=function(t){if("object"!=ve(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=ve(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ve(e)?e:e+""}const we=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"resample",value:(n=ge().m(function t(e,n,o){var r,i,a,c,s,u,l,d,f,p,h,v,g;return ge().w(function(t){for(;;)switch(t.n){case 0:if(n!==o){t.n=1;break}return t.a(2,e);case 1:for(r=new Int16Array(e),i=new Float32Array(r.length),a=1/32768,c=0;c<r.length;c++)i[c]=r[c]*a;return s=Math.ceil(i.length*o/n),u=new OfflineAudioContext(1,s,o),(l=u.createBuffer(1,i.length,n)).getChannelData(0).set(i),(d=u.createBufferSource()).buffer=l,d.connect(u.destination),d.start(),t.n=2,u.startRendering();case 2:for(f=t.v,p=f.getChannelData(0),h=new Int16Array(p.length),v=0;v<p.length;v++)g=Math.max(-1,Math.min(1,p[v])),h[v]=Math.round(32767*g);return t.a(2,h.buffer)}},t)}),o=function(){var t=this,e=arguments;return new Promise(function(o,r){var i=n.apply(t,e);function a(t){me(i,o,r,a,c,"next",t)}function c(t){me(i,o,r,a,c,"throw",t)}a(void 0)})},function(t,e,n){return o.apply(this,arguments)})}],e&&be(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function xe(t){return xe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},xe(t)}function ke(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Ce(o.key),o)}}function Ce(t){var e=function(t){if("object"!=xe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=xe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==xe(e)?e:e+""}const Pe=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=[{key:"convert",value:function(e,n,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(n===o)return e;if(1===n&&1===o)return e;if(1===n&&2===o)return t.monoToStereo(e,r);if(2===n&&1===o)return t.stereoToMono(e,r);throw new Error("Unsupported channel conversion: ".concat(n," → ").concat(o))}},{key:"monoToStereo",value:function(t,e){for(var n=e/8,o=t.byteLength/n,r=new ArrayBuffer(o*n*2),i=new Uint8Array(t),a=new Uint8Array(r),c=0;c<o;c++)for(var s=c*n,u=c*n*2,l=0;l<n;l++)a[u+l]=i[s+l],a[u+n+l]=i[s+l];return r}},{key:"stereoToMono",value:function(t,e){var n=e/8,o=t.byteLength/(2*n),r=new ArrayBuffer(o*n),i=new Uint8Array(t),a=new Uint8Array(r);if(16===e)for(var c=0;c<o;c++){var s=c*n*2,u=s+n,l=(i[s]|i[s+1]<<8)<<16>>16,d=(i[u]|i[u+1]<<8)<<16>>16,f=Math.round((l+d)/2),p=c*n;a[p]=255&f,a[p+1]=f>>8&255}else for(var h=0;h<o;h++)for(var v=h*n*2,g=h*n,y=0;y<n;y++)a[g+y]=i[v+y];return r}}],null&&ke(e.prototype,null),n&&ke(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();function Oe(t){return Oe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Oe(t)}function Ee(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Te(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Te(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Te(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Te(d,"constructor",u),Te(u,"constructor",s),s.displayName="GeneratorFunction",Te(u,r,"GeneratorFunction"),Te(d),Te(d,r,"Generator"),Te(d,o,function(){return this}),Te(d,"toString",function(){return"[object Generator]"}),(Ee=function(){return{w:i,m:f}})()}function Te(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Te=function(t,e,n,o){function i(e,n){Te(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Te(t,e,n,o)}function Ie(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function je(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ie(Object(n),!0).forEach(function(e){Ae(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ie(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ae(t,e,n){return(e=Be(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function De(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Fe(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Be(o.key),o)}}function Be(t){var e=function(t){if("object"!=Oe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Oe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Oe(e)?e:e+""}const Re=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.requestedFormat=e,this.actualFormat=n,this.encodingConverter=new le,this.conversionSteps=[],this._analyzeConversions()},e=[{key:"_analyzeConversions",value:function(){this.conversionSteps=[],this.actualFormat.container!==this.requestedFormat.container&&("wav"===this.actualFormat.container?this.conversionSteps.push("extract_wav"):"wav"===this.requestedFormat.container&&this.conversionSteps.push("wrap_wav")),this.actualFormat.encoding!==this.requestedFormat.encoding&&("pcm"!==this.actualFormat.encoding&&this.conversionSteps.push("decode_encoding"),"pcm"!==this.requestedFormat.encoding&&this.conversionSteps.push("encode_encoding")),this.actualFormat.sampleRate!==this.requestedFormat.sampleRate&&this.conversionSteps.push("resample"),this.actualFormat.bitDepth!==this.requestedFormat.bitDepth&&this.conversionSteps.push("convert_bitdepth"),this.actualFormat.channels!==this.requestedFormat.channels&&this.conversionSteps.push("convert_channels")}},{key:"needsConversion",value:function(){return this.conversionSteps.length>0}},{key:"getConversionSteps",value:function(){var t=[];return this.conversionSteps.includes("extract_wav")&&t.push("Extract PCM from WAV (".concat(this.actualFormat.container," → raw)")),this.conversionSteps.includes("decode_encoding")&&t.push("Decode ".concat(this.actualFormat.encoding.toUpperCase()," → PCM")),this.conversionSteps.includes("resample")&&t.push("Resample ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz")),this.conversionSteps.includes("convert_bitdepth")&&t.push("Convert bit depth ".concat(this.actualFormat.bitDepth,"-bit → ").concat(this.requestedFormat.bitDepth,"-bit")),this.conversionSteps.includes("convert_channels")&&t.push("Convert channels ".concat(this.actualFormat.channels," → ").concat(this.requestedFormat.channels)),this.conversionSteps.includes("encode_encoding")&&t.push("Encode PCM → ".concat(this.requestedFormat.encoding.toUpperCase())),this.conversionSteps.includes("wrap_wav")&&t.push("Wrap in WAV container (raw → ".concat(this.requestedFormat.container,")")),t}},{key:"convert",value:(n=Ee().m(function t(e){var n,o,r,i;return Ee().w(function(t){for(;;)switch(t.n){case 0:if(this.needsConversion()){t.n=1;break}return t.a(2,e instanceof ArrayBuffer?e:e.buffer);case 1:if(n=e instanceof ArrayBuffer?e:e.buffer,o=je({},this.actualFormat),this.conversionSteps.includes("extract_wav")&&(r=ae.extractPcmFromWav(n),n=r.pcmData,o=je(je({},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=he.convert(n,24,16),o.bitDepth=16,console.log("🔄 AudioFormatConverter: Normalized 24-bit → 16-bit PCM")),!this.conversionSteps.includes("resample")){t.n=3;break}return t.n=2,we.resample(n,o.sampleRate,this.requestedFormat.sampleRate);case 2:n=t.v,o.sampleRate=this.requestedFormat.sampleRate,console.log("🔄 AudioFormatConverter: Resampled ".concat(this.actualFormat.sampleRate,"Hz → ").concat(this.requestedFormat.sampleRate,"Hz"));case 3:return this.conversionSteps.includes("convert_channels")&&(n=Pe.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=he.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=ae.wrapPcmInWav(n,o),o.container="wav",console.log("🔄 AudioFormatConverter: Wrapped in WAV container")),console.log("✅ AudioFormatConverter: Conversion complete"),t.a(2,n)}},t,this)}),o=function(){var t=this,e=arguments;return new Promise(function(o,r){var i=n.apply(t,e);function a(t){De(i,o,r,a,c,"next",t)}function c(t){De(i,o,r,a,c,"throw",t)}a(void 0)})},function(t){return o.apply(this,arguments)})}],e&&Fe(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function _e(t){return _e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_e(t)}function Ue(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Me(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ue(Object(n),!0).forEach(function(e){qe(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ue(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ne(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ze(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ze(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ze(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ze(d,"constructor",u),ze(u,"constructor",s),s.displayName="GeneratorFunction",ze(u,r,"GeneratorFunction"),ze(d),ze(d,r,"Generator"),ze(d,o,function(){return this}),ze(d,"toString",function(){return"[object Generator]"}),(Ne=function(){return{w:i,m:f}})()}function ze(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ze=function(t,e,n,o){function i(e,n){ze(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ze(t,e,n,o)}function Le(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Ve(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Le(i,o,r,a,c,"next",t)}function c(t){Le(i,o,r,a,c,"throw",t)}a(void 0)})}}function Ke(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Qe(o.key),o)}}function He(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(He=function(){return!!t})()}function We(t){return We=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},We(t)}function Ge(t,e){return Ge=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ge(t,e)}function qe(t,e,n){return(e=Qe(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Qe(t){var e=function(t){if("object"!=_e(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=_e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==_e(e)?e:e+""}var Je=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=We(e),function(t,e){if(e&&("object"==_e(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,He()?Reflect.construct(e,n||[],We(t).constructor):e.apply(t,n))}(this,e)).version="2.0.0",t.config={websocketUrl:n.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:n.agentId,appId:n.appId,sampleRate:n.sampleRate||16e3,channels:n.channels||1,bitDepth:n.bitDepth||16,audioProcessorPath:n.audioProcessorPath,outputContainer:n.outputContainer||t.getDefaultContainer(n),outputEncoding:n.outputEncoding||n.outputCodec||"pcm",outputSampleRate:n.outputSampleRate||16e3,outputChannels:n.outputChannels||1,outputBitDepth:n.outputBitDepth||16,outputFrameDurationMs:n.outputFrameDurationMs||600,outputCodec:n.outputCodec,agentSettingsOverride:n.agentSettingsOverride||null,variables:n.variables||null,autoReconnect:!1!==n.autoReconnect,protocolVersion:n.protocolVersion||2},t.isConnected=!1,t.hasEverConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.outputAudioFormat=null,t.requestedOutputFormat=null,t.formatConverter=null,t.websocket=null,t.conversationId=null,t.transcriptQueue=[],t.currentPlayingSentenceId=null,t.audioFrameCount=0,t.audioPlayer=new Ht(t.config),t.audioRecorder=new ne(t.config),t.setupAudioPlayerEvents(),t.setupAudioRecorderEvents(),t.validateConfig(),console.log("🎵 VoiceSDK v2 initialized:",{version:t.version,outputContainer:t.config.outputContainer,outputEncoding:t.config.outputEncoding,outputSampleRate:t.config.outputSampleRate}),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Ge(t,e)}(e,t),n=e,o=[{key:"getDefaultContainer",value:function(t){return"wav"===t.outputCodec?"wav":"raw"}},{key:"validateInputFormat",value:function(t){var n;if(!t)return"Input format is required";var o=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();return o&&e.SUPPORTED_INPUT_ENCODINGS.includes(o)?t.sampleRate&&e.SUPPORTED_INPUT_SAMPLE_RATES.includes(t.sampleRate)?t.bitDepth&&e.SUPPORTED_INPUT_BIT_DEPTHS.includes(t.bitDepth)?t.channels&&e.SUPPORTED_INPUT_CHANNELS.includes(t.channels)?null:"Unsupported input channels: ".concat(t.channels,". Supported: ").concat(e.SUPPORTED_INPUT_CHANNELS.join(", ")):"Unsupported input bit depth: ".concat(t.bitDepth,". Supported: ").concat(e.SUPPORTED_INPUT_BIT_DEPTHS.join(", ")):"Unsupported input sample rate: ".concat(t.sampleRate,". Supported: ").concat(e.SUPPORTED_INPUT_SAMPLE_RATES.join(", ")):"Unsupported input encoding: ".concat(t.encoding,". Supported: ").concat(e.SUPPORTED_INPUT_ENCODINGS.join(", "))}},{key:"validateOutputFormat",value:function(t){var n,o;if(!t)return"Output format is required";var r=null===(n=t.encoding)||void 0===n?void 0:n.toLowerCase();if(!r||!e.SUPPORTED_OUTPUT_ENCODINGS.includes(r))return"Unsupported output encoding: ".concat(t.encoding,". Supported: ").concat(e.SUPPORTED_OUTPUT_ENCODINGS.join(", "));if(!t.sampleRate||!e.SUPPORTED_OUTPUT_SAMPLE_RATES.includes(t.sampleRate))return"Unsupported output sample rate: ".concat(t.sampleRate,". Supported: ").concat(e.SUPPORTED_OUTPUT_SAMPLE_RATES.join(", "));if(!t.bitDepth||!e.SUPPORTED_OUTPUT_BIT_DEPTHS.includes(t.bitDepth))return"Unsupported output bit depth: ".concat(t.bitDepth,". Supported: ").concat(e.SUPPORTED_OUTPUT_BIT_DEPTHS.join(", "));if(!t.channels||!e.SUPPORTED_OUTPUT_CHANNELS.includes(t.channels))return"Unsupported output channels: ".concat(t.channels,". Supported: ").concat(e.SUPPORTED_OUTPUT_CHANNELS.join(", "));var i=null===(o=t.container)||void 0===o?void 0:o.toLowerCase();return i&&e.SUPPORTED_OUTPUT_CONTAINERS.includes(i)?null:"Unsupported output container: ".concat(t.container,". Supported: ").concat(e.SUPPORTED_OUTPUT_CONTAINERS.join(", "))}},{key:"validateConfig",value:function(){var t={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},e=this.validateInputFormat(t);if(e)return console.error("❌ VoiceSDK v2: Invalid input format:",e),void this.emit("error",new Error(e));var n={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},o=this.validateOutputFormat(n);if(o)return console.error("❌ VoiceSDK v2: Invalid output format:",o),void this.emit("error",new Error(o));console.log("✅ VoiceSDK v2: Format validation passed")}},{key:"setupAudioPlayerEvents",value:function(){var t=this;this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_started_playing message to server"),t.sendMessage({t:"audio_started_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_started_playing - not connected")}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected?(console.log("📤 VoiceSDK v2: Sending audio_stopped_playing message to server"),t.sendMessage({t:"audio_stopped_playing"})):console.warn("⚠️ VoiceSDK v2: Cannot send audio_stopped_playing - not connected")}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e),t.emit("error",e)})}},{key:"setupAudioRecorderEvents",value:function(){var t=this;this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0;var e=t.audioPlayer.getStatus(),n=e.scheduledBuffers&&e.scheduledBuffers>0||e.scheduledSourcesCount&&e.scheduledSourcesCount>0,o=t.isPlaying||e.isPlaying||n;console.log("🎤 VoiceSDK v2: Recording started - checking for barge-in..."),console.log(" VoiceSDK.isPlaying:",t.isPlaying),console.log(" AudioPlayer.isPlaying:",e.isPlaying),console.log(" scheduledBuffers:",e.scheduledBuffers||0),console.log(" scheduledSourcesCount:",e.scheduledSourcesCount||0),console.log(" preparedBufferLength:",e.preparedBufferLength||0),console.log(" isActuallyPlaying:",o),o?(console.log("🛑 VoiceSDK v2: Barge-in detected! Stopping audio playback..."),t.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),t.isConnected?(t.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")):console.warn("⚠️ VoiceSDK v2: Cannot send barge_in - not connected")):console.log("ℹ️ VoiceSDK v2: No audio playing, normal recording start"),console.log("🎤 [VOICE SDK] About to emit recordingStarted event"),t.emit("recordingStarted"),console.log("🎤 [VOICE SDK] ✅ recordingStarted event emitted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t._bargeInChecked=!1,t.emit("recordingStopped"),console.log("🛑 VoiceSDK v2: Recording stopped")}),this.audioRecorder.on("audioData",function(e){if(!t._bargeInChecked&&t.isRecording){t._bargeInChecked=!0;var n=t.audioPlayer.getStatus(),o=n.scheduledBuffers&&n.scheduledBuffers>0||n.scheduledSourcesCount&&n.scheduledSourcesCount>0;(t.isPlaying||n.isPlaying||o)&&(console.log("🛑 VoiceSDK v2: Barge-in detected on first audio data! Stopping audio playback..."),console.log(" VoiceSDK.isPlaying:",t.isPlaying),console.log(" AudioPlayer.isPlaying:",n.isPlaying),console.log(" scheduledBuffers:",n.scheduledBuffers||0),console.log(" scheduledSourcesCount:",n.scheduledSourcesCount||0),t.stopAudioPlayback(),console.log("✅ VoiceSDK v2: Audio playback stopped"),t.isConnected&&(t.sendMessage({t:"barge_in"}),console.log("📤 VoiceSDK v2: Sent barge_in message to server")))}t.isConnected&&t.sendBinary(e)}),this.audioRecorder.on("error",function(e){console.error("❌ AudioRecorder error:",e),t.emit("error",e)})}},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),e.toString()){var n=t.includes("?")?"&":"?";return"".concat(t).concat(n).concat(e.toString())}return t}},{key:"connect",value:(u=Ve(Ne().m(function t(){var e,n,o=this;return Ne().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK v2: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:if(!this.isConnected){t.n=2;break}return console.warn("VoiceSDK v2: Already connected"),t.a(2,!0);case 2:return t.p=2,e=this.buildWebSocketUrl(),console.log("🔌 VoiceSDK v2: Connecting to",e),t.n=3,new Promise(function(t,n){o.websocket=new WebSocket(e),o.websocket.onopen=function(){console.log("✅ VoiceSDK v2: WebSocket connected"),o.isConnected=!0,o.hasEverConnected=!0,o.sendHelloMessage(),o.emit("connected"),t(!0)},o.websocket.onerror=function(t){console.error("❌ VoiceSDK v2: WebSocket error:",t),n(t)},o.websocket.onclose=function(t){console.log("🔌 VoiceSDK v2: WebSocket closed:",t.code,t.reason),o.isConnected=!1,o.isRecording&&o.stopRecording().catch(function(t){return console.error("Error stopping recording:",t)}),o.emit("disconnected",t),o.config.autoReconnect&&!o.isDestroyed&&o.hasEverConnected?(console.log("🔄 VoiceSDK v2: Auto-reconnecting in 3s..."),setTimeout(function(){o.isDestroyed||o.isConnected||o.connect()},3e3)):o.config.autoReconnect&&!o.hasEverConnected&&console.log("⚠️ VoiceSDK v2: Initial connection failed. Auto-reconnect disabled to prevent retry loop.")},o.websocket.onmessage=function(t){o.handleMessage(t)}});case 3:return t.a(2,t.v);case 4:return t.p=4,n=t.v,console.error("🔌 VoiceSDK v2: Connection failed:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[2,4]])})),function(){return u.apply(this,arguments)})},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={encoding:"pcm",sampleRate:this.config.sampleRate,channels:this.config.channels,bitDepth:this.config.bitDepth},e={encoding:this.config.outputEncoding,sampleRate:this.config.outputSampleRate,channels:this.config.outputChannels,bitDepth:this.config.outputBitDepth,container:this.config.outputContainer},n=this.validateInputFormat(t);if(n)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid input format:",n),void this.emit("error",new Error("Invalid input format: ".concat(n)));var o=this.validateOutputFormat(e);if(o)return console.error("❌ VoiceSDK v2: Cannot send hello - invalid output format:",o),void this.emit("error",new Error("Invalid output format: ".concat(o)));var r={t:"hello",v:this.config.protocolVersion,inputFormat:t,requestedOutputFormat:e,outputFrameDurationMs:this.config.outputFrameDurationMs};this.config.agentSettingsOverride&&(r.agentSettingsOverride=this.config.agentSettingsOverride),console.log("🔍 VoiceSDK v2: Checking variables:",{hasVariables:!!this.config.variables,variables:this.config.variables,keys:this.config.variables?Object.keys(this.config.variables):[]}),this.config.variables&&Object.keys(this.config.variables).length>0?(r.variables=this.config.variables,console.log("📝 VoiceSDK v2: Including variables in hello:",Object.keys(this.config.variables))):console.log("⚠️ VoiceSDK v2: Variables NOT included - condition failed"),console.log("📤 VoiceSDK v2: Sending hello:",{version:r.v,requestedFormat:r.requestedOutputFormat,variables:r.variables?Object.keys(r.variables):void 0}),console.log("📤 VoiceSDK v2: Requested output format:",{container:r.requestedOutputFormat.container,encoding:r.requestedOutputFormat.encoding,sampleRate:r.requestedOutputFormat.sampleRate,bitDepth:r.requestedOutputFormat.bitDepth}),console.log("📤 VoiceSDK v2: Full hello message being sent:",JSON.stringify(r,null,2));try{this.sendMessage(r)}catch(t){console.error("VoiceSDK v2: Failed to send hello:",t),this.emit("error",t)}}else console.warn("VoiceSDK v2: Cannot send hello - not connected")}},{key:"handleMessage",value:function(t){if(t.data instanceof ArrayBuffer||t.data instanceof Blob)this.handleBinaryMessage(t.data);else try{var e=JSON.parse(t.data);switch(console.log("📥 VoiceSDK v2: Received message:",e.t),!this.conversationId&&e.conversationId&&(this.conversationId=e.conversationId,console.log("🔍 VoiceSDK v2: Captured conversationId from message:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),e.t){case"hello_ack":this.handleHelloAck(e);break;case"transcript":this.handleTranscript(e);break;case"user_transcript":case"agent_response":case"error":this.emit("message",e);break;case"barge_in":this.emit("bargeIn",e),this.stopAudioPlayback();break;case"stop_playing":this.emit("stopPlaying",e),this.stopAudioPlayback();break;default:console.log("VoiceSDK v2: Unknown message type:",e.t),this.emit("message",e)}}catch(t){console.error("VoiceSDK v2: Error parsing message:",t)}}},{key:"handleHelloAck",value:function(t){if(console.log("📥 VoiceSDK v2: Received hello_ack:",{hasOutputFormat:!!t.outputAudioFormat,outputFormat:t.outputAudioFormat,hasConversationId:!!t.conversationId,messageType:t.t}),t.conversationId&&(this.conversationId=t.conversationId,console.log("🔍 VoiceSDK v2: Received conversationId:",this.conversationId),this.emit("conversationIdChanged",this.conversationId)),t.outputAudioFormat){this.outputAudioFormat=t.outputAudioFormat,this.audioPlayer.setOutputFormat(t.outputAudioFormat),console.log("✅ VoiceSDK v2: Format negotiated by server:",this.outputAudioFormat),this.requestedOutputFormat={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1};var e={container:this.outputAudioFormat.container||"unknown",encoding:this.outputAudioFormat.encoding||"unknown",sampleRate:this.outputAudioFormat.sampleRate||0,bitDepth:this.outputAudioFormat.bitDepth||0,channels:this.outputAudioFormat.channels||0},n=[];if(this.requestedOutputFormat.container!==e.container&&n.push('container: "'.concat(this.requestedOutputFormat.container,'" → "').concat(e.container,'"')),this.requestedOutputFormat.encoding!==e.encoding&&n.push('encoding: "'.concat(this.requestedOutputFormat.encoding,'" → "').concat(e.encoding,'"')),this.requestedOutputFormat.sampleRate!==e.sampleRate&&n.push("sampleRate: ".concat(this.requestedOutputFormat.sampleRate,"Hz → ").concat(e.sampleRate,"Hz")),this.requestedOutputFormat.bitDepth!==e.bitDepth&&n.push("bitDepth: ".concat(this.requestedOutputFormat.bitDepth,"-bit → ").concat(e.bitDepth,"-bit")),this.requestedOutputFormat.channels!==e.channels&&n.push("channels: ".concat(this.requestedOutputFormat.channels," → ").concat(e.channels)),n.length>0){console.warn("⚠️ VoiceSDK v2: Format negotiation mismatch!"),console.warn(" Requested:",this.requestedOutputFormat),console.warn(" Negotiated:",e),console.warn(" Differences:",n.join(", "));try{if(this.formatConverter=new Re(this.requestedOutputFormat,e),this.formatConverter.needsConversion()){var o=this.formatConverter.getConversionSteps();console.log("🔄 VoiceSDK v2: Format conversion enabled"),console.log(" Conversion steps:",o.join(", ")),console.log(" Audio will be automatically converted to requested format")}}catch(t){console.error("❌ VoiceSDK v2: Failed to create format converter:",t),console.warn(" Will use backend format without conversion"),this.formatConverter=null}}else console.log("✅ VoiceSDK v2: Format perfectly matched!",e),this.formatConverter=null;this.emit("formatNegotiated",this.outputAudioFormat)}else{this.config.protocolVersion>=2?(console.warn("⚠️ VoiceSDK v2: hello_ack received but no outputAudioFormat in response."),console.warn(" This may happen if:"),console.warn(" 1. Backend is not sending outputAudioFormat (check backend logs)"),console.warn(" 2. Hello message missing v2 fields (v, inputFormat, requestedOutputFormat)"),console.warn(" 3. Backend validation failed (check backend error logs)"),console.warn(" Using default format from config...")):console.log("✅ VoiceSDK v2: Connected (v1 legacy mode)");var r={container:this.config.outputContainer||"wav",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,channels:this.config.outputChannels||1,bitDepth:this.config.outputBitDepth||16};this.outputAudioFormat=r,this.requestedOutputFormat=r,this.audioPlayer.setOutputFormat(r),this.formatConverter=null}}},{key:"handleTranscript",value:function(t){if(t.sentenceId&&t.text){var e=t.sentenceId,n={text:t.text,role:t.role||"assistant",sentenceId:e,final:!1!==t.final,timestamp:t.timestamp||Date.now()};this.transcriptQueue.push(n),console.log("📝 VoiceSDK v2: Received transcript for sentence",e,":",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",e),this.emit("transcriptDisplay",n),this.currentPlayingSentenceId=e,this.emit("transcript",n)}else console.warn("⚠️ VoiceSDK v2: Invalid transcript message:",t)}},{key:"handleBinaryMessage",value:(s=Ve(Ne().m(function t(e){var n,o,r,i,a,c,s,u,l,d;return Ne().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!(e instanceof Blob)){t.n=2;break}return t.n=1,e.arrayBuffer();case 1:o=t.v,t.n=3;break;case 2:o=e;case 3:if(console.log("📥 VoiceSDK v2: Received audio:",o.byteLength,"bytes"),console.log(" Current outputFormat:",this.outputAudioFormat),console.log(" AudioPlayer outputFormat:",null===(n=this.audioPlayer)||void 0===n?void 0:n.outputFormat),console.log(" Format converter:",this.formatConverter?"active":"none"),r=o,!this.formatConverter||!this.formatConverter.needsConversion()){t.n=7;break}return t.p=4,t.n=5,this.formatConverter.convert(o);case 5:r=t.v,console.log("✅ VoiceSDK v2: Audio converted to requested format"),t.n=7;break;case 6:t.p=6,d=t.v,console.error("❌ VoiceSDK v2: Format conversion failed:",d),console.warn(" Using backend format without conversion"),r=o;case 7:i=this.formatConverter&&this.formatConverter.needsConversion()?this.requestedOutputFormat:this.outputAudioFormat||{container:this.config.outputContainer||"raw",encoding:this.config.outputEncoding||"pcm",sampleRate:this.config.outputSampleRate||16e3,bitDepth:this.config.outputBitDepth||16,channels:this.config.outputChannels||1},a=i.container||"raw",c=(i.encoding||"pcm").toLowerCase(),"raw"===a?(s=r,"pcm"!==c&&((u=this.audioPlayer.getCodec(c))?(l=u.decode(new Uint8Array(r)),s=l.buffer,console.log("🔄 VoiceSDK v2: Decoded ".concat(c.toUpperCase()," to PCM (").concat(l.byteLength," bytes)"))):console.warn("⚠️ VoiceSDK v2: No codec for ".concat(c,", treating as PCM"))),this.audioPlayer.outputFormat||(console.warn("⚠️ VoiceSDK v2: outputFormat not set on AudioPlayer, setting from playbackFormat"),this.audioPlayer.setOutputFormat(i)),this.audioFrameCount++,this.audioPlayer.playChunk(s)):(this.audioFrameCount++,this.audioPlayer.playAudio(r));case 8:return t.a(2)}},t,this,[[4,6]])})),function(t){return s.apply(this,arguments)})},{key:"sendMessage",value:function(t){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send message - not connected"),!1;try{return this.websocket.send(JSON.stringify(t)),!0}catch(t){return console.error("VoiceSDK v2: Error sending message:",t),this.emit("error",t),!1}}},{key:"sendBinary",value:function(t){if(!this.websocket||this.websocket.readyState!==WebSocket.OPEN)return console.warn("VoiceSDK v2: Cannot send audio - not connected"),!1;try{return this.websocket.send(t),!0}catch(t){return console.error("VoiceSDK v2: Error sending audio:",t),this.emit("error",t),!1}}},{key:"disconnect",value:function(){this.isDestroyed||(console.log("🔌 VoiceSDK v2: Disconnecting..."),this.stopRecording(),this.audioPlayer&&this.stopAudioPlayback(),this.websocket&&(this.websocket.close(),this.websocket=null),this.isConnected=!1)}},{key:"startRecording",value:(c=Ve(Ne().m(function t(){var e,n;return Ne().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw e=new Error("Not connected to voice server"),this.emit("error",e),e;case 1:if(!this.isRecording){t.n=2;break}return console.warn("VoiceSDK v2: Already recording"),t.a(2,!0);case 2:return console.log("🎤 VoiceSDK v2: Starting recording..."),t.p=3,console.log("🎤 VoiceSDK v2: Requesting microphone permission (mobile-friendly)..."),t.n=4,this.audioRecorder.start();case 4:return this.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId()}),t.a(2,!0);case 5:return t.p=5,n=t.v,console.error("❌ VoiceSDK v2: Failed to start recording:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[3,5]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=Ve(Ne().m(function t(){var e;return Ne().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return console.warn("VoiceSDK v2: Not recording"),t.a(2,!0);case 1:return console.log("🛑 VoiceSDK v2: Stopping recording..."),t.p=2,this.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=3,this.audioRecorder.stop();case 3:return this.stopAudioPlayback(),t.a(2,!0);case 4:return t.p=4,e=t.v,console.error("VoiceSDK v2: Error stopping recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[2,4]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=Ve(Ne().m(function t(){return Ne().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"clearTranscriptState",value:function(){this.currentPlayingSentenceId=null,console.log("📝 VoiceSDK v2: Cleared transcript state")}},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate(),this.clearTranscriptState()}},{key:"handleBargeIn",value:(r=Ve(Ne().m(function t(){return Ne().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{version:this.version,isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying,outputFormat:this.outputAudioFormat,conversationId:this.conversationId,audioPlayer:this.audioPlayer.getStatus(),audioRecorder:this.audioRecorder.getStatus()}}},{key:"updateConfig",value:function(t){this.config=Me(Me({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"destroy",value:function(){this.isDestroyed||(console.log("🗑️ VoiceSDK v2: Destroying..."),this.disconnect(),this.isDestroyed=!0,this.audioPlayer&&this.audioPlayer.destroy(),this.audioRecorder&&this.audioRecorder.destroy(),this.removeAllListeners())}}],o&&Ke(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(mt);qe(Je,"SUPPORTED_INPUT_ENCODINGS",["pcm","pcmu","pcma"]),qe(Je,"SUPPORTED_INPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),qe(Je,"SUPPORTED_INPUT_BIT_DEPTHS",[8,16,24]),qe(Je,"SUPPORTED_INPUT_CHANNELS",[1]),qe(Je,"SUPPORTED_OUTPUT_ENCODINGS",["pcm","pcmu","pcma"]),qe(Je,"SUPPORTED_OUTPUT_SAMPLE_RATES",[8e3,16e3,22050,24e3,44100,48e3]),qe(Je,"SUPPORTED_OUTPUT_BIT_DEPTHS",[8,16,24]),qe(Je,"SUPPORTED_OUTPUT_CHANNELS",[1]),qe(Je,"SUPPORTED_OUTPUT_CONTAINERS",["raw","wav"]);const Ye=Je;function $e(t){return $e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},$e(t)}function Xe(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ze(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ze(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Ze(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ze(d,"constructor",u),Ze(u,"constructor",s),s.displayName="GeneratorFunction",Ze(u,r,"GeneratorFunction"),Ze(d),Ze(d,r,"Generator"),Ze(d,o,function(){return this}),Ze(d,"toString",function(){return"[object Generator]"}),(Xe=function(){return{w:i,m:f}})()}function Ze(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Ze=function(t,e,n,o){function i(e,n){Ze(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Ze(t,e,n,o)}function tn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function en(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function nn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?en(Object(n),!0).forEach(function(e){on(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):en(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function on(t,e,n){return(e=an(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function rn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,an(o.key),o)}}function an(t){var e=function(t){if("object"!=$e(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=$e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==$e(e)?e:e+""}function cn(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(cn=function(){return!!t})()}function sn(t){return sn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},sn(t)}function un(t,e){return un=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},un(t,e)}var ln=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=(t=function(t,e,n){return e=sn(e),function(t,e){if(e&&("object"==$e(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,cn()?Reflect.construct(e,n||[],sn(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=nn({baseWsUrl:"wss://backend.talktopc.com/chat/websocket",appId:n.appId||o.appId,agentId:n.agentId||o.agentId,conversationId:void 0!==n.conversationId?n.conversationId:t.getPersistedConversationId(),forceConversationId:n.forceConversationId,queue:[],inFlight:!1},n),t.fullResponseBuffer="",t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&un(t,e)}(e,t),n=e,o=[{key:"readScriptTagConfig",value:function(){try{var t=Array.from(document.getElementsByTagName("script")).reverse().find(function(t){return t.dataset&&(t.dataset.appId||t.dataset.agentId)||t.src&&t.src.includes("agent-widget")});return t?{appId:t.dataset.appId,agentId:t.dataset.agentId}:{}}catch(t){return{}}}},{key:"buildWebSocketUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,e=new URLSearchParams;return this.config.appId&&e.append("appId",this.config.appId),this.config.agentId&&e.append("agentId",this.config.agentId),this.config.conversationId&&e.append("conversationId",this.config.conversationId),"".concat(t,"?").concat(e.toString())}},{key:"sendMessage",value:(r=Xe().m(function t(e){var n=this;return Xe().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,o){if(e&&e.trim())if(n.config.appId&&n.config.agentId){var r={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(r):n.executeTask(r)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){tn(i,n,o,a,c,"next",t)}function c(t){tn(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"executeTask",value:function(t){var e=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,r=this.buildWebSocketUrl(this.config.baseWsUrl),i=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(i),c=!1,s=!1,u=null,l=function(n){if(!s)try{var o={message:t.text},r=e.config.forceConversationId||e.config.conversationId;r&&(o.conversationId=r,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=r,e.persistConversationId(r))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",e.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){t.reject(o),e.emit("error",o);try{n.close()}catch(t){}}},d=function(t){return function(){e.config.conversationId?l(t):u=setTimeout(function(){return l(t)},200)}},f=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(t){}var r=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",r)}catch(t){}if("hello"===r.type&&r.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId),e.emit&&e.emit("conversationIdChanged",r.conversationId),!s&&n&&1===n.readyState){if(u)try{clearTimeout(u)}catch(t){}l(n)}return}if(!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId)),"chunk"===r.type&&"string"==typeof r.content)e.fullResponseBuffer+=r.content,e.emit("chunk",r.content);else if("done"===r.type){try{var i=r.text||r.content||r.answer||r.message||"";i&&!e.fullResponseBuffer&&(e.fullResponseBuffer=i)}catch(t){}!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",r.conversationId),e.config.conversationId=r.conversationId),e.persistConversationId(e.config.conversationId),e.emit("done",{text:e.fullResponseBuffer}),t.resolve({conversationId:e.config.conversationId,fullText:e.fullResponseBuffer});try{n.close()}catch(t){}}else if("error"===r.type){var a=new Error(r.message||"Server error");e.emit("error",a),t.reject(a);try{n.close()}catch(t){}}}catch(t){}}},p=function(n){if(1008===n.code&&n.reason&&(n.reason.includes("Domain not whitelisted")||n.reason.includes("domain")||n.reason.includes("whitelist"))){var o=new Error("DOMAIN_NOT_WHITELISTED");return o.reason=n.reason,o.code=n.code,e.emit("domainError",o),t.reject(o),e.config.inFlight=!1,void e.drainQueue()}e.config.inFlight=!1,e.drainQueue()},h=new WebSocket(r);h.onopen=d(h),h.onmessage=f(h),h.onerror=(o=h,function(n){if(!c){c=!0;try{o.close()}catch(t){}var r=new WebSocket(a);return r.onopen=d(r),r.onmessage=f(r),r.onerror=function(n){e.emit("error",n),t.reject(n)},void(r.onclose=p)}e.emit("error",n),t.reject(n)}),h.onclose=p}},{key:"drainQueue",value:function(){if(0!==this.config.queue.length&&!this.config.inFlight){var t=this.config.queue.shift();this.executeTask(t)}}},{key:"persistConversationId",value:function(t){try{t&&localStorage.setItem("ttp_text_chat_conversation_id",t)}catch(t){}}},{key:"getPersistedConversationId",value:function(){try{return localStorage.getItem("ttp_text_chat_conversation_id")||null}catch(t){return null}}},{key:"updateConfig",value:function(t){this.config=nn(nn({},this.config),t)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&rn(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c),dn=n(540),fn=n(848);function pn(t){return pn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},pn(t)}function hn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function vn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?hn(Object(n),!0).forEach(function(e){gn(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):hn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function gn(t,e,n){return(e=function(t){var e=function(t){if("object"!=pn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=pn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==pn(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function yn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return mn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(mn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,mn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,mn(d,"constructor",u),mn(u,"constructor",s),s.displayName="GeneratorFunction",mn(u,r,"GeneratorFunction"),mn(d),mn(d,r,"Generator"),mn(d,o,function(){return this}),mn(d,"toString",function(){return"[object Generator]"}),(yn=function(){return{w:i,m:f}})()}function mn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}mn=function(t,e,n,o){function i(e,n){mn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},mn(t,e,n,o)}function bn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Sn(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return wn(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?wn(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function wn(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}const xn=function(t){var e=t.websocketUrl,n=t.agentId,o=t.appId,r=t.voice,i=void 0===r?"default":r,a=t.language,c=void 0===a?"en":a,s=t.autoReconnect,u=void 0===s||s,l=t.agentSettingsOverride,d=void 0===l?null:l,f=t.onConnected,p=t.onDisconnected,h=t.onRecordingStarted,v=t.onRecordingStopped,g=t.onPlaybackStarted,y=t.onPlaybackStopped,m=t.onError,b=t.onMessage,S=t.onBargeIn,w=t.onStopPlaying,x=t.className,k=void 0===x?"":x,C=t.style,P=void 0===C?{}:C,O=t.children,E=Sn((0,dn.useState)(!1),2),T=E[0],I=E[1],j=Sn((0,dn.useState)(!1),2),A=j[0],D=j[1],F=Sn((0,dn.useState)(!1),2),B=(F[0],F[1]),R=Sn((0,dn.useState)("Disconnected"),2),_=(R[0],R[1]),U=(0,dn.useRef)(null);(0,dn.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),U.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),U.current.destroy(),U.current=null);var t=new pt({websocketUrl:e,agentId:n,appId:o,voice:i,language:c,autoReconnect:u,agentSettingsOverride:d});return t.on("connected",function(){I(!0),_("Connected"),null==f||f()}),t.on("disconnected",function(){I(!1),_("Disconnected"),null==p||p()}),t.on("recordingStarted",function(){D(!0),null==h||h()}),t.on("recordingStopped",function(){D(!1),null==v||v()}),t.on("playbackStarted",function(){B(!0),null==g||g()}),t.on("playbackStopped",function(){B(!1),null==y||y()}),t.on("error",function(t){null==m||m(t)}),t.on("message",function(t){null==b||b(t)}),t.on("bargeIn",function(t){null==S||S(t)}),t.on("stopPlaying",function(t){null==w||w(t)}),U.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),U.current&&(U.current.destroy(),U.current=null)}},[e,n,o,i,c,d]);var M=function(){var t,e=(t=yn().m(function t(){var e;return yn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(U.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,U.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){bn(i,o,r,a,c,"next",t)}function c(t){bn(i,o,r,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),N=(0,fn.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,fn.jsx)("div",{style:{fontSize:"20px"},children:A?"🔴":"🎤"}),(0,fn.jsx)("div",{children:A?"Stop Listening":"Start Listening"})]});return(0,fn.jsx)("button",{className:"voice-button ".concat(A?"recording":""," ").concat(k),style:vn({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:A?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},P),onClick:M,disabled:!T,children:O||N})};function kn(t){return kn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},kn(t)}function Cn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Pn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Pn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Pn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Pn(d,"constructor",u),Pn(u,"constructor",s),s.displayName="GeneratorFunction",Pn(u,r,"GeneratorFunction"),Pn(d),Pn(d,r,"Generator"),Pn(d,o,function(){return this}),Pn(d,"toString",function(){return"[object Generator]"}),(Cn=function(){return{w:i,m:f}})()}function Pn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Pn=function(t,e,n,o){function i(e,n){Pn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Pn(t,e,n,o)}function On(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function En(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){On(i,o,r,a,c,"next",t)}function c(t){On(i,o,r,a,c,"throw",t)}a(void 0)})}}function Tn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function In(t,e,n){return(e=An(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function jn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,An(o.key),o)}}function An(t){var e=function(t){if("object"!=kn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=kn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==kn(e)?e:e+""}var Dn=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Tn(Object(n),!0).forEach(function(e){In(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({websocketUrl:e.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:e.agentId,voice:e.voice||"default",language:e.language||"en",container:e.container||document.body,buttonText:e.buttonText||"Start Listening",buttonClass:e.buttonClass||"voice-button"},e),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new pt({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},e=[{key:"setupEventListeners",value:function(){var t=this;this.voiceSDK.on("connected",function(){var e,n;t.isConnected=!0,t.updateButton(),null===(e=(n=t.options).onConnected)||void 0===e||e.call(n)}),this.voiceSDK.on("disconnected",function(){var e,n;t.isConnected=!1,t.updateButton(),null===(e=(n=t.options).onDisconnected)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStarted",function(){var e,n;t.isRecording=!0,t.updateButton(),null===(e=(n=t.options).onRecordingStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStopped",function(){var e,n;t.isRecording=!1,t.updateButton(),null===(e=(n=t.options).onRecordingStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStarted",function(){var e,n;t.isPlaying=!0,null===(e=(n=t.options).onPlaybackStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStopped",function(){var e,n;t.isPlaying=!1,null===(e=(n=t.options).onPlaybackStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("error",function(e){var n,o;null===(n=(o=t.options).onError)||void 0===n||n.call(o,e)}),this.voiceSDK.on("message",function(e){var n,o;null===(n=(o=t.options).onMessage)||void 0===n||n.call(o,e)}),this.voiceSDK.on("bargeIn",function(e){var n,o;null===(n=(o=t.options).onBargeIn)||void 0===n||n.call(o,e)}),this.voiceSDK.on("stopPlaying",function(e){var n,o;null===(n=(o=t.options).onStopPlaying)||void 0===n||n.call(o,e)})}},{key:"createButton",value:function(){var t=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return t.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var t=this.isRecording?"🔴":"🎤",e=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(t,"</span>\n <span>").concat(e,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=En(Cn().m(function t(){var e;return Cn().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.voiceSDK.connect();case 1:t.n=3;break;case 2:t.p=2,e=t.v,console.error("Failed to connect:",e);case 3:return t.a(2)}},t,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=En(Cn().m(function t(){var e;return Cn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.voiceSDK){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,this.voiceSDK.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.voiceSDK.updateConfig(t)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],e&&jn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Fn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Bn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Bn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Bn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Bn(d,"constructor",u),Bn(u,"constructor",s),s.displayName="GeneratorFunction",Bn(u,r,"GeneratorFunction"),Bn(d),Bn(d,r,"Generator"),Bn(d,o,function(){return this}),Bn(d,"toString",function(){return"[object Generator]"}),(Fn=function(){return{w:i,m:f}})()}function Bn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Bn=function(t,e,n,o){function i(e,n){Bn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Bn(t,e,n,o)}function Rn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function _n(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Rn(i,o,r,a,c,"next",t)}function c(t){Rn(i,o,r,a,c,"throw",t)}a(void 0)})}}function Un(t){return Un="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Un(t)}function Mn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Nn(o.key),o)}}function Nn(t){var e=function(t){if("object"!=Un(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Un(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Un(e)?e:e+""}var zn=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),console.log("🚀 AgentSDK v2.1.8 initialized with config:",e),this.config=e,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(t){return console.error("SDK Error:",t)},this.onTranscript=function(t){},this.onAgentSpeaking=function(t){},console.log("🎤 [AGENT SDK] Constructor - config.onConversationStart:",Un(e.onConversationStart),e.onConversationStart),console.log("🎤 [AGENT SDK] Constructor - config.onConversationEnd:",Un(e.onConversationEnd),e.onConversationEnd),this.onConversationStart=e.onConversationStart||function(){console.warn("🎤 [AGENT SDK] ⚠️ Using default empty onConversationStart")},this.onConversationEnd=e.onConversationEnd||function(){console.warn("🎤 [AGENT SDK] ⚠️ Using default empty onConversationEnd")},this.onBargeIn=e.onBargeIn||function(){},this.onAudioStartPlaying=e.onAudioStartPlaying||function(){},this.onAudioStoppedPlaying=e.onAudioStoppedPlaying||function(){},this.onSubtitleDisplay=e.onSubtitleDisplay||function(){},console.log("🎤 [AGENT SDK] Constructor - this.onConversationStart:",Un(this.onConversationStart),this.onConversationStart),console.log("🎤 [AGENT SDK] Constructor - this.onConversationEnd:",Un(this.onConversationEnd),this.onConversationEnd)},e=[{key:"connect",value:(o=_n(Fn().m(function t(e){var n,o=this;return Fn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,e){t.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new Ye({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en",protocolVersion:2,outputContainer:this.config.outputContainer||"raw",outputEncoding:this.config.outputEncoding||"pcm",outputSampleRate:this.config.outputSampleRate||44100,outputChannels:this.config.outputChannels||1,outputBitDepth:this.config.outputBitDepth||16}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(t){if(o.isConnected=!1,t&&1008===t.code&&t.reason&&(t.reason.includes("Domain not whitelisted")||t.reason.includes("domain")||t.reason.includes("whitelist"))){var e=new Error("DOMAIN_NOT_WHITELISTED");e.reason=t.reason,e.code=t.code,o.onError(e)}o.isListening&&o.onConversationEnd(),o.onDisconnected()}),this.voiceSDK.on("domainError",function(t){o.onError(t)}),this.voiceSDK.on("error",function(t){o.onError(t)}),this.voiceSDK.on("message",function(t){o.handleWebSocketMessage(t)}),console.log("🎤 [AGENT SDK] Setting up recordingStarted event listener"),console.log("🎤 [AGENT SDK] onConversationStart hook type:",Un(this.onConversationStart)),console.log("🎤 [AGENT SDK] onConversationStart hook value:",this.onConversationStart),this.voiceSDK.on("recordingStarted",function(){if(console.log("🎤 [AGENT SDK] ✅✅✅ recordingStarted event received! ✅✅✅"),o.isListening=!0,console.log("🎤 [AGENT SDK] recordingStarted event fired, calling onConversationStart hook"),console.log("🎤 [AGENT SDK] onConversationStart type:",Un(o.onConversationStart)),o.onConversationStart&&"function"==typeof o.onConversationStart)try{o.onConversationStart(),console.log("🎤 [AGENT SDK] ✅ onConversationStart hook called successfully")}catch(t){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationStart:",t)}else console.warn("🎤 [AGENT SDK] ⚠️ onConversationStart is not a function:",o.onConversationStart)}),this.voiceSDK.on("recordingStopped",function(){if(o.isListening=!1,console.log("🎤 [AGENT SDK] recordingStopped event fired, calling onConversationEnd hook"),console.log("🎤 [AGENT SDK] onConversationEnd type:",Un(o.onConversationEnd)),o.onConversationEnd&&"function"==typeof o.onConversationEnd)try{o.onConversationEnd(),console.log("🎤 [AGENT SDK] ✅ onConversationEnd hook called successfully")}catch(t){console.error("🎤 [AGENT SDK] ❌ Error calling onConversationEnd:",t)}else console.warn("🎤 [AGENT SDK] ⚠️ onConversationEnd is not a function:",o.onConversationEnd)}),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(t){o.onBargeIn(t)}),this.voiceSDK.on("transcriptDisplay",function(t){t&&t.text&&o.onTranscript(t.text),o.onSubtitleDisplay(t)}),t.n=2,this.voiceSDK.connect();case 2:t.n=4;break;case 3:throw t.p=3,n=t.v,this.onError(n),n;case 4:return t.a(2)}},t,this,[[0,3]])})),function(t){return o.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(t){switch(t.t||t.type){case"connected":case"hello_ack":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text||t.transcript);break;case"agent_response":case"barge_in":case"stop_playing":default:break;case"error":this.onError(new Error(t.message||t.error||"Unknown error"))}}},{key:"startListening",value:(n=_n(Fn().m(function t(){var e;return Fn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){t.n=5;break}return t.p=1,console.log("🎤 AgentSDK: Starting recording..."),t.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),t.n=4;break;case 3:throw t.p=3,e=t.v,console.error("❌ AgentSDK: Failed to start recording:",e),e;case 4:t.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(t){this.voiceSDK&&this.isConnected&&this.voiceSDK.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],e&&Mn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Ln(t){return Ln="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Ln(t)}function Vn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Kn(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Kn(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Kn(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Kn(d,"constructor",u),Kn(u,"constructor",s),s.displayName="GeneratorFunction",Kn(u,r,"GeneratorFunction"),Kn(d),Kn(d,r,"Generator"),Kn(d,o,function(){return this}),Kn(d,"toString",function(){return"[object Generator]"}),(Vn=function(){return{w:i,m:f}})()}function Kn(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Kn=function(t,e,n,o){function i(e,n){Kn(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Kn(t,e,n,o)}function Hn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Wn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Hn(i,o,r,a,c,"next",t)}function c(t){Hn(i,o,r,a,c,"throw",t)}a(void 0)})}}function Gn(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,qn(o.key),o)}}function qn(t){var e=function(t){if("object"!=Ln(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Ln(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Ln(e)?e:e+""}var Qn=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.audioStream=null,this.callStartTime=null,this.callTimerInterval=null,this.sdk=null,this.isActive=!1,this.sdk=new zn({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,variables:e.variables||{},language:e.language||"en",outputContainer:e.outputContainer,outputEncoding:e.outputEncoding,outputSampleRate:e.outputSampleRate,outputChannels:e.outputChannels,outputBitDepth:e.outputBitDepth,onConversationStart:e.onConversationStart,onConversationEnd:e.onConversationEnd,onBargeIn:e.onBargeIn,onAudioStartPlaying:e.onAudioStartPlaying,onAudioStoppedPlaying:e.onAudioStoppedPlaying,onSubtitleDisplay:e.onSubtitleDisplay}),this.setupSDKEventHandlers()},e=[{key:"setupSDKEventHandlers",value:function(){var t=this;this.sdk.onTranscript=function(e){t.updateTranscript(e)},this.sdk.onAgentSpeaking=function(t){var e=document.getElementById("voiceAvatarActive");e&&(t?e.classList.add("speaking"):e.classList.remove("speaking"))},this.sdk.onDisconnected=function(){console.log("🔌 WebSocket disconnected, hanging up call..."),t.isActive&&(t.isActive=!1,t.endVoiceCall())},this.sdk.onError=function(e){console.error("❌ Voice SDK Error:",e),e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))?t.showDomainError():t.showError(e.message||e)}}},{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"getTooltip",value:function(t){var e,n=null===(e=this.config.tooltips)||void 0===e?void 0:e[t];return null!=n?n:{mute:this.t("mute"),speaker:this.t("speaker"),endCall:this.t("endCall")}[t]||""}},{key:"generateHTML",value:function(){return'<div class="voice-interface" id="voiceInterface">\n \x3c!-- Before Call State --\x3e\n <div id="voiceIdleState">\n <div class="voice-avatar" id="voiceAvatar">🤖</div>\n <div class="voice-status">\n <div class="voice-status-title">'.concat(this.t("clickToStartCall"),'</div>\n <div class="voice-status-subtitle">').concat(this.t("realTimeVoice"),'</div>\n </div>\n <button class="start-call-btn" id="startCallBtn">\n <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">\n <path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56-.35-.12-.74-.03-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"/>\n </svg>\n <span>').concat(this.t("startCall"),'</span>\n </button>\n </div>\n \x3c!-- During Call State --\x3e\n <div id="voiceActiveState" style="display: none;">\n <div class="voice-avatar-active" id="voiceAvatarActive">\n <div class="voice-rings">\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n </div>\n 🤖\n </div>\n <div class="voice-status">\n <div class="voice-status-title" id="voiceStatusTitleActive">').concat(this.t("listening"),'</div>\n <div class="voice-status-subtitle" id="voiceStatusSubtitleActive">').concat(this.t("speakFreely"),'</div>\n </div>\n <div class="voice-transcript">\n <div class="transcript-label">').concat(this.t("liveTranscript"),'</div>\n <div class="transcript-text empty" id="transcriptText">\n ').concat(this.t("transcriptWillAppear"),'\n </div>\n </div>\n <div class="voice-controls">\n <button class="voice-control-btn secondary" id="muteBtn" title="').concat(this.getTooltip("mute"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="mute-icon">\n <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>\n <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>\n <line x1="12" y1="19" x2="12" y2="23"/>\n <line x1="8" y1="23" x2="16" y2="23"/>\n <line x1="2" y1="2" x2="22" y2="22" class="mute-cross" style="display: none; stroke: #ef4444; stroke-width: 3.5;"/>\n </svg>\n </button>\n <button class="voice-control-btn primary active" id="endCallBtn" title="').concat(this.getTooltip("endCall"),'">\n <svg width="56" height="56" viewBox="0 0 24 24" fill="#ef4444">\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n </svg>\n <div class="voice-timer" id="voiceTimer">00:00</div>\n </button>\n <button class="voice-control-btn secondary" id="speakerBtn" title="').concat(this.getTooltip("speaker"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">\n <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/>\n <path d="M19.07 4.93a10 10 0 0 1 0 14.14"/>\n <path d="M15.54 8.46a5 5 0 0 1 0 7.07"/>\n </svg>\n </button>\n </div>\n </div>\n </div>')}},{key:"generateCSS",value:function(){var t=this.config.avatarBackgroundColor||"#667eea",e=this.config.avatarActiveBackgroundColor||this.config.avatarBackgroundColor||"#667eea",n=this.config.statusTitleColor||"#1e293b",o=this.config.statusSubtitleColor||"#64748b",r=this.config.startCallButtonColor||"#667eea",i=this.config.startCallButtonTextColor||"#FFFFFF",a=this.config.transcriptBackgroundColor||"#FFFFFF",c=this.config.transcriptTextColor||"#1e293b",s=this.config.transcriptLabelColor||"#94a3b8",u=this.config.controlButtonColor||"#FFFFFF",l=this.config.controlButtonSecondaryColor||"#64748b";return this.config.endCallButtonColor,'\n /* Voice Interface Styles - Ultra-compact for Wix iframes */\n .voice-interface { \n display: none; \n flex: 1; \n flex-direction: column;\n align-items: center; \n justify-content: center; \n padding: 6px 10px 6px 10px; \n background: linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%);\n overflow: hidden;\n min-height: 0;\n height: 100%;\n width: 100%;\n box-sizing: border-box;\n }\n .voice-interface.active { display: flex; }\n \n /* Voice States - Better scaling gaps */\n #voiceIdleState,\n #voiceActiveState {\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n height: 100%;\n min-height: 0;\n justify-content: center;\n overflow: hidden;\n flex: 1;\n box-sizing: border-box;\n gap: clamp(6px, 1.5vh, 12px);\n }\n \n #voiceActiveState[style*="display: none"] {\n display: none !important;\n }\n \n /* Voice Avatar - Scales better from small to large */\n .voice-avatar,\n .voice-avatar-active {\n width: clamp(80px, 18vh, 160px);\n height: clamp(80px, 18vh, 160px);\n aspect-ratio: 1;\n border-radius: 50%;\n background: linear-gradient(135deg, '.concat(t," 0%, ").concat(e," 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: clamp(40px, 9vh, 80px);\n margin: 0;\n box-shadow: 0 8px 30px rgba(102, 126, 234, 0.3);\n transition: all 0.3s ease;\n flex-shrink: 1;\n position: relative;\n }\n \n .voice-avatar-active {\n animation: avatarPulse 2s ease-in-out infinite;\n }\n \n @keyframes avatarPulse {\n 0%, 100% { \n transform: scale(1);\n }\n 50% { \n transform: scale(1.05);\n }\n }\n \n .voice-avatar-active.speaking {\n animation: avatarSpeak 0.5s ease-in-out infinite;\n }\n \n @keyframes avatarSpeak {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.08); }\n }\n \n /* Voice Rings Animation */\n .voice-rings {\n position: absolute;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n }\n \n .voice-ring {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n border: 2px solid rgba(102, 126, 234, 0.3);\n border-radius: 50%;\n opacity: 0;\n animation: ringExpand 2s ease-out infinite;\n }\n \n .voice-ring:nth-child(2) { animation-delay: 0.5s; }\n .voice-ring:nth-child(3) { animation-delay: 1s; }\n \n @keyframes ringExpand {\n 0% {\n width: 100%;\n height: 100%;\n opacity: 0.6;\n }\n 100% {\n width: 160%;\n height: 160%;\n opacity: 0;\n }\n }\n \n /* Voice Status - Scales with container */\n .voice-status {\n text-align: center;\n margin: 0;\n flex-shrink: 1;\n min-height: 0;\n }\n \n .voice-status-title {\n font-size: clamp(12px, 3vh, 20px);\n font-weight: 600;\n color: ").concat(n,";\n margin-bottom: clamp(2px, 0.5vh, 4px);\n line-height: 1.2;\n }\n \n .voice-status-subtitle {\n font-size: clamp(10px, 2vh, 14px);\n color: ").concat(o,";\n line-height: 1.2;\n }\n \n /* Start Call Button - Scales with container */\n .start-call-btn {\n margin: 0;\n width: min(280px, 70vw);\n height: clamp(48px, 8vh, 64px);\n border-radius: clamp(24px, 4vh, 32px);\n border: none;\n background: ").concat(r,";\n color: ").concat(i,";\n font-size: clamp(14px, 2.5vh, 18px);\n font-weight: 600;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: clamp(8px, 1.5vh, 12px);\n box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);\n transition: all 0.3s ease;\n flex-shrink: 0;\n }\n \n .start-call-btn svg {\n width: clamp(22px, 4vh, 32px);\n height: clamp(22px, 4vh, 32px);\n }\n \n .start-call-btn:hover {\n transform: translateY(-2px);\n box-shadow: 0 12px 28px rgba(102, 126, 234, 0.5);\n }\n \n .start-call-btn:active {\n transform: translateY(-1px);\n }\n \n /* Voice Transcript - Scales with container */\n .voice-transcript {\n background: ").concat(a,";\n padding: clamp(6px, 1.5vh, 12px);\n border-radius: 10px;\n width: min(360px, calc(100% - 40px));\n margin: 0;\n min-height: clamp(45px, 10vh, 80px);\n max-height: clamp(70px, 16vh, 110px);\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n flex-shrink: 1;\n overflow-y: auto;\n overflow-x: hidden;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n \n .transcript-label {\n font-size: clamp(8px, 1.4vh, 11px);\n color: ").concat(s,";\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.3px;\n margin-bottom: clamp(3px, 0.6vh, 6px);\n flex-shrink: 0;\n word-wrap: break-word;\n }\n \n .transcript-text {\n font-size: clamp(11px, 2vh, 15px);\n color: ").concat(c,";\n line-height: 1.4;\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n word-wrap: break-word;\n overflow-wrap: break-word;\n }\n \n .transcript-text.empty {\n color: #cbd5e1;\n font-style: italic;\n }\n \n /* Voice Controls - Scales with container */\n .voice-controls {\n display: flex;\n gap: clamp(8px, 1.8vh, 14px);\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n margin: 0;\n padding-top: clamp(5px, 1.2vh, 10px);\n }\n \n .voice-control-btn {\n width: clamp(48px, 9vh, 72px);\n height: clamp(48px, 9vh, 72px);\n aspect-ratio: 1;\n border-radius: 50%;\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n position: relative;\n flex-shrink: 0;\n }\n \n .voice-control-btn svg {\n width: 48%;\n height: 48%;\n }\n \n .voice-control-btn.primary {\n width: clamp(54px, 10vh, 80px);\n height: clamp(54px, 10vh, 80px);\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n box-shadow: 0 6px 18px rgba(102, 126, 234, 0.4);\n }\n \n .voice-control-btn.primary:hover {\n transform: scale(1.05);\n }\n \n .voice-control-btn.primary.active {\n background: white;\n animation: recordingPulse 1.5s ease-in-out infinite;\n }\n \n @keyframes recordingPulse {\n 0%, 100% { \n box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);\n }\n 50% { \n box-shadow: 0 6px 24px rgba(239, 68, 68, 0.7);\n }\n }\n \n .voice-control-btn.secondary {\n background: ").concat(u,";\n color: ").concat(l,";\n box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);\n }\n \n .voice-control-btn.secondary:hover {\n background: #f8fafc;\n transform: scale(1.05);\n }\n \n .voice-control-btn.secondary.muted {\n background: #f3f4f6;\n }\n \n .voice-control-btn.secondary.muted .mute-icon {\n stroke: #9ca3af !important;\n }\n \n .voice-timer {\n position: absolute;\n bottom: clamp(-18px, -3vh, -24px);\n font-size: clamp(9px, 1.6vh, 12px);\n color: #64748b;\n font-weight: 500;\n white-space: nowrap;\n }\n \n /* Mobile optimization */\n @media (max-width: 768px) {\n .voice-interface {\n padding: 6px 10px;\n }\n }\n \n @media (max-width: 480px) {\n .voice-interface {\n padding: 5px 8px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(t){var e=this,n=document.getElementById("startCallBtn"),o=document.getElementById("endCallBtn"),r=document.getElementById("muteBtn"),i=document.getElementById("speakerBtn");n&&(n.onclick=function(){return e.startVoiceCall()}),o&&(o.onclick=function(){return e.endVoiceCall()}),r&&(r.onclick=function(){return e.toggleMute()}),i&&(i.onclick=function(){return e.toggleSpeaker()});var a=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=document.getElementById("voiceInterface");n&&n.classList.contains("active")&&n.clientHeight>100?(console.log("✅ Interface is active and has proper dimensions, adjusting sizes (attempt",t+1,")"),e.adjustSizesForContainer(),0===t&&setTimeout(function(){return e.adjustSizesForContainer()},500)):t<15?(console.log("⏳ Interface not ready yet (height:",null==n?void 0:n.clientHeight,"), retrying... (attempt",t+1,")"),setTimeout(function(){return a(t+1)},250)):(console.warn("⚠️ Interface never became fully ready, adjusting sizes anyway"),e.adjustSizesForContainer())};setTimeout(function(){return a()},200),window.addEventListener("resize",function(){console.log("🔄 Window resized, re-adjusting sizes"),e.adjustSizesForContainer()})}},{key:"getSignedUrl",value:(o=Wn(Vn().m(function t(){var e,n,o,r,i,a,c;return Vn().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"adjustSizesForContainer",value:function(){var t=document.getElementById("voiceInterface");if(t){var e=t.clientHeight,n=t.clientWidth;console.log("📏 Container size:",e,"x",n);var o,r,i,a,c,s,u,l,d,f=document.getElementById("voiceIdleState"),p=document.getElementById("voiceActiveState"),h=f&&"none"!==f.style.display,v=p&&"none"!==p.style.display;console.log("👁️ Visible state - Idle:",h,"Active:",v),e<=350?(d=5,o=70,r=35,i=11,a=9,c=32,s=45,u=42,l=48):e<=450?(d=7,o=110,r=55,i=15,a=11,c=38,s=58,u=52,l=58):e<=550?(d=8,o=140,r=70,i=16,a=12,c=42,s=68,u=56,l=64):e<=700?(d=10,o=130,r=65,i=18,a=13,c=46,s=85,u=60,l=70):(d=12,o=150,r=75,i=20,a=14,c=50,s=100,u=66,l=76),document.querySelectorAll("#voiceIdleState, #voiceActiveState").forEach(function(t){t.style.gap="".concat(d,"px")});var g=document.querySelectorAll(".voice-avatar, .voice-avatar-active");console.log("🤖 Found",g.length,"avatars, setting size to",o,"px"),g.forEach(function(t){t.style.width="".concat(o,"px"),t.style.height="".concat(o,"px"),t.style.fontSize="".concat(r,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(t){return t.style.fontSize="".concat(i,"px")}),document.querySelectorAll(".voice-status-subtitle").forEach(function(t){return t.style.fontSize="".concat(a,"px")});var y=document.querySelector(".voice-transcript");y&&(y.style.minHeight="".concat(s,"px"),y.style.maxHeight="".concat(s,"px"),y.style.height="".concat(s,"px"),y.style.width="min(360px, ".concat(n-40,"px)"),y.style.boxSizing="border-box");var m=document.querySelector(".transcript-label");m&&(m.style.fontSize="".concat(Math.max(8,i-4),"px"));var b=document.querySelector(".transcript-text");b&&(b.style.fontSize="".concat(Math.max(10,i-2),"px")),document.querySelectorAll(".voice-control-btn.secondary").forEach(function(t){t.style.width="".concat(u,"px"),t.style.height="".concat(u,"px");var e=t.querySelector("svg");if(e){var n=.65*u;e.style.setProperty("width","".concat(n,"px"),"important"),e.style.setProperty("height","".concat(n,"px"),"important"),e.style.setProperty("min-width","".concat(n,"px"),"important"),e.style.setProperty("min-height","".concat(n,"px"),"important")}});var S=document.querySelector(".voice-control-btn.primary");if(S){S.style.width="".concat(l,"px"),S.style.height="".concat(l,"px");var w=S.querySelector("svg");if(w){var x=.7*l;w.style.setProperty("width","".concat(x,"px"),"important"),w.style.setProperty("height","".concat(x,"px"),"important"),w.style.setProperty("min-width","".concat(x,"px"),"important"),w.style.setProperty("min-height","".concat(x,"px"),"important")}}var k=document.querySelector(".start-call-btn");if(k){var C,P;e<=350?(C=48,P=14):e<=450?(C=52,P=15):e<=550?(C=58,P=17):e<=700?(C=62,P=18):(C=64,P=18),k.style.height="".concat(C,"px"),k.style.fontSize="".concat(P,"px");var O=k.querySelector("svg");if(O){var E=Math.max(22,.5*C);O.style.width="".concat(E,"px"),O.style.height="".concat(E,"px")}}console.log("✅ Sizes adjusted - Avatar:",o,"Status:",c,"Transcript:",s,"Buttons:",u)}else console.warn("⚠️ voiceInterface not found, skipping size adjustment")}},{key:"startVoiceCall",value:(n=Wn(Vn().m(function t(){var e,n,o,r,i,a,c,s,u,l=this;return Vn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isActive){t.n=1;break}return console.log("⚠️ Voice call already active"),t.a(2);case 1:return console.log("🎤 Starting voice call..."),t.p=2,e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState"),o=document.getElementById("voiceInterface"),e&&(e.style.display="none"),n&&(n.style.display="flex"),setTimeout(function(){return l.adjustSizesForContainer()},50),o&&(o.scrollTop=0),t.n=3,this.getSignedUrl();case 3:return r=t.v,console.log("🔗 Got signed URL:",r),t.n=4,this.sdk.connect(r);case 4:i=t.v,console.log("✅ Connected to WebSocket, connected:",i),a=0;case 5:if(this.sdk.isConnected||!(a<50)){t.n=7;break}return t.n=6,new Promise(function(t){return setTimeout(t,100)});case 6:a++,t.n=5;break;case 7:if(!this.sdk.isConnected){t.n=9;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=8,this.sdk.startListening();case 8:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-l.callStartTime,e=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(e.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3),t.n=11;break;case 9:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),t.n=10,this.sdk.startListening();case 10:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-l.callStartTime,e=Math.floor(t/6e4),n=Math.floor(t%6e4/1e3),o=document.getElementById("voiceTimer");o&&(o.textContent="".concat(e.toString().padStart(2,"0"),":").concat(n.toString().padStart(2,"0")))},1e3);case 11:console.log("✅ Voice call started successfully"),t.n=13;break;case 12:t.p=12,u=t.v,console.error("❌ Error starting voice call:",u),this.showError(u.message||u),c=document.getElementById("voiceIdleState"),s=document.getElementById("voiceActiveState"),c&&(c.style.display="flex"),s&&(s.style.display="none");case 13:return t.a(2)}},t,this,[[2,12]])})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){var t=this;console.log("🔴 Ending voice call..."),this.sdk&&this.isActive&&(this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null);var e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState");e&&(e.style.display="flex"),n&&(n.style.display="none"),setTimeout(function(){return t.adjustSizesForContainer()},50);var o=document.getElementById("transcriptText");o&&(o.textContent=this.t("transcriptWillAppear"),o.classList.add("empty"));var r=document.getElementById("voiceAvatarActive");r&&r.classList.remove("speaking"),console.log("✅ Voice call ended")}},{key:"updateTranscript",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent=t,e.classList.remove("empty"))}},{key:"showError",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent="".concat(this.t("error"),": ").concat(t),e.classList.remove("empty"))}},{key:"showDomainError",value:function(){var t=document.getElementById("transcriptText");if(t){var e=this.t("domainNotValidated"),n=this.t("domainErrorMessage");t.innerHTML='<div style="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;">'.concat(e,'</div><div style="font-size: 14px; color: #991B1B; line-height: 1.5;">').concat(n,"</div>"),t.classList.remove("empty")}}},{key:"toggleMute",value:function(){if(this.sdk&&this.isActive){var t=null;if(this.sdk.voiceSDK&&this.sdk.voiceSDK.audioRecorder&&this.sdk.voiceSDK.audioRecorder.mediaStream&&(t=this.sdk.voiceSDK.audioRecorder.mediaStream.getAudioTracks()[0]),!t&&this.audioStream&&(t=this.audioStream.getAudioTracks()[0]),t){t.enabled=!t.enabled;var e=document.getElementById("muteBtn"),n=null==e?void 0:e.querySelector(".mute-icon"),o=null==e?void 0:e.querySelector(".mute-cross");e&&n&&o&&(t.enabled?(n.style.stroke="",o.style.display="none",e.classList.remove("muted")):(n.style.stroke="#9ca3af",o.style.display="block",e.classList.add("muted"))),console.log(t.enabled?"🔊 Unmuted":"🔇 Muted")}else console.warn("⚠️ No audio track available for mute toggle")}}},{key:"toggleSpeaker",value:function(){console.log("🔊 Speaker toggle")}},{key:"destroy",value:function(){this.isActive&&this.endVoiceCall(),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&(this.sdk.disconnect(),this.sdk=null)}}],e&&Gn(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Jn(t){return Jn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Jn(t)}function Yn(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return $n(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):($n(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,$n(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,$n(d,"constructor",u),$n(u,"constructor",s),s.displayName="GeneratorFunction",$n(u,r,"GeneratorFunction"),$n(d),$n(d,r,"Generator"),$n(d,o,function(){return this}),$n(d,"toString",function(){return"[object Generator]"}),(Yn=function(){return{w:i,m:f}})()}function $n(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}$n=function(t,e,n,o){function i(e,n){$n(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},$n(t,e,n,o)}function Xn(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Zn(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Xn(i,o,r,a,c,"next",t)}function c(t){Xn(i,o,r,a,c,"throw",t)}a(void 0)})}}function to(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,eo(o.key),o)}}function eo(t){var e=function(t){if("object"!=Jn(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Jn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Jn(e)?e:e+""}var no=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.sdk=n,this.streamingEl=null,this.hasStartedStreaming=!1,this.isActive=!1,this.eventHandlers={autoResize:null,keydown:null},this.eventHandlersSetup=!1},e=[{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"generateHTML",value:function(){var t,e,n,o,r,i,a,c,s,u=this.config.inputPlaceholder||(null===(t=this.config.panel)||void 0===t?void 0:t.inputPlaceholder)||this.t("typeMessage")||"Type your message...";return'<div class="text-interface" id="textInterface">\n <div class="messages-container" id="messagesContainer">\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),'</div>\n </div>\n </div>\n <div class="input-container">\n <div class="input-wrapper" style="flex:1;">\n <textarea class="message-input" id="messageInput" placeholder="').concat(u,'" rows="1" dir="').concat(this.config.direction||"ltr",'"></textarea>\n </div>\n <button class="send-button" id="sendButton" aria-label="').concat(this.t("sendMessageAria"),'">').concat(this.config.sendButtonText||"➤","</button>\n ").concat(null!==(e=this.config.sendButtonHint)&&void 0!==e&&e.text||null!==(n=this.config.panel)&&void 0!==n&&null!==(n=n.sendButtonHint)&&void 0!==n&&n.text?'\n <div class="send-button-hint" style="color: '.concat((null===(o=this.config.sendButtonHint)||void 0===o?void 0:o.color)||(null===(r=this.config.panel)||void 0===r||null===(r=r.sendButtonHint)||void 0===r?void 0:r.color)||"#6B7280","; font-size: ").concat((null===(i=this.config.sendButtonHint)||void 0===i?void 0:i.fontSize)||(null===(a=this.config.panel)||void 0===a||null===(a=a.sendButtonHint)||void 0===a?void 0:a.fontSize)||"12px",'; text-align: center; margin-top: 4px;">\n ').concat((null===(c=this.config.sendButtonHint)||void 0===c?void 0:c.text)||(null===(s=this.config.panel)||void 0===s||null===(s=s.sendButtonHint)||void 0===s?void 0:s.text),"\n </div>\n "):"","\n </div>\n </div>")}},{key:"generateCSS",value:function(){var t,e,n,o,r,i,a,c,s,u,l,d,f,p=this.config.messages,h=(this.config.panel,this.config.animation,this.config.sendButtonColor||(null===(t=this.config.panel)||void 0===t?void 0:t.sendButtonColor)||"#7C3AED"),v=this.config.sendButtonHoverColor||(null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonHoverColor)||"#6D28D9",g=this.config.sendButtonTextColor||(null===(n=this.config.panel)||void 0===n?void 0:n.sendButtonTextColor)||"#FFFFFF",y=(this.config.inputPlaceholder||null===(o=this.config.panel)||void 0===o||o.inputPlaceholder,this.config.inputBorderColor||(null===(r=this.config.panel)||void 0===r?void 0:r.inputBorderColor)||"#E5E7EB"),m=this.config.inputFocusColor||(null===(i=this.config.panel)||void 0===i?void 0:i.inputFocusColor)||"#7C3AED",b=this.config.inputBackgroundColor||(null===(a=this.config.panel)||void 0===a?void 0:a.inputBackgroundColor)||"#FFFFFF",S=this.config.inputTextColor||(null===(c=this.config.panel)||void 0===c?void 0:c.inputTextColor)||"#1F2937",w=this.config.inputFontSize||(null===(s=this.config.panel)||void 0===s?void 0:s.inputFontSize)||"14px",x=this.config.inputBorderRadius||(null===(u=this.config.panel)||void 0===u?void 0:u.inputBorderRadius)||20,k=this.config.inputPadding||(null===(l=this.config.panel)||void 0===l?void 0:l.inputPadding)||"6px 14px";return"\n /* Messages container using new classes */\n #messagesContainer { \n flex: 1; \n overflow-y: auto; \n overflow-x: hidden; \n padding: 20px; \n background: #f8fafc; \n display: flex; \n flex-direction: column; \n gap: 16px; \n min-height: 0; \n }\n .empty-state { \n flex: 1; \n display: flex; \n flex-direction: column; \n align-items: center; \n justify-content: center; \n gap: 12px; \n color: #64748b; \n text-align: center; \n padding: 20px; \n }\n .empty-state-icon { font-size: 48px; opacity: 0.3; }\n .empty-state-title { font-size: 20px; font-weight: 700; color: #334155; }\n .empty-state-text { font-size: 13px; max-width: 280px; }\n\n .text-interface { \n display: none; \n flex: 1; \n flex-direction: column; \n min-height: 0; \n overflow: hidden; \n }\n .text-interface.active { display: flex; }\n \n .message { \n display: flex; \n gap: 8px; \n padding: 4px 0; \n max-width: 100%; \n align-items: center; \n }\n .message.edge-left { flex-direction: row; }\n .message.edge-right { flex-direction: row-reverse; }\n .message-bubble { \n padding: 12px; \n border-radius: ".concat(p.borderRadius,"px; \n max-width: 80%; \n font-size: ").concat(p.fontSize,"; \n color: ").concat(p.textColor,"; \n word-wrap: break-word; \n text-align: ").concat("rtl"===this.config.direction?"right":"left","; \n direction: ").concat(this.config.direction||"ltr",";\n }\n .message.user { \n background: ").concat(p.userBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-start":"flex-end","; \n }\n .message.agent { \n background: ").concat(p.agentBackgroundColor,"; \n align-self: ").concat("rtl"===this.config.direction?"flex-end":"flex-start","; \n }\n .message .message-bubble { \n text-align: ").concat("rtl"===this.config.direction?"right":"left"," !important; \n }\n ").concat("rtl"===this.config.direction?"\n .message-bubble {\n text-align: right !important;\n }\n ":"","\n .message-avatar { \n width: 20px; \n height: 20px; \n display: flex; \n align-items: center; \n justify-content: center; \n flex-shrink: 0; \n color: inherit; \n font-size: 18px; \n line-height: 1; \n background: transparent; \n border: none; \n }\n .message-avatar.user { background: transparent; }\n .message-avatar.agent { background: transparent; }\n \n .message.system {\n background: ").concat(p.systemBackgroundColor,";\n align-self: flex-start;\n }\n .message.error {\n background: ").concat(p.errorBackgroundColor,";\n align-self: flex-start;\n }\n \n .input-container {\n display: flex;\n gap: 8px;\n padding: 12px 16px;\n background: #FFFFFF;\n border-top: 1px solid #E5E7EB;\n align-items: center;\n flex-shrink: 0;\n flex-direction: ").concat("rtl"===this.config.direction?"row-reverse":"row",";\n }\n \n .input-wrapper {\n position: relative;\n display: flex;\n align-items: center;\n }\n \n .message-input {\n width: 100%;\n min-height: 32px;\n max-height: 120px;\n padding: ").concat(k,";\n border: 1px solid ").concat(y,";\n border-radius: ").concat(x,"px;\n font-size: ").concat(w,";\n font-family: inherit;\n line-height: 1.3;\n resize: none;\n overflow-y: auto;\n background: ").concat(b,";\n color: ").concat(S,";\n vertical-align: top;\n margin: 0;\n display: block;\n white-space: pre-wrap;\n word-wrap: break-word;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n direction: ").concat(this.config.direction||"ltr",";\n -webkit-appearance: none;\n appearance: none;\n box-sizing: border-box;\n }\n \n .message-input:focus {\n outline: none;\n border-color: ").concat(m,";\n background: ").concat("#FFFFFF"===b?"#FFFFFF":b,";\n box-shadow: 0 0 0 3px ").concat(m,"33;\n }\n \n .message-input::placeholder {\n color: #9CA3AF;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n }\n \n .send-button {\n width: 40px;\n height: 40px;\n border-radius: 50%;\n border: none;\n background: ").concat(h,";\n color: ").concat(g,";\n font-size: ").concat(this.config.sendButtonFontSize||(null===(d=this.config.panel)||void 0===d?void 0:d.sendButtonFontSize)||"18px",";\n font-weight: ").concat(this.config.sendButtonFontWeight||(null===(f=this.config.panel)||void 0===f?void 0:f.sendButtonFontWeight)||"500",";\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n transition: all 0.2s ease;\n box-shadow: 0 4px 12px rgba(124, 60, 237, 0.3);\n }\n \n .send-button:hover:not(:disabled) {\n background: ").concat(v,";\n transform: scale(1.05);\n box-shadow: 0 6px 16px rgba(124, 60, 237, 0.4);\n }\n \n .send-button-hint {\n width: 100%;\n text-align: center;\n margin-top: 4px;\n }\n \n .send-button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n \n .typing-indicator {\n display: inline-flex;\n gap: 4px;\n align-items: center;\n }\n \n .typing-dot {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: #64748b;\n animation: typingDot 1.4s ease-in-out infinite;\n }\n \n .typing-dot:nth-child(2) { animation-delay: 0.2s; }\n .typing-dot:nth-child(3) { animation-delay: 0.4s; }\n \n @keyframes typingDot {\n 0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }\n 30% { transform: translateY(-8px); opacity: 1; }\n }\n \n .error-message {\n padding: 12px;\n background: ").concat(p.errorBackgroundColor,";\n border-radius: ").concat(p.borderRadius,"px;\n color: #991B1B;\n font-size: ").concat(p.fontSize,";\n margin: 8px 0;\n }\n \n @media (max-width: 768px) {\n #messagesContainer {\n padding: 12px;\n gap: 12px;\n }\n \n .message-bubble {\n max-width: 85%;\n font-size: 14px;\n padding: 10px;\n }\n \n .text-input-container {\n padding: 10px;\n gap: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 10px 14px;\n min-height: 44px;\n }\n \n #text-chat-send {\n min-width: 56px;\n min-height: 44px;\n width: 56px;\n height: 44px;\n }\n \n .empty-state-icon {\n font-size: 40px;\n }\n \n .empty-state-title {\n font-size: 18px;\n }\n \n .empty-state-text {\n font-size: 12px;\n }\n }\n \n @media (max-width: 480px) {\n #messagesContainer {\n padding: 10px;\n gap: 10px;\n }\n \n .message-bubble {\n max-width: 90%;\n font-size: 13px;\n padding: 8px;\n }\n \n .text-input-container {\n padding: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important;\n padding: 8px 12px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(){var t=this,e=document.getElementById("sendButton"),n=document.getElementById("messageInput"),o=document.getElementById("newChatBtn");if(e&&(e.onclick=function(){return t.sendMessage()}),o&&(o.onclick=function(){return t.startNewChat()}),this.updateInputAttributes(),n){n.style.height="32px",n.style.overflow="hidden";var r=function(){n.style.height="auto";var t=Math.min(n.scrollHeight,120);n.style.height=t+"px",n.style.overflowY=t>=120?"auto":"hidden",t>=120&&setTimeout(function(){n.scrollTop=n.scrollHeight},0)};n.addEventListener("input",r),n.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey?"Enter"===e.key&&e.shiftKey&&setTimeout(r,0):(e.preventDefault(),t.sendMessage())})}}},{key:"startNewChat",value:function(){try{localStorage.removeItem("ttp_text_chat_conversation_id")}catch(t){}this.sdk&&(this.sdk.config.conversationId=null);var t=document.getElementById("messagesContainer");t&&(t.innerHTML='\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),"</div>\n </div>"));var e=document.getElementById("messageInput");e&&e.focus()}},{key:"updateInputAttributes",value:function(){var t=document.getElementById("messageInput");if(t){var e,n=this.config.inputPlaceholder||(null===(e=this.config.panel)||void 0===e?void 0:e.inputPlaceholder)||this.t("typeMessage")||"Type your message...";t.placeholder=n,t.dir=this.config.direction||"ltr",t.style.textAlign="rtl"===this.config.direction?"right":"left"}}},{key:"show",value:function(){var t=document.getElementById("textInterface");t&&t.classList.add("active"),setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},50)}},{key:"hide",value:function(){var t=document.getElementById("textInterface");t&&t.classList.remove("active")}},{key:"startChat",value:(o=Zn(Yn().m(function t(){return Yn().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.updateSendButtonState();case 1:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"sendMessage",value:(n=Zn(Yn().m(function t(){var e,n,o;return Yn().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("messageInput"),n=e.value.trim()){t.n=1;break}return t.a(2);case 1:if(this.isActive){t.n=2;break}return t.n=2,this.startChat();case 2:return this.addMessage("user",n),e.value="",e.style.height="32px",e.style.overflow="hidden",t.p=3,this.beginStreaming(),t.n=4,this.sdk.sendMessage(n);case 4:t.n=6;break;case 5:t.p=5,o=t.v,console.error("❌ Failed to send message:",o),o&&("DOMAIN_NOT_WHITELISTED"===o.message||o.message&&o.message.includes("Domain not whitelisted"))||this.showError(o),this.stopStreamingState();case 6:return t.a(2)}},t,this,[[3,5]])})),function(){return n.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var t=document.getElementById("sendButton");t&&(t.disabled=!this.isActive)}},{key:"addMessage",value:function(t,e){var n=document.getElementById("messagesContainer");if(n){var o=n.querySelector(".empty-state");o&&o.remove();var r=document.createElement("div"),i="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";r.className="message ".concat(t," ").concat(i);var a=document.createElement("div");a.className="message-avatar ".concat(t),a.textContent="user"===t?"👤":"🤖";var c=document.createElement("div");c.className="message-bubble",c.textContent=e,r.appendChild(a),r.appendChild(c),n.appendChild(r),n.scrollTop=n.scrollHeight}}},{key:"beginStreaming",value:function(){var t=document.getElementById("messagesContainer");if(t){this.stopStreamingState();var e=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";e.className="message agent ".concat(n),e.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var r=document.createElement("div");r.className="message-bubble",r.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',e.appendChild(o),e.appendChild(r),t.appendChild(e),this.streamingEl=r,this.hasStartedStreaming=!1,t.scrollTop=t.scrollHeight}}},{key:"appendStreamingChunk",value:function(t){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=t;var e=document.getElementById("messagesContainer");e&&(e.scrollTop=e.scrollHeight)}}},{key:"finalizeStreaming",value:function(t){if(this.streamingEl){this.streamingEl.textContent=t||this.streamingEl.textContent;var e=document.getElementById("agent-streaming");e&&(e.id=""),this.streamingEl=null}this.updateSendButtonState()}},{key:"stopStreamingState",value:function(){var t=document.getElementById("agent-streaming");t&&t.remove(),this.streamingEl=null,this.hasStartedStreaming=!1}},{key:"showError",value:function(t){var e=document.getElementById("messagesContainer");if(e){if(t&&("DOMAIN_NOT_WHITELISTED"===t.message||"string"==typeof t&&t.includes("DOMAIN_NOT_WHITELISTED")||t.message&&t.message.includes("Domain not whitelisted")||"string"==typeof t&&t.includes("Domain not whitelisted"))){var n,o=document.createElement("div");o.className="error-message",o.style.cssText="padding: 16px; margin: 12px; border-radius: 8px; background: "+((null===(n=this.config.messages)||void 0===n?void 0:n.errorBackgroundColor)||"#FEE2E2")+";";var r=document.createElement("div");r.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",r.textContent=this.t("domainNotValidated");var i=document.createElement("div");i.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",i.textContent=this.t("domainErrorMessage"),o.appendChild(r),o.appendChild(i),e.appendChild(o)}else{var a=document.createElement("div");a.className="error-message",a.textContent="string"==typeof t?t:(null==t?void 0:t.message)||t,e.appendChild(a)}e.scrollTop=e.scrollHeight}}},{key:"setActive",value:function(t){this.isActive=t,this.updateSendButtonState()}}],e&&to(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();const oo={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 ro(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return io(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,h=i[2];n>3?(r=h===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,f.n=h,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,h),c=l,s=h;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(io(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,io(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,io(d,"constructor",u),io(u,"constructor",s),s.displayName="GeneratorFunction",io(u,r,"GeneratorFunction"),io(d),io(d,r,"Generator"),io(d,o,function(){return this}),io(d,"toString",function(){return"[object Generator]"}),(ro=function(){return{w:i,m:f}})()}function io(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}io=function(t,e,n,o){function i(e,n){io(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},io(t,e,n,o)}function ao(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function co(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){ao(i,o,r,a,c,"next",t)}function c(t){ao(i,o,r,a,c,"throw",t)}a(void 0)})}}function so(t){return so="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},so(t)}function uo(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function lo(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?uo(Object(n),!0).forEach(function(e){fo(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):uo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function fo(t,e,n){return(e=ho(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function po(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ho(o.key),o)}}function ho(t){var e=function(t){if("object"!=so(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=so(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==so(e)?e:e+""}var vo=function(){return t=function t(){var e,n,o,r,i,a,c,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=this.mergeWithDefaults(s),this.sdk=new ln(this.config),this.isOpen=!1,this.isActive=!1,this.translations=oo,this.currentView="landing";var u=lo(lo(lo({},this.config),this.config.voice),{},{language:(null===(e=this.config.voice)||void 0===e?void 0:e.language)||this.config.language||"en",websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations,outputContainer:(null===(o=this.config.voice)||void 0===o?void 0:o.outputContainer)||"raw",outputEncoding:(null===(r=this.config.voice)||void 0===r?void 0:r.outputEncoding)||"pcm",outputSampleRate:(null===(i=this.config.voice)||void 0===i?void 0:i.outputSampleRate)||44100,outputChannels:(null===(a=this.config.voice)||void 0===a?void 0:a.outputChannels)||1,outputBitDepth:(null===(c=this.config.voice)||void 0===c?void 0:c.outputBitDepth)||16,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 Qn(u);var l=lo(lo(lo({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new no(l,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var d=document.getElementById("text-chat-panel");d&&(this.isOpen=!0,d.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,a,c,s,u,l,d,f,p,h,v,g,y,m,b,S,w,x,k,C,P,O,E,T,I,j,A,D,F,B,R,_,U,M,N,z,L,V,K,H,W,G,q,Q,J,Y,$,X,Z,tt,et,nt,ot,rt,it,at,ct,st,ut,lt,dt,ft,pt,ht,vt,gt,yt,mt,bt,St,wt,xt,kt,Ct,Pt,Ot,Et,Tt,It,jt,At,Dt,Ft,Bt,Rt,_t,Ut,Mt,Nt,zt,Lt,Vt,Kt,Ht,Wt,Gt,qt,Qt,Jt,Yt,$t,Xt,Zt,te,ee,ne,oe,re,ie,ae,ce,se,ue,le,de,fe,pe,he,ve,ge,ye,me,be,Se,we,xe,ke,Ce,Pe,Oe,Ee=t.position||"bottom-right";if("string"==typeof Ee){var Te=Ee.split("-");Ee={vertical:Te[0]||"bottom",horizontal:Te[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var Ie=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||(null===(n=t.button)||void 0===n?void 0:n.backgroundColor)||"#7C3AED",je=(null===(o=t.header)||void 0===o?void 0:o.backgroundColor)||(null===(r=t.button)||void 0===r?void 0:r.backgroundColor)||Ie;return lo({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",language:t.language||"en",icon:lo({type:(null===(i=t.icon)||void 0===i?void 0:i.type)||"custom",customImage:(null===(a=t.icon)||void 0===a?void 0:a.customImage)||"https://talktopc.com/logo192.png",emoji:(null===(c=t.icon)||void 0===c?void 0:c.emoji)||"🎤",text:(null===(s=t.icon)||void 0===s?void 0:s.text)||"AI",size:(null===(u=t.icon)||void 0===u?void 0:u.size)||"medium",backgroundColor:(null===(l=t.icon)||void 0===l?void 0:l.backgroundColor)||"#FFFFFF"},t.icon),position:lo({vertical:Ee.vertical||"bottom",horizontal:Ee.horizontal||"right",offset:Ee.offset||{x:20,y:20}},"object"===so(t.position)?t.position:{}),button:lo({size:(null===(d=t.button)||void 0===d?void 0:d.size)||"medium",shape:(null===(f=t.button)||void 0===f?void 0:f.shape)||"circle",backgroundColor:(null===(p=t.button)||void 0===p?void 0:p.backgroundColor)||(null===(h=t.icon)||void 0===h?void 0:h.backgroundColor)||Ie,hoverColor:(null===(v=t.button)||void 0===v?void 0:v.hoverColor)||"#7C3AED",shadow:!1!==(null===(g=t.button)||void 0===g?void 0:g.shadow),shadowColor:(null===(y=t.button)||void 0===y?void 0:y.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(m=t.button)||void 0===m?void 0:m.backgroundColor)||(null===(b=t.icon)||void 0===b?void 0:b.backgroundColor)||Ie},t.button),panel:lo({width:(null===(S=t.panel)||void 0===S?void 0:S.width)||350,height:(null===(w=t.panel)||void 0===w?void 0:w.height)||500,borderRadius:(null===(x=t.panel)||void 0===x?void 0:x.borderRadius)||12,backgroundColor:(null===(k=t.panel)||void 0===k?void 0:k.backgroundColor)||"#FFFFFF",backdropFilter:(null===(C=t.panel)||void 0===C?void 0:C.backdropFilter)||null,border:(null===(P=t.panel)||void 0===P?void 0:P.border)||"1px solid rgba(0,0,0,0.1)"},t.panel),voice:lo({micButtonColor:(null===(O=t.voice)||void 0===O?void 0:O.micButtonColor)||(null===(E=t.panel)||void 0===E?void 0:E.micButtonColor)||Ie,micButtonActiveColor:(null===(T=t.voice)||void 0===T?void 0:T.micButtonActiveColor)||(null===(I=t.panel)||void 0===I?void 0:I.micButtonActiveColor)||"#EF4444",micButtonHint:lo(lo({text:(null===(j=t.voice)||void 0===j||null===(j=j.micButtonHint)||void 0===j?void 0:j.text)||(null===(A=t.panel)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.text)||"Click the button to start voice conversation",color:(null===(D=t.voice)||void 0===D||null===(D=D.micButtonHint)||void 0===D?void 0:D.color)||(null===(F=t.panel)||void 0===F||null===(F=F.micButtonHint)||void 0===F?void 0:F.color)||"#6B7280",fontSize:(null===(B=t.voice)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.fontSize)||(null===(R=t.panel)||void 0===R||null===(R=R.micButtonHint)||void 0===R?void 0:R.fontSize)||"12px"},null===(_=t.voice)||void 0===_?void 0:_.micButtonHint),null===(U=t.panel)||void 0===U?void 0:U.micButtonHint),avatarBackgroundColor:(null===(M=t.voice)||void 0===M?void 0:M.avatarBackgroundColor)||"#667eea",avatarActiveBackgroundColor:(null===(N=t.voice)||void 0===N?void 0:N.avatarActiveBackgroundColor)||"#667eea",statusTitleColor:(null===(z=t.voice)||void 0===z?void 0:z.statusTitleColor)||"#1e293b",statusSubtitleColor:(null===(L=t.voice)||void 0===L?void 0:L.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(V=t.voice)||void 0===V?void 0:V.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(K=t.voice)||void 0===K?void 0:K.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(H=t.voice)||void 0===H?void 0:H.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(W=t.voice)||void 0===W?void 0:W.transcriptTextColor)||"#1e293b",transcriptLabelColor:(null===(G=t.voice)||void 0===G?void 0:G.transcriptLabelColor)||"#94a3b8",controlButtonColor:(null===(q=t.voice)||void 0===q?void 0:q.controlButtonColor)||"#FFFFFF",controlButtonSecondaryColor:(null===(Q=t.voice)||void 0===Q?void 0:Q.controlButtonSecondaryColor)||"#64748b",endCallButtonColor:(null===(J=t.voice)||void 0===J?void 0:J.endCallButtonColor)||"#ef4444",language:(null===(Y=t.voice)||void 0===Y?void 0:Y.language)||t.language||"en",websocketUrl:(null===($=t.voice)||void 0===$?void 0:$.websocketUrl)||t.websocketUrl},t.voice),text:lo({sendButtonColor:(null===(X=t.text)||void 0===X?void 0:X.sendButtonColor)||(null===(Z=t.panel)||void 0===Z?void 0:Z.sendButtonColor)||"#7C3AED",sendButtonHoverColor:(null===(tt=t.text)||void 0===tt?void 0:tt.sendButtonHoverColor)||(null===(et=t.panel)||void 0===et?void 0:et.sendButtonHoverColor)||"#6D28D9",sendButtonActiveColor:(null===(nt=t.text)||void 0===nt?void 0:nt.sendButtonActiveColor)||(null===(ot=t.panel)||void 0===ot?void 0:ot.sendButtonActiveColor)||"#6D28D9",sendButtonText:(null===(rt=t.text)||void 0===rt?void 0:rt.sendButtonText)||(null===(it=t.panel)||void 0===it?void 0:it.sendButtonText)||"➤",sendButtonTextColor:(null===(at=t.text)||void 0===at?void 0:at.sendButtonTextColor)||(null===(ct=t.panel)||void 0===ct?void 0:ct.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(st=t.text)||void 0===st?void 0:st.sendButtonFontSize)||(null===(ut=t.panel)||void 0===ut?void 0:ut.sendButtonFontSize)||"18px",sendButtonFontWeight:(null===(lt=t.text)||void 0===lt?void 0:lt.sendButtonFontWeight)||(null===(dt=t.panel)||void 0===dt?void 0:dt.sendButtonFontWeight)||"500",sendButtonHint:lo(lo({text:(null===(ft=t.text)||void 0===ft||null===(ft=ft.sendButtonHint)||void 0===ft?void 0:ft.text)||(null===(pt=t.panel)||void 0===pt||null===(pt=pt.sendButtonHint)||void 0===pt?void 0:pt.text)||"",color:(null===(ht=t.text)||void 0===ht||null===(ht=ht.sendButtonHint)||void 0===ht?void 0:ht.color)||(null===(vt=t.panel)||void 0===vt||null===(vt=vt.sendButtonHint)||void 0===vt?void 0:vt.color)||"#6B7280",fontSize:(null===(gt=t.text)||void 0===gt||null===(gt=gt.sendButtonHint)||void 0===gt?void 0:gt.fontSize)||(null===(yt=t.panel)||void 0===yt||null===(yt=yt.sendButtonHint)||void 0===yt?void 0:yt.fontSize)||"12px"},null===(mt=t.text)||void 0===mt?void 0:mt.sendButtonHint),null===(bt=t.panel)||void 0===bt?void 0:bt.sendButtonHint),inputPlaceholder:(null===(St=t.text)||void 0===St?void 0:St.inputPlaceholder)||(null===(wt=t.panel)||void 0===wt?void 0:wt.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(xt=t.text)||void 0===xt?void 0:xt.inputBorderColor)||(null===(kt=t.panel)||void 0===kt?void 0:kt.inputBorderColor)||"#E5E7EB",inputFocusColor:(null===(Ct=t.text)||void 0===Ct?void 0:Ct.inputFocusColor)||(null===(Pt=t.panel)||void 0===Pt?void 0:Pt.inputFocusColor)||"#7C3AED",inputBackgroundColor:(null===(Ot=t.text)||void 0===Ot?void 0:Ot.inputBackgroundColor)||(null===(Et=t.panel)||void 0===Et?void 0:Et.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(Tt=t.text)||void 0===Tt?void 0:Tt.inputTextColor)||(null===(It=t.panel)||void 0===It?void 0:It.inputTextColor)||"#1F2937",inputFontSize:(null===(jt=t.text)||void 0===jt?void 0:jt.inputFontSize)||(null===(At=t.panel)||void 0===At?void 0:At.inputFontSize)||"14px",inputBorderRadius:(null===(Dt=t.text)||void 0===Dt?void 0:Dt.inputBorderRadius)||(null===(Ft=t.panel)||void 0===Ft?void 0:Ft.inputBorderRadius)||20,inputPadding:(null===(Bt=t.text)||void 0===Bt?void 0:Bt.inputPadding)||(null===(Rt=t.panel)||void 0===Rt?void 0:Rt.inputPadding)||"6px 14px"},t.text),landing:lo({backgroundColor:(null===(_t=t.landing)||void 0===_t?void 0:_t.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)",logo:(null===(Ut=t.landing)||void 0===Ut?void 0:Ut.logo)||"🤖",title:(null===(Mt=t.landing)||void 0===Mt?void 0:Mt.title)||null,titleColor:(null===(Nt=t.landing)||void 0===Nt?void 0:Nt.titleColor)||"#1e293b",modeCardBackgroundColor:(null===(zt=t.landing)||void 0===zt?void 0:zt.modeCardBackgroundColor)||"#FFFFFF",modeCardBorderColor:(null===(Lt=t.landing)||void 0===Lt?void 0:Lt.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Vt=t.landing)||void 0===Vt?void 0:Vt.modeCardHoverBorderColor)||je,modeCardIconBackgroundColor:(null===(Kt=t.landing)||void 0===Kt?void 0:Kt.modeCardIconBackgroundColor)||je,modeCardTitleColor:(null===(Ht=t.landing)||void 0===Ht?void 0:Ht.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(Wt=t.landing)||void 0===Wt?void 0:Wt.voiceCardIcon)||"🎤",textCardIcon:(null===(Gt=t.landing)||void 0===Gt?void 0:Gt.textCardIcon)||"💬"},t.landing),header:lo({title:(null===(qt=t.header)||void 0===qt?void 0:qt.title)||"Chat Assistant",showTitle:!1!==(null===(Qt=t.header)||void 0===Qt?void 0:Qt.showTitle),backgroundColor:(null===(Jt=t.header)||void 0===Jt?void 0:Jt.backgroundColor)||(null===(Yt=t.button)||void 0===Yt?void 0:Yt.backgroundColor)||"#7C3AED",textColor:(null===($t=t.header)||void 0===$t?void 0:$t.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(Xt=t.header)||void 0===Xt?void 0:Xt.showCloseButton)},t.header),tooltips:lo({newChat:(null===(Zt=t.tooltips)||void 0===Zt?void 0:Zt.newChat)||null,back:(null===(te=t.tooltips)||void 0===te?void 0:te.back)||null,close:(null===(ee=t.tooltips)||void 0===ee?void 0:ee.close)||null,mute:(null===(ne=t.tooltips)||void 0===ne?void 0:ne.mute)||null,speaker:(null===(oe=t.tooltips)||void 0===oe?void 0:oe.speaker)||null,endCall:(null===(re=t.tooltips)||void 0===re?void 0:re.endCall)||null},t.tooltips),messages:lo({userBackgroundColor:(null===(ie=t.messages)||void 0===ie?void 0:ie.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(ae=t.messages)||void 0===ae?void 0:ae.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(ce=t.messages)||void 0===ce?void 0:ce.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(se=t.messages)||void 0===se?void 0:se.errorBackgroundColor)||"#FEE2E2",textColor:(null===(ue=t.messages)||void 0===ue?void 0:ue.textColor)||"#1F2937",fontSize:(null===(le=t.messages)||void 0===le?void 0:le.fontSize)||"14px",borderRadius:(null===(de=t.messages)||void 0===de?void 0:de.borderRadius)||8},t.messages),animation:lo({enableHover:!1!==(null===(fe=t.animation)||void 0===fe?void 0:fe.enableHover),enablePulse:!1!==(null===(pe=t.animation)||void 0===pe?void 0:pe.enablePulse),enableSlide:!1!==(null===(he=t.animation)||void 0===he?void 0:he.enableSlide),duration:(null===(ve=t.animation)||void 0===ve?void 0:ve.duration)||.3},t.animation),behavior:lo({autoOpen:(null===(ge=t.behavior)||void 0===ge?void 0:ge.autoOpen)||!1,startOpen:(null===(ye=t.behavior)||void 0===ye?void 0:ye.startOpen)||!1,hidden:(null===(me=t.behavior)||void 0===me?void 0:me.hidden)||!1,autoConnect:(null===(be=t.behavior)||void 0===be?void 0:be.autoConnect)||!1,showWelcomeMessage:!1!==(null===(Se=t.behavior)||void 0===Se?void 0:Se.showWelcomeMessage),welcomeMessage:(null===(we=t.behavior)||void 0===we?void 0:we.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:void 0===(null===(xe=t.behavior)||void 0===xe?void 0:xe.enableVoiceMode)||t.behavior.enableVoiceMode,mode:(null===(ke=t.behavior)||void 0===ke?void 0:ke.mode)||"unified"},t.behavior),accessibility:lo({ariaLabel:(null===(Ce=t.accessibility)||void 0===Ce?void 0:Ce.ariaLabel)||"Chat Assistant",ariaDescription:(null===(Pe=t.accessibility)||void 0===Pe?void 0:Pe.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(Oe=t.accessibility)||void 0===Oe?void 0:Oe.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},forceConversationId:t.forceConversationId,onConversationStart:t.onConversationStart,onConversationEnd:t.onConversationEnd,onBargeIn:t.onBargeIn,onAudioStartPlaying:t.onAudioStartPlaying,onAudioStoppedPlaying:t.onAudioStoppedPlaying,onSubtitleDisplay:t.onSubtitleDisplay,primaryColor:Ie},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.on("domainError",function(e){t.textInterface.showError(e),t.textInterface.stopStreamingState()}),this.sdk.on("error",function(e){e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))||(t.textInterface.showError(e.message||e),t.textInterface.stopStreamingState())}),this.sdk.on("chunk",function(e){t.textInterface.appendStreamingChunk(e)}),this.sdk.on("done",function(e){var n=e.text;t.textInterface.finalizeStreaming(n)})}},{key:"createWidget",value:function(){console.log("🏗️ createWidget called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var t=document.getElementById("text-chat-widget");t&&t.remove();var e=document.createElement("div");if(e.id="text-chat-widget",e.innerHTML=this.generateWidgetHTML(),document.body.appendChild(e),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("text-chat-panel");n&&(this.isOpen=!0,n.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){var t=this,e=(this.config.position,this.config.button),n=this.config.icon,o=(this.config.panel,this.config.header),r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),i={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i),s=this.config.behavior.mode||"unified",u="unified"===s,l="unified"===s||"voice-only"===s,d="unified"===s||"text-only"===s,f=function(e){var n=t.config.language||"en";return(t.translations[n]||t.translations.en)[e]||e},p=function(e){var n,o=null===(n=t.config.tooltips)||void 0===n?void 0:n[e];return null!=o?o:{newChat:f("newChat"),back:f("back"),close:f("close"),mute:f("mute"),speaker:f("speaker"),endCall:f("endCall")}[e]||""};return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header" style="background: ').concat(o.backgroundColor,"; color: ").concat(o.textColor,';">\n <div>\n ').concat(o.showTitle?'<div class="header-title">'.concat(o.title,"</div>"):"",'\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat(f("online"),'</span>\n </div>\n </div>\n \n <div style="display: flex; gap: 12px; align-items: center;">\n \x3c!-- New Chat Button (hide on landing screen, show otherwise) --\x3e\n <button class="header-icon new-chat-btn" id="newChatBtn" title="').concat(p("newChat"),'" style="').concat(u?"display: none;":"",'">\n <span style="font-size: 18px; font-weight: bold;">+</span>\n </button>\n \n \x3c!-- Back Button (only show in unified mode) --\x3e\n ').concat("unified"===s?'<button class="header-icon back-btn" id="backBtn" title="'.concat(p("back"),'" style="display: none;">\n <span style="font-size: 16px;">‹</span>\n </button>'):"","\n \n \x3c!-- Close Button --\x3e\n ").concat(o.showCloseButton?'<button class="header-icon close-btn" id="closeBtn" title="'+p("close")+'"><span style="font-size: 18px; font-weight: bold;">×</span></button>':"","\n </div>\n </div>\n\n ").concat(u?'\n <div class="landing-screen" id="landingScreen">\n <div class="landing-logo">🤖</div>\n <div class="landing-title">'.concat(f("landingTitle"),'</div>\n <div class="mode-selection">\n ').concat(l?'<div class="mode-card voice" id="mode-card-voice">\n <div class="mode-card-icon">🎤</div>\n <div class="mode-card-title">'.concat(f("voiceCall"),"</div>\n </div>"):"","\n ").concat(d?'<div class="mode-card text" id="mode-card-text">\n <div class="mode-card-icon">💬</div>\n <div class="mode-card-title">'.concat(f("textChat"),"</div>\n </div>"):"","\n </div>\n </div>"):"","\n\n ").concat(l?this.voiceInterface.generateHTML():"","\n ").concat(d?this.textInterface.generateHTML():"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var t=this.config.position,e=t.offset||{x:20,y:20},n="";return"top"===t.vertical?n+="top: ".concat(e.y,"px;"):"bottom"===t.vertical?n+="bottom: ".concat(e.y,"px;"):"center"===t.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===t.horizontal?n+="left: ".concat(e.x,"px;"):"right"===t.horizontal?n+="right: ".concat(e.x,"px;"):"center"===t.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(t){var e=this.config.icon;switch(e.type){case"custom":return'<img src="'.concat(e.customImage,'" alt="Chat Assistant" style="width: ').concat(t,"px; height: ").concat(t,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(t,'px; line-height: 1;">').concat(e.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*t),'px; font-weight: bold; color: white;">').concat(e.text,"</span>");case"microphone":default:return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>');case"chat":return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/>\n </svg>')}}},{key:"generateCSS",value:function(t,e,n){var o,r,i,a,c,s,u,l=this.config.button,d=this.config.icon,f=this.config.panel,p=this.config.header,h=(this.config.messages,this.config.animation),v=this.config.behavior.mode||"unified",g="unified"===v||"voice-only"===v,y="unified"===v||"text-only"===v,m=p.backgroundColor;return'\n /* MOBILE FIRST - Default styles for all devices */\n #text-chat-widget {\n position: fixed !important;\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n /* Mobile defaults */\n right: 10px;\n bottom: 10px;\n left: auto;\n top: auto;\n }\n \n /* Desktop positioning (only on larger screens) */\n @media (min-width: 769px) {\n #text-chat-widget {\n '.concat(t,"\n right: ").concat("right"===this.config.position.horizontal?"20px":"auto",";\n left: ").concat("left"===this.config.position.horizontal?"20px":"auto",";\n bottom: ").concat("bottom"===this.config.position.vertical?"20px":"auto",";\n top: ").concat("top"===this.config.position.vertical?"20px":"auto",";\n }\n }\n \n /* Mobile override (force mobile positioning) */\n @media (max-width: 768px) {\n #text-chat-widget {\n right: 10px !important;\n bottom: 10px !important;\n left: auto !important;\n top: auto !important;\n transform: none !important;\n }\n }\n \n @media (max-width: 480px) {\n #text-chat-widget {\n right: 8px !important;\n bottom: 8px !important;\n left: auto !important;\n top: auto !important;\n }\n }\n \n #text-chat-button {\n width: ").concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===l.shape?"50%":"square"===l.shape?"0":"12px",";\n background: ").concat(l.backgroundColor||d.backgroundColor||"#7C3AED",";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(h.duration,"s ease;\n box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);\n touch-action: manipulation;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n user-select: none;\n min-width: 44px;\n min-height: 44px;\n }\n \n @media (max-width: 768px) {\n #text-chat-widget {\n right: 10px !important;\n bottom: 10px !important;\n left: auto !important;\n top: auto !important;\n transform: none !important;\n }\n \n #text-chat-button {\n width: 56px !important;\n height: 56px !important;\n min-width: 56px !important;\n min-height: 56px !important;\n max-width: 56px !important;\n max-height: 56px !important;\n }\n \n #text-chat-panel {\n position: fixed !important;\n left: 10px !important;\n right: 10px !important;\n bottom: 76px !important; /* 56px button + 20px gap */\n top: 60px !important; /* Add top spacing */\n width: auto !important;\n max-width: none !important;\n height: auto !important; /* Change from max-height to auto */\n max-height: none !important; /* Remove max-height */\n transform: none !important;\n margin: 0 !important;\n }\n \n #text-chat-panel .widget-header {\n padding: 10px 14px;\n min-height: 56px;\n }\n \n #text-chat-panel .header-title {\n font-size: 15px;\n }\n \n #text-chat-panel .header-icon {\n width: 40px;\n height: 40px;\n min-width: 40px;\n min-height: 40px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 12px 16px !important;\n min-height: 48px !important;\n }\n \n #text-chat-send {\n min-width: 48px !important;\n min-height: 48px !important;\n width: 48px !important;\n height: 48px !important;\n }\n \n .landing-screen {\n padding: 16px;\n }\n \n .landing-logo {\n font-size: 40px;\n }\n \n .landing-title {\n font-size: 18px;\n margin-bottom: 16px;\n }\n \n .mode-selection {\n flex-direction: column;\n gap: 12px;\n align-items: center;\n }\n \n .mode-card {\n max-width: 100%;\n width: 100%;\n padding: 16px;\n }\n \n .mode-card-icon {\n width: 50px;\n height: 50px;\n font-size: 28px;\n }\n \n .mode-card-title {\n font-size: 14px;\n }\n }\n \n @media (max-width: 480px) {\n #text-chat-widget {\n right: 8px !important;\n bottom: 8px !important;\n left: auto !important;\n top: auto !important;\n }\n \n #text-chat-button {\n width: 54px !important;\n height: 54px !important;\n min-width: 54px !important;\n min-height: 54px !important;\n }\n \n #text-chat-panel {\n left: 8px !important;\n right: 8px !important;\n bottom: 70px !important;\n top: 50px !important; /* Add top spacing for very small screens */\n height: auto !important;\n max-height: none !important;\n }\n \n #text-chat-panel .widget-header {\n padding: 8px 12px;\n min-height: 52px;\n }\n \n #text-chat-panel .header-title {\n font-size: 14px;\n }\n \n .landing-logo {\n font-size: 36px;\n }\n \n .landing-title {\n font-size: 16px;\n }\n }\n \n ").concat(h.enableHover?"\n #text-chat-button:hover {\n background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);\n transform: scale(1.05);\n box-shadow: 0 8px 20px rgba(102, 126, 234, 0.5);\n }\n ":"","\n \n #text-chat-panel {\n display: none;\n position: fixed;\n bottom: calc(").concat(e,"px + 20px);\n ").concat("right"===this.config.position.horizontal?"right: 20px;":"left: 20px;","\n width: ").concat(f.width,"px;\n max-width: calc(100vw - 40px);\n height: ").concat(f.height,"px;\n max-height: calc(100vh - ").concat(e,"px - 40px);\n background: transparent;\n border-radius: ").concat(f.borderRadius,"px;\n border: none;\n flex-direction: column;\n overflow: hidden;\n ").concat(f.backdropFilter?"backdrop-filter: ".concat(f.backdropFilter,";"):"","\n ").concat(h.enableSlide?"transition: all ".concat(h.duration,"s ease;"):"","\n box-sizing: border-box;\n }\n \n #text-chat-panel.open {\n display: flex;\n ").concat(h.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n\n /* Shell for gradient border/background */\n .widget-shell { width: 100%; height: 100%; padding: 0; border-radius: ").concat(f.borderRadius,"px; background: transparent; box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; display: flex; flex-direction: column; box-sizing: border-box; }\n .panel-inner { width: 100%; height: 100%; background: #ffffff; border-radius: ").concat(f.borderRadius,"px; overflow: hidden; display:flex; flex-direction: column; padding: 0; box-sizing: border-box; max-width: 100%; }\n\n /* New structure styles matching provided design */\n #text-chat-panel .widget-container {\n width: 100%; height: 100%; min-height: 0; background: #FFFFFF; overflow: hidden; display: flex; flex-direction: column; border-radius: ").concat(f.borderRadius,"px;\n container-type: size;\n }\n \n /* Ensure content areas can scroll when height is constrained */\n #text-chat-panel .widget-container > .landing-screen,\n #text-chat-panel .widget-container > .voice-interface,\n #text-chat-panel .widget-container > .text-interface {\n flex: 1;\n min-height: 0;\n overflow-y: auto;\n overflow-x: hidden;\n }\n \n /* Header should not scroll */\n #text-chat-panel .widget-header {\n padding: 12px 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-top-left-radius: ").concat(f.borderRadius,"px;\n border-top-right-radius: ").concat(f.borderRadius,"px;\n flex-shrink: 0;\n min-height: 60px;\n box-sizing: border-box;\n }\n #text-chat-panel .header-title { font-size: 16px; font-weight: 600; }\n #text-chat-panel .header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.9; }\n #text-chat-panel .status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }\n @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n /* Header icon buttons */\n .header-icon {\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 36px;\n height: 36px;\n min-width: 36px;\n min-height: 36px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n flex-shrink: 0;\n font-size: 16px;\n padding: 0;\n box-sizing: border-box;\n }\n \n .header-icon:hover {\n background: rgba(255, 255, 255, 0.3);\n }\n \n .header-icon svg {\n pointer-events: none;\n stroke: white;\n fill: none;\n }\n \n .back-btn.visible {\n display: flex !important;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { \n display: none; \n flex: 1; \n padding: 20px; \n background: ").concat((null===(o=this.config.landing)||void 0===o?void 0:o.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)","; \n align-items: center; \n justify-content: flex-start; \n flex-direction: column; \n gap: 16px; \n overflow-y: auto; \n min-height: 0; \n }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { \n font-size: 20px; \n color: ").concat((null===(r=this.config.landing)||void 0===r?void 0:r.titleColor)||"#1e293b","; \n font-weight: 700; \n margin-bottom: 20px; \n text-align: center;\n width: 100%;\n }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { \n flex: 1; \n max-width: 180px; \n background: ").concat((null===(i=this.config.landing)||void 0===i?void 0:i.modeCardBackgroundColor)||"#FFFFFF","; \n border: 2px solid ").concat((null===(a=this.config.landing)||void 0===a?void 0:a.modeCardBorderColor)||"#E2E8F0","; \n border-radius: 20px; \n padding: 20px 12px; \n cursor: pointer; \n display: flex; \n flex-direction: column; \n align-items: center; \n gap: 8px; \n transition: transform ").concat(h.duration,"s ease, box-shadow ").concat(h.duration,"s ease, border-color ").concat(h.duration,"s ease; \n box-shadow: 0 4px 12px rgba(0,0,0,0.05); \n }\n .mode-card:hover { \n transform: translateY(-6px); \n box-shadow: 0 12px 24px rgba(102, 126, 234, 0.2); \n border-color: ").concat((null===(c=this.config.landing)||void 0===c?void 0:c.modeCardHoverBorderColor)||m,"; \n }\n .mode-card-icon { \n width: 60px; \n height: 60px; \n display: flex; \n align-items: center; \n justify-content: center; \n border-radius: 50%; \n background: ").concat((null===(s=this.config.landing)||void 0===s?void 0:s.modeCardIconBackgroundColor)||m,"; \n color: #fff; \n font-size: 32px; \n }\n .mode-card-title { \n color: ").concat((null===(u=this.config.landing)||void 0===u?void 0:u.modeCardTitleColor)||"#111827","; \n font-weight: 600; \n text-align: center;\n width: 100%;\n }\n\n ").concat(g?this.voiceInterface.generateCSS():"","\n ").concat(y?this.textInterface.generateCSS():"","\n \n #text-chat-send-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this;console.log("⚙️ setupWidgetEvents called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n"),currentView:this.currentView});var e=document.getElementById("text-chat-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("closeBtn");n&&(n.onclick=function(){return t.togglePanel()});var o=this.config.behavior.mode||"unified",r="unified"===o,i="unified"===o||"voice-only"===o,a="unified"===o||"text-only"===o,c=document.getElementById("backBtn"),s=document.getElementById("landingScreen"),u=document.getElementById("mode-card-voice"),l=document.getElementById("mode-card-text"),d=document.getElementById("textInterface"),f=document.getElementById("voiceInterface");c&&(c.onclick=function(){return t.showLanding()}),r?(u&&(u.onclick=function(){return t.showVoice()}),l&&(l.onclick=function(){return t.showText()}),"text"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.add("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="")):"voice"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.remove("active"),f&&f.classList.add("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="none")):(this.currentView="landing",s&&s.classList.add("active"),d&&d.classList.remove("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.remove("visible"))):"voice-only"===o?(f&&f.classList.add("active"),d&&d.classList.remove("active"),s&&s.classList.remove("active")):"text-only"===o&&(d&&d.classList.add("active"),f&&f.classList.remove("active"),s&&s.classList.remove("active")),i&&(console.log("⚙️ Setting up voice interface event handlers"),this.voiceInterface.setupEventHandlers()),a&&(console.log("⚙️ Setting up text interface event handlers"),this.textInterface.setupEventHandlers());var p=document.getElementById("newChatBtn");p&&(p.onclick=function(){return t.textInterface.startNewChat()},r&&(p.style.display="none")),this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"startNewChat",value:function(){this.textInterface.startNewChat()}},{key:"showLanding",value:function(){if("unified"===(this.config.behavior.mode||"unified")){this.currentView="landing";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),r&&(r.style.display="none")}}},{key:"showText",value:function(){this.currentView="text";var t=document.getElementById("landingScreen"),e=document.getElementById("voiceInterface"),n=document.getElementById("backBtn"),o=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),this.textInterface.show();var r=this.config.behavior.mode||"unified";n&&"unified"===r&&n.classList.add("visible"),o&&(o.style.display="")}},{key:"showVoice",value:function(){this.currentView="voice";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),r=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active");var i=this.config.behavior.mode||"unified";o&&"unified"===i&&o.classList.add("visible"),r&&(r.style.display="none")}},{key:"setupKeyboardNavigation",value:function(){var t=this;document.addEventListener("keydown",function(e){"Escape"===e.key&&t.isOpen&&t.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("text-chat-panel").classList.toggle("open"),this.isOpen&&setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},100),this.isOpen&&!this.isActive&&this.config.behavior.autoConnect&&this.startChat()}},{key:"startChat",value:(i=co(ro().m(function t(){return ro().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.textInterface.setActive(!0);case 1:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"sendMessage",value:(r=co(ro().m(function t(){return ro().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.textInterface.sendMessage();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=co(ro().m(function t(){var e,n,o,r,i,a,c;return ro().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://backend.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"addMessage",value:function(t,e){this.textInterface.addMessage(t,e)}},{key:"beginStreaming",value:function(){this.textInterface.beginStreaming()}},{key:"appendStreamingChunk",value:function(t){this.textInterface.appendStreamingChunk(t)}},{key:"finalizeStreaming",value:function(t){this.textInterface.finalizeStreaming(t)}},{key:"stopStreamingState",value:function(){this.textInterface.stopStreamingState()}},{key:"showError",value:function(t){this.textInterface.showError(t)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n,o,r,i,a,c;console.log("🔄 updateConfig called",{newConfig:t,stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var s,u,l=lo({},this.config);t.panel&&(l.panel=lo(lo({},this.config.panel),t.panel)),t.voice&&(l.voice=lo(lo({},this.config.voice),t.voice),t.voice.micButtonHint&&(l.voice.micButtonHint=lo(lo({},null===(s=this.config.voice)||void 0===s?void 0:s.micButtonHint),t.voice.micButtonHint))),t.text&&(l.text=lo(lo({},this.config.text),t.text),t.text.sendButtonHint&&(l.text.sendButtonHint=lo(lo({},null===(u=this.config.text)||void 0===u?void 0:u.sendButtonHint),t.text.sendButtonHint))),void 0!==t.language&&(l.language=t.language),void 0!==t.language&&(["he","ar"].includes(t.language)?l.direction="rtl":void 0===t.direction&&(l.direction="ltr")),t.translations&&(l.translations=t.translations,this.translations=t.translations),t.button&&(l.button=lo(lo({},this.config.button),t.button)),t.header&&(l.header=lo(lo({},this.config.header),t.header)),t.icon&&(l.icon=lo(lo({},this.config.icon),t.icon)),t.messages&&(l.messages=lo(lo({},this.config.messages),t.messages)),t.animation&&(l.animation=lo(lo({},this.config.animation),t.animation)),t.behavior&&(l.behavior=lo(lo({},this.config.behavior),t.behavior)),t.accessibility&&(l.accessibility=lo(lo({},this.config.accessibility),t.accessibility)),t.tooltips&&(l.tooltips=lo(lo({},this.config.tooltips),t.tooltips)),t.landing&&(l.landing=lo(lo({},this.config.landing),t.landing)),void 0!==t.direction&&void 0===l.direction&&(l.direction=t.direction),void 0!==t.primaryColor&&(l.primaryColor=t.primaryColor),void 0!==t.onConversationStart&&(l.onConversationStart=t.onConversationStart),void 0!==t.onConversationEnd&&(l.onConversationEnd=t.onConversationEnd),void 0!==t.onBargeIn&&(l.onBargeIn=t.onBargeIn),void 0!==t.onAudioStartPlaying&&(l.onAudioStartPlaying=t.onAudioStartPlaying),void 0!==t.onAudioStoppedPlaying&&(l.onAudioStoppedPlaying=t.onAudioStoppedPlaying),void 0!==t.onSubtitleDisplay&&(l.onSubtitleDisplay=t.onSubtitleDisplay),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction","voice","text","animation","behavior","accessibility","language","tooltips","landing","primaryColor","onConversationStart","onConversationEnd","onBargeIn","onAudioStartPlaying","onAudioStoppedPlaying","onSubtitleDisplay"].includes(e)||(l[e]=t[e])}),null===(e=this.config)||void 0===e||e.language,this.config=this.mergeWithDefaults(l);var d=this.config.language||"en",f=lo(lo(lo({},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 Qn(f);var p=lo(lo(lo({},this.config),this.config.text),{},{language:d,translations:this.translations});this.textInterface=new no(p,this.sdk);var h=document.getElementById("text-chat-widget");h&&h.remove(),this.createWidget(),this.textInterface&&this.textInterface.updateInputAttributes&&this.textInterface.updateInputAttributes()}},{key:"destroy",value:function(){var t=document.getElementById("text-chat-widget");t&&t.remove(),this.sdk&&this.sdk.destroy(),this.voiceInterface&&this.voiceInterface.destroy()}},{key:"startVoiceCall",value:(n=co(ro().m(function t(){return ro().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.voiceInterface.startVoiceCall();case 1:return t.a(2)}},t,this)})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){this.voiceInterface.endVoiceCall()}},{key:"toggleMute",value:function(){this.voiceInterface.toggleMute()}},{key:"toggleSpeaker",value:function(){this.voiceInterface.toggleSpeaker()}}],e&&po(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,r,i}(),go="2.4.4";const yo={VoiceSDK:pt,VoiceSDK_v2:Ye,TextChatSDK:ln,WebSocketManager:A,AudioRecorder:K,AudioPlayer:Z,EventEmitter:c,VoiceButton:xn,VanillaVoiceButton:Dn,AgentSDK:zn,TTPChatWidget:vo,VERSION:go};return o})());
|
|
3
3
|
//# sourceMappingURL=agent-widget.js.map
|