@headwai/chat-bubble 7.3.0 → 7.3.1
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.
|
@@ -240,7 +240,7 @@ ${W.text}
|
|
|
240
240
|
|
|
241
241
|
${Array.from(e).sort((r,i)=>r-i).map(r=>{const o=a[r].name||"Untitled Reference";return`**[${r+1}]** ${o}`}).join(`
|
|
242
242
|
|
|
243
|
-
`)}`}function hp(a){if(!a||typeof a!="string")return a;const s=/\n\n---\n\n\*\*References:\*\*[\s\S]*$/;return a.replace(s,"").trim()}function Dr(a){if(G.group("Message History"),a.length===0){G.log("No messages in history");return}a.forEach((s,t)=>{const e=s.content||s.html||"",n=e.length>50?e.substring(0,50)+"...":e;G.log(`${t+1}. ${s.role.toUpperCase()}: ${n}`)})}class fp{constructor(s){this.baseUrl=s}async post(s,t,e={}){try{const n=`${this.baseUrl}${s}`,r={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...e.headers},body:JSON.stringify(t),...e};G.log(`API POST Request to ${n}`,{data:t});const i=await fetch(n,r);if(i.ok){const o=await i.json();return G.log(`API POST Success for ${s}:`,o),o}else{const o=await i.json().catch(()=>null);return G.error(`API POST Failed for ${s}:`,i.status,i.statusText,o),null}}catch{return null}}async get(s,t={}){try{const e=`${this.baseUrl}${s}`,n={method:"GET",headers:{Accept:"application/json",...t.headers},...t};G.log(`API GET Request to ${e}`);const r=await fetch(e,n);if(r.ok){const i=await r.json();return G.log(`API GET Success for ${s}:`,i),i}else{const i=await r.json().catch(()=>null);return G.error(`API GET Failed for ${s}:`,r.status,r.statusText,i),null}}catch{return null}}}function ya(a){return new fp(a)}class pp{constructor(s){this.client=ya(s)}async createNewChat(s,t){const e=Math.floor(Date.now()/1e3),n=[],r={},i=fr(),o={id:i,parentId:null,childrenIds:[],role:Ut,content:t,model:s,modelId:s,modelIdx:0,timestamp:e};n.push(o),r[i]=o;const l={assistantId:s,chat:{id:"",title:"New Chatbubble Chat",models:[s],params:{},history:{messages:r,currentId:i},messages:n,tags:[],timestamp:Date.now()},folder_id:null};return await this.client.post("/api/v1/chats/new",l)}async storeChatHistory(s,t,e,n=null){if(!s)throw new Error("No chat ID available to store history");const r=this.filterFeedbackMessagesAndFixRelationships(e),i={};r.forEach(c=>{i[c.id]=c});const o=r.filter(c=>c.role===Ut),l=o[o.length-1],u={...n&&{title:n},assistantId:t,chat:{files:[],models:[t],history:{messages:i,currentId:(l==null?void 0:l.id)||null},messages:r,params:{},...n&&{title:n}}};return await this.client.post(`/api/v1/chats/${s}`,u)}filterFeedbackMessagesAndFixRelationships(s){const e=s.filter(i=>i.role!==St).map(i=>({...i,childrenIds:[...i.childrenIds||[]]})),n=new Map,r=new Set;return s.forEach(i=>{n.set(i.id,i),i.role===St&&r.add(i.id)}),e.forEach(i=>{const o=[];if((i.childrenIds||[]).forEach(l=>{if(r.has(l)){const u=n.get(l);u&&u.childrenIds&&u.childrenIds.forEach(c=>{r.has(c)||o.push(c)})}else o.push(l)}),i.childrenIds=o,i.parentId&&r.has(i.parentId)){let l=n.get(i.parentId);for(;l&&r.has(l.id);)l=l.parentId?n.get(l.parentId):null;i.parentId=l?l.id:null}}),e}async updateAssistantMessageWithFeedback(s,t,e,n=null){return this.storeChatHistory(s,t,e,n)}async storeTag(s,t,e){if(!s)throw new Error("No chat ID available to store tag");const n={name:e.trim(),assistantId:t};return await this.client.post(`/api/v1/chats/${s}/tags`,n)}}class mp{constructor(s){this.client=ya(s)}async sendFeedback({assistantId:s,messageId:t,rating:e,chatId:n,messageHistory:r}){var d;if(!n)throw new Error("No chat ID available to send feedback");if(!r.find(h=>h.id===t))throw new Error(`Message not found in history for feedback ID: ${t}`);const o=r.findIndex(h=>h.id===t),l={assistantId:s,type:"rating",data:{rating:e,model_id:s},meta:{model_id:s,message_id:t,message_index:o,chat_id:n,base_models:{[s]:s}},snapshot:{chat:{id:n,user_id:null,title:"New Chatbubble Chat",chat:{id:"",title:"New Chatbubble Chat",models:[s],params:{},history:{messages:{},currentId:t},messages:r,params:{}},updated_at:Date.now(),created_at:Date.now(),share_id:null,archived:!1,pinned:!1,meta:{},folder_id:null}}},u={};return r.forEach(h=>{u[h.id]=h}),l.snapshot.chat.chat.history.messages=u,l.snapshot.chat.chat.history.currentId=(d=r[r.length-1])==null?void 0:d.id,await this.client.post("/api/v1/evaluations/feedback",l)}}class vp{constructor(s){this.client=ya(s)}async createTags(s,t,e){try{const n={model:s,messages:t,chat_id:e};return await this.client.post("/api/v1/tasks/tags/completions",n)}catch(n){return console.error("Failed to generate tags:",n),null}}}class gp{constructor(s){this.client=ya(s)}async createTitle(s,t,e=null){const n={model:s,messages:t,...e&&{chat_id:e}},r=await this.client.post("/api/v1/tasks/title/completions",n);if(r&&r.choices&&r.choices[0]&&r.choices[0].message){const i=r.choices[0].message.content;try{return JSON.parse(i).title}catch{return i}}return null}}function yp(a){return{chats:new pp(a),evaluations:new mp(a),tags:new vp(a),titles:new gp(a)}}function bp(a){let s,t;return{c(){s=ve("div"),t=ve("deep-chat"),ht(t,"chatStyle",a[4]),ht(t,"textInput",a[5]),ht(t,"messageStyles",a[6]),ht(t,"demo","false"),ht(t,"history",a[1]),ht(t,"connect",a[7]),ht(t,"requestBodyLimits",a[8]),ht(t,"requestInterceptor",a[9]),ht(t,"responseInterceptor",a[10]),ht(t,"onMessage",a[11]),ht(t,"submitButtonStyles",a[3]),R(s,"class","chat-content svelte-nmr4np")},m(e,n){sn(e,s,n),Z(s,t),a[29](t)},p(e,n){n[0]&2&&ht(t,"history",e[1])},i:Je,o:Je,d(e){e&&Gt(s),a[29](null)}}}function kp(a,s,t){let e,n,r,i,o,l,u,c,d,h;Le(a,gr,A=>t(26,e=A)),Le(a,Mn,A=>t(27,n=A)),Le(a,yr,A=>t(28,r=A)),Le(a,_n,A=>t(32,o=A)),Le(a,dr,A=>t(33,l=A)),Le(a,cr,A=>t(34,u=A)),Le(a,ur,A=>t(35,c=A)),Le(a,np,A=>t(36,d=A)),Le(a,hr,A=>t(37,h=A));let{deepChatRef:f}=s,{placeholderText:m}=s,{fontFamily:p}=s,{fontSize:b}=s,{userMessageBackgroundColor:_}=s,{userMessageTextColor:C}=s,{aiMessageBackgroundColor:x}=s,{aiMessageTextColor:B}=s,{feedbackMessageBackgroundColor:M}=s,{feedbackMessageTextColor:O}=s,{initialHistory:z}=s,{apiUrl:U}=s,{assistantId:X}=s,{maxMessages:W}=s,{submitButtonBackgroundColor:q}=s;const D=yp(U),he=ds("i18n");Le(a,he,A=>t(31,i=A));let $=!1;const be={submit:{container:{default:{backgroundColor:q},hover:{backgroundColor:q,opacity:"0.8"},click:{backgroundColor:q,opacity:"0.6"}},svg:{styles:{default:{filter:"brightness(0) saturate(100%) invert(100%)"},hover:{filter:"brightness(0) saturate(100%) invert(100%)"},click:{filter:"brightness(0) saturate(100%) invert(100%)"}}}},loading:{container:{default:{backgroundColor:q},hover:{backgroundColor:q,opacity:"0.8"},click:{backgroundColor:q,opacity:"0.6"}},svg:{content:`<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
243
|
+
`)}`}function hp(a){if(!a||typeof a!="string")return a;const s=/\n\n---\n\n\*\*References:\*\*[\s\S]*$/;return a.replace(s,"").trim()}function Dr(a){if(G.group("Message History"),a.length===0){G.log("No messages in history");return}a.forEach((s,t)=>{const e=s.content||s.html||"",n=e.length>50?e.substring(0,50)+"...":e;G.log(`${t+1}. ${s.role.toUpperCase()}: ${n}`)})}class fp{constructor(s){this.baseUrl=s}async post(s,t,e={}){try{const n=`${this.baseUrl}${s}`,r={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...e.headers},body:JSON.stringify(t),...e};G.log(`API POST Request to ${n}`,{data:t});const i=await fetch(n,r);if(i.ok){const o=await i.json();return G.log(`API POST Success for ${s}:`,o),o}else{const o=await i.json().catch(()=>null);return G.error(`API POST Failed for ${s}:`,i.status,i.statusText,o),null}}catch{return null}}async get(s,t={}){try{const e=`${this.baseUrl}${s}`,n={method:"GET",headers:{Accept:"application/json",...t.headers},...t};G.log(`API GET Request to ${e}`);const r=await fetch(e,n);if(r.ok){const i=await r.json();return G.log(`API GET Success for ${s}:`,i),i}else{const i=await r.json().catch(()=>null);return G.error(`API GET Failed for ${s}:`,r.status,r.statusText,i),null}}catch{return null}}}function ya(a){return new fp(a)}class pp{constructor(s){this.client=ya(s)}async createNewChat(s,t){const e=Math.floor(Date.now()/1e3),n=[],r={},i=fr(),o={id:i,parentId:null,childrenIds:[],role:Ut,content:t,model:s,modelId:s,modelIdx:0,timestamp:e};n.push(o),r[i]=o;const l={assistantId:s,chat:{id:"",title:"New Chatbubble Chat",models:[s],params:{},history:{messages:r,currentId:i},messages:n,tags:[],timestamp:Date.now()},folder_id:null};return await this.client.post("/api/v1/chats/new",l)}async storeChatHistory(s,t,e,n=null){if(!s)throw new Error("No chat ID available to store history");const r=this.filterFeedbackMessagesAndFixRelationships(e),i={};r.forEach(c=>{i[c.id]=c});const o=r.filter(c=>c.role===Ut),l=o[o.length-1],u={...n&&{title:n},assistantId:t,chat:{files:[],models:[t],history:{messages:i,currentId:(l==null?void 0:l.id)||null},messages:r,params:{},...n&&{title:n}}};return await this.client.post(`/api/v1/chats/${s}`,u)}filterFeedbackMessagesAndFixRelationships(s){const e=s.filter(i=>i.role!==St).map(i=>({...i,childrenIds:[...i.childrenIds||[]]})),n=new Map,r=new Set;return s.forEach(i=>{n.set(i.id,i),i.role===St&&r.add(i.id)}),e.forEach(i=>{const o=[];if((i.childrenIds||[]).forEach(l=>{if(r.has(l)){const u=n.get(l);u&&u.childrenIds&&u.childrenIds.forEach(c=>{r.has(c)||o.push(c)})}else o.push(l)}),i.childrenIds=o,i.parentId&&r.has(i.parentId)){let l=n.get(i.parentId);for(;l&&r.has(l.id);)l=l.parentId?n.get(l.parentId):null;i.parentId=l?l.id:null}}),e}async updateAssistantMessageWithFeedback(s,t,e,n=null){return this.storeChatHistory(s,t,e,n)}async storeTag(s,t,e){if(!s)throw new Error("No chat ID available to store tag");const n={name:e.trim(),assistantId:t};return await this.client.post(`/api/v1/chats/${s}/tags`,n)}}class mp{constructor(s){this.client=ya(s)}async sendFeedback({assistantId:s,messageId:t,rating:e,chatId:n,messageHistory:r}){var d;if(!n)throw new Error("No chat ID available to send feedback");if(!r.find(h=>h.id===t))throw new Error(`Message not found in history for feedback ID: ${t}`);const o=r.findIndex(h=>h.id===t),l={assistantId:s,type:"rating",data:{rating:e,model_id:s},meta:{model_id:s,message_id:t,message_index:o,chat_id:n,base_models:{[s]:s}},snapshot:{chat:{id:n,user_id:null,title:"New Chatbubble Chat",chat:{id:"",title:"New Chatbubble Chat",models:[s],params:{},history:{messages:{},currentId:t},messages:r,params:{}},updated_at:Date.now(),created_at:Date.now(),share_id:null,archived:!1,pinned:!1,meta:{},folder_id:null}}},u={};return r.forEach(h=>{u[h.id]=h}),l.snapshot.chat.chat.history.messages=u,l.snapshot.chat.chat.history.currentId=(d=r[r.length-1])==null?void 0:d.id,await this.client.post("/api/v1/evaluations/feedback",l)}}class vp{constructor(s){this.client=ya(s)}async createTags(s,t,e){try{const n={model:s,messages:t,chat_id:e};return await this.client.post("/api/v1/tasks/tags/completions",n)}catch(n){return console.error("Failed to generate tags:",n),null}}}class gp{constructor(s){this.client=ya(s)}async createTitle(s,t,e=null){const n={model:s,messages:t,...e&&{chat_id:e}},r=await this.client.post("/api/v1/tasks/title/completions",n);if(r&&r.choices&&r.choices[0]&&r.choices[0].message){const i=r.choices[0].message.content;try{return JSON.parse(i).title}catch{return i}}return null}}function yp(a){return{chats:new pp(a),evaluations:new mp(a),tags:new vp(a),titles:new gp(a)}}function bp(a){let s,t;return{c(){s=ve("div"),t=ve("deep-chat"),ht(t,"chatStyle",a[4]),ht(t,"textInput",a[5]),ht(t,"messageStyles",a[6]),ht(t,"demo","false"),ht(t,"history",a[1]),ht(t,"connect",a[7]),ht(t,"requestBodyLimits",a[8]),ht(t,"requestInterceptor",a[9]),ht(t,"responseInterceptor",a[10]),ht(t,"onMessage",a[11]),ht(t,"submitButtonStyles",a[3]),R(s,"class","chat-content svelte-nmr4np")},m(e,n){sn(e,s,n),Z(s,t),a[29](t)},p(e,n){n[0]&2&&ht(t,"history",e[1])},i:Je,o:Je,d(e){e&&Gt(s),a[29](null)}}}function kp(a,s,t){let e,n,r,i,o,l,u,c,d,h;Le(a,gr,A=>t(26,e=A)),Le(a,Mn,A=>t(27,n=A)),Le(a,yr,A=>t(28,r=A)),Le(a,_n,A=>t(32,o=A)),Le(a,dr,A=>t(33,l=A)),Le(a,cr,A=>t(34,u=A)),Le(a,ur,A=>t(35,c=A)),Le(a,np,A=>t(36,d=A)),Le(a,hr,A=>t(37,h=A));let{deepChatRef:f}=s,{placeholderText:m}=s,{fontFamily:p}=s,{fontSize:b}=s,{userMessageBackgroundColor:_}=s,{userMessageTextColor:C}=s,{aiMessageBackgroundColor:x}=s,{aiMessageTextColor:B}=s,{feedbackMessageBackgroundColor:M}=s,{feedbackMessageTextColor:O}=s,{initialHistory:z}=s,{apiUrl:U}=s,{assistantId:X}=s,{maxMessages:W}=s,{submitButtonBackgroundColor:q}=s;const D=yp(U),he=ds("i18n");Le(a,he,A=>t(31,i=A));let $=!1;const be={submit:{container:{default:{backgroundColor:q,marginBottom:"0.05em",width:"1.8em",height:"1.8em"},hover:{backgroundColor:q,opacity:"0.8"},click:{backgroundColor:q,opacity:"0.6"}},svg:{styles:{default:{filter:"brightness(0) saturate(100%) invert(100%)"},hover:{filter:"brightness(0) saturate(100%) invert(100%)"},click:{filter:"brightness(0) saturate(100%) invert(100%)"}}}},loading:{container:{default:{backgroundColor:q},hover:{backgroundColor:q,opacity:"0.8"},click:{backgroundColor:q,opacity:"0.6"}},svg:{content:`<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
244
244
|
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" stroke-dasharray="31.416" stroke-dashoffset="31.416">
|
|
245
245
|
<animate attributeName="stroke-dasharray" dur="2s" values="0 31.416;15.708 15.708;0 31.416;0 31.416" repeatCount="indefinite"/>
|
|
246
246
|
<animate attributeName="stroke-dashoffset" dur="2s" values="0;-15.708;-31.416;-31.416" repeatCount="indefinite"/>
|