react-aichatbot-widget 2.0.1 → 2.0.3

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