@nabeh/chat-widget 0.1.2 → 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.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as o}from"./chunk-IFIILMOK.js";var e="0.1.0",t=o,r={init:t,createChatWidget:o,version:e};typeof window<"u"&&(window.ChatWidget=r);export{r as browserGlobal,o as createChatWidget,t as init,e as version};
1
+ import{a as o}from"./chunk-LET2O6EB.js";var e="0.1.0",t=o,r={init:t,createChatWidget:o,version:e};typeof window<"u"&&(window.ChatWidget=r);export{r as browserGlobal,o as createChatWidget,t as init,e as version};
2
2
  //# sourceMappingURL=browser.js.map
@@ -1,4 +1,4 @@
1
- function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t){let o={...e};for(let n of Object.keys(t)){let i=t[n],s=o[n];if(tt(s)&&tt(i)){o[n]=ye(s,i);continue}i!==void 0&&(o[n]=i)}return o}function nt(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 ot(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 at(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 st(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 rt(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 we(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 it(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=nt(t);return e.onError?.(o),o}var ve={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:ve,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0};function pt(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=ye(ve,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 lt="kp-chat-widget-styles";function ct(e,t){if(e.getElementById(lt))return;let o=document.createElement("style");o.id=lt,o.textContent=qt(t),e.appendChild(o)}function qt(e){return`
1
+ function nt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ve(e,t){let a={...e};for(let n of Object.keys(t)){let i=t[n],l=a[n];if(nt(l)&&nt(i)){a[n]=ve(l,i);continue}i!==void 0&&(a[n]=i)}return a}function at(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function J(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 J(e.apiBaseUrl,n)}async function ot(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 st(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(J(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 rt(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,a=await q(e),n=await fetch(J(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 it(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(J(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 Ce(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 lt(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=at(t);return e.onError?.(a),a}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'},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:Le,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0};function pt(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=ve(Le,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 ct="kp-chat-widget-styles";function dt(e,t){if(e.getElementById(ct))return;let a=document.createElement("style");a.id=ct,a.textContent=Ft(t),e.appendChild(a)}function Ft(e){return`
2
2
  :host {
3
3
  all: initial;
4
4
  }
@@ -25,6 +25,15 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
25
25
  box-sizing: border-box;
26
26
  }
27
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
+
28
37
  *,
29
38
  *::before,
30
39
  *::after {
@@ -37,6 +46,11 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
37
46
  right: auto;
38
47
  }
39
48
 
49
+ .kp-chat-widget.kp-chat-widget-embedded.bottom-left {
50
+ left: auto;
51
+ right: auto;
52
+ }
53
+
40
54
  .kp-rtl .kp-dropdown-item,
41
55
  .kp-rtl .kp-suggestion,
42
56
  .kp-rtl .kp-input,
@@ -195,6 +209,18 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
195
209
  overflow: hidden;
196
210
  }
197
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
+
198
224
  .kp-full-page.open {
199
225
  opacity: 1;
200
226
  pointer-events: auto;
@@ -210,6 +236,13 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
210
236
  overflow: hidden;
211
237
  }
212
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
+
213
246
  .kp-full-page-header {
214
247
  display: flex;
215
248
  align-items: center;
@@ -219,6 +252,10 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
219
252
  flex: none;
220
253
  }
221
254
 
255
+ .kp-hidden {
256
+ display: none !important;
257
+ }
258
+
222
259
  .kp-full-page-brand {
223
260
  display: flex;
224
261
  align-items: center;
@@ -286,6 +323,10 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
286
323
  align-items: stretch;
287
324
  }
288
325
 
326
+ .kp-full-page-embedded .kp-full-page-content {
327
+ height: 100%;
328
+ }
329
+
289
330
  .kp-full-page-sidebar,
290
331
  .kp-full-page-panel,
291
332
  .kp-source-panel {
@@ -1280,6 +1321,10 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
1280
1321
  max-height: 260px;
1281
1322
  }
1282
1323
 
1324
+ .kp-full-page-embedded .kp-full-page-sidebar {
1325
+ max-height: none;
1326
+ }
1327
+
1283
1328
  .kp-source-panel.open {
1284
1329
  position: static;
1285
1330
  inset: auto;
@@ -1296,6 +1341,13 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
1296
1341
  bottom: 16px;
1297
1342
  }
1298
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
+
1299
1351
  .kp-panel,
1300
1352
  .kp-chat-widget.bottom-left .kp-panel {
1301
1353
  inset: 0;
@@ -1314,6 +1366,10 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
1314
1366
  padding: 14px;
1315
1367
  }
1316
1368
 
1369
+ .kp-full-page-embedded .kp-full-page-shell {
1370
+ padding: 0;
1371
+ }
1372
+
1317
1373
  .kp-full-page-header {
1318
1374
  padding: 0;
1319
1375
  }
@@ -1373,15 +1429,15 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
1373
1429
  40% { transform: translate(16px, -13px) scale(0.92); opacity: 0.96; }
1374
1430
  62% { transform: translate(2px, -2px) scale(1); opacity: 0.98; }
1375
1431
  }
1376
- `}var dt={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 En(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=pt(e),o=Ce(t.locale),n=Qt(t.locale),i=Gt(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"});ct(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"),xt=a("h2","kp-title",t.title),yt=a("div","kp-subtitle",t.subtitle);C.append(xt,yt);let G=a("button","kp-close","\xD7");G.type="button",G.setAttribute("aria-label",t.closeAriaLabel),m.append(y,C,G);let Z=a("div","kp-body"),de=a("div","kp-hero"),wt=a("div","kp-hero-icon","\u2726"),vt=a("div","kp-hero-text",t.welcomeMessage);de.append(wt,vt);let Le=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 Ct=a("div","kp-note",n.authTokenForwarded);ue.append(S,ge),Le.append(ue,Ct),f.append(m,Z,Le),l.append(u,g,f),p.appendChild(l),Z.appendChild(de);let Ae=a("div","kp-suggestions");Z.appendChild(Ae);let ee=a("section","kp-my-chats-sheet"),Pe=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),Pe.append(te,ne);let Se=a("div","kp-my-chats-body"),Lt=a("div","kp-my-chats-section-label",n.recentActivity),Te=a("div","kp-my-chats-list"),At=a("div","kp-my-chats-section-label",n.pinnedCollections),Ee=a("div","kp-my-chats-list");Se.append(Lt,Te,At,Ee),ee.append(Pe,Se),f.appendChild(ee);let A={body:Z,input:S,suggestions:Ae,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 Ie=a("div","kp-full-page-shell"),Re=a("div","kp-full-page-header"),$e=a("div","kp-full-page-brand"),Pt=a("div","kp-full-page-brand-mark","\u2726"),St=a("div","kp-full-page-brand-text",t.title);$e.append(Pt,St);let He=a("div","kp-full-page-header-actions"),Tt=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),He.append(Tt,oe),Re.append($e,He);let ze=a("div","kp-full-page-content"),Me=a("aside","kp-full-page-sidebar"),fe=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);fe.type="button";let Ne=a("div","kp-full-page-search"),V=a("input","kp-full-page-search-input");V.type="search",V.placeholder=n.searchChat;let Et=a("span","kp-full-page-search-icon","\u2315");Ne.append(V,Et);let It=a("div","kp-full-page-section-label",n.recentActivity),Be=a("div","kp-full-page-recent-list"),Rt=a("div","kp-full-page-section-label",n.pinnedCollections),Ue=a("div","kp-full-page-pinned-list");Me.append(fe,Ne,It,Be,Rt,Ue);let Oe=a("main","kp-full-page-main"),We=a("section","kp-full-page-panel"),he=a("div","kp-full-page-body"),me=a("div","kp-full-page-hero"),je=a("div","kp-full-page-hero-badge");je.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 $t=a("div","kp-full-page-hero-text",t.welcomeMessage);me.append(je,$t);let De=a("div","kp-suggestions kp-full-page-suggestions");he.append(me,De);let Ve=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 Ht=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);be.append(P,ke),Ve.append(be,Ht),We.append(he,Ve),Oe.appendChild(We);let ae=a("aside","kp-source-panel"),qe=a("div","kp-source-panel-header"),_e=a("div","kp-source-panel-title-wrap"),Fe=a("div","kp-source-panel-title",n.allSourcesUsed),zt=a("div","kp-source-panel-subtitle",n.documentsAndReferences);_e.append(Fe,zt);let se=a("button","kp-source-panel-close","\xD7");se.type="button",se.setAttribute("aria-label",n.closeSourcesPanel),qe.append(_e,se);let q=a("div","kp-source-panel-list"),Mt=a("div","kp-source-panel-empty",n.noSources);q.appendChild(Mt),ae.append(qe,q),ze.append(Me,Oe,ae),Ie.append(Re,ze),T.appendChild(Ie),l.appendChild(T);let L={body:he,input:P,suggestions:De,hero:me,kind:"full-page"},H=()=>({...t,getAccessToken:s.accessTokenProvider}),Ke=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,Fe.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(pn(h,n))},re=()=>{s.sourcePanelOpen=!1,s.sourcePanelTitle=null,ae.classList.remove("open")};j(A,t.initialSuggestions,async r=>{await E(r,A)}),j(L,t.initialSuggestions,async r=>{await E(r,L)}),N(),ie();function Xe(){s.open||(s.open=!0,s.fullPageOpen=!1,I(),T.classList.remove("open"),g.classList.add("hidden"),u.classList.add("visible"),f.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&xe.loadHistory(),queueMicrotask(()=>S.focus()))}function F(){s.open&&(z(),I(),s.open=!1,g.classList.remove("hidden"),u.classList.remove("visible"),f.classList.remove("open"),t.onClose?.())}async function E(r,c){let h=r.trim();if(!h)return;c.input.value="";try{await Wt(h)}catch(R){let K=U(t,R);J(c.body,"bot",`${n.unableToCreateChat}: ${K.message}`,{strings:n,view:c,userName:null,onShowSources:_});return}ut(c),J(c.body,"user",h,{strings:n,view:c,userName:await Ke(),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 ot(H(),{message:h,chatId:s.chatId,knowledgeNames:await _t(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 E(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 Ye(r){let c=s.fullPageOpen?L:A;await E(r,c)}async function Nt(){s.fullPageOpen=!0,s.open=!1,z(),I(),f.classList.remove("open"),u.classList.remove("visible"),g.classList.add("hidden"),T.classList.add("open"),await M(),await pe(L,s.chatId),queueMicrotask(()=>P.focus())}function Je(){s.fullPageOpen&&(s.fullPageOpen=!1,T.classList.remove("open"),g.classList.remove("hidden"),re())}function Bt(){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 Ut(){s.chatId=ce(t),s.historyLoadedChatId=null,I(),Y(A),j(A,t.initialSuggestions,async r=>{await E(r,A)}),z()}async function Ot(){s.chatId=ce(t),s.historyLoadedChatId=null,Y(L),re(),j(L,t.initialSuggestions,async r=>{await E(r,L)}),N()}async function M(){if(!t.endpoints.listChats)return N(),ie(),[];s.loadingChats=!0,N(),ie();try{let r=await st(H());return s.chats=r,r}catch(r){return U(t,r),s.chats}finally{s.loadingChats=!1,N(),ie()}}async function Wt(r){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(c=>c.chatId===s.chatId)||await rt(H(),s.chatId,r?Jt(r,n.newChat):void 0)}async function jt(r){s.chatId=r,s.historyLoadedChatId=null,await pe(L,r),N()}async function Dt(r){s.chatId=r,s.historyLoadedChatId=null,await pe(A,r),I()}async function Vt(){z(),await M(),s.myChatsOpen=!0,f.classList.add("kp-sheet-open"),ee.classList.add("open")}function I(){s.myChatsOpen=!1,f.classList.remove("kp-sheet-open"),ee.classList.remove("open")}async function Qe(r){if(!t.endpoints.updateChat)return;let c=window.prompt(n.renamePrompt,r.title)?.trim();if(!(!c||c===r.title))try{await we(H(),r.chatId,{title:c}),await M()}catch(h){U(t,h)}}async function Ge(r){if(t.endpoints.deleteChat)try{await it(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(){gt(Be,Ue,s,n,async r=>{await jt(r.chatId)},async r=>{await Ze(r)},async r=>{await Qe(r)},async r=>{await Ge(r)})}function ie(){gt(Te,Ee,s,n,async r=>{await Dt(r.chatId)},async r=>{await Ze(r)},async r=>{await Qe(r)},async r=>{await Ge(r)})}async function Ze(r){if(t.endpoints.updateChat)try{await we(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 E(B,r)});let h=await at(H(),c);return h.length>0&&(ut(r),ht(r.body,r.hero,r.suggestions),Yt(r.body,h,{strings:n,view:r,userName:await Ke(),onShowSources:_})),s.historyLoadedChatId=c,h}let xe={open:Xe,close:F,toggle(){if(s.open){F();return}Xe()},destroy(){document.removeEventListener("keydown",et),d.remove()},sendMessage:Ye,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()),G.addEventListener("click",F),u.addEventListener("click",F),se.addEventListener("click",re),te.addEventListener("click",I),ne.addEventListener("click",I),b.addEventListener("click",r=>{if(r.stopPropagation(),!s.menuOpen){Bt();return}z()}),v.addEventListener("click",Ut),k.addEventListener("click",async()=>{await Vt()}),$.addEventListener("click",()=>{Nt()}),oe.addEventListener("click",Je),fe.addEventListener("click",()=>{Ot(),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 Ye(S.value)}),be.addEventListener("submit",async r=>{r.preventDefault(),await E(P.value,L)});function et(r){if(r.key==="Escape"){if(s.sourcePanelOpen){re();return}if(s.myChatsOpen){I();return}if(s.fullPageOpen){Je();return}s.open&&F()}}return document.addEventListener("keydown",et),xe}async function _t(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"?en(o,n.citations??[]):{displayText:o,citations:n.citations??[]},s=a("div",`kp-message-row ${t}`),d=Kt(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),p=a("div",`kp-bubble ${t}`),l=a("div","kp-bubble-content");dn(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=sn(x,n.strings);v.addEventListener("click",async()=>{bt(x,n.strings)}),y.appendChild(v)}let b=rn(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(Ft(i.displayText,n.strings)),t==="user"?s.append(p,d):s.append(d,p),e.appendChild(s),e.scrollTop=e.scrollHeight,s}function Ft(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 Kt(e,t){let o=a("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":Zt(e);return o.textContent=n,o.setAttribute("aria-hidden","true"),o}function Xt(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){Xt(e.suggestions,t,async n=>{e.input.value=n,await o(n)})}function ht(e,t,o){let n=new Set([t,o]);for(let i of Array.from(e.children))n.has(i)||i.remove()}function ut(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),ht(e.body,e.hero,e.suggestions),e.input.value=""}function Yt(e,t,o){for(let n of t)J(e,n.role==="assistant"?"bot":"user",n.text,o)}function gt(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);ft(e,g,o.chatId,n,i,s,d,p),ft(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 ft(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 Jt(e,t){return e.trim().slice(0,60)||t}function Ce(e){return e.toLowerCase().split("-")[0]||"en"}function Qt(e){let t=dt.en;return dt[Ce(e)]??t}function Gt(e){return["ar","fa","he","ur"].includes(Ce(e))}function Zt(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(o=>o[0]?.toUpperCase()??"").join("")}function mt(e){return e.knowledgeName?.trim()||e.sourceDocument?.trim()||null}function en(e,t){let o=tn(e);return{displayText:o.displayText,citations:t.length>0?an(t,o.citations):o.citations}}function tn(e){let o=kt(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=nn(s).map(l=>on(l)).filter(l=>!!l);return{displayText:i,citations:p}}function nn(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 on(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 an(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 sn(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",mt(e)??t.untitledSource);return o.append(n,i),o}function rn(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 pn(e,t){let o=a("button","kp-source-card");o.type="button",o.setAttribute("aria-label",t.openSource),o.addEventListener("click",()=>{bt(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",mt(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 bt(e,t){let o=e.sourceDocument?.trim()||e.knowledgeName?.trim()||t.untitledSource,n=ln(e.sourceDocument);if(n){window.open(n,"_blank","noopener,noreferrer");return}let i=window.open("","_blank","noopener,noreferrer");if(!i)return;let s=Q(o),d=cn(e,t).map(p=>`<li>${Q(p)}</li>`).join("");i.document.write(`<!doctype html>
1432
+ `}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 Rn(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=pt(e),a=Ae(t.locale),n=Zt(t.locale),i=en(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"});dt(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"),mt(!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 Pe=o("div","kp-title-wrap"),wt=o("h2","kp-title",t.title),vt=o("div","kp-subtitle",t.subtitle);Pe.append(wt,vt);let ee=o("button","kp-close","\xD7");ee.type="button",ee.setAttribute("aria-label",t.closeAriaLabel),w.append(L,Pe,ee);let te=o("div","kp-body"),de=o("div","kp-hero"),Ct=o("div","kp-hero-icon","\u2726"),Lt=o("div","kp-hero-text",t.welcomeMessage);de.append(Ct,Lt);let Se=o("div","kp-footer"),ue=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 ge=o("button","kp-send","\u279C");ge.type="submit",ge.setAttribute("aria-label",n.send);let At=o("div","kp-note",n.authTokenForwarded);ue.append(E,ge),Se.append(ue,At),h.append(w,te,Se),l||u.append(g,f,h),c.appendChild(u),te.appendChild(de);let Te=o("div","kp-suggestions");te.appendChild(Te);let ne=o("section","kp-my-chats-sheet"),Ee=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),Ee.append(ae,oe);let Ie=o("div","kp-my-chats-body"),Pt=o("div","kp-my-chats-section-label",n.recentActivity),Re=o("div","kp-my-chats-list"),St=o("div","kp-my-chats-section-label",n.pinnedCollections),$e=o("div","kp-my-chats-list");Ie.append(Pt,Re,St,$e),ne.append(Ee,Ie),h.appendChild(ne);let S={body:te,input:E,suggestions:Te,hero:de,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 He=o("div","kp-full-page-shell"),fe=o("div","kp-full-page-header"),Me=o("div","kp-full-page-brand"),Tt=o("div","kp-full-page-brand-mark","\u2726"),Et=o("div","kp-full-page-brand-text",t.title);Me.append(Tt,Et);let ze=o("div","kp-full-page-header-actions"),It=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),ze.append(It,se),fe.append(Me,ze),t.embedded.showHeader||fe.classList.add("kp-hidden");let Ne=o("div","kp-full-page-content"),Oe=o("aside","kp-full-page-sidebar"),he=o("button","kp-full-page-new-chat",`+ ${n.newChat}`);he.type="button";let Ue=o("div","kp-full-page-search"),F=o("input","kp-full-page-search-input");F.type="search",F.placeholder=n.searchChat;let Rt=o("span","kp-full-page-search-icon","\u2315");Ue.append(F,Rt);let $t=o("div","kp-full-page-section-label",n.recentActivity),Be=o("div","kp-full-page-recent-list"),Ht=o("div","kp-full-page-section-label",n.pinnedCollections),We=o("div","kp-full-page-pinned-list");Oe.append(he,Ue,$t,Be,Ht,We);let je=o("main","kp-full-page-main"),De=o("section","kp-full-page-panel"),me=o("div","kp-full-page-body"),be=o("div","kp-full-page-hero"),qe=o("div","kp-full-page-hero-badge");qe.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 Mt=o("div","kp-full-page-hero-text",t.welcomeMessage);be.append(qe,Mt);let Ve=o("div","kp-suggestions kp-full-page-suggestions");me.append(be,Ve);let _e=o("div","kp-full-page-footer"),ke=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 xe=o("button","kp-send kp-full-page-send","\u279C");xe.type="submit",xe.setAttribute("aria-label",n.send);let zt=o("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);ke.append(P,xe),_e.append(ke,zt),De.append(me,_e),je.appendChild(De);let re=o("aside","kp-source-panel"),Fe=o("div","kp-source-panel-header"),Ke=o("div","kp-source-panel-title-wrap"),Xe=o("div","kp-source-panel-title",n.allSourcesUsed),Nt=o("div","kp-source-panel-subtitle",n.documentsAndReferences);Ke.append(Xe,Nt);let ie=o("button","kp-source-panel-close","\xD7");ie.type="button",ie.setAttribute("aria-label",n.closeSourcesPanel),Fe.append(Ke,ie);let K=o("div","kp-source-panel-list"),Ot=o("div","kp-source-panel-empty",n.noSources);K.appendChild(Ot),re.append(Fe,K),Ne.append(Oe,je,re),He.append(fe,Ne),A.appendChild(He),u.appendChild(A);let C={body:me,input:P,suggestions:Ve,hero:be,kind:"full-page"},z=()=>({...t,getAccessToken:s.accessTokenProvider}),Ye=async()=>{if(!t.getUserContext)return null;try{let r=await t.getUserContext();return r?.displayName?.trim()||r?.email?.trim()||r?.userId?.trim()||null}catch{return null}},X=(r,d)=>{if(s.sourcePanelOpen=!0,s.sourcePanelTitle=d??n.allSourcesUsed,Xe.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(cn(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 ye(){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&&we.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 Dt(m)}catch(H){let Y=B(t,H);G(d.body,"bot",`${n.unableToCreateChat}: ${Y.message}`,{strings:n,view:d,userName:null,onShowSources:X});return}gt(d),G(d.body,"user",m,{strings:n,view:d,userName:await Ye(),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 ot(z(),{message:m,chatId:s.chatId,knowledgeNames:await Kt(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});U.isConnected&&U.remove(),G(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(),G(d.body,"bot",`${n.requestFailed}: ${Y.message}`,{strings:n,view:d,userName:null,onShowSources:X})}}async function Je(r){let d=s.fullPageOpen?C:S;await I(r,d)}async function Ut(){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 Qe(){if(l){W();return}s.fullPageOpen&&(s.fullPageOpen=!1,A.classList.remove("open"),f.classList.remove("hidden"),W())}function Bt(){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 Wt(){s.chatId=ce(t),s.historyLoadedChatId=null,$(),Q(S),V(S,t.initialSuggestions,async r=>{await I(r,S)}),R()}async function jt(){s.chatId=ce(t),s.historyLoadedChatId=null,Q(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 rt(z());return s.chats=r,r}catch(r){return B(t,r),s.chats}finally{s.loadingChats=!1,O(),le()}}async function Dt(r){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(d=>d.chatId===s.chatId)||await it(z(),s.chatId,r?Gt(r,n.newChat):void 0)}async function qt(r){s.chatId=r,s.historyLoadedChatId=null,await j(C,r),O()}async function Vt(r){s.chatId=r,s.historyLoadedChatId=null,await j(S,r),$()}async function _t(){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 Ge(r){if(!t.endpoints.updateChat)return;let d=window.prompt(n.renamePrompt,r.title)?.trim();if(!(!d||d===r.title))try{await Ce(z(),r.chatId,{title:d}),await T()}catch(m){B(t,m)}}async function Ze(r){if(t.endpoints.deleteChat)try{await lt(z(),r.chatId),s.chatId===r.chatId&&(s.chatId=ce(t),s.historyLoadedChatId=null,Q(S),Q(C)),await T()}catch(d){B(t,d)}}function O(){ft(Be,We,s,n,async r=>{await qt(r.chatId)},async r=>{await et(r)},async r=>{await Ge(r)},async r=>{await Ze(r)})}function le(){ft(Re,$e,s,n,async r=>{await Vt(r.chatId)},async r=>{await et(r)},async r=>{await Ge(r)},async r=>{await Ze(r)})}async function et(r){if(t.endpoints.updateChat)try{await Ce(z(),r.chatId,{pinned:!r.pinned}),await T()}catch(d){B(t,d)}}async function j(r,d){Q(r),V(r,t.initialSuggestions,async U=>{await I(U,r)});let m=await st(z(),d);return m.length>0&&(gt(r),bt(r.body,r.hero,r.suggestions),Qt(r.body,m,{strings:n,view:r,userName:await Ye(),onShowSources:X})),s.historyLoadedChatId=d,m}let we={open:ye,close:N,toggle(){if(l){ye();return}if(s.open){N();return}ye()},destroy(){if(document.removeEventListener("keydown",tt),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||mt(!1)}},sendMessage:Je,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",()=>we.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){Bt();return}R()}),k.addEventListener("click",Wt),M.addEventListener("click",async()=>{await _t()}),v.addEventListener("click",()=>{if(R(),t.onOpenAssistantPage){N(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){N(),window.location.href=t.assistantPageUrl;return}Ut()}),se.addEventListener("click",Qe),he.addEventListener("click",()=>{jt(),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")}}),ue.addEventListener("submit",async r=>{r.preventDefault(),await Je(E.value)}),ke.addEventListener("submit",async r=>{r.preventDefault(),await I(P.value,C)});function tt(r){if(r.key==="Escape"){if(s.sourcePanelOpen){W();return}if(s.myChatsOpen){$();return}if(s.fullPageOpen){if(l)return;Qe();return}s.open&&N()}}return document.addEventListener("keydown",tt),we}async function Kt(e){if(e.rag.getKnowledgeNames){let t=await e.rag.getKnowledgeNames();return Array.isArray(t)?t.filter(Boolean):[]}return(e.rag.knowledgeNames??[]).filter(Boolean)}function ce(e){return e.rag.chatId?.trim()?e.rag.chatId:e.rag.chatIdFactory?e.rag.chatIdFactory():typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`kp-chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function G(e,t,a,n){let i=t==="bot"?nn(a,n.citations??[]):{displayText:a,citations:n.citations??[]},l=o("div",`kp-message-row ${t}`),s=Yt(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),p=o("div",`kp-bubble ${t}`),c=o("div","kp-bubble-content");gn(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=ln(b,n.strings);y.addEventListener("click",async()=>{xt(b,n.strings)}),w.appendChild(y)}let L=pn(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(Xt(i.displayText,n.strings)),t==="user"?l.append(p,s):l.append(s,p),e.appendChild(l),e.scrollTop=e.scrollHeight,l}function Xt(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 Yt(e,t){let a=o("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":tn(e);return a.textContent=n,a.setAttribute("aria-hidden","true"),a}function Jt(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){Jt(e.suggestions,t,async n=>{e.input.value=n,await a(n)})}function bt(e,t,a){let n=new Set([t,a]);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 Q(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 Qt(e,t,a){for(let n of t)G(e,n.role==="assistant"?"bot":"user",n.text,a)}function ft(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);ht(e,g,a.chatId,n,i,l,s,p),ht(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 ht(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 Gt(e,t){return e.trim().slice(0,60)||t}function Ae(e){return e.toLowerCase().split("-")[0]||"en"}function Zt(e){let t=ut.en;return ut[Ae(e)]??t}function en(e){return["ar","fa","he","ur"].includes(Ae(e))}function tn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(a=>a[0]?.toUpperCase()??"").join("")}function kt(e){return e.knowledgeName?.trim()||e.sourceDocument?.trim()||null}function nn(e,t){let a=an(e);return{displayText:a.displayText,citations:t.length>0?rn(t,a.citations):a.citations}}function an(e){let a=yt(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=on(l).map(c=>sn(c)).filter(c=>!!c);return{displayText:i,citations:p}}function on(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 sn(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 rn(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 ln(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",kt(e)??t.untitledSource);return a.append(n,i),a}function pn(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 cn(e,t){let a=o("button","kp-source-card");a.type="button",a.setAttribute("aria-label",t.openSource),a.addEventListener("click",()=>{xt(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",kt(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 xt(e,t){let a=e.sourceDocument?.trim()||e.knowledgeName?.trim()||t.untitledSource,n=dn(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=un(e,t).map(p=>`<li>${Z(p)}</li>`).join("");i.document.write(`<!doctype html>
1381
1437
  <html lang="en">
1382
1438
  <head>
1383
1439
  <meta charset="utf-8">
1384
- <title>${s}</title>
1440
+ <title>${l}</title>
1385
1441
  <style>
1386
1442
  body { font-family: Arial, sans-serif; margin: 32px; color: #1f2937; }
1387
1443
  .card { max-width: 720px; padding: 24px; border: 1px solid #dbe4ee; border-radius: 16px; background: #fff; }
@@ -1392,13 +1448,13 @@ function tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ye(e,t)
1392
1448
  </head>
1393
1449
  <body>
1394
1450
  <div class="card">
1395
- <h1>${s}</h1>
1396
- <p>${Q(t.documentsAndReferences)}</p>
1397
- <ul>${d||`<li>${Q(t.noSources)}</li>`}</ul>
1451
+ <h1>${l}</h1>
1452
+ <p>${Z(t.documentsAndReferences)}</p>
1453
+ <ul>${s||`<li>${Z(t.noSources)}</li>`}</ul>
1398
1454
  </div>
1399
1455
  </body>
1400
- </html>`),i.document.close()}function ln(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function cn(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 dn(e,t){e.innerHTML=un(kt(t))}function kt(e){return e.replace(/\r\n/g,`
1456
+ </html>`),i.document.close()}function dn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function un(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 gn(e,t){e.innerHTML=fn(yt(t))}function yt(e){return e.replace(/\r\n/g,`
1401
1457
  `).replace(/<br\s*\/?>/gi,`
1402
- `)}function un(e){return e.split(/\n{2,}/).map(o=>o.trim()).filter(Boolean).map(gn).join("")}function gn(e){let t=e.split(`
1403
- `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return fn(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 fn(e){let t=e.filter((d,p)=>!(p===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(d))).map(d=>hn(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 hn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function D(e){let t=Q(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 Q(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}export{En as a};
1404
- //# sourceMappingURL=chunk-IFIILMOK.js.map
1458
+ `)}function fn(e){return e.split(/\n{2,}/).map(a=>a.trim()).filter(Boolean).map(hn).join("")}function hn(e){let t=e.split(`
1459
+ `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return mn(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 mn(e){let t=e.filter((s,p)=>!(p===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(s))).map(s=>bn(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 bn(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 mt(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":"")}})}export{Rn as a};
1460
+ //# sourceMappingURL=chunk-LET2O6EB.js.map