react-aichatbot-widget 2.0.2 → 2.0.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/README.md CHANGED
@@ -44,8 +44,6 @@ function App() {
44
44
  {/*add a namespace for chatbot and chatbot url*/}
45
45
  <ChatBotWidget
46
46
  pineconeNamespace=''
47
- url=''
48
- chatMessageUrl=''
49
47
  primaryColor="" // hex color code
50
48
  secondaryColor="" // hex color code
51
49
  fontColor="" // hex color code
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const t=require("react/jsx-runtime"),u=require("react"),k=require("lucide-react"),D=({onMinimise:o,isOpen:e,theme:s,chatBotData:i})=>{const c=i.position==="left",y=c?"32px":"auto",d=c?"auto":"32px",f=localStorage.getItem("clone67ChatSessionId"),p={position:"fixed",bottom:"32px",left:y,right:d,background:`linear-gradient(135deg, ${s.primaryColor}, ${s.secondaryColor})`,color:s.fontColor,width:"64px",height:"64px",borderRadius:"50%",border:"none",boxShadow:"0 20px 25px -5px rgba(0,0,0,0.15), 0 10px 10px -5px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",pointerEvents:"auto",transition:"all 300ms ease",outline:"none"},g={position:"absolute",top:"-4px",right:"-4px",width:"16px",height:"16px",backgroundColor:"#34d399",borderRadius:"50%",border:"4px solid white",animation:"pulse 2s infinite"};return t.jsxs("button",{onClick:o,style:p,children:[e?t.jsx(k.Minus,{size:20,strokeWidth:2.5}):t.jsx(k.MessageCircle,{size:20,strokeWidth:2.5}),!e&&f&&t.jsx("span",{style:g})]})},a=[];for(let o=0;o<256;++o)a.push((o+256).toString(16).slice(1));function M(o,e=0){return(a[o[e+0]]+a[o[e+1]]+a[o[e+2]]+a[o[e+3]]+"-"+a[o[e+4]]+a[o[e+5]]+"-"+a[o[e+6]]+a[o[e+7]]+"-"+a[o[e+8]]+a[o[e+9]]+"-"+a[o[e+10]]+a[o[e+11]]+a[o[e+12]]+a[o[e+13]]+a[o[e+14]]+a[o[e+15]]).toLowerCase()}let E;const L=new Uint8Array(16);function T(){if(!E){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");E=crypto.getRandomValues.bind(crypto)}return E(L)}const U=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),$={randomUUID:U};function F(o,e,s){o=o||{};const i=o.random??o.rng?.()??T();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,M(i)}function O(o,e,s){return $.randomUUID&&!o?$.randomUUID():F(o)}const _=({messages:o,chatBotData:e,theme:s,isExpand:i})=>{const[c,y]=u.useState([]),d=u.useRef(null),f=n=>{if(n==="")return null;try{return JSON.parse(n)}catch(x){return console.error("Error parsing message string to JSON:",x),null}},p=n=>new Date(n).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!0});u.useEffect(()=>{o===""&&y([{created_at:Date.now(),sender_type:"bot",message:e.aiInitialMessage,suggested_prompt:[]}]);const n=f(o);n&&y(x=>[...x,n])},[o]),u.useEffect(()=>{d.current?.scrollIntoView({behavior:"smooth"})},[c]);const g=c.flat(),S={height:i?"500px":"400px",overflowY:"auto",padding:"10px",background:s.backgroundColor,color:s.fontColor,borderTop:"1px solid rgba(255, 255, 255, 0.2)",display:"flex",flexDirection:"column"},b=n=>({display:"flex",justifyContent:n==="user"?"flex-end":"flex-start",width:"100%"}),m={display:"flex",flexDirection:"column",maxWidth:"80%"},h=n=>({padding:"10px",borderRadius:n==="user"?"12px 0 12px 12px":"0 12px 12px 12px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",fontSize:"14px",lineHeight:"1.5",background:n==="user"?s.primaryColor:"#f5f5f5",color:s.fontColor,wordWrap:"break-word"});return t.jsxs("div",{style:S,children:[g.map((n,x)=>t.jsx("div",{style:b(n.sender_type),children:t.jsxs("div",{style:m,children:[t.jsx("div",{style:n.sender_type==="user"?h("user"):h("ai"),children:n.message}),t.jsx("div",{style:{display:"flex",alignItems:"center",marginLeft:"4px",justifyContent:n.sender_type==="user"?"flex-end":"flex-start"},children:t.jsxs("span",{style:{fontSize:"10px",opacity:.55,color:s.fontColor},children:[n.sender_type==="user"?"You":`${e.name}`," • ",p(n.created_at)]})})]})},x)),t.jsx("div",{ref:d})]})},H=(o,e)=>({socket:new WebSocket(`wss://handle-chat-session.clone67.com?chatbotNamespace=${e}&sessionId=${o}`)}),A=({chatBotData:o,theme:e,onlineStatus:s,isExpand:i})=>{const[c,y]=u.useState(null),[d,f]=u.useState(""),[p,g]=u.useState("Connecting to server..."),[S,b]=u.useState(""),[m,h]=u.useState(!1);u.useEffect(()=>{var r=localStorage.getItem("clone67ChatSessionId");r===null&&(r=O(),localStorage.setItem("clone67ChatSessionId",r));const{socket:v}=H(r,o.pineconeNamespace);y(v),v.onopen=()=>{g("Server connected"),setTimeout(()=>{g("")},2e3),s("online")},v.onmessage=async W=>{try{const R=await W.data;b(R),h(!1)}catch(R){console.error("Error handling server message:",R)}},v.onerror=W=>{g("Server error occurred"),console.error("WebSocket error:",W),s("offline")},v.onclose=()=>{g("Server disconnected"),s("offline")}},[]);const n=async r=>{r.preventDefault(),c&&c.readyState===WebSocket.OPEN&&c.send(JSON.stringify(d)),h(!0);const v={created_at:Date.now(),sender_type:"user",message:d};b(JSON.stringify(v)),f("")},x=r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),n(r))},C={flex:1,padding:"12px 16px",background:e.backgroundColor,color:e.fontColor,border:`1px solid ${e.primaryColor}`,borderRadius:"12px",fontSize:"14px",outline:"none",transition:"all 0.2s ease",boxShadow:"none"},w={padding:"12px 20px",borderRadius:"12px",background:`linear-gradient(135deg, ${e.primaryColor}, ${e.secondaryColor})`,color:e.fontColor,border:"none",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",fontWeight:"600",fontSize:"14px",transition:"all 0.2s ease",minWidth:"48px"},I={padding:"10px",borderColor:e.fontColor,background:e.backgroundColor,flexShrink:0},j={display:"flex",gap:"12px",alignItems:"center"},z={textAlign:"center",padding:"2px",backgroundColor:p==="Server connected"||p==="online"?"#09BA00":p==="Connecting to server..."?"#DED000":"#FF3408",color:"#ffffff",fontSize:"10px"},l={padding:"8px",animation:"fadeIn 0.3s ease-in-out, pulse 1.5s ease-in-out infinite",animationDelay:"0s, 0.3s",fontSize:"10px",color:e.fontColor};return t.jsxs(t.Fragment,{children:[p&&t.jsx("p",{style:z,children:p}),t.jsx(_,{messages:S,chatBotData:o,theme:e,isExpand:i}),m&&t.jsx("div",{style:l,children:`${o.name} is typing...`}),t.jsx("div",{style:I,children:t.jsxs("form",{onSubmit:n,style:j,children:[t.jsx("input",{type:"text",placeholder:"Type a message...",value:d,onChange:r=>f(r.target.value),onKeyDown:x,style:C,onFocus:r=>{r.target.style.boxShadow=`0 0 0 1px ${e.primaryColor}`,r.target.style.borderColor=e.primaryColor},onBlur:r=>{r.target.style.boxShadow="none",r.target.style.borderColor=e.primaryColor}}),t.jsx("button",{onClick:n,style:w,"aria-label":"Send message",children:t.jsx(k.Send,{size:18})})]})})]})},N=({onClose:o,theme:e,chatBotData:s})=>{const[i,c]=u.useState(!1),[y,d]=u.useState(!1),p={position:"fixed",bottom:"112px",[s.position==="left"?"left":"right"]:"32px",zIndex:50,width:i?"684px":"384px",height:i?"620px":"520px",background:`${e.backgroundColor}cc`,backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",borderRadius:"16px",border:"1px solid rgba(255, 255, 255, 0.3)",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"system-ui, -apple-system, sans-serif",boxShadow:"0 10px 25px -3px rgba(0,0,0,0.1)"},g={padding:"16px 20px",background:`linear-gradient(135deg, ${e.primaryColor}, ${e.secondaryColor})`,color:e.fontColor,borderRadius:"16px 16px 0 0",display:"flex",alignItems:"center",justifyContent:"space-between",boxShadow:"0 4px 6px -1px rgba(0,0,0,0.1)"},S={position:"relative"},b={width:"44px",height:"44px",borderRadius:"50%",background:"rgba(255,255,255,0.2)",display:"flex",alignItems:"center",justifyContent:"center"},m={position:"absolute",bottom:0,right:0,width:"14px",height:"14px",backgroundColor:y?"#00BF49":"#F54927",borderRadius:"50%",border:"3px solid white"},h={fontSize:"18px",fontWeight:"600",margin:0,lineHeight:"1.2"},n={fontSize:"12px",opacity:.9,margin:0,lineHeight:"1.3"},x={padding:"8px",borderRadius:"50%",background:"transparent",border:"none",cursor:"pointer",transition:"background 0.2s"},C={padding:"10px",borderTop:"1px solid rgba(255,255,255,0.2)",background:e.backgroundColor,textAlign:"center"},w={fontSize:"11px",color:e.fontColor,letterSpacing:"0.5px"},I={fontWeight:"600"},j=(l,r)=>{l.currentTarget.style.background=r?"rgba(255,255,255,0.2)":"transparent"},z=l=>{d(l==="online")};return t.jsxs("div",{style:p,children:[t.jsxs("div",{style:g,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[t.jsxs("div",{style:S,children:[t.jsx("div",{style:b,children:t.jsx(k.MessageCircle,{size:22})}),t.jsx("span",{style:m})]}),t.jsxs("div",{children:[t.jsx("h3",{style:h,children:s.name}),t.jsx("p",{style:n,children:s.subTitle})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"left"},children:[t.jsx("button",{onClick:()=>c(l=>!l),"aria-label":"expand chat",style:x,onMouseEnter:l=>j(l,!0),onMouseLeave:l=>j(l,!1),children:i?t.jsx(k.Minimize2,{size:20}):t.jsx(k.Maximize2,{size:20})}),t.jsx("button",{onClick:o,"aria-label":"close chat",style:x,onMouseEnter:l=>j(l,!0),onMouseLeave:l=>j(l,!1),children:t.jsx(k.X,{size:20})})]})]}),t.jsx(A,{chatBotData:s,theme:e,onlineStatus:z,isExpand:i}),t.jsx("div",{style:C,children:t.jsxs("p",{style:w,children:["powered by ",t.jsx("span",{style:I,children:"clone67.com"})]})})]})},V=({pineconeNamespace:o,primaryColor:e="#3b82f6",secondaryColor:s="#8b5cf6",backgroundColor:i="#ffffff",fontColor:c="#1f2937",placeholderColor:y="#9ca3af",position:d="right",name:f="AI Assistant",subTitle:p="AI powered assistant",welcomeText:g="Hi! How can I help you today?",aiInitialMessage:S=""})=>{const[b,m]=u.useState(!1),h=()=>{m(l=>!l),localStorage.removeItem("clone67ChatSessionId")},n=()=>m(l=>!l),x={primaryColor:e,secondaryColor:s,backgroundColor:i,fontColor:c,placeholderColor:y,inputBackgroundColor:i},C={name:f,subTitle:p,welcomeText:g,pineconeNamespace:o,position:d,aiInitialMessage:S};S===""&&(C.aiInitialMessage=`Hello! I'm ${C.name}, your AI assistant. How can I help you today?`);const w=d==="left",I="32px",j={position:"fixed",bottom:"104px",[w?"left":"right"]:I,zIndex:9999,pointerEvents:"auto"},z={position:"fixed",bottom:"32px",[w?"left":"right"]:I,zIndex:1e4,pointerEvents:"auto"};return t.jsxs(t.Fragment,{children:[b&&t.jsx("div",{style:j,children:t.jsx(N,{onClose:h,theme:x,chatBotData:C})}),t.jsx("div",{style:z,children:t.jsx(D,{onMinimise:n,isOpen:b,theme:x,chatBotData:C})})]})};module.exports=V;
1
+ "use strict";const t=require("react/jsx-runtime"),d=require("react"),v=require("lucide-react"),L=({onMinimise:e,isOpen:o,theme:r,chatBotData:i})=>{const u=i.position==="left",a=u?"32px":"auto",x=u?"auto":"32px",y=localStorage.getItem("clone67ChatSessionId"),b={position:"fixed",bottom:"32px",left:a,right:x,background:`linear-gradient(135deg, ${r.primaryColor}, ${r.secondaryColor})`,color:r.fontColor,width:"64px",height:"64px",borderRadius:"50%",border:"none",boxShadow:"0 20px 25px -5px rgba(0,0,0,0.15), 0 10px 10px -5px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",pointerEvents:"auto",transition:"all 300ms ease",outline:"none"},g={position:"absolute",top:"-4px",right:"-4px",width:"16px",height:"16px",backgroundColor:"#34d399",borderRadius:"50%",border:"4px solid white",animation:"pulse 2s infinite"};return t.jsxs("button",{onClick:e,style:b,children:[o?t.jsx(v.Minus,{size:20,strokeWidth:2.5}):t.jsx(v.MessageCircle,{size:20,strokeWidth:2.5}),!o&&y&&t.jsx("span",{style:g})]})},l=[];for(let e=0;e<256;++e)l.push((e+256).toString(16).slice(1));function M(e,o=0){return(l[e[o+0]]+l[e[o+1]]+l[e[o+2]]+l[e[o+3]]+"-"+l[e[o+4]]+l[e[o+5]]+"-"+l[e[o+6]]+l[e[o+7]]+"-"+l[e[o+8]]+l[e[o+9]]+"-"+l[e[o+10]]+l[e[o+11]]+l[e[o+12]]+l[e[o+13]]+l[e[o+14]]+l[e[o+15]]).toLowerCase()}let $;const O=new Uint8Array(16);function T(){if(!$){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");$=crypto.getRandomValues.bind(crypto)}return $(O)}const F=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),D={randomUUID:F};function U(e,o,r){e=e||{};const i=e.random??e.rng?.()??T();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,M(i)}function _(e,o,r){return D.randomUUID&&!e?D.randomUUID():U(e)}const N=({messages:e,chatBotData:o,theme:r,isExpand:i})=>{const[u,a]=d.useState([]),x=d.useRef(null),y=s=>{if(s==="")return null;try{return JSON.parse(s)}catch(p){return console.error("Error parsing message string to JSON:",p),null}},b=s=>new Date(s).toLocaleString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!0});d.useEffect(()=>{e===""&&a([{created_at:Date.now(),sender_type:"bot",message:o.aiInitialMessage,suggested_prompt:[]}]);const s=y(e);s&&a(p=>[...p,s])},[e]),d.useEffect(()=>{x.current?.scrollIntoView({behavior:"smooth"})},[u]);const g=u.flat(),f={height:i?"500px":"400px",overflowY:"auto",padding:"10px",background:r.backgroundColor,color:r.fontColor,borderTop:"1px solid rgba(255, 255, 255, 0.2)",display:"flex",flexDirection:"column"},m=s=>({display:"flex",justifyContent:s==="user"?"flex-end":"flex-start",width:"100%"}),S={display:"flex",flexDirection:"column",maxWidth:"80%"},c=s=>({padding:"10px",borderRadius:s==="user"?"12px 0 12px 12px":"0 12px 12px 12px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",fontSize:"14px",lineHeight:"1.5",background:s==="user"?r.primaryColor:"#f5f5f5",color:r.fontColor,wordWrap:"break-word"});return t.jsxs("div",{style:f,children:[g.map((s,p)=>t.jsx("div",{style:m(s.sender_type),children:t.jsxs("div",{style:S,children:[t.jsx("div",{style:s.sender_type==="user"?c("user"):c("ai"),children:s.message}),t.jsx("div",{style:{display:"flex",alignItems:"center",marginLeft:"4px",justifyContent:s.sender_type==="user"?"flex-end":"flex-start"},children:t.jsxs("span",{style:{fontSize:"10px",opacity:.55,color:r.fontColor},children:[s.sender_type==="user"?"You":`${o.name}`," • ",b(s.created_at)]})})]})},p)),t.jsx("div",{ref:x})]})},H=({theme:e})=>{const o={height:"100%",background:e.backgroundColor,color:e.fontColor,display:"flex",alignItems:"center",justifyContent:"center"},r={padding:"24px 32px",background:e.backgroundColor,display:"flex",flexDirection:"column",alignItems:"center",gap:"10px"},i={fontSize:"14px",opacity:.85};return t.jsx("div",{style:o,children:t.jsxs("div",{style:r,children:[t.jsx(v.Loader,{size:26}),t.jsx("p",{style:i,children:"Exiting chat… please wait"})]})})},A=(e,o)=>({socket:new WebSocket(`wss://handle-chat-session.clone67.com?chatbotNamespace=${o}&sessionId=${e}`)}),V=({chatBotData:e,theme:o,onlineStatus:r,isExpand:i,endSession:u})=>{const[a,x]=d.useState(null),[y,b]=d.useState(""),[g,f]=d.useState("Connecting to server..."),[m,S]=d.useState(""),[c,s]=d.useState(!1);d.useEffect(()=>{var n=localStorage.getItem("clone67ChatSessionId");n===null&&(n=_(),localStorage.setItem("clone67ChatSessionId",n));const{socket:h}=A(n,e.pineconeNamespace);x(h),h.onopen=()=>{f("Server connected"),setTimeout(()=>{f("")},2e3),r("online")},h.onmessage=async W=>{try{const R=await W.data;S(R),s(!1)}catch(R){console.error("Error handling server message:",R)}},h.onerror=W=>{f("Server error occurred"),console.error("WebSocket error:",W),r("offline")},h.onclose=()=>{f("Server disconnected"),r("offline")}},[]),d.useEffect(()=>{if(u&&a&&a.readyState===WebSocket.OPEN){const n={type:"end_session"};a.send(JSON.stringify(n)),a.close(),localStorage.removeItem("clone67ChatSessionId")}},[u]);const p=async n=>{if(n.preventDefault(),a&&a.readyState===WebSocket.OPEN){const W={type:"chat",userInput:y};a.send(JSON.stringify(W))}s(!0);const h={created_at:Date.now(),sender_type:"user",message:y};S(JSON.stringify(h)),b("")},C=n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),p(n))},k={flex:1,padding:"12px 16px",background:`${c?`${o.primaryColor}33`:o.backgroundColor}`,color:o.fontColor,border:`1px solid ${o.primaryColor}`,borderRadius:"12px",fontSize:"14px",outline:"none",transition:"all 0.2s ease",boxShadow:"none",cursor:c?"not-allowed":"auto"},w={padding:"12px 20px",borderRadius:"12px",background:c?`${o.primaryColor}33`:`linear-gradient(135deg, ${o.primaryColor}, ${o.secondaryColor})`,color:o.fontColor,border:"none",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",fontWeight:"600",fontSize:"14px",transition:"all 0.2s ease",minWidth:"48px",cursor:c?"not-allowed":"pointer"},I={padding:"10px",borderColor:o.fontColor,background:o.backgroundColor,flexShrink:0},z={display:"flex",gap:"12px",alignItems:"center"},j={textAlign:"center",padding:"2px",backgroundColor:g==="Server connected"||g==="online"?"#09BA00":g==="Connecting to server..."?"#DED000":"#FF3408",color:"#ffffff",fontSize:"10px"},E={padding:"8px",animation:"fadeIn 0.3s ease-in-out, pulse 1.5s ease-in-out infinite",animationDelay:"0s, 0.3s",fontSize:"10px",color:o.fontColor};return t.jsxs(t.Fragment,{children:[g&&t.jsx("p",{style:j,children:g}),u?t.jsx(H,{theme:o}):t.jsxs(t.Fragment,{children:[t.jsx(N,{messages:m,chatBotData:e,theme:o,isExpand:i}),c&&t.jsx("div",{style:E,children:`${e.name} is typing...`}),t.jsx("div",{style:I,children:t.jsxs("form",{onSubmit:p,style:z,children:[t.jsx("input",{type:"text",placeholder:"Type a message...",value:y,onChange:n=>b(n.target.value),disabled:c,onKeyDown:C,style:k,onFocus:n=>{n.target.style.boxShadow=`0 0 0 1px ${o.primaryColor}`,n.target.style.borderColor=o.primaryColor},onBlur:n=>{n.target.style.boxShadow="none",n.target.style.borderColor=o.primaryColor}}),t.jsx("button",{onClick:p,style:w,disabled:c,"aria-label":"Send message",children:t.jsx(v.Send,{size:18})})]})})]})]})},B=({theme:e,chatBotData:o,onClose:r})=>{const[i,u]=d.useState(!1),[a,x]=d.useState(!1),[y,b]=d.useState(!1),f={position:"fixed",bottom:"112px",[o.position==="left"?"left":"right"]:"32px",zIndex:50,width:i?"684px":"384px",height:i?"620px":"520px",background:`${e.backgroundColor}cc`,backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",borderRadius:"16px",border:"1px solid rgba(255, 255, 255, 0.3)",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:"system-ui, -apple-system, sans-serif",boxShadow:"0 10px 25px -3px rgba(0,0,0,0.1)"},m={padding:"16px 20px",background:`linear-gradient(135deg, ${e.primaryColor}, ${e.secondaryColor})`,color:e.fontColor,borderRadius:"16px 16px 0 0",display:"flex",alignItems:"center",justifyContent:"space-between",boxShadow:"0 4px 6px -1px rgba(0,0,0,0.1)"},S={position:"relative"},c={width:"44px",height:"44px",borderRadius:"50%",background:"rgba(255,255,255,0.2)",display:"flex",alignItems:"center",justifyContent:"center"},s={position:"absolute",bottom:0,right:0,width:"14px",height:"14px",backgroundColor:a?"#00BF49":"#F54927",borderRadius:"50%",border:"3px solid white"},p={fontSize:"18px",fontWeight:"600",margin:0,lineHeight:"1.2"},C={fontSize:"12px",opacity:.9,margin:0,lineHeight:"1.3"},k={padding:"8px",borderRadius:"50%",background:"transparent",border:"none",cursor:"pointer",transition:"background 0.2s"},w={padding:"10px",borderTop:"1px solid rgba(255,255,255,0.2)",background:e.backgroundColor,textAlign:"center"},I={fontSize:"11px",color:e.fontColor,letterSpacing:"0.5px"},z={fontWeight:"600"},j=(n,h)=>{n.currentTarget.style.background=h?"rgba(255,255,255,0.2)":"transparent"},E=n=>{x(n==="online")};return t.jsxs("div",{style:f,children:[t.jsxs("div",{style:m,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[t.jsxs("div",{style:S,children:[t.jsx("div",{style:c,children:t.jsx(v.MessageCircle,{size:22})}),t.jsx("span",{style:s})]}),t.jsxs("div",{children:[t.jsx("h3",{style:p,children:o.name}),t.jsx("p",{style:C,children:o.subTitle})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"left"},children:[t.jsx("button",{onClick:()=>u(n=>!n),"aria-label":"expand chat",style:k,onMouseEnter:n=>j(n,!0),onMouseLeave:n=>j(n,!1),children:i?t.jsx(v.Minimize2,{size:20}):t.jsx(v.Maximize2,{size:20})}),t.jsx("button",{onClick:()=>{b(!0),setTimeout(()=>{r()},2e3)},style:k,onMouseEnter:n=>j(n,!0),onMouseLeave:n=>j(n,!1),children:t.jsx(v.X,{size:20})})]})]}),t.jsx(V,{chatBotData:o,theme:e,onlineStatus:E,isExpand:i,endSession:y}),t.jsx("div",{style:w,children:t.jsxs("p",{style:I,children:["powered by ",t.jsx("span",{style:z,children:"clone67.com"})]})})]})},J=({pineconeNamespace:e,primaryColor:o="#3b82f6",secondaryColor:r="#8b5cf6",backgroundColor:i="#ffffff",fontColor:u="#1f2937",placeholderColor:a="#9ca3af",position:x="right",name:y="AI Assistant",subTitle:b="AI powered assistant",welcomeText:g="Hi! How can I help you today?",aiInitialMessage:f=""})=>{const[m,S]=d.useState(!1),c=()=>S(j=>!j),s=()=>{S(!1)},p={primaryColor:o,secondaryColor:r,backgroundColor:i,fontColor:u,placeholderColor:a,inputBackgroundColor:i},C={name:y,subTitle:b,welcomeText:g,pineconeNamespace:e,position:x,aiInitialMessage:f};f===""&&(C.aiInitialMessage=`Hello! I'm ${C.name}, your AI assistant. How can I help you today?`);const k=x==="left",w="32px",I={position:"fixed",bottom:"104px",[k?"left":"right"]:w,zIndex:9999,pointerEvents:"auto"},z={position:"fixed",bottom:"32px",[k?"left":"right"]:w,zIndex:1e4,pointerEvents:"auto"};return t.jsxs(t.Fragment,{children:[m&&t.jsx("div",{style:I,children:t.jsx(B,{onClose:s,theme:p,chatBotData:C})}),t.jsx("div",{style:z,children:t.jsx(L,{onMinimise:c,isOpen:m,theme:p,chatBotData:C})})]})};module.exports=J;
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { jsxs as c, jsx as o, Fragment as M } from "react/jsx-runtime";
2
- import { useState as S, useRef as U, useEffect as D } from "react";
3
- import { Minus as j, MessageCircle as T, Send as O, Minimize2 as _, Maximize2 as F, X as H } from "lucide-react";
4
- const A = ({ onMinimise: t, isOpen: e, theme: r, chatBotData: i }) => {
5
- const p = i.position === "left", y = p ? "32px" : "auto", d = p ? "auto" : "32px", f = localStorage.getItem("clone67ChatSessionId"), u = {
1
+ import { jsxs as d, jsx as n, Fragment as M } from "react/jsx-runtime";
2
+ import { useState as h, useRef as j, useEffect as R } from "react";
3
+ import { Minus as U, MessageCircle as T, Loader as _, Send as N, Minimize2 as F, Maximize2 as H, X as A } from "lucide-react";
4
+ const V = ({ onMinimise: e, isOpen: t, theme: s, chatBotData: i }) => {
5
+ const u = i.position === "left", a = u ? "32px" : "auto", y = u ? "auto" : "32px", g = localStorage.getItem("clone67ChatSessionId"), b = {
6
6
  position: "fixed",
7
7
  bottom: "32px",
8
- left: y,
9
- right: d,
10
- background: `linear-gradient(135deg, ${r.primaryColor}, ${r.secondaryColor})`,
11
- color: r.fontColor,
8
+ left: a,
9
+ right: y,
10
+ background: `linear-gradient(135deg, ${s.primaryColor}, ${s.secondaryColor})`,
11
+ color: s.fontColor,
12
12
  width: "64px",
13
13
  height: "64px",
14
14
  borderRadius: "50%",
@@ -22,14 +22,14 @@ const A = ({ onMinimise: t, isOpen: e, theme: r, chatBotData: i }) => {
22
22
  transition: "all 300ms ease",
23
23
  outline: "none"
24
24
  };
25
- return /* @__PURE__ */ c(
25
+ return /* @__PURE__ */ d(
26
26
  "button",
27
27
  {
28
- onClick: t,
29
- style: u,
28
+ onClick: e,
29
+ style: b,
30
30
  children: [
31
- e ? /* @__PURE__ */ o(j, { size: 20, strokeWidth: 2.5 }) : /* @__PURE__ */ o(T, { size: 20, strokeWidth: 2.5 }),
32
- !e && f && /* @__PURE__ */ o("span", { style: {
31
+ t ? /* @__PURE__ */ n(U, { size: 20, strokeWidth: 2.5 }) : /* @__PURE__ */ n(T, { size: 20, strokeWidth: 2.5 }),
32
+ !t && g && /* @__PURE__ */ n("span", { style: {
33
33
  position: "absolute",
34
34
  top: "-4px",
35
35
  right: "-4px",
@@ -43,152 +43,190 @@ const A = ({ onMinimise: t, isOpen: e, theme: r, chatBotData: i }) => {
43
43
  ]
44
44
  }
45
45
  );
46
- }, a = [];
47
- for (let t = 0; t < 256; ++t)
48
- a.push((t + 256).toString(16).slice(1));
49
- function N(t, e = 0) {
50
- return (a[t[e + 0]] + a[t[e + 1]] + a[t[e + 2]] + a[t[e + 3]] + "-" + a[t[e + 4]] + a[t[e + 5]] + "-" + a[t[e + 6]] + a[t[e + 7]] + "-" + a[t[e + 8]] + a[t[e + 9]] + "-" + a[t[e + 10]] + a[t[e + 11]] + a[t[e + 12]] + a[t[e + 13]] + a[t[e + 14]] + a[t[e + 15]]).toLowerCase();
46
+ }, l = [];
47
+ for (let e = 0; e < 256; ++e)
48
+ l.push((e + 256).toString(16).slice(1));
49
+ function B(e, t = 0) {
50
+ return (l[e[t + 0]] + l[e[t + 1]] + l[e[t + 2]] + l[e[t + 3]] + "-" + l[e[t + 4]] + l[e[t + 5]] + "-" + l[e[t + 6]] + l[e[t + 7]] + "-" + l[e[t + 8]] + l[e[t + 9]] + "-" + l[e[t + 10]] + l[e[t + 11]] + l[e[t + 12]] + l[e[t + 13]] + l[e[t + 14]] + l[e[t + 15]]).toLowerCase();
51
51
  }
52
- let $;
53
- const V = new Uint8Array(16);
54
- function B() {
55
- if (!$) {
52
+ let L;
53
+ const J = new Uint8Array(16);
54
+ function P() {
55
+ if (!L) {
56
56
  if (typeof crypto > "u" || !crypto.getRandomValues)
57
57
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
58
- $ = crypto.getRandomValues.bind(crypto);
58
+ L = crypto.getRandomValues.bind(crypto);
59
59
  }
60
- return $(V);
60
+ return L(J);
61
61
  }
62
- const J = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), L = { randomUUID: J };
63
- function P(t, e, r) {
64
- t = t || {};
65
- const i = t.random ?? t.rng?.() ?? B();
62
+ const K = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), O = { randomUUID: K };
63
+ function Y(e, t, s) {
64
+ e = e || {};
65
+ const i = e.random ?? e.rng?.() ?? P();
66
66
  if (i.length < 16)
67
67
  throw new Error("Random bytes length must be >= 16");
68
- return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, N(i);
68
+ return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, B(i);
69
69
  }
70
- function K(t, e, r) {
71
- return L.randomUUID && !t ? L.randomUUID() : P(t);
70
+ function X(e, t, s) {
71
+ return O.randomUUID && !e ? O.randomUUID() : Y(e);
72
72
  }
73
- const Y = ({ messages: t, chatBotData: e, theme: r, isExpand: i }) => {
74
- const [p, y] = S([]), d = U(null), f = (n) => {
75
- if (n === "") return null;
73
+ const q = ({ messages: e, chatBotData: t, theme: s, isExpand: i }) => {
74
+ const [u, a] = h([]), y = j(null), g = (r) => {
75
+ if (r === "") return null;
76
76
  try {
77
- return JSON.parse(n);
78
- } catch (g) {
79
- return console.error("Error parsing message string to JSON:", g), null;
77
+ return JSON.parse(r);
78
+ } catch (p) {
79
+ return console.error("Error parsing message string to JSON:", p), null;
80
80
  }
81
- }, u = (n) => new Date(n).toLocaleString(void 0, {
81
+ }, b = (r) => new Date(r).toLocaleString(void 0, {
82
82
  hour: "2-digit",
83
83
  minute: "2-digit",
84
84
  hour12: !0
85
85
  });
86
- D(() => {
87
- t === "" && y([
86
+ R(() => {
87
+ e === "" && a([
88
88
  {
89
89
  created_at: Date.now(),
90
90
  sender_type: "bot",
91
- message: e.aiInitialMessage,
91
+ message: t.aiInitialMessage,
92
92
  suggested_prompt: []
93
93
  }
94
94
  ]);
95
- const n = f(t);
96
- n && y((g) => [...g, n]);
97
- }, [t]), D(() => {
98
- d.current?.scrollIntoView({ behavior: "smooth" });
99
- }, [p]);
100
- const x = p.flat(), m = {
95
+ const r = g(e);
96
+ r && a((p) => [...p, r]);
97
+ }, [e]), R(() => {
98
+ y.current?.scrollIntoView({ behavior: "smooth" });
99
+ }, [u]);
100
+ const x = u.flat(), f = {
101
101
  height: i ? "500px" : "400px",
102
102
  overflowY: "auto",
103
103
  padding: "10px",
104
- background: r.backgroundColor,
105
- color: r.fontColor,
104
+ background: s.backgroundColor,
105
+ color: s.fontColor,
106
106
  borderTop: "1px solid rgba(255, 255, 255, 0.2)",
107
107
  display: "flex",
108
108
  flexDirection: "column"
109
- }, b = (n) => ({
109
+ }, C = (r) => ({
110
110
  display: "flex",
111
- justifyContent: n === "user" ? "flex-end" : "flex-start",
111
+ justifyContent: r === "user" ? "flex-end" : "flex-start",
112
112
  width: "100%"
113
- }), C = {
113
+ }), S = {
114
114
  display: "flex",
115
115
  flexDirection: "column",
116
116
  maxWidth: "80%"
117
- }, h = (n) => ({
117
+ }, c = (r) => ({
118
118
  padding: "10px",
119
- borderRadius: n === "user" ? "12px 0 12px 12px" : "0 12px 12px 12px",
119
+ borderRadius: r === "user" ? "12px 0 12px 12px" : "0 12px 12px 12px",
120
120
  boxShadow: "0 1px 3px rgba(0, 0, 0, 0.1)",
121
121
  fontSize: "14px",
122
122
  lineHeight: "1.5",
123
- background: n === "user" ? r.primaryColor : "#f5f5f5",
124
- color: r.fontColor,
123
+ background: r === "user" ? s.primaryColor : "#f5f5f5",
124
+ color: s.fontColor,
125
125
  wordWrap: "break-word"
126
126
  });
127
- return /* @__PURE__ */ c("div", { style: m, children: [
128
- x.map((n, g) => /* @__PURE__ */ o("div", { style: b(n.sender_type), children: /* @__PURE__ */ c("div", { style: C, children: [
129
- /* @__PURE__ */ o("div", { style: n.sender_type === "user" ? h("user") : h("ai"), children: n.message }),
130
- /* @__PURE__ */ o("div", { style: {
127
+ return /* @__PURE__ */ d("div", { style: f, children: [
128
+ x.map((r, p) => /* @__PURE__ */ n("div", { style: C(r.sender_type), children: /* @__PURE__ */ d("div", { style: S, children: [
129
+ /* @__PURE__ */ n("div", { style: r.sender_type === "user" ? c("user") : c("ai"), children: r.message }),
130
+ /* @__PURE__ */ n("div", { style: {
131
131
  display: "flex",
132
132
  alignItems: "center",
133
133
  marginLeft: "4px",
134
- justifyContent: n.sender_type === "user" ? "flex-end" : "flex-start"
135
- }, children: /* @__PURE__ */ c("span", { style: { fontSize: "10px", opacity: 0.55, color: r.fontColor }, children: [
136
- n.sender_type === "user" ? "You" : `${e.name}`,
134
+ justifyContent: r.sender_type === "user" ? "flex-end" : "flex-start"
135
+ }, children: /* @__PURE__ */ d("span", { style: { fontSize: "10px", opacity: 0.55, color: s.fontColor }, children: [
136
+ r.sender_type === "user" ? "You" : `${t.name}`,
137
137
  " • ",
138
- u(n.created_at)
138
+ b(r.created_at)
139
139
  ] }) })
140
- ] }) }, g)),
141
- /* @__PURE__ */ o("div", { ref: d })
140
+ ] }) }, p)),
141
+ /* @__PURE__ */ n("div", { ref: y })
142
142
  ] });
143
- }, X = (t, e) => ({ socket: new WebSocket(`wss://handle-chat-session.clone67.com?chatbotNamespace=${e}&sessionId=${t}`) }), q = ({ chatBotData: t, theme: e, onlineStatus: r, isExpand: i }) => {
144
- const [p, y] = S(null), [d, f] = S(""), [u, x] = S("Connecting to server..."), [m, b] = S(""), [C, h] = S(!1);
145
- D(() => {
146
- var s = localStorage.getItem("clone67ChatSessionId");
147
- s === null && (s = K(), localStorage.setItem("clone67ChatSessionId", s));
148
- const { socket: w } = X(s, t.pineconeNamespace);
149
- y(w), w.onopen = () => {
150
- x("Server connected"), setTimeout(() => {
151
- x("");
152
- }, 2e3), r("online");
153
- }, w.onmessage = async (R) => {
143
+ }, G = ({ theme: e }) => {
144
+ const t = {
145
+ height: "100%",
146
+ background: e.backgroundColor,
147
+ color: e.fontColor,
148
+ display: "flex",
149
+ alignItems: "center",
150
+ justifyContent: "center"
151
+ }, s = {
152
+ padding: "24px 32px",
153
+ background: e.backgroundColor,
154
+ display: "flex",
155
+ flexDirection: "column",
156
+ alignItems: "center",
157
+ gap: "10px"
158
+ };
159
+ return /* @__PURE__ */ n("div", { style: t, children: /* @__PURE__ */ d("div", { style: s, children: [
160
+ /* @__PURE__ */ n(_, { size: 26 }),
161
+ /* @__PURE__ */ n("p", { style: {
162
+ fontSize: "14px",
163
+ opacity: 0.85
164
+ }, children: "Exiting chat… please wait" })
165
+ ] }) });
166
+ }, Q = (e, t) => ({ socket: new WebSocket(`wss://handle-chat-session.clone67.com?chatbotNamespace=${t}&sessionId=${e}`) }), Z = ({ chatBotData: e, theme: t, onlineStatus: s, isExpand: i, endSession: u }) => {
167
+ const [a, y] = h(null), [g, b] = h(""), [x, f] = h("Connecting to server..."), [C, S] = h(""), [c, r] = h(!1);
168
+ R(() => {
169
+ var o = localStorage.getItem("clone67ChatSessionId");
170
+ o === null && (o = X(), localStorage.setItem("clone67ChatSessionId", o));
171
+ const { socket: m } = Q(o, e.pineconeNamespace);
172
+ y(m), m.onopen = () => {
173
+ f("Server connected"), setTimeout(() => {
174
+ f("");
175
+ }, 2e3), s("online");
176
+ }, m.onmessage = async (E) => {
154
177
  try {
155
- const E = await R.data;
156
- b(E), h(!1);
157
- } catch (E) {
158
- console.error("Error handling server message:", E);
178
+ const D = await E.data;
179
+ S(D), r(!1);
180
+ } catch (D) {
181
+ console.error("Error handling server message:", D);
159
182
  }
160
- }, w.onerror = (R) => {
161
- x("Server error occurred"), console.error("WebSocket error:", R), r("offline");
162
- }, w.onclose = () => {
163
- x("Server disconnected"), r("offline");
183
+ }, m.onerror = (E) => {
184
+ f("Server error occurred"), console.error("WebSocket error:", E), s("offline");
185
+ }, m.onclose = () => {
186
+ f("Server disconnected"), s("offline");
164
187
  };
165
- }, []);
166
- const n = async (s) => {
167
- s.preventDefault(), p && p.readyState === WebSocket.OPEN && p.send(JSON.stringify(d)), h(!0);
168
- const w = {
188
+ }, []), R(() => {
189
+ if (u && a && a.readyState === WebSocket.OPEN) {
190
+ const o = {
191
+ type: "end_session"
192
+ };
193
+ a.send(JSON.stringify(o)), a.close(), localStorage.removeItem("clone67ChatSessionId");
194
+ }
195
+ }, [u]);
196
+ const p = async (o) => {
197
+ if (o.preventDefault(), a && a.readyState === WebSocket.OPEN) {
198
+ const E = {
199
+ type: "chat",
200
+ userInput: g
201
+ };
202
+ a.send(JSON.stringify(E));
203
+ }
204
+ r(!0);
205
+ const m = {
169
206
  created_at: Date.now(),
170
207
  sender_type: "user",
171
- message: d
208
+ message: g
172
209
  };
173
- b(JSON.stringify(w)), f("");
174
- }, g = (s) => {
175
- s.key === "Enter" && !s.shiftKey && (s.preventDefault(), n(s));
176
- }, v = {
210
+ S(JSON.stringify(m)), b("");
211
+ }, v = (o) => {
212
+ o.key === "Enter" && !o.shiftKey && (o.preventDefault(), p(o));
213
+ }, w = {
177
214
  flex: 1,
178
215
  padding: "12px 16px",
179
- background: e.backgroundColor,
180
- color: e.fontColor,
181
- border: `1px solid ${e.primaryColor}`,
216
+ background: `${c ? `${t.primaryColor}33` : t.backgroundColor}`,
217
+ color: t.fontColor,
218
+ border: `1px solid ${t.primaryColor}`,
182
219
  borderRadius: "12px",
183
220
  fontSize: "14px",
184
221
  outline: "none",
185
222
  transition: "all 0.2s ease",
186
- boxShadow: "none"
223
+ boxShadow: "none",
224
+ cursor: c ? "not-allowed" : "auto"
187
225
  }, I = {
188
226
  padding: "12px 20px",
189
227
  borderRadius: "12px",
190
- background: `linear-gradient(135deg, ${e.primaryColor}, ${e.secondaryColor})`,
191
- color: e.fontColor,
228
+ background: c ? `${t.primaryColor}33` : `linear-gradient(135deg, ${t.primaryColor}, ${t.secondaryColor})`,
229
+ color: t.fontColor,
192
230
  border: "none",
193
231
  display: "flex",
194
232
  alignItems: "center",
@@ -197,67 +235,72 @@ const Y = ({ messages: t, chatBotData: e, theme: r, isExpand: i }) => {
197
235
  fontWeight: "600",
198
236
  fontSize: "14px",
199
237
  transition: "all 0.2s ease",
200
- minWidth: "48px"
238
+ minWidth: "48px",
239
+ cursor: c ? "not-allowed" : "pointer"
201
240
  }, z = {
202
241
  padding: "10px",
203
- borderColor: e.fontColor,
204
- background: e.backgroundColor,
242
+ borderColor: t.fontColor,
243
+ background: t.backgroundColor,
205
244
  flexShrink: 0
206
- }, k = {
245
+ }, W = {
207
246
  display: "flex",
208
247
  gap: "12px",
209
248
  alignItems: "center"
210
- }, W = {
249
+ }, k = {
211
250
  textAlign: "center",
212
251
  padding: "2px",
213
- backgroundColor: u === "Server connected" || u === "online" ? "#09BA00" : u === "Connecting to server..." ? "#DED000" : "#FF3408",
252
+ backgroundColor: x === "Server connected" || x === "online" ? "#09BA00" : x === "Connecting to server..." ? "#DED000" : "#FF3408",
214
253
  color: "#ffffff",
215
254
  fontSize: "10px"
216
- }, l = {
255
+ }, $ = {
217
256
  padding: "8px",
218
257
  animation: "fadeIn 0.3s ease-in-out, pulse 1.5s ease-in-out infinite",
219
258
  animationDelay: "0s, 0.3s",
220
259
  fontSize: "10px",
221
- color: e.fontColor
260
+ color: t.fontColor
222
261
  };
223
- return /* @__PURE__ */ c(M, { children: [
224
- u && /* @__PURE__ */ o("p", { style: W, children: u }),
225
- /* @__PURE__ */ o(Y, { messages: m, chatBotData: t, theme: e, isExpand: i }),
226
- C && /* @__PURE__ */ o("div", { style: l, children: `${t.name} is typing...` }),
227
- /* @__PURE__ */ o("div", { style: z, children: /* @__PURE__ */ c("form", { onSubmit: n, style: k, children: [
228
- /* @__PURE__ */ o(
229
- "input",
230
- {
231
- type: "text",
232
- placeholder: "Type a message...",
233
- value: d,
234
- onChange: (s) => f(s.target.value),
235
- onKeyDown: g,
236
- style: v,
237
- onFocus: (s) => {
238
- s.target.style.boxShadow = `0 0 0 1px ${e.primaryColor}`, s.target.style.borderColor = e.primaryColor;
239
- },
240
- onBlur: (s) => {
241
- s.target.style.boxShadow = "none", s.target.style.borderColor = e.primaryColor;
262
+ return /* @__PURE__ */ d(M, { children: [
263
+ x && /* @__PURE__ */ n("p", { style: k, children: x }),
264
+ u ? /* @__PURE__ */ n(G, { theme: t }) : /* @__PURE__ */ d(M, { children: [
265
+ /* @__PURE__ */ n(q, { messages: C, chatBotData: e, theme: t, isExpand: i }),
266
+ c && /* @__PURE__ */ n("div", { style: $, children: `${e.name} is typing...` }),
267
+ /* @__PURE__ */ n("div", { style: z, children: /* @__PURE__ */ d("form", { onSubmit: p, style: W, children: [
268
+ /* @__PURE__ */ n(
269
+ "input",
270
+ {
271
+ type: "text",
272
+ placeholder: "Type a message...",
273
+ value: g,
274
+ onChange: (o) => b(o.target.value),
275
+ disabled: c,
276
+ onKeyDown: v,
277
+ style: w,
278
+ onFocus: (o) => {
279
+ o.target.style.boxShadow = `0 0 0 1px ${t.primaryColor}`, o.target.style.borderColor = t.primaryColor;
280
+ },
281
+ onBlur: (o) => {
282
+ o.target.style.boxShadow = "none", o.target.style.borderColor = t.primaryColor;
283
+ }
242
284
  }
243
- }
244
- ),
245
- /* @__PURE__ */ o(
246
- "button",
247
- {
248
- onClick: n,
249
- style: I,
250
- "aria-label": "Send message",
251
- children: /* @__PURE__ */ o(O, { size: 18 })
252
- }
253
- )
254
- ] }) })
285
+ ),
286
+ /* @__PURE__ */ n(
287
+ "button",
288
+ {
289
+ onClick: p,
290
+ style: I,
291
+ disabled: c,
292
+ "aria-label": "Send message",
293
+ children: /* @__PURE__ */ n(N, { size: 18 })
294
+ }
295
+ )
296
+ ] }) })
297
+ ] })
255
298
  ] });
256
- }, G = ({ onClose: t, theme: e, chatBotData: r }) => {
257
- const [i, p] = S(!1), [y, d] = S(!1), u = {
299
+ }, ee = ({ theme: e, chatBotData: t, onClose: s }) => {
300
+ const [i, u] = h(!1), [a, y] = h(!1), [g, b] = h(!1), f = {
258
301
  position: "fixed",
259
302
  bottom: "112px",
260
- [r.position === "left" ? "left" : "right"]: "32px",
303
+ [t.position === "left" ? "left" : "right"]: "32px",
261
304
  zIndex: 50,
262
305
  width: i ? "684px" : "384px",
263
306
  height: i ? "620px" : "520px",
@@ -271,7 +314,7 @@ const Y = ({ messages: t, chatBotData: e, theme: r, isExpand: i }) => {
271
314
  overflow: "hidden",
272
315
  fontFamily: "system-ui, -apple-system, sans-serif",
273
316
  boxShadow: "0 10px 25px -3px rgba(0,0,0,0.1)"
274
- }, x = {
317
+ }, C = {
275
318
  padding: "16px 20px",
276
319
  background: `linear-gradient(135deg, ${e.primaryColor}, ${e.secondaryColor})`,
277
320
  color: e.fontColor,
@@ -280,9 +323,9 @@ const Y = ({ messages: t, chatBotData: e, theme: r, isExpand: i }) => {
280
323
  alignItems: "center",
281
324
  justifyContent: "space-between",
282
325
  boxShadow: "0 4px 6px -1px rgba(0,0,0,0.1)"
283
- }, m = {
326
+ }, S = {
284
327
  position: "relative"
285
- }, b = {
328
+ }, c = {
286
329
  width: "44px",
287
330
  height: "44px",
288
331
  borderRadius: "50%",
@@ -290,155 +333,158 @@ const Y = ({ messages: t, chatBotData: e, theme: r, isExpand: i }) => {
290
333
  display: "flex",
291
334
  alignItems: "center",
292
335
  justifyContent: "center"
293
- }, C = {
336
+ }, r = {
294
337
  position: "absolute",
295
338
  bottom: 0,
296
339
  right: 0,
297
340
  width: "14px",
298
341
  height: "14px",
299
- backgroundColor: y ? "#00BF49" : "#F54927",
342
+ backgroundColor: a ? "#00BF49" : "#F54927",
300
343
  borderRadius: "50%",
301
344
  border: "3px solid white"
302
- }, h = {
345
+ }, p = {
303
346
  fontSize: "18px",
304
347
  fontWeight: "600",
305
348
  margin: 0,
306
349
  lineHeight: "1.2"
307
- }, n = {
350
+ }, v = {
308
351
  fontSize: "12px",
309
352
  opacity: 0.9,
310
353
  margin: 0,
311
354
  lineHeight: "1.3"
312
- }, g = {
355
+ }, w = {
313
356
  padding: "8px",
314
357
  borderRadius: "50%",
315
358
  background: "transparent",
316
359
  border: "none",
317
360
  cursor: "pointer",
318
361
  transition: "background 0.2s"
319
- }, v = {
362
+ }, I = {
320
363
  padding: "10px",
321
364
  borderTop: "1px solid rgba(255,255,255,0.2)",
322
365
  background: e.backgroundColor,
323
366
  textAlign: "center"
324
- }, I = {
367
+ }, z = {
325
368
  fontSize: "11px",
326
369
  color: e.fontColor,
327
370
  letterSpacing: "0.5px"
328
- }, z = {
371
+ }, W = {
329
372
  fontWeight: "600"
330
- }, k = (l, s) => {
331
- l.currentTarget.style.background = s ? "rgba(255,255,255,0.2)" : "transparent";
332
- }, W = (l) => {
333
- d(l === "online");
373
+ }, k = (o, m) => {
374
+ o.currentTarget.style.background = m ? "rgba(255,255,255,0.2)" : "transparent";
375
+ }, $ = (o) => {
376
+ y(o === "online");
334
377
  };
335
- return /* @__PURE__ */ c("div", { style: u, children: [
336
- /* @__PURE__ */ c("div", { style: x, children: [
337
- /* @__PURE__ */ c("div", { style: { display: "flex", alignItems: "center", gap: "12px" }, children: [
338
- /* @__PURE__ */ c("div", { style: m, children: [
339
- /* @__PURE__ */ o("div", { style: b, children: /* @__PURE__ */ o(T, { size: 22 }) }),
340
- /* @__PURE__ */ o("span", { style: C })
378
+ return /* @__PURE__ */ d("div", { style: f, children: [
379
+ /* @__PURE__ */ d("div", { style: C, children: [
380
+ /* @__PURE__ */ d("div", { style: { display: "flex", alignItems: "center", gap: "12px" }, children: [
381
+ /* @__PURE__ */ d("div", { style: S, children: [
382
+ /* @__PURE__ */ n("div", { style: c, children: /* @__PURE__ */ n(T, { size: 22 }) }),
383
+ /* @__PURE__ */ n("span", { style: r })
341
384
  ] }),
342
- /* @__PURE__ */ c("div", { children: [
343
- /* @__PURE__ */ o("h3", { style: h, children: r.name }),
344
- /* @__PURE__ */ o("p", { style: n, children: r.subTitle })
385
+ /* @__PURE__ */ d("div", { children: [
386
+ /* @__PURE__ */ n("h3", { style: p, children: t.name }),
387
+ /* @__PURE__ */ n("p", { style: v, children: t.subTitle })
345
388
  ] })
346
389
  ] }),
347
- /* @__PURE__ */ c("div", { style: { display: "flex", alignItems: "left" }, children: [
348
- /* @__PURE__ */ o(
390
+ /* @__PURE__ */ d("div", { style: { display: "flex", alignItems: "left" }, children: [
391
+ /* @__PURE__ */ n(
349
392
  "button",
350
393
  {
351
- onClick: () => p((l) => !l),
394
+ onClick: () => u((o) => !o),
352
395
  "aria-label": "expand chat",
353
- style: g,
354
- onMouseEnter: (l) => k(l, !0),
355
- onMouseLeave: (l) => k(l, !1),
356
- children: i ? /* @__PURE__ */ o(_, { size: 20 }) : /* @__PURE__ */ o(F, { size: 20 })
396
+ style: w,
397
+ onMouseEnter: (o) => k(o, !0),
398
+ onMouseLeave: (o) => k(o, !1),
399
+ children: i ? /* @__PURE__ */ n(F, { size: 20 }) : /* @__PURE__ */ n(H, { size: 20 })
357
400
  }
358
401
  ),
359
- /* @__PURE__ */ o(
402
+ /* @__PURE__ */ n(
360
403
  "button",
361
404
  {
362
- onClick: t,
363
- "aria-label": "close chat",
364
- style: g,
365
- onMouseEnter: (l) => k(l, !0),
366
- onMouseLeave: (l) => k(l, !1),
367
- children: /* @__PURE__ */ o(H, { size: 20 })
405
+ onClick: () => {
406
+ b(!0), setTimeout(() => {
407
+ s();
408
+ }, 2e3);
409
+ },
410
+ style: w,
411
+ onMouseEnter: (o) => k(o, !0),
412
+ onMouseLeave: (o) => k(o, !1),
413
+ children: /* @__PURE__ */ n(A, { size: 20 })
368
414
  }
369
415
  )
370
416
  ] })
371
417
  ] }),
372
- /* @__PURE__ */ o(q, { chatBotData: r, theme: e, onlineStatus: W, isExpand: i }),
373
- /* @__PURE__ */ o("div", { style: v, children: /* @__PURE__ */ c("p", { style: I, children: [
418
+ /* @__PURE__ */ n(Z, { chatBotData: t, theme: e, onlineStatus: $, isExpand: i, endSession: g }),
419
+ /* @__PURE__ */ n("div", { style: I, children: /* @__PURE__ */ d("p", { style: z, children: [
374
420
  "powered by ",
375
- /* @__PURE__ */ o("span", { style: z, children: "clone67.com" })
421
+ /* @__PURE__ */ n("span", { style: W, children: "clone67.com" })
376
422
  ] }) })
377
423
  ] });
378
- }, te = ({
379
- pineconeNamespace: t,
380
- primaryColor: e = "#3b82f6",
381
- secondaryColor: r = "#8b5cf6",
424
+ }, re = ({
425
+ pineconeNamespace: e,
426
+ primaryColor: t = "#3b82f6",
427
+ secondaryColor: s = "#8b5cf6",
382
428
  backgroundColor: i = "#ffffff",
383
- fontColor: p = "#1f2937",
384
- placeholderColor: y = "#9ca3af",
385
- position: d = "right",
386
- name: f = "AI Assistant",
387
- subTitle: u = "AI powered assistant",
429
+ fontColor: u = "#1f2937",
430
+ placeholderColor: a = "#9ca3af",
431
+ position: y = "right",
432
+ name: g = "AI Assistant",
433
+ subTitle: b = "AI powered assistant",
388
434
  welcomeText: x = "Hi! How can I help you today?",
389
- aiInitialMessage: m = ""
435
+ aiInitialMessage: f = ""
390
436
  }) => {
391
- const [b, C] = S(!1), h = () => {
392
- C((l) => !l), localStorage.removeItem("clone67ChatSessionId");
393
- }, n = () => C((l) => !l), g = {
394
- primaryColor: e,
395
- secondaryColor: r,
437
+ const [C, S] = h(!1), c = () => S((k) => !k), r = () => {
438
+ S(!1);
439
+ }, p = {
440
+ primaryColor: t,
441
+ secondaryColor: s,
396
442
  backgroundColor: i,
397
- fontColor: p,
398
- placeholderColor: y,
443
+ fontColor: u,
444
+ placeholderColor: a,
399
445
  inputBackgroundColor: i
400
446
  }, v = {
401
- name: f,
402
- subTitle: u,
447
+ name: g,
448
+ subTitle: b,
403
449
  welcomeText: x,
404
- pineconeNamespace: t,
405
- position: d,
406
- aiInitialMessage: m
450
+ pineconeNamespace: e,
451
+ position: y,
452
+ aiInitialMessage: f
407
453
  };
408
- m === "" && (v.aiInitialMessage = `Hello! I'm ${v.name}, your AI assistant. How can I help you today?`);
409
- const I = d === "left", z = "32px", k = {
454
+ f === "" && (v.aiInitialMessage = `Hello! I'm ${v.name}, your AI assistant. How can I help you today?`);
455
+ const w = y === "left", I = "32px", z = {
410
456
  position: "fixed",
411
457
  bottom: "104px",
412
- [I ? "left" : "right"]: z,
458
+ [w ? "left" : "right"]: I,
413
459
  zIndex: 9999,
414
460
  pointerEvents: "auto"
415
461
  }, W = {
416
462
  position: "fixed",
417
463
  bottom: "32px",
418
- [I ? "left" : "right"]: z,
464
+ [w ? "left" : "right"]: I,
419
465
  zIndex: 1e4,
420
466
  pointerEvents: "auto"
421
467
  };
422
- return /* @__PURE__ */ c(M, { children: [
423
- b && /* @__PURE__ */ o("div", { style: k, children: /* @__PURE__ */ o(
424
- G,
468
+ return /* @__PURE__ */ d(M, { children: [
469
+ C && /* @__PURE__ */ n("div", { style: z, children: /* @__PURE__ */ n(
470
+ ee,
425
471
  {
426
- onClose: h,
427
- theme: g,
472
+ onClose: r,
473
+ theme: p,
428
474
  chatBotData: v
429
475
  }
430
476
  ) }),
431
- /* @__PURE__ */ o("div", { style: W, children: /* @__PURE__ */ o(
432
- A,
477
+ /* @__PURE__ */ n("div", { style: W, children: /* @__PURE__ */ n(
478
+ V,
433
479
  {
434
- onMinimise: n,
435
- isOpen: b,
436
- theme: g,
480
+ onMinimise: c,
481
+ isOpen: C,
482
+ theme: p,
437
483
  chatBotData: v
438
484
  }
439
485
  ) })
440
486
  ] });
441
487
  };
442
488
  export {
443
- te as default
489
+ re as default
444
490
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-aichatbot-widget",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "A React ChatBot Widget",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",