ttp-agent-sdk 2.2.4 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-widget.js +1 -1
- package/dist/agent-widget.js.map +1 -1
- package/package.json +1 -1
package/dist/agent-widget.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see agent-widget.js.LICENSE.txt */
|
|
2
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==e.key&&(r=""+e.key),"key"in e)for(var i in o={},e)"key"!==i&&(o[i]=e[i]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:r,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},i.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=i.prototype;var s=c.prototype=new a;s.constructor=c,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var u={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return u.H.useEffect(t,e)},e.useRef=function(t){return u.H.useRef(t)},e.useState=function(t){return u.H.useState(t)}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>ae,AgentWidget:()=>ce,AudioPlayer:()=>Z,AudioRecorder:()=>K,EventEmitter:()=>c,TextChatSDK:()=>Ct,TextChatWidget:()=>be,VERSION:()=>me,VanillaVoiceButton:()=>Qt,VoiceButton:()=>At,VoiceSDK:()=>ft,WebSocketManager:()=>T,default:()=>we});var c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||d(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=d(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function d(t,e){if(t){if("string"==typeof t)return f(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return g(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(g(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,g(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,g(d,"constructor",u),g(u,"constructor",s),s.displayName="GeneratorFunction",g(u,r,"GeneratorFunction"),g(d),g(d,r,"Generator"),g(d,o,function(){return this}),g(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:f}})()}function g(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}g=function(t,e,n,o){function i(e,n){g(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},g(t,e,n,o)}function h(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function v(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 b(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(b=function(){return!!t})()}function m(t){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},m(t)}function w(t,e){return w=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},w(t,e)}const k=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=m(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,b()?Reflect.construct(e,n||[],m(t).constructor):e.apply(t,n))}(this,e)).connections=new Map,t.connectionCounts=new Map,t.creatingConnections=new Set,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&w(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=p().m(function t(e){var n,o,r=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(r.connections.has(e)){var o=r.connections.get(e);r.connectionCounts.set(e,(r.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){r.creatingConnections.delete(e),r.emit("error",t,e)}),o.addEventListener("message",function(t){r.emit("message",t,e)}),t.a(2,o)}},t,this)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){h(i,n,o,a,c,"next",t)}function c(t){h(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=l(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=u(t.value,2),r=o[0],i=o[1];e[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&v(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(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 x(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return O(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(O(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,O(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,O(d,"constructor",u),O(u,"constructor",s),s.displayName="GeneratorFunction",O(u,r,"GeneratorFunction"),O(d),O(d,r,"Generator"),O(d,o,function(){return this}),O(d,"toString",function(){return"[object Generator]"}),(x=function(){return{w:i,m:f}})()}function O(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}O=function(t,e,n,o){function i(e,n){O(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},O(t,e,n,o)}function C(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function j(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,P(o.key),o)}}function P(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 E(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(E=function(){return!!t})()}function I(t){return I=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},I(t)}function B(t,e){return B=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},B(t,e)}var T=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=I(e),function(t,e){if(e&&("object"==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,E()?Reflect.construct(e,n||[],I(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&B(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=x().m(function t(){var e=this;return x().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,k.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t(),e.connectResolve=null,e.connectReject=null)}).catch(function(t){console.error("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null})}catch(t){console.error("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null}}))},t)}),a=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){C(r,n,o,a,c,"next",t)}function c(t){C(r,n,o,a,c,"throw",t)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};k.on("open",e),k.on("close",n),k.on("error",o),k.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(k.off("open",this.eventHandlers.open),k.off("close",this.eventHandlers.close),k.off("error",this.eventHandlers.error),k.off("message",this.eventHandlers.message)),this.config.websocketUrl&&k.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(t))}catch(t){console.warn("🔌 WebSocketManager: Failed to send message:",t.message)}}},{key:"sendBinary",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(t)}catch(t){console.warn("🔌 WebSocketManager: Failed to send binary data:",t.message)}}},{key:"handleMessage",value:function(t){var e=this;if(t.data instanceof ArrayBuffer)this.emit("binaryAudio",t.data);else if(t.data instanceof Blob)t.data.arrayBuffer().then(function(t){e.emit("binaryAudio",t)}).catch(function(t){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return k.getAllConnections()}},{key:"clearAllConnections",value:function(){k.clearAll()}}],o&&j(n.prototype,o),r&&j(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a}(c);function F(t){return F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},F(t)}function R(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return _(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(_(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,_(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,_(d,"constructor",u),_(u,"constructor",s),s.displayName="GeneratorFunction",_(u,r,"GeneratorFunction"),_(d),_(d,r,"Generator"),_(d,o,function(){return this}),_(d,"toString",function(){return"[object Generator]"}),(R=function(){return{w:i,m:f}})()}function _(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}_=function(t,e,n,o){function i(e,n){_(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},_(t,e,n,o)}function D(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function M(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){D(i,o,r,a,c,"next",t)}function c(t){D(i,o,r,a,c,"throw",t)}a(void 0)})}}function A(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 z(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(z=function(){return!!t})()}function U(t){return U=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},U(t)}function H(t,e){return H=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},H(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,z()?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&&H(t,e)}(e,t),n=e,o=[{key:"start",value:(i=M(R().m(function t(){var e,n=this;return R().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 t.n=3,this.audioContext.audioWorklet.addModule("/audio-processor.js");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,o=e.type,r=e.data;"pcm_audio_data"===o&&n.emit("audioData",r)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,e=t.v,this.emit("error",e),e;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=M(R().m(function t(){var e;return R().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&A(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(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 N(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return G(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(G(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,G(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,G(d,"constructor",u),G(u,"constructor",s),s.displayName="GeneratorFunction",G(u,r,"GeneratorFunction"),G(d),G(d,r,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(N=function(){return{w:i,m:f}})()}function G(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}G=function(t,e,n,o){function i(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},G(t,e,n,o)}function V(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function 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,q(o.key),o)}}function q(t){var e=function(t){if("object"!=W(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=W(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==W(e)?e:e+""}function Y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Y=function(){return!!t})()}function J(t){return J=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},J(t)}function $(t,e){return $=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},$(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=J(e),function(t,e){if(e&&("object"==W(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Y()?Reflect.construct(e,n||[],J(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&&$(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(r=N().m(function t(){var e,n,o,r,i,a,c,s,u=this;return N().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 r=t.v,t.n=5,o.decodeAudioData(r);case 5:i=t.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=i,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){u.currentSource=null,u.isProcessingQueue=!1,u.audioQueue.length>0?setTimeout(function(){return u.processQueue()},50):setTimeout(function(){0!==u.audioQueue.length||u.currentSource||(u.isPlaying=!1,u.emit("playbackStopped"))},100)},c.start(),t.n=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 u.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){V(i,n,o,a,c,"next",t)}function c(t){V(i,n,o,a,c,"throw",t)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&Q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function X(t){return X="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},X(t)}function tt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return et(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(et(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,et(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,et(d,"constructor",u),et(u,"constructor",s),s.displayName="GeneratorFunction",et(u,r,"GeneratorFunction"),et(d),et(d,r,"Generator"),et(d,o,function(){return this}),et(d,"toString",function(){return"[object Generator]"}),(tt=function(){return{w:i,m:f}})()}function et(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}et=function(t,e,n,o){function i(e,n){et(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},et(t,e,n,o)}function nt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function ot(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){nt(i,o,r,a,c,"next",t)}function c(t){nt(i,o,r,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 it(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){at(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 at(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 ct(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,st(o.key),o)}}function st(t){var e=function(t){if("object"!=X(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=X(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==X(e)?e:e+""}function ut(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ut=function(){return!!t})()}function lt(t){return lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},lt(t)}function dt(t,e){return dt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},dt(t,e)}var ft=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=lt(e),function(t,e){if(e&&("object"==X(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ut()?Reflect.construct(e,n||[],lt(t).constructor):e.apply(t,n))}(this,e)).config=it({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 T(it(it({},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&&dt(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){t.isConnected=!1,t.isRecording&&t.stopRecording().catch(function(t){console.error("VoiceSDK: Error stopping recording on disconnect:",t)}),t.emit("disconnected",e)}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){if("greeting_audio"===e.t&&e.data)try{for(var n=atob(e.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(u=ot(tt().m(function t(){var e,n;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=ot(tt().m(function t(){return tt().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=ot(tt().m(function t(){var e;return tt().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=ot(tt().m(function t(){var e;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=it(it({},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&&ct(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(c);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 gt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ht(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ht(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ht(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ht(d,"constructor",u),ht(u,"constructor",s),s.displayName="GeneratorFunction",ht(u,r,"GeneratorFunction"),ht(d),ht(d,r,"Generator"),ht(d,o,function(){return this}),ht(d,"toString",function(){return"[object Generator]"}),(gt=function(){return{w:i,m:f}})()}function ht(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ht=function(t,e,n,o){function i(e,n){ht(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ht(t,e,n,o)}function vt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function yt(t,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?yt(Object(n),!0).forEach(function(e){mt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):yt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function mt(t,e,n){return(e=kt(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,kt(o.key),o)}}function kt(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+""}function St(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(St=function(){return!!t})()}function xt(t){return xt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},xt(t)}function Ot(t,e){return Ot=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ot(t,e)}var Ct=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=xt(e),function(t,e){if(e&&("object"==pt(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,St()?Reflect.construct(e,n||[],xt(t).constructor):e.apply(t,n))}(this,e)).readScriptTagConfig();return t.config=bt({baseWsUrl:"wss://backend.talktopc.com/chat",appId:n.appId||o.appId,agentId:n.agentId||o.agentId,conversationId:n.conversationId||t.getPersistedConversationId(),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&&Ot(t,e)}(e,t),n=e,o=[{key:"readScriptTagConfig",value:function(){try{var t=Array.from(document.getElementsByTagName("script")).reverse().find(function(t){return t.dataset&&(t.dataset.appId||t.dataset.agentId)||t.src&&t.src.includes("agent-widget")});return t?{appId:t.dataset.appId,agentId:t.dataset.agentId}:{}}catch(t){return{}}}},{key:"buildWebSocketUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,e=new URLSearchParams;return this.config.appId&&e.append("appId",this.config.appId),this.config.agentId&&e.append("agentId",this.config.agentId),this.config.conversationId&&e.append("conversationId",this.config.conversationId),"".concat(t,"?").concat(e.toString())}},{key:"sendMessage",value:(r=gt().m(function t(e){var n=this;return gt().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,o){if(e&&e.trim())if(n.config.appId&&n.config.agentId){var r={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(r):n.executeTask(r)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){vt(i,n,o,a,c,"next",t)}function c(t){vt(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"executeTask",value:function(t){var e=this;this.config.inFlight=!0,this.fullResponseBuffer="";var n=this.buildWebSocketUrl(this.config.baseWsUrl),o=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),r=this.buildWebSocketUrl(o),i=!1,a=new WebSocket(n);a.onopen=function(){try{var n={conversationId:e.config.conversationId||void 0,message:t.text};a.send(JSON.stringify(n))}catch(n){t.reject(n),e.emit("error",n);try{a.close()}catch(t){}}},a.onmessage=function(n){try{var o=JSON.parse(n.data);if("hello"===o.type&&o.conversationId)return e.config.conversationId=o.conversationId,e.persistConversationId(o.conversationId),void(e.emit&&e.emit("conversationIdChanged",o.conversationId));if("chunk"===o.type&&"string"==typeof o.content)e.fullResponseBuffer+=o.content,e.emit("chunk",o.content);else if("done"===o.type){e.config.conversationId,e.persistConversationId(e.config.conversationId),e.emit("done",{text:e.fullResponseBuffer}),t.resolve({conversationId:e.config.conversationId,fullText:e.fullResponseBuffer});try{a.close()}catch(t){}}else if("error"===o.type){var r=new Error(o.message||"Server error");e.emit("error",r),t.reject(r);try{a.close()}catch(t){}}}catch(t){}},a.onerror=function(n){if(!i){i=!0;try{a.close()}catch(t){}try{return(a=new WebSocket(r)).onopen=a.onopen,a.onmessage=a.onmessage,a.onerror=function(n){e.emit("error",n),t.reject(n)},void(a.onclose=a.onclose)}catch(n){return e.emit("error",n),void t.reject(n)}}e.emit("error",n),t.reject(n)},a.onclose=function(){e.config.inFlight=!1,e.drainQueue()}}},{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,r,i}(c),jt=n(540),Pt=n(848);function Et(t){return Et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Et(t)}function It(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Bt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?It(Object(n),!0).forEach(function(e){Tt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):It(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Tt(t,e,n){return(e=function(t){var e=function(t){if("object"!=Et(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Et(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Ft(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Rt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Rt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Rt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Rt(d,"constructor",u),Rt(u,"constructor",s),s.displayName="GeneratorFunction",Rt(u,r,"GeneratorFunction"),Rt(d),Rt(d,r,"Generator"),Rt(d,o,function(){return this}),Rt(d,"toString",function(){return"[object Generator]"}),(Ft=function(){return{w:i,m:f}})()}function Rt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Rt=function(t,e,n,o){function i(e,n){Rt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Rt(t,e,n,o)}function _t(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Dt(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Mt(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)?Mt(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 Mt(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 At=function(t){var e=t.websocketUrl,n=t.agentId,o=t.voice,r=void 0===o?"default":o,i=t.language,a=void 0===i?"en":i,c=t.autoReconnect,s=void 0===c||c,u=t.onConnected,l=t.onDisconnected,d=t.onRecordingStarted,f=t.onRecordingStopped,p=t.onPlaybackStarted,g=t.onPlaybackStopped,h=t.onError,v=t.onMessage,y=t.onBargeIn,b=t.onStopPlaying,m=t.className,w=void 0===m?"":m,k=t.style,S=void 0===k?{}:k,x=t.children,O=Dt((0,jt.useState)(!1),2),C=O[0],j=O[1],P=Dt((0,jt.useState)(!1),2),E=P[0],I=P[1],B=Dt((0,jt.useState)(!1),2),T=(B[0],B[1]),F=Dt((0,jt.useState)("Disconnected"),2),R=(F[0],F[1]),_=(0,jt.useRef)(null);(0,jt.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),_.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),_.current.destroy(),_.current=null);var t=new ft({websocketUrl:e,agentId:n,voice:r,language:a,autoReconnect:s});return t.on("connected",function(){j(!0),R("Connected"),null==u||u()}),t.on("disconnected",function(){j(!1),R("Disconnected"),null==l||l()}),t.on("recordingStarted",function(){I(!0),null==d||d()}),t.on("recordingStopped",function(){I(!1),null==f||f()}),t.on("playbackStarted",function(){T(!0),null==p||p()}),t.on("playbackStopped",function(){T(!1),null==g||g()}),t.on("error",function(t){null==h||h(t)}),t.on("message",function(t){null==v||v(t)}),t.on("bargeIn",function(t){null==y||y(t)}),t.on("stopPlaying",function(t){null==b||b(t)}),_.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),_.current&&(_.current.destroy(),_.current=null)}},[e,n,r,a]);var D=function(){var t,e=(t=Ft().m(function t(){var e;return Ft().w(function(t){for(;;)switch(t.p=t.n){case 0:if(_.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,_.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){_t(i,o,r,a,c,"next",t)}function c(t){_t(i,o,r,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),M=(0,Pt.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,Pt.jsx)("div",{style:{fontSize:"20px"},children:E?"🔴":"🎤"}),(0,Pt.jsx)("div",{children:E?"Stop Listening":"Start Listening"})]});return(0,Pt.jsx)("button",{className:"voice-button ".concat(E?"recording":""," ").concat(w),style:Bt({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:E?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},S),onClick:D,disabled:!C,children:x||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 zt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Ut(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Ut(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Ut(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Ut(d,"constructor",u),Ut(u,"constructor",s),s.displayName="GeneratorFunction",Ut(u,r,"GeneratorFunction"),Ut(d),Ut(d,r,"Generator"),Ut(d,o,function(){return this}),Ut(d,"toString",function(){return"[object Generator]"}),(zt=function(){return{w:i,m:f}})()}function Ut(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Ut=function(t,e,n,o){function i(e,n){Ut(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Ut(t,e,n,o)}function Ht(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Kt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Ht(i,o,r,a,c,"next",t)}function c(t){Ht(i,o,r,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 Nt(t,e,n){return(e=Vt(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,Vt(o.key),o)}}function Vt(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){Nt(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 ft({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(zt().m(function t(){var e;return zt().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(zt().m(function t(){var e;return zt().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 qt(t){return qt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},qt(t)}function Yt(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 Jt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Yt(Object(n),!0).forEach(function(e){$t(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function $t(t,e,n){return(e=ie(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Zt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Xt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Xt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Xt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Xt(d,"constructor",u),Xt(u,"constructor",s),s.displayName="GeneratorFunction",Xt(u,r,"GeneratorFunction"),Xt(d),Xt(d,r,"Generator"),Xt(d,o,function(){return this}),Xt(d,"toString",function(){return"[object Generator]"}),(Zt=function(){return{w:i,m:f}})()}function Xt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Xt=function(t,e,n,o){function i(e,n){Xt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Xt(t,e,n,o)}function te(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function ee(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){te(i,o,r,a,c,"next",t)}function c(t){te(i,o,r,a,c,"throw",t)}a(void 0)})}}function ne(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function oe(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ie(o.key),o)}}function re(t,e,n){return e&&oe(t.prototype,e),n&&oe(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function ie(t){var e=function(t){if("object"!=qt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=qt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==qt(e)?e:e+""}var ae=function(){return re(function t(e){ne(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){}},[{key:"connect",value:(e=ee(Zt().m(function t(e){var n,o=this;return Zt().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 ft({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(){o.isConnected=!1,o.onDisconnected()}),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 e.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:(t=ee(Zt().m(function t(){var e;return Zt().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 t.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}}]);var t,e}(),ce=function(){return re(function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(ne(this,t),this.config=this.mergeWithDefaults(e),this.sdk=new ae(this.config),this.isOpen=!1,this.isActive=!1,this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("agent-panel");n&&(this.isOpen=!0,n.classList.add("open"))}},[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,a,c,s,u,l,d,f,p,g,h,v,y,b,m,w,k,S,x,O,C,j,P,E,I,B,T,F,R,_,D,M,A,L,z,U,H,K,W,N,G,V,Q,q,Y,J,$,Z,X,tt,et=t.position||"bottom-right";if("string"==typeof et){var nt=et.split("-");et={vertical:nt[0]||"bottom",horizontal:nt[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var ot=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||"#4F46E5";return Jt({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",icon:Jt({type:(null===(n=t.icon)||void 0===n?void 0:n.type)||"microphone",customImage:(null===(o=t.icon)||void 0===o?void 0:o.customImage)||null,emoji:(null===(r=t.icon)||void 0===r?void 0:r.emoji)||"🎤",text:(null===(i=t.icon)||void 0===i?void 0:i.text)||"AI",size:(null===(a=t.icon)||void 0===a?void 0:a.size)||"medium",backgroundColor:(null===(c=t.icon)||void 0===c?void 0:c.backgroundColor)||null},t.icon),position:Jt({vertical:et.vertical||"bottom",horizontal:et.horizontal||"right",offset:et.offset||{x:20,y:20}},"object"===qt(t.position)?t.position:{}),button:Jt({size:(null===(s=t.button)||void 0===s?void 0:s.size)||"medium",shape:(null===(u=t.button)||void 0===u?void 0:u.shape)||"circle",backgroundColor:(null===(l=t.button)||void 0===l?void 0:l.backgroundColor)||(null===(d=t.icon)||void 0===d?void 0:d.backgroundColor)||ot,hoverColor:(null===(f=t.button)||void 0===f?void 0:f.hoverColor)||"#7C3AED",shadow:!1!==(null===(p=t.button)||void 0===p?void 0:p.shadow),shadowColor:(null===(g=t.button)||void 0===g?void 0:g.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(h=t.button)||void 0===h?void 0:h.backgroundColor)||(null===(v=t.icon)||void 0===v?void 0:v.backgroundColor)||ot},t.button),panel:Jt({width:(null===(y=t.panel)||void 0===y?void 0:y.width)||350,height:(null===(b=t.panel)||void 0===b?void 0:b.height)||500,borderRadius:(null===(m=t.panel)||void 0===m?void 0:m.borderRadius)||12,backgroundColor:(null===(w=t.panel)||void 0===w?void 0:w.backgroundColor)||"#FFFFFF",backdropFilter:(null===(k=t.panel)||void 0===k?void 0:k.backdropFilter)||null,border:(null===(S=t.panel)||void 0===S?void 0:S.border)||"1px solid rgba(0,0,0,0.1)",micButtonColor:(null===(x=t.panel)||void 0===x?void 0:x.micButtonColor)||ot,micButtonActiveColor:(null===(O=t.panel)||void 0===O?void 0:O.micButtonActiveColor)||"#EF4444",micButtonHint:Jt({text:(null===(C=t.panel)||void 0===C||null===(C=C.micButtonHint)||void 0===C?void 0:C.text)||"Click the button to start voice conversation",color:(null===(j=t.panel)||void 0===j||null===(j=j.micButtonHint)||void 0===j?void 0:j.color)||"#6B7280",fontSize:(null===(P=t.panel)||void 0===P||null===(P=P.micButtonHint)||void 0===P?void 0:P.fontSize)||"12px"},null===(E=t.panel)||void 0===E?void 0:E.micButtonHint)},t.panel),header:Jt({title:(null===(I=t.header)||void 0===I?void 0:I.title)||"Voice Assistant",showTitle:!1!==(null===(B=t.header)||void 0===B?void 0:B.showTitle),backgroundColor:(null===(T=t.header)||void 0===T?void 0:T.backgroundColor)||(null===(F=t.button)||void 0===F?void 0:F.backgroundColor)||ot,textColor:(null===(R=t.header)||void 0===R?void 0:R.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(_=t.header)||void 0===_?void 0:_.showCloseButton)},t.header),messages:Jt({userBackgroundColor:(null===(D=t.messages)||void 0===D?void 0:D.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(M=t.messages)||void 0===M?void 0:M.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(A=t.messages)||void 0===A?void 0:A.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(L=t.messages)||void 0===L?void 0:L.errorBackgroundColor)||"#FEE2E2",textColor:(null===(z=t.messages)||void 0===z?void 0:z.textColor)||"#1F2937",fontSize:(null===(U=t.messages)||void 0===U?void 0:U.fontSize)||"14px",borderRadius:(null===(H=t.messages)||void 0===H?void 0:H.borderRadius)||8},t.messages),animation:Jt({enableHover:!1!==(null===(K=t.animation)||void 0===K?void 0:K.enableHover),enablePulse:!1!==(null===(W=t.animation)||void 0===W?void 0:W.enablePulse),enableSlide:!1!==(null===(N=t.animation)||void 0===N?void 0:N.enableSlide),duration:(null===(G=t.animation)||void 0===G?void 0:G.duration)||.3},t.animation),behavior:Jt({autoOpen:(null===(V=t.behavior)||void 0===V?void 0:V.autoOpen)||!1,startOpen:(null===(Q=t.behavior)||void 0===Q?void 0:Q.startOpen)||!1,hidden:(null===(q=t.behavior)||void 0===q?void 0:q.hidden)||!1,autoConnect:(null===(Y=t.behavior)||void 0===Y?void 0:Y.autoConnect)||!1,showWelcomeMessage:!1!==(null===(J=t.behavior)||void 0===J?void 0:J.showWelcomeMessage),welcomeMessage:(null===($=t.behavior)||void 0===$?void 0:$.welcomeMessage)||"Hello! How can I help you today?"},t.behavior),accessibility:Jt({ariaLabel:(null===(Z=t.accessibility)||void 0===Z?void 0:Z.ariaLabel)||"Voice Assistant",ariaDescription:(null===(X=t.accessibility)||void 0===X?void 0:X.ariaDescription)||"Click to open voice assistant",keyboardNavigation:!1!==(null===(tt=t.accessibility)||void 0===tt?void 0:tt.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},primaryColor:ot},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.onConnected=function(){t.updateStatus("connected"),t.config.behavior.showWelcomeMessage&&t.addMessage("system",t.config.behavior.welcomeMessage)},this.sdk.onDisconnected=function(){t.updateStatus("disconnected"),t.isActive=!1,t.updateMicButtonState(!1),t.showError("Conversation ended. Click to start a new conversation.")},this.sdk.onError=function(e){t.showError(e.message)},this.sdk.onTranscript=function(e){t.addMessage("user",e)},this.sdk.onAgentSpeaking=function(e){e?t.showAgentThinking():t.hideAgentThinking()}}},{key:"createWidget",value:function(){var t=document.createElement("div");if(t.id="agent-widget",t.innerHTML=this.generateWidgetHTML(),document.body.appendChild(t),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var e=document.getElementById("agent-panel");e&&(this.isOpen=!0,e.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){this.config.position;var t=this.config.button,e=this.config.icon,n=this.config.panel,o=this.config.header,r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[t.size]||60),i={small:20,medium:28,large:36,xl:44}[e.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i);return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="agent-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="agent-panel">\n ').concat(o.showTitle?'\n <div id="agent-header" style="direction: '.concat(this.config.direction,';">\n ').concat("rtl"===this.config.direction?"\n ".concat(o.showCloseButton?'<button id="agent-close">×</button>':"",'\n <h3 style="margin: 0; color: ').concat(o.textColor,';">').concat(o.title,"</h3>\n "):'\n <h3 style="margin: 0; color: '.concat(o.textColor,';">').concat(o.title,"</h3>\n ").concat(o.showCloseButton?'<button id="agent-close">×</button>':"","\n "),"\n </div>\n "):"",'\n \n <div id="agent-messages"></div>\n \n <div id="agent-controls">\n <div style="display: flex; flex-direction: column; align-items: center; gap: 8px;">\n <button id="agent-mic-button" \n aria-label="Start/Stop Voice Recording">\n ').concat(c,"\n </button>\n ").concat(n.micButtonHint.text&&n.micButtonHint.text.trim()?'\n <div id="agent-mic-hint" style="color: '.concat(n.micButtonHint.color,"; font-size: ").concat(n.micButtonHint.fontSize,'; text-align: center; max-width: 200px;">\n ').concat(n.micButtonHint.text,"\n </div>\n "):"","\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="Voice 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>");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>')}}},{key:"generateCSS",value:function(t,e,n){var o=this.config.button,r=this.config.panel,i=this.config.header,a=this.config.messages,c=this.config.animation,s=o.backgroundColor||o.primaryColor,u=i.backgroundColor,l=r.micButtonColor||o.primaryColor,d=r.micButtonActiveColor||"#EF4444";return"\n #agent-widget {\n position: fixed;\n ".concat(t,'\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n -webkit-transform: translateZ(0);\n transform: translateZ(0);\n will-change: transform;\n }\n \n #agent-button {\n width: ').concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n background: ").concat(s,";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(c.duration,"s ease;\n ").concat(o.shadow?"box-shadow: 0 4px 12px ".concat(o.shadowColor,";"):"","\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 #agent-button {\n min-width: 56px;\n min-height: 56px;\n }\n }\n \n ").concat(c.enableHover?"\n #agent-button:hover {\n background: ".concat(o.hoverColor,";\n transform: scale(1.05);\n ").concat(o.shadow?"box-shadow: 0 8px 20px ".concat(o.shadowColor,";"):"","\n }\n "):"","\n \n #agent-panel {\n display: none;\n position: absolute;\n bottom: ").concat(this.config.behavior.hidden?20:e+20,"px;\n ").concat("right"===this.config.position.horizontal?"right: 0;":"left: 0;","\n width: ").concat(r.width,"px;\n height: ").concat(r.height,"px;\n background: ").concat(r.backgroundColor,";\n border-radius: ").concat(r.borderRadius,"px;\n border: ").concat(r.border,";\n flex-direction: column;\n overflow: hidden;\n ").concat(r.backdropFilter?"backdrop-filter: ".concat(r.backdropFilter,";"):"","\n ").concat(c.enableSlide?"transition: all ".concat(c.duration,"s ease;"):"","\n }\n \n #agent-panel.open {\n display: flex;\n ").concat(c.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n \n #agent-header {\n background: ").concat(u,";\n color: ").concat(i.textColor,";\n padding: 16px;\n display: flex;\n flex-direction: ").concat("rtl"===this.config.direction?"row-reverse":"row",";\n justify-content: space-between;\n align-items: center;\n border-radius: ").concat(r.borderRadius,"px ").concat(r.borderRadius,"px 0 0;\n direction: ").concat(this.config.direction,";\n }\n \n #agent-header h3 {\n margin: 0;\n flex: 1;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n }\n \n #agent-close {\n background: none;\n border: none;\n color: ").concat(i.textColor,";\n cursor: pointer;\n font-size: 24px;\n padding: 0;\n width: 24px;\n height: 24px;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n }\n \n #agent-messages {\n flex: 1;\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n \n .message {\n padding: 12px;\n border-radius: ").concat(a.borderRadius,"px;\n max-width: 80%;\n font-size: ").concat(a.fontSize,";\n color: ").concat(a.textColor,";\n }\n \n .message.user {\n background: ").concat(a.userBackgroundColor,";\n align-self: flex-end;\n }\n \n .message.agent {\n background: ").concat(a.agentBackgroundColor,";\n align-self: flex-start;\n }\n \n .message.system {\n background: ").concat(a.systemBackgroundColor,";\n align-self: flex-start;\n font-style: italic;\n }\n \n .error-message {\n background: ").concat(a.errorBackgroundColor,";\n color: #991B1B;\n padding: 12px;\n border-radius: ").concat(a.borderRadius,"px;\n margin: 8px;\n }\n \n #agent-controls {\n padding: 16px;\n border-top: 1px solid #E5E7EB;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n \n #agent-controls > div {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 8px;\n }\n \n #agent-mic-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n #agent-mic-button {\n width: ").concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n border: none;\n background: ").concat(l,";\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(c.duration,"s ease;\n }\n \n #agent-mic-button.active {\n background: ").concat(d,";\n ").concat(c.enablePulse?"\n animation: pulse 1.5s infinite;\n ":"","\n }\n \n ").concat(c.enablePulse?"\n @keyframes pulse {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.05); }\n }\n ":"","\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this,e=document.getElementById("agent-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("agent-close");n&&(n.onclick=function(){return t.togglePanel()}),document.getElementById("agent-mic-button").onclick=function(){return t.toggleVoice()},this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{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("agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(e=ee(Zt().m(function t(){var e,n,o,r;return Zt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isActive){t.n=13;break}return t.p=1,console.log("🎤 Starting voice session..."),t.n=2,this.getSignedUrl();case 2:return e=t.v,console.log("🔗 Got signed URL:",e),t.n=3,this.sdk.connect(e);case 3:n=t.v,console.log("✅ Connected to WebSocket, connected:",n),o=0;case 4:if(this.sdk.isConnected||!(o<50)){t.n=6;break}return t.n=5,new Promise(function(t){return setTimeout(t,100)});case 5:o++,t.n=4;break;case 6:if(!this.sdk.isConnected){t.n=8;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=7,this.sdk.startListening();case 7:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop"),t.n=10;break;case 8:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),t.n=9,this.sdk.startListening();case 9:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop");case 10:t.n=12;break;case 11:t.p=11,r=t.v,console.error("❌ Failed to start:",r),this.showError(r.message);case 12:t.n=14;break;case 13:console.log("🔇 Stopping voice session..."),this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,this.updateMicButtonState(!1),this.addMessage("system","🔇 Stopped listening");case 14:return t.a(2)}},t,this,[[1,11]])})),function(){return e.apply(this,arguments)})},{key:"updateMicButtonState",value:function(t){var e=document.getElementById("agent-mic-button");if(e)if(this.config.icon.size,t){if(e.classList.add("active"),e.title="Click to stop listening","microphone"===this.config.icon.type||"custom"===this.config.icon.type){var n=e.querySelector("svg")||e.querySelector("img");n&&"svg"===n.tagName&&(n.innerHTML='\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n <path d="M9 9h6"/>\n ')}}else if(e.classList.remove("active"),e.title="Click to start listening","microphone"===this.config.icon.type){var o=e.querySelector("svg");o&&(o.innerHTML='\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 ')}}},{key:"getSignedUrl",value:(t=ee(Zt().m(function t(){var e,n,o,r,i,a,c;return Zt().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return t.apply(this,arguments)})},{key:"addMessage",value:function(t,e){var n=document.getElementById("agent-messages"),o=document.createElement("div");o.className="message ".concat(t),o.textContent=e,n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"showAgentThinking",value:function(){var t=document.getElementById("agent-messages"),e=document.createElement("div");e.className="message agent agent-thinking",e.id="thinking-indicator",e.textContent="Agent is speaking...",t.appendChild(e),t.scrollTop=t.scrollHeight}},{key:"hideAgentThinking",value:function(){var t=document.getElementById("thinking-indicator");t&&t.remove()}},{key:"showError",value:function(t){var e=document.getElementById("agent-messages"),n=document.createElement("div");n.className="error-message",n.textContent=t,e.appendChild(n)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n=Jt({},this.config);t.panel&&(n.panel=Jt(Jt({},this.config.panel),t.panel),t.panel.micButtonHint&&(n.panel.micButtonHint=Jt(Jt({},null===(e=this.config.panel)||void 0===e?void 0:e.micButtonHint),t.panel.micButtonHint))),t.button&&(n.button=Jt(Jt({},this.config.button),t.button)),t.header&&(n.header=Jt(Jt({},this.config.header),t.header)),t.icon&&(n.icon=Jt(Jt({},this.config.icon),t.icon)),t.messages&&(n.messages=Jt(Jt({},this.config.messages),t.messages)),void 0!==t.direction&&(n.direction=t.direction),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction"].includes(e)||(n[e]=t[e])}),this.config=this.mergeWithDefaults(n);var o=document.getElementById("agent-widget");o&&o.remove(),this.createWidget()}},{key:"destroy",value:function(){var t=document.getElementById("agent-widget");t&&t.remove(),this.sdk&&this.sdk.disconnect()}}]);var t,e}();function se(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ue(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ue(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ue(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ue(d,"constructor",u),ue(u,"constructor",s),s.displayName="GeneratorFunction",ue(u,r,"GeneratorFunction"),ue(d),ue(d,r,"Generator"),ue(d,o,function(){return this}),ue(d,"toString",function(){return"[object Generator]"}),(se=function(){return{w:i,m:f}})()}function ue(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ue=function(t,e,n,o){function i(e,n){ue(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ue(t,e,n,o)}function le(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function de(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){le(i,o,r,a,c,"next",t)}function c(t){le(i,o,r,a,c,"throw",t)}a(void 0)})}}function fe(t){return fe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},fe(t)}function pe(t,e){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 ge(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?pe(Object(n),!0).forEach(function(e){he(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):pe(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function he(t,e,n){return(e=ye(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ve(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"!=fe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=fe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==fe(e)?e:e+""}var be=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=this.mergeWithDefaults(e),this.sdk=new Ct(this.config),this.isOpen=!1,this.isActive=!1,this.streamingEl=null,this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("text-chat-panel");n&&(this.isOpen=!0,n.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,a,c,s,u,l,d,f,p,g,h,v,y,b,m,w,k,S,x,O,C,j,P,E,I,B,T,F,R,_,D,M,A,L,z,U,H,K,W,N,G,V,Q,q,Y,J,$,Z,X,tt,et,nt,ot,rt,it,at,ct,st,ut,lt,dt,ft,pt,gt,ht=t.position||"bottom-right";if("string"==typeof ht){var vt=ht.split("-");ht={vertical:vt[0]||"bottom",horizontal:vt[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var yt=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||"#4F46E5";return ge({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",icon:ge({type:(null===(n=t.icon)||void 0===n?void 0:n.type)||"chat",customImage:(null===(o=t.icon)||void 0===o?void 0:o.customImage)||null,emoji:(null===(r=t.icon)||void 0===r?void 0:r.emoji)||"💬",text:(null===(i=t.icon)||void 0===i?void 0:i.text)||"AI",size:(null===(a=t.icon)||void 0===a?void 0:a.size)||"medium",backgroundColor:(null===(c=t.icon)||void 0===c?void 0:c.backgroundColor)||null},t.icon),position:ge({vertical:ht.vertical||"bottom",horizontal:ht.horizontal||"right",offset:ht.offset||{x:20,y:20}},"object"===fe(t.position)?t.position:{}),button:ge({size:(null===(s=t.button)||void 0===s?void 0:s.size)||"medium",shape:(null===(u=t.button)||void 0===u?void 0:u.shape)||"circle",backgroundColor:(null===(l=t.button)||void 0===l?void 0:l.backgroundColor)||(null===(d=t.icon)||void 0===d?void 0:d.backgroundColor)||yt,hoverColor:(null===(f=t.button)||void 0===f?void 0:f.hoverColor)||"#7C3AED",shadow:!1!==(null===(p=t.button)||void 0===p?void 0:p.shadow),shadowColor:(null===(g=t.button)||void 0===g?void 0:g.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(h=t.button)||void 0===h?void 0:h.backgroundColor)||(null===(v=t.icon)||void 0===v?void 0:v.backgroundColor)||yt},t.button),panel:ge({width:(null===(y=t.panel)||void 0===y?void 0:y.width)||350,height:(null===(b=t.panel)||void 0===b?void 0:b.height)||500,borderRadius:(null===(m=t.panel)||void 0===m?void 0:m.borderRadius)||12,backgroundColor:(null===(w=t.panel)||void 0===w?void 0:w.backgroundColor)||"#FFFFFF",backdropFilter:(null===(k=t.panel)||void 0===k?void 0:k.backdropFilter)||null,border:(null===(S=t.panel)||void 0===S?void 0:S.border)||"1px solid rgba(0,0,0,0.1)",sendButtonColor:(null===(x=t.panel)||void 0===x?void 0:x.sendButtonColor)||yt,sendButtonHoverColor:(null===(O=t.panel)||void 0===O?void 0:O.sendButtonHoverColor)||"#7C3AED",sendButtonActiveColor:(null===(C=t.panel)||void 0===C?void 0:C.sendButtonActiveColor)||"#059669",sendButtonText:(null===(j=t.panel)||void 0===j?void 0:j.sendButtonText)||"Send",sendButtonTextColor:(null===(P=t.panel)||void 0===P?void 0:P.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(E=t.panel)||void 0===E?void 0:E.sendButtonFontSize)||"14px",sendButtonFontWeight:(null===(I=t.panel)||void 0===I?void 0:I.sendButtonFontWeight)||"500",sendButtonHint:ge({text:(null===(B=t.panel)||void 0===B||null===(B=B.sendButtonHint)||void 0===B?void 0:B.text)||"",color:(null===(T=t.panel)||void 0===T||null===(T=T.sendButtonHint)||void 0===T?void 0:T.color)||"#6B7280",fontSize:(null===(F=t.panel)||void 0===F||null===(F=F.sendButtonHint)||void 0===F?void 0:F.fontSize)||"12px"},null===(R=t.panel)||void 0===R?void 0:R.sendButtonHint),inputPlaceholder:(null===(_=t.panel)||void 0===_?void 0:_.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(D=t.panel)||void 0===D?void 0:D.inputBorderColor)||"#E5E7EB",inputFocusColor:(null===(M=t.panel)||void 0===M?void 0:M.inputFocusColor)||yt,inputBackgroundColor:(null===(A=t.panel)||void 0===A?void 0:A.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(L=t.panel)||void 0===L?void 0:L.inputTextColor)||"#1F2937",inputFontSize:(null===(z=t.panel)||void 0===z?void 0:z.inputFontSize)||"14px",inputBorderRadius:(null===(U=t.panel)||void 0===U?void 0:U.inputBorderRadius)||8,inputPadding:(null===(H=t.panel)||void 0===H?void 0:H.inputPadding)||"12px"},t.panel),header:ge({title:(null===(K=t.header)||void 0===K?void 0:K.title)||"Chat Assistant",showTitle:!1!==(null===(W=t.header)||void 0===W?void 0:W.showTitle),backgroundColor:(null===(N=t.header)||void 0===N?void 0:N.backgroundColor)||(null===(G=t.button)||void 0===G?void 0:G.backgroundColor)||yt,textColor:(null===(V=t.header)||void 0===V?void 0:V.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(Q=t.header)||void 0===Q?void 0:Q.showCloseButton)},t.header),messages:ge({userBackgroundColor:(null===(q=t.messages)||void 0===q?void 0:q.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(Y=t.messages)||void 0===Y?void 0:Y.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(J=t.messages)||void 0===J?void 0:J.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===($=t.messages)||void 0===$?void 0:$.errorBackgroundColor)||"#FEE2E2",textColor:(null===(Z=t.messages)||void 0===Z?void 0:Z.textColor)||"#1F2937",fontSize:(null===(X=t.messages)||void 0===X?void 0:X.fontSize)||"14px",borderRadius:(null===(tt=t.messages)||void 0===tt?void 0:tt.borderRadius)||8},t.messages),animation:ge({enableHover:!1!==(null===(et=t.animation)||void 0===et?void 0:et.enableHover),enablePulse:!1!==(null===(nt=t.animation)||void 0===nt?void 0:nt.enablePulse),enableSlide:!1!==(null===(ot=t.animation)||void 0===ot?void 0:ot.enableSlide),duration:(null===(rt=t.animation)||void 0===rt?void 0:rt.duration)||.3},t.animation),behavior:ge({autoOpen:(null===(it=t.behavior)||void 0===it?void 0:it.autoOpen)||!1,startOpen:(null===(at=t.behavior)||void 0===at?void 0:at.startOpen)||!1,hidden:(null===(ct=t.behavior)||void 0===ct?void 0:ct.hidden)||!1,autoConnect:(null===(st=t.behavior)||void 0===st?void 0:st.autoConnect)||!1,showWelcomeMessage:!1!==(null===(ut=t.behavior)||void 0===ut?void 0:ut.showWelcomeMessage),welcomeMessage:(null===(lt=t.behavior)||void 0===lt?void 0:lt.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:(null===(dt=t.behavior)||void 0===dt?void 0:dt.enableVoiceMode)||!1},t.behavior),accessibility:ge({ariaLabel:(null===(ft=t.accessibility)||void 0===ft?void 0:ft.ariaLabel)||"Chat Assistant",ariaDescription:(null===(pt=t.accessibility)||void 0===pt?void 0:pt.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(gt=t.accessibility)||void 0===gt?void 0:gt.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},primaryColor:yt},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.on("error",function(e){t.showError(e.message||e),t.stopStreamingState()}),this.sdk.on("chunk",function(e){t.appendStreamingChunk(e)}),this.sdk.on("done",function(e){var n=e.text;t.finalizeStreaming(n)})}},{key:"createWidget",value:function(){var t=document.createElement("div");if(t.id="text-chat-widget",t.innerHTML=this.generateWidgetHTML(),document.body.appendChild(t),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var e=document.getElementById("text-chat-panel");e&&(this.isOpen=!0,e.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){this.config.position;var t=this.config.button,e=this.config.icon,n=this.config.panel,o=this.config.header,r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[t.size]||60),i={small:20,medium:28,large:36,xl:44}[e.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i),s=!!this.config.behavior.enableVoiceMode;return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header">\n <div>\n <div class="header-title">').concat(o.title,'</div>\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat("rtl"===this.config.direction?"מקוון":"Online",'</span>\n </div>\n </div>\n <div style="display: flex; gap: 12px; align-items: center;">\n ').concat(s?'<button class="back-btn header-icon" id="backBtn"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M10 12L6 8L10 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>':"","\n ").concat(o.showCloseButton?'<button class="close-btn header-icon" id="text-chat-close"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M12 4L4 12M4 4L12 12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></button>':"","\n </div>\n </div>\n\n ").concat(s?'\n <div class="landing-screen" id="landingScreen">\n <div class="landing-logo">🤖</div>\n <div class="landing-title">'.concat("rtl"===this.config.direction?"איך תרצה לתקשר?":"How would you like to communicate?",'</div>\n <div class="mode-selection">\n <div class="mode-card voice" id="mode-card-voice">\n <div class="mode-card-icon">🎤</div>\n <div class="mode-card-title">').concat("rtl"===this.config.direction?"שיחה קולית":"Voice Call",'</div>\n </div>\n <div class="mode-card text" id="mode-card-text">\n <div class="mode-card-icon">💬</div>\n <div class="mode-card-title">').concat("rtl"===this.config.direction?"צ'אט טקסט":"Text Chat","</div>\n </div>\n </div>\n </div>"):"",'\n\n <div class="voice-interface" id="voiceInterface">\n <div class="empty-voice">').concat("rtl"===this.config.direction?"מצב קול placeholder":"Voice mode placeholder",'</div>\n </div>\n\n <div class="text-interface ').concat(s?"":"active",'" 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("rtl"===this.config.direction?"שלום! איך אפשר לעזור?":"Hello! How can I help?",'</div>\n <div class="empty-state-text">').concat("rtl"===this.config.direction?"שלח הודעה או עבור למצב קולי לשיחה בזמן אמת":"Send a message to get started",'</div>\n </div>\n <div class="message assistant">\n <div class="message-avatar">🤖</div>\n <div class="typing-indicator" id="typingIndicator">\n <div class="typing-dot"></div>\n <div class="typing-dot"></div>\n <div class="typing-dot"></div>\n </div>\n </div>\n </div>\n <div class="input-container">\n ').concat("rtl"===this.config.direction?'\n <button class="send-button" id="sendButton" aria-label="Send message">➤</button>\n <div class="input-wrapper" style="flex:1;">\n <textarea class="message-input" id="messageInput" placeholder="'.concat(n.inputPlaceholder,'" rows="1"></textarea>\n </div>\n '):'\n <div class="input-wrapper" style="flex:1;">\n <textarea class="message-input" id="messageInput" placeholder="'.concat(n.inputPlaceholder,'" rows="1"></textarea>\n </div>\n <button class="send-button" id="sendButton" aria-label="Send message">➤</button>\n '),"\n </div>\n </div>\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>");default: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=this.config.button,r=this.config.panel,i=this.config.header,a=this.config.messages,c=this.config.animation,s=(o.backgroundColor||o.primaryColor,i.backgroundColor);return r.sendButtonColor||o.primaryColor,r.sendButtonHoverColor,r.sendButtonActiveColor,"\n #text-chat-widget {\n position: fixed;\n ".concat(t,'\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n -webkit-transform: translateZ(0);\n transform: translateZ(0);\n will-change: transform;\n }\n \n #text-chat-button {\n width: ').concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(c.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-button {\n min-width: 56px;\n min-height: 56px;\n }\n \n #text-chat-panel {\n width: calc(100vw - 20px) !important;\n max-width: ").concat(r.width,"px;\n max-height: calc(100vh - 120px) !important;\n left: 10px !important;\n right: 10px !important;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n }\n \n #text-chat-send {\n min-width: 60px;\n min-height: 44px;\n }\n }\n \n ").concat(c.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(r.width,"px;\n max-width: calc(100vw - 40px);\n height: ").concat(r.height,"px;\n max-height: calc(100vh - ").concat(e,"px - 40px);\n background: transparent;\n border-radius: ").concat(r.borderRadius,"px;\n border: none;\n flex-direction: column;\n overflow: hidden;\n ").concat(r.backdropFilter?"backdrop-filter: ".concat(r.backdropFilter,";"):"","\n ").concat(c.enableSlide?"transition: all ".concat(c.duration,"s ease;"):"","\n }\n \n #text-chat-panel.open {\n display: flex;\n ").concat(c.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(r.borderRadius,"px; background: transparent; box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; display: flex; flex-direction: column; }\n .panel-inner { width: 100%; height: 100%; background: #ffffff; border-radius: ").concat(r.borderRadius,"px; overflow: hidden; display:flex; flex-direction: column; padding: 0; box-sizing: border-box; }\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(r.borderRadius,"px;\n }\n #text-chat-panel .widget-header {\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: #FFFFFF;\n padding: 12px 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-top-left-radius: ").concat(r.borderRadius,"px;\n border-top-right-radius: ").concat(r.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 #text-chat-panel .back-btn, #text-chat-panel .close-btn {\n background: rgba(255,255,255,0.2);\n border: none; color: white; width: 32px; height: 32px; border-radius: 50%; cursor: pointer;\n display: flex; align-items: center; justify-content: center;\n }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { display: none; flex: 1; padding: 20px; background: linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%); align-items: center; justify-content: flex-start; flex-direction: column; gap: 16px; overflow-y: auto; min-height: 0; }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { font-size: 20px; color: #1e293b; font-weight: 700; margin-bottom: 20px; }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { flex: 1; max-width: 180px; background: #FFFFFF; border: 2px solid #E2E8F0; border-radius: 20px; padding: 20px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; transition: transform ").concat(c.duration,"s ease, box-shadow ").concat(c.duration,"s ease, border-color ").concat(c.duration,"s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }\n .mode-card:hover { transform: translateY(-6px); box-shadow: 0 12px 24px rgba(102, 126, 234, 0.2); border-color: ").concat(s,"; }\n .mode-card-icon { width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: ").concat(s,"; color: #fff; font-size: 32px; }\n .mode-card-title { color: #111827; font-weight: 600; }\n\n .voice-interface { display: none; flex: 1; align-items: center; justify-content: center; padding: 20px; background: #F8FAFC; }\n .voice-interface.active { display: flex; }\n .empty-voice { color: #6B7280; font-size: 14px; }\n \n /* Messages container using new classes */\n #messagesContainer { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 20px; background: #f8fafc; display: flex; flex-direction: column; gap: 16px; min-height: 0; }\n .empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #64748b; text-align: center; padding: 20px; }\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 { display: none; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; }\n .text-interface.active { display: flex; }\n \n .message { display: flex; gap: 8px; padding: 4px 0; max-width: 100%; align-items: center; }\n .message.edge-left { flex-direction: row; }\n .message.edge-right { flex-direction: row-reverse; }\n .message-bubble { padding: 12px; border-radius: ").concat(a.borderRadius,"px; max-width: 80%; font-size: ").concat(a.fontSize,"; color: ").concat(a.textColor,"; word-wrap: break-word; text-align: ").concat("rtl"===this.config.direction?"right":"left","; }\n .message.user { background: ").concat(a.userBackgroundColor,"; align-self: ").concat("rtl"===this.config.direction?"flex-start":"flex-end","; }\n .message.agent { background: ").concat(a.agentBackgroundColor,"; align-self: ").concat("rtl"===this.config.direction?"flex-end":"flex-start","; }\n .message .message-bubble { text-align: ").concat("rtl"===this.config.direction?"right":"left","; }\n .message-avatar { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: inherit; font-size: 18px; line-height: 1; background: transparent; border: none; }\n .message-avatar.user { background: transparent; }\n .message-avatar.agent { background: transparent; }\n \n .message.system {\n background: ").concat(a.systemBackgroundColor,";\n align-self: flex-start;\n font-style: italic;\n }\n \n .error-message {\n background: ").concat(a.errorBackgroundColor,";\n color: #991B1B;\n padding: 12px;\n border-radius: ").concat(a.borderRadius,"px;\n margin: 8px;\n }\n \n .input-container { padding: 10px 16px; background: white; border-top: 1px solid #E2E8F0; display: flex; gap: 10px; align-items: center; border-bottom-left-radius: ").concat(r.borderRadius,"px; border-bottom-right-radius: ").concat(r.borderRadius,"px; flex-shrink: 0; box-sizing: border-box; }\n .input-wrapper { flex: 1; display: flex; align-items: center; order: initial; }\n .message-input { width: 100%; padding: 0 14px; border: 2px solid #E5E7EB; border-radius: 20px; font-size: 14px; font-family: inherit; resize: none; height: 32px; transition: border-color ").concat(c.duration,"s, box-shadow ").concat(c.duration,"s; outline: none; background: #F9FAFB; color: ").concat(r.inputTextColor,"; line-height: 32px; overflow-y: auto; }\n .message-input::placeholder { line-height: 32px; }\n .message-input:focus { border-color: #667eea; background: #FFFFFF; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); }\n .message-input::placeholder { color: #9CA3AF; }\n .send-button { width: 44px; height: 44px; border-radius: 50%; border: none; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; flex-shrink: 0; box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); order: initial; }\n .send-button:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5); background: linear-gradient(135deg, #764ba2 0%, #667eea 100%); }\n .send-button:active { transform: translateY(0px); box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4); }\n .send-button svg { width: 18px; height: 18px; display: block; pointer-events: none; }\n .send-button svg * { stroke: white !important; fill: none !important; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }\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,e=document.getElementById("text-chat-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("text-chat-close");n&&(n.onclick=function(){return t.togglePanel()});var o=document.getElementById("backBtn"),r=document.getElementById("landingScreen"),i=document.getElementById("mode-card-voice"),a=document.getElementById("mode-card-text"),c=document.getElementById("textInterface"),s=document.getElementById("voiceInterface");this.config.behavior.enableVoiceMode&&(o&&(o.onclick=function(){return t.showLanding()}),i&&(i.onclick=function(){return t.showVoice()}),a&&(a.onclick=function(){return t.showText()}),r&&r.classList.add("active"),c&&c.classList.remove("active"),s&&s.classList.remove("active"));var u=document.getElementById("sendButton"),l=document.getElementById("messageInput");u&&(u.onclick=function(){return t.sendMessage()}),l&&l.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey||(e.preventDefault(),t.sendMessage())}),this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"showLanding",value:function(){if(this.config.behavior.enableVoiceMode){var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active")}}},{key:"showText",value:function(){var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface");t&&t.classList.remove("active"),e&&e.classList.add("active"),n&&n.classList.remove("active"),setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},50)}},{key:"showVoice",value:function(){var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active")}},{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=de(se().m(function t(){return se().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.updateSendButtonState();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"sendMessage",value:(o=de(se().m(function t(){var e,n,o;return se().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="",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),this.showError(o.message),this.stopStreamingState();case 6:return t.a(2)}},t,this,[[3,5]])})),function(){return o.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var t=document.getElementById("sendButton");t&&(t.disabled=!this.isActive)}},{key:"getSignedUrl",value:(n=de(se().m(function t(){var e,n,o,r,i,a,c;return se().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://backend.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return n.apply(this,arguments)})},{key:"addMessage",value:function(t,e){var n=document.getElementById("messagesContainer"),o=document.createElement("div"),r="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";o.className="message ".concat(t," ").concat(r);var i=document.createElement("div");i.className="message-avatar ".concat(t),i.textContent="user"===t?"👤":"🤖";var a=document.createElement("div");a.className="message-bubble",a.textContent=e,o.appendChild(i),o.appendChild(a),n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"beginStreaming",value:function(){var t=document.getElementById("messagesContainer");this.stopStreamingState();var e=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";e.className="message agent ".concat(n),e.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var r=document.createElement("div");r.className="message-bubble",e.appendChild(o),e.appendChild(r),t.appendChild(e),this.streamingEl=r,t.scrollTop=t.scrollHeight}},{key:"appendStreamingChunk",value:function(t){if(this.streamingEl){this.streamingEl.textContent+=t;var e=document.getElementById("messagesContainer");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}},{key:"showError",value:function(t){var e=document.getElementById("messagesContainer"),n=document.createElement("div");n.className="error-message",n.textContent=t,e.appendChild(n),e.scrollTop=e.scrollHeight}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n,o=ge({},this.config);t.panel&&(o.panel=ge(ge({},this.config.panel),t.panel),t.panel.sendButtonHint&&(o.panel.sendButtonHint=ge(ge({},null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonHint),t.panel.sendButtonHint)),t.panel.inputConfig&&(o.panel.inputConfig=ge(ge({},null===(n=this.config.panel)||void 0===n?void 0:n.inputConfig),t.panel.inputConfig))),t.button&&(o.button=ge(ge({},this.config.button),t.button)),t.header&&(o.header=ge(ge({},this.config.header),t.header)),t.icon&&(o.icon=ge(ge({},this.config.icon),t.icon)),t.messages&&(o.messages=ge(ge({},this.config.messages),t.messages)),void 0!==t.direction&&(o.direction=t.direction),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction"].includes(e)||(o[e]=t[e])}),this.config=this.mergeWithDefaults(o);var r=document.getElementById("text-chat-widget");r&&r.remove(),this.createWidget()}},{key:"destroy",value:function(){var t=document.getElementById("text-chat-widget");t&&t.remove(),this.sdk&&this.sdk.destroy()}}],e&&ve(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,r}(),me="2.0.0";const we={VoiceSDK:ft,TextChatSDK:Ct,WebSocketManager:T,AudioRecorder:K,AudioPlayer:Z,EventEmitter:c,VoiceButton:At,VanillaVoiceButton:Qt,AgentSDK:ae,AgentWidget:ce,TextChatWidget:be,VERSION:me};return o})());
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==e.key&&(r=""+e.key),"key"in e)for(var i in o={},e)"key"!==i&&(o[i]=e[i]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:r,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}function a(){}function c(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},i.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},a.prototype=i.prototype;var s=c.prototype=new a;s.constructor=c,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var u={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return u.H.useEffect(t,e)},e.useRef=function(t){return u.H.useRef(t)},e.useState=function(t){return u.H.useState(t)}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,a(o.key),o)}}function a(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>ae,AgentWidget:()=>ce,AudioPlayer:()=>Z,AudioRecorder:()=>K,EventEmitter:()=>c,TextChatSDK:()=>Ot,TextChatWidget:()=>be,VERSION:()=>me,VanillaVoiceButton:()=>Qt,VoiceButton:()=>At,VoiceSDK:()=>ft,WebSocketManager:()=>T,default:()=>we});var c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||d(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=d(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function d(t,e){if(t){if("string"==typeof t)return f(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return g(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(g(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,g(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,g(d,"constructor",u),g(u,"constructor",s),s.displayName="GeneratorFunction",g(u,r,"GeneratorFunction"),g(d),g(d,r,"Generator"),g(d,o,function(){return this}),g(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:f}})()}function g(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}g=function(t,e,n,o){function i(e,n){g(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},g(t,e,n,o)}function h(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function v(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 b(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(b=function(){return!!t})()}function m(t){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},m(t)}function w(t,e){return w=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},w(t,e)}const S=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=m(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,b()?Reflect.construct(e,n||[],m(t).constructor):e.apply(t,n))}(this,e)).connections=new Map,t.connectionCounts=new Map,t.creatingConnections=new Set,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&w(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=p().m(function t(e){var n,o,r=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(r.connections.has(e)){var o=r.connections.get(e);r.connectionCounts.set(e,(r.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){r.creatingConnections.delete(e),r.emit("error",t,e)}),o.addEventListener("message",function(t){r.emit("message",t,e)}),t.a(2,o)}},t,this)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){h(i,n,o,a,c,"next",t)}function c(t){h(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=l(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=u(t.value,2),r=o[0],i=o[1];e[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&v(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c));function k(t){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k(t)}function x(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return C(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(C(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,C(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,C(d,"constructor",u),C(u,"constructor",s),s.displayName="GeneratorFunction",C(u,r,"GeneratorFunction"),C(d),C(d,r,"Generator"),C(d,o,function(){return this}),C(d,"toString",function(){return"[object Generator]"}),(x=function(){return{w:i,m:f}})()}function C(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}C=function(t,e,n,o){function i(e,n){C(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},C(t,e,n,o)}function O(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function j(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,P(o.key),o)}}function P(t){var e=function(t){if("object"!=k(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==k(e)?e:e+""}function I(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(I=function(){return!!t})()}function E(t){return E=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},E(t)}function B(t,e){return B=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},B(t,e)}var T=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(e),function(t,e){if(e&&("object"==k(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,I()?Reflect.construct(e,n||[],E(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:(i=x().m(function t(){var e=this;return x().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,S.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t(),e.connectResolve=null,e.connectReject=null)}).catch(function(t){console.error("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null})}catch(t){console.error("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null}}))},t)}),a=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function a(t){O(r,n,o,a,c,"next",t)}function c(t){O(r,n,o,a,c,"throw",t)}a(void 0)})},function(){return a.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};S.on("open",e),S.on("close",n),S.on("error",o),S.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(S.off("open",this.eventHandlers.open),S.off("close",this.eventHandlers.close),S.off("error",this.eventHandlers.error),S.off("message",this.eventHandlers.message)),this.config.websocketUrl&&S.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(t))}catch(t){console.warn("🔌 WebSocketManager: Failed to send message:",t.message)}}},{key:"sendBinary",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(t)}catch(t){console.warn("🔌 WebSocketManager: Failed to send binary data:",t.message)}}},{key:"handleMessage",value:function(t){var e=this;if(t.data instanceof ArrayBuffer)this.emit("binaryAudio",t.data);else if(t.data instanceof Blob)t.data.arrayBuffer().then(function(t){e.emit("binaryAudio",t)}).catch(function(t){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return S.getAllConnections()}},{key:"clearAllConnections",value:function(){S.clearAll()}}],o&&j(n.prototype,o),r&&j(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a}(c);function F(t){return F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},F(t)}function R(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return _(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(_(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,_(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,_(d,"constructor",u),_(u,"constructor",s),s.displayName="GeneratorFunction",_(u,r,"GeneratorFunction"),_(d),_(d,r,"Generator"),_(d,o,function(){return this}),_(d,"toString",function(){return"[object Generator]"}),(R=function(){return{w:i,m:f}})()}function _(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}_=function(t,e,n,o){function i(e,n){_(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},_(t,e,n,o)}function D(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function M(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){D(i,o,r,a,c,"next",t)}function c(t){D(i,o,r,a,c,"throw",t)}a(void 0)})}}function A(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 z(t){return z=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},z(t)}function U(t,e){return U=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},U(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=z(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||[],z(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&&U(t,e)}(e,t),n=e,o=[{key:"start",value:(i=M(R().m(function t(){var e,n=this;return R().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 t.n=3,this.audioContext.audioWorklet.addModule("/audio-processor.js");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,o=e.type,r=e.data;"pcm_audio_data"===o&&n.emit("audioData",r)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,e=t.v,this.emit("error",e),e;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=M(R().m(function t(){var e;return R().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&A(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(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 N(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return G(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(G(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,G(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,G(d,"constructor",u),G(u,"constructor",s),s.displayName="GeneratorFunction",G(u,r,"GeneratorFunction"),G(d),G(d,r,"Generator"),G(d,o,function(){return this}),G(d,"toString",function(){return"[object Generator]"}),(N=function(){return{w:i,m:f}})()}function G(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}G=function(t,e,n,o){function i(e,n){G(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},G(t,e,n,o)}function V(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function 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,q(o.key),o)}}function q(t){var e=function(t){if("object"!=W(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=W(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==W(e)?e:e+""}function Y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Y=function(){return!!t})()}function J(t){return J=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},J(t)}function $(t,e){return $=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},$(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=J(e),function(t,e){if(e&&("object"==W(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Y()?Reflect.construct(e,n||[],J(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&&$(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(r=N().m(function t(){var e,n,o,r,i,a,c,s,u=this;return N().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 r=t.v,t.n=5,o.decodeAudioData(r);case 5:i=t.v,a=n&&!this.isPlaying&&null===this.currentSource,(c=o.createBufferSource()).buffer=i,c.connect(o.destination),this.currentSource=c,this.isPlaying=!0,a&&this.emit("playbackStarted"),c.onended=function(){u.currentSource=null,u.isProcessingQueue=!1,u.audioQueue.length>0?setTimeout(function(){return u.processQueue()},50):setTimeout(function(){0!==u.audioQueue.length||u.currentSource||(u.isPlaying=!1,u.emit("playbackStopped"))},100)},c.start(),t.n=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 u.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){V(i,n,o,a,c,"next",t)}function c(t){V(i,n,o,a,c,"throw",t)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&Q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(c);function X(t){return X="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},X(t)}function tt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return et(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(et(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,et(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,et(d,"constructor",u),et(u,"constructor",s),s.displayName="GeneratorFunction",et(u,r,"GeneratorFunction"),et(d),et(d,r,"Generator"),et(d,o,function(){return this}),et(d,"toString",function(){return"[object Generator]"}),(tt=function(){return{w:i,m:f}})()}function et(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}et=function(t,e,n,o){function i(e,n){et(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},et(t,e,n,o)}function nt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function ot(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){nt(i,o,r,a,c,"next",t)}function c(t){nt(i,o,r,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 it(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){at(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 at(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 ct(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,st(o.key),o)}}function st(t){var e=function(t){if("object"!=X(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=X(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==X(e)?e:e+""}function ut(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ut=function(){return!!t})()}function lt(t){return lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},lt(t)}function dt(t,e){return dt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},dt(t,e)}var ft=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=lt(e),function(t,e){if(e&&("object"==X(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ut()?Reflect.construct(e,n||[],lt(t).constructor):e.apply(t,n))}(this,e)).config=it({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 T(it(it({},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&&dt(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){t.isConnected=!1,t.isRecording&&t.stopRecording().catch(function(t){console.error("VoiceSDK: Error stopping recording on disconnect:",t)}),t.emit("disconnected",e)}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){if("greeting_audio"===e.t&&e.data)try{for(var n=atob(e.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(u=ot(tt().m(function t(){var e,n;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=ot(tt().m(function t(){return tt().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=ot(tt().m(function t(){var e;return tt().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=ot(tt().m(function t(){var e;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"toggleRecording",value:(i=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=it(it({},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&&ct(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,a,c,s,u}(c);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 gt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ht(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ht(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ht(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ht(d,"constructor",u),ht(u,"constructor",s),s.displayName="GeneratorFunction",ht(u,r,"GeneratorFunction"),ht(d),ht(d,r,"Generator"),ht(d,o,function(){return this}),ht(d,"toString",function(){return"[object Generator]"}),(gt=function(){return{w:i,m:f}})()}function ht(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ht=function(t,e,n,o){function i(e,n){ht(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ht(t,e,n,o)}function vt(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function yt(t,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?yt(Object(n),!0).forEach(function(e){mt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):yt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function mt(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"!=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+""}function kt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(kt=function(){return!!t})()}function xt(t){return xt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},xt(t)}function Ct(t,e){return Ct=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ct(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=xt(e),function(t,e){if(e&&("object"==pt(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||[],xt(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&&Ct(t,e)}(e,t),n=e,o=[{key:"readScriptTagConfig",value:function(){try{var t=Array.from(document.getElementsByTagName("script")).reverse().find(function(t){return t.dataset&&(t.dataset.appId||t.dataset.agentId)||t.src&&t.src.includes("agent-widget")});return t?{appId:t.dataset.appId,agentId:t.dataset.agentId}:{}}catch(t){return{}}}},{key:"buildWebSocketUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.baseWsUrl,e=new URLSearchParams;return this.config.appId&&e.append("appId",this.config.appId),this.config.agentId&&e.append("agentId",this.config.agentId),this.config.conversationId&&e.append("conversationId",this.config.conversationId),"".concat(t,"?").concat(e.toString())}},{key:"sendMessage",value:(r=gt().m(function t(e){var n=this;return gt().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,o){if(e&&e.trim())if(n.config.appId&&n.config.agentId){var r={text:e,resolve:t,reject:o};n.config.inFlight?n.config.queue.push(r):n.executeTask(r)}else o(new Error("Missing appId or agentId"));else o(new Error("Message is empty"))}))},t)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function a(t){vt(i,n,o,a,c,"next",t)}function c(t){vt(i,n,o,a,c,"throw",t)}a(void 0)})},function(t){return i.apply(this,arguments)})},{key:"executeTask",value:function(t){var e=this;if(this.config.inFlight=!0,this.fullResponseBuffer="",!this.config.conversationId){var n=this.getPersistedConversationId();n&&(this.config.conversationId=n,console.log("🔍 TextChatSDK hydrated conversationId from storage:",n))}var o,r=this.buildWebSocketUrl(this.config.baseWsUrl),i=this.config.baseWsUrl.endsWith("/websocket")?this.config.baseWsUrl.replace(/\/websocket$/,""):"".concat(this.config.baseWsUrl,"/websocket"),a=this.buildWebSocketUrl(i),c=!1,s=!1,u=null,l=function(n){if(!s)try{var o={message:t.text},r=e.config.forceConversationId||e.config.conversationId;r&&(o.conversationId=r,e.config.forceConversationId&&!e.config.conversationId&&(e.config.conversationId=r,e.persistConversationId(r))),console.log("🔍 TextChatSDK sending payload:",o,"conversationId in config:",e.config.conversationId),n.send(JSON.stringify(o)),s=!0}catch(o){t.reject(o),e.emit("error",o);try{n.close()}catch(t){}}},d=function(t){return function(){e.config.conversationId?l(t):u=setTimeout(function(){return l(t)},200)}},f=function(n){return function(o){try{try{console.log("🔎 [TextChatSDK] WS <= raw:",o.data)}catch(t){}var r=JSON.parse(o.data);try{console.log("🔎 [TextChatSDK] WS <= parsed:",r)}catch(t){}if("hello"===r.type&&r.conversationId){if(console.log("🔍 TextChatSDK received conversationId:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId),e.emit&&e.emit("conversationIdChanged",r.conversationId),!s&&n&&1===n.readyState){if(u)try{clearTimeout(u)}catch(t){}l(n)}return}if(!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from message:",r.conversationId),e.config.conversationId=r.conversationId,e.persistConversationId(r.conversationId)),"chunk"===r.type&&"string"==typeof r.content)e.fullResponseBuffer+=r.content,e.emit("chunk",r.content);else if("done"===r.type){try{var i=r.text||r.content||r.answer||r.message||"";i&&!e.fullResponseBuffer&&(e.fullResponseBuffer=i)}catch(t){}!e.config.conversationId&&r.conversationId&&(console.log("🔍 TextChatSDK captured conversationId from done:",r.conversationId),e.config.conversationId=r.conversationId),e.persistConversationId(e.config.conversationId),e.emit("done",{text:e.fullResponseBuffer}),t.resolve({conversationId:e.config.conversationId,fullText:e.fullResponseBuffer});try{n.close()}catch(t){}}else if("error"===r.type){var a=new Error(r.message||"Server error");e.emit("error",a),t.reject(a);try{n.close()}catch(t){}}}catch(t){}}},p=function(){e.config.inFlight=!1,e.drainQueue()},g=new WebSocket(r);g.onopen=d(g),g.onmessage=f(g),g.onerror=(o=g,function(n){if(!c){c=!0;try{o.close()}catch(t){}var r=new WebSocket(a);return r.onopen=d(r),r.onmessage=f(r),r.onerror=function(n){e.emit("error",n),t.reject(n)},void(r.onclose=p)}e.emit("error",n),t.reject(n)}),g.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,r,i}(c),jt=n(540),Pt=n(848);function It(t){return It="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},It(t)}function Et(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?Et(Object(n),!0).forEach(function(e){Tt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Et(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Tt(t,e,n){return(e=function(t){var e=function(t){if("object"!=It(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=It(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==It(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Ft(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Rt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Rt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Rt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Rt(d,"constructor",u),Rt(u,"constructor",s),s.displayName="GeneratorFunction",Rt(u,r,"GeneratorFunction"),Rt(d),Rt(d,r,"Generator"),Rt(d,o,function(){return this}),Rt(d,"toString",function(){return"[object Generator]"}),(Ft=function(){return{w:i,m:f}})()}function Rt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Rt=function(t,e,n,o){function i(e,n){Rt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Rt(t,e,n,o)}function _t(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Dt(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,a,c=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(c.push(o.value),c.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw r}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Mt(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)?Mt(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 Mt(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 At=function(t){var e=t.websocketUrl,n=t.agentId,o=t.voice,r=void 0===o?"default":o,i=t.language,a=void 0===i?"en":i,c=t.autoReconnect,s=void 0===c||c,u=t.onConnected,l=t.onDisconnected,d=t.onRecordingStarted,f=t.onRecordingStopped,p=t.onPlaybackStarted,g=t.onPlaybackStopped,h=t.onError,v=t.onMessage,y=t.onBargeIn,b=t.onStopPlaying,m=t.className,w=void 0===m?"":m,S=t.style,k=void 0===S?{}:S,x=t.children,C=Dt((0,jt.useState)(!1),2),O=C[0],j=C[1],P=Dt((0,jt.useState)(!1),2),I=P[0],E=P[1],B=Dt((0,jt.useState)(!1),2),T=(B[0],B[1]),F=Dt((0,jt.useState)("Disconnected"),2),R=(F[0],F[1]),_=(0,jt.useRef)(null);(0,jt.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),_.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),_.current.destroy(),_.current=null);var t=new ft({websocketUrl:e,agentId:n,voice:r,language:a,autoReconnect:s});return t.on("connected",function(){j(!0),R("Connected"),null==u||u()}),t.on("disconnected",function(){j(!1),R("Disconnected"),null==l||l()}),t.on("recordingStarted",function(){E(!0),null==d||d()}),t.on("recordingStopped",function(){E(!1),null==f||f()}),t.on("playbackStarted",function(){T(!0),null==p||p()}),t.on("playbackStopped",function(){T(!1),null==g||g()}),t.on("error",function(t){null==h||h(t)}),t.on("message",function(t){null==v||v(t)}),t.on("bargeIn",function(t){null==y||y(t)}),t.on("stopPlaying",function(t){null==b||b(t)}),_.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),_.current&&(_.current.destroy(),_.current=null)}},[e,n,r,a]);var D=function(){var t,e=(t=Ft().m(function t(){var e;return Ft().w(function(t){for(;;)switch(t.p=t.n){case 0:if(_.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,_.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){_t(i,o,r,a,c,"next",t)}function c(t){_t(i,o,r,a,c,"throw",t)}a(void 0)})});return function(){return e.apply(this,arguments)}}(),M=(0,Pt.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,Pt.jsx)("div",{style:{fontSize:"20px"},children:I?"🔴":"🎤"}),(0,Pt.jsx)("div",{children:I?"Stop Listening":"Start Listening"})]});return(0,Pt.jsx)("button",{className:"voice-button ".concat(I?"recording":""," ").concat(w),style:Bt({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:I?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},k),onClick:D,disabled:!O,children:x||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",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return zt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(zt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,zt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,zt(d,"constructor",u),zt(u,"constructor",s),s.displayName="GeneratorFunction",zt(u,r,"GeneratorFunction"),zt(d),zt(d,r,"Generator"),zt(d,o,function(){return this}),zt(d,"toString",function(){return"[object Generator]"}),(Ht=function(){return{w:i,m:f}})()}function zt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}zt=function(t,e,n,o){function i(e,n){zt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},zt(t,e,n,o)}function Ut(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function Kt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){Ut(i,o,r,a,c,"next",t)}function c(t){Ut(i,o,r,a,c,"throw",t)}a(void 0)})}}function 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 Nt(t,e,n){return(e=Vt(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,Vt(o.key),o)}}function Vt(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){Nt(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 ft({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 qt(t){return qt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},qt(t)}function Yt(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 Jt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Yt(Object(n),!0).forEach(function(e){$t(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function $t(t,e,n){return(e=ie(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Zt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return Xt(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Xt(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Xt(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,Xt(d,"constructor",u),Xt(u,"constructor",s),s.displayName="GeneratorFunction",Xt(u,r,"GeneratorFunction"),Xt(d),Xt(d,r,"Generator"),Xt(d,o,function(){return this}),Xt(d,"toString",function(){return"[object Generator]"}),(Zt=function(){return{w:i,m:f}})()}function Xt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Xt=function(t,e,n,o){function i(e,n){Xt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Xt(t,e,n,o)}function te(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function ee(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){te(i,o,r,a,c,"next",t)}function c(t){te(i,o,r,a,c,"throw",t)}a(void 0)})}}function ne(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function oe(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,ie(o.key),o)}}function re(t,e,n){return e&&oe(t.prototype,e),n&&oe(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function ie(t){var e=function(t){if("object"!=qt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=qt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==qt(e)?e:e+""}var ae=function(){return re(function t(e){ne(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){}},[{key:"connect",value:(e=ee(Zt().m(function t(e){var n,o=this;return Zt().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 ft({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(){o.isConnected=!1,o.onDisconnected()}),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 e.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:(t=ee(Zt().m(function t(){var e;return Zt().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 t.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}}]);var t,e}(),ce=function(){return re(function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(ne(this,t),this.config=this.mergeWithDefaults(e),this.sdk=new ae(this.config),this.isOpen=!1,this.isActive=!1,this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("agent-panel");n&&(this.isOpen=!0,n.classList.add("open"))}},[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,a,c,s,u,l,d,f,p,g,h,v,y,b,m,w,S,k,x,C,O,j,P,I,E,B,T,F,R,_,D,M,A,L,H,z,U,K,W,N,G,V,Q,q,Y,J,$,Z,X,tt,et=t.position||"bottom-right";if("string"==typeof et){var nt=et.split("-");et={vertical:nt[0]||"bottom",horizontal:nt[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var ot=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||"#4F46E5";return Jt({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",icon:Jt({type:(null===(n=t.icon)||void 0===n?void 0:n.type)||"microphone",customImage:(null===(o=t.icon)||void 0===o?void 0:o.customImage)||null,emoji:(null===(r=t.icon)||void 0===r?void 0:r.emoji)||"🎤",text:(null===(i=t.icon)||void 0===i?void 0:i.text)||"AI",size:(null===(a=t.icon)||void 0===a?void 0:a.size)||"medium",backgroundColor:(null===(c=t.icon)||void 0===c?void 0:c.backgroundColor)||null},t.icon),position:Jt({vertical:et.vertical||"bottom",horizontal:et.horizontal||"right",offset:et.offset||{x:20,y:20}},"object"===qt(t.position)?t.position:{}),button:Jt({size:(null===(s=t.button)||void 0===s?void 0:s.size)||"medium",shape:(null===(u=t.button)||void 0===u?void 0:u.shape)||"circle",backgroundColor:(null===(l=t.button)||void 0===l?void 0:l.backgroundColor)||(null===(d=t.icon)||void 0===d?void 0:d.backgroundColor)||ot,hoverColor:(null===(f=t.button)||void 0===f?void 0:f.hoverColor)||"#7C3AED",shadow:!1!==(null===(p=t.button)||void 0===p?void 0:p.shadow),shadowColor:(null===(g=t.button)||void 0===g?void 0:g.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(h=t.button)||void 0===h?void 0:h.backgroundColor)||(null===(v=t.icon)||void 0===v?void 0:v.backgroundColor)||ot},t.button),panel:Jt({width:(null===(y=t.panel)||void 0===y?void 0:y.width)||350,height:(null===(b=t.panel)||void 0===b?void 0:b.height)||500,borderRadius:(null===(m=t.panel)||void 0===m?void 0:m.borderRadius)||12,backgroundColor:(null===(w=t.panel)||void 0===w?void 0:w.backgroundColor)||"#FFFFFF",backdropFilter:(null===(S=t.panel)||void 0===S?void 0:S.backdropFilter)||null,border:(null===(k=t.panel)||void 0===k?void 0:k.border)||"1px solid rgba(0,0,0,0.1)",micButtonColor:(null===(x=t.panel)||void 0===x?void 0:x.micButtonColor)||ot,micButtonActiveColor:(null===(C=t.panel)||void 0===C?void 0:C.micButtonActiveColor)||"#EF4444",micButtonHint:Jt({text:(null===(O=t.panel)||void 0===O||null===(O=O.micButtonHint)||void 0===O?void 0:O.text)||"Click the button to start voice conversation",color:(null===(j=t.panel)||void 0===j||null===(j=j.micButtonHint)||void 0===j?void 0:j.color)||"#6B7280",fontSize:(null===(P=t.panel)||void 0===P||null===(P=P.micButtonHint)||void 0===P?void 0:P.fontSize)||"12px"},null===(I=t.panel)||void 0===I?void 0:I.micButtonHint)},t.panel),header:Jt({title:(null===(E=t.header)||void 0===E?void 0:E.title)||"Voice Assistant",showTitle:!1!==(null===(B=t.header)||void 0===B?void 0:B.showTitle),backgroundColor:(null===(T=t.header)||void 0===T?void 0:T.backgroundColor)||(null===(F=t.button)||void 0===F?void 0:F.backgroundColor)||ot,textColor:(null===(R=t.header)||void 0===R?void 0:R.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(_=t.header)||void 0===_?void 0:_.showCloseButton)},t.header),messages:Jt({userBackgroundColor:(null===(D=t.messages)||void 0===D?void 0:D.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(M=t.messages)||void 0===M?void 0:M.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(A=t.messages)||void 0===A?void 0:A.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(L=t.messages)||void 0===L?void 0:L.errorBackgroundColor)||"#FEE2E2",textColor:(null===(H=t.messages)||void 0===H?void 0:H.textColor)||"#1F2937",fontSize:(null===(z=t.messages)||void 0===z?void 0:z.fontSize)||"14px",borderRadius:(null===(U=t.messages)||void 0===U?void 0:U.borderRadius)||8},t.messages),animation:Jt({enableHover:!1!==(null===(K=t.animation)||void 0===K?void 0:K.enableHover),enablePulse:!1!==(null===(W=t.animation)||void 0===W?void 0:W.enablePulse),enableSlide:!1!==(null===(N=t.animation)||void 0===N?void 0:N.enableSlide),duration:(null===(G=t.animation)||void 0===G?void 0:G.duration)||.3},t.animation),behavior:Jt({autoOpen:(null===(V=t.behavior)||void 0===V?void 0:V.autoOpen)||!1,startOpen:(null===(Q=t.behavior)||void 0===Q?void 0:Q.startOpen)||!1,hidden:(null===(q=t.behavior)||void 0===q?void 0:q.hidden)||!1,autoConnect:(null===(Y=t.behavior)||void 0===Y?void 0:Y.autoConnect)||!1,showWelcomeMessage:!1!==(null===(J=t.behavior)||void 0===J?void 0:J.showWelcomeMessage),welcomeMessage:(null===($=t.behavior)||void 0===$?void 0:$.welcomeMessage)||"Hello! How can I help you today?"},t.behavior),accessibility:Jt({ariaLabel:(null===(Z=t.accessibility)||void 0===Z?void 0:Z.ariaLabel)||"Voice Assistant",ariaDescription:(null===(X=t.accessibility)||void 0===X?void 0:X.ariaDescription)||"Click to open voice assistant",keyboardNavigation:!1!==(null===(tt=t.accessibility)||void 0===tt?void 0:tt.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},primaryColor:ot},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.onConnected=function(){t.updateStatus("connected"),t.config.behavior.showWelcomeMessage&&t.addMessage("system",t.config.behavior.welcomeMessage)},this.sdk.onDisconnected=function(){t.updateStatus("disconnected"),t.isActive=!1,t.updateMicButtonState(!1),t.showError("Conversation ended. Click to start a new conversation.")},this.sdk.onError=function(e){t.showError(e.message)},this.sdk.onTranscript=function(e){t.addMessage("user",e)},this.sdk.onAgentSpeaking=function(e){e?t.showAgentThinking():t.hideAgentThinking()}}},{key:"createWidget",value:function(){var t=document.createElement("div");if(t.id="agent-widget",t.innerHTML=this.generateWidgetHTML(),document.body.appendChild(t),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var e=document.getElementById("agent-panel");e&&(this.isOpen=!0,e.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){this.config.position;var t=this.config.button,e=this.config.icon,n=this.config.panel,o=this.config.header,r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[t.size]||60),i={small:20,medium:28,large:36,xl:44}[e.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i);return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="agent-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="agent-panel">\n ').concat(o.showTitle?'\n <div id="agent-header" style="direction: '.concat(this.config.direction,';">\n ').concat("rtl"===this.config.direction?"\n ".concat(o.showCloseButton?'<button id="agent-close">×</button>':"",'\n <h3 style="margin: 0; color: ').concat(o.textColor,';">').concat(o.title,"</h3>\n "):'\n <h3 style="margin: 0; color: '.concat(o.textColor,';">').concat(o.title,"</h3>\n ").concat(o.showCloseButton?'<button id="agent-close">×</button>':"","\n "),"\n </div>\n "):"",'\n \n <div id="agent-messages"></div>\n \n <div id="agent-controls">\n <div style="display: flex; flex-direction: column; align-items: center; gap: 8px;">\n <button id="agent-mic-button" \n aria-label="Start/Stop Voice Recording">\n ').concat(c,"\n </button>\n ").concat(n.micButtonHint.text&&n.micButtonHint.text.trim()?'\n <div id="agent-mic-hint" style="color: '.concat(n.micButtonHint.color,"; font-size: ").concat(n.micButtonHint.fontSize,'; text-align: center; max-width: 200px;">\n ').concat(n.micButtonHint.text,"\n </div>\n "):"","\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="Voice 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>");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>')}}},{key:"generateCSS",value:function(t,e,n){var o=this.config.button,r=this.config.panel,i=this.config.header,a=this.config.messages,c=this.config.animation,s=o.backgroundColor||o.primaryColor,u=i.backgroundColor,l=r.micButtonColor||o.primaryColor,d=r.micButtonActiveColor||"#EF4444";return"\n #agent-widget {\n position: fixed;\n ".concat(t,'\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n -webkit-transform: translateZ(0);\n transform: translateZ(0);\n will-change: transform;\n }\n \n #agent-button {\n width: ').concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n background: ").concat(s,";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(c.duration,"s ease;\n ").concat(o.shadow?"box-shadow: 0 4px 12px ".concat(o.shadowColor,";"):"","\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 #agent-button {\n min-width: 56px;\n min-height: 56px;\n }\n }\n \n ").concat(c.enableHover?"\n #agent-button:hover {\n background: ".concat(o.hoverColor,";\n transform: scale(1.05);\n ").concat(o.shadow?"box-shadow: 0 8px 20px ".concat(o.shadowColor,";"):"","\n }\n "):"","\n \n #agent-panel {\n display: none;\n position: absolute;\n bottom: ").concat(this.config.behavior.hidden?20:e+20,"px;\n ").concat("right"===this.config.position.horizontal?"right: 0;":"left: 0;","\n width: ").concat(r.width,"px;\n height: ").concat(r.height,"px;\n background: ").concat(r.backgroundColor,";\n border-radius: ").concat(r.borderRadius,"px;\n border: ").concat(r.border,";\n flex-direction: column;\n overflow: hidden;\n ").concat(r.backdropFilter?"backdrop-filter: ".concat(r.backdropFilter,";"):"","\n ").concat(c.enableSlide?"transition: all ".concat(c.duration,"s ease;"):"","\n }\n \n #agent-panel.open {\n display: flex;\n ").concat(c.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n \n #agent-header {\n background: ").concat(u,";\n color: ").concat(i.textColor,";\n padding: 16px;\n display: flex;\n flex-direction: ").concat("rtl"===this.config.direction?"row-reverse":"row",";\n justify-content: space-between;\n align-items: center;\n border-radius: ").concat(r.borderRadius,"px ").concat(r.borderRadius,"px 0 0;\n direction: ").concat(this.config.direction,";\n }\n \n #agent-header h3 {\n margin: 0;\n flex: 1;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n }\n \n #agent-close {\n background: none;\n border: none;\n color: ").concat(i.textColor,";\n cursor: pointer;\n font-size: 24px;\n padding: 0;\n width: 24px;\n height: 24px;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n }\n \n #agent-messages {\n flex: 1;\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n \n .message {\n padding: 12px;\n border-radius: ").concat(a.borderRadius,"px;\n max-width: 80%;\n font-size: ").concat(a.fontSize,";\n color: ").concat(a.textColor,";\n }\n \n .message.user {\n background: ").concat(a.userBackgroundColor,";\n align-self: flex-end;\n }\n \n .message.agent {\n background: ").concat(a.agentBackgroundColor,";\n align-self: flex-start;\n }\n \n .message.system {\n background: ").concat(a.systemBackgroundColor,";\n align-self: flex-start;\n font-style: italic;\n }\n \n .error-message {\n background: ").concat(a.errorBackgroundColor,";\n color: #991B1B;\n padding: 12px;\n border-radius: ").concat(a.borderRadius,"px;\n margin: 8px;\n }\n \n #agent-controls {\n padding: 16px;\n border-top: 1px solid #E5E7EB;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n \n #agent-controls > div {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 8px;\n }\n \n #agent-mic-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n #agent-mic-button {\n width: ").concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n border: none;\n background: ").concat(l,";\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(c.duration,"s ease;\n }\n \n #agent-mic-button.active {\n background: ").concat(d,";\n ").concat(c.enablePulse?"\n animation: pulse 1.5s infinite;\n ":"","\n }\n \n ").concat(c.enablePulse?"\n @keyframes pulse {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.05); }\n }\n ":"","\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this,e=document.getElementById("agent-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("agent-close");n&&(n.onclick=function(){return t.togglePanel()}),document.getElementById("agent-mic-button").onclick=function(){return t.toggleVoice()},this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{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("agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(e=ee(Zt().m(function t(){var e,n,o,r;return Zt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isActive){t.n=13;break}return t.p=1,console.log("🎤 Starting voice session..."),t.n=2,this.getSignedUrl();case 2:return e=t.v,console.log("🔗 Got signed URL:",e),t.n=3,this.sdk.connect(e);case 3:n=t.v,console.log("✅ Connected to WebSocket, connected:",n),o=0;case 4:if(this.sdk.isConnected||!(o<50)){t.n=6;break}return t.n=5,new Promise(function(t){return setTimeout(t,100)});case 5:o++,t.n=4;break;case 6:if(!this.sdk.isConnected){t.n=8;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=7,this.sdk.startListening();case 7:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop"),t.n=10;break;case 8:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),t.n=9,this.sdk.startListening();case 9:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop");case 10:t.n=12;break;case 11:t.p=11,r=t.v,console.error("❌ Failed to start:",r),this.showError(r.message);case 12:t.n=14;break;case 13:console.log("🔇 Stopping voice session..."),this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,this.updateMicButtonState(!1),this.addMessage("system","🔇 Stopped listening");case 14:return t.a(2)}},t,this,[[1,11]])})),function(){return e.apply(this,arguments)})},{key:"updateMicButtonState",value:function(t){var e=document.getElementById("agent-mic-button");if(e)if(this.config.icon.size,t){if(e.classList.add("active"),e.title="Click to stop listening","microphone"===this.config.icon.type||"custom"===this.config.icon.type){var n=e.querySelector("svg")||e.querySelector("img");n&&"svg"===n.tagName&&(n.innerHTML='\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n <path d="M9 9h6"/>\n ')}}else if(e.classList.remove("active"),e.title="Click to start listening","microphone"===this.config.icon.type){var o=e.querySelector("svg");o&&(o.innerHTML='\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 ')}}},{key:"getSignedUrl",value:(t=ee(Zt().m(function t(){var e,n,o,r,i,a,c;return Zt().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return t.apply(this,arguments)})},{key:"addMessage",value:function(t,e){var n=document.getElementById("agent-messages"),o=document.createElement("div");o.className="message ".concat(t),o.textContent=e,n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"showAgentThinking",value:function(){var t=document.getElementById("agent-messages"),e=document.createElement("div");e.className="message agent agent-thinking",e.id="thinking-indicator",e.textContent="Agent is speaking...",t.appendChild(e),t.scrollTop=t.scrollHeight}},{key:"hideAgentThinking",value:function(){var t=document.getElementById("thinking-indicator");t&&t.remove()}},{key:"showError",value:function(t){var e=document.getElementById("agent-messages"),n=document.createElement("div");n.className="error-message",n.textContent=t,e.appendChild(n)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n=Jt({},this.config);t.panel&&(n.panel=Jt(Jt({},this.config.panel),t.panel),t.panel.micButtonHint&&(n.panel.micButtonHint=Jt(Jt({},null===(e=this.config.panel)||void 0===e?void 0:e.micButtonHint),t.panel.micButtonHint))),t.button&&(n.button=Jt(Jt({},this.config.button),t.button)),t.header&&(n.header=Jt(Jt({},this.config.header),t.header)),t.icon&&(n.icon=Jt(Jt({},this.config.icon),t.icon)),t.messages&&(n.messages=Jt(Jt({},this.config.messages),t.messages)),void 0!==t.direction&&(n.direction=t.direction),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction"].includes(e)||(n[e]=t[e])}),this.config=this.mergeWithDefaults(n);var o=document.getElementById("agent-widget");o&&o.remove(),this.createWidget()}},{key:"destroy",value:function(){var t=document.getElementById("agent-widget");t&&t.remove(),this.sdk&&this.sdk.disconnect()}}]);var t,e}();function se(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof c?o:c,u=Object.create(s.prototype);return ue(u,"_invoke",function(n,o,r){var i,c,s,u=0,l=r||[],d=!1,f={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,c=0,s=t,f.n=n,a}};function p(n,o){for(c=n,s=o,e=0;!d&&u&&!r&&e<l.length;e++){var r,i=l[e],p=f.p,g=i[2];n>3?(r=g===o)&&(s=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(c=0,f.v=o,f.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,f.n=g,c=0))}if(r||n>1)return a;throw d=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(d&&1===l&&p(l,g),c=l,s=g;(e=c<2?t:s)||!d;){i||(c?c<3?(c>1&&(f.n=-1),p(c,s)):f.n=s:f.v=s);try{if(u=2,i){if(c||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),c=1);i=t}else if((e=(d=f.n<0)?s:n.call(o,f))!==a)break}catch(e){i=t,c=1,s=e}finally{u=1}}return{value:e,done:d}}}(n,r,i),!0),u}var a={};function c(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(ue(e={},o,function(){return this}),e),d=u.prototype=c.prototype=Object.create(l);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,ue(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return s.prototype=u,ue(d,"constructor",u),ue(u,"constructor",s),s.displayName="GeneratorFunction",ue(u,r,"GeneratorFunction"),ue(d),ue(d,r,"Generator"),ue(d,o,function(){return this}),ue(d,"toString",function(){return"[object Generator]"}),(se=function(){return{w:i,m:f}})()}function ue(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}ue=function(t,e,n,o){function i(e,n){ue(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},ue(t,e,n,o)}function le(t,e,n,o,r,i,a){try{var c=t[i](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(o,r)}function de(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function a(t){le(i,o,r,a,c,"next",t)}function c(t){le(i,o,r,a,c,"throw",t)}a(void 0)})}}function fe(t){return fe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},fe(t)}function pe(t,e){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 ge(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?pe(Object(n),!0).forEach(function(e){he(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):pe(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function he(t,e,n){return(e=ye(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ve(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"!=fe(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=fe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==fe(e)?e:e+""}var be=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=this.mergeWithDefaults(e),this.sdk=new Ot(this.config),this.isOpen=!1,this.isActive=!1,this.streamingEl=null,this.hasStartedStreaming=!1,this.streamingTimer=null,this.setupEventHandlers(),this.createWidget(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var n=document.getElementById("text-chat-panel");n&&(this.isOpen=!0,n.classList.add("open"))}},e=[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,a,c,s,u,l,d,f,p,g,h,v,y,b,m,w,S,k,x,C,O,j,P,I,E,B,T,F,R,_,D,M,A,L,H,z,U,K,W,N,G,V,Q,q,Y,J,$,Z,X,tt,et,nt,ot,rt,it,at,ct,st,ut,lt,dt,ft,pt,gt,ht=t.position||"bottom-right";if("string"==typeof ht){var vt=ht.split("-");ht={vertical:vt[0]||"bottom",horizontal:vt[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var yt=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||"#4F46E5";return ge({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",icon:ge({type:(null===(n=t.icon)||void 0===n?void 0:n.type)||"chat",customImage:(null===(o=t.icon)||void 0===o?void 0:o.customImage)||null,emoji:(null===(r=t.icon)||void 0===r?void 0:r.emoji)||"💬",text:(null===(i=t.icon)||void 0===i?void 0:i.text)||"AI",size:(null===(a=t.icon)||void 0===a?void 0:a.size)||"medium",backgroundColor:(null===(c=t.icon)||void 0===c?void 0:c.backgroundColor)||null},t.icon),position:ge({vertical:ht.vertical||"bottom",horizontal:ht.horizontal||"right",offset:ht.offset||{x:20,y:20}},"object"===fe(t.position)?t.position:{}),button:ge({size:(null===(s=t.button)||void 0===s?void 0:s.size)||"medium",shape:(null===(u=t.button)||void 0===u?void 0:u.shape)||"circle",backgroundColor:(null===(l=t.button)||void 0===l?void 0:l.backgroundColor)||(null===(d=t.icon)||void 0===d?void 0:d.backgroundColor)||yt,hoverColor:(null===(f=t.button)||void 0===f?void 0:f.hoverColor)||"#7C3AED",shadow:!1!==(null===(p=t.button)||void 0===p?void 0:p.shadow),shadowColor:(null===(g=t.button)||void 0===g?void 0:g.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(h=t.button)||void 0===h?void 0:h.backgroundColor)||(null===(v=t.icon)||void 0===v?void 0:v.backgroundColor)||yt},t.button),panel:ge({width:(null===(y=t.panel)||void 0===y?void 0:y.width)||350,height:(null===(b=t.panel)||void 0===b?void 0:b.height)||500,borderRadius:(null===(m=t.panel)||void 0===m?void 0:m.borderRadius)||12,backgroundColor:(null===(w=t.panel)||void 0===w?void 0:w.backgroundColor)||"#FFFFFF",backdropFilter:(null===(S=t.panel)||void 0===S?void 0:S.backdropFilter)||null,border:(null===(k=t.panel)||void 0===k?void 0:k.border)||"1px solid rgba(0,0,0,0.1)",sendButtonColor:(null===(x=t.panel)||void 0===x?void 0:x.sendButtonColor)||yt,sendButtonHoverColor:(null===(C=t.panel)||void 0===C?void 0:C.sendButtonHoverColor)||"#7C3AED",sendButtonActiveColor:(null===(O=t.panel)||void 0===O?void 0:O.sendButtonActiveColor)||"#059669",sendButtonText:(null===(j=t.panel)||void 0===j?void 0:j.sendButtonText)||"Send",sendButtonTextColor:(null===(P=t.panel)||void 0===P?void 0:P.sendButtonTextColor)||"#FFFFFF",sendButtonFontSize:(null===(I=t.panel)||void 0===I?void 0:I.sendButtonFontSize)||"14px",sendButtonFontWeight:(null===(E=t.panel)||void 0===E?void 0:E.sendButtonFontWeight)||"500",sendButtonHint:ge({text:(null===(B=t.panel)||void 0===B||null===(B=B.sendButtonHint)||void 0===B?void 0:B.text)||"",color:(null===(T=t.panel)||void 0===T||null===(T=T.sendButtonHint)||void 0===T?void 0:T.color)||"#6B7280",fontSize:(null===(F=t.panel)||void 0===F||null===(F=F.sendButtonHint)||void 0===F?void 0:F.fontSize)||"12px"},null===(R=t.panel)||void 0===R?void 0:R.sendButtonHint),inputPlaceholder:(null===(_=t.panel)||void 0===_?void 0:_.inputPlaceholder)||"Type your message...",inputBorderColor:(null===(D=t.panel)||void 0===D?void 0:D.inputBorderColor)||"#E5E7EB",inputFocusColor:(null===(M=t.panel)||void 0===M?void 0:M.inputFocusColor)||yt,inputBackgroundColor:(null===(A=t.panel)||void 0===A?void 0:A.inputBackgroundColor)||"#FFFFFF",inputTextColor:(null===(L=t.panel)||void 0===L?void 0:L.inputTextColor)||"#1F2937",inputFontSize:(null===(H=t.panel)||void 0===H?void 0:H.inputFontSize)||"14px",inputBorderRadius:(null===(z=t.panel)||void 0===z?void 0:z.inputBorderRadius)||8,inputPadding:(null===(U=t.panel)||void 0===U?void 0:U.inputPadding)||"12px"},t.panel),header:ge({title:(null===(K=t.header)||void 0===K?void 0:K.title)||"Chat Assistant",showTitle:!1!==(null===(W=t.header)||void 0===W?void 0:W.showTitle),backgroundColor:(null===(N=t.header)||void 0===N?void 0:N.backgroundColor)||(null===(G=t.button)||void 0===G?void 0:G.backgroundColor)||yt,textColor:(null===(V=t.header)||void 0===V?void 0:V.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(Q=t.header)||void 0===Q?void 0:Q.showCloseButton)},t.header),messages:ge({userBackgroundColor:(null===(q=t.messages)||void 0===q?void 0:q.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(Y=t.messages)||void 0===Y?void 0:Y.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(J=t.messages)||void 0===J?void 0:J.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===($=t.messages)||void 0===$?void 0:$.errorBackgroundColor)||"#FEE2E2",textColor:(null===(Z=t.messages)||void 0===Z?void 0:Z.textColor)||"#1F2937",fontSize:(null===(X=t.messages)||void 0===X?void 0:X.fontSize)||"14px",borderRadius:(null===(tt=t.messages)||void 0===tt?void 0:tt.borderRadius)||8},t.messages),animation:ge({enableHover:!1!==(null===(et=t.animation)||void 0===et?void 0:et.enableHover),enablePulse:!1!==(null===(nt=t.animation)||void 0===nt?void 0:nt.enablePulse),enableSlide:!1!==(null===(ot=t.animation)||void 0===ot?void 0:ot.enableSlide),duration:(null===(rt=t.animation)||void 0===rt?void 0:rt.duration)||.3},t.animation),behavior:ge({autoOpen:(null===(it=t.behavior)||void 0===it?void 0:it.autoOpen)||!1,startOpen:(null===(at=t.behavior)||void 0===at?void 0:at.startOpen)||!1,hidden:(null===(ct=t.behavior)||void 0===ct?void 0:ct.hidden)||!1,autoConnect:(null===(st=t.behavior)||void 0===st?void 0:st.autoConnect)||!1,showWelcomeMessage:!1!==(null===(ut=t.behavior)||void 0===ut?void 0:ut.showWelcomeMessage),welcomeMessage:(null===(lt=t.behavior)||void 0===lt?void 0:lt.welcomeMessage)||"Hello! How can I help you today?",enableVoiceMode:(null===(dt=t.behavior)||void 0===dt?void 0:dt.enableVoiceMode)||!1},t.behavior),accessibility:ge({ariaLabel:(null===(ft=t.accessibility)||void 0===ft?void 0:ft.ariaLabel)||"Chat Assistant",ariaDescription:(null===(pt=t.accessibility)||void 0===pt?void 0:pt.ariaDescription)||"Click to open chat assistant",keyboardNavigation:!1!==(null===(gt=t.accessibility)||void 0===gt?void 0:gt.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},forceConversationId:t.forceConversationId,primaryColor:yt},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.on("error",function(e){t.showError(e.message||e),t.stopStreamingState()}),this.sdk.on("chunk",function(e){t.appendStreamingChunk(e)}),this.sdk.on("done",function(e){var n=e.text;t.finalizeStreaming(n)})}},{key:"createWidget",value:function(){var t=document.createElement("div");if(t.id="text-chat-widget",t.innerHTML=this.generateWidgetHTML(),document.body.appendChild(t),this.setupWidgetEvents(),this.config.behavior.startOpen||this.config.behavior.autoOpen){var e=document.getElementById("text-chat-panel");e&&(this.isOpen=!0,e.classList.add("open"))}}},{key:"generateWidgetHTML",value:function(){this.config.position;var t=this.config.button,e=this.config.icon,n=this.config.panel,o=this.config.header,r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[t.size]||60),i={small:20,medium:28,large:36,xl:44}[e.size]||28,a=this.generatePositionStyles(),c=this.generateIconHTML(i),s=!!this.config.behavior.enableVoiceMode;return"\n <style>\n ".concat(this.generateCSS(a,r,i),"\n ").concat(this.config.customStyles,"\n </style>\n \n ").concat(this.config.behavior.hidden?"":'\n <button id="text-chat-button" \n aria-label="'.concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,"\n </button>\n "),'\n \n <div id="text-chat-panel">\n <div class="widget-shell">\n <div class="panel-inner widget-container" style="direction: ').concat(this.config.direction,';">\n <div class="widget-header">\n <div>\n <div class="header-title">').concat(o.title,'</div>\n <div class="header-status">\n <span class="status-dot"></span>\n <span>').concat("rtl"===this.config.direction?"מקוון":"Online",'</span>\n </div>\n </div>\n <div style="display: flex; gap: 12px; align-items: center;">\n <button class="new-chat-btn header-icon" id="newChatBtn" title="Start new chat">\n <svg width="16" height="16" viewBox="0 0 24 24" fill="none">\n <path d="M12 5v14M5 12h14" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>\n </svg>\n </button>\n ').concat(s?'<button class="back-btn header-icon" id="backBtn"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M10 12L6 8L10 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>':"","\n ").concat(o.showCloseButton?'<button class="close-btn header-icon" id="text-chat-close"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M12 4L4 12M4 4L12 12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></button>':"","\n </div>\n </div>\n\n ").concat(s?'\n <div class="landing-screen" id="landingScreen">\n <div class="landing-logo">🤖</div>\n <div class="landing-title">'.concat("rtl"===this.config.direction?"איך תרצה לתקשר?":"How would you like to communicate?",'</div>\n <div class="mode-selection">\n <div class="mode-card voice" id="mode-card-voice">\n <div class="mode-card-icon">🎤</div>\n <div class="mode-card-title">').concat("rtl"===this.config.direction?"שיחה קולית":"Voice Call",'</div>\n </div>\n <div class="mode-card text" id="mode-card-text">\n <div class="mode-card-icon">💬</div>\n <div class="mode-card-title">').concat("rtl"===this.config.direction?"צ'אט טקסט":"Text Chat","</div>\n </div>\n </div>\n </div>"):"",'\n\n <div class="voice-interface" id="voiceInterface">\n <div class="empty-voice">').concat("rtl"===this.config.direction?"מצב קול placeholder":"Voice mode placeholder",'</div>\n </div>\n\n <div class="text-interface ').concat(s?"":"active",'" 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("rtl"===this.config.direction?"שלום! איך אפשר לעזור?":"Hello! How can I help?",'</div>\n <div class="empty-state-text">').concat("rtl"===this.config.direction?"שלח הודעה או עבור למצב קולי לשיחה בזמן אמת":"Send a message to get started",'</div>\n </div>\n \n </div>\n <div class="input-container">\n ').concat("rtl"===this.config.direction?'\n <button class="send-button" id="sendButton" aria-label="Send message">➤</button>\n <div class="input-wrapper" style="flex:1;">\n <textarea class="message-input" id="messageInput" placeholder="'.concat(n.inputPlaceholder,'" rows="1"></textarea>\n </div>\n '):'\n <div class="input-wrapper" style="flex:1;">\n <textarea class="message-input" id="messageInput" placeholder="'.concat(n.inputPlaceholder,'" rows="1"></textarea>\n </div>\n <button class="send-button" id="sendButton" aria-label="Send message">➤</button>\n '),"\n </div>\n </div>\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>");default: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=this.config.button,r=this.config.panel,i=this.config.header,a=this.config.messages,c=this.config.animation,s=(o.backgroundColor||o.primaryColor,i.backgroundColor);return r.sendButtonColor||o.primaryColor,r.sendButtonHoverColor,r.sendButtonActiveColor,"\n #text-chat-widget {\n position: fixed;\n ".concat(t,'\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n -webkit-transform: translateZ(0);\n transform: translateZ(0);\n will-change: transform;\n }\n \n #text-chat-button {\n width: ').concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(c.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-button {\n min-width: 56px;\n min-height: 56px;\n }\n \n #text-chat-panel {\n width: calc(100vw - 20px) !important;\n max-width: ").concat(r.width,"px;\n max-height: calc(100vh - 120px) !important;\n left: 10px !important;\n right: 10px !important;\n }\n \n #text-chat-input {\n font-size: 16px !important; /* Prevents iOS zoom on focus */\n }\n \n #text-chat-send {\n min-width: 60px;\n min-height: 44px;\n }\n }\n \n ").concat(c.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(r.width,"px;\n max-width: calc(100vw - 40px);\n height: ").concat(r.height,"px;\n max-height: calc(100vh - ").concat(e,"px - 40px);\n background: transparent;\n border-radius: ").concat(r.borderRadius,"px;\n border: none;\n flex-direction: column;\n overflow: hidden;\n ").concat(r.backdropFilter?"backdrop-filter: ".concat(r.backdropFilter,";"):"","\n ").concat(c.enableSlide?"transition: all ".concat(c.duration,"s ease;"):"","\n }\n \n #text-chat-panel.open {\n display: flex;\n ").concat(c.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(r.borderRadius,"px; background: transparent; box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; display: flex; flex-direction: column; }\n .panel-inner { width: 100%; height: 100%; background: #ffffff; border-radius: ").concat(r.borderRadius,"px; overflow: hidden; display:flex; flex-direction: column; padding: 0; box-sizing: border-box; }\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(r.borderRadius,"px;\n }\n #text-chat-panel .widget-header {\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: #FFFFFF;\n padding: 12px 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-top-left-radius: ").concat(r.borderRadius,"px;\n border-top-right-radius: ").concat(r.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 #text-chat-panel .back-btn, #text-chat-panel .close-btn {\n background: rgba(255,255,255,0.2);\n border: none; color: white; width: 32px; height: 32px; border-radius: 50%; cursor: pointer;\n display: flex; align-items: center; justify-content: center;\n }\n #text-chat-panel .new-chat-btn { background: rgba(255,255,255,0.2); border: none; color: white; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; }\n\n /* Landing and mode selection (shown only if voice enabled) */\n .landing-screen { display: none; flex: 1; padding: 20px; background: linear-gradient(180deg, #f8fafc 0%, #e0e7ff 100%); align-items: center; justify-content: flex-start; flex-direction: column; gap: 16px; overflow-y: auto; min-height: 0; }\n .landing-screen.active { display: flex; }\n .landing-logo { font-size: 48px; }\n .landing-title { font-size: 20px; color: #1e293b; font-weight: 700; margin-bottom: 20px; }\n .mode-selection { display: flex; gap: 16px; width: 100%; justify-content: center; }\n .mode-card { flex: 1; max-width: 180px; background: #FFFFFF; border: 2px solid #E2E8F0; border-radius: 20px; padding: 20px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; transition: transform ").concat(c.duration,"s ease, box-shadow ").concat(c.duration,"s ease, border-color ").concat(c.duration,"s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }\n .mode-card:hover { transform: translateY(-6px); box-shadow: 0 12px 24px rgba(102, 126, 234, 0.2); border-color: ").concat(s,"; }\n .mode-card-icon { width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: ").concat(s,"; color: #fff; font-size: 32px; }\n .mode-card-title { color: #111827; font-weight: 600; }\n\n .voice-interface { display: none; flex: 1; align-items: center; justify-content: center; padding: 20px; background: #F8FAFC; }\n .voice-interface.active { display: flex; }\n .empty-voice { color: #6B7280; font-size: 14px; }\n \n /* Messages container using new classes */\n #messagesContainer { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 20px; background: #f8fafc; display: flex; flex-direction: column; gap: 16px; min-height: 0; }\n .empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #64748b; text-align: center; padding: 20px; }\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 { display: none; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; }\n .text-interface.active { display: flex; }\n \n .message { display: flex; gap: 8px; padding: 4px 0; max-width: 100%; align-items: center; }\n .message.edge-left { flex-direction: row; }\n .message.edge-right { flex-direction: row-reverse; }\n .message-bubble { padding: 12px; border-radius: ").concat(a.borderRadius,"px; max-width: 80%; font-size: ").concat(a.fontSize,"; color: ").concat(a.textColor,"; word-wrap: break-word; text-align: ").concat("rtl"===this.config.direction?"right":"left","; }\n .message.user { background: ").concat(a.userBackgroundColor,"; align-self: ").concat("rtl"===this.config.direction?"flex-start":"flex-end","; }\n .message.agent { background: ").concat(a.agentBackgroundColor,"; align-self: ").concat("rtl"===this.config.direction?"flex-end":"flex-start","; }\n .message .message-bubble { text-align: ").concat("rtl"===this.config.direction?"right":"left","; }\n .message-avatar { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: inherit; font-size: 18px; line-height: 1; background: transparent; border: none; }\n .message-avatar.user { background: transparent; }\n .message-avatar.agent { background: transparent; }\n \n .message.system {\n background: ").concat(a.systemBackgroundColor,";\n align-self: flex-start;\n font-style: italic;\n }\n \n .error-message {\n background: ").concat(a.errorBackgroundColor,";\n color: #991B1B;\n padding: 12px;\n border-radius: ").concat(a.borderRadius,"px;\n margin: 8px;\n }\n \n .input-container { padding: 10px 16px; background: white; border-top: 1px solid #E2E8F0; display: flex; gap: 10px; align-items: center; border-bottom-left-radius: ").concat(r.borderRadius,"px; border-bottom-right-radius: ").concat(r.borderRadius,"px; flex-shrink: 0; box-sizing: border-box; }\n .input-wrapper { flex: 1; display: flex; align-items: center; order: initial; }\n .message-input { width: 100%; padding: 0 14px; border: 2px solid #E5E7EB; border-radius: 20px; font-size: 14px; font-family: inherit; resize: none; height: 32px; transition: border-color ").concat(c.duration,"s, box-shadow ").concat(c.duration,"s; outline: none; background: #F9FAFB; color: ").concat(r.inputTextColor,"; line-height: 32px; overflow-y: auto; }\n .message-input::placeholder { line-height: 32px; }\n .message-input:focus { border-color: #667eea; background: #FFFFFF; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); }\n .message-input::placeholder { color: #9CA3AF; }\n .send-button { width: 44px; height: 44px; border-radius: 50%; border: none; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; flex-shrink: 0; box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); order: initial; }\n .send-button:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5); background: linear-gradient(135deg, #764ba2 0%, #667eea 100%); }\n .send-button:active { transform: translateY(0px); box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4); }\n .send-button svg { width: 18px; height: 18px; display: block; pointer-events: none; }\n .send-button svg * { stroke: white !important; fill: none !important; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }\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\n /* Typing indicator */\n .typing-indicator { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }\n .typing-dot { width: 6px; height: 6px; background: #9CA3AF; border-radius: 50%; opacity: 0.6; animation: typingBlink 1.2s infinite ease-in-out; }\n .typing-dot:nth-child(2) { animation-delay: 0.2s; }\n .typing-dot:nth-child(3) { animation-delay: 0.4s; }\n @keyframes typingBlink { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-3px); opacity: 1; } }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this,e=document.getElementById("text-chat-button");e&&(e.onclick=function(){return t.togglePanel()});var n=document.getElementById("text-chat-close");n&&(n.onclick=function(){return t.togglePanel()});var o=document.getElementById("backBtn"),r=document.getElementById("landingScreen"),i=document.getElementById("mode-card-voice"),a=document.getElementById("mode-card-text"),c=document.getElementById("textInterface"),s=document.getElementById("voiceInterface");this.config.behavior.enableVoiceMode&&(o&&(o.onclick=function(){return t.showLanding()}),i&&(i.onclick=function(){return t.showVoice()}),a&&(a.onclick=function(){return t.showText()}),r&&r.classList.add("active"),c&&c.classList.remove("active"),s&&s.classList.remove("active"));var u=document.getElementById("sendButton"),l=document.getElementById("messageInput"),d=document.getElementById("newChatBtn");u&&(u.onclick=function(){return t.sendMessage()}),d&&(d.onclick=function(){return t.startNewChat()}),l&&l.addEventListener("keydown",function(e){"Enter"!==e.key||e.shiftKey||(e.preventDefault(),t.sendMessage())}),this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{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("rtl"===this.config.direction?"שלום! איך אפשר לעזור?":"Hello! How can I help?",'</div>\n <div class="empty-state-text">').concat("rtl"===this.config.direction?"שלח הודעה כדי להתחיל":"Send a message to get started",'</div>\n </div>\n <div class="message assistant">\n <div class="message-avatar">🤖</div>\n <div class="typing-indicator" id="typingIndicator">\n <div class="typing-dot"></div>\n <div class="typing-dot"></div>\n <div class="typing-dot"></div>\n </div>\n </div>'));var e=document.getElementById("messageInput");e&&e.focus()}},{key:"showLanding",value:function(){if(this.config.behavior.enableVoiceMode){var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface");t&&t.classList.add("active"),e&&e.classList.remove("active"),n&&n.classList.remove("active")}}},{key:"showText",value:function(){var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface");t&&t.classList.remove("active"),e&&e.classList.add("active"),n&&n.classList.remove("active"),setTimeout(function(){var t=document.getElementById("messageInput");t&&t.focus()},50)}},{key:"showVoice",value:function(){var t=document.getElementById("landingScreen"),e=document.getElementById("textInterface"),n=document.getElementById("voiceInterface");t&&t.classList.remove("active"),e&&e.classList.remove("active"),n&&n.classList.add("active")}},{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=de(se().m(function t(){return se().w(function(t){for(;;)switch(t.n){case 0:this.isActive=!0,this.updateSendButtonState();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"sendMessage",value:(o=de(se().m(function t(){var e,n,o;return se().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="",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),this.showError(o.message),this.stopStreamingState();case 6:return t.a(2)}},t,this,[[3,5]])})),function(){return o.apply(this,arguments)})},{key:"updateSendButtonState",value:function(){var t=document.getElementById("sendButton");t&&(t.disabled=!this.isActive)}},{key:"getSignedUrl",value:(n=de(se().m(function t(){var e,n,o,r,i,a,c;return se().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://backend.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return a={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(a.appId=this.config.appId),t.n=7,this.config.getSessionUrl(a);case 7:return c=t.v,t.a(2,"string"==typeof c?c:c.signedUrl||c.wsUrl||c.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return n.apply(this,arguments)})},{key:"addMessage",value:function(t,e){var n=document.getElementById("messagesContainer"),o=document.createElement("div"),r="rtl"===this.config.direction?"user"===t?"edge-left":"edge-right":"user"===t?"edge-right":"edge-left";o.className="message ".concat(t," ").concat(r);var i=document.createElement("div");i.className="message-avatar ".concat(t),i.textContent="user"===t?"👤":"🤖";var a=document.createElement("div");a.className="message-bubble",a.textContent=e,o.appendChild(i),o.appendChild(a),n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"beginStreaming",value:function(){var t=document.getElementById("messagesContainer");this.stopStreamingState();var e=document.createElement("div"),n="rtl"===this.config.direction?"edge-right":"edge-left";e.className="message agent ".concat(n),e.id="agent-streaming";var o=document.createElement("div");o.className="message-avatar agent",o.textContent="🤖";var r=document.createElement("div");r.className="message-bubble",r.innerHTML='<span class="typing-indicator"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></span>',e.appendChild(o),e.appendChild(r),t.appendChild(e),this.streamingEl=r,this.hasStartedStreaming=!1,t.scrollTop=t.scrollHeight}},{key:"appendStreamingChunk",value:function(t){if(this.streamingEl){this.hasStartedStreaming||(this.streamingEl.textContent="",this.hasStartedStreaming=!0),this.streamingEl.textContent+=t;var e=document.getElementById("messagesContainer");e.scrollTop=e.scrollHeight}}},{key:"finalizeStreaming",value:function(t){var e=this;if(this.streamingEl){if(!this.hasStartedStreaming&&t&&t.length>0){this.streamingEl.textContent="",this.hasStartedStreaming=!0;var n=t,o=0,r=document.getElementById("messagesContainer");return clearInterval(this.streamingTimer),void(this.streamingTimer=setInterval(function(){if(e.streamingEl){if(e.streamingEl.textContent+=n.charAt(o),r&&(r.scrollTop=r.scrollHeight),++o>=n.length){clearInterval(e.streamingTimer);var t=document.getElementById("agent-streaming");t&&(t.id=""),e.streamingEl=null,e.updateSendButtonState()}}else clearInterval(e.streamingTimer)},20))}this.streamingEl.textContent=t||this.streamingEl.textContent;var i=document.getElementById("agent-streaming");i&&(i.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,clearInterval(this.streamingTimer)}},{key:"showError",value:function(t){var e=document.getElementById("messagesContainer"),n=document.createElement("div");n.className="error-message",n.textContent=t,e.appendChild(n),e.scrollTop=e.scrollHeight}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n,o=ge({},this.config);t.panel&&(o.panel=ge(ge({},this.config.panel),t.panel),t.panel.sendButtonHint&&(o.panel.sendButtonHint=ge(ge({},null===(e=this.config.panel)||void 0===e?void 0:e.sendButtonHint),t.panel.sendButtonHint)),t.panel.inputConfig&&(o.panel.inputConfig=ge(ge({},null===(n=this.config.panel)||void 0===n?void 0:n.inputConfig),t.panel.inputConfig))),t.button&&(o.button=ge(ge({},this.config.button),t.button)),t.header&&(o.header=ge(ge({},this.config.header),t.header)),t.icon&&(o.icon=ge(ge({},this.config.icon),t.icon)),t.messages&&(o.messages=ge(ge({},this.config.messages),t.messages)),void 0!==t.direction&&(o.direction=t.direction),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction"].includes(e)||(o[e]=t[e])}),this.config=this.mergeWithDefaults(o);var r=document.getElementById("text-chat-widget");r&&r.remove(),this.createWidget()}},{key:"destroy",value:function(){var t=document.getElementById("text-chat-widget");t&&t.remove(),this.sdk&&this.sdk.destroy()}}],e&&ve(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,r}(),me="2.0.0";const we={VoiceSDK:ft,TextChatSDK:Ot,WebSocketManager:T,AudioRecorder:K,AudioPlayer:Z,EventEmitter:c,VoiceButton:At,VanillaVoiceButton:Qt,AgentSDK:ae,AgentWidget:ce,TextChatWidget:be,VERSION:me};return o})());
|
|
3
3
|
//# sourceMappingURL=agent-widget.js.map
|