@botuyo/chat-widget-standalone 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"VoiceCallOverlay.d.ts","sourceRoot":"","sources":["../../../../src/chat-widget/components/VoiceCallOverlay.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAoBH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAA;AAOzB,8CAA8C;AAC9C,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,8DAA8D;IAC9D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,2DAA2D;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,4DAA4D;IAC5D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,yEAAyE;IACzE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,mDAAmD;IACnD,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,kDAAkD;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wDAAwD;IACxD,aAAa,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAC/C,qCAAqC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAA;IACjD,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B;;;;;;;;;;OAUG;IACH,GAAG,CAAC,EAAE,KAAK,GAAG,cAAc,CAAA;IAC5B,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,UAAU,qBAAqB;IAC7B,MAAM,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,CAAA;IACrB,OAAO,CAAC,EAAE,gBAAgB,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AAED,KAAK,SAAS,GAAG,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,CAAA;AA4b9E,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,OAAO,EACP,YAAwB,EACxB,SAAS,EACT,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,GACZ,EAAE,qBAAqB,kDAi/CvB"}
1
+ {"version":3,"file":"VoiceCallOverlay.d.ts","sourceRoot":"","sources":["../../../../src/chat-widget/components/VoiceCallOverlay.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAoBH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAML,KA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C,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,CAAA;IACrB,OAAO,CAAC,EAAE,gBAAgB,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AAED,KAAK,SAAS,GAAG,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,CAAA;AA4b9E,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,OAAO,EACP,YAAwB,EACxB,SAAS,EACT,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,GACZ,EAAE,qBAAqB,kDAo/CvB"}
@@ -99,6 +99,24 @@ export declare function resolveVadInput(ctx: VadInputContext): {
99
99
  frame: VadFrame;
100
100
  confirmedSpeech: boolean;
101
101
  };
102
+ /**
103
+ * Resolves the `speech` flag carried with a STREAMED audio chunk (i.e. one the
104
+ * {@link VadGate} already decided to forward). The server's greeting audio-gate drops
105
+ * unmarked mic audio while the greeting plays, so this flag is what lets the user be heard.
106
+ *
107
+ * - A fresh Silero confirmation (`confirmedSpeech`) is the strong signal — trust it.
108
+ * - Otherwise we are in the energy-only fallback (Silero/ONNX could not load — offline,
109
+ * CSP, or a network that blocks the CDN). There, a frame the energy gate chose to stream
110
+ * IS itself the near-field-speech decision, so we mark it as speech. This keeps the voice
111
+ * INPUT path working WITHOUT depending on the third-party VAD CDN being reachable.
112
+ *
113
+ * Echo safety is unaffected: while the bot speaks with no fresh VAD, {@link resolveVadInput}
114
+ * feeds a silent frame so the gate never streams — those frames never reach this function.
115
+ */
116
+ export declare function resolveSpeechFlag(ctx: {
117
+ confirmedSpeech: boolean;
118
+ vadFresh: boolean;
119
+ }): boolean;
102
120
  /**
103
121
  * Stateful speech gate. Feed it one analysed frame at a time via {@link process};
104
122
  * it returns whether to stream the frame plus any transition event.
@@ -1 +1 @@
1
- {"version":3,"file":"vadGate.d.ts","sourceRoot":"","sources":["../../../../src/chat-widget/voice/vadGate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAA;AAE/C,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,YAAY,GAAG,UAAU,CAAA;AAErE,MAAM,WAAW,aAAa;IAC5B,oFAAoF;IACpF,uBAAuB,EAAE,MAAM,CAAA;IAC/B,yFAAyF;IACzF,uBAAuB,EAAE,MAAM,CAAA;IAC/B,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAA;IACpB,qFAAqF;IACrF,UAAU,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAA;IACnB,0FAA0F;IAC1F,gBAAgB,EAAE,MAAM,CAAA;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,qDAAqD;AACrD,MAAM,WAAW,QAAQ;IACvB,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAA;IAClB,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAA;IACX,6EAA6E;IAC7E,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,YAAY,EAAE,OAAO,CAAA;IACrB,8CAA8C;IAC9C,KAAK,EAAE,YAAY,CAAA;IACnB,uDAAuD;IACvD,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,KAAK,GAAG,UAAU,GAAG,MAAM,EAAE,aAAa,CAyB/E,CAAA;AAED,sDAAsD;AACtD,MAAM,MAAM,cAAc,GAAG,KAAK,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AE,eAAe,GAAG;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,CAYnG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE;IAAE,eAAe,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAE/F;AAED;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,eAAe,CAAI;gBAEf,MAAM,GAAE,OAAO,CAAC,aAAa,CAAM;IAI/C,IAAI,KAAK,IAAI,YAAY,CAExB;IAED,qDAAqD;IACrD,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,KAAK,EAAE,QAAQ,GAAG,aAAa;IAMvC,OAAO,CAAC,cAAc;IA2BtB,OAAO,CAAC,aAAa;CAqBtB"}
@@ -15,7 +15,7 @@ return y("div",{className:Et("flex items-center w-fit transition-all duration-50
15
15
  /* @__PURE__ */b(W,{size:10}),
16
16
  /* @__PURE__ */y("span",{children:[e.length," fuente",e.length>1?"s":""]}),
17
17
  /* @__PURE__ */b("span",{className:"transition-transform duration-200",style:{transform:t?"rotate(180deg)":"rotate(0)"},children:"▾"})]}),t&&/* @__PURE__ */b("div",{className:"flex flex-wrap gap-1 mt-1 animate-in fade-in slide-in-from-top-1 duration-200",children:e.map((e,t)=>/* @__PURE__ */y("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-medium rounded-md",style:{backgroundColor:"hsl(var(--muted) / 0.4)",color:"hsl(var(--muted-foreground))"},children:[
18
- /* @__PURE__ */b(W,{size:9}),e]},`${e}-${t}`))})]}):null}),Ul=p(()=>import("./AudioPlayer-CMZ9EdSY.js").then(e=>({default:e.AudioPlayer}))),ql=p(()=>import("./Gallery-CYqlHLLG.js").then(e=>({default:e.Gallery})));function Vl({message:e,brandColor:t,onButtonClick:n}){const[r,o]=i(e.selectedId||null);/* @__PURE__ */
18
+ /* @__PURE__ */b(W,{size:9}),e]},`${e}-${t}`))})]}):null}),Ul=p(()=>import("./AudioPlayer-CzaYLuuQ.js").then(e=>({default:e.AudioPlayer}))),ql=p(()=>import("./Gallery-DfZMfTse.js").then(e=>({default:e.Gallery})));function Vl({message:e,brandColor:t,onButtonClick:n}){const[r,o]=i(e.selectedId||null);/* @__PURE__ */
19
19
  return y("div",{className:"space-y-3",children:[
20
20
  /* @__PURE__ */b("div",{className:Et("prose prose-sm max-w-none break-words leading-relaxed dark:prose-invert text-foreground"),children:/* @__PURE__ */b(ja,{remarkPlugins:[Il],rehypePlugins:[[$l,{tagNames:["p","strong","em","br","span"],attributes:{}}]],components:{p:({children:e})=>/* @__PURE__ */b("p",{className:"mb-0 last:mb-0",children:e})},children:e.content})}),
21
21
  /* @__PURE__ */b("div",{className:"flex flex-col gap-2",children:e.buttons.map((i,a)=>{const s=r===i.id;/* @__PURE__ */
@@ -103,7 +103,7 @@ return y("div",n&&!d?{className:"relative flex flex-col items-center gap-4",chil
103
103
  /* @__PURE__ */b("div",{className:"absolute rounded-full",style:{inset:"12px",border:`1px solid ${g}15`,animation:m?"spin 12s linear infinite reverse":"none"}}),
104
104
  /* @__PURE__ */b("div",{className:"absolute rounded-full flex items-center justify-center",style:{inset:"24px",background:`radial-gradient(circle at 35% 35%, ${g}40, ${g}10 60%, transparent 80%)`,boxShadow:m?`0 0 60px ${g}35, 0 0 120px ${g}15, inset 0 0 40px ${g}10`:`0 0 30px ${g}15`,transform:`scale(${v})`,transition:"all 0.5s cubic-bezier(0.4, 0, 0.2, 1)"},children:/* @__PURE__ */b("div",{className:"rounded-full",style:{width:.35*w+"px",height:.35*w+"px",background:`radial-gradient(circle, ${g}90, ${g}40)`,boxShadow:`0 0 20px ${g}60`,animation:m?"pulse 2s ease-in-out infinite":"none"}})}),m&&[0,1,2].map(e=>/* @__PURE__ */b("div",{className:"absolute rounded-full",style:{width:"4px",height:"4px",backgroundColor:g,opacity:.6,top:"50%",left:"50%",transform:`rotate(${120*e}deg) translateX(${(w+48)/2}px)`,animation:`spin ${6+2*e}s linear infinite`,boxShadow:`0 0 6px ${g}`}},e))]}),s.showWaveform&&/* @__PURE__ */b(Bc,{isActive:m,audioLevel:a,color:g})]})}function Bc({isActive:e,audioLevel:t,color:n}){/* @__PURE__ */
105
105
  return b("div",{className:"flex items-center gap-[3px] h-10",children:Array.from({length:12}).map((r,o)=>{const i=Math.abs(o-5.5)/5.5,a=e?Math.max(4,40*t*(1-.5*i)*(.5+.5*Math.sin(.8*o))):4;/* @__PURE__ */
106
- return b("div",{className:"rounded-full transition-all duration-100",style:{width:"3px",height:`${a}px`,backgroundColor:n,opacity:e?.7-.3*i:.2}},o)})})}function Uc({isOpen:e,onClose:t,primaryColor:n="#10b981",getSocket:r,avatars:o,logoUrl:l,avatar3dUrl:c,voiceConfig:d,onCallEnded:p}){const h=u(()=>function(e,t="#10b981"){return{backgroundColor:e?.backgroundColor??"#0a0a0a",listeningColor:e?.listeningColor??"#10b981",speakingColor:e?.speakingColor??t,thinkingColor:e?.thinkingColor??"#a855f7",showEmojis:e?.showEmojis??!0,showEmotionLabel:e?.showEmotionLabel??!0,showWaveform:e?.showWaveform??!0,showBadge:e?.showBadge??!1,badgeText:e?.badgeText??"",emotionEmojis:{...Pc,...e?.emotionEmojis},statusLabels:{...Lc,...e?.statusLabels},orbSize:e?.orbSize??128,speakingScale:e?.speakingScale??1.08,thinkingScale:e?.thinkingScale??.95,avatar3dUrl:e?.avatar3dUrl,voiceGate:(n=e?.noiseGate,void 0===n||!0===n||"standard"===n?{...kc.standard}:!1===n||"off"===n?{...kc.off}:"string"==typeof n?{...kc[n]??kc.standard}:{...kc.standard,...n}),vad:!1!==e?.vad&&Cc(e?.vad),vadAssetBaseUrl:e?.vadAssetBaseUrl};var n}(d,n),[d,n]);!function(e){const t=f(null);a(()=>{const n="undefined"==typeof navigator?null:navigator.wakeLock??null;if(!e||!n)return;let r=!1;const o=async()=>{if(!t.current||t.current.released)try{const e=await n.request("screen");if(r)return void e.release();t.current=e,e.addEventListener("release",()=>{t.current===e&&(t.current=null)})}catch(e){Dt("[useWakeLock] Could not acquire screen wake lock",e)}},i=()=>{"visible"===document.visibilityState&&o()};return o(),document.addEventListener("visibilitychange",i),()=>{r=!0,document.removeEventListener("visibilitychange",i);const e=t.current;t.current=null,e&&!e.released&&e.release().catch(()=>{})}},[e])}(e);const[m,g]=i("idle"),[w,x]=i(0),[k,_]=i(!1),[S,C]=i(0),[E,z]=i(null),[N,A]=i([]),[I,T]=i(!1),[O,M]=i(""),[P,L]=i(!1),[D,j]=i(null),[F,R]=i(void 0),[$,B]=i(void 0),[U,q]=i(void 0),[V,W]=i(!1),H=f(null),Z=f(null),K=f(null),G=f(null),Y=f(null),te=f(0),ne=f(!1),oe=f(null),ie=f(null),se=f(()=>{}),le=f(null),ce=f(0),ue=f(null),de=f([]),pe=f(!1),he=f(0),fe=f([]),me=f(null),ge=f(null),be=f(1),ye=f(0),ve=s(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,"0")}`,[]),we=s(()=>{if(0===de.current.length)return;ue.current&&"closed"!==ue.current.state||(ue.current=new AudioContext({sampleRate:jc})),"suspended"===ue.current.state&&ue.current.resume().catch(()=>{});const e=ue.current;pe.current=!0,g("speaking");const t=e.currentTime;for(he.current<t&&(he.current=t);de.current.length>0;){const t=de.current.shift(),n=e.createBuffer(1,t.length,jc);n.getChannelData(0).set(t);const r=e.createBufferSource();r.buffer=n,r.connect(e.destination),r.start(he.current),fe.current.push(r),r.onended=()=>{fe.current=fe.current.filter(e=>e!==r),0===fe.current.length&&0===de.current.length&&(pe.current=!1,g(e=>"speaking"===e?"listening":e))},he.current+=t.length/jc}},[]),xe=s(()=>{fe.current.forEach(e=>{try{e.stop()}catch{}}),fe.current=[],de.current.length=0,he.current=0,pe.current=!1,g("listening")},[]),ke=f({}),_e=s(()=>{const e=r?.();if(!e||ne.current)return;const n=e=>{e&&(R(e.avatars||void 0),B(e.logoUrl||void 0),q(e.avatar3dUrl||void 0),W(!0))},o=e=>{g("listening"),n(e?.agentAvatar)},i=e=>{Ae();const t=(e?.agentName||"").toString().trim();j(t||"Nuevo agente"),n(e?.agentAvatar),A(e=>[...e,{role:"bot",text:t?`🔄 Continuás con ${t}.`:"🔄 Te derivé con el área correspondiente.",standalone:!0}])},a=e=>{if(!e?.data)return;const t=function(e){const t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);const r=new Int16Array(n.buffer),o=new Float32Array(r.length);for(let i=0;i<r.length;i++)o[i]=r[i]/32768;return o}(e.data);de.current.push(t),we(),Ae()},s=()=>{xe()},l=()=>{},c=e=>{console.error("[VoiceCall] Voice error:",e)},u=e=>{e?.emotion&&(z(e.emotion),setTimeout(()=>z(t=>t===e.emotion?null:t),4e3))},d=e=>{e?.text&&(Ae(),A(t=>{if(t.length>0&&"user"===t[t.length-1].role){const n=[...t],r=n[n.length-1].text,o=r.length>0&&!r.endsWith(" ")&&!e.text.startsWith(" ");return n[n.length-1]={...n[n.length-1],text:r+(o?" ":"")+e.text},n}return[...t,{role:"user",text:e.text}]}))},h=e=>{e?.text&&A(t=>{const n=t.map(e=>e.quizButtons?{...e,quizButtons:void 0}:e),r=n.map(e=>e.role).lastIndexOf("user");return r>=0?(n[r]={...n[r],text:e.text},n):[...n,{role:"user",text:e.text}]})},f=e=>{e?.text&&A(t=>{const n=[...t];for(let o=n.length-1;o>=0;o--)if("user"===n[o].role&&n[o].text===e.original)return n[o]={...n[o],text:e.text},n;const r=n.map(e=>e.role).lastIndexOf("user");return r>=0?(n[r]={...n[r],text:e.text},n):t})},m=e=>{e?.text&&(Ae(),A(t=>{const n=t[t.length-1];if(n&&"bot"===n.role&&!n.standalone){const r=[...t],o=n.text,i=o.length>0&&!o.endsWith(" ")&&!e.text.startsWith(" ");return r[r.length-1]={...n,text:o+(i?" ":"")+e.text},r}return[...t,{role:"bot",text:e.text}]}))},b=()=>{g("thinking"),Ae()},y=e=>{if(!e?.items?.length)return;if(Ae(),"present_quiz"===e.tool)return;if("show_content"===e.tool){const t=e.items.map(e=>"link"===e.type?`[${e.label||e.url}](${e.url})`:"image"===e.type?`![${e.label||""}](${e.url})`:e.label||"").filter(Boolean).join("\n");return void(t&&A(e=>[...e,{role:"bot",text:t,standalone:!0}]))}const t=e.items.map(t=>{if("search_accommodations"===e.tool){const e=t.options?.[0],n=e?`${e.totalPrice} ${e.currency}`:"",r=(t.features||[]).slice(0,3).join(" • "),o=t.cover?`![${t.title}](${t.cover})`:"",i=e?.link?`[Ver detalles](${e.link})`:"";return`${o}\n**${t.index}. ${t.title}**\n📍 ${t.location} ${t.rating?`⭐ ${t.rating}`:""}\n💰 ${n}\n${r}\n${i}`}if("get_accommodation_details"===e.tool){const e=(t.images||[]).slice(0,4).map(e=>`![](${e})`).join("\n"),n=t.specs?Object.entries(t.specs).map(([e,t])=>`${e}: ${t}`).join(" • "):"",r=(t.rooms||[]).map(e=>`• ${e.name}: ${e.price}`).join("\n"),o=t.rules?`🕐 Check-in: ${t.rules.checkIn||"-"} | Check-out: ${t.rules.checkOut||"-"} | Mascotas: ${t.rules.pets||"-"}`:"",i=t.seeMoreLink?`[Ver más detalles](${t.seeMoreLink})`:"";return`${e}\n**${t.title||t.name}**\n${t.description||""}\n${n}\n${r}\n${o}\n${i}`}if("card"===t.type&&t.content)return t.content;if("link"===t.type&&t.url)return`🔗 [${t.label||t.url}](${t.url})`;if("image"===t.type&&t.url)return`![${t.label||""}](${t.url})`;if(t.systemInstruction&&"string"==typeof t.systemInstruction)return t.systemInstruction;const n=t.signupUrl||t.url||t.link||t.redirectUrl||t.actionPayload?.signupUrl||t.actionPayload?.url;return n?`🔗 [${t.label||t.title||e.tool.replace(/_/g," ")}](${n})`:"error"===t.status?t.error||"Error al ejecutar la acción":""}).filter(Boolean).join("\n\n---\n\n");t&&A(e=>[...e,{role:"bot",text:t,standalone:!0}])},v=e=>{if("quiz_question"===e?.eventName&&e?.data){const{question:t,buttons:n}=e.data;t&&n?.length&&(Ae(),A(e=>[...e,{role:"bot",text:`📝 ${t}`,quizButtons:n,standalone:!0}]))}};ke.current={voiceReady:o,voiceAudioChunk:a,voiceInterrupted:s,voiceTurnComplete:l,voiceError:c,voiceEmotion:u,voiceUserTranscript:d,voiceUserTranscriptFinal:h,voiceUserTranscriptCorrected:f,voiceModelTranscript:m,voiceModelThinking:b,voiceToolVisual:y,voiceCustomEvent:v,voiceAgentSwitched:i},e.on("voice_ready",o),e.on("voice_audio_chunk",a),e.on("voice_interrupted",s),e.on("voice_turn_complete",l),e.on("voice_error",c),e.on("voice_emotion",u),e.on("voice_user_transcript",d),e.on("voice_user_transcript_final",h),e.on("voice_user_transcript_corrected",f),e.on("voice_model_transcript",m),e.on("voice_model_thinking",b),e.on("voice_tool_visual",y),e.on("custom_event",v),e.on("voice_agent_switched",i),e.on("voice_timeout",()=>{se.current()});const w=e=>{p?.(e?.reason),A(e=>[...e,{role:"bot",text:"📞 Llamada finalizada."}]);const n=r?.();n?.connected&&setTimeout(()=>{try{n.emit("request_history")}catch{}},1500),setTimeout(()=>{t()},2500)};e.on("voice_call_ended",w),ke.current.voiceCallEnded=w,ne.current=!0},[r,we,xe]),Se=s(()=>{const e=r?.();if(!e||!ne.current)return;const t=ke.current;t.voiceReady&&e.off("voice_ready",t.voiceReady),t.voiceAudioChunk&&e.off("voice_audio_chunk",t.voiceAudioChunk),t.voiceInterrupted&&e.off("voice_interrupted",t.voiceInterrupted),t.voiceTurnComplete&&e.off("voice_turn_complete",t.voiceTurnComplete),t.voiceError&&e.off("voice_error",t.voiceError),t.voiceEmotion&&e.off("voice_emotion",t.voiceEmotion),t.voiceUserTranscript&&e.off("voice_user_transcript",t.voiceUserTranscript),t.voiceUserTranscriptFinal&&e.off("voice_user_transcript_final",t.voiceUserTranscriptFinal),t.voiceUserTranscriptCorrected&&e.off("voice_user_transcript_corrected",t.voiceUserTranscriptCorrected),t.voiceModelTranscript&&e.off("voice_model_transcript",t.voiceModelTranscript),t.voiceModelThinking&&e.off("voice_model_thinking",t.voiceModelThinking),t.voiceToolVisual&&e.off("voice_tool_visual",t.voiceToolVisual),t.voiceCustomEvent&&e.off("custom_event",t.voiceCustomEvent),t.voiceAgentSwitched&&e.off("voice_agent_switched",t.voiceAgentSwitched),t.voiceCallEnded&&e.off("voice_call_ended",t.voiceCallEnded),e.off("voice_timeout"),ke.current={},ne.current=!1},[r]),Ce=s(async()=>{const e=r?.();if(!e)return;const t=await navigator.mediaDevices.getUserMedia({audio:ac});K.current=t;const n=!1!==h.vad;me.current=new Ec(n?h.vad:{energyOnly:!0}),be.current=1,ye.current=0,n&&async function(e){const t=e.loadVad??Tc;try{const n=await t(),r=(t,n)=>{e.onFrame({speechProb:t?.isSpeech??0,rms:Ic(n)})},o=await n.MicVAD.new(function(e,t){const n={model:e.model??"v5",baseAssetPath:e.assetBaseUrl??Nc,onnxWASMBasePath:e.onnxWasmBaseUrl??"https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/",startOnLoad:!1,onFrameProcessed:t};if(e.audioContext&&(n.audioContext=e.audioContext),e.stream){const t=e.stream;n.getStream=async()=>t,n.pauseStream=async()=>{},n.resumeStream=async()=>{}}return n}(e,r));return Rt("[VAD] Silero speech detector ready"),new Oc(o)}catch(n){return Dt("[VAD] Silero unavailable — falling back to energy gate",n),null}}({stream:t,assetBaseUrl:h.vadAssetBaseUrl,onFrame:({speechProb:e})=>{be.current=e,ye.current=performance.now()}}).then(e=>{if(e){if(K.current)return ge.current=e,e.start();e.destroy()}}).catch(()=>{});const o=new AudioContext({sampleRate:16e3});G.current=o,"suspended"===o.state&&await o.resume();const i=o.createMediaStreamSource(t),a=function(e,t){const n=e.createBiquadFilter();n.type="highpass",n.frequency.value=sc,n.Q.value=lc;const r=e.createBiquadFilter();r.type="highpass",r.frequency.value=cc,r.Q.value=uc;const o=e.createBiquadFilter();o.type="peaking",o.frequency.value=dc,o.Q.value=pc,o.gain.value=hc;const i=e.createBiquadFilter();i.type="lowpass",i.frequency.value=fc,i.Q.value=mc;const a=e.createDynamicsCompressor();return a.threshold.value=gc,a.knee.value=bc,a.ratio.value=yc,a.attack.value=vc,a.release.value=wc,t.connect(n),n.connect(r),r.connect(o),o.connect(i),i.connect(a),a}(o,i),s=o.createAnalyser();if(s.fftSize=256,a.connect(s),Z.current=s,!oe.current){const e=new Blob([_c(h.voiceGate)],{type:"application/javascript"});oe.current=URL.createObjectURL(e)}await o.audioWorklet.addModule(oe.current);const l=new AudioWorkletNode(o,"voice-pcm-processor");Y.current=l,l.port.onmessage=t=>{const n=me.current;if(!n)return;const r=performance.now()-ye.current<600,{frame:o,confirmedSpeech:i}=function(e){return e.botSpeaking&&!e.vadFresh?{frame:{speechProb:0,rms:0,botSpeaking:!0},confirmedSpeech:!1}:{frame:{speechProb:e.vadFresh?e.speechProb:1,rms:e.rms,botSpeaking:e.botSpeaking},confirmedSpeech:e.vadFresh}}({botSpeaking:pe.current,vadFresh:r,speechProb:be.current,rms:t.data.rms}),{shouldStream:a,event:s}=n.process(o);"barge_in"===s&&xe(),a&&e.connected&&!k&&e.emit("voice_audio_chunk",{data:Fc(t.data.pcm),speech:i})},a.connect(l);const c=()=>{if(!Z.current)return;const e=new Uint8Array(Z.current.frequencyBinCount);Z.current.getByteFrequencyData(e);const t=e.reduce((e,t)=>e+t,0)/e.length;C(t/255),te.current=requestAnimationFrame(c)};c()},[r,k,h.voiceGate,h.vad,h.vadAssetBaseUrl,xe]),Ee=s(()=>{cancelAnimationFrame(te.current),ge.current?.destroy(),ge.current=null,me.current=null,be.current=1,ye.current=0,Y.current?.disconnect(),Y.current=null,K.current?.getTracks().forEach(e=>e.stop()),K.current=null,G.current?.close(),G.current=null,Z.current=null,C(0)},[]),ze=s(async()=>{const e=r?.();if(e?.connected){g("connecting"),x(0),A([]),z(null),R(void 0),B(void 0),q(void 0),W(!1),de.current=[],_e(),ue.current&&"closed"!==ue.current.state||(ue.current=new AudioContext({sampleRate:jc})),ue.current.resume().catch(()=>{});try{await Ce()}catch(t){return console.error("[VoiceCall] Mic error:",t),void g("idle")}e.emit("voice_start",{language:"es-AR",voice:"Kore"}),H.current=setInterval(()=>{x(e=>e+1)},1e3),Ie()}else console.error("[VoiceCall] Socket not connected")},[r,_e,Ce]),Ne=s(()=>{Ee(),fe.current.forEach(e=>{try{e.stop()}catch{}}),fe.current=[],de.current=[],he.current=0,pe.current=!1,ue.current?.close(),ue.current=null,H.current&&(clearInterval(H.current),H.current=null),le.current&&(clearInterval(le.current),le.current=null);const e=r?.();e?.connected&&(e.emit("voice_stop"),setTimeout(()=>{try{e.emit("request_history")}catch{}},1500)),Se(),g("idle"),C(0),x(0),_(!1),A([]),L(!1),j(null),R(void 0),B(void 0),q(void 0),W(!1),t()},[r,Ee,Se,t]);a(()=>{se.current=Ne},[Ne]);const Ae=s(()=>{ce.current=0,L(!1)},[]),Ie=s(()=>{ce.current=0,le.current&&clearInterval(le.current),le.current=setInterval(()=>{ce.current+=1;const e=ce.current;e>=90&&e<120&&L(!0),e>=120&&se.current()},1e3)},[]),Te=s(()=>{_(e=>!e)},[]),Oe=s(()=>{const e=O.trim();if(!e)return;const t=r?.();t?.connected&&(t.emit("voice_text_input",{text:e}),M(""),T(!1))},[O,r]);if(a(()=>{e&&"idle"===m&&ze()},[e]),a(()=>{ie.current?.scrollIntoView({behavior:"smooth"})},[N]),a(()=>()=>{Ee(),H.current&&clearInterval(H.current),Se()},[]),!e)return null;const Me="speaking"===m?h.speakingColor:"thinking"===m?h.thinkingColor:"listening"===m?h.listeningColor:n,Pe=V?F:o,Le=V?$:l,De=(V?U:c)||h.avatar3dUrl;let je=-1;for(let i=N.length-1;i>=0;i--)if(N[i].quizButtons&&N[i].quizButtons.length>0){je=i;break}const Fe=je>=0?N[je]:null;/* @__PURE__ */
106
+ return b("div",{className:"rounded-full transition-all duration-100",style:{width:"3px",height:`${a}px`,backgroundColor:n,opacity:e?.7-.3*i:.2}},o)})})}function Uc({isOpen:e,onClose:t,primaryColor:n="#10b981",getSocket:r,avatars:o,logoUrl:l,avatar3dUrl:c,voiceConfig:d,onCallEnded:p}){const h=u(()=>function(e,t="#10b981"){return{backgroundColor:e?.backgroundColor??"#0a0a0a",listeningColor:e?.listeningColor??"#10b981",speakingColor:e?.speakingColor??t,thinkingColor:e?.thinkingColor??"#a855f7",showEmojis:e?.showEmojis??!0,showEmotionLabel:e?.showEmotionLabel??!0,showWaveform:e?.showWaveform??!0,showBadge:e?.showBadge??!1,badgeText:e?.badgeText??"",emotionEmojis:{...Pc,...e?.emotionEmojis},statusLabels:{...Lc,...e?.statusLabels},orbSize:e?.orbSize??128,speakingScale:e?.speakingScale??1.08,thinkingScale:e?.thinkingScale??.95,avatar3dUrl:e?.avatar3dUrl,voiceGate:(n=e?.noiseGate,void 0===n||!0===n||"standard"===n?{...kc.standard}:!1===n||"off"===n?{...kc.off}:"string"==typeof n?{...kc[n]??kc.standard}:{...kc.standard,...n}),vad:!1!==e?.vad&&Cc(e?.vad),vadAssetBaseUrl:e?.vadAssetBaseUrl};var n}(d,n),[d,n]);!function(e){const t=f(null);a(()=>{const n="undefined"==typeof navigator?null:navigator.wakeLock??null;if(!e||!n)return;let r=!1;const o=async()=>{if(!t.current||t.current.released)try{const e=await n.request("screen");if(r)return void e.release();t.current=e,e.addEventListener("release",()=>{t.current===e&&(t.current=null)})}catch(e){Dt("[useWakeLock] Could not acquire screen wake lock",e)}},i=()=>{"visible"===document.visibilityState&&o()};return o(),document.addEventListener("visibilitychange",i),()=>{r=!0,document.removeEventListener("visibilitychange",i);const e=t.current;t.current=null,e&&!e.released&&e.release().catch(()=>{})}},[e])}(e);const[m,g]=i("idle"),[w,x]=i(0),[k,_]=i(!1),[S,C]=i(0),[E,z]=i(null),[N,A]=i([]),[I,T]=i(!1),[O,M]=i(""),[P,L]=i(!1),[D,j]=i(null),[F,R]=i(void 0),[$,B]=i(void 0),[U,q]=i(void 0),[V,W]=i(!1),H=f(null),Z=f(null),K=f(null),G=f(null),Y=f(null),te=f(0),ne=f(!1),oe=f(null),ie=f(null),se=f(()=>{}),le=f(null),ce=f(0),ue=f(null),de=f([]),pe=f(!1),he=f(0),fe=f([]),me=f(null),ge=f(null),be=f(1),ye=f(0),ve=s(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,"0")}`,[]),we=s(()=>{if(0===de.current.length)return;ue.current&&"closed"!==ue.current.state||(ue.current=new AudioContext({sampleRate:jc})),"suspended"===ue.current.state&&ue.current.resume().catch(()=>{});const e=ue.current;pe.current=!0,g("speaking");const t=e.currentTime;for(he.current<t&&(he.current=t);de.current.length>0;){const t=de.current.shift(),n=e.createBuffer(1,t.length,jc);n.getChannelData(0).set(t);const r=e.createBufferSource();r.buffer=n,r.connect(e.destination),r.start(he.current),fe.current.push(r),r.onended=()=>{fe.current=fe.current.filter(e=>e!==r),0===fe.current.length&&0===de.current.length&&(pe.current=!1,g(e=>"speaking"===e?"listening":e))},he.current+=t.length/jc}},[]),xe=s(()=>{fe.current.forEach(e=>{try{e.stop()}catch{}}),fe.current=[],de.current.length=0,he.current=0,pe.current=!1,g("listening")},[]),ke=f({}),_e=s(()=>{const e=r?.();if(!e||ne.current)return;const n=e=>{e&&(R(e.avatars||void 0),B(e.logoUrl||void 0),q(e.avatar3dUrl||void 0),W(!0))},o=e=>{g("listening"),n(e?.agentAvatar)},i=e=>{Ae();const t=(e?.agentName||"").toString().trim();j(t||"Nuevo agente"),n(e?.agentAvatar),A(e=>[...e,{role:"bot",text:t?`🔄 Continuás con ${t}.`:"🔄 Te derivé con el área correspondiente.",standalone:!0}])},a=e=>{if(!e?.data)return;const t=function(e){const t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);const r=new Int16Array(n.buffer),o=new Float32Array(r.length);for(let i=0;i<r.length;i++)o[i]=r[i]/32768;return o}(e.data);de.current.push(t),we(),Ae()},s=()=>{xe()},l=()=>{},c=e=>{console.error("[VoiceCall] Voice error:",e)},u=e=>{e?.emotion&&(z(e.emotion),setTimeout(()=>z(t=>t===e.emotion?null:t),4e3))},d=e=>{e?.text&&(Ae(),A(t=>{if(t.length>0&&"user"===t[t.length-1].role){const n=[...t],r=n[n.length-1].text,o=r.length>0&&!r.endsWith(" ")&&!e.text.startsWith(" ");return n[n.length-1]={...n[n.length-1],text:r+(o?" ":"")+e.text},n}return[...t,{role:"user",text:e.text}]}))},h=e=>{e?.text&&A(t=>{const n=t.map(e=>e.quizButtons?{...e,quizButtons:void 0}:e),r=n.map(e=>e.role).lastIndexOf("user");return r>=0?(n[r]={...n[r],text:e.text},n):[...n,{role:"user",text:e.text}]})},f=e=>{e?.text&&A(t=>{const n=[...t];for(let o=n.length-1;o>=0;o--)if("user"===n[o].role&&n[o].text===e.original)return n[o]={...n[o],text:e.text},n;const r=n.map(e=>e.role).lastIndexOf("user");return r>=0?(n[r]={...n[r],text:e.text},n):t})},m=e=>{e?.text&&(Ae(),A(t=>{const n=t[t.length-1];if(n&&"bot"===n.role&&!n.standalone){const r=[...t],o=n.text,i=o.length>0&&!o.endsWith(" ")&&!e.text.startsWith(" ");return r[r.length-1]={...n,text:o+(i?" ":"")+e.text},r}return[...t,{role:"bot",text:e.text}]}))},b=()=>{g("thinking"),Ae()},y=e=>{if(!e?.items?.length)return;if(Ae(),"present_quiz"===e.tool)return;if("show_content"===e.tool){const t=e.items.map(e=>"link"===e.type?`[${e.label||e.url}](${e.url})`:"image"===e.type?`![${e.label||""}](${e.url})`:e.label||"").filter(Boolean).join("\n");return void(t&&A(e=>[...e,{role:"bot",text:t,standalone:!0}]))}const t=e.items.map(t=>{if("search_accommodations"===e.tool){const e=t.options?.[0],n=e?`${e.totalPrice} ${e.currency}`:"",r=(t.features||[]).slice(0,3).join(" • "),o=t.cover?`![${t.title}](${t.cover})`:"",i=e?.link?`[Ver detalles](${e.link})`:"";return`${o}\n**${t.index}. ${t.title}**\n📍 ${t.location} ${t.rating?`⭐ ${t.rating}`:""}\n💰 ${n}\n${r}\n${i}`}if("get_accommodation_details"===e.tool){const e=(t.images||[]).slice(0,4).map(e=>`![](${e})`).join("\n"),n=t.specs?Object.entries(t.specs).map(([e,t])=>`${e}: ${t}`).join(" • "):"",r=(t.rooms||[]).map(e=>`• ${e.name}: ${e.price}`).join("\n"),o=t.rules?`🕐 Check-in: ${t.rules.checkIn||"-"} | Check-out: ${t.rules.checkOut||"-"} | Mascotas: ${t.rules.pets||"-"}`:"",i=t.seeMoreLink?`[Ver más detalles](${t.seeMoreLink})`:"";return`${e}\n**${t.title||t.name}**\n${t.description||""}\n${n}\n${r}\n${o}\n${i}`}if("card"===t.type&&t.content)return t.content;if("link"===t.type&&t.url)return`🔗 [${t.label||t.url}](${t.url})`;if("image"===t.type&&t.url)return`![${t.label||""}](${t.url})`;if(t.systemInstruction&&"string"==typeof t.systemInstruction)return t.systemInstruction;const n=t.signupUrl||t.url||t.link||t.redirectUrl||t.actionPayload?.signupUrl||t.actionPayload?.url;return n?`🔗 [${t.label||t.title||e.tool.replace(/_/g," ")}](${n})`:"error"===t.status?t.error||"Error al ejecutar la acción":""}).filter(Boolean).join("\n\n---\n\n");t&&A(e=>[...e,{role:"bot",text:t,standalone:!0}])},v=e=>{if("quiz_question"===e?.eventName&&e?.data){const{question:t,buttons:n}=e.data;t&&n?.length&&(Ae(),A(e=>[...e,{role:"bot",text:`📝 ${t}`,quizButtons:n,standalone:!0}]))}};ke.current={voiceReady:o,voiceAudioChunk:a,voiceInterrupted:s,voiceTurnComplete:l,voiceError:c,voiceEmotion:u,voiceUserTranscript:d,voiceUserTranscriptFinal:h,voiceUserTranscriptCorrected:f,voiceModelTranscript:m,voiceModelThinking:b,voiceToolVisual:y,voiceCustomEvent:v,voiceAgentSwitched:i},e.on("voice_ready",o),e.on("voice_audio_chunk",a),e.on("voice_interrupted",s),e.on("voice_turn_complete",l),e.on("voice_error",c),e.on("voice_emotion",u),e.on("voice_user_transcript",d),e.on("voice_user_transcript_final",h),e.on("voice_user_transcript_corrected",f),e.on("voice_model_transcript",m),e.on("voice_model_thinking",b),e.on("voice_tool_visual",y),e.on("custom_event",v),e.on("voice_agent_switched",i),e.on("voice_timeout",()=>{se.current()});const w=e=>{p?.(e?.reason),A(e=>[...e,{role:"bot",text:"📞 Llamada finalizada."}]);const n=r?.();n?.connected&&setTimeout(()=>{try{n.emit("request_history")}catch{}},1500),setTimeout(()=>{t()},2500)};e.on("voice_call_ended",w),ke.current.voiceCallEnded=w,ne.current=!0},[r,we,xe]),Se=s(()=>{const e=r?.();if(!e||!ne.current)return;const t=ke.current;t.voiceReady&&e.off("voice_ready",t.voiceReady),t.voiceAudioChunk&&e.off("voice_audio_chunk",t.voiceAudioChunk),t.voiceInterrupted&&e.off("voice_interrupted",t.voiceInterrupted),t.voiceTurnComplete&&e.off("voice_turn_complete",t.voiceTurnComplete),t.voiceError&&e.off("voice_error",t.voiceError),t.voiceEmotion&&e.off("voice_emotion",t.voiceEmotion),t.voiceUserTranscript&&e.off("voice_user_transcript",t.voiceUserTranscript),t.voiceUserTranscriptFinal&&e.off("voice_user_transcript_final",t.voiceUserTranscriptFinal),t.voiceUserTranscriptCorrected&&e.off("voice_user_transcript_corrected",t.voiceUserTranscriptCorrected),t.voiceModelTranscript&&e.off("voice_model_transcript",t.voiceModelTranscript),t.voiceModelThinking&&e.off("voice_model_thinking",t.voiceModelThinking),t.voiceToolVisual&&e.off("voice_tool_visual",t.voiceToolVisual),t.voiceCustomEvent&&e.off("custom_event",t.voiceCustomEvent),t.voiceAgentSwitched&&e.off("voice_agent_switched",t.voiceAgentSwitched),t.voiceCallEnded&&e.off("voice_call_ended",t.voiceCallEnded),e.off("voice_timeout"),ke.current={},ne.current=!1},[r]),Ce=s(async()=>{const e=r?.();if(!e)return;const t=await navigator.mediaDevices.getUserMedia({audio:ac});K.current=t;const n=!1!==h.vad;me.current=new Ec(n?h.vad:{energyOnly:!0}),be.current=1,ye.current=0,n&&async function(e){const t=e.loadVad??Tc;try{const n=await t(),r=(t,n)=>{e.onFrame({speechProb:t?.isSpeech??0,rms:Ic(n)})},o=await n.MicVAD.new(function(e,t){const n={model:e.model??"v5",baseAssetPath:e.assetBaseUrl??Nc,onnxWASMBasePath:e.onnxWasmBaseUrl??"https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/",startOnLoad:!1,onFrameProcessed:t};if(e.audioContext&&(n.audioContext=e.audioContext),e.stream){const t=e.stream;n.getStream=async()=>t,n.pauseStream=async()=>{},n.resumeStream=async()=>{}}return n}(e,r));return Rt("[VAD] Silero speech detector ready"),new Oc(o)}catch(n){return Dt("[VAD] Silero unavailable — falling back to energy gate",n),null}}({stream:t,assetBaseUrl:h.vadAssetBaseUrl,onFrame:({speechProb:e})=>{be.current=e,ye.current=performance.now()}}).then(e=>{if(e){if(K.current)return ge.current=e,e.start();e.destroy()}}).catch(()=>{});const o=new AudioContext({sampleRate:16e3});G.current=o,"suspended"===o.state&&await o.resume();const i=o.createMediaStreamSource(t),a=function(e,t){const n=e.createBiquadFilter();n.type="highpass",n.frequency.value=sc,n.Q.value=lc;const r=e.createBiquadFilter();r.type="highpass",r.frequency.value=cc,r.Q.value=uc;const o=e.createBiquadFilter();o.type="peaking",o.frequency.value=dc,o.Q.value=pc,o.gain.value=hc;const i=e.createBiquadFilter();i.type="lowpass",i.frequency.value=fc,i.Q.value=mc;const a=e.createDynamicsCompressor();return a.threshold.value=gc,a.knee.value=bc,a.ratio.value=yc,a.attack.value=vc,a.release.value=wc,t.connect(n),n.connect(r),r.connect(o),o.connect(i),i.connect(a),a}(o,i),s=o.createAnalyser();if(s.fftSize=256,a.connect(s),Z.current=s,!oe.current){const e=new Blob([_c(h.voiceGate)],{type:"application/javascript"});oe.current=URL.createObjectURL(e)}await o.audioWorklet.addModule(oe.current);const l=new AudioWorkletNode(o,"voice-pcm-processor");Y.current=l,l.port.onmessage=t=>{const n=me.current;if(!n)return;const r=performance.now()-ye.current<600,{frame:o,confirmedSpeech:i}=function(e){return e.botSpeaking&&!e.vadFresh?{frame:{speechProb:0,rms:0,botSpeaking:!0},confirmedSpeech:!1}:{frame:{speechProb:e.vadFresh?e.speechProb:1,rms:e.rms,botSpeaking:e.botSpeaking},confirmedSpeech:e.vadFresh}}({botSpeaking:pe.current,vadFresh:r,speechProb:be.current,rms:t.data.rms}),{shouldStream:a,event:s}=n.process(o);if("barge_in"===s&&xe(),a&&e.connected&&!k){const n=function(e){return e.confirmedSpeech||!e.vadFresh}({confirmedSpeech:i,vadFresh:r});e.emit("voice_audio_chunk",{data:Fc(t.data.pcm),speech:n})}},a.connect(l);const c=()=>{if(!Z.current)return;const e=new Uint8Array(Z.current.frequencyBinCount);Z.current.getByteFrequencyData(e);const t=e.reduce((e,t)=>e+t,0)/e.length;C(t/255),te.current=requestAnimationFrame(c)};c()},[r,k,h.voiceGate,h.vad,h.vadAssetBaseUrl,xe]),Ee=s(()=>{cancelAnimationFrame(te.current),ge.current?.destroy(),ge.current=null,me.current=null,be.current=1,ye.current=0,Y.current?.disconnect(),Y.current=null,K.current?.getTracks().forEach(e=>e.stop()),K.current=null,G.current?.close(),G.current=null,Z.current=null,C(0)},[]),ze=s(async()=>{const e=r?.();if(e?.connected){g("connecting"),x(0),A([]),z(null),R(void 0),B(void 0),q(void 0),W(!1),de.current=[],_e(),ue.current&&"closed"!==ue.current.state||(ue.current=new AudioContext({sampleRate:jc})),ue.current.resume().catch(()=>{});try{await Ce()}catch(t){return console.error("[VoiceCall] Mic error:",t),void g("idle")}e.emit("voice_start",{language:"es-AR",voice:"Kore"}),H.current=setInterval(()=>{x(e=>e+1)},1e3),Ie()}else console.error("[VoiceCall] Socket not connected")},[r,_e,Ce]),Ne=s(()=>{Ee(),fe.current.forEach(e=>{try{e.stop()}catch{}}),fe.current=[],de.current=[],he.current=0,pe.current=!1,ue.current?.close(),ue.current=null,H.current&&(clearInterval(H.current),H.current=null),le.current&&(clearInterval(le.current),le.current=null);const e=r?.();e?.connected&&(e.emit("voice_stop"),setTimeout(()=>{try{e.emit("request_history")}catch{}},1500)),Se(),g("idle"),C(0),x(0),_(!1),A([]),L(!1),j(null),R(void 0),B(void 0),q(void 0),W(!1),t()},[r,Ee,Se,t]);a(()=>{se.current=Ne},[Ne]);const Ae=s(()=>{ce.current=0,L(!1)},[]),Ie=s(()=>{ce.current=0,le.current&&clearInterval(le.current),le.current=setInterval(()=>{ce.current+=1;const e=ce.current;e>=90&&e<120&&L(!0),e>=120&&se.current()},1e3)},[]),Te=s(()=>{_(e=>!e)},[]),Oe=s(()=>{const e=O.trim();if(!e)return;const t=r?.();t?.connected&&(t.emit("voice_text_input",{text:e}),M(""),T(!1))},[O,r]);if(a(()=>{e&&"idle"===m&&ze()},[e]),a(()=>{ie.current?.scrollIntoView({behavior:"smooth"})},[N]),a(()=>()=>{Ee(),H.current&&clearInterval(H.current),Se()},[]),!e)return null;const Me="speaking"===m?h.speakingColor:"thinking"===m?h.thinkingColor:"listening"===m?h.listeningColor:n,Pe=V?F:o,Le=V?$:l,De=(V?U:c)||h.avatar3dUrl;let je=-1;for(let i=N.length-1;i>=0;i--)if(N[i].quizButtons&&N[i].quizButtons.length>0){je=i;break}const Fe=je>=0?N[je]:null;/* @__PURE__ */
107
107
  return y("div",{className:Et("absolute inset-0 z-50 flex flex-col overflow-hidden","animate-in fade-in duration-300"),style:{backgroundColor:"#0a0a0f",borderRadius:"inherit"},children:[
108
108
  /* @__PURE__ */y("div",{className:"absolute inset-0 pointer-events-none",style:{overflow:"hidden"},children:[
109
109
  /* @__PURE__ */b("div",{className:"absolute rounded-full",style:{width:"300px",height:"300px",top:"-80px",right:"-60px",background:`radial-gradient(circle, ${Me}18 0%, transparent 70%)`,transition:"background 1.5s ease",filter:"blur(40px)"}}),
@@ -196,4 +196,4 @@ return b("div",{style:{width:"100%",height:"100%",position:"relative",overflow:"
196
196
  /* @__PURE__ */b("directionalLight",{position:[-1,1,-1],intensity:.3,color:"#b4c6e7"}),
197
197
  /* @__PURE__ */b("pointLight",{position:[0,.5,-.5],intensity:.5,distance:3}),
198
198
  /* @__PURE__ */b(Tb,{url:e,autoRotate:o,hasCustomCamera:!(!n||!r)})]})})}):null}const Pb="https://api.botuyo.com";class Lb extends m{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){console.error("[BotUyoChat] Widget error:",e,t)}render(){return this.state.hasError?null:this.props.children}}const Db={"--background":"240 10% 3.9%","--foreground":"0 0% 98%","--card":"240 10% 3.9%","--card-foreground":"0 0% 98%","--primary":"160 84% 39%","--primary-foreground":"0 0% 100%","--muted":"240 3.7% 15.9%","--muted-foreground":"240 5% 64.9%","--border":"240 3.7% 15.9%"},jb=p(()=>Promise.resolve().then(()=>Ab).then(e=>({default:e.ChatWidgetWithProviders})));class Fb{root=null;container=null;shadowRoot=null;mountPoint=null;darkModeObserver=null;darkModeMediaQuery=null;config=null;init(e){return this.config={...e,apiBaseUrl:e.apiBaseUrl||Pb},this.render(),this.setupDarkModeDetection(),this}render(){if(!this.config)return void console.error("[BotUyoChat] No configuration provided");if(!this.container){this.container=document.createElement("div"),this.container.id="botuyo-chat-widget-root",document.body.appendChild(this.container),this.shadowRoot=this.container.attachShadow({mode:"open"});const e=document.createElement("style");e.textContent=L.replace(/:root/g,":host"),this.shadowRoot.appendChild(e),this.mountPoint=document.createElement("div"),this.mountPoint.id="botuyo-chat-widget-root",this.shadowRoot.appendChild(this.mountPoint)}if(this.config.theme?.cssVariables&&this.mountPoint){const e=this.config.theme.cssVariables;[["--background",e.background],["--foreground",e.foreground],["--card",e.card],["--card-foreground",e.cardForeground],["--primary",e.primary],["--primary-foreground",e.primaryForeground],["--muted",e.muted],["--muted-foreground",e.mutedForeground],["--border",e.border],["--destructive",e.destructive],["--radius",e.radius],["--window-border-radius",e.windowBorderRadius],["--launcher-border-radius",e.launcherBorderRadius],["--window-height",e.windowHeight],["--window-bottom",e.windowBottom],["--spacing-1",e.spacing1],["--spacing-2",e.spacing2],["--spacing-3",e.spacing3],["--spacing-4",e.spacing4],["--spacing-5",e.spacing5],["--spacing-6",e.spacing6],["--spacing-7",e.spacing7],["--spacing-8",e.spacing8]].forEach(([e,t])=>{void 0!==t&&this.mountPoint.style.setProperty(e,t)})}this.mountPoint&&!this.config.theme?.cssVariables&&(!function(){const e=document.documentElement.getAttribute("data-theme");return"dark"===e||"light"!==e&&window.matchMedia("(prefers-color-scheme: dark)").matches}()?Object.keys(Db).forEach(e=>{this.mountPoint.style.removeProperty(e)}):Object.entries(Db).forEach(([e,t])=>{this.mountPoint.style.setProperty(e,t)})),!this.root&&this.mountPoint&&(this.root=e(this.mountPoint));const t={apiKey:this.config.apiKey,apiBaseUrl:this.config.apiBaseUrl||Pb,agentId:this.config.agentId,theme:{botName:"Asistente Virtual",position:"bottom-right",welcomeMessage:"¡Hola! 👋 ¿En qué puedo ayudarte?",inputPlaceholder:"Escribe tu mensaje...",cssVariables:{primary:"160 84% 39%",windowBorderRadius:"24px",launcherBorderRadius:"50%"},...this.config.theme},userContext:this.config.userContext,pageContext:this.config.pageContext,includeSEOMetadata:this.config.includeSEOMetadata??!1,mediaConfig:this.config.mediaConfig,onNavigate:this.config.onNavigate,onLogin:this.config.onLogin,onEvent:this.config.onEvent,onStateChange:this.config.onStateChange},r=n.createElement(h,{fallback:n.createElement("div",{style:{position:"fixed",bottom:"24px",right:"24px",width:"60px",height:"60px",borderRadius:"50%",backgroundColor:"#10b981",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",cursor:"wait"}},n.createElement("div",{style:{width:"24px",height:"24px",border:"3px solid rgba(255, 255, 255, 0.3)",borderTopColor:"#fff",borderRadius:"50%",animation:"spin 1s linear infinite"}}))},n.createElement(jb,t));this.root.render(n.createElement(Lb,null,n.createElement(M,{defaultLocale:this.config.theme?.defaultLocale,children:r}))),console.log("[BotUyoChat] Widget initialized",t)}update(e){this.config?(this.config={...this.config,...e,theme:{...this.config.theme,...e.theme}},this.render()):console.error("[BotUyoChat] Widget not initialized")}destroy(){this.darkModeObserver&&(this.darkModeObserver.disconnect(),this.darkModeObserver=null),this.darkModeMediaQuery&&(this.darkModeMediaQuery.removeEventListener("change",this.handleDarkModeChange),this.darkModeMediaQuery=null),this.root&&(this.root.unmount(),this.root=null),this.container&&this.container.parentNode&&(this.container.parentNode.removeChild(this.container),this.container=null,this.shadowRoot=null,this.mountPoint=null),this.config=null,console.log("[BotUyoChat] Widget destroyed")}setupDarkModeDetection(){this.config?.theme?.cssVariables||(this.handleDarkModeChange=()=>this.render(),this.darkModeObserver=new MutationObserver(this.handleDarkModeChange),this.darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),this.darkModeMediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),this.darkModeMediaQuery.addEventListener("change",this.handleDarkModeChange))}handleDarkModeChange=()=>{};open(){window.dispatchEvent(new CustomEvent("botuyo-chat:open"))}close(){window.dispatchEvent(new CustomEvent("botuyo-chat:close"))}startCall(){window.dispatchEvent(new CustomEvent("botuyo-chat:start-call"))}sendMessage(e){window.dispatchEvent(new CustomEvent("botuyo-chat:send-message",{detail:{message:e}}))}getState(){return null}}const Rb=new Fb;window.BotUyoChat=Rb;export{Mb as A,Fb as B,Nb as C,K as L,Ib as P,se as X,Et as a,xb as b,$ as c,zb as d,M as e,kb as f,At as g,P as h,Rb as i,D as u};
199
- //# sourceMappingURL=standalone-DN84q-yx.js.map
199
+ //# sourceMappingURL=standalone-DOLAS_vS.js.map