@nabeh/chat-widget 0.1.1 → 0.1.3

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 Ce=Object.defineProperty;var Jt=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var Zt=Object.prototype.hasOwnProperty;var en=(e,t)=>{for(var a in t)Ce(e,a,{get:t[a],enumerable:!0})},tn=(e,t,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Qt(t))!Zt.call(e,i)&&i!==a&&Ce(e,i,{get:()=>t[i],enumerable:!(n=Jt(t,i))||n.enumerable});return e};var nn=e=>tn(Ce({},"__esModule",{value:!0}),e);var En={};en(En,{browserGlobal:()=>At,createChatWidget:()=>de,init:()=>Lt,version:()=>Ct});module.exports=nn(En);function ot(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Le(e,t){let a={...e};for(let n of Object.keys(t)){let i=t[n],l=a[n];if(ot(l)&&ot(i)){a[n]=Le(l,i);continue}i!==void 0&&(a[n]=i)}return a}function st(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function G(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}function D(e,t,a){return{"Content-Type":"application/json",...e.customHeaders,...a?{"X-Chat-User-Context":a}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function q(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function pe(e,t,a={}){let n=t.replace(/\{chatId\}/g,encodeURIComponent(a.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(a.chatId??""));return G(e.apiBaseUrl,n)}async function rt(e,t){let a=e.getAccessToken?await e.getAccessToken():null,n=await q(e),i=pe(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},p=await fetch(i,{method:"POST",headers:D(e,a,n),body:JSON.stringify(s)});if(!p.ok)throw new Error(`Chat backend returned ${p.status}.`);let c=await p.json();if(!Array.isArray(c)){if(!c.answer||typeof c.answer!="string")throw new Error("Chat backend response is missing a valid answer.");return{chatId:c.chatId??t.chatId,answer:c.answer,suggestions:c.suggestions??[],citations:c.citations??[]}}let u=c[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??[],h=g?.scores??[],w=g?.page_numbers??[],L=g?.sheet_names??[],b=g?.row_numbers??[],y=g?.knowledge_names??[],k=f.map((M,v)=>({sourceDocument:M,score:h[v]??null,pageNumber:w[v]??null,sheetName:L[v]??null,rowNumber:b[v]??null,knowledgeName:y[v]??null}));return{chatId:t.chatId,answer:u.answer,suggestions:[],citations:k}}async function it(e,t){if(!e.endpoints.history)return[];let a=e.getAccessToken?await e.getAccessToken():null,n=await q(e),l=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?pe(e,e.endpoints.history,{chatId:t}):(()=>{let u=new URL(G(e.apiBaseUrl,e.endpoints.history));return u.searchParams.set("chat_id",t),u.toString()})(),s=await fetch(l,{method:"GET",headers:D(e,a,n)});if(!s.ok)throw new Error(`Chat history endpoint returned ${s.status}.`);let p=await s.json(),c=Array.isArray(p)?p:p&&typeof p=="object"?p.history??p.messages??p.data??[]:[];return Array.isArray(c)?c.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,h=g.text??g.message??g.content??g.answer;if(typeof h!="string")return null;let w=typeof f=="string"?f.toLowerCase():"assistant";return[{role:w==="user"||w==="human"?"user":"assistant",text:h}]}).flat().filter(u=>!!u):[]}async function lt(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,a=await q(e),n=await fetch(G(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:D(e,t,a)});if(!n.ok)throw new Error(`Chat list endpoint returned ${n.status}.`);let i=await n.json(),l=Array.isArray(i)?i:i&&typeof i=="object"?i.chats??i.data??i.items??[]:[];return Array.isArray(l)?l.map(s=>{if(!s||typeof s!="object")return null;let p=s,c=p.chatId??p.chat_id??p.id,u=p.title??p.name??p.chatId;if(typeof c!="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,h={chatId:c,title:u,pinned:typeof p.pinned=="boolean"?p.pinned:!1};return g&&(h.createdAt=g),f&&(h.updatedAt=f),h}).filter(s=>!!s):[]}async function pt(e,t,a){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let i=e.getAccessToken?await e.getAccessToken():null,l=await q(e),s=await fetch(G(e.apiBaseUrl,n),{method:"POST",headers:D(e,i,l),body:JSON.stringify({chatId:t,...a?{title:a}:{}})});if(!s.ok)throw new Error(`Create chat endpoint returned ${s.status}.`)}async function Ae(e,t,a){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,i=await q(e),l=pe(e,e.endpoints.updateChat,{chatId:t}),s=await fetch(l,{method:"PATCH",headers:D(e,n,i),body:JSON.stringify(a)});if(!s.ok)throw new Error(`Update chat endpoint returned ${s.status}.`)}async function ct(e,t){if(!e.endpoints.deleteChat)return;let a=e.getAccessToken?await e.getAccessToken():null,n=await q(e),i=pe(e,e.endpoints.deleteChat,{chatId:t}),l=await fetch(i,{method:"DELETE",headers:D(e,a,n)});if(!l.ok)throw new Error(`Delete chat endpoint returned ${l.status}.`)}function B(e,t){let a=st(t);return e.onError?.(a),a}var Pe={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'},x={displayMode:"widget",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:{},assistantPageUrl:"/knowledge-assistant",embedded:{showHeader:!1},rag:{knowledgeNames:[],enableReferences:!0,loadHistoryOnOpen:!1},theme:Pe,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0};function dt(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,a=Le(Pe,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,displayMode:e.displayMode??x.displayMode,position:e.position??x.position,title:e.title??x.title,subtitle:e.subtitle??x.subtitle,welcomeMessage:e.welcomeMessage??x.welcomeMessage,inputPlaceholder:e.inputPlaceholder??x.inputPlaceholder,launcherAriaLabel:e.launcherAriaLabel??x.launcherAriaLabel,closeAriaLabel:e.closeAriaLabel??x.closeAriaLabel,initialSuggestions:e.initialSuggestions??x.initialSuggestions,sourceApp:e.sourceApp??x.sourceApp,locale:e.locale??x.locale,customHeaders:e.customHeaders??x.customHeaders,embedded:{...x.embedded,...e.embedded??{}},rag:{...x.rag,...e.rag??{}},assistantPageUrl:e.assistantPageUrl??x.assistantPageUrl,theme:a,getAccessToken:e.getAccessToken,getUserContext:e.getUserContext,onOpen:e.onOpen,onClose:e.onClose,onError:e.onError,onOpenAssistantPage:e.onOpenAssistantPage}}function o(e,t,a){let n=document.createElement(e);return t&&(n.className=t),a!==void 0&&(n.textContent=a),n}var ut="kp-chat-widget-styles";function gt(e,t){if(e.getElementById(ut))return;let a=document.createElement("style");a.id=ut,a.textContent=an(t),e.appendChild(a)}function an(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;
@@ -23,6 +25,15 @@
23
25
  box-sizing: border-box;
24
26
  }
25
27
 
28
+ .kp-chat-widget.kp-chat-widget-embedded {
29
+ position: relative;
30
+ inset: auto;
31
+ width: 100%;
32
+ height: 100%;
33
+ min-height: 640px;
34
+ display: block;
35
+ }
36
+
26
37
  *,
27
38
  *::before,
28
39
  *::after {
@@ -35,6 +46,21 @@
35
46
  right: auto;
36
47
  }
37
48
 
49
+ .kp-chat-widget.kp-chat-widget-embedded.bottom-left {
50
+ left: auto;
51
+ right: auto;
52
+ }
53
+
54
+ .kp-rtl .kp-dropdown-item,
55
+ .kp-rtl .kp-suggestion,
56
+ .kp-rtl .kp-input,
57
+ .kp-rtl .kp-full-page-search-input,
58
+ .kp-rtl .kp-bubble-content,
59
+ .kp-rtl .kp-source-card,
60
+ .kp-rtl .kp-source-panel {
61
+ text-align: right;
62
+ }
63
+
38
64
  .kp-launcher {
39
65
  width: 72px;
40
66
  height: 72px;
@@ -64,9 +90,11 @@
64
90
  .kp-input:focus-visible,
65
91
  .kp-full-page-new-chat:focus-visible,
66
92
  .kp-full-page-close:focus-visible,
67
- .kp-full-page-search-input:focus-visible,
68
93
  .kp-full-page-chat-item:focus-visible,
69
- .kp-chat-pin:focus-visible {
94
+ .kp-chat-pin:focus-visible,
95
+ .kp-message-action:focus-visible,
96
+ .kp-source-chip:focus-visible,
97
+ .kp-source-panel-close:focus-visible {
70
98
  outline: 2px solid var(--kp-accent);
71
99
  outline-offset: 2px;
72
100
  }
@@ -139,12 +167,11 @@
139
167
  position: fixed;
140
168
  bottom: 88px;
141
169
  right: 24px;
142
- width: 480px;
143
- max-width: calc(100vw - 24px);
170
+ width: min(480px, calc(100vw - 48px));
144
171
  height: min(730px, calc(100vh - 118px));
145
172
  background: var(--kp-panel-background);
146
173
  border: 1px solid rgba(255, 255, 255, 0.35);
147
- border-radius: 20px;
174
+ border-radius: 24px;
148
175
  box-shadow: var(--kp-shadow);
149
176
  overflow: hidden;
150
177
  display: flex;
@@ -173,9 +200,7 @@
173
200
  .kp-full-page {
174
201
  position: fixed;
175
202
  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%);
203
+ background: #ffffff;
179
204
  opacity: 0;
180
205
  pointer-events: none;
181
206
  transform: translateY(18px);
@@ -184,6 +209,18 @@
184
209
  overflow: hidden;
185
210
  }
186
211
 
212
+ .kp-full-page.kp-full-page-embedded {
213
+ position: relative;
214
+ inset: auto;
215
+ opacity: 1;
216
+ pointer-events: auto;
217
+ transform: none;
218
+ min-height: 100%;
219
+ height: 100%;
220
+ z-index: auto;
221
+ background: transparent;
222
+ }
223
+
187
224
  .kp-full-page.open {
188
225
  opacity: 1;
189
226
  pointer-events: auto;
@@ -194,20 +231,31 @@
194
231
  height: 100vh;
195
232
  display: flex;
196
233
  flex-direction: column;
197
- padding: 22px 34px 26px;
234
+ padding: 22px 28px 26px;
198
235
  gap: 16px;
199
236
  overflow: hidden;
200
237
  }
201
238
 
239
+ .kp-full-page-embedded .kp-full-page-shell {
240
+ height: 100%;
241
+ min-height: 100%;
242
+ padding: 0;
243
+ gap: 12px;
244
+ }
245
+
202
246
  .kp-full-page-header {
203
247
  display: flex;
204
248
  align-items: center;
205
249
  justify-content: space-between;
206
250
  gap: 16px;
207
- padding: 12px 4px 0;
251
+ padding: 8px 4px 0;
208
252
  flex: none;
209
253
  }
210
254
 
255
+ .kp-hidden {
256
+ display: none !important;
257
+ }
258
+
211
259
  .kp-full-page-brand {
212
260
  display: flex;
213
261
  align-items: center;
@@ -251,39 +299,38 @@
251
299
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
252
300
  }
253
301
 
254
- .kp-full-page-close {
255
- width: 44px;
256
- height: 44px;
302
+ .kp-full-page-close,
303
+ .kp-source-panel-close {
304
+ width: 40px;
305
+ height: 40px;
257
306
  border: none;
258
307
  border-radius: 14px;
259
308
  background: rgba(255, 255, 255, 0.82);
260
309
  color: #61788a;
261
- font-size: 28px;
310
+ font-size: 24px;
262
311
  line-height: 1;
263
312
  cursor: pointer;
264
313
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
265
314
  }
266
315
 
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
316
  .kp-full-page-content {
276
317
  display: grid;
277
- grid-template-columns: 290px minmax(0, 1fr);
318
+ grid-template-columns: 290px minmax(0, 1fr) minmax(0, 0);
278
319
  gap: 16px;
279
320
  flex: 1;
280
321
  min-height: 0;
281
322
  overflow: hidden;
323
+ align-items: stretch;
324
+ }
325
+
326
+ .kp-full-page-embedded .kp-full-page-content {
327
+ height: 100%;
282
328
  }
283
329
 
284
330
  .kp-full-page-sidebar,
285
- .kp-full-page-panel {
286
- border-radius: 22px;
331
+ .kp-full-page-panel,
332
+ .kp-source-panel {
333
+ border-radius: 24px;
287
334
  border: 1px solid rgba(219, 228, 238, 0.9);
288
335
  background: rgba(255, 255, 255, 0.88);
289
336
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
@@ -331,6 +378,15 @@
331
378
  color: #334155;
332
379
  font-size: 14px;
333
380
  min-width: 0;
381
+ box-shadow: none;
382
+ }
383
+
384
+ .kp-full-page-search-input:focus,
385
+ .kp-full-page-search-input:focus-visible,
386
+ .kp-full-page-search-input:active {
387
+ outline: none;
388
+ box-shadow: none;
389
+ border: none;
334
390
  }
335
391
 
336
392
  .kp-full-page-search-icon {
@@ -357,7 +413,7 @@
357
413
 
358
414
  .kp-full-page-item {
359
415
  padding: 12px 12px 13px;
360
- border-radius: 12px;
416
+ border-radius: 14px;
361
417
  color: #293845;
362
418
  font-size: 15px;
363
419
  line-height: 1.5;
@@ -366,12 +422,14 @@
366
422
  }
367
423
 
368
424
  .kp-full-page-chat-item {
425
+ position: relative;
369
426
  display: flex;
370
427
  align-items: center;
371
428
  justify-content: space-between;
372
429
  gap: 10px;
373
430
  cursor: pointer;
374
431
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
432
+ overflow: visible;
375
433
  }
376
434
 
377
435
  .kp-full-page-chat-item:hover {
@@ -385,6 +443,10 @@
385
443
  background: rgba(220, 252, 231, 0.72);
386
444
  }
387
445
 
446
+ .kp-full-page-chat-item.menu-open {
447
+ z-index: 4;
448
+ }
449
+
388
450
  .kp-full-page-item-title {
389
451
  min-width: 0;
390
452
  overflow: hidden;
@@ -411,11 +473,6 @@
411
473
  line-height: 1.5;
412
474
  }
413
475
 
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
476
  .kp-full-page-main {
420
477
  min-width: 0;
421
478
  min-height: 0;
@@ -430,6 +487,112 @@
430
487
  overflow: hidden;
431
488
  }
432
489
 
490
+ .kp-source-panel {
491
+ min-width: 0;
492
+ min-height: 0;
493
+ overflow: hidden;
494
+ display: none;
495
+ flex-direction: column;
496
+ }
497
+
498
+ .kp-source-panel.open {
499
+ display: flex;
500
+ }
501
+
502
+ .kp-full-page-content:has(.kp-source-panel.open) {
503
+ grid-template-columns: 290px minmax(0, 1fr) 320px;
504
+ }
505
+
506
+ .kp-source-panel-header {
507
+ display: flex;
508
+ align-items: flex-start;
509
+ justify-content: space-between;
510
+ gap: 12px;
511
+ padding: 18px 18px 12px;
512
+ border-bottom: 1px solid rgba(219, 228, 238, 0.7);
513
+ }
514
+
515
+ .kp-source-panel-title {
516
+ font-size: 17px;
517
+ font-weight: 700;
518
+ color: #16394b;
519
+ }
520
+
521
+ .kp-source-panel-subtitle {
522
+ margin-top: 4px;
523
+ font-size: 12px;
524
+ color: #7a8a99;
525
+ }
526
+
527
+ .kp-source-panel-list {
528
+ display: flex;
529
+ flex-direction: column;
530
+ gap: 12px;
531
+ padding: 16px;
532
+ overflow: auto;
533
+ }
534
+
535
+ .kp-source-panel-empty {
536
+ color: #7a8a99;
537
+ font-size: 14px;
538
+ line-height: 1.5;
539
+ }
540
+
541
+ .kp-source-card {
542
+ width: 100%;
543
+ text-align: left;
544
+ cursor: pointer;
545
+ appearance: none;
546
+ border: 1px solid rgba(219, 228, 238, 0.9);
547
+ border-radius: 16px;
548
+ background: #ffffff;
549
+ padding: 14px;
550
+ }
551
+
552
+ .kp-source-card-media {
553
+ display: flex;
554
+ align-items: center;
555
+ margin-bottom: 10px;
556
+ }
557
+
558
+ .kp-source-thumb,
559
+ .kp-source-thumb-large {
560
+ flex: none;
561
+ width: 32px;
562
+ height: 32px;
563
+ border-radius: 999px;
564
+ display: inline-flex;
565
+ align-items: center;
566
+ justify-content: center;
567
+ background: linear-gradient(180deg, #eefcf8 0%, #dff7f2 100%);
568
+ border: 1px solid rgba(15, 118, 110, 0.18);
569
+ color: #0f6a75;
570
+ font-size: 14px;
571
+ line-height: 1;
572
+ box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
573
+ }
574
+
575
+ .kp-source-thumb-large {
576
+ width: 42px;
577
+ height: 42px;
578
+ font-size: 18px;
579
+ }
580
+
581
+ .kp-source-card-title {
582
+ font-size: 14px;
583
+ font-weight: 700;
584
+ color: #16394b;
585
+ word-break: break-word;
586
+ }
587
+
588
+ .kp-source-card-meta {
589
+ margin-top: 8px;
590
+ font-size: 12px;
591
+ line-height: 1.5;
592
+ color: #667a8d;
593
+ word-break: break-word;
594
+ }
595
+
433
596
  .kp-full-page-body {
434
597
  flex: 1;
435
598
  overflow: auto;
@@ -437,9 +600,7 @@
437
600
  flex-direction: column;
438
601
  gap: 14px;
439
602
  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%);
603
+ background: #ffffff;
443
604
  scroll-behavior: smooth;
444
605
  }
445
606
 
@@ -588,7 +749,7 @@
588
749
  position: absolute;
589
750
  top: 44px;
590
751
  left: 0;
591
- width: 164px;
752
+ width: 184px;
592
753
  background: #ffffff;
593
754
  border: 1px solid rgba(15, 79, 104, 0.12);
594
755
  border-radius: 10px;
@@ -601,6 +762,11 @@
601
762
  z-index: 2;
602
763
  }
603
764
 
765
+ .kp-rtl .kp-dropdown {
766
+ left: auto;
767
+ right: 0;
768
+ }
769
+
604
770
  .kp-dropdown.open {
605
771
  opacity: 1;
606
772
  transform: translateY(0);
@@ -652,6 +818,127 @@
652
818
  padding-top: 16px;
653
819
  }
654
820
 
821
+ .kp-panel.kp-sheet-open .kp-body,
822
+ .kp-panel.kp-sheet-open .kp-footer,
823
+ .kp-panel.kp-sheet-open .kp-header {
824
+ opacity: 0;
825
+ pointer-events: none;
826
+ }
827
+
828
+ .kp-my-chats-sheet {
829
+ position: absolute;
830
+ inset: 0;
831
+ border-radius: inherit;
832
+ border: none;
833
+ background: #ffffff;
834
+ box-shadow: none;
835
+ display: none;
836
+ flex-direction: column;
837
+ z-index: 3;
838
+ overflow: hidden;
839
+ }
840
+
841
+ .kp-my-chats-sheet.open {
842
+ display: flex;
843
+ }
844
+
845
+ .kp-my-chats-header {
846
+ display: flex;
847
+ align-items: center;
848
+ justify-content: space-between;
849
+ padding: 18px 18px 10px;
850
+ flex: none;
851
+ background: #ffffff;
852
+ }
853
+
854
+ .kp-my-chats-nav {
855
+ width: 36px;
856
+ height: 36px;
857
+ border: none;
858
+ border-radius: 999px;
859
+ background: transparent;
860
+ color: #61788a;
861
+ font-size: 22px;
862
+ line-height: 1;
863
+ cursor: pointer;
864
+ }
865
+
866
+ .kp-my-chats-body {
867
+ flex: 1;
868
+ overflow: auto;
869
+ padding: 8px 18px 18px;
870
+ background: #ffffff;
871
+ }
872
+
873
+ .kp-my-chats-section-label {
874
+ font-size: 14px;
875
+ line-height: 1.5;
876
+ color: #7a8a99;
877
+ margin: 14px 0 10px;
878
+ }
879
+
880
+ .kp-my-chats-list {
881
+ display: flex;
882
+ flex-direction: column;
883
+ gap: 10px;
884
+ }
885
+
886
+ .kp-chat-actions {
887
+ position: relative;
888
+ flex: none;
889
+ }
890
+
891
+ .kp-chat-actions-trigger {
892
+ width: 28px;
893
+ height: 28px;
894
+ border: none;
895
+ border-radius: 999px;
896
+ background: transparent;
897
+ color: #526678;
898
+ font-size: 20px;
899
+ line-height: 1;
900
+ cursor: pointer;
901
+ display: inline-flex;
902
+ align-items: center;
903
+ justify-content: center;
904
+ }
905
+
906
+ .kp-chat-actions-menu {
907
+ position: absolute;
908
+ top: 30px;
909
+ inset-inline-end: 0;
910
+ width: 120px;
911
+ padding: 8px;
912
+ border-radius: 10px;
913
+ border: 1px solid rgba(219, 228, 238, 0.95);
914
+ background: #ffffff;
915
+ box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
916
+ display: none;
917
+ flex-direction: column;
918
+ gap: 2px;
919
+ z-index: 20;
920
+ }
921
+
922
+ .kp-chat-actions.open .kp-chat-actions-menu {
923
+ display: flex;
924
+ }
925
+
926
+ .kp-chat-actions-item {
927
+ width: 100%;
928
+ border: none;
929
+ background: transparent;
930
+ color: #1f2937;
931
+ text-align: left;
932
+ padding: 10px 12px;
933
+ border-radius: 8px;
934
+ font-size: 14px;
935
+ cursor: pointer;
936
+ }
937
+
938
+ .kp-chat-actions-item:hover {
939
+ background: rgba(241, 245, 249, 0.95);
940
+ }
941
+
655
942
  .kp-hero {
656
943
  display: flex;
657
944
  gap: 10px;
@@ -673,32 +960,245 @@
673
960
  color: #374151;
674
961
  }
675
962
 
963
+ .kp-message-row {
964
+ display: flex;
965
+ align-items: flex-start;
966
+ gap: 10px;
967
+ width: 100%;
968
+ }
969
+
970
+ .kp-message-row.user {
971
+ justify-content: flex-end;
972
+ }
973
+
974
+ .kp-avatar {
975
+ flex: none;
976
+ width: 36px;
977
+ height: 36px;
978
+ border-radius: 999px;
979
+ display: flex;
980
+ align-items: center;
981
+ justify-content: center;
982
+ font-size: 13px;
983
+ font-weight: 700;
984
+ box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
985
+ }
986
+
987
+ .kp-avatar.bot {
988
+ background: linear-gradient(180deg, #e8fbff 0%, #dff7f2 100%);
989
+ color: #0f6a75;
990
+ border: 1px solid rgba(15, 118, 110, 0.16);
991
+ }
992
+
993
+ .kp-avatar.user {
994
+ background: linear-gradient(180deg, #fff4ee 0%, #fbe3d5 100%);
995
+ color: #8c4b1f;
996
+ border: 1px solid rgba(180, 102, 43, 0.16);
997
+ }
998
+
676
999
  .kp-bubble {
677
- max-width: 85%;
678
- padding: 12px 14px;
679
- border-radius: 18px;
1000
+ max-width: min(85%, 720px);
1001
+ padding: 14px 16px;
1002
+ border-radius: 20px;
680
1003
  font-size: 14px;
681
- line-height: 1.5;
682
- white-space: pre-wrap;
1004
+ line-height: 1.65;
683
1005
  border: 1px solid var(--kp-border-color);
684
1006
  background: #ffffff;
1007
+ box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
685
1008
  }
686
1009
 
687
1010
  .kp-bubble.user {
688
- align-self: flex-end;
689
- background: var(--kp-accent-soft);
690
- border-color: rgba(15, 118, 110, 0.22);
1011
+ background: linear-gradient(180deg, #fff8f3 0%, #fdf1e8 100%);
1012
+ border-color: rgba(222, 184, 135, 0.34);
691
1013
  }
692
1014
 
693
1015
  .kp-bubble.bot {
694
- align-self: flex-start;
1016
+ background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
1017
+ }
1018
+
1019
+ .kp-bubble-content {
1020
+ color: var(--kp-text);
1021
+ white-space: normal;
1022
+ word-break: break-word;
1023
+ }
1024
+
1025
+ .kp-bubble-content p,
1026
+ .kp-bubble-content ul,
1027
+ .kp-bubble-content ol,
1028
+ .kp-bubble-content table,
1029
+ .kp-bubble-content blockquote {
1030
+ margin: 0;
1031
+ }
1032
+
1033
+ .kp-bubble-content p + p,
1034
+ .kp-bubble-content p + ul,
1035
+ .kp-bubble-content p + ol,
1036
+ .kp-bubble-content ul + p,
1037
+ .kp-bubble-content ol + p,
1038
+ .kp-bubble-content .kp-table-wrap + p,
1039
+ .kp-bubble-content p + .kp-table-wrap,
1040
+ .kp-bubble-content h1 + p,
1041
+ .kp-bubble-content h2 + p,
1042
+ .kp-bubble-content h3 + p {
1043
+ margin-top: 12px;
1044
+ }
1045
+
1046
+ .kp-bubble-content h1,
1047
+ .kp-bubble-content h2,
1048
+ .kp-bubble-content h3,
1049
+ .kp-bubble-content h4,
1050
+ .kp-bubble-content h5,
1051
+ .kp-bubble-content h6 {
1052
+ margin: 0 0 10px;
1053
+ font-size: 16px;
1054
+ line-height: 1.4;
1055
+ color: #16394b;
1056
+ }
1057
+
1058
+ .kp-bubble-content ul,
1059
+ .kp-bubble-content ol {
1060
+ padding-inline-start: 20px;
1061
+ }
1062
+
1063
+ .kp-bubble-content code {
1064
+ padding: 2px 6px;
1065
+ border-radius: 8px;
1066
+ background: rgba(226, 232, 240, 0.66);
1067
+ font-size: 0.92em;
1068
+ }
1069
+
1070
+ .kp-bubble-content a {
1071
+ color: #0f6a75;
1072
+ text-decoration: underline;
1073
+ }
1074
+
1075
+ .kp-table-wrap {
1076
+ overflow-x: auto;
1077
+ margin-top: 8px;
1078
+ }
1079
+
1080
+ .kp-bubble-content table {
1081
+ width: 100%;
1082
+ border-collapse: collapse;
1083
+ border: 1px solid rgba(203, 213, 225, 0.95);
1084
+ border-radius: 14px;
1085
+ overflow: hidden;
1086
+ background: #ffffff;
1087
+ }
1088
+
1089
+ .kp-bubble-content th,
1090
+ .kp-bubble-content td {
1091
+ padding: 10px 12px;
1092
+ border-bottom: 1px solid rgba(226, 232, 240, 0.95);
1093
+ border-inline-end: 1px solid rgba(226, 232, 240, 0.95);
1094
+ vertical-align: top;
1095
+ text-align: start;
1096
+ }
1097
+
1098
+ .kp-bubble-content tr:last-child td {
1099
+ border-bottom: none;
1100
+ }
1101
+
1102
+ .kp-bubble-content th:last-child,
1103
+ .kp-bubble-content td:last-child {
1104
+ border-inline-end: none;
1105
+ }
1106
+
1107
+ .kp-bubble-content th {
1108
+ background: #f4fbfc;
1109
+ color: #16394b;
1110
+ font-weight: 700;
695
1111
  }
696
1112
 
697
1113
  .kp-meta {
698
1114
  font-size: 11px;
699
1115
  line-height: 1.4;
700
1116
  color: var(--kp-muted-text);
701
- margin-top: 6px;
1117
+ margin-top: 10px;
1118
+ }
1119
+
1120
+ .kp-source-preview {
1121
+ margin-top: 10px;
1122
+ padding: 12px;
1123
+ border-radius: 16px;
1124
+ border: 1px solid rgba(219, 228, 238, 0.88);
1125
+ background: #ffffff;
1126
+ }
1127
+
1128
+ .kp-source-preview-title {
1129
+ font-size: 12px;
1130
+ font-weight: 700;
1131
+ color: #16394b;
1132
+ margin-bottom: 8px;
1133
+ }
1134
+
1135
+ .kp-source-preview-list {
1136
+ display: flex;
1137
+ flex-wrap: nowrap;
1138
+ gap: 8px;
1139
+ overflow-x: auto;
1140
+ }
1141
+
1142
+ .kp-source-chip {
1143
+ display: inline-flex;
1144
+ align-items: center;
1145
+ gap: 10px;
1146
+ border: 1px solid rgba(15, 118, 110, 0.16);
1147
+ background: #ffffff;
1148
+ color: #0f4f68;
1149
+ border-radius: 999px;
1150
+ padding: 8px 12px;
1151
+ cursor: pointer;
1152
+ font-size: 12px;
1153
+ line-height: 1.3;
1154
+ max-width: 100%;
1155
+ min-width: 0;
1156
+ }
1157
+
1158
+ .kp-source-chip-more {
1159
+ background: rgba(236, 254, 255, 0.9);
1160
+ }
1161
+
1162
+ .kp-source-chip-label {
1163
+ min-width: 0;
1164
+ overflow: hidden;
1165
+ text-overflow: ellipsis;
1166
+ white-space: nowrap;
1167
+ }
1168
+
1169
+ .kp-source-thumb-stack {
1170
+ display: inline-flex;
1171
+ align-items: center;
1172
+ margin-inline-end: 2px;
1173
+ }
1174
+
1175
+ .kp-source-thumb.stacked {
1176
+ margin-inline-end: -10px;
1177
+ background: #ffffff;
1178
+ }
1179
+
1180
+ .kp-message-actions {
1181
+ display: flex;
1182
+ align-items: center;
1183
+ gap: 8px;
1184
+ margin-top: 10px;
1185
+ }
1186
+
1187
+ .kp-message-action {
1188
+ border: 1px solid rgba(219, 228, 238, 0.9);
1189
+ background: #ffffff;
1190
+ color: #4b6478;
1191
+ border-radius: 999px;
1192
+ padding: 7px 10px;
1193
+ cursor: pointer;
1194
+ font-size: 12px;
1195
+ line-height: 1;
1196
+ }
1197
+
1198
+ .kp-message-action.active {
1199
+ color: #0f6a75;
1200
+ border-color: rgba(15, 118, 110, 0.3);
1201
+ background: rgba(236, 254, 255, 0.92);
702
1202
  }
703
1203
 
704
1204
  .kp-suggestions {
@@ -731,11 +1231,15 @@
731
1231
  align-items: center;
732
1232
  gap: 10px;
733
1233
  border: 1px solid var(--kp-border-color);
734
- border-radius: 14px;
1234
+ border-radius: 16px;
735
1235
  padding: 10px 12px;
736
1236
  background: #ffffff;
737
1237
  }
738
1238
 
1239
+ .kp-rtl .kp-form {
1240
+ flex-direction: row-reverse;
1241
+ }
1242
+
739
1243
  .kp-input {
740
1244
  flex: 1;
741
1245
  border: none;
@@ -770,6 +1274,11 @@
770
1274
  display: flex;
771
1275
  align-items: center;
772
1276
  justify-content: center;
1277
+ flex: none;
1278
+ }
1279
+
1280
+ .kp-rtl .kp-send {
1281
+ transform: scaleX(-1);
773
1282
  }
774
1283
 
775
1284
  .kp-note {
@@ -787,6 +1296,43 @@
787
1296
  padding: 4px 2px;
788
1297
  }
789
1298
 
1299
+ @media (max-width: 1100px) {
1300
+ .kp-full-page-content:has(.kp-source-panel.open) {
1301
+ grid-template-columns: 260px minmax(0, 1fr);
1302
+ }
1303
+
1304
+ .kp-source-panel.open {
1305
+ position: absolute;
1306
+ inset-inline-end: 28px;
1307
+ top: 92px;
1308
+ bottom: 26px;
1309
+ width: min(320px, calc(100vw - 56px));
1310
+ z-index: 3;
1311
+ }
1312
+ }
1313
+
1314
+ @media (max-width: 860px) {
1315
+ .kp-full-page-content,
1316
+ .kp-full-page-content:has(.kp-source-panel.open) {
1317
+ grid-template-columns: 1fr;
1318
+ }
1319
+
1320
+ .kp-full-page-sidebar {
1321
+ max-height: 260px;
1322
+ }
1323
+
1324
+ .kp-full-page-embedded .kp-full-page-sidebar {
1325
+ max-height: none;
1326
+ }
1327
+
1328
+ .kp-source-panel.open {
1329
+ position: static;
1330
+ inset: auto;
1331
+ width: auto;
1332
+ max-height: 280px;
1333
+ }
1334
+ }
1335
+
790
1336
  @media (max-width: 640px) {
791
1337
  .kp-chat-widget,
792
1338
  .kp-chat-widget.bottom-left {
@@ -795,11 +1341,17 @@
795
1341
  bottom: 16px;
796
1342
  }
797
1343
 
1344
+ .kp-chat-widget.kp-chat-widget-embedded,
1345
+ .kp-chat-widget.kp-chat-widget-embedded.bottom-left {
1346
+ left: auto;
1347
+ right: auto;
1348
+ bottom: auto;
1349
+ }
1350
+
798
1351
  .kp-panel,
799
1352
  .kp-chat-widget.bottom-left .kp-panel {
800
1353
  inset: 0;
801
1354
  width: 100vw;
802
- max-width: none;
803
1355
  height: 100vh;
804
1356
  border-radius: 0;
805
1357
  transform: translateX(72px) scale(0.985);
@@ -814,16 +1366,12 @@
814
1366
  padding: 14px;
815
1367
  }
816
1368
 
817
- .kp-full-page-header {
1369
+ .kp-full-page-embedded .kp-full-page-shell {
818
1370
  padding: 0;
819
1371
  }
820
1372
 
821
- .kp-full-page-content {
822
- grid-template-columns: 1fr;
823
- }
824
-
825
- .kp-full-page-sidebar {
826
- order: 2;
1373
+ .kp-full-page-header {
1374
+ padding: 0;
827
1375
  }
828
1376
 
829
1377
  .kp-full-page-body {
@@ -838,6 +1386,19 @@
838
1386
  .kp-full-page-hero-text {
839
1387
  font-size: 22px;
840
1388
  }
1389
+
1390
+ .kp-message-row {
1391
+ gap: 8px;
1392
+ }
1393
+
1394
+ .kp-avatar {
1395
+ width: 32px;
1396
+ height: 32px;
1397
+ }
1398
+
1399
+ .kp-bubble {
1400
+ max-width: calc(100% - 40px);
1401
+ }
841
1402
  }
842
1403
 
843
1404
  @keyframes kp-cluster-rotate {
@@ -868,5 +1429,32 @@
868
1429
  40% { transform: translate(16px, -13px) scale(0.92); opacity: 0.96; }
869
1430
  62% { transform: translate(2px, -2px) scale(1); opacity: 0.98; }
870
1431
  }
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});
1432
+ `}var ft={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=dt(e),a=Se(t.locale),n=dn(t.locale),i=un(a),l=t.displayMode==="embedded",s={chatId:ce(t),open:!1,fullPageOpen:l,myChatsOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1,sourcePanelOpen:!1,sourcePanelTitle:null},p=document.createElement("div");p.dataset.chatWidgetHost="true",t.mount.appendChild(p);let c=p.attachShadow({mode:"open"});gt(c,t.theme);let u=o("div",`kp-chat-widget ${t.position}`);u.lang=a,u.dir=i?"rtl":"ltr",l&&(u.classList.add("kp-chat-widget-embedded"),kt(!0)),i&&u.classList.add("kp-rtl");let g=o("div","kp-overlay"),f=o("button","kp-launcher");f.type="button",f.setAttribute("aria-label",t.launcherAriaLabel),f.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 h=o("section","kp-panel");h.setAttribute("role","dialog"),h.setAttribute("aria-modal","true"),h.setAttribute("aria-label",t.title);let w=o("div","kp-header"),L=o("div","kp-toolbar"),b=o("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 y=o("div","kp-dropdown"),k=o("button","kp-dropdown-item",n.newChat);k.type="button";let M=o("button","kp-dropdown-item",n.myChats);M.type="button";let v=o("button","kp-dropdown-item",n.openAssistant);v.type="button",y.append(k,M,v),L.append(b,y);let Te=o("div","kp-title-wrap"),Pt=o("h2","kp-title",t.title),St=o("div","kp-subtitle",t.subtitle);Te.append(Pt,St);let ee=o("button","kp-close","\xD7");ee.type="button",ee.setAttribute("aria-label",t.closeAriaLabel),w.append(L,Te,ee);let te=o("div","kp-body"),ue=o("div","kp-hero"),Tt=o("div","kp-hero-icon","\u2726"),Et=o("div","kp-hero-text",t.welcomeMessage);ue.append(Tt,Et);let Ee=o("div","kp-footer"),ge=o("form","kp-form"),E=o("input","kp-input");E.type="text",E.autocomplete="off",E.placeholder=t.inputPlaceholder,E.setAttribute("aria-label",t.inputPlaceholder);let fe=o("button","kp-send","\u279C");fe.type="submit",fe.setAttribute("aria-label",n.send);let It=o("div","kp-note",n.authTokenForwarded);ge.append(E,fe),Ee.append(ge,It),h.append(w,te,Ee),l||u.append(g,f,h),c.appendChild(u),te.appendChild(ue);let Ie=o("div","kp-suggestions");te.appendChild(Ie);let ne=o("section","kp-my-chats-sheet"),Re=o("div","kp-my-chats-header"),ae=o("button","kp-my-chats-nav","\u2190");ae.type="button",ae.setAttribute("aria-label",n.back);let oe=o("button","kp-my-chats-nav kp-my-chats-close","\xD7");oe.type="button",oe.setAttribute("aria-label",n.close),Re.append(ae,oe);let $e=o("div","kp-my-chats-body"),Rt=o("div","kp-my-chats-section-label",n.recentActivity),He=o("div","kp-my-chats-list"),$t=o("div","kp-my-chats-section-label",n.pinnedCollections),Me=o("div","kp-my-chats-list");$e.append(Rt,He,$t,Me),ne.append(Re,$e),h.appendChild(ne);let S={body:te,input:E,suggestions:Ie,hero:ue,kind:"panel"},A=o("section","kp-full-page");l&&A.classList.add("kp-full-page-embedded","open"),A.setAttribute("role","dialog"),l||A.setAttribute("aria-modal","true"),A.setAttribute("aria-label",`${t.title} page`);let ze=o("div","kp-full-page-shell"),he=o("div","kp-full-page-header"),Ne=o("div","kp-full-page-brand"),Ht=o("div","kp-full-page-brand-mark","\u2726"),Mt=o("div","kp-full-page-brand-text",t.title);Ne.append(Ht,Mt);let Oe=o("div","kp-full-page-header-actions"),zt=o("div","kp-full-page-badge",n.assistantBadge),se=o("button","kp-full-page-close","\xD7");se.type="button",se.setAttribute("aria-label",n.closeAssistantPage),Oe.append(zt,se),he.append(Ne,Oe),t.embedded.showHeader||he.classList.add("kp-hidden");let Ue=o("div","kp-full-page-content"),Be=o("aside","kp-full-page-sidebar"),me=o("button","kp-full-page-new-chat",`+ ${n.newChat}`);me.type="button";let We=o("div","kp-full-page-search"),F=o("input","kp-full-page-search-input");F.type="search",F.placeholder=n.searchChat;let Nt=o("span","kp-full-page-search-icon","\u2315");We.append(F,Nt);let Ot=o("div","kp-full-page-section-label",n.recentActivity),je=o("div","kp-full-page-recent-list"),Ut=o("div","kp-full-page-section-label",n.pinnedCollections),De=o("div","kp-full-page-pinned-list");Be.append(me,We,Ot,je,Ut,De);let qe=o("main","kp-full-page-main"),Ve=o("section","kp-full-page-panel"),be=o("div","kp-full-page-body"),ke=o("div","kp-full-page-hero"),_e=o("div","kp-full-page-hero-badge");_e.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=o("div","kp-full-page-hero-text",t.welcomeMessage);ke.append(_e,Bt);let Fe=o("div","kp-suggestions kp-full-page-suggestions");be.append(ke,Fe);let Ke=o("div","kp-full-page-footer"),xe=o("form","kp-form kp-full-page-form"),P=o("input","kp-input kp-full-page-input");P.type="text",P.autocomplete="off",P.placeholder=t.inputPlaceholder,P.setAttribute("aria-label",t.inputPlaceholder);let ye=o("button","kp-send kp-full-page-send","\u279C");ye.type="submit",ye.setAttribute("aria-label",n.send);let Wt=o("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);xe.append(P,ye),Ke.append(xe,Wt),Ve.append(be,Ke),qe.appendChild(Ve);let re=o("aside","kp-source-panel"),Xe=o("div","kp-source-panel-header"),Ye=o("div","kp-source-panel-title-wrap"),Ge=o("div","kp-source-panel-title",n.allSourcesUsed),jt=o("div","kp-source-panel-subtitle",n.documentsAndReferences);Ye.append(Ge,jt);let ie=o("button","kp-source-panel-close","\xD7");ie.type="button",ie.setAttribute("aria-label",n.closeSourcesPanel),Xe.append(Ye,ie);let K=o("div","kp-source-panel-list"),Dt=o("div","kp-source-panel-empty",n.noSources);K.appendChild(Dt),re.append(Xe,K),Ue.append(Be,qe,re),ze.append(he,Ue),A.appendChild(ze),u.appendChild(A);let C={body:be,input:P,suggestions:Fe,hero:ke,kind:"full-page"},z=()=>({...t,getAccessToken:s.accessTokenProvider}),Je=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}},X=(r,d)=>{if(s.sourcePanelOpen=!0,s.sourcePanelTitle=d??n.allSourcesUsed,Ge.textContent=s.sourcePanelTitle,re.classList.add("open"),K.textContent="",r.length===0){K.appendChild(o("div","kp-source-panel-empty",n.noSources));return}for(let m of r)K.appendChild(wn(m,n))},W=()=>{s.sourcePanelOpen=!1,s.sourcePanelTitle=null,re.classList.remove("open")};V(S,t.initialSuggestions,async r=>{await I(r,S)}),V(C,t.initialSuggestions,async r=>{await I(r,C)}),O(),le(),l&&(T(),t.rag.loadHistoryOnOpen&&j(C,s.chatId));function we(){if(l){s.fullPageOpen=!0,A.classList.add("open");return}s.open||(s.open=!0,s.fullPageOpen=!1,$(),A.classList.remove("open"),f.classList.add("hidden"),g.classList.add("visible"),h.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&ve.loadHistory(),queueMicrotask(()=>E.focus()))}function N(){if(l){W();return}s.open&&(R(),$(),s.open=!1,f.classList.remove("hidden"),g.classList.remove("visible"),h.classList.remove("open"),t.onClose?.())}async function I(r,d){let m=r.trim();if(!m)return;d.input.value="";try{await Kt(m)}catch(H){let Y=B(t,H);Q(d.body,"bot",`${n.unableToCreateChat}: ${Y.message}`,{strings:n,view:d,userName:null,onShowSources:X});return}ht(d),Q(d.body,"user",m,{strings:n,view:d,userName:await Je(),onShowSources:X}),d.body.scrollTop=d.body.scrollHeight;let U=o("div","kp-loading",n.thinking);d.body.appendChild(U),d.body.scrollTop=d.body.scrollHeight;try{let H=await rt(z(),{message:m,chatId:s.chatId,knowledgeNames:await on(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});U.isConnected&&U.remove(),Q(d.body,"bot",H.answer,{strings:n,view:d,userName:null,citations:H.citations??[],onShowSources:X}),s.historyLoadedChatId=null,await T(),H.suggestions?.length&&V(d,H.suggestions,async Y=>{await I(Y,d)})}catch(H){let Y=B(t,H);U.isConnected&&U.remove(),Q(d.body,"bot",`${n.requestFailed}: ${Y.message}`,{strings:n,view:d,userName:null,onShowSources:X})}}async function Qe(r){let d=s.fullPageOpen?C:S;await I(r,d)}async function qt(){if(l){s.fullPageOpen=!0,A.classList.add("open"),await T(),await j(C,s.chatId),queueMicrotask(()=>P.focus());return}s.fullPageOpen=!0,s.open=!1,R(),$(),h.classList.remove("open"),g.classList.remove("visible"),f.classList.add("hidden"),A.classList.add("open"),await T(),await j(C,s.chatId),queueMicrotask(()=>P.focus())}function Ze(){if(l){W();return}s.fullPageOpen&&(s.fullPageOpen=!1,A.classList.remove("open"),f.classList.remove("hidden"),W())}function Vt(){s.menuOpen=!0,b.classList.add("open"),y.classList.add("open")}function R(){s.menuOpen=!1,b.classList.remove("open"),y.classList.remove("open")}function _t(){s.chatId=ce(t),s.historyLoadedChatId=null,$(),J(S),V(S,t.initialSuggestions,async r=>{await I(r,S)}),R()}async function Ft(){s.chatId=ce(t),s.historyLoadedChatId=null,J(C),W(),V(C,t.initialSuggestions,async r=>{await I(r,C)}),O()}async function T(){if(!t.endpoints.listChats)return O(),le(),[];s.loadingChats=!0,O(),le();try{let r=await lt(z());return s.chats=r,r}catch(r){return B(t,r),s.chats}finally{s.loadingChats=!1,O(),le()}}async function Kt(r){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(d=>d.chatId===s.chatId)||await pt(z(),s.chatId,r?cn(r,n.newChat):void 0)}async function Xt(r){s.chatId=r,s.historyLoadedChatId=null,await j(C,r),O()}async function Yt(r){s.chatId=r,s.historyLoadedChatId=null,await j(S,r),$()}async function Gt(){R(),await T(),s.myChatsOpen=!0,h.classList.add("kp-sheet-open"),ne.classList.add("open")}function $(){s.myChatsOpen=!1,h.classList.remove("kp-sheet-open"),ne.classList.remove("open")}async function et(r){if(!t.endpoints.updateChat)return;let d=window.prompt(n.renamePrompt,r.title)?.trim();if(!(!d||d===r.title))try{await Ae(z(),r.chatId,{title:d}),await T()}catch(m){B(t,m)}}async function tt(r){if(t.endpoints.deleteChat)try{await ct(z(),r.chatId),s.chatId===r.chatId&&(s.chatId=ce(t),s.historyLoadedChatId=null,J(S),J(C)),await T()}catch(d){B(t,d)}}function O(){mt(je,De,s,n,async r=>{await Xt(r.chatId)},async r=>{await nt(r)},async r=>{await et(r)},async r=>{await tt(r)})}function le(){mt(He,Me,s,n,async r=>{await Yt(r.chatId)},async r=>{await nt(r)},async r=>{await et(r)},async r=>{await tt(r)})}async function nt(r){if(t.endpoints.updateChat)try{await Ae(z(),r.chatId,{pinned:!r.pinned}),await T()}catch(d){B(t,d)}}async function j(r,d){J(r),V(r,t.initialSuggestions,async U=>{await I(U,r)});let m=await it(z(),d);return m.length>0&&(ht(r),xt(r.body,r.hero,r.suggestions),pn(r.body,m,{strings:n,view:r,userName:await Je(),onShowSources:X})),s.historyLoadedChatId=d,m}let ve={open:we,close:N,toggle(){if(l){we();return}if(s.open){N();return}we()},destroy(){if(document.removeEventListener("keydown",at),p.remove(),l){let r=!1;document.querySelectorAll("[data-chat-widget-host]").forEach(d=>{let m=d.shadowRoot;m&&m.querySelector(".kp-chat-widget-embedded")&&(r=!0)}),r||kt(!1)}},sendMessage:Qe,setAccessTokenProvider(r){s.accessTokenProvider=r},getChatId(){return s.chatId},loadChats(){return T()},async loadHistory(){let r=s.fullPageOpen?C:S;return j(r,s.chatId)}};f.addEventListener("click",()=>ve.toggle()),ee.addEventListener("click",N),g.addEventListener("click",N),ie.addEventListener("click",W),ae.addEventListener("click",$),oe.addEventListener("click",$),b.addEventListener("click",r=>{if(r.stopPropagation(),!s.menuOpen){Vt();return}R()}),k.addEventListener("click",_t),M.addEventListener("click",async()=>{await Gt()}),v.addEventListener("click",()=>{if(R(),t.onOpenAssistantPage){N(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){N(),window.location.href=t.assistantPageUrl;return}qt()}),se.addEventListener("click",Ze),me.addEventListener("click",()=>{Ft(),queueMicrotask(()=>P.focus())}),F.addEventListener("input",()=>{s.chatSearchTerm=F.value.trim().toLowerCase(),O()}),h.addEventListener("click",r=>{let d=r.target;if(!(d instanceof Element)||!d.closest(".kp-chat-actions")){for(let m of Array.from(c.querySelectorAll(".kp-chat-actions.open")))m.classList.remove("open");for(let m of Array.from(c.querySelectorAll(".kp-full-page-chat-item.menu-open")))m.classList.remove("menu-open")}s.menuOpen&&!y.contains(d)&&!b.contains(d)&&R(),r.stopPropagation()}),c.addEventListener("click",r=>{let d=r.target;if(s.menuOpen&&d instanceof Node&&!y.contains(d)&&!b.contains(d)&&R(),d instanceof Element&&!d.closest(".kp-chat-actions")){for(let m of Array.from(c.querySelectorAll(".kp-chat-actions.open")))m.classList.remove("open");for(let m of Array.from(c.querySelectorAll(".kp-full-page-chat-item.menu-open")))m.classList.remove("menu-open")}}),ge.addEventListener("submit",async r=>{r.preventDefault(),await Qe(E.value)}),xe.addEventListener("submit",async r=>{r.preventDefault(),await I(P.value,C)});function at(r){if(r.key==="Escape"){if(s.sourcePanelOpen){W();return}if(s.myChatsOpen){$();return}if(s.fullPageOpen){if(l)return;Ze();return}s.open&&N()}}return document.addEventListener("keydown",at),ve}async function on(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 Q(e,t,a,n){let i=t==="bot"?fn(a,n.citations??[]):{displayText:a,citations:n.citations??[]},l=o("div",`kp-message-row ${t}`),s=rn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),p=o("div",`kp-bubble ${t}`),c=o("div","kp-bubble-content");Ln(c,i.displayText),p.appendChild(c);let u=i.citations;if(u.length){let g=o("div","kp-meta",n.strings.citationsAttached(u.length));p.appendChild(g);let f=o("div","kp-source-preview"),h=o("div","kp-source-preview-title",n.strings.sourcesUsed),w=o("div","kp-source-preview-list");for(let b of u.slice(0,2)){let y=xn(b,n.strings);y.addEventListener("click",async()=>{wt(b,n.strings)}),w.appendChild(y)}let L=yn(n.strings);L.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),w.appendChild(L),f.append(h,w),p.appendChild(f)}return t==="bot"&&p.appendChild(sn(i.displayText,n.strings)),t==="user"?l.append(p,s):l.append(s,p),e.appendChild(l),e.scrollTop=e.scrollHeight,l}function sn(e,t){let a=o("div","kp-message-actions"),n=o("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=o("button","kp-message-action","\u{1F44D}");i.type="button",i.setAttribute("aria-label",t.helpful),i.addEventListener("click",()=>{i.classList.toggle("active"),l.classList.remove("active")});let l=o("button","kp-message-action","\u{1F44E}");return l.type="button",l.setAttribute("aria-label",t.notHelpful),l.addEventListener("click",()=>{l.classList.toggle("active"),i.classList.remove("active")}),a.append(n,i,l),a}function rn(e,t){let a=o("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":gn(e);return a.textContent=n,a.setAttribute("aria-hidden","true"),a}function ln(e,t,a){e.textContent="";for(let n of t){let i=o("button","kp-suggestion",n);i.type="button",i.addEventListener("click",async()=>{await a(n)}),e.appendChild(i)}}function V(e,t,a){ln(e.suggestions,t,async n=>{e.input.value=n,await a(n)})}function xt(e,t,a){let n=new Set([t,a]);for(let i of Array.from(e.children))n.has(i)||i.remove()}function ht(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function J(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),xt(e.body,e.hero,e.suggestions),e.input.value=""}function pn(e,t,a){for(let n of t)Q(e,n.role==="assistant"?"bot":"user",n.text,a)}function mt(e,t,a,n,i,l,s,p){if(e.textContent="",t.textContent="",a.loadingChats){e.appendChild(o("div","kp-full-page-empty",n.loadingChats));return}let c=a.chats.filter(u=>a.chatSearchTerm?u.title.toLowerCase().includes(a.chatSearchTerm):!0);if(c.length>0){let u=c.filter(f=>f.pinned),g=c.filter(f=>!f.pinned).slice(0,8);bt(e,g,a.chatId,n,i,l,s,p),bt(t,u,a.chatId,n,i,l,s,p),g.length===0&&e.appendChild(o("div","kp-full-page-empty",n.noRecentChats)),u.length===0&&t.appendChild(o("div","kp-full-page-empty",n.noPinnedChats));return}e.appendChild(o("div","kp-full-page-empty",n.noChats)),t.appendChild(o("div","kp-full-page-empty",n.noPinnedChats))}function bt(e,t,a,n,i,l,s,p){for(let c of t){let u=o("div",`kp-full-page-item kp-full-page-chat-item${c.chatId===a?" active":""}`),g=o("span","kp-full-page-item-title",c.title),f=o("div","kp-chat-actions"),h=o("button","kp-chat-actions-trigger","\u22EF");h.type="button",h.setAttribute("aria-label",n.chatActions);let w=o("div","kp-chat-actions-menu"),L=o("button","kp-chat-actions-item",c.pinned?n.unpinChat:n.pinChat);L.type="button",L.addEventListener("click",async k=>{k.stopPropagation(),await l(c)});let b=o("button","kp-chat-actions-item",n.renameChat);b.type="button",b.addEventListener("click",async k=>{k.stopPropagation(),await s(c)});let y=o("button","kp-chat-actions-item",n.deleteChat);y.type="button",y.addEventListener("click",async k=>{k.stopPropagation(),await p(c)}),w.append(L,b,y),f.append(h,w),h.addEventListener("click",k=>{k.stopPropagation();let M=f.classList.contains("open");for(let v of Array.from(e.querySelectorAll(".kp-chat-actions.open")))v.classList.remove("open");for(let v of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))v.classList.remove("menu-open");M||(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(c)}),u.addEventListener("keydown",async k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),await i(c))}),u.addEventListener("blur",()=>{f.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function cn(e,t){return e.trim().slice(0,60)||t}function Se(e){return e.toLowerCase().split("-")[0]||"en"}function dn(e){let t=ft.en;return ft[Se(e)]??t}function un(e){return["ar","fa","he","ur"].includes(Se(e))}function gn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(a=>a[0]?.toUpperCase()??"").join("")}function yt(e){return e.knowledgeName?.trim()||e.sourceDocument?.trim()||null}function fn(e,t){let a=hn(e);return{displayText:a.displayText,citations:t.length>0?kn(t,a.citations):a.citations}}function hn(e){let a=vt(e).split(`
1433
+ `),n=-1;for(let c=0;c<a.length;c+=1)/^#{0,6}\s*References\s*$/i.test(a[c]?.trim()??"")&&(n=c);if(n===-1)return{displayText:e,citations:[]};let i=a.slice(0,n).join(`
1434
+ `).trimEnd(),l=a.slice(n+1).join(`
1435
+ `).trim(),p=mn(l).map(c=>bn(c)).filter(c=>!!c);return{displayText:i,citations:p}}function mn(e){let t=[],a="";for(let n of e.split(`
1436
+ `)){let i=n.trim();if(i){if(/^\d+\.\s+/.test(i)){a&&t.push(a.trim()),a=i.replace(/^\d+\.\s+/,"");continue}a&&(a=`${a} ${i}`)}}return a&&t.push(a.trim()),t}function bn(e){let t=e.match(/https?:\/\/\S+/i);if(!t)return null;let a=t[0],n=e.slice(0,t.index).replace(/[.\s]+$/,"").trim();return{sourceDocument:a,knowledgeName:n||a}}function kn(e,t){let a=[],n=new Set;for(let i of[...e,...t]){let l=`${i.knowledgeName??""}::${i.sourceDocument??""}`;n.has(l)||(n.add(l),a.push(i))}return a}function xn(e,t){let a=o("button","kp-source-chip");a.type="button",a.setAttribute("aria-label",t.openSource);let n=o("span","kp-source-thumb");n.textContent="\u2726";let i=o("span","kp-source-chip-label",yt(e)??t.untitledSource);return a.append(n,i),a}function yn(e){let t=o("button","kp-source-chip kp-source-chip-more");t.type="button";let a=o("span","kp-source-thumb-stack");for(let i=0;i<3;i+=1){let l=o("span","kp-source-thumb stacked");l.textContent="\u2726",a.appendChild(l)}let n=o("span","kp-source-chip-label",e.showAll);return t.append(a,n),t}function wn(e,t){let a=o("button","kp-source-card");a.type="button",a.setAttribute("aria-label",t.openSource),a.addEventListener("click",()=>{wt(e,t)});let n=o("div","kp-source-card-media"),i=o("span","kp-source-thumb kp-source-thumb-large");i.textContent="\u2726";let l=o("div","kp-source-card-title",yt(e)??t.untitledSource),s=o("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}`),s.textContent=p.join(" \u2022 "),n.appendChild(i),a.append(n,l,s),a}function wt(e,t){let a=e.sourceDocument?.trim()||e.knowledgeName?.trim()||t.untitledSource,n=vn(e.sourceDocument);if(n){window.open(n,"_blank","noopener,noreferrer");return}let i=window.open("","_blank","noopener,noreferrer");if(!i)return;let l=Z(a),s=Cn(e,t).map(p=>`<li>${Z(p)}</li>`).join("");i.document.write(`<!doctype html>
1437
+ <html lang="en">
1438
+ <head>
1439
+ <meta charset="utf-8">
1440
+ <title>${l}</title>
1441
+ <style>
1442
+ body { font-family: Arial, sans-serif; margin: 32px; color: #1f2937; }
1443
+ .card { max-width: 720px; padding: 24px; border: 1px solid #dbe4ee; border-radius: 16px; background: #fff; }
1444
+ h1 { margin: 0 0 12px; font-size: 24px; }
1445
+ p { margin: 0 0 16px; color: #64748b; }
1446
+ ul { margin: 0; padding-left: 20px; }
1447
+ </style>
1448
+ </head>
1449
+ <body>
1450
+ <div class="card">
1451
+ <h1>${l}</h1>
1452
+ <p>${Z(t.documentsAndReferences)}</p>
1453
+ <ul>${s||`<li>${Z(t.noSources)}</li>`}</ul>
1454
+ </div>
1455
+ </body>
1456
+ </html>`),i.document.close()}function vn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function Cn(e,t){let a=[];return e.sourceDocument&&a.push(e.sourceDocument),typeof e.score=="number"&&a.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&a.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&a.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&a.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&a.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),a}function Ln(e,t){e.innerHTML=An(vt(t))}function vt(e){return e.replace(/\r\n/g,`
1457
+ `).replace(/<br\s*\/?>/gi,`
1458
+ `)}function An(e){return e.split(/\n{2,}/).map(a=>a.trim()).filter(Boolean).map(Pn).join("")}function Pn(e){let t=e.split(`
1459
+ `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return Sn(t);if(t.every(n=>/^\d+\.\s+/.test(n)))return`<ol>${t.map(n=>`<li>${_(n.replace(/^\d+\.\s+/,""))}</li>`).join("")}</ol>`;if(t.every(n=>/^[-*]\s+/.test(n)))return`<ul>${t.map(n=>`<li>${_(n.replace(/^[-*]\s+/,""))}</li>`).join("")}</ul>`;let a=t[0]?.match(/^(#{1,6})\s+(.*)$/);if(a){let n=a[1]??"#",i=a[2]??"",l=n.length;return`<h${l}>${_(i)}</h${l}>`}return`<p>${t.map(n=>_(n)).join("<br>")}</p>`}function Sn(e){let t=e.filter((s,p)=>!(p===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(s))).map(s=>Tn(s));if(t.length===0)return"";let a=t[0]??[],n=t.slice(1),i=`<thead><tr>${a.map(s=>`<th>${_(s)}</th>`).join("")}</tr></thead>`,l=n.length?`<tbody>${n.map(s=>`<tr>${s.map(p=>`<td>${_(p)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${i}${l}</table></div>`}function Tn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function _(e){let t=Z(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 Z(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function kt(e){typeof document>"u"||document.querySelectorAll("[data-chat-widget-host]").forEach(t=>{let a=t.shadowRoot;if(a){let n=a.querySelector(".kp-chat-widget");n&&!n.classList.contains("kp-chat-widget-embedded")&&(t.style.display=e?"none":"")}})}var Ct="0.1.0",Lt=de,At={init:Lt,createChatWidget:de,version:Ct};typeof window<"u"&&(window.ChatWidget=At);0&&(module.exports={browserGlobal,createChatWidget,init,version});
872
1460
  //# sourceMappingURL=browser.cjs.map