@flowengage/react-chatbot 0.1.4 → 0.1.5

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.
@@ -332,4 +332,4 @@ registerProcessor("scribeAudioProcessor", ScribeAudioProcessor);
332
332
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
333
333
  40% { transform: translateY(-5px); opacity: 1; }
334
334
  }
335
- `})]})});function xh(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatId:r,chatHistory:i,isOpen:a,activeScreen:o,isHumanHandled:s,agentName:c,isAgentTyping:l,isAiTyping:u,isLoading:d,isVoiceMode:f,isRateLimited:p,rateLimitMessage:m,isConversationEnded:h,incomingCall:g,activeCallId:_,callConnectionState:y,callConnectedAt:b,isCallMuted:x,webRTCError:ee,language:te,historyRef:S,onMessageSync:ne,endConversation:re,acceptCall:ie,rejectCall:ae,endWebRTCCall:oe,toggleCallMute:se,dismissCallError:ce,openWidget:le,closeWidget:ue,sendMessage:de,setVoiceMode:fe,startTyping:C,stopTyping:w,updateTypingDraft:pe}=Zt(),[me,he]=(0,v.useState)(``),[ge,_e]=(0,v.useState)(null),[ve,ye]=(0,v.useState)(null),[be,xe]=(0,v.useState)(null),[Se,Ce]=(0,v.useState)(0),we=t?.widgetSettings||{},T=n?.widgetSettings||{},Te={...we.branding||{},...T.branding||{}},Ee={...we.theme||{},...T.theme||{}},De=Ee.primaryColor||`#3B82F6`,Oe=Ee.accentColor||`#1D4ED8`,ke=(Ee.position||`bottom-right`)===`bottom-left`?`left-6 bottom-6`:`right-6 bottom-6`,Ae={"--flowengage-primary":De,"--flowengage-accent":Oe},je=T.recommendations?.[te]||we.recommendations?.[te]||yh,Me=T.greetings?.[te]||we.greetings?.[te],Ne=Te.chatButtonText||`Chat with us`,Pe=Te.headerName||t?.websiteName||`OpenSense Labs`,Fe=Te.logoUrl||null,Ie=Te.hideWatermark||!1,Le=T.elevenLabsAgentId||t?.elevenLabsAgentId||null,E=Te.fallbackAgentName||`Agent`,Re=g?.agentName||c||E;(0,v.useEffect)(()=>{if(!b||y!==`connected`){Ce(0);return}let e=()=>{let e=new Date(b).getTime();isNaN(e)||Ce(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[b,y]),(0,v.useEffect)(()=>{if(!s||f||h){pe(``),w();return}if(!me.trim()){pe(``),w();return}C();let e=window.setTimeout(()=>{pe(me)},120),t=window.setTimeout(()=>{w()},1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[me,s,f,h,C,w,pe]);let ze=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null;return e===`ready`?(0,O.jsxs)(`div`,{className:`flowengage-shell fixed z-999999 font-sans border-none outline-none ${a?`inset-0 md:inset-auto md:right-6 md:bottom-6`:ke}`,style:Ae,children:[(0,O.jsx)(bn,{isOpen:a,openWidget:le,launcherText:Ne,primaryColor:De,posClass:ke}),a&&(0,O.jsxs)(`div`,{className:`relative w-full h-full md:w-[min(423px,calc(100vw-40px))] md:h-[min(700px,calc(100vh-120px))] flex flex-col md:rounded-[24px] overflow-hidden shadow-[0_20px_50px_rgba(0,0,0,0.15)] border-none outline-none transition-all duration-300 ${i.length===0&&!f?`bg-gradient-to-b from-[var(--flowengage-primary)] from-0% via-[var(--flowengage-primary)] via-70% to-white to-85%`:`bg-white`}`,children:[(0,O.jsx)(Cn,{logoUrl:Fe,brandName:Pe,agentName:c,fallbackAgentName:E,activeScreen:o,branding:Te,isConversationEnded:h,endConversation:re,closeWidget:ue,isInitial:i.length===0&&!f}),(0,O.jsx)(`div`,{className:`flex-1 overflow-y-auto flex flex-col`,children:f?(0,O.jsx)(vh,{agentId:Le,chatId:r,historyRef:S,onMessageSync:ne,onEnd:()=>{ge&&(ge.getTracks().forEach(e=>e.stop()),_e(null)),fe(!1)}}):i.length===0?(0,O.jsx)(En,{greetings:Me,recommendations:je,onSendMessage:de}):(0,O.jsx)(Tn,{chatHistory:i,isAiTyping:u,isAgentTyping:l,setReplyContext:xe,TypingDots:bh})}),(0,O.jsx)(An,{webRTCError:ee,micError:ve,setMicError:ye,dismissCallError:ce,incomingCall:g,rejectCall:ae,acceptCall:ie,activeCallId:_,callConnectionState:y,formatCallDuration:e=>{let t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,`0`)}:${n.toString().padStart(2,`0`)}`},callDurationSeconds:Se,endWebRTCCall:oe,isCallMuted:x,toggleCallMute:se,isAIVoiceActive:f,currentCallAgentName:Re,isRateLimited:p,rateLimitMessage:m}),!f&&(0,O.jsx)(Dn,{input:me,setInput:he,onSubmit:async e=>{if(e.preventDefault(),!me.trim()||h)return;let t=me.trim(),n=ze(be);he(``),xe(null),await de(t,``,n)},isConversationEnded:h,callUiActive:!!(g||_),handleToggleVoice:async()=>{if(f){fe(!1);return}ye(null);try{_e(await navigator.mediaDevices.getUserMedia({audio:!0})),fe(!0)}catch(e){ye(e.message||`Could not access microphone.`)}},activeScreen:o,inputDisabled:d||p||h,replyContext:be,clearReplyContext:()=>xe(null)}),!Ie&&(0,O.jsx)(`div`,{className:`flex items-center justify-center gap-3 pt-3 pb-4 text-[12px] text-gray-400`,children:(0,O.jsxs)(`div`,{children:[`Powered by `,(0,O.jsx)(`span`,{className:`text-blue-500`,children:`Open`}),(0,O.jsx)(`span`,{className:`text-red-500`,children:`Sense`}),` `,(0,O.jsx)(`span`,{className:`text-amber-500`,children:`Labs`})]})})]})]}):null}var Sh=null,Ch=!1;function wh(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function Th({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(Ch){console.warn(`[FlowEngage] Already initialized. Call FlowEngage.destroy() first to re-initialize.`);return}if(!e){console.error(`[FlowEngage] siteId is required. Pass it via data-site-id attribute or FlowEngage.init({ siteId: 'YOUR_SITE_ID' }).`);return}if(!document.body){console.error(`[FlowEngage] document.body is not available yet. The widget will auto-retry once the DOM is ready.`),wh(()=>Th({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}));return}if(document.getElementById(`flowengage-root`)){console.warn(`[FlowEngage] #flowengage-root already exists. Skipping duplicate mount.`);return}let i=document.createElement(`div`);i.id=`flowengage-root`,document.body.appendChild(i),Sh=(0,y.createRoot)(i);let a={widgetSettings:n,...r&&{apiBaseUrl:r}};Sh.render(v.createElement(dn,{siteId:e,language:t,config:a},v.createElement(xh))),Ch=!0}var Eh={init({siteId:e,language:t=`en`,widgetSettings:n={}}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>wh(()=>Th({siteId:e,language:t,widgetSettings:n}))):wh(()=>Th({siteId:e,language:t,widgetSettings:n}))},destroy(){Sh&&=(Sh.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),Ch=!1}},Dh=()=>{let e=document.currentScript;(!e||!e.getAttribute(`data-site-id`))&&(e=document.querySelector(`script[data-site-id]`));let t=e?.getAttribute(`data-site-id`);if(!t)return;let n=e?.getAttribute(`data-language`)||`en`,r=e?.getAttribute(`data-api-url`)||void 0,i={};try{let t=e?.getAttribute(`data-widget-settings`);t&&(i=JSON.parse(t))}catch{}let a={widgetSettings:i,...r&&{apiBaseUrl:r}};wh(()=>Th({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,Dh):Dh(),typeof window<`u`&&(window.FlowEngage=Eh),Eh})();
335
+ `})]})});function xh(){let{status:e,runtimeConfig:t,resolvedConfig:n,chatId:r,chatHistory:i,isOpen:a,activeScreen:o,isHumanHandled:s,agentName:c,isAgentTyping:l,isAiTyping:u,isLoading:d,isVoiceMode:f,isRateLimited:p,rateLimitMessage:m,isConversationEnded:h,incomingCall:g,activeCallId:_,callConnectionState:y,callConnectedAt:b,isCallMuted:x,webRTCError:ee,language:te,historyRef:S,onMessageSync:ne,endConversation:re,acceptCall:ie,rejectCall:ae,endWebRTCCall:oe,toggleCallMute:se,dismissCallError:ce,openWidget:le,closeWidget:ue,sendMessage:de,setVoiceMode:fe,startTyping:C,stopTyping:w,updateTypingDraft:pe}=Zt(),[me,he]=(0,v.useState)(``),[ge,_e]=(0,v.useState)(null),[ve,ye]=(0,v.useState)(null),[be,xe]=(0,v.useState)(null),[Se,Ce]=(0,v.useState)(0),we=t?.widgetSettings||{},T=n?.widgetSettings||{},Te={...we.branding||{},...T.branding||{}},Ee={...we.theme||{},...T.theme||{}},De=Ee.primaryColor||`#3B82F6`,Oe=Ee.accentColor||`#1D4ED8`,ke=(Ee.position||`bottom-right`)===`bottom-left`?`left-6 bottom-6`:`right-6 bottom-6`,Ae={"--flowengage-primary":De,"--flowengage-accent":Oe},je=T.recommendations?.[te]||we.recommendations?.[te]||yh,Me=T.greetings?.[te]||we.greetings?.[te],Ne=Te.chatButtonText||`Chat with us`,Pe=Te.headerName||t?.websiteName||`OpenSense Labs`,Fe=Te.logoUrl||null,Ie=Te.hideWatermark||!1,Le=T.elevenLabsAgentId||t?.elevenLabsAgentId||null,E=Te.fallbackAgentName||`Agent`,Re=g?.agentName||c||E;(0,v.useEffect)(()=>{if(!b||y!==`connected`){Ce(0);return}let e=()=>{let e=new Date(b).getTime();isNaN(e)||Ce(Math.max(0,Math.floor((Date.now()-e)/1e3)))};e();let t=window.setInterval(e,1e3);return()=>window.clearInterval(t)},[b,y]),(0,v.useEffect)(()=>{if(!s||f||h){pe(``),w();return}if(!me.trim()){pe(``),w();return}C();let e=window.setTimeout(()=>{pe(me)},120),t=window.setTimeout(()=>{w()},1200);return()=>{window.clearTimeout(e),window.clearTimeout(t)}},[me,s,f,h,C,w,pe]);let ze=e=>e?{replyTo:e.messageId||e.id||null,replyToContent:(e.replyToContent||e.message||``).replace(/<[^>]+>/g,``).trim().slice(0,200),replyToSender:e.sender||null}:null;return e===`ready`?(0,O.jsxs)(`div`,{className:`flowengage-shell fixed z-999999 font-sans border-none outline-none ${a?`inset-0 md:inset-auto md:right-6 md:bottom-6`:ke}`,style:Ae,children:[(0,O.jsx)(bn,{isOpen:a,openWidget:le,launcherText:Ne,primaryColor:De,posClass:ke}),a&&(0,O.jsxs)(`div`,{className:`relative w-full h-full md:w-[min(423px,calc(100vw-40px))] md:h-[min(700px,calc(100vh-120px))] flex flex-col md:rounded-[24px] overflow-hidden shadow-[0_20px_50px_rgba(0,0,0,0.15)] border-none outline-none transition-all duration-300 ${i.length===0&&!f?`bg-gradient-to-b from-[var(--flowengage-primary)] from-0% via-[var(--flowengage-primary)] via-70% to-white to-85%`:`bg-white`}`,children:[(0,O.jsx)(Cn,{logoUrl:Fe,brandName:Pe,agentName:c,fallbackAgentName:E,activeScreen:o,branding:Te,isConversationEnded:h,endConversation:re,closeWidget:ue,isInitial:i.length===0&&!f}),(0,O.jsx)(`div`,{className:`flex-1 overflow-y-auto flex flex-col`,children:f?(0,O.jsx)(vh,{agentId:Le,chatId:r,historyRef:S,onMessageSync:ne,onEnd:()=>{ge&&(ge.getTracks().forEach(e=>e.stop()),_e(null)),fe(!1)}}):i.length===0?(0,O.jsx)(En,{greetings:Me,recommendations:je,onSendMessage:de}):(0,O.jsx)(Tn,{chatHistory:i,isAiTyping:u,isAgentTyping:l,setReplyContext:xe,TypingDots:bh})}),(0,O.jsx)(An,{webRTCError:ee,micError:ve,setMicError:ye,dismissCallError:ce,incomingCall:g,rejectCall:ae,acceptCall:ie,activeCallId:_,callConnectionState:y,formatCallDuration:e=>{let t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,`0`)}:${n.toString().padStart(2,`0`)}`},callDurationSeconds:Se,endWebRTCCall:oe,isCallMuted:x,toggleCallMute:se,isAIVoiceActive:f,currentCallAgentName:Re,isRateLimited:p,rateLimitMessage:m}),!f&&(0,O.jsx)(Dn,{input:me,setInput:he,onSubmit:async e=>{if(e.preventDefault(),!me.trim()||h)return;let t=me.trim(),n=ze(be);he(``),xe(null),await de(t,``,n)},isConversationEnded:h,callUiActive:!!(g||_),handleToggleVoice:async()=>{if(f){fe(!1);return}ye(null);try{_e(await navigator.mediaDevices.getUserMedia({audio:!0})),fe(!0)}catch(e){ye(e.message||`Could not access microphone.`)}},activeScreen:o,inputDisabled:d||p||h,replyContext:be,clearReplyContext:()=>xe(null)}),!Ie&&(0,O.jsx)(`div`,{className:`flex items-center justify-center gap-3 pt-3 pb-4 text-[12px] text-gray-400`,children:(0,O.jsxs)(`div`,{children:[`Powered by `,(0,O.jsx)(`span`,{className:`text-blue-500`,children:`Open`}),(0,O.jsx)(`span`,{className:`text-red-500`,children:`Sense`}),` `,(0,O.jsx)(`span`,{className:`text-amber-500`,children:`Labs`})]})})]})]}):null}var Sh=null,Ch=!1;function wh(e){if(document.body){e();return}let t=new MutationObserver(()=>{document.body&&(t.disconnect(),e())});t.observe(document.documentElement,{childList:!0})}function Th({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}){if(Ch){console.warn(`[FlowEngage] Already initialized. Call FlowEngage.destroy() first to re-initialize.`);return}if(!e){console.error(`[FlowEngage] siteId is required. Pass it via data-site-id attribute or FlowEngage.init({ siteId: 'YOUR_SITE_ID' }).`);return}if(!document.body){console.error(`[FlowEngage] document.body is not available yet. The widget will auto-retry once the DOM is ready.`),wh(()=>Th({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}));return}if(document.getElementById(`flowengage-root`)){console.warn(`[FlowEngage] #flowengage-root already exists. Skipping duplicate mount.`);return}let i=document.createElement(`div`);i.id=`flowengage-root`,document.body.appendChild(i),Sh=(0,y.createRoot)(i);let a={widgetSettings:n,...r&&{apiBaseUrl:r}};Sh.render(v.createElement(dn,{siteId:e,language:t,config:a},v.createElement(xh))),Ch=!0}var Eh={init({siteId:e,language:t=`en`,widgetSettings:n={},apiBaseUrl:r}={}){document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>wh(()=>Th({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))):wh(()=>Th({siteId:e,language:t,widgetSettings:n,apiBaseUrl:r}))},destroy(){Sh&&=(Sh.unmount(),null);let e=document.getElementById(`flowengage-root`);e&&e.remove();let t=document.getElementById(`flowengage-styles`);t&&t.remove(),Ch=!1}},Dh=()=>{let e=document.currentScript;(!e||!e.getAttribute(`data-site-id`))&&(e=document.querySelector(`script[data-site-id]`));let t=e?.getAttribute(`data-site-id`);if(!t)return;let n=e?.getAttribute(`data-language`)||`en`,r=e?.getAttribute(`data-api-url`)||void 0,i={};try{let t=e?.getAttribute(`data-widget-settings`);t&&(i=JSON.parse(t))}catch{}let a={widgetSettings:i,...r&&{apiBaseUrl:r}};wh(()=>Th({siteId:t,language:n,widgetSettings:a.widgetSettings,apiBaseUrl:r}))};return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,Dh):Dh(),typeof window<`u`&&(window.FlowEngage=Eh),Eh})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Embeddable AI chat widget for React — powered by FlowEngage. Drop it in with a single siteId.",
5
5
  "keywords": [
6
6
  "chatbot",