@nabeh/chat-widget 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var ie=Object.defineProperty;var ut=Object.getOwnPropertyDescriptor;var gt=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var ht=(e,t)=>{for(var n in t)ie(e,n,{get:t[n],enumerable:!0})},mt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of gt(t))!ft.call(e,i)&&i!==n&&ie(e,i,{get:()=>t[i],enumerable:!(r=ut(t,i))||r.enumerable});return e};var bt=e=>mt(ie({},"__esModule",{value:!0}),e);var Ct={};ht(Ct,{browserGlobal:()=>Ye,createChatWidget:()=>G,init:()=>Xe,version:()=>Fe});module.exports=bt(Ct);function ze(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function pe(e,t){let n={...e};for(let r of Object.keys(t)){let i=t[r],l=n[r];if(ze(l)&&ze(i)){n[r]=pe(l,i);continue}i!==void 0&&(n[r]=i)}return n}function We(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function V(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}function D(e,t,n){return{"Content-Type":"application/json",...e.customHeaders,...n?{"X-Chat-User-Context":n}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function _(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function le(e,t,n={}){let r=t.replace(/\{chatId\}/g,encodeURIComponent(n.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(n.chatId??""));return V(e.apiBaseUrl,r)}async function Ne(e,t){let n=e.getAccessToken?await e.getAccessToken():null,r=await _(e),i=le(e,e.endpoints.ask,{chatId:t.chatId}),s=/(\{chatId\}|:chatId\b)/.test(e.endpoints.ask)?{message:t.message,knowledgeNames:t.knowledgeNames,editLastQa:t.editLastQa??!1,enableReferences:t.enableReferences??!0}:{query:t.message,chat_id:t.chatId,knowledge_names:t.knowledgeNames,edit_last_qa:t.editLastQa??!1,enable_references:t.enableReferences??!0},u=await fetch(i,{method:"POST",headers:D(e,n,r),body:JSON.stringify(s)});if(!u.ok)throw new Error(`Chat backend returned ${u.status}.`);let p=await u.json();if(!Array.isArray(p)){if(!p.answer||typeof p.answer!="string")throw new Error("Chat backend response is missing a valid answer.");return{chatId:p.chatId??t.chatId,answer:p.answer,suggestions:p.suggestions??[],citations:p.citations??[]}}let c=p[0];if(!c?.answer||typeof c.answer!="string")throw new Error("Chat backend response is missing a valid answer.");let f=c.content,g=f?.source_documents??[],m=f?.scores??[],z=f?.page_numbers??[],W=f?.sheet_names??[],N=f?.row_numbers??[],q=f?.knowledge_names??[],J=g.map((Q,b)=>({sourceDocument:Q,score:m[b]??null,pageNumber:z[b]??null,sheetName:W[b]??null,rowNumber:N[b]??null,knowledgeName:q[b]??null}));return{chatId:t.chatId,answer:c.answer,suggestions:[],citations:J}}async function Oe(e,t){if(!e.endpoints.history)return[];let n=e.getAccessToken?await e.getAccessToken():null,r=await _(e),l=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?le(e,e.endpoints.history,{chatId:t}):(()=>{let p=new URL(V(e.apiBaseUrl,e.endpoints.history));return p.searchParams.set("chat_id",t),p.toString()})(),s=await fetch(l,{method:"GET",headers:D(e,n,r)});if(!s.ok)throw new Error(`Chat history endpoint returned ${s.status}.`);let u=await s.json();return Array.isArray(u)?u.map(p=>{if(!p||typeof p!="object")return null;let c=p,f=c.role??c.type??c.sender??c.author,g=c.text??c.message??c.content??c.answer;if(typeof g!="string")return null;let m=typeof f=="string"?f.toLowerCase():"assistant";return{role:m==="user"||m==="human"?"user":"assistant",text:g}}).filter(p=>!!p):[]}async function Be(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,n=await _(e),r=await fetch(V(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:D(e,t,n)});if(!r.ok)throw new Error(`Chat list endpoint returned ${r.status}.`);let i=await r.json();return Array.isArray(i)?i.map(l=>{if(!l||typeof l!="object")return null;let s=l,u=s.chatId??s.chat_id??s.id,p=s.title??s.name??s.chatId;if(typeof u!="string"||typeof p!="string")return null;let c=typeof s.createdAt=="string"?s.createdAt:typeof s.created_at=="string"?s.created_at:null,f=typeof s.updatedAt=="string"?s.updatedAt:typeof s.updated_at=="string"?s.updated_at:null,g={chatId:u,title:p,pinned:typeof s.pinned=="boolean"?s.pinned:!1};return c&&(g.createdAt=c),f&&(g.updatedAt=f),g}).filter(l=>!!l):[]}async function Ue(e,t,n){let r=e.endpoints.createChat??e.endpoints.listChats;if(!r)return;let i=e.getAccessToken?await e.getAccessToken():null,l=await _(e),s=await fetch(V(e.apiBaseUrl,r),{method:"POST",headers:D(e,i,l),body:JSON.stringify({chatId:t,...n?{title:n}:{}})});if(!s.ok)throw new Error(`Create chat endpoint returned ${s.status}.`)}async function $e(e,t,n){if(!e.endpoints.updateChat)return;let r=e.getAccessToken?await e.getAccessToken():null,i=await _(e),l=le(e,e.endpoints.updateChat,{chatId:t}),s=await fetch(l,{method:"PATCH",headers:D(e,r,i),body:JSON.stringify(n)});if(!s.ok)throw new Error(`Update chat endpoint returned ${s.status}.`)}function j(e,t){let n=We(t);return e.onError?.(n),n}var de={accent:"#0f766e",accentSoft:"#ecfeff",panelBackground:"#ffffff",surfaceBackground:"#f8fafc",text:"#1f2937",mutedText:"#64748b",borderColor:"#dbe4ee",shadow:"0 24px 64px rgba(15, 23, 42, 0.20)",zIndex:2147483e3,fontFamily:'"Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif'},h={position:"bottom-right",title:"Knowledge Assistant",subtitle:"Answers are generated based on your access permissions",welcomeMessage:"How can I assist you today?",inputPlaceholder:"Ask your question...",launcherAriaLabel:"Open chat assistant",closeAriaLabel:"Close chat assistant",initialSuggestions:["Which indicators reflect the achievements of Vision KSA goals?","Case studies of real estate initiatives for economic growth","Study of UX for the ministry external portal"],sourceApp:"knowledge-platform",locale:"en",customHeaders:{},rag:{knowledgeNames:[],enableReferences:!0,loadHistoryOnOpen:!1},theme:de,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0};function Ve(e){if(!e.apiBaseUrl?.trim())throw new Error("Chat widget config requires a non-empty apiBaseUrl.");if(!e.endpoints?.ask?.trim())throw new Error("Chat widget config requires endpoints.ask to be provided.");let t=e.mount??document.body,n=pe(de,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,position:e.position??h.position,title:e.title??h.title,subtitle:e.subtitle??h.subtitle,welcomeMessage:e.welcomeMessage??h.welcomeMessage,inputPlaceholder:e.inputPlaceholder??h.inputPlaceholder,launcherAriaLabel:e.launcherAriaLabel??h.launcherAriaLabel,closeAriaLabel:e.closeAriaLabel??h.closeAriaLabel,initialSuggestions:e.initialSuggestions??h.initialSuggestions,sourceApp:e.sourceApp??h.sourceApp,locale:e.locale??h.locale,customHeaders:e.customHeaders??h.customHeaders,rag:{...h.rag,...e.rag??{}},theme:n,getAccessToken:e.getAccessToken,getUserContext:e.getUserContext,onOpen:e.onOpen,onClose:e.onClose,onError:e.onError}}function o(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=n),r}var De="kp-chat-widget-styles";function _e(e,t){if(e.getElementById(De))return;let n=document.createElement("style");n.id=De,n.textContent=kt(t),e.appendChild(n)}function kt(e){return`
1
+ "use strict";var we=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Jt=Object.prototype.hasOwnProperty;var Qt=(e,t)=>{for(var o in t)we(e,o,{get:t[o],enumerable:!0})},Zt=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gt(t))!Jt.call(e,i)&&i!==o&&we(e,i,{get:()=>t[i],enumerable:!(n=Yt(t,i))||n.enumerable});return e};var en=e=>Zt(we({},"__esModule",{value:!0}),e);var Sn={};Qt(Sn,{browserGlobal:()=>Ct,createChatWidget:()=>de,init:()=>vt,version:()=>wt});module.exports=en(Sn);function ot(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ve(e,t){let o={...e};for(let n of Object.keys(t)){let i=t[n],s=o[n];if(ot(s)&&ot(i)){o[n]=ve(s,i);continue}i!==void 0&&(o[n]=i)}return o}function at(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function X(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}function O(e,t,o){return{"Content-Type":"application/json",...e.customHeaders,...o?{"X-Chat-User-Context":o}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function W(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function pe(e,t,o={}){let n=t.replace(/\{chatId\}/g,encodeURIComponent(o.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(o.chatId??""));return X(e.apiBaseUrl,n)}async function st(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),i=pe(e,e.endpoints.ask,{chatId:t.chatId}),d=/(\{chatId\}|:chatId\b)/.test(e.endpoints.ask)?{message:t.message,knowledgeNames:t.knowledgeNames,editLastQa:t.editLastQa??!1,enableReferences:t.enableReferences??!0}:{query:t.message,chat_id:t.chatId,knowledge_names:t.knowledgeNames,edit_last_qa:t.editLastQa??!1,enable_references:t.enableReferences??!0},l=await fetch(i,{method:"POST",headers:O(e,o,n),body:JSON.stringify(d)});if(!l.ok)throw new Error(`Chat backend returned ${l.status}.`);let p=await l.json();if(!Array.isArray(p)){if(!p.answer||typeof p.answer!="string")throw new Error("Chat backend response is missing a valid answer.");return{chatId:p.chatId??t.chatId,answer:p.answer,suggestions:p.suggestions??[],citations:p.citations??[]}}let u=p[0];if(!u?.answer||typeof u.answer!="string")throw new Error("Chat backend response is missing a valid answer.");let g=u.content,f=g?.source_documents??[],m=g?.scores??[],y=g?.page_numbers??[],b=g?.sheet_names??[],x=g?.row_numbers??[],v=g?.knowledge_names??[],k=f.map(($,C)=>({sourceDocument:$,score:m[C]??null,pageNumber:y[C]??null,sheetName:b[C]??null,rowNumber:x[C]??null,knowledgeName:v[C]??null}));return{chatId:t.chatId,answer:u.answer,suggestions:[],citations:k}}async function rt(e,t){if(!e.endpoints.history)return[];let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),s=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?pe(e,e.endpoints.history,{chatId:t}):(()=>{let u=new URL(X(e.apiBaseUrl,e.endpoints.history));return u.searchParams.set("chat_id",t),u.toString()})(),d=await fetch(s,{method:"GET",headers:O(e,o,n)});if(!d.ok)throw new Error(`Chat history endpoint returned ${d.status}.`);let l=await d.json(),p=Array.isArray(l)?l:l&&typeof l=="object"?l.history??l.messages??l.data??[]:[];return Array.isArray(p)?p.map(u=>{if(!u||typeof u!="object")return null;let g=u;if(typeof g.question=="string"&&typeof g.answer=="string")return[{role:"user",text:g.question},{role:"assistant",text:g.answer}];let f=g.role??g.type??g.sender??g.author,m=g.text??g.message??g.content??g.answer;if(typeof m!="string")return null;let y=typeof f=="string"?f.toLowerCase():"assistant";return[{role:y==="user"||y==="human"?"user":"assistant",text:m}]}).flat().filter(u=>!!u):[]}async function it(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,o=await W(e),n=await fetch(X(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:O(e,t,o)});if(!n.ok)throw new Error(`Chat list endpoint returned ${n.status}.`);let i=await n.json(),s=Array.isArray(i)?i:i&&typeof i=="object"?i.chats??i.data??i.items??[]:[];return Array.isArray(s)?s.map(d=>{if(!d||typeof d!="object")return null;let l=d,p=l.chatId??l.chat_id??l.id,u=l.title??l.name??l.chatId;if(typeof p!="string"||typeof u!="string")return null;let g=typeof l.createdAt=="string"?l.createdAt:typeof l.created_at=="string"?l.created_at:null,f=typeof l.updatedAt=="string"?l.updatedAt:typeof l.updated_at=="string"?l.updated_at:null,m={chatId:p,title:u,pinned:typeof l.pinned=="boolean"?l.pinned:!1};return g&&(m.createdAt=g),f&&(m.updatedAt=f),m}).filter(d=>!!d):[]}async function lt(e,t,o){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let i=e.getAccessToken?await e.getAccessToken():null,s=await W(e),d=await fetch(X(e.apiBaseUrl,n),{method:"POST",headers:O(e,i,s),body:JSON.stringify({chatId:t,...o?{title:o}:{}})});if(!d.ok)throw new Error(`Create chat endpoint returned ${d.status}.`)}async function Ce(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,i=await W(e),s=pe(e,e.endpoints.updateChat,{chatId:t}),d=await fetch(s,{method:"PATCH",headers:O(e,n,i),body:JSON.stringify(o)});if(!d.ok)throw new Error(`Update chat endpoint returned ${d.status}.`)}async function pt(e,t){if(!e.endpoints.deleteChat)return;let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),i=pe(e,e.endpoints.deleteChat,{chatId:t}),s=await fetch(i,{method:"DELETE",headers:O(e,o,n)});if(!s.ok)throw new Error(`Delete chat endpoint returned ${s.status}.`)}function U(e,t){let o=at(t);return e.onError?.(o),o}var Le={accent:"#0f766e",accentSoft:"#ecfeff",panelBackground:"#ffffff",surfaceBackground:"#f8fafc",text:"#1f2937",mutedText:"#64748b",borderColor:"#dbe4ee",shadow:"0 24px 64px rgba(15, 23, 42, 0.20)",zIndex:2147483e3,fontFamily:'"Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif'},w={position:"bottom-right",title:"Knowledge Assistant",subtitle:"Answers are generated based on your access permissions",welcomeMessage:"How can I assist you today?",inputPlaceholder:"Ask your question...",launcherAriaLabel:"Open chat assistant",closeAriaLabel:"Close chat assistant",initialSuggestions:["Which indicators reflect the achievements of Vision KSA goals?","Case studies of real estate initiatives for economic growth","Study of UX for the ministry external portal"],sourceApp:"knowledge-platform",locale:"en",customHeaders:{},rag:{knowledgeNames:[],enableReferences:!0,loadHistoryOnOpen:!1},theme:Le,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0};function ct(e){if(!e.apiBaseUrl?.trim())throw new Error("Chat widget config requires a non-empty apiBaseUrl.");if(!e.endpoints?.ask?.trim())throw new Error("Chat widget config requires endpoints.ask to be provided.");let t=e.mount??document.body,o=ve(Le,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,position:e.position??w.position,title:e.title??w.title,subtitle:e.subtitle??w.subtitle,welcomeMessage:e.welcomeMessage??w.welcomeMessage,inputPlaceholder:e.inputPlaceholder??w.inputPlaceholder,launcherAriaLabel:e.launcherAriaLabel??w.launcherAriaLabel,closeAriaLabel:e.closeAriaLabel??w.closeAriaLabel,initialSuggestions:e.initialSuggestions??w.initialSuggestions,sourceApp:e.sourceApp??w.sourceApp,locale:e.locale??w.locale,customHeaders:e.customHeaders??w.customHeaders,rag:{...w.rag,...e.rag??{}},theme:o,getAccessToken:e.getAccessToken,getUserContext:e.getUserContext,onOpen:e.onOpen,onClose:e.onClose,onError:e.onError}}function a(e,t,o){let n=document.createElement(e);return t&&(n.className=t),o!==void 0&&(n.textContent=o),n}var dt="kp-chat-widget-styles";function ut(e,t){if(e.getElementById(dt))return;let o=document.createElement("style");o.id=dt,o.textContent=tn(t),e.appendChild(o)}function tn(e){return`
2
2
  :host {
3
3
  all: initial;
4
4
  }
@@ -14,6 +14,8 @@
14
14
  --kp-shadow: ${e.shadow};
15
15
  --kp-z-index: ${e.zIndex};
16
16
  --kp-font-family: ${e.fontFamily};
17
+ --kp-card-background: rgba(255, 255, 255, 0.92);
18
+ --kp-soft-highlight: rgba(236, 254, 255, 0.82);
17
19
  position: fixed;
18
20
  bottom: 24px;
19
21
  right: 24px;
@@ -35,6 +37,16 @@
35
37
  right: auto;
36
38
  }
37
39
 
40
+ .kp-rtl .kp-dropdown-item,
41
+ .kp-rtl .kp-suggestion,
42
+ .kp-rtl .kp-input,
43
+ .kp-rtl .kp-full-page-search-input,
44
+ .kp-rtl .kp-bubble-content,
45
+ .kp-rtl .kp-source-card,
46
+ .kp-rtl .kp-source-panel {
47
+ text-align: right;
48
+ }
49
+
38
50
  .kp-launcher {
39
51
  width: 72px;
40
52
  height: 72px;
@@ -64,9 +76,11 @@
64
76
  .kp-input:focus-visible,
65
77
  .kp-full-page-new-chat:focus-visible,
66
78
  .kp-full-page-close:focus-visible,
67
- .kp-full-page-search-input:focus-visible,
68
79
  .kp-full-page-chat-item:focus-visible,
69
- .kp-chat-pin:focus-visible {
80
+ .kp-chat-pin:focus-visible,
81
+ .kp-message-action:focus-visible,
82
+ .kp-source-chip:focus-visible,
83
+ .kp-source-panel-close:focus-visible {
70
84
  outline: 2px solid var(--kp-accent);
71
85
  outline-offset: 2px;
72
86
  }
@@ -139,12 +153,11 @@
139
153
  position: fixed;
140
154
  bottom: 88px;
141
155
  right: 24px;
142
- width: 480px;
143
- max-width: calc(100vw - 24px);
156
+ width: min(480px, calc(100vw - 48px));
144
157
  height: min(730px, calc(100vh - 118px));
145
158
  background: var(--kp-panel-background);
146
159
  border: 1px solid rgba(255, 255, 255, 0.35);
147
- border-radius: 20px;
160
+ border-radius: 24px;
148
161
  box-shadow: var(--kp-shadow);
149
162
  overflow: hidden;
150
163
  display: flex;
@@ -173,9 +186,7 @@
173
186
  .kp-full-page {
174
187
  position: fixed;
175
188
  inset: 0;
176
- background:
177
- radial-gradient(circle at top, rgba(32, 185, 210, 0.12), transparent 24%),
178
- linear-gradient(180deg, #f9fbfd 0%, #eef3f8 100%);
189
+ background: #ffffff;
179
190
  opacity: 0;
180
191
  pointer-events: none;
181
192
  transform: translateY(18px);
@@ -194,7 +205,7 @@
194
205
  height: 100vh;
195
206
  display: flex;
196
207
  flex-direction: column;
197
- padding: 22px 34px 26px;
208
+ padding: 22px 28px 26px;
198
209
  gap: 16px;
199
210
  overflow: hidden;
200
211
  }
@@ -204,7 +215,7 @@
204
215
  align-items: center;
205
216
  justify-content: space-between;
206
217
  gap: 16px;
207
- padding: 12px 4px 0;
218
+ padding: 8px 4px 0;
208
219
  flex: none;
209
220
  }
210
221
 
@@ -251,39 +262,34 @@
251
262
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
252
263
  }
253
264
 
254
- .kp-full-page-close {
255
- width: 44px;
256
- height: 44px;
265
+ .kp-full-page-close,
266
+ .kp-source-panel-close {
267
+ width: 40px;
268
+ height: 40px;
257
269
  border: none;
258
270
  border-radius: 14px;
259
271
  background: rgba(255, 255, 255, 0.82);
260
272
  color: #61788a;
261
- font-size: 28px;
273
+ font-size: 24px;
262
274
  line-height: 1;
263
275
  cursor: pointer;
264
276
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
265
277
  }
266
278
 
267
- .kp-full-page-breadcrumb {
268
- padding: 0 4px;
269
- color: #8192a0;
270
- font-size: 13px;
271
- line-height: 1.5;
272
- flex: none;
273
- }
274
-
275
279
  .kp-full-page-content {
276
280
  display: grid;
277
- grid-template-columns: 290px minmax(0, 1fr);
281
+ grid-template-columns: 290px minmax(0, 1fr) minmax(0, 0);
278
282
  gap: 16px;
279
283
  flex: 1;
280
284
  min-height: 0;
281
285
  overflow: hidden;
286
+ align-items: stretch;
282
287
  }
283
288
 
284
289
  .kp-full-page-sidebar,
285
- .kp-full-page-panel {
286
- border-radius: 22px;
290
+ .kp-full-page-panel,
291
+ .kp-source-panel {
292
+ border-radius: 24px;
287
293
  border: 1px solid rgba(219, 228, 238, 0.9);
288
294
  background: rgba(255, 255, 255, 0.88);
289
295
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
@@ -331,6 +337,15 @@
331
337
  color: #334155;
332
338
  font-size: 14px;
333
339
  min-width: 0;
340
+ box-shadow: none;
341
+ }
342
+
343
+ .kp-full-page-search-input:focus,
344
+ .kp-full-page-search-input:focus-visible,
345
+ .kp-full-page-search-input:active {
346
+ outline: none;
347
+ box-shadow: none;
348
+ border: none;
334
349
  }
335
350
 
336
351
  .kp-full-page-search-icon {
@@ -357,7 +372,7 @@
357
372
 
358
373
  .kp-full-page-item {
359
374
  padding: 12px 12px 13px;
360
- border-radius: 12px;
375
+ border-radius: 14px;
361
376
  color: #293845;
362
377
  font-size: 15px;
363
378
  line-height: 1.5;
@@ -366,12 +381,14 @@
366
381
  }
367
382
 
368
383
  .kp-full-page-chat-item {
384
+ position: relative;
369
385
  display: flex;
370
386
  align-items: center;
371
387
  justify-content: space-between;
372
388
  gap: 10px;
373
389
  cursor: pointer;
374
390
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
391
+ overflow: visible;
375
392
  }
376
393
 
377
394
  .kp-full-page-chat-item:hover {
@@ -385,6 +402,10 @@
385
402
  background: rgba(220, 252, 231, 0.72);
386
403
  }
387
404
 
405
+ .kp-full-page-chat-item.menu-open {
406
+ z-index: 4;
407
+ }
408
+
388
409
  .kp-full-page-item-title {
389
410
  min-width: 0;
390
411
  overflow: hidden;
@@ -411,11 +432,6 @@
411
432
  line-height: 1.5;
412
433
  }
413
434
 
414
- .kp-full-page-item-pinned {
415
- background: rgba(237, 248, 251, 0.92);
416
- border-color: rgba(127, 208, 217, 0.4);
417
- }
418
-
419
435
  .kp-full-page-main {
420
436
  min-width: 0;
421
437
  min-height: 0;
@@ -430,6 +446,112 @@
430
446
  overflow: hidden;
431
447
  }
432
448
 
449
+ .kp-source-panel {
450
+ min-width: 0;
451
+ min-height: 0;
452
+ overflow: hidden;
453
+ display: none;
454
+ flex-direction: column;
455
+ }
456
+
457
+ .kp-source-panel.open {
458
+ display: flex;
459
+ }
460
+
461
+ .kp-full-page-content:has(.kp-source-panel.open) {
462
+ grid-template-columns: 290px minmax(0, 1fr) 320px;
463
+ }
464
+
465
+ .kp-source-panel-header {
466
+ display: flex;
467
+ align-items: flex-start;
468
+ justify-content: space-between;
469
+ gap: 12px;
470
+ padding: 18px 18px 12px;
471
+ border-bottom: 1px solid rgba(219, 228, 238, 0.7);
472
+ }
473
+
474
+ .kp-source-panel-title {
475
+ font-size: 17px;
476
+ font-weight: 700;
477
+ color: #16394b;
478
+ }
479
+
480
+ .kp-source-panel-subtitle {
481
+ margin-top: 4px;
482
+ font-size: 12px;
483
+ color: #7a8a99;
484
+ }
485
+
486
+ .kp-source-panel-list {
487
+ display: flex;
488
+ flex-direction: column;
489
+ gap: 12px;
490
+ padding: 16px;
491
+ overflow: auto;
492
+ }
493
+
494
+ .kp-source-panel-empty {
495
+ color: #7a8a99;
496
+ font-size: 14px;
497
+ line-height: 1.5;
498
+ }
499
+
500
+ .kp-source-card {
501
+ width: 100%;
502
+ text-align: left;
503
+ cursor: pointer;
504
+ appearance: none;
505
+ border: 1px solid rgba(219, 228, 238, 0.9);
506
+ border-radius: 16px;
507
+ background: #ffffff;
508
+ padding: 14px;
509
+ }
510
+
511
+ .kp-source-card-media {
512
+ display: flex;
513
+ align-items: center;
514
+ margin-bottom: 10px;
515
+ }
516
+
517
+ .kp-source-thumb,
518
+ .kp-source-thumb-large {
519
+ flex: none;
520
+ width: 32px;
521
+ height: 32px;
522
+ border-radius: 999px;
523
+ display: inline-flex;
524
+ align-items: center;
525
+ justify-content: center;
526
+ background: linear-gradient(180deg, #eefcf8 0%, #dff7f2 100%);
527
+ border: 1px solid rgba(15, 118, 110, 0.18);
528
+ color: #0f6a75;
529
+ font-size: 14px;
530
+ line-height: 1;
531
+ box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
532
+ }
533
+
534
+ .kp-source-thumb-large {
535
+ width: 42px;
536
+ height: 42px;
537
+ font-size: 18px;
538
+ }
539
+
540
+ .kp-source-card-title {
541
+ font-size: 14px;
542
+ font-weight: 700;
543
+ color: #16394b;
544
+ word-break: break-word;
545
+ }
546
+
547
+ .kp-source-card-meta {
548
+ margin-top: 8px;
549
+ font-size: 12px;
550
+ line-height: 1.5;
551
+ color: #667a8d;
552
+ word-break: break-word;
553
+ }
554
+
433
555
  .kp-full-page-body {
434
556
  flex: 1;
435
557
  overflow: auto;
@@ -437,9 +559,7 @@
437
559
  flex-direction: column;
438
560
  gap: 14px;
439
561
  padding: 42px 28px 18px;
440
- background:
441
- radial-gradient(circle at top, rgba(54, 196, 220, 0.14), transparent 22%),
442
- linear-gradient(180deg, #ffffff 0%, #f8fbfd 100%);
562
+ background: #ffffff;
443
563
  scroll-behavior: smooth;
444
564
  }
445
565
 
@@ -588,7 +708,7 @@
588
708
  position: absolute;
589
709
  top: 44px;
590
710
  left: 0;
591
- width: 164px;
711
+ width: 184px;
592
712
  background: #ffffff;
593
713
  border: 1px solid rgba(15, 79, 104, 0.12);
594
714
  border-radius: 10px;
@@ -601,6 +721,11 @@
601
721
  z-index: 2;
602
722
  }
603
723
 
724
+ .kp-rtl .kp-dropdown {
725
+ left: auto;
726
+ right: 0;
727
+ }
728
+
604
729
  .kp-dropdown.open {
605
730
  opacity: 1;
606
731
  transform: translateY(0);
@@ -652,6 +777,127 @@
652
777
  padding-top: 16px;
653
778
  }
654
779
 
780
+ .kp-panel.kp-sheet-open .kp-body,
781
+ .kp-panel.kp-sheet-open .kp-footer,
782
+ .kp-panel.kp-sheet-open .kp-header {
783
+ opacity: 0;
784
+ pointer-events: none;
785
+ }
786
+
787
+ .kp-my-chats-sheet {
788
+ position: absolute;
789
+ inset: 0;
790
+ border-radius: inherit;
791
+ border: none;
792
+ background: #ffffff;
793
+ box-shadow: none;
794
+ display: none;
795
+ flex-direction: column;
796
+ z-index: 3;
797
+ overflow: hidden;
798
+ }
799
+
800
+ .kp-my-chats-sheet.open {
801
+ display: flex;
802
+ }
803
+
804
+ .kp-my-chats-header {
805
+ display: flex;
806
+ align-items: center;
807
+ justify-content: space-between;
808
+ padding: 18px 18px 10px;
809
+ flex: none;
810
+ background: #ffffff;
811
+ }
812
+
813
+ .kp-my-chats-nav {
814
+ width: 36px;
815
+ height: 36px;
816
+ border: none;
817
+ border-radius: 999px;
818
+ background: transparent;
819
+ color: #61788a;
820
+ font-size: 22px;
821
+ line-height: 1;
822
+ cursor: pointer;
823
+ }
824
+
825
+ .kp-my-chats-body {
826
+ flex: 1;
827
+ overflow: auto;
828
+ padding: 8px 18px 18px;
829
+ background: #ffffff;
830
+ }
831
+
832
+ .kp-my-chats-section-label {
833
+ font-size: 14px;
834
+ line-height: 1.5;
835
+ color: #7a8a99;
836
+ margin: 14px 0 10px;
837
+ }
838
+
839
+ .kp-my-chats-list {
840
+ display: flex;
841
+ flex-direction: column;
842
+ gap: 10px;
843
+ }
844
+
845
+ .kp-chat-actions {
846
+ position: relative;
847
+ flex: none;
848
+ }
849
+
850
+ .kp-chat-actions-trigger {
851
+ width: 28px;
852
+ height: 28px;
853
+ border: none;
854
+ border-radius: 999px;
855
+ background: transparent;
856
+ color: #526678;
857
+ font-size: 20px;
858
+ line-height: 1;
859
+ cursor: pointer;
860
+ display: inline-flex;
861
+ align-items: center;
862
+ justify-content: center;
863
+ }
864
+
865
+ .kp-chat-actions-menu {
866
+ position: absolute;
867
+ top: 30px;
868
+ inset-inline-end: 0;
869
+ width: 120px;
870
+ padding: 8px;
871
+ border-radius: 10px;
872
+ border: 1px solid rgba(219, 228, 238, 0.95);
873
+ background: #ffffff;
874
+ box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
875
+ display: none;
876
+ flex-direction: column;
877
+ gap: 2px;
878
+ z-index: 20;
879
+ }
880
+
881
+ .kp-chat-actions.open .kp-chat-actions-menu {
882
+ display: flex;
883
+ }
884
+
885
+ .kp-chat-actions-item {
886
+ width: 100%;
887
+ border: none;
888
+ background: transparent;
889
+ color: #1f2937;
890
+ text-align: left;
891
+ padding: 10px 12px;
892
+ border-radius: 8px;
893
+ font-size: 14px;
894
+ cursor: pointer;
895
+ }
896
+
897
+ .kp-chat-actions-item:hover {
898
+ background: rgba(241, 245, 249, 0.95);
899
+ }
900
+
655
901
  .kp-hero {
656
902
  display: flex;
657
903
  gap: 10px;
@@ -673,32 +919,245 @@
673
919
  color: #374151;
674
920
  }
675
921
 
922
+ .kp-message-row {
923
+ display: flex;
924
+ align-items: flex-start;
925
+ gap: 10px;
926
+ width: 100%;
927
+ }
928
+
929
+ .kp-message-row.user {
930
+ justify-content: flex-end;
931
+ }
932
+
933
+ .kp-avatar {
934
+ flex: none;
935
+ width: 36px;
936
+ height: 36px;
937
+ border-radius: 999px;
938
+ display: flex;
939
+ align-items: center;
940
+ justify-content: center;
941
+ font-size: 13px;
942
+ font-weight: 700;
943
+ box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
944
+ }
945
+
946
+ .kp-avatar.bot {
947
+ background: linear-gradient(180deg, #e8fbff 0%, #dff7f2 100%);
948
+ color: #0f6a75;
949
+ border: 1px solid rgba(15, 118, 110, 0.16);
950
+ }
951
+
952
+ .kp-avatar.user {
953
+ background: linear-gradient(180deg, #fff4ee 0%, #fbe3d5 100%);
954
+ color: #8c4b1f;
955
+ border: 1px solid rgba(180, 102, 43, 0.16);
956
+ }
957
+
676
958
  .kp-bubble {
677
- max-width: 85%;
678
- padding: 12px 14px;
679
- border-radius: 18px;
959
+ max-width: min(85%, 720px);
960
+ padding: 14px 16px;
961
+ border-radius: 20px;
680
962
  font-size: 14px;
681
- line-height: 1.5;
682
- white-space: pre-wrap;
963
+ line-height: 1.65;
683
964
  border: 1px solid var(--kp-border-color);
684
965
  background: #ffffff;
966
+ box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
685
967
  }
686
968
 
687
969
  .kp-bubble.user {
688
- align-self: flex-end;
689
- background: var(--kp-accent-soft);
690
- border-color: rgba(15, 118, 110, 0.22);
970
+ background: linear-gradient(180deg, #fff8f3 0%, #fdf1e8 100%);
971
+ border-color: rgba(222, 184, 135, 0.34);
691
972
  }
692
973
 
693
974
  .kp-bubble.bot {
694
- align-self: flex-start;
975
+ background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
976
+ }
977
+
978
+ .kp-bubble-content {
979
+ color: var(--kp-text);
980
+ white-space: normal;
981
+ word-break: break-word;
982
+ }
983
+
984
+ .kp-bubble-content p,
985
+ .kp-bubble-content ul,
986
+ .kp-bubble-content ol,
987
+ .kp-bubble-content table,
988
+ .kp-bubble-content blockquote {
989
+ margin: 0;
990
+ }
991
+
992
+ .kp-bubble-content p + p,
993
+ .kp-bubble-content p + ul,
994
+ .kp-bubble-content p + ol,
995
+ .kp-bubble-content ul + p,
996
+ .kp-bubble-content ol + p,
997
+ .kp-bubble-content .kp-table-wrap + p,
998
+ .kp-bubble-content p + .kp-table-wrap,
999
+ .kp-bubble-content h1 + p,
1000
+ .kp-bubble-content h2 + p,
1001
+ .kp-bubble-content h3 + p {
1002
+ margin-top: 12px;
1003
+ }
1004
+
1005
+ .kp-bubble-content h1,
1006
+ .kp-bubble-content h2,
1007
+ .kp-bubble-content h3,
1008
+ .kp-bubble-content h4,
1009
+ .kp-bubble-content h5,
1010
+ .kp-bubble-content h6 {
1011
+ margin: 0 0 10px;
1012
+ font-size: 16px;
1013
+ line-height: 1.4;
1014
+ color: #16394b;
1015
+ }
1016
+
1017
+ .kp-bubble-content ul,
1018
+ .kp-bubble-content ol {
1019
+ padding-inline-start: 20px;
1020
+ }
1021
+
1022
+ .kp-bubble-content code {
1023
+ padding: 2px 6px;
1024
+ border-radius: 8px;
1025
+ background: rgba(226, 232, 240, 0.66);
1026
+ font-size: 0.92em;
1027
+ }
1028
+
1029
+ .kp-bubble-content a {
1030
+ color: #0f6a75;
1031
+ text-decoration: underline;
1032
+ }
1033
+
1034
+ .kp-table-wrap {
1035
+ overflow-x: auto;
1036
+ margin-top: 8px;
1037
+ }
1038
+
1039
+ .kp-bubble-content table {
1040
+ width: 100%;
1041
+ border-collapse: collapse;
1042
+ border: 1px solid rgba(203, 213, 225, 0.95);
1043
+ border-radius: 14px;
1044
+ overflow: hidden;
1045
+ background: #ffffff;
1046
+ }
1047
+
1048
+ .kp-bubble-content th,
1049
+ .kp-bubble-content td {
1050
+ padding: 10px 12px;
1051
+ border-bottom: 1px solid rgba(226, 232, 240, 0.95);
1052
+ border-inline-end: 1px solid rgba(226, 232, 240, 0.95);
1053
+ vertical-align: top;
1054
+ text-align: start;
1055
+ }
1056
+
1057
+ .kp-bubble-content tr:last-child td {
1058
+ border-bottom: none;
1059
+ }
1060
+
1061
+ .kp-bubble-content th:last-child,
1062
+ .kp-bubble-content td:last-child {
1063
+ border-inline-end: none;
1064
+ }
1065
+
1066
+ .kp-bubble-content th {
1067
+ background: #f4fbfc;
1068
+ color: #16394b;
1069
+ font-weight: 700;
695
1070
  }
696
1071
 
697
1072
  .kp-meta {
698
1073
  font-size: 11px;
699
1074
  line-height: 1.4;
700
1075
  color: var(--kp-muted-text);
701
- margin-top: 6px;
1076
+ margin-top: 10px;
1077
+ }
1078
+
1079
+ .kp-source-preview {
1080
+ margin-top: 10px;
1081
+ padding: 12px;
1082
+ border-radius: 16px;
1083
+ border: 1px solid rgba(219, 228, 238, 0.88);
1084
+ background: #ffffff;
1085
+ }
1086
+
1087
+ .kp-source-preview-title {
1088
+ font-size: 12px;
1089
+ font-weight: 700;
1090
+ color: #16394b;
1091
+ margin-bottom: 8px;
1092
+ }
1093
+
1094
+ .kp-source-preview-list {
1095
+ display: flex;
1096
+ flex-wrap: nowrap;
1097
+ gap: 8px;
1098
+ overflow-x: auto;
1099
+ }
1100
+
1101
+ .kp-source-chip {
1102
+ display: inline-flex;
1103
+ align-items: center;
1104
+ gap: 10px;
1105
+ border: 1px solid rgba(15, 118, 110, 0.16);
1106
+ background: #ffffff;
1107
+ color: #0f4f68;
1108
+ border-radius: 999px;
1109
+ padding: 8px 12px;
1110
+ cursor: pointer;
1111
+ font-size: 12px;
1112
+ line-height: 1.3;
1113
+ max-width: 100%;
1114
+ min-width: 0;
1115
+ }
1116
+
1117
+ .kp-source-chip-more {
1118
+ background: rgba(236, 254, 255, 0.9);
1119
+ }
1120
+
1121
+ .kp-source-chip-label {
1122
+ min-width: 0;
1123
+ overflow: hidden;
1124
+ text-overflow: ellipsis;
1125
+ white-space: nowrap;
1126
+ }
1127
+
1128
+ .kp-source-thumb-stack {
1129
+ display: inline-flex;
1130
+ align-items: center;
1131
+ margin-inline-end: 2px;
1132
+ }
1133
+
1134
+ .kp-source-thumb.stacked {
1135
+ margin-inline-end: -10px;
1136
+ background: #ffffff;
1137
+ }
1138
+
1139
+ .kp-message-actions {
1140
+ display: flex;
1141
+ align-items: center;
1142
+ gap: 8px;
1143
+ margin-top: 10px;
1144
+ }
1145
+
1146
+ .kp-message-action {
1147
+ border: 1px solid rgba(219, 228, 238, 0.9);
1148
+ background: #ffffff;
1149
+ color: #4b6478;
1150
+ border-radius: 999px;
1151
+ padding: 7px 10px;
1152
+ cursor: pointer;
1153
+ font-size: 12px;
1154
+ line-height: 1;
1155
+ }
1156
+
1157
+ .kp-message-action.active {
1158
+ color: #0f6a75;
1159
+ border-color: rgba(15, 118, 110, 0.3);
1160
+ background: rgba(236, 254, 255, 0.92);
702
1161
  }
703
1162
 
704
1163
  .kp-suggestions {
@@ -731,11 +1190,15 @@
731
1190
  align-items: center;
732
1191
  gap: 10px;
733
1192
  border: 1px solid var(--kp-border-color);
734
- border-radius: 14px;
1193
+ border-radius: 16px;
735
1194
  padding: 10px 12px;
736
1195
  background: #ffffff;
737
1196
  }
738
1197
 
1198
+ .kp-rtl .kp-form {
1199
+ flex-direction: row-reverse;
1200
+ }
1201
+
739
1202
  .kp-input {
740
1203
  flex: 1;
741
1204
  border: none;
@@ -770,6 +1233,11 @@
770
1233
  display: flex;
771
1234
  align-items: center;
772
1235
  justify-content: center;
1236
+ flex: none;
1237
+ }
1238
+
1239
+ .kp-rtl .kp-send {
1240
+ transform: scaleX(-1);
773
1241
  }
774
1242
 
775
1243
  .kp-note {
@@ -787,6 +1255,39 @@
787
1255
  padding: 4px 2px;
788
1256
  }
789
1257
 
1258
+ @media (max-width: 1100px) {
1259
+ .kp-full-page-content:has(.kp-source-panel.open) {
1260
+ grid-template-columns: 260px minmax(0, 1fr);
1261
+ }
1262
+
1263
+ .kp-source-panel.open {
1264
+ position: absolute;
1265
+ inset-inline-end: 28px;
1266
+ top: 92px;
1267
+ bottom: 26px;
1268
+ width: min(320px, calc(100vw - 56px));
1269
+ z-index: 3;
1270
+ }
1271
+ }
1272
+
1273
+ @media (max-width: 860px) {
1274
+ .kp-full-page-content,
1275
+ .kp-full-page-content:has(.kp-source-panel.open) {
1276
+ grid-template-columns: 1fr;
1277
+ }
1278
+
1279
+ .kp-full-page-sidebar {
1280
+ max-height: 260px;
1281
+ }
1282
+
1283
+ .kp-source-panel.open {
1284
+ position: static;
1285
+ inset: auto;
1286
+ width: auto;
1287
+ max-height: 280px;
1288
+ }
1289
+ }
1290
+
790
1291
  @media (max-width: 640px) {
791
1292
  .kp-chat-widget,
792
1293
  .kp-chat-widget.bottom-left {
@@ -799,7 +1300,6 @@
799
1300
  .kp-chat-widget.bottom-left .kp-panel {
800
1301
  inset: 0;
801
1302
  width: 100vw;
802
- max-width: none;
803
1303
  height: 100vh;
804
1304
  border-radius: 0;
805
1305
  transform: translateX(72px) scale(0.985);
@@ -818,14 +1318,6 @@
818
1318
  padding: 0;
819
1319
  }
820
1320
 
821
- .kp-full-page-content {
822
- grid-template-columns: 1fr;
823
- }
824
-
825
- .kp-full-page-sidebar {
826
- order: 2;
827
- }
828
-
829
1321
  .kp-full-page-body {
830
1322
  padding: 24px 16px 16px;
831
1323
  }
@@ -838,6 +1330,19 @@
838
1330
  .kp-full-page-hero-text {
839
1331
  font-size: 22px;
840
1332
  }
1333
+
1334
+ .kp-message-row {
1335
+ gap: 8px;
1336
+ }
1337
+
1338
+ .kp-avatar {
1339
+ width: 32px;
1340
+ height: 32px;
1341
+ }
1342
+
1343
+ .kp-bubble {
1344
+ max-width: calc(100% - 40px);
1345
+ }
841
1346
  }
842
1347
 
843
1348
  @keyframes kp-cluster-rotate {
@@ -868,5 +1373,32 @@
868
1373
  40% { transform: translate(16px, -13px) scale(0.92); opacity: 0.96; }
869
1374
  62% { transform: translate(2px, -2px) scale(1); opacity: 0.98; }
870
1375
  }
871
- `}function G(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=Ve(e),n={chatId:ce(t),open:!1,fullPageOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1},r=document.createElement("div");r.dataset.chatWidgetHost="true",t.mount.appendChild(r);let i=r.attachShadow({mode:"open"});_e(i,t.theme);let l=o("div",`kp-chat-widget ${t.position}`),s=o("div","kp-overlay"),u=o("button","kp-launcher");u.type="button",u.setAttribute("aria-label",t.launcherAriaLabel),u.innerHTML=['<span class="kp-star-cluster" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let p=o("section","kp-panel");p.setAttribute("role","dialog"),p.setAttribute("aria-modal","true"),p.setAttribute("aria-label",t.title);let c=o("div","kp-header"),f=o("div","kp-toolbar"),g=o("button","kp-tool-button kp-menu-trigger");g.type="button",g.setAttribute("aria-label","Open chat actions"),g.innerHTML=['<span class="kp-pencil-icon" aria-hidden="true"></span>','<span class="kp-chevron" aria-hidden="true">\u2304</span>'].join("");let m=o("div","kp-dropdown"),z=o("button","kp-dropdown-item","New Chat");z.type="button";let W=o("button","kp-dropdown-item","My Chats");W.type="button";let N=o("button","kp-dropdown-item","Open Knowledge Assistant");N.type="button",m.append(z,W,N),f.append(g,m);let q=o("div","kp-title-wrap"),J=o("h2","kp-title",t.title),Q=o("div","kp-subtitle",t.subtitle);q.append(J,Q);let b=o("button","kp-close","\xD7");b.type="button",b.setAttribute("aria-label",t.closeAriaLabel),c.append(f,q,b);let F=o("div","kp-body"),Z=o("div","kp-hero"),Ge=o("div","kp-hero-icon","\u2726"),Je=o("div","kp-hero-text",t.welcomeMessage);Z.append(Ge,Je);let ge=o("div","kp-footer"),ee=o("form","kp-form"),I=o("input","kp-input");I.type="text",I.autocomplete="off",I.placeholder=t.inputPlaceholder;let fe=o("button","kp-send","\u279C");fe.type="submit";let Qe=o("div","kp-note","Auth token is forwarded from the host app when configured.");ee.append(I,fe),ge.append(ee,Qe),p.append(c,F,ge),l.append(s,u,p),i.appendChild(l),F.appendChild(Z);let he=o("div","kp-suggestions");F.appendChild(he);let A={body:F,input:I,suggestions:he,hero:Z},x=o("section","kp-full-page");x.setAttribute("role","dialog"),x.setAttribute("aria-modal","true"),x.setAttribute("aria-label",`${t.title} page`);let me=o("div","kp-full-page-shell"),be=o("div","kp-full-page-header"),ke=o("div","kp-full-page-brand"),Ze=o("div","kp-full-page-brand-mark","\u2726"),et=o("div","kp-full-page-brand-text",t.title);ke.append(Ze,et);let xe=o("div","kp-full-page-header-actions"),tt=o("div","kp-full-page-badge","Knowledge Assistant"),X=o("button","kp-full-page-close","\xD7");X.type="button",X.setAttribute("aria-label","Close knowledge assistant page"),xe.append(tt,X),be.append(ke,xe);let nt=o("div","kp-full-page-breadcrumb","Home \u203A Knowledge Assistant"),ye=o("div","kp-full-page-content"),we=o("aside","kp-full-page-sidebar"),te=o("button","kp-full-page-new-chat","+ New Chat");te.type="button";let ve=o("div","kp-full-page-search"),O=o("input","kp-full-page-search-input");O.type="search",O.placeholder="Search Chat";let at=o("span","kp-full-page-search-icon","\u2315");ve.append(O,at);let ot=o("div","kp-full-page-section-label","Recent Activity"),y=o("div","kp-full-page-recent-list"),rt=o("div","kp-full-page-section-label","Pinned Collections"),w=o("div","kp-full-page-pinned-list");we.append(te,ve,ot,y,rt,w);let Ce=o("main","kp-full-page-main"),Le=o("section","kp-full-page-panel"),ne=o("div","kp-full-page-body"),ae=o("div","kp-full-page-hero"),Pe=o("div","kp-full-page-hero-badge");Pe.innerHTML=['<span class="kp-star-cluster kp-star-cluster-static" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let st=o("div","kp-full-page-hero-text",t.welcomeMessage);ae.append(Pe,st);let Ie=o("div","kp-suggestions kp-full-page-suggestions");ne.append(ae,Ie);let Ae=o("div","kp-full-page-footer"),oe=o("form","kp-form kp-full-page-form"),v=o("input","kp-input kp-full-page-input");v.type="text",v.autocomplete="off",v.placeholder=t.inputPlaceholder;let Te=o("button","kp-send kp-full-page-send","\u279C");Te.type="submit";let it=o("div","kp-note kp-full-page-note","Answers are generated based on your access permissions");oe.append(v,Te),Ae.append(oe,it),Le.append(ne,Ae),Ce.appendChild(Le),ye.append(we,Ce),me.append(be,nt,ye),x.appendChild(me),l.appendChild(x);let k={body:ne,input:v,suggestions:Ie,hero:ae},B=()=>({...t,getAccessToken:n.accessTokenProvider});S(A,t.initialSuggestions,async a=>{await C(a,A)}),S(k,t.initialSuggestions,async a=>{await C(a,k)}),R(y,w,n,async a=>{await E(a.chatId)},async a=>{await H(a)});function Ee(){n.open||(n.open=!0,n.fullPageOpen=!1,x.classList.remove("open"),u.classList.add("hidden"),s.classList.add("visible"),p.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&se.loadHistory(),queueMicrotask(()=>I.focus()))}function U(){n.open&&(T(),n.open=!1,u.classList.remove("hidden"),s.classList.remove("visible"),p.classList.remove("open"),t.onClose?.())}async function C(a,d){let L=a.trim();if(!L)return;d.input.value="";try{await ct(L)}catch(P){let $=j(t,P);K(d.body,"bot",`Unable to create chat: ${$.message}`);return}je(d),K(d.body,"user",L),d.body.scrollTop=d.body.scrollHeight;let M=o("div","kp-loading","Thinking...");d.body.appendChild(M),d.body.scrollTop=d.body.scrollHeight;try{let P=await Ne(B(),{message:L,chatId:n.chatId,knowledgeNames:await xt(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});M.isConnected&&M.remove(),K(d.body,"bot",P.answer,P.citations?.length),n.historyLoadedChatId=null,await Y(),P.suggestions?.length&&S(d,P.suggestions,async $=>{await C($,d)})}catch(P){let $=j(t,P);M.isConnected&&M.remove(),K(d.body,"bot",`Request failed: ${$.message}`)}}async function He(a){let d=n.fullPageOpen?k:A;await C(a,d)}async function Me(){n.fullPageOpen=!0,n.open=!1,T(),p.classList.remove("open"),s.classList.remove("visible"),u.classList.add("hidden"),x.classList.add("open"),await Y(),await re(k,n.chatId),queueMicrotask(()=>v.focus())}function Re(){n.fullPageOpen&&(n.fullPageOpen=!1,x.classList.remove("open"),u.classList.remove("hidden"))}function pt(){n.menuOpen=!0,g.classList.add("open"),m.classList.add("open")}function T(){n.menuOpen=!1,g.classList.remove("open"),m.classList.remove("open")}function lt(){n.chatId=ce(t),n.historyLoadedChatId=null,ue(A),S(A,t.initialSuggestions,async a=>{await C(a,A)}),T()}async function dt(){n.chatId=ce(t),n.historyLoadedChatId=null,ue(k),S(k,t.initialSuggestions,async a=>{await C(a,k)}),R(y,w,n,async a=>{await E(a.chatId)},async a=>{await H(a)})}async function Y(){if(!t.endpoints.listChats)return R(y,w,n,async a=>{await E(a.chatId)},async a=>{await H(a)}),[];n.loadingChats=!0,R(y,w,n,async a=>{await E(a.chatId)},async a=>{await H(a)});try{let a=await Be(B());return n.chats=a,a}catch(a){return j(t,a),n.chats}finally{n.loadingChats=!1,R(y,w,n,async a=>{await E(a.chatId)},async a=>{await H(a)})}}async function ct(a){!t.endpoints.listChats&&!t.endpoints.createChat||n.chats.some(d=>d.chatId===n.chatId)||await Ue(B(),n.chatId,a?vt(a):void 0)}async function E(a){n.chatId=a,n.historyLoadedChatId=null,await re(k,a),R(y,w,n,async d=>{await E(d.chatId)},async d=>{await H(d)})}async function H(a){if(t.endpoints.updateChat)try{await $e(B(),a.chatId,{pinned:!a.pinned}),await Y()}catch(d){j(t,d)}}async function re(a,d){ue(a),S(a,t.initialSuggestions,async M=>{await C(M,a)});let L=await Oe(B(),d);return L.length>0&&(je(a),qe(a.body,a.hero,a.suggestions),wt(a.body,L)),n.historyLoadedChatId=d,L}let se={open:Ee,close:U,toggle(){if(n.open){U();return}Ee()},destroy(){document.removeEventListener("keydown",Se),r.remove()},sendMessage:He,setAccessTokenProvider(a){n.accessTokenProvider=a},getChatId(){return n.chatId},loadChats(){return Y()},async loadHistory(){let a=n.fullPageOpen?k:A;return re(a,n.chatId)}};u.addEventListener("click",()=>se.toggle()),b.addEventListener("click",U),s.addEventListener("click",U),g.addEventListener("click",a=>{if(a.stopPropagation(),!n.menuOpen){pt();return}T()}),z.addEventListener("click",lt),W.addEventListener("click",async()=>{T(),await Me()}),N.addEventListener("click",()=>{Me()}),X.addEventListener("click",Re),te.addEventListener("click",()=>{dt(),queueMicrotask(()=>v.focus())}),O.addEventListener("input",()=>{n.chatSearchTerm=O.value.trim().toLowerCase(),R(y,w,n,async a=>{await E(a.chatId)},async a=>{await H(a)})}),p.addEventListener("click",a=>{n.menuOpen&&!m.contains(a.target)&&!g.contains(a.target)&&T(),a.stopPropagation()}),i.addEventListener("click",a=>{let d=a.target;n.menuOpen&&d instanceof Node&&!m.contains(d)&&!g.contains(d)&&T()}),ee.addEventListener("submit",async a=>{a.preventDefault(),await He(I.value)}),oe.addEventListener("submit",async a=>{a.preventDefault(),await C(v.value,k)});function Se(a){if(a.key==="Escape"){if(n.fullPageOpen){Re();return}n.open&&U()}}return document.addEventListener("keydown",Se),se}async function xt(e){if(e.rag.getKnowledgeNames){let t=await e.rag.getKnowledgeNames();return Array.isArray(t)?t.filter(Boolean):[]}return(e.rag.knowledgeNames??[]).filter(Boolean)}function ce(e){return e.rag.chatId?.trim()?e.rag.chatId:e.rag.chatIdFactory?e.rag.chatIdFactory():typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`kp-chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function K(e,t,n,r){let i=o("div",`kp-bubble ${t}`,n);if(r){let l=o("div","kp-meta",`${r} citation${r>1?"s":""} attached`);i.appendChild(l)}return e.appendChild(i),e.scrollTop=e.scrollHeight,i}function yt(e,t,n){e.textContent="";for(let r of t){let i=o("button","kp-suggestion",r);i.type="button",i.addEventListener("click",async()=>{await n(r)}),e.appendChild(i)}}function S(e,t,n){yt(e.suggestions,t,async r=>{e.input.value=r,await n(r)})}function qe(e,t,n){let r=new Set([t,n]);for(let i of Array.from(e.children))r.has(i)||i.remove()}function je(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function ue(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),qe(e.body,e.hero,e.suggestions),e.input.value=""}function wt(e,t){for(let n of t)K(e,n.role==="assistant"?"bot":"user",n.text)}function R(e,t,n,r,i){if(e.textContent="",t.textContent="",n.loadingChats){e.appendChild(o("div","kp-full-page-empty","Loading chats..."));return}let l=n.chats.filter(s=>n.chatSearchTerm?s.title.toLowerCase().includes(n.chatSearchTerm):!0);if(l.length>0){let s=l.filter(p=>p.pinned),u=l.filter(p=>!p.pinned).slice(0,8);Ke(e,u,n.chatId,r,i),Ke(t,s,n.chatId,r,i),u.length===0&&e.appendChild(o("div","kp-full-page-empty","No recent chats yet.")),s.length===0&&t.appendChild(o("div","kp-full-page-empty","No pinned chats yet."));return}e.appendChild(o("div","kp-full-page-empty","No chats yet.")),t.appendChild(o("div","kp-full-page-empty","No pinned chats yet."))}function Ke(e,t,n,r,i){for(let l of t){let s=o("div",`kp-full-page-item kp-full-page-chat-item${l.chatId===n?" active":""}`),u=o("span","kp-full-page-item-title",l.title),p=o("button","kp-chat-pin",l.pinned?"\u2605":"\u2606");p.type="button",p.setAttribute("aria-label",l.pinned?"Unpin chat":"Pin chat"),p.addEventListener("click",async c=>{c.stopPropagation(),await i(l)}),s.append(u,p),s.setAttribute("role","button"),s.tabIndex=0,s.addEventListener("click",async()=>{await r(l)}),s.addEventListener("keydown",async c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),await r(l))}),e.appendChild(s)}}function vt(e){return e.trim().slice(0,60)||"New Chat"}var Fe="0.1.0",Xe=G,Ye={init:Xe,createChatWidget:G,version:Fe};typeof window<"u"&&(window.ChatWidget=Ye);0&&(module.exports={browserGlobal,createChatWidget,init,version});
1376
+ `}var gt={en:{openChatActions:"Open chat actions",newChat:"New Chat",myChats:"My Chats",openAssistant:"Open Knowledge Assistant",back:"Back",close:"Close",assistantBadge:"Knowledge Assistant",closeAssistantPage:"Close knowledge assistant page",searchChat:"Search Chat",recentActivity:"Recent Activity",pinnedCollections:"Pinned Collections",answersBasedOnPermissions:"Answers are generated based on your access permissions",authTokenForwarded:"Auth token is forwarded from the host app when configured.",thinking:"Thinking...",unableToCreateChat:"Unable to create chat",requestFailed:"Request failed",noRecentChats:"No recent chats yet.",noPinnedChats:"No pinned chats yet.",noChats:"No chats yet.",loadingChats:"Loading chats...",pinChat:"Pin chat",unpinChat:"Unpin chat",renameChat:"Rename",deleteChat:"Delete",chatActions:"Chat actions",renamePrompt:"Enter a new chat name",citationsAttached:e=>`${e} citation${e>1?"s":""} attached`,sourcesUsed:"Sources Used",allSourcesUsed:"All Sources Used",documentsAndReferences:"AI documents and references",showAll:"Show All",noSources:"No sources were returned for this answer.",closeSourcesPanel:"Close sources panel",openSource:"Open source",sourceScore:"Score",sourcePage:"Page",sourceSheet:"Sheet",sourceRow:"Row",sourceKnowledge:"Knowledge Base",untitledSource:"Untitled Source",copy:"Copy",copied:"Copied",helpful:"Helpful",notHelpful:"Needs work",send:"Send message",assistantAvatar:"Assistant",userAvatar:"User"},ar:{openChatActions:"\u0641\u062A\u062D \u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",newChat:"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629",myChats:"\u0645\u062D\u0627\u062F\u062B\u0627\u062A\u064A",openAssistant:"\u0641\u062A\u062D \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",back:"\u0631\u062C\u0648\u0639",close:"\u0625\u063A\u0644\u0627\u0642",assistantBadge:"\u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",closeAssistantPage:"\u0625\u063A\u0644\u0627\u0642 \u0635\u0641\u062D\u0629 \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",searchChat:"\u0627\u0628\u062D\u062B \u0641\u064A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A",recentActivity:"\u0627\u0644\u0646\u0634\u0627\u0637 \u0627\u0644\u0623\u062E\u064A\u0631",pinnedCollections:"\u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0627\u0644\u0645\u062B\u0628\u062A\u0629",answersBasedOnPermissions:"\u064A\u062A\u0645 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0625\u062C\u0627\u0628\u0627\u062A \u0628\u0646\u0627\u0621\u064B \u0639\u0644\u0649 \u0635\u0644\u0627\u062D\u064A\u0627\u062A \u0627\u0644\u0648\u0635\u0648\u0644 \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0643",authTokenForwarded:"\u064A\u062A\u0645 \u062A\u0645\u0631\u064A\u0631 \u0631\u0645\u0632 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0627\u0644\u062A\u0637\u0628\u064A\u0642 \u0627\u0644\u0645\u0636\u064A\u0641 \u0639\u0646\u062F \u0627\u0644\u0625\u0639\u062F\u0627\u062F.",thinking:"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631...",unableToCreateChat:"\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",requestFailed:"\u0641\u0634\u0644 \u0627\u0644\u0637\u0644\u0628",noRecentChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u062D\u062F\u064A\u062B\u0629 \u0628\u0639\u062F.",noPinnedChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0645\u062B\u0628\u062A\u0629 \u0628\u0639\u062F.",noChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0628\u0639\u062F.",loadingChats:"\u062C\u0627\u0631\u064D \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A...",pinChat:"\u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",unpinChat:"\u0625\u0644\u063A\u0627\u0621 \u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renameChat:"\u0625\u0639\u0627\u062F\u0629 \u062A\u0633\u0645\u064A\u0629",deleteChat:"\u062D\u0630\u0641",chatActions:"\u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renamePrompt:"\u0623\u062F\u062E\u0644 \u0627\u0633\u0645\u064B\u0627 \u062C\u062F\u064A\u062F\u064B\u0627 \u0644\u0644\u0645\u062D\u0627\u062F\u062B\u0629",citationsAttached:e=>`\u062A\u0645 \u0625\u0631\u0641\u0627\u0642 ${e} \u0645\u0631\u062C\u0639${e>1?"\u0627\u062A":""}`,sourcesUsed:"\u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",allSourcesUsed:"\u0643\u0644 \u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",documentsAndReferences:"\u0645\u0633\u062A\u0646\u062F\u0627\u062A \u0648\u0645\u0631\u0627\u062C\u0639 \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A",showAll:"\u0639\u0631\u0636 \u0627\u0644\u0643\u0644",noSources:"\u0644\u0645 \u064A\u062A\u0645 \u0625\u0631\u062C\u0627\u0639 \u0645\u0635\u0627\u062F\u0631 \u0644\u0647\u0630\u0647 \u0627\u0644\u0625\u062C\u0627\u0628\u0629.",closeSourcesPanel:"\u0625\u063A\u0644\u0627\u0642 \u0644\u0648\u062D\u0629 \u0627\u0644\u0645\u0635\u0627\u062F\u0631",openSource:"\u0641\u062A\u062D \u0627\u0644\u0645\u0635\u062F\u0631",sourceScore:"\u0627\u0644\u062F\u0631\u062C\u0629",sourcePage:"\u0627\u0644\u0635\u0641\u062D\u0629",sourceSheet:"\u0627\u0644\u0648\u0631\u0642\u0629",sourceRow:"\u0627\u0644\u0635\u0641",sourceKnowledge:"\u0642\u0627\u0639\u062F\u0629 \u0627\u0644\u0645\u0639\u0631\u0641\u0629",untitledSource:"\u0645\u0635\u062F\u0631 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646",copy:"\u0646\u0633\u062E",copied:"\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",helpful:"\u0645\u0641\u064A\u062F",notHelpful:"\u064A\u062D\u062A\u0627\u062C \u062A\u062D\u0633\u064A\u0646",send:"\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629",assistantAvatar:"\u0627\u0644\u0645\u0633\u0627\u0639\u062F",userAvatar:"\u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645"}};function de(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=ct(e),o=Ae(t.locale),n=pn(t.locale),i=cn(o),s={chatId:ce(t),open:!1,fullPageOpen:!1,myChatsOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1,sourcePanelOpen:!1,sourcePanelTitle:null},d=document.createElement("div");d.dataset.chatWidgetHost="true",t.mount.appendChild(d);let l=d.attachShadow({mode:"open"});ut(l,t.theme);let p=a("div",`kp-chat-widget ${t.position}`);p.lang=o,p.dir=i?"rtl":"ltr",i&&p.classList.add("kp-rtl");let u=a("div","kp-overlay"),g=a("button","kp-launcher");g.type="button",g.setAttribute("aria-label",t.launcherAriaLabel),g.innerHTML=['<span class="kp-star-cluster" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let f=a("section","kp-panel");f.setAttribute("role","dialog"),f.setAttribute("aria-modal","true"),f.setAttribute("aria-label",t.title);let m=a("div","kp-header"),y=a("div","kp-toolbar"),b=a("button","kp-tool-button kp-menu-trigger");b.type="button",b.setAttribute("aria-label",n.openChatActions),b.innerHTML=['<span class="kp-pencil-icon" aria-hidden="true"></span>','<span class="kp-chevron" aria-hidden="true">\u2304</span>'].join("");let x=a("div","kp-dropdown"),v=a("button","kp-dropdown-item",n.newChat);v.type="button";let k=a("button","kp-dropdown-item",n.myChats);k.type="button";let $=a("button","kp-dropdown-item",n.openAssistant);$.type="button",x.append(v,k,$),y.append(b,x);let C=a("div","kp-title-wrap"),Lt=a("h2","kp-title",t.title),At=a("div","kp-subtitle",t.subtitle);C.append(Lt,At);let Q=a("button","kp-close","\xD7");Q.type="button",Q.setAttribute("aria-label",t.closeAriaLabel),m.append(y,C,Q);let Z=a("div","kp-body"),ue=a("div","kp-hero"),Pt=a("div","kp-hero-icon","\u2726"),St=a("div","kp-hero-text",t.welcomeMessage);ue.append(Pt,St);let Pe=a("div","kp-footer"),ge=a("form","kp-form"),S=a("input","kp-input");S.type="text",S.autocomplete="off",S.placeholder=t.inputPlaceholder,S.setAttribute("aria-label",t.inputPlaceholder);let fe=a("button","kp-send","\u279C");fe.type="submit",fe.setAttribute("aria-label",n.send);let Tt=a("div","kp-note",n.authTokenForwarded);ge.append(S,fe),Pe.append(ge,Tt),f.append(m,Z,Pe),p.append(u,g,f),l.appendChild(p),Z.appendChild(ue);let Se=a("div","kp-suggestions");Z.appendChild(Se);let ee=a("section","kp-my-chats-sheet"),Te=a("div","kp-my-chats-header"),te=a("button","kp-my-chats-nav","\u2190");te.type="button",te.setAttribute("aria-label",n.back);let ne=a("button","kp-my-chats-nav kp-my-chats-close","\xD7");ne.type="button",ne.setAttribute("aria-label",n.close),Te.append(te,ne);let Ee=a("div","kp-my-chats-body"),Et=a("div","kp-my-chats-section-label",n.recentActivity),Ie=a("div","kp-my-chats-list"),It=a("div","kp-my-chats-section-label",n.pinnedCollections),Re=a("div","kp-my-chats-list");Ee.append(Et,Ie,It,Re),ee.append(Te,Ee),f.appendChild(ee);let A={body:Z,input:S,suggestions:Se,hero:ue,kind:"panel"},T=a("section","kp-full-page");T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",`${t.title} page`);let $e=a("div","kp-full-page-shell"),He=a("div","kp-full-page-header"),ze=a("div","kp-full-page-brand"),Rt=a("div","kp-full-page-brand-mark","\u2726"),$t=a("div","kp-full-page-brand-text",t.title);ze.append(Rt,$t);let Me=a("div","kp-full-page-header-actions"),Ht=a("div","kp-full-page-badge",n.assistantBadge),oe=a("button","kp-full-page-close","\xD7");oe.type="button",oe.setAttribute("aria-label",n.closeAssistantPage),Me.append(Ht,oe),He.append(ze,Me);let Ne=a("div","kp-full-page-content"),Be=a("aside","kp-full-page-sidebar"),he=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);he.type="button";let Ue=a("div","kp-full-page-search"),V=a("input","kp-full-page-search-input");V.type="search",V.placeholder=n.searchChat;let zt=a("span","kp-full-page-search-icon","\u2315");Ue.append(V,zt);let Mt=a("div","kp-full-page-section-label",n.recentActivity),Oe=a("div","kp-full-page-recent-list"),Nt=a("div","kp-full-page-section-label",n.pinnedCollections),We=a("div","kp-full-page-pinned-list");Be.append(he,Ue,Mt,Oe,Nt,We);let je=a("main","kp-full-page-main"),De=a("section","kp-full-page-panel"),me=a("div","kp-full-page-body"),be=a("div","kp-full-page-hero"),Ve=a("div","kp-full-page-hero-badge");Ve.innerHTML=['<span class="kp-star-cluster kp-star-cluster-static" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let Bt=a("div","kp-full-page-hero-text",t.welcomeMessage);be.append(Ve,Bt);let qe=a("div","kp-suggestions kp-full-page-suggestions");me.append(be,qe);let _e=a("div","kp-full-page-footer"),ke=a("form","kp-form kp-full-page-form"),P=a("input","kp-input kp-full-page-input");P.type="text",P.autocomplete="off",P.placeholder=t.inputPlaceholder,P.setAttribute("aria-label",t.inputPlaceholder);let xe=a("button","kp-send kp-full-page-send","\u279C");xe.type="submit",xe.setAttribute("aria-label",n.send);let Ut=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);ke.append(P,xe),_e.append(ke,Ut),De.append(me,_e),je.appendChild(De);let ae=a("aside","kp-source-panel"),Fe=a("div","kp-source-panel-header"),Ke=a("div","kp-source-panel-title-wrap"),Xe=a("div","kp-source-panel-title",n.allSourcesUsed),Ot=a("div","kp-source-panel-subtitle",n.documentsAndReferences);Ke.append(Xe,Ot);let se=a("button","kp-source-panel-close","\xD7");se.type="button",se.setAttribute("aria-label",n.closeSourcesPanel),Fe.append(Ke,se);let q=a("div","kp-source-panel-list"),Wt=a("div","kp-source-panel-empty",n.noSources);q.appendChild(Wt),ae.append(Fe,q),Ne.append(Be,je,ae),$e.append(He,Ne),T.appendChild($e),p.appendChild(T);let L={body:me,input:P,suggestions:qe,hero:be,kind:"full-page"},H=()=>({...t,getAccessToken:s.accessTokenProvider}),Ye=async()=>{if(!t.getUserContext)return null;try{let r=await t.getUserContext();return r?.displayName?.trim()||r?.email?.trim()||r?.userId?.trim()||null}catch{return null}},_=(r,c)=>{if(s.sourcePanelOpen=!0,s.sourcePanelTitle=c??n.allSourcesUsed,Xe.textContent=s.sourcePanelTitle,ae.classList.add("open"),q.textContent="",r.length===0){q.appendChild(a("div","kp-source-panel-empty",n.noSources));return}for(let h of r)q.appendChild(xn(h,n))},re=()=>{s.sourcePanelOpen=!1,s.sourcePanelTitle=null,ae.classList.remove("open")};j(A,t.initialSuggestions,async r=>{await E(r,A)}),j(L,t.initialSuggestions,async r=>{await E(r,L)}),N(),ie();function Ge(){s.open||(s.open=!0,s.fullPageOpen=!1,I(),T.classList.remove("open"),g.classList.add("hidden"),u.classList.add("visible"),f.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&ye.loadHistory(),queueMicrotask(()=>S.focus()))}function F(){s.open&&(z(),I(),s.open=!1,g.classList.remove("hidden"),u.classList.remove("visible"),f.classList.remove("open"),t.onClose?.())}async function E(r,c){let h=r.trim();if(!h)return;c.input.value="";try{await _t(h)}catch(R){let K=U(t,R);G(c.body,"bot",`${n.unableToCreateChat}: ${K.message}`,{strings:n,view:c,userName:null,onShowSources:_});return}ft(c),G(c.body,"user",h,{strings:n,view:c,userName:await Ye(),onShowSources:_}),c.body.scrollTop=c.body.scrollHeight;let B=a("div","kp-loading",n.thinking);c.body.appendChild(B),c.body.scrollTop=c.body.scrollHeight;try{let R=await st(H(),{message:h,chatId:s.chatId,knowledgeNames:await nn(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});B.isConnected&&B.remove(),G(c.body,"bot",R.answer,{strings:n,view:c,userName:null,citations:R.citations??[],onShowSources:_}),s.historyLoadedChatId=null,await M(),R.suggestions?.length&&j(c,R.suggestions,async K=>{await E(K,c)})}catch(R){let K=U(t,R);B.isConnected&&B.remove(),G(c.body,"bot",`${n.requestFailed}: ${K.message}`,{strings:n,view:c,userName:null,onShowSources:_})}}async function Je(r){let c=s.fullPageOpen?L:A;await E(r,c)}async function jt(){s.fullPageOpen=!0,s.open=!1,z(),I(),f.classList.remove("open"),u.classList.remove("visible"),g.classList.add("hidden"),T.classList.add("open"),await M(),await le(L,s.chatId),queueMicrotask(()=>P.focus())}function Qe(){s.fullPageOpen&&(s.fullPageOpen=!1,T.classList.remove("open"),g.classList.remove("hidden"),re())}function Dt(){s.menuOpen=!0,b.classList.add("open"),x.classList.add("open")}function z(){s.menuOpen=!1,b.classList.remove("open"),x.classList.remove("open")}function Vt(){s.chatId=ce(t),s.historyLoadedChatId=null,I(),Y(A),j(A,t.initialSuggestions,async r=>{await E(r,A)}),z()}async function qt(){s.chatId=ce(t),s.historyLoadedChatId=null,Y(L),re(),j(L,t.initialSuggestions,async r=>{await E(r,L)}),N()}async function M(){if(!t.endpoints.listChats)return N(),ie(),[];s.loadingChats=!0,N(),ie();try{let r=await it(H());return s.chats=r,r}catch(r){return U(t,r),s.chats}finally{s.loadingChats=!1,N(),ie()}}async function _t(r){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(c=>c.chatId===s.chatId)||await lt(H(),s.chatId,r?ln(r,n.newChat):void 0)}async function Ft(r){s.chatId=r,s.historyLoadedChatId=null,await le(L,r),N()}async function Kt(r){s.chatId=r,s.historyLoadedChatId=null,await le(A,r),I()}async function Xt(){z(),await M(),s.myChatsOpen=!0,f.classList.add("kp-sheet-open"),ee.classList.add("open")}function I(){s.myChatsOpen=!1,f.classList.remove("kp-sheet-open"),ee.classList.remove("open")}async function Ze(r){if(!t.endpoints.updateChat)return;let c=window.prompt(n.renamePrompt,r.title)?.trim();if(!(!c||c===r.title))try{await Ce(H(),r.chatId,{title:c}),await M()}catch(h){U(t,h)}}async function et(r){if(t.endpoints.deleteChat)try{await pt(H(),r.chatId),s.chatId===r.chatId&&(s.chatId=ce(t),s.historyLoadedChatId=null,Y(A),Y(L)),await M()}catch(c){U(t,c)}}function N(){ht(Oe,We,s,n,async r=>{await Ft(r.chatId)},async r=>{await tt(r)},async r=>{await Ze(r)},async r=>{await et(r)})}function ie(){ht(Ie,Re,s,n,async r=>{await Kt(r.chatId)},async r=>{await tt(r)},async r=>{await Ze(r)},async r=>{await et(r)})}async function tt(r){if(t.endpoints.updateChat)try{await Ce(H(),r.chatId,{pinned:!r.pinned}),await M()}catch(c){U(t,c)}}async function le(r,c){Y(r),j(r,t.initialSuggestions,async B=>{await E(B,r)});let h=await rt(H(),c);return h.length>0&&(ft(r),bt(r.body,r.hero,r.suggestions),rn(r.body,h,{strings:n,view:r,userName:await Ye(),onShowSources:_})),s.historyLoadedChatId=c,h}let ye={open:Ge,close:F,toggle(){if(s.open){F();return}Ge()},destroy(){document.removeEventListener("keydown",nt),d.remove()},sendMessage:Je,setAccessTokenProvider(r){s.accessTokenProvider=r},getChatId(){return s.chatId},loadChats(){return M()},async loadHistory(){let r=s.fullPageOpen?L:A;return le(r,s.chatId)}};g.addEventListener("click",()=>ye.toggle()),Q.addEventListener("click",F),u.addEventListener("click",F),se.addEventListener("click",re),te.addEventListener("click",I),ne.addEventListener("click",I),b.addEventListener("click",r=>{if(r.stopPropagation(),!s.menuOpen){Dt();return}z()}),v.addEventListener("click",Vt),k.addEventListener("click",async()=>{await Xt()}),$.addEventListener("click",()=>{jt()}),oe.addEventListener("click",Qe),he.addEventListener("click",()=>{qt(),queueMicrotask(()=>P.focus())}),V.addEventListener("input",()=>{s.chatSearchTerm=V.value.trim().toLowerCase(),N()}),f.addEventListener("click",r=>{let c=r.target;if(!(c instanceof Element)||!c.closest(".kp-chat-actions")){for(let h of Array.from(l.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(l.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}s.menuOpen&&!x.contains(c)&&!b.contains(c)&&z(),r.stopPropagation()}),l.addEventListener("click",r=>{let c=r.target;if(s.menuOpen&&c instanceof Node&&!x.contains(c)&&!b.contains(c)&&z(),c instanceof Element&&!c.closest(".kp-chat-actions")){for(let h of Array.from(l.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(l.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}}),ge.addEventListener("submit",async r=>{r.preventDefault(),await Je(S.value)}),ke.addEventListener("submit",async r=>{r.preventDefault(),await E(P.value,L)});function nt(r){if(r.key==="Escape"){if(s.sourcePanelOpen){re();return}if(s.myChatsOpen){I();return}if(s.fullPageOpen){Qe();return}s.open&&F()}}return document.addEventListener("keydown",nt),ye}async function nn(e){if(e.rag.getKnowledgeNames){let t=await e.rag.getKnowledgeNames();return Array.isArray(t)?t.filter(Boolean):[]}return(e.rag.knowledgeNames??[]).filter(Boolean)}function ce(e){return e.rag.chatId?.trim()?e.rag.chatId:e.rag.chatIdFactory?e.rag.chatIdFactory():typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`kp-chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function G(e,t,o,n){let i=t==="bot"?un(o,n.citations??[]):{displayText:o,citations:n.citations??[]},s=a("div",`kp-message-row ${t}`),d=an(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),l=a("div",`kp-bubble ${t}`),p=a("div","kp-bubble-content");vn(p,i.displayText),l.appendChild(p);let u=i.citations;if(u.length){let g=a("div","kp-meta",n.strings.citationsAttached(u.length));l.appendChild(g);let f=a("div","kp-source-preview"),m=a("div","kp-source-preview-title",n.strings.sourcesUsed),y=a("div","kp-source-preview-list");for(let x of u.slice(0,2)){let v=bn(x,n.strings);v.addEventListener("click",async()=>{xt(x,n.strings)}),y.appendChild(v)}let b=kn(n.strings);b.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),y.appendChild(b),f.append(m,y),l.appendChild(f)}return t==="bot"&&l.appendChild(on(i.displayText,n.strings)),t==="user"?s.append(l,d):s.append(d,l),e.appendChild(s),e.scrollTop=e.scrollHeight,s}function on(e,t){let o=a("div","kp-message-actions"),n=a("button","kp-message-action",t.copy);n.type="button",n.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(e),n.textContent=t.copied,window.setTimeout(()=>{n.textContent=t.copy},1200)}catch{n.textContent=t.copy}});let i=a("button","kp-message-action","\u{1F44D}");i.type="button",i.setAttribute("aria-label",t.helpful),i.addEventListener("click",()=>{i.classList.toggle("active"),s.classList.remove("active")});let s=a("button","kp-message-action","\u{1F44E}");return s.type="button",s.setAttribute("aria-label",t.notHelpful),s.addEventListener("click",()=>{s.classList.toggle("active"),i.classList.remove("active")}),o.append(n,i,s),o}function an(e,t){let o=a("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":dn(e);return o.textContent=n,o.setAttribute("aria-hidden","true"),o}function sn(e,t,o){e.textContent="";for(let n of t){let i=a("button","kp-suggestion",n);i.type="button",i.addEventListener("click",async()=>{await o(n)}),e.appendChild(i)}}function j(e,t,o){sn(e.suggestions,t,async n=>{e.input.value=n,await o(n)})}function bt(e,t,o){let n=new Set([t,o]);for(let i of Array.from(e.children))n.has(i)||i.remove()}function ft(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function Y(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),bt(e.body,e.hero,e.suggestions),e.input.value=""}function rn(e,t,o){for(let n of t)G(e,n.role==="assistant"?"bot":"user",n.text,o)}function ht(e,t,o,n,i,s,d,l){if(e.textContent="",t.textContent="",o.loadingChats){e.appendChild(a("div","kp-full-page-empty",n.loadingChats));return}let p=o.chats.filter(u=>o.chatSearchTerm?u.title.toLowerCase().includes(o.chatSearchTerm):!0);if(p.length>0){let u=p.filter(f=>f.pinned),g=p.filter(f=>!f.pinned).slice(0,8);mt(e,g,o.chatId,n,i,s,d,l),mt(t,u,o.chatId,n,i,s,d,l),g.length===0&&e.appendChild(a("div","kp-full-page-empty",n.noRecentChats)),u.length===0&&t.appendChild(a("div","kp-full-page-empty",n.noPinnedChats));return}e.appendChild(a("div","kp-full-page-empty",n.noChats)),t.appendChild(a("div","kp-full-page-empty",n.noPinnedChats))}function mt(e,t,o,n,i,s,d,l){for(let p of t){let u=a("div",`kp-full-page-item kp-full-page-chat-item${p.chatId===o?" active":""}`),g=a("span","kp-full-page-item-title",p.title),f=a("div","kp-chat-actions"),m=a("button","kp-chat-actions-trigger","\u22EF");m.type="button",m.setAttribute("aria-label",n.chatActions);let y=a("div","kp-chat-actions-menu"),b=a("button","kp-chat-actions-item",p.pinned?n.unpinChat:n.pinChat);b.type="button",b.addEventListener("click",async k=>{k.stopPropagation(),await s(p)});let x=a("button","kp-chat-actions-item",n.renameChat);x.type="button",x.addEventListener("click",async k=>{k.stopPropagation(),await d(p)});let v=a("button","kp-chat-actions-item",n.deleteChat);v.type="button",v.addEventListener("click",async k=>{k.stopPropagation(),await l(p)}),y.append(b,x,v),f.append(m,y),m.addEventListener("click",k=>{k.stopPropagation();let $=f.classList.contains("open");for(let C of Array.from(e.querySelectorAll(".kp-chat-actions.open")))C.classList.remove("open");for(let C of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))C.classList.remove("menu-open");$||(f.classList.add("open"),u.classList.add("menu-open"))}),u.append(g,f),u.setAttribute("role","button"),u.tabIndex=0,u.addEventListener("click",async()=>{await i(p)}),u.addEventListener("keydown",async k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),await i(p))}),u.addEventListener("blur",()=>{f.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function ln(e,t){return e.trim().slice(0,60)||t}function Ae(e){return e.toLowerCase().split("-")[0]||"en"}function pn(e){let t=gt.en;return gt[Ae(e)]??t}function cn(e){return["ar","fa","he","ur"].includes(Ae(e))}function dn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(o=>o[0]?.toUpperCase()??"").join("")}function kt(e){return e.knowledgeName?.trim()||e.sourceDocument?.trim()||null}function un(e,t){let o=gn(e);return{displayText:o.displayText,citations:t.length>0?mn(t,o.citations):o.citations}}function gn(e){let o=yt(e).split(`
1377
+ `),n=-1;for(let p=0;p<o.length;p+=1)/^#{0,6}\s*References\s*$/i.test(o[p]?.trim()??"")&&(n=p);if(n===-1)return{displayText:e,citations:[]};let i=o.slice(0,n).join(`
1378
+ `).trimEnd(),s=o.slice(n+1).join(`
1379
+ `).trim(),l=fn(s).map(p=>hn(p)).filter(p=>!!p);return{displayText:i,citations:l}}function fn(e){let t=[],o="";for(let n of e.split(`
1380
+ `)){let i=n.trim();if(i){if(/^\d+\.\s+/.test(i)){o&&t.push(o.trim()),o=i.replace(/^\d+\.\s+/,"");continue}o&&(o=`${o} ${i}`)}}return o&&t.push(o.trim()),t}function hn(e){let t=e.match(/https?:\/\/\S+/i);if(!t)return null;let o=t[0],n=e.slice(0,t.index).replace(/[.\s]+$/,"").trim();return{sourceDocument:o,knowledgeName:n||o}}function mn(e,t){let o=[],n=new Set;for(let i of[...e,...t]){let s=`${i.knowledgeName??""}::${i.sourceDocument??""}`;n.has(s)||(n.add(s),o.push(i))}return o}function bn(e,t){let o=a("button","kp-source-chip");o.type="button",o.setAttribute("aria-label",t.openSource);let n=a("span","kp-source-thumb");n.textContent="\u2726";let i=a("span","kp-source-chip-label",kt(e)??t.untitledSource);return o.append(n,i),o}function kn(e){let t=a("button","kp-source-chip kp-source-chip-more");t.type="button";let o=a("span","kp-source-thumb-stack");for(let i=0;i<3;i+=1){let s=a("span","kp-source-thumb stacked");s.textContent="\u2726",o.appendChild(s)}let n=a("span","kp-source-chip-label",e.showAll);return t.append(o,n),t}function xn(e,t){let o=a("button","kp-source-card");o.type="button",o.setAttribute("aria-label",t.openSource),o.addEventListener("click",()=>{xt(e,t)});let n=a("div","kp-source-card-media"),i=a("span","kp-source-thumb kp-source-thumb-large");i.textContent="\u2726";let s=a("div","kp-source-card-title",kt(e)??t.untitledSource),d=a("div","kp-source-card-meta"),l=[];return typeof e.score=="number"&&l.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&l.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&l.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&l.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&l.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),d.textContent=l.join(" \u2022 "),n.appendChild(i),o.append(n,s,d),o}function xt(e,t){let o=e.sourceDocument?.trim()||e.knowledgeName?.trim()||t.untitledSource,n=yn(e.sourceDocument);if(n){window.open(n,"_blank","noopener,noreferrer");return}let i=window.open("","_blank","noopener,noreferrer");if(!i)return;let s=J(o),d=wn(e,t).map(l=>`<li>${J(l)}</li>`).join("");i.document.write(`<!doctype html>
1381
+ <html lang="en">
1382
+ <head>
1383
+ <meta charset="utf-8">
1384
+ <title>${s}</title>
1385
+ <style>
1386
+ body { font-family: Arial, sans-serif; margin: 32px; color: #1f2937; }
1387
+ .card { max-width: 720px; padding: 24px; border: 1px solid #dbe4ee; border-radius: 16px; background: #fff; }
1388
+ h1 { margin: 0 0 12px; font-size: 24px; }
1389
+ p { margin: 0 0 16px; color: #64748b; }
1390
+ ul { margin: 0; padding-left: 20px; }
1391
+ </style>
1392
+ </head>
1393
+ <body>
1394
+ <div class="card">
1395
+ <h1>${s}</h1>
1396
+ <p>${J(t.documentsAndReferences)}</p>
1397
+ <ul>${d||`<li>${J(t.noSources)}</li>`}</ul>
1398
+ </div>
1399
+ </body>
1400
+ </html>`),i.document.close()}function yn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function wn(e,t){let o=[];return e.sourceDocument&&o.push(e.sourceDocument),typeof e.score=="number"&&o.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&o.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&o.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&o.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&o.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),o}function vn(e,t){e.innerHTML=Cn(yt(t))}function yt(e){return e.replace(/\r\n/g,`
1401
+ `).replace(/<br\s*\/?>/gi,`
1402
+ `)}function Cn(e){return e.split(/\n{2,}/).map(o=>o.trim()).filter(Boolean).map(Ln).join("")}function Ln(e){let t=e.split(`
1403
+ `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return An(t);if(t.every(n=>/^\d+\.\s+/.test(n)))return`<ol>${t.map(n=>`<li>${D(n.replace(/^\d+\.\s+/,""))}</li>`).join("")}</ol>`;if(t.every(n=>/^[-*]\s+/.test(n)))return`<ul>${t.map(n=>`<li>${D(n.replace(/^[-*]\s+/,""))}</li>`).join("")}</ul>`;let o=t[0]?.match(/^(#{1,6})\s+(.*)$/);if(o){let n=o[1]??"#",i=o[2]??"",s=n.length;return`<h${s}>${D(i)}</h${s}>`}return`<p>${t.map(n=>D(n)).join("<br>")}</p>`}function An(e){let t=e.filter((d,l)=>!(l===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(d))).map(d=>Pn(d));if(t.length===0)return"";let o=t[0]??[],n=t.slice(1),i=`<thead><tr>${o.map(d=>`<th>${D(d)}</th>`).join("")}</tr></thead>`,s=n.length?`<tbody>${n.map(d=>`<tr>${d.map(l=>`<td>${D(l)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${i}${s}</table></div>`}function Pn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function D(e){let t=J(e);return t=t.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g,'<a href="$2" target="_blank" rel="noreferrer">$1</a>'),t=t.replace(/`([^`]+)`/g,"<code>$1</code>"),t=t.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*([^*]+)\*/g,"<em>$1</em>"),t}function J(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}var wt="0.1.0",vt=de,Ct={init:vt,createChatWidget:de,version:wt};typeof window<"u"&&(window.ChatWidget=Ct);0&&(module.exports={browserGlobal,createChatWidget,init,version});
872
1404
  //# sourceMappingURL=browser.cjs.map