@nabeh/chat-widget 0.1.0 → 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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var re=Object.defineProperty;var lt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var ct=Object.prototype.hasOwnProperty;var ut=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},gt=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of dt(t))!ct.call(e,i)&&i!==n&&re(e,i,{get:()=>t[i],enumerable:!(s=lt(t,i))||s.enumerable});return e};var ft=e=>gt(re({},"__esModule",{value:!0}),e);var yt={};ut(yt,{createChatWidget:()=>qe});module.exports=ft(yt);function Se(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ie(e,t){let n={...e};for(let s of Object.keys(t)){let i=t[s],l=n[s];if(Se(l)&&Se(i)){n[s]=ie(l,i);continue}i!==void 0&&(n[s]=i)}return n}function ze(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 pe(e,t,n={}){let s=t.replace(/\{chatId\}/g,encodeURIComponent(n.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(n.chatId??""));return V(e.apiBaseUrl,s)}async function We(e,t){let n=e.getAccessToken?await e.getAccessToken():null,s=await _(e),i=pe(e,e.endpoints.ask,{chatId:t.chatId}),r=/(\{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,s),body:JSON.stringify(r)});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??[],K=f?.knowledge_names??[],J=g.map((G,b)=>({sourceDocument:G,score:m[b]??null,pageNumber:z[b]??null,sheetName:W[b]??null,rowNumber:N[b]??null,knowledgeName:K[b]??null}));return{chatId:t.chatId,answer:c.answer,suggestions:[],citations:J}}async function Ne(e,t){if(!e.endpoints.history)return[];let n=e.getAccessToken?await e.getAccessToken():null,s=await _(e),l=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?pe(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()})(),r=await fetch(l,{method:"GET",headers:D(e,n,s)});if(!r.ok)throw new Error(`Chat history endpoint returned ${r.status}.`);let u=await r.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 Oe(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,n=await _(e),s=await fetch(V(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:D(e,t,n)});if(!s.ok)throw new Error(`Chat list endpoint returned ${s.status}.`);let i=await s.json();return Array.isArray(i)?i.map(l=>{if(!l||typeof l!="object")return null;let r=l,u=r.chatId??r.chat_id??r.id,p=r.title??r.name??r.chatId;if(typeof u!="string"||typeof p!="string")return null;let c=typeof r.createdAt=="string"?r.createdAt:typeof r.created_at=="string"?r.created_at:null,f=typeof r.updatedAt=="string"?r.updatedAt:typeof r.updated_at=="string"?r.updated_at:null,g={chatId:u,title:p,pinned:typeof r.pinned=="boolean"?r.pinned:!1};return c&&(g.createdAt=c),f&&(g.updatedAt=f),g}).filter(l=>!!l):[]}async function Ue(e,t,n){let s=e.endpoints.createChat??e.endpoints.listChats;if(!s)return;let i=e.getAccessToken?await e.getAccessToken():null,l=await _(e),r=await fetch(V(e.apiBaseUrl,s),{method:"POST",headers:D(e,i,l),body:JSON.stringify({chatId:t,...n?{title:n}:{}})});if(!r.ok)throw new Error(`Create chat endpoint returned ${r.status}.`)}async function Be(e,t,n){if(!e.endpoints.updateChat)return;let s=e.getAccessToken?await e.getAccessToken():null,i=await _(e),l=pe(e,e.endpoints.updateChat,{chatId:t}),r=await fetch(l,{method:"PATCH",headers:D(e,s,i),body:JSON.stringify(n)});if(!r.ok)throw new Error(`Update chat endpoint returned ${r.status}.`)}function j(e,t){let n=ze(t);return e.onError?.(n),n}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'},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:le,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0};function $e(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=ie(le,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 s=document.createElement(e);return t&&(s.className=t),n!==void 0&&(s.textContent=n),s}var Ve="kp-chat-widget-styles";function De(e,t){if(e.getElementById(Ve))return;let n=document.createElement("style");n.id=Ve,n.textContent=ht(t),e.appendChild(n)}function ht(e){return`
1
+ "use strict";var ye=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Xt=Object.prototype.hasOwnProperty;var Yt=(e,t)=>{for(var o in t)ye(e,o,{get:t[o],enumerable:!0})},Jt=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Kt(t))!Xt.call(e,i)&&i!==o&&ye(e,i,{get:()=>t[i],enumerable:!(n=Ft(t,i))||n.enumerable});return e};var Gt=e=>Jt(ye({},"__esModule",{value:!0}),e);var Ln={};Yt(Ln,{createChatWidget:()=>mt});module.exports=Gt(Ln);function nt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function we(e,t){let o={...e};for(let n of Object.keys(t)){let i=t[n],s=o[n];if(nt(s)&&nt(i)){o[n]=we(s,i);continue}i!==void 0&&(o[n]=i)}return o}function ot(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 le(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 at(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),i=le(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},p=await fetch(i,{method:"POST",headers:O(e,o,n),body:JSON.stringify(d)});if(!p.ok)throw new Error(`Chat backend returned ${p.status}.`);let l=await p.json();if(!Array.isArray(l)){if(!l.answer||typeof l.answer!="string")throw new Error("Chat backend response is missing a valid answer.");return{chatId:l.chatId??t.chatId,answer:l.answer,suggestions:l.suggestions??[],citations:l.citations??[]}}let u=l[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 st(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)?le(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 p=await d.json(),l=Array.isArray(p)?p:p&&typeof p=="object"?p.history??p.messages??p.data??[]:[];return Array.isArray(l)?l.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 rt(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 p=d,l=p.chatId??p.chat_id??p.id,u=p.title??p.name??p.chatId;if(typeof l!="string"||typeof u!="string")return null;let g=typeof p.createdAt=="string"?p.createdAt:typeof p.created_at=="string"?p.created_at:null,f=typeof p.updatedAt=="string"?p.updatedAt:typeof p.updated_at=="string"?p.updated_at:null,m={chatId:l,title:u,pinned:typeof p.pinned=="boolean"?p.pinned:!1};return g&&(m.createdAt=g),f&&(m.updatedAt=f),m}).filter(d=>!!d):[]}async function it(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 ve(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,i=await W(e),s=le(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=le(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=ot(t);return e.onError?.(o),o}var Ce={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:Ce,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0};function lt(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=we(Ce,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 ct="kp-chat-widget-styles";function dt(e,t){if(e.getElementById(ct))return;let o=document.createElement("style");o.id=ct,o.textContent=Qt(t),e.appendChild(o)}function Qt(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 qe(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=$e(e),n={chatId:de(t),open:!1,fullPageOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1},s=document.createElement("div");s.dataset.chatWidgetHost="true",t.mount.appendChild(s);let i=s.attachShadow({mode:"open"});De(i,t.theme);let l=o("div",`kp-chat-widget ${t.position}`),r=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 K=o("div","kp-title-wrap"),J=o("h2","kp-title",t.title),G=o("div","kp-subtitle",t.subtitle);K.append(J,G);let b=o("button","kp-close","\xD7");b.type="button",b.setAttribute("aria-label",t.closeAriaLabel),c.append(f,K,b);let F=o("div","kp-body"),Q=o("div","kp-hero"),Fe=o("div","kp-hero-icon","\u2726"),Xe=o("div","kp-hero-text",t.welcomeMessage);Q.append(Fe,Xe);let ue=o("div","kp-footer"),Z=o("form","kp-form"),I=o("input","kp-input");I.type="text",I.autocomplete="off",I.placeholder=t.inputPlaceholder;let ge=o("button","kp-send","\u279C");ge.type="submit";let Ye=o("div","kp-note","Auth token is forwarded from the host app when configured.");Z.append(I,ge),ue.append(Z,Ye),p.append(c,F,ue),l.append(r,u,p),i.appendChild(l),F.appendChild(Q);let fe=o("div","kp-suggestions");F.appendChild(fe);let A={body:F,input:I,suggestions:fe,hero:Q},x=o("section","kp-full-page");x.setAttribute("role","dialog"),x.setAttribute("aria-modal","true"),x.setAttribute("aria-label",`${t.title} page`);let he=o("div","kp-full-page-shell"),me=o("div","kp-full-page-header"),be=o("div","kp-full-page-brand"),Je=o("div","kp-full-page-brand-mark","\u2726"),Ge=o("div","kp-full-page-brand-text",t.title);be.append(Je,Ge);let ke=o("div","kp-full-page-header-actions"),Qe=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"),ke.append(Qe,X),me.append(be,ke);let Ze=o("div","kp-full-page-breadcrumb","Home \u203A Knowledge Assistant"),xe=o("div","kp-full-page-content"),ye=o("aside","kp-full-page-sidebar"),ee=o("button","kp-full-page-new-chat","+ New Chat");ee.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 et=o("span","kp-full-page-search-icon","\u2315");ve.append(O,et);let tt=o("div","kp-full-page-section-label","Recent Activity"),y=o("div","kp-full-page-recent-list"),nt=o("div","kp-full-page-section-label","Pinned Collections"),v=o("div","kp-full-page-pinned-list");ye.append(ee,ve,tt,y,nt,v);let we=o("main","kp-full-page-main"),Ce=o("section","kp-full-page-panel"),te=o("div","kp-full-page-body"),ne=o("div","kp-full-page-hero"),Le=o("div","kp-full-page-hero-badge");Le.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 at=o("div","kp-full-page-hero-text",t.welcomeMessage);ne.append(Le,at);let Pe=o("div","kp-suggestions kp-full-page-suggestions");te.append(ne,Pe);let Ie=o("div","kp-full-page-footer"),ae=o("form","kp-form kp-full-page-form"),w=o("input","kp-input kp-full-page-input");w.type="text",w.autocomplete="off",w.placeholder=t.inputPlaceholder;let Ae=o("button","kp-send kp-full-page-send","\u279C");Ae.type="submit";let ot=o("div","kp-note kp-full-page-note","Answers are generated based on your access permissions");ae.append(w,Ae),Ie.append(ae,ot),Ce.append(te,Ie),we.appendChild(Ce),xe.append(ye,we),he.append(me,Ze,xe),x.appendChild(he),l.appendChild(x);let k={body:te,input:w,suggestions:Pe,hero:ne},U=()=>({...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,v,n,async a=>{await E(a.chatId)},async a=>{await H(a)});function Te(){n.open||(n.open=!0,n.fullPageOpen=!1,x.classList.remove("open"),u.classList.add("hidden"),r.classList.add("visible"),p.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&se.loadHistory(),queueMicrotask(()=>I.focus()))}function B(){n.open&&(T(),n.open=!1,u.classList.remove("hidden"),r.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 pt(L)}catch(P){let $=j(t,P);q(d.body,"bot",`Unable to create chat: ${$.message}`);return}_e(d),q(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 We(U(),{message:L,chatId:n.chatId,knowledgeNames:await mt(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});M.isConnected&&M.remove(),q(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(),q(d.body,"bot",`Request failed: ${$.message}`)}}async function Ee(a){let d=n.fullPageOpen?k:A;await C(a,d)}async function He(){n.fullPageOpen=!0,n.open=!1,T(),p.classList.remove("open"),r.classList.remove("visible"),u.classList.add("hidden"),x.classList.add("open"),await Y(),await oe(k,n.chatId),queueMicrotask(()=>w.focus())}function Me(){n.fullPageOpen&&(n.fullPageOpen=!1,x.classList.remove("open"),u.classList.remove("hidden"))}function st(){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 rt(){n.chatId=de(t),n.historyLoadedChatId=null,ce(A),S(A,t.initialSuggestions,async a=>{await C(a,A)}),T()}async function it(){n.chatId=de(t),n.historyLoadedChatId=null,ce(k),S(k,t.initialSuggestions,async a=>{await C(a,k)}),R(y,v,n,async a=>{await E(a.chatId)},async a=>{await H(a)})}async function Y(){if(!t.endpoints.listChats)return R(y,v,n,async a=>{await E(a.chatId)},async a=>{await H(a)}),[];n.loadingChats=!0,R(y,v,n,async a=>{await E(a.chatId)},async a=>{await H(a)});try{let a=await Oe(U());return n.chats=a,a}catch(a){return j(t,a),n.chats}finally{n.loadingChats=!1,R(y,v,n,async a=>{await E(a.chatId)},async a=>{await H(a)})}}async function pt(a){!t.endpoints.listChats&&!t.endpoints.createChat||n.chats.some(d=>d.chatId===n.chatId)||await Ue(U(),n.chatId,a?xt(a):void 0)}async function E(a){n.chatId=a,n.historyLoadedChatId=null,await oe(k,a),R(y,v,n,async d=>{await E(d.chatId)},async d=>{await H(d)})}async function H(a){if(t.endpoints.updateChat)try{await Be(U(),a.chatId,{pinned:!a.pinned}),await Y()}catch(d){j(t,d)}}async function oe(a,d){ce(a),S(a,t.initialSuggestions,async M=>{await C(M,a)});let L=await Ne(U(),d);return L.length>0&&(_e(a),Ke(a.body,a.hero,a.suggestions),kt(a.body,L)),n.historyLoadedChatId=d,L}let se={open:Te,close:B,toggle(){if(n.open){B();return}Te()},destroy(){document.removeEventListener("keydown",Re),s.remove()},sendMessage:Ee,setAccessTokenProvider(a){n.accessTokenProvider=a},getChatId(){return n.chatId},loadChats(){return Y()},async loadHistory(){let a=n.fullPageOpen?k:A;return oe(a,n.chatId)}};u.addEventListener("click",()=>se.toggle()),b.addEventListener("click",B),r.addEventListener("click",B),g.addEventListener("click",a=>{if(a.stopPropagation(),!n.menuOpen){st();return}T()}),z.addEventListener("click",rt),W.addEventListener("click",async()=>{T(),await He()}),N.addEventListener("click",()=>{He()}),X.addEventListener("click",Me),ee.addEventListener("click",()=>{it(),queueMicrotask(()=>w.focus())}),O.addEventListener("input",()=>{n.chatSearchTerm=O.value.trim().toLowerCase(),R(y,v,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()}),Z.addEventListener("submit",async a=>{a.preventDefault(),await Ee(I.value)}),ae.addEventListener("submit",async a=>{a.preventDefault(),await C(w.value,k)});function Re(a){if(a.key==="Escape"){if(n.fullPageOpen){Me();return}n.open&&B()}}return document.addEventListener("keydown",Re),se}async function mt(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 de(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 q(e,t,n,s){let i=o("div",`kp-bubble ${t}`,n);if(s){let l=o("div","kp-meta",`${s} citation${s>1?"s":""} attached`);i.appendChild(l)}return e.appendChild(i),e.scrollTop=e.scrollHeight,i}function bt(e,t,n){e.textContent="";for(let s of t){let i=o("button","kp-suggestion",s);i.type="button",i.addEventListener("click",async()=>{await n(s)}),e.appendChild(i)}}function S(e,t,n){bt(e.suggestions,t,async s=>{e.input.value=s,await n(s)})}function Ke(e,t,n){let s=new Set([t,n]);for(let i of Array.from(e.children))s.has(i)||i.remove()}function _e(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function ce(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),Ke(e.body,e.hero,e.suggestions),e.input.value=""}function kt(e,t){for(let n of t)q(e,n.role==="assistant"?"bot":"user",n.text)}function R(e,t,n,s,i){if(e.textContent="",t.textContent="",n.loadingChats){e.appendChild(o("div","kp-full-page-empty","Loading chats..."));return}let l=n.chats.filter(r=>n.chatSearchTerm?r.title.toLowerCase().includes(n.chatSearchTerm):!0);if(l.length>0){let r=l.filter(p=>p.pinned),u=l.filter(p=>!p.pinned).slice(0,8);je(e,u,n.chatId,s,i),je(t,r,n.chatId,s,i),u.length===0&&e.appendChild(o("div","kp-full-page-empty","No recent chats yet.")),r.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 je(e,t,n,s,i){for(let l of t){let r=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)}),r.append(u,p),r.setAttribute("role","button"),r.tabIndex=0,r.addEventListener("click",async()=>{await s(l)}),r.addEventListener("keydown",async c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),await s(l))}),e.appendChild(r)}}function xt(e){return e.trim().slice(0,60)||"New Chat"}0&&(module.exports={createChatWidget});
1376
+ `}var ut={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 mt(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=lt(e),o=Le(t.locale),n=sn(t.locale),i=rn(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 p=d.attachShadow({mode:"open"});dt(p,t.theme);let l=a("div",`kp-chat-widget ${t.position}`);l.lang=o,l.dir=i?"rtl":"ltr",i&&l.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"),wt=a("h2","kp-title",t.title),vt=a("div","kp-subtitle",t.subtitle);C.append(wt,vt);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"),de=a("div","kp-hero"),Ct=a("div","kp-hero-icon","\u2726"),Lt=a("div","kp-hero-text",t.welcomeMessage);de.append(Ct,Lt);let Ae=a("div","kp-footer"),ue=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 ge=a("button","kp-send","\u279C");ge.type="submit",ge.setAttribute("aria-label",n.send);let At=a("div","kp-note",n.authTokenForwarded);ue.append(S,ge),Ae.append(ue,At),f.append(m,Z,Ae),l.append(u,g,f),p.appendChild(l),Z.appendChild(de);let Pe=a("div","kp-suggestions");Z.appendChild(Pe);let ee=a("section","kp-my-chats-sheet"),Se=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),Se.append(te,ne);let Te=a("div","kp-my-chats-body"),Pt=a("div","kp-my-chats-section-label",n.recentActivity),Ie=a("div","kp-my-chats-list"),St=a("div","kp-my-chats-section-label",n.pinnedCollections),Ee=a("div","kp-my-chats-list");Te.append(Pt,Ie,St,Ee),ee.append(Se,Te),f.appendChild(ee);let A={body:Z,input:S,suggestions:Pe,hero:de,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 Re=a("div","kp-full-page-shell"),$e=a("div","kp-full-page-header"),He=a("div","kp-full-page-brand"),Tt=a("div","kp-full-page-brand-mark","\u2726"),It=a("div","kp-full-page-brand-text",t.title);He.append(Tt,It);let ze=a("div","kp-full-page-header-actions"),Et=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),ze.append(Et,oe),$e.append(He,ze);let Me=a("div","kp-full-page-content"),Ne=a("aside","kp-full-page-sidebar"),fe=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);fe.type="button";let Be=a("div","kp-full-page-search"),V=a("input","kp-full-page-search-input");V.type="search",V.placeholder=n.searchChat;let Rt=a("span","kp-full-page-search-icon","\u2315");Be.append(V,Rt);let $t=a("div","kp-full-page-section-label",n.recentActivity),Ue=a("div","kp-full-page-recent-list"),Ht=a("div","kp-full-page-section-label",n.pinnedCollections),Oe=a("div","kp-full-page-pinned-list");Ne.append(fe,Be,$t,Ue,Ht,Oe);let We=a("main","kp-full-page-main"),je=a("section","kp-full-page-panel"),he=a("div","kp-full-page-body"),me=a("div","kp-full-page-hero"),De=a("div","kp-full-page-hero-badge");De.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 zt=a("div","kp-full-page-hero-text",t.welcomeMessage);me.append(De,zt);let Ve=a("div","kp-suggestions kp-full-page-suggestions");he.append(me,Ve);let qe=a("div","kp-full-page-footer"),be=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 ke=a("button","kp-send kp-full-page-send","\u279C");ke.type="submit",ke.setAttribute("aria-label",n.send);let Mt=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);be.append(P,ke),qe.append(be,Mt),je.append(he,qe),We.appendChild(je);let ae=a("aside","kp-source-panel"),_e=a("div","kp-source-panel-header"),Fe=a("div","kp-source-panel-title-wrap"),Ke=a("div","kp-source-panel-title",n.allSourcesUsed),Nt=a("div","kp-source-panel-subtitle",n.documentsAndReferences);Fe.append(Ke,Nt);let se=a("button","kp-source-panel-close","\xD7");se.type="button",se.setAttribute("aria-label",n.closeSourcesPanel),_e.append(Fe,se);let q=a("div","kp-source-panel-list"),Bt=a("div","kp-source-panel-empty",n.noSources);q.appendChild(Bt),ae.append(_e,q),Me.append(Ne,We,ae),Re.append($e,Me),T.appendChild(Re),l.appendChild(T);let L={body:he,input:P,suggestions:Ve,hero:me,kind:"full-page"},H=()=>({...t,getAccessToken:s.accessTokenProvider}),Xe=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,Ke.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(mn(h,n))},re=()=>{s.sourcePanelOpen=!1,s.sourcePanelTitle=null,ae.classList.remove("open")};j(A,t.initialSuggestions,async r=>{await I(r,A)}),j(L,t.initialSuggestions,async r=>{await I(r,L)}),N(),ie();function Ye(){s.open||(s.open=!0,s.fullPageOpen=!1,E(),T.classList.remove("open"),g.classList.add("hidden"),u.classList.add("visible"),f.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&xe.loadHistory(),queueMicrotask(()=>S.focus()))}function F(){s.open&&(z(),E(),s.open=!1,g.classList.remove("hidden"),u.classList.remove("visible"),f.classList.remove("open"),t.onClose?.())}async function I(r,c){let h=r.trim();if(!h)return;c.input.value="";try{await Dt(h)}catch(R){let K=U(t,R);J(c.body,"bot",`${n.unableToCreateChat}: ${K.message}`,{strings:n,view:c,userName:null,onShowSources:_});return}gt(c),J(c.body,"user",h,{strings:n,view:c,userName:await Xe(),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 at(H(),{message:h,chatId:s.chatId,knowledgeNames:await Zt(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});B.isConnected&&B.remove(),J(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 I(K,c)})}catch(R){let K=U(t,R);B.isConnected&&B.remove(),J(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 I(r,c)}async function Ut(){s.fullPageOpen=!0,s.open=!1,z(),E(),f.classList.remove("open"),u.classList.remove("visible"),g.classList.add("hidden"),T.classList.add("open"),await M(),await pe(L,s.chatId),queueMicrotask(()=>P.focus())}function Ge(){s.fullPageOpen&&(s.fullPageOpen=!1,T.classList.remove("open"),g.classList.remove("hidden"),re())}function Ot(){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 Wt(){s.chatId=ce(t),s.historyLoadedChatId=null,E(),Y(A),j(A,t.initialSuggestions,async r=>{await I(r,A)}),z()}async function jt(){s.chatId=ce(t),s.historyLoadedChatId=null,Y(L),re(),j(L,t.initialSuggestions,async r=>{await I(r,L)}),N()}async function M(){if(!t.endpoints.listChats)return N(),ie(),[];s.loadingChats=!0,N(),ie();try{let r=await rt(H());return s.chats=r,r}catch(r){return U(t,r),s.chats}finally{s.loadingChats=!1,N(),ie()}}async function Dt(r){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(c=>c.chatId===s.chatId)||await it(H(),s.chatId,r?an(r,n.newChat):void 0)}async function Vt(r){s.chatId=r,s.historyLoadedChatId=null,await pe(L,r),N()}async function qt(r){s.chatId=r,s.historyLoadedChatId=null,await pe(A,r),E()}async function _t(){z(),await M(),s.myChatsOpen=!0,f.classList.add("kp-sheet-open"),ee.classList.add("open")}function E(){s.myChatsOpen=!1,f.classList.remove("kp-sheet-open"),ee.classList.remove("open")}async function Qe(r){if(!t.endpoints.updateChat)return;let c=window.prompt(n.renamePrompt,r.title)?.trim();if(!(!c||c===r.title))try{await ve(H(),r.chatId,{title:c}),await M()}catch(h){U(t,h)}}async function Ze(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(){ft(Ue,Oe,s,n,async r=>{await Vt(r.chatId)},async r=>{await et(r)},async r=>{await Qe(r)},async r=>{await Ze(r)})}function ie(){ft(Ie,Ee,s,n,async r=>{await qt(r.chatId)},async r=>{await et(r)},async r=>{await Qe(r)},async r=>{await Ze(r)})}async function et(r){if(t.endpoints.updateChat)try{await ve(H(),r.chatId,{pinned:!r.pinned}),await M()}catch(c){U(t,c)}}async function pe(r,c){Y(r),j(r,t.initialSuggestions,async B=>{await I(B,r)});let h=await st(H(),c);return h.length>0&&(gt(r),bt(r.body,r.hero,r.suggestions),on(r.body,h,{strings:n,view:r,userName:await Xe(),onShowSources:_})),s.historyLoadedChatId=c,h}let xe={open:Ye,close:F,toggle(){if(s.open){F();return}Ye()},destroy(){document.removeEventListener("keydown",tt),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 pe(r,s.chatId)}};g.addEventListener("click",()=>xe.toggle()),Q.addEventListener("click",F),u.addEventListener("click",F),se.addEventListener("click",re),te.addEventListener("click",E),ne.addEventListener("click",E),b.addEventListener("click",r=>{if(r.stopPropagation(),!s.menuOpen){Ot();return}z()}),v.addEventListener("click",Wt),k.addEventListener("click",async()=>{await _t()}),$.addEventListener("click",()=>{Ut()}),oe.addEventListener("click",Ge),fe.addEventListener("click",()=>{jt(),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(p.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(p.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}s.menuOpen&&!x.contains(c)&&!b.contains(c)&&z(),r.stopPropagation()}),p.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(p.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(p.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}}),ue.addEventListener("submit",async r=>{r.preventDefault(),await Je(S.value)}),be.addEventListener("submit",async r=>{r.preventDefault(),await I(P.value,L)});function tt(r){if(r.key==="Escape"){if(s.sourcePanelOpen){re();return}if(s.myChatsOpen){E();return}if(s.fullPageOpen){Ge();return}s.open&&F()}}return document.addEventListener("keydown",tt),xe}async function Zt(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 J(e,t,o,n){let i=t==="bot"?ln(o,n.citations??[]):{displayText:o,citations:n.citations??[]},s=a("div",`kp-message-row ${t}`),d=tn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),p=a("div",`kp-bubble ${t}`),l=a("div","kp-bubble-content");xn(l,i.displayText),p.appendChild(l);let u=i.citations;if(u.length){let g=a("div","kp-meta",n.strings.citationsAttached(u.length));p.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=fn(x,n.strings);v.addEventListener("click",async()=>{xt(x,n.strings)}),y.appendChild(v)}let b=hn(n.strings);b.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),y.appendChild(b),f.append(m,y),p.appendChild(f)}return t==="bot"&&p.appendChild(en(i.displayText,n.strings)),t==="user"?s.append(p,d):s.append(d,p),e.appendChild(s),e.scrollTop=e.scrollHeight,s}function en(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 tn(e,t){let o=a("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":pn(e);return o.textContent=n,o.setAttribute("aria-hidden","true"),o}function nn(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){nn(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 gt(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 on(e,t,o){for(let n of t)J(e,n.role==="assistant"?"bot":"user",n.text,o)}function ft(e,t,o,n,i,s,d,p){if(e.textContent="",t.textContent="",o.loadingChats){e.appendChild(a("div","kp-full-page-empty",n.loadingChats));return}let l=o.chats.filter(u=>o.chatSearchTerm?u.title.toLowerCase().includes(o.chatSearchTerm):!0);if(l.length>0){let u=l.filter(f=>f.pinned),g=l.filter(f=>!f.pinned).slice(0,8);ht(e,g,o.chatId,n,i,s,d,p),ht(t,u,o.chatId,n,i,s,d,p),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 ht(e,t,o,n,i,s,d,p){for(let l of t){let u=a("div",`kp-full-page-item kp-full-page-chat-item${l.chatId===o?" active":""}`),g=a("span","kp-full-page-item-title",l.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",l.pinned?n.unpinChat:n.pinChat);b.type="button",b.addEventListener("click",async k=>{k.stopPropagation(),await s(l)});let x=a("button","kp-chat-actions-item",n.renameChat);x.type="button",x.addEventListener("click",async k=>{k.stopPropagation(),await d(l)});let v=a("button","kp-chat-actions-item",n.deleteChat);v.type="button",v.addEventListener("click",async k=>{k.stopPropagation(),await p(l)}),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(l)}),u.addEventListener("keydown",async k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),await i(l))}),u.addEventListener("blur",()=>{f.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function an(e,t){return e.trim().slice(0,60)||t}function Le(e){return e.toLowerCase().split("-")[0]||"en"}function sn(e){let t=ut.en;return ut[Le(e)]??t}function rn(e){return["ar","fa","he","ur"].includes(Le(e))}function pn(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 ln(e,t){let o=cn(e);return{displayText:o.displayText,citations:t.length>0?gn(t,o.citations):o.citations}}function cn(e){let o=yt(e).split(`
1377
+ `),n=-1;for(let l=0;l<o.length;l+=1)/^#{0,6}\s*References\s*$/i.test(o[l]?.trim()??"")&&(n=l);if(n===-1)return{displayText:e,citations:[]};let i=o.slice(0,n).join(`
1378
+ `).trimEnd(),s=o.slice(n+1).join(`
1379
+ `).trim(),p=dn(s).map(l=>un(l)).filter(l=>!!l);return{displayText:i,citations:p}}function dn(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 un(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 gn(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 fn(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 hn(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 mn(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"),p=[];return typeof e.score=="number"&&p.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&p.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&p.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&p.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&p.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),d.textContent=p.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=bn(e.sourceDocument);if(n){window.open(n,"_blank","noopener,noreferrer");return}let i=window.open("","_blank","noopener,noreferrer");if(!i)return;let s=G(o),d=kn(e,t).map(p=>`<li>${G(p)}</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>${G(t.documentsAndReferences)}</p>
1397
+ <ul>${d||`<li>${G(t.noSources)}</li>`}</ul>
1398
+ </div>
1399
+ </body>
1400
+ </html>`),i.document.close()}function bn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function kn(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 xn(e,t){e.innerHTML=yn(yt(t))}function yt(e){return e.replace(/\r\n/g,`
1401
+ `).replace(/<br\s*\/?>/gi,`
1402
+ `)}function yn(e){return e.split(/\n{2,}/).map(o=>o.trim()).filter(Boolean).map(wn).join("")}function wn(e){let t=e.split(`
1403
+ `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return vn(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 vn(e){let t=e.filter((d,p)=>!(p===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(d))).map(d=>Cn(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(p=>`<td>${D(p)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${i}${s}</table></div>`}function Cn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function D(e){let t=G(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 G(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}0&&(module.exports={createChatWidget});
872
1404
  //# sourceMappingURL=index.cjs.map