@headwai/chat-bubble 6.0.0 → 6.1.0-rc.publish-npm-package.df2535f
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/README.dev.md +22 -19
- package/README.md +9 -9
- package/dist-widget/chat-bubble.js +4 -4
- package/package.json +1 -1
package/README.dev.md
CHANGED
|
@@ -61,7 +61,7 @@ Create a `.env` by copying `.env.example` file in your project root with the fol
|
|
|
61
61
|
// Runtime configuration override
|
|
62
62
|
window.HEADWAI_CHAT_BUBBLE_CONFIG = {
|
|
63
63
|
apiUrl: 'https://company.localchat.at',
|
|
64
|
-
|
|
64
|
+
assistantId: 'customer-support-assistant-id',
|
|
65
65
|
};
|
|
66
66
|
</script>
|
|
67
67
|
```
|
|
@@ -102,7 +102,7 @@ This project builds a standalone widget that can be integrated into any website.
|
|
|
102
102
|
```bash
|
|
103
103
|
# Production .env file
|
|
104
104
|
VITE_CHAT_BUBBLE_API_URL=https://company.localchat.at
|
|
105
|
-
|
|
105
|
+
VITE_CHAT_BUBBLE_ASSISTANT_ID=customer-support-assistant-id
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
2. **Bump package version**
|
|
@@ -197,10 +197,10 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
197
197
|
|
|
198
198
|
#### Core API Configuration
|
|
199
199
|
|
|
200
|
-
| Attribute
|
|
201
|
-
|
|
|
202
|
-
| `apiUrl`
|
|
203
|
-
| `
|
|
200
|
+
| Attribute | Environment Variable | Data Attribute | Purpose | Default |
|
|
201
|
+
| ------------- | ------------------------------- | ------------------------------- | ----------------------------------------- | ------------------- |
|
|
202
|
+
| `apiUrl` | `VITE_CHAT_BUBBLE_API_URL` | `data-chat-bubble-api-url` | Base URL for API endpoints | `https://localhost` |
|
|
203
|
+
| `assistantId` | `VITE_CHAT_BUBBLE_ASSISTANT_ID` | `data-chat-bubble-assistant-id` | Assistant identifier to use for responses | `test-model` |
|
|
204
204
|
|
|
205
205
|
#### Message Configuration
|
|
206
206
|
|
|
@@ -243,7 +243,7 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
243
243
|
"content": "message text"
|
|
244
244
|
}
|
|
245
245
|
],
|
|
246
|
-
"model": "
|
|
246
|
+
"model": "customer-support-assistant-id",
|
|
247
247
|
"stream": true,
|
|
248
248
|
"chat_id": "uuid-if-existing",
|
|
249
249
|
"params": {},
|
|
@@ -272,10 +272,11 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
272
272
|
|
|
273
273
|
```javascript
|
|
274
274
|
{
|
|
275
|
+
"assistantId": "customer-support-assistant-id",
|
|
275
276
|
"chat": {
|
|
276
277
|
"id": "",
|
|
277
278
|
"title": "New Chatbubble Chat",
|
|
278
|
-
"models": ["
|
|
279
|
+
"models": ["customer-support-assistant-id"],
|
|
279
280
|
"params": {},
|
|
280
281
|
"history": {
|
|
281
282
|
"messages": {"message-id": {...}},
|
|
@@ -288,7 +289,7 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
288
289
|
"role": "assistant|user",
|
|
289
290
|
"content": "message content",
|
|
290
291
|
"timestamp": 1704636645,
|
|
291
|
-
"models": ["
|
|
292
|
+
"models": ["customer-support-assistant-id"]
|
|
292
293
|
}],
|
|
293
294
|
"tags": [],
|
|
294
295
|
"timestamp": 1704636645000
|
|
@@ -301,8 +302,9 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
301
302
|
|
|
302
303
|
```javascript
|
|
303
304
|
{
|
|
305
|
+
"assistantId": "customer-support-assistant-id",
|
|
304
306
|
"chat": {
|
|
305
|
-
"models": ["
|
|
307
|
+
"models": ["customer-support-assistant-id"],
|
|
306
308
|
"history": {
|
|
307
309
|
"messages": {
|
|
308
310
|
"message-uuid-1": {
|
|
@@ -312,7 +314,7 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
312
314
|
"role": "user",
|
|
313
315
|
"content": "user message content",
|
|
314
316
|
"timestamp": 1704636645,
|
|
315
|
-
"models": ["
|
|
317
|
+
"models": ["customer-support-assistant-id"]
|
|
316
318
|
},
|
|
317
319
|
"message-uuid-2": {
|
|
318
320
|
"id": "message-uuid-2",
|
|
@@ -320,8 +322,8 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
320
322
|
"childrenIds": [],
|
|
321
323
|
"role": "assistant",
|
|
322
324
|
"content": "assistant response content",
|
|
323
|
-
"model": "
|
|
324
|
-
"modelId": "
|
|
325
|
+
"model": "customer-support-assistant-id",
|
|
326
|
+
"modelId": "customer-support-assistant-id",
|
|
325
327
|
"modelIdx": 0,
|
|
326
328
|
"timestamp": 1704636645,
|
|
327
329
|
"sources": []
|
|
@@ -337,7 +339,7 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
337
339
|
"role": "user",
|
|
338
340
|
"content": "user message content",
|
|
339
341
|
"timestamp": 1704636645,
|
|
340
|
-
"models": ["
|
|
342
|
+
"models": ["customer-support-assistant-id"]
|
|
341
343
|
},
|
|
342
344
|
{
|
|
343
345
|
"id": "message-uuid-2",
|
|
@@ -345,8 +347,8 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
345
347
|
"childrenIds": [],
|
|
346
348
|
"role": "assistant",
|
|
347
349
|
"content": "assistant response content",
|
|
348
|
-
"model": "
|
|
349
|
-
"modelId": "
|
|
350
|
+
"model": "customer-support-assistant-id",
|
|
351
|
+
"modelId": "customer-support-assistant-id",
|
|
350
352
|
"modelIdx": 0,
|
|
351
353
|
"timestamp": 1704636645,
|
|
352
354
|
"sources": []
|
|
@@ -361,17 +363,18 @@ The chat bubble can be configured using environment variables, data attributes,
|
|
|
361
363
|
|
|
362
364
|
```javascript
|
|
363
365
|
{
|
|
366
|
+
"assistantId": "customer-support-assistant-id",
|
|
364
367
|
"type": "rating",
|
|
365
368
|
"data": {
|
|
366
369
|
"rating": 1, // 1 for positive, -1 for negative
|
|
367
|
-
"model_id": "
|
|
370
|
+
"model_id": "customer-support-assistant-id"
|
|
368
371
|
},
|
|
369
372
|
"meta": {
|
|
370
|
-
"model_id": "
|
|
373
|
+
"model_id": "customer-support-assistant-id",
|
|
371
374
|
"message_id": "message-uuid",
|
|
372
375
|
"message_index": 2,
|
|
373
376
|
"chat_id": "chat-uuid",
|
|
374
|
-
"base_models": {"
|
|
377
|
+
"base_models": {"customer-support-assistant-id": "customer-support-assistant-id"}
|
|
375
378
|
},
|
|
376
379
|
"snapshot": {
|
|
377
380
|
"chat": {
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## Features
|
|
4
4
|
|
|
5
5
|
- 🚀 Easy integration
|
|
6
|
-
- 💬 Connect to any LocalChat
|
|
6
|
+
- 💬 Connect to any LocalChat Assistant
|
|
7
7
|
- 📋 Review conversations in LocalChat
|
|
8
8
|
- 📱 Responsive design
|
|
9
9
|
- 🎨 Customizable UI components
|
|
@@ -23,7 +23,7 @@ Add the Headwai Chat Bubble to the respective .html file.
|
|
|
23
23
|
// Runtime configuration override
|
|
24
24
|
window.HEADWAI_CHAT_BUBBLE_CONFIG = {
|
|
25
25
|
apiUrl: 'https://company.localchat.at', // required
|
|
26
|
-
|
|
26
|
+
assistantId: 'customer-support-assistant-id', // required
|
|
27
27
|
maxMessages: 0, // optional - 0 means unlimited
|
|
28
28
|
placeholderText: 'Ask your question here!', // optional - default: 'Enter your questions here'
|
|
29
29
|
faviconPath: 'https://cdn.company.at/icons/favicon.svg', // optional - default: '/icons/favicon.svg'
|
|
@@ -85,7 +85,7 @@ For multiple instances use data attributes of the `<div>` tag for configuration
|
|
|
85
85
|
<div
|
|
86
86
|
data-chat-bubble
|
|
87
87
|
data-chat-bubble-api-url="https://company.localchat.at"
|
|
88
|
-
data-chat-bubble-
|
|
88
|
+
data-chat-bubble-assistant-id="customer-support-assistant-id"
|
|
89
89
|
data-chat-bubble-max-messages="0"
|
|
90
90
|
data-chat-bubble-placeholder-text="Ask your question here!"
|
|
91
91
|
data-chat-bubble-favicon-path="https://cdn.company.at/icons/favicon.svg"
|
|
@@ -104,7 +104,7 @@ For multiple instances use data attributes of the `<div>` tag for configuration
|
|
|
104
104
|
<div
|
|
105
105
|
data-chat-bubble
|
|
106
106
|
data-chat-bubble-api-url="https://company.localchat.at"
|
|
107
|
-
data-chat-bubble-
|
|
107
|
+
data-chat-bubble-assistant-id="faq-assistant-id"
|
|
108
108
|
data-chat-bubble-max-messages="10"
|
|
109
109
|
data-chat-bubble-placeholder-text="Ask about our FAQ..."
|
|
110
110
|
data-chat-bubble-favicon-path="https://cdn.company.at/icons/faq-icon.svg"
|
|
@@ -141,20 +141,20 @@ The base URL of your LocalChat API endpoint where the chat bubble will send mess
|
|
|
141
141
|
apiUrl: 'https://company.localchat.at';
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
#### `
|
|
144
|
+
#### `assistantId`
|
|
145
145
|
|
|
146
146
|
**Type:** `string` | **Required:** ✅
|
|
147
|
-
The identifier of the AI
|
|
147
|
+
The identifier of the AI assistant to use for generating responses. This should match an assistant configured in your LocalChat instance.
|
|
148
148
|
|
|
149
149
|
```javascript
|
|
150
|
-
|
|
150
|
+
assistantId: 'customer-support-assistant-id';
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
1. **Navigate to
|
|
153
|
+
1. **Navigate to Assistant**: Login to LocalChat with the dedicated Headwai Chat Bubble user (Or any other user that is allowed to see the desired assistant) and click on the `Workspace` menu, then select `Assistants`. Search for the name of the desired assistant (Or create one). Click onto the edit-`Pen`.
|
|
154
154
|
|
|
155
155
|
<img src="docs/images/model-edit.png" alt="LocalChat User Menu" width="50%" />
|
|
156
156
|
|
|
157
|
-
1. **Copy
|
|
157
|
+
1. **Copy Assistant Id**: Now the assistant is displayed with its `name` and right underneath the `assistant-id`. Copy the `assistant-id`.
|
|
158
158
|
|
|
159
159
|
<img src="docs/images/model-id.png" alt="LocalChat User Menu" width="50%" />
|
|
160
160
|
|
|
@@ -276,7 +276,7 @@ new Remarkable().use(linkify)
|
|
|
276
276
|
|
|
277
277
|
${Array.from(e).sort((a,i)=>a-i).map(a=>{const o=r[a].name||"Untitled Reference";return`**[${a+1}]** ${o}`}).join(`
|
|
278
278
|
|
|
279
|
-
`)}`}function kc(r){if(!r||typeof r!="string")return r;const s=/\n\n---\n\n\*\*References:\*\*[\s\S]*$/;return r.replace(s,"").trim()}function Rr(r){if(X.group("Message History"),r.length===0){X.log("No messages in history");return}r.forEach((s,t)=>{const e=s.content.length>50?s.content.substring(0,50)+"...":s.content;X.log(`${t+1}. ${s.role.toUpperCase()}: ${e}`)})}function _c(r){let s,t,e,n,a,i,o,l,u,c,d,f,h,v,p,g,y,b,M,w,C;return{c(){s=ge("div"),t=ge("div"),e=ge("img"),a=ft(),i=ge("h3"),o=ss(r[1]),l=ft(),u=ge("div"),c=ge("button"),c.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 5V19M5 12H19" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>',d=ft(),f=ge("button"),h=on("svg"),v=on("path"),p=on("polyline"),g=on("line"),b=ft(),M=ge("button"),M.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6L6 18M6 6L18 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>',On(e.src,n=r[0])||j(e,"src",n),j(e,"alt","Headwai Chat Bubble"),j(e,"class","chat-header-icon svelte-1dl0fot"),j(i,"class","chat-title svelte-1dl0fot"),pt(i,"font-family",r[2]),j(c,"class","chat-new-button svelte-1dl0fot"),j(c,"aria-label","Start new chat"),j(c,"title","Start new chat"),j(v,"d","M21 15V19A2 2 0 0 1 19 21H5A2 2 0 0 1 3 19V15"),j(v,"stroke","currentColor"),j(v,"stroke-width","2"),j(v,"stroke-linecap","round"),j(v,"stroke-linejoin","round"),j(p,"points","7,10 12,15 17,10"),j(p,"stroke","currentColor"),j(p,"stroke-width","2"),j(p,"stroke-linecap","round"),j(p,"stroke-linejoin","round"),j(g,"x1","12"),j(g,"y1","15"),j(g,"x2","12"),j(g,"y2","3"),j(g,"stroke","currentColor"),j(g,"stroke-width","2"),j(g,"stroke-linecap","round"),j(g,"stroke-linejoin","round"),j(h,"width","16"),j(h,"height","16"),j(h,"viewBox","0 0 24 24"),j(h,"fill","none"),j(h,"xmlns","http://www.w3.org/2000/svg"),j(f,"class","chat-download-button svelte-1dl0fot"),j(f,"aria-label","Download chat history"),j(f,"title","Download chat history"),f.disabled=y=!r[4]||r[5].length===0,j(M,"class","chat-close-button svelte-1dl0fot"),j(M,"aria-label","Close chat"),j(M,"title","Close chat"),j(u,"class","chat-header-buttons svelte-1dl0fot"),j(t,"class","chat-header-content svelte-1dl0fot"),j(s,"class","chat-header svelte-1dl0fot"),pt(s,"background",r[3])},m(T,P){nn(T,s,P),ae(s,t),ae(t,e),ae(t,a),ae(t,i),ae(i,o),ae(t,l),ae(t,u),ae(u,c),ae(u,d),ae(u,f),ae(f,h),ae(h,v),ae(h,p),ae(h,g),ae(u,b),ae(u,M),w||(C=[je(c,"click",r[7]),je(c,"keydown",r[13]),je(f,"click",r[8]),je(f,"keydown",r[14]),je(M,"click",r[6]),je(M,"keydown",r[15])],w=!0)},p(T,[P]){P&1&&!On(e.src,n=T[0])&&j(e,"src",n),P&2&&di(o,T[1]),P&4&&pt(i,"font-family",T[2]),P&48&&y!==(y=!T[4]||T[5].length===0)&&(f.disabled=y),P&8&&pt(s,"background",T[3])},i:me,o:me,d(T){T&&yt(s),w=!1,et(C)}}}function Sc(r,s,t){let e,n;Ce(r,Rn,w=>t(4,e=w)),Ce(r,Ln,w=>t(5,n=w));let{iconPath:a}=s,{chatTitle:i}=s,{fontFamily:o}=s,{chatHeaderBackground:l}=s,{initialMessage:u}=s,{deepChatRef:c}=s,{
|
|
279
|
+
`)}`}function kc(r){if(!r||typeof r!="string")return r;const s=/\n\n---\n\n\*\*References:\*\*[\s\S]*$/;return r.replace(s,"").trim()}function Rr(r){if(X.group("Message History"),r.length===0){X.log("No messages in history");return}r.forEach((s,t)=>{const e=s.content.length>50?s.content.substring(0,50)+"...":s.content;X.log(`${t+1}. ${s.role.toUpperCase()}: ${e}`)})}function _c(r){let s,t,e,n,a,i,o,l,u,c,d,f,h,v,p,g,y,b,M,w,C;return{c(){s=ge("div"),t=ge("div"),e=ge("img"),a=ft(),i=ge("h3"),o=ss(r[1]),l=ft(),u=ge("div"),c=ge("button"),c.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 5V19M5 12H19" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>',d=ft(),f=ge("button"),h=on("svg"),v=on("path"),p=on("polyline"),g=on("line"),b=ft(),M=ge("button"),M.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6L6 18M6 6L18 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>',On(e.src,n=r[0])||j(e,"src",n),j(e,"alt","Headwai Chat Bubble"),j(e,"class","chat-header-icon svelte-1dl0fot"),j(i,"class","chat-title svelte-1dl0fot"),pt(i,"font-family",r[2]),j(c,"class","chat-new-button svelte-1dl0fot"),j(c,"aria-label","Start new chat"),j(c,"title","Start new chat"),j(v,"d","M21 15V19A2 2 0 0 1 19 21H5A2 2 0 0 1 3 19V15"),j(v,"stroke","currentColor"),j(v,"stroke-width","2"),j(v,"stroke-linecap","round"),j(v,"stroke-linejoin","round"),j(p,"points","7,10 12,15 17,10"),j(p,"stroke","currentColor"),j(p,"stroke-width","2"),j(p,"stroke-linecap","round"),j(p,"stroke-linejoin","round"),j(g,"x1","12"),j(g,"y1","15"),j(g,"x2","12"),j(g,"y2","3"),j(g,"stroke","currentColor"),j(g,"stroke-width","2"),j(g,"stroke-linecap","round"),j(g,"stroke-linejoin","round"),j(h,"width","16"),j(h,"height","16"),j(h,"viewBox","0 0 24 24"),j(h,"fill","none"),j(h,"xmlns","http://www.w3.org/2000/svg"),j(f,"class","chat-download-button svelte-1dl0fot"),j(f,"aria-label","Download chat history"),j(f,"title","Download chat history"),f.disabled=y=!r[4]||r[5].length===0,j(M,"class","chat-close-button svelte-1dl0fot"),j(M,"aria-label","Close chat"),j(M,"title","Close chat"),j(u,"class","chat-header-buttons svelte-1dl0fot"),j(t,"class","chat-header-content svelte-1dl0fot"),j(s,"class","chat-header svelte-1dl0fot"),pt(s,"background",r[3])},m(T,P){nn(T,s,P),ae(s,t),ae(t,e),ae(t,a),ae(t,i),ae(i,o),ae(t,l),ae(t,u),ae(u,c),ae(u,d),ae(u,f),ae(f,h),ae(h,v),ae(h,p),ae(h,g),ae(u,b),ae(u,M),w||(C=[je(c,"click",r[7]),je(c,"keydown",r[13]),je(f,"click",r[8]),je(f,"keydown",r[14]),je(M,"click",r[6]),je(M,"keydown",r[15])],w=!0)},p(T,[P]){P&1&&!On(e.src,n=T[0])&&j(e,"src",n),P&2&&di(o,T[1]),P&4&&pt(i,"font-family",T[2]),P&48&&y!==(y=!T[4]||T[5].length===0)&&(f.disabled=y),P&8&&pt(s,"background",T[3])},i:me,o:me,d(T){T&&yt(s),w=!1,et(C)}}}function Sc(r,s,t){let e,n;Ce(r,Rn,w=>t(4,e=w)),Ce(r,Ln,w=>t(5,n=w));let{iconPath:a}=s,{chatTitle:i}=s,{fontFamily:o}=s,{chatHeaderBackground:l}=s,{initialMessage:u}=s,{deepChatRef:c}=s,{assistantId:d}=s,{apiUrl:f}=s;function h(){jn.set(!1)}function v(){Rn.set(null),Ln.set([]),In.set([]),Mn.set(""),An.set(""),xn.set([]),p([{role:"assistant",content:u}]),c&&(c.clearMessages(),c.addMessage({text:u,role:"ai"},!1))}async function p(w){var C;try{const T=Math.floor(Date.now()/1e3),P=[d],L=[],K={};let R=null;w.forEach(($,ie)=>{const Y=Wt(),re=ie<w.length-1?Wt():null,ce={id:Y,parentId:R,childrenIds:re?[re]:[],role:$.role,content:$.content,timestamp:T,models:P};$.role==="assistant"&&(ce.model=P[0],ce.modelId=P[0],ce.modelIdx=0),L.push(ce),K[Y]=ce,R=Y}),L.forEach(($,ie)=>{ie<L.length-1&&($.childrenIds=[L[ie+1].id])});const x=(C=L[L.length-1])==null?void 0:C.id,S={assistantId:d,chat:{id:"",title:"New Chatbubble Chat",models:P,params:{},history:{messages:K,currentId:x},messages:L,tags:[],timestamp:Date.now()},folder_id:null},I=`${f}/api/v1/chats/new`,G=await fetch(I,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(S)});if(G.ok){const $=await G.json();return Rn.set($.id),X.log("New chat created with ID:",e),Ln.set(L),Rr(n),e}else return X.error("Failed to create new chat:",G.statusText),null}catch{return null}}function g(){if(!e||c.getMessages().length===0)return;let w=`Chat ID: ${e}
|
|
280
280
|
|
|
281
281
|
`;c.getMessages().forEach(L=>{if(X.log("Processing message for download:",L),L.role!=="feedback"){const K=L.role.toUpperCase();if(X.log(`Adding ${K} message to download content`),L.custom&&L.custom.timestamp){const R=new Date(L.custom.timestamp*1e3).toLocaleString();w+=`[${R}]
|
|
282
282
|
|
|
@@ -286,7 +286,7 @@ ${L.text}
|
|
|
286
286
|
`,X.log(`Message timestamp: ${R}, content: ${w}`)}else w+=`[${K}]:
|
|
287
287
|
${L.text}
|
|
288
288
|
|
|
289
|
-
`,X.log(`Message content: ${w}`)}});const C=new Blob([w],{type:"text/plain"}),T=URL.createObjectURL(C),P=document.createElement("a");P.href=T,P.download=`chat-history-${e}.txt`,document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(T),X.log("Message history downloaded")}fi(()=>{v()});const y=w=>w.key==="Enter"&&v(),b=w=>w.key==="Enter"&&g(),M=w=>w.key==="Enter"&&h();return r.$$set=w=>{"iconPath"in w&&t(0,a=w.iconPath),"chatTitle"in w&&t(1,i=w.chatTitle),"fontFamily"in w&&t(2,o=w.fontFamily),"chatHeaderBackground"in w&&t(3,l=w.chatHeaderBackground),"initialMessage"in w&&t(9,u=w.initialMessage),"deepChatRef"in w&&t(10,c=w.deepChatRef),"
|
|
289
|
+
`,X.log(`Message content: ${w}`)}});const C=new Blob([w],{type:"text/plain"}),T=URL.createObjectURL(C),P=document.createElement("a");P.href=T,P.download=`chat-history-${e}.txt`,document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(T),X.log("Message history downloaded")}fi(()=>{v()});const y=w=>w.key==="Enter"&&v(),b=w=>w.key==="Enter"&&g(),M=w=>w.key==="Enter"&&h();return r.$$set=w=>{"iconPath"in w&&t(0,a=w.iconPath),"chatTitle"in w&&t(1,i=w.chatTitle),"fontFamily"in w&&t(2,o=w.fontFamily),"chatHeaderBackground"in w&&t(3,l=w.chatHeaderBackground),"initialMessage"in w&&t(9,u=w.initialMessage),"deepChatRef"in w&&t(10,c=w.deepChatRef),"assistantId"in w&&t(11,d=w.assistantId),"apiUrl"in w&&t(12,f=w.apiUrl)},[a,i,o,l,e,n,h,v,g,u,c,d,f,y,b,M]}class Ec extends qn{constructor(s){super(),Hn(this,s,Sc,_c,tn,{iconPath:0,chatTitle:1,fontFamily:2,chatHeaderBackground:3,initialMessage:9,deepChatRef:10,assistantId:11,apiUrl:12})}}function wc(r){let s,t,e,n,a;return{c(){s=ge("div"),t=ge("img"),On(t.src,e=r[1])||j(t,"src",e),j(t,"alt","Headwai Chat Bubble"),j(t,"class","svelte-15lda29"),j(s,"class","ai-assistant-icon svelte-15lda29"),pt(s,"background",r[0]),j(s,"role","button"),j(s,"tabindex","0")},m(i,o){nn(i,s,o),ae(s,t),n||(a=[je(s,"click",r[2]),je(s,"keydown",r[3])],n=!0)},p(i,[o]){o&2&&!On(t.src,e=i[1])&&j(t,"src",e),o&1&&pt(s,"background",i[0])},i:me,o:me,d(i){i&&yt(s),n=!1,et(a)}}}function Cc(r,s,t){let e;Ce(r,jn,l=>t(4,e=l));let{faviconBackgroundColor:n}=s,{iconPath:a}=s;function i(){jn.set(!e)}const o=l=>l.key==="Enter"&&i();return r.$$set=l=>{"faviconBackgroundColor"in l&&t(0,n=l.faviconBackgroundColor),"iconPath"in l&&t(1,a=l.iconPath)},[n,a,i,o]}class Tc extends qn{constructor(s){super(),Hn(this,s,Cc,wc,tn,{faviconBackgroundColor:0,iconPath:1})}}function Ac(r){let s,t;return{c(){s=ge("div"),t=ge("deep-chat"),Le(t,"demo","false"),Le(t,"textInput",r[1]),Le(t,"messageStyles",r[2]),Le(t,"history",r[3]),Le(t,"connect",r[4]),Le(t,"requestBodyLimits",r[5]),Le(t,"requestInterceptor",r[6]),Le(t,"responseInterceptor",r[7]),Le(t,"onMessage",r[8]),j(s,"class","chat-content svelte-i2r2w9")},m(e,n){nn(e,s,n),ae(s,t),r[22](t)},p:me,i:me,o:me,d(e){e&&yt(s),r[22](null)}}}function Mc(r){return r.map(s=>{let t=s.text||s.content;return{role:s.role==="ai"?"assistant":s.role,content:t}})}function xc(r,s,t){let e,n,a,i,o,l;Ce(r,Ln,A=>t(23,e=A)),Ce(r,Rn,A=>t(24,n=A)),Ce(r,xn,A=>t(25,a=A)),Ce(r,Mn,A=>t(26,i=A)),Ce(r,An,A=>t(27,o=A)),Ce(r,In,A=>t(28,l=A));let{deepChatRef:u}=s,{placeholderText:c}=s,{fontFamily:d}=s,{fontSize:f}=s,{userMessageBackgroundColor:h}=s,{userMessageTextColor:v}=s,{aiMessageBackgroundColor:p}=s,{aiMessageTextColor:g}=s,{feedbackMessageBackgroundColor:y}=s,{feedbackMessageTextColor:b}=s,{initialMessage:M}=s,{apiUrl:w}=s,{assistantId:C}=s,{maxMessages:T}=s;const P={placeholder:{text:c},styles:{container:{fontFamily:d,fontSize:f}}},L={default:{shared:{bubble:{fontFamily:d,fontSize:f}},user:{bubble:{backgroundColor:h,color:v}},ai:{bubble:{backgroundColor:p,color:g}},feedback:{bubble:{backgroundColor:y,color:b}}}},K=[{role:"ai",text:M,custom:{timestamp:Math.floor(Date.now()/1e3)}}],R={type:"websocket",url:`${w}/api/chat/completions`,headers:{"Content-Type":"application/json"},additionalBodyProps:{model:C,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"},...n&&{chat_id:n},background_tasks:{title_generation:!0,tags_generation:!1,follow_up_generation:!1}},stream:!0},x={maxMessages:T},S=async A=>{if(A.body&&A.body.messages){A.body.messages=Mc(A.body.messages).map(Z=>(Z.role==="assistant"&&Z.content&&(Z.content=kc(Z.content)),Z)),A.body.messages=A.body.messages.filter(Z=>Z.role!=="feedback");const W=A.body.messages.filter(Z=>Z.role==="user");W.length>0&&An.set(W[W.length-1].content),n&&(A.body.chat_id=n)}return A},D=A=>{X.log(A),A.sources&&Array.isArray(A.sources)&&(xn.set(A.sources),X.log(`Found ${A.sources.length} sources in response`),X.log("assistantMessageSources:",A.sources));try{const W=yc(A);W.length>0&&(In.set(W),X.log(`Found ${W.length} references in response`))}catch{}if(A.choices&&A.choices[0]&&A.choices[0].delta){const W=A.choices[0].delta,Z=W.content||"";return Z&&Mn.update(Q=>Q+Z),A.choices[0].finish_reason&&X.log("Streaming response ended"),{text:Z,role:W.role==="assistant"?"ai":W.role||"ai"}}if(A.choices&&A.choices[0]&&A.choices[0].message){const W=A.choices[0].message;return X.log("Non-streaming response received"),{text:W.content,role:W.role==="assistant"?"ai":W.role}}return A.text||A.html||A.files?A:typeof A=="string"?{text:A}:A};async function I(A){const{message:W,isHistory:Z}=A;if(X.log(A),!Z&&(W.role==="ai"||W.role==="assistant")){X.log("🤖 AI answered:",W.text);const Q=W.text||"";let _e=Q;if(l.length>0&&u){X.log("📚 Formatting and updating AI message with references");const we=bc(l,Q);_e=Q+we,we?(X.log("Found inline citations, adding references"),u.updateMessage({text:_e},u.getMessages().length-1)):X.log("No inline citations found, skipping references")}u.scrollToBottom(),G(o,i,a);const ve=e.filter(we=>we.role==="assistant").pop();X.log("Last assistant message:",ve);const Ee=ve?ve.id:Wt();X.log("Using assistant message ID for feedback:",Ee);const Ie=u.getMessages().length;u.addMessage({html:`
|
|
290
290
|
<div class="feedback">
|
|
291
291
|
<div class="feedback-icons">
|
|
292
292
|
<span class="feedback-icon feedback-icon-positive" title="Good response" onclick="window.handleFeedback('${Ee}', 'positive', '${Ie}')" style="cursor: pointer;">
|
|
@@ -325,7 +325,7 @@ ${L.text}
|
|
|
325
325
|
</span>
|
|
326
326
|
</div>
|
|
327
327
|
</div>
|
|
328
|
-
`,role:"feedback"}),An.set(""),Mn.set(""),xn.set([]),In.set([])}}async function G(A,W,Z){if(n){X.log("assistantMessageSources:",Z);try{const Q=Math.floor(Date.now()/1e3),_e=[C],ve=Wt(),Ee=Wt(),Ie=e[e.length-1],we={id:ve,parentId:Ie?Ie.id:null,childrenIds:[Ee],role:"user",content:A,timestamp:Q,models:_e},Re={id:Ee,parentId:ve,childrenIds:[],role:"assistant",content:W,model:_e[0],modelId:_e[0],modelIdx:0,timestamp:Q,sources:Z};Ie&&(Ie.childrenIds=[ve]),e.push(we,Re);const oe={};e.forEach(Zr=>{oe[Zr.id]=Zr});const ai={
|
|
328
|
+
`,role:"feedback"}),An.set(""),Mn.set(""),xn.set([]),In.set([])}}async function G(A,W,Z){if(n){X.log("assistantMessageSources:",Z);try{const Q=Math.floor(Date.now()/1e3),_e=[C],ve=Wt(),Ee=Wt(),Ie=e[e.length-1],we={id:ve,parentId:Ie?Ie.id:null,childrenIds:[Ee],role:"user",content:A,timestamp:Q,models:_e},Re={id:Ee,parentId:ve,childrenIds:[],role:"assistant",content:W,model:_e[0],modelId:_e[0],modelIdx:0,timestamp:Q,sources:Z};Ie&&(Ie.childrenIds=[ve]),e.push(we,Re);const oe={};e.forEach(Zr=>{oe[Zr.id]=Zr});const ai={assistantId:C,chat:{models:_e,history:{messages:oe,currentId:Ee},messages:e,params:{}}},si=`${w}/api/v1/chats/${n}`,Yr=await fetch(si,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ai)});Yr.ok?(X.log("Chat history stored successfully"),Rr(e)):X.error("Failed to store chat history:",Yr.statusText)}catch{}}}async function $(A,W,Z){Y(A,W,Z),X.log(`Feedback recorded for message ${A}: ${W}`);const _e=await ie(A,W==="positive"?1:-1);await re(A,_e)}async function ie(A,W){var Z;try{if(!n){X.error("Cannot send feedback: no chat ID available");return}if(!e.find(oe=>oe.id===A)){X.error(`Message not found in history for feedback ID: ${A}`);return}const _e=e.findIndex(oe=>oe.id===A),ve={assistantId:C,type:"rating",data:{rating:W,model_id:C},meta:{model_id:C,message_id:A,message_index:_e,chat_id:n,base_models:{[C]:C}},snapshot:{chat:{id:n,user_id:null,title:"New Chatbubble Chat",chat:{id:"",title:"New Chatbubble Chat",models:[C],params:{},history:{messages:{},currentId:A},messages:e,params:{}},updated_at:Date.now(),created_at:Date.now(),share_id:null,archived:!1,pinned:!1,meta:{},folder_id:null}}},Ee={};e.forEach(oe=>{Ee[oe.id]=oe}),ve.snapshot.chat.chat.history.messages=Ee,ve.snapshot.chat.chat.history.currentId=(Z=e[e.length-1])==null?void 0:Z.id;const we=`${w}/api/v1/evaluations/feedback`,Re=await fetch(we,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(ve)});if(Re.ok){const oe=await Re.json();return X.log("Feedback sent successfully:",oe),oe}else{const oe=await Re.json().catch(()=>null);X.error("Failed to send feedback:",Re.statusText,oe)}}catch{}return null}function Y(A,W,Z){X.log(A,W,Z),W==="positive"?u.updateMessage({html:`
|
|
329
329
|
<div class="feedback">
|
|
330
330
|
<div class="feedback-icons">
|
|
331
331
|
<span class="feedback-icon feedback-icon-positive" title="Good response" onclick="window.handleFeedback('${A}', 'positive', ${Z})" style="cursor: pointer;">
|
|
@@ -403,4 +403,4 @@ ${L.text}
|
|
|
403
403
|
</span>
|
|
404
404
|
</div>
|
|
405
405
|
</div>
|
|
406
|
-
`,role:"feedback"},Z)}async function re(A,W){if(!(!n||!W||!A||(e.forEach(Q=>{Q.id===A&&Q.role==="assistant"&&(Q.feedbackId=W.id,Q.annotation={rating:W.data.rating})}),!e.find(Q=>Q.id===A))))try{const Q=e.filter(oe=>oe.role==="assistant");if(Q.length===0){X.error("No assistant messages found to update with feedback");return}const _e=Q[Q.length-1],ve={};e.forEach(oe=>{ve[oe.id]=oe});const Ee={
|
|
406
|
+
`,role:"feedback"},Z)}async function re(A,W){if(!(!n||!W||!A||(e.forEach(Q=>{Q.id===A&&Q.role==="assistant"&&(Q.feedbackId=W.id,Q.annotation={rating:W.data.rating})}),!e.find(Q=>Q.id===A))))try{const Q=e.filter(oe=>oe.role==="assistant");if(Q.length===0){X.error("No assistant messages found to update with feedback");return}const _e=Q[Q.length-1],ve={};e.forEach(oe=>{ve[oe.id]=oe});const Ee={assistantId:C,chat:{models:[C],history:{messages:ve,currentId:_e.id},messages:e,params:{}}},we=`${w}/api/v1/chats/${n}`,Re=await fetch(we,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Ee)});Re.ok?(X.log("Assistant message updated with feedback successfully"),Rr(e)):X.error("Failed to update assistant message with feedback:",Re.statusText)}catch{}}typeof window<"u"&&(window.handleFeedback=$);function ce(A){Pn[A?"unshift":"push"](()=>{u=A,t(0,u)})}return r.$$set=A=>{"deepChatRef"in A&&t(0,u=A.deepChatRef),"placeholderText"in A&&t(9,c=A.placeholderText),"fontFamily"in A&&t(10,d=A.fontFamily),"fontSize"in A&&t(11,f=A.fontSize),"userMessageBackgroundColor"in A&&t(12,h=A.userMessageBackgroundColor),"userMessageTextColor"in A&&t(13,v=A.userMessageTextColor),"aiMessageBackgroundColor"in A&&t(14,p=A.aiMessageBackgroundColor),"aiMessageTextColor"in A&&t(15,g=A.aiMessageTextColor),"feedbackMessageBackgroundColor"in A&&t(16,y=A.feedbackMessageBackgroundColor),"feedbackMessageTextColor"in A&&t(17,b=A.feedbackMessageTextColor),"initialMessage"in A&&t(18,M=A.initialMessage),"apiUrl"in A&&t(19,w=A.apiUrl),"assistantId"in A&&t(20,C=A.assistantId),"maxMessages"in A&&t(21,T=A.maxMessages)},[u,P,L,K,R,x,S,D,I,c,d,f,h,v,p,g,y,b,M,w,C,T,ce]}class Ic extends qn{constructor(s){super(),Hn(this,s,xc,Ac,tn,{deepChatRef:0,placeholderText:9,fontFamily:10,fontSize:11,userMessageBackgroundColor:12,userMessageTextColor:13,aiMessageBackgroundColor:14,aiMessageTextColor:15,feedbackMessageBackgroundColor:16,feedbackMessageTextColor:17,initialMessage:18,apiUrl:19,assistantId:20,maxMessages:21},null,[-1,-1])}}function ts(r){let s,t;return s=new Tc({props:{faviconBackgroundColor:r[15],iconPath:r[13]}}),{c(){or(s.$$.fragment)},m(e,n){Nn(s,e,n),t=!0},p:me,i(e){t||(Te(s.$$.fragment,e),t=!0)},o(e){We(s.$$.fragment,e),t=!1},d(e){Bn(s,e)}}}function ns(r){let s,t,e,n,a,i;t=new Ec({props:{iconPath:r[13],chatTitle:r[9]||void 0||"Headwai Chat Bubble",fontFamily:r[14],chatHeaderBackground:r[15],initialMessage:r[12],deepChatRef:r[10],assistantId:r[16],apiUrl:r[17]}});function o(u){r[24](u)}let l={placeholderText:r[1]||void 0||"Enter your questions here",fontFamily:r[14],fontSize:r[8]||void 0||"inherit",userMessageBackgroundColor:r[2]||void 0||"#007bff",userMessageTextColor:r[4]||void 0||"#000000",aiMessageBackgroundColor:r[3]||void 0||"#f1f3f4",aiMessageTextColor:r[5]||void 0||"#000000",feedbackMessageBackgroundColor:r[6]||void 0||"#ffffff",feedbackMessageTextColor:r[7]||void 0||"#000000",initialMessage:r[12],apiUrl:r[17],assistantId:r[16],maxMessages:parseInt(r[0]||void 0)||0};return r[10]!==void 0&&(l.deepChatRef=r[10]),n=new Ic({props:l}),Pn.push(()=>bi(n,"deepChatRef",o)),{c(){s=ge("div"),or(t.$$.fragment),e=ft(),or(n.$$.fragment),j(s,"class","chat-container svelte-hopfzj")},m(u,c){nn(u,s,c),Nn(t,s,null),ae(s,e),Nn(n,s,null),i=!0},p(u,c){const d={};c&512&&(d.chatTitle=u[9]||void 0||"Headwai Chat Bubble"),c&1024&&(d.deepChatRef=u[10]),t.$set(d);const f={};c&2&&(f.placeholderText=u[1]||void 0||"Enter your questions here"),c&256&&(f.fontSize=u[8]||void 0||"inherit"),c&4&&(f.userMessageBackgroundColor=u[2]||void 0||"#007bff"),c&16&&(f.userMessageTextColor=u[4]||void 0||"#000000"),c&8&&(f.aiMessageBackgroundColor=u[3]||void 0||"#f1f3f4"),c&32&&(f.aiMessageTextColor=u[5]||void 0||"#000000"),c&64&&(f.feedbackMessageBackgroundColor=u[6]||void 0||"#ffffff"),c&128&&(f.feedbackMessageTextColor=u[7]||void 0||"#000000"),c&1&&(f.maxMessages=parseInt(u[0]||void 0)||0),!a&&c&1024&&(a=!0,f.deepChatRef=u[10],vi(()=>a=!1)),n.$set(f)},i(u){i||(Te(t.$$.fragment,u),Te(n.$$.fragment,u),i=!0)},o(u){We(t.$$.fragment,u),We(n.$$.fragment,u),i=!1},d(u){u&&yt(s),Bn(t),Bn(n)}}}function Rc(r){let s,t,e,n=!r[11]&&ts(r),a=r[11]&&ns(r);return{c(){s=ge("main"),n&&n.c(),t=ft(),a&&a.c(),j(s,"class","svelte-hopfzj")},m(i,o){nn(i,s,o),n&&n.m(s,null),ae(s,t),a&&a.m(s,null),e=!0},p(i,[o]){i[11]?n&&(Qr(),We(n,1,1,()=>{n=null}),ea()):n?(n.p(i,o),o&2048&&Te(n,1)):(n=ts(i),n.c(),Te(n,1),n.m(s,t)),i[11]?a?(a.p(i,o),o&2048&&Te(a,1)):(a=ns(i),a.c(),Te(a,1),a.m(s,null)):a&&(Qr(),We(a,1,1,()=>{a=null}),ea())},i(i){e||(Te(n),Te(a),e=!0)},o(i){We(n),We(a),e=!1},d(i){i&&yt(s),n&&n.d(),a&&a.d()}}}function Lc(r,s,t){let e;Ce(r,jn,S=>t(11,e=S));let{apiUrl:n=void 0}=s,{assistantId:a=void 0}=s,{maxMessages:i=void 0}=s,{placeholderText:o=void 0}=s,{faviconPath:l=void 0}=s,{initialMessage:u=void 0}=s,{userMessageBackgroundColor:c=void 0}=s,{aiMessageBackgroundColor:d=void 0}=s,{userMessageTextColor:f=void 0}=s,{aiMessageTextColor:h=void 0}=s,{feedbackMessageBackgroundColor:v=void 0}=s,{feedbackMessageTextColor:p=void 0}=s,{faviconBackgroundColor:g=void 0}=s,{fontFamily:y=void 0}=s,{fontSize:b=void 0}=s,{chatTitle:M=void 0}=s,w;const C=u||void 0||"Hey, how can I help you?",T=l||void 0||gc,P=y||void 0||"inherit",L=g||void 0||"#667eea",K=a||void 0||"test-model",R=(n||void 0||"https://localhost").replace(/\/$/,"");function x(S){w=S,t(10,w)}return r.$$set=S=>{"apiUrl"in S&&t(18,n=S.apiUrl),"assistantId"in S&&t(19,a=S.assistantId),"maxMessages"in S&&t(0,i=S.maxMessages),"placeholderText"in S&&t(1,o=S.placeholderText),"faviconPath"in S&&t(20,l=S.faviconPath),"initialMessage"in S&&t(21,u=S.initialMessage),"userMessageBackgroundColor"in S&&t(2,c=S.userMessageBackgroundColor),"aiMessageBackgroundColor"in S&&t(3,d=S.aiMessageBackgroundColor),"userMessageTextColor"in S&&t(4,f=S.userMessageTextColor),"aiMessageTextColor"in S&&t(5,h=S.aiMessageTextColor),"feedbackMessageBackgroundColor"in S&&t(6,v=S.feedbackMessageBackgroundColor),"feedbackMessageTextColor"in S&&t(7,p=S.feedbackMessageTextColor),"faviconBackgroundColor"in S&&t(22,g=S.faviconBackgroundColor),"fontFamily"in S&&t(23,y=S.fontFamily),"fontSize"in S&&t(8,b=S.fontSize),"chatTitle"in S&&t(9,M=S.chatTitle)},[i,o,c,d,f,h,v,p,b,M,w,e,C,T,P,L,K,R,n,a,l,u,g,y,x]}class Lr extends qn{constructor(s){super(),Hn(this,s,Lc,Rc,tn,{apiUrl:18,assistantId:19,maxMessages:0,placeholderText:1,faviconPath:20,initialMessage:21,userMessageBackgroundColor:2,aiMessageBackgroundColor:3,userMessageTextColor:4,aiMessageTextColor:5,feedbackMessageBackgroundColor:6,feedbackMessageTextColor:7,faviconBackgroundColor:22,fontFamily:23,fontSize:8,chatTitle:9})}}function ri(){const r={apiUrl:void 0,assistantId:void 0,maxMessages:void 0,placeholderText:void 0,userMessageBackgroundColor:void 0,aiMessageBackgroundColor:void 0,userMessageTextColor:void 0,aiMessageTextColor:void 0,faviconBackgroundColor:void 0,chatTitle:void 0},s=typeof window<"u"&&window.HEADWAI_CHAT_BUBBLE_CONFIG||{};return{...r,...s}}typeof window<"u"&&window.document&&document.addEventListener("DOMContentLoaded",()=>{const r=ri(),s=document.querySelectorAll("[data-chat-bubble]");if(s.length===0){const t=document.getElementById("chat-bubble-container");t&&new Lr({target:t,props:r})}else s.forEach(t=>{const e={...r},n={chatBubbleApiUrl:"apiUrl",chatBubbleAssistantId:"assistantId",chatBubbleMaxMessages:"maxMessages",chatBubblePlaceholderText:"placeholderText",chatBubbleFaviconPath:"faviconPath",chatBubbleInitialMessage:"initialMessage",chatBubbleUserMessageBackgroundColor:"userMessageBackgroundColor",chatBubbleAiMessageBackgroundColor:"aiMessageBackgroundColor",chatBubbleUserMessageTextColor:"userMessageTextColor",chatBubbleAiMessageTextColor:"aiMessageTextColor",chatBubbleFaviconBackgroundColor:"faviconBackgroundColor",chatBubbleChatTitle:"chatTitle"};Object.keys(t.dataset).forEach(a=>{n[a]&&(e[n[a]]=t.dataset[a])}),new Lr({target:t,props:e})})});window.ChatBubble={init:(r,s={})=>new Lr({target:r,props:{...ri(),...s}})};
|