ttp-agent-sdk 2.2.18 → 2.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see agent-widget.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var i=null;if(void 0!==o&&(i=""+o),void 0!==e.key&&(i=""+e.key),"key"in e)for(var r in o={},e)"key"!==r&&(o[r]=e[r]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:i,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,i={};function r(t,e,o){this.props=t,this.context=e,this.refs=i,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=i,this.updater=o||n}r.prototype.isReactComponent={},r.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},r.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=r.prototype;var s=c.prototype=new a;s.constructor=c,o(s,r.prototype),s.isPureReactComponent=!0;Array.isArray;var l={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return l.H.useEffect(t,e)},e.useRef=function(t){return l.H.useRef(t)},e.useState=function(t){return l.H.useState(t)}}},e={};function n(o){var i=e[o];if(void 0!==i)return i.exports;var r=e[o]={exports:{}};return t[o](r,r.exports,n),r.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function r(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(t){var e=function(t){if("object"!=i(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==i(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>ne,AudioPlayer:()=>Z,AudioRecorder:()=>K,EventEmitter:()=>c,TTPChatWidget:()=>Be,TextChatSDK:()=>Ot,VERSION:()=>Pe,VanillaVoiceButton:()=>qt,VoiceButton:()=>zt,VoiceSDK:()=>pt,WebSocketManager:()=>P,default:()=>Fe});var c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&r(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,i,r,a,c=[],s=!0,l=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){l=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw i}}return c}}(t,e)||d(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=d(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}function d(t,e){if(t){if("string"==typeof t)return f(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return v(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(v(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,v(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,v(d,"constructor",l),v(l,"constructor",s),s.displayName="GeneratorFunction",v(l,i,"GeneratorFunction"),v(d),v(d,i,"Generator"),v(d,o,function(){return this}),v(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:r,m:f}})()}function v(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}v=function(t,e,n,o){function r(e,n){v(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},v(t,e,n,o)}function h(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,y(o.key),o)}}function y(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(m=function(){return!!t})()}function b(t){return b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},b(t)}function x(t,e){return x=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},x(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&&x(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(i=p().m(function t(e){var n,o,i=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(i.connections.has(e)){var o=i.connections.get(e);i.connectionCounts.set(e,(i.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){i.creatingConnections.delete(e),i.emit("open",t,e)}),o.addEventListener("close",function(t){i.creatingConnections.delete(e),i.connections.delete(e),i.connectionCounts.delete(e),i.emit("close",t,e)}),o.addEventListener("error",function(t){i.creatingConnections.delete(e),i.emit("error",t,e)}),o.addEventListener("message",function(t){i.emit("message",t,e)}),t.a(2,o)}},t,this)}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){h(r,n,o,a,c,"next",t)}function c(t){h(r,n,o,a,c,"throw",t)}a(void 0)})},function(t){return r.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=u(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=l(t.value,2),i=o[0],r=o[1];e[i]={readyState:r.readyState,subscribers:this.connectionCounts.get(i)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=u(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=l(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c));function 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 k(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return C(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(C(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,C(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,C(d,"constructor",l),C(l,"constructor",s),s.displayName="GeneratorFunction",C(l,i,"GeneratorFunction"),C(d),C(d,i,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(k=function(){return{w:r,m:f}})()}function C(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}C=function(t,e,n,o){function r(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},C(t,e,n,o)}function I(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,E(o.key),o)}}function E(t){var e=function(t){if("object"!=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 j(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(j=function(){return!!t})()}function T(t){return T=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},T(t)}function B(t,e){return B=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},B(t,e)}var P=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=T(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,j()?Reflect.construct(e,n||[],T(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&&B(t,e)}(e,t),n=e,o=[{key:"connect",value:(r=k().m(function t(){var e=this;return k().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,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 i=r.apply(t,e);function a(t){I(i,n,o,a,c,"next",t)}function c(t){I(i,n,o,a,c,"throw",t)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},i=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};w.on("open",e),w.on("close",n),w.on("error",o),w.on("message",i),this.eventHandlers={open:e,close:n,error:o,message:i}}}},{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}}}],i=[{key:"getSingletonStatus",value:function(){return w.getAllConnections()}},{key:"clearAllConnections",value:function(){w.clearAll()}}],o&&O(n.prototype,o),i&&O(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a}(c);function 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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return A(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(A(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,A(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,A(d,"constructor",l),A(l,"constructor",s),s.displayName="GeneratorFunction",A(l,i,"GeneratorFunction"),A(d),A(d,i,"Generator"),A(d,o,function(){return this}),A(d,"toString",function(){return"[object Generator]"}),(D=function(){return{w:r,m:f}})()}function A(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}A=function(t,e,n,o){function r(e,n){A(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},A(t,e,n,o)}function _(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function M(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){_(r,o,i,a,c,"next",t)}function c(t){_(r,o,i,a,c,"throw",t)}a(void 0)})}}function R(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 z(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,L(o.key),o)}}function L(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 H(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(H=function(){return!!t})()}function U(t){return U=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},U(t)}function N(t,e){return N=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},N(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=U(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,H()?Reflect.construct(e,n||[],U(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&&N(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 R(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)?R(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{new URL(n);var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var i=n.substring(0,n.lastIndexOf("/"));return"".concat(i,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(r=M(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,i=e.data;"pcm_audio_data"===n&&o.emit("audioData",i)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,n=t.v,this.emit("error",n),n;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:(i=M(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 i.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&z(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c);function W(t){return W="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},W(t)}function V(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return G(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(G(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,G(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,G(d,"constructor",l),G(l,"constructor",s),s.displayName="GeneratorFunction",G(l,i,"GeneratorFunction"),G(d),G(d,i,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(V=function(){return{w:r,m:f}})()}function G(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}G=function(t,e,n,o){function r(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},G(t,e,n,o)}function Q(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function q(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Y(o.key),o)}}function Y(t){var e=function(t){if("object"!=W(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=W(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==W(e)?e:e+""}function J(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(J=function(){return!!t})()}function $(t){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},$(t)}function X(t,e){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},X(t,e)}var Z=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=$(e),function(t,e){if(e&&("object"==W(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,J()?Reflect.construct(e,n||[],$(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&X(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(i=V().m(function t(){var e,n,o,i,r,a,c,s,l=this;return V().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.audioContext=new(window.AudioContext||window.webkitAudioContext)),"suspended"!==(o=this.audioContext).state){t.n=3;break}return t.n=3,o.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return i=t.v,t.n=5,o.decodeAudioData(i);case 5:r=t.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=r,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){l.currentSource=null,l.isProcessingQueue=!1,l.audioQueue.length>0?setTimeout(function(){return l.processQueue()},50):setTimeout(function(){0!==l.audioQueue.length||l.currentSource||(l.isPlaying=!1,l.emit("playbackStopped"))},100)},c.start(),t.n=7;break;case 6:t.p=6,s=t.v,this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){Q(r,n,o,a,c,"next",t)}function c(t){Q(r,n,o,a,c,"throw",t)}a(void 0)})},function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c);function tt(t){return tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tt(t)}function et(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return nt(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(nt(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,nt(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,nt(d,"constructor",l),nt(l,"constructor",s),s.displayName="GeneratorFunction",nt(l,i,"GeneratorFunction"),nt(d),nt(d,i,"Generator"),nt(d,o,function(){return this}),nt(d,"toString",function(){return"[object Generator]"}),(et=function(){return{w:r,m:f}})()}function nt(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}nt=function(t,e,n,o){function r(e,n){nt(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},nt(t,e,n,o)}function ot(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function it(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ot(r,o,i,a,c,"next",t)}function c(t){ot(r,o,i,a,c,"throw",t)}a(void 0)})}}function rt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function at(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?rt(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=lt(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,lt(o.key),o)}}function lt(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 ut(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ut=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,ut()?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},n),t.isConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.webSocketManager=new P(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),i=0;i<n.length;i++)o[i]=n.charCodeAt(i);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(l=it(et().m(function t(){var e,n;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return l.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=it(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isDestroyed){t.n=1;break}return t.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),t.n=2,this.connect();case 2:return t.a(2,t.v)}},t,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(c=it(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw new Error("Not connected to voice server");case 1:return t.p=1,this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),t.n=2,this.audioRecorder.start();case 2:return t.a(2,!0);case 3:return t.p=3,e=t.v,console.error("❌ VoiceSDK: Failed to start recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=it(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(r=it(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(i=it(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=at(at({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={t:"hello"};this.config.appId?t.appId=this.config.appId:this.config.ttpId?t.ttpId=this.config.ttpId:t.ttpId=this.generateTtpId();try{this.webSocketManager.sendMessage(t)}catch(t){console.error("VoiceSDK: Failed to send hello message:",t),this.emit("error",t)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&st(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a,c,s,l}(c);function vt(t){return vt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},vt(t)}function ht(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return gt(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(gt(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,gt(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,gt(d,"constructor",l),gt(l,"constructor",s),s.displayName="GeneratorFunction",gt(l,i,"GeneratorFunction"),gt(d),gt(d,i,"Generator"),gt(d,o,function(){return this}),gt(d,"toString",function(){return"[object Generator]"}),(ht=function(){return{w:r,m:f}})()}function gt(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}gt=function(t,e,n,o){function r(e,n){gt(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},gt(t,e,n,o)}function yt(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function mt(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 bt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?mt(Object(n),!0).forEach(function(e){xt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):mt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function xt(t,e,n){return(e=St(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function wt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,St(o.key),o)}}function St(t){var e=function(t){if("object"!=vt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=vt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==vt(e)?e:e+""}function kt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(kt=function(){return!!t})()}function Ct(t){return Ct=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Ct(t)}function It(t,e){return It=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},It(t,e)}var Ot=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=Ct(e),function(t,e){if(e&&("object"==vt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,kt()?Reflect.construct(e,n||[],Ct(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=bt({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&&It(t,e)}(e,t),n=e,o=[{key:"readScriptTagConfig",value:function(){try{var t=Array.from(document.getElementsByTagName("script")).reverse().find(function(t){return t.dataset&&(t.dataset.appId||t.dataset.agentId)||t.src&&t.src.includes("agent-widget")});return t?{appId:t.dataset.appId,agentId:t.dataset.agentId}:{}}catch(t){return{}}}},{key:"buildWebSocketUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,e=new URLSearchParams;return this.config.appId&&e.append("appId",this.config.appId),this.config.agentId&&e.append("agentId",this.config.agentId),this.config.conversationId&&e.append("conversationId",this.config.conversationId),"".concat(t,"?").concat(e.toString())}},{key:"sendMessage",value:(i=ht().m(function t(e){var n=this;return ht().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,o){if(e&&e.trim())if(n.config.appId&&n.config.agentId){var i={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(i):n.executeTask(i)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){yt(r,n,o,a,c,"next",t)}function c(t){yt(r,n,o,a,c,"throw",t)}a(void 0)})},function(t){return r.apply(this,arguments)})},{key:"executeTask",value:function(t){var e=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,i=this.buildWebSocketUrl(this.config.baseWsUrl),r=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(r),c=!1,s=!1,l=null,u=function(n){if(!s)try{var o={message:t.text},i=e.config.forceConversationId||e.config.conversationId;i&&(o.conversationId=i,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=i,e.persistConversationId(i))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",e.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){t.reject(o),e.emit("error",o);try{n.close()}catch(t){}}},d=function(t){return function(){e.config.conversationId?u(t):l=setTimeout(function(){return u(t)},200)}},f=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(t){}var i=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",i)}catch(t){}if("hello"===i.type&&i.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",i.conversationId),e.config.conversationId=i.conversationId,e.persistConversationId(i.conversationId),e.emit&&e.emit("conversationIdChanged",i.conversationId),!s&&n&&1===n.readyState){if(l)try{clearTimeout(l)}catch(t){}u(n)}return}if(!e.config.conversationId&&i.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",i.conversationId),e.config.conversationId=i.conversationId,e.persistConversationId(i.conversationId)),"chunk"===i.type&&"string"==typeof i.content)e.fullResponseBuffer+=i.content,e.emit("chunk",i.content);else if("done"===i.type){try{var r=i.text||i.content||i.answer||i.message||"";r&&!e.fullResponseBuffer&&(e.fullResponseBuffer=r)}catch(t){}!e.config.conversationId&&i.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",i.conversationId),e.config.conversationId=i.conversationId),e.persistConversationId(e.config.conversationId),e.emit("done",{text:e.fullResponseBuffer}),t.resolve({conversationId:e.config.conversationId,fullText:e.fullResponseBuffer});try{n.close()}catch(t){}}else if("error"===i.type){var a=new Error(i.message||"Server error");e.emit("error",a),t.reject(a);try{n.close()}catch(t){}}}catch(t){}}},p=function(n){if(1008===n.code&&n.reason&&(n.reason.includes("Domain not whitelisted")||n.reason.includes("domain")||n.reason.includes("whitelist"))){var o=new Error("DOMAIN_NOT_WHITELISTED");return o.reason=n.reason,o.code=n.code,e.emit("domainError",o),t.reject(o),e.config.inFlight=!1,void e.drainQueue()}e.config.inFlight=!1,e.drainQueue()},v=new WebSocket(i);v.onopen=d(v),v.onmessage=f(v),v.onerror=(o=v,function(n){if(!c){c=!0;try{o.close()}catch(t){}var i=new WebSocket(a);return i.onopen=d(i),i.onmessage=f(i),i.onerror=function(n){e.emit("error",n),t.reject(n)},void(i.onclose=p)}e.emit("error",n),t.reject(n)}),v.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=bt(bt({},this.config),t)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&wt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c),Et=n(540),jt=n(848);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 Bt(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 Pt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Bt(Object(n),!0).forEach(function(e){Ft(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Bt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ft(t,e,n){return(e=function(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+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Dt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return At(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(At(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,At(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,At(d,"constructor",l),At(l,"constructor",s),s.displayName="GeneratorFunction",At(l,i,"GeneratorFunction"),At(d),At(d,i,"Generator"),At(d,o,function(){return this}),At(d,"toString",function(){return"[object Generator]"}),(Dt=function(){return{w:r,m:f}})()}function At(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}At=function(t,e,n,o){function r(e,n){At(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},At(t,e,n,o)}function _t(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Mt(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,i,r,a,c=[],s=!0,l=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){l=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw i}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Rt(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)?Rt(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 Rt(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 zt=function(t){var e=t.websocketUrl,n=t.agentId,o=t.voice,i=void 0===o?"default":o,r=t.language,a=void 0===r?"en":r,c=t.autoReconnect,s=void 0===c||c,l=t.onConnected,u=t.onDisconnected,d=t.onRecordingStarted,f=t.onRecordingStopped,p=t.onPlaybackStarted,v=t.onPlaybackStopped,h=t.onError,g=t.onMessage,y=t.onBargeIn,m=t.onStopPlaying,b=t.className,x=void 0===b?"":b,w=t.style,S=void 0===w?{}:w,k=t.children,C=Mt((0,Et.useState)(!1),2),I=C[0],O=C[1],E=Mt((0,Et.useState)(!1),2),j=E[0],T=E[1],B=Mt((0,Et.useState)(!1),2),P=(B[0],B[1]),F=Mt((0,Et.useState)("Disconnected"),2),D=(F[0],F[1]),A=(0,Et.useRef)(null);(0,Et.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),A.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),A.current.destroy(),A.current=null);var t=new pt({websocketUrl:e,agentId:n,voice:i,language:a,autoReconnect:s});return t.on("connected",function(){O(!0),D("Connected"),null==l||l()}),t.on("disconnected",function(){O(!1),D("Disconnected"),null==u||u()}),t.on("recordingStarted",function(){T(!0),null==d||d()}),t.on("recordingStopped",function(){T(!1),null==f||f()}),t.on("playbackStarted",function(){P(!0),null==p||p()}),t.on("playbackStopped",function(){P(!1),null==v||v()}),t.on("error",function(t){null==h||h(t)}),t.on("message",function(t){null==g||g(t)}),t.on("bargeIn",function(t){null==y||y(t)}),t.on("stopPlaying",function(t){null==m||m(t)}),A.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),A.current&&(A.current.destroy(),A.current=null)}},[e,n,i,a]);var _=function(){var t,e=(t=Dt().m(function t(){var e;return Dt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(A.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,A.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){_t(r,o,i,a,c,"next",t)}function c(t){_t(r,o,i,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),M=(0,jt.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,jt.jsx)("div",{style:{fontSize:"20px"},children:j?"🔴":"🎤"}),(0,jt.jsx)("div",{children:j?"Stop Listening":"Start Listening"})]});return(0,jt.jsx)("button",{className:"voice-button ".concat(j?"recording":""," ").concat(x),style:Pt({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:j?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},S),onClick:_,disabled:!I,children:k||M})};function Lt(t){return Lt="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},Lt(t)}function Ht(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Ut(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(Ut(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,Ut(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,Ut(d,"constructor",l),Ut(l,"constructor",s),s.displayName="GeneratorFunction",Ut(l,i,"GeneratorFunction"),Ut(d),Ut(d,i,"Generator"),Ut(d,o,function(){return this}),Ut(d,"toString",function(){return"[object Generator]"}),(Ht=function(){return{w:r,m:f}})()}function Ut(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Ut=function(t,e,n,o){function r(e,n){Ut(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Ut(t,e,n,o)}function Nt(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Kt(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Nt(r,o,i,a,c,"next",t)}function c(t){Nt(r,o,i,a,c,"throw",t)}a(void 0)})}}function Wt(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 Vt(t,e,n){return(e=Qt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Gt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Qt(o.key),o)}}function Qt(t){var e=function(t){if("object"!=Lt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Lt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Lt(e)?e:e+""}var qt=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?Wt(Object(n),!0).forEach(function(e){Vt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Wt(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=Kt(Ht().m(function t(){var e;return Ht().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=Kt(Ht().m(function t(){var e;return Ht().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&&Gt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Yt(t){return Yt="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},Yt(t)}function Jt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return $t(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):($t(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,$t(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,$t(d,"constructor",l),$t(l,"constructor",s),s.displayName="GeneratorFunction",$t(l,i,"GeneratorFunction"),$t(d),$t(d,i,"Generator"),$t(d,o,function(){return this}),$t(d,"toString",function(){return"[object Generator]"}),(Jt=function(){return{w:r,m:f}})()}function $t(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}$t=function(t,e,n,o){function r(e,n){$t(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},$t(t,e,n,o)}function Xt(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Zt(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Xt(r,o,i,a,c,"next",t)}function c(t){Xt(r,o,i,a,c,"throw",t)}a(void 0)})}}function te(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,ee(o.key),o)}}function ee(t){var e=function(t){if("object"!=Yt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Yt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Yt(e)?e:e+""}var ne=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),console.log("🚀 AgentSDK v2.1.8 initialized with config:",e),this.config=e,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(t){return console.error("SDK Error:",t)},this.onTranscript=function(t){},this.onAgentSpeaking=function(t){}},e=[{key:"connect",value:(o=Zt(Jt().m(function t(e){var n,o=this;return Jt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,e){t.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new pt({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en"}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(t){if(o.isConnected=!1,t&&1008===t.code&&t.reason&&(t.reason.includes("Domain not whitelisted")||t.reason.includes("domain")||t.reason.includes("whitelist"))){var e=new Error("DOMAIN_NOT_WHITELISTED");e.reason=t.reason,e.code=t.code,o.onError(e)}o.onDisconnected()}),this.voiceSDK.on("domainError",function(t){o.onError(t)}),this.voiceSDK.on("error",function(t){o.onError(t)}),this.voiceSDK.on("message",function(t){o.handleWebSocketMessage(t)}),this.voiceSDK.on("recordingStarted",function(){o.isListening=!0}),this.voiceSDK.on("recordingStopped",function(){o.isListening=!1}),this.voiceSDK.on("playbackStarted",function(){o.onAgentSpeaking(!0)}),this.voiceSDK.on("playbackStopped",function(){o.onAgentSpeaking(!1)}),t.n=2,this.voiceSDK.connect();case 2:t.n=4;break;case 3:throw t.p=3,n=t.v,this.onError(n),n;case 4:return t.a(2)}},t,this,[[0,3]])})),function(t){return o.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(t){switch(t.type){case"connected":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text);break;case"agent_response":case"barge_in":case"stop_playing":break;case"error":this.onError(new Error(t.message))}}},{key:"startListening",value:(n=Zt(Jt().m(function t(){var e;return Jt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){t.n=5;break}return t.p=1,console.log("🎤 AgentSDK: Starting recording..."),t.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),t.n=4;break;case 3:throw t.p=3,e=t.v,console.error("❌ AgentSDK: Failed to start recording:",e),e;case 4:t.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(t){this.voiceSDK&&this.isConnected&&this.voiceSDK.webSocketManager.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],e&&te(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();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 ie(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return re(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(re(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,re(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,re(d,"constructor",l),re(l,"constructor",s),s.displayName="GeneratorFunction",re(l,i,"GeneratorFunction"),re(d),re(d,i,"Generator"),re(d,o,function(){return this}),re(d,"toString",function(){return"[object Generator]"}),(ie=function(){return{w:r,m:f}})()}function re(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}re=function(t,e,n,o){function r(e,n){re(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},re(t,e,n,o)}function ae(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function ce(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ae(r,o,i,a,c,"next",t)}function c(t){ae(r,o,i,a,c,"throw",t)}a(void 0)})}}function se(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,le(o.key),o)}}function le(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+""}var ue=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 ne({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,variables:e.variables||{},language:e.language||"en"}),this.setupSDKEventHandlers()},e=[{key:"setupSDKEventHandlers",value:function(){var t=this;this.sdk.onTranscript=function(e){t.updateTranscript(e)},this.sdk.onAgentSpeaking=function(t){var e=document.getElementById("voiceAvatarActive");e&&(t?e.classList.add("speaking"):e.classList.remove("speaking"))},this.sdk.onError=function(e){console.error("❌ Voice SDK Error:",e),e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))?t.showDomainError():t.showError(e.message||e)}}},{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"getTooltip",value:function(t){var e,n=null===(e=this.config.tooltips)||void 0===e?void 0:e[t];return null!=n?n:{mute:this.t("mute"),speaker:this.t("speaker"),endCall:this.t("endCall")}[t]||""}},{key:"generateHTML",value:function(){return'<div class="voice-interface" id="voiceInterface">\n \x3c!-- Before Call State --\x3e\n <div id="voiceIdleState">\n <div class="voice-avatar" id="voiceAvatar">🤖</div>\n <div class="voice-status">\n <div class="voice-status-title">'.concat(this.t("clickToStartCall"),'</div>\n <div class="voice-status-subtitle">').concat(this.t("realTimeVoice"),'</div>\n </div>\n <button class="start-call-btn" id="startCallBtn">\n <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">\n <path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56-.35-.12-.74-.03-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"/>\n </svg>\n <span>').concat(this.t("startCall"),'</span>\n </button>\n </div>\n \x3c!-- During Call State --\x3e\n <div id="voiceActiveState" style="display: none;">\n <div class="voice-avatar-active" id="voiceAvatarActive">\n <div class="voice-rings">\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n </div>\n 🤖\n </div>\n <div class="voice-status">\n <div class="voice-status-title" id="voiceStatusTitleActive">').concat(this.t("listening"),'</div>\n <div class="voice-status-subtitle" id="voiceStatusSubtitleActive">').concat(this.t("speakFreely"),'</div>\n </div>\n <div class="voice-transcript">\n <div class="transcript-label">').concat(this.t("liveTranscript"),'</div>\n <div class="transcript-text empty" id="transcriptText">\n ').concat(this.t("transcriptWillAppear"),'\n </div>\n </div>\n <div class="voice-controls">\n <button class="voice-control-btn secondary" id="muteBtn" title="').concat(this.getTooltip("mute"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="mute-icon">\n <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>\n <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>\n <line x1="12" y1="19" x2="12" y2="23"/>\n <line x1="8" y1="23" x2="16" y2="23"/>\n <line x1="2" y1="2" x2="22" y2="22" class="mute-cross" style="display: none; stroke: #ef4444; stroke-width: 3.5;"/>\n </svg>\n </button>\n <button class="voice-control-btn primary active" id="endCallBtn" title="').concat(this.getTooltip("endCall"),'">\n <svg width="56" height="56" viewBox="0 0 24 24" fill="#ef4444">\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n </svg>\n <div class="voice-timer" id="voiceTimer">00:00</div>\n </button>\n <button class="voice-control-btn secondary" id="speakerBtn" title="').concat(this.getTooltip("speaker"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">\n <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/>\n <path d="M19.07 4.93a10 10 0 0 1 0 14.14"/>\n <path d="M15.54 8.46a5 5 0 0 1 0 7.07"/>\n </svg>\n </button>\n </div>\n </div>\n </div>')}},{key:"generateCSS",value:function(){var t=this.config.avatarBackgroundColor||"#667eea",e=this.config.avatarActiveBackgroundColor||this.config.avatarBackgroundColor||"#667eea",n=this.config.statusTitleColor||"#1e293b",o=this.config.statusSubtitleColor||"#64748b",i=this.config.startCallButtonColor||"#667eea",r=this.config.startCallButtonTextColor||"#FFFFFF",a=this.config.transcriptBackgroundColor||"#FFFFFF",c=this.config.transcriptTextColor||"#1e293b",s=this.config.transcriptLabelColor||"#94a3b8",l=this.config.controlButtonColor||"#FFFFFF",u=this.config.controlButtonSecondaryColor||"#64748b";return this.config.endCallButtonColor,'\n /* Voice Interface Styles - Better iframe compatibility */\n .voice-interface { \n display: none; \n flex: 1; \n flex-direction: column;\n align-items: center; \n justify-content: center; \n padding: 12px 16px; \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 - Use flexbox to distribute space */\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(8px, 2vh, 16px);\n }\n \n #voiceActiveState[style*="display: none"] {\n display: none !important;\n }\n \n /* Voice Avatar - Scale based on available height */\n .voice-avatar,\n .voice-avatar-active {\n width: min(25vh, 180px, 40vw);\n height: min(25vh, 180px, 40vw);\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: min(12vh, 80px, 20vw);\n margin: 0;\n box-shadow: 0 10px 40px 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 box-shadow: 0 10px 40px rgba(102, 126, 234, 0.3);\n }\n 50% { \n transform: scale(1.05);\n box-shadow: 0 15px 50px rgba(102, 126, 234, 0.5);\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 */\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(14px, 3.5vh, 22px);\n font-weight: 600;\n color: ").concat(n,";\n margin-bottom: 4px;\n line-height: 1.2;\n }\n \n .voice-status-subtitle {\n font-size: clamp(11px, 2.2vh, 15px);\n color: ").concat(o,";\n line-height: 1.3;\n }\n \n /* Start Call Button */\n .start-call-btn {\n margin: 0;\n width: min(280px, 70vw);\n height: clamp(48px, 8vh, 64px);\n border-radius: clamp(24px, 4vh, 32px);\n border: none;\n background: ").concat(i,";\n color: ").concat(r,";\n font-size: clamp(14px, 2.5vh, 18px);\n font-weight: 600;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 10px;\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(24px, 4vh, 32px);\n height: clamp(24px, 4vh, 32px);\n }\n \n .start-call-btn:hover {\n transform: translateY(-4px);\n box-shadow: 0 16px 40px rgba(102, 126, 234, 0.5);\n }\n \n .start-call-btn:active {\n transform: translateY(-2px);\n }\n \n /* Voice Transcript - More flexible sizing */\n .voice-transcript {\n background: ").concat(a,";\n padding: clamp(8px, 1.5vh, 14px);\n border-radius: 12px;\n width: min(360px, 85vw);\n margin: 0;\n min-height: clamp(60px, 12vh, 90px);\n max-height: clamp(80px, 18vh, 120px);\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n flex-shrink: 1;\n overflow-y: auto;\n display: flex;\n flex-direction: column;\n }\n \n .transcript-label {\n font-size: clamp(9px, 1.6vh, 11px);\n color: ").concat(s,";\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n margin-bottom: 6px;\n flex-shrink: 0;\n }\n \n .transcript-text {\n font-size: clamp(12px, 2.2vh, 15px);\n color: ").concat(c,";\n line-height: 1.4;\n flex: 1;\n overflow-y: auto;\n }\n \n .transcript-text.empty {\n color: #cbd5e1;\n font-style: italic;\n }\n \n /* Voice Controls */\n .voice-controls {\n display: flex;\n gap: clamp(12px, 2vh, 16px);\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n margin: 0;\n padding-top: clamp(8px, 1.5vh, 12px);\n }\n \n .voice-control-btn {\n width: clamp(56px, 10vh, 80px);\n height: clamp(56px, 10vh, 80px);\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: 50%;\n height: 50%;\n }\n \n .voice-control-btn.primary {\n width: clamp(64px, 11vh, 88px);\n height: clamp(64px, 11vh, 88px);\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);\n }\n \n .voice-control-btn.primary:hover {\n transform: scale(1.05);\n box-shadow: 0 10px 25px rgba(102, 126, 234, 0.5);\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 8px 20px rgba(239, 68, 68, 0.4);\n }\n 50% { \n box-shadow: 0 8px 30px rgba(239, 68, 68, 0.7);\n }\n }\n \n .voice-control-btn.secondary {\n background: ").concat(l,";\n color: ").concat(u,";\n box-shadow: 0 4px 12px 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: -24px;\n font-size: clamp(10px, 1.8vh, 13px);\n color: #64748b;\n font-weight: 500;\n white-space: nowrap;\n }\n \n @media (max-width: 768px) {\n .voice-interface {\n padding: 8px 12px 16px 12px;\n }\n \n .voice-avatar,\n .voice-avatar-active {\n width: 100px;\n height: 100px;\n font-size: 48px;\n margin-top: 8px;\n margin-bottom: 12px;\n }\n \n .voice-status-title {\n font-size: 16px;\n }\n \n .voice-status-subtitle {\n font-size: 13px;\n }\n \n .voice-start-call-btn {\n padding: 12px 24px;\n font-size: 15px;\n min-height: 44px;\n }\n \n .voice-transcript-container {\n padding: 12px;\n max-height: 180px;\n }\n \n .voice-transcript-text {\n font-size: 14px;\n line-height: 1.5;\n }\n \n .voice-controls {\n gap: 12px;\n padding: 12px;\n }\n \n .voice-control-btn {\n width: 48px;\n height: 48px;\n min-width: 48px;\n min-height: 48px;\n }\n \n .voice-control-btn.end-call {\n width: 52px;\n height: 52px;\n min-width: 52px;\n min-height: 52px;\n }\n }\n \n @media (max-width: 480px) {\n .voice-interface {\n padding: 6px 10px 12px 10px;\n }\n \n .voice-avatar,\n .voice-avatar-active {\n width: 90px;\n height: 90px;\n font-size: 42px;\n }\n \n .voice-status-title {\n font-size: 15px;\n }\n \n .voice-status-subtitle {\n font-size: 12px;\n }\n \n .voice-start-call-btn {\n padding: 10px 20px;\n font-size: 14px;\n }\n \n .voice-transcript-container {\n padding: 10px;\n max-height: 150px;\n }\n \n .voice-transcript-text {\n font-size: 13px;\n }\n \n .voice-controls {\n gap: 10px;\n padding: 10px;\n }\n \n .voice-control-btn {\n width: 44px;\n height: 44px;\n min-width: 44px;\n min-height: 44px;\n }\n \n .voice-control-btn.end-call {\n width: 48px;\n height: 48px;\n min-width: 48px;\n min-height: 48px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(t){var e=this,n=document.getElementById("startCallBtn"),o=document.getElementById("endCallBtn"),i=document.getElementById("muteBtn"),r=document.getElementById("speakerBtn");n&&(n.onclick=function(){return e.startVoiceCall()}),o&&(o.onclick=function(){return e.endVoiceCall()}),i&&(i.onclick=function(){return e.toggleMute()}),r&&(r.onclick=function(){return e.toggleSpeaker()})}},{key:"getSignedUrl",value:(o=ce(ie().m(function t(){var e,n,o,i,r,a,c;return ie().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((i=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(i.statusText));case 4:return t.n=5,i.json();case 5:return r=t.v,t.a(2,r.signedUrl||r.wsUrl||r.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"startVoiceCall",value:(n=ce(ie().m(function t(){var e,n,o,i,r,a,c,s,l,u=this;return ie().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"),o&&(o.scrollTop=0),t.n=3,this.getSignedUrl();case 3:return i=t.v,console.log("🔗 Got signed URL:",i),t.n=4,this.sdk.connect(i);case 4:r=t.v,console.log("✅ Connected to WebSocket, connected:",r),a=0;case 5:if(this.sdk.isConnected||!(a<50)){t.n=7;break}return t.n=6,new Promise(function(t){return setTimeout(t,100)});case 6:a++,t.n=5;break;case 7:if(!this.sdk.isConnected){t.n=9;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=8,this.sdk.startListening();case 8:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-u.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()-u.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,l=t.v,console.error("❌ Error starting voice call:",l),this.showError(l.message||l),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(){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 t=document.getElementById("voiceIdleState"),e=document.getElementById("voiceActiveState");t&&(t.style.display="flex"),e&&(e.style.display="none");var n=document.getElementById("transcriptText");n&&(n.textContent=this.t("transcriptWillAppear"),n.classList.add("empty"));var o=document.getElementById("voiceAvatarActive");o&&o.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&&se(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();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(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return pe(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(pe(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,pe(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,pe(d,"constructor",l),pe(l,"constructor",s),s.displayName="GeneratorFunction",pe(l,i,"GeneratorFunction"),pe(d),pe(d,i,"Generator"),pe(d,o,function(){return this}),pe(d,"toString",function(){return"[object Generator]"}),(fe=function(){return{w:r,m:f}})()}function pe(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}pe=function(t,e,n,o){function r(e,n){pe(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},pe(t,e,n,o)}function ve(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function he(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ve(r,o,i,a,c,"next",t)}function c(t){ve(r,o,i,a,c,"throw",t)}a(void 0)})}}function ge(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ye(o.key),o)}}function ye(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+""}var me=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.sdk=n,this.streamingEl=null,this.hasStartedStreaming=!1,this.isActive=!1,this.eventHandlers={autoResize:null,keydown:null},this.eventHandlersSetup=!1},e=[{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"generateHTML",value:function(){var t,e,n,o,i,r,a,c,s,l=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(l,'" rows="1" dir="').concat(this.config.direction||"ltr",'"></textarea>\n </div>\n <button class="send-button" id="sendButton" aria-label="').concat(this.t("sendMessageAria"),'">').concat(this.config.sendButtonText||"➤","</button>\n ").concat(null!==(e=this.config.sendButtonHint)&&void 0!==e&&e.text||null!==(n=this.config.panel)&&void 0!==n&&null!==(n=n.sendButtonHint)&&void 0!==n&&n.text?'\n <div class="send-button-hint" style="color: '.concat((null===(o=this.config.sendButtonHint)||void 0===o?void 0:o.color)||(null===(i=this.config.panel)||void 0===i||null===(i=i.sendButtonHint)||void 0===i?void 0:i.color)||"#6B7280","; font-size: ").concat((null===(r=this.config.sendButtonHint)||void 0===r?void 0:r.fontSize)||(null===(a=this.config.panel)||void 0===a||null===(a=a.sendButtonHint)||void 0===a?void 0:a.fontSize)||"12px",'; text-align: center; margin-top: 4px;">\n ').concat((null===(c=this.config.sendButtonHint)||void 0===c?void 0:c.text)||(null===(s=this.config.panel)||void 0===s||null===(s=s.sendButtonHint)||void 0===s?void 0:s.text),"\n </div>\n "):"","\n </div>\n </div>")}},{key:"generateCSS",value:function(){var t,e,n,o,i,r,a,c,s,l,u,d,f,p=this.config.messages,v=(this.config.panel,this.config.animation,this.config.sendButtonColor||(null===(t=this.config.panel)||void 0===t?void 0:t.sendButtonColor)||"#7C3AED"),h=this.config.sendButtonHoverColor||(null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonHoverColor)||"#6D28D9",g=this.config.sendButtonTextColor||(null===(n=this.config.panel)||void 0===n?void 0:n.sendButtonTextColor)||"#FFFFFF",y=(this.config.inputPlaceholder||null===(o=this.config.panel)||void 0===o||o.inputPlaceholder,this.config.inputBorderColor||(null===(i=this.config.panel)||void 0===i?void 0:i.inputBorderColor)||"#E5E7EB"),m=this.config.inputFocusColor||(null===(r=this.config.panel)||void 0===r?void 0:r.inputFocusColor)||"#7C3AED",b=this.config.inputBackgroundColor||(null===(a=this.config.panel)||void 0===a?void 0:a.inputBackgroundColor)||"#FFFFFF",x=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",S=this.config.inputBorderRadius||(null===(l=this.config.panel)||void 0===l?void 0:l.inputBorderRadius)||20,k=this.config.inputPadding||(null===(u=this.config.panel)||void 0===u?void 0:u.inputPadding)||"6px 14px";return"\n /* Messages container using new classes */\n #messagesContainer { \n flex: 1; \n overflow-y: auto; \n overflow-x: hidden; \n padding: 20px; \n background: #f8fafc; \n display: flex; \n flex-direction: column; \n gap: 16px; \n min-height: 0; \n }\n .empty-state { \n flex: 1; \n display: flex; \n flex-direction: column; \n align-items: center; \n justify-content: center; \n gap: 12px; \n color: #64748b; \n text-align: center; \n padding: 20px; \n }\n .empty-state-icon { font-size: 48px; opacity: 0.3; }\n .empty-state-title { font-size: 20px; font-weight: 700; color: #334155; }\n .empty-state-text { font-size: 13px; max-width: 280px; }\n\n .text-interface { \n display: none; \n flex: 1; \n flex-direction: column; \n min-height: 0; \n overflow: hidden; \n }\n .text-interface.active { display: flex; }\n \n .message { \n display: flex; \n gap: 8px; \n padding: 4px 0; \n max-width: 100%; \n align-items: center; \n }\n .message.edge-left { flex-direction: row; }\n .message.edge-right { flex-direction: row-reverse; }\n .message-bubble { \n padding: 12px; \n border-radius: ".concat(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","; \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(S,"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(x,";\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(v,";\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(h,";\n transform: scale(1.05);\n box-shadow: 0 6px 16px rgba(124, 60, 237, 0.4);\n }\n \n .send-button-hint {\n width: 100%;\n text-align: center;\n margin-top: 4px;\n }\n \n .send-button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n \n .typing-indicator {\n display: inline-flex;\n gap: 4px;\n align-items: center;\n }\n \n .typing-dot {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: #64748b;\n animation: typingDot 1.4s ease-in-out infinite;\n }\n \n .typing-dot:nth-child(2) { animation-delay: 0.2s; }\n .typing-dot:nth-child(3) { animation-delay: 0.4s; }\n \n @keyframes typingDot {\n 0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }\n 30% { transform: translateY(-8px); opacity: 1; }\n }\n \n .error-message {\n padding: 12px;\n background: ").concat(p.errorBackgroundColor,";\n border-radius: ").concat(p.borderRadius,"px;\n color: #991B1B;\n font-size: ").concat(p.fontSize,";\n margin: 8px 0;\n }\n \n @media (max-width: 768px) {\n #messagesContainer {\n padding: 12px;\n gap: 12px;\n }\n \n .message-bubble {\n max-width: 85%;\n font-size: 14px;\n padding: 10px;\n }\n \n .text-input-container {\n padding: 10px;\n gap: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 10px 14px;\n min-height: 44px;\n }\n \n #text-chat-send {\n min-width: 56px;\n min-height: 44px;\n width: 56px;\n height: 44px;\n }\n \n .empty-state-icon {\n font-size: 40px;\n }\n \n .empty-state-title {\n font-size: 18px;\n }\n \n .empty-state-text {\n font-size: 12px;\n }\n }\n \n @media (max-width: 480px) {\n #messagesContainer {\n padding: 10px;\n gap: 10px;\n }\n \n .message-bubble {\n max-width: 90%;\n font-size: 13px;\n padding: 8px;\n }\n \n .text-input-container {\n padding: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important;\n padding: 8px 12px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(){var t=this,e=document.getElementById("sendButton"),n=document.getElementById("messageInput"),o=document.getElementById("newChatBtn");if(e&&(e.onclick=function(){return t.sendMessage()}),o&&(o.onclick=function(){return t.startNewChat()}),this.updateInputAttributes(),n){n.style.height="32px",n.style.overflow="hidden";var i=function(){n.style.height="auto";var t=Math.min(n.scrollHeight,120);n.style.height=t+"px",n.style.overflowY=t>=120?"auto":"hidden",t>=120&&setTimeout(function(){n.scrollTop=n.scrollHeight},0)};n.addEventListener("input",i),n.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey?"Enter"===e.key&&e.shiftKey&&setTimeout(i,0):(e.preventDefault(),t.sendMessage())})}}},{key:"startNewChat",value:function(){try{localStorage.removeItem("ttp_text_chat_conversation_id")}catch(t){}this.sdk&&(this.sdk.config.conversationId=null);var t=document.getElementById("messagesContainer");t&&(t.innerHTML='\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),"</div>\n </div>"));var e=document.getElementById("messageInput");e&&e.focus()}},{key:"updateInputAttributes",value:function(){var t=document.getElementById("messageInput");if(t){var e,n=this.config.inputPlaceholder||(null===(e=this.config.panel)||void 0===e?void 0:e.inputPlaceholder)||this.t("typeMessage")||"Type your message...";t.placeholder=n,t.dir=this.config.direction||"ltr",t.style.textAlign="rtl"===this.config.direction?"right":"left"}}},{key:"show",value:function(){var t=document.getElementById("textInterface");t&&t.classList.add("active"),setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},50)}},{key:"hide",value:function(){var t=document.getElementById("textInterface");t&&t.classList.remove("active")}},{key:"startChat",value:(o=he(fe().m(function t(){return fe().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=he(fe().m(function t(){var e,n,o;return fe().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("messageInput"),n=e.value.trim()){t.n=1;break}return t.a(2);case 1:if(this.isActive){t.n=2;break}return t.n=2,this.startChat();case 2:return this.addMessage("user",n),e.value="",e.style.height="32px",e.style.overflow="hidden",t.p=3,this.beginStreaming(),t.n=4,this.sdk.sendMessage(n);case 4:t.n=6;break;case 5:t.p=5,o=t.v,console.error("❌ Failed to send message:",o),o&&("DOMAIN_NOT_WHITELISTED"===o.message||o.message&&o.message.includes("Domain not whitelisted"))||this.showError(o),this.stopStreamingState();case 6:return t.a(2)}},t,this,[[3,5]])})),function(){return n.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var t=document.getElementById("sendButton");t&&(t.disabled=!this.isActive)}},{key:"addMessage",value:function(t,e){var n=document.getElementById("messagesContainer");if(n){var o=n.querySelector(".empty-state");o&&o.remove();var i=document.createElement("div"),r="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";i.className="message ".concat(t," ").concat(r);var a=document.createElement("div");a.className="message-avatar ".concat(t),a.textContent="user"===t?"👤":"🤖";var c=document.createElement("div");c.className="message-bubble",c.textContent=e,i.appendChild(a),i.appendChild(c),n.appendChild(i),n.scrollTop=n.scrollHeight}}},{key:"beginStreaming",value:function(){var t=document.getElementById("messagesContainer");if(t){this.stopStreamingState();var e=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";e.className="message agent ".concat(n),e.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var i=document.createElement("div");i.className="message-bubble",i.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',e.appendChild(o),e.appendChild(i),t.appendChild(e),this.streamingEl=i,this.hasStartedStreaming=!1,t.scrollTop=t.scrollHeight}}},{key:"appendStreamingChunk",value:function(t){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=t;var e=document.getElementById("messagesContainer");e&&(e.scrollTop=e.scrollHeight)}}},{key:"finalizeStreaming",value:function(t){if(this.streamingEl){this.streamingEl.textContent=t||this.streamingEl.textContent;var e=document.getElementById("agent-streaming");e&&(e.id=""),this.streamingEl=null}this.updateSendButtonState()}},{key:"stopStreamingState",value:function(){var t=document.getElementById("agent-streaming");t&&t.remove(),this.streamingEl=null,this.hasStartedStreaming=!1}},{key:"showError",value:function(t){var e=document.getElementById("messagesContainer");if(e){if(t&&("DOMAIN_NOT_WHITELISTED"===t.message||"string"==typeof t&&t.includes("DOMAIN_NOT_WHITELISTED")||t.message&&t.message.includes("Domain not whitelisted")||"string"==typeof t&&t.includes("Domain not whitelisted"))){var n,o=document.createElement("div");o.className="error-message",o.style.cssText="padding: 16px; margin: 12px; border-radius: 8px; background: "+((null===(n=this.config.messages)||void 0===n?void 0:n.errorBackgroundColor)||"#FEE2E2")+";";var i=document.createElement("div");i.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",i.textContent=this.t("domainNotValidated");var r=document.createElement("div");r.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",r.textContent=this.t("domainErrorMessage"),o.appendChild(i),o.appendChild(r),e.appendChild(o)}else{var a=document.createElement("div");a.className="error-message",a.textContent="string"==typeof t?t:(null==t?void 0:t.message)||t,e.appendChild(a)}e.scrollTop=e.scrollHeight}}},{key:"setActive",value:function(t){this.isActive=t,this.updateSendButtonState()}}],e&&ge(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();const be={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 xe(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return we(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(we(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,we(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,we(d,"constructor",l),we(l,"constructor",s),s.displayName="GeneratorFunction",we(l,i,"GeneratorFunction"),we(d),we(d,i,"Generator"),we(d,o,function(){return this}),we(d,"toString",function(){return"[object Generator]"}),(xe=function(){return{w:r,m:f}})()}function we(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}we=function(t,e,n,o){function r(e,n){we(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},we(t,e,n,o)}function Se(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function ke(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Se(r,o,i,a,c,"next",t)}function c(t){Se(r,o,i,a,c,"throw",t)}a(void 0)})}}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 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 Oe(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){Ee(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 Ee(t,e,n){return(e=Te(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function je(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Te(o.key),o)}}function Te(t){var e=function(t){if("object"!=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+""}var Be=function(){return t=function t(){var e,n,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=this.mergeWithDefaults(o),this.sdk=new Ot(this.config),this.isOpen=!1,this.isActive=!1,this.translations=be,this.currentView="landing";var i=Oe(Oe(Oe({},this.config),this.config.voice),{},{language:(null===(e=this.config.voice)||void 0===e?void 0:e.language)||this.config.language||"en",websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations});this.voiceInterface=new ue(i);var r=Oe(Oe(Oe({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new me(r,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var a=document.getElementById("text-chat-panel");a&&(this.isOpen=!0,a.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,i,r,a,c,s,l,u,d,f,p,v,h,g,y,m,b,x,w,S,k,C,I,O,E,j,T,B,P,F,D,A,_,M,R,z,L,H,U,N,K,W,V,G,Q,q,Y,J,$,X,Z,tt,et,nt,ot,it,rt,at,ct,st,lt,ut,dt,ft,pt,vt,ht,gt,yt,mt,bt,xt,wt,St,kt,Ct,It,Ot,Et,jt,Tt,Bt,Pt,Ft,Dt,At,_t,Mt,Rt,zt,Lt,Ht,Ut,Nt,Kt,Wt,Vt,Gt,Qt,qt,Yt,Jt,$t,Xt,Zt,te,ee,ne,oe,ie,re,ae,ce,se,le,ue,de,fe,pe,ve,he,ge,ye,me,be,xe,we,Se,ke,Ie,Ee,je,Te=t.position||"bottom-right";if("string"==typeof Te){var Be=Te.split("-");Te={vertical:Be[0]||"bottom",horizontal:Be[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var Pe=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",Fe=(null===(o=t.header)||void 0===o?void 0:o.backgroundColor)||(null===(i=t.button)||void 0===i?void 0:i.backgroundColor)||Pe;return Oe({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:Oe({type:(null===(r=t.icon)||void 0===r?void 0:r.type)||"custom",customImage:(null===(a=t.icon)||void 0===a?void 0:a.customImage)||"https://talktopc.com/logo192.png",emoji:(null===(c=t.icon)||void 0===c?void 0:c.emoji)||"🎤",text:(null===(s=t.icon)||void 0===s?void 0:s.text)||"AI",size:(null===(l=t.icon)||void 0===l?void 0:l.size)||"medium",backgroundColor:(null===(u=t.icon)||void 0===u?void 0:u.backgroundColor)||"#FFFFFF"},t.icon),position:Oe({vertical:Te.vertical||"bottom",horizontal:Te.horizontal||"right",offset:Te.offset||{x:20,y:20}},"object"===Ce(t.position)?t.position:{}),button:Oe({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===(v=t.icon)||void 0===v?void 0:v.backgroundColor)||Pe,hoverColor:(null===(h=t.button)||void 0===h?void 0:h.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)||Pe},t.button),panel:Oe({width:(null===(x=t.panel)||void 0===x?void 0:x.width)||350,height:(null===(w=t.panel)||void 0===w?void 0:w.height)||500,borderRadius:(null===(S=t.panel)||void 0===S?void 0:S.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===(I=t.panel)||void 0===I?void 0:I.border)||"1px solid rgba(0,0,0,0.1)"},t.panel),voice:Oe({micButtonColor:(null===(O=t.voice)||void 0===O?void 0:O.micButtonColor)||(null===(E=t.panel)||void 0===E?void 0:E.micButtonColor)||Pe,micButtonActiveColor:(null===(j=t.voice)||void 0===j?void 0:j.micButtonActiveColor)||(null===(T=t.panel)||void 0===T?void 0:T.micButtonActiveColor)||"#EF4444",micButtonHint:Oe(Oe({text:(null===(B=t.voice)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.text)||(null===(P=t.panel)||void 0===P||null===(P=P.micButtonHint)||void 0===P?void 0:P.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===(A=t.voice)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.fontSize)||(null===(_=t.panel)||void 0===_||null===(_=_.micButtonHint)||void 0===_?void 0:_.fontSize)||"12px"},null===(M=t.voice)||void 0===M?void 0:M.micButtonHint),null===(R=t.panel)||void 0===R?void 0:R.micButtonHint),avatarBackgroundColor:(null===(z=t.voice)||void 0===z?void 0:z.avatarBackgroundColor)||"#667eea",avatarActiveBackgroundColor:(null===(L=t.voice)||void 0===L?void 0:L.avatarActiveBackgroundColor)||"#667eea",statusTitleColor:(null===(H=t.voice)||void 0===H?void 0:H.statusTitleColor)||"#1e293b",statusSubtitleColor:(null===(U=t.voice)||void 0===U?void 0:U.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(N=t.voice)||void 0===N?void 0:N.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(K=t.voice)||void 0===K?void 0:K.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(W=t.voice)||void 0===W?void 0:W.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(V=t.voice)||void 0===V?void 0:V.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===(Y=t.voice)||void 0===Y?void 0:Y.endCallButtonColor)||"#ef4444",language:(null===(J=t.voice)||void 0===J?void 0:J.language)||t.language||"en",websocketUrl:(null===($=t.voice)||void 0===$?void 0:$.websocketUrl)||t.websocketUrl},t.voice),text:Oe({sendButtonColor:(null===(X=t.text)||void 0===X?void 0:X.sendButtonColor)||(null===(Z=t.panel)||void 0===Z?void 0:Z.sendButtonColor)||"#7C3AED",sendButtonHoverColor:(null===(tt=t.text)||void 0===tt?void 0:tt.sendButtonHoverColor)||(null===(et=t.panel)||void 0===et?void 0:et.sendButtonHoverColor)||"#6D28D9",sendButtonActiveColor:(null===(nt=t.text)||void 0===nt?void 0:nt.sendButtonActiveColor)||(null===(ot=t.panel)||void 0===ot?void 0:ot.sendButtonActiveColor)||"#6D28D9",sendButtonText:(null===(it=t.text)||void 0===it?void 0:it.sendButtonText)||(null===(rt=t.panel)||void 0===rt?void 0:rt.sendButtonText)||"➤",sendButtonTextColor:(null===(at=t.text)||void 0===at?void 0:at.sendButtonTextColor)||(null===(ct=t.panel)||void 0===ct?void 0:ct.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(st=t.text)||void 0===st?void 0:st.sendButtonFontSize)||(null===(lt=t.panel)||void 0===lt?void 0:lt.sendButtonFontSize)||"18px",sendButtonFontWeight:(null===(ut=t.text)||void 0===ut?void 0:ut.sendButtonFontWeight)||(null===(dt=t.panel)||void 0===dt?void 0:dt.sendButtonFontWeight)||"500",sendButtonHint:Oe(Oe({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===(vt=t.text)||void 0===vt||null===(vt=vt.sendButtonHint)||void 0===vt?void 0:vt.color)||(null===(ht=t.panel)||void 0===ht||null===(ht=ht.sendButtonHint)||void 0===ht?void 0:ht.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===(xt=t.text)||void 0===xt?void 0:xt.inputPlaceholder)||(null===(wt=t.panel)||void 0===wt?void 0:wt.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(St=t.text)||void 0===St?void 0:St.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===(It=t.panel)||void 0===It?void 0:It.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===(jt=t.text)||void 0===jt?void 0:jt.inputTextColor)||(null===(Tt=t.panel)||void 0===Tt?void 0:Tt.inputTextColor)||"#1F2937",inputFontSize:(null===(Bt=t.text)||void 0===Bt?void 0:Bt.inputFontSize)||(null===(Pt=t.panel)||void 0===Pt?void 0:Pt.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===(At=t.text)||void 0===At?void 0:At.inputPadding)||(null===(_t=t.panel)||void 0===_t?void 0:_t.inputPadding)||"6px 14px"},t.text),landing:Oe({backgroundColor:(null===(Mt=t.landing)||void 0===Mt?void 0:Mt.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)",logo:(null===(Rt=t.landing)||void 0===Rt?void 0:Rt.logo)||"🤖",title:(null===(zt=t.landing)||void 0===zt?void 0:zt.title)||null,titleColor:(null===(Lt=t.landing)||void 0===Lt?void 0:Lt.titleColor)||"#1e293b",modeCardBackgroundColor:(null===(Ht=t.landing)||void 0===Ht?void 0:Ht.modeCardBackgroundColor)||"#FFFFFF",modeCardBorderColor:(null===(Ut=t.landing)||void 0===Ut?void 0:Ut.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Nt=t.landing)||void 0===Nt?void 0:Nt.modeCardHoverBorderColor)||Fe,modeCardIconBackgroundColor:(null===(Kt=t.landing)||void 0===Kt?void 0:Kt.modeCardIconBackgroundColor)||Fe,modeCardTitleColor:(null===(Wt=t.landing)||void 0===Wt?void 0:Wt.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(Vt=t.landing)||void 0===Vt?void 0:Vt.voiceCardIcon)||"🎤",textCardIcon:(null===(Gt=t.landing)||void 0===Gt?void 0:Gt.textCardIcon)||"💬"},t.landing),header:Oe({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===(Yt=t.header)||void 0===Yt?void 0:Yt.backgroundColor)||(null===(Jt=t.button)||void 0===Jt?void 0:Jt.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:Oe({newChat:(null===(Zt=t.tooltips)||void 0===Zt?void 0:Zt.newChat)||null,back:(null===(te=t.tooltips)||void 0===te?void 0:te.back)||null,close:(null===(ee=t.tooltips)||void 0===ee?void 0:ee.close)||null,mute:(null===(ne=t.tooltips)||void 0===ne?void 0:ne.mute)||null,speaker:(null===(oe=t.tooltips)||void 0===oe?void 0:oe.speaker)||null,endCall:(null===(ie=t.tooltips)||void 0===ie?void 0:ie.endCall)||null},t.tooltips),messages:Oe({userBackgroundColor:(null===(re=t.messages)||void 0===re?void 0:re.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(ae=t.messages)||void 0===ae?void 0:ae.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(ce=t.messages)||void 0===ce?void 0:ce.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(se=t.messages)||void 0===se?void 0:se.errorBackgroundColor)||"#FEE2E2",textColor:(null===(le=t.messages)||void 0===le?void 0:le.textColor)||"#1F2937",fontSize:(null===(ue=t.messages)||void 0===ue?void 0:ue.fontSize)||"14px",borderRadius:(null===(de=t.messages)||void 0===de?void 0:de.borderRadius)||8},t.messages),animation:Oe({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===(ve=t.animation)||void 0===ve?void 0:ve.enableSlide),duration:(null===(he=t.animation)||void 0===he?void 0:he.duration)||.3},t.animation),behavior:Oe({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===(xe=t.behavior)||void 0===xe?void 0:xe.showWelcomeMessage),welcomeMessage:(null===(we=t.behavior)||void 0===we?void 0:we.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:void 0===(null===(Se=t.behavior)||void 0===Se?void 0:Se.enableVoiceMode)||t.behavior.enableVoiceMode,mode:(null===(ke=t.behavior)||void 0===ke?void 0:ke.mode)||"unified"},t.behavior),accessibility:Oe({ariaLabel:(null===(Ie=t.accessibility)||void 0===Ie?void 0:Ie.ariaLabel)||"Chat Assistant",ariaDescription:(null===(Ee=t.accessibility)||void 0===Ee?void 0:Ee.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(je=t.accessibility)||void 0===je?void 0:je.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},forceConversationId:t.forceConversationId,primaryColor:Pe},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.on("domainError",function(e){t.textInterface.showError(e),t.textInterface.stopStreamingState()}),this.sdk.on("error",function(e){e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))||(t.textInterface.showError(e.message||e),t.textInterface.stopStreamingState())}),this.sdk.on("chunk",function(e){t.textInterface.appendStreamingChunk(e)}),this.sdk.on("done",function(e){var n=e.text;t.textInterface.finalizeStreaming(n)})}},{key:"createWidget",value:function(){console.log("🏗️ createWidget called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var t=document.getElementById("text-chat-widget");t&&t.remove();var e=document.createElement("div");if(e.id="text-chat-widget",e.innerHTML=this.generateWidgetHTML(),document.body.appendChild(e),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("text-chat-panel");n&&(this.isOpen=!0,n.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){var t=this,e=(this.config.position,this.config.button),n=this.config.icon,o=(this.config.panel,this.config.header),i=(this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),r={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(r),s=this.config.behavior.mode||"unified",l="unified"===s,u="unified"===s||"voice-only"===s,d="unified"===s||"text-only"===s,f=function(e){var n=t.config.language||"en";return(t.translations[n]||t.translations.en)[e]||e},p=function(e){var n,o=null===(n=t.config.tooltips)||void 0===n?void 0:n[e];return null!=o?o:{newChat:f("newChat"),back:f("back"),close:f("close"),mute:f("mute"),speaker:f("speaker"),endCall:f("endCall")}[e]||""};return"\n <style>\n ".concat(this.generateCSS(a,i,r),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header" style="background: ').concat(o.backgroundColor,"; color: ").concat(o.textColor,';">\n <div>\n ').concat(o.showTitle?'<div class="header-title">'.concat(o.title,"</div>"):"",'\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat(f("online"),'</span>\n </div>\n </div>\n \n <div style="display: flex; gap: 12px; align-items: center;">\n \x3c!-- New Chat Button (hide on landing screen, show otherwise) --\x3e\n <button class="header-icon new-chat-btn" id="newChatBtn" title="').concat(p("newChat"),'" style="').concat(l?"display: none;":"",'">\n <span style="font-size: 18px; font-weight: bold;">+</span>\n </button>\n \n \x3c!-- Back Button (only show in unified mode) --\x3e\n ').concat("unified"===s?'<button class="header-icon back-btn" id="backBtn" title="'.concat(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(l?'\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(u?'<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(u?this.voiceInterface.generateHTML():"","\n ").concat(d?this.textInterface.generateHTML():"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var t=this.config.position,e=t.offset||{x:20,y:20},n="";return"top"===t.vertical?n+="top: ".concat(e.y,"px;"):"bottom"===t.vertical?n+="bottom: ".concat(e.y,"px;"):"center"===t.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===t.horizontal?n+="left: ".concat(e.x,"px;"):"right"===t.horizontal?n+="right: ".concat(e.x,"px;"):"center"===t.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(t){var e=this.config.icon;switch(e.type){case"custom":return'<img src="'.concat(e.customImage,'" alt="Chat Assistant" style="width: ').concat(t,"px; height: ").concat(t,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(t,'px; line-height: 1;">').concat(e.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*t),'px; font-weight: bold; color: white;">').concat(e.text,"</span>");case"microphone":default:return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>');case"chat":return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/>\n </svg>')}}},{key:"generateCSS",value:function(t,e,n){var o,i,r,a,c,s,l,u=this.config.button,d=this.config.icon,f=this.config.panel,p=this.config.header,v=(this.config.messages,this.config.animation),h=this.config.behavior.mode||"unified",g="unified"===h||"voice-only"===h,y="unified"===h||"text-only"===h,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"===u.shape?"50%":"square"===u.shape?"0":"12px",";\n background: ").concat(u.backgroundColor||d.backgroundColor||"#7C3AED",";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(v.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(v.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(v.enableSlide?"transition: all ".concat(v.duration,"s ease;"):"","\n box-sizing: border-box;\n }\n \n #text-chat-panel.open {\n display: flex;\n ").concat(v.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n\n /* Shell for gradient border/background */\n .widget-shell { width: 100%; height: 100%; padding: 0; border-radius: ").concat(f.borderRadius,"px; background: transparent; box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; display: flex; flex-direction: column; box-sizing: border-box; }\n .panel-inner { width: 100%; height: 100%; background: #ffffff; border-radius: ").concat(f.borderRadius,"px; overflow: hidden; display:flex; flex-direction: column; padding: 0; box-sizing: border-box; max-width: 100%; }\n\n /* New structure styles matching provided design */\n #text-chat-panel .widget-container {\n width: 100%; height: 100%; min-height: 0; background: #FFFFFF; overflow: hidden; display: flex; flex-direction: column; border-radius: ").concat(f.borderRadius,"px;\n container-type: size;\n }\n \n /* Ensure content areas can scroll when height is constrained */\n #text-chat-panel .widget-container > .landing-screen,\n #text-chat-panel .widget-container > .voice-interface,\n #text-chat-panel .widget-container > .text-interface {\n flex: 1;\n min-height: 0;\n overflow-y: auto;\n overflow-x: hidden;\n }\n \n /* Header should not scroll */\n #text-chat-panel .widget-header {\n padding: 12px 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-top-left-radius: ").concat(f.borderRadius,"px;\n border-top-right-radius: ").concat(f.borderRadius,"px;\n flex-shrink: 0;\n min-height: 60px;\n box-sizing: border-box;\n }\n #text-chat-panel .header-title { font-size: 16px; font-weight: 600; }\n #text-chat-panel .header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.9; }\n #text-chat-panel .status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }\n @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n /* Header icon buttons */\n .header-icon {\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 36px;\n height: 36px;\n min-width: 36px;\n min-height: 36px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n flex-shrink: 0;\n font-size: 16px;\n padding: 0;\n box-sizing: border-box;\n }\n \n .header-icon:hover {\n background: rgba(255, 255, 255, 0.3);\n }\n \n .header-icon svg {\n pointer-events: none;\n stroke: white;\n fill: none;\n }\n \n .back-btn.visible {\n display: flex !important;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { \n display: none; \n flex: 1; \n padding: 20px; \n background: ").concat((null===(o=this.config.landing)||void 0===o?void 0:o.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)","; \n align-items: center; \n justify-content: flex-start; \n flex-direction: column; \n gap: 16px; \n overflow-y: auto; \n min-height: 0; \n }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { \n font-size: 20px; \n color: ").concat((null===(i=this.config.landing)||void 0===i?void 0:i.titleColor)||"#1e293b","; \n font-weight: 700; \n margin-bottom: 20px; \n text-align: center;\n width: 100%;\n }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { \n flex: 1; \n max-width: 180px; \n background: ").concat((null===(r=this.config.landing)||void 0===r?void 0:r.modeCardBackgroundColor)||"#FFFFFF","; \n border: 2px solid ").concat((null===(a=this.config.landing)||void 0===a?void 0:a.modeCardBorderColor)||"#E2E8F0","; \n border-radius: 20px; \n padding: 20px 12px; \n cursor: pointer; \n display: flex; \n flex-direction: column; \n align-items: center; \n gap: 8px; \n transition: transform ").concat(v.duration,"s ease, box-shadow ").concat(v.duration,"s ease, border-color ").concat(v.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===(l=this.config.landing)||void 0===l?void 0:l.modeCardTitleColor)||"#111827","; \n font-weight: 600; \n text-align: center;\n width: 100%;\n }\n\n ").concat(g?this.voiceInterface.generateCSS():"","\n ").concat(y?this.textInterface.generateCSS():"","\n \n #text-chat-send-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this;console.log("⚙️ setupWidgetEvents called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n"),currentView:this.currentView});var e=document.getElementById("text-chat-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("closeBtn");n&&(n.onclick=function(){return t.togglePanel()});var o=this.config.behavior.mode||"unified",i="unified"===o,r="unified"===o||"voice-only"===o,a="unified"===o||"text-only"===o,c=document.getElementById("backBtn"),s=document.getElementById("landingScreen"),l=document.getElementById("mode-card-voice"),u=document.getElementById("mode-card-text"),d=document.getElementById("textInterface"),f=document.getElementById("voiceInterface");c&&(c.onclick=function(){return t.showLanding()}),i?(l&&(l.onclick=function(){return t.showVoice()}),u&&(u.onclick=function(){return t.showText()}),"text"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.add("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="")):"voice"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.remove("active"),f&&f.classList.add("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="none")):(this.currentView="landing",s&&s.classList.add("active"),d&&d.classList.remove("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.remove("visible"))):"voice-only"===o?(f&&f.classList.add("active"),d&&d.classList.remove("active"),s&&s.classList.remove("active")):"text-only"===o&&(d&&d.classList.add("active"),f&&f.classList.remove("active"),s&&s.classList.remove("active")),r&&(console.log("⚙️ Setting up voice interface event handlers"),this.voiceInterface.setupEventHandlers()),a&&(console.log("⚙️ Setting up text interface event handlers"),this.textInterface.setupEventHandlers());var p=document.getElementById("newChatBtn");p&&(p.onclick=function(){return t.textInterface.startNewChat()},i&&(p.style.display="none")),this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"startNewChat",value:function(){this.textInterface.startNewChat()}},{key:"showLanding",value:function(){if("unified"===(this.config.behavior.mode||"unified")){this.currentView="landing";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),i=document.getElementById("newChatBtn");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),i&&(i.style.display="none")}}},{key:"showText",value:function(){this.currentView="text";var t=document.getElementById("landingScreen"),e=document.getElementById("voiceInterface"),n=document.getElementById("backBtn"),o=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),this.textInterface.show();var i=this.config.behavior.mode||"unified";n&&"unified"===i&&n.classList.add("visible"),o&&(o.style.display="")}},{key:"showVoice",value:function(){this.currentView="voice";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),i=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active");var r=this.config.behavior.mode||"unified";o&&"unified"===r&&o.classList.add("visible"),i&&(i.style.display="none")}},{key:"setupKeyboardNavigation",value:function(){var t=this;document.addEventListener("keydown",function(e){"Escape"===e.key&&t.isOpen&&t.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("text-chat-panel").classList.toggle("open"),this.isOpen&&setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},100),this.isOpen&&!this.isActive&&this.config.behavior.autoConnect&&this.startChat()}},{key:"startChat",value:(r=ke(xe().m(function t(){return xe().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.textInterface.setActive(!0);case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"sendMessage",value:(i=ke(xe().m(function t(){return xe().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.textInterface.sendMessage();case 1:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=ke(xe().m(function t(){var e,n,o,i,r,a,c;return xe().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://backend.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((i=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(i.statusText));case 4:return t.n=5,i.json();case 5:return r=t.v,t.a(2,r.signedUrl||r.wsUrl||r.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"addMessage",value:function(t,e){this.textInterface.addMessage(t,e)}},{key:"beginStreaming",value:function(){this.textInterface.beginStreaming()}},{key:"appendStreamingChunk",value:function(t){this.textInterface.appendStreamingChunk(t)}},{key:"finalizeStreaming",value:function(t){this.textInterface.finalizeStreaming(t)}},{key:"stopStreamingState",value:function(){this.textInterface.stopStreamingState()}},{key:"showError",value:function(t){this.textInterface.showError(t)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n;console.log("🔄 updateConfig called",{newConfig:t,stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var o,i,r=Oe({},this.config);t.panel&&(r.panel=Oe(Oe({},this.config.panel),t.panel)),t.voice&&(r.voice=Oe(Oe({},this.config.voice),t.voice),t.voice.micButtonHint&&(r.voice.micButtonHint=Oe(Oe({},null===(o=this.config.voice)||void 0===o?void 0:o.micButtonHint),t.voice.micButtonHint))),t.text&&(r.text=Oe(Oe({},this.config.text),t.text),t.text.sendButtonHint&&(r.text.sendButtonHint=Oe(Oe({},null===(i=this.config.text)||void 0===i?void 0:i.sendButtonHint),t.text.sendButtonHint))),void 0!==t.language&&(r.language=t.language),void 0!==t.language&&(["he","ar"].includes(t.language)?r.direction="rtl":void 0===t.direction&&(r.direction="ltr")),t.translations&&(r.translations=t.translations,this.translations=t.translations),t.button&&(r.button=Oe(Oe({},this.config.button),t.button)),t.header&&(r.header=Oe(Oe({},this.config.header),t.header)),t.icon&&(r.icon=Oe(Oe({},this.config.icon),t.icon)),t.messages&&(r.messages=Oe(Oe({},this.config.messages),t.messages)),t.animation&&(r.animation=Oe(Oe({},this.config.animation),t.animation)),t.behavior&&(r.behavior=Oe(Oe({},this.config.behavior),t.behavior)),t.accessibility&&(r.accessibility=Oe(Oe({},this.config.accessibility),t.accessibility)),t.tooltips&&(r.tooltips=Oe(Oe({},this.config.tooltips),t.tooltips)),t.landing&&(r.landing=Oe(Oe({},this.config.landing),t.landing)),void 0!==t.direction&&void 0===r.direction&&(r.direction=t.direction),void 0!==t.primaryColor&&(r.primaryColor=t.primaryColor),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction","voice","text","animation","behavior","accessibility","language","tooltips","landing","primaryColor"].includes(e)||(r[e]=t[e])}),null===(e=this.config)||void 0===e||e.language,this.config=this.mergeWithDefaults(r);var a=this.config.language||"en",c=Oe(Oe(Oe({},this.config),this.config.voice),{},{language:a,websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations});this.voiceInterface=new ue(c);var s=Oe(Oe(Oe({},this.config),this.config.text),{},{language:a,translations:this.translations});this.textInterface=new me(s,this.sdk);var l=document.getElementById("text-chat-widget");l&&l.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=ke(xe().m(function t(){return xe().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&&je(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,i,r}(),Pe="2.0.0";const Fe={VoiceSDK:pt,TextChatSDK:Ot,WebSocketManager:P,AudioRecorder:K,AudioPlayer:Z,EventEmitter:c,VoiceButton:zt,VanillaVoiceButton:qt,AgentSDK:ne,TTPChatWidget:Be,VERSION:Pe};return o})());
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var i=null;if(void 0!==o&&(i=""+o),void 0!==e.key&&(i=""+e.key),"key"in e)for(var r in o={},e)"key"!==r&&(o[r]=e[r]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:i,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,i={};function r(t,e,o){this.props=t,this.context=e,this.refs=i,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=i,this.updater=o||n}r.prototype.isReactComponent={},r.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},r.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=r.prototype;var s=c.prototype=new a;s.constructor=c,o(s,r.prototype),s.isPureReactComponent=!0;Array.isArray;var l={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return l.H.useEffect(t,e)},e.useRef=function(t){return l.H.useRef(t)},e.useState=function(t){return l.H.useState(t)}}},e={};function n(o){var i=e[o];if(void 0!==i)return i.exports;var r=e[o]={exports:{}};return t[o](r,r.exports,n),r.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function r(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(t){var e=function(t){if("object"!=i(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==i(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>ne,AudioPlayer:()=>Z,AudioRecorder:()=>K,EventEmitter:()=>c,TTPChatWidget:()=>Te,TextChatSDK:()=>Ot,VERSION:()=>Be,VanillaVoiceButton:()=>Qt,VoiceButton:()=>zt,VoiceSDK:()=>pt,WebSocketManager:()=>B,default:()=>Fe});var c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&r(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,i,r,a,c=[],s=!0,l=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){l=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw i}}return c}}(t,e)||d(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=d(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}function d(t,e){if(t){if("string"==typeof t)return f(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return v(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(v(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,v(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,v(d,"constructor",l),v(l,"constructor",s),s.displayName="GeneratorFunction",v(l,i,"GeneratorFunction"),v(d),v(d,i,"Generator"),v(d,o,function(){return this}),v(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:r,m:f}})()}function v(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}v=function(t,e,n,o){function r(e,n){v(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},v(t,e,n,o)}function h(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,y(o.key),o)}}function y(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}function m(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(m=function(){return!!t})()}function b(t){return b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},b(t)}function x(t,e){return x=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},x(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&&x(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(i=p().m(function t(e){var n,o,i=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(i.connections.has(e)){var o=i.connections.get(e);i.connectionCounts.set(e,(i.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){i.creatingConnections.delete(e),i.emit("open",t,e)}),o.addEventListener("close",function(t){i.creatingConnections.delete(e),i.connections.delete(e),i.connectionCounts.delete(e),i.emit("close",t,e)}),o.addEventListener("error",function(t){i.creatingConnections.delete(e),i.emit("error",t,e)}),o.addEventListener("message",function(t){i.emit("message",t,e)}),t.a(2,o)}},t,this)}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){h(r,n,o,a,c,"next",t)}function c(t){h(r,n,o,a,c,"throw",t)}a(void 0)})},function(t){return r.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=u(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=l(t.value,2),i=o[0],r=o[1];e[i]={readyState:r.readyState,subscribers:this.connectionCounts.get(i)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=u(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=l(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c));function 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 k(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return C(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(C(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,C(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,C(d,"constructor",l),C(l,"constructor",s),s.displayName="GeneratorFunction",C(l,i,"GeneratorFunction"),C(d),C(d,i,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(k=function(){return{w:r,m:f}})()}function C(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}C=function(t,e,n,o){function r(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},C(t,e,n,o)}function I(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,E(o.key),o)}}function E(t){var e=function(t){if("object"!=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 j(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(j=function(){return!!t})()}function P(t){return P=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},P(t)}function T(t,e){return T=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},T(t,e)}var B=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=P(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,j()?Reflect.construct(e,n||[],P(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&&T(t,e)}(e,t),n=e,o=[{key:"connect",value:(r=k().m(function t(){var e=this;return k().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,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 i=r.apply(t,e);function a(t){I(i,n,o,a,c,"next",t)}function c(t){I(i,n,o,a,c,"throw",t)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},i=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};w.on("open",e),w.on("close",n),w.on("error",o),w.on("message",i),this.eventHandlers={open:e,close:n,error:o,message:i}}}},{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}}}],i=[{key:"getSingletonStatus",value:function(){return w.getAllConnections()}},{key:"clearAllConnections",value:function(){w.clearAll()}}],o&&O(n.prototype,o),i&&O(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a}(c);function 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",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return A(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(A(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,A(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,A(d,"constructor",l),A(l,"constructor",s),s.displayName="GeneratorFunction",A(l,i,"GeneratorFunction"),A(d),A(d,i,"Generator"),A(d,o,function(){return this}),A(d,"toString",function(){return"[object Generator]"}),(D=function(){return{w:r,m:f}})()}function A(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}A=function(t,e,n,o){function r(e,n){A(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},A(t,e,n,o)}function _(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function M(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){_(r,o,i,a,c,"next",t)}function c(t){_(r,o,i,a,c,"throw",t)}a(void 0)})}}function R(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 z(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,L(o.key),o)}}function L(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 H(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(H=function(){return!!t})()}function U(t){return U=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},U(t)}function N(t,e){return N=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},N(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=U(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,H()?Reflect.construct(e,n||[],U(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&&N(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 R(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)?R(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,r=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw r}}}}(document.getElementsByTagName("script"));try{for(e.s();!(t=e.n()).done;){var n=t.value.src;if(n&&(n.includes("agent-widget.js")||n.includes("ttp-agent-sdk")))try{new URL(n);var o=n.substring(0,n.lastIndexOf("/"));return"".concat(o,"/audio-processor.js")}catch(t){var i=n.substring(0,n.lastIndexOf("/"));return"".concat(i,"/audio-processor.js")}}}catch(t){e.e(t)}finally{e.f()}return"https://cdn.talktopc.com/audio-processor.js"}},{key:"start",value:(r=M(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,i=e.data;"pcm_audio_data"===n&&o.emit("audioData",i)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,n=t.v,this.emit("error",n),n;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return r.apply(this,arguments)})},{key:"stop",value:(i=M(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 i.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&z(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c);function W(t){return W="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},W(t)}function V(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return G(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(G(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,G(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,G(d,"constructor",l),G(l,"constructor",s),s.displayName="GeneratorFunction",G(l,i,"GeneratorFunction"),G(d),G(d,i,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(V=function(){return{w:r,m:f}})()}function G(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}G=function(t,e,n,o){function r(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},G(t,e,n,o)}function q(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Q(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Y(o.key),o)}}function Y(t){var e=function(t){if("object"!=W(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=W(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==W(e)?e:e+""}function J(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(J=function(){return!!t})()}function $(t){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},$(t)}function X(t,e){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},X(t,e)}var Z=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=$(e),function(t,e){if(e&&("object"==W(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,J()?Reflect.construct(e,n||[],$(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&X(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(i=V().m(function t(){var e,n,o,i,r,a,c,s,l=this;return V().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.audioContext=new(window.AudioContext||window.webkitAudioContext)),"suspended"!==(o=this.audioContext).state){t.n=3;break}return t.n=3,o.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return i=t.v,t.n=5,o.decodeAudioData(i);case 5:r=t.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=r,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){l.currentSource=null,l.isProcessingQueue=!1,l.audioQueue.length>0?setTimeout(function(){return l.processQueue()},50):setTimeout(function(){0!==l.audioQueue.length||l.currentSource||(l.isPlaying=!1,l.emit("playbackStopped"))},100)},c.start(),t.n=7;break;case 6:t.p=6,s=t.v,this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return l.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){q(r,n,o,a,c,"next",t)}function c(t){q(r,n,o,a,c,"throw",t)}a(void 0)})},function(){return r.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&Q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c);function tt(t){return tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tt(t)}function et(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return nt(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(nt(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,nt(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,nt(d,"constructor",l),nt(l,"constructor",s),s.displayName="GeneratorFunction",nt(l,i,"GeneratorFunction"),nt(d),nt(d,i,"Generator"),nt(d,o,function(){return this}),nt(d,"toString",function(){return"[object Generator]"}),(et=function(){return{w:r,m:f}})()}function nt(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}nt=function(t,e,n,o){function r(e,n){nt(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},nt(t,e,n,o)}function ot(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function it(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ot(r,o,i,a,c,"next",t)}function c(t){ot(r,o,i,a,c,"throw",t)}a(void 0)})}}function rt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function at(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?rt(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=lt(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,lt(o.key),o)}}function lt(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 ut(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ut=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,ut()?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},n),t.isConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.webSocketManager=new B(at(at({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new 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),i=0;i<n.length;i++)o[i]=n.charCodeAt(i);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(l=it(et().m(function t(){var e,n;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return l.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=it(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isDestroyed){t.n=1;break}return t.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),t.n=2,this.connect();case 2:return t.a(2,t.v)}},t,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(c=it(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw new Error("Not connected to voice server");case 1:return t.p=1,this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),t.n=2,this.audioRecorder.start();case 2:return t.a(2,!0);case 3:return t.p=3,e=t.v,console.error("❌ VoiceSDK: Failed to start recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"stopRecording",value:(a=it(et().m(function t(){var e;return et().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(r=it(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(i=it(et().m(function t(){return et().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=at(at({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={t:"hello"};this.config.appId?t.appId=this.config.appId:this.config.ttpId?t.ttpId=this.config.ttpId:t.ttpId=this.generateTtpId();try{this.webSocketManager.sendMessage(t)}catch(t){console.error("VoiceSDK: Failed to send hello message:",t),this.emit("error",t)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&st(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r,a,c,s,l}(c);function vt(t){return vt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},vt(t)}function ht(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return gt(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(gt(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,gt(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,gt(d,"constructor",l),gt(l,"constructor",s),s.displayName="GeneratorFunction",gt(l,i,"GeneratorFunction"),gt(d),gt(d,i,"Generator"),gt(d,o,function(){return this}),gt(d,"toString",function(){return"[object Generator]"}),(ht=function(){return{w:r,m:f}})()}function gt(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}gt=function(t,e,n,o){function r(e,n){gt(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},gt(t,e,n,o)}function yt(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function mt(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 bt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?mt(Object(n),!0).forEach(function(e){xt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):mt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function xt(t,e,n){return(e=St(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function wt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,St(o.key),o)}}function St(t){var e=function(t){if("object"!=vt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=vt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==vt(e)?e:e+""}function kt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(kt=function(){return!!t})()}function Ct(t){return Ct=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Ct(t)}function It(t,e){return It=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},It(t,e)}var Ot=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=Ct(e),function(t,e){if(e&&("object"==vt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,kt()?Reflect.construct(e,n||[],Ct(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=bt({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&&It(t,e)}(e,t),n=e,o=[{key:"readScriptTagConfig",value:function(){try{var t=Array.from(document.getElementsByTagName("script")).reverse().find(function(t){return t.dataset&&(t.dataset.appId||t.dataset.agentId)||t.src&&t.src.includes("agent-widget")});return t?{appId:t.dataset.appId,agentId:t.dataset.agentId}:{}}catch(t){return{}}}},{key:"buildWebSocketUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,e=new URLSearchParams;return this.config.appId&&e.append("appId",this.config.appId),this.config.agentId&&e.append("agentId",this.config.agentId),this.config.conversationId&&e.append("conversationId",this.config.conversationId),"".concat(t,"?").concat(e.toString())}},{key:"sendMessage",value:(i=ht().m(function t(e){var n=this;return ht().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,o){if(e&&e.trim())if(n.config.appId&&n.config.agentId){var i={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(i):n.executeTask(i)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),r=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){yt(r,n,o,a,c,"next",t)}function c(t){yt(r,n,o,a,c,"throw",t)}a(void 0)})},function(t){return r.apply(this,arguments)})},{key:"executeTask",value:function(t){var e=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,i=this.buildWebSocketUrl(this.config.baseWsUrl),r=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(r),c=!1,s=!1,l=null,u=function(n){if(!s)try{var o={message:t.text},i=e.config.forceConversationId||e.config.conversationId;i&&(o.conversationId=i,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=i,e.persistConversationId(i))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",e.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){t.reject(o),e.emit("error",o);try{n.close()}catch(t){}}},d=function(t){return function(){e.config.conversationId?u(t):l=setTimeout(function(){return u(t)},200)}},f=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(t){}var i=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",i)}catch(t){}if("hello"===i.type&&i.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",i.conversationId),e.config.conversationId=i.conversationId,e.persistConversationId(i.conversationId),e.emit&&e.emit("conversationIdChanged",i.conversationId),!s&&n&&1===n.readyState){if(l)try{clearTimeout(l)}catch(t){}u(n)}return}if(!e.config.conversationId&&i.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",i.conversationId),e.config.conversationId=i.conversationId,e.persistConversationId(i.conversationId)),"chunk"===i.type&&"string"==typeof i.content)e.fullResponseBuffer+=i.content,e.emit("chunk",i.content);else if("done"===i.type){try{var r=i.text||i.content||i.answer||i.message||"";r&&!e.fullResponseBuffer&&(e.fullResponseBuffer=r)}catch(t){}!e.config.conversationId&&i.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",i.conversationId),e.config.conversationId=i.conversationId),e.persistConversationId(e.config.conversationId),e.emit("done",{text:e.fullResponseBuffer}),t.resolve({conversationId:e.config.conversationId,fullText:e.fullResponseBuffer});try{n.close()}catch(t){}}else if("error"===i.type){var a=new Error(i.message||"Server error");e.emit("error",a),t.reject(a);try{n.close()}catch(t){}}}catch(t){}}},p=function(n){if(1008===n.code&&n.reason&&(n.reason.includes("Domain not whitelisted")||n.reason.includes("domain")||n.reason.includes("whitelist"))){var o=new Error("DOMAIN_NOT_WHITELISTED");return o.reason=n.reason,o.code=n.code,e.emit("domainError",o),t.reject(o),e.config.inFlight=!1,void e.drainQueue()}e.config.inFlight=!1,e.drainQueue()},v=new WebSocket(i);v.onopen=d(v),v.onmessage=f(v),v.onerror=(o=v,function(n){if(!c){c=!0;try{o.close()}catch(t){}var i=new WebSocket(a);return i.onopen=d(i),i.onmessage=f(i),i.onerror=function(n){e.emit("error",n),t.reject(n)},void(i.onclose=p)}e.emit("error",n),t.reject(n)}),v.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=bt(bt({},this.config),t)}},{key:"destroy",value:function(){this.config.queue=[],this.config.inFlight=!1,this.removeAllListeners()}}],o&&wt(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,i,r}(c),Et=n(540),jt=n(848);function Pt(t){return Pt="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},Pt(t)}function Tt(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 Bt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Tt(Object(n),!0).forEach(function(e){Ft(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Tt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ft(t,e,n){return(e=function(t){var e=function(t){if("object"!=Pt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Pt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Pt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Dt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return At(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(At(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,At(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,At(d,"constructor",l),At(l,"constructor",s),s.displayName="GeneratorFunction",At(l,i,"GeneratorFunction"),At(d),At(d,i,"Generator"),At(d,o,function(){return this}),At(d,"toString",function(){return"[object Generator]"}),(Dt=function(){return{w:r,m:f}})()}function At(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}At=function(t,e,n,o){function r(e,n){At(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},At(t,e,n,o)}function _t(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Mt(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,i,r,a,c=[],s=!0,l=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){l=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw i}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Rt(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)?Rt(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 Rt(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 zt=function(t){var e=t.websocketUrl,n=t.agentId,o=t.voice,i=void 0===o?"default":o,r=t.language,a=void 0===r?"en":r,c=t.autoReconnect,s=void 0===c||c,l=t.onConnected,u=t.onDisconnected,d=t.onRecordingStarted,f=t.onRecordingStopped,p=t.onPlaybackStarted,v=t.onPlaybackStopped,h=t.onError,g=t.onMessage,y=t.onBargeIn,m=t.onStopPlaying,b=t.className,x=void 0===b?"":b,w=t.style,S=void 0===w?{}:w,k=t.children,C=Mt((0,Et.useState)(!1),2),I=C[0],O=C[1],E=Mt((0,Et.useState)(!1),2),j=E[0],P=E[1],T=Mt((0,Et.useState)(!1),2),B=(T[0],T[1]),F=Mt((0,Et.useState)("Disconnected"),2),D=(F[0],F[1]),A=(0,Et.useRef)(null);(0,Et.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),A.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),A.current.destroy(),A.current=null);var t=new pt({websocketUrl:e,agentId:n,voice:i,language:a,autoReconnect:s});return t.on("connected",function(){O(!0),D("Connected"),null==l||l()}),t.on("disconnected",function(){O(!1),D("Disconnected"),null==u||u()}),t.on("recordingStarted",function(){P(!0),null==d||d()}),t.on("recordingStopped",function(){P(!1),null==f||f()}),t.on("playbackStarted",function(){B(!0),null==p||p()}),t.on("playbackStopped",function(){B(!1),null==v||v()}),t.on("error",function(t){null==h||h(t)}),t.on("message",function(t){null==g||g(t)}),t.on("bargeIn",function(t){null==y||y(t)}),t.on("stopPlaying",function(t){null==m||m(t)}),A.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),A.current&&(A.current.destroy(),A.current=null)}},[e,n,i,a]);var _=function(){var t,e=(t=Dt().m(function t(){var e;return Dt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(A.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,A.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){_t(r,o,i,a,c,"next",t)}function c(t){_t(r,o,i,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),M=(0,jt.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,jt.jsx)("div",{style:{fontSize:"20px"},children:j?"🔴":"🎤"}),(0,jt.jsx)("div",{children:j?"Stop Listening":"Start Listening"})]});return(0,jt.jsx)("button",{className:"voice-button ".concat(j?"recording":""," ").concat(x),style:Bt({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:j?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},S),onClick:_,disabled:!I,children:k||M})};function Lt(t){return Lt="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},Lt(t)}function Ht(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return Ut(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(Ut(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,Ut(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,Ut(d,"constructor",l),Ut(l,"constructor",s),s.displayName="GeneratorFunction",Ut(l,i,"GeneratorFunction"),Ut(d),Ut(d,i,"Generator"),Ut(d,o,function(){return this}),Ut(d,"toString",function(){return"[object Generator]"}),(Ht=function(){return{w:r,m:f}})()}function Ut(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}Ut=function(t,e,n,o){function r(e,n){Ut(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},Ut(t,e,n,o)}function Nt(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Kt(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Nt(r,o,i,a,c,"next",t)}function c(t){Nt(r,o,i,a,c,"throw",t)}a(void 0)})}}function Wt(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 Vt(t,e,n){return(e=qt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Gt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,qt(o.key),o)}}function qt(t){var e=function(t){if("object"!=Lt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Lt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Lt(e)?e:e+""}var Qt=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?Wt(Object(n),!0).forEach(function(e){Vt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Wt(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=Kt(Ht().m(function t(){var e;return Ht().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=Kt(Ht().m(function t(){var e;return Ht().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&&Gt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Yt(t){return Yt="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},Yt(t)}function Jt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return $t(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):($t(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,$t(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,$t(d,"constructor",l),$t(l,"constructor",s),s.displayName="GeneratorFunction",$t(l,i,"GeneratorFunction"),$t(d),$t(d,i,"Generator"),$t(d,o,function(){return this}),$t(d,"toString",function(){return"[object Generator]"}),(Jt=function(){return{w:r,m:f}})()}function $t(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}$t=function(t,e,n,o){function r(e,n){$t(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},$t(t,e,n,o)}function Xt(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function Zt(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Xt(r,o,i,a,c,"next",t)}function c(t){Xt(r,o,i,a,c,"throw",t)}a(void 0)})}}function te(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,ee(o.key),o)}}function ee(t){var e=function(t){if("object"!=Yt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Yt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Yt(e)?e:e+""}var ne=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),console.log("🚀 AgentSDK v2.1.8 initialized with config:",e),this.config=e,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(t){return console.error("SDK Error:",t)},this.onTranscript=function(t){},this.onAgentSpeaking=function(t){}},e=[{key:"connect",value:(o=Zt(Jt().m(function t(e){var n,o=this;return Jt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,e){t.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new pt({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en"}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(t){if(o.isConnected=!1,t&&1008===t.code&&t.reason&&(t.reason.includes("Domain not whitelisted")||t.reason.includes("domain")||t.reason.includes("whitelist"))){var e=new Error("DOMAIN_NOT_WHITELISTED");e.reason=t.reason,e.code=t.code,o.onError(e)}o.onDisconnected()}),this.voiceSDK.on("domainError",function(t){o.onError(t)}),this.voiceSDK.on("error",function(t){o.onError(t)}),this.voiceSDK.on("message",function(t){o.handleWebSocketMessage(t)}),this.voiceSDK.on("recordingStarted",function(){o.isListening=!0}),this.voiceSDK.on("recordingStopped",function(){o.isListening=!1}),this.voiceSDK.on("playbackStarted",function(){o.onAgentSpeaking(!0)}),this.voiceSDK.on("playbackStopped",function(){o.onAgentSpeaking(!1)}),t.n=2,this.voiceSDK.connect();case 2:t.n=4;break;case 3:throw t.p=3,n=t.v,this.onError(n),n;case 4:return t.a(2)}},t,this,[[0,3]])})),function(t){return o.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(t){switch(t.type){case"connected":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text);break;case"agent_response":case"barge_in":case"stop_playing":break;case"error":this.onError(new Error(t.message))}}},{key:"startListening",value:(n=Zt(Jt().m(function t(){var e;return Jt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){t.n=5;break}return t.p=1,console.log("🎤 AgentSDK: Starting recording..."),t.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),t.n=4;break;case 3:throw t.p=3,e=t.v,console.error("❌ AgentSDK: Failed to start recording:",e),e;case 4:t.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(t){this.voiceSDK&&this.isConnected&&this.voiceSDK.webSocketManager.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}],e&&te(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();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 ie(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return re(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(re(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,re(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,re(d,"constructor",l),re(l,"constructor",s),s.displayName="GeneratorFunction",re(l,i,"GeneratorFunction"),re(d),re(d,i,"Generator"),re(d,o,function(){return this}),re(d,"toString",function(){return"[object Generator]"}),(ie=function(){return{w:r,m:f}})()}function re(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}re=function(t,e,n,o){function r(e,n){re(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},re(t,e,n,o)}function ae(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function ce(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ae(r,o,i,a,c,"next",t)}function c(t){ae(r,o,i,a,c,"throw",t)}a(void 0)})}}function se(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,le(o.key),o)}}function le(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+""}var ue=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 ne({agentId:e.agentId,appId:e.appId,getSessionUrl:e.getSessionUrl,websocketUrl:e.websocketUrl,variables:e.variables||{},language:e.language||"en"}),this.setupSDKEventHandlers()},e=[{key:"setupSDKEventHandlers",value:function(){var t=this;this.sdk.onTranscript=function(e){t.updateTranscript(e)},this.sdk.onAgentSpeaking=function(t){var e=document.getElementById("voiceAvatarActive");e&&(t?e.classList.add("speaking"):e.classList.remove("speaking"))},this.sdk.onError=function(e){console.error("❌ Voice SDK Error:",e),e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))?t.showDomainError():t.showError(e.message||e)}}},{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"getTooltip",value:function(t){var e,n=null===(e=this.config.tooltips)||void 0===e?void 0:e[t];return null!=n?n:{mute:this.t("mute"),speaker:this.t("speaker"),endCall:this.t("endCall")}[t]||""}},{key:"generateHTML",value:function(){return'<div class="voice-interface" id="voiceInterface">\n \x3c!-- Before Call State --\x3e\n <div id="voiceIdleState">\n <div class="voice-avatar" id="voiceAvatar">🤖</div>\n <div class="voice-status">\n <div class="voice-status-title">'.concat(this.t("clickToStartCall"),'</div>\n <div class="voice-status-subtitle">').concat(this.t("realTimeVoice"),'</div>\n </div>\n <button class="start-call-btn" id="startCallBtn">\n <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">\n <path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56-.35-.12-.74-.03-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"/>\n </svg>\n <span>').concat(this.t("startCall"),'</span>\n </button>\n </div>\n \x3c!-- During Call State --\x3e\n <div id="voiceActiveState" style="display: none;">\n <div class="voice-avatar-active" id="voiceAvatarActive">\n <div class="voice-rings">\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n <div class="voice-ring"></div>\n </div>\n 🤖\n </div>\n <div class="voice-status">\n <div class="voice-status-title" id="voiceStatusTitleActive">').concat(this.t("listening"),'</div>\n <div class="voice-status-subtitle" id="voiceStatusSubtitleActive">').concat(this.t("speakFreely"),'</div>\n </div>\n <div class="voice-transcript">\n <div class="transcript-label">').concat(this.t("liveTranscript"),'</div>\n <div class="transcript-text empty" id="transcriptText">\n ').concat(this.t("transcriptWillAppear"),'\n </div>\n </div>\n <div class="voice-controls">\n <button class="voice-control-btn secondary" id="muteBtn" title="').concat(this.getTooltip("mute"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="mute-icon">\n <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>\n <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>\n <line x1="12" y1="19" x2="12" y2="23"/>\n <line x1="8" y1="23" x2="16" y2="23"/>\n <line x1="2" y1="2" x2="22" y2="22" class="mute-cross" style="display: none; stroke: #ef4444; stroke-width: 3.5;"/>\n </svg>\n </button>\n <button class="voice-control-btn primary active" id="endCallBtn" title="').concat(this.getTooltip("endCall"),'">\n <svg width="56" height="56" viewBox="0 0 24 24" fill="#ef4444">\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n </svg>\n <div class="voice-timer" id="voiceTimer">00:00</div>\n </button>\n <button class="voice-control-btn secondary" id="speakerBtn" title="').concat(this.getTooltip("speaker"),'">\n <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">\n <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/>\n <path d="M19.07 4.93a10 10 0 0 1 0 14.14"/>\n <path d="M15.54 8.46a5 5 0 0 1 0 7.07"/>\n </svg>\n </button>\n </div>\n </div>\n </div>')}},{key:"generateCSS",value:function(){var t=this.config.avatarBackgroundColor||"#667eea",e=this.config.avatarActiveBackgroundColor||this.config.avatarBackgroundColor||"#667eea",n=this.config.statusTitleColor||"#1e293b",o=this.config.statusSubtitleColor||"#64748b",i=this.config.startCallButtonColor||"#667eea",r=this.config.startCallButtonTextColor||"#FFFFFF",a=this.config.transcriptBackgroundColor||"#FFFFFF",c=this.config.transcriptTextColor||"#1e293b",s=this.config.transcriptLabelColor||"#94a3b8",l=this.config.controlButtonColor||"#FFFFFF",u=this.config.controlButtonSecondaryColor||"#64748b";return this.config.endCallButtonColor,'\n /* Voice Interface Styles - Ultra-compact for Wix iframes */\n .voice-interface { \n display: none; \n flex: 1; \n flex-direction: column;\n align-items: center; \n justify-content: center; \n padding: 6px 10px 6px 10px; \n background: linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%);\n overflow: hidden;\n min-height: 0;\n height: 100%;\n width: 100%;\n box-sizing: border-box;\n }\n .voice-interface.active { display: flex; }\n \n /* Voice States - Better scaling gaps */\n #voiceIdleState,\n #voiceActiveState {\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n height: 100%;\n min-height: 0;\n justify-content: center;\n overflow: hidden;\n flex: 1;\n box-sizing: border-box;\n gap: clamp(6px, 1.5vh, 12px);\n }\n \n #voiceActiveState[style*="display: none"] {\n display: none !important;\n }\n \n /* Voice Avatar - Scales better from small to large */\n .voice-avatar,\n .voice-avatar-active {\n width: clamp(80px, 18vh, 160px);\n height: clamp(80px, 18vh, 160px);\n aspect-ratio: 1;\n border-radius: 50%;\n background: linear-gradient(135deg, '.concat(t," 0%, ").concat(e," 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: clamp(40px, 9vh, 80px);\n margin: 0;\n box-shadow: 0 8px 30px rgba(102, 126, 234, 0.3);\n transition: all 0.3s ease;\n flex-shrink: 1;\n position: relative;\n }\n \n .voice-avatar-active {\n animation: avatarPulse 2s ease-in-out infinite;\n }\n \n @keyframes avatarPulse {\n 0%, 100% { \n transform: scale(1);\n }\n 50% { \n transform: scale(1.05);\n }\n }\n \n .voice-avatar-active.speaking {\n animation: avatarSpeak 0.5s ease-in-out infinite;\n }\n \n @keyframes avatarSpeak {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.08); }\n }\n \n /* Voice Rings Animation */\n .voice-rings {\n position: absolute;\n width: 100%;\n height: 100%;\n border-radius: 50%;\n }\n \n .voice-ring {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n border: 2px solid rgba(102, 126, 234, 0.3);\n border-radius: 50%;\n opacity: 0;\n animation: ringExpand 2s ease-out infinite;\n }\n \n .voice-ring:nth-child(2) { animation-delay: 0.5s; }\n .voice-ring:nth-child(3) { animation-delay: 1s; }\n \n @keyframes ringExpand {\n 0% {\n width: 100%;\n height: 100%;\n opacity: 0.6;\n }\n 100% {\n width: 160%;\n height: 160%;\n opacity: 0;\n }\n }\n \n /* Voice Status - Scales with container */\n .voice-status {\n text-align: center;\n margin: 0;\n flex-shrink: 1;\n min-height: 0;\n }\n \n .voice-status-title {\n font-size: clamp(12px, 3vh, 20px);\n font-weight: 600;\n color: ").concat(n,";\n margin-bottom: clamp(2px, 0.5vh, 4px);\n line-height: 1.2;\n }\n \n .voice-status-subtitle {\n font-size: clamp(10px, 2vh, 14px);\n color: ").concat(o,";\n line-height: 1.2;\n }\n \n /* Start Call Button - Scales with container */\n .start-call-btn {\n margin: 0;\n width: min(280px, 70vw);\n height: clamp(48px, 8vh, 64px);\n border-radius: clamp(24px, 4vh, 32px);\n border: none;\n background: ").concat(i,";\n color: ").concat(r,";\n font-size: clamp(14px, 2.5vh, 18px);\n font-weight: 600;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: clamp(8px, 1.5vh, 12px);\n box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);\n transition: all 0.3s ease;\n flex-shrink: 0;\n }\n \n .start-call-btn svg {\n width: clamp(22px, 4vh, 32px);\n height: clamp(22px, 4vh, 32px);\n }\n \n .start-call-btn:hover {\n transform: translateY(-2px);\n box-shadow: 0 12px 28px rgba(102, 126, 234, 0.5);\n }\n \n .start-call-btn:active {\n transform: translateY(-1px);\n }\n \n /* Voice Transcript - Scales with container */\n .voice-transcript {\n background: ").concat(a,";\n padding: clamp(6px, 1.5vh, 12px);\n border-radius: 10px;\n width: min(360px, calc(100% - 40px));\n margin: 0;\n min-height: clamp(45px, 10vh, 80px);\n max-height: clamp(70px, 16vh, 110px);\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n flex-shrink: 1;\n overflow-y: auto;\n overflow-x: hidden;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n \n .transcript-label {\n font-size: clamp(8px, 1.4vh, 11px);\n color: ").concat(s,";\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.3px;\n margin-bottom: clamp(3px, 0.6vh, 6px);\n flex-shrink: 0;\n word-wrap: break-word;\n }\n \n .transcript-text {\n font-size: clamp(11px, 2vh, 15px);\n color: ").concat(c,";\n line-height: 1.4;\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n word-wrap: break-word;\n overflow-wrap: break-word;\n }\n \n .transcript-text.empty {\n color: #cbd5e1;\n font-style: italic;\n }\n \n /* Voice Controls - Scales with container */\n .voice-controls {\n display: flex;\n gap: clamp(8px, 1.8vh, 14px);\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n margin: 0;\n padding-top: clamp(5px, 1.2vh, 10px);\n }\n \n .voice-control-btn {\n width: clamp(48px, 9vh, 72px);\n height: clamp(48px, 9vh, 72px);\n aspect-ratio: 1;\n border-radius: 50%;\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n position: relative;\n flex-shrink: 0;\n }\n \n .voice-control-btn svg {\n width: 48%;\n height: 48%;\n }\n \n .voice-control-btn.primary {\n width: clamp(54px, 10vh, 80px);\n height: clamp(54px, 10vh, 80px);\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n box-shadow: 0 6px 18px rgba(102, 126, 234, 0.4);\n }\n \n .voice-control-btn.primary:hover {\n transform: scale(1.05);\n }\n \n .voice-control-btn.primary.active {\n background: white;\n animation: recordingPulse 1.5s ease-in-out infinite;\n }\n \n @keyframes recordingPulse {\n 0%, 100% { \n box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);\n }\n 50% { \n box-shadow: 0 6px 24px rgba(239, 68, 68, 0.7);\n }\n }\n \n .voice-control-btn.secondary {\n background: ").concat(l,";\n color: ").concat(u,";\n box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);\n }\n \n .voice-control-btn.secondary:hover {\n background: #f8fafc;\n transform: scale(1.05);\n }\n \n .voice-control-btn.secondary.muted {\n background: #f3f4f6;\n }\n \n .voice-control-btn.secondary.muted .mute-icon {\n stroke: #9ca3af !important;\n }\n \n .voice-timer {\n position: absolute;\n bottom: clamp(-18px, -3vh, -24px);\n font-size: clamp(9px, 1.6vh, 12px);\n color: #64748b;\n font-weight: 500;\n white-space: nowrap;\n }\n \n /* Mobile optimization */\n @media (max-width: 768px) {\n .voice-interface {\n padding: 6px 10px;\n }\n }\n \n @media (max-width: 480px) {\n .voice-interface {\n padding: 5px 8px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(t){var e=this,n=document.getElementById("startCallBtn"),o=document.getElementById("endCallBtn"),i=document.getElementById("muteBtn"),r=document.getElementById("speakerBtn");n&&(n.onclick=function(){return e.startVoiceCall()}),o&&(o.onclick=function(){return e.endVoiceCall()}),i&&(i.onclick=function(){return e.toggleMute()}),r&&(r.onclick=function(){return e.toggleSpeaker()});var a=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=document.getElementById("voiceInterface");n&&n.classList.contains("active")?(console.log("✅ Interface is active, adjusting sizes (attempt",t+1,")"),e.adjustSizesForContainer()):t<10?(console.log("⏳ Interface not active yet, retrying... (attempt",t+1,")"),setTimeout(function(){return a(t+1)},200)):(console.warn("⚠️ Interface never became active, adjusting sizes anyway"),e.adjustSizesForContainer())};setTimeout(function(){return a()},100),window.addEventListener("resize",function(){return e.adjustSizesForContainer()})}},{key:"getSignedUrl",value:(o=ce(ie().m(function t(){var e,n,o,i,r,a,c;return ie().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((i=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(i.statusText));case 4:return t.n=5,i.json();case 5:return r=t.v,t.a(2,r.signedUrl||r.wsUrl||r.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"adjustSizesForContainer",value:function(){var t=document.getElementById("voiceInterface");if(t){var e=t.clientHeight,n=t.clientWidth;console.log("📏 Container size:",e,"x",n);var o,i,r,a,c,s,l,u,d,f=document.getElementById("voiceIdleState"),p=document.getElementById("voiceActiveState"),v=f&&"none"!==f.style.display,h=p&&"none"!==p.style.display;console.log("👁️ Visible state - Idle:",v,"Active:",h),e<=350?(d=5,o=70,i=35,r=11,a=9,c=32,s=45,l=42,u=48):e<=450?(d=7,o=110,i=55,r=15,a=11,c=38,s=58,l=52,u=58):e<=550?(d=8,o=140,i=70,r=16,a=12,c=42,s=68,l=56,u=64):e<=700?(d=10,o=130,i=65,r=18,a=13,c=46,s=85,l=60,u=70):(d=12,o=150,i=75,r=20,a=14,c=50,s=100,l=66,u=76),document.querySelectorAll("#voiceIdleState, #voiceActiveState").forEach(function(t){t.style.gap="".concat(d,"px")});var g=document.querySelectorAll(".voice-avatar, .voice-avatar-active");console.log("🤖 Found",g.length,"avatars, setting size to",o,"px"),g.forEach(function(t){t.style.width="".concat(o,"px"),t.style.height="".concat(o,"px"),t.style.fontSize="".concat(i,"px")}),document.querySelectorAll(".voice-status-title").forEach(function(t){return t.style.fontSize="".concat(r,"px")}),document.querySelectorAll(".voice-status-subtitle").forEach(function(t){return t.style.fontSize="".concat(a,"px")});var y=document.querySelector(".voice-transcript");y&&(y.style.minHeight="".concat(s,"px"),y.style.maxHeight="".concat(s,"px"),y.style.height="".concat(s,"px"),y.style.width="min(360px, ".concat(n-40,"px)"),y.style.boxSizing="border-box");var m=document.querySelector(".transcript-label");m&&(m.style.fontSize="".concat(Math.max(8,r-4),"px"));var b=document.querySelector(".transcript-text");b&&(b.style.fontSize="".concat(Math.max(10,r-2),"px")),document.querySelectorAll(".voice-control-btn.secondary").forEach(function(t){t.style.width="".concat(l,"px"),t.style.height="".concat(l,"px");var e=t.querySelector("svg");if(e){var n=.65*l;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 x=document.querySelector(".voice-control-btn.primary");if(x){x.style.width="".concat(u,"px"),x.style.height="".concat(u,"px");var w=x.querySelector("svg");if(w){var S=.7*u;w.style.setProperty("width","".concat(S,"px"),"important"),w.style.setProperty("height","".concat(S,"px"),"important"),w.style.setProperty("min-width","".concat(S,"px"),"important"),w.style.setProperty("min-height","".concat(S,"px"),"important")}}var k=document.querySelector(".start-call-btn");if(k){var C,I;e<=350?(C=48,I=14):e<=450?(C=52,I=15):e<=550?(C=58,I=17):e<=700?(C=62,I=18):(C=64,I=18),k.style.height="".concat(C,"px"),k.style.fontSize="".concat(I,"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:",l)}else console.warn("⚠️ voiceInterface not found, skipping size adjustment")}},{key:"startVoiceCall",value:(n=ce(ie().m(function t(){var e,n,o,i,r,a,c,s,l,u=this;return ie().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 u.adjustSizesForContainer()},50),o&&(o.scrollTop=0),t.n=3,this.getSignedUrl();case 3:return i=t.v,console.log("🔗 Got signed URL:",i),t.n=4,this.sdk.connect(i);case 4:r=t.v,console.log("✅ Connected to WebSocket, connected:",r),a=0;case 5:if(this.sdk.isConnected||!(a<50)){t.n=7;break}return t.n=6,new Promise(function(t){return setTimeout(t,100)});case 6:a++,t.n=5;break;case 7:if(!this.sdk.isConnected){t.n=9;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=8,this.sdk.startListening();case 8:console.log("🎤 Started listening"),this.isActive=!0,this.callStartTime=Date.now(),this.callTimerInterval=setInterval(function(){var t=Date.now()-u.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()-u.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,l=t.v,console.error("❌ Error starting voice call:",l),this.showError(l.message||l),c=document.getElementById("voiceIdleState"),s=document.getElementById("voiceActiveState"),c&&(c.style.display="flex"),s&&(s.style.display="none");case 13:return t.a(2)}},t,this,[[2,12]])})),function(){return n.apply(this,arguments)})},{key:"endVoiceCall",value:function(){var t=this;console.log("🔴 Ending voice call..."),this.sdk&&this.isActive&&(this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null);var e=document.getElementById("voiceIdleState"),n=document.getElementById("voiceActiveState");e&&(e.style.display="flex"),n&&(n.style.display="none"),setTimeout(function(){return t.adjustSizesForContainer()},50);var o=document.getElementById("transcriptText");o&&(o.textContent=this.t("transcriptWillAppear"),o.classList.add("empty"));var i=document.getElementById("voiceAvatarActive");i&&i.classList.remove("speaking"),console.log("✅ Voice call ended")}},{key:"updateTranscript",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent=t,e.classList.remove("empty"))}},{key:"showError",value:function(t){var e=document.getElementById("transcriptText");e&&(e.textContent="".concat(this.t("error"),": ").concat(t),e.classList.remove("empty"))}},{key:"showDomainError",value:function(){var t=document.getElementById("transcriptText");if(t){var e=this.t("domainNotValidated"),n=this.t("domainErrorMessage");t.innerHTML='<div style="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;">'.concat(e,'</div><div style="font-size: 14px; color: #991B1B; line-height: 1.5;">').concat(n,"</div>"),t.classList.remove("empty")}}},{key:"toggleMute",value:function(){if(this.sdk&&this.isActive){var t=null;if(this.sdk.voiceSDK&&this.sdk.voiceSDK.audioRecorder&&this.sdk.voiceSDK.audioRecorder.mediaStream&&(t=this.sdk.voiceSDK.audioRecorder.mediaStream.getAudioTracks()[0]),!t&&this.audioStream&&(t=this.audioStream.getAudioTracks()[0]),t){t.enabled=!t.enabled;var e=document.getElementById("muteBtn"),n=null==e?void 0:e.querySelector(".mute-icon"),o=null==e?void 0:e.querySelector(".mute-cross");e&&n&&o&&(t.enabled?(n.style.stroke="",o.style.display="none",e.classList.remove("muted")):(n.style.stroke="#9ca3af",o.style.display="block",e.classList.add("muted"))),console.log(t.enabled?"🔊 Unmuted":"🔇 Muted")}else console.warn("⚠️ No audio track available for mute toggle")}}},{key:"toggleSpeaker",value:function(){console.log("🔊 Speaker toggle")}},{key:"destroy",value:function(){this.isActive&&this.endVoiceCall(),this.audioStream&&(this.audioStream.getTracks().forEach(function(t){return t.stop()}),this.audioStream=null),this.callTimerInterval&&(clearInterval(this.callTimerInterval),this.callTimerInterval=null),this.sdk&&(this.sdk.disconnect(),this.sdk=null)}}],e&&se(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();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(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return pe(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(pe(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,pe(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,pe(d,"constructor",l),pe(l,"constructor",s),s.displayName="GeneratorFunction",pe(l,i,"GeneratorFunction"),pe(d),pe(d,i,"Generator"),pe(d,o,function(){return this}),pe(d,"toString",function(){return"[object Generator]"}),(fe=function(){return{w:r,m:f}})()}function pe(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}pe=function(t,e,n,o){function r(e,n){pe(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},pe(t,e,n,o)}function ve(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function he(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){ve(r,o,i,a,c,"next",t)}function c(t){ve(r,o,i,a,c,"throw",t)}a(void 0)})}}function ge(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ye(o.key),o)}}function ye(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+""}var me=function(){return t=function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=e,this.sdk=n,this.streamingEl=null,this.hasStartedStreaming=!1,this.isActive=!1,this.eventHandlers={autoResize:null,keydown:null},this.eventHandlersSetup=!1},e=[{key:"t",value:function(t){var e,n,o=this.config.language||"en";return((null===(e=this.config.translations)||void 0===e?void 0:e[o])||(null===(n=this.config.translations)||void 0===n?void 0:n.en)||{})[t]||t}},{key:"generateHTML",value:function(){var t,e,n,o,i,r,a,c,s,l=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(l,'" rows="1" dir="').concat(this.config.direction||"ltr",'"></textarea>\n </div>\n <button class="send-button" id="sendButton" aria-label="').concat(this.t("sendMessageAria"),'">').concat(this.config.sendButtonText||"➤","</button>\n ").concat(null!==(e=this.config.sendButtonHint)&&void 0!==e&&e.text||null!==(n=this.config.panel)&&void 0!==n&&null!==(n=n.sendButtonHint)&&void 0!==n&&n.text?'\n <div class="send-button-hint" style="color: '.concat((null===(o=this.config.sendButtonHint)||void 0===o?void 0:o.color)||(null===(i=this.config.panel)||void 0===i||null===(i=i.sendButtonHint)||void 0===i?void 0:i.color)||"#6B7280","; font-size: ").concat((null===(r=this.config.sendButtonHint)||void 0===r?void 0:r.fontSize)||(null===(a=this.config.panel)||void 0===a||null===(a=a.sendButtonHint)||void 0===a?void 0:a.fontSize)||"12px",'; text-align: center; margin-top: 4px;">\n ').concat((null===(c=this.config.sendButtonHint)||void 0===c?void 0:c.text)||(null===(s=this.config.panel)||void 0===s||null===(s=s.sendButtonHint)||void 0===s?void 0:s.text),"\n </div>\n "):"","\n </div>\n </div>")}},{key:"generateCSS",value:function(){var t,e,n,o,i,r,a,c,s,l,u,d,f,p=this.config.messages,v=(this.config.panel,this.config.animation,this.config.sendButtonColor||(null===(t=this.config.panel)||void 0===t?void 0:t.sendButtonColor)||"#7C3AED"),h=this.config.sendButtonHoverColor||(null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonHoverColor)||"#6D28D9",g=this.config.sendButtonTextColor||(null===(n=this.config.panel)||void 0===n?void 0:n.sendButtonTextColor)||"#FFFFFF",y=(this.config.inputPlaceholder||null===(o=this.config.panel)||void 0===o||o.inputPlaceholder,this.config.inputBorderColor||(null===(i=this.config.panel)||void 0===i?void 0:i.inputBorderColor)||"#E5E7EB"),m=this.config.inputFocusColor||(null===(r=this.config.panel)||void 0===r?void 0:r.inputFocusColor)||"#7C3AED",b=this.config.inputBackgroundColor||(null===(a=this.config.panel)||void 0===a?void 0:a.inputBackgroundColor)||"#FFFFFF",x=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",S=this.config.inputBorderRadius||(null===(l=this.config.panel)||void 0===l?void 0:l.inputBorderRadius)||20,k=this.config.inputPadding||(null===(u=this.config.panel)||void 0===u?void 0:u.inputPadding)||"6px 14px";return"\n /* Messages container using new classes */\n #messagesContainer { \n flex: 1; \n overflow-y: auto; \n overflow-x: hidden; \n padding: 20px; \n background: #f8fafc; \n display: flex; \n flex-direction: column; \n gap: 16px; \n min-height: 0; \n }\n .empty-state { \n flex: 1; \n display: flex; \n flex-direction: column; \n align-items: center; \n justify-content: center; \n gap: 12px; \n color: #64748b; \n text-align: center; \n padding: 20px; \n }\n .empty-state-icon { font-size: 48px; opacity: 0.3; }\n .empty-state-title { font-size: 20px; font-weight: 700; color: #334155; }\n .empty-state-text { font-size: 13px; max-width: 280px; }\n\n .text-interface { \n display: none; \n flex: 1; \n flex-direction: column; \n min-height: 0; \n overflow: hidden; \n }\n .text-interface.active { display: flex; }\n \n .message { \n display: flex; \n gap: 8px; \n padding: 4px 0; \n max-width: 100%; \n align-items: center; \n }\n .message.edge-left { flex-direction: row; }\n .message.edge-right { flex-direction: row-reverse; }\n .message-bubble { \n padding: 12px; \n border-radius: ".concat(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","; \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(S,"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(x,";\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(v,";\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(h,";\n transform: scale(1.05);\n box-shadow: 0 6px 16px rgba(124, 60, 237, 0.4);\n }\n \n .send-button-hint {\n width: 100%;\n text-align: center;\n margin-top: 4px;\n }\n \n .send-button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n \n .typing-indicator {\n display: inline-flex;\n gap: 4px;\n align-items: center;\n }\n \n .typing-dot {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: #64748b;\n animation: typingDot 1.4s ease-in-out infinite;\n }\n \n .typing-dot:nth-child(2) { animation-delay: 0.2s; }\n .typing-dot:nth-child(3) { animation-delay: 0.4s; }\n \n @keyframes typingDot {\n 0%, 60%, 100% { transform: translateY(0); opacity: 0.7; }\n 30% { transform: translateY(-8px); opacity: 1; }\n }\n \n .error-message {\n padding: 12px;\n background: ").concat(p.errorBackgroundColor,";\n border-radius: ").concat(p.borderRadius,"px;\n color: #991B1B;\n font-size: ").concat(p.fontSize,";\n margin: 8px 0;\n }\n \n @media (max-width: 768px) {\n #messagesContainer {\n padding: 12px;\n gap: 12px;\n }\n \n .message-bubble {\n max-width: 85%;\n font-size: 14px;\n padding: 10px;\n }\n \n .text-input-container {\n padding: 10px;\n gap: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n padding: 10px 14px;\n min-height: 44px;\n }\n \n #text-chat-send {\n min-width: 56px;\n min-height: 44px;\n width: 56px;\n height: 44px;\n }\n \n .empty-state-icon {\n font-size: 40px;\n }\n \n .empty-state-title {\n font-size: 18px;\n }\n \n .empty-state-text {\n font-size: 12px;\n }\n }\n \n @media (max-width: 480px) {\n #messagesContainer {\n padding: 10px;\n gap: 10px;\n }\n \n .message-bubble {\n max-width: 90%;\n font-size: 13px;\n padding: 8px;\n }\n \n .text-input-container {\n padding: 8px;\n }\n \n #text-chat-input {\n font-size: 16px !important;\n padding: 8px 12px;\n }\n }\n ")}},{key:"setupEventHandlers",value:function(){var t=this,e=document.getElementById("sendButton"),n=document.getElementById("messageInput"),o=document.getElementById("newChatBtn");if(e&&(e.onclick=function(){return t.sendMessage()}),o&&(o.onclick=function(){return t.startNewChat()}),this.updateInputAttributes(),n){n.style.height="32px",n.style.overflow="hidden";var i=function(){n.style.height="auto";var t=Math.min(n.scrollHeight,120);n.style.height=t+"px",n.style.overflowY=t>=120?"auto":"hidden",t>=120&&setTimeout(function(){n.scrollTop=n.scrollHeight},0)};n.addEventListener("input",i),n.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey?"Enter"===e.key&&e.shiftKey&&setTimeout(i,0):(e.preventDefault(),t.sendMessage())})}}},{key:"startNewChat",value:function(){try{localStorage.removeItem("ttp_text_chat_conversation_id")}catch(t){}this.sdk&&(this.sdk.config.conversationId=null);var t=document.getElementById("messagesContainer");t&&(t.innerHTML='\n <div class="empty-state">\n <div class="empty-state-icon">💬</div>\n <div class="empty-state-title">'.concat(this.t("hello"),'</div>\n <div class="empty-state-text">').concat(this.t("sendMessage"),"</div>\n </div>"));var e=document.getElementById("messageInput");e&&e.focus()}},{key:"updateInputAttributes",value:function(){var t=document.getElementById("messageInput");if(t){var e,n=this.config.inputPlaceholder||(null===(e=this.config.panel)||void 0===e?void 0:e.inputPlaceholder)||this.t("typeMessage")||"Type your message...";t.placeholder=n,t.dir=this.config.direction||"ltr",t.style.textAlign="rtl"===this.config.direction?"right":"left"}}},{key:"show",value:function(){var t=document.getElementById("textInterface");t&&t.classList.add("active"),setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},50)}},{key:"hide",value:function(){var t=document.getElementById("textInterface");t&&t.classList.remove("active")}},{key:"startChat",value:(o=he(fe().m(function t(){return fe().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=he(fe().m(function t(){var e,n,o;return fe().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("messageInput"),n=e.value.trim()){t.n=1;break}return t.a(2);case 1:if(this.isActive){t.n=2;break}return t.n=2,this.startChat();case 2:return this.addMessage("user",n),e.value="",e.style.height="32px",e.style.overflow="hidden",t.p=3,this.beginStreaming(),t.n=4,this.sdk.sendMessage(n);case 4:t.n=6;break;case 5:t.p=5,o=t.v,console.error("❌ Failed to send message:",o),o&&("DOMAIN_NOT_WHITELISTED"===o.message||o.message&&o.message.includes("Domain not whitelisted"))||this.showError(o),this.stopStreamingState();case 6:return t.a(2)}},t,this,[[3,5]])})),function(){return n.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var t=document.getElementById("sendButton");t&&(t.disabled=!this.isActive)}},{key:"addMessage",value:function(t,e){var n=document.getElementById("messagesContainer");if(n){var o=n.querySelector(".empty-state");o&&o.remove();var i=document.createElement("div"),r="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";i.className="message ".concat(t," ").concat(r);var a=document.createElement("div");a.className="message-avatar ".concat(t),a.textContent="user"===t?"👤":"🤖";var c=document.createElement("div");c.className="message-bubble",c.textContent=e,i.appendChild(a),i.appendChild(c),n.appendChild(i),n.scrollTop=n.scrollHeight}}},{key:"beginStreaming",value:function(){var t=document.getElementById("messagesContainer");if(t){this.stopStreamingState();var e=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";e.className="message agent ".concat(n),e.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var i=document.createElement("div");i.className="message-bubble",i.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',e.appendChild(o),e.appendChild(i),t.appendChild(e),this.streamingEl=i,this.hasStartedStreaming=!1,t.scrollTop=t.scrollHeight}}},{key:"appendStreamingChunk",value:function(t){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=t;var e=document.getElementById("messagesContainer");e&&(e.scrollTop=e.scrollHeight)}}},{key:"finalizeStreaming",value:function(t){if(this.streamingEl){this.streamingEl.textContent=t||this.streamingEl.textContent;var e=document.getElementById("agent-streaming");e&&(e.id=""),this.streamingEl=null}this.updateSendButtonState()}},{key:"stopStreamingState",value:function(){var t=document.getElementById("agent-streaming");t&&t.remove(),this.streamingEl=null,this.hasStartedStreaming=!1}},{key:"showError",value:function(t){var e=document.getElementById("messagesContainer");if(e){if(t&&("DOMAIN_NOT_WHITELISTED"===t.message||"string"==typeof t&&t.includes("DOMAIN_NOT_WHITELISTED")||t.message&&t.message.includes("Domain not whitelisted")||"string"==typeof t&&t.includes("Domain not whitelisted"))){var n,o=document.createElement("div");o.className="error-message",o.style.cssText="padding: 16px; margin: 12px; border-radius: 8px; background: "+((null===(n=this.config.messages)||void 0===n?void 0:n.errorBackgroundColor)||"#FEE2E2")+";";var i=document.createElement("div");i.style.cssText="font-weight: 600; font-size: 16px; margin-bottom: 8px; color: #991B1B;",i.textContent=this.t("domainNotValidated");var r=document.createElement("div");r.style.cssText="font-size: 14px; color: #991B1B; line-height: 1.5;",r.textContent=this.t("domainErrorMessage"),o.appendChild(i),o.appendChild(r),e.appendChild(o)}else{var a=document.createElement("div");a.className="error-message",a.textContent="string"==typeof t?t:(null==t?void 0:t.message)||t,e.appendChild(a)}e.scrollTop=e.scrollHeight}}},{key:"setActive",value:function(t){this.isActive=t,this.updateSendButtonState()}}],e&&ge(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();const be={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 xe(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function r(n,o,i,r){var s=o&&o.prototype instanceof c?o:c,l=Object.create(s.prototype);return we(l,"_invoke",function(n,o,i){var r,c,s,l=0,u=i||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return r=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&l&&!i&&e<u.length;e++){var i,r=u[e],p=f.p,v=r[2];n>3?(i=v===o)&&(s=r[(c=r[4])?5:(c=3,3)],r[4]=r[5]=t):r[0]<=p&&((i=n<2&&p<r[1])?(c=0,f.v=o,f.n=r[1]):p<v&&(i=n<3||r[0]>o||o>v)&&(r[4]=n,r[5]=o,f.n=v,c=0))}if(i||n>1)return a;throw d=!0,o}return function(i,u,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,v),c=u,s=v;(e=c<2?t:s)||!d;){r||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(l=2,r){if(c||(i="next"),e=r[i]){if(!(e=e.call(r,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=r.return)&&e.call(r),c<2&&(s=TypeError("The iterator does not provide a '"+i+"' method"),c=1);r=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){r=t,c=1,s=e}finally{l=1}}return{value:e,done:d}}}(n,i,r),!0),l}var a={};function c(){}function s(){}function l(){}e=Object.getPrototypeOf;var u=[][o]?e(e([][o]())):(we(e={},o,function(){return this}),e),d=l.prototype=c.prototype=Object.create(u);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,we(t,i,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=l,we(d,"constructor",l),we(l,"constructor",s),s.displayName="GeneratorFunction",we(l,i,"GeneratorFunction"),we(d),we(d,i,"Generator"),we(d,o,function(){return this}),we(d,"toString",function(){return"[object Generator]"}),(xe=function(){return{w:r,m:f}})()}function we(t,e,n,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}we=function(t,e,n,o){function r(e,n){we(t,e,function(t){return this._invoke(e,n,t)})}e?i?i(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(r("next",0),r("throw",1),r("return",2))},we(t,e,n,o)}function Se(t,e,n,o,i,r,a){try{var c=t[r](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,i)}function ke(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var r=t.apply(e,n);function a(t){Se(r,o,i,a,c,"next",t)}function c(t){Se(r,o,i,a,c,"throw",t)}a(void 0)})}}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 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 Oe(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){Ee(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 Ee(t,e,n){return(e=Pe(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function je(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"!=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+""}var Te=function(){return t=function t(){var e,n,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=this.mergeWithDefaults(o),this.sdk=new Ot(this.config),this.isOpen=!1,this.isActive=!1,this.translations=be,this.currentView="landing";var i=Oe(Oe(Oe({},this.config),this.config.voice),{},{language:(null===(e=this.config.voice)||void 0===e?void 0:e.language)||this.config.language||"en",websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations});this.voiceInterface=new ue(i);var r=Oe(Oe(Oe({},this.config),this.config.text),{},{translations:this.translations});if(this.textInterface=new me(r,this.sdk),this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var a=document.getElementById("text-chat-panel");a&&(this.isOpen=!0,a.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,i,r,a,c,s,l,u,d,f,p,v,h,g,y,m,b,x,w,S,k,C,I,O,E,j,P,T,B,F,D,A,_,M,R,z,L,H,U,N,K,W,V,G,q,Q,Y,J,$,X,Z,tt,et,nt,ot,it,rt,at,ct,st,lt,ut,dt,ft,pt,vt,ht,gt,yt,mt,bt,xt,wt,St,kt,Ct,It,Ot,Et,jt,Pt,Tt,Bt,Ft,Dt,At,_t,Mt,Rt,zt,Lt,Ht,Ut,Nt,Kt,Wt,Vt,Gt,qt,Qt,Yt,Jt,$t,Xt,Zt,te,ee,ne,oe,ie,re,ae,ce,se,le,ue,de,fe,pe,ve,he,ge,ye,me,be,xe,we,Se,ke,Ie,Ee,je,Pe=t.position||"bottom-right";if("string"==typeof Pe){var Te=Pe.split("-");Pe={vertical:Te[0]||"bottom",horizontal:Te[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var Be=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",Fe=(null===(o=t.header)||void 0===o?void 0:o.backgroundColor)||(null===(i=t.button)||void 0===i?void 0:i.backgroundColor)||Be;return Oe({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:Oe({type:(null===(r=t.icon)||void 0===r?void 0:r.type)||"custom",customImage:(null===(a=t.icon)||void 0===a?void 0:a.customImage)||"https://talktopc.com/logo192.png",emoji:(null===(c=t.icon)||void 0===c?void 0:c.emoji)||"🎤",text:(null===(s=t.icon)||void 0===s?void 0:s.text)||"AI",size:(null===(l=t.icon)||void 0===l?void 0:l.size)||"medium",backgroundColor:(null===(u=t.icon)||void 0===u?void 0:u.backgroundColor)||"#FFFFFF"},t.icon),position:Oe({vertical:Pe.vertical||"bottom",horizontal:Pe.horizontal||"right",offset:Pe.offset||{x:20,y:20}},"object"===Ce(t.position)?t.position:{}),button:Oe({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===(v=t.icon)||void 0===v?void 0:v.backgroundColor)||Be,hoverColor:(null===(h=t.button)||void 0===h?void 0:h.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)||Be},t.button),panel:Oe({width:(null===(x=t.panel)||void 0===x?void 0:x.width)||350,height:(null===(w=t.panel)||void 0===w?void 0:w.height)||500,borderRadius:(null===(S=t.panel)||void 0===S?void 0:S.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===(I=t.panel)||void 0===I?void 0:I.border)||"1px solid rgba(0,0,0,0.1)"},t.panel),voice:Oe({micButtonColor:(null===(O=t.voice)||void 0===O?void 0:O.micButtonColor)||(null===(E=t.panel)||void 0===E?void 0:E.micButtonColor)||Be,micButtonActiveColor:(null===(j=t.voice)||void 0===j?void 0:j.micButtonActiveColor)||(null===(P=t.panel)||void 0===P?void 0:P.micButtonActiveColor)||"#EF4444",micButtonHint:Oe(Oe({text:(null===(T=t.voice)||void 0===T||null===(T=T.micButtonHint)||void 0===T?void 0:T.text)||(null===(B=t.panel)||void 0===B||null===(B=B.micButtonHint)||void 0===B?void 0:B.text)||"Click the button to start voice conversation",color:(null===(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===(A=t.voice)||void 0===A||null===(A=A.micButtonHint)||void 0===A?void 0:A.fontSize)||(null===(_=t.panel)||void 0===_||null===(_=_.micButtonHint)||void 0===_?void 0:_.fontSize)||"12px"},null===(M=t.voice)||void 0===M?void 0:M.micButtonHint),null===(R=t.panel)||void 0===R?void 0:R.micButtonHint),avatarBackgroundColor:(null===(z=t.voice)||void 0===z?void 0:z.avatarBackgroundColor)||"#667eea",avatarActiveBackgroundColor:(null===(L=t.voice)||void 0===L?void 0:L.avatarActiveBackgroundColor)||"#667eea",statusTitleColor:(null===(H=t.voice)||void 0===H?void 0:H.statusTitleColor)||"#1e293b",statusSubtitleColor:(null===(U=t.voice)||void 0===U?void 0:U.statusSubtitleColor)||"#64748b",startCallButtonColor:(null===(N=t.voice)||void 0===N?void 0:N.startCallButtonColor)||"#667eea",startCallButtonTextColor:(null===(K=t.voice)||void 0===K?void 0:K.startCallButtonTextColor)||"#FFFFFF",transcriptBackgroundColor:(null===(W=t.voice)||void 0===W?void 0:W.transcriptBackgroundColor)||"#FFFFFF",transcriptTextColor:(null===(V=t.voice)||void 0===V?void 0:V.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===(Y=t.voice)||void 0===Y?void 0:Y.endCallButtonColor)||"#ef4444",language:(null===(J=t.voice)||void 0===J?void 0:J.language)||t.language||"en",websocketUrl:(null===($=t.voice)||void 0===$?void 0:$.websocketUrl)||t.websocketUrl},t.voice),text:Oe({sendButtonColor:(null===(X=t.text)||void 0===X?void 0:X.sendButtonColor)||(null===(Z=t.panel)||void 0===Z?void 0:Z.sendButtonColor)||"#7C3AED",sendButtonHoverColor:(null===(tt=t.text)||void 0===tt?void 0:tt.sendButtonHoverColor)||(null===(et=t.panel)||void 0===et?void 0:et.sendButtonHoverColor)||"#6D28D9",sendButtonActiveColor:(null===(nt=t.text)||void 0===nt?void 0:nt.sendButtonActiveColor)||(null===(ot=t.panel)||void 0===ot?void 0:ot.sendButtonActiveColor)||"#6D28D9",sendButtonText:(null===(it=t.text)||void 0===it?void 0:it.sendButtonText)||(null===(rt=t.panel)||void 0===rt?void 0:rt.sendButtonText)||"➤",sendButtonTextColor:(null===(at=t.text)||void 0===at?void 0:at.sendButtonTextColor)||(null===(ct=t.panel)||void 0===ct?void 0:ct.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(st=t.text)||void 0===st?void 0:st.sendButtonFontSize)||(null===(lt=t.panel)||void 0===lt?void 0:lt.sendButtonFontSize)||"18px",sendButtonFontWeight:(null===(ut=t.text)||void 0===ut?void 0:ut.sendButtonFontWeight)||(null===(dt=t.panel)||void 0===dt?void 0:dt.sendButtonFontWeight)||"500",sendButtonHint:Oe(Oe({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===(vt=t.text)||void 0===vt||null===(vt=vt.sendButtonHint)||void 0===vt?void 0:vt.color)||(null===(ht=t.panel)||void 0===ht||null===(ht=ht.sendButtonHint)||void 0===ht?void 0:ht.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===(xt=t.text)||void 0===xt?void 0:xt.inputPlaceholder)||(null===(wt=t.panel)||void 0===wt?void 0:wt.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(St=t.text)||void 0===St?void 0:St.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===(It=t.panel)||void 0===It?void 0:It.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===(jt=t.text)||void 0===jt?void 0:jt.inputTextColor)||(null===(Pt=t.panel)||void 0===Pt?void 0:Pt.inputTextColor)||"#1F2937",inputFontSize:(null===(Tt=t.text)||void 0===Tt?void 0:Tt.inputFontSize)||(null===(Bt=t.panel)||void 0===Bt?void 0:Bt.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===(At=t.text)||void 0===At?void 0:At.inputPadding)||(null===(_t=t.panel)||void 0===_t?void 0:_t.inputPadding)||"6px 14px"},t.text),landing:Oe({backgroundColor:(null===(Mt=t.landing)||void 0===Mt?void 0:Mt.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)",logo:(null===(Rt=t.landing)||void 0===Rt?void 0:Rt.logo)||"🤖",title:(null===(zt=t.landing)||void 0===zt?void 0:zt.title)||null,titleColor:(null===(Lt=t.landing)||void 0===Lt?void 0:Lt.titleColor)||"#1e293b",modeCardBackgroundColor:(null===(Ht=t.landing)||void 0===Ht?void 0:Ht.modeCardBackgroundColor)||"#FFFFFF",modeCardBorderColor:(null===(Ut=t.landing)||void 0===Ut?void 0:Ut.modeCardBorderColor)||"#E2E8F0",modeCardHoverBorderColor:(null===(Nt=t.landing)||void 0===Nt?void 0:Nt.modeCardHoverBorderColor)||Fe,modeCardIconBackgroundColor:(null===(Kt=t.landing)||void 0===Kt?void 0:Kt.modeCardIconBackgroundColor)||Fe,modeCardTitleColor:(null===(Wt=t.landing)||void 0===Wt?void 0:Wt.modeCardTitleColor)||"#111827",voiceCardIcon:(null===(Vt=t.landing)||void 0===Vt?void 0:Vt.voiceCardIcon)||"🎤",textCardIcon:(null===(Gt=t.landing)||void 0===Gt?void 0:Gt.textCardIcon)||"💬"},t.landing),header:Oe({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===(Yt=t.header)||void 0===Yt?void 0:Yt.backgroundColor)||(null===(Jt=t.button)||void 0===Jt?void 0:Jt.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:Oe({newChat:(null===(Zt=t.tooltips)||void 0===Zt?void 0:Zt.newChat)||null,back:(null===(te=t.tooltips)||void 0===te?void 0:te.back)||null,close:(null===(ee=t.tooltips)||void 0===ee?void 0:ee.close)||null,mute:(null===(ne=t.tooltips)||void 0===ne?void 0:ne.mute)||null,speaker:(null===(oe=t.tooltips)||void 0===oe?void 0:oe.speaker)||null,endCall:(null===(ie=t.tooltips)||void 0===ie?void 0:ie.endCall)||null},t.tooltips),messages:Oe({userBackgroundColor:(null===(re=t.messages)||void 0===re?void 0:re.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(ae=t.messages)||void 0===ae?void 0:ae.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(ce=t.messages)||void 0===ce?void 0:ce.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(se=t.messages)||void 0===se?void 0:se.errorBackgroundColor)||"#FEE2E2",textColor:(null===(le=t.messages)||void 0===le?void 0:le.textColor)||"#1F2937",fontSize:(null===(ue=t.messages)||void 0===ue?void 0:ue.fontSize)||"14px",borderRadius:(null===(de=t.messages)||void 0===de?void 0:de.borderRadius)||8},t.messages),animation:Oe({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===(ve=t.animation)||void 0===ve?void 0:ve.enableSlide),duration:(null===(he=t.animation)||void 0===he?void 0:he.duration)||.3},t.animation),behavior:Oe({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===(xe=t.behavior)||void 0===xe?void 0:xe.showWelcomeMessage),welcomeMessage:(null===(we=t.behavior)||void 0===we?void 0:we.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:void 0===(null===(Se=t.behavior)||void 0===Se?void 0:Se.enableVoiceMode)||t.behavior.enableVoiceMode,mode:(null===(ke=t.behavior)||void 0===ke?void 0:ke.mode)||"unified"},t.behavior),accessibility:Oe({ariaLabel:(null===(Ie=t.accessibility)||void 0===Ie?void 0:Ie.ariaLabel)||"Chat Assistant",ariaDescription:(null===(Ee=t.accessibility)||void 0===Ee?void 0:Ee.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(je=t.accessibility)||void 0===je?void 0:je.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},forceConversationId:t.forceConversationId,primaryColor:Be},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.on("domainError",function(e){t.textInterface.showError(e),t.textInterface.stopStreamingState()}),this.sdk.on("error",function(e){e&&("DOMAIN_NOT_WHITELISTED"===e.message||e.message&&e.message.includes("Domain not whitelisted"))||(t.textInterface.showError(e.message||e),t.textInterface.stopStreamingState())}),this.sdk.on("chunk",function(e){t.textInterface.appendStreamingChunk(e)}),this.sdk.on("done",function(e){var n=e.text;t.textInterface.finalizeStreaming(n)})}},{key:"createWidget",value:function(){console.log("🏗️ createWidget called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var t=document.getElementById("text-chat-widget");t&&t.remove();var e=document.createElement("div");if(e.id="text-chat-widget",e.innerHTML=this.generateWidgetHTML(),document.body.appendChild(e),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("text-chat-panel");n&&(this.isOpen=!0,n.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){var t=this,e=(this.config.position,this.config.button),n=this.config.icon,o=(this.config.panel,this.config.header),i=(this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),r={small:20,medium:28,large:36,xl:44}[n.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(r),s=this.config.behavior.mode||"unified",l="unified"===s,u="unified"===s||"voice-only"===s,d="unified"===s||"text-only"===s,f=function(e){var n=t.config.language||"en";return(t.translations[n]||t.translations.en)[e]||e},p=function(e){var n,o=null===(n=t.config.tooltips)||void 0===n?void 0:n[e];return null!=o?o:{newChat:f("newChat"),back:f("back"),close:f("close"),mute:f("mute"),speaker:f("speaker"),endCall:f("endCall")}[e]||""};return"\n <style>\n ".concat(this.generateCSS(a,i,r),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header" style="background: ').concat(o.backgroundColor,"; color: ").concat(o.textColor,';">\n <div>\n ').concat(o.showTitle?'<div class="header-title">'.concat(o.title,"</div>"):"",'\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat(f("online"),'</span>\n </div>\n </div>\n \n <div style="display: flex; gap: 12px; align-items: center;">\n \x3c!-- New Chat Button (hide on landing screen, show otherwise) --\x3e\n <button class="header-icon new-chat-btn" id="newChatBtn" title="').concat(p("newChat"),'" style="').concat(l?"display: none;":"",'">\n <span style="font-size: 18px; font-weight: bold;">+</span>\n </button>\n \n \x3c!-- Back Button (only show in unified mode) --\x3e\n ').concat("unified"===s?'<button class="header-icon back-btn" id="backBtn" title="'.concat(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(l?'\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(u?'<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(u?this.voiceInterface.generateHTML():"","\n ").concat(d?this.textInterface.generateHTML():"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var t=this.config.position,e=t.offset||{x:20,y:20},n="";return"top"===t.vertical?n+="top: ".concat(e.y,"px;"):"bottom"===t.vertical?n+="bottom: ".concat(e.y,"px;"):"center"===t.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===t.horizontal?n+="left: ".concat(e.x,"px;"):"right"===t.horizontal?n+="right: ".concat(e.x,"px;"):"center"===t.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(t){var e=this.config.icon;switch(e.type){case"custom":return'<img src="'.concat(e.customImage,'" alt="Chat Assistant" style="width: ').concat(t,"px; height: ").concat(t,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(t,'px; line-height: 1;">').concat(e.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*t),'px; font-weight: bold; color: white;">').concat(e.text,"</span>");case"microphone":default:return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>');case"chat":return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/>\n </svg>')}}},{key:"generateCSS",value:function(t,e,n){var o,i,r,a,c,s,l,u=this.config.button,d=this.config.icon,f=this.config.panel,p=this.config.header,v=(this.config.messages,this.config.animation),h=this.config.behavior.mode||"unified",g="unified"===h||"voice-only"===h,y="unified"===h||"text-only"===h,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"===u.shape?"50%":"square"===u.shape?"0":"12px",";\n background: ").concat(u.backgroundColor||d.backgroundColor||"#7C3AED",";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(v.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(v.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(v.enableSlide?"transition: all ".concat(v.duration,"s ease;"):"","\n box-sizing: border-box;\n }\n \n #text-chat-panel.open {\n display: flex;\n ").concat(v.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n\n /* Shell for gradient border/background */\n .widget-shell { width: 100%; height: 100%; padding: 0; border-radius: ").concat(f.borderRadius,"px; background: transparent; box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; display: flex; flex-direction: column; box-sizing: border-box; }\n .panel-inner { width: 100%; height: 100%; background: #ffffff; border-radius: ").concat(f.borderRadius,"px; overflow: hidden; display:flex; flex-direction: column; padding: 0; box-sizing: border-box; max-width: 100%; }\n\n /* New structure styles matching provided design */\n #text-chat-panel .widget-container {\n width: 100%; height: 100%; min-height: 0; background: #FFFFFF; overflow: hidden; display: flex; flex-direction: column; border-radius: ").concat(f.borderRadius,"px;\n container-type: size;\n }\n \n /* Ensure content areas can scroll when height is constrained */\n #text-chat-panel .widget-container > .landing-screen,\n #text-chat-panel .widget-container > .voice-interface,\n #text-chat-panel .widget-container > .text-interface {\n flex: 1;\n min-height: 0;\n overflow-y: auto;\n overflow-x: hidden;\n }\n \n /* Header should not scroll */\n #text-chat-panel .widget-header {\n padding: 12px 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-top-left-radius: ").concat(f.borderRadius,"px;\n border-top-right-radius: ").concat(f.borderRadius,"px;\n flex-shrink: 0;\n min-height: 60px;\n box-sizing: border-box;\n }\n #text-chat-panel .header-title { font-size: 16px; font-weight: 600; }\n #text-chat-panel .header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: 0.9; }\n #text-chat-panel .status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }\n @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n /* Header icon buttons */\n .header-icon {\n background: rgba(255, 255, 255, 0.2);\n border: none;\n color: white;\n width: 36px;\n height: 36px;\n min-width: 36px;\n min-height: 36px;\n border-radius: 50%;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.2s;\n flex-shrink: 0;\n font-size: 16px;\n padding: 0;\n box-sizing: border-box;\n }\n \n .header-icon:hover {\n background: rgba(255, 255, 255, 0.3);\n }\n \n .header-icon svg {\n pointer-events: none;\n stroke: white;\n fill: none;\n }\n \n .back-btn.visible {\n display: flex !important;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { \n display: none; \n flex: 1; \n padding: 20px; \n background: ").concat((null===(o=this.config.landing)||void 0===o?void 0:o.backgroundColor)||"linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%)","; \n align-items: center; \n justify-content: flex-start; \n flex-direction: column; \n gap: 16px; \n overflow-y: auto; \n min-height: 0; \n }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { \n font-size: 20px; \n color: ").concat((null===(i=this.config.landing)||void 0===i?void 0:i.titleColor)||"#1e293b","; \n font-weight: 700; \n margin-bottom: 20px; \n text-align: center;\n width: 100%;\n }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { \n flex: 1; \n max-width: 180px; \n background: ").concat((null===(r=this.config.landing)||void 0===r?void 0:r.modeCardBackgroundColor)||"#FFFFFF","; \n border: 2px solid ").concat((null===(a=this.config.landing)||void 0===a?void 0:a.modeCardBorderColor)||"#E2E8F0","; \n border-radius: 20px; \n padding: 20px 12px; \n cursor: pointer; \n display: flex; \n flex-direction: column; \n align-items: center; \n gap: 8px; \n transition: transform ").concat(v.duration,"s ease, box-shadow ").concat(v.duration,"s ease, border-color ").concat(v.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===(l=this.config.landing)||void 0===l?void 0:l.modeCardTitleColor)||"#111827","; \n font-weight: 600; \n text-align: center;\n width: 100%;\n }\n\n ").concat(g?this.voiceInterface.generateCSS():"","\n ").concat(y?this.textInterface.generateCSS():"","\n \n #text-chat-send-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this;console.log("⚙️ setupWidgetEvents called",{stack:(new Error).stack.split("\n").slice(1,6).join("\n"),currentView:this.currentView});var e=document.getElementById("text-chat-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("closeBtn");n&&(n.onclick=function(){return t.togglePanel()});var o=this.config.behavior.mode||"unified",i="unified"===o,r="unified"===o||"voice-only"===o,a="unified"===o||"text-only"===o,c=document.getElementById("backBtn"),s=document.getElementById("landingScreen"),l=document.getElementById("mode-card-voice"),u=document.getElementById("mode-card-text"),d=document.getElementById("textInterface"),f=document.getElementById("voiceInterface");c&&(c.onclick=function(){return t.showLanding()}),i?(l&&(l.onclick=function(){return t.showVoice()}),u&&(u.onclick=function(){return t.showText()}),"text"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.add("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="")):"voice"===this.currentView?(s&&s.classList.remove("active"),d&&d.classList.remove("active"),f&&f.classList.add("active"),c&&"unified"===o&&c.classList.add("visible"),p&&(p.style.display="none")):(this.currentView="landing",s&&s.classList.add("active"),d&&d.classList.remove("active"),f&&f.classList.remove("active"),c&&"unified"===o&&c.classList.remove("visible"))):"voice-only"===o?(f&&f.classList.add("active"),d&&d.classList.remove("active"),s&&s.classList.remove("active")):"text-only"===o&&(d&&d.classList.add("active"),f&&f.classList.remove("active"),s&&s.classList.remove("active")),r&&(console.log("⚙️ Setting up voice interface event handlers"),this.voiceInterface.setupEventHandlers()),a&&(console.log("⚙️ Setting up text interface event handlers"),this.textInterface.setupEventHandlers());var p=document.getElementById("newChatBtn");p&&(p.onclick=function(){return t.textInterface.startNewChat()},i&&(p.style.display="none")),this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"startNewChat",value:function(){this.textInterface.startNewChat()}},{key:"showLanding",value:function(){if("unified"===(this.config.behavior.mode||"unified")){this.currentView="landing";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),i=document.getElementById("newChatBtn");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active"),o&&o.classList.remove("visible"),i&&(i.style.display="none")}}},{key:"showText",value:function(){this.currentView="text";var t=document.getElementById("landingScreen"),e=document.getElementById("voiceInterface"),n=document.getElementById("backBtn"),o=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),this.textInterface.show();var i=this.config.behavior.mode||"unified";n&&"unified"===i&&n.classList.add("visible"),o&&(o.style.display="")}},{key:"showVoice",value:function(){this.currentView="voice";var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface"),o=document.getElementById("backBtn"),i=document.getElementById("newChatBtn");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active");var r=this.config.behavior.mode||"unified";o&&"unified"===r&&o.classList.add("visible"),i&&(i.style.display="none")}},{key:"setupKeyboardNavigation",value:function(){var t=this;document.addEventListener("keydown",function(e){"Escape"===e.key&&t.isOpen&&t.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("text-chat-panel").classList.toggle("open"),this.isOpen&&setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},100),this.isOpen&&!this.isActive&&this.config.behavior.autoConnect&&this.startChat()}},{key:"startChat",value:(r=ke(xe().m(function t(){return xe().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.textInterface.setActive(!0);case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"sendMessage",value:(i=ke(xe().m(function t(){return xe().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.textInterface.sendMessage();case 1:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){this.textInterface.updateSendButtonState()}},{key:"getSignedUrl",value:(o=ke(xe().m(function t(){var e,n,o,i,r,a,c;return xe().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://backend.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((i=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(i.statusText));case 4:return t.n=5,i.json();case 5:return r=t.v,t.a(2,r.signedUrl||r.wsUrl||r.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return o.apply(this,arguments)})},{key:"addMessage",value:function(t,e){this.textInterface.addMessage(t,e)}},{key:"beginStreaming",value:function(){this.textInterface.beginStreaming()}},{key:"appendStreamingChunk",value:function(t){this.textInterface.appendStreamingChunk(t)}},{key:"finalizeStreaming",value:function(t){this.textInterface.finalizeStreaming(t)}},{key:"stopStreamingState",value:function(){this.textInterface.stopStreamingState()}},{key:"showError",value:function(t){this.textInterface.showError(t)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n;console.log("🔄 updateConfig called",{newConfig:t,stack:(new Error).stack.split("\n").slice(1,6).join("\n")});var o,i,r=Oe({},this.config);t.panel&&(r.panel=Oe(Oe({},this.config.panel),t.panel)),t.voice&&(r.voice=Oe(Oe({},this.config.voice),t.voice),t.voice.micButtonHint&&(r.voice.micButtonHint=Oe(Oe({},null===(o=this.config.voice)||void 0===o?void 0:o.micButtonHint),t.voice.micButtonHint))),t.text&&(r.text=Oe(Oe({},this.config.text),t.text),t.text.sendButtonHint&&(r.text.sendButtonHint=Oe(Oe({},null===(i=this.config.text)||void 0===i?void 0:i.sendButtonHint),t.text.sendButtonHint))),void 0!==t.language&&(r.language=t.language),void 0!==t.language&&(["he","ar"].includes(t.language)?r.direction="rtl":void 0===t.direction&&(r.direction="ltr")),t.translations&&(r.translations=t.translations,this.translations=t.translations),t.button&&(r.button=Oe(Oe({},this.config.button),t.button)),t.header&&(r.header=Oe(Oe({},this.config.header),t.header)),t.icon&&(r.icon=Oe(Oe({},this.config.icon),t.icon)),t.messages&&(r.messages=Oe(Oe({},this.config.messages),t.messages)),t.animation&&(r.animation=Oe(Oe({},this.config.animation),t.animation)),t.behavior&&(r.behavior=Oe(Oe({},this.config.behavior),t.behavior)),t.accessibility&&(r.accessibility=Oe(Oe({},this.config.accessibility),t.accessibility)),t.tooltips&&(r.tooltips=Oe(Oe({},this.config.tooltips),t.tooltips)),t.landing&&(r.landing=Oe(Oe({},this.config.landing),t.landing)),void 0!==t.direction&&void 0===r.direction&&(r.direction=t.direction),void 0!==t.primaryColor&&(r.primaryColor=t.primaryColor),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction","voice","text","animation","behavior","accessibility","language","tooltips","landing","primaryColor"].includes(e)||(r[e]=t[e])}),null===(e=this.config)||void 0===e||e.language,this.config=this.mergeWithDefaults(r);var a=this.config.language||"en",c=Oe(Oe(Oe({},this.config),this.config.voice),{},{language:a,websocketUrl:(null===(n=this.config.voice)||void 0===n?void 0:n.websocketUrl)||this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",translations:this.translations});this.voiceInterface=new ue(c);var s=Oe(Oe(Oe({},this.config),this.config.text),{},{language:a,translations:this.translations});this.textInterface=new me(s,this.sdk);var l=document.getElementById("text-chat-widget");l&&l.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=ke(xe().m(function t(){return xe().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&&je(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,i,r}(),Be="2.0.0";const Fe={VoiceSDK:pt,TextChatSDK:Ot,WebSocketManager:B,AudioRecorder:K,AudioPlayer:Z,EventEmitter:c,VoiceButton:zt,VanillaVoiceButton:Qt,AgentSDK:ne,TTPChatWidget:Te,VERSION:Be};return o})());
3
3
  //# sourceMappingURL=agent-widget.js.map