@headwai/chat-bubble 2.0.4 → 2.0.5

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.
@@ -276,6 +276,6 @@ new Remarkable().use(linkify)
276
276
 
277
277
  ${r.map((t,e)=>{const n=t.name||"Untitled Reference";let a=`**[${e+1}]** `;return a+=n,a}).join(`
278
278
 
279
- `)}`}function Ns(r){let s,t,e,n,a;return{c(){s=ct("div"),t=ct("img"),js(t.src,e=r[5])||Ee(t,"src",e),Ee(t,"alt","AI Assistant"),Ee(t,"class","svelte-bjand4"),Ee(s,"class","ai-assistant-icon svelte-bjand4"),Br(s,"background",r[2]),Ee(s,"role","button"),Ee(s,"tabindex","0")},m(i,o){Ln(i,s,o),Rn(s,t),n||(a=[Nr(s,"click",r[10]),Nr(s,"keydown",r[27])],n=!0)},p(i,o){o[0]&4&&Br(s,"background",i[2])},d(i){i&&Zt(s),n=!1,ut(a)}}}function Bs(r){let s,t;return{c(){s=ct("div"),t=ct("deep-chat"),me(t,"demo","false"),me(t,"textInput",r[9]),me(t,"messageStyles",r[3]),me(t,"history",r[6]),me(t,"connect",r[4]),me(t,"requestBodyLimits",r[8]),me(t,"requestInterceptor",r[12]),me(t,"responseInterceptor",r[13]),me(t,"customButtons",r[7]),me(t,"onMessage",r[11]),Ee(s,"class","chat-container svelte-bjand4")},m(e,n){Ln(e,s,n),Rn(s,t),r[28](t)},p(e,n){n[0]&8&&me(t,"messageStyles",e[3]),n[0]&16&&me(t,"connect",e[4])},d(e){e&&Zt(s),r[28](null)}}}function tc(r){let s,t,e=!r[0]&&Ns(r),n=r[0]&&Bs(r);return{c(){s=ct("main"),e&&e.c(),t=Vs(),n&&n.c(),Ee(s,"class","svelte-bjand4")},m(a,i){Ln(a,s,i),e&&e.m(s,null),Rn(s,t),n&&n.m(s,null)},p(a,i){a[0]?e&&(e.d(1),e=null):e?e.p(a,i):(e=Ns(a),e.c(),e.m(s,t)),a[0]?n?n.p(a,i):(n=Bs(a),n.c(),n.m(s,null)):n&&(n.d(1),n=null)},i:pe,o:pe,d(a){a&&Zt(s),e&&e.d(),n&&n.d()}}}function nc(r,s){r=r.replace("#","");const t=parseInt(r,16),e=(t>>16)+s,n=(t>>8&255)+s,a=(t&255)+s,i=Math.max(0,Math.min(255,e)),o=Math.max(0,Math.min(255,n)),l=Math.max(0,Math.min(255,a));return`#${(i<<16|o<<8|l).toString(16).padStart(6,"0")}`}function rc(r){return r.map(s=>{let t=s.text||s.content;return(s.role==="ai"||s.role==="assistant")&&(t=t.replace(/\n\n---\n\n\*\*References:\*\*[\s\S]*$/,"")),{role:s.role==="ai"?"assistant":s.role,content:t}})}function ac(r,s,t){let e,n,a,{apiUrl:i=void 0}=s,{apiKey:o=void 0}=s,{modelId:l=void 0}=s,{maxMessages:u=void 0}=s,{placeholderText:c=void 0}=s,{faviconPath:d=void 0}=s,{initialMessage:p=void 0}=s,{userMessageBackgroundColor:h=void 0}=s,{aiMessageBackgroundColor:v=void 0}=s,{userMessageTextColor:f=void 0}=s,{aiMessageTextColor:g=void 0}=s,{faviconBackgroundColor:y=void 0}=s,_=!1,C=null,I=[],w="",A="",U=[],P="",G;const x=d||void 0||Zu,T=p||"Hey, how can I assist you?",E=[{role:"ai",text:T}],F=[{styles:{button:{default:{container:{default:{backgroundColor:"transparent",borderRadius:"4px",width:"24px",height:"24px",border:"1px solid #e0e0e0",cursor:"pointer",transition:"all 0.2s ease"},hover:{backgroundColor:"#2196F3",borderColor:"#2196F3",transform:"scale(1.05)"},click:{backgroundColor:"#1976D2",borderColor:"#1976D2"}},svg:{content:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
279
+ `)}`}function Ns(r){let s,t,e,n,a;return{c(){s=ct("div"),t=ct("img"),js(t.src,e=r[5])||Ee(t,"src",e),Ee(t,"alt","AI Assistant"),Ee(t,"class","svelte-bjand4"),Ee(s,"class","ai-assistant-icon svelte-bjand4"),Br(s,"background",r[2]),Ee(s,"role","button"),Ee(s,"tabindex","0")},m(i,o){Ln(i,s,o),Rn(s,t),n||(a=[Nr(s,"click",r[10]),Nr(s,"keydown",r[27])],n=!0)},p(i,o){o[0]&4&&Br(s,"background",i[2])},d(i){i&&Zt(s),n=!1,ut(a)}}}function Bs(r){let s,t;return{c(){s=ct("div"),t=ct("deep-chat"),me(t,"demo","false"),me(t,"textInput",r[9]),me(t,"messageStyles",r[3]),me(t,"history",r[6]),me(t,"connect",r[4]),me(t,"requestBodyLimits",r[8]),me(t,"requestInterceptor",r[12]),me(t,"responseInterceptor",r[13]),me(t,"customButtons",r[7]),me(t,"onMessage",r[11]),Ee(s,"class","chat-container svelte-bjand4")},m(e,n){Ln(e,s,n),Rn(s,t),r[28](t)},p(e,n){n[0]&8&&me(t,"messageStyles",e[3]),n[0]&16&&me(t,"connect",e[4])},d(e){e&&Zt(s),r[28](null)}}}function tc(r){let s,t,e=!r[0]&&Ns(r),n=r[0]&&Bs(r);return{c(){s=ct("main"),e&&e.c(),t=Vs(),n&&n.c(),Ee(s,"class","svelte-bjand4")},m(a,i){Ln(a,s,i),e&&e.m(s,null),Rn(s,t),n&&n.m(s,null)},p(a,i){a[0]?e&&(e.d(1),e=null):e?e.p(a,i):(e=Ns(a),e.c(),e.m(s,t)),a[0]?n?n.p(a,i):(n=Bs(a),n.c(),n.m(s,null)):n&&(n.d(1),n=null)},i:pe,o:pe,d(a){a&&Zt(s),e&&e.d(),n&&n.d()}}}function nc(r,s){r=r.replace("#","");const t=parseInt(r,16),e=(t>>16)+s,n=(t>>8&255)+s,a=(t&255)+s,i=Math.max(0,Math.min(255,e)),o=Math.max(0,Math.min(255,n)),l=Math.max(0,Math.min(255,a));return`#${(i<<16|o<<8|l).toString(16).padStart(6,"0")}`}function rc(r){return r.map(s=>{let t=s.text||s.content;return(s.role==="ai"||s.role==="assistant")&&(t=t.replace(/\n\n---\n\n\*\*References:\*\*[\s\S]*$/,"")),{role:s.role==="ai"?"assistant":s.role,content:t}})}function ac(r,s,t){let e,n,a,{apiUrl:i=void 0}=s,{apiKey:o=void 0}=s,{modelId:l=void 0}=s,{maxMessages:u=void 0}=s,{placeholderText:c=void 0}=s,{faviconPath:d=void 0}=s,{initialMessage:p=void 0}=s,{userMessageBackgroundColor:h=void 0}=s,{aiMessageBackgroundColor:v=void 0}=s,{userMessageTextColor:f=void 0}=s,{aiMessageTextColor:g=void 0}=s,{faviconBackgroundColor:y=void 0}=s,_=!1,C=null,I=[],w="",A="",U=[],P="",G;const x=d||void 0||Zu,T=p||void 0||"Hey, how can I help you?",E=[{role:"ai",text:T}],F=[{styles:{button:{default:{container:{default:{backgroundColor:"transparent",borderRadius:"4px",width:"24px",height:"24px",border:"1px solid #e0e0e0",cursor:"pointer",transition:"all 0.2s ease"},hover:{backgroundColor:"#2196F3",borderColor:"#2196F3",transform:"scale(1.05)"},click:{backgroundColor:"#1976D2",borderColor:"#1976D2"}},svg:{content:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
280
280
  <path d="M19 14L12 21L5 14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
281
- </svg>`,styles:{default:{width:"14px",height:"14px",color:"#666"},hover:{color:"white"}}}}}},position:"outside-right",tooltip:{text:"Minimize chat",timeout:300,style:{backgroundColor:"#333",color:"white",fontSize:"12px",padding:"4px 8px",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}},onClick:()=>(Y(),"default")}],M={maxMessages:parseInt(u||"0")||0},K={placeholder:{text:c||"Welcome to the demo!"}};function Y(){_?(t(26,C=null),I=[]):$([{role:"assistant",content:T}]),t(0,_=!_)}function le(){if(console.log("=== Message History ==="),I.length===0){console.log("No messages in history");return}I.forEach((R,W)=>{const se=R.content.length>50?R.content.substring(0,50)+"...":R.content;console.log(`${W+1}. ${R.role.toUpperCase()}: ${se}`)}),console.log("=====================")}async function $(R){var W;try{const se=Math.floor(Date.now()/1e3),Se=[l||"test-model"],ue=[],at={};let st=null;R.forEach((Ne,ot)=>{const lt=Mn(),Jt=ot<R.length-1?Mn():null,Xt={id:lt,parentId:st,childrenIds:Jt?[Jt]:[],role:Ne.role,content:Ne.content,timestamp:se,models:Se};Ne.role==="assistant"&&(Xt.model=Se[0],Xt.modelId=Se[0],Xt.modelIdx=0),ue.push(Xt),at[lt]=Xt,st=lt}),ue.forEach((Ne,ot)=>{ot<ue.length-1&&(Ne.childrenIds=[ue[ot+1].id])});const it=(W=ue[ue.length-1])==null?void 0:W.id,Rr={chat:{id:"",title:"New Chatbubble Chat",models:Se,params:{},history:{messages:at,currentId:it},messages:ue,tags:[],timestamp:Date.now()},folder_id:null},In=`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/v1/chats/new`,$t=await fetch(In,{method:"POST",headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},body:JSON.stringify(Rr)});if($t.ok){const Ne=await $t.json();return t(26,C=Ne.id),console.log("New chat created with ID:",C),I=ue,le(),C}else return console.error("Failed to create new chat:",$t.statusText),null}catch(se){return console.error("Error creating new chat:",se),null}}async function re(R,W,se){if(!C){console.error("Cannot store chat history: no chat ID available");return}console.log("assistantMessageSources:",se);try{const Se=Math.floor(Date.now()/1e3),ue=[l||"test-model"],at=Mn(),st=Mn(),it=I[I.length-1],Rr={id:at,parentId:it?it.id:null,childrenIds:[st],role:"user",content:R,timestamp:Se,models:ue},Fs={id:st,parentId:at,childrenIds:[],role:"assistant",content:W,model:ue[0],modelId:ue[0],modelIdx:0,timestamp:Se,sources:se};it&&(it.childrenIds=[at]),I.push(Rr,Fs);const In={};I.forEach(Jt=>{In[Jt.id]=Jt});const $t={chat:{models:ue,history:{messages:In,currentId:st},messages:I,params:{}}},ot=`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/v1/chats/${C}`,lt=await fetch(ot,{method:"POST",headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},body:JSON.stringify($t)});lt.ok?(console.log("Chat history stored successfully"),le()):console.error("Failed to store chat history:",lt.statusText)}catch(Se){console.error("Error storing chat history:",Se)}}async function ve(R){const{message:W,isHistory:se}=R;if(console.log(R),console.log(W),!se&&(W.role==="ai"||W.role==="assistant")&&(console.log("🤖 AI answered:",W.text||W.content),P&&G)){console.log("📚 Updating AI message with references");const ue=(W.text||W.content||"")+P;console.log(G.getMessages()),console.log(G.getMessages().length-1),G.updateMessage({text:ue},G.getMessages().length-1),P=""}}const ge=async R=>{if(R.body&&R.body.messages){R.body.messages=rc(R.body.messages);const W=R.body.messages.filter(se=>se.role==="user");W.length>0&&(w=W[W.length-1].content),C&&(R.body.chat_id=C)}return R},xn=R=>{console.log(R),R.sources&&Array.isArray(R.sources)&&(U=R.sources,console.log(`Found ${U.length} sources in response`),console.log("assistantMessageSources:",U));try{const W=Qu(R);W.length>0&&(P=ec(W),console.log(`Found ${W.length} references in response`))}catch(W){console.error("Error extracting references:",W)}if(R.choices&&R.choices[0]&&R.choices[0].delta){const W=R.choices[0].delta,se=W.content||"";return se&&(A+=se),R.choices[0].finish_reason&&(console.log("Streaming response ended"),w&&A&&re(w,A,U),A="",w=""),{text:se,role:W.role==="assistant"?"ai":W.role||"ai"}}if(R.choices&&R.choices[0]&&R.choices[0].message){const W=R.choices[0].message;return console.log("Non-streaming response received"),w&&W.content&&(re(w,W.content),w=""),{text:W.content,role:W.role==="assistant"?"ai":W.role}}return R.text||R.html||R.files?R:typeof R=="string"?{text:R}:R},Wt=R=>R.key==="Enter"&&Y();function Je(R){Pn[R?"unshift":"push"](()=>{G=R,t(1,G)})}return r.$$set=R=>{"apiUrl"in R&&t(14,i=R.apiUrl),"apiKey"in R&&t(15,o=R.apiKey),"modelId"in R&&t(16,l=R.modelId),"maxMessages"in R&&t(17,u=R.maxMessages),"placeholderText"in R&&t(18,c=R.placeholderText),"faviconPath"in R&&t(19,d=R.faviconPath),"initialMessage"in R&&t(20,p=R.initialMessage),"userMessageBackgroundColor"in R&&t(21,h=R.userMessageBackgroundColor),"aiMessageBackgroundColor"in R&&t(22,v=R.aiMessageBackgroundColor),"userMessageTextColor"in R&&t(23,f=R.userMessageTextColor),"aiMessageTextColor"in R&&t(24,g=R.aiMessageTextColor),"faviconBackgroundColor"in R&&t(25,y=R.faviconBackgroundColor)},r.$$.update=()=>{r.$$.dirty[0]&67223552&&t(4,e={type:"websocket",url:`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/chat/completions`,headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},additionalBodyProps:{model:l||"test-model",stream:!0,params:{},tool_servers:[],features:{image_generation:!1,code_interpreter:!1,web_search:!1,memory:!1},variables:{"{{USER_NAME}}":"David Schneebauer | headwAI GmbH","{{USER_LOCATION}}":"Unknown","{{CURRENT_DATETIME}}":new Date().toISOString().slice(0,19).replace("T"," "),"{{CURRENT_DATE}}":new Date().toISOString().slice(0,10),"{{CURRENT_TIME}}":new Date().toTimeString().slice(0,8),"{{CURRENT_WEEKDAY}}":new Date().toLocaleDateString("en-US",{weekday:"long"}),"{{CURRENT_TIMEZONE}}":Intl.DateTimeFormat().resolvedOptions().timeZone,"{{USER_LANGUAGE}}":"en-GB"},...C&&{chat_id:C},background_tasks:{title_generation:!0,tags_generation:!1,follow_up_generation:!1}},stream:!0}),r.$$.dirty[0]&31457280&&t(3,n={default:{user:{bubble:{backgroundColor:h||"green",color:f||"white"}},ai:{bubble:{backgroundColor:v||"gray",color:g||"black"}}}}),r.$$.dirty[0]&33554432&&t(2,a=(()=>{const R=y||"lightgreen",W=nc(R,-20);return`linear-gradient(135deg, ${R} 0%, ${W} 100%)`})())},[_,G,a,n,e,x,E,F,M,K,Y,ve,ge,xn,i,o,l,u,c,d,p,h,v,f,g,y,C,Wt,Je]}class Ds extends ti{constructor(s){super(),ei(this,s,ac,tc,Us,{apiUrl:14,apiKey:15,modelId:16,maxMessages:17,placeholderText:18,faviconPath:19,initialMessage:20,userMessageBackgroundColor:21,aiMessageBackgroundColor:22,userMessageTextColor:23,aiMessageTextColor:24,faviconBackgroundColor:25},null,[-1,-1])}}function Ir(r,s={}){return new Ds({target:r,props:s})}typeof window<"u"&&window.document&&document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-chat-bubble]").forEach(s=>{const t=window.DEEP_CHAT_CONFIG||{};Object.keys(s.dataset).forEach(e=>{if(e.startsWith("chatBubble")){const n=e.replace("chatBubble","").toLowerCase();t[n]=s.dataset[e]}}),Ir(s,t)})});const sc={ChatBubble,createChatBubble:Ir};return ye.ChatBubble=Ds,ye.createChatBubble=Ir,ye.default=sc,Object.defineProperties(ye,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),ye}({});
281
+ </svg>`,styles:{default:{width:"14px",height:"14px",color:"#666"},hover:{color:"white"}}}}}},position:"outside-right",tooltip:{text:"Minimize chat",timeout:300,style:{backgroundColor:"#333",color:"white",fontSize:"12px",padding:"4px 8px",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}},onClick:()=>(Y(),"default")}],M={maxMessages:parseInt(u||void 0)||0},K={placeholder:{text:c||void 0||"Enter your questions here"}};function Y(){_?(t(26,C=null),I=[]):$([{role:"assistant",content:T}]),t(0,_=!_)}function le(){if(console.log("=== Message History ==="),I.length===0){console.log("No messages in history");return}I.forEach((R,W)=>{const se=R.content.length>50?R.content.substring(0,50)+"...":R.content;console.log(`${W+1}. ${R.role.toUpperCase()}: ${se}`)}),console.log("=====================")}async function $(R){var W;try{const se=Math.floor(Date.now()/1e3),Se=[l||void 0||"deepseek-r1-distill-qwen-7b"],ue=[],at={};let st=null;R.forEach((Ne,ot)=>{const lt=Mn(),Jt=ot<R.length-1?Mn():null,Xt={id:lt,parentId:st,childrenIds:Jt?[Jt]:[],role:Ne.role,content:Ne.content,timestamp:se,models:Se};Ne.role==="assistant"&&(Xt.model=Se[0],Xt.modelId=Se[0],Xt.modelIdx=0),ue.push(Xt),at[lt]=Xt,st=lt}),ue.forEach((Ne,ot)=>{ot<ue.length-1&&(Ne.childrenIds=[ue[ot+1].id])});const it=(W=ue[ue.length-1])==null?void 0:W.id,Rr={chat:{id:"",title:"New Chatbubble Chat",models:Se,params:{},history:{messages:at,currentId:it},messages:ue,tags:[],timestamp:Date.now()},folder_id:null},In=`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/v1/chats/new`,$t=await fetch(In,{method:"POST",headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},body:JSON.stringify(Rr)});if($t.ok){const Ne=await $t.json();return t(26,C=Ne.id),console.log("New chat created with ID:",C),I=ue,le(),C}else return console.error("Failed to create new chat:",$t.statusText),null}catch(se){return console.error("Error creating new chat:",se),null}}async function re(R,W,se){if(!C){console.error("Cannot store chat history: no chat ID available");return}console.log("assistantMessageSources:",se);try{const Se=Math.floor(Date.now()/1e3),ue=[l||void 0||"deepseek-r1-distill-qwen-7b"],at=Mn(),st=Mn(),it=I[I.length-1],Rr={id:at,parentId:it?it.id:null,childrenIds:[st],role:"user",content:R,timestamp:Se,models:ue},Fs={id:st,parentId:at,childrenIds:[],role:"assistant",content:W,model:ue[0],modelId:ue[0],modelIdx:0,timestamp:Se,sources:se};it&&(it.childrenIds=[at]),I.push(Rr,Fs);const In={};I.forEach(Jt=>{In[Jt.id]=Jt});const $t={chat:{models:ue,history:{messages:In,currentId:st},messages:I,params:{}}},ot=`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/v1/chats/${C}`,lt=await fetch(ot,{method:"POST",headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},body:JSON.stringify($t)});lt.ok?(console.log("Chat history stored successfully"),le()):console.error("Failed to store chat history:",lt.statusText)}catch(Se){console.error("Error storing chat history:",Se)}}async function ve(R){const{message:W,isHistory:se}=R;if(console.log(R),console.log(W),!se&&(W.role==="ai"||W.role==="assistant")&&(console.log("🤖 AI answered:",W.text||W.content),P&&G)){console.log("📚 Updating AI message with references");const ue=(W.text||W.content||"")+P;console.log(G.getMessages()),console.log(G.getMessages().length-1),G.updateMessage({text:ue},G.getMessages().length-1),P=""}}const ge=async R=>{if(R.body&&R.body.messages){R.body.messages=rc(R.body.messages);const W=R.body.messages.filter(se=>se.role==="user");W.length>0&&(w=W[W.length-1].content),C&&(R.body.chat_id=C)}return R},xn=R=>{console.log(R),R.sources&&Array.isArray(R.sources)&&(U=R.sources,console.log(`Found ${U.length} sources in response`),console.log("assistantMessageSources:",U));try{const W=Qu(R);W.length>0&&(P=ec(W),console.log(`Found ${W.length} references in response`))}catch(W){console.error("Error extracting references:",W)}if(R.choices&&R.choices[0]&&R.choices[0].delta){const W=R.choices[0].delta,se=W.content||"";return se&&(A+=se),R.choices[0].finish_reason&&(console.log("Streaming response ended"),w&&A&&re(w,A,U),A="",w=""),{text:se,role:W.role==="assistant"?"ai":W.role||"ai"}}if(R.choices&&R.choices[0]&&R.choices[0].message){const W=R.choices[0].message;return console.log("Non-streaming response received"),w&&W.content&&(re(w,W.content),w=""),{text:W.content,role:W.role==="assistant"?"ai":W.role}}return R.text||R.html||R.files?R:typeof R=="string"?{text:R}:R},Wt=R=>R.key==="Enter"&&Y();function Je(R){Pn[R?"unshift":"push"](()=>{G=R,t(1,G)})}return r.$$set=R=>{"apiUrl"in R&&t(14,i=R.apiUrl),"apiKey"in R&&t(15,o=R.apiKey),"modelId"in R&&t(16,l=R.modelId),"maxMessages"in R&&t(17,u=R.maxMessages),"placeholderText"in R&&t(18,c=R.placeholderText),"faviconPath"in R&&t(19,d=R.faviconPath),"initialMessage"in R&&t(20,p=R.initialMessage),"userMessageBackgroundColor"in R&&t(21,h=R.userMessageBackgroundColor),"aiMessageBackgroundColor"in R&&t(22,v=R.aiMessageBackgroundColor),"userMessageTextColor"in R&&t(23,f=R.userMessageTextColor),"aiMessageTextColor"in R&&t(24,g=R.aiMessageTextColor),"faviconBackgroundColor"in R&&t(25,y=R.faviconBackgroundColor)},r.$$.update=()=>{r.$$.dirty[0]&67223552&&t(4,e={type:"websocket",url:`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/chat/completions`,headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},additionalBodyProps:{model:l||void 0||"enterprise-search",stream:!0,params:{},tool_servers:[],features:{image_generation:!1,code_interpreter:!1,web_search:!1,memory:!1},variables:{"{{USER_NAME}}":"David Schneebauer | headwAI GmbH","{{USER_LOCATION}}":"Unknown","{{CURRENT_DATETIME}}":new Date().toISOString().slice(0,19).replace("T"," "),"{{CURRENT_DATE}}":new Date().toISOString().slice(0,10),"{{CURRENT_TIME}}":new Date().toTimeString().slice(0,8),"{{CURRENT_WEEKDAY}}":new Date().toLocaleDateString("en-US",{weekday:"long"}),"{{CURRENT_TIMEZONE}}":Intl.DateTimeFormat().resolvedOptions().timeZone,"{{USER_LANGUAGE}}":"en-GB"},...C&&{chat_id:C},background_tasks:{title_generation:!0,tags_generation:!1,follow_up_generation:!1}},stream:!0}),r.$$.dirty[0]&31457280&&t(3,n={default:{user:{bubble:{backgroundColor:h||void 0||"#007bff",color:f||void 0||"#000000"}},ai:{bubble:{backgroundColor:v||void 0||"#f1f3f4",color:g||void 0||"#000000"}}}}),r.$$.dirty[0]&33554432&&t(2,a=(()=>{const R=y||void 0||"#667eea",W=nc(R,-20);return`linear-gradient(135deg, ${R} 0%, ${W} 100%)`})())},[_,G,a,n,e,x,E,F,M,K,Y,ve,ge,xn,i,o,l,u,c,d,p,h,v,f,g,y,C,Wt,Je]}class Ds extends ti{constructor(s){super(),ei(this,s,ac,tc,Us,{apiUrl:14,apiKey:15,modelId:16,maxMessages:17,placeholderText:18,faviconPath:19,initialMessage:20,userMessageBackgroundColor:21,aiMessageBackgroundColor:22,userMessageTextColor:23,aiMessageTextColor:24,faviconBackgroundColor:25},null,[-1,-1])}}function Ir(r,s={}){return new Ds({target:r,props:s})}typeof window<"u"&&window.document&&document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-chat-bubble]").forEach(s=>{const t=window.DEEP_CHAT_CONFIG||{};Object.keys(s.dataset).forEach(e=>{if(e.startsWith("chatBubble")){const n=e.replace("chatBubble","").toLowerCase();t[n]=s.dataset[e]}}),Ir(s,t)})});const sc={ChatBubble,createChatBubble:Ir};return ye.ChatBubble=Ds,ye.createChatBubble=Ir,ye.default=sc,Object.defineProperties(ye,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),ye}({});
package/dist/index.js CHANGED
@@ -15835,7 +15835,7 @@ function rc(r) {
15835
15835
  }
15836
15836
  function ac(r, s, t) {
15837
15837
  let e, n, a, { apiUrl: i = void 0 } = s, { apiKey: o = void 0 } = s, { modelId: l = void 0 } = s, { maxMessages: u = void 0 } = s, { placeholderText: c = void 0 } = s, { faviconPath: d = void 0 } = s, { initialMessage: p = void 0 } = s, { userMessageBackgroundColor: h = void 0 } = s, { aiMessageBackgroundColor: v = void 0 } = s, { userMessageTextColor: f = void 0 } = s, { aiMessageTextColor: g = void 0 } = s, { faviconBackgroundColor: y = void 0 } = s, _ = !1, C = null, I = [], w = "", A = "", U = [], P = "", G;
15838
- const x = d || void 0 || Zu, T = p || "Hey, how can I assist you?", E = [{ role: "ai", text: T }], B = [
15838
+ const x = d || void 0 || Zu, T = p || void 0 || "Hey, how can I help you?", E = [{ role: "ai", text: T }], B = [
15839
15839
  {
15840
15840
  styles: {
15841
15841
  button: {
@@ -15892,11 +15892,11 @@ function ac(r, s, t) {
15892
15892
  onClick: () => (Y(), "default")
15893
15893
  }
15894
15894
  ], M = {
15895
- maxMessages: parseInt(u || "0") || 0
15895
+ maxMessages: parseInt(u || void 0) || 0
15896
15896
  // 0 means include all messages in the conversation
15897
15897
  }, K = {
15898
15898
  placeholder: {
15899
- text: c || "Welcome to the demo!"
15899
+ text: c || void 0 || "Enter your questions here"
15900
15900
  }
15901
15901
  };
15902
15902
  function Y() {
@@ -15921,7 +15921,7 @@ function ac(r, s, t) {
15921
15921
  var W;
15922
15922
  try {
15923
15923
  const se = Math.floor(Date.now() / 1e3), ge = [
15924
- l || "test-model"
15924
+ l || void 0 || "deepseek-r1-distill-qwen-7b"
15925
15925
  ], oe = [], We = {};
15926
15926
  let $e = null;
15927
15927
  R.forEach((Me, Xe) => {
@@ -15953,10 +15953,10 @@ function ac(r, s, t) {
15953
15953
  timestamp: Date.now()
15954
15954
  },
15955
15955
  folder_id: null
15956
- }, Xt = `${(i || "https://localchat.headwai.org/").replace(/\/$/, "")}/api/v1/chats/new`, ot = await fetch(Xt, {
15956
+ }, Xt = `${(i || void 0 || "https://localhost").replace(/\/$/, "")}/api/v1/chats/new`, ot = await fetch(Xt, {
15957
15957
  method: "POST",
15958
15958
  headers: {
15959
- Authorization: `Bearer ${o || "sk-47ec23c1fd214846ada1e9c812596eef"}`,
15959
+ Authorization: `Bearer ${o || void 0 || ""}`,
15960
15960
  "Content-Type": "application/json"
15961
15961
  },
15962
15962
  body: JSON.stringify(xn)
@@ -15978,7 +15978,7 @@ function ac(r, s, t) {
15978
15978
  console.log("assistantMessageSources:", se);
15979
15979
  try {
15980
15980
  const ge = Math.floor(Date.now() / 1e3), oe = [
15981
- l || "test-model"
15981
+ l || void 0 || "deepseek-r1-distill-qwen-7b"
15982
15982
  ], We = rn(), $e = rn(), Je = I[I.length - 1], xn = {
15983
15983
  id: We,
15984
15984
  parentId: Je ? Je.id : null,
@@ -16015,10 +16015,10 @@ function ac(r, s, t) {
16015
16015
  messages: I,
16016
16016
  params: {}
16017
16017
  }
16018
- }, Xe = `${(i || "https://localchat.headwai.org/").replace(/\/$/, "")}/api/v1/chats/${C}`, Ye = await fetch(Xe, {
16018
+ }, Xe = `${(i || void 0 || "https://localhost").replace(/\/$/, "")}/api/v1/chats/${C}`, Ye = await fetch(Xe, {
16019
16019
  method: "POST",
16020
16020
  headers: {
16021
- Authorization: `Bearer ${o || "sk-47ec23c1fd214846ada1e9c812596eef"}`,
16021
+ Authorization: `Bearer ${o || void 0 || ""}`,
16022
16022
  "Content-Type": "application/json"
16023
16023
  },
16024
16024
  body: JSON.stringify(ot)
@@ -16078,13 +16078,13 @@ function ac(r, s, t) {
16078
16078
  r.$$.dirty[0] & /*apiUrl, apiKey, modelId, chatId*/
16079
16079
  67223552 && t(4, e = {
16080
16080
  type: "websocket",
16081
- url: `${(i || "https://localchat.headwai.org/").replace(/\/$/, "")}/api/chat/completions`,
16081
+ url: `${(i || void 0 || "https://localhost").replace(/\/$/, "")}/api/chat/completions`,
16082
16082
  headers: {
16083
- Authorization: `Bearer ${o || "sk-47ec23c1fd214846ada1e9c812596eef"}`,
16083
+ Authorization: `Bearer ${o || void 0 || ""}`,
16084
16084
  "Content-Type": "application/json"
16085
16085
  },
16086
16086
  additionalBodyProps: {
16087
- model: l || "test-model",
16087
+ model: l || void 0 || "enterprise-search",
16088
16088
  stream: !0,
16089
16089
  // Ensure the API endpoint knows we want streaming
16090
16090
  params: {},
@@ -16175,20 +16175,20 @@ function ac(r, s, t) {
16175
16175
  default: {
16176
16176
  user: {
16177
16177
  bubble: {
16178
- backgroundColor: h || "green",
16179
- color: f || "white"
16178
+ backgroundColor: h || void 0 || "#007bff",
16179
+ color: f || void 0 || "#000000"
16180
16180
  }
16181
16181
  },
16182
16182
  ai: {
16183
16183
  bubble: {
16184
- backgroundColor: v || "gray",
16185
- color: g || "black"
16184
+ backgroundColor: v || void 0 || "#f1f3f4",
16185
+ color: g || void 0 || "#000000"
16186
16186
  }
16187
16187
  }
16188
16188
  }
16189
16189
  }), r.$$.dirty[0] & /*faviconBackgroundColor*/
16190
16190
  33554432 && t(2, a = (() => {
16191
- const R = y || "lightgreen", W = nc(R, -20);
16191
+ const R = y || void 0 || "#667eea", W = nc(R, -20);
16192
16192
  return `linear-gradient(135deg, ${R} 0%, ${W} 100%)`;
16193
16193
  })());
16194
16194
  }, [
@@ -276,6 +276,6 @@ new Remarkable().use(linkify)
276
276
 
277
277
  ${r.map((t,e)=>{const n=t.name||"Untitled Reference";let a=`**[${e+1}]** `;return a+=n,a}).join(`
278
278
 
279
- `)}`}function Ns(r){let s,t,e,n,a;return{c(){s=ct("div"),t=ct("img"),js(t.src,e=r[5])||Ee(t,"src",e),Ee(t,"alt","AI Assistant"),Ee(t,"class","svelte-bjand4"),Ee(s,"class","ai-assistant-icon svelte-bjand4"),Br(s,"background",r[2]),Ee(s,"role","button"),Ee(s,"tabindex","0")},m(i,o){Ln(i,s,o),Rn(s,t),n||(a=[Nr(s,"click",r[10]),Nr(s,"keydown",r[27])],n=!0)},p(i,o){o[0]&4&&Br(s,"background",i[2])},d(i){i&&Zt(s),n=!1,ut(a)}}}function Bs(r){let s,t;return{c(){s=ct("div"),t=ct("deep-chat"),ve(t,"demo","false"),ve(t,"textInput",r[9]),ve(t,"messageStyles",r[3]),ve(t,"history",r[6]),ve(t,"connect",r[4]),ve(t,"requestBodyLimits",r[8]),ve(t,"requestInterceptor",r[12]),ve(t,"responseInterceptor",r[13]),ve(t,"customButtons",r[7]),ve(t,"onMessage",r[11]),Ee(s,"class","chat-container svelte-bjand4")},m(e,n){Ln(e,s,n),Rn(s,t),r[28](t)},p(e,n){n[0]&8&&ve(t,"messageStyles",e[3]),n[0]&16&&ve(t,"connect",e[4])},d(e){e&&Zt(s),r[28](null)}}}function tc(r){let s,t,e=!r[0]&&Ns(r),n=r[0]&&Bs(r);return{c(){s=ct("main"),e&&e.c(),t=Vs(),n&&n.c(),Ee(s,"class","svelte-bjand4")},m(a,i){Ln(a,s,i),e&&e.m(s,null),Rn(s,t),n&&n.m(s,null)},p(a,i){a[0]?e&&(e.d(1),e=null):e?e.p(a,i):(e=Ns(a),e.c(),e.m(s,t)),a[0]?n?n.p(a,i):(n=Bs(a),n.c(),n.m(s,null)):n&&(n.d(1),n=null)},i:ae,o:ae,d(a){a&&Zt(s),e&&e.d(),n&&n.d()}}}function nc(r,s){r=r.replace("#","");const t=parseInt(r,16),e=(t>>16)+s,n=(t>>8&255)+s,a=(t&255)+s,i=Math.max(0,Math.min(255,e)),o=Math.max(0,Math.min(255,n)),l=Math.max(0,Math.min(255,a));return`#${(i<<16|o<<8|l).toString(16).padStart(6,"0")}`}function rc(r){return r.map(s=>{let t=s.text||s.content;return(s.role==="ai"||s.role==="assistant")&&(t=t.replace(/\n\n---\n\n\*\*References:\*\*[\s\S]*$/,"")),{role:s.role==="ai"?"assistant":s.role,content:t}})}function ac(r,s,t){let e,n,a,{apiUrl:i=void 0}=s,{apiKey:o=void 0}=s,{modelId:l=void 0}=s,{maxMessages:u=void 0}=s,{placeholderText:c=void 0}=s,{faviconPath:d=void 0}=s,{initialMessage:p=void 0}=s,{userMessageBackgroundColor:h=void 0}=s,{aiMessageBackgroundColor:v=void 0}=s,{userMessageTextColor:f=void 0}=s,{aiMessageTextColor:g=void 0}=s,{faviconBackgroundColor:y=void 0}=s,_=!1,C=null,I=[],w="",A="",U=[],P="",G;const x=d||void 0||Zu,T=p||"Hey, how can I assist you?",E=[{role:"ai",text:T}],F=[{styles:{button:{default:{container:{default:{backgroundColor:"transparent",borderRadius:"4px",width:"24px",height:"24px",border:"1px solid #e0e0e0",cursor:"pointer",transition:"all 0.2s ease"},hover:{backgroundColor:"#2196F3",borderColor:"#2196F3",transform:"scale(1.05)"},click:{backgroundColor:"#1976D2",borderColor:"#1976D2"}},svg:{content:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
279
+ `)}`}function Ns(r){let s,t,e,n,a;return{c(){s=ct("div"),t=ct("img"),js(t.src,e=r[5])||Ee(t,"src",e),Ee(t,"alt","AI Assistant"),Ee(t,"class","svelte-bjand4"),Ee(s,"class","ai-assistant-icon svelte-bjand4"),Br(s,"background",r[2]),Ee(s,"role","button"),Ee(s,"tabindex","0")},m(i,o){Ln(i,s,o),Rn(s,t),n||(a=[Nr(s,"click",r[10]),Nr(s,"keydown",r[27])],n=!0)},p(i,o){o[0]&4&&Br(s,"background",i[2])},d(i){i&&Zt(s),n=!1,ut(a)}}}function Bs(r){let s,t;return{c(){s=ct("div"),t=ct("deep-chat"),ve(t,"demo","false"),ve(t,"textInput",r[9]),ve(t,"messageStyles",r[3]),ve(t,"history",r[6]),ve(t,"connect",r[4]),ve(t,"requestBodyLimits",r[8]),ve(t,"requestInterceptor",r[12]),ve(t,"responseInterceptor",r[13]),ve(t,"customButtons",r[7]),ve(t,"onMessage",r[11]),Ee(s,"class","chat-container svelte-bjand4")},m(e,n){Ln(e,s,n),Rn(s,t),r[28](t)},p(e,n){n[0]&8&&ve(t,"messageStyles",e[3]),n[0]&16&&ve(t,"connect",e[4])},d(e){e&&Zt(s),r[28](null)}}}function tc(r){let s,t,e=!r[0]&&Ns(r),n=r[0]&&Bs(r);return{c(){s=ct("main"),e&&e.c(),t=Vs(),n&&n.c(),Ee(s,"class","svelte-bjand4")},m(a,i){Ln(a,s,i),e&&e.m(s,null),Rn(s,t),n&&n.m(s,null)},p(a,i){a[0]?e&&(e.d(1),e=null):e?e.p(a,i):(e=Ns(a),e.c(),e.m(s,t)),a[0]?n?n.p(a,i):(n=Bs(a),n.c(),n.m(s,null)):n&&(n.d(1),n=null)},i:ae,o:ae,d(a){a&&Zt(s),e&&e.d(),n&&n.d()}}}function nc(r,s){r=r.replace("#","");const t=parseInt(r,16),e=(t>>16)+s,n=(t>>8&255)+s,a=(t&255)+s,i=Math.max(0,Math.min(255,e)),o=Math.max(0,Math.min(255,n)),l=Math.max(0,Math.min(255,a));return`#${(i<<16|o<<8|l).toString(16).padStart(6,"0")}`}function rc(r){return r.map(s=>{let t=s.text||s.content;return(s.role==="ai"||s.role==="assistant")&&(t=t.replace(/\n\n---\n\n\*\*References:\*\*[\s\S]*$/,"")),{role:s.role==="ai"?"assistant":s.role,content:t}})}function ac(r,s,t){let e,n,a,{apiUrl:i=void 0}=s,{apiKey:o=void 0}=s,{modelId:l=void 0}=s,{maxMessages:u=void 0}=s,{placeholderText:c=void 0}=s,{faviconPath:d=void 0}=s,{initialMessage:p=void 0}=s,{userMessageBackgroundColor:h=void 0}=s,{aiMessageBackgroundColor:v=void 0}=s,{userMessageTextColor:f=void 0}=s,{aiMessageTextColor:g=void 0}=s,{faviconBackgroundColor:y=void 0}=s,_=!1,C=null,I=[],w="",A="",U=[],P="",G;const x=d||void 0||Zu,T=p||void 0||"Hey, how can I help you?",E=[{role:"ai",text:T}],F=[{styles:{button:{default:{container:{default:{backgroundColor:"transparent",borderRadius:"4px",width:"24px",height:"24px",border:"1px solid #e0e0e0",cursor:"pointer",transition:"all 0.2s ease"},hover:{backgroundColor:"#2196F3",borderColor:"#2196F3",transform:"scale(1.05)"},click:{backgroundColor:"#1976D2",borderColor:"#1976D2"}},svg:{content:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
280
280
  <path d="M19 14L12 21L5 14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
281
- </svg>`,styles:{default:{width:"14px",height:"14px",color:"#666"},hover:{color:"white"}}}}}},position:"outside-right",tooltip:{text:"Minimize chat",timeout:300,style:{backgroundColor:"#333",color:"white",fontSize:"12px",padding:"4px 8px",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}},onClick:()=>(Y(),"default")}],M={maxMessages:parseInt(u||"0")||0},K={placeholder:{text:c||"Welcome to the demo!"}};function Y(){_?(t(26,C=null),I=[]):$([{role:"assistant",content:T}]),t(0,_=!_)}function ue(){if(console.log("=== Message History ==="),I.length===0){console.log("No messages in history");return}I.forEach((R,W)=>{const ie=R.content.length>50?R.content.substring(0,50)+"...":R.content;console.log(`${W+1}. ${R.role.toUpperCase()}: ${ie}`)}),console.log("=====================")}async function $(R){var W;try{const ie=Math.floor(Date.now()/1e3),Se=[l||"test-model"],ce=[],at={};let st=null;R.forEach((Ne,ot)=>{const lt=Mn(),Jt=ot<R.length-1?Mn():null,Xt={id:lt,parentId:st,childrenIds:Jt?[Jt]:[],role:Ne.role,content:Ne.content,timestamp:ie,models:Se};Ne.role==="assistant"&&(Xt.model=Se[0],Xt.modelId=Se[0],Xt.modelIdx=0),ce.push(Xt),at[lt]=Xt,st=lt}),ce.forEach((Ne,ot)=>{ot<ce.length-1&&(Ne.childrenIds=[ce[ot+1].id])});const it=(W=ce[ce.length-1])==null?void 0:W.id,Rr={chat:{id:"",title:"New Chatbubble Chat",models:Se,params:{},history:{messages:at,currentId:it},messages:ce,tags:[],timestamp:Date.now()},folder_id:null},In=`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/v1/chats/new`,$t=await fetch(In,{method:"POST",headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},body:JSON.stringify(Rr)});if($t.ok){const Ne=await $t.json();return t(26,C=Ne.id),console.log("New chat created with ID:",C),I=ce,ue(),C}else return console.error("Failed to create new chat:",$t.statusText),null}catch(ie){return console.error("Error creating new chat:",ie),null}}async function re(R,W,ie){if(!C){console.error("Cannot store chat history: no chat ID available");return}console.log("assistantMessageSources:",ie);try{const Se=Math.floor(Date.now()/1e3),ce=[l||"test-model"],at=Mn(),st=Mn(),it=I[I.length-1],Rr={id:at,parentId:it?it.id:null,childrenIds:[st],role:"user",content:R,timestamp:Se,models:ce},Fs={id:st,parentId:at,childrenIds:[],role:"assistant",content:W,model:ce[0],modelId:ce[0],modelIdx:0,timestamp:Se,sources:ie};it&&(it.childrenIds=[at]),I.push(Rr,Fs);const In={};I.forEach(Jt=>{In[Jt.id]=Jt});const $t={chat:{models:ce,history:{messages:In,currentId:st},messages:I,params:{}}},ot=`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/v1/chats/${C}`,lt=await fetch(ot,{method:"POST",headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},body:JSON.stringify($t)});lt.ok?(console.log("Chat history stored successfully"),ue()):console.error("Failed to store chat history:",lt.statusText)}catch(Se){console.error("Error storing chat history:",Se)}}async function ge(R){const{message:W,isHistory:ie}=R;if(console.log(R),console.log(W),!ie&&(W.role==="ai"||W.role==="assistant")&&(console.log("🤖 AI answered:",W.text||W.content),P&&G)){console.log("📚 Updating AI message with references");const ce=(W.text||W.content||"")+P;console.log(G.getMessages()),console.log(G.getMessages().length-1),G.updateMessage({text:ce},G.getMessages().length-1),P=""}}const ye=async R=>{if(R.body&&R.body.messages){R.body.messages=rc(R.body.messages);const W=R.body.messages.filter(ie=>ie.role==="user");W.length>0&&(w=W[W.length-1].content),C&&(R.body.chat_id=C)}return R},xn=R=>{console.log(R),R.sources&&Array.isArray(R.sources)&&(U=R.sources,console.log(`Found ${U.length} sources in response`),console.log("assistantMessageSources:",U));try{const W=Qu(R);W.length>0&&(P=ec(W),console.log(`Found ${W.length} references in response`))}catch(W){console.error("Error extracting references:",W)}if(R.choices&&R.choices[0]&&R.choices[0].delta){const W=R.choices[0].delta,ie=W.content||"";return ie&&(A+=ie),R.choices[0].finish_reason&&(console.log("Streaming response ended"),w&&A&&re(w,A,U),A="",w=""),{text:ie,role:W.role==="assistant"?"ai":W.role||"ai"}}if(R.choices&&R.choices[0]&&R.choices[0].message){const W=R.choices[0].message;return console.log("Non-streaming response received"),w&&W.content&&(re(w,W.content),w=""),{text:W.content,role:W.role==="assistant"?"ai":W.role}}return R.text||R.html||R.files?R:typeof R=="string"?{text:R}:R},Wt=R=>R.key==="Enter"&&Y();function Je(R){Pn[R?"unshift":"push"](()=>{G=R,t(1,G)})}return r.$$set=R=>{"apiUrl"in R&&t(14,i=R.apiUrl),"apiKey"in R&&t(15,o=R.apiKey),"modelId"in R&&t(16,l=R.modelId),"maxMessages"in R&&t(17,u=R.maxMessages),"placeholderText"in R&&t(18,c=R.placeholderText),"faviconPath"in R&&t(19,d=R.faviconPath),"initialMessage"in R&&t(20,p=R.initialMessage),"userMessageBackgroundColor"in R&&t(21,h=R.userMessageBackgroundColor),"aiMessageBackgroundColor"in R&&t(22,v=R.aiMessageBackgroundColor),"userMessageTextColor"in R&&t(23,f=R.userMessageTextColor),"aiMessageTextColor"in R&&t(24,g=R.aiMessageTextColor),"faviconBackgroundColor"in R&&t(25,y=R.faviconBackgroundColor)},r.$$.update=()=>{r.$$.dirty[0]&67223552&&t(4,e={type:"websocket",url:`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/chat/completions`,headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},additionalBodyProps:{model:l||"test-model",stream:!0,params:{},tool_servers:[],features:{image_generation:!1,code_interpreter:!1,web_search:!1,memory:!1},variables:{"{{USER_NAME}}":"David Schneebauer | headwAI GmbH","{{USER_LOCATION}}":"Unknown","{{CURRENT_DATETIME}}":new Date().toISOString().slice(0,19).replace("T"," "),"{{CURRENT_DATE}}":new Date().toISOString().slice(0,10),"{{CURRENT_TIME}}":new Date().toTimeString().slice(0,8),"{{CURRENT_WEEKDAY}}":new Date().toLocaleDateString("en-US",{weekday:"long"}),"{{CURRENT_TIMEZONE}}":Intl.DateTimeFormat().resolvedOptions().timeZone,"{{USER_LANGUAGE}}":"en-GB"},...C&&{chat_id:C},background_tasks:{title_generation:!0,tags_generation:!1,follow_up_generation:!1}},stream:!0}),r.$$.dirty[0]&31457280&&t(3,n={default:{user:{bubble:{backgroundColor:h||"green",color:f||"white"}},ai:{bubble:{backgroundColor:v||"gray",color:g||"black"}}}}),r.$$.dirty[0]&33554432&&t(2,a=(()=>{const R=y||"lightgreen",W=nc(R,-20);return`linear-gradient(135deg, ${R} 0%, ${W} 100%)`})())},[_,G,a,n,e,x,E,F,M,K,Y,ge,ye,xn,i,o,l,u,c,d,p,h,v,f,g,y,C,Wt,Je]}class Ds extends ti{constructor(s){super(),ei(this,s,ac,tc,Us,{apiUrl:14,apiKey:15,modelId:16,maxMessages:17,placeholderText:18,faviconPath:19,initialMessage:20,userMessageBackgroundColor:21,aiMessageBackgroundColor:22,userMessageTextColor:23,aiMessageTextColor:24,faviconBackgroundColor:25},null,[-1,-1])}}function Ir(r,s={}){return new Ds({target:r,props:s})}typeof window<"u"&&window.document&&document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-chat-bubble]").forEach(s=>{const t=window.DEEP_CHAT_CONFIG||{};Object.keys(s.dataset).forEach(e=>{if(e.startsWith("chatBubble")){const n=e.replace("chatBubble","").toLowerCase();t[n]=s.dataset[e]}}),Ir(s,t)})});const sc={ChatBubble,createChatBubble:Ir};de.ChatBubble=Ds,de.createChatBubble=Ir,de.default=sc,Object.defineProperties(de,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
281
+ </svg>`,styles:{default:{width:"14px",height:"14px",color:"#666"},hover:{color:"white"}}}}}},position:"outside-right",tooltip:{text:"Minimize chat",timeout:300,style:{backgroundColor:"#333",color:"white",fontSize:"12px",padding:"4px 8px",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}},onClick:()=>(Y(),"default")}],M={maxMessages:parseInt(u||void 0)||0},K={placeholder:{text:c||void 0||"Enter your questions here"}};function Y(){_?(t(26,C=null),I=[]):$([{role:"assistant",content:T}]),t(0,_=!_)}function ue(){if(console.log("=== Message History ==="),I.length===0){console.log("No messages in history");return}I.forEach((R,W)=>{const ie=R.content.length>50?R.content.substring(0,50)+"...":R.content;console.log(`${W+1}. ${R.role.toUpperCase()}: ${ie}`)}),console.log("=====================")}async function $(R){var W;try{const ie=Math.floor(Date.now()/1e3),Se=[l||void 0||"deepseek-r1-distill-qwen-7b"],ce=[],at={};let st=null;R.forEach((Ne,ot)=>{const lt=Mn(),Jt=ot<R.length-1?Mn():null,Xt={id:lt,parentId:st,childrenIds:Jt?[Jt]:[],role:Ne.role,content:Ne.content,timestamp:ie,models:Se};Ne.role==="assistant"&&(Xt.model=Se[0],Xt.modelId=Se[0],Xt.modelIdx=0),ce.push(Xt),at[lt]=Xt,st=lt}),ce.forEach((Ne,ot)=>{ot<ce.length-1&&(Ne.childrenIds=[ce[ot+1].id])});const it=(W=ce[ce.length-1])==null?void 0:W.id,Rr={chat:{id:"",title:"New Chatbubble Chat",models:Se,params:{},history:{messages:at,currentId:it},messages:ce,tags:[],timestamp:Date.now()},folder_id:null},In=`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/v1/chats/new`,$t=await fetch(In,{method:"POST",headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},body:JSON.stringify(Rr)});if($t.ok){const Ne=await $t.json();return t(26,C=Ne.id),console.log("New chat created with ID:",C),I=ce,ue(),C}else return console.error("Failed to create new chat:",$t.statusText),null}catch(ie){return console.error("Error creating new chat:",ie),null}}async function re(R,W,ie){if(!C){console.error("Cannot store chat history: no chat ID available");return}console.log("assistantMessageSources:",ie);try{const Se=Math.floor(Date.now()/1e3),ce=[l||void 0||"deepseek-r1-distill-qwen-7b"],at=Mn(),st=Mn(),it=I[I.length-1],Rr={id:at,parentId:it?it.id:null,childrenIds:[st],role:"user",content:R,timestamp:Se,models:ce},Fs={id:st,parentId:at,childrenIds:[],role:"assistant",content:W,model:ce[0],modelId:ce[0],modelIdx:0,timestamp:Se,sources:ie};it&&(it.childrenIds=[at]),I.push(Rr,Fs);const In={};I.forEach(Jt=>{In[Jt.id]=Jt});const $t={chat:{models:ce,history:{messages:In,currentId:st},messages:I,params:{}}},ot=`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/v1/chats/${C}`,lt=await fetch(ot,{method:"POST",headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},body:JSON.stringify($t)});lt.ok?(console.log("Chat history stored successfully"),ue()):console.error("Failed to store chat history:",lt.statusText)}catch(Se){console.error("Error storing chat history:",Se)}}async function ge(R){const{message:W,isHistory:ie}=R;if(console.log(R),console.log(W),!ie&&(W.role==="ai"||W.role==="assistant")&&(console.log("🤖 AI answered:",W.text||W.content),P&&G)){console.log("📚 Updating AI message with references");const ce=(W.text||W.content||"")+P;console.log(G.getMessages()),console.log(G.getMessages().length-1),G.updateMessage({text:ce},G.getMessages().length-1),P=""}}const ye=async R=>{if(R.body&&R.body.messages){R.body.messages=rc(R.body.messages);const W=R.body.messages.filter(ie=>ie.role==="user");W.length>0&&(w=W[W.length-1].content),C&&(R.body.chat_id=C)}return R},xn=R=>{console.log(R),R.sources&&Array.isArray(R.sources)&&(U=R.sources,console.log(`Found ${U.length} sources in response`),console.log("assistantMessageSources:",U));try{const W=Qu(R);W.length>0&&(P=ec(W),console.log(`Found ${W.length} references in response`))}catch(W){console.error("Error extracting references:",W)}if(R.choices&&R.choices[0]&&R.choices[0].delta){const W=R.choices[0].delta,ie=W.content||"";return ie&&(A+=ie),R.choices[0].finish_reason&&(console.log("Streaming response ended"),w&&A&&re(w,A,U),A="",w=""),{text:ie,role:W.role==="assistant"?"ai":W.role||"ai"}}if(R.choices&&R.choices[0]&&R.choices[0].message){const W=R.choices[0].message;return console.log("Non-streaming response received"),w&&W.content&&(re(w,W.content),w=""),{text:W.content,role:W.role==="assistant"?"ai":W.role}}return R.text||R.html||R.files?R:typeof R=="string"?{text:R}:R},Wt=R=>R.key==="Enter"&&Y();function Je(R){Pn[R?"unshift":"push"](()=>{G=R,t(1,G)})}return r.$$set=R=>{"apiUrl"in R&&t(14,i=R.apiUrl),"apiKey"in R&&t(15,o=R.apiKey),"modelId"in R&&t(16,l=R.modelId),"maxMessages"in R&&t(17,u=R.maxMessages),"placeholderText"in R&&t(18,c=R.placeholderText),"faviconPath"in R&&t(19,d=R.faviconPath),"initialMessage"in R&&t(20,p=R.initialMessage),"userMessageBackgroundColor"in R&&t(21,h=R.userMessageBackgroundColor),"aiMessageBackgroundColor"in R&&t(22,v=R.aiMessageBackgroundColor),"userMessageTextColor"in R&&t(23,f=R.userMessageTextColor),"aiMessageTextColor"in R&&t(24,g=R.aiMessageTextColor),"faviconBackgroundColor"in R&&t(25,y=R.faviconBackgroundColor)},r.$$.update=()=>{r.$$.dirty[0]&67223552&&t(4,e={type:"websocket",url:`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/chat/completions`,headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},additionalBodyProps:{model:l||void 0||"enterprise-search",stream:!0,params:{},tool_servers:[],features:{image_generation:!1,code_interpreter:!1,web_search:!1,memory:!1},variables:{"{{USER_NAME}}":"David Schneebauer | headwAI GmbH","{{USER_LOCATION}}":"Unknown","{{CURRENT_DATETIME}}":new Date().toISOString().slice(0,19).replace("T"," "),"{{CURRENT_DATE}}":new Date().toISOString().slice(0,10),"{{CURRENT_TIME}}":new Date().toTimeString().slice(0,8),"{{CURRENT_WEEKDAY}}":new Date().toLocaleDateString("en-US",{weekday:"long"}),"{{CURRENT_TIMEZONE}}":Intl.DateTimeFormat().resolvedOptions().timeZone,"{{USER_LANGUAGE}}":"en-GB"},...C&&{chat_id:C},background_tasks:{title_generation:!0,tags_generation:!1,follow_up_generation:!1}},stream:!0}),r.$$.dirty[0]&31457280&&t(3,n={default:{user:{bubble:{backgroundColor:h||void 0||"#007bff",color:f||void 0||"#000000"}},ai:{bubble:{backgroundColor:v||void 0||"#f1f3f4",color:g||void 0||"#000000"}}}}),r.$$.dirty[0]&33554432&&t(2,a=(()=>{const R=y||void 0||"#667eea",W=nc(R,-20);return`linear-gradient(135deg, ${R} 0%, ${W} 100%)`})())},[_,G,a,n,e,x,E,F,M,K,Y,ge,ye,xn,i,o,l,u,c,d,p,h,v,f,g,y,C,Wt,Je]}class Ds extends ti{constructor(s){super(),ei(this,s,ac,tc,Us,{apiUrl:14,apiKey:15,modelId:16,maxMessages:17,placeholderText:18,faviconPath:19,initialMessage:20,userMessageBackgroundColor:21,aiMessageBackgroundColor:22,userMessageTextColor:23,aiMessageTextColor:24,faviconBackgroundColor:25},null,[-1,-1])}}function Ir(r,s={}){return new Ds({target:r,props:s})}typeof window<"u"&&window.document&&document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("[data-chat-bubble]").forEach(s=>{const t=window.DEEP_CHAT_CONFIG||{};Object.keys(s.dataset).forEach(e=>{if(e.startsWith("chatBubble")){const n=e.replace("chatBubble","").toLowerCase();t[n]=s.dataset[e]}}),Ir(s,t)})});const sc={ChatBubble,createChatBubble:Ir};de.ChatBubble=Ds,de.createChatBubble=Ir,de.default=sc,Object.defineProperties(de,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -276,6 +276,6 @@ new Remarkable().use(linkify)
276
276
 
277
277
  ${r.map((t,e)=>{const n=t.name||"Untitled Reference";let a=`**[${e+1}]** `;return a+=n,a}).join(`
278
278
 
279
- `)}`}function Ba(r){let s,t,e,n,a;return{c(){s=Ut("div"),t=Ut("img"),Hs(t.src,e=r[5])||Ee(t,"src",e),Ee(t,"alt","AI Assistant"),Ee(t,"class","svelte-bjand4"),Ee(s,"class","ai-assistant-icon svelte-bjand4"),Pr(s,"background",r[2]),Ee(s,"role","button"),Ee(s,"tabindex","0")},m(i,o){hr(i,s,o),dr(s,t),n||(a=[Or(s,"click",r[10]),Or(s,"keydown",r[27])],n=!0)},p(i,o){o[0]&4&&Pr(s,"background",i[2])},d(i){i&&_n(s),n=!1,Kt(a)}}}function Da(r){let s,t;return{c(){s=Ut("div"),t=Ut("deep-chat"),ve(t,"demo","false"),ve(t,"textInput",r[9]),ve(t,"messageStyles",r[3]),ve(t,"history",r[6]),ve(t,"connect",r[4]),ve(t,"requestBodyLimits",r[8]),ve(t,"requestInterceptor",r[12]),ve(t,"responseInterceptor",r[13]),ve(t,"customButtons",r[7]),ve(t,"onMessage",r[11]),Ee(s,"class","chat-container svelte-bjand4")},m(e,n){hr(e,s,n),dr(s,t),r[28](t)},p(e,n){n[0]&8&&ve(t,"messageStyles",e[3]),n[0]&16&&ve(t,"connect",e[4])},d(e){e&&_n(s),r[28](null)}}}function nc(r){let s,t,e=!r[0]&&Ba(r),n=r[0]&&Da(r);return{c(){s=Ut("main"),e&&e.c(),t=zs(),n&&n.c(),Ee(s,"class","svelte-bjand4")},m(a,i){hr(a,s,i),e&&e.m(s,null),dr(s,t),n&&n.m(s,null)},p(a,i){a[0]?e&&(e.d(1),e=null):e?e.p(a,i):(e=Ba(a),e.c(),e.m(s,t)),a[0]?n?n.p(a,i):(n=Da(a),n.c(),n.m(s,null)):n&&(n.d(1),n=null)},i:Ft,o:Ft,d(a){a&&_n(s),e&&e.d(),n&&n.d()}}}function rc(r,s){r=r.replace("#","");const t=parseInt(r,16),e=(t>>16)+s,n=(t>>8&255)+s,a=(t&255)+s,i=Math.max(0,Math.min(255,e)),o=Math.max(0,Math.min(255,n)),l=Math.max(0,Math.min(255,a));return`#${(i<<16|o<<8|l).toString(16).padStart(6,"0")}`}function ac(r){return r.map(s=>{let t=s.text||s.content;return(s.role==="ai"||s.role==="assistant")&&(t=t.replace(/\n\n---\n\n\*\*References:\*\*[\s\S]*$/,"")),{role:s.role==="ai"?"assistant":s.role,content:t}})}function sc(r,s,t){let e,n,a,{apiUrl:i=void 0}=s,{apiKey:o=void 0}=s,{modelId:l=void 0}=s,{maxMessages:u=void 0}=s,{placeholderText:c=void 0}=s,{faviconPath:d=void 0}=s,{initialMessage:p=void 0}=s,{userMessageBackgroundColor:h=void 0}=s,{aiMessageBackgroundColor:v=void 0}=s,{userMessageTextColor:f=void 0}=s,{aiMessageTextColor:g=void 0}=s,{faviconBackgroundColor:y=void 0}=s,_=!1,C=null,I=[],w="",A="",U=[],P="",G;const x=d||void 0||Qu,T=p||"Hey, how can I assist you?",E=[{role:"ai",text:T}],B=[{styles:{button:{default:{container:{default:{backgroundColor:"transparent",borderRadius:"4px",width:"24px",height:"24px",border:"1px solid #e0e0e0",cursor:"pointer",transition:"all 0.2s ease"},hover:{backgroundColor:"#2196F3",borderColor:"#2196F3",transform:"scale(1.05)"},click:{backgroundColor:"#1976D2",borderColor:"#1976D2"}},svg:{content:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
279
+ `)}`}function Ba(r){let s,t,e,n,a;return{c(){s=Ut("div"),t=Ut("img"),Hs(t.src,e=r[5])||Ee(t,"src",e),Ee(t,"alt","AI Assistant"),Ee(t,"class","svelte-bjand4"),Ee(s,"class","ai-assistant-icon svelte-bjand4"),Pr(s,"background",r[2]),Ee(s,"role","button"),Ee(s,"tabindex","0")},m(i,o){hr(i,s,o),dr(s,t),n||(a=[Or(s,"click",r[10]),Or(s,"keydown",r[27])],n=!0)},p(i,o){o[0]&4&&Pr(s,"background",i[2])},d(i){i&&_n(s),n=!1,Kt(a)}}}function Da(r){let s,t;return{c(){s=Ut("div"),t=Ut("deep-chat"),ve(t,"demo","false"),ve(t,"textInput",r[9]),ve(t,"messageStyles",r[3]),ve(t,"history",r[6]),ve(t,"connect",r[4]),ve(t,"requestBodyLimits",r[8]),ve(t,"requestInterceptor",r[12]),ve(t,"responseInterceptor",r[13]),ve(t,"customButtons",r[7]),ve(t,"onMessage",r[11]),Ee(s,"class","chat-container svelte-bjand4")},m(e,n){hr(e,s,n),dr(s,t),r[28](t)},p(e,n){n[0]&8&&ve(t,"messageStyles",e[3]),n[0]&16&&ve(t,"connect",e[4])},d(e){e&&_n(s),r[28](null)}}}function nc(r){let s,t,e=!r[0]&&Ba(r),n=r[0]&&Da(r);return{c(){s=Ut("main"),e&&e.c(),t=zs(),n&&n.c(),Ee(s,"class","svelte-bjand4")},m(a,i){hr(a,s,i),e&&e.m(s,null),dr(s,t),n&&n.m(s,null)},p(a,i){a[0]?e&&(e.d(1),e=null):e?e.p(a,i):(e=Ba(a),e.c(),e.m(s,t)),a[0]?n?n.p(a,i):(n=Da(a),n.c(),n.m(s,null)):n&&(n.d(1),n=null)},i:Ft,o:Ft,d(a){a&&_n(s),e&&e.d(),n&&n.d()}}}function rc(r,s){r=r.replace("#","");const t=parseInt(r,16),e=(t>>16)+s,n=(t>>8&255)+s,a=(t&255)+s,i=Math.max(0,Math.min(255,e)),o=Math.max(0,Math.min(255,n)),l=Math.max(0,Math.min(255,a));return`#${(i<<16|o<<8|l).toString(16).padStart(6,"0")}`}function ac(r){return r.map(s=>{let t=s.text||s.content;return(s.role==="ai"||s.role==="assistant")&&(t=t.replace(/\n\n---\n\n\*\*References:\*\*[\s\S]*$/,"")),{role:s.role==="ai"?"assistant":s.role,content:t}})}function sc(r,s,t){let e,n,a,{apiUrl:i=void 0}=s,{apiKey:o=void 0}=s,{modelId:l=void 0}=s,{maxMessages:u=void 0}=s,{placeholderText:c=void 0}=s,{faviconPath:d=void 0}=s,{initialMessage:p=void 0}=s,{userMessageBackgroundColor:h=void 0}=s,{aiMessageBackgroundColor:v=void 0}=s,{userMessageTextColor:f=void 0}=s,{aiMessageTextColor:g=void 0}=s,{faviconBackgroundColor:y=void 0}=s,_=!1,C=null,I=[],w="",A="",U=[],P="",G;const x=d||void 0||Qu,T=p||void 0||"Hey, how can I help you?",E=[{role:"ai",text:T}],B=[{styles:{button:{default:{container:{default:{backgroundColor:"transparent",borderRadius:"4px",width:"24px",height:"24px",border:"1px solid #e0e0e0",cursor:"pointer",transition:"all 0.2s ease"},hover:{backgroundColor:"#2196F3",borderColor:"#2196F3",transform:"scale(1.05)"},click:{backgroundColor:"#1976D2",borderColor:"#1976D2"}},svg:{content:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
280
280
  <path d="M19 14L12 21L5 14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
281
- </svg>`,styles:{default:{width:"14px",height:"14px",color:"#666"},hover:{color:"white"}}}}}},position:"outside-right",tooltip:{text:"Minimize chat",timeout:300,style:{backgroundColor:"#333",color:"white",fontSize:"12px",padding:"4px 8px",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}},onClick:()=>(Y(),"default")}],M={maxMessages:parseInt(u||"0")||0},K={placeholder:{text:c||"Welcome to the demo!"}};function Y(){_?(t(26,C=null),I=[]):$([{role:"assistant",content:T}]),t(0,_=!_)}function ie(){if(console.log("=== Message History ==="),I.length===0){console.log("No messages in history");return}I.forEach((R,W)=>{const se=R.content.length>50?R.content.substring(0,50)+"...":R.content;console.log(`${W+1}. ${R.role.toUpperCase()}: ${se}`)}),console.log("=====================")}async function $(R){var W;try{const se=Math.floor(Date.now()/1e3),ge=[l||"test-model"],oe=[],We={};let $e=null;R.forEach((Me,Xe)=>{const Ye=rn(),lt=Xe<R.length-1?rn():null,ut={id:Ye,parentId:$e,childrenIds:lt?[lt]:[],role:Me.role,content:Me.content,timestamp:se,models:ge};Me.role==="assistant"&&(ut.model=ge[0],ut.modelId=ge[0],ut.modelIdx=0),oe.push(ut),We[Ye]=ut,$e=Ye}),oe.forEach((Me,Xe)=>{Xe<oe.length-1&&(Me.childrenIds=[oe[Xe+1].id])});const Je=(W=oe[oe.length-1])==null?void 0:W.id,xn={chat:{id:"",title:"New Chatbubble Chat",models:ge,params:{},history:{messages:We,currentId:Je},messages:oe,tags:[],timestamp:Date.now()},folder_id:null},Xt=`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/v1/chats/new`,ot=await fetch(Xt,{method:"POST",headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},body:JSON.stringify(xn)});if(ot.ok){const Me=await ot.json();return t(26,C=Me.id),console.log("New chat created with ID:",C),I=oe,ie(),C}else return console.error("Failed to create new chat:",ot.statusText),null}catch(se){return console.error("Error creating new chat:",se),null}}async function ne(R,W,se){if(!C){console.error("Cannot store chat history: no chat ID available");return}console.log("assistantMessageSources:",se);try{const ge=Math.floor(Date.now()/1e3),oe=[l||"test-model"],We=rn(),$e=rn(),Je=I[I.length-1],xn={id:We,parentId:Je?Je.id:null,childrenIds:[$e],role:"user",content:R,timestamp:ge,models:oe},Rr={id:$e,parentId:We,childrenIds:[],role:"assistant",content:W,model:oe[0],modelId:oe[0],modelIdx:0,timestamp:ge,sources:se};Je&&(Je.childrenIds=[We]),I.push(xn,Rr);const Xt={};I.forEach(lt=>{Xt[lt.id]=lt});const ot={chat:{models:oe,history:{messages:Xt,currentId:$e},messages:I,params:{}}},Xe=`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/v1/chats/${C}`,Ye=await fetch(Xe,{method:"POST",headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},body:JSON.stringify(ot)});Ye.ok?(console.log("Chat history stored successfully"),ie()):console.error("Failed to store chat history:",Ye.statusText)}catch(ge){console.error("Error storing chat history:",ge)}}async function fe(R){const{message:W,isHistory:se}=R;if(console.log(R),console.log(W),!se&&(W.role==="ai"||W.role==="assistant")&&(console.log("🤖 AI answered:",W.text||W.content),P&&G)){console.log("📚 Updating AI message with references");const oe=(W.text||W.content||"")+P;console.log(G.getMessages()),console.log(G.getMessages().length-1),G.updateMessage({text:oe},G.getMessages().length-1),P=""}}const me=async R=>{if(R.body&&R.body.messages){R.body.messages=ac(R.body.messages);const W=R.body.messages.filter(se=>se.role==="user");W.length>0&&(w=W[W.length-1].content),C&&(R.body.chat_id=C)}return R},Jt=R=>{console.log(R),R.sources&&Array.isArray(R.sources)&&(U=R.sources,console.log(`Found ${U.length} sources in response`),console.log("assistantMessageSources:",U));try{const W=ec(R);W.length>0&&(P=tc(W),console.log(`Found ${W.length} references in response`))}catch(W){console.error("Error extracting references:",W)}if(R.choices&&R.choices[0]&&R.choices[0].delta){const W=R.choices[0].delta,se=W.content||"";return se&&(A+=se),R.choices[0].finish_reason&&(console.log("Streaming response ended"),w&&A&&ne(w,A,U),A="",w=""),{text:se,role:W.role==="assistant"?"ai":W.role||"ai"}}if(R.choices&&R.choices[0]&&R.choices[0].message){const W=R.choices[0].message;return console.log("Non-streaming response received"),w&&W.content&&(ne(w,W.content),w=""),{text:W.content,role:W.role==="assistant"?"ai":W.role}}return R.text||R.html||R.files?R:typeof R=="string"?{text:R}:R},it=R=>R.key==="Enter"&&Y();function Pe(R){Fn[R?"unshift":"push"](()=>{G=R,t(1,G)})}return r.$$set=R=>{"apiUrl"in R&&t(14,i=R.apiUrl),"apiKey"in R&&t(15,o=R.apiKey),"modelId"in R&&t(16,l=R.modelId),"maxMessages"in R&&t(17,u=R.maxMessages),"placeholderText"in R&&t(18,c=R.placeholderText),"faviconPath"in R&&t(19,d=R.faviconPath),"initialMessage"in R&&t(20,p=R.initialMessage),"userMessageBackgroundColor"in R&&t(21,h=R.userMessageBackgroundColor),"aiMessageBackgroundColor"in R&&t(22,v=R.aiMessageBackgroundColor),"userMessageTextColor"in R&&t(23,f=R.userMessageTextColor),"aiMessageTextColor"in R&&t(24,g=R.aiMessageTextColor),"faviconBackgroundColor"in R&&t(25,y=R.faviconBackgroundColor)},r.$$.update=()=>{r.$$.dirty[0]&67223552&&t(4,e={type:"websocket",url:`${(i||"https://localchat.headwai.org/").replace(/\/$/,"")}/api/chat/completions`,headers:{Authorization:`Bearer ${o||"sk-47ec23c1fd214846ada1e9c812596eef"}`,"Content-Type":"application/json"},additionalBodyProps:{model:l||"test-model",stream:!0,params:{},tool_servers:[],features:{image_generation:!1,code_interpreter:!1,web_search:!1,memory:!1},variables:{"{{USER_NAME}}":"David Schneebauer | headwAI GmbH","{{USER_LOCATION}}":"Unknown","{{CURRENT_DATETIME}}":new Date().toISOString().slice(0,19).replace("T"," "),"{{CURRENT_DATE}}":new Date().toISOString().slice(0,10),"{{CURRENT_TIME}}":new Date().toTimeString().slice(0,8),"{{CURRENT_WEEKDAY}}":new Date().toLocaleDateString("en-US",{weekday:"long"}),"{{CURRENT_TIMEZONE}}":Intl.DateTimeFormat().resolvedOptions().timeZone,"{{USER_LANGUAGE}}":"en-GB"},...C&&{chat_id:C},background_tasks:{title_generation:!0,tags_generation:!1,follow_up_generation:!1}},stream:!0}),r.$$.dirty[0]&31457280&&t(3,n={default:{user:{bubble:{backgroundColor:h||"green",color:f||"white"}},ai:{bubble:{backgroundColor:v||"gray",color:g||"black"}}}}),r.$$.dirty[0]&33554432&&t(2,a=(()=>{const R=y||"lightgreen",W=rc(R,-20);return`linear-gradient(135deg, ${R} 0%, ${W} 100%)`})())},[_,G,a,n,e,x,E,B,M,K,Y,fe,me,Jt,i,o,l,u,c,d,p,h,v,f,g,y,C,it,Pe]}class cr extends ni{constructor(s){super(),ti(this,s,sc,nc,js,{apiUrl:14,apiKey:15,modelId:16,maxMessages:17,placeholderText:18,faviconPath:19,initialMessage:20,userMessageBackgroundColor:21,aiMessageBackgroundColor:22,userMessageTextColor:23,aiMessageTextColor:24,faviconBackgroundColor:25},null,[-1,-1])}}function Ds(){const r={apiUrl:"https://localchat.headwai.org/",apiKey:"sk-47ec23c1fd214846ada1e9c812596eef",modelId:"test-model",connectionType:void 0,contentType:void 0,maxMessages:"0",placeholderText:"Welcome to the demo!",demoMode:void 0,userMessageBackgroundColor:"green",aiMessageBackgroundColor:"gray",userMessageTextColor:"white",aiMessageTextColor:"black",faviconBackgroundColor:"lightgreen"},s=typeof window<"u"&&window.DEEP_CHAT_CONFIG||{};return{...r,...s}}typeof window<"u"&&window.document&&document.addEventListener("DOMContentLoaded",()=>{const r=Ds(),s=document.querySelectorAll("[data-chat-bubble]");if(s.length===0){const t=document.getElementById("chat-bubble-container");t&&new cr({target:t,props:r})}else s.forEach(t=>{const e={...r};Object.keys(t.dataset).forEach(n=>{if(n.startsWith("chatBubble")){const a=n.replace("chatBubble","").toLowerCase();e[a]=t.dataset[n]}}),new cr({target:t,props:e})})});window.ChatBubble={init:(r,s={})=>new cr({target:r,props:{...Ds(),...s}})};
281
+ </svg>`,styles:{default:{width:"14px",height:"14px",color:"#666"},hover:{color:"white"}}}}}},position:"outside-right",tooltip:{text:"Minimize chat",timeout:300,style:{backgroundColor:"#333",color:"white",fontSize:"12px",padding:"4px 8px",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}},onClick:()=>(Y(),"default")}],M={maxMessages:parseInt(u||void 0)||0},K={placeholder:{text:c||void 0||"Enter your questions here"}};function Y(){_?(t(26,C=null),I=[]):$([{role:"assistant",content:T}]),t(0,_=!_)}function ie(){if(console.log("=== Message History ==="),I.length===0){console.log("No messages in history");return}I.forEach((R,W)=>{const se=R.content.length>50?R.content.substring(0,50)+"...":R.content;console.log(`${W+1}. ${R.role.toUpperCase()}: ${se}`)}),console.log("=====================")}async function $(R){var W;try{const se=Math.floor(Date.now()/1e3),ge=[l||void 0||"deepseek-r1-distill-qwen-7b"],oe=[],We={};let $e=null;R.forEach((Me,Xe)=>{const Ye=rn(),lt=Xe<R.length-1?rn():null,ut={id:Ye,parentId:$e,childrenIds:lt?[lt]:[],role:Me.role,content:Me.content,timestamp:se,models:ge};Me.role==="assistant"&&(ut.model=ge[0],ut.modelId=ge[0],ut.modelIdx=0),oe.push(ut),We[Ye]=ut,$e=Ye}),oe.forEach((Me,Xe)=>{Xe<oe.length-1&&(Me.childrenIds=[oe[Xe+1].id])});const Je=(W=oe[oe.length-1])==null?void 0:W.id,xn={chat:{id:"",title:"New Chatbubble Chat",models:ge,params:{},history:{messages:We,currentId:Je},messages:oe,tags:[],timestamp:Date.now()},folder_id:null},Xt=`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/v1/chats/new`,ot=await fetch(Xt,{method:"POST",headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},body:JSON.stringify(xn)});if(ot.ok){const Me=await ot.json();return t(26,C=Me.id),console.log("New chat created with ID:",C),I=oe,ie(),C}else return console.error("Failed to create new chat:",ot.statusText),null}catch(se){return console.error("Error creating new chat:",se),null}}async function ne(R,W,se){if(!C){console.error("Cannot store chat history: no chat ID available");return}console.log("assistantMessageSources:",se);try{const ge=Math.floor(Date.now()/1e3),oe=[l||void 0||"deepseek-r1-distill-qwen-7b"],We=rn(),$e=rn(),Je=I[I.length-1],xn={id:We,parentId:Je?Je.id:null,childrenIds:[$e],role:"user",content:R,timestamp:ge,models:oe},Rr={id:$e,parentId:We,childrenIds:[],role:"assistant",content:W,model:oe[0],modelId:oe[0],modelIdx:0,timestamp:ge,sources:se};Je&&(Je.childrenIds=[We]),I.push(xn,Rr);const Xt={};I.forEach(lt=>{Xt[lt.id]=lt});const ot={chat:{models:oe,history:{messages:Xt,currentId:$e},messages:I,params:{}}},Xe=`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/v1/chats/${C}`,Ye=await fetch(Xe,{method:"POST",headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},body:JSON.stringify(ot)});Ye.ok?(console.log("Chat history stored successfully"),ie()):console.error("Failed to store chat history:",Ye.statusText)}catch(ge){console.error("Error storing chat history:",ge)}}async function fe(R){const{message:W,isHistory:se}=R;if(console.log(R),console.log(W),!se&&(W.role==="ai"||W.role==="assistant")&&(console.log("🤖 AI answered:",W.text||W.content),P&&G)){console.log("📚 Updating AI message with references");const oe=(W.text||W.content||"")+P;console.log(G.getMessages()),console.log(G.getMessages().length-1),G.updateMessage({text:oe},G.getMessages().length-1),P=""}}const me=async R=>{if(R.body&&R.body.messages){R.body.messages=ac(R.body.messages);const W=R.body.messages.filter(se=>se.role==="user");W.length>0&&(w=W[W.length-1].content),C&&(R.body.chat_id=C)}return R},Jt=R=>{console.log(R),R.sources&&Array.isArray(R.sources)&&(U=R.sources,console.log(`Found ${U.length} sources in response`),console.log("assistantMessageSources:",U));try{const W=ec(R);W.length>0&&(P=tc(W),console.log(`Found ${W.length} references in response`))}catch(W){console.error("Error extracting references:",W)}if(R.choices&&R.choices[0]&&R.choices[0].delta){const W=R.choices[0].delta,se=W.content||"";return se&&(A+=se),R.choices[0].finish_reason&&(console.log("Streaming response ended"),w&&A&&ne(w,A,U),A="",w=""),{text:se,role:W.role==="assistant"?"ai":W.role||"ai"}}if(R.choices&&R.choices[0]&&R.choices[0].message){const W=R.choices[0].message;return console.log("Non-streaming response received"),w&&W.content&&(ne(w,W.content),w=""),{text:W.content,role:W.role==="assistant"?"ai":W.role}}return R.text||R.html||R.files?R:typeof R=="string"?{text:R}:R},it=R=>R.key==="Enter"&&Y();function Pe(R){Fn[R?"unshift":"push"](()=>{G=R,t(1,G)})}return r.$$set=R=>{"apiUrl"in R&&t(14,i=R.apiUrl),"apiKey"in R&&t(15,o=R.apiKey),"modelId"in R&&t(16,l=R.modelId),"maxMessages"in R&&t(17,u=R.maxMessages),"placeholderText"in R&&t(18,c=R.placeholderText),"faviconPath"in R&&t(19,d=R.faviconPath),"initialMessage"in R&&t(20,p=R.initialMessage),"userMessageBackgroundColor"in R&&t(21,h=R.userMessageBackgroundColor),"aiMessageBackgroundColor"in R&&t(22,v=R.aiMessageBackgroundColor),"userMessageTextColor"in R&&t(23,f=R.userMessageTextColor),"aiMessageTextColor"in R&&t(24,g=R.aiMessageTextColor),"faviconBackgroundColor"in R&&t(25,y=R.faviconBackgroundColor)},r.$$.update=()=>{r.$$.dirty[0]&67223552&&t(4,e={type:"websocket",url:`${(i||void 0||"https://localhost").replace(/\/$/,"")}/api/chat/completions`,headers:{Authorization:`Bearer ${o||void 0||""}`,"Content-Type":"application/json"},additionalBodyProps:{model:l||void 0||"enterprise-search",stream:!0,params:{},tool_servers:[],features:{image_generation:!1,code_interpreter:!1,web_search:!1,memory:!1},variables:{"{{USER_NAME}}":"David Schneebauer | headwAI GmbH","{{USER_LOCATION}}":"Unknown","{{CURRENT_DATETIME}}":new Date().toISOString().slice(0,19).replace("T"," "),"{{CURRENT_DATE}}":new Date().toISOString().slice(0,10),"{{CURRENT_TIME}}":new Date().toTimeString().slice(0,8),"{{CURRENT_WEEKDAY}}":new Date().toLocaleDateString("en-US",{weekday:"long"}),"{{CURRENT_TIMEZONE}}":Intl.DateTimeFormat().resolvedOptions().timeZone,"{{USER_LANGUAGE}}":"en-GB"},...C&&{chat_id:C},background_tasks:{title_generation:!0,tags_generation:!1,follow_up_generation:!1}},stream:!0}),r.$$.dirty[0]&31457280&&t(3,n={default:{user:{bubble:{backgroundColor:h||void 0||"#007bff",color:f||void 0||"#000000"}},ai:{bubble:{backgroundColor:v||void 0||"#f1f3f4",color:g||void 0||"#000000"}}}}),r.$$.dirty[0]&33554432&&t(2,a=(()=>{const R=y||void 0||"#667eea",W=rc(R,-20);return`linear-gradient(135deg, ${R} 0%, ${W} 100%)`})())},[_,G,a,n,e,x,E,B,M,K,Y,fe,me,Jt,i,o,l,u,c,d,p,h,v,f,g,y,C,it,Pe]}class cr extends ni{constructor(s){super(),ti(this,s,sc,nc,js,{apiUrl:14,apiKey:15,modelId:16,maxMessages:17,placeholderText:18,faviconPath:19,initialMessage:20,userMessageBackgroundColor:21,aiMessageBackgroundColor:22,userMessageTextColor:23,aiMessageTextColor:24,faviconBackgroundColor:25},null,[-1,-1])}}function Ds(){const r={apiUrl:void 0,apiKey:void 0,modelId:void 0,maxMessages:void 0,placeholderText:void 0,userMessageBackgroundColor:void 0,aiMessageBackgroundColor:void 0,userMessageTextColor:void 0,aiMessageTextColor:void 0,faviconBackgroundColor:void 0},s=typeof window<"u"&&window.HEADWAI_CHAT_BUBBLE_CONFIG||{};console.log("Environment config:",r),console.log("Global config:",s);const t={...r,...s};return console.log("Final merged config:",t),t}typeof window<"u"&&window.document&&document.addEventListener("DOMContentLoaded",()=>{const r=Ds(),s=document.querySelectorAll("[data-chat-bubble]");if(s.length===0){const t=document.getElementById("chat-bubble-container");t&&new cr({target:t,props:r})}else s.forEach(t=>{const e={...r},n={chatBubbleApiUrl:"apiUrl",chatBubbleApiKey:"apiKey",chatBubbleModelId:"modelId",chatBubbleMaxMessages:"maxMessages",chatBubblePlaceholderText:"placeholderText",chatBubbleFaviconPath:"faviconPath",chatBubbleInitialMessage:"initialMessage",chatBubbleUserMessageBackgroundColor:"userMessageBackgroundColor",chatBubbleAiMessageBackgroundColor:"aiMessageBackgroundColor",chatBubbleUserMessageTextColor:"userMessageTextColor",chatBubbleAiMessageTextColor:"aiMessageTextColor",chatBubbleFaviconBackgroundColor:"faviconBackgroundColor"};Object.keys(t.dataset).forEach(a=>{n[a]&&(e[n[a]]=t.dataset[a])}),new cr({target:t,props:e})})});window.ChatBubble={init:(r,s={})=>new cr({target:r,props:{...Ds(),...s}})};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headwai/chat-bubble",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "A chat bubble component for LocalChat by headwAI",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",