@brainbase-labs/chat-widget 0.1.11 → 0.1.12
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/embed/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +39 -39
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
`);){const[C,P]=a.split(`
|
|
4
4
|
|
|
5
5
|
`,2);a=P;for(const te of C.split(`
|
|
6
|
-
`))if(te.startsWith("data: "))try{const me=JSON.parse(te.slice(6));D(me,k,j)}catch{}}}}finally{d.releaseLock()}},[D]),J=i.useCallback(async p=>{if(!p.trim())return;const k={id:`user-${Date.now()}`,role:"user",content:p,timestamp:Date.now(),status:"sent"};o(a=>[...a,k]),c==null||c(k);const j=`assistant-${Date.now()}`,d={id:j,role:"assistant",content:"",timestamp:Date.now(),status:"streaming"};o(a=>[...a,d]),T(!0),V(null);const h=a=>{_(a)};try{if(r){const a=n.sendMessage(p);for await(const f of a)D(f,j,h)}else{const a=await n.sendMessage({embedId:t.embedId,message:p,sessionId:b??void 0});await S(a,j,h)}o(a=>a.map(f=>f.id===j&&f.status==="streaming"?{...f,status:"sent"}:f))}catch(a){const f=a instanceof Error?a:new Error("Failed to send message");V(f),m==null||m(f),o(N=>N.map(C=>C.id===j?{...C,status:"error",content:"Failed to get response"}:C))}finally{T(!1)}},[b,n,r,t.embedId,D,S,c,m]),q=i.useCallback(async()=>{if(!b)return;const p={sessionId:b,deploymentId:t.deploymentId,workerId:t.workerId,flowId:t.flowId,startTime:$.current,messages:l,toolCalls:x,status:"completed"};g==null||g(p),X(t.embedId),_(null),o([]),L([])},[b,t,l,x,g]),A=i.useCallback(()=>{o([]),L([])},[]);return{messages:l,toolCalls:x,isLoading:E,error:W,sessionId:b,sendMessage:J,endSession:q,clearMessages:A,startNewSession:U}}const pe="https://whatsapp-based-server.onrender.com";function ne(s=pe){return{async getDeploymentConfig(t){const n=await fetch(`${s}/chat/config/${t}`);if(!n.ok)throw new Error(`Failed to fetch deployment config: ${n.status}`);const r=await n.json();return{embedId:r.embedId,deploymentId:"",workerId:"",flowId:"",welcomeMessage:r.welcomeMessage,agentName:r.agentName,agentLogoUrl:r.agentLogoUrl,primaryColor:r.primaryColor,styling:r.styling}},async sendMessage(t){const n=await fetch(`${s}/chat/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({embed_id:t.embedId,message:t.message,session_id:t.sessionId||void 0,metadata:t.metadata})});if(!n.ok){const r=await n.text();throw new Error(`Failed to send message: ${n.status} - ${r}`)}if(!n.body)throw new Error("No response stream available");return n.body}}}const he={embedId:"mock-embed-id",deploymentId:"mock-deployment-id",workerId:"mock-worker-id",flowId:"mock-flow-id",agentName:"AI Assistant",agentLogoUrl:void 0,primaryColor:"#1a1a2e",styling:{}},_e=[{trigger:/hello|hi|hey/i,response:"Hello! I'm a demo AI assistant. How can I help you today?",delay:500},{trigger:/weather/i,response:"I'd check the weather for you, but I'm in mock mode! In production, I could use a weather API.",delay:800,toolCalls:[{name:"get_weather",arguments:{location:"San Francisco"},result:{temperature:72,condition:"sunny"}}]},{trigger:/help|support/i,response:"I'm here to help! You can ask me questions, and I'll do my best to assist you. In production, I'd be connected to your agent with full capabilities.",delay:600},{trigger:/pricing|cost|price/i,response:"For pricing information, I'd typically check our database or connect you with the sales team. This is a mock response demonstrating how I'd handle pricing questions.",delay:700,toolCalls:[{name:"lookup_pricing",arguments:{plan:"all"},result:{plans:[{name:"Starter",price:"$29/mo"},{name:"Pro",price:"$99/mo"}]}}]},{trigger:/.*/,response:"I'm running in mock mode. This is a simulated response to demonstrate the chat UI. In production, I'd be connected to your agent!",delay:1e3}];function R(s){return new Promise(t=>setTimeout(t,s))}function re(s,t){const n={...he,...s},r=t??_e,u=`mock-session-${Date.now()}`;return{async getDeploymentConfig(g){return await R(300),n},async*sendMessage(g){yield{type:"session",data:{session_id:u,is_new:!0},timestamp:Date.now()};const c=r.find(o=>typeof o.trigger=="string"?g.toLowerCase().includes(o.trigger.toLowerCase()):o.trigger.test(g))??r[r.length-1];if(await R(c.delay??500),c.toolCalls)for(const o of c.toolCalls)yield{type:"tool_call",data:{function:o.name,args:o.arguments},timestamp:Date.now()},await R(300),yield{type:"tool_call",data:{function:o.name,result:o.result},timestamp:Date.now()},await R(200);const m=c.response.split(" ");let l="";for(const o of m)l+=(l?" ":"")+o,yield{type:"message",data:{content:l,role:"assistant"},timestamp:Date.now()},await R(30+Math.random()*40);yield{type:"done",data:{session_id:u},timestamp:Date.now()}}}}const O=({className:s,color:t="currentColor",cutoutColor:n="var(--bb-primary-color)"})=>e.jsxs("svg",{className:s,viewBox:"0 0 800 800",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H788C794.627 400 800 405.373 800 412V740C800 773.137 773.137 800 740 800H412C405.373 800 400 794.627 400 788V412Z",fill:t}),e.jsx("circle",{cx:"400",cy:"400",r:"400",fill:t}),e.jsx("path",{d:"M0 60C0 26.8629 26.8629 0 60 0H397.614C398.932 0 400 1.06811 400 2.38569V2.38569C400 221.982 221.982 400 2.38569 400V400C1.06811 400 0 398.932 0 397.614V60Z",fill:t}),e.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H738C744.627 400 750 405.373 750 412V725C750 738.807 738.807 750 725 750H412C405.373 750 400 744.627 400 738V412Z",fill:t}),e.jsx("circle",{cx:"400",cy:"400",r:"350",fill:t}),e.jsx("path",{d:"M50 75C50 61.1929 61.1929 50 75 50H388C394.627 50 400 55.3726 400 62V388C400 394.627 394.627 400 388 400H62C55.3726 400 50 394.627 50 388V75Z",fill:t}),e.jsx("rect",{x:"399.919",y:"209",width:"270",height:"270",rx:"12",transform:"rotate(45 399.919 209)",fill:n})]}),fe="_header_1p6z5_1",xe="_compact_1p6z5_9",be="_headerBackground_1p6z5_20",ye="_headerContent_1p6z5_59",we="_topRow_1p6z5_64",je="_agentInfo_1p6z5_79",Ce="_agentLogo_1p6z5_85",ke="_agentLogoPlaceholder_1p6z5_102",ve="_brainbaseLogo_1p6z5_123",Ie="_agentName_1p6z5_137",Ne="_actions_1p6z5_144",Le="_actionButton_1p6z5_149",$e="_welcomeText_1p6z5_183",Se="_title_1p6z5_202",Be="_subtitle_1p6z5_210",y={header:fe,compact:xe,headerBackground:be,headerContent:ye,topRow:we,agentInfo:je,agentLogo:Ce,agentLogoPlaceholder:ke,brainbaseLogo:ve,agentName:Ie,actions:Ne,actionButton:Le,welcomeText:$e,title:Se,subtitle:Be},ae=({agentName:s="AI Assistant",agentLogoUrl:t,welcomeTitle:n,welcomeSubtitle:r,onClose:u,onNewChatRequest:g,showNewChatButton:c=!1,compact:m=!1})=>{const l=n||"Hello there.",o=r!==void 0?r:n?void 0:"How can we help?";return e.jsxs("div",{className:`${y.header} ${m?y.compact:""}`,children:[e.jsx("div",{className:y.headerBackground}),e.jsxs("div",{className:y.headerContent,children:[e.jsxs("div",{className:y.topRow,children:[e.jsxs("div",{className:y.agentInfo,children:[t?e.jsx("img",{src:t,alt:s,className:y.agentLogo}):e.jsx("div",{className:y.agentLogoPlaceholder,children:e.jsx(O,{className:y.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})}),e.jsx("span",{className:y.agentName,children:s})]}),e.jsxs("div",{className:y.actions,children:[c&&g&&e.jsx("button",{className:y.actionButton,onClick:g,"aria-label":"Start new chat",type:"button",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M12 5V19M5 12H19",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),u&&e.jsx("button",{className:y.actionButton,onClick:u,"aria-label":"Close chat",type:"button",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),!m&&e.jsxs("div",{className:y.welcomeText,children:[e.jsx("h1",{className:y.title,children:l}),o&&e.jsx("p",{className:y.subtitle,children:o})]})]})]})},Me="_messageWrapper_c86gj_1",Te="_user_c86gj_19",We="_assistant_c86gj_24",De="_avatar_c86gj_28",Pe="_avatarPlaceholder_c86gj_43",He="_brainbaseLogo_c86gj_53",Ee="_messageBubble_c86gj_58",Ve="_error_c86gj_76",Ae="_content_c86gj_81",Re="_cursor_c86gj_88",ze="_errorIndicator_c86gj_107",v={messageWrapper:Me,user:Te,assistant:We,avatar:De,avatarPlaceholder:Pe,brainbaseLogo:He,messageBubble:Ee,error:Ve,content:Ae,cursor:Re,errorIndicator:ze},ce=({message:s,agentName:t,agentLogoUrl:n})=>{const r=s.role==="user",u=s.status==="streaming",g=s.status==="error";return e.jsxs("div",{className:`${v.messageWrapper} ${r?v.user:v.assistant}`,children:[!r&&e.jsx("div",{className:v.avatar,children:n?e.jsx("img",{src:n,alt:t||"AI"}):e.jsx("div",{className:v.avatarPlaceholder,children:e.jsx(O,{className:v.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})})}),e.jsxs("div",{className:`${v.messageBubble} ${g?v.error:""}`,role:"article","aria-label":`${r?"Your message":`${t||"AI"} says`}`,children:[e.jsxs("div",{className:v.content,children:[s.content,u&&e.jsx("span",{className:v.cursor})]}),g&&e.jsxs("div",{className:v.errorIndicator,children:[e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M12 8V12M12 16H12.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.jsx("span",{children:"Failed to send"})]})]})]})},Oe="_toolCall_1wby1_1",Fe="_iconWrapper_1wby1_24",Ue="_spinner_1wby1_33",qe="_checkIcon_1wby1_48",Ze="_errorIcon_1wby1_54",Ke="_content_1wby1_60",Ge="_label_1wby1_66",Je="_name_1wby1_73",Ye="_pending_1wby1_78",Xe="_completed_1wby1_82",Qe="_error_1wby1_54",I={toolCall:Oe,iconWrapper:Fe,spinner:Ue,checkIcon:qe,errorIcon:Ze,content:Ke,label:Ge,name:Je,pending:Ye,completed:Xe,error:Qe},ie=({toolCall:s})=>{const t=s.status==="pending"||s.status==="executing",n=s.status==="completed",r=s.status==="error",u=g=>g.replace(/_/g," ").replace(/([A-Z])/g," $1").trim().toLowerCase().replace(/^./,c=>c.toUpperCase());return e.jsxs("div",{className:`${I.toolCall} ${t?I.pending:""} ${n?I.completed:""} ${r?I.error:""}`,children:[e.jsx("div",{className:I.iconWrapper,children:t?e.jsx("div",{className:I.spinner}):n?e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:I.checkIcon,children:e.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:I.errorIcon,children:e.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsxs("div",{className:I.content,children:[e.jsx("span",{className:I.label,children:t?"Running":n?"Completed":"Failed"}),e.jsx("span",{className:I.name,children:u(s.name)})]})]})},et="_wrapper_10rss_2",tt="_avatar_10rss_22",st="_avatarPlaceholder_10rss_37",ot="_brainbaseLogo_10rss_47",nt="_bubble_10rss_52",rt="_dot_10rss_63",B={wrapper:et,avatar:tt,avatarPlaceholder:st,brainbaseLogo:ot,bubble:nt,dot:rt},le=({agentName:s="AI",agentLogoUrl:t})=>e.jsxs("div",{className:B.wrapper,role:"status","aria-label":`${s} is typing`,children:[e.jsx("div",{className:B.avatar,children:t?e.jsx("img",{src:t,alt:s}):e.jsx("div",{className:B.avatarPlaceholder,children:e.jsx(O,{className:B.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})})}),e.jsxs("div",{className:B.bubble,children:[e.jsx("span",{className:B.dot}),e.jsx("span",{className:B.dot}),e.jsx("span",{className:B.dot})]})]}),at="_messageList_241kk_1",ct="_emptyState_241kk_29",it="_emptyIcon_241kk_40",lt="_emptyText_241kk_52",Z={messageList:at,emptyState:ct,emptyIcon:it,emptyText:lt},de=({messages:s,toolCalls:t=[],isLoading:n,agentName:r,agentLogoUrl:u})=>{var l;const g=i.useRef(null),c=i.useRef(null);i.useEffect(()=>{var o;(o=c.current)==null||o.scrollIntoView({behavior:"smooth"})},[s,t,n]);const m=t.filter(o=>o.status==="pending"||o.status==="executing");return e.jsxs("div",{className:Z.messageList,ref:g,role:"log","aria-live":"polite",children:[s.length===0&&!n&&e.jsxs("div",{className:Z.emptyState,children:[e.jsx("div",{className:Z.emptyIcon,children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("p",{className:Z.emptyText,children:"Start a conversation"})]}),s.map(o=>e.jsx(ce,{message:o,agentName:r,agentLogoUrl:u},o.id)),m.map(o=>e.jsx(ie,{toolCall:o},o.id)),n&&((l=s[s.length-1])==null?void 0:l.role)==="user"&&e.jsx(le,{agentName:r,agentLogoUrl:u}),e.jsx("div",{ref:c})]})},dt="_inputWrapper_5lgg7_1",ut="_inputContainer_5lgg7_7",gt="_textarea_5lgg7_23",mt="_sendButton_5lgg7_50",pt="_hint_5lgg7_89",z={inputWrapper:dt,inputContainer:ut,textarea:gt,sendButton:mt,hint:pt},ue=({onSend:s,disabled:t=!1,placeholder:n="Send a message..."})=>{const[r,u]=i.useState(""),g=i.useRef(null),c=i.useCallback(()=>{const o=g.current;o&&(o.style.height="auto",o.style.height=`${Math.min(o.scrollHeight,150)}px`)},[]);i.useEffect(()=>{c()},[r,c]);const m=i.useCallback(o=>{o==null||o.preventDefault();const x=r.trim();x&&!t&&(s(x),u(""),g.current&&(g.current.style.height="auto"))},[r,t,s]),l=i.useCallback(o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),m())},[m]);return e.jsxs("form",{className:z.inputWrapper,onSubmit:m,children:[e.jsxs("div",{className:z.inputContainer,children:[e.jsx("textarea",{ref:g,className:z.textarea,value:r,onChange:o=>u(o.target.value),onKeyDown:l,placeholder:n,disabled:t,rows:1,"aria-label":"Message input"}),e.jsx("button",{type:"submit",className:z.sendButton,disabled:t||!r.trim(),"aria-label":"Send message",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e.jsxs("div",{className:z.hint,children:["Press ",e.jsx("kbd",{children:"Enter"})," to send, ",e.jsx("kbd",{children:"Shift + Enter"})," for new line"]})]})},ht="_poweredBy_9jh5q_1",_t="_logo_9jh5q_20",ft="_poweredText_9jh5q_24",xt="_text_9jh5q_36",K={poweredBy:ht,logo:_t,poweredText:ft,text:xt},bt=({className:s})=>e.jsxs("svg",{className:s,viewBox:"0 0 800 800",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H788C794.627 400 800 405.373 800 412V740C800 773.137 773.137 800 740 800H412C405.373 800 400 794.627 400 788V412Z",fill:"currentColor"}),e.jsx("circle",{cx:"400",cy:"400",r:"400",fill:"currentColor"}),e.jsx("path",{d:"M0 60C0 26.8629 26.8629 0 60 0H397.614C398.932 0 400 1.06811 400 2.38569V2.38569C400 221.982 221.982 400 2.38569 400V400C1.06811 400 0 398.932 0 397.614V60Z",fill:"currentColor"}),e.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H738C744.627 400 750 405.373 750 412V725C750 738.807 738.807 750 725 750H412C405.373 750 400 744.627 400 738V412Z",fill:"currentColor"}),e.jsx("circle",{cx:"400",cy:"400",r:"350",fill:"currentColor"}),e.jsx("path",{d:"M50 75C50 61.1929 61.1929 50 75 50H388C394.627 50 400 55.3726 400 62V388C400 394.627 394.627 400 388 400H62C55.3726 400 50 394.627 50 388V75Z",fill:"currentColor"}),e.jsx("rect",{x:"399.919",y:"209",width:"270",height:"270",rx:"12",transform:"rotate(45 399.919 209)",fill:"var(--bb-surface-bg, #ffffff)"})]}),yt=({showBranding:s=!0})=>s?e.jsxs("a",{href:"https://brainbaselabs.com/",target:"_blank",rel:"noopener noreferrer",className:K.poweredBy,"aria-label":"Powered by Brainbase Labs",children:[e.jsx("span",{className:K.poweredText,children:"Powered by"}),e.jsx(bt,{className:K.logo}),e.jsx("span",{className:K.text,children:"Brainbase Labs"})]}):null,wt="_container_m2o9l_1",jt="_body_m2o9l_26",Ct="_confirmationOverlay_m2o9l_35",kt="_confirmationDialog_m2o9l_56",vt="_confirmationText_m2o9l_78",It="_confirmationButtons_m2o9l_86",Nt="_cancelButton_m2o9l_91",Lt="_confirmButton_m2o9l_92",M={container:wt,body:jt,confirmationOverlay:Ct,confirmationDialog:kt,confirmationText:vt,confirmationButtons:It,cancelButton:Nt,confirmButton:Lt},ge=({config:s,messages:t,toolCalls:n=[],isLoading:r,onSendMessage:u,onClose:g,onNewChat:c})=>{var T;const[m,l]=i.useState(!1),o=t.length>0,x=()=>{l(!0)},L=()=>{l(!1),c==null||c()},E=()=>{l(!1)};return e.jsxs("div",{className:M.container,role:"dialog","aria-label":"Chat window",children:[e.jsx(ae,{agentName:s.agentName,agentLogoUrl:s.agentLogoUrl,welcomeTitle:s.welcomeMessage||"Hello there.",welcomeSubtitle:s.welcomeMessage?void 0:"How can we help?",onClose:g,onNewChatRequest:x,showNewChatButton:o,compact:o}),e.jsxs("div",{className:M.body,children:[e.jsx(de,{messages:t,toolCalls:n,isLoading:r,agentName:s.agentName,agentLogoUrl:s.agentLogoUrl}),e.jsx(ue,{onSend:u,disabled:r,placeholder:"Ask a question..."})]}),e.jsx(yt,{showBranding:((T=s.styling)==null?void 0:T.showBranding)??!0}),m&&e.jsx("div",{className:M.confirmationOverlay,children:e.jsxs("div",{className:M.confirmationDialog,children:[e.jsx("p",{className:M.confirmationText,children:"End current chat and start a new conversation?"}),e.jsxs("div",{className:M.confirmationButtons,children:[e.jsx("button",{className:M.cancelButton,onClick:E,type:"button",children:"Cancel"}),e.jsx("button",{className:M.confirmButton,onClick:L,type:"button",children:"End Chat"})]})]})})]})},$t="_toggleButton_11dqz_1",St="_icon_11dqz_31",Bt="_agentLogo_11dqz_36",Mt="_unreadBadge_11dqz_43",G={toggleButton:$t,icon:St,agentLogo:Bt,unreadBadge:Mt},Q=({onClick:s,agentLogoUrl:t,unreadCount:n=0})=>e.jsxs("button",{className:G.toggleButton,onClick:s,"aria-label":"Open chat",type:"button",children:[t?e.jsx("img",{src:t,alt:"",className:G.agentLogo}):e.jsx("svg",{className:G.icon,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),n>0&&e.jsx("span",{className:G.unreadBadge,children:n>9?"9+":n})]}),Tt="_container_kgfgt_1",Wt="_header_kgfgt_25",Dt="_logoWrapper_kgfgt_38",Pt="_logo_kgfgt_38",Ht="_closeButton_kgfgt_51",Et="_content_kgfgt_74",Vt="_iconWrapper_kgfgt_84",At="_errorIcon_kgfgt_95",Rt="_title_kgfgt_101",zt="_description_kgfgt_109",Ot="_retryButton_kgfgt_117",Ft="_footer_kgfgt_139",Ut="_poweredBy_kgfgt_146",qt="_footerLogo_kgfgt_160",w={container:Tt,header:Wt,logoWrapper:Dt,logo:Pt,closeButton:Ht,content:Et,iconWrapper:Vt,errorIcon:At,title:Rt,description:zt,retryButton:Ot,footer:Ft,poweredBy:Ut,footerLogo:qt},Zt=({errorType:s,message:t,onRetry:n,onClose:r})=>{const u=()=>{switch(s){case"not_found":return{title:"Chat Not Found",description:t||"This chat widget is not configured correctly. Please check the embed ID.",icon:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",className:w.errorIcon,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M12 7V13M12 16V16.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})};case"network":return{title:"Connection Error",description:t||"Unable to connect to the chat service. Please check your internet connection.",icon:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",className:w.errorIcon,children:[e.jsx("path",{d:"M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M8 15L16 9M8 9L16 15",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})};default:return{title:"Something Went Wrong",description:t||"An unexpected error occurred. Please try again later.",icon:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:w.errorIcon,children:e.jsx("path",{d:"M12 9V13M12 17H12.01M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}}},{title:g,description:c,icon:m}=u();return e.jsxs("div",{className:w.container,children:[e.jsxs("div",{className:w.header,children:[e.jsx("div",{className:w.logoWrapper,children:e.jsx(O,{className:w.logo,color:"white",cutoutColor:"var(--bb-primary-color)"})}),r&&e.jsx("button",{className:w.closeButton,onClick:r,"aria-label":"Close",type:"button",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),e.jsxs("div",{className:w.content,children:[e.jsx("div",{className:w.iconWrapper,children:m}),e.jsx("h2",{className:w.title,children:g}),e.jsx("p",{className:w.description,children:c}),n&&e.jsx("button",{className:w.retryButton,onClick:n,type:"button",children:"Try Again"})]}),e.jsx("div",{className:w.footer,children:e.jsxs("a",{href:"https://brainbaselabs.com",target:"_blank",rel:"noopener noreferrer",className:w.poweredBy,children:["Powered by"," ",e.jsx(O,{className:w.footerLogo,color:"var(--bb-text-tertiary)",cutoutColor:"var(--bb-surface-bg)"}),e.jsx("span",{children:"Brainbase Labs"})]})})]})},Kt="_widget_1ehud_1",Gt="_inline_1ehud_25",H={widget:Kt,"bottom-right":"_bottom-right_1ehud_10","bottom-left":"_bottom-left_1ehud_17",inline:Gt},Jt="https://whatsapp-based-server.onrender.com",Yt=({embedId:s,apiBaseUrl:t=Jt,mockMode:n=!1,mockResponses:r,position:u="bottom-right",defaultOpen:g=!1,primaryColor:c,agentName:m,welcomeMessage:l,showBranding:o,className:x,onSessionStart:L,onSessionEnd:E,onMessage:T,onError:W})=>{const[V,b]=i.useState(g),[_,$]=i.useState(null),[F,U]=i.useState(!0),[D,S]=i.useState(null),[J,q]=i.useState(),A=i.useMemo(()=>n?re({primaryColor:c,agentName:m,welcomeMessage:l},r):ne(t),[n,c,m,l,r,t]),p=i.useCallback(async()=>{U(!0),S(null),q(void 0);try{const C=await A.getDeploymentConfig(s);$({...C,primaryColor:c??C.primaryColor,agentName:m??C.agentName,welcomeMessage:l??C.welcomeMessage,styling:{...C.styling??{},...o!==void 0?{showBranding:o}:{}}})}catch(C){const P=C instanceof Error?C:new Error("Failed to load config");P.message.includes("404")?(S("not_found"),q("The chat widget with this embed ID was not found.")):P.message.includes("Failed to fetch")||P.message.includes("network")?S("network"):S("unknown"),n&&($({embedId:s,deploymentId:"mock-deployment",workerId:"mock-worker",flowId:"mock-flow",primaryColor:c??"#1a1a2e",agentName:m??"AI Assistant",styling:o!==void 0?{showBranding:o}:void 0}),S(null)),W==null||W(P)}finally{U(!1)}},[s,n,A,c,m,l,W]);i.useEffect(()=>{p()},[p]);const k=i.useMemo(()=>_||{embedId:s,deploymentId:"",workerId:"",flowId:"",primaryColor:c,agentName:m,welcomeMessage:l,styling:o!==void 0?{showBranding:o}:void 0},[_,s,c,m,l,o]),j=oe({config:k,apiClient:A,mockMode:n,onSessionStart:L,onSessionEnd:E,onMessage:T,onError:W}),d=i.useMemo(()=>({"--bb-primary-color":(_==null?void 0:_.primaryColor)??c??"#1a1a2e"}),[_==null?void 0:_.primaryColor,c]),h=()=>{j.endSession(),j.startNewSession()},a=()=>{b(!1)},f=()=>{p()},N=u==="inline";return F?null:D&&!n?!N&&!V?e.jsx("div",{className:`${H.widget} ${H[u]} ${x??""}`,style:d,children:e.jsx(Q,{onClick:()=>b(!0),agentName:m})}):e.jsx("div",{className:`${H.widget} ${H[u]} ${x??""}`,style:d,children:e.jsx(Zt,{errorType:D,message:J,onRetry:f,onClose:N?void 0:a})}):e.jsx("div",{className:`${H.widget} ${H[u]} ${x??""}`,style:d,children:V||N?e.jsx(ge,{config:k,messages:j.messages,isLoading:j.isLoading,onSendMessage:j.sendMessage,onClose:N?void 0:a,onNewChat:h}):e.jsx(Q,{onClick:()=>b(!0),agentName:_==null?void 0:_.agentName,agentLogoUrl:_==null?void 0:_.agentLogoUrl})})};function Xt(){if(typeof crypto<"u"&&crypto.randomUUID)return`bb-${crypto.randomUUID()}`;const s=Date.now().toString(36),t=Math.random().toString(36).substring(2,15),n=Math.random().toString(36).substring(2,15);return`bb-${s}-${t}${n}`}exports.ChatContainer=ge;exports.ChatHeader=ae;exports.ChatToggleButton=Q;exports.ChatWidget=Yt;exports.Message=ce;exports.MessageInput=ue;exports.MessageList=de;exports.ToolCallDisplay=ie;exports.TypingIndicator=le;exports.clearSession=X;exports.createAPIClient=ne;exports.createMockAPIClient=re;exports.generateSessionId=Xt;exports.getStoredSession=se;exports.storeSession=Y;exports.useChat=oe;
|
|
6
|
+
`))if(te.startsWith("data: "))try{const me=JSON.parse(te.slice(6));D(me,k,j)}catch{}}}}finally{d.releaseLock()}},[D]),J=i.useCallback(async p=>{if(!p.trim())return;const k={id:`user-${Date.now()}`,role:"user",content:p,timestamp:Date.now(),status:"sent"};o(a=>[...a,k]),c==null||c(k);const j=`assistant-${Date.now()}`,d={id:j,role:"assistant",content:"",timestamp:Date.now(),status:"streaming"};o(a=>[...a,d]),T(!0),V(null);const h=a=>{_(a)};try{if(r){const a=n.sendMessage(p);for await(const f of a)D(f,j,h)}else{const a=await n.sendMessage({embedId:t.embedId,message:p,sessionId:b??void 0});await S(a,j,h)}o(a=>a.map(f=>f.id===j&&f.status==="streaming"?{...f,status:"sent"}:f))}catch(a){const f=a instanceof Error?a:new Error("Failed to send message");V(f),m==null||m(f),o(N=>N.map(C=>C.id===j?{...C,status:"error",content:"Failed to get response"}:C))}finally{T(!1)}},[b,n,r,t.embedId,D,S,c,m]),q=i.useCallback(async()=>{if(!b)return;const p={sessionId:b,deploymentId:t.deploymentId,workerId:t.workerId,flowId:t.flowId,startTime:$.current,messages:l,toolCalls:x,status:"completed"};g==null||g(p),X(t.embedId),_(null),o([]),L([])},[b,t,l,x,g]),A=i.useCallback(()=>{o([]),L([])},[]);return{messages:l,toolCalls:x,isLoading:E,error:W,sessionId:b,sendMessage:J,endSession:q,clearMessages:A,startNewSession:U}}const pe="https://chat-embed-deployment.onrender.com";function ne(s=pe){return{async getDeploymentConfig(t){const n=await fetch(`${s}/chat/config/${t}`);if(!n.ok)throw new Error(`Failed to fetch deployment config: ${n.status}`);const r=await n.json();return{embedId:r.embedId,deploymentId:"",workerId:"",flowId:"",welcomeMessage:r.welcomeMessage,agentName:r.agentName,agentLogoUrl:r.agentLogoUrl,primaryColor:r.primaryColor,styling:r.styling}},async sendMessage(t){const n=await fetch(`${s}/chat/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({embed_id:t.embedId,message:t.message,session_id:t.sessionId||void 0,metadata:t.metadata})});if(!n.ok){const r=await n.text();throw new Error(`Failed to send message: ${n.status} - ${r}`)}if(!n.body)throw new Error("No response stream available");return n.body}}}const he={embedId:"mock-embed-id",deploymentId:"mock-deployment-id",workerId:"mock-worker-id",flowId:"mock-flow-id",agentName:"AI Assistant",agentLogoUrl:void 0,primaryColor:"#1a1a2e",styling:{}},_e=[{trigger:/hello|hi|hey/i,response:"Hello! I'm a demo AI assistant. How can I help you today?",delay:500},{trigger:/weather/i,response:"I'd check the weather for you, but I'm in mock mode! In production, I could use a weather API.",delay:800,toolCalls:[{name:"get_weather",arguments:{location:"San Francisco"},result:{temperature:72,condition:"sunny"}}]},{trigger:/help|support/i,response:"I'm here to help! You can ask me questions, and I'll do my best to assist you. In production, I'd be connected to your agent with full capabilities.",delay:600},{trigger:/pricing|cost|price/i,response:"For pricing information, I'd typically check our database or connect you with the sales team. This is a mock response demonstrating how I'd handle pricing questions.",delay:700,toolCalls:[{name:"lookup_pricing",arguments:{plan:"all"},result:{plans:[{name:"Starter",price:"$29/mo"},{name:"Pro",price:"$99/mo"}]}}]},{trigger:/.*/,response:"I'm running in mock mode. This is a simulated response to demonstrate the chat UI. In production, I'd be connected to your agent!",delay:1e3}];function R(s){return new Promise(t=>setTimeout(t,s))}function re(s,t){const n={...he,...s},r=t??_e,u=`mock-session-${Date.now()}`;return{async getDeploymentConfig(g){return await R(300),n},async*sendMessage(g){yield{type:"session",data:{session_id:u,is_new:!0},timestamp:Date.now()};const c=r.find(o=>typeof o.trigger=="string"?g.toLowerCase().includes(o.trigger.toLowerCase()):o.trigger.test(g))??r[r.length-1];if(await R(c.delay??500),c.toolCalls)for(const o of c.toolCalls)yield{type:"tool_call",data:{function:o.name,args:o.arguments},timestamp:Date.now()},await R(300),yield{type:"tool_call",data:{function:o.name,result:o.result},timestamp:Date.now()},await R(200);const m=c.response.split(" ");let l="";for(const o of m)l+=(l?" ":"")+o,yield{type:"message",data:{content:l,role:"assistant"},timestamp:Date.now()},await R(30+Math.random()*40);yield{type:"done",data:{session_id:u},timestamp:Date.now()}}}}const O=({className:s,color:t="currentColor",cutoutColor:n="var(--bb-primary-color)"})=>e.jsxs("svg",{className:s,viewBox:"0 0 800 800",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H788C794.627 400 800 405.373 800 412V740C800 773.137 773.137 800 740 800H412C405.373 800 400 794.627 400 788V412Z",fill:t}),e.jsx("circle",{cx:"400",cy:"400",r:"400",fill:t}),e.jsx("path",{d:"M0 60C0 26.8629 26.8629 0 60 0H397.614C398.932 0 400 1.06811 400 2.38569V2.38569C400 221.982 221.982 400 2.38569 400V400C1.06811 400 0 398.932 0 397.614V60Z",fill:t}),e.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H738C744.627 400 750 405.373 750 412V725C750 738.807 738.807 750 725 750H412C405.373 750 400 744.627 400 738V412Z",fill:t}),e.jsx("circle",{cx:"400",cy:"400",r:"350",fill:t}),e.jsx("path",{d:"M50 75C50 61.1929 61.1929 50 75 50H388C394.627 50 400 55.3726 400 62V388C400 394.627 394.627 400 388 400H62C55.3726 400 50 394.627 50 388V75Z",fill:t}),e.jsx("rect",{x:"399.919",y:"209",width:"270",height:"270",rx:"12",transform:"rotate(45 399.919 209)",fill:n})]}),fe="_header_1p6z5_1",xe="_compact_1p6z5_9",be="_headerBackground_1p6z5_20",ye="_headerContent_1p6z5_59",we="_topRow_1p6z5_64",je="_agentInfo_1p6z5_79",Ce="_agentLogo_1p6z5_85",ke="_agentLogoPlaceholder_1p6z5_102",ve="_brainbaseLogo_1p6z5_123",Ie="_agentName_1p6z5_137",Ne="_actions_1p6z5_144",Le="_actionButton_1p6z5_149",$e="_welcomeText_1p6z5_183",Se="_title_1p6z5_202",Be="_subtitle_1p6z5_210",y={header:fe,compact:xe,headerBackground:be,headerContent:ye,topRow:we,agentInfo:je,agentLogo:Ce,agentLogoPlaceholder:ke,brainbaseLogo:ve,agentName:Ie,actions:Ne,actionButton:Le,welcomeText:$e,title:Se,subtitle:Be},ae=({agentName:s="AI Assistant",agentLogoUrl:t,welcomeTitle:n,welcomeSubtitle:r,onClose:u,onNewChatRequest:g,showNewChatButton:c=!1,compact:m=!1})=>{const l=n||"Hello there.",o=r!==void 0?r:n?void 0:"How can we help?";return e.jsxs("div",{className:`${y.header} ${m?y.compact:""}`,children:[e.jsx("div",{className:y.headerBackground}),e.jsxs("div",{className:y.headerContent,children:[e.jsxs("div",{className:y.topRow,children:[e.jsxs("div",{className:y.agentInfo,children:[t?e.jsx("img",{src:t,alt:s,className:y.agentLogo}):e.jsx("div",{className:y.agentLogoPlaceholder,children:e.jsx(O,{className:y.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})}),e.jsx("span",{className:y.agentName,children:s})]}),e.jsxs("div",{className:y.actions,children:[c&&g&&e.jsx("button",{className:y.actionButton,onClick:g,"aria-label":"Start new chat",type:"button",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M12 5V19M5 12H19",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),u&&e.jsx("button",{className:y.actionButton,onClick:u,"aria-label":"Close chat",type:"button",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),!m&&e.jsxs("div",{className:y.welcomeText,children:[e.jsx("h1",{className:y.title,children:l}),o&&e.jsx("p",{className:y.subtitle,children:o})]})]})]})},Me="_messageWrapper_c86gj_1",Te="_user_c86gj_19",We="_assistant_c86gj_24",De="_avatar_c86gj_28",Pe="_avatarPlaceholder_c86gj_43",He="_brainbaseLogo_c86gj_53",Ee="_messageBubble_c86gj_58",Ve="_error_c86gj_76",Ae="_content_c86gj_81",Re="_cursor_c86gj_88",ze="_errorIndicator_c86gj_107",v={messageWrapper:Me,user:Te,assistant:We,avatar:De,avatarPlaceholder:Pe,brainbaseLogo:He,messageBubble:Ee,error:Ve,content:Ae,cursor:Re,errorIndicator:ze},ce=({message:s,agentName:t,agentLogoUrl:n})=>{const r=s.role==="user",u=s.status==="streaming",g=s.status==="error";return e.jsxs("div",{className:`${v.messageWrapper} ${r?v.user:v.assistant}`,children:[!r&&e.jsx("div",{className:v.avatar,children:n?e.jsx("img",{src:n,alt:t||"AI"}):e.jsx("div",{className:v.avatarPlaceholder,children:e.jsx(O,{className:v.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})})}),e.jsxs("div",{className:`${v.messageBubble} ${g?v.error:""}`,role:"article","aria-label":`${r?"Your message":`${t||"AI"} says`}`,children:[e.jsxs("div",{className:v.content,children:[s.content,u&&e.jsx("span",{className:v.cursor})]}),g&&e.jsxs("div",{className:v.errorIndicator,children:[e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M12 8V12M12 16H12.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.jsx("span",{children:"Failed to send"})]})]})]})},Oe="_toolCall_1wby1_1",Fe="_iconWrapper_1wby1_24",Ue="_spinner_1wby1_33",qe="_checkIcon_1wby1_48",Ze="_errorIcon_1wby1_54",Ke="_content_1wby1_60",Ge="_label_1wby1_66",Je="_name_1wby1_73",Ye="_pending_1wby1_78",Xe="_completed_1wby1_82",Qe="_error_1wby1_54",I={toolCall:Oe,iconWrapper:Fe,spinner:Ue,checkIcon:qe,errorIcon:Ze,content:Ke,label:Ge,name:Je,pending:Ye,completed:Xe,error:Qe},ie=({toolCall:s})=>{const t=s.status==="pending"||s.status==="executing",n=s.status==="completed",r=s.status==="error",u=g=>g.replace(/_/g," ").replace(/([A-Z])/g," $1").trim().toLowerCase().replace(/^./,c=>c.toUpperCase());return e.jsxs("div",{className:`${I.toolCall} ${t?I.pending:""} ${n?I.completed:""} ${r?I.error:""}`,children:[e.jsx("div",{className:I.iconWrapper,children:t?e.jsx("div",{className:I.spinner}):n?e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:I.checkIcon,children:e.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:I.errorIcon,children:e.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsxs("div",{className:I.content,children:[e.jsx("span",{className:I.label,children:t?"Running":n?"Completed":"Failed"}),e.jsx("span",{className:I.name,children:u(s.name)})]})]})},et="_wrapper_10rss_2",tt="_avatar_10rss_22",st="_avatarPlaceholder_10rss_37",ot="_brainbaseLogo_10rss_47",nt="_bubble_10rss_52",rt="_dot_10rss_63",B={wrapper:et,avatar:tt,avatarPlaceholder:st,brainbaseLogo:ot,bubble:nt,dot:rt},le=({agentName:s="AI",agentLogoUrl:t})=>e.jsxs("div",{className:B.wrapper,role:"status","aria-label":`${s} is typing`,children:[e.jsx("div",{className:B.avatar,children:t?e.jsx("img",{src:t,alt:s}):e.jsx("div",{className:B.avatarPlaceholder,children:e.jsx(O,{className:B.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})})}),e.jsxs("div",{className:B.bubble,children:[e.jsx("span",{className:B.dot}),e.jsx("span",{className:B.dot}),e.jsx("span",{className:B.dot})]})]}),at="_messageList_241kk_1",ct="_emptyState_241kk_29",it="_emptyIcon_241kk_40",lt="_emptyText_241kk_52",Z={messageList:at,emptyState:ct,emptyIcon:it,emptyText:lt},de=({messages:s,toolCalls:t=[],isLoading:n,agentName:r,agentLogoUrl:u})=>{var l;const g=i.useRef(null),c=i.useRef(null);i.useEffect(()=>{var o;(o=c.current)==null||o.scrollIntoView({behavior:"smooth"})},[s,t,n]);const m=t.filter(o=>o.status==="pending"||o.status==="executing");return e.jsxs("div",{className:Z.messageList,ref:g,role:"log","aria-live":"polite",children:[s.length===0&&!n&&e.jsxs("div",{className:Z.emptyState,children:[e.jsx("div",{className:Z.emptyIcon,children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("p",{className:Z.emptyText,children:"Start a conversation"})]}),s.map(o=>e.jsx(ce,{message:o,agentName:r,agentLogoUrl:u},o.id)),m.map(o=>e.jsx(ie,{toolCall:o},o.id)),n&&((l=s[s.length-1])==null?void 0:l.role)==="user"&&e.jsx(le,{agentName:r,agentLogoUrl:u}),e.jsx("div",{ref:c})]})},dt="_inputWrapper_5lgg7_1",ut="_inputContainer_5lgg7_7",gt="_textarea_5lgg7_23",mt="_sendButton_5lgg7_50",pt="_hint_5lgg7_89",z={inputWrapper:dt,inputContainer:ut,textarea:gt,sendButton:mt,hint:pt},ue=({onSend:s,disabled:t=!1,placeholder:n="Send a message..."})=>{const[r,u]=i.useState(""),g=i.useRef(null),c=i.useCallback(()=>{const o=g.current;o&&(o.style.height="auto",o.style.height=`${Math.min(o.scrollHeight,150)}px`)},[]);i.useEffect(()=>{c()},[r,c]);const m=i.useCallback(o=>{o==null||o.preventDefault();const x=r.trim();x&&!t&&(s(x),u(""),g.current&&(g.current.style.height="auto"))},[r,t,s]),l=i.useCallback(o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),m())},[m]);return e.jsxs("form",{className:z.inputWrapper,onSubmit:m,children:[e.jsxs("div",{className:z.inputContainer,children:[e.jsx("textarea",{ref:g,className:z.textarea,value:r,onChange:o=>u(o.target.value),onKeyDown:l,placeholder:n,disabled:t,rows:1,"aria-label":"Message input"}),e.jsx("button",{type:"submit",className:z.sendButton,disabled:t||!r.trim(),"aria-label":"Send message",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e.jsxs("div",{className:z.hint,children:["Press ",e.jsx("kbd",{children:"Enter"})," to send, ",e.jsx("kbd",{children:"Shift + Enter"})," for new line"]})]})},ht="_poweredBy_9jh5q_1",_t="_logo_9jh5q_20",ft="_poweredText_9jh5q_24",xt="_text_9jh5q_36",K={poweredBy:ht,logo:_t,poweredText:ft,text:xt},bt=({className:s})=>e.jsxs("svg",{className:s,viewBox:"0 0 800 800",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H788C794.627 400 800 405.373 800 412V740C800 773.137 773.137 800 740 800H412C405.373 800 400 794.627 400 788V412Z",fill:"currentColor"}),e.jsx("circle",{cx:"400",cy:"400",r:"400",fill:"currentColor"}),e.jsx("path",{d:"M0 60C0 26.8629 26.8629 0 60 0H397.614C398.932 0 400 1.06811 400 2.38569V2.38569C400 221.982 221.982 400 2.38569 400V400C1.06811 400 0 398.932 0 397.614V60Z",fill:"currentColor"}),e.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H738C744.627 400 750 405.373 750 412V725C750 738.807 738.807 750 725 750H412C405.373 750 400 744.627 400 738V412Z",fill:"currentColor"}),e.jsx("circle",{cx:"400",cy:"400",r:"350",fill:"currentColor"}),e.jsx("path",{d:"M50 75C50 61.1929 61.1929 50 75 50H388C394.627 50 400 55.3726 400 62V388C400 394.627 394.627 400 388 400H62C55.3726 400 50 394.627 50 388V75Z",fill:"currentColor"}),e.jsx("rect",{x:"399.919",y:"209",width:"270",height:"270",rx:"12",transform:"rotate(45 399.919 209)",fill:"var(--bb-surface-bg, #ffffff)"})]}),yt=({showBranding:s=!0})=>s?e.jsxs("a",{href:"https://brainbaselabs.com/",target:"_blank",rel:"noopener noreferrer",className:K.poweredBy,"aria-label":"Powered by Brainbase Labs",children:[e.jsx("span",{className:K.poweredText,children:"Powered by"}),e.jsx(bt,{className:K.logo}),e.jsx("span",{className:K.text,children:"Brainbase Labs"})]}):null,wt="_container_m2o9l_1",jt="_body_m2o9l_26",Ct="_confirmationOverlay_m2o9l_35",kt="_confirmationDialog_m2o9l_56",vt="_confirmationText_m2o9l_78",It="_confirmationButtons_m2o9l_86",Nt="_cancelButton_m2o9l_91",Lt="_confirmButton_m2o9l_92",M={container:wt,body:jt,confirmationOverlay:Ct,confirmationDialog:kt,confirmationText:vt,confirmationButtons:It,cancelButton:Nt,confirmButton:Lt},ge=({config:s,messages:t,toolCalls:n=[],isLoading:r,onSendMessage:u,onClose:g,onNewChat:c})=>{var T;const[m,l]=i.useState(!1),o=t.length>0,x=()=>{l(!0)},L=()=>{l(!1),c==null||c()},E=()=>{l(!1)};return e.jsxs("div",{className:M.container,role:"dialog","aria-label":"Chat window",children:[e.jsx(ae,{agentName:s.agentName,agentLogoUrl:s.agentLogoUrl,welcomeTitle:s.welcomeMessage||"Hello there.",welcomeSubtitle:s.welcomeMessage?void 0:"How can we help?",onClose:g,onNewChatRequest:x,showNewChatButton:o,compact:o}),e.jsxs("div",{className:M.body,children:[e.jsx(de,{messages:t,toolCalls:n,isLoading:r,agentName:s.agentName,agentLogoUrl:s.agentLogoUrl}),e.jsx(ue,{onSend:u,disabled:r,placeholder:"Ask a question..."})]}),e.jsx(yt,{showBranding:((T=s.styling)==null?void 0:T.showBranding)??!0}),m&&e.jsx("div",{className:M.confirmationOverlay,children:e.jsxs("div",{className:M.confirmationDialog,children:[e.jsx("p",{className:M.confirmationText,children:"End current chat and start a new conversation?"}),e.jsxs("div",{className:M.confirmationButtons,children:[e.jsx("button",{className:M.cancelButton,onClick:E,type:"button",children:"Cancel"}),e.jsx("button",{className:M.confirmButton,onClick:L,type:"button",children:"End Chat"})]})]})})]})},$t="_toggleButton_11dqz_1",St="_icon_11dqz_31",Bt="_agentLogo_11dqz_36",Mt="_unreadBadge_11dqz_43",G={toggleButton:$t,icon:St,agentLogo:Bt,unreadBadge:Mt},Q=({onClick:s,agentLogoUrl:t,unreadCount:n=0})=>e.jsxs("button",{className:G.toggleButton,onClick:s,"aria-label":"Open chat",type:"button",children:[t?e.jsx("img",{src:t,alt:"",className:G.agentLogo}):e.jsx("svg",{className:G.icon,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),n>0&&e.jsx("span",{className:G.unreadBadge,children:n>9?"9+":n})]}),Tt="_container_kgfgt_1",Wt="_header_kgfgt_25",Dt="_logoWrapper_kgfgt_38",Pt="_logo_kgfgt_38",Ht="_closeButton_kgfgt_51",Et="_content_kgfgt_74",Vt="_iconWrapper_kgfgt_84",At="_errorIcon_kgfgt_95",Rt="_title_kgfgt_101",zt="_description_kgfgt_109",Ot="_retryButton_kgfgt_117",Ft="_footer_kgfgt_139",Ut="_poweredBy_kgfgt_146",qt="_footerLogo_kgfgt_160",w={container:Tt,header:Wt,logoWrapper:Dt,logo:Pt,closeButton:Ht,content:Et,iconWrapper:Vt,errorIcon:At,title:Rt,description:zt,retryButton:Ot,footer:Ft,poweredBy:Ut,footerLogo:qt},Zt=({errorType:s,message:t,onRetry:n,onClose:r})=>{const u=()=>{switch(s){case"not_found":return{title:"Chat Not Found",description:t||"This chat widget is not configured correctly. Please check the embed ID.",icon:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",className:w.errorIcon,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M12 7V13M12 16V16.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})};case"network":return{title:"Connection Error",description:t||"Unable to connect to the chat service. Please check your internet connection.",icon:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",className:w.errorIcon,children:[e.jsx("path",{d:"M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M8 15L16 9M8 9L16 15",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})};default:return{title:"Something Went Wrong",description:t||"An unexpected error occurred. Please try again later.",icon:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:w.errorIcon,children:e.jsx("path",{d:"M12 9V13M12 17H12.01M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}}},{title:g,description:c,icon:m}=u();return e.jsxs("div",{className:w.container,children:[e.jsxs("div",{className:w.header,children:[e.jsx("div",{className:w.logoWrapper,children:e.jsx(O,{className:w.logo,color:"white",cutoutColor:"var(--bb-primary-color)"})}),r&&e.jsx("button",{className:w.closeButton,onClick:r,"aria-label":"Close",type:"button",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:e.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),e.jsxs("div",{className:w.content,children:[e.jsx("div",{className:w.iconWrapper,children:m}),e.jsx("h2",{className:w.title,children:g}),e.jsx("p",{className:w.description,children:c}),n&&e.jsx("button",{className:w.retryButton,onClick:n,type:"button",children:"Try Again"})]}),e.jsx("div",{className:w.footer,children:e.jsxs("a",{href:"https://brainbaselabs.com",target:"_blank",rel:"noopener noreferrer",className:w.poweredBy,children:["Powered by"," ",e.jsx(O,{className:w.footerLogo,color:"var(--bb-text-tertiary)",cutoutColor:"var(--bb-surface-bg)"}),e.jsx("span",{children:"Brainbase Labs"})]})})]})},Kt="_widget_1ehud_1",Gt="_inline_1ehud_25",H={widget:Kt,"bottom-right":"_bottom-right_1ehud_10","bottom-left":"_bottom-left_1ehud_17",inline:Gt},Jt="https://whatsapp-based-server.onrender.com",Yt=({embedId:s,apiBaseUrl:t=Jt,mockMode:n=!1,mockResponses:r,position:u="bottom-right",defaultOpen:g=!1,primaryColor:c,agentName:m,welcomeMessage:l,showBranding:o,className:x,onSessionStart:L,onSessionEnd:E,onMessage:T,onError:W})=>{const[V,b]=i.useState(g),[_,$]=i.useState(null),[F,U]=i.useState(!0),[D,S]=i.useState(null),[J,q]=i.useState(),A=i.useMemo(()=>n?re({primaryColor:c,agentName:m,welcomeMessage:l},r):ne(t),[n,c,m,l,r,t]),p=i.useCallback(async()=>{U(!0),S(null),q(void 0);try{const C=await A.getDeploymentConfig(s);$({...C,primaryColor:c??C.primaryColor,agentName:m??C.agentName,welcomeMessage:l??C.welcomeMessage,styling:{...C.styling??{},...o!==void 0?{showBranding:o}:{}}})}catch(C){const P=C instanceof Error?C:new Error("Failed to load config");P.message.includes("404")?(S("not_found"),q("The chat widget with this embed ID was not found.")):P.message.includes("Failed to fetch")||P.message.includes("network")?S("network"):S("unknown"),n&&($({embedId:s,deploymentId:"mock-deployment",workerId:"mock-worker",flowId:"mock-flow",primaryColor:c??"#1a1a2e",agentName:m??"AI Assistant",styling:o!==void 0?{showBranding:o}:void 0}),S(null)),W==null||W(P)}finally{U(!1)}},[s,n,A,c,m,l,W]);i.useEffect(()=>{p()},[p]);const k=i.useMemo(()=>_||{embedId:s,deploymentId:"",workerId:"",flowId:"",primaryColor:c,agentName:m,welcomeMessage:l,styling:o!==void 0?{showBranding:o}:void 0},[_,s,c,m,l,o]),j=oe({config:k,apiClient:A,mockMode:n,onSessionStart:L,onSessionEnd:E,onMessage:T,onError:W}),d=i.useMemo(()=>({"--bb-primary-color":(_==null?void 0:_.primaryColor)??c??"#1a1a2e"}),[_==null?void 0:_.primaryColor,c]),h=()=>{j.endSession(),j.startNewSession()},a=()=>{b(!1)},f=()=>{p()},N=u==="inline";return F?null:D&&!n?!N&&!V?e.jsx("div",{className:`${H.widget} ${H[u]} ${x??""}`,style:d,children:e.jsx(Q,{onClick:()=>b(!0),agentName:m})}):e.jsx("div",{className:`${H.widget} ${H[u]} ${x??""}`,style:d,children:e.jsx(Zt,{errorType:D,message:J,onRetry:f,onClose:N?void 0:a})}):e.jsx("div",{className:`${H.widget} ${H[u]} ${x??""}`,style:d,children:V||N?e.jsx(ge,{config:k,messages:j.messages,isLoading:j.isLoading,onSendMessage:j.sendMessage,onClose:N?void 0:a,onNewChat:h}):e.jsx(Q,{onClick:()=>b(!0),agentName:_==null?void 0:_.agentName,agentLogoUrl:_==null?void 0:_.agentLogoUrl})})};function Xt(){if(typeof crypto<"u"&&crypto.randomUUID)return`bb-${crypto.randomUUID()}`;const s=Date.now().toString(36),t=Math.random().toString(36).substring(2,15),n=Math.random().toString(36).substring(2,15);return`bb-${s}-${t}${n}`}exports.ChatContainer=ge;exports.ChatHeader=ae;exports.ChatToggleButton=Q;exports.ChatWidget=Yt;exports.Message=ce;exports.MessageInput=ue;exports.MessageList=de;exports.ToolCallDisplay=ie;exports.TypingIndicator=le;exports.clearSession=X;exports.createAPIClient=ne;exports.createMockAPIClient=re;exports.generateSessionId=Xt;exports.getStoredSession=se;exports.storeSession=Y;exports.useChat=oe;
|
package/dist/index.js
CHANGED
|
@@ -33,24 +33,24 @@ function le(o) {
|
|
|
33
33
|
onSessionEnd: m,
|
|
34
34
|
onMessage: c,
|
|
35
35
|
onError: g
|
|
36
|
-
} = o, [l, n] = N([]), [
|
|
36
|
+
} = o, [l, n] = N([]), [y, M] = N([]), [A, H] = N(!1), [P, z] = N(null), [b, _] = N(null), S = U(0), K = U(!1);
|
|
37
37
|
Z(() => {
|
|
38
38
|
if (K.current) return;
|
|
39
39
|
K.current = !0;
|
|
40
40
|
const p = ie(t.embedId);
|
|
41
41
|
p && p.status === "active" && (_(p.sessionId), n(p.messages), M(p.toolCalls), S.current = p.startTime);
|
|
42
42
|
}, [t.embedId]), Z(() => {
|
|
43
|
-
|
|
44
|
-
sessionId:
|
|
43
|
+
b && l.length > 0 && se(t.embedId, {
|
|
44
|
+
sessionId: b,
|
|
45
45
|
deploymentId: t.deploymentId,
|
|
46
46
|
workerId: t.workerId,
|
|
47
47
|
flowId: t.flowId,
|
|
48
48
|
startTime: S.current,
|
|
49
49
|
messages: l,
|
|
50
|
-
toolCalls:
|
|
50
|
+
toolCalls: y,
|
|
51
51
|
status: "active"
|
|
52
52
|
});
|
|
53
|
-
}, [
|
|
53
|
+
}, [b, l, y, t]);
|
|
54
54
|
const G = x(async () => (S.current = Date.now(), _(null), n([]), M([]), re(t.embedId), ""), [t.embedId]), E = x(
|
|
55
55
|
(p, I, k) => {
|
|
56
56
|
switch (p.type) {
|
|
@@ -104,14 +104,14 @@ function le(o) {
|
|
|
104
104
|
case "completed": {
|
|
105
105
|
n(
|
|
106
106
|
(d) => d.map((h) => h.id === I ? { ...h, status: "sent" } : h)
|
|
107
|
-
),
|
|
108
|
-
sessionId:
|
|
107
|
+
), b && se(t.embedId, {
|
|
108
|
+
sessionId: b,
|
|
109
109
|
deploymentId: t.deploymentId,
|
|
110
110
|
workerId: t.workerId,
|
|
111
111
|
flowId: t.flowId,
|
|
112
112
|
startTime: S.current,
|
|
113
113
|
messages: l,
|
|
114
|
-
toolCalls:
|
|
114
|
+
toolCalls: y,
|
|
115
115
|
status: "completed"
|
|
116
116
|
});
|
|
117
117
|
break;
|
|
@@ -131,7 +131,7 @@ function le(o) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
},
|
|
134
|
-
[t,
|
|
134
|
+
[t, b, l, y, u]
|
|
135
135
|
), T = x(
|
|
136
136
|
async (p, I, k) => {
|
|
137
137
|
const d = p.getReader(), h = new TextDecoder();
|
|
@@ -193,7 +193,7 @@ function le(o) {
|
|
|
193
193
|
const a = await s.sendMessage({
|
|
194
194
|
embedId: t.embedId,
|
|
195
195
|
message: p,
|
|
196
|
-
sessionId:
|
|
196
|
+
sessionId: b ?? void 0
|
|
197
197
|
});
|
|
198
198
|
await T(a, k, h);
|
|
199
199
|
}
|
|
@@ -214,7 +214,7 @@ function le(o) {
|
|
|
214
214
|
}
|
|
215
215
|
},
|
|
216
216
|
[
|
|
217
|
-
|
|
217
|
+
b,
|
|
218
218
|
s,
|
|
219
219
|
r,
|
|
220
220
|
t.embedId,
|
|
@@ -224,40 +224,40 @@ function le(o) {
|
|
|
224
224
|
g
|
|
225
225
|
]
|
|
226
226
|
), J = x(async () => {
|
|
227
|
-
if (!
|
|
227
|
+
if (!b) return;
|
|
228
228
|
const p = {
|
|
229
|
-
sessionId:
|
|
229
|
+
sessionId: b,
|
|
230
230
|
deploymentId: t.deploymentId,
|
|
231
231
|
workerId: t.workerId,
|
|
232
232
|
flowId: t.flowId,
|
|
233
233
|
startTime: S.current,
|
|
234
234
|
messages: l,
|
|
235
|
-
toolCalls:
|
|
235
|
+
toolCalls: y,
|
|
236
236
|
status: "completed"
|
|
237
237
|
};
|
|
238
238
|
m == null || m(p), re(t.embedId), _(null), n([]), M([]);
|
|
239
239
|
}, [
|
|
240
|
-
|
|
240
|
+
b,
|
|
241
241
|
t,
|
|
242
242
|
l,
|
|
243
|
-
|
|
243
|
+
y,
|
|
244
244
|
m
|
|
245
245
|
]), F = x(() => {
|
|
246
246
|
n([]), M([]);
|
|
247
247
|
}, []);
|
|
248
248
|
return {
|
|
249
249
|
messages: l,
|
|
250
|
-
toolCalls:
|
|
250
|
+
toolCalls: y,
|
|
251
251
|
isLoading: A,
|
|
252
252
|
error: P,
|
|
253
|
-
sessionId:
|
|
253
|
+
sessionId: b,
|
|
254
254
|
sendMessage: ee,
|
|
255
255
|
endSession: J,
|
|
256
256
|
clearMessages: F,
|
|
257
257
|
startNewSession: G
|
|
258
258
|
};
|
|
259
259
|
}
|
|
260
|
-
const de = "https://
|
|
260
|
+
const de = "https://chat-embed-deployment.onrender.com";
|
|
261
261
|
function ue(o = de) {
|
|
262
262
|
return {
|
|
263
263
|
async getDeploymentConfig(t) {
|
|
@@ -463,12 +463,12 @@ const q = ({
|
|
|
463
463
|
)
|
|
464
464
|
]
|
|
465
465
|
}
|
|
466
|
-
), he = "_header_1p6z5_1", _e = "_compact_1p6z5_9", fe = "_headerBackground_1p6z5_20",
|
|
466
|
+
), he = "_header_1p6z5_1", _e = "_compact_1p6z5_9", fe = "_headerBackground_1p6z5_20", ye = "_headerContent_1p6z5_59", be = "_topRow_1p6z5_64", we = "_agentInfo_1p6z5_79", Ce = "_agentLogo_1p6z5_85", ke = "_agentLogoPlaceholder_1p6z5_102", ve = "_brainbaseLogo_1p6z5_123", Ie = "_agentName_1p6z5_137", Ne = "_actions_1p6z5_144", Le = "_actionButton_1p6z5_149", $e = "_welcomeText_1p6z5_183", Be = "_title_1p6z5_202", xe = "_subtitle_1p6z5_210", w = {
|
|
467
467
|
header: he,
|
|
468
468
|
compact: _e,
|
|
469
469
|
headerBackground: fe,
|
|
470
|
-
headerContent:
|
|
471
|
-
topRow:
|
|
470
|
+
headerContent: ye,
|
|
471
|
+
topRow: be,
|
|
472
472
|
agentInfo: we,
|
|
473
473
|
agentLogo: Ce,
|
|
474
474
|
agentLogoPlaceholder: ke,
|
|
@@ -737,7 +737,7 @@ const q = ({
|
|
|
737
737
|
textarea: ht,
|
|
738
738
|
sendButton: _t,
|
|
739
739
|
hint: ft
|
|
740
|
-
},
|
|
740
|
+
}, yt = ({
|
|
741
741
|
onSend: o,
|
|
742
742
|
disabled: t = !1,
|
|
743
743
|
placeholder: s = "Send a message..."
|
|
@@ -752,8 +752,8 @@ const q = ({
|
|
|
752
752
|
const g = x(
|
|
753
753
|
(n) => {
|
|
754
754
|
n == null || n.preventDefault();
|
|
755
|
-
const
|
|
756
|
-
|
|
755
|
+
const y = r.trim();
|
|
756
|
+
y && !t && (o(y), u(""), m.current && (m.current.style.height = "auto"));
|
|
757
757
|
},
|
|
758
758
|
[r, t, o]
|
|
759
759
|
), l = x(
|
|
@@ -806,8 +806,8 @@ const q = ({
|
|
|
806
806
|
" for new line"
|
|
807
807
|
] })
|
|
808
808
|
] });
|
|
809
|
-
},
|
|
810
|
-
poweredBy:
|
|
809
|
+
}, bt = "_poweredBy_9jh5q_1", wt = "_logo_9jh5q_20", Ct = "_poweredText_9jh5q_24", kt = "_text_9jh5q_36", X = {
|
|
810
|
+
poweredBy: bt,
|
|
811
811
|
logo: wt,
|
|
812
812
|
poweredText: Ct,
|
|
813
813
|
text: kt
|
|
@@ -896,7 +896,7 @@ const q = ({
|
|
|
896
896
|
onNewChat: c
|
|
897
897
|
}) => {
|
|
898
898
|
var H;
|
|
899
|
-
const [g, l] = N(!1), n = t.length > 0,
|
|
899
|
+
const [g, l] = N(!1), n = t.length > 0, y = () => {
|
|
900
900
|
l(!0);
|
|
901
901
|
}, M = () => {
|
|
902
902
|
l(!1), c == null || c();
|
|
@@ -912,7 +912,7 @@ const q = ({
|
|
|
912
912
|
welcomeTitle: o.welcomeMessage || "Hello there.",
|
|
913
913
|
welcomeSubtitle: o.welcomeMessage ? void 0 : "How can we help?",
|
|
914
914
|
onClose: m,
|
|
915
|
-
onNewChatRequest:
|
|
915
|
+
onNewChatRequest: y,
|
|
916
916
|
showNewChatButton: n,
|
|
917
917
|
compact: n
|
|
918
918
|
}
|
|
@@ -929,7 +929,7 @@ const q = ({
|
|
|
929
929
|
}
|
|
930
930
|
),
|
|
931
931
|
/* @__PURE__ */ e(
|
|
932
|
-
|
|
932
|
+
yt,
|
|
933
933
|
{
|
|
934
934
|
onSend: u,
|
|
935
935
|
disabled: r,
|
|
@@ -1164,13 +1164,13 @@ const q = ({
|
|
|
1164
1164
|
agentName: g,
|
|
1165
1165
|
welcomeMessage: l,
|
|
1166
1166
|
showBranding: n,
|
|
1167
|
-
className:
|
|
1167
|
+
className: y,
|
|
1168
1168
|
onSessionStart: M,
|
|
1169
1169
|
onSessionEnd: A,
|
|
1170
1170
|
onMessage: H,
|
|
1171
1171
|
onError: P
|
|
1172
1172
|
}) => {
|
|
1173
|
-
const [z,
|
|
1173
|
+
const [z, b] = N(m), [_, S] = N(null), [K, G] = N(!0), [E, T] = N(null), [ee, J] = N(), F = te(() => s ? pe(
|
|
1174
1174
|
{ primaryColor: c, agentName: g, welcomeMessage: l },
|
|
1175
1175
|
r
|
|
1176
1176
|
) : ue(t), [s, c, g, l, r, t]), p = x(async () => {
|
|
@@ -1233,19 +1233,19 @@ const q = ({
|
|
|
1233
1233
|
), h = () => {
|
|
1234
1234
|
k.endSession(), k.startNewSession();
|
|
1235
1235
|
}, a = () => {
|
|
1236
|
-
|
|
1236
|
+
b(!1);
|
|
1237
1237
|
}, f = () => {
|
|
1238
1238
|
p();
|
|
1239
1239
|
}, B = u === "inline";
|
|
1240
1240
|
return K ? null : E && !s ? !B && !z ? /* @__PURE__ */ e(
|
|
1241
1241
|
"div",
|
|
1242
1242
|
{
|
|
1243
|
-
className: `${V.widget} ${V[u]} ${
|
|
1243
|
+
className: `${V.widget} ${V[u]} ${y ?? ""}`,
|
|
1244
1244
|
style: d,
|
|
1245
1245
|
children: /* @__PURE__ */ e(
|
|
1246
1246
|
ae,
|
|
1247
1247
|
{
|
|
1248
|
-
onClick: () =>
|
|
1248
|
+
onClick: () => b(!0),
|
|
1249
1249
|
agentName: g
|
|
1250
1250
|
}
|
|
1251
1251
|
)
|
|
@@ -1253,7 +1253,7 @@ const q = ({
|
|
|
1253
1253
|
) : /* @__PURE__ */ e(
|
|
1254
1254
|
"div",
|
|
1255
1255
|
{
|
|
1256
|
-
className: `${V.widget} ${V[u]} ${
|
|
1256
|
+
className: `${V.widget} ${V[u]} ${y ?? ""}`,
|
|
1257
1257
|
style: d,
|
|
1258
1258
|
children: /* @__PURE__ */ e(
|
|
1259
1259
|
Xt,
|
|
@@ -1268,7 +1268,7 @@ const q = ({
|
|
|
1268
1268
|
) : /* @__PURE__ */ e(
|
|
1269
1269
|
"div",
|
|
1270
1270
|
{
|
|
1271
|
-
className: `${V.widget} ${V[u]} ${
|
|
1271
|
+
className: `${V.widget} ${V[u]} ${y ?? ""}`,
|
|
1272
1272
|
style: d,
|
|
1273
1273
|
children: z || B ? /* @__PURE__ */ e(
|
|
1274
1274
|
Wt,
|
|
@@ -1283,7 +1283,7 @@ const q = ({
|
|
|
1283
1283
|
) : /* @__PURE__ */ e(
|
|
1284
1284
|
ae,
|
|
1285
1285
|
{
|
|
1286
|
-
onClick: () =>
|
|
1286
|
+
onClick: () => b(!0),
|
|
1287
1287
|
agentName: _ == null ? void 0 : _.agentName,
|
|
1288
1288
|
agentLogoUrl: _ == null ? void 0 : _.agentLogoUrl
|
|
1289
1289
|
}
|
|
@@ -1303,7 +1303,7 @@ export {
|
|
|
1303
1303
|
ae as ChatToggleButton,
|
|
1304
1304
|
so as ChatWidget,
|
|
1305
1305
|
Fe as Message,
|
|
1306
|
-
|
|
1306
|
+
yt as MessageInput,
|
|
1307
1307
|
mt as MessageList,
|
|
1308
1308
|
et as ToolCallDisplay,
|
|
1309
1309
|
ct as TypingIndicator,
|
package/package.json
CHANGED