ttp-agent-sdk 2.0.0 → 2.0.2
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/GETTING_STARTED.md +6 -6
- package/README.md +6 -6
- package/dist/agent-widget.js +1 -1
- package/dist/agent-widget.js.map +1 -1
- package/dist/examples/react-example.html +3 -3
- package/dist/examples/react-example.jsx +2 -2
- package/dist/examples/test.html +2 -2
- package/dist/examples/vanilla-example.html +3 -3
- package/dist/index.html +2 -2
- package/examples/react-example.html +3 -3
- package/examples/react-example.jsx +2 -2
- package/examples/test.html +2 -2
- package/examples/vanilla-example.html +3 -3
- package/package.json +2 -3
- package/src/core/AudioPlayer.js +0 -185
- package/src/core/AudioRecorder.js +0 -128
- package/src/core/ConnectionManager.js +0 -86
- package/src/core/EventEmitter.js +0 -53
- package/src/core/VoiceSDK.js +0 -390
- package/src/core/WebSocketManager.js +0 -218
- package/src/core/WebSocketManagerV2.js +0 -211
- package/src/core/WebSocketSingleton.js +0 -171
- package/src/index.js +0 -64
- package/src/legacy/AgentSDK.js +0 -462
- package/src/react/VoiceButton.jsx +0 -163
- package/src/vanilla/VoiceButton.js +0 -190
package/GETTING_STARTED.md
CHANGED
|
@@ -54,7 +54,7 @@ import { VoiceButton } from 'ttp-agent-sdk';
|
|
|
54
54
|
function App() {
|
|
55
55
|
return (
|
|
56
56
|
<VoiceButton
|
|
57
|
-
|
|
57
|
+
websocketUrl="wss://speech.talktopc.com/ws/conv"
|
|
58
58
|
agentId="your_agent_id"
|
|
59
59
|
appId="your_app_id"
|
|
60
60
|
onConnected={() => console.log('Connected!')}
|
|
@@ -70,7 +70,7 @@ function App() {
|
|
|
70
70
|
import { VoiceSDK } from 'ttp-agent-sdk';
|
|
71
71
|
|
|
72
72
|
const voiceSDK = new VoiceSDK({
|
|
73
|
-
|
|
73
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv',
|
|
74
74
|
agentId: 'your_agent_id',
|
|
75
75
|
appId: 'your_app_id'
|
|
76
76
|
});
|
|
@@ -88,7 +88,7 @@ For development and testing, you can use direct agent ID authentication:
|
|
|
88
88
|
|
|
89
89
|
```javascript
|
|
90
90
|
const voiceSDK = new VoiceSDK({
|
|
91
|
-
|
|
91
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv',
|
|
92
92
|
agentId: 'your_agent_id', // Direct agent ID
|
|
93
93
|
appId: 'your_app_id' // User's app ID
|
|
94
94
|
});
|
|
@@ -127,7 +127,7 @@ async function getSignedUrl(agentId, variables = {}) {
|
|
|
127
127
|
|
|
128
128
|
```javascript
|
|
129
129
|
const voiceSDK = new VoiceSDK({
|
|
130
|
-
|
|
130
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv', // Required
|
|
131
131
|
agentId: 'agent_12345', // Optional - for direct access
|
|
132
132
|
appId: 'app_67890', // Optional - user's app ID
|
|
133
133
|
ttpId: 'ttp_abc123', // Optional - custom TTP ID
|
|
@@ -260,7 +260,7 @@ function VoiceChat() {
|
|
|
260
260
|
|
|
261
261
|
useEffect(() => {
|
|
262
262
|
const voiceSDK = new VoiceSDK({
|
|
263
|
-
|
|
263
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv',
|
|
264
264
|
agentId: 'your_agent_id',
|
|
265
265
|
appId: 'your_app_id'
|
|
266
266
|
});
|
|
@@ -327,7 +327,7 @@ function VoiceChat() {
|
|
|
327
327
|
import { VoiceSDK } from 'https://unpkg.com/ttp-agent-sdk/dist/agent-widget.js';
|
|
328
328
|
|
|
329
329
|
const voiceSDK = new VoiceSDK({
|
|
330
|
-
|
|
330
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv',
|
|
331
331
|
agentId: 'your_agent_id',
|
|
332
332
|
appId: 'your_app_id'
|
|
333
333
|
});
|
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ npm install ttp-agent-sdk
|
|
|
27
27
|
import { VoiceSDK } from 'ttp-agent-sdk';
|
|
28
28
|
|
|
29
29
|
const voiceSDK = new VoiceSDK({
|
|
30
|
-
websocketUrl: 'wss://speech.
|
|
30
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv',
|
|
31
31
|
agentId: 'your_agent_id',
|
|
32
32
|
appId: 'your_app_id',
|
|
33
33
|
voice: 'default',
|
|
@@ -45,7 +45,7 @@ await voiceSDK.startRecording();
|
|
|
45
45
|
import { VoiceSDK } from 'ttp-agent-sdk';
|
|
46
46
|
|
|
47
47
|
const voiceSDK = new VoiceSDK({
|
|
48
|
-
websocketUrl: 'wss://speech.
|
|
48
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv',
|
|
49
49
|
// No agentId needed - server validates signed token from URL
|
|
50
50
|
});
|
|
51
51
|
|
|
@@ -86,7 +86,7 @@ import { VoiceButton } from 'ttp-agent-sdk';
|
|
|
86
86
|
function App() {
|
|
87
87
|
return (
|
|
88
88
|
<VoiceButton
|
|
89
|
-
websocketUrl="wss://speech.
|
|
89
|
+
websocketUrl="wss://speech.talktopc.com/ws/conv"
|
|
90
90
|
agentId="your_agent_id"
|
|
91
91
|
appId="your_app_id"
|
|
92
92
|
onConnected={() => console.log('Connected!')}
|
|
@@ -107,7 +107,7 @@ The main SDK class for voice interaction.
|
|
|
107
107
|
|
|
108
108
|
```javascript
|
|
109
109
|
const voiceSDK = new VoiceSDK({
|
|
110
|
-
websocketUrl: 'wss://speech.
|
|
110
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv', // Required
|
|
111
111
|
agentId: 'agent_12345', // Optional - for direct agent access
|
|
112
112
|
appId: 'app_67890', // Optional - user's app ID for authentication
|
|
113
113
|
ttpId: 'ttp_abc123', // Optional - custom TTP ID (fallback)
|
|
@@ -146,7 +146,7 @@ A React component that provides a voice interaction button.
|
|
|
146
146
|
|
|
147
147
|
```jsx
|
|
148
148
|
<VoiceButton
|
|
149
|
-
websocketUrl="wss://speech.
|
|
149
|
+
websocketUrl="wss://speech.talktopc.com/ws/conv"
|
|
150
150
|
agentId="agent_12345"
|
|
151
151
|
appId="app_67890"
|
|
152
152
|
voice="default"
|
|
@@ -190,7 +190,7 @@ TTPAgentSDK.AgentWidget.init({
|
|
|
190
190
|
|
|
191
191
|
```javascript
|
|
192
192
|
const voiceSDK = new VoiceSDK({
|
|
193
|
-
websocketUrl: 'wss://speech.
|
|
193
|
+
websocketUrl: 'wss://speech.talktopc.com/ws/conv',
|
|
194
194
|
agentId: 'agent_12345', // Visible in network traffic
|
|
195
195
|
appId: 'app_67890'
|
|
196
196
|
});
|
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()}(this,()=>(()=>{"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 c(){}function a(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")},c.prototype=i.prototype;var s=a.prototype=new c;s.constructor=a,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,c(o.key),o)}}function c(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:()=>re,AgentWidget:()=>ie,AudioPlayer:()=>Y,AudioRecorder:()=>N,EventEmitter:()=>a,VERSION:()=>ce,VanillaVoiceButton:()=>qt,VoiceButton:()=>Kt,VoiceSDK:()=>pt,WebSocketManager:()=>Ct,WebSocketManagerV2:()=>D,default:()=>ae});var a=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,c,a=[],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)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(t,e)||f(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=f(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,c=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function f(t,e){if(t){if("string"==typeof t)return p(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)?p(t,e):void 0}}function p(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 d(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return y(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(y(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,y(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,y(f,"constructor",u),y(u,"constructor",s),s.displayName="GeneratorFunction",y(u,r,"GeneratorFunction"),y(f),y(f,r,"Generator"),y(f,o,function(){return this}),y(f,"toString",function(){return"[object Generator]"}),(d=function(){return{w:i,m:p}})()}function y(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}y=function(t,e,n,o){function i(e,n){y(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))},y(t,e,n,o)}function h(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,b(o.key),o)}}function b(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 v(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(v=function(){return!!t})()}function m(t){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},m(t)}function S(t,e){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},S(t,e)}const w=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=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,v()?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&&S(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=d().m(function t(e){var n,o,r=this;return d().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),console.log("🔌 WebSocketSingleton: Reusing existing connection for ".concat(e," (").concat(this.connectionCounts.get(e)," subscribers)")),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return console.log("🔌 WebSocketSingleton: Connection already being created for ".concat(e,", waiting...")),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),console.log("🔌 WebSocketSingleton: Got existing connection after wait for ".concat(e," (").concat(r.connectionCounts.get(e)," subscribers)")),t(o)}else setTimeout(n,50)};n()}));case 2:return console.log("🔌 WebSocketSingleton: Creating new connection for ".concat(e)),this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){console.log("🔌 WebSocketSingleton: Connection opened for ".concat(e)),r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){console.log("🔌 WebSocketSingleton: Connection closed for ".concat(e," (Code: ").concat(t.code,")")),r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){console.log("🔌 WebSocketSingleton: Connection error for ".concat(e),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 c(t){h(i,n,o,c,a,"next",t)}function a(t){h(i,n,o,c,a,"throw",t)}c(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),console.log("🔌 WebSocketSingleton: Released connection for ".concat(t," (").concat(n," subscribers remaining)")),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&(console.log("🔌 WebSocketSingleton: Closing connection for ".concat(t," (no more subscribers)")),o.close(1e3,"No more subscribers")),this.connections.delete(t),this.connectionCounts.delete(t)}}else console.log("🔌 WebSocketSingleton: Attempted to release non-existent connection for ".concat(t))}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&(console.log("🔌 WebSocketSingleton: Force closing connection for ".concat(t)),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(){console.log("🔌 WebSocketSingleton: Clearing all connections");var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a));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 O(){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 a?o:a,u=Object.create(s.prototype);return j(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(j(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,j(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,j(f,"constructor",u),j(u,"constructor",s),s.displayName="GeneratorFunction",j(u,r,"GeneratorFunction"),j(f),j(f,r,"Generator"),j(f,o,function(){return this}),j(f,"toString",function(){return"[object Generator]"}),(O=function(){return{w:i,m:p}})()}function j(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}j=function(t,e,n,o){function i(e,n){j(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))},j(t,e,n,o)}function P(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function C(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,x(o.key),o)}}function x(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 E(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(E=function(){return!!t})()}function T(t){return T=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},T(t)}function _(t,e){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},_(t,e)}var D=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=T(e),function(t,e){if(e&&("object"==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,E()?Reflect.construct(e,n||[],T(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=O().m(function t(){var e=this;return O().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),console.log("🔌 WebSocketManagerV2: Requesting connection ".concat(e.connectionId," for ").concat(e.config.websocketUrl)),w.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,console.log("🔌 WebSocketManagerV2: Got connection ".concat(e.connectionId)),e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t())}).catch(function(t){console.error("🔌 WebSocketManagerV2: Connection failed ".concat(e.connectionId),t),n(t)})}catch(t){console.error("🔌 WebSocketManagerV2: Connection error ".concat(e.connectionId),t),n(t)}}))},t)}),c=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function c(t){P(r,n,o,c,a,"next",t)}function a(t){P(r,n,o,c,a,"throw",t)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection opened ".concat(t.connectionId)),t.isConnected=!0,t.emit("connected"))},n=function(e,n){n===t.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection closed ".concat(t.connectionId," (Code: ").concat(e.code,")")),t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection error ".concat(t.connectionId),e),t.emit("error",e))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};w.on("open",e),w.on("close",n),w.on("error",o),w.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){console.log("🔌 WebSocketManagerV2: Disconnecting ".concat(this.connectionId)),this.eventHandlers&&(w.off("open",this.eventHandlers.open),w.off("close",this.eventHandlers.close),w.off("error",this.eventHandlers.error),w.off("message",this.eventHandlers.message)),this.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Releasing connection ".concat(this.connectionId," from singleton")),w.releaseConnection(this.config.websocketUrl)),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(JSON.stringify(t))}},{key:"sendBinary",value:function(t){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(t)}},{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("🔌 WebSocketManagerV2: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return w.getAllConnections()}},{key:"clearAllConnections",value:function(){w.clearAll()}}],o&&C(n.prototype,o),r&&C(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a);function I(t){return I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},I(t)}function R(){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 a?o:a,u=Object.create(s.prototype);return A(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(A(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,A(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,A(f,"constructor",u),A(u,"constructor",s),s.displayName="GeneratorFunction",A(u,r,"GeneratorFunction"),A(f),A(f,r,"Generator"),A(f,o,function(){return this}),A(f,"toString",function(){return"[object Generator]"}),(R=function(){return{w:i,m:p}})()}function A(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}A=function(t,e,n,o){function i(e,n){A(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))},A(t,e,n,o)}function M(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function W(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){M(i,o,r,c,a,"next",t)}function a(t){M(i,o,r,c,a,"throw",t)}c(void 0)})}}function B(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,K(o.key),o)}}function K(t){var e=function(t){if("object"!=I(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=I(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==I(e)?e:e+""}function G(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(G=function(){return!!t})()}function U(t){return U=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},U(t)}function V(t,e){return V=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},V(t,e)}var N=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"==I(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,G()?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&&V(t,e)}(e,t),n=e,o=[{key:"start",value:(i=W(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=W(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&&B(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a);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 L(){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 a?o:a,u=Object.create(s.prototype);return H(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(H(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,H(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,H(f,"constructor",u),H(u,"constructor",s),s.displayName="GeneratorFunction",H(u,r,"GeneratorFunction"),H(f),H(f,r,"Generator"),H(f,o,function(){return this}),H(f,"toString",function(){return"[object Generator]"}),(L=function(){return{w:i,m:p}})()}function H(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}H=function(t,e,n,o){function i(e,n){H(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},H(t,e,n,o)}function Q(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function z(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,q(o.key),o)}}function q(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 J(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(J=function(){return!!t})()}function $(t){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},$(t)}function X(t,e){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},X(t,e)}var Y=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=$(e),function(t,e){if(e&&("object"==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,J()?Reflect.construct(e,n||[],$(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&X(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||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=L().m(function t(){var e,n,o,r,i,c,a=this;return L().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&!this.isPlaying&&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,this.isPlaying=!0,this.emit("playbackStarted"),this.audioContext||(this.audioContext=new(window.AudioContext||window.webkitAudioContext)),"suspended"!==(n=this.audioContext).state){t.n=3;break}return t.n=3,n.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return o=t.v,t.n=5,n.decodeAudioData(o);case 5:r=t.v,(i=n.createBufferSource()).buffer=r,i.connect(n.destination),this.currentSource=i,i.onended=function(){a.isPlaying=!1,a.isProcessingQueue=!1,a.currentSource=null,a.emit("playbackStopped"),a.audioQueue.length>0&&setTimeout(function(){return a.processQueue()},100)},i.start(),t.n=7;break;case 6:t.p=6,c=t.v,this.isPlaying=!1,this.isProcessingQueue=!1,this.currentSource=null,this.emit("playbackError",c),this.audioQueue.length>0&&setTimeout(function(){return a.processQueue()},100);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 c(t){Q(i,n,o,c,a,"next",t)}function a(t){Q(i,n,o,c,a,"throw",t)}c(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],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&&z(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a);function Z(t){return Z="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},Z(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 a?o:a,u=Object.create(s.prototype);return et(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(et(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,et(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,et(f,"constructor",u),et(u,"constructor",s),s.displayName="GeneratorFunction",et(u,r,"GeneratorFunction"),et(f),et(f,r,"Generator"),et(f,o,function(){return this}),et(f,"toString",function(){return"[object Generator]"}),(tt=function(){return{w:i,m:p}})()}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,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.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 c(t){nt(i,o,r,c,a,"next",t)}function a(t){nt(i,o,r,c,a,"throw",t)}c(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){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=st(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function at(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"!=Z(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Z(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 ft(t,e){return ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ft(t,e)}var pt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=lt(e),function(t,e){if(e&&("object"==Z(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.bidme.co.il/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 D(it(it({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new N(t.config),t.audioPlayer=new Y(t.config),t.setupEventHandlers(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ft(t,e)}(e,t),n=e,o=[{key:"setupEventHandlers",value:function(){var t=this;this.webSocketManager.on("connected",function(){t.isConnected=!0,t.sendHelloMessage(),t.emit("connected")}),this.webSocketManager.on("disconnected",function(){t.isConnected=!1,t.emit("disconnected")}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){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.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")}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped")}),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 t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),console.log("VoiceSDK: Using WebSocket URL:",e),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,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),console.log("VoiceSDK: Adding agentId to URL:",this.config.agentId)),this.config.appId&&(e.append("appId",this.config.appId),console.log("VoiceSDK: Adding appId to URL:",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?console.log("🎙️ VoiceSDK: Disconnect called but already destroyed"):(console.log("🎙️ VoiceSDK: Disconnecting from voice server"),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:(a=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,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"stopRecording",value:(c=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 c.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,console.log("VoiceSDK: Sending hello message with appId (app-based authentication)")):this.config.ttpId?(t.ttpId=this.config.ttpId,console.log("VoiceSDK: Sending hello message with custom TTP ID (fallback method)")):(t.ttpId=this.generateTtpId(),console.log("VoiceSDK: Sending hello message with generated TTP ID (last resort)")),this.config.appId?console.log("VoiceSDK: Using app ID for authentication:",this.config.appId):this.config.ttpId?console.log("VoiceSDK: Using custom TTP ID:",this.config.ttpId):console.log("VoiceSDK: Using generated TTP ID:",t.ttpId);try{this.webSocketManager.sendMessage(t),console.log("VoiceSDK: Hello message sent:",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?console.log("🎙️ VoiceSDK: Destroy called but already destroyed"):(console.log("🎙️ VoiceSDK: Destroying VoiceSDK instance"),this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners(),console.log("🎙️ VoiceSDK: VoiceSDK instance destroyed"))}}],o&&at(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c,a,s,u}(a);function dt(t){return dt="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},dt(t)}function yt(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,ht(o.key),o)}}function ht(t){var e=function(t){if("object"!=dt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=dt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==dt(e)?e:e+""}const gt=new(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.connections=new Map},(e=[{key:"registerConnection",value:function(t,e){if(!this.connections.has(t))return this.connections.set(t,{connectionId:e,timestamp:Date.now(),count:1}),console.log("🔌 ConnectionManager: Registered connection ".concat(e," for ").concat(t)),!0;var n=this.connections.get(t),o=Date.now()-n.timestamp;return o>3e4?(this.connections.set(t,{connectionId:e,timestamp:Date.now(),count:1}),console.log("🔌 ConnectionManager: Allowed new connection ".concat(e," for ").concat(t," (old connection was ").concat(o,"ms ago)")),!0):(n.count++,console.log("🔌 ConnectionManager: Blocked connection ".concat(e," for ").concat(t," (").concat(n.count," attempts in ").concat(o,"ms)")),!1)}},{key:"unregisterConnection",value:function(t,e){var n=this.connections.get(t);n&&n.connectionId===e&&(this.connections.delete(t),console.log("🔌 ConnectionManager: Unregistered connection ".concat(e," for ").concat(t)))}},{key:"isConnectionAllowed",value:function(t){var e=this.connections.get(t);return!e||Date.now()-e.timestamp>3e4}},{key:"getConnectionInfo",value:function(t){return this.connections.get(t)}},{key:"clearAll",value:function(){this.connections.clear(),console.log("🔌 ConnectionManager: Cleared all connections")}}])&&yt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}());function bt(t){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},bt(t)}function vt(){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 a?o:a,u=Object.create(s.prototype);return mt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(mt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,mt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,mt(f,"constructor",u),mt(u,"constructor",s),s.displayName="GeneratorFunction",mt(u,r,"GeneratorFunction"),mt(f),mt(f,r,"Generator"),mt(f,o,function(){return this}),mt(f,"toString",function(){return"[object Generator]"}),(vt=function(){return{w:i,m:p}})()}function mt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}mt=function(t,e,n,o){function i(e,n){mt(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))},mt(t,e,n,o)}function St(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}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"!=bt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==bt(e)?e:e+""}function Ot(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Ot=function(){return!!t})()}function jt(t){return jt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},jt(t)}function Pt(t,e){return Pt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Pt(t,e)}var Ct=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=jt(e),function(t,e){if(e&&("object"==bt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Ot()?Reflect.construct(e,n||[],jt(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.reconnectAttempts=0,n.maxReconnectAttempts=!1!==t.autoReconnect?3:0,n.isReconnecting=!1,n.isConnecting=!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&&Pt(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=vt().m(function t(){var e=this;return vt().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{if(e.ws&&(e.ws.readyState===WebSocket.CONNECTING||e.ws.readyState===WebSocket.OPEN))return void t();if(e.isReconnecting)return void t();if(e.isConnecting)return void t();if(!gt.isConnectionAllowed(e.config.websocketUrl))return console.log("🔌 WebSocketManager: Connection blocked by global manager for ".concat(e.config.websocketUrl)),void t();if(e.isConnecting=!0,e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),!gt.registerConnection(e.config.websocketUrl,e.connectionId))return console.log("🔌 WebSocketManager: Connection registration failed for ".concat(e.connectionId)),e.isConnecting=!1,void t();console.log("🔌 WebSocketManager: Starting connection attempt ".concat(e.connectionId)),e.ws=new WebSocket(e.config.websocketUrl),e.ws.onopen=function(){console.log("🔌 WebSocketManager: Connection successful ".concat(e.connectionId)),e.isConnected=!0,e.reconnectAttempts=0,e.isReconnecting=!1,e.isConnecting=!1,e.emit("connected"),t()},e.ws.onmessage=function(t){e.handleMessage(t)},e.ws.onclose=function(t){console.log("🔌 WebSocketManager: Connection closed ".concat(e.connectionId," (Code: ").concat(t.code,")")),e.isConnected=!1,e.isConnecting=!1,e.emit("disconnected",t),1e3!==t.code&&e.reconnectAttempts<e.maxReconnectAttempts&&!e.isReconnecting&&(e.isReconnecting=!0,e.reconnectAttempts++,console.log("🔌 WebSocketManager: Attempting reconnection ".concat(e.reconnectAttempts,"/").concat(e.maxReconnectAttempts)),setTimeout(function(){e.isReconnecting=!1,e.connect().catch(function(){})},1e3*e.reconnectAttempts))},e.ws.onerror=function(t){console.log("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),e.isConnecting=!1,e.emit("error",t),n(t)}}catch(t){console.log("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),e.isConnecting=!1,n(t)}}))},t)}),c=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function c(t){St(r,n,o,c,a,"next",t)}function a(t){St(r,n,o,c,a,"throw",t)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"disconnect",value:function(){this.isReconnecting=!1,this.reconnectAttempts=this.maxReconnectAttempts,this.connectionId&>.unregisterConnection(this.config.websocketUrl,this.connectionId),this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.close(1e3,"Intentional disconnect"),this.ws=null,this.isConnected=!1,this.isConnecting=!1}},{key:"resetReconnectionAttempts",value:function(){this.reconnectAttempts=0,this.isReconnecting=!1}},{key:"sendMessage",value:function(t){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(JSON.stringify(t))}},{key:"sendBinary",value:function(t){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(t)}},{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){e.emit("error",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:WebSocket.CLOSED}}}],r=[{key:"clearAllConnections",value:function(){gt.clearAll()}}],o&&wt(n.prototype,o),r&&wt(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a),xt=n(540),Et=n(848);function Tt(t){return Tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Tt(t)}function _t(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 Dt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?_t(Object(n),!0).forEach(function(e){It(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):_t(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function It(t,e,n){return(e=function(t){var e=function(t){if("object"!=Tt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Tt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Rt(){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 a?o:a,u=Object.create(s.prototype);return At(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(At(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,At(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,At(f,"constructor",u),At(u,"constructor",s),s.displayName="GeneratorFunction",At(u,r,"GeneratorFunction"),At(f),At(f,r,"Generator"),At(f,o,function(){return this}),At(f,"toString",function(){return"[object Generator]"}),(Rt=function(){return{w:i,m:p}})()}function At(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}At=function(t,e,n,o){function i(e,n){At(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))},At(t,e,n,o)}function Mt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Wt(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,c,a=[],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)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Bt(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)?Bt(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 Bt(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 Kt=function(t){var e=t.websocketUrl,n=t.agentId,o=t.voice,r=void 0===o?"default":o,i=t.language,c=void 0===i?"en":i,a=t.autoReconnect,s=void 0===a||a,u=t.onConnected,l=t.onDisconnected,f=t.onRecordingStarted,p=t.onRecordingStopped,d=t.onPlaybackStarted,y=t.onPlaybackStopped,h=t.onError,g=t.onMessage,b=t.onBargeIn,v=t.onStopPlaying,m=t.className,S=void 0===m?"":m,w=t.style,k=void 0===w?{}:w,O=t.children,j=Wt((0,xt.useState)(!1),2),P=j[0],C=j[1],x=Wt((0,xt.useState)(!1),2),E=x[0],T=x[1],_=Wt((0,xt.useState)(!1),2),D=(_[0],_[1]),I=Wt((0,xt.useState)("Disconnected"),2),R=(I[0],I[1]),A=(0,xt.useRef)(null);(0,xt.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),A.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),A.current.destroy(),A.current=null);var t=new pt({websocketUrl:e,agentId:n,voice:r,language:c,autoReconnect:s});return t.on("connected",function(){C(!0),R("Connected"),null==u||u()}),t.on("disconnected",function(){C(!1),R("Disconnected"),null==l||l()}),t.on("recordingStarted",function(){T(!0),null==f||f()}),t.on("recordingStopped",function(){T(!1),null==p||p()}),t.on("playbackStarted",function(){D(!0),null==d||d()}),t.on("playbackStopped",function(){D(!1),null==y||y()}),t.on("error",function(t){null==h||h(t)}),t.on("message",function(t){null==g||g(t)}),t.on("bargeIn",function(t){null==b||b(t)}),t.on("stopPlaying",function(t){null==v||v(t)}),A.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),A.current&&(A.current.destroy(),A.current=null)}},[e,n,r,c]);var M=function(){var t,e=(t=Rt().m(function t(){var e;return Rt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(A.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,A.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Mt(i,o,r,c,a,"next",t)}function a(t){Mt(i,o,r,c,a,"throw",t)}c(void 0)})});return function(){return e.apply(this,arguments)}}(),W=(0,Et.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,Et.jsx)("div",{style:{fontSize:"20px"},children:E?"🔴":"🎤"}),(0,Et.jsx)("div",{children:E?"Stop Listening":"Start Listening"})]});return(0,Et.jsx)("button",{className:"voice-button ".concat(E?"recording":""," ").concat(S),style:Dt({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:E?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},k),onClick:M,disabled:!P,children:O||W})};function Gt(t){return Gt="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},Gt(t)}function Ut(){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 a?o:a,u=Object.create(s.prototype);return Vt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Vt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Vt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,Vt(f,"constructor",u),Vt(u,"constructor",s),s.displayName="GeneratorFunction",Vt(u,r,"GeneratorFunction"),Vt(f),Vt(f,r,"Generator"),Vt(f,o,function(){return this}),Vt(f,"toString",function(){return"[object Generator]"}),(Ut=function(){return{w:i,m:p}})()}function Vt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Vt=function(t,e,n,o){function i(e,n){Vt(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))},Vt(t,e,n,o)}function Nt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Ft(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Nt(i,o,r,c,a,"next",t)}function a(t){Nt(i,o,r,c,a,"throw",t)}c(void 0)})}}function Lt(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 Ht(t,e,n){return(e=zt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Qt(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,zt(o.key),o)}}function zt(t){var e=function(t){if("object"!=Gt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Gt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Gt(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?Lt(Object(n),!0).forEach(function(e){Ht(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Lt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({websocketUrl:e.websocketUrl||"wss://speech.bidme.co.il/ws/conv",agentId:e.agentId,voice:e.voice||"default",language:e.language||"en",container:e.container||document.body,buttonText:e.buttonText||"Start Listening",buttonClass:e.buttonClass||"voice-button"},e),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new pt({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},e=[{key:"setupEventListeners",value:function(){var t=this;this.voiceSDK.on("connected",function(){var e,n;t.isConnected=!0,t.updateButton(),null===(e=(n=t.options).onConnected)||void 0===e||e.call(n)}),this.voiceSDK.on("disconnected",function(){var e,n;t.isConnected=!1,t.updateButton(),null===(e=(n=t.options).onDisconnected)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStarted",function(){var e,n;t.isRecording=!0,t.updateButton(),null===(e=(n=t.options).onRecordingStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStopped",function(){var e,n;t.isRecording=!1,t.updateButton(),null===(e=(n=t.options).onRecordingStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStarted",function(){var e,n;t.isPlaying=!0,null===(e=(n=t.options).onPlaybackStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStopped",function(){var e,n;t.isPlaying=!1,null===(e=(n=t.options).onPlaybackStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("error",function(e){var n,o;null===(n=(o=t.options).onError)||void 0===n||n.call(o,e)}),this.voiceSDK.on("message",function(e){var n,o;null===(n=(o=t.options).onMessage)||void 0===n||n.call(o,e)}),this.voiceSDK.on("bargeIn",function(e){var n,o;null===(n=(o=t.options).onBargeIn)||void 0===n||n.call(o,e)}),this.voiceSDK.on("stopPlaying",function(e){var n,o;null===(n=(o=t.options).onStopPlaying)||void 0===n||n.call(o,e)})}},{key:"createButton",value:function(){var t=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return t.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var t=this.isRecording?"🔴":"🎤",e=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(t,"</span>\n <span>").concat(e,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=Ft(Ut().m(function t(){var e;return Ut().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=Ft(Ut().m(function t(){var e;return Ut().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&&Qt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Jt(t){return Jt="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},Jt(t)}function $t(){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 a?o:a,u=Object.create(s.prototype);return Xt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Xt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Xt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,Xt(f,"constructor",u),Xt(u,"constructor",s),s.displayName="GeneratorFunction",Xt(u,r,"GeneratorFunction"),Xt(f),Xt(f,r,"Generator"),Xt(f,o,function(){return this}),Xt(f,"toString",function(){return"[object Generator]"}),($t=function(){return{w:i,m:p}})()}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 Yt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Zt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Yt(i,o,r,c,a,"next",t)}function a(t){Yt(i,o,r,c,a,"throw",t)}c(void 0)})}}function te(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function ee(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,oe(o.key),o)}}function ne(t,e,n){return e&&ee(t.prototype,e),n&&ee(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function oe(t){var e=function(t){if("object"!=Jt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Jt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Jt(e)?e:e+""}var re=function(){return ne(function t(e){te(this,t),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=Zt($t().m(function t(e){var n,o=this;return $t().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=new pt({websocketUrl:e,autoReconnect:!1}),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=Zt($t().m(function t(){return $t().w(function(t){for(;;)switch(t.n){case 0:if(!this.voiceSDK){t.n=1;break}return t.n=1,this.voiceSDK.startRecording();case 1:return t.a(2)}},t,this)})),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}(),ie=function(){return ne(function t(e){te(this,t),this.config=e,this.sdk=new re,this.isOpen=!1,this.isActive=!1,this.position=e.position||"bottom-right",this.primaryColor=e.primaryColor||"#4F46E5",this.setupEventHandlers(),this.createWidget()},[{key:"setupEventHandlers",value:function(){var t=this;this.sdk.onConnected=function(){t.updateStatus("connected")},this.sdk.onDisconnected=function(){t.updateStatus("disconnected"),t.isActive=!1},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=this,e=document.createElement("div");e.id="agent-widget",e.innerHTML="\n <style>\n #agent-widget {\n position: fixed;\n ".concat(this.position.includes("bottom")?"bottom: 20px;":"top: 20px;","\n ").concat(this.position.includes("right")?"right: 20px;":"left: 20px;",'\n z-index: 9999;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n }\n \n #agent-button {\n width: 60px;\n height: 60px;\n border-radius: 50%;\n background: ').concat(this.primaryColor,";\n border: none;\n cursor: pointer;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n display: flex;\n align-items: center;\n justify-content: center;\n transition: transform 0.2s;\n }\n \n #agent-button:hover {\n transform: scale(1.1);\n }\n \n #agent-button svg {\n width: 28px;\n height: 28px;\n fill: white;\n }\n \n #agent-panel {\n display: none;\n position: absolute;\n bottom: 80px;\n ").concat(this.position.includes("right")?"right: 0;":"left: 0;","\n width: 350px;\n height: 500px;\n background: white;\n border-radius: 12px;\n box-shadow: 0 8px 32px rgba(0,0,0,0.2);\n flex-direction: column;\n overflow: hidden;\n }\n \n #agent-panel.open {\n display: flex;\n }\n \n #agent-header {\n background: ").concat(this.primaryColor,";\n color: white;\n padding: 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n \n #agent-close {\n background: none;\n border: none;\n color: white;\n cursor: pointer;\n font-size: 24px;\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: 8px;\n max-width: 80%;\n }\n \n .message.user {\n background: #E5E7EB;\n align-self: flex-end;\n }\n \n .message.agent {\n background: #F3F4F6;\n align-self: flex-start;\n }\n \n #agent-controls {\n padding: 16px;\n border-top: 1px solid #E5E7EB;\n display: flex;\n justify-content: center;\n }\n \n #agent-mic-button {\n width: 60px;\n height: 60px;\n border-radius: 50%;\n border: none;\n background: ").concat(this.primaryColor,';\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n }\n \n #agent-mic-button.active {\n background: #EF4444;\n animation: pulse 1.5s infinite;\n }\n \n #agent-mic-button svg {\n width: 28px;\n height: 28px;\n fill: white;\n }\n \n @keyframes pulse {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.05); }\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n \n .error-message {\n background: #FEE2E2;\n color: #991B1B;\n padding: 12px;\n border-radius: 8px;\n margin: 8px;\n }\n </style>\n \n <button id="agent-button">\n <svg viewBox="0 0 24 24">\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>\n </button>\n \n <div id="agent-panel">\n <div id="agent-header">\n <h3 style="margin: 0;">Voice Assistant</h3>\n <button id="agent-close">×</button>\n </div>\n \n <div id="agent-messages"></div>\n \n <div id="agent-controls">\n <button id="agent-mic-button">\n <svg viewBox="0 0 24 24">\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>\n </button>\n </div>\n </div>\n '),document.body.appendChild(e),document.getElementById("agent-button").onclick=function(){return t.togglePanel()},document.getElementById("agent-close").onclick=function(){return t.togglePanel()},document.getElementById("agent-mic-button").onclick=function(){return t.toggleVoice()}}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(e=Zt($t().m(function t(){var e,n;return $t().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isActive){t.n=7;break}return t.p=1,t.n=2,this.getSignedUrl();case 2:return e=t.v,t.n=3,this.sdk.connect(e);case 3:return t.n=4,this.sdk.startListening();case 4:this.isActive=!0,document.getElementById("agent-mic-button").classList.add("active"),this.addMessage("system","Listening..."),t.n=6;break;case 5:t.p=5,n=t.v,console.error("Failed to start:",n),this.showError(n.message);case 6:t.n=8;break;case 7:this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,document.getElementById("agent-mic-button").classList.remove("active");case 8:return t.a(2)}},t,this,[[1,5]])})),function(){return e.apply(this,arguments)})},{key:"getSignedUrl",value:(t=Zt($t().m(function t(){var e,n,o;return $t().w(function(t){for(;;)switch(t.n){case 0:if("string"!=typeof this.config.getSessionUrl){t.n=4;break}return t.n=1,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:this.config.agentId,variables:this.config.variables||{}})});case 1:if((e=t.v).ok){t.n=2;break}throw new Error("Failed to get session URL: ".concat(e.statusText));case 2:return t.n=3,e.json();case 3:return n=t.v,t.a(2,n.signedUrl||n.wsUrl||n.url);case 4:if("function"!=typeof this.config.getSessionUrl){t.n=6;break}return t.n=5,this.config.getSessionUrl({agentId:this.config.agentId,variables:this.config.variables||{}});case 5:return o=t.v,t.a(2,"string"==typeof o?o:o.signedUrl||o.wsUrl||o.url);case 6:throw new Error("getSessionUrl is required (URL string or function)");case 7: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){console.log("Widget status:",t)}}]);var t,e}(),ce="2.0.0";const ae={VoiceSDK:pt,WebSocketManager:Ct,WebSocketManagerV2:D,AudioRecorder:N,AudioPlayer:Y,EventEmitter:a,VoiceButton:Kt,VanillaVoiceButton:qt,AgentSDK:re,AgentWidget:ie,VERSION:ce};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()}(this,()=>(()=>{"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 c(){}function a(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")},c.prototype=i.prototype;var s=a.prototype=new c;s.constructor=a,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,c(o.key),o)}}function c(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:()=>re,AgentWidget:()=>ie,AudioPlayer:()=>Y,AudioRecorder:()=>N,EventEmitter:()=>a,VERSION:()=>ce,VanillaVoiceButton:()=>qt,VoiceButton:()=>Kt,VoiceSDK:()=>pt,WebSocketManager:()=>Ct,WebSocketManagerV2:()=>D,default:()=>ae});var a=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,c,a=[],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)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(t,e)||f(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=f(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,c=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function f(t,e){if(t){if("string"==typeof t)return p(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)?p(t,e):void 0}}function p(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 d(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return y(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(y(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,y(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,y(f,"constructor",u),y(u,"constructor",s),s.displayName="GeneratorFunction",y(u,r,"GeneratorFunction"),y(f),y(f,r,"Generator"),y(f,o,function(){return this}),y(f,"toString",function(){return"[object Generator]"}),(d=function(){return{w:i,m:p}})()}function y(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}y=function(t,e,n,o){function i(e,n){y(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))},y(t,e,n,o)}function h(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,b(o.key),o)}}function b(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 v(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(v=function(){return!!t})()}function m(t){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},m(t)}function S(t,e){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},S(t,e)}const w=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=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,v()?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&&S(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=d().m(function t(e){var n,o,r=this;return d().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),console.log("🔌 WebSocketSingleton: Reusing existing connection for ".concat(e," (").concat(this.connectionCounts.get(e)," subscribers)")),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return console.log("🔌 WebSocketSingleton: Connection already being created for ".concat(e,", waiting...")),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),console.log("🔌 WebSocketSingleton: Got existing connection after wait for ".concat(e," (").concat(r.connectionCounts.get(e)," subscribers)")),t(o)}else setTimeout(n,50)};n()}));case 2:return console.log("🔌 WebSocketSingleton: Creating new connection for ".concat(e)),this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){console.log("🔌 WebSocketSingleton: Connection opened for ".concat(e)),r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){console.log("🔌 WebSocketSingleton: Connection closed for ".concat(e," (Code: ").concat(t.code,")")),r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){console.log("🔌 WebSocketSingleton: Connection error for ".concat(e),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 c(t){h(i,n,o,c,a,"next",t)}function a(t){h(i,n,o,c,a,"throw",t)}c(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),console.log("🔌 WebSocketSingleton: Released connection for ".concat(t," (").concat(n," subscribers remaining)")),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&(console.log("🔌 WebSocketSingleton: Closing connection for ".concat(t," (no more subscribers)")),o.close(1e3,"No more subscribers")),this.connections.delete(t),this.connectionCounts.delete(t)}}else console.log("🔌 WebSocketSingleton: Attempted to release non-existent connection for ".concat(t))}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&(console.log("🔌 WebSocketSingleton: Force closing connection for ".concat(t)),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(){console.log("🔌 WebSocketSingleton: Clearing all connections");var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a));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 O(){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 a?o:a,u=Object.create(s.prototype);return j(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(j(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,j(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,j(f,"constructor",u),j(u,"constructor",s),s.displayName="GeneratorFunction",j(u,r,"GeneratorFunction"),j(f),j(f,r,"Generator"),j(f,o,function(){return this}),j(f,"toString",function(){return"[object Generator]"}),(O=function(){return{w:i,m:p}})()}function j(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}j=function(t,e,n,o){function i(e,n){j(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))},j(t,e,n,o)}function P(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function C(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,x(o.key),o)}}function x(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 E(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(E=function(){return!!t})()}function T(t){return T=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},T(t)}function _(t,e){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},_(t,e)}var D=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=T(e),function(t,e){if(e&&("object"==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,E()?Reflect.construct(e,n||[],T(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=O().m(function t(){var e=this;return O().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),console.log("🔌 WebSocketManagerV2: Requesting connection ".concat(e.connectionId," for ").concat(e.config.websocketUrl)),w.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,console.log("🔌 WebSocketManagerV2: Got connection ".concat(e.connectionId)),e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t())}).catch(function(t){console.error("🔌 WebSocketManagerV2: Connection failed ".concat(e.connectionId),t),n(t)})}catch(t){console.error("🔌 WebSocketManagerV2: Connection error ".concat(e.connectionId),t),n(t)}}))},t)}),c=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function c(t){P(r,n,o,c,a,"next",t)}function a(t){P(r,n,o,c,a,"throw",t)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection opened ".concat(t.connectionId)),t.isConnected=!0,t.emit("connected"))},n=function(e,n){n===t.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection closed ".concat(t.connectionId," (Code: ").concat(e.code,")")),t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection error ".concat(t.connectionId),e),t.emit("error",e))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};w.on("open",e),w.on("close",n),w.on("error",o),w.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){console.log("🔌 WebSocketManagerV2: Disconnecting ".concat(this.connectionId)),this.eventHandlers&&(w.off("open",this.eventHandlers.open),w.off("close",this.eventHandlers.close),w.off("error",this.eventHandlers.error),w.off("message",this.eventHandlers.message)),this.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Releasing connection ".concat(this.connectionId," from singleton")),w.releaseConnection(this.config.websocketUrl)),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(JSON.stringify(t))}},{key:"sendBinary",value:function(t){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(t)}},{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("🔌 WebSocketManagerV2: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return w.getAllConnections()}},{key:"clearAllConnections",value:function(){w.clearAll()}}],o&&C(n.prototype,o),r&&C(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a);function I(t){return I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},I(t)}function R(){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 a?o:a,u=Object.create(s.prototype);return A(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(A(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,A(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,A(f,"constructor",u),A(u,"constructor",s),s.displayName="GeneratorFunction",A(u,r,"GeneratorFunction"),A(f),A(f,r,"Generator"),A(f,o,function(){return this}),A(f,"toString",function(){return"[object Generator]"}),(R=function(){return{w:i,m:p}})()}function A(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}A=function(t,e,n,o){function i(e,n){A(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))},A(t,e,n,o)}function M(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function W(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){M(i,o,r,c,a,"next",t)}function a(t){M(i,o,r,c,a,"throw",t)}c(void 0)})}}function B(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,K(o.key),o)}}function K(t){var e=function(t){if("object"!=I(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=I(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==I(e)?e:e+""}function G(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(G=function(){return!!t})()}function U(t){return U=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},U(t)}function V(t,e){return V=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},V(t,e)}var N=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"==I(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,G()?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&&V(t,e)}(e,t),n=e,o=[{key:"start",value:(i=W(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=W(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&&B(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a);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 L(){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 a?o:a,u=Object.create(s.prototype);return H(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(H(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,H(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,H(f,"constructor",u),H(u,"constructor",s),s.displayName="GeneratorFunction",H(u,r,"GeneratorFunction"),H(f),H(f,r,"Generator"),H(f,o,function(){return this}),H(f,"toString",function(){return"[object Generator]"}),(L=function(){return{w:i,m:p}})()}function H(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}H=function(t,e,n,o){function i(e,n){H(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},H(t,e,n,o)}function Q(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function z(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,q(o.key),o)}}function q(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 J(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(J=function(){return!!t})()}function $(t){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},$(t)}function X(t,e){return X=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},X(t,e)}var Y=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=$(e),function(t,e){if(e&&("object"==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,J()?Reflect.construct(e,n||[],$(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&X(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||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=L().m(function t(){var e,n,o,r,i,c,a=this;return L().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&!this.isPlaying&&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,this.isPlaying=!0,this.emit("playbackStarted"),this.audioContext||(this.audioContext=new(window.AudioContext||window.webkitAudioContext)),"suspended"!==(n=this.audioContext).state){t.n=3;break}return t.n=3,n.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return o=t.v,t.n=5,n.decodeAudioData(o);case 5:r=t.v,(i=n.createBufferSource()).buffer=r,i.connect(n.destination),this.currentSource=i,i.onended=function(){a.isPlaying=!1,a.isProcessingQueue=!1,a.currentSource=null,a.emit("playbackStopped"),a.audioQueue.length>0&&setTimeout(function(){return a.processQueue()},100)},i.start(),t.n=7;break;case 6:t.p=6,c=t.v,this.isPlaying=!1,this.isProcessingQueue=!1,this.currentSource=null,this.emit("playbackError",c),this.audioQueue.length>0&&setTimeout(function(){return a.processQueue()},100);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 c(t){Q(i,n,o,c,a,"next",t)}function a(t){Q(i,n,o,c,a,"throw",t)}c(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],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&&z(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a);function Z(t){return Z="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},Z(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 a?o:a,u=Object.create(s.prototype);return et(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(et(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,et(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,et(f,"constructor",u),et(u,"constructor",s),s.displayName="GeneratorFunction",et(u,r,"GeneratorFunction"),et(f),et(f,r,"Generator"),et(f,o,function(){return this}),et(f,"toString",function(){return"[object Generator]"}),(tt=function(){return{w:i,m:p}})()}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,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.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 c(t){nt(i,o,r,c,a,"next",t)}function a(t){nt(i,o,r,c,a,"throw",t)}c(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){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=st(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function at(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"!=Z(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Z(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 ft(t,e){return ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ft(t,e)}var pt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=lt(e),function(t,e){if(e&&("object"==Z(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 D(it(it({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new N(t.config),t.audioPlayer=new Y(t.config),t.setupEventHandlers(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ft(t,e)}(e,t),n=e,o=[{key:"setupEventHandlers",value:function(){var t=this;this.webSocketManager.on("connected",function(){t.isConnected=!0,t.sendHelloMessage(),t.emit("connected")}),this.webSocketManager.on("disconnected",function(){t.isConnected=!1,t.emit("disconnected")}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){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.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")}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped")}),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 t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),console.log("VoiceSDK: Using WebSocket URL:",e),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,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),console.log("VoiceSDK: Adding agentId to URL:",this.config.agentId)),this.config.appId&&(e.append("appId",this.config.appId),console.log("VoiceSDK: Adding appId to URL:",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?console.log("🎙️ VoiceSDK: Disconnect called but already destroyed"):(console.log("🎙️ VoiceSDK: Disconnecting from voice server"),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:(a=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,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"stopRecording",value:(c=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 c.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,console.log("VoiceSDK: Sending hello message with appId (app-based authentication)")):this.config.ttpId?(t.ttpId=this.config.ttpId,console.log("VoiceSDK: Sending hello message with custom TTP ID (fallback method)")):(t.ttpId=this.generateTtpId(),console.log("VoiceSDK: Sending hello message with generated TTP ID (last resort)")),this.config.appId?console.log("VoiceSDK: Using app ID for authentication:",this.config.appId):this.config.ttpId?console.log("VoiceSDK: Using custom TTP ID:",this.config.ttpId):console.log("VoiceSDK: Using generated TTP ID:",t.ttpId);try{this.webSocketManager.sendMessage(t),console.log("VoiceSDK: Hello message sent:",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?console.log("🎙️ VoiceSDK: Destroy called but already destroyed"):(console.log("🎙️ VoiceSDK: Destroying VoiceSDK instance"),this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners(),console.log("🎙️ VoiceSDK: VoiceSDK instance destroyed"))}}],o&&at(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c,a,s,u}(a);function dt(t){return dt="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},dt(t)}function yt(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,ht(o.key),o)}}function ht(t){var e=function(t){if("object"!=dt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=dt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==dt(e)?e:e+""}const gt=new(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.connections=new Map},(e=[{key:"registerConnection",value:function(t,e){if(!this.connections.has(t))return this.connections.set(t,{connectionId:e,timestamp:Date.now(),count:1}),console.log("🔌 ConnectionManager: Registered connection ".concat(e," for ").concat(t)),!0;var n=this.connections.get(t),o=Date.now()-n.timestamp;return o>3e4?(this.connections.set(t,{connectionId:e,timestamp:Date.now(),count:1}),console.log("🔌 ConnectionManager: Allowed new connection ".concat(e," for ").concat(t," (old connection was ").concat(o,"ms ago)")),!0):(n.count++,console.log("🔌 ConnectionManager: Blocked connection ".concat(e," for ").concat(t," (").concat(n.count," attempts in ").concat(o,"ms)")),!1)}},{key:"unregisterConnection",value:function(t,e){var n=this.connections.get(t);n&&n.connectionId===e&&(this.connections.delete(t),console.log("🔌 ConnectionManager: Unregistered connection ".concat(e," for ").concat(t)))}},{key:"isConnectionAllowed",value:function(t){var e=this.connections.get(t);return!e||Date.now()-e.timestamp>3e4}},{key:"getConnectionInfo",value:function(t){return this.connections.get(t)}},{key:"clearAll",value:function(){this.connections.clear(),console.log("🔌 ConnectionManager: Cleared all connections")}}])&&yt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}());function bt(t){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},bt(t)}function vt(){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 a?o:a,u=Object.create(s.prototype);return mt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(mt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,mt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,mt(f,"constructor",u),mt(u,"constructor",s),s.displayName="GeneratorFunction",mt(u,r,"GeneratorFunction"),mt(f),mt(f,r,"Generator"),mt(f,o,function(){return this}),mt(f,"toString",function(){return"[object Generator]"}),(vt=function(){return{w:i,m:p}})()}function mt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}mt=function(t,e,n,o){function i(e,n){mt(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))},mt(t,e,n,o)}function St(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}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"!=bt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==bt(e)?e:e+""}function Ot(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Ot=function(){return!!t})()}function jt(t){return jt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},jt(t)}function Pt(t,e){return Pt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Pt(t,e)}var Ct=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=jt(e),function(t,e){if(e&&("object"==bt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Ot()?Reflect.construct(e,n||[],jt(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.reconnectAttempts=0,n.maxReconnectAttempts=!1!==t.autoReconnect?3:0,n.isReconnecting=!1,n.isConnecting=!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&&Pt(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=vt().m(function t(){var e=this;return vt().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{if(e.ws&&(e.ws.readyState===WebSocket.CONNECTING||e.ws.readyState===WebSocket.OPEN))return void t();if(e.isReconnecting)return void t();if(e.isConnecting)return void t();if(!gt.isConnectionAllowed(e.config.websocketUrl))return console.log("🔌 WebSocketManager: Connection blocked by global manager for ".concat(e.config.websocketUrl)),void t();if(e.isConnecting=!0,e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),!gt.registerConnection(e.config.websocketUrl,e.connectionId))return console.log("🔌 WebSocketManager: Connection registration failed for ".concat(e.connectionId)),e.isConnecting=!1,void t();console.log("🔌 WebSocketManager: Starting connection attempt ".concat(e.connectionId)),e.ws=new WebSocket(e.config.websocketUrl),e.ws.onopen=function(){console.log("🔌 WebSocketManager: Connection successful ".concat(e.connectionId)),e.isConnected=!0,e.reconnectAttempts=0,e.isReconnecting=!1,e.isConnecting=!1,e.emit("connected"),t()},e.ws.onmessage=function(t){e.handleMessage(t)},e.ws.onclose=function(t){console.log("🔌 WebSocketManager: Connection closed ".concat(e.connectionId," (Code: ").concat(t.code,")")),e.isConnected=!1,e.isConnecting=!1,e.emit("disconnected",t),1e3!==t.code&&e.reconnectAttempts<e.maxReconnectAttempts&&!e.isReconnecting&&(e.isReconnecting=!0,e.reconnectAttempts++,console.log("🔌 WebSocketManager: Attempting reconnection ".concat(e.reconnectAttempts,"/").concat(e.maxReconnectAttempts)),setTimeout(function(){e.isReconnecting=!1,e.connect().catch(function(){})},1e3*e.reconnectAttempts))},e.ws.onerror=function(t){console.log("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),e.isConnecting=!1,e.emit("error",t),n(t)}}catch(t){console.log("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),e.isConnecting=!1,n(t)}}))},t)}),c=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function c(t){St(r,n,o,c,a,"next",t)}function a(t){St(r,n,o,c,a,"throw",t)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"disconnect",value:function(){this.isReconnecting=!1,this.reconnectAttempts=this.maxReconnectAttempts,this.connectionId&>.unregisterConnection(this.config.websocketUrl,this.connectionId),this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.close(1e3,"Intentional disconnect"),this.ws=null,this.isConnected=!1,this.isConnecting=!1}},{key:"resetReconnectionAttempts",value:function(){this.reconnectAttempts=0,this.isReconnecting=!1}},{key:"sendMessage",value:function(t){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(JSON.stringify(t))}},{key:"sendBinary",value:function(t){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(t)}},{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){e.emit("error",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:WebSocket.CLOSED}}}],r=[{key:"clearAllConnections",value:function(){gt.clearAll()}}],o&&wt(n.prototype,o),r&&wt(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a),xt=n(540),Et=n(848);function Tt(t){return Tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Tt(t)}function _t(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 Dt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?_t(Object(n),!0).forEach(function(e){It(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):_t(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function It(t,e,n){return(e=function(t){var e=function(t){if("object"!=Tt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Tt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Rt(){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 a?o:a,u=Object.create(s.prototype);return At(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(At(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,At(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,At(f,"constructor",u),At(u,"constructor",s),s.displayName="GeneratorFunction",At(u,r,"GeneratorFunction"),At(f),At(f,r,"Generator"),At(f,o,function(){return this}),At(f,"toString",function(){return"[object Generator]"}),(Rt=function(){return{w:i,m:p}})()}function At(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}At=function(t,e,n,o){function i(e,n){At(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))},At(t,e,n,o)}function Mt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Wt(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,c,a=[],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)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Bt(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)?Bt(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 Bt(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 Kt=function(t){var e=t.websocketUrl,n=t.agentId,o=t.voice,r=void 0===o?"default":o,i=t.language,c=void 0===i?"en":i,a=t.autoReconnect,s=void 0===a||a,u=t.onConnected,l=t.onDisconnected,f=t.onRecordingStarted,p=t.onRecordingStopped,d=t.onPlaybackStarted,y=t.onPlaybackStopped,h=t.onError,g=t.onMessage,b=t.onBargeIn,v=t.onStopPlaying,m=t.className,S=void 0===m?"":m,w=t.style,k=void 0===w?{}:w,O=t.children,j=Wt((0,xt.useState)(!1),2),P=j[0],C=j[1],x=Wt((0,xt.useState)(!1),2),E=x[0],T=x[1],_=Wt((0,xt.useState)(!1),2),D=(_[0],_[1]),I=Wt((0,xt.useState)("Disconnected"),2),R=(I[0],I[1]),A=(0,xt.useRef)(null);(0,xt.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),A.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),A.current.destroy(),A.current=null);var t=new pt({websocketUrl:e,agentId:n,voice:r,language:c,autoReconnect:s});return t.on("connected",function(){C(!0),R("Connected"),null==u||u()}),t.on("disconnected",function(){C(!1),R("Disconnected"),null==l||l()}),t.on("recordingStarted",function(){T(!0),null==f||f()}),t.on("recordingStopped",function(){T(!1),null==p||p()}),t.on("playbackStarted",function(){D(!0),null==d||d()}),t.on("playbackStopped",function(){D(!1),null==y||y()}),t.on("error",function(t){null==h||h(t)}),t.on("message",function(t){null==g||g(t)}),t.on("bargeIn",function(t){null==b||b(t)}),t.on("stopPlaying",function(t){null==v||v(t)}),A.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),A.current&&(A.current.destroy(),A.current=null)}},[e,n,r,c]);var M=function(){var t,e=(t=Rt().m(function t(){var e;return Rt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(A.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,A.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Mt(i,o,r,c,a,"next",t)}function a(t){Mt(i,o,r,c,a,"throw",t)}c(void 0)})});return function(){return e.apply(this,arguments)}}(),W=(0,Et.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,Et.jsx)("div",{style:{fontSize:"20px"},children:E?"🔴":"🎤"}),(0,Et.jsx)("div",{children:E?"Stop Listening":"Start Listening"})]});return(0,Et.jsx)("button",{className:"voice-button ".concat(E?"recording":""," ").concat(S),style:Dt({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:E?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},k),onClick:M,disabled:!P,children:O||W})};function Gt(t){return Gt="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},Gt(t)}function Ut(){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 a?o:a,u=Object.create(s.prototype);return Vt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Vt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Vt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,Vt(f,"constructor",u),Vt(u,"constructor",s),s.displayName="GeneratorFunction",Vt(u,r,"GeneratorFunction"),Vt(f),Vt(f,r,"Generator"),Vt(f,o,function(){return this}),Vt(f,"toString",function(){return"[object Generator]"}),(Ut=function(){return{w:i,m:p}})()}function Vt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Vt=function(t,e,n,o){function i(e,n){Vt(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))},Vt(t,e,n,o)}function Nt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Ft(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Nt(i,o,r,c,a,"next",t)}function a(t){Nt(i,o,r,c,a,"throw",t)}c(void 0)})}}function Lt(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 Ht(t,e,n){return(e=zt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Qt(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,zt(o.key),o)}}function zt(t){var e=function(t){if("object"!=Gt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Gt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Gt(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?Lt(Object(n),!0).forEach(function(e){Ht(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Lt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({websocketUrl:e.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:e.agentId,voice:e.voice||"default",language:e.language||"en",container:e.container||document.body,buttonText:e.buttonText||"Start Listening",buttonClass:e.buttonClass||"voice-button"},e),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new pt({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},e=[{key:"setupEventListeners",value:function(){var t=this;this.voiceSDK.on("connected",function(){var e,n;t.isConnected=!0,t.updateButton(),null===(e=(n=t.options).onConnected)||void 0===e||e.call(n)}),this.voiceSDK.on("disconnected",function(){var e,n;t.isConnected=!1,t.updateButton(),null===(e=(n=t.options).onDisconnected)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStarted",function(){var e,n;t.isRecording=!0,t.updateButton(),null===(e=(n=t.options).onRecordingStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStopped",function(){var e,n;t.isRecording=!1,t.updateButton(),null===(e=(n=t.options).onRecordingStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStarted",function(){var e,n;t.isPlaying=!0,null===(e=(n=t.options).onPlaybackStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStopped",function(){var e,n;t.isPlaying=!1,null===(e=(n=t.options).onPlaybackStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("error",function(e){var n,o;null===(n=(o=t.options).onError)||void 0===n||n.call(o,e)}),this.voiceSDK.on("message",function(e){var n,o;null===(n=(o=t.options).onMessage)||void 0===n||n.call(o,e)}),this.voiceSDK.on("bargeIn",function(e){var n,o;null===(n=(o=t.options).onBargeIn)||void 0===n||n.call(o,e)}),this.voiceSDK.on("stopPlaying",function(e){var n,o;null===(n=(o=t.options).onStopPlaying)||void 0===n||n.call(o,e)})}},{key:"createButton",value:function(){var t=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return t.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var t=this.isRecording?"🔴":"🎤",e=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(t,"</span>\n <span>").concat(e,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=Ft(Ut().m(function t(){var e;return Ut().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=Ft(Ut().m(function t(){var e;return Ut().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&&Qt(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Jt(t){return Jt="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},Jt(t)}function $t(){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 a?o:a,u=Object.create(s.prototype);return Xt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,a=0,s=t,p.n=n,c}};function d(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],d=p.p,y=i[2];n>3?(r=y===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=d&&((r=n<2&&d<i[1])?(a=0,p.v=o,p.n=i[1]):d<y&&(r=n<3||i[0]>o||o>y)&&(i[4]=n,i[5]=o,p.n=y,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,y){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,y),a=l,s=y;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(p.n=-1),d(a,s)):p.n=s:p.v=s);try{if(u=2,i){if(a||(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,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=p.n<0)?s:n.call(o,p))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Xt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Xt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,Xt(f,"constructor",u),Xt(u,"constructor",s),s.displayName="GeneratorFunction",Xt(u,r,"GeneratorFunction"),Xt(f),Xt(f,r,"Generator"),Xt(f,o,function(){return this}),Xt(f,"toString",function(){return"[object Generator]"}),($t=function(){return{w:i,m:p}})()}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 Yt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Zt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Yt(i,o,r,c,a,"next",t)}function a(t){Yt(i,o,r,c,a,"throw",t)}c(void 0)})}}function te(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function ee(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,oe(o.key),o)}}function ne(t,e,n){return e&&ee(t.prototype,e),n&&ee(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function oe(t){var e=function(t){if("object"!=Jt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Jt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Jt(e)?e:e+""}var re=function(){return ne(function t(e){te(this,t),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=Zt($t().m(function t(e){var n,o=this;return $t().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=new pt({websocketUrl:e,autoReconnect:!1}),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=Zt($t().m(function t(){return $t().w(function(t){for(;;)switch(t.n){case 0:if(!this.voiceSDK){t.n=1;break}return t.n=1,this.voiceSDK.startRecording();case 1:return t.a(2)}},t,this)})),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}(),ie=function(){return ne(function t(e){te(this,t),this.config=e,this.sdk=new re,this.isOpen=!1,this.isActive=!1,this.position=e.position||"bottom-right",this.primaryColor=e.primaryColor||"#4F46E5",this.setupEventHandlers(),this.createWidget()},[{key:"setupEventHandlers",value:function(){var t=this;this.sdk.onConnected=function(){t.updateStatus("connected")},this.sdk.onDisconnected=function(){t.updateStatus("disconnected"),t.isActive=!1},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=this,e=document.createElement("div");e.id="agent-widget",e.innerHTML="\n <style>\n #agent-widget {\n position: fixed;\n ".concat(this.position.includes("bottom")?"bottom: 20px;":"top: 20px;","\n ").concat(this.position.includes("right")?"right: 20px;":"left: 20px;",'\n z-index: 9999;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n }\n \n #agent-button {\n width: 60px;\n height: 60px;\n border-radius: 50%;\n background: ').concat(this.primaryColor,";\n border: none;\n cursor: pointer;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n display: flex;\n align-items: center;\n justify-content: center;\n transition: transform 0.2s;\n }\n \n #agent-button:hover {\n transform: scale(1.1);\n }\n \n #agent-button svg {\n width: 28px;\n height: 28px;\n fill: white;\n }\n \n #agent-panel {\n display: none;\n position: absolute;\n bottom: 80px;\n ").concat(this.position.includes("right")?"right: 0;":"left: 0;","\n width: 350px;\n height: 500px;\n background: white;\n border-radius: 12px;\n box-shadow: 0 8px 32px rgba(0,0,0,0.2);\n flex-direction: column;\n overflow: hidden;\n }\n \n #agent-panel.open {\n display: flex;\n }\n \n #agent-header {\n background: ").concat(this.primaryColor,";\n color: white;\n padding: 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n \n #agent-close {\n background: none;\n border: none;\n color: white;\n cursor: pointer;\n font-size: 24px;\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: 8px;\n max-width: 80%;\n }\n \n .message.user {\n background: #E5E7EB;\n align-self: flex-end;\n }\n \n .message.agent {\n background: #F3F4F6;\n align-self: flex-start;\n }\n \n #agent-controls {\n padding: 16px;\n border-top: 1px solid #E5E7EB;\n display: flex;\n justify-content: center;\n }\n \n #agent-mic-button {\n width: 60px;\n height: 60px;\n border-radius: 50%;\n border: none;\n background: ").concat(this.primaryColor,';\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n }\n \n #agent-mic-button.active {\n background: #EF4444;\n animation: pulse 1.5s infinite;\n }\n \n #agent-mic-button svg {\n width: 28px;\n height: 28px;\n fill: white;\n }\n \n @keyframes pulse {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.05); }\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n \n .error-message {\n background: #FEE2E2;\n color: #991B1B;\n padding: 12px;\n border-radius: 8px;\n margin: 8px;\n }\n </style>\n \n <button id="agent-button">\n <svg viewBox="0 0 24 24">\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>\n </button>\n \n <div id="agent-panel">\n <div id="agent-header">\n <h3 style="margin: 0;">Voice Assistant</h3>\n <button id="agent-close">×</button>\n </div>\n \n <div id="agent-messages"></div>\n \n <div id="agent-controls">\n <button id="agent-mic-button">\n <svg viewBox="0 0 24 24">\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>\n </button>\n </div>\n </div>\n '),document.body.appendChild(e),document.getElementById("agent-button").onclick=function(){return t.togglePanel()},document.getElementById("agent-close").onclick=function(){return t.togglePanel()},document.getElementById("agent-mic-button").onclick=function(){return t.toggleVoice()}}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(e=Zt($t().m(function t(){var e,n;return $t().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isActive){t.n=7;break}return t.p=1,t.n=2,this.getSignedUrl();case 2:return e=t.v,t.n=3,this.sdk.connect(e);case 3:return t.n=4,this.sdk.startListening();case 4:this.isActive=!0,document.getElementById("agent-mic-button").classList.add("active"),this.addMessage("system","Listening..."),t.n=6;break;case 5:t.p=5,n=t.v,console.error("Failed to start:",n),this.showError(n.message);case 6:t.n=8;break;case 7:this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,document.getElementById("agent-mic-button").classList.remove("active");case 8:return t.a(2)}},t,this,[[1,5]])})),function(){return e.apply(this,arguments)})},{key:"getSignedUrl",value:(t=Zt($t().m(function t(){var e,n,o;return $t().w(function(t){for(;;)switch(t.n){case 0:if("string"!=typeof this.config.getSessionUrl){t.n=4;break}return t.n=1,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:this.config.agentId,variables:this.config.variables||{}})});case 1:if((e=t.v).ok){t.n=2;break}throw new Error("Failed to get session URL: ".concat(e.statusText));case 2:return t.n=3,e.json();case 3:return n=t.v,t.a(2,n.signedUrl||n.wsUrl||n.url);case 4:if("function"!=typeof this.config.getSessionUrl){t.n=6;break}return t.n=5,this.config.getSessionUrl({agentId:this.config.agentId,variables:this.config.variables||{}});case 5:return o=t.v,t.a(2,"string"==typeof o?o:o.signedUrl||o.wsUrl||o.url);case 6:throw new Error("getSessionUrl is required (URL string or function)");case 7: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){console.log("Widget status:",t)}}]);var t,e}(),ce="2.0.0";const ae={VoiceSDK:pt,WebSocketManager:Ct,WebSocketManagerV2:D,AudioRecorder:N,AudioPlayer:Y,EventEmitter:a,VoiceButton:Kt,VanillaVoiceButton:qt,AgentSDK:re,AgentWidget:ie,VERSION:ce};return o})());
|
|
3
3
|
//# sourceMappingURL=agent-widget.js.map
|