nui-chatbot-pkg 1.0.7 → 1.0.8
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.
Potentially problematic release.
This version of nui-chatbot-pkg might be problematic. Click here for more details.
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";"use client";var K=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var r in t)K(e,r,{get:t[r],enumerable:!0})},he=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of le(t))!me.call(e,a)&&a!==r&&K(e,a,{get:()=>t[a],enumerable:!(o=ce(t,a))||o.enumerable});return e};var ue=e=>he(K({},"__esModule",{value:!0}),e);var Ce={};pe(Ce,{ChatBot:()=>Z,ChatHeader:()=>W,ChatInput:()=>U,Chatbot:()=>Z,ICONS:()=>I,MessageBubble:()=>F,Suggestions:()=>Q});module.exports=ue(Ce);var k=require("react");var f=require("react/jsx-runtime"),I={MessageCircle:({size:e=24,className:t=""})=>(0,f.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,f.jsx)("path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z"})}),Bot:({size:e=24,className:t=""})=>(0,f.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,f.jsx)("path",{d:"M12 8V4m8 4V4M4 8V4M2 11h20m-1 0v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V11m5 5v2m8-2v2"})}),X:({size:e=24,className:t=""})=>(0,f.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,f.jsx)("path",{d:"M18 6 6 18M6 6l12 12"})}),Sparkles:({size:e=24,className:t=""})=>(0,f.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,f.jsx)("path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"})}),Send:({size:e=24,className:t=""})=>(0,f.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,f.jsx)("path",{d:"m22 2-7 20-4-9-9-4Z"}),(0,f.jsx)("path",{d:"M22 2 11 13"})]})};var R=require("react/jsx-runtime"),ge=({isExpanded:e,onOpen:t,theming:r})=>(0,R.jsx)("div",{onClick:t,className:`chat-floating-btn ${e?"chat-btn-hidden":"chat-btn-visible"}`,children:(0,R.jsx)("div",{className:"chat-btn-border seamless-border",children:(0,R.jsxs)("div",{className:"chat-btn-inner",children:[(0,R.jsx)("div",{className:"chat-btn-gradient",style:{background:r?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary))"}}),(0,R.jsx)(I.MessageCircle,{size:30,className:"chat-btn-icon"})]})})}),_=ge;var Y=require("react");var B=(e,t)=>t?`${e} ${t}`:e;var y=require("react/jsx-runtime"),fe=({onClose:e,title:t,theming:r,strapiUrl:o})=>{let[a,i]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{if(!o)return;(async()=>{try{let m=await(await fetch(`${o}/api/faq-ai-bot/suggestion-and-logo`)).json();m?.logoUrl&&i(`${o}${m.logoUrl}`)}catch(l){console.error("Failed to fetch logo",l)}})()},[o]);let u=B("chat-header",r?.header);return(0,y.jsxs)("header",{className:u,style:r?.headerStyle,children:[(0,y.jsxs)("div",{className:"chat-header-left",children:[a?(0,y.jsx)("img",{src:a,alt:"Bot Logo",className:"chat-header-logo"}):(0,y.jsx)("div",{className:"chat-header-logo-placeholder",children:(0,y.jsx)(I.Bot,{size:20,className:"chat-header-bot-icon"})}),(0,y.jsx)("div",{className:"chat-header-title-wrap",children:(0,y.jsx)("span",{className:"chat-header-title",children:t})})]}),(0,y.jsx)("div",{className:"chat-header-actions",children:(0,y.jsx)("button",{onClick:e,className:"chat-header-close-btn","aria-label":"Close chat",children:(0,y.jsx)(I.X,{size:20})})})]})},W=fe;var A=require("react");var b=require("react/jsx-runtime"),be=({input:e,onInputChange:t,onSendMessage:r,isLoading:o,theming:a})=>{let i=a?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))",s=(0,A.useRef)(null),d=B("chat-input-container",a?.input);(0,A.useEffect)(()=>{o||s.current?.focus()},[o]);let l=m=>{m.key==="Enter"&&!m.nativeEvent.isComposing&&e.trim()&&!o&&r()};return(0,b.jsx)("div",{className:"chat-input-outer",children:(0,b.jsxs)("div",{className:"chat-input-wrap",children:[(0,b.jsx)("div",{style:{background:i},className:"chat-input-glow-lg"}),(0,b.jsx)("div",{style:{background:i},className:"chat-input-glow-sm"}),(0,b.jsx)("div",{className:d,style:a?.inputStyle,children:(0,b.jsxs)("div",{className:"chat-input-inner",children:[(0,b.jsx)("input",{ref:s,type:"text",className:"chat-input-field",placeholder:o?"AI is thinking...":"Ask anything...",value:e,onChange:m=>t(m.target.value),onKeyDown:l,disabled:o,"aria-label":"User message"}),(0,b.jsx)("div",{className:"chat-input-send-wrap",children:(0,b.jsx)("button",{onClick:r,disabled:o||!e.trim(),style:{background:i},className:"chat-input-send-btn","aria-label":"Send message",children:o?(0,b.jsx)("div",{className:"chat-input-spinner"}):(0,b.jsx)(I.Send,{className:"chat-input-send-icon"})})})]})})]})})},U=be;var w=require("react/jsx-runtime"),we=({message:e,cardRegistry:t,themeStyles:r,theming:o})=>{let a=s=>{let u=s?.__collectionUid?.split(".").pop()?.toLowerCase();return t.find(d=>d.id===u)||t.find(d=>d.id==="default")},i=e.record?a(e.record)?.component:null;if(e.items?.items?.length){let s=e.items.cardStyle?.toLowerCase()||e.items.collection?.toLowerCase()||e.items.title?.toLowerCase(),d=t.find(l=>l.id===s)?.component;return(0,w.jsxs)("div",{className:"mb-card-container",children:[e.content&&(0,w.jsx)("div",{className:"mb-card-content",children:e.content}),d&&e.items.items.map((l,m)=>(0,w.jsx)(d,{items:l,style:r},m))]})}return(0,w.jsx)("div",{className:`mb-row ${e.role==="user"?"mb-row-user":"mb-row-assistant"}`,children:i&&e.record?(0,w.jsx)("div",{className:"mb-card-wrapper",children:(0,w.jsx)(i,{record:e.record,style:r})}):(0,w.jsx)("div",{style:e.role==="user"?{background:o?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))"}:{},className:`mb-bubble ${e.role==="user"?"mb-bubble-user":"mb-bubble-assistant"}`,children:e.loading&&!e.content?(0,w.jsxs)("div",{className:"mb-typing",children:[(0,w.jsx)("span",{className:"mb-dot mb-dot-1"}),(0,w.jsx)("span",{className:"mb-dot mb-dot-2"}),(0,w.jsx)("span",{className:"mb-dot mb-dot-3"})]}):e.content})})},F=we;var T=require("react");var c=require("react/jsx-runtime"),xe=({strapiUrl:e,onSelectQuestion:t,variant:r,theming:o})=>{let[a,i]=(0,T.useState)([]),[s,u]=(0,T.useState)(!0),[d,l]=(0,T.useState)(!1);(0,T.useEffect)(()=>{let n=new AbortController;return u(!0),fetch(`${e}/api/faq-ai-bot/suggestion-and-logo`,{signal:n.signal}).then(p=>p.json()).then(p=>{i(p.suggestedQuestions||[]),u(!1)}).catch(p=>{p.name!=="AbortError"&&(console.error("Suggestions fetch failed",p),u(!1))}),()=>n.abort()},[e]);let m=()=>r==="floating"?(0,c.jsxs)("div",{className:"sug-skeleton-float",children:[[1,2].map(n=>(0,c.jsx)("div",{className:"sug-skeleton-item",style:{backgroundColor:o?.primaryColor?`${o.primaryColor}`:"hsla(178, 100%, 51%, 0.05)",transform:n%2===0?"rotate(1deg)":"rotate(-1deg)"}},n)),(0,c.jsx)("div",{className:"sug-skeleton-more"})]}):(0,c.jsx)("div",{className:"sug-skeleton-list",children:[1,2,3].map(n=>(0,c.jsx)("div",{className:"sug-skeleton-chip"},n))});if(s&&a.length===0)return(0,c.jsx)(m,{});if(r==="floating"){let n=d?a:a.slice(0,2),p=!d&&a.length>2;return(0,c.jsxs)("div",{className:"sug-float-wrap",children:[n.map((M,z)=>{let G=z%2===0?"rotate(-1deg)":"rotate(1deg)";return(0,c.jsx)("button",{onClick:()=>t(M),className:"sug-float-btn",style:{borderColor:o?.primaryColor||"var(--cb-primary)",transform:G,animationDelay:`${z*.1}s`},children:(0,c.jsx)("span",{className:"sug-float-text",children:M})},`float-${z}-${M}`)}),p&&(0,c.jsx)("button",{onClick:()=>l(!0),"aria-label":"Show more suggestions",title:"Show more suggestions",className:"sug-more-btn",style:{animationDelay:`${n.length*.1}s`},children:(0,c.jsxs)("div",{className:"sug-more-dots",style:{color:o?.secondaryColor||"var(--cb-secondary)"},children:[(0,c.jsx)("span",{}),(0,c.jsx)("span",{}),(0,c.jsx)("span",{})]})})]})}return(0,c.jsx)("div",{className:"sug-list-wrap",children:a.map((n,p)=>(0,c.jsx)("button",{onClick:()=>t(n),className:"sug-list-btn",style:{animationDelay:`${p*.05}s`},children:n},`list-${p}-${n}`))})},Q=xe;var v=require("react/jsx-runtime"),ye=({messages:e,scrollRef:t,sendMessage:r,strapiUrl:o,resolvedRegistry:a,theming:i})=>{let s=i?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))",u=i?.welcomeMessage||"How can I help you?",d=i?.welcomeDescription||"Select a common question below or type your own.";return(0,v.jsxs)("div",{ref:t,className:"chat-messages-container",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:[e.length===0&&(0,v.jsxs)("div",{className:"chat-welcome",children:[(0,v.jsx)("div",{className:"chat-welcome-icon",style:{background:s},children:(0,v.jsx)(I.MessageCircle,{size:40})}),(0,v.jsxs)("div",{children:[(0,v.jsx)("h3",{className:"chat-welcome-title",children:u}),(0,v.jsx)("p",{className:"chat-welcome-subtitle",children:d})]}),(0,v.jsx)("div",{className:"chat-welcome-suggestions",children:(0,v.jsx)(Q,{onSelectQuestion:r,strapiUrl:o,variant:"floating",theming:i})})]}),e.map(l=>(0,v.jsx)(F,{message:l,cardRegistry:a,theming:i},l.id))]})},ee=ye;var N=require("react/jsx-runtime"),ve=({isExpanded:e,setIsExpanded:t,messages:r,scrollRef:o,sendMessage:a,strapiUrl:i,resolvedRegistry:s,input:u,setInput:d,isLoading:l,title:m,theming:n})=>{let p=B(`chat-window ${e?"chat-window-open":"chat-window-closed"}`,n?.container);return(0,N.jsxs)("div",{className:p,style:n?.containerStyle,children:[(0,N.jsx)("div",{className:"chat-window-header",children:(0,N.jsx)(W,{title:m,onClose:()=>t(!1),theming:n,strapiUrl:i})}),(0,N.jsx)(ee,{messages:r,scrollRef:o,sendMessage:a,strapiUrl:i,resolvedRegistry:s,theming:n}),(0,N.jsxs)("div",{className:"chat-window-footer",children:[(0,N.jsx)(U,{input:u,onInputChange:d,onSendMessage:a,isLoading:l,theming:n}),(0,N.jsx)("div",{className:"chat-window-powered",children:(0,N.jsxs)("span",{className:"chat-powered-text",children:["Powered by"," ",(0,N.jsx)("a",{href:"https://numentica-ui.com",className:"chat-powered-link",children:"Numentica-UI"})]})})]})]})},te=ve;var O=require("react/jsx-runtime"),ke=({strapiUrl:e,cardRegistry:t,theme:r,title:o,streamSpeed:a})=>{let[i,s]=(0,k.useState)([]),[u,d]=(0,k.useState)(""),[l,m]=(0,k.useState)(!1),[n,p]=(0,k.useState)(!1),M=(0,k.useRef)(null),[z,G]=(0,k.useState)([]),ae=(0,k.useRef)(null),re={"--cb-primary":r?.primaryColor||"#2999d6","--cb-secondary":r?.secondaryColor||"#179fa3","--cb-accent":r?.accentColor||"#07a372"};return(0,k.useEffect)(()=>{t.length>0&&G(t)},[t]),(0,k.useEffect)(()=>()=>M.current?.abort(),[]),(0,O.jsxs)("div",{className:"chatbot-container",style:re,children:[(0,O.jsx)(_,{isExpanded:n,onOpen:()=>p(!0),theming:r}),(0,O.jsx)(te,{isExpanded:n,setIsExpanded:p,messages:i,scrollRef:ae,sendMessage:async oe=>{let V=oe||u;if(!V.trim())return;M.current?.abort(),M.current=new AbortController,p(!0),d(""),m(!0);let ne={role:"user",content:V,id:Date.now()},S=Date.now()+1;s(L=>[...L,ne,{role:"assistant",content:"",items:null,loading:!0,id:S}]);try{let L=await fetch(`${e}/api/faq-ai-bot/ask`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:V,history:i.slice(-4).map(g=>({role:g.role,content:g.content}))}),signal:M.current.signal});if(!L.ok)throw new Error("Network response was not ok");let D=L.body?.getReader(),P=new TextDecoder;if(!D)throw new Error("No reader available");let $=[],J=!1,ie=(async()=>{for(;!J||$.length>0;)if($.length>0){let g=$.shift();if(g?.type==="text")if(a&&a>0)for(let h of g.content)s(x=>x.map(C=>C.id===S?{...C,content:C.content+h}:C)),await new Promise(x=>setTimeout(x,a));else s(h=>h.map(x=>x.id===S?{...x,content:x.content+g.content}:x));else if(g?.type==="card")try{let h=g.data;s(x=>x.map(C=>C.id===S?{...C,items:{items:h.items,schema:h.schema,collection:h.title,title:h.title,cardStyle:h.cardStyle}}:C))}catch(h){console.error("Error processing card data:",h)}}else await new Promise(g=>setTimeout(g,20));m(!1),s(g=>g.map(h=>h.id===S?{...h,loading:!1}:h))})(),q="";for(;;){let{value:g,done:h}=await D.read();if(h)break;let x=P.decode(g,{stream:!0});q+=x;let C=q.split(`
|
|
1
|
+
"use strict";"use client";var K=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var r in t)K(e,r,{get:t[r],enumerable:!0})},he=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of le(t))!me.call(e,a)&&a!==r&&K(e,a,{get:()=>t[a],enumerable:!(o=ce(t,a))||o.enumerable});return e};var ue=e=>he(K({},"__esModule",{value:!0}),e);var Ce={};pe(Ce,{ChatBot:()=>Z,ChatHeader:()=>W,ChatInput:()=>U,Chatbot:()=>Z,ICONS:()=>I,MessageBubble:()=>F,Suggestions:()=>Q});module.exports=ue(Ce);var k=require("react");var f=require("react/jsx-runtime"),I={MessageCircle:({size:e=24,className:t=""})=>(0,f.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,f.jsx)("path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z"})}),Bot:({size:e=24,className:t=""})=>(0,f.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,f.jsx)("path",{d:"M12 8V4m8 4V4M4 8V4M2 11h20m-1 0v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V11m5 5v2m8-2v2"})}),X:({size:e=24,className:t=""})=>(0,f.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,f.jsx)("path",{d:"M18 6 6 18M6 6l12 12"})}),Sparkles:({size:e=24,className:t=""})=>(0,f.jsx)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,f.jsx)("path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"})}),Send:({size:e=24,className:t=""})=>(0,f.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,f.jsx)("path",{d:"m22 2-7 20-4-9-9-4Z"}),(0,f.jsx)("path",{d:"M22 2 11 13"})]})};var R=require("react/jsx-runtime"),ge=({isExpanded:e,onOpen:t,theming:r})=>(0,R.jsx)("div",{onClick:t,className:`chat-floating-btn ${e?"chat-btn-hidden":"chat-btn-visible"}`,children:(0,R.jsx)("div",{className:"chat-btn-border seamless-border",children:(0,R.jsxs)("div",{className:"chat-btn-inner",children:[(0,R.jsx)("div",{className:"chat-btn-gradient",style:{background:r?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary))"}}),(0,R.jsx)(I.MessageCircle,{size:30,className:"chat-btn-icon"})]})})}),_=ge;var Y=require("react");var T=(e,t)=>t?`${e} ${t}`:e;var y=require("react/jsx-runtime"),fe=({onClose:e,title:t,theming:r,strapiUrl:o})=>{let[a,i]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{if(!o)return;(async()=>{try{let m=await(await fetch(`${o}/api/faq-ai-bot/suggestion-and-logo`)).json();m?.logoUrl&&i(`${o}${m.logoUrl}`)}catch(l){console.error("Failed to fetch logo",l)}})()},[o]);let u=T("chat-header",r?.header);return(0,y.jsxs)("header",{className:u,style:r?.headerStyle,children:[(0,y.jsxs)("div",{className:"chat-header-left",children:[a?(0,y.jsx)("img",{src:a,alt:"Bot Logo",className:"chat-header-logo"}):(0,y.jsx)("div",{className:"chat-header-logo-placeholder",children:(0,y.jsx)(I.Bot,{size:20,className:"chat-header-bot-icon"})}),(0,y.jsx)("div",{className:"chat-header-title-wrap",children:(0,y.jsx)("span",{className:"chat-header-title",children:t})})]}),(0,y.jsx)("div",{className:"chat-header-actions",children:(0,y.jsx)("button",{onClick:e,className:"chat-header-close-btn","aria-label":"Close chat",children:(0,y.jsx)(I.X,{size:20})})})]})},W=fe;var A=require("react");var b=require("react/jsx-runtime"),be=({input:e,onInputChange:t,onSendMessage:r,isLoading:o,theming:a})=>{let i=a?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))",s=(0,A.useRef)(null),d=T("chat-input-container",a?.input);(0,A.useEffect)(()=>{o||s.current?.focus()},[o]);let l=m=>{m.key==="Enter"&&!m.nativeEvent.isComposing&&e.trim()&&!o&&r()};return(0,b.jsx)("div",{className:"chat-input-outer",children:(0,b.jsxs)("div",{className:"chat-input-wrap",children:[(0,b.jsx)("div",{style:{background:i},className:"chat-input-glow-lg"}),(0,b.jsx)("div",{style:{background:i},className:"chat-input-glow-sm"}),(0,b.jsx)("div",{className:d,style:a?.inputStyle,children:(0,b.jsxs)("div",{className:"chat-input-inner",children:[(0,b.jsx)("input",{ref:s,type:"text",className:"chat-input-field",placeholder:o?"AI is thinking...":"Ask anything...",value:e,onChange:m=>t(m.target.value),onKeyDown:l,disabled:o,"aria-label":"User message"}),(0,b.jsx)("div",{className:"chat-input-send-wrap",children:(0,b.jsx)("button",{onClick:r,disabled:o||!e.trim(),style:{background:i},className:"chat-input-send-btn","aria-label":"Send message",children:o?(0,b.jsx)("div",{className:"chat-input-spinner"}):(0,b.jsx)(I.Send,{className:"chat-input-send-icon"})})})]})})]})})},U=be;var w=require("react/jsx-runtime"),we=({message:e,cardRegistry:t,themeStyles:r,theming:o})=>{let a=s=>{let u=s?.__collectionUid?.split(".").pop()?.toLowerCase();return t.find(d=>d.id===u)||t.find(d=>d.id==="default")},i=e.record?a(e.record)?.component:null;if(e.items?.items?.length){let s=e.items.cardStyle?.toLowerCase()||e.items.collection?.toLowerCase()||e.items.title?.toLowerCase(),d=t.find(l=>l.id===s)?.component;return(0,w.jsxs)("div",{className:"mb-card-container",children:[e.content&&(0,w.jsx)("div",{className:"mb-card-content",children:e.content}),d&&e.items.items.map((l,m)=>(0,w.jsx)(d,{items:l,style:r},m))]})}return(0,w.jsx)("div",{className:`mb-row ${e.role==="user"?"mb-row-user":"mb-row-assistant"}`,children:i&&e.record?(0,w.jsx)("div",{className:"mb-card-wrapper",children:(0,w.jsx)(i,{record:e.record,style:r})}):(0,w.jsx)("div",{style:e.role==="user"?{background:o?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))"}:{},className:`mb-bubble ${e.role==="user"?"mb-bubble-user":"mb-bubble-assistant"}`,children:e.loading&&!e.content?(0,w.jsxs)("div",{className:"mb-typing",children:[(0,w.jsx)("span",{className:"mb-dot mb-dot-1"}),(0,w.jsx)("span",{className:"mb-dot mb-dot-2"}),(0,w.jsx)("span",{className:"mb-dot mb-dot-3"})]}):e.content})})},F=we;var z=require("react");var c=require("react/jsx-runtime"),xe=({strapiUrl:e,onSelectQuestion:t,variant:r,theming:o})=>{let[a,i]=(0,z.useState)([]),[s,u]=(0,z.useState)(!0),[d,l]=(0,z.useState)(!1);(0,z.useEffect)(()=>{let n=new AbortController;return u(!0),fetch(`${e}/api/faq-ai-bot/suggestion-and-logo`,{signal:n.signal}).then(p=>p.json()).then(p=>{i(p.suggestedQuestions||[]),u(!1)}).catch(p=>{p.name!=="AbortError"&&(console.error("Suggestions fetch failed",p),u(!1))}),()=>n.abort()},[e]);let m=()=>r==="floating"?(0,c.jsxs)("div",{className:"sug-skeleton-float",children:[[1,2].map(n=>(0,c.jsx)("div",{className:"sug-skeleton-item",style:{backgroundColor:o?.primaryColor?`${o.primaryColor}`:"hsla(178, 100%, 51%, 0.05)",transform:n%2===0?"rotate(1deg)":"rotate(-1deg)"}},n)),(0,c.jsx)("div",{className:"sug-skeleton-more"})]}):(0,c.jsx)("div",{className:"sug-skeleton-list",children:[1,2,3].map(n=>(0,c.jsx)("div",{className:"sug-skeleton-chip"},n))});if(s&&a.length===0)return(0,c.jsx)(m,{});if(r==="floating"){let n=d?a:a.slice(0,2),p=!d&&a.length>2;return(0,c.jsxs)("div",{className:"sug-float-wrap",children:[n.map((M,P)=>{let G=P%2===0?"rotate(-1deg)":"rotate(1deg)";return(0,c.jsx)("button",{onClick:()=>t(M),className:"sug-float-btn",style:{borderColor:o?.primaryColor||"var(--cb-primary)",transform:G,animationDelay:`${P*.1}s`},children:(0,c.jsx)("span",{className:"sug-float-text",children:M})},`float-${P}-${M}`)}),p&&(0,c.jsx)("button",{onClick:()=>l(!0),"aria-label":"Show more suggestions",title:"Show more suggestions",className:"sug-more-btn",style:{animationDelay:`${n.length*.1}s`},children:(0,c.jsxs)("div",{className:"sug-more-dots",style:{color:o?.secondaryColor||"var(--cb-secondary)"},children:[(0,c.jsx)("span",{}),(0,c.jsx)("span",{}),(0,c.jsx)("span",{})]})})]})}return(0,c.jsx)("div",{className:"sug-list-wrap",children:a.map((n,p)=>(0,c.jsx)("button",{onClick:()=>t(n),className:"sug-list-btn",style:{animationDelay:`${p*.05}s`},children:n},`list-${p}-${n}`))})},Q=xe;var v=require("react/jsx-runtime"),ye=({messages:e,scrollRef:t,sendMessage:r,strapiUrl:o,resolvedRegistry:a,theming:i})=>{let s=i?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))",u=i?.welcomeMessage||"How can I help you?",d=i?.welcomeDescription||"Select a common question below or type your own.";return(0,v.jsxs)("div",{ref:t,className:"chat-messages-container",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:[e.length===0&&(0,v.jsxs)("div",{className:"chat-welcome",children:[(0,v.jsx)("div",{className:"chat-welcome-icon",style:{background:s},children:(0,v.jsx)(I.MessageCircle,{size:40})}),(0,v.jsxs)("div",{children:[(0,v.jsx)("h3",{className:"chat-welcome-title",children:u}),(0,v.jsx)("p",{className:"chat-welcome-subtitle",children:d})]}),(0,v.jsx)("div",{className:"chat-welcome-suggestions",children:(0,v.jsx)(Q,{onSelectQuestion:r,strapiUrl:o,variant:"floating",theming:i})})]}),e.map(l=>(0,v.jsx)(F,{message:l,cardRegistry:a,theming:i},l.id))]})},ee=ye;var N=require("react/jsx-runtime"),ve=({isExpanded:e,setIsExpanded:t,messages:r,scrollRef:o,sendMessage:a,strapiUrl:i,resolvedRegistry:s,input:u,setInput:d,isLoading:l,title:m,theming:n})=>{let p=T(`chat-window ${e?"chat-window-open":"chat-window-closed"}`,n?.container);return(0,N.jsxs)("div",{className:p,style:n?.containerStyle,children:[(0,N.jsx)("div",{className:"chat-window-header",children:(0,N.jsx)(W,{title:m,onClose:()=>t(!1),theming:n,strapiUrl:i})}),(0,N.jsx)(ee,{messages:r,scrollRef:o,sendMessage:a,strapiUrl:i,resolvedRegistry:s,theming:n}),(0,N.jsxs)("div",{className:"chat-window-footer",children:[(0,N.jsx)(U,{input:u,onInputChange:d,onSendMessage:a,isLoading:l,theming:n}),(0,N.jsx)("div",{className:"chat-window-powered",children:(0,N.jsxs)("span",{className:"chat-powered-text",children:["Powered by"," ",(0,N.jsx)("a",{href:"https://numentica-ui.com",className:"chat-powered-link",children:"Numentica-UI"})]})})]})]})},te=ve;var O=require("react/jsx-runtime"),ke=({strapiUrl:e,cardRegistry:t,theme:r,title:o,streamSpeed:a})=>{let[i,s]=(0,k.useState)([]),[u,d]=(0,k.useState)(""),[l,m]=(0,k.useState)(!1),[n,p]=(0,k.useState)(!1),M=(0,k.useRef)(null),[P,G]=(0,k.useState)([]),ae=(0,k.useRef)(null),re={"--cb-primary":r?.primaryColor||"#2999d6","--cb-secondary":r?.secondaryColor||"#179fa3","--cb-accent":r?.accentColor||"#07a372"};return(0,k.useEffect)(()=>{t.length>0&&G(t)},[t]),(0,k.useEffect)(()=>()=>M.current?.abort(),[]),(0,O.jsxs)("div",{className:"chatbot-container",style:re,children:[(0,O.jsx)(_,{isExpanded:n,onOpen:()=>p(!0),theming:r}),(0,O.jsx)(te,{isExpanded:n,setIsExpanded:p,messages:i,scrollRef:ae,sendMessage:async oe=>{let V=oe||u;if(!V.trim())return;M.current?.abort(),M.current=new AbortController,p(!0),d(""),m(!0);let ne={role:"user",content:V,id:Date.now()},S=Date.now()+1;s(L=>[...L,ne,{role:"assistant",content:"",items:null,loading:!0,id:S}]);try{let L=await fetch(`${e}/api/faqchatbot/ask`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:V,history:i.slice(-4).map(g=>({role:g.role,content:g.content}))}),signal:M.current.signal});if(!L.ok)throw new Error("Network response was not ok");let H=L.body?.getReader(),$=new TextDecoder;if(!H)throw new Error("No reader available");let j=[],J=!1,ie=(async()=>{for(;!J||j.length>0;)if(j.length>0){let g=j.shift();if(g?.type==="text")if(a&&a>0)for(let h of g.content)s(x=>x.map(C=>C.id===S?{...C,content:C.content+h}:C)),await new Promise(x=>setTimeout(x,a));else s(h=>h.map(x=>x.id===S?{...x,content:x.content+g.content}:x));else if(g?.type==="card")try{let h=g.data;s(x=>x.map(C=>C.id===S?{...C,items:{items:h.items,schema:h.schema,collection:h.title,title:h.title,cardStyle:h.cardStyle}}:C))}catch(h){console.error("Error processing card data:",h)}}else await new Promise(g=>setTimeout(g,20));m(!1),s(g=>g.map(h=>h.id===S?{...h,loading:!1}:h))})(),q="";for(;;){let{value:g,done:h}=await H.read();if(h)break;let x=$.decode(g,{stream:!0});q+=x;let C=q.split(`
|
|
2
2
|
|
|
3
3
|
`);q=C.pop()||"";for(let se of C){let de=se.split(`
|
|
4
|
-
`),X="message",
|
|
5
|
-
`:"")+
|
|
4
|
+
`),X="message",D="";for(let E of de)if(E.startsWith("event:"))X=E.slice(6).trim();else if(E.startsWith("data:")){let B=E.slice(5);if(B.startsWith(" ")&&(B=B.slice(1)),B.trim()==="[DONE]"||B.trim()==="[Done]")continue;D+=(D?`
|
|
5
|
+
`:"")+B}if(X==="cards"){let E=JSON.parse(D);j.push({type:"card",data:E})}else D&&j.push({type:"text",content:D})}}J=!0,await ie}catch(L){L.name!=="AbortError"&&s(H=>H.map($=>$.id===S?{...$,content:"I'm sorry, I'm having trouble connecting right now.",loading:!1}:$)),m(!1)}},strapiUrl:e,resolvedRegistry:P,input:u,setInput:d,isLoading:l,title:o,theming:r})]})},Z=ke;0&&(module.exports={ChatBot,ChatHeader,ChatInput,Chatbot,ICONS,MessageBubble,Suggestions});
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use client";import{useState as P,useEffect as re,useRef as oe}from"react";import{jsx as w,jsxs as ue}from"react/jsx-runtime";var x={MessageCircle:({size:e=24,className:t=""})=>w("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:w("path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z"})}),Bot:({size:e=24,className:t=""})=>w("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:w("path",{d:"M12 8V4m8 4V4M4 8V4M2 11h20m-1 0v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V11m5 5v2m8-2v2"})}),X:({size:e=24,className:t=""})=>w("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:w("path",{d:"M18 6 6 18M6 6l12 12"})}),Sparkles:({size:e=24,className:t=""})=>w("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:w("path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"})}),Send:({size:e=24,className:t=""})=>ue("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[w("path",{d:"m22 2-7 20-4-9-9-4Z"}),w("path",{d:"M22 2 11 13"})]})};import{jsx as O,jsxs as fe}from"react/jsx-runtime";var ge=({isExpanded:e,onOpen:t,theming:r})=>O("div",{onClick:t,className:`chat-floating-btn ${e?"chat-btn-hidden":"chat-btn-visible"}`,children:O("div",{className:"chat-btn-border seamless-border",children:fe("div",{className:"chat-btn-inner",children:[O("div",{className:"chat-btn-gradient",style:{background:r?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary))"}}),O(x.MessageCircle,{size:30,className:"chat-btn-icon"})]})})}),J=ge;import{useEffect as be,useState as we}from"react";var S=(e,t)=>t?`${e} ${t}`:e;import{jsx as C,jsxs as X}from"react/jsx-runtime";var xe=({onClose:e,title:t,theming:r,strapiUrl:a})=>{let[o,i]=we(null);be(()=>{if(!a)return;(async()=>{try{let l=await(await fetch(`${a}/api/faq-ai-bot/suggestion-and-logo`)).json();l?.logoUrl&&i(`${a}${l.logoUrl}`)}catch(c){console.error("Failed to fetch logo",c)}})()},[a]);let h=S("chat-header",r?.header);return X("header",{className:h,style:r?.headerStyle,children:[X("div",{className:"chat-header-left",children:[o?C("img",{src:o,alt:"Bot Logo",className:"chat-header-logo"}):C("div",{className:"chat-header-logo-placeholder",children:C(x.Bot,{size:20,className:"chat-header-bot-icon"})}),C("div",{className:"chat-header-title-wrap",children:C("span",{className:"chat-header-title",children:t})})]}),C("div",{className:"chat-header-actions",children:C("button",{onClick:e,className:"chat-header-close-btn","aria-label":"Close chat",children:C(x.X,{size:20})})})]})},W=xe;import{useRef as ye,useEffect as ve}from"react";import{jsx as y,jsxs as _}from"react/jsx-runtime";var ke=({input:e,onInputChange:t,onSendMessage:r,isLoading:a,theming:o})=>{let i=o?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))",s=ye(null),d=S("chat-input-container",o?.input);ve(()=>{a||s.current?.focus()},[a]);let c=l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&e.trim()&&!a&&r()};return y("div",{className:"chat-input-outer",children:_("div",{className:"chat-input-wrap",children:[y("div",{style:{background:i},className:"chat-input-glow-lg"}),y("div",{style:{background:i},className:"chat-input-glow-sm"}),y("div",{className:d,style:o?.inputStyle,children:_("div",{className:"chat-input-inner",children:[y("input",{ref:s,type:"text",className:"chat-input-field",placeholder:a?"AI is thinking...":"Ask anything...",value:e,onChange:l=>t(l.target.value),onKeyDown:c,disabled:a,"aria-label":"User message"}),y("div",{className:"chat-input-send-wrap",children:y("button",{onClick:r,disabled:a||!e.trim(),style:{background:i},className:"chat-input-send-btn","aria-label":"Send message",children:a?y("div",{className:"chat-input-spinner"}):y(x.Send,{className:"chat-input-send-icon"})})})]})})]})})},A=ke;import{jsx as v,jsxs as ee}from"react/jsx-runtime";var Ce=({message:e,cardRegistry:t,themeStyles:r,theming:a})=>{let o=s=>{let h=s?.__collectionUid?.split(".").pop()?.toLowerCase();return t.find(d=>d.id===h)||t.find(d=>d.id==="default")},i=e.record?o(e.record)?.component:null;if(e.items?.items?.length){let s=e.items.cardStyle?.toLowerCase()||e.items.collection?.toLowerCase()||e.items.title?.toLowerCase(),d=t.find(c=>c.id===s)?.component;return ee("div",{className:"mb-card-container",children:[e.content&&v("div",{className:"mb-card-content",children:e.content}),d&&e.items.items.map((c,l)=>v(d,{items:c,style:r},l))]})}return v("div",{className:`mb-row ${e.role==="user"?"mb-row-user":"mb-row-assistant"}`,children:i&&e.record?v("div",{className:"mb-card-wrapper",children:v(i,{record:e.record,style:r})}):v("div",{style:e.role==="user"?{background:a?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))"}:{},className:`mb-bubble ${e.role==="user"?"mb-bubble-user":"mb-bubble-assistant"}`,children:e.loading&&!e.content?ee("div",{className:"mb-typing",children:[v("span",{className:"mb-dot mb-dot-1"}),v("span",{className:"mb-dot mb-dot-2"}),v("span",{className:"mb-dot mb-dot-3"})]}):e.content})})},U=Ce;import{useState as F,useEffect as Ne}from"react";import{jsx as g,jsxs as Q}from"react/jsx-runtime";var Ie=({strapiUrl:e,onSelectQuestion:t,variant:r,theming:a})=>{let[o,i]=F([]),[s,h]=F(!0),[d,c]=F(!1);Ne(()=>{let n=new AbortController;return h(!0),fetch(`${e}/api/faq-ai-bot/suggestion-and-logo`,{signal:n.signal}).then(m=>m.json()).then(m=>{i(m.suggestedQuestions||[]),h(!1)}).catch(m=>{m.name!=="AbortError"&&(console.error("Suggestions fetch failed",m),h(!1))}),()=>n.abort()},[e]);let l=()=>r==="floating"?Q("div",{className:"sug-skeleton-float",children:[[1,2].map(n=>g("div",{className:"sug-skeleton-item",style:{backgroundColor:a?.primaryColor?`${a.primaryColor}`:"hsla(178, 100%, 51%, 0.05)",transform:n%2===0?"rotate(1deg)":"rotate(-1deg)"}},n)),g("div",{className:"sug-skeleton-more"})]}):g("div",{className:"sug-skeleton-list",children:[1,2,3].map(n=>g("div",{className:"sug-skeleton-chip"},n))});if(s&&o.length===0)return g(l,{});if(r==="floating"){let n=d?o:o.slice(0,2),m=!d&&o.length>2;return Q("div",{className:"sug-float-wrap",children:[n.map((k,E)=>{let D=E%2===0?"rotate(-1deg)":"rotate(1deg)";return g("button",{onClick:()=>t(k),className:"sug-float-btn",style:{borderColor:a?.primaryColor||"var(--cb-primary)",transform:D,animationDelay:`${E*.1}s`},children:g("span",{className:"sug-float-text",children:k})},`float-${E}-${k}`)}),m&&g("button",{onClick:()=>c(!0),"aria-label":"Show more suggestions",title:"Show more suggestions",className:"sug-more-btn",style:{animationDelay:`${n.length*.1}s`},children:Q("div",{className:"sug-more-dots",style:{color:a?.secondaryColor||"var(--cb-secondary)"},children:[g("span",{}),g("span",{}),g("span",{})]})})]})}return g("div",{className:"sug-list-wrap",children:o.map((n,m)=>g("button",{onClick:()=>t(n),className:"sug-list-btn",style:{animationDelay:`${m*.05}s`},children:n},`list-${m}-${n}`))})},G=Ie;import{jsx as N,jsxs as V}from"react/jsx-runtime";var Me=({messages:e,scrollRef:t,sendMessage:r,strapiUrl:a,resolvedRegistry:o,theming:i})=>{let s=i?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))",h=i?.welcomeMessage||"How can I help you?",d=i?.welcomeDescription||"Select a common question below or type your own.";return V("div",{ref:t,className:"chat-messages-container",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:[e.length===0&&V("div",{className:"chat-welcome",children:[N("div",{className:"chat-welcome-icon",style:{background:s},children:N(x.MessageCircle,{size:40})}),V("div",{children:[N("h3",{className:"chat-welcome-title",children:h}),N("p",{className:"chat-welcome-subtitle",children:d})]}),N("div",{className:"chat-welcome-suggestions",children:N(G,{onSelectQuestion:r,strapiUrl:a,variant:"floating",theming:i})})]}),e.map(c=>N(U,{message:c,cardRegistry:o,theming:i},c.id))]})},te=Me;import{jsx as L,jsxs as q}from"react/jsx-runtime";var Re=({isExpanded:e,setIsExpanded:t,messages:r,scrollRef:a,sendMessage:o,strapiUrl:i,resolvedRegistry:s,input:h,setInput:d,isLoading:c,title:l,theming:n})=>{let m=S(`chat-window ${e?"chat-window-open":"chat-window-closed"}`,n?.container);return q("div",{className:m,style:n?.containerStyle,children:[L("div",{className:"chat-window-header",children:L(W,{title:l,onClose:()=>t(!1),theming:n,strapiUrl:i})}),L(te,{messages:r,scrollRef:a,sendMessage:o,strapiUrl:i,resolvedRegistry:s,theming:n}),q("div",{className:"chat-window-footer",children:[L(A,{input:h,onInputChange:d,onSendMessage:o,isLoading:c,theming:n}),L("div",{className:"chat-window-powered",children:q("span",{className:"chat-powered-text",children:["Powered by"," ",L("a",{href:"https://numentica-ui.com",className:"chat-powered-link",children:"Numentica-UI"})]})})]})]})},ae=Re;import{jsx as ne,jsxs as Le}from"react/jsx-runtime";var Se=({strapiUrl:e,cardRegistry:t,theme:r,title:a,streamSpeed:o})=>{let[i,s]=P([]),[h,d]=P(""),[c,l]=P(!1),[n,m]=P(!1),k=oe(null),[E,D]=P([]),se=oe(null),de={"--cb-primary":r?.primaryColor||"#2999d6","--cb-secondary":r?.secondaryColor||"#179fa3","--cb-accent":r?.accentColor||"#07a372"};return re(()=>{t.length>0&&D(t)},[t]),re(()=>()=>k.current?.abort(),[]),Le("div",{className:"chatbot-container",style:de,children:[ne(J,{isExpanded:n,onOpen:()=>m(!0),theming:r}),ne(ae,{isExpanded:n,setIsExpanded:m,messages:i,scrollRef:se,sendMessage:async ce=>{let H=ce||h;if(!H.trim())return;k.current?.abort(),k.current=new AbortController,m(!0),d(""),l(!0);let le={role:"user",content:H,id:Date.now()},I=Date.now()+1;s(M=>[...M,le,{role:"assistant",content:"",items:null,loading:!0,id:I}]);try{let M=await fetch(`${e}/api/faq-ai-bot/ask`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:H,history:i.slice(-4).map(u=>({role:u.role,content:u.content}))}),signal:k.current.signal});if(!M.ok)throw new Error("Network response was not ok");let $=M.body?.getReader(),B=new TextDecoder;if(!$)throw new Error("No reader available");let T=[],K=!1,me=(async()=>{for(;!K||T.length>0;)if(T.length>0){let u=T.shift();if(u?.type==="text")if(o&&o>0)for(let p of u.content)s(f=>f.map(b=>b.id===I?{...b,content:b.content+p}:b)),await new Promise(f=>setTimeout(f,o));else s(p=>p.map(f=>f.id===I?{...f,content:f.content+u.content}:f));else if(u?.type==="card")try{let p=u.data;s(f=>f.map(b=>b.id===I?{...b,items:{items:p.items,schema:p.schema,collection:p.title,title:p.title,cardStyle:p.cardStyle}}:b))}catch(p){console.error("Error processing card data:",p)}}else await new Promise(u=>setTimeout(u,20));l(!1),s(u=>u.map(p=>p.id===I?{...p,loading:!1}:p))})(),Y="";for(;;){let{value:u,done:p}=await $.read();if(p)break;let f=B.decode(u,{stream:!0});Y+=f;let b=Y.split(`
|
|
1
|
+
"use client";import{useState as $,useEffect as re,useRef as oe}from"react";import{jsx as w,jsxs as ue}from"react/jsx-runtime";var x={MessageCircle:({size:e=24,className:t=""})=>w("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:w("path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z"})}),Bot:({size:e=24,className:t=""})=>w("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:w("path",{d:"M12 8V4m8 4V4M4 8V4M2 11h20m-1 0v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V11m5 5v2m8-2v2"})}),X:({size:e=24,className:t=""})=>w("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:w("path",{d:"M18 6 6 18M6 6l12 12"})}),Sparkles:({size:e=24,className:t=""})=>w("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:w("path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"})}),Send:({size:e=24,className:t=""})=>ue("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[w("path",{d:"m22 2-7 20-4-9-9-4Z"}),w("path",{d:"M22 2 11 13"})]})};import{jsx as D,jsxs as fe}from"react/jsx-runtime";var ge=({isExpanded:e,onOpen:t,theming:r})=>D("div",{onClick:t,className:`chat-floating-btn ${e?"chat-btn-hidden":"chat-btn-visible"}`,children:D("div",{className:"chat-btn-border seamless-border",children:fe("div",{className:"chat-btn-inner",children:[D("div",{className:"chat-btn-gradient",style:{background:r?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary))"}}),D(x.MessageCircle,{size:30,className:"chat-btn-icon"})]})})}),J=ge;import{useEffect as be,useState as we}from"react";var L=(e,t)=>t?`${e} ${t}`:e;import{jsx as C,jsxs as X}from"react/jsx-runtime";var xe=({onClose:e,title:t,theming:r,strapiUrl:a})=>{let[o,i]=we(null);be(()=>{if(!a)return;(async()=>{try{let l=await(await fetch(`${a}/api/faq-ai-bot/suggestion-and-logo`)).json();l?.logoUrl&&i(`${a}${l.logoUrl}`)}catch(c){console.error("Failed to fetch logo",c)}})()},[a]);let h=L("chat-header",r?.header);return X("header",{className:h,style:r?.headerStyle,children:[X("div",{className:"chat-header-left",children:[o?C("img",{src:o,alt:"Bot Logo",className:"chat-header-logo"}):C("div",{className:"chat-header-logo-placeholder",children:C(x.Bot,{size:20,className:"chat-header-bot-icon"})}),C("div",{className:"chat-header-title-wrap",children:C("span",{className:"chat-header-title",children:t})})]}),C("div",{className:"chat-header-actions",children:C("button",{onClick:e,className:"chat-header-close-btn","aria-label":"Close chat",children:C(x.X,{size:20})})})]})},W=xe;import{useRef as ye,useEffect as ve}from"react";import{jsx as y,jsxs as _}from"react/jsx-runtime";var ke=({input:e,onInputChange:t,onSendMessage:r,isLoading:a,theming:o})=>{let i=o?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))",s=ye(null),d=L("chat-input-container",o?.input);ve(()=>{a||s.current?.focus()},[a]);let c=l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&e.trim()&&!a&&r()};return y("div",{className:"chat-input-outer",children:_("div",{className:"chat-input-wrap",children:[y("div",{style:{background:i},className:"chat-input-glow-lg"}),y("div",{style:{background:i},className:"chat-input-glow-sm"}),y("div",{className:d,style:o?.inputStyle,children:_("div",{className:"chat-input-inner",children:[y("input",{ref:s,type:"text",className:"chat-input-field",placeholder:a?"AI is thinking...":"Ask anything...",value:e,onChange:l=>t(l.target.value),onKeyDown:c,disabled:a,"aria-label":"User message"}),y("div",{className:"chat-input-send-wrap",children:y("button",{onClick:r,disabled:a||!e.trim(),style:{background:i},className:"chat-input-send-btn","aria-label":"Send message",children:a?y("div",{className:"chat-input-spinner"}):y(x.Send,{className:"chat-input-send-icon"})})})]})})]})})},A=ke;import{jsx as v,jsxs as ee}from"react/jsx-runtime";var Ce=({message:e,cardRegistry:t,themeStyles:r,theming:a})=>{let o=s=>{let h=s?.__collectionUid?.split(".").pop()?.toLowerCase();return t.find(d=>d.id===h)||t.find(d=>d.id==="default")},i=e.record?o(e.record)?.component:null;if(e.items?.items?.length){let s=e.items.cardStyle?.toLowerCase()||e.items.collection?.toLowerCase()||e.items.title?.toLowerCase(),d=t.find(c=>c.id===s)?.component;return ee("div",{className:"mb-card-container",children:[e.content&&v("div",{className:"mb-card-content",children:e.content}),d&&e.items.items.map((c,l)=>v(d,{items:c,style:r},l))]})}return v("div",{className:`mb-row ${e.role==="user"?"mb-row-user":"mb-row-assistant"}`,children:i&&e.record?v("div",{className:"mb-card-wrapper",children:v(i,{record:e.record,style:r})}):v("div",{style:e.role==="user"?{background:a?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))"}:{},className:`mb-bubble ${e.role==="user"?"mb-bubble-user":"mb-bubble-assistant"}`,children:e.loading&&!e.content?ee("div",{className:"mb-typing",children:[v("span",{className:"mb-dot mb-dot-1"}),v("span",{className:"mb-dot mb-dot-2"}),v("span",{className:"mb-dot mb-dot-3"})]}):e.content})})},U=Ce;import{useState as F,useEffect as Ne}from"react";import{jsx as g,jsxs as Q}from"react/jsx-runtime";var Ie=({strapiUrl:e,onSelectQuestion:t,variant:r,theming:a})=>{let[o,i]=F([]),[s,h]=F(!0),[d,c]=F(!1);Ne(()=>{let n=new AbortController;return h(!0),fetch(`${e}/api/faq-ai-bot/suggestion-and-logo`,{signal:n.signal}).then(m=>m.json()).then(m=>{i(m.suggestedQuestions||[]),h(!1)}).catch(m=>{m.name!=="AbortError"&&(console.error("Suggestions fetch failed",m),h(!1))}),()=>n.abort()},[e]);let l=()=>r==="floating"?Q("div",{className:"sug-skeleton-float",children:[[1,2].map(n=>g("div",{className:"sug-skeleton-item",style:{backgroundColor:a?.primaryColor?`${a.primaryColor}`:"hsla(178, 100%, 51%, 0.05)",transform:n%2===0?"rotate(1deg)":"rotate(-1deg)"}},n)),g("div",{className:"sug-skeleton-more"})]}):g("div",{className:"sug-skeleton-list",children:[1,2,3].map(n=>g("div",{className:"sug-skeleton-chip"},n))});if(s&&o.length===0)return g(l,{});if(r==="floating"){let n=d?o:o.slice(0,2),m=!d&&o.length>2;return Q("div",{className:"sug-float-wrap",children:[n.map((k,B)=>{let O=B%2===0?"rotate(-1deg)":"rotate(1deg)";return g("button",{onClick:()=>t(k),className:"sug-float-btn",style:{borderColor:a?.primaryColor||"var(--cb-primary)",transform:O,animationDelay:`${B*.1}s`},children:g("span",{className:"sug-float-text",children:k})},`float-${B}-${k}`)}),m&&g("button",{onClick:()=>c(!0),"aria-label":"Show more suggestions",title:"Show more suggestions",className:"sug-more-btn",style:{animationDelay:`${n.length*.1}s`},children:Q("div",{className:"sug-more-dots",style:{color:a?.secondaryColor||"var(--cb-secondary)"},children:[g("span",{}),g("span",{}),g("span",{})]})})]})}return g("div",{className:"sug-list-wrap",children:o.map((n,m)=>g("button",{onClick:()=>t(n),className:"sug-list-btn",style:{animationDelay:`${m*.05}s`},children:n},`list-${m}-${n}`))})},G=Ie;import{jsx as N,jsxs as V}from"react/jsx-runtime";var Me=({messages:e,scrollRef:t,sendMessage:r,strapiUrl:a,resolvedRegistry:o,theming:i})=>{let s=i?.showGradient===!1?"var(--cb-primary)":"linear-gradient(to top right, var(--cb-primary), var(--cb-secondary), var(--cb-accent))",h=i?.welcomeMessage||"How can I help you?",d=i?.welcomeDescription||"Select a common question below or type your own.";return V("div",{ref:t,className:"chat-messages-container",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:[e.length===0&&V("div",{className:"chat-welcome",children:[N("div",{className:"chat-welcome-icon",style:{background:s},children:N(x.MessageCircle,{size:40})}),V("div",{children:[N("h3",{className:"chat-welcome-title",children:h}),N("p",{className:"chat-welcome-subtitle",children:d})]}),N("div",{className:"chat-welcome-suggestions",children:N(G,{onSelectQuestion:r,strapiUrl:a,variant:"floating",theming:i})})]}),e.map(c=>N(U,{message:c,cardRegistry:o,theming:i},c.id))]})},te=Me;import{jsx as E,jsxs as q}from"react/jsx-runtime";var Re=({isExpanded:e,setIsExpanded:t,messages:r,scrollRef:a,sendMessage:o,strapiUrl:i,resolvedRegistry:s,input:h,setInput:d,isLoading:c,title:l,theming:n})=>{let m=L(`chat-window ${e?"chat-window-open":"chat-window-closed"}`,n?.container);return q("div",{className:m,style:n?.containerStyle,children:[E("div",{className:"chat-window-header",children:E(W,{title:l,onClose:()=>t(!1),theming:n,strapiUrl:i})}),E(te,{messages:r,scrollRef:a,sendMessage:o,strapiUrl:i,resolvedRegistry:s,theming:n}),q("div",{className:"chat-window-footer",children:[E(A,{input:h,onInputChange:d,onSendMessage:o,isLoading:c,theming:n}),E("div",{className:"chat-window-powered",children:q("span",{className:"chat-powered-text",children:["Powered by"," ",E("a",{href:"https://numentica-ui.com",className:"chat-powered-link",children:"Numentica-UI"})]})})]})]})},ae=Re;import{jsx as ne,jsxs as Le}from"react/jsx-runtime";var Se=({strapiUrl:e,cardRegistry:t,theme:r,title:a,streamSpeed:o})=>{let[i,s]=$([]),[h,d]=$(""),[c,l]=$(!1),[n,m]=$(!1),k=oe(null),[B,O]=$([]),se=oe(null),de={"--cb-primary":r?.primaryColor||"#2999d6","--cb-secondary":r?.secondaryColor||"#179fa3","--cb-accent":r?.accentColor||"#07a372"};return re(()=>{t.length>0&&O(t)},[t]),re(()=>()=>k.current?.abort(),[]),Le("div",{className:"chatbot-container",style:de,children:[ne(J,{isExpanded:n,onOpen:()=>m(!0),theming:r}),ne(ae,{isExpanded:n,setIsExpanded:m,messages:i,scrollRef:se,sendMessage:async ce=>{let H=ce||h;if(!H.trim())return;k.current?.abort(),k.current=new AbortController,m(!0),d(""),l(!0);let le={role:"user",content:H,id:Date.now()},I=Date.now()+1;s(M=>[...M,le,{role:"assistant",content:"",items:null,loading:!0,id:I}]);try{let M=await fetch(`${e}/api/faqchatbot/ask`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:H,history:i.slice(-4).map(u=>({role:u.role,content:u.content}))}),signal:k.current.signal});if(!M.ok)throw new Error("Network response was not ok");let j=M.body?.getReader(),T=new TextDecoder;if(!j)throw new Error("No reader available");let z=[],K=!1,me=(async()=>{for(;!K||z.length>0;)if(z.length>0){let u=z.shift();if(u?.type==="text")if(o&&o>0)for(let p of u.content)s(f=>f.map(b=>b.id===I?{...b,content:b.content+p}:b)),await new Promise(f=>setTimeout(f,o));else s(p=>p.map(f=>f.id===I?{...f,content:f.content+u.content}:f));else if(u?.type==="card")try{let p=u.data;s(f=>f.map(b=>b.id===I?{...b,items:{items:p.items,schema:p.schema,collection:p.title,title:p.title,cardStyle:p.cardStyle}}:b))}catch(p){console.error("Error processing card data:",p)}}else await new Promise(u=>setTimeout(u,20));l(!1),s(u=>u.map(p=>p.id===I?{...p,loading:!1}:p))})(),Y="";for(;;){let{value:u,done:p}=await j.read();if(p)break;let f=T.decode(u,{stream:!0});Y+=f;let b=Y.split(`
|
|
2
2
|
|
|
3
3
|
`);Y=b.pop()||"";for(let pe of b){let he=pe.split(`
|
|
4
|
-
`),Z="message",
|
|
5
|
-
`:"")+
|
|
4
|
+
`),Z="message",P="";for(let R of he)if(R.startsWith("event:"))Z=R.slice(6).trim();else if(R.startsWith("data:")){let S=R.slice(5);if(S.startsWith(" ")&&(S=S.slice(1)),S.trim()==="[DONE]"||S.trim()==="[Done]")continue;P+=(P?`
|
|
5
|
+
`:"")+S}if(Z==="cards"){let R=JSON.parse(P);z.push({type:"card",data:R})}else P&&z.push({type:"text",content:P})}}K=!0,await me}catch(M){M.name!=="AbortError"&&s(j=>j.map(T=>T.id===I?{...T,content:"I'm sorry, I'm having trouble connecting right now.",loading:!1}:T)),l(!1)}},strapiUrl:e,resolvedRegistry:B,input:h,setInput:d,isLoading:c,title:a,theming:r})]})},ie=Se;export{ie as ChatBot,W as ChatHeader,A as ChatInput,ie as Chatbot,x as ICONS,U as MessageBubble,G as Suggestions};
|