@botuyo/chat-widget-standalone 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AudioPlayer-D0c-fLlI.js → AudioPlayer-DMcR7gZw.js} +2 -2
- package/dist/{AudioPlayer-D0c-fLlI.js.map → AudioPlayer-DMcR7gZw.js.map} +1 -1
- package/dist/{Gallery-DAgN2s6U.js → Gallery-Bpfz_yGW.js} +2 -2
- package/dist/{Gallery-DAgN2s6U.js.map → Gallery-Bpfz_yGW.js.map} +1 -1
- package/dist/botuyo-chat.es.js +1 -1
- package/dist/botuyo-chat.umd.js +1 -1
- package/dist/botuyo-chat.umd.js.map +1 -1
- package/dist/src/chat-widget/components/VoiceCallOverlay.d.ts.map +1 -1
- package/dist/{standalone-BTJrjLfC.js → standalone-BpzprslZ.js} +14 -14
- package/dist/{standalone-BTJrjLfC.js.map → standalone-BpzprslZ.js.map} +1 -1
- package/dist/stats-umd.html +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceCallOverlay.d.ts","sourceRoot":"","sources":["../../../../src/chat-widget/components/VoiceCallOverlay.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
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;AAMlC,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;CAC7B;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;AAwb9E,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,kDA43CvB"}
|
|
@@ -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-
|
|
18
|
+
/* @__PURE__ */b(W,{size:9}),e]},`${e}-${t}`))})]}):null}),Ul=p(()=>import("./AudioPlayer-DMcR7gZw.js").then(e=>({default:e.AudioPlayer}))),ql=p(()=>import("./Gallery-Bpfz_yGW.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__ */
|
|
@@ -98,35 +98,35 @@ return y("div",n&&!d?{className:"relative flex flex-col items-center gap-4",chil
|
|
|
98
98
|
/* @__PURE__ */b("div",{className:"absolute rounded-full",style:{inset:"12px",border:`1px solid ${g}15`,animation:m?"spin 12s linear infinite reverse":"none"}}),
|
|
99
99
|
/* @__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(Ic,{isActive:m,audioLevel:a,color:g})]})}function Ic({isActive:e,audioLevel:t,color:n}){/* @__PURE__ */
|
|
100
100
|
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__ */
|
|
101
|
-
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 Tc({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:{...Sc,...e?.emotionEmojis},statusLabels:{...Cc,...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?{...xc.standard}:!1===n||"off"===n?{...xc.off}:"string"==typeof n?{...xc[n]??xc.standard}:{...xc.standard,...n})};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=f(null),R=f(null),$=f(null),B=f(null),U=f(null),q=f(0),V=f(!1),W=f(null),H=f(null),Z=f(()=>{}),K=f(null),G=f(0),Y=f(null),te=f([]),ne=f(!1),oe=f(0),ie=f([]),se=s(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,"0")}`,[]),le=s(()=>{if(0===te.current.length)return;Y.current&&"closed"!==Y.current.state||(Y.current=new AudioContext({sampleRate:zc})),"suspended"===Y.current.state&&Y.current.resume().catch(()=>{});const e=Y.current;ne.current=!0,g("speaking");const t=e.currentTime;for(oe.current<t&&(oe.current=t);te.current.length>0;){const t=te.current.shift(),n=e.createBuffer(1,t.length,zc);n.getChannelData(0).set(t);const r=e.createBufferSource();r.buffer=n,r.connect(e.destination),r.start(oe.current),ie.current.push(r),r.onended=()=>{ie.current=ie.current.filter(e=>e!==r),0===ie.current.length&&0===te.current.length&&(ne.current=!1,g(e=>"speaking"===e?"listening":e))},oe.current+=t.length/zc}},[]),ce=f({}),ue=s(()=>{const e=r?.();if(!e||V.current)return;const n=()=>{g("listening")},o=e=>{ge();const t=(e?.agentName||"").toString().trim();j(t||"Nuevo agente"),A(e=>[...e,{role:"bot",text:t?`🔄 Continuás con ${t}.`:"🔄 Te derivé con el área correspondiente.",standalone:!0}])},i=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);te.current.push(t),le(),ge()},a=()=>{ie.current.forEach(e=>{try{e.stop()}catch{}}),ie.current=[],te.current.length=0,oe.current=0,ne.current=!1,g("listening")},s=()=>{},l=e=>{console.error("[VoiceCall] Voice error:",e)},c=e=>{e?.emotion&&(z(e.emotion),setTimeout(()=>z(t=>t===e.emotion?null:t),4e3))},u=e=>{e?.text&&(ge(),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}]}))},d=e=>{e?.text&&A(t=>{const n=t.map(e=>e.role).lastIndexOf("user");if(n>=0){const r=[...t];return r[n]={...r[n],text:e.text},r}return[...t,{role:"user",text:e.text}]})},h=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})},f=e=>{e?.text&&(ge(),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}]}))},m=()=>{g("thinking"),ge()},b=e=>{if(!e?.items?.length)return;if(ge(),"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||"").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?``:"",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=>``).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``;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}])},y=e=>{if("quiz_question"===e?.eventName&&e?.data){const{question:t,buttons:n}=e.data;t&&n?.length&&(ge(),A(e=>[...e,{role:"bot",text:`📝 ${t}`,quizButtons:n,standalone:!0}]))}};ce.current={voiceReady:n,voiceAudioChunk:i,voiceInterrupted:a,voiceTurnComplete:s,voiceError:l,voiceEmotion:c,voiceUserTranscript:u,voiceUserTranscriptFinal:d,voiceUserTranscriptCorrected:h,voiceModelTranscript:f,voiceModelThinking:m,voiceToolVisual:b,voiceCustomEvent:y,voiceAgentSwitched:o},e.on("voice_ready",n),e.on("voice_audio_chunk",i),e.on("voice_interrupted",a),e.on("voice_turn_complete",s),e.on("voice_error",l),e.on("voice_emotion",c),e.on("voice_user_transcript",u),e.on("voice_user_transcript_final",d),e.on("voice_user_transcript_corrected",h),e.on("voice_model_transcript",f),e.on("voice_model_thinking",m),e.on("voice_tool_visual",b),e.on("custom_event",y),e.on("voice_agent_switched",o),e.on("voice_timeout",()=>{Z.current()});const v=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",v),ce.current.voiceCallEnded=v,V.current=!0},[r,le]),de=s(()=>{const e=r?.();if(!e||!V.current)return;const t=ce.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"),ce.current={},V.current=!1},[r]),pe=s(async()=>{const e=r?.();if(!e)return;const t=await navigator.mediaDevices.getUserMedia({audio:ic});$.current=t;const n=new AudioContext({sampleRate:16e3});B.current=n,"suspended"===n.state&&await n.resume();const o=n.createMediaStreamSource(t),i=function(e,t){const n=e.createBiquadFilter();n.type="highpass",n.frequency.value=ac,n.Q.value=sc;const r=e.createBiquadFilter();r.type="highpass",r.frequency.value=lc,r.Q.value=cc;const o=e.createBiquadFilter();o.type="peaking",o.frequency.value=uc,o.Q.value=dc,o.gain.value=pc;const i=e.createBiquadFilter();i.type="lowpass",i.frequency.value=hc,i.Q.value=fc;const a=e.createDynamicsCompressor();return a.threshold.value=mc,a.knee.value=gc,a.ratio.value=bc,a.attack.value=yc,a.release.value=vc,t.connect(n),n.connect(r),r.connect(o),o.connect(i),i.connect(a),a}(n,o),a=n.createAnalyser();if(a.fftSize=256,i.connect(a),R.current=a,!W.current){const e=new Blob([kc(h.voiceGate)],{type:"application/javascript"});W.current=URL.createObjectURL(e)}await n.audioWorklet.addModule(W.current);const s=new AudioWorkletNode(n,"voice-pcm-processor");U.current=s,s.port.onmessage=t=>{if(e.connected&&!k){const n=function(e){const t=new Uint8Array(e);let n="";for(let r=0;r<t.byteLength;r++)n+=String.fromCharCode(t[r]);return btoa(n)}(t.data);e.emit("voice_audio_chunk",{data:n})}},i.connect(s);const l=()=>{if(!R.current)return;const e=new Uint8Array(R.current.frequencyBinCount);R.current.getByteFrequencyData(e);const t=e.reduce((e,t)=>e+t,0)/e.length;C(t/255),q.current=requestAnimationFrame(l)};l()},[r,k,h.voiceGate]),he=s(()=>{cancelAnimationFrame(q.current),U.current?.disconnect(),U.current=null,$.current?.getTracks().forEach(e=>e.stop()),$.current=null,B.current?.close(),B.current=null,R.current=null,C(0)},[]),fe=s(async()=>{const e=r?.();if(e?.connected){g("connecting"),x(0),A([]),z(null),te.current=[],ue(),Y.current&&"closed"!==Y.current.state||(Y.current=new AudioContext({sampleRate:zc})),Y.current.resume().catch(()=>{});try{await pe()}catch(t){return console.error("[VoiceCall] Mic error:",t),void g("idle")}e.emit("voice_start",{language:"es-AR",voice:"Kore"}),F.current=setInterval(()=>{x(e=>e+1)},1e3),be()}else console.error("[VoiceCall] Socket not connected")},[r,ue,pe]),me=s(()=>{he(),ie.current.forEach(e=>{try{e.stop()}catch{}}),ie.current=[],te.current=[],oe.current=0,ne.current=!1,Y.current?.close(),Y.current=null,F.current&&(clearInterval(F.current),F.current=null),K.current&&(clearInterval(K.current),K.current=null);const e=r?.();e?.connected&&(e.emit("voice_stop"),setTimeout(()=>{try{e.emit("request_history")}catch{}},1500)),de(),g("idle"),C(0),x(0),_(!1),A([]),L(!1),j(null),t()},[r,he,de,t]);a(()=>{Z.current=me},[me]);const ge=s(()=>{G.current=0,L(!1)},[]),be=s(()=>{G.current=0,K.current&&clearInterval(K.current),K.current=setInterval(()=>{G.current+=1;const e=G.current;e>=90&&e<120&&L(!0),e>=120&&Z.current()},1e3)},[]),ye=s(()=>{_(e=>!e)},[]),ve=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&&fe()},[e]),a(()=>{H.current?.scrollIntoView({behavior:"smooth"})},[N]),a(()=>()=>{he(),F.current&&clearInterval(F.current),de()},[]),!e)return null;const we="speaking"===m?h.speakingColor:"thinking"===m?h.thinkingColor:"listening"===m?h.listeningColor:n;/* @__PURE__ */
|
|
101
|
+
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 Tc({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:{...Sc,...e?.emotionEmojis},statusLabels:{...Cc,...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?{...xc.standard}:!1===n||"off"===n?{...xc.off}:"string"==typeof n?{...xc[n]??xc.standard}:{...xc.standard,...n})};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=s(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,"0")}`,[]),ge=s(()=>{if(0===de.current.length)return;ue.current&&"closed"!==ue.current.state||(ue.current=new AudioContext({sampleRate:zc})),"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,zc);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/zc}},[]),be=f({}),ye=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=>{Se();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),ge(),Se()},s=()=>{fe.current.forEach(e=>{try{e.stop()}catch{}}),fe.current=[],de.current.length=0,he.current=0,pe.current=!1,g("listening")},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&&(Se(),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.role).lastIndexOf("user");if(n>=0){const r=[...t];return r[n]={...r[n],text:e.text},r}return[...t,{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&&(Se(),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"),Se()},y=e=>{if(!e?.items?.length)return;if(Se(),"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||"").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?``:"",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=>``).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``;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&&(Se(),A(e=>[...e,{role:"bot",text:`📝 ${t}`,quizButtons:n,standalone:!0}]))}};be.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),be.current.voiceCallEnded=w,ne.current=!0},[r,ge]),ve=s(()=>{const e=r?.();if(!e||!ne.current)return;const t=be.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"),be.current={},ne.current=!1},[r]),we=s(async()=>{const e=r?.();if(!e)return;const t=await navigator.mediaDevices.getUserMedia({audio:ic});K.current=t;const n=new AudioContext({sampleRate:16e3});G.current=n,"suspended"===n.state&&await n.resume();const o=n.createMediaStreamSource(t),i=function(e,t){const n=e.createBiquadFilter();n.type="highpass",n.frequency.value=ac,n.Q.value=sc;const r=e.createBiquadFilter();r.type="highpass",r.frequency.value=lc,r.Q.value=cc;const o=e.createBiquadFilter();o.type="peaking",o.frequency.value=uc,o.Q.value=dc,o.gain.value=pc;const i=e.createBiquadFilter();i.type="lowpass",i.frequency.value=hc,i.Q.value=fc;const a=e.createDynamicsCompressor();return a.threshold.value=mc,a.knee.value=gc,a.ratio.value=bc,a.attack.value=yc,a.release.value=vc,t.connect(n),n.connect(r),r.connect(o),o.connect(i),i.connect(a),a}(n,o),a=n.createAnalyser();if(a.fftSize=256,i.connect(a),Z.current=a,!oe.current){const e=new Blob([kc(h.voiceGate)],{type:"application/javascript"});oe.current=URL.createObjectURL(e)}await n.audioWorklet.addModule(oe.current);const s=new AudioWorkletNode(n,"voice-pcm-processor");Y.current=s,s.port.onmessage=t=>{if(e.connected&&!k){const n=function(e){const t=new Uint8Array(e);let n="";for(let r=0;r<t.byteLength;r++)n+=String.fromCharCode(t[r]);return btoa(n)}(t.data);e.emit("voice_audio_chunk",{data:n})}},i.connect(s);const l=()=>{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(l)};l()},[r,k,h.voiceGate]),xe=s(()=>{cancelAnimationFrame(te.current),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)},[]),ke=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=[],ye(),ue.current&&"closed"!==ue.current.state||(ue.current=new AudioContext({sampleRate:zc})),ue.current.resume().catch(()=>{});try{await we()}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),Ce()}else console.error("[VoiceCall] Socket not connected")},[r,ye,we]),_e=s(()=>{xe(),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)),ve(),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,xe,ve,t]);a(()=>{se.current=_e},[_e]);const Se=s(()=>{ce.current=0,L(!1)},[]),Ce=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)},[]),Ee=s(()=>{_(e=>!e)},[]),ze=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&&ke()},[e]),a(()=>{ie.current?.scrollIntoView({behavior:"smooth"})},[N]),a(()=>()=>{xe(),H.current&&clearInterval(H.current),ve()},[]),!e)return null;const Ne="speaking"===m?h.speakingColor:"thinking"===m?h.thinkingColor:"listening"===m?h.listeningColor:n,Ae=V?F:o,Ie=V?$:l,Te=(V?U:c)||h.avatar3dUrl;/* @__PURE__ */
|
|
102
102
|
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:[
|
|
103
103
|
/* @__PURE__ */y("div",{className:"absolute inset-0 pointer-events-none",style:{overflow:"hidden"},children:[
|
|
104
|
-
/* @__PURE__ */b("div",{className:"absolute rounded-full",style:{width:"300px",height:"300px",top:"-80px",right:"-60px",background:`radial-gradient(circle, ${
|
|
104
|
+
/* @__PURE__ */b("div",{className:"absolute rounded-full",style:{width:"300px",height:"300px",top:"-80px",right:"-60px",background:`radial-gradient(circle, ${Ne}18 0%, transparent 70%)`,transition:"background 1.5s ease",filter:"blur(40px)"}}),
|
|
105
105
|
/* @__PURE__ */b("div",{className:"absolute rounded-full",style:{width:"250px",height:"250px",bottom:"-40px",left:"-50px",background:`radial-gradient(circle, ${h.thinkingColor}12 0%, transparent 70%)`,filter:"blur(50px)"}}),
|
|
106
|
-
/* @__PURE__ */b("div",{className:"absolute rounded-full",style:{width:"200px",height:"200px",top:"40%",left:"50%",transform:"translateX(-50%)",background:`radial-gradient(circle, ${
|
|
106
|
+
/* @__PURE__ */b("div",{className:"absolute rounded-full",style:{width:"200px",height:"200px",top:"40%",left:"50%",transform:"translateX(-50%)",background:`radial-gradient(circle, ${Ne}10 0%, transparent 70%)`,transition:"background 1.5s ease",filter:"blur(60px)"}})]}),
|
|
107
107
|
/* @__PURE__ */y("div",{className:"relative flex items-center justify-between",style:{background:"rgba(255,255,255,0.03)",borderBottom:"1px solid rgba(255,255,255,0.06)",padding:"16px 24px",paddingTop:"20px"},children:[
|
|
108
108
|
/* @__PURE__ */y("div",{className:"flex items-center gap-3",children:[
|
|
109
|
-
/* @__PURE__ */b("div",{className:"relative",children:/* @__PURE__ */b("div",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:
|
|
109
|
+
/* @__PURE__ */b("div",{className:"relative",children:/* @__PURE__ */b("div",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:Ne,boxShadow:`0 0 8px ${Ne}80`,animation:"idle"!==m?"pulse 2s ease-in-out infinite":"none"}})}),
|
|
110
110
|
/* @__PURE__ */b("span",{style:{color:"rgba(255,255,255,0.8)",fontSize:"13px",fontWeight:500,letterSpacing:"-0.01em"},children:h.statusLabels[m]||m})]}),
|
|
111
|
-
/* @__PURE__ */y("div",{className:"flex items-center gap-3",children:[h.showEmotionLabel&&E&&/* @__PURE__ */y("span",{style:{fontSize:"11px",padding:"2px 10px",borderRadius:"20px",background:`${
|
|
112
|
-
/* @__PURE__ */b("span",{style:{fontSize:"13px",fontFamily:"ui-monospace, monospace",color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums"},children:
|
|
111
|
+
/* @__PURE__ */y("div",{className:"flex items-center gap-3",children:[h.showEmotionLabel&&E&&/* @__PURE__ */y("span",{style:{fontSize:"11px",padding:"2px 10px",borderRadius:"20px",background:`${Ne}15`,border:`1px solid ${Ne}25`,color:Ne,fontWeight:600},children:[h.showEmojis&&(h.emotionEmojis[E]||"💬")," ",E]}),D&&/* @__PURE__ */y("span",{style:{fontSize:"11px",padding:"2px 10px",borderRadius:"20px",background:`${n}22`,border:`1px solid ${n}44`,color:"#fff",fontWeight:600},children:["🔄 ",D]}),
|
|
112
|
+
/* @__PURE__ */b("span",{style:{fontSize:"13px",fontFamily:"ui-monospace, monospace",color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums"},children:me(w)}),P&&(()=>{const e=120-ce.current,t=e<=15;/* @__PURE__ */
|
|
113
113
|
return y("span",{style:{fontSize:"10px",padding:"2px 8px",borderRadius:"12px",backgroundColor:t?"rgba(239,68,68,0.2)":"rgba(245,158,11,0.15)",color:t?"#ef4444":"#f59e0b",fontWeight:700,fontVariantNumeric:"tabular-nums",animation:t?"pulse 1s ease-in-out infinite":"none"},children:["⏸ Inactivo — ",e>0?e:0,"s"]})})()]})]}),h.showBadge&&h.badgeText&&/* @__PURE__ */b("div",{style:{display:"flex",justifyContent:"center",padding:"8px 0"},children:/* @__PURE__ */b("span",{style:{padding:"4px 14px",borderRadius:"20px",fontSize:"11px",fontWeight:700,background:`linear-gradient(135deg, ${n}, ${h.thinkingColor})`,color:"white"},children:h.badgeText})}),
|
|
114
|
-
/* @__PURE__ */b("div",{className:"relative shrink-0 flex justify-center",style:{padding:"16px 20px 8px"},children:/* @__PURE__ */b(Ac,{avatars:
|
|
114
|
+
/* @__PURE__ */b("div",{className:"relative shrink-0 flex justify-center",style:{padding:"16px 20px 8px"},children:/* @__PURE__ */b(Ac,{avatars:Ae,logoUrl:Ie,avatar3dUrl:Te,emotion:E,callState:m,audioLevel:S,config:h})}),
|
|
115
115
|
/* @__PURE__ */b("div",{className:"relative flex-1 overflow-y-auto px-5 pb-4",style:{scrollbarWidth:"none"},children:/* @__PURE__ */b("div",{className:"flex flex-col gap-4 w-full",children:N.length>0&&/* @__PURE__ */y("div",{style:{display:"flex",flexDirection:"column",gap:"12px",width:"100%"},children:[N.map((e,t)=>/* @__PURE__ */y("div",{style:{maxWidth:"85%",padding:"10px 14px",borderRadius:"user"===e.role?"16px 16px 4px 16px":"16px 16px 16px 4px",fontSize:"13.5px",lineHeight:1.5,color:"white",marginLeft:"user"===e.role?"auto":"0",marginRight:"user"===e.role?"0":"auto",backgroundColor:"user"===e.role?"rgba(255,255,255,0.08)":`${n}25`,backdropFilter:"blur(8px)",border:"user"===e.role?"1px solid rgba(255,255,255,0.08)":`1px solid ${n}20`},children:[
|
|
116
116
|
/* @__PURE__ */b("div",{className:"prose prose-sm prose-invert max-w-none break-words leading-relaxed",style:{fontSize:"13.5px"},children:/* @__PURE__ */b(ja,{remarkPlugins:[Il],rehypePlugins:[[$l,Ec]],components:{p:({children:e})=>/* @__PURE__ */b("p",{style:{margin:"0 0 4px"},children:e}),a:({href:e,children:t})=>{if(!e)return null;const r=String(t).toLowerCase(),o=r.includes("reservar")||r.includes("ver")||r.includes("pagar");return e.includes("maps.google")||e.includes("goo.gl")||e.includes("google.com/maps")?/* @__PURE__ */b("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",margin:"6px 0",borderRadius:"10px",background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.1)",color:n,textDecoration:"none",fontSize:"12px",fontWeight:700},children:"📍 Ver ubicación"}):o?/* @__PURE__ */y("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",margin:"6px 0",borderRadius:"10px",background:n,color:"white",textDecoration:"none",fontSize:"11px",fontWeight:800,letterSpacing:"0.05em",textTransform:"uppercase",width:"100%",textAlign:"center"},children:[t," →"]}):/* @__PURE__ */b("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:n,textDecoration:"underline",fontWeight:600},children:t})},strong:({children:e})=>/* @__PURE__ */b("strong",{style:{fontWeight:700,color:"rgba(255,255,255,0.95)"},children:e}),em:({children:e})=>/* @__PURE__ */b("em",{style:{color:"rgba(255,255,255,0.8)"},children:e}),ul:({children:e})=>/* @__PURE__ */b("ul",{style:{margin:"4px 0",paddingLeft:"18px"},children:e}),ol:({children:e})=>/* @__PURE__ */b("ol",{style:{margin:"4px 0",paddingLeft:"18px"},children:e}),li:({children:e})=>/* @__PURE__ */b("li",{style:{marginBottom:"2px"},children:e}),hr:()=>/* @__PURE__ */b("hr",{style:{border:"none",borderTop:"1px solid rgba(255,255,255,0.1)",margin:"8px 0"}}),img:({src:e,alt:t})=>/* @__PURE__ */b("img",{src:e,alt:t||"",style:{maxWidth:"100%",borderRadius:"8px",margin:"6px 0"}}),code:({children:e})=>/* @__PURE__ */b("code",{style:{background:"rgba(255,255,255,0.1)",padding:"1px 5px",borderRadius:"4px",fontSize:"12px"},children:e})},children:e.text})}),e.quizButtons&&e.quizButtons.length>0&&/* @__PURE__ */b("div",{style:{display:"flex",flexDirection:"column",gap:"10px",marginTop:"14px"},children:e.quizButtons.map((e,o)=>/* @__PURE__ */y("button",{onClick:()=>{const n=r?.();n?.connected&&n.emit("voice_text_input",{text:`Answer: ${e.label}`}),A(n=>[...n.map((e,n)=>n===t?{...e,quizButtons:void 0}:e),{role:"user",text:e.label}])},style:{display:"flex",alignItems:"center",gap:"12px",width:"100%",padding:"14px 16px",borderRadius:"14px",border:"1px solid rgba(255,255,255,0.18)",background:`linear-gradient(135deg, ${n}, ${n}cc)`,color:"white",fontSize:"14px",fontWeight:700,cursor:"pointer",textAlign:"left",boxShadow:`0 4px 14px ${n}55, inset 0 1px 0 rgba(255,255,255,0.25)`,transition:"all 150ms ease"},onMouseEnter:e=>{e.currentTarget.style.transform="translateY(-2px)",e.currentTarget.style.boxShadow=`0 8px 22px ${n}77, inset 0 1px 0 rgba(255,255,255,0.3)`},onMouseLeave:e=>{e.currentTarget.style.transform="translateY(0)",e.currentTarget.style.boxShadow=`0 4px 14px ${n}55, inset 0 1px 0 rgba(255,255,255,0.25)`},children:[
|
|
117
117
|
/* @__PURE__ */b("span",{style:{flexShrink:0,width:"22px",height:"22px",borderRadius:"50%",background:"#ffffff",color:n,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:700},children:o+1}),
|
|
118
118
|
/* @__PURE__ */b("span",{style:{flex:1},children:e.label})]},e.id))})]},t)),
|
|
119
|
-
/* @__PURE__ */b("div",{ref:
|
|
119
|
+
/* @__PURE__ */b("div",{ref:ie})]})})}),
|
|
120
120
|
/* @__PURE__ */b("div",{style:{textAlign:"center",paddingBottom:"12px"},children:/* @__PURE__ */b("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 16px",borderRadius:"20px",fontSize:"11px",fontWeight:500,color:"rgba(255,255,255,0.35)",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.06)",letterSpacing:"0.02em"},children:k?/* @__PURE__ */y(v,{children:[
|
|
121
121
|
/* @__PURE__ */b(Q,{style:{width:"12px",height:"12px"}})," Micrófono silenciado"]}):"thinking"===m?"Procesando...":"speaking"===m?/* @__PURE__ */y(v,{children:[
|
|
122
122
|
/* @__PURE__ */b(ae,{style:{width:"12px",height:"12px"}})," Respuesta de voz"]}):"Habla cuando quieras"})}),
|
|
123
123
|
/* @__PURE__ */y("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"20px",paddingBottom:"28px",paddingTop:"8px"},children:[
|
|
124
|
-
/* @__PURE__ */b("button",{onClick:
|
|
125
|
-
/* @__PURE__ */b("button",{onClick:
|
|
124
|
+
/* @__PURE__ */b("button",{onClick:Ee,style:{width:"52px",height:"52px",borderRadius:"50%",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s",backgroundColor:k?"rgba(239,68,68,0.15)":"rgba(255,255,255,0.08)",color:k?"#f87171":"rgba(255,255,255,0.7)",backdropFilter:"blur(12px)",border:"1px solid "+(k?"rgba(239,68,68,0.2)":"rgba(255,255,255,0.08)")},"aria-label":k?"Activar micrófono":"Silenciar micrófono",children:/* @__PURE__ */b(k?Q:X,{style:{width:"22px",height:"22px"}})}),
|
|
125
|
+
/* @__PURE__ */b("button",{onClick:_e,style:{width:"64px",height:"64px",borderRadius:"50%",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#ef4444",color:"white",boxShadow:"0 4px 24px rgba(239,68,68,0.4), 0 0 0 4px rgba(239,68,68,0.1)",transition:"all 0.2s"},"aria-label":"Finalizar llamada",children:/* @__PURE__ */b(ee,{style:{width:"26px",height:"26px"}})}),
|
|
126
126
|
/* @__PURE__ */b("div",{style:{width:"52px",height:"52px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"speaking"===m?`${h.listeningColor}15`:"rgba(255,255,255,0.08)",color:"speaking"===m?h.listeningColor:"rgba(255,255,255,0.5)",border:"1px solid "+("speaking"===m?`${h.listeningColor}25`:"rgba(255,255,255,0.08)"),transition:"all 0.3s"},children:/* @__PURE__ */b(ae,{style:{width:"22px",height:"22px"}})}),
|
|
127
127
|
/* @__PURE__ */b("button",{onClick:()=>T(e=>!e),style:{width:"52px",height:"52px",borderRadius:"50%",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s",backgroundColor:I?`${n}20`:"rgba(255,255,255,0.08)",color:I?n:"rgba(255,255,255,0.5)",border:"1px solid "+(I?`${n}30`:"rgba(255,255,255,0.08)")},"aria-label":"Escribir texto",children:/* @__PURE__ */b(J,{style:{width:"20px",height:"20px"}})})]}),I&&/* @__PURE__ */y("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 20px 20px"},children:[
|
|
128
|
-
/* @__PURE__ */b("input",{type:"text",value:O,onChange:e=>M(e.target.value),onKeyDown:e=>"Enter"===e.key&&
|
|
129
|
-
/* @__PURE__ */b("button",{onClick:
|
|
128
|
+
/* @__PURE__ */b("input",{type:"text",value:O,onChange:e=>M(e.target.value),onKeyDown:e=>"Enter"===e.key&&ze(),placeholder:"Escribí email, teléfono, etc.",autoFocus:!0,style:{flex:1,padding:"10px 14px",borderRadius:"12px",border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.06)",color:"white",fontSize:"13px",outline:"none",backdropFilter:"blur(8px)"}}),
|
|
129
|
+
/* @__PURE__ */b("button",{onClick:ze,disabled:!O.trim(),style:{width:"40px",height:"40px",borderRadius:"50%",border:"none",cursor:O.trim()?"pointer":"default",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:O.trim()?n:"rgba(255,255,255,0.06)",color:O.trim()?"white":"rgba(255,255,255,0.2)",transition:"all 0.2s"},"aria-label":"Enviar texto",children:/* @__PURE__ */b(re,{style:{width:"16px",height:"16px"}})})]}),
|
|
130
130
|
/* @__PURE__ */b("style",{children:"\n @keyframes spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n @keyframes pulse {\n 0%, 100% { opacity: 1; transform: scale(1); }\n 50% { opacity: 0.7; transform: scale(0.95); }\n }\n "})]})}function Oc({isOpen:e,isConnected:t,isTyping:n,messages:r,botName:o="BotUyo",logoUrl:l,welcomeMessage:c,inputPlaceholder:u,mediaConfig:d,onClose:p,onSendMessage:h,bubbleStyles:m,avatars:g,onSendAttachment:w,onSendLocation:x,getSocket:k,avatar3dUrl:_,voiceConfig:S,theme:C,suggestedQuestions:E}){const[z,N]=i(!1),[A,I]=i(!1),[T,O]=i(!1),{t:M}=D(),P=rc(),L=At({cssVariables:C?.cssVariables}),j=function({isOpen:e,height:t,bottom:n}){const r=rc(),[o,l]=i({}),c=s(()=>{if(r){const e=()=>{window.visualViewport?l({height:`${window.visualViewport.height}px`,transform:`translateY(${window.visualViewport.offsetTop}px)`}):l({height:"100dvh",transform:"none"})};return e(),window.visualViewport?.addEventListener("resize",e),window.visualViewport?.addEventListener("scroll",e),()=>{window.visualViewport?.removeEventListener("resize",e),window.visualViewport?.removeEventListener("scroll",e)}}{const e=parseFloat(n||oc)||24,r=window.innerHeight-64-e;if(t){const e=parseFloat(t)||700,o=Math.min(e,r);l({height:`${o}px`,maxHeight:`${r}px`,bottom:n||oc})}else{const e=Math.min(700,Math.max(500,r));l({height:`${e}px`,maxHeight:`${r}px`,bottom:n||oc})}}},[r,t,n]);return a(()=>{if(!e)return;const t=c();return window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c),t&&t()}},[e,c]),o}({isOpen:e,height:C?.cssVariables?.windowHeight,bottom:C?.cssVariables?.windowBottom}),F=function({enabled:e,returnFocusRef:t,onEscape:n}){const r=f(null),o=f(null),i=f(n);i.current=n;const l=s(e=>{const t=r.current;if(t)if("Escape"!==e.key){if("Tab"===e.key){const n=t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(0===n.length)return;const r=n[0],o=n[n.length-1];e.shiftKey&&document.activeElement===r?(e.preventDefault(),o.focus()):e.shiftKey||document.activeElement!==o||(e.preventDefault(),r.focus())}}else i.current?.()},[]);return a(()=>{if(!e)return;o.current=document.activeElement;const n=t?.current,i=r.current;if(!i)return;const a=setTimeout(()=>{const e=i.querySelector('textarea, input[type="text"]');if(e)e.focus();else{const e=i.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');e.length>0?e[0].focus():i.focus()}},100);return document.addEventListener("keydown",l),()=>{clearTimeout(a),document.removeEventListener("keydown",l);const e=n||o.current;e&&"function"==typeof e.focus&&e.focus()}},[e,t,l]),r}({enabled:e,onEscape:p});if(a(()=>{if(e)return P&&(document.body.style.overflow="hidden"),()=>{document.body.style.overflow=""}},[e,P]),!e)return null;const R="bottom-left"===C?.position;/* @__PURE__ */
|
|
131
131
|
return y(v,{children:[
|
|
132
132
|
/* @__PURE__ */b("div",{id:"chat-dialog-description",className:"sr-only",children:M("accessibility.dialogDescription",{botName:o??"BotUyo"})}),
|
|
@@ -190,4 +190,4 @@ return b("div",{style:{width:"100%",height:"100%",position:"relative",overflow:"
|
|
|
190
190
|
/* @__PURE__ */b("directionalLight",{position:[-1,1,-1],intensity:.3,color:"#b4c6e7"}),
|
|
191
191
|
/* @__PURE__ */b("pointLight",{position:[0,.5,-.5],intensity:.5,distance:3}),
|
|
192
192
|
/* @__PURE__ */b(wb,{url:e,autoRotate:o,hasCustomCamera:!(!n||!r)})]})})}):null}const _b="https://api.botuyo.com";class Sb 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 Cb={"--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%"},Eb=p(()=>Promise.resolve().then(()=>yb).then(e=>({default:e.ChatWidgetWithProviders})));class zb{root=null;container=null;shadowRoot=null;mountPoint=null;darkModeObserver=null;darkModeMediaQuery=null;config=null;init(e){return this.config={...e,apiBaseUrl:e.apiBaseUrl||_b},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(Cb).forEach(e=>{this.mountPoint.style.removeProperty(e)}):Object.entries(Cb).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||_b,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(Eb,t));this.root.render(n.createElement(Sb,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"))}sendMessage(e){window.dispatchEvent(new CustomEvent("botuyo-chat:send-message",{detail:{message:e}}))}getState(){return null}}const Nb=new zb;window.BotUyoChat=Nb;export{kb as A,zb as B,bb as C,K as L,vb as P,se as X,Et as a,ub as b,$ as c,gb as d,M as e,db as f,At as g,P as h,Nb as i,D as u};
|
|
193
|
-
//# sourceMappingURL=standalone-
|
|
193
|
+
//# sourceMappingURL=standalone-BpzprslZ.js.map
|