@nabeh/chat-widget 0.1.2 → 0.1.4

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.
@@ -1,4 +1,4 @@
1
- "use strict";var ChatWidget=(()=>{var we=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Jt=Object.prototype.hasOwnProperty;var Qt=(e,t)=>{for(var o in t)we(e,o,{get:t[o],enumerable:!0})},Zt=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gt(t))!Jt.call(e,i)&&i!==o&&we(e,i,{get:()=>t[i],enumerable:!(n=Yt(t,i))||n.enumerable});return e};var en=e=>Zt(we({},"__esModule",{value:!0}),e);var Sn={};Qt(Sn,{browserGlobal:()=>Ct,createChatWidget:()=>de,init:()=>vt,version:()=>wt});function ot(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ve(e,t){let o={...e};for(let n of Object.keys(t)){let i=t[n],s=o[n];if(ot(s)&&ot(i)){o[n]=ve(s,i);continue}i!==void 0&&(o[n]=i)}return o}function at(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function X(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}function O(e,t,o){return{"Content-Type":"application/json",...e.customHeaders,...o?{"X-Chat-User-Context":o}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function W(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function pe(e,t,o={}){let n=t.replace(/\{chatId\}/g,encodeURIComponent(o.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(o.chatId??""));return X(e.apiBaseUrl,n)}async function st(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),i=pe(e,e.endpoints.ask,{chatId:t.chatId}),d=/(\{chatId\}|:chatId\b)/.test(e.endpoints.ask)?{message:t.message,knowledgeNames:t.knowledgeNames,editLastQa:t.editLastQa??!1,enableReferences:t.enableReferences??!0}:{query:t.message,chat_id:t.chatId,knowledge_names:t.knowledgeNames,edit_last_qa:t.editLastQa??!1,enable_references:t.enableReferences??!0},l=await fetch(i,{method:"POST",headers:O(e,o,n),body:JSON.stringify(d)});if(!l.ok)throw new Error(`Chat backend returned ${l.status}.`);let p=await l.json();if(!Array.isArray(p)){if(!p.answer||typeof p.answer!="string")throw new Error("Chat backend response is missing a valid answer.");return{chatId:p.chatId??t.chatId,answer:p.answer,suggestions:p.suggestions??[],citations:p.citations??[]}}let u=p[0];if(!u?.answer||typeof u.answer!="string")throw new Error("Chat backend response is missing a valid answer.");let g=u.content,f=g?.source_documents??[],m=g?.scores??[],y=g?.page_numbers??[],b=g?.sheet_names??[],x=g?.row_numbers??[],v=g?.knowledge_names??[],k=f.map(($,C)=>({sourceDocument:$,score:m[C]??null,pageNumber:y[C]??null,sheetName:b[C]??null,rowNumber:x[C]??null,knowledgeName:v[C]??null}));return{chatId:t.chatId,answer:u.answer,suggestions:[],citations:k}}async function rt(e,t){if(!e.endpoints.history)return[];let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),s=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?pe(e,e.endpoints.history,{chatId:t}):(()=>{let u=new URL(X(e.apiBaseUrl,e.endpoints.history));return u.searchParams.set("chat_id",t),u.toString()})(),d=await fetch(s,{method:"GET",headers:O(e,o,n)});if(!d.ok)throw new Error(`Chat history endpoint returned ${d.status}.`);let l=await d.json(),p=Array.isArray(l)?l:l&&typeof l=="object"?l.history??l.messages??l.data??[]:[];return Array.isArray(p)?p.map(u=>{if(!u||typeof u!="object")return null;let g=u;if(typeof g.question=="string"&&typeof g.answer=="string")return[{role:"user",text:g.question},{role:"assistant",text:g.answer}];let f=g.role??g.type??g.sender??g.author,m=g.text??g.message??g.content??g.answer;if(typeof m!="string")return null;let y=typeof f=="string"?f.toLowerCase():"assistant";return[{role:y==="user"||y==="human"?"user":"assistant",text:m}]}).flat().filter(u=>!!u):[]}async function it(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,o=await W(e),n=await fetch(X(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:O(e,t,o)});if(!n.ok)throw new Error(`Chat list endpoint returned ${n.status}.`);let i=await n.json(),s=Array.isArray(i)?i:i&&typeof i=="object"?i.chats??i.data??i.items??[]:[];return Array.isArray(s)?s.map(d=>{if(!d||typeof d!="object")return null;let l=d,p=l.chatId??l.chat_id??l.id,u=l.title??l.name??l.chatId;if(typeof p!="string"||typeof u!="string")return null;let g=typeof l.createdAt=="string"?l.createdAt:typeof l.created_at=="string"?l.created_at:null,f=typeof l.updatedAt=="string"?l.updatedAt:typeof l.updated_at=="string"?l.updated_at:null,m={chatId:p,title:u,pinned:typeof l.pinned=="boolean"?l.pinned:!1};return g&&(m.createdAt=g),f&&(m.updatedAt=f),m}).filter(d=>!!d):[]}async function lt(e,t,o){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let i=e.getAccessToken?await e.getAccessToken():null,s=await W(e),d=await fetch(X(e.apiBaseUrl,n),{method:"POST",headers:O(e,i,s),body:JSON.stringify({chatId:t,...o?{title:o}:{}})});if(!d.ok)throw new Error(`Create chat endpoint returned ${d.status}.`)}async function Ce(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,i=await W(e),s=pe(e,e.endpoints.updateChat,{chatId:t}),d=await fetch(s,{method:"PATCH",headers:O(e,n,i),body:JSON.stringify(o)});if(!d.ok)throw new Error(`Update chat endpoint returned ${d.status}.`)}async function pt(e,t){if(!e.endpoints.deleteChat)return;let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),i=pe(e,e.endpoints.deleteChat,{chatId:t}),s=await fetch(i,{method:"DELETE",headers:O(e,o,n)});if(!s.ok)throw new Error(`Delete chat endpoint returned ${s.status}.`)}function U(e,t){let o=at(t);return e.onError?.(o),o}var Le={accent:"#0f766e",accentSoft:"#ecfeff",panelBackground:"#ffffff",surfaceBackground:"#f8fafc",text:"#1f2937",mutedText:"#64748b",borderColor:"#dbe4ee",shadow:"0 24px 64px rgba(15, 23, 42, 0.20)",zIndex:2147483e3,fontFamily:'"Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif'},w={position:"bottom-right",title:"Knowledge Assistant",subtitle:"Answers are generated based on your access permissions",welcomeMessage:"How can I assist you today?",inputPlaceholder:"Ask your question...",launcherAriaLabel:"Open chat assistant",closeAriaLabel:"Close chat assistant",initialSuggestions:["Which indicators reflect the achievements of Vision KSA goals?","Case studies of real estate initiatives for economic growth","Study of UX for the ministry external portal"],sourceApp:"knowledge-platform",locale:"en",customHeaders:{},rag:{knowledgeNames:[],enableReferences:!0,loadHistoryOnOpen:!1},theme:Le,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0};function ct(e){if(!e.apiBaseUrl?.trim())throw new Error("Chat widget config requires a non-empty apiBaseUrl.");if(!e.endpoints?.ask?.trim())throw new Error("Chat widget config requires endpoints.ask to be provided.");let t=e.mount??document.body,o=ve(Le,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,position:e.position??w.position,title:e.title??w.title,subtitle:e.subtitle??w.subtitle,welcomeMessage:e.welcomeMessage??w.welcomeMessage,inputPlaceholder:e.inputPlaceholder??w.inputPlaceholder,launcherAriaLabel:e.launcherAriaLabel??w.launcherAriaLabel,closeAriaLabel:e.closeAriaLabel??w.closeAriaLabel,initialSuggestions:e.initialSuggestions??w.initialSuggestions,sourceApp:e.sourceApp??w.sourceApp,locale:e.locale??w.locale,customHeaders:e.customHeaders??w.customHeaders,rag:{...w.rag,...e.rag??{}},theme:o,getAccessToken:e.getAccessToken,getUserContext:e.getUserContext,onOpen:e.onOpen,onClose:e.onClose,onError:e.onError}}function a(e,t,o){let n=document.createElement(e);return t&&(n.className=t),o!==void 0&&(n.textContent=o),n}var dt="kp-chat-widget-styles";function ut(e,t){if(e.getElementById(dt))return;let o=document.createElement("style");o.id=dt,o.textContent=tn(t),e.appendChild(o)}function tn(e){return`
1
+ "use strict";var ChatWidget=(()=>{var Ie=Object.defineProperty;var hn=Object.getOwnPropertyDescriptor;var mn=Object.getOwnPropertyNames;var bn=Object.prototype.hasOwnProperty;var xn=(e,t)=>{for(var a in t)Ie(e,a,{get:t[a],enumerable:!0})},kn=(e,t,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of mn(t))!bn.call(e,r)&&r!==a&&Ie(e,r,{get:()=>t[r],enumerable:!(n=hn(t,r))||n.enumerable});return e};var yn=e=>kn(Ie({},"__esModule",{value:!0}),e);var Fn={};xn(Fn,{browserGlobal:()=>Nt,createChatWidget:()=>xe,init:()=>Mt,version:()=>Ht});function bt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ze(e,t){let a={...e};for(let n of Object.keys(t)){let r=t[n],l=a[n];if(bt(l)&&bt(r)){a[n]=ze(l,r);continue}r!==void 0&&(a[n]=r)}return a}function xt(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function ae(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}function X(e,t,a){return{"Content-Type":"application/json",...e.customHeaders,...a?{"X-Chat-User-Context":a}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function G(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function me(e,t,a={}){let n=t.replace(/\{chatId\}/g,encodeURIComponent(a.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(a.chatId??""));return ae(e.apiBaseUrl,n)}async function kt(e,t){let a=e.getAccessToken?await e.getAccessToken():null,n=await G(e),r=me(e,e.endpoints.ask,{chatId:t.chatId}),i=/(\{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(r,{method:"POST",headers:X(e,a,n),body:JSON.stringify(i)});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??[],v=g?.page_numbers??[],P=g?.sheet_names??[],b=g?.row_numbers??[],y=g?.knowledge_names??[],x=f.map((U,w)=>({sourceDocument:U,score:h[w]??null,pageNumber:v[w]??null,sheetName:P[w]??null,rowNumber:b[w]??null,knowledgeName:y[w]??null}));return{chatId:t.chatId,answer:u.answer,suggestions:[],citations:x}}async function yt(e,t){if(!e.endpoints.history)return[];let a=e.getAccessToken?await e.getAccessToken():null,n=await G(e),l=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?me(e,e.endpoints.history,{chatId:t}):(()=>{let u=new URL(ae(e.apiBaseUrl,e.endpoints.history));return u.searchParams.set("chat_id",t),u.toString()})(),i=await fetch(l,{method:"GET",headers:X(e,a,n)});if(!i.ok)throw new Error(`Chat history endpoint returned ${i.status}.`);let p=await i.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 v=typeof f=="string"?f.toLowerCase():"assistant";return[{role:v==="user"||v==="human"?"user":"assistant",text:h}]}).flat().filter(u=>!!u):[]}async function vt(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,a=await G(e),n=await fetch(ae(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:X(e,t,a)});if(!n.ok)throw new Error(`Chat list endpoint returned ${n.status}.`);let r=await n.json(),l=Array.isArray(r)?r:r&&typeof r=="object"?r.chats??r.data??r.items??[]:[];return Array.isArray(l)?l.map(i=>{if(!i||typeof i!="object")return null;let p=i,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(i=>!!i):[]}async function wt(e,t,a){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let r=e.getAccessToken?await e.getAccessToken():null,l=await G(e),i=await fetch(ae(e.apiBaseUrl,n),{method:"POST",headers:X(e,r,l),body:JSON.stringify({chatId:t,...a?{title:a}:{}})});if(!i.ok)throw new Error(`Create chat endpoint returned ${i.status}.`)}async function $e(e,t,a){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,r=await G(e),l=me(e,e.endpoints.updateChat,{chatId:t}),i=await fetch(l,{method:"PATCH",headers:X(e,n,r),body:JSON.stringify(a)});if(!i.ok)throw new Error(`Update chat endpoint returned ${i.status}.`)}async function Ct(e,t){if(!e.endpoints.deleteChat)return;let a=e.getAccessToken?await e.getAccessToken():null,n=await G(e),r=me(e,e.endpoints.deleteChat,{chatId:t}),l=await fetch(r,{method:"DELETE",headers:X(e,a,n)});if(!l.ok)throw new Error(`Delete chat endpoint returned ${l.status}.`)}function V(e,t){let a=xt(t);return e.onError?.(a),a}var He={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'},k={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:He,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0};function Lt(e){if(!e.apiBaseUrl?.trim())throw new Error("Chat widget config requires a non-empty apiBaseUrl.");if(!e.endpoints?.ask?.trim())throw new Error("Chat widget config requires endpoints.ask to be provided.");let t=e.mount??document.body,a=ze(He,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,displayMode:e.displayMode??k.displayMode,position:e.position??k.position,title:e.title??k.title,subtitle:e.subtitle??k.subtitle,welcomeMessage:e.welcomeMessage??k.welcomeMessage,inputPlaceholder:e.inputPlaceholder??k.inputPlaceholder,launcherAriaLabel:e.launcherAriaLabel??k.launcherAriaLabel,closeAriaLabel:e.closeAriaLabel??k.closeAriaLabel,initialSuggestions:e.initialSuggestions??k.initialSuggestions,sourceApp:e.sourceApp??k.sourceApp,locale:e.locale??k.locale,customHeaders:e.customHeaders??k.customHeaders,embedded:{...k.embedded,...e.embedded??{}},rag:{...k.rag,...e.rag??{}},assistantPageUrl:e.assistantPageUrl??k.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 Pt="kp-chat-widget-styles";function At(e,t){if(e.getElementById(Pt))return;let a=document.createElement("style");a.id=Pt,a.textContent=vn(t),e.appendChild(a)}function vn(e){return`
2
2
  :host {
3
3
  all: initial;
4
4
  }
@@ -25,6 +25,15 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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,32 +1429,457 @@
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 gt={en:{openChatActions:"Open chat actions",newChat:"New Chat",myChats:"My Chats",openAssistant:"Open Knowledge Assistant",back:"Back",close:"Close",assistantBadge:"Knowledge Assistant",closeAssistantPage:"Close knowledge assistant page",searchChat:"Search Chat",recentActivity:"Recent Activity",pinnedCollections:"Pinned Collections",answersBasedOnPermissions:"Answers are generated based on your access permissions",authTokenForwarded:"Auth token is forwarded from the host app when configured.",thinking:"Thinking...",unableToCreateChat:"Unable to create chat",requestFailed:"Request failed",noRecentChats:"No recent chats yet.",noPinnedChats:"No pinned chats yet.",noChats:"No chats yet.",loadingChats:"Loading chats...",pinChat:"Pin chat",unpinChat:"Unpin chat",renameChat:"Rename",deleteChat:"Delete",chatActions:"Chat actions",renamePrompt:"Enter a new chat name",citationsAttached:e=>`${e} citation${e>1?"s":""} attached`,sourcesUsed:"Sources Used",allSourcesUsed:"All Sources Used",documentsAndReferences:"AI documents and references",showAll:"Show All",noSources:"No sources were returned for this answer.",closeSourcesPanel:"Close sources panel",openSource:"Open source",sourceScore:"Score",sourcePage:"Page",sourceSheet:"Sheet",sourceRow:"Row",sourceKnowledge:"Knowledge Base",untitledSource:"Untitled Source",copy:"Copy",copied:"Copied",helpful:"Helpful",notHelpful:"Needs work",send:"Send message",assistantAvatar:"Assistant",userAvatar:"User"},ar:{openChatActions:"\u0641\u062A\u062D \u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",newChat:"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629",myChats:"\u0645\u062D\u0627\u062F\u062B\u0627\u062A\u064A",openAssistant:"\u0641\u062A\u062D \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",back:"\u0631\u062C\u0648\u0639",close:"\u0625\u063A\u0644\u0627\u0642",assistantBadge:"\u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",closeAssistantPage:"\u0625\u063A\u0644\u0627\u0642 \u0635\u0641\u062D\u0629 \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",searchChat:"\u0627\u0628\u062D\u062B \u0641\u064A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A",recentActivity:"\u0627\u0644\u0646\u0634\u0627\u0637 \u0627\u0644\u0623\u062E\u064A\u0631",pinnedCollections:"\u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0627\u0644\u0645\u062B\u0628\u062A\u0629",answersBasedOnPermissions:"\u064A\u062A\u0645 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0625\u062C\u0627\u0628\u0627\u062A \u0628\u0646\u0627\u0621\u064B \u0639\u0644\u0649 \u0635\u0644\u0627\u062D\u064A\u0627\u062A \u0627\u0644\u0648\u0635\u0648\u0644 \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0643",authTokenForwarded:"\u064A\u062A\u0645 \u062A\u0645\u0631\u064A\u0631 \u0631\u0645\u0632 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0627\u0644\u062A\u0637\u0628\u064A\u0642 \u0627\u0644\u0645\u0636\u064A\u0641 \u0639\u0646\u062F \u0627\u0644\u0625\u0639\u062F\u0627\u062F.",thinking:"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631...",unableToCreateChat:"\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",requestFailed:"\u0641\u0634\u0644 \u0627\u0644\u0637\u0644\u0628",noRecentChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u062D\u062F\u064A\u062B\u0629 \u0628\u0639\u062F.",noPinnedChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0645\u062B\u0628\u062A\u0629 \u0628\u0639\u062F.",noChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0628\u0639\u062F.",loadingChats:"\u062C\u0627\u0631\u064D \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A...",pinChat:"\u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",unpinChat:"\u0625\u0644\u063A\u0627\u0621 \u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renameChat:"\u0625\u0639\u0627\u062F\u0629 \u062A\u0633\u0645\u064A\u0629",deleteChat:"\u062D\u0630\u0641",chatActions:"\u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renamePrompt:"\u0623\u062F\u062E\u0644 \u0627\u0633\u0645\u064B\u0627 \u062C\u062F\u064A\u062F\u064B\u0627 \u0644\u0644\u0645\u062D\u0627\u062F\u062B\u0629",citationsAttached:e=>`\u062A\u0645 \u0625\u0631\u0641\u0627\u0642 ${e} \u0645\u0631\u062C\u0639${e>1?"\u0627\u062A":""}`,sourcesUsed:"\u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",allSourcesUsed:"\u0643\u0644 \u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",documentsAndReferences:"\u0645\u0633\u062A\u0646\u062F\u0627\u062A \u0648\u0645\u0631\u0627\u062C\u0639 \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A",showAll:"\u0639\u0631\u0636 \u0627\u0644\u0643\u0644",noSources:"\u0644\u0645 \u064A\u062A\u0645 \u0625\u0631\u062C\u0627\u0639 \u0645\u0635\u0627\u062F\u0631 \u0644\u0647\u0630\u0647 \u0627\u0644\u0625\u062C\u0627\u0628\u0629.",closeSourcesPanel:"\u0625\u063A\u0644\u0627\u0642 \u0644\u0648\u062D\u0629 \u0627\u0644\u0645\u0635\u0627\u062F\u0631",openSource:"\u0641\u062A\u062D \u0627\u0644\u0645\u0635\u062F\u0631",sourceScore:"\u0627\u0644\u062F\u0631\u062C\u0629",sourcePage:"\u0627\u0644\u0635\u0641\u062D\u0629",sourceSheet:"\u0627\u0644\u0648\u0631\u0642\u0629",sourceRow:"\u0627\u0644\u0635\u0641",sourceKnowledge:"\u0642\u0627\u0639\u062F\u0629 \u0627\u0644\u0645\u0639\u0631\u0641\u0629",untitledSource:"\u0645\u0635\u062F\u0631 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646",copy:"\u0646\u0633\u062E",copied:"\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",helpful:"\u0645\u0641\u064A\u062F",notHelpful:"\u064A\u062D\u062A\u0627\u062C \u062A\u062D\u0633\u064A\u0646",send:"\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629",assistantAvatar:"\u0627\u0644\u0645\u0633\u0627\u0639\u062F",userAvatar:"\u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645"}};function de(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=ct(e),o=Ae(t.locale),n=pn(t.locale),i=cn(o),s={chatId:ce(t),open:!1,fullPageOpen:!1,myChatsOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1,sourcePanelOpen:!1,sourcePanelTitle:null},d=document.createElement("div");d.dataset.chatWidgetHost="true",t.mount.appendChild(d);let l=d.attachShadow({mode:"open"});ut(l,t.theme);let p=a("div",`kp-chat-widget ${t.position}`);p.lang=o,p.dir=i?"rtl":"ltr",i&&p.classList.add("kp-rtl");let u=a("div","kp-overlay"),g=a("button","kp-launcher");g.type="button",g.setAttribute("aria-label",t.launcherAriaLabel),g.innerHTML=['<span class="kp-star-cluster" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let f=a("section","kp-panel");f.setAttribute("role","dialog"),f.setAttribute("aria-modal","true"),f.setAttribute("aria-label",t.title);let m=a("div","kp-header"),y=a("div","kp-toolbar"),b=a("button","kp-tool-button kp-menu-trigger");b.type="button",b.setAttribute("aria-label",n.openChatActions),b.innerHTML=['<span class="kp-pencil-icon" aria-hidden="true"></span>','<span class="kp-chevron" aria-hidden="true">\u2304</span>'].join("");let x=a("div","kp-dropdown"),v=a("button","kp-dropdown-item",n.newChat);v.type="button";let k=a("button","kp-dropdown-item",n.myChats);k.type="button";let $=a("button","kp-dropdown-item",n.openAssistant);$.type="button",x.append(v,k,$),y.append(b,x);let C=a("div","kp-title-wrap"),Lt=a("h2","kp-title",t.title),At=a("div","kp-subtitle",t.subtitle);C.append(Lt,At);let Q=a("button","kp-close","\xD7");Q.type="button",Q.setAttribute("aria-label",t.closeAriaLabel),m.append(y,C,Q);let Z=a("div","kp-body"),ue=a("div","kp-hero"),Pt=a("div","kp-hero-icon","\u2726"),St=a("div","kp-hero-text",t.welcomeMessage);ue.append(Pt,St);let Pe=a("div","kp-footer"),ge=a("form","kp-form"),S=a("input","kp-input");S.type="text",S.autocomplete="off",S.placeholder=t.inputPlaceholder,S.setAttribute("aria-label",t.inputPlaceholder);let fe=a("button","kp-send","\u279C");fe.type="submit",fe.setAttribute("aria-label",n.send);let Tt=a("div","kp-note",n.authTokenForwarded);ge.append(S,fe),Pe.append(ge,Tt),f.append(m,Z,Pe),p.append(u,g,f),l.appendChild(p),Z.appendChild(ue);let Se=a("div","kp-suggestions");Z.appendChild(Se);let ee=a("section","kp-my-chats-sheet"),Te=a("div","kp-my-chats-header"),te=a("button","kp-my-chats-nav","\u2190");te.type="button",te.setAttribute("aria-label",n.back);let ne=a("button","kp-my-chats-nav kp-my-chats-close","\xD7");ne.type="button",ne.setAttribute("aria-label",n.close),Te.append(te,ne);let Ee=a("div","kp-my-chats-body"),Et=a("div","kp-my-chats-section-label",n.recentActivity),Ie=a("div","kp-my-chats-list"),It=a("div","kp-my-chats-section-label",n.pinnedCollections),Re=a("div","kp-my-chats-list");Ee.append(Et,Ie,It,Re),ee.append(Te,Ee),f.appendChild(ee);let A={body:Z,input:S,suggestions:Se,hero:ue,kind:"panel"},T=a("section","kp-full-page");T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",`${t.title} page`);let $e=a("div","kp-full-page-shell"),He=a("div","kp-full-page-header"),ze=a("div","kp-full-page-brand"),Rt=a("div","kp-full-page-brand-mark","\u2726"),$t=a("div","kp-full-page-brand-text",t.title);ze.append(Rt,$t);let Me=a("div","kp-full-page-header-actions"),Ht=a("div","kp-full-page-badge",n.assistantBadge),oe=a("button","kp-full-page-close","\xD7");oe.type="button",oe.setAttribute("aria-label",n.closeAssistantPage),Me.append(Ht,oe),He.append(ze,Me);let Ne=a("div","kp-full-page-content"),Be=a("aside","kp-full-page-sidebar"),he=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);he.type="button";let Ue=a("div","kp-full-page-search"),V=a("input","kp-full-page-search-input");V.type="search",V.placeholder=n.searchChat;let zt=a("span","kp-full-page-search-icon","\u2315");Ue.append(V,zt);let Mt=a("div","kp-full-page-section-label",n.recentActivity),Oe=a("div","kp-full-page-recent-list"),Nt=a("div","kp-full-page-section-label",n.pinnedCollections),We=a("div","kp-full-page-pinned-list");Be.append(he,Ue,Mt,Oe,Nt,We);let je=a("main","kp-full-page-main"),De=a("section","kp-full-page-panel"),me=a("div","kp-full-page-body"),be=a("div","kp-full-page-hero"),Ve=a("div","kp-full-page-hero-badge");Ve.innerHTML=['<span class="kp-star-cluster kp-star-cluster-static" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let Bt=a("div","kp-full-page-hero-text",t.welcomeMessage);be.append(Ve,Bt);let qe=a("div","kp-suggestions kp-full-page-suggestions");me.append(be,qe);let _e=a("div","kp-full-page-footer"),ke=a("form","kp-form kp-full-page-form"),P=a("input","kp-input kp-full-page-input");P.type="text",P.autocomplete="off",P.placeholder=t.inputPlaceholder,P.setAttribute("aria-label",t.inputPlaceholder);let xe=a("button","kp-send kp-full-page-send","\u279C");xe.type="submit",xe.setAttribute("aria-label",n.send);let Ut=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);ke.append(P,xe),_e.append(ke,Ut),De.append(me,_e),je.appendChild(De);let ae=a("aside","kp-source-panel"),Fe=a("div","kp-source-panel-header"),Ke=a("div","kp-source-panel-title-wrap"),Xe=a("div","kp-source-panel-title",n.allSourcesUsed),Ot=a("div","kp-source-panel-subtitle",n.documentsAndReferences);Ke.append(Xe,Ot);let se=a("button","kp-source-panel-close","\xD7");se.type="button",se.setAttribute("aria-label",n.closeSourcesPanel),Fe.append(Ke,se);let q=a("div","kp-source-panel-list"),Wt=a("div","kp-source-panel-empty",n.noSources);q.appendChild(Wt),ae.append(Fe,q),Ne.append(Be,je,ae),$e.append(He,Ne),T.appendChild($e),p.appendChild(T);let L={body:me,input:P,suggestions:qe,hero:be,kind:"full-page"},H=()=>({...t,getAccessToken:s.accessTokenProvider}),Ye=async()=>{if(!t.getUserContext)return null;try{let r=await t.getUserContext();return r?.displayName?.trim()||r?.email?.trim()||r?.userId?.trim()||null}catch{return null}},_=(r,c)=>{if(s.sourcePanelOpen=!0,s.sourcePanelTitle=c??n.allSourcesUsed,Xe.textContent=s.sourcePanelTitle,ae.classList.add("open"),q.textContent="",r.length===0){q.appendChild(a("div","kp-source-panel-empty",n.noSources));return}for(let h of r)q.appendChild(xn(h,n))},re=()=>{s.sourcePanelOpen=!1,s.sourcePanelTitle=null,ae.classList.remove("open")};j(A,t.initialSuggestions,async r=>{await E(r,A)}),j(L,t.initialSuggestions,async r=>{await E(r,L)}),N(),ie();function Ge(){s.open||(s.open=!0,s.fullPageOpen=!1,I(),T.classList.remove("open"),g.classList.add("hidden"),u.classList.add("visible"),f.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&ye.loadHistory(),queueMicrotask(()=>S.focus()))}function F(){s.open&&(z(),I(),s.open=!1,g.classList.remove("hidden"),u.classList.remove("visible"),f.classList.remove("open"),t.onClose?.())}async function E(r,c){let h=r.trim();if(!h)return;c.input.value="";try{await _t(h)}catch(R){let K=U(t,R);G(c.body,"bot",`${n.unableToCreateChat}: ${K.message}`,{strings:n,view:c,userName:null,onShowSources:_});return}ft(c),G(c.body,"user",h,{strings:n,view:c,userName:await Ye(),onShowSources:_}),c.body.scrollTop=c.body.scrollHeight;let B=a("div","kp-loading",n.thinking);c.body.appendChild(B),c.body.scrollTop=c.body.scrollHeight;try{let R=await st(H(),{message:h,chatId:s.chatId,knowledgeNames:await nn(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});B.isConnected&&B.remove(),G(c.body,"bot",R.answer,{strings:n,view:c,userName:null,citations:R.citations??[],onShowSources:_}),s.historyLoadedChatId=null,await M(),R.suggestions?.length&&j(c,R.suggestions,async K=>{await E(K,c)})}catch(R){let K=U(t,R);B.isConnected&&B.remove(),G(c.body,"bot",`${n.requestFailed}: ${K.message}`,{strings:n,view:c,userName:null,onShowSources:_})}}async function Je(r){let c=s.fullPageOpen?L:A;await E(r,c)}async function jt(){s.fullPageOpen=!0,s.open=!1,z(),I(),f.classList.remove("open"),u.classList.remove("visible"),g.classList.add("hidden"),T.classList.add("open"),await M(),await le(L,s.chatId),queueMicrotask(()=>P.focus())}function Qe(){s.fullPageOpen&&(s.fullPageOpen=!1,T.classList.remove("open"),g.classList.remove("hidden"),re())}function Dt(){s.menuOpen=!0,b.classList.add("open"),x.classList.add("open")}function z(){s.menuOpen=!1,b.classList.remove("open"),x.classList.remove("open")}function Vt(){s.chatId=ce(t),s.historyLoadedChatId=null,I(),Y(A),j(A,t.initialSuggestions,async r=>{await E(r,A)}),z()}async function qt(){s.chatId=ce(t),s.historyLoadedChatId=null,Y(L),re(),j(L,t.initialSuggestions,async r=>{await E(r,L)}),N()}async function M(){if(!t.endpoints.listChats)return N(),ie(),[];s.loadingChats=!0,N(),ie();try{let r=await it(H());return s.chats=r,r}catch(r){return U(t,r),s.chats}finally{s.loadingChats=!1,N(),ie()}}async function _t(r){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(c=>c.chatId===s.chatId)||await lt(H(),s.chatId,r?ln(r,n.newChat):void 0)}async function Ft(r){s.chatId=r,s.historyLoadedChatId=null,await le(L,r),N()}async function Kt(r){s.chatId=r,s.historyLoadedChatId=null,await le(A,r),I()}async function Xt(){z(),await M(),s.myChatsOpen=!0,f.classList.add("kp-sheet-open"),ee.classList.add("open")}function I(){s.myChatsOpen=!1,f.classList.remove("kp-sheet-open"),ee.classList.remove("open")}async function Ze(r){if(!t.endpoints.updateChat)return;let c=window.prompt(n.renamePrompt,r.title)?.trim();if(!(!c||c===r.title))try{await Ce(H(),r.chatId,{title:c}),await M()}catch(h){U(t,h)}}async function et(r){if(t.endpoints.deleteChat)try{await pt(H(),r.chatId),s.chatId===r.chatId&&(s.chatId=ce(t),s.historyLoadedChatId=null,Y(A),Y(L)),await M()}catch(c){U(t,c)}}function N(){ht(Oe,We,s,n,async r=>{await Ft(r.chatId)},async r=>{await tt(r)},async r=>{await Ze(r)},async r=>{await et(r)})}function ie(){ht(Ie,Re,s,n,async r=>{await Kt(r.chatId)},async r=>{await tt(r)},async r=>{await Ze(r)},async r=>{await et(r)})}async function tt(r){if(t.endpoints.updateChat)try{await Ce(H(),r.chatId,{pinned:!r.pinned}),await M()}catch(c){U(t,c)}}async function le(r,c){Y(r),j(r,t.initialSuggestions,async B=>{await E(B,r)});let h=await rt(H(),c);return h.length>0&&(ft(r),bt(r.body,r.hero,r.suggestions),rn(r.body,h,{strings:n,view:r,userName:await Ye(),onShowSources:_})),s.historyLoadedChatId=c,h}let ye={open:Ge,close:F,toggle(){if(s.open){F();return}Ge()},destroy(){document.removeEventListener("keydown",nt),d.remove()},sendMessage:Je,setAccessTokenProvider(r){s.accessTokenProvider=r},getChatId(){return s.chatId},loadChats(){return M()},async loadHistory(){let r=s.fullPageOpen?L:A;return le(r,s.chatId)}};g.addEventListener("click",()=>ye.toggle()),Q.addEventListener("click",F),u.addEventListener("click",F),se.addEventListener("click",re),te.addEventListener("click",I),ne.addEventListener("click",I),b.addEventListener("click",r=>{if(r.stopPropagation(),!s.menuOpen){Dt();return}z()}),v.addEventListener("click",Vt),k.addEventListener("click",async()=>{await Xt()}),$.addEventListener("click",()=>{jt()}),oe.addEventListener("click",Qe),he.addEventListener("click",()=>{qt(),queueMicrotask(()=>P.focus())}),V.addEventListener("input",()=>{s.chatSearchTerm=V.value.trim().toLowerCase(),N()}),f.addEventListener("click",r=>{let c=r.target;if(!(c instanceof Element)||!c.closest(".kp-chat-actions")){for(let h of Array.from(l.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(l.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}s.menuOpen&&!x.contains(c)&&!b.contains(c)&&z(),r.stopPropagation()}),l.addEventListener("click",r=>{let c=r.target;if(s.menuOpen&&c instanceof Node&&!x.contains(c)&&!b.contains(c)&&z(),c instanceof Element&&!c.closest(".kp-chat-actions")){for(let h of Array.from(l.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(l.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}}),ge.addEventListener("submit",async r=>{r.preventDefault(),await Je(S.value)}),ke.addEventListener("submit",async r=>{r.preventDefault(),await E(P.value,L)});function nt(r){if(r.key==="Escape"){if(s.sourcePanelOpen){re();return}if(s.myChatsOpen){I();return}if(s.fullPageOpen){Qe();return}s.open&&F()}}return document.addEventListener("keydown",nt),ye}async function nn(e){if(e.rag.getKnowledgeNames){let t=await e.rag.getKnowledgeNames();return Array.isArray(t)?t.filter(Boolean):[]}return(e.rag.knowledgeNames??[]).filter(Boolean)}function ce(e){return e.rag.chatId?.trim()?e.rag.chatId:e.rag.chatIdFactory?e.rag.chatIdFactory():typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`kp-chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function G(e,t,o,n){let i=t==="bot"?un(o,n.citations??[]):{displayText:o,citations:n.citations??[]},s=a("div",`kp-message-row ${t}`),d=an(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),l=a("div",`kp-bubble ${t}`),p=a("div","kp-bubble-content");vn(p,i.displayText),l.appendChild(p);let u=i.citations;if(u.length){let g=a("div","kp-meta",n.strings.citationsAttached(u.length));l.appendChild(g);let f=a("div","kp-source-preview"),m=a("div","kp-source-preview-title",n.strings.sourcesUsed),y=a("div","kp-source-preview-list");for(let x of u.slice(0,2)){let v=bn(x,n.strings);v.addEventListener("click",async()=>{xt(x,n.strings)}),y.appendChild(v)}let b=kn(n.strings);b.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),y.appendChild(b),f.append(m,y),l.appendChild(f)}return t==="bot"&&l.appendChild(on(i.displayText,n.strings)),t==="user"?s.append(l,d):s.append(d,l),e.appendChild(s),e.scrollTop=e.scrollHeight,s}function on(e,t){let o=a("div","kp-message-actions"),n=a("button","kp-message-action",t.copy);n.type="button",n.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(e),n.textContent=t.copied,window.setTimeout(()=>{n.textContent=t.copy},1200)}catch{n.textContent=t.copy}});let i=a("button","kp-message-action","\u{1F44D}");i.type="button",i.setAttribute("aria-label",t.helpful),i.addEventListener("click",()=>{i.classList.toggle("active"),s.classList.remove("active")});let s=a("button","kp-message-action","\u{1F44E}");return s.type="button",s.setAttribute("aria-label",t.notHelpful),s.addEventListener("click",()=>{s.classList.toggle("active"),i.classList.remove("active")}),o.append(n,i,s),o}function an(e,t){let o=a("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":dn(e);return o.textContent=n,o.setAttribute("aria-hidden","true"),o}function sn(e,t,o){e.textContent="";for(let n of t){let i=a("button","kp-suggestion",n);i.type="button",i.addEventListener("click",async()=>{await o(n)}),e.appendChild(i)}}function j(e,t,o){sn(e.suggestions,t,async n=>{e.input.value=n,await o(n)})}function bt(e,t,o){let n=new Set([t,o]);for(let i of Array.from(e.children))n.has(i)||i.remove()}function ft(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function Y(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),bt(e.body,e.hero,e.suggestions),e.input.value=""}function rn(e,t,o){for(let n of t)G(e,n.role==="assistant"?"bot":"user",n.text,o)}function ht(e,t,o,n,i,s,d,l){if(e.textContent="",t.textContent="",o.loadingChats){e.appendChild(a("div","kp-full-page-empty",n.loadingChats));return}let p=o.chats.filter(u=>o.chatSearchTerm?u.title.toLowerCase().includes(o.chatSearchTerm):!0);if(p.length>0){let u=p.filter(f=>f.pinned),g=p.filter(f=>!f.pinned).slice(0,8);mt(e,g,o.chatId,n,i,s,d,l),mt(t,u,o.chatId,n,i,s,d,l),g.length===0&&e.appendChild(a("div","kp-full-page-empty",n.noRecentChats)),u.length===0&&t.appendChild(a("div","kp-full-page-empty",n.noPinnedChats));return}e.appendChild(a("div","kp-full-page-empty",n.noChats)),t.appendChild(a("div","kp-full-page-empty",n.noPinnedChats))}function mt(e,t,o,n,i,s,d,l){for(let p of t){let u=a("div",`kp-full-page-item kp-full-page-chat-item${p.chatId===o?" active":""}`),g=a("span","kp-full-page-item-title",p.title),f=a("div","kp-chat-actions"),m=a("button","kp-chat-actions-trigger","\u22EF");m.type="button",m.setAttribute("aria-label",n.chatActions);let y=a("div","kp-chat-actions-menu"),b=a("button","kp-chat-actions-item",p.pinned?n.unpinChat:n.pinChat);b.type="button",b.addEventListener("click",async k=>{k.stopPropagation(),await s(p)});let x=a("button","kp-chat-actions-item",n.renameChat);x.type="button",x.addEventListener("click",async k=>{k.stopPropagation(),await d(p)});let v=a("button","kp-chat-actions-item",n.deleteChat);v.type="button",v.addEventListener("click",async k=>{k.stopPropagation(),await l(p)}),y.append(b,x,v),f.append(m,y),m.addEventListener("click",k=>{k.stopPropagation();let $=f.classList.contains("open");for(let C of Array.from(e.querySelectorAll(".kp-chat-actions.open")))C.classList.remove("open");for(let C of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))C.classList.remove("menu-open");$||(f.classList.add("open"),u.classList.add("menu-open"))}),u.append(g,f),u.setAttribute("role","button"),u.tabIndex=0,u.addEventListener("click",async()=>{await i(p)}),u.addEventListener("keydown",async k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),await i(p))}),u.addEventListener("blur",()=>{f.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function ln(e,t){return e.trim().slice(0,60)||t}function Ae(e){return e.toLowerCase().split("-")[0]||"en"}function pn(e){let t=gt.en;return gt[Ae(e)]??t}function cn(e){return["ar","fa","he","ur"].includes(Ae(e))}function dn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(o=>o[0]?.toUpperCase()??"").join("")}function kt(e){return e.knowledgeName?.trim()||e.sourceDocument?.trim()||null}function un(e,t){let o=gn(e);return{displayText:o.displayText,citations:t.length>0?mn(t,o.citations):o.citations}}function gn(e){let o=yt(e).split(`
1377
- `),n=-1;for(let p=0;p<o.length;p+=1)/^#{0,6}\s*References\s*$/i.test(o[p]?.trim()??"")&&(n=p);if(n===-1)return{displayText:e,citations:[]};let i=o.slice(0,n).join(`
1378
- `).trimEnd(),s=o.slice(n+1).join(`
1379
- `).trim(),l=fn(s).map(p=>hn(p)).filter(p=>!!p);return{displayText:i,citations:l}}function fn(e){let t=[],o="";for(let n of e.split(`
1380
- `)){let i=n.trim();if(i){if(/^\d+\.\s+/.test(i)){o&&t.push(o.trim()),o=i.replace(/^\d+\.\s+/,"");continue}o&&(o=`${o} ${i}`)}}return o&&t.push(o.trim()),t}function hn(e){let t=e.match(/https?:\/\/\S+/i);if(!t)return null;let o=t[0],n=e.slice(0,t.index).replace(/[.\s]+$/,"").trim();return{sourceDocument:o,knowledgeName:n||o}}function mn(e,t){let o=[],n=new Set;for(let i of[...e,...t]){let s=`${i.knowledgeName??""}::${i.sourceDocument??""}`;n.has(s)||(n.add(s),o.push(i))}return o}function bn(e,t){let o=a("button","kp-source-chip");o.type="button",o.setAttribute("aria-label",t.openSource);let n=a("span","kp-source-thumb");n.textContent="\u2726";let i=a("span","kp-source-chip-label",kt(e)??t.untitledSource);return o.append(n,i),o}function kn(e){let t=a("button","kp-source-chip kp-source-chip-more");t.type="button";let o=a("span","kp-source-thumb-stack");for(let i=0;i<3;i+=1){let s=a("span","kp-source-thumb stacked");s.textContent="\u2726",o.appendChild(s)}let n=a("span","kp-source-chip-label",e.showAll);return t.append(o,n),t}function xn(e,t){let o=a("button","kp-source-card");o.type="button",o.setAttribute("aria-label",t.openSource),o.addEventListener("click",()=>{xt(e,t)});let n=a("div","kp-source-card-media"),i=a("span","kp-source-thumb kp-source-thumb-large");i.textContent="\u2726";let s=a("div","kp-source-card-title",kt(e)??t.untitledSource),d=a("div","kp-source-card-meta"),l=[];return typeof e.score=="number"&&l.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&l.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&l.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&l.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&l.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),d.textContent=l.join(" \u2022 "),n.appendChild(i),o.append(n,s,d),o}function xt(e,t){let o=e.sourceDocument?.trim()||e.knowledgeName?.trim()||t.untitledSource,n=yn(e.sourceDocument);if(n){window.open(n,"_blank","noopener,noreferrer");return}let i=window.open("","_blank","noopener,noreferrer");if(!i)return;let s=J(o),d=wn(e,t).map(l=>`<li>${J(l)}</li>`).join("");i.document.write(`<!doctype html>
1381
- <html lang="en">
1382
- <head>
1383
- <meta charset="utf-8">
1384
- <title>${s}</title>
1385
- <style>
1386
- body { font-family: Arial, sans-serif; margin: 32px; color: #1f2937; }
1387
- .card { max-width: 720px; padding: 24px; border: 1px solid #dbe4ee; border-radius: 16px; background: #fff; }
1388
- h1 { margin: 0 0 12px; font-size: 24px; }
1389
- p { margin: 0 0 16px; color: #64748b; }
1390
- ul { margin: 0; padding-left: 20px; }
1391
- </style>
1392
- </head>
1393
- <body>
1394
- <div class="card">
1395
- <h1>${s}</h1>
1396
- <p>${J(t.documentsAndReferences)}</p>
1397
- <ul>${d||`<li>${J(t.noSources)}</li>`}</ul>
1432
+
1433
+ /* In-Widget Premium Document Preview Overlay Styles */
1434
+ .kp-citation-overlay {
1435
+ position: fixed;
1436
+ inset: 0;
1437
+ background: #f8fafc;
1438
+ color: #1f2937;
1439
+ display: flex;
1440
+ flex-direction: column;
1441
+ opacity: 0;
1442
+ pointer-events: none;
1443
+ transform: translateY(18px);
1444
+ transition: opacity 260ms ease, transform 320ms ease;
1445
+ z-index: 100000;
1446
+ overflow: hidden;
1447
+ box-sizing: border-box;
1448
+ }
1449
+
1450
+ .kp-chat-widget-embedded .kp-citation-overlay {
1451
+ position: absolute;
1452
+ inset: 0;
1453
+ z-index: 100000;
1454
+ }
1455
+
1456
+ .kp-citation-overlay.open {
1457
+ opacity: 1;
1458
+ pointer-events: auto;
1459
+ transform: translateY(0);
1460
+ }
1461
+
1462
+ .kp-citation-overlay-header {
1463
+ background: #ffffff;
1464
+ border-bottom: 1px solid rgba(226, 232, 240, 0.8);
1465
+ height: 64px;
1466
+ display: flex;
1467
+ align-items: center;
1468
+ padding: 0 24px;
1469
+ justify-content: space-between;
1470
+ flex: none;
1471
+ box-sizing: border-box;
1472
+ }
1473
+
1474
+ .kp-citation-overlay-brand {
1475
+ display: flex;
1476
+ align-items: center;
1477
+ gap: 12px;
1478
+ font-weight: 600;
1479
+ font-size: 16px;
1480
+ color: #0f766e;
1481
+ }
1482
+
1483
+ .kp-citation-overlay-brand-logo {
1484
+ font-size: 20px;
1485
+ }
1486
+
1487
+ .kp-citation-overlay-close {
1488
+ width: 40px;
1489
+ height: 40px;
1490
+ border: none;
1491
+ border-radius: 14px;
1492
+ background: rgba(255, 255, 255, 0.82);
1493
+ color: #61788a;
1494
+ font-size: 24px;
1495
+ line-height: 1;
1496
+ cursor: pointer;
1497
+ box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
1498
+ display: flex;
1499
+ align-items: center;
1500
+ justify-content: center;
1501
+ transition: background 140ms ease;
1502
+ }
1503
+
1504
+ .kp-citation-overlay-close:hover {
1505
+ background: rgba(15, 118, 110, 0.08);
1506
+ }
1507
+
1508
+ .kp-citation-overlay-content {
1509
+ display: grid;
1510
+ grid-template-columns: 380px minmax(0, 1fr);
1511
+ flex: 1;
1512
+ overflow: hidden;
1513
+ align-items: stretch;
1514
+ box-sizing: border-box;
1515
+ }
1516
+
1517
+ .kp-citation-overlay-metadata-panel {
1518
+ background: #ffffff;
1519
+ border-right: 1px solid #e2e8f0;
1520
+ padding: 32px 24px;
1521
+ overflow-y: auto;
1522
+ display: flex;
1523
+ flex-direction: column;
1524
+ gap: 24px;
1525
+ box-sizing: border-box;
1526
+ }
1527
+
1528
+ .kp-citation-overlay-viewer-panel {
1529
+ flex: 1;
1530
+ background: #f1f5f9;
1531
+ display: flex;
1532
+ flex-direction: column;
1533
+ overflow: hidden;
1534
+ box-sizing: border-box;
1535
+ }
1536
+
1537
+ .doc-badge-wrapper {
1538
+ display: flex;
1539
+ align-items: center;
1540
+ gap: 16px;
1541
+ }
1542
+
1543
+ .doc-icon {
1544
+ background: #ecfeff;
1545
+ color: #0f766e;
1546
+ width: 48px;
1547
+ height: 48px;
1548
+ border-radius: 12px;
1549
+ display: flex;
1550
+ align-items: center;
1551
+ justify-content: center;
1552
+ font-size: 20px;
1553
+ font-weight: bold;
1554
+ }
1555
+
1556
+ .doc-badge-info h2 {
1557
+ font-size: 11px;
1558
+ text-transform: uppercase;
1559
+ letter-spacing: 0.05em;
1560
+ color: #64748b;
1561
+ font-weight: 600;
1562
+ margin: 0;
1563
+ }
1564
+
1565
+ .doc-title-section h1 {
1566
+ font-size: 18px;
1567
+ font-weight: 700;
1568
+ line-height: 1.4;
1569
+ color: #0f172a;
1570
+ margin: 8px 0 0;
1571
+ }
1572
+
1573
+ .doc-source-type {
1574
+ font-size: 12px;
1575
+ color: #64748b;
1576
+ margin-top: 4px;
1577
+ }
1578
+
1579
+ .section-divider {
1580
+ height: 1px;
1581
+ background: #e2e8f0;
1582
+ }
1583
+
1584
+ .meta-section-title {
1585
+ font-size: 11px;
1586
+ text-transform: uppercase;
1587
+ letter-spacing: 0.05em;
1588
+ color: #0f766e;
1589
+ font-weight: 600;
1590
+ margin-bottom: 12px;
1591
+ }
1592
+
1593
+ .summary-box {
1594
+ background: #f8fafc;
1595
+ border: 1px solid #e2e8f0;
1596
+ border-radius: 12px;
1597
+ padding: 16px;
1598
+ font-size: 13.5px;
1599
+ line-height: 1.6;
1600
+ color: #374151;
1601
+ white-space: pre-wrap;
1602
+ }
1603
+
1604
+ .meta-list {
1605
+ display: flex;
1606
+ flex-direction: column;
1607
+ gap: 12px;
1608
+ }
1609
+
1610
+ .meta-item {
1611
+ display: flex;
1612
+ justify-content: space-between;
1613
+ font-size: 13px;
1614
+ line-height: 1.5;
1615
+ border-bottom: 1px dashed #f1f5f9;
1616
+ padding-bottom: 8px;
1617
+ }
1618
+
1619
+ .meta-label {
1620
+ color: #64748b;
1621
+ font-weight: 500;
1622
+ }
1623
+
1624
+ .meta-value {
1625
+ color: #1f2937;
1626
+ font-weight: 600;
1627
+ text-align: right;
1628
+ max-width: 200px;
1629
+ word-wrap: break-word;
1630
+ }
1631
+
1632
+ .viewer-toolbar {
1633
+ background: #0f172a;
1634
+ color: #ffffff;
1635
+ height: 48px;
1636
+ display: flex;
1637
+ align-items: center;
1638
+ justify-content: space-between;
1639
+ padding: 0 20px;
1640
+ font-size: 13px;
1641
+ flex: none;
1642
+ box-sizing: border-box;
1643
+ }
1644
+
1645
+ .toolbar-left {
1646
+ font-weight: 500;
1647
+ max-width: 300px;
1648
+ white-space: nowrap;
1649
+ overflow: hidden;
1650
+ text-overflow: ellipsis;
1651
+ }
1652
+
1653
+ .toolbar-center {
1654
+ display: flex;
1655
+ align-items: center;
1656
+ gap: 16px;
1657
+ }
1658
+
1659
+ .page-indicator {
1660
+ background: rgba(255, 255, 255, 0.15);
1661
+ padding: 4px 10px;
1662
+ border-radius: 6px;
1663
+ font-weight: 500;
1664
+ }
1665
+
1666
+ .toolbar-btn {
1667
+ background: transparent;
1668
+ border: none;
1669
+ color: #e2e8f0;
1670
+ cursor: pointer;
1671
+ padding: 4px 12px;
1672
+ border-radius: 6px;
1673
+ font-size: 13px;
1674
+ display: flex;
1675
+ align-items: center;
1676
+ justify-content: center;
1677
+ transition: all 0.2s;
1678
+ font-weight: 500;
1679
+ }
1680
+
1681
+ .toolbar-btn:hover {
1682
+ background: rgba(255, 255, 255, 0.1);
1683
+ color: #ffffff;
1684
+ }
1685
+
1686
+ .toolbar-right {
1687
+ display: flex;
1688
+ align-items: center;
1689
+ gap: 12px;
1690
+ }
1691
+
1692
+ .viewer-body {
1693
+ flex: 1;
1694
+ overflow: auto;
1695
+ padding: 40px;
1696
+ display: flex;
1697
+ justify-content: center;
1698
+ align-items: flex-start;
1699
+ box-sizing: border-box;
1700
+ }
1701
+
1702
+ .document-sheet {
1703
+ background: #ffffff;
1704
+ width: 100%;
1705
+ max-width: 800px;
1706
+ min-height: 1000px;
1707
+ box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
1708
+ border-radius: 4px;
1709
+ padding: 60px 50px;
1710
+ display: flex;
1711
+ flex-direction: column;
1712
+ position: relative;
1713
+ transition: transform 0.2s ease;
1714
+ transform-origin: top center;
1715
+ box-sizing: border-box;
1716
+ }
1717
+
1718
+ .sheet-header {
1719
+ border-bottom: 2px solid #0f766e;
1720
+ padding-bottom: 15px;
1721
+ margin-bottom: 30px;
1722
+ display: flex;
1723
+ justify-content: space-between;
1724
+ align-items: center;
1725
+ font-size: 11px;
1726
+ color: #64748b;
1727
+ text-transform: uppercase;
1728
+ letter-spacing: 0.1em;
1729
+ font-weight: 600;
1730
+ }
1731
+
1732
+ .sheet-content {
1733
+ font-size: 14.5px;
1734
+ line-height: 1.8;
1735
+ color: #27272a;
1736
+ white-space: pre-wrap;
1737
+ flex: 1;
1738
+ font-family: 'Inter', sans-serif;
1739
+ text-align: left;
1740
+ }
1741
+
1742
+ .sheet-footer {
1743
+ border-top: 1px solid #e2e8f0;
1744
+ padding-top: 15px;
1745
+ margin-top: 40px;
1746
+ display: flex;
1747
+ justify-content: space-between;
1748
+ align-items: center;
1749
+ font-size: 11px;
1750
+ color: #64748b;
1751
+ }
1752
+
1753
+ .kp-citation-overlay iframe {
1754
+ width: 100%;
1755
+ height: 100%;
1756
+ border: none;
1757
+ }
1758
+
1759
+ @media (max-width: 860px) {
1760
+ .kp-citation-overlay-content {
1761
+ grid-template-columns: 1fr;
1762
+ overflow-y: auto;
1763
+ }
1764
+
1765
+ .kp-citation-overlay-metadata-panel {
1766
+ border-right: none;
1767
+ border-bottom: 1px solid #e2e8f0;
1768
+ padding: 20px 16px;
1769
+ }
1770
+
1771
+ .viewer-body {
1772
+ padding: 20px;
1773
+ }
1774
+
1775
+ .document-sheet {
1776
+ padding: 30px 20px;
1777
+ min-height: auto;
1778
+ }
1779
+ }
1780
+ `}var St={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 xe(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=Lt(e),a=Me(t.locale),n=Tn(t.locale),r=En(a),l=t.displayMode==="embedded",i={chatId:be(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"});At(c,t.theme);let u=o("div",`kp-chat-widget ${t.position}`);u.lang=a,u.dir=r?"rtl":"ltr",l&&(u.classList.add("kp-chat-widget-embedded"),It(!0)),r&&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 v=o("div","kp-header"),P=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"),x=o("button","kp-dropdown-item",n.newChat);x.type="button";let U=o("button","kp-dropdown-item",n.myChats);U.type="button";let w=o("button","kp-dropdown-item",n.openAssistant);w.type="button",y.append(x,U,w),P.append(b,y);let Oe=o("div","kp-title-wrap"),Ot=o("h2","kp-title",t.title),Ut=o("div","kp-subtitle",t.subtitle);Oe.append(Ot,Ut);let ie=o("button","kp-close","\xD7");ie.type="button",ie.setAttribute("aria-label",t.closeAriaLabel),v.append(P,Oe,ie);let re=o("div","kp-body"),ke=o("div","kp-hero"),Bt=o("div","kp-hero-icon","\u2726"),jt=o("div","kp-hero-text",t.welcomeMessage);ke.append(Bt,jt);let Ue=o("div","kp-footer"),ye=o("form","kp-form"),z=o("input","kp-input");z.type="text",z.autocomplete="off",z.placeholder=t.inputPlaceholder,z.setAttribute("aria-label",t.inputPlaceholder);let ve=o("button","kp-send","\u279C");ve.type="submit",ve.setAttribute("aria-label",n.send);let Wt=o("div","kp-note",n.authTokenForwarded);ye.append(z,ve),Ue.append(ye,Wt),h.append(v,re,Ue),l||u.append(g,f,h),c.appendChild(u),re.appendChild(ke);let Be=o("div","kp-suggestions");re.appendChild(Be);let le=o("section","kp-my-chats-sheet"),je=o("div","kp-my-chats-header"),pe=o("button","kp-my-chats-nav","\u2190");pe.type="button",pe.setAttribute("aria-label",n.back);let ce=o("button","kp-my-chats-nav kp-my-chats-close","\xD7");ce.type="button",ce.setAttribute("aria-label",n.close),je.append(pe,ce);let We=o("div","kp-my-chats-body"),Dt=o("div","kp-my-chats-section-label",n.recentActivity),De=o("div","kp-my-chats-list"),qt=o("div","kp-my-chats-section-label",n.pinnedCollections),qe=o("div","kp-my-chats-list");We.append(Dt,De,qt,qe),le.append(je,We),h.appendChild(le);let E={body:re,input:z,suggestions:Be,hero:ke,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 Ve=o("div","kp-full-page-shell"),we=o("div","kp-full-page-header"),Fe=o("div","kp-full-page-brand"),Vt=o("div","kp-full-page-brand-mark","\u2726"),Ft=o("div","kp-full-page-brand-text",t.title);Fe.append(Vt,Ft);let _e=o("div","kp-full-page-header-actions"),_t=o("div","kp-full-page-badge",n.assistantBadge),de=o("button","kp-full-page-close","\xD7");de.type="button",de.setAttribute("aria-label",n.closeAssistantPage),_e.append(_t,de),we.append(Fe,_e),t.embedded.showHeader||we.classList.add("kp-hidden");let Ke=o("div","kp-full-page-content"),Ye=o("aside","kp-full-page-sidebar"),Ce=o("button","kp-full-page-new-chat",`+ ${n.newChat}`);Ce.type="button";let Xe=o("div","kp-full-page-search"),Z=o("input","kp-full-page-search-input");Z.type="search",Z.placeholder=n.searchChat;let Kt=o("span","kp-full-page-search-icon","\u2315");Xe.append(Z,Kt);let Yt=o("div","kp-full-page-section-label",n.recentActivity),Ge=o("div","kp-full-page-recent-list"),Xt=o("div","kp-full-page-section-label",n.pinnedCollections),Je=o("div","kp-full-page-pinned-list");Ye.append(Ce,Xe,Yt,Ge,Xt,Je);let Qe=o("main","kp-full-page-main"),Ze=o("section","kp-full-page-panel"),Le=o("div","kp-full-page-body"),Pe=o("div","kp-full-page-hero"),et=o("div","kp-full-page-hero-badge");et.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 Gt=o("div","kp-full-page-hero-text",t.welcomeMessage);Pe.append(et,Gt);let tt=o("div","kp-suggestions kp-full-page-suggestions");Le.append(Pe,tt);let nt=o("div","kp-full-page-footer"),Ae=o("form","kp-form kp-full-page-form"),T=o("input","kp-input kp-full-page-input");T.type="text",T.autocomplete="off",T.placeholder=t.inputPlaceholder,T.setAttribute("aria-label",t.inputPlaceholder);let Se=o("button","kp-send kp-full-page-send","\u279C");Se.type="submit",Se.setAttribute("aria-label",n.send);let Jt=o("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Ae.append(T,Se),nt.append(Ae,Jt),Ze.append(Le,nt),Qe.appendChild(Ze);let ue=o("aside","kp-source-panel"),at=o("div","kp-source-panel-header"),ot=o("div","kp-source-panel-title-wrap"),st=o("div","kp-source-panel-title",n.allSourcesUsed),Qt=o("div","kp-source-panel-subtitle",n.documentsAndReferences);ot.append(st,Qt);let ge=o("button","kp-source-panel-close","\xD7");ge.type="button",ge.setAttribute("aria-label",n.closeSourcesPanel),at.append(ot,ge);let ee=o("div","kp-source-panel-list"),Zt=o("div","kp-source-panel-empty",n.noSources);ee.appendChild(Zt),ue.append(at,ee),Ke.append(Ye,Qe,ue),Ve.append(we,Ke),A.appendChild(Ve),u.appendChild(A);let te=o("div","kp-citation-overlay");u.appendChild(te);let C={body:Le,input:T,suggestions:tt,hero:Pe,kind:"full-page"},B=()=>({...t,getAccessToken:i.accessTokenProvider}),it=async()=>{if(!t.getUserContext)return null;try{let s=await t.getUserContext();return s?.displayName?.trim()||s?.email?.trim()||s?.userId?.trim()||null}catch{return null}},F=s=>{let d=Ne(s)??n.untitledSource,m=(s.text||"").trim(),S=m,L=m.split(`
1781
+ `);if(L.length>1&&L[0]){let N=L[0].trim().replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();N&&(N===d||d.indexOf(N)!==-1||N.indexOf(d)!==-1)&&(S=L.slice(1).join(`
1782
+ `).trim())}let I=Bn(s.sourceDocument),D=[];(s.pageNumber||s.pageNumber===0)&&D.push(`
1783
+ <div class="meta-item">
1784
+ <span class="meta-label">Page Number</span>
1785
+ <span class="meta-value">${s.pageNumber}</span>
1786
+ </div>
1787
+ `),typeof s.score=="number"&&D.push(`
1788
+ <div class="meta-item">
1789
+ <span class="meta-label">Relevance Score</span>
1790
+ <span class="meta-value">${s.score.toFixed(2)}</span>
1791
+ </div>
1792
+ `),s.sheetName&&D.push(`
1793
+ <div class="meta-item">
1794
+ <span class="meta-label">Sheet Name</span>
1795
+ <span class="meta-value">${O(s.sheetName)}</span>
1796
+ </div>
1797
+ `),(s.rowNumber||s.rowNumber===0)&&D.push(`
1798
+ <div class="meta-item">
1799
+ <span class="meta-label">Row Number</span>
1800
+ <span class="meta-value">${s.rowNumber}</span>
1801
+ </div>
1802
+ `),s.knowledgeName&&D.push(`
1803
+ <div class="meta-item">
1804
+ <span class="meta-label">Database Source</span>
1805
+ <span class="meta-value">${O(s.knowledgeName)}</span>
1806
+ </div>
1807
+ `),D.push(`
1808
+ <div class="meta-item">
1809
+ <span class="meta-label">Classification</span>
1810
+ <span class="meta-value">Uploaded Knowledge</span>
1811
+ </div>
1812
+ <div class="meta-item">
1813
+ <span class="meta-label">Confidentiality</span>
1814
+ <span class="meta-value" style="color: #0f766e;">Public</span>
1815
+ </div>
1816
+ <div class="meta-item">
1817
+ <span class="meta-label">Language</span>
1818
+ <span class="meta-value">English</span>
1819
+ </div>
1820
+ `);let pn=D.join(""),cn=S?O(S):"No text snippet available for this citation.",dn=`
1821
+ <div class="doc-badge-wrapper">
1822
+ <div class="doc-icon">\u{1F4C4}</div>
1823
+ <div class="doc-badge-info">
1824
+ <h2>Document Citation</h2>
1825
+ </div>
1826
+ </div>
1827
+
1828
+ <div class="doc-title-section">
1829
+ <h1>${O(d)}</h1>
1830
+ <div class="doc-source-type">Uploaded Knowledge Resource</div>
1831
+ </div>
1832
+
1833
+ <div class="section-divider"></div>
1834
+
1835
+ <div>
1836
+ <h3 class="meta-section-title">Retrieved Passage Snippet</h3>
1837
+ <div class="summary-box">${cn}</div>
1838
+ </div>
1839
+
1840
+ <div class="section-divider"></div>
1841
+
1842
+ <div>
1843
+ <h3 class="meta-section-title">Metadata & Classification</h3>
1844
+ <div class="meta-list">
1845
+ ${pn}
1846
+ </div>
1398
1847
  </div>
1399
- </body>
1400
- </html>`),i.document.close()}function yn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function wn(e,t){let o=[];return e.sourceDocument&&o.push(e.sourceDocument),typeof e.score=="number"&&o.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&o.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&o.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&o.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&o.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),o}function vn(e,t){e.innerHTML=Cn(yt(t))}function yt(e){return e.replace(/\r\n/g,`
1848
+ `,Re="";I?Re=`<iframe src="${I}" title="Document Viewer"></iframe>`:Re=`
1849
+ <div class="viewer-toolbar">
1850
+ <div class="toolbar-left">${O(d)}</div>
1851
+ <div class="toolbar-center">
1852
+ <button class="toolbar-btn zoom-out-btn">\u2212</button>
1853
+ <span class="page-indicator">Page ${s.pageNumber||1}</span>
1854
+ <button class="toolbar-btn zoom-in-btn">+</button>
1855
+ </div>
1856
+ <div class="toolbar-right">
1857
+ <button class="toolbar-btn print-btn">\u{1F5A8}\uFE0F Print</button>
1858
+ </div>
1859
+ </div>
1860
+ <div class="viewer-body">
1861
+ <div class="document-sheet">
1862
+ <div class="sheet-header">
1863
+ <span>${O(d)}</span>
1864
+ <span>Page ${s.pageNumber||1}</span>
1865
+ </div>
1866
+ <div class="sheet-content">${O(m||"No document content retrieved.")}</div>
1867
+ <div class="sheet-footer">
1868
+ <span>Confidentiality: Public</span>
1869
+ <span>Knowledge Platform CB</span>
1870
+ </div>
1871
+ </div>
1872
+ </div>
1873
+ `,te.textContent="";let gt=o("header","kp-citation-overlay-header"),ft=o("div","kp-citation-overlay-brand");ft.innerHTML=`
1874
+ <span class="kp-citation-overlay-brand-logo">\u2726</span>
1875
+ <span>Knowledge Assistant Document Viewer</span>
1876
+ `;let he=o("button","kp-citation-overlay-close","\xD7");he.type="button",he.setAttribute("aria-label","Close document preview"),he.addEventListener("click",()=>{te.classList.remove("open")}),gt.append(ft,he);let ht=o("div","kp-citation-overlay-content"),mt=o("aside","kp-citation-overlay-metadata-panel");mt.innerHTML=dn;let Y=o("main","kp-citation-overlay-viewer-panel");if(Y.innerHTML=Re,ht.append(mt,Y),te.append(gt,ht),!I){let q=1,N=Y.querySelector(".document-sheet"),un=Y.querySelector(".zoom-in-btn"),gn=Y.querySelector(".zoom-out-btn"),fn=Y.querySelector(".print-btn");N&&(un?.addEventListener("click",()=>{q<1.5&&(q+=.1,N.style.transform=`scale(${q})`)}),gn?.addEventListener("click",()=>{q>.6&&(q-=.1,N.style.transform=`scale(${q})`)}),fn?.addEventListener("click",()=>{window.print()}))}te.classList.add("open")},ne=(s,d)=>{if(i.sourcePanelOpen=!0,i.sourcePanelTitle=d??n.allSourcesUsed,st.textContent=i.sourcePanelTitle,ue.classList.add("open"),ee.textContent="",s.length===0){ee.appendChild(o("div","kp-source-panel-empty",n.noSources));return}for(let m of s)ee.appendChild(Un(m,n,()=>{F(m)}))},_=()=>{i.sourcePanelOpen=!1,i.sourcePanelTitle=null,ue.classList.remove("open")};J(E,t.initialSuggestions,async s=>{await $(s,E)}),J(C,t.initialSuggestions,async s=>{await $(s,C)}),W(),fe(),l&&(R(),t.rag.loadHistoryOnOpen&&K(C,i.chatId));function Te(){if(l){i.fullPageOpen=!0,A.classList.add("open");return}i.open||(i.open=!0,i.fullPageOpen=!1,M(),A.classList.remove("open"),f.classList.add("hidden"),g.classList.add("visible"),h.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&Ee.loadHistory(),queueMicrotask(()=>z.focus()))}function j(){if(l){_();return}i.open&&(H(),M(),i.open=!1,f.classList.remove("hidden"),g.classList.remove("visible"),h.classList.remove("open"),t.onClose?.())}async function $(s,d){let m=s.trim();if(!m)return;d.input.value="";try{await on(m)}catch(L){let I=V(t,L);se(d.body,"bot",`${n.unableToCreateChat}: ${I.message}`,{strings:n,view:d,userName:null,onShowSources:ne,onShowCitation:F});return}Tt(d),se(d.body,"user",m,{strings:n,view:d,userName:await it(),onShowSources:ne,onShowCitation:F}),d.body.scrollTop=d.body.scrollHeight;let S=o("div","kp-loading",n.thinking);d.body.appendChild(S),d.body.scrollTop=d.body.scrollHeight;try{let L=await kt(B(),{message:m,chatId:i.chatId,knowledgeNames:await wn(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});S.isConnected&&S.remove(),se(d.body,"bot",L.answer,{strings:n,view:d,userName:null,citations:L.citations??[],onShowSources:ne,onShowCitation:F}),i.historyLoadedChatId=null,await R(),L.suggestions?.length&&J(d,L.suggestions,async I=>{await $(I,d)})}catch(L){let I=V(t,L);S.isConnected&&S.remove(),se(d.body,"bot",`${n.requestFailed}: ${I.message}`,{strings:n,view:d,userName:null,onShowSources:ne,onShowCitation:F})}}async function rt(s){let d=i.fullPageOpen?C:E;await $(s,d)}async function en(){if(l){i.fullPageOpen=!0,A.classList.add("open"),await R(),await K(C,i.chatId),queueMicrotask(()=>T.focus());return}i.fullPageOpen=!0,i.open=!1,H(),M(),h.classList.remove("open"),g.classList.remove("visible"),f.classList.add("hidden"),A.classList.add("open"),await R(),await K(C,i.chatId),queueMicrotask(()=>T.focus())}function lt(){if(l){_();return}i.fullPageOpen&&(i.fullPageOpen=!1,A.classList.remove("open"),f.classList.remove("hidden"),_())}function tn(){i.menuOpen=!0,b.classList.add("open"),y.classList.add("open")}function H(){i.menuOpen=!1,b.classList.remove("open"),y.classList.remove("open")}function nn(){i.chatId=be(t),i.historyLoadedChatId=null,M(),oe(E),J(E,t.initialSuggestions,async s=>{await $(s,E)}),H()}async function an(){i.chatId=be(t),i.historyLoadedChatId=null,oe(C),_(),J(C,t.initialSuggestions,async s=>{await $(s,C)}),W()}async function R(){if(!t.endpoints.listChats)return W(),fe(),[];i.loadingChats=!0,W(),fe();try{let s=await vt(B());return i.chats=s,s}catch(s){return V(t,s),i.chats}finally{i.loadingChats=!1,W(),fe()}}async function on(s){!t.endpoints.listChats&&!t.endpoints.createChat||i.chats.some(d=>d.chatId===i.chatId)||await wt(B(),i.chatId,s?Sn(s,n.newChat):void 0)}async function sn(s){i.chatId=s,i.historyLoadedChatId=null,await K(C,s),W()}async function rn(s){i.chatId=s,i.historyLoadedChatId=null,await K(E,s),M()}async function ln(){H(),await R(),i.myChatsOpen=!0,h.classList.add("kp-sheet-open"),le.classList.add("open")}function M(){i.myChatsOpen=!1,h.classList.remove("kp-sheet-open"),le.classList.remove("open")}async function pt(s){if(!t.endpoints.updateChat)return;let d=window.prompt(n.renamePrompt,s.title)?.trim();if(!(!d||d===s.title))try{await $e(B(),s.chatId,{title:d}),await R()}catch(m){V(t,m)}}async function ct(s){if(t.endpoints.deleteChat)try{await Ct(B(),s.chatId),i.chatId===s.chatId&&(i.chatId=be(t),i.historyLoadedChatId=null,oe(E),oe(C)),await R()}catch(d){V(t,d)}}function W(){Et(Ge,Je,i,n,async s=>{await sn(s.chatId)},async s=>{await dt(s)},async s=>{await pt(s)},async s=>{await ct(s)})}function fe(){Et(De,qe,i,n,async s=>{await rn(s.chatId)},async s=>{await dt(s)},async s=>{await pt(s)},async s=>{await ct(s)})}async function dt(s){if(t.endpoints.updateChat)try{await $e(B(),s.chatId,{pinned:!s.pinned}),await R()}catch(d){V(t,d)}}async function K(s,d){oe(s),J(s,t.initialSuggestions,async S=>{await $(S,s)});let m=await yt(B(),d);return m.length>0&&(Tt(s),zt(s.body,s.hero,s.suggestions),An(s.body,m,{strings:n,view:s,userName:await it(),onShowSources:ne,onShowCitation:F})),i.historyLoadedChatId=d,m}let Ee={open:Te,close:j,toggle(){if(l){Te();return}if(i.open){j();return}Te()},destroy(){if(document.removeEventListener("keydown",ut),p.remove(),l){let s=!1;document.querySelectorAll("[data-chat-widget-host]").forEach(d=>{let m=d.shadowRoot;m&&m.querySelector(".kp-chat-widget-embedded")&&(s=!0)}),s||It(!1)}},sendMessage:rt,setAccessTokenProvider(s){i.accessTokenProvider=s},getChatId(){return i.chatId},loadChats(){return R()},async loadHistory(){let s=i.fullPageOpen?C:E;return K(s,i.chatId)}};f.addEventListener("click",()=>Ee.toggle()),ie.addEventListener("click",j),g.addEventListener("click",j),ge.addEventListener("click",_),pe.addEventListener("click",M),ce.addEventListener("click",M),b.addEventListener("click",s=>{if(s.stopPropagation(),!i.menuOpen){tn();return}H()}),x.addEventListener("click",nn),U.addEventListener("click",async()=>{await ln()}),w.addEventListener("click",()=>{if(H(),t.onOpenAssistantPage){j(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){j(),window.location.href=t.assistantPageUrl;return}en()}),de.addEventListener("click",lt),Ce.addEventListener("click",()=>{an(),queueMicrotask(()=>T.focus())}),Z.addEventListener("input",()=>{i.chatSearchTerm=Z.value.trim().toLowerCase(),W()}),h.addEventListener("click",s=>{let d=s.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")}i.menuOpen&&!y.contains(d)&&!b.contains(d)&&H(),s.stopPropagation()}),c.addEventListener("click",s=>{let d=s.target;if(i.menuOpen&&d instanceof Node&&!y.contains(d)&&!b.contains(d)&&H(),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")}}),ye.addEventListener("submit",async s=>{s.preventDefault(),await rt(z.value)}),Ae.addEventListener("submit",async s=>{s.preventDefault(),await $(T.value,C)});function ut(s){if(s.key==="Escape"){if(i.sourcePanelOpen){_();return}if(i.myChatsOpen){M();return}if(i.fullPageOpen){if(l)return;lt();return}i.open&&j()}}return document.addEventListener("keydown",ut),Ee}async function wn(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 be(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 se(e,t,a,n){let r=t==="bot"?In(a,n.citations??[]):{displayText:a,citations:n.citations??[]},l=o("div",`kp-message-row ${t}`),i=Ln(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),p=o("div",`kp-bubble ${t}`),c=o("div","kp-bubble-content");jn(c,r.displayText),p.appendChild(c);let u=r.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),v=o("div","kp-source-preview-list");for(let b of u.slice(0,2)){let y=Nn(b,n.strings);y.addEventListener("click",async()=>{n.onShowCitation(b)}),v.appendChild(y)}let P=On(n.strings);P.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),v.appendChild(P),f.append(h,v),p.appendChild(f)}return t==="bot"&&p.appendChild(Cn(r.displayText,n.strings)),t==="user"?l.append(p,i):l.append(i,p),e.appendChild(l),e.scrollTop=e.scrollHeight,l}function Cn(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 r=o("button","kp-message-action","\u{1F44D}");r.type="button",r.setAttribute("aria-label",t.helpful),r.addEventListener("click",()=>{r.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"),r.classList.remove("active")}),a.append(n,r,l),a}function Ln(e,t){let a=o("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":Rn(e);return a.textContent=n,a.setAttribute("aria-hidden","true"),a}function Pn(e,t,a){e.textContent="";for(let n of t){let r=o("button","kp-suggestion",n);r.type="button",r.addEventListener("click",async()=>{await a(n)}),e.appendChild(r)}}function J(e,t,a){Pn(e.suggestions,t,async n=>{e.input.value=n,await a(n)})}function zt(e,t,a){let n=new Set([t,a]);for(let r of Array.from(e.children))n.has(r)||r.remove()}function Tt(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function oe(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),zt(e.body,e.hero,e.suggestions),e.input.value=""}function An(e,t,a){for(let n of t)se(e,n.role==="assistant"?"bot":"user",n.text,a)}function Et(e,t,a,n,r,l,i,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);Rt(e,g,a.chatId,n,r,l,i,p),Rt(t,u,a.chatId,n,r,l,i,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 Rt(e,t,a,n,r,l,i,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 v=o("div","kp-chat-actions-menu"),P=o("button","kp-chat-actions-item",c.pinned?n.unpinChat:n.pinChat);P.type="button",P.addEventListener("click",async x=>{x.stopPropagation(),await l(c)});let b=o("button","kp-chat-actions-item",n.renameChat);b.type="button",b.addEventListener("click",async x=>{x.stopPropagation(),await i(c)});let y=o("button","kp-chat-actions-item",n.deleteChat);y.type="button",y.addEventListener("click",async x=>{x.stopPropagation(),await p(c)}),v.append(P,b,y),f.append(h,v),h.addEventListener("click",x=>{x.stopPropagation();let U=f.classList.contains("open");for(let w of Array.from(e.querySelectorAll(".kp-chat-actions.open")))w.classList.remove("open");for(let w of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))w.classList.remove("menu-open");U||(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 r(c)}),u.addEventListener("keydown",async x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),await r(c))}),u.addEventListener("blur",()=>{f.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function Sn(e,t){return e.trim().slice(0,60)||t}function Me(e){return e.toLowerCase().split("-")[0]||"en"}function Tn(e){let t=St.en;return St[Me(e)]??t}function En(e){return["ar","fa","he","ur"].includes(Me(e))}function Rn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(a=>a[0]?.toUpperCase()??"").join("")}function Ne(e){if(e.knowledgeName?.trim())return e.knowledgeName.trim();if(e.text){let t=e.text.split(`
1877
+ `)[0]?.trim();if(t){let a=t.replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();if(a)return a}}if(e.sourceDocument&&/^https?:\/\//i.test(e.sourceDocument)){try{let t=new URL(e.sourceDocument),a=decodeURIComponent(t.pathname),n=a.substring(a.lastIndexOf("/")+1);if(n)return n}catch{}return e.sourceDocument}return e.sourceDocument?.trim()&&!/^c\d+$/i.test(e.sourceDocument)?e.sourceDocument.trim():null}function In(e,t){let a=zn(e);return{displayText:a.displayText,citations:t.length>0?Mn(t,a.citations):a.citations}}function zn(e){let a=$t(e).split(`
1878
+ `),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 r=a.slice(0,n).join(`
1879
+ `).trimEnd(),l=a.slice(n+1).join(`
1880
+ `).trim(),p=$n(l).map(c=>Hn(c)).filter(c=>!!c);return{displayText:r,citations:p}}function $n(e){let t=[],a="";for(let n of e.split(`
1881
+ `)){let r=n.trim();if(r){if(/^\d+\.\s+/.test(r)){a&&t.push(a.trim()),a=r.replace(/^\d+\.\s+/,"");continue}a&&(a=`${a} ${r}`)}}return a&&t.push(a.trim()),t}function Hn(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 Mn(e,t){let a=[],n=new Set;for(let r of[...e,...t]){let l=`${r.knowledgeName??""}::${r.sourceDocument??""}`;n.has(l)||(n.add(l),a.push(r))}return a}function Nn(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 r=o("span","kp-source-chip-label",Ne(e)??t.untitledSource);return a.append(n,r),a}function On(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 r=0;r<3;r+=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 Un(e,t,a){let n=o("button","kp-source-card");n.type="button",n.setAttribute("aria-label",t.openSource),n.addEventListener("click",a);let r=o("div","kp-source-card-media"),l=o("span","kp-source-thumb kp-source-thumb-large");l.textContent="\u2726";let i=o("div","kp-source-card-title",Ne(e)??t.untitledSource),p=o("div","kp-source-card-meta"),c=[];return typeof e.score=="number"&&c.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&c.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&c.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&c.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&c.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),p.textContent=c.join(" \u2022 "),r.appendChild(l),n.append(r,i,p),n}function Bn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function jn(e,t){e.innerHTML=Wn($t(t))}function $t(e){return e.replace(/\r\n/g,`
1401
1882
  `).replace(/<br\s*\/?>/gi,`
1402
- `)}function Cn(e){return e.split(/\n{2,}/).map(o=>o.trim()).filter(Boolean).map(Ln).join("")}function Ln(e){let t=e.split(`
1403
- `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return An(t);if(t.every(n=>/^\d+\.\s+/.test(n)))return`<ol>${t.map(n=>`<li>${D(n.replace(/^\d+\.\s+/,""))}</li>`).join("")}</ol>`;if(t.every(n=>/^[-*]\s+/.test(n)))return`<ul>${t.map(n=>`<li>${D(n.replace(/^[-*]\s+/,""))}</li>`).join("")}</ul>`;let o=t[0]?.match(/^(#{1,6})\s+(.*)$/);if(o){let n=o[1]??"#",i=o[2]??"",s=n.length;return`<h${s}>${D(i)}</h${s}>`}return`<p>${t.map(n=>D(n)).join("<br>")}</p>`}function An(e){let t=e.filter((d,l)=>!(l===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(d))).map(d=>Pn(d));if(t.length===0)return"";let o=t[0]??[],n=t.slice(1),i=`<thead><tr>${o.map(d=>`<th>${D(d)}</th>`).join("")}</tr></thead>`,s=n.length?`<tbody>${n.map(d=>`<tr>${d.map(l=>`<td>${D(l)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${i}${s}</table></div>`}function Pn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function D(e){let t=J(e);return t=t.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g,'<a href="$2" target="_blank" rel="noreferrer">$1</a>'),t=t.replace(/`([^`]+)`/g,"<code>$1</code>"),t=t.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*([^*]+)\*/g,"<em>$1</em>"),t}function J(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}var wt="0.1.0",vt=de,Ct={init:vt,createChatWidget:de,version:wt};typeof window<"u"&&(window.ChatWidget=Ct);return en(Sn);})();
1883
+ `)}function Wn(e){return e.split(/\n{2,}/).map(a=>a.trim()).filter(Boolean).map(Dn).join("")}function Dn(e){let t=e.split(`
1884
+ `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return qn(t);if(t.every(n=>/^\d+\.\s+/.test(n)))return`<ol>${t.map(n=>`<li>${Q(n.replace(/^\d+\.\s+/,""))}</li>`).join("")}</ol>`;if(t.every(n=>/^[-*]\s+/.test(n)))return`<ul>${t.map(n=>`<li>${Q(n.replace(/^[-*]\s+/,""))}</li>`).join("")}</ul>`;let a=t[0]?.match(/^(#{1,6})\s+(.*)$/);if(a){let n=a[1]??"#",r=a[2]??"",l=n.length;return`<h${l}>${Q(r)}</h${l}>`}return`<p>${t.map(n=>Q(n)).join("<br>")}</p>`}function qn(e){let t=e.filter((i,p)=>!(p===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(i))).map(i=>Vn(i));if(t.length===0)return"";let a=t[0]??[],n=t.slice(1),r=`<thead><tr>${a.map(i=>`<th>${Q(i)}</th>`).join("")}</tr></thead>`,l=n.length?`<tbody>${n.map(i=>`<tr>${i.map(p=>`<td>${Q(p)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${r}${l}</table></div>`}function Vn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function Q(e){let t=O(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 O(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function It(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 Ht="0.1.0",Mt=xe,Nt={init:Mt,createChatWidget:xe,version:Ht};typeof window<"u"&&(window.ChatWidget=Nt);return yn(Fn);})();
1404
1885
  //# sourceMappingURL=browser.iife.js.map