chatbotlite 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/embed.global.js +2 -2
- package/dist/embed.global.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +7 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/embed.global.js
CHANGED
|
@@ -89,11 +89,11 @@ data: ${r}
|
|
|
89
89
|
.chatbotlite-dot:nth-child(2) { animation-delay: 0.15s; }
|
|
90
90
|
.chatbotlite-dot:nth-child(3) { animation-delay: 0.3s; margin-right: 0; }
|
|
91
91
|
.chatbotlite-brand:hover { color: ${Ml} !important; }
|
|
92
|
-
`;function Oh(){if(typeof document>"u"||document.getElementById(Im))return;let t=document.createElement("style");t.id=Im,t.textContent=Mh+xh,document.head.appendChild(t);}function wi(t){let{theme:e,title:l,subtitle:a,greeting:n,showBranding:u=true,position:i="bottom-right"}=t,c="endpoint"in t&&typeof t.endpoint=="string",o=l??"Chat",s=n??"Hi! How can we help?",h=e?.primary??Sh,g=Hm(h)>.65,r=e?.onPrimary??(g?"#0f172a":Th),y=t.attach,b=y?.enabled===true,A=y?.accept?.join(","),M=y?.maxSizeMb??10,d=y?.maxFiles??5,f=t.voice,m=f?.enabled===true,p=f?.lang??"en-US",E=typeof window<"u"&&(!!window.SpeechRecognition||!!window.webkitSpeechRecognition),[z,S]=(0, ct.useState)(
|
|
92
|
+
`;function Oh(){if(typeof document>"u"||document.getElementById(Im))return;let t=document.createElement("style");t.id=Im,t.textContent=Mh+xh,document.head.appendChild(t);}function wi(t){let{theme:e,title:l,subtitle:a,greeting:n,showBranding:u=true,position:i="bottom-right"}=t,c="endpoint"in t&&typeof t.endpoint=="string",o=l??"Chat",s=n??"Hi! How can we help?",h=e?.primary??Sh,g=Hm(h)>.65,r=e?.onPrimary??(g?"#0f172a":Th),y=t.attach,b=y?.enabled===true,A=y?.accept?.join(","),M=y?.maxSizeMb??10,d=y?.maxFiles??5,f=t.voice,m=f?.enabled===true,p=f?.lang??"en-US",E=typeof window<"u"&&(!!window.SpeechRecognition||!!window.webkitSpeechRecognition),[z,S]=(0, ct.useState)(!!t.defaultOpen),[_,C]=(0, ct.useState)(()=>{if(typeof window>"u")return false;try{return window.localStorage.getItem("cbl-panel-size")==="expanded"}catch{return false}}),[U,Pt]=(0, ct.useState)(()=>typeof window>"u"?false:window.innerWidth<640);(0, ct.useEffect)(()=>{if(typeof window>"u")return;let O=()=>Pt(window.innerWidth<640);return window.addEventListener("resize",O),()=>window.removeEventListener("resize",O)},[]);function xl(){C(O=>{let x=!O;try{window.localStorage.setItem("cbl-panel-size",x?"expanded":"compact");}catch{}return x});}let[ve,te]=(0, ct.useState)([{id:"g0",role:"assistant",content:s,ts:Date.now()}]),[Ol,Il]=(0, ct.useState)(""),[pt,_l]=(0, ct.useState)(false),[Lt,Gi]=(0, ct.useState)([]),tu=(0, ct.useRef)(null),Li=(0, ct.useRef)(null),Yf=(0, ct.useRef)(null),[ay,Dl]=(0, ct.useState)([]),de=t.tools??{},[Wa,Xi]=(0, ct.useState)(false),wf=(0, ct.useRef)(null);async function ny(O,x){let G=`[Tool ${O} result: ${JSON.stringify(x)}]`;_l(true);let ot=`a${Date.now()}`;te(F=>[...F,{id:ot,role:"assistant",content:"",ts:Date.now()}]);let ft=F=>{te(w=>w.map(j=>j.id===ot?{...j,content:j.content+F}:j));};try{let F=ve.filter(I=>I.role!=="system").map(I=>({role:I.role,content:I.content})),w=c?await Gf(G,F,[],ft):(await jf.reply(G,{history:F})).reply,j=Rf(w),W=Nf(w);te(I=>I.map(V=>V.id===ot?{...V,content:W}:V)),j.length>0&&Dl(I=>[...I,...j.map(V=>({messageId:ot,marker:V,status:"pending"}))]);}catch(F){let w=F instanceof Error?F.message:String(F);te(j=>j.map(W=>W.id===ot?{...W,content:`Sorry \u2014 something went wrong. (${w})`}:W));}finally{_l(false);}}async function Qi(O,x,G){Dl(ot=>ot.map((ft,F)=>F===x?{...ft,status:"submitted",result:G}:ft)),await ny(O,G);}function uy(){if(!E)return;if(Wa){wf.current?.stop();return}let O=window.SpeechRecognition??window.webkitSpeechRecognition;if(!O)return;let x=new O;x.lang=p,x.continuous=false,x.interimResults=true,x.onresult=G=>{let ot="";for(let ft=G.resultIndex;ft<G.results.length;ft++)ot+=G.results[ft][0].transcript;Il(ot);},x.onend=()=>Xi(false),x.onerror=()=>Xi(false),wf.current=x,Xi(true),x.start();}function iy(O){let x=Array.from(O).filter(G=>G.size<=M*1024*1024);Gi(G=>[...G,...x].slice(0,d));}function cy(O){Gi(x=>x.filter((G,ot)=>ot!==O));}(0, ct.useEffect)(()=>{Oh();},[]);let be=c?null:t,jf=(0, ct.useMemo)(()=>!be||!be.knowledge||!be.providers?null:new qi({knowledge:be.knowledge,providers:be.providers,...be.extraInstructions?{extraInstructions:be.extraInstructions}:{},...be.systemPromptTransform?{systemPromptTransform:be.systemPromptTransform}:{}}),[be]);(0, ct.useEffect)(()=>{tu.current&&(tu.current.scrollTop=tu.current.scrollHeight);},[ve,pt,z]),(0, ct.useEffect)(()=>{if(z&&Li.current){let O=setTimeout(()=>Li.current?.focus(),240);return ()=>clearTimeout(O)}},[z]);async function Gf(O,x,G,ot){let ft=Object.keys(de),F,w={Accept:"text/event-stream, application/json"};if(G.length>0){let V=new FormData;V.append("message",O),V.append("transcript",JSON.stringify(x)),V.append("enabledTools",JSON.stringify(ft));for(let Xt of G)V.append("attachments",Xt,Xt.name);F=V;}else w["Content-Type"]="application/json",F=JSON.stringify({message:O,transcript:x,enabledTools:ft});let j=await fetch(t.endpoint,{method:"POST",headers:w,body:F});if(!j.ok){let V=await j.text().catch(()=>""),Pl=/^\s*<(!doctype|html|head|body)/i.test(V)?"":V.slice(0,120).replace(/\s+/g," ").trim();throw new Error(`Server returned ${j.status}${Pl?` \u2014 ${Pl}`:""}`)}if((j.headers.get("Content-Type")??"").includes("text/event-stream")&&j.body){let V=j.body.getReader(),Xt=new TextDecoder,Pl="",Xf="",eu=null;for(;;){let{done:sy,value:ry}=await V.read();if(sy)break;Pl+=Xt.decode(ry,{stream:true});let Qf=Pl.split(`
|
|
93
93
|
|
|
94
94
|
`);Pl=Qf.pop()??"";for(let dy of Qf){let my=dy.split(`
|
|
95
95
|
`),lu="message",$a="";for(let me of my)me.startsWith("event:")?lu=me.slice(6).trim():me.startsWith("data:")&&($a=me.slice(5).trim());if($a){if(lu==="token")try{let me=JSON.parse($a);Xf+=me,ot(me);}catch{}else if(lu==="done")try{let me=JSON.parse($a);if(me.reply)return me.reply}catch{}else if(lu==="error")try{eu=JSON.parse($a).message??"stream error";}catch{eu="stream error";}}}}if(eu)throw new Error(eu);return Xf}let I=await j.json();if(I.error)throw new Error(I.error);if(!I.reply)throw new Error("Endpoint returned no reply.");return I.reply}async function Lf(){let O=Ol.trim(),x=Lt;if(!O&&x.length===0||pt)return;Il(""),Gi([]);let G=x.length>0?`${O}${O?`
|
|
96
|
-
`:""}\u{1F4CE} ${x.map(w=>w.name).join(", ")}`:O,ot={id:`u${Date.now()}`,role:"user",content:G,ts:Date.now()};te(w=>[...w,ot]),_l(true);let ft=`a${Date.now()}`;te(w=>[...w,{id:ft,role:"assistant",content:"",ts:Date.now()}]);let F=w=>{te(j=>j.map(W=>W.id===ft?{...W,content:W.content+w}:W));};try{let w=ve.filter(V=>V.role!=="system").map(V=>({role:V.role,content:V.content})),j=c?await Gf(O,w,x,F):(await jf.reply(O,{history:w})).reply,W=Rf(j),I=Nf(j);te(V=>V.map(Xt=>Xt.id===ft?{...Xt,content:I}:Xt)),W.length>0&&Dl(V=>[...V,...W.map(Xt=>({messageId:ft,marker:Xt,status:"pending"}))]);}catch(w){let j=w instanceof Error?w.message:String(w);te(W=>W.map(I=>I.id===ft?{...I,content:`Sorry \u2014 something went wrong. (${j})`}:I));}finally{_l(false);}}let oy=i==="bottom-left"?{left:20}:{right:20},fy=i==="bottom-left"?{left:20}:{right:20};return (0, T.jsxs)(T.Fragment,{children:[!z&&(0, T.jsx)("button",{className:"chatbotlite-root chatbotlite-launcher","data-color-scheme":"auto",onClick:()=>S(true),"aria-label":"Open chat",style:{"--cbl-primary":h,"--cbl-on-primary":r,position:"fixed",bottom:20,...oy,width:60,height:60,borderRadius:18,background:h,color:r,border:"none",fontSize:28,lineHeight:1,cursor:"pointer",boxShadow:"0 12px 28px -8px rgba(15,23,42,0.32), 0 4px 8px -2px rgba(15,23,42,0.12)",zIndex:99999,animation:"chatbotlite-pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1)",display:"flex",alignItems:"center",justifyContent:"center"},children:t.launcherIcon?t.launcherIcon.startsWith("http")||t.launcherIcon.startsWith("/")?(0, T.jsx)("img",{src:t.launcherIcon,alt:"",style:{width:28,height:28,objectFit:"contain"}}):(0, T.jsx)("span",{style:{filter:"drop-shadow(0 1px 2px rgba(0,0,0,0.2))"},children:t.launcherIcon}):(0, T.jsxs)("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0, T.jsx)("path",{d:"M21 12a8 8 0 0 1-13.6 5.8L3 19l1.2-4.4A8 8 0 1 1 21 12z"}),(0, T.jsx)("circle",{cx:"9",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),(0, T.jsx)("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),(0, T.jsx)("circle",{cx:"15",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]})}),z&&(0, T.jsxs)("div",{className:"chatbotlite-root","data-color-scheme":"auto",role:"dialog","aria-label":"Chat",style:{"--cbl-primary":h,"--cbl-on-primary":r,position:"fixed",bottom:U?0:20,...U?{left:0,right:0}:fy,width:U?"100vw":_?720:380,maxWidth:U?"100vw":"calc(100vw - 40px)",height:U?"100vh":_?800:580,maxHeight:U?"100vh":"calc(100vh - 40px)",background:Fl,color:We,borderRadius:20,boxShadow:"0 24px 60px -16px rgba(15,23,42,0.32), 0 8px 24px -8px rgba(15,23,42,0.12), 0 0 0 1px rgba(15,23,42,0.04)",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:qf,zIndex:99999,animation:"chatbotlite-slide 280ms cubic-bezier(0.16, 1, 0.3, 1)"},children:[(0, T.jsxs)("header",{style:{padding:"14px 16px",background:Fl,color:We,display:"flex",justifyContent:"space-between",alignItems:"center",gap:12,borderBottom:`1px solid ${Ah}`},children:[(0, T.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:t.avatar?10:0,minWidth:0},children:[t.avatar===true&&(0, T.jsx)("div",{style:{width:32,height:32,borderRadius:"50%",background:h,color:r,display:"flex",alignItems:"center",justifyContent:"center",fontSize:14,fontWeight:600,flexShrink:0,letterSpacing:"-0.02em"},children:o.charAt(0).toUpperCase()}),typeof t.avatar=="string"&&(0, T.jsx)("img",{src:t.avatar,alt:"",style:{width:32,height:32,borderRadius:"50%",objectFit:"cover",flexShrink:0,border:`1px solid ${ka}`}}),(0, T.jsxs)("div",{style:{display:"flex",flexDirection:"column",lineHeight:1.2,minWidth:0},children:[(0, T.jsx)("span",{style:{fontWeight:600,fontSize:15,letterSpacing:"-0.01em",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:We},children:o}),(a||pt)&&(0, T.jsx)("span",{style:{fontSize:12,color:Ml,marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a??(pt?"typing\u2026":"")})]})]}),(0, T.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[!U&&(0, T.jsx)("button",{className:"chatbotlite-resize",onClick:xl,"aria-label":_?"Compact view":"Expand view",title:_?"Compact view":"Expand view",style:{background:"transparent",border:"none",color:Ml,width:32,height:32,borderRadius:10,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:_?(0, T.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0, T.jsx)("polyline",{points:"9 4 4 4 4 9"}),(0, T.jsx)("polyline",{points:"15 4 20 4 20 9"}),(0, T.jsx)("polyline",{points:"4 15 4 20 9 20"}),(0, T.jsx)("polyline",{points:"20 15 20 20 15 20"})]}):(0, T.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0, T.jsx)("polyline",{points:"3 9 3 3 9 3"}),(0, T.jsx)("polyline",{points:"21 9 21 3 15 3"}),(0, T.jsx)("polyline",{points:"3 15 3 21 9 21"}),(0, T.jsx)("polyline",{points:"21 15 21 21 15 21"})]})}),(0, T.jsx)("button",{className:"chatbotlite-close",onClick:()=>S(false),"aria-label":"Close chat",style:{background:"transparent",border:"none",color:Ml,width:32,height:32,borderRadius:10,fontSize:22,lineHeight:1,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]})]}),(0, T.jsxs)("div",{ref:tu,style:{flex:1,overflowY:"auto",padding:"16px 14px",display:"flex",flexDirection:"column",gap:8,background:Wm},children:[ve.map(O=>(0, T.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,alignItems:O.role==="user"?"flex-end":"stretch"},children:[O.content&&(0, T.jsxs)("div",{className:"chatbotlite-msg",style:{alignSelf:O.role==="user"?"flex-end":"flex-start",maxWidth:"82%",padding:"9px 13px",borderRadius:O.role==="user"?"18px 18px 4px 18px":"18px 18px 18px 4px",background:O.role==="user"?h:$m,color:O.role==="user"?r:We,border:O.role==="user"?"none":`1px solid ${ka}`,fontSize:14,lineHeight:1.5,letterSpacing:"-0.005em",whiteSpace:"pre-wrap",wordBreak:"break-word",boxShadow:O.role==="user"?"0 1px 2px rgba(15,23,42,0.12)":"0 1px 2px rgba(15,23,42,0.04)"},children:[O.content,pt&&O.role==="assistant"&&O===ve[ve.length-1]&&(0, T.jsx)("span",{className:"chatbotlite-cursor",style:{color:h},"aria-hidden":"true",children:"\u258D"})]}),ay.map((x,G)=>({pt:x,originalIdx:G})).filter(({pt:x})=>x.messageId===O.id).map(({pt:x,originalIdx:G})=>{let ot={className:"chatbotlite-msg",style:{alignSelf:"stretch"}},ft={primary:h,onPrimary:r,border:ka,surface:Fl,surfaceMuted:Wm,textBody:We,textMuted:Ml};return x.marker.name==="uploadForReview"&&de.uploadForReview?(0, T.jsx)("div",{...ot,children:(0, T.jsx)(Zm,{...ft,purpose:String(x.marker.args.purpose??"files"),accept:String(x.marker.args.accept??"*"),maxMb:Number(x.marker.args.maxMb??10),submitting:x.status==="submitting",submitted:x.status==="submitted",onSubmit:async F=>{Dl(w=>w.map((j,W)=>W===G?{...j,status:"submitting"}:j));try{let w=await de.uploadForReview.handler({files:F,purpose:String(x.marker.args.purpose??"files")});await Qi("uploadForReview",G,w);}catch(w){throw Dl(j=>j.map((W,I)=>I===G?{...W,status:"pending"}:W)),w}}})},`tool-${G}`):x.marker.name==="scheduleCallback"&&de.scheduleCallback?(0, T.jsx)("div",{...ot,children:(0, T.jsx)(Km,{...ft,durationMin:Number(x.marker.args.durationMin??15),timezone:String(x.marker.args.timezone??"UTC"),submitting:x.status==="submitting",submitted:x.status==="submitted",...x.result?.confirmedAt?{submittedSlot:String(x.result.confirmedAt)}:{},getAvailableSlots:de.scheduleCallback.getAvailableSlots,onConfirm:async F=>{Dl(j=>j.map((W,I)=>I===G?{...W,status:"submitting"}:W));let w=await de.scheduleCallback.onConfirm({slot:F});await Qi("scheduleCallback",G,w);}})},`tool-${G}`):x.marker.name==="requestPayment"&&de.requestPayment?(0, T.jsx)("div",{...ot,children:(0, T.jsx)(km,{...ft,amount:Number(x.marker.args.amount??0),currency:String(x.marker.args.currency??"USD"),...x.marker.args.reason?{reason:String(x.marker.args.reason)}:{},showInterac:de.requestPayment.showInterac??true,...de.requestPayment.stripeLink?{stripeLink:de.requestPayment.stripeLink}:{},submitting:x.status==="submitting",submitted:x.status==="submitted",...x.result?.method?{submittedMethod:x.result.method}:{},onPick:async F=>{Dl(I=>I.map((V,Xt)=>Xt===G?{...V,status:"submitting"}:V));let w=Number(x.marker.args.amount??0),j=String(x.marker.args.currency??"USD"),W=await de.requestPayment.onPick({method:F,amount:w,currency:j});await Qi("requestPayment",G,{...W,method:F});}})},`tool-${G}`):null})]},O.id)),pt&&ve[ve.length-1]?.content===""&&(0, T.jsxs)("div",{className:"chatbotlite-msg",style:{alignSelf:"flex-start",padding:"12px 14px",borderRadius:"18px 18px 18px 4px",background:$m,border:`1px solid ${ka}`,boxShadow:"0 1px 2px rgba(15,23,42,0.04)"},children:[(0, T.jsx)("span",{className:"chatbotlite-dot"}),(0, T.jsx)("span",{className:"chatbotlite-dot"}),(0, T.jsx)("span",{className:"chatbotlite-dot"})]})]}),Lt.length>0&&(0, T.jsx)("div",{style:{padding:"8px 12px 0",background:Fl,display:"flex",flexWrap:"wrap",gap:6},children:Lt.map((O,x)=>(0, T.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 8px 4px 10px",borderRadius:999,background:Fm,fontSize:12,color:We,maxWidth:200},children:[(0, T.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ml},children:[(0, T.jsx)(Jm,{size:12}),(0, T.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",color:We},children:O.name})]}),(0, T.jsx)("button",{onClick:()=>cy(x),"aria-label":`Remove ${O.name}`,style:{background:"transparent",border:"none",cursor:"pointer",color:Ml,fontSize:14,lineHeight:1,padding:0},children:"\xD7"})]},`${O.name}-${x}`))}),(0, T.jsx)("div",{style:{padding:"10px 12px 12px",background:Fl},children:(0, T.jsxs)("div",{className:"chatbotlite-composer",style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px 4px 8px",background:Fm,borderRadius:999},children:[b&&(0, T.jsxs)(T.Fragment,{children:[(0, T.jsx)("input",{ref:Yf,type:"file",multiple:true,accept:A,style:{display:"none"},onChange:O=>{O.target.files&&iy(O.target.files),O.target.value="";}}),(0, T.jsx)("button",{className:"chatbotlite-icon-btn",onClick:()=>Yf.current?.click(),disabled:pt||Lt.length>=d,"aria-label":"Attach file",style:{width:32,height:32,borderRadius:"50%",background:"transparent",border:"none",cursor:pt||Lt.length>=d?"default":"pointer",opacity:pt||Lt.length>=d?.35:.75,color:Ml,lineHeight:1,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,alignSelf:"center",transition:"opacity 120ms ease, background 120ms ease"},children:(0, T.jsx)(Jm,{size:18})})]}),m&&E&&(0, T.jsx)("button",{className:"chatbotlite-icon-btn",onClick:uy,disabled:pt,"aria-label":Wa?"Stop recording":"Start voice input",style:{width:32,height:32,borderRadius:"50%",background:Wa?h:"transparent",color:Wa?r:"inherit",border:"none",cursor:pt?"default":"pointer",opacity:pt?.35:Wa?1:.75,lineHeight:1,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,alignSelf:"center",transition:"opacity 120ms ease, background 120ms ease, color 120ms ease"},children:(0, T.jsx)(Eh,{size:16})}),(0, T.jsx)("textarea",{ref:Li,className:"chatbotlite-input",rows:1,value:Ol,onChange:O=>{Il(O.target.value);let x=O.currentTarget;x.style.height="20px",x.scrollHeight>28&&(x.style.height=Math.min(x.scrollHeight,100)+"px");},onKeyDown:O=>{O.key==="Enter"&&!O.shiftKey&&(O.preventDefault(),Lf());},placeholder:"Message",disabled:pt,style:{flex:1,padding:"4px 6px",margin:0,border:"none",background:"transparent",fontSize:14,fontFamily:qf,color:We,outline:"none",resize:"none",lineHeight:1.4,height:20,maxHeight:100,boxSizing:"content-box",overflow:"hidden"}}),(0, T.jsx)("button",{className:"chatbotlite-send",onClick:()=>{Lf();},disabled:pt||!Ol.trim()&&Lt.length===0,"aria-label":"Send message",style:{width:34,height:34,borderRadius:"50%",background:h,color:r,border:"none",fontSize:14,fontWeight:600,fontFamily:qf,cursor:pt||!Ol.trim()&&Lt.length===0?"default":"pointer",opacity:pt||!Ol.trim()&&Lt.length===0?.35:1,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,padding:0,transition:"opacity 120ms ease, transform 80ms ease"},children:(0, T.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0, T.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),(0, T.jsx)("polyline",{points:"5 12 12 5 19 12"})]})})]})}),u&&(0, T.jsx)("a",{className:"chatbotlite-brand",href:"https://github.com/agents-io/chatbotlite",target:"_blank",rel:"noreferrer",style:{padding:"8px 12px",fontSize:11,fontWeight:500,color:Pm,textAlign:"center",textDecoration:"none",background:Fl,borderTop:`1px solid ${ka}`,letterSpacing:"0.01em",transition:"color 120ms ease"},children:(0, T.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5},children:[(0, T.jsx)(zh,{size:11}),"Powered by chatbotlite"]})})]})]})}var ji=Ct(pe()),Ja=new Map;function _h(t){let e=t.id??`chatbotlite-${Math.random().toString(36).slice(2,9)}`,l=Dh(t);if(Ja.has(e)){let u=Ja.get(e);return u.props=ly(u.props,l),u.root.render((0, ji.jsx)(wi,{...u.props})),ty(e)}let a=document.createElement("div");a.id=e,document.body.appendChild(a);let n=(0, ey.createRoot)(a);return n.render((0, ji.jsx)(wi,{...l})),Ja.set(e,{root:n,container:a,props:l}),ty(e)}function Dh(t){let{id:e,...l}=t;return l}function ly(t,e){return {...t,...e}}function ty(t){return {unmount(){let e=Ja.get(t);e&&(e.root.unmount(),e.container.remove(),Ja.delete(t));},update(e){let l=Ja.get(t);l&&(l.props=ly(l.props,e),l.root.render((0, ji.jsx)(wi,{...l.props})));}}}typeof window<"u"&&(window.chatbotlite={mount:_h,version:"0.6.1"});/*! Bundled license information:
|
|
96
|
+
`:""}\u{1F4CE} ${x.map(w=>w.name).join(", ")}`:O,ot={id:`u${Date.now()}`,role:"user",content:G,ts:Date.now()};te(w=>[...w,ot]),_l(true);let ft=`a${Date.now()}`;te(w=>[...w,{id:ft,role:"assistant",content:"",ts:Date.now()}]);let F=w=>{te(j=>j.map(W=>W.id===ft?{...W,content:W.content+w}:W));};try{let w=ve.filter(V=>V.role!=="system").map(V=>({role:V.role,content:V.content})),j=c?await Gf(O,w,x,F):(await jf.reply(O,{history:w})).reply,W=Rf(j),I=Nf(j);te(V=>V.map(Xt=>Xt.id===ft?{...Xt,content:I}:Xt)),W.length>0&&Dl(V=>[...V,...W.map(Xt=>({messageId:ft,marker:Xt,status:"pending"}))]);}catch(w){let j=w instanceof Error?w.message:String(w);te(W=>W.map(I=>I.id===ft?{...I,content:`Sorry \u2014 something went wrong. (${j})`}:I));}finally{_l(false);}}let oy=i==="bottom-left"?{left:20}:{right:20},fy=i==="bottom-left"?{left:20}:{right:20};return (0, T.jsxs)(T.Fragment,{children:[!z&&(0, T.jsx)("button",{className:"chatbotlite-root chatbotlite-launcher","data-color-scheme":"auto",onClick:()=>S(true),"aria-label":"Open chat",style:{"--cbl-primary":h,"--cbl-on-primary":r,position:"fixed",bottom:20,...oy,width:60,height:60,borderRadius:18,background:h,color:r,border:"none",fontSize:28,lineHeight:1,cursor:"pointer",boxShadow:"0 12px 28px -8px rgba(15,23,42,0.32), 0 4px 8px -2px rgba(15,23,42,0.12)",zIndex:99999,animation:"chatbotlite-pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1)",display:"flex",alignItems:"center",justifyContent:"center"},children:t.launcherIcon?t.launcherIcon.startsWith("http")||t.launcherIcon.startsWith("/")?(0, T.jsx)("img",{src:t.launcherIcon,alt:"",style:{width:28,height:28,objectFit:"contain"}}):(0, T.jsx)("span",{style:{filter:"drop-shadow(0 1px 2px rgba(0,0,0,0.2))"},children:t.launcherIcon}):(0, T.jsxs)("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0, T.jsx)("path",{d:"M21 12a8 8 0 0 1-13.6 5.8L3 19l1.2-4.4A8 8 0 1 1 21 12z"}),(0, T.jsx)("circle",{cx:"9",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),(0, T.jsx)("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),(0, T.jsx)("circle",{cx:"15",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]})}),z&&(0, T.jsxs)("div",{className:"chatbotlite-root","data-color-scheme":"auto",role:"dialog","aria-label":"Chat",style:{"--cbl-primary":h,"--cbl-on-primary":r,position:"fixed",bottom:U?0:20,...U?{left:0,right:0}:fy,width:U?"100vw":_?720:380,maxWidth:U?"100vw":"calc(100vw - 40px)",height:U?"100vh":_?800:580,maxHeight:U?"100vh":"calc(100vh - 40px)",background:Fl,color:We,borderRadius:20,boxShadow:"0 24px 60px -16px rgba(15,23,42,0.32), 0 8px 24px -8px rgba(15,23,42,0.12), 0 0 0 1px rgba(15,23,42,0.04)",display:"flex",flexDirection:"column",overflow:"hidden",fontFamily:qf,zIndex:99999,animation:"chatbotlite-slide 280ms cubic-bezier(0.16, 1, 0.3, 1)"},children:[(0, T.jsxs)("header",{style:{padding:"14px 16px",background:Fl,color:We,display:"flex",justifyContent:"space-between",alignItems:"center",gap:12,borderBottom:`1px solid ${Ah}`},children:[(0, T.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:t.avatar?10:0,minWidth:0},children:[t.avatar===true&&(0, T.jsx)("div",{style:{width:32,height:32,borderRadius:"50%",background:h,color:r,display:"flex",alignItems:"center",justifyContent:"center",fontSize:14,fontWeight:600,flexShrink:0,letterSpacing:"-0.02em"},children:o.charAt(0).toUpperCase()}),typeof t.avatar=="string"&&(0, T.jsx)("img",{src:t.avatar,alt:"",style:{width:32,height:32,borderRadius:"50%",objectFit:"cover",flexShrink:0,border:`1px solid ${ka}`}}),(0, T.jsxs)("div",{style:{display:"flex",flexDirection:"column",lineHeight:1.2,minWidth:0},children:[(0, T.jsx)("span",{style:{fontWeight:600,fontSize:15,letterSpacing:"-0.01em",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:We},children:o}),(a||pt)&&(0, T.jsx)("span",{style:{fontSize:12,color:Ml,marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a??(pt?"typing\u2026":"")})]})]}),(0, T.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[!U&&(0, T.jsx)("button",{className:"chatbotlite-resize",onClick:xl,"aria-label":_?"Compact view":"Expand view",title:_?"Compact view":"Expand view",style:{background:"transparent",border:"none",color:Ml,width:32,height:32,borderRadius:10,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:_?(0, T.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0, T.jsx)("polyline",{points:"9 4 4 4 4 9"}),(0, T.jsx)("polyline",{points:"15 4 20 4 20 9"}),(0, T.jsx)("polyline",{points:"4 15 4 20 9 20"}),(0, T.jsx)("polyline",{points:"20 15 20 20 15 20"})]}):(0, T.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0, T.jsx)("polyline",{points:"3 9 3 3 9 3"}),(0, T.jsx)("polyline",{points:"21 9 21 3 15 3"}),(0, T.jsx)("polyline",{points:"3 15 3 21 9 21"}),(0, T.jsx)("polyline",{points:"21 15 21 21 15 21"})]})}),(0, T.jsx)("button",{className:"chatbotlite-close",onClick:()=>S(false),"aria-label":"Close chat",style:{background:"transparent",border:"none",color:Ml,width:32,height:32,borderRadius:10,fontSize:22,lineHeight:1,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]})]}),(0, T.jsxs)("div",{ref:tu,style:{flex:1,overflowY:"auto",padding:"16px 14px",display:"flex",flexDirection:"column",gap:8,background:Wm},children:[ve.map(O=>(0, T.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,alignItems:O.role==="user"?"flex-end":"stretch"},children:[O.content&&(0, T.jsxs)("div",{className:"chatbotlite-msg",style:{alignSelf:O.role==="user"?"flex-end":"flex-start",maxWidth:"82%",padding:"9px 13px",borderRadius:O.role==="user"?"18px 18px 4px 18px":"18px 18px 18px 4px",background:O.role==="user"?h:$m,color:O.role==="user"?r:We,border:O.role==="user"?"none":`1px solid ${ka}`,fontSize:14,lineHeight:1.5,letterSpacing:"-0.005em",whiteSpace:"pre-wrap",wordBreak:"break-word",boxShadow:O.role==="user"?"0 1px 2px rgba(15,23,42,0.12)":"0 1px 2px rgba(15,23,42,0.04)"},children:[O.content,pt&&O.role==="assistant"&&O===ve[ve.length-1]&&(0, T.jsx)("span",{className:"chatbotlite-cursor",style:{color:h},"aria-hidden":"true",children:"\u258D"})]}),ay.map((x,G)=>({pt:x,originalIdx:G})).filter(({pt:x})=>x.messageId===O.id).map(({pt:x,originalIdx:G})=>{let ot={className:"chatbotlite-msg",style:{alignSelf:"stretch"}},ft={primary:h,onPrimary:r,border:ka,surface:Fl,surfaceMuted:Wm,textBody:We,textMuted:Ml};return x.marker.name==="uploadForReview"&&de.uploadForReview?(0, T.jsx)("div",{...ot,children:(0, T.jsx)(Zm,{...ft,purpose:String(x.marker.args.purpose??"files"),accept:String(x.marker.args.accept??"*"),maxMb:Number(x.marker.args.maxMb??10),submitting:x.status==="submitting",submitted:x.status==="submitted",onSubmit:async F=>{Dl(w=>w.map((j,W)=>W===G?{...j,status:"submitting"}:j));try{let w=await de.uploadForReview.handler({files:F,purpose:String(x.marker.args.purpose??"files")});await Qi("uploadForReview",G,w);}catch(w){throw Dl(j=>j.map((W,I)=>I===G?{...W,status:"pending"}:W)),w}}})},`tool-${G}`):x.marker.name==="scheduleCallback"&&de.scheduleCallback?(0, T.jsx)("div",{...ot,children:(0, T.jsx)(Km,{...ft,durationMin:Number(x.marker.args.durationMin??15),timezone:String(x.marker.args.timezone??"UTC"),submitting:x.status==="submitting",submitted:x.status==="submitted",...x.result?.confirmedAt?{submittedSlot:String(x.result.confirmedAt)}:{},getAvailableSlots:de.scheduleCallback.getAvailableSlots,onConfirm:async F=>{Dl(j=>j.map((W,I)=>I===G?{...W,status:"submitting"}:W));let w=await de.scheduleCallback.onConfirm({slot:F});await Qi("scheduleCallback",G,w);}})},`tool-${G}`):x.marker.name==="requestPayment"&&de.requestPayment?(0, T.jsx)("div",{...ot,children:(0, T.jsx)(km,{...ft,amount:Number(x.marker.args.amount??0),currency:String(x.marker.args.currency??"USD"),...x.marker.args.reason?{reason:String(x.marker.args.reason)}:{},showInterac:de.requestPayment.showInterac??true,...de.requestPayment.stripeLink?{stripeLink:de.requestPayment.stripeLink}:{},submitting:x.status==="submitting",submitted:x.status==="submitted",...x.result?.method?{submittedMethod:x.result.method}:{},onPick:async F=>{Dl(I=>I.map((V,Xt)=>Xt===G?{...V,status:"submitting"}:V));let w=Number(x.marker.args.amount??0),j=String(x.marker.args.currency??"USD"),W=await de.requestPayment.onPick({method:F,amount:w,currency:j});await Qi("requestPayment",G,{...W,method:F});}})},`tool-${G}`):null})]},O.id)),pt&&ve[ve.length-1]?.content===""&&(0, T.jsxs)("div",{className:"chatbotlite-msg",style:{alignSelf:"flex-start",padding:"12px 14px",borderRadius:"18px 18px 18px 4px",background:$m,border:`1px solid ${ka}`,boxShadow:"0 1px 2px rgba(15,23,42,0.04)"},children:[(0, T.jsx)("span",{className:"chatbotlite-dot"}),(0, T.jsx)("span",{className:"chatbotlite-dot"}),(0, T.jsx)("span",{className:"chatbotlite-dot"})]})]}),Lt.length>0&&(0, T.jsx)("div",{style:{padding:"8px 12px 0",background:Fl,display:"flex",flexWrap:"wrap",gap:6},children:Lt.map((O,x)=>(0, T.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 8px 4px 10px",borderRadius:999,background:Fm,fontSize:12,color:We,maxWidth:200},children:[(0, T.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ml},children:[(0, T.jsx)(Jm,{size:12}),(0, T.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",color:We},children:O.name})]}),(0, T.jsx)("button",{onClick:()=>cy(x),"aria-label":`Remove ${O.name}`,style:{background:"transparent",border:"none",cursor:"pointer",color:Ml,fontSize:14,lineHeight:1,padding:0},children:"\xD7"})]},`${O.name}-${x}`))}),(0, T.jsx)("div",{style:{padding:"10px 12px 12px",background:Fl},children:(0, T.jsxs)("div",{className:"chatbotlite-composer",style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px 4px 8px",background:Fm,borderRadius:999},children:[b&&(0, T.jsxs)(T.Fragment,{children:[(0, T.jsx)("input",{ref:Yf,type:"file",multiple:true,accept:A,style:{display:"none"},onChange:O=>{O.target.files&&iy(O.target.files),O.target.value="";}}),(0, T.jsx)("button",{className:"chatbotlite-icon-btn",onClick:()=>Yf.current?.click(),disabled:pt||Lt.length>=d,"aria-label":"Attach file",style:{width:32,height:32,borderRadius:"50%",background:"transparent",border:"none",cursor:pt||Lt.length>=d?"default":"pointer",opacity:pt||Lt.length>=d?.35:.75,color:Ml,lineHeight:1,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,alignSelf:"center",transition:"opacity 120ms ease, background 120ms ease"},children:(0, T.jsx)(Jm,{size:18})})]}),m&&E&&(0, T.jsx)("button",{className:"chatbotlite-icon-btn",onClick:uy,disabled:pt,"aria-label":Wa?"Stop recording":"Start voice input",style:{width:32,height:32,borderRadius:"50%",background:Wa?h:"transparent",color:Wa?r:"inherit",border:"none",cursor:pt?"default":"pointer",opacity:pt?.35:Wa?1:.75,lineHeight:1,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,alignSelf:"center",transition:"opacity 120ms ease, background 120ms ease, color 120ms ease"},children:(0, T.jsx)(Eh,{size:16})}),(0, T.jsx)("textarea",{ref:Li,className:"chatbotlite-input",rows:1,value:Ol,onChange:O=>{Il(O.target.value);let x=O.currentTarget;x.style.height="20px",x.scrollHeight>28&&(x.style.height=Math.min(x.scrollHeight,100)+"px");},onKeyDown:O=>{O.key==="Enter"&&!O.shiftKey&&(O.preventDefault(),Lf());},placeholder:"Message",disabled:pt,style:{flex:1,padding:"4px 6px",margin:0,border:"none",background:"transparent",fontSize:14,fontFamily:qf,color:We,outline:"none",resize:"none",lineHeight:1.4,height:20,maxHeight:100,boxSizing:"content-box",overflow:"hidden"}}),(0, T.jsx)("button",{className:"chatbotlite-send",onClick:()=>{Lf();},disabled:pt||!Ol.trim()&&Lt.length===0,"aria-label":"Send message",style:{width:34,height:34,borderRadius:"50%",background:h,color:r,border:"none",fontSize:14,fontWeight:600,fontFamily:qf,cursor:pt||!Ol.trim()&&Lt.length===0?"default":"pointer",opacity:pt||!Ol.trim()&&Lt.length===0?.35:1,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,padding:0,transition:"opacity 120ms ease, transform 80ms ease"},children:(0, T.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0, T.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),(0, T.jsx)("polyline",{points:"5 12 12 5 19 12"})]})})]})}),u&&(0, T.jsx)("a",{className:"chatbotlite-brand",href:"https://github.com/agents-io/chatbotlite",target:"_blank",rel:"noreferrer",style:{padding:"8px 12px",fontSize:11,fontWeight:500,color:Pm,textAlign:"center",textDecoration:"none",background:Fl,borderTop:`1px solid ${ka}`,letterSpacing:"0.01em",transition:"color 120ms ease"},children:(0, T.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5},children:[(0, T.jsx)(zh,{size:11}),"Powered by chatbotlite"]})})]})]})}var ji=Ct(pe()),Ja=new Map;function _h(t){let e=t.id??`chatbotlite-${Math.random().toString(36).slice(2,9)}`,l=Dh(t);if(Ja.has(e)){let u=Ja.get(e);return u.props=ly(u.props,l),u.root.render((0, ji.jsx)(wi,{...u.props})),ty(e)}let a=document.createElement("div");a.id=e,document.body.appendChild(a);let n=(0, ey.createRoot)(a);return n.render((0, ji.jsx)(wi,{...l})),Ja.set(e,{root:n,container:a,props:l}),ty(e)}function Dh(t){let{id:e,...l}=t;return l}function ly(t,e){return {...t,...e}}function ty(t){return {unmount(){let e=Ja.get(t);e&&(e.root.unmount(),e.container.remove(),Ja.delete(t));},update(e){let l=Ja.get(t);l&&(l.props=ly(l.props,e),l.root.render((0, ji.jsx)(wi,{...l.props})));}}}typeof window<"u"&&(window.chatbotlite={mount:_h,version:"0.6.2"});/*! Bundled license information:
|
|
97
97
|
|
|
98
98
|
scheduler/cjs/scheduler.production.js:
|
|
99
99
|
(**
|