react-aichatbot-widget 2.0.0 → 2.0.2

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