@nabeh/chat-widget 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as o}from"./chunk-JHMDAOE6.js";var e="0.1.0",t=o,r={init:t,createChatWidget:o,version:e};typeof window<"u"&&(window.ChatWidget=r);export{r as browserGlobal,o as createChatWidget,t as init,e as version};
1
+ import{a as o}from"./chunk-YJTDM6ZC.js";var e="0.1.0",t=o,r={init:t,createChatWidget:o,version:e};typeof window<"u"&&(window.ChatWidget=r);export{r as browserGlobal,o as createChatWidget,t as init,e as version};
2
2
  //# sourceMappingURL=browser.js.map
@@ -1,4 +1,4 @@
1
- function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t){let o={...e};for(let n of Object.keys(t)){let r=t[n],l=o[n];if(ht(l)&&ht(r)){o[n]=Re(l,r);continue}r!==void 0&&(o[n]=r)}return o}function mt(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,o){return{"Content-Type":"application/json",...e.customHeaders,...o?{"X-Chat-User-Context":o}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function J(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function me(e,t,o={}){let n=t.replace(/\{chatId\}/g,encodeURIComponent(o.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(o.chatId??""));return ae(e.apiBaseUrl,n)}async function bt(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await J(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,o,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 xt(e,t){if(!e.endpoints.history)return[];let o=e.getAccessToken?await e.getAccessToken():null,n=await J(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,o,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 kt(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,o=await J(e),n=await fetch(ae(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:X(e,t,o)});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 yt(e,t,o){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let r=e.getAccessToken?await e.getAccessToken():null,l=await J(e),i=await fetch(ae(e.apiBaseUrl,n),{method:"POST",headers:X(e,r,l),body:JSON.stringify({chatId:t,...o?{title:o}:{}})});if(!i.ok)throw new Error(`Create chat endpoint returned ${i.status}.`)}async function Ie(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,r=await J(e),l=me(e,e.endpoints.updateChat,{chatId:t}),i=await fetch(l,{method:"PATCH",headers:X(e,n,r),body:JSON.stringify(o)});if(!i.ok)throw new Error(`Update chat endpoint returned ${i.status}.`)}async function vt(e,t){if(!e.endpoints.deleteChat)return;let o=e.getAccessToken?await e.getAccessToken():null,n=await J(e),r=me(e,e.endpoints.deleteChat,{chatId:t}),l=await fetch(r,{method:"DELETE",headers:X(e,o,n)});if(!l.ok)throw new Error(`Delete chat endpoint returned ${l.status}.`)}function V(e,t){let o=mt(t);return e.onError?.(o),o}var ze={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:ze,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0};function wt(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=Re(ze,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:o,getAccessToken:e.getAccessToken,getUserContext:e.getUserContext,onOpen:e.onOpen,onClose:e.onClose,onError:e.onError,onOpenAssistantPage:e.onOpenAssistantPage}}function a(e,t,o){let n=document.createElement(e);return t&&(n.className=t),o!==void 0&&(n.textContent=o),n}var Ct="kp-chat-widget-styles";function Lt(e,t){if(e.getElementById(Ct))return;let o=document.createElement("style");o.id=Ct,o.textContent=cn(t),e.appendChild(o)}function cn(e){return`
1
+ function St(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function je(e,t){let o={...e};for(let n of Object.keys(t)){let l=t[n],p=o[n];if(St(p)&&St(l)){o[n]=je(p,l);continue}l!==void 0&&(o[n]=l)}return o}function Tt(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function de(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}function X(e,t,o){return{"Content-Type":"application/json",...e.customHeaders,...o?{"X-Chat-User-Context":o}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function D(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function ae(e,t,o={}){let n=t.replace(/\{chatId\}/g,encodeURIComponent(o.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(o.chatId??""));return de(e.apiBaseUrl,n)}async function Et(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await D(e),l=ae(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},r=await fetch(l,{method:"POST",headers:X(e,o,n),body:JSON.stringify(i)});if(!r.ok)throw new Error(`Chat backend returned ${r.status}.`);let c=r.body?.getReader(),u="";if(c)for(;;){let{done:J,value:I}=await c.read();if(J)break;I&&(u+=new TextDecoder("utf-8").decode(I,{stream:!0}))}else u=await r.text();let g;try{g=JSON.parse(u)}catch{return{chatId:t.chatId,answer:u,suggestions:[],citations:[]}}if(!Array.isArray(g)){if(!g.answer||typeof g.answer!="string")throw new Error("Chat backend response is missing a valid answer.");return{chatId:g.chatId??t.chatId,answer:g.answer,suggestions:g.suggestions??[],citations:g.citations??[]}}let h=g[0];if(!h?.answer||typeof h.answer!="string")throw new Error("Chat backend response is missing a valid answer.");let m=h.content,A=m?.source_documents??[],S=m?.scores??[],v=m?.page_numbers??[],L=m?.sheet_names??[],w=m?.row_numbers??[],F=m?.knowledge_names??[],R=A.map((J,I)=>({sourceDocument:J,score:S[I]??null,pageNumber:v[I]??null,sheetName:L[I]??null,rowNumber:w[I]??null,knowledgeName:F[I]??null}));return{chatId:t.chatId,answer:h.answer,suggestions:[],citations:R}}async function It(e,t){if(!e.endpoints.history)return[];let o=e.getAccessToken?await e.getAccessToken():null,n=await D(e),p=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?ae(e,e.endpoints.history,{chatId:t}):(()=>{let u=new URL(de(e.apiBaseUrl,e.endpoints.history));return u.searchParams.set("chat_id",t),u.toString()})(),i=await fetch(p,{method:"GET",headers:X(e,o,n)});if(!i.ok)throw new Error(`Chat history endpoint returned ${i.status}.`);let r=await i.json(),c=Array.isArray(r)?r:r&&typeof r=="object"?r.history??r.messages??r.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 h=g.role??g.type??g.sender??g.author,m=g.text??g.message??g.content??g.answer;if(typeof m!="string")return null;let A=typeof h=="string"?h.toLowerCase():"assistant";return[{role:A==="user"||A==="human"?"user":"assistant",text:m,...Array.isArray(g.citations)?{citations:g.citations}:{},...typeof g.isLike=="boolean"?{isLike:g.isLike}:{}}]}).flat().filter(u=>!!u):[]}async function Rt(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,o=await D(e),n=await fetch(de(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:X(e,t,o)});if(!n.ok)throw new Error(`Chat list endpoint returned ${n.status}.`);let l=await n.json(),p=Array.isArray(l)?l:l&&typeof l=="object"?l.chats??l.data??l.items??[]:[];return Array.isArray(p)?p.map(i=>{if(!i||typeof i!="object")return null;let r=i,c=r.chatId??r.chat_id??r.id,u=r.title??r.name??r.chatId;if(typeof c!="string"||typeof u!="string")return null;let g=typeof r.createdAt=="string"?r.createdAt:typeof r.created_at=="string"?r.created_at:null,h=typeof r.updatedAt=="string"?r.updatedAt:typeof r.updated_at=="string"?r.updated_at:null,m={chatId:c,title:u,pinned:typeof r.pinned=="boolean"?r.pinned:!1};return g&&(m.createdAt=g),h&&(m.updatedAt=h),m}).filter(i=>!!i):[]}async function $t(e,t,o){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let l=e.getAccessToken?await e.getAccessToken():null,p=await D(e),i=await fetch(de(e.apiBaseUrl,n),{method:"POST",headers:X(e,l,p),body:JSON.stringify({chatId:t,...o?{title:o}:{}})});if(!i.ok)throw new Error(`Create chat endpoint returned ${i.status}.`)}async function We(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,l=await D(e),p=ae(e,e.endpoints.updateChat,{chatId:t}),i=await fetch(p,{method:"PATCH",headers:X(e,n,l),body:JSON.stringify(o)});if(!i.ok)throw new Error(`Update chat endpoint returned ${i.status}.`)}async function zt(e,t){if(!e.endpoints.deleteChat)return;let o=e.getAccessToken?await e.getAccessToken():null,n=await D(e),l=ae(e,e.endpoints.deleteChat,{chatId:t}),p=await fetch(l,{method:"DELETE",headers:X(e,o,n)});if(!p.ok)throw new Error(`Delete chat endpoint returned ${p.status}.`)}function j(e,t){let o=Tt(t);return e.onError?.(o),o}async function ce(e,t,o,n){if(!e.endpoints.feedback)return;let l=e.getAccessToken?await e.getAccessToken():null,p=await D(e),i=ae(e,e.endpoints.feedback,{chatId:t}),r=await fetch(i,{method:"POST",headers:X(e,l,p),body:JSON.stringify({message:o,isLike:n})});if(!r.ok)throw new Error(`Feedback endpoint returned ${r.status}.`)}async function Ht(e,t){if(!e.endpoints.upload)throw new Error("Upload endpoint is not configured.");let o=e.getAccessToken?await e.getAccessToken():null,n=await D(e),l=ae(e,e.endpoints.upload),p=new FormData;p.append("file",t);let i={...e.customHeaders,...n?{"X-Chat-User-Context":n}:{},...o?{Authorization:`Bearer ${o}`}:{}},r=await fetch(l,{method:"POST",headers:i,body:p});if(!r.ok){let c=`Upload endpoint returned ${r.status}.`;try{let u=await r.json();u.message?c=`Failed to upload: ${u.message}`:u.error&&(c=`Failed to upload: ${u.error}`)}catch{}throw new Error(c)}return r.json()}var Fe={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'},C={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:Fe,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0};function Mt(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=je(Fe,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,displayMode:e.displayMode??C.displayMode,position:e.position??C.position,title:e.title??C.title,subtitle:e.subtitle??C.subtitle,welcomeMessage:e.welcomeMessage??C.welcomeMessage,inputPlaceholder:e.inputPlaceholder??C.inputPlaceholder,launcherAriaLabel:e.launcherAriaLabel??C.launcherAriaLabel,closeAriaLabel:e.closeAriaLabel??C.closeAriaLabel,initialSuggestions:e.initialSuggestions??C.initialSuggestions,sourceApp:e.sourceApp??C.sourceApp,locale:e.locale??C.locale,customHeaders:e.customHeaders??C.customHeaders,embedded:{...C.embedded,...e.embedded??{}},rag:{...C.rag,...e.rag??{}},assistantPageUrl:e.assistantPageUrl??C.assistantPageUrl,theme:o,getAccessToken:e.getAccessToken,getUserContext:e.getUserContext,onOpen:e.onOpen,onClose:e.onClose,onError:e.onError,onOpenAssistantPage:e.onOpenAssistantPage}}function a(e,t,o){let n=document.createElement(e);return t&&(n.className=t),o!==void 0&&(n.textContent=o),n}var Nt="kp-chat-widget-styles";function Ot(e,t){if(e.getElementById(Nt))return;let o=document.createElement("style");o.id=Nt,o.textContent=yn(t),e.appendChild(o)}function yn(e){return`
2
2
  :host {
3
3
  all: initial;
4
4
  }
@@ -191,7 +191,8 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
191
191
  transform-origin: bottom left;
192
192
  }
193
193
 
194
- .kp-panel.open {
194
+ .kp-chat-widget .kp-panel.open,
195
+ .kp-chat-widget.bottom-left .kp-panel.open {
195
196
  opacity: 1;
196
197
  transform: translateX(0) scale(1);
197
198
  pointer-events: auto;
@@ -1276,11 +1277,45 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
1276
1277
  justify-content: center;
1277
1278
  flex: none;
1278
1279
  }
1279
-
1280
1280
  .kp-rtl .kp-send {
1281
- transform: scaleX(-1);
1281
+ transform: none; /* remove mirroring for RTL, keep button orientation */
1282
+ }
1283
+
1284
+ .kp-attach {
1285
+ width: 40px;
1286
+ height: 40px;
1287
+ border: none;
1288
+ border-radius: 999px;
1289
+ background: transparent;
1290
+ color: var(--kp-accent);
1291
+ cursor: pointer;
1292
+ font-size: 20px;
1293
+ line-height: 1;
1294
+ display: flex;
1295
+ align-items: center;
1296
+ justify-content: center;
1297
+ flex: none;
1298
+ transition: background 140ms ease;
1282
1299
  }
1283
1300
 
1301
+ .kp-attach:hover {
1302
+ background: rgba(15, 118, 110, 0.08);
1303
+ }
1304
+
1305
+ .kp-attachment-badge {
1306
+ display: inline-flex;
1307
+ align-items: center;
1308
+ padding: 4px 10px;
1309
+ margin-bottom: 8px;
1310
+ border-radius: 12px;
1311
+ background: rgba(228, 241, 248, 0.8);
1312
+ color: var(--kp-accent);
1313
+ font-size: 12px;
1314
+ font-weight: 500;
1315
+ border: 1px solid rgba(15, 118, 110, 0.2);
1316
+ }
1317
+
1318
+
1284
1319
  .kp-note {
1285
1320
  margin-top: 8px;
1286
1321
  text-align: center;
@@ -1312,13 +1347,19 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
1312
1347
  }
1313
1348
 
1314
1349
  @media (max-width: 860px) {
1315
- .kp-full-page-content,
1350
+ .kp-full-page-content {
1351
+ grid-template-columns: 1fr;
1352
+ grid-template-rows: auto 1fr;
1353
+ }
1354
+
1316
1355
  .kp-full-page-content:has(.kp-source-panel.open) {
1317
1356
  grid-template-columns: 1fr;
1357
+ grid-template-rows: auto 1fr auto;
1318
1358
  }
1319
1359
 
1320
1360
  .kp-full-page-sidebar {
1321
- max-height: 260px;
1361
+ flex: none;
1362
+ max-height: 140px;
1322
1363
  }
1323
1364
 
1324
1365
  .kp-full-page-embedded .kp-full-page-sidebar {
@@ -1777,34 +1818,34 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
1777
1818
  min-height: auto;
1778
1819
  }
1779
1820
  }
1780
- `}var Pt={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 Kn(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=wt(e),o=$e(t.locale),n=bn(t.locale),r=xn(o),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"});Lt(c,t.theme);let u=a("div",`kp-chat-widget ${t.position}`);u.lang=o,u.dir=r?"rtl":"ltr",l&&(u.classList.add("kp-chat-widget-embedded"),Et(!0)),r&&u.classList.add("kp-rtl");let g=a("div","kp-overlay"),f=a("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=a("section","kp-panel");h.setAttribute("role","dialog"),h.setAttribute("aria-modal","true"),h.setAttribute("aria-label",t.title);let v=a("div","kp-header"),P=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 y=a("div","kp-dropdown"),x=a("button","kp-dropdown-item",n.newChat);x.type="button";let U=a("button","kp-dropdown-item",n.myChats);U.type="button";let w=a("button","kp-dropdown-item",n.openAssistant);w.type="button",y.append(x,U,w),P.append(b,y);let Me=a("div","kp-title-wrap"),zt=a("h2","kp-title",t.title),$t=a("div","kp-subtitle",t.subtitle);Me.append(zt,$t);let ie=a("button","kp-close","\xD7");ie.type="button",ie.setAttribute("aria-label",t.closeAriaLabel),v.append(P,Me,ie);let re=a("div","kp-body"),xe=a("div","kp-hero"),Ht=a("div","kp-hero-icon","\u2726"),Mt=a("div","kp-hero-text",t.welcomeMessage);xe.append(Ht,Mt);let Ne=a("div","kp-footer"),ke=a("form","kp-form"),z=a("input","kp-input");z.type="text",z.autocomplete="off",z.placeholder=t.inputPlaceholder,z.setAttribute("aria-label",t.inputPlaceholder);let ye=a("button","kp-send","\u279C");ye.type="submit",ye.setAttribute("aria-label",n.send);let Nt=a("div","kp-note",n.authTokenForwarded);ke.append(z,ye),Ne.append(ke,Nt),h.append(v,re,Ne),l||u.append(g,f,h),c.appendChild(u),re.appendChild(xe);let Oe=a("div","kp-suggestions");re.appendChild(Oe);let le=a("section","kp-my-chats-sheet"),Ue=a("div","kp-my-chats-header"),pe=a("button","kp-my-chats-nav","\u2190");pe.type="button",pe.setAttribute("aria-label",n.back);let ce=a("button","kp-my-chats-nav kp-my-chats-close","\xD7");ce.type="button",ce.setAttribute("aria-label",n.close),Ue.append(pe,ce);let Be=a("div","kp-my-chats-body"),Ot=a("div","kp-my-chats-section-label",n.recentActivity),je=a("div","kp-my-chats-list"),Ut=a("div","kp-my-chats-section-label",n.pinnedCollections),De=a("div","kp-my-chats-list");Be.append(Ot,je,Ut,De),le.append(Ue,Be),h.appendChild(le);let E={body:re,input:z,suggestions:Oe,hero:xe,kind:"panel"},A=a("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 We=a("div","kp-full-page-shell"),ve=a("div","kp-full-page-header"),qe=a("div","kp-full-page-brand"),Bt=a("div","kp-full-page-brand-mark","\u2726"),jt=a("div","kp-full-page-brand-text",t.title);qe.append(Bt,jt);let Ve=a("div","kp-full-page-header-actions"),Dt=a("div","kp-full-page-badge",n.assistantBadge),de=a("button","kp-full-page-close","\xD7");de.type="button",de.setAttribute("aria-label",n.closeAssistantPage),Ve.append(Dt,de),ve.append(qe,Ve),t.embedded.showHeader||ve.classList.add("kp-hidden");let Fe=a("div","kp-full-page-content"),_e=a("aside","kp-full-page-sidebar"),we=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);we.type="button";let Ke=a("div","kp-full-page-search"),Z=a("input","kp-full-page-search-input");Z.type="search",Z.placeholder=n.searchChat;let Wt=a("span","kp-full-page-search-icon","\u2315");Ke.append(Z,Wt);let qt=a("div","kp-full-page-section-label",n.recentActivity),Ye=a("div","kp-full-page-recent-list"),Vt=a("div","kp-full-page-section-label",n.pinnedCollections),Xe=a("div","kp-full-page-pinned-list");_e.append(we,Ke,qt,Ye,Vt,Xe);let Je=a("main","kp-full-page-main"),Qe=a("section","kp-full-page-panel"),Ce=a("div","kp-full-page-body"),Le=a("div","kp-full-page-hero"),Ge=a("div","kp-full-page-hero-badge");Ge.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 Ft=a("div","kp-full-page-hero-text",t.welcomeMessage);Le.append(Ge,Ft);let Ze=a("div","kp-suggestions kp-full-page-suggestions");Ce.append(Le,Ze);let et=a("div","kp-full-page-footer"),Pe=a("form","kp-form kp-full-page-form"),T=a("input","kp-input kp-full-page-input");T.type="text",T.autocomplete="off",T.placeholder=t.inputPlaceholder,T.setAttribute("aria-label",t.inputPlaceholder);let Ae=a("button","kp-send kp-full-page-send","\u279C");Ae.type="submit",Ae.setAttribute("aria-label",n.send);let _t=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Pe.append(T,Ae),et.append(Pe,_t),Qe.append(Ce,et),Je.appendChild(Qe);let ue=a("aside","kp-source-panel"),tt=a("div","kp-source-panel-header"),nt=a("div","kp-source-panel-title-wrap"),at=a("div","kp-source-panel-title",n.allSourcesUsed),Kt=a("div","kp-source-panel-subtitle",n.documentsAndReferences);nt.append(at,Kt);let ge=a("button","kp-source-panel-close","\xD7");ge.type="button",ge.setAttribute("aria-label",n.closeSourcesPanel),tt.append(nt,ge);let ee=a("div","kp-source-panel-list"),Yt=a("div","kp-source-panel-empty",n.noSources);ee.appendChild(Yt),ue.append(tt,ee),Fe.append(_e,Je,ue),We.append(ve,Fe),A.appendChild(We),u.appendChild(A);let te=a("div","kp-citation-overlay");u.appendChild(te);let C={body:Ce,input:T,suggestions:Ze,hero:Le,kind:"full-page"},B=()=>({...t,getAccessToken:i.accessTokenProvider}),ot=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=He(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=Tn(s.sourceDocument),W=[];(s.pageNumber||s.pageNumber===0)&&W.push(`
1821
+ `}var Ut={en:{openChatActions:"Open chat actions",newChat:"New Chat",myChats:"My Chats",openAssistant:"Open Knowledge Assistant",back:"Back",close:"Close",assistantBadge:"Knowledge Assistant",closeAssistantPage:"Close knowledge assistant page",searchChat:"Search Chat",recentActivity:"Recent Activity",pinnedCollections:"Pinned Collections",answersBasedOnPermissions:"Answers are generated based on your access permissions",authTokenForwarded:"Auth token is forwarded from the host app when configured.",thinking:"Thinking...",unableToCreateChat:"Unable to create chat",requestFailed:"Request failed",noRecentChats:"No recent chats yet.",noPinnedChats:"No pinned chats yet.",noChats:"No chats yet.",loadingChats:"Loading chats...",pinChat:"Pin chat",unpinChat:"Unpin chat",renameChat:"Rename",deleteChat:"Delete",chatActions:"Chat actions",renamePrompt:"Enter a new chat name",citationsAttached:e=>`${e} citation${e>1?"s":""} attached`,sourcesUsed:"Sources Used",allSourcesUsed:"All Sources Used",documentsAndReferences:"AI documents and references",showAll:"Show All",noSources:"No sources were returned for this answer.",closeSourcesPanel:"Close sources panel",openSource:"Open source",sourceScore:"Score",sourcePage:"Page",sourceSheet:"Sheet",sourceRow:"Row",sourceKnowledge:"Knowledge Base",untitledSource:"Untitled Source",copy:"Copy",copied:"Copied",helpful:"Helpful",notHelpful:"Needs work",send:"Send message",assistantAvatar:"Assistant",userAvatar:"User"},ar:{openChatActions:"\u0641\u062A\u062D \u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",newChat:"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629",myChats:"\u0645\u062D\u0627\u062F\u062B\u0627\u062A\u064A",openAssistant:"\u0641\u062A\u062D \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",back:"\u0631\u062C\u0648\u0639",close:"\u0625\u063A\u0644\u0627\u0642",assistantBadge:"\u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",closeAssistantPage:"\u0625\u063A\u0644\u0627\u0642 \u0635\u0641\u062D\u0629 \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",searchChat:"\u0627\u0628\u062D\u062B \u0641\u064A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A",recentActivity:"\u0627\u0644\u0646\u0634\u0627\u0637 \u0627\u0644\u0623\u062E\u064A\u0631",pinnedCollections:"\u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0627\u0644\u0645\u062B\u0628\u062A\u0629",answersBasedOnPermissions:"\u064A\u062A\u0645 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0625\u062C\u0627\u0628\u0627\u062A \u0628\u0646\u0627\u0621\u064B \u0639\u0644\u0649 \u0635\u0644\u0627\u062D\u064A\u0627\u062A \u0627\u0644\u0648\u0635\u0648\u0644 \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0643",authTokenForwarded:"\u064A\u062A\u0645 \u062A\u0645\u0631\u064A\u0631 \u0631\u0645\u0632 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0627\u0644\u062A\u0637\u0628\u064A\u0642 \u0627\u0644\u0645\u0636\u064A\u0641 \u0639\u0646\u062F \u0627\u0644\u0625\u0639\u062F\u0627\u062F.",thinking:"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631...",unableToCreateChat:"\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",requestFailed:"\u0641\u0634\u0644 \u0627\u0644\u0637\u0644\u0628",noRecentChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u062D\u062F\u064A\u062B\u0629 \u0628\u0639\u062F.",noPinnedChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0645\u062B\u0628\u062A\u0629 \u0628\u0639\u062F.",noChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0628\u0639\u062F.",loadingChats:"\u062C\u0627\u0631\u064D \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A...",pinChat:"\u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",unpinChat:"\u0625\u0644\u063A\u0627\u0621 \u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renameChat:"\u0625\u0639\u0627\u062F\u0629 \u062A\u0633\u0645\u064A\u0629",deleteChat:"\u062D\u0630\u0641",chatActions:"\u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renamePrompt:"\u0623\u062F\u062E\u0644 \u0627\u0633\u0645\u064B\u0627 \u062C\u062F\u064A\u062F\u064B\u0627 \u0644\u0644\u0645\u062D\u0627\u062F\u062B\u0629",citationsAttached:e=>`\u062A\u0645 \u0625\u0631\u0641\u0627\u0642 ${e} \u0645\u0631\u062C\u0639${e>1?"\u0627\u062A":""}`,sourcesUsed:"\u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",allSourcesUsed:"\u0643\u0644 \u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",documentsAndReferences:"\u0645\u0633\u062A\u0646\u062F\u0627\u062A \u0648\u0645\u0631\u0627\u062C\u0639 \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A",showAll:"\u0639\u0631\u0636 \u0627\u0644\u0643\u0644",noSources:"\u0644\u0645 \u064A\u062A\u0645 \u0625\u0631\u062C\u0627\u0639 \u0645\u0635\u0627\u062F\u0631 \u0644\u0647\u0630\u0647 \u0627\u0644\u0625\u062C\u0627\u0628\u0629.",closeSourcesPanel:"\u0625\u063A\u0644\u0627\u0642 \u0644\u0648\u062D\u0629 \u0627\u0644\u0645\u0635\u0627\u062F\u0631",openSource:"\u0641\u062A\u062D \u0627\u0644\u0645\u0635\u062F\u0631",sourceScore:"\u0627\u0644\u062F\u0631\u062C\u0629",sourcePage:"\u0627\u0644\u0635\u0641\u062D\u0629",sourceSheet:"\u0627\u0644\u0648\u0631\u0642\u0629",sourceRow:"\u0627\u0644\u0635\u0641",sourceKnowledge:"\u0642\u0627\u0639\u062F\u0629 \u0627\u0644\u0645\u0639\u0631\u0641\u0629",untitledSource:"\u0645\u0635\u062F\u0631 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646",copy:"\u0646\u0633\u062E",copied:"\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",helpful:"\u0645\u0641\u064A\u062F",notHelpful:"\u064A\u062D\u062A\u0627\u062C \u062A\u062D\u0633\u064A\u0646",send:"\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629",assistantAvatar:"\u0627\u0644\u0645\u0633\u0627\u0639\u062F",userAvatar:"\u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645"}};function aa(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=Mt(e),o=Ve(t.locale),n=Sn(t.locale),l=Tn(o),p=t.displayMode==="embedded",i={chatId:Pe(t),open:!1,fullPageOpen:p,myChatsOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1,sourcePanelOpen:!1,sourcePanelTitle:null,attachedFile:null},r=document.createElement("div");r.dataset.chatWidgetHost="true",t.mount.appendChild(r);let c=r.attachShadow({mode:"open"});Ot(c,t.theme);let u=a("div",`kp-chat-widget ${t.position}`);u.lang=o,u.dir=l?"rtl":"ltr",p&&(u.classList.add("kp-chat-widget-embedded"),jt(!0)),l&&u.classList.add("kp-rtl");let g=a("div","kp-overlay"),h=a("button","kp-launcher");h.type="button",h.setAttribute("aria-label",t.launcherAriaLabel),h.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 m=a("section","kp-panel");m.setAttribute("role","dialog"),m.setAttribute("aria-modal","true"),m.setAttribute("aria-label",t.title);let A=a("div","kp-header"),S=a("div","kp-toolbar"),v=a("button","kp-tool-button kp-menu-trigger");v.type="button",v.setAttribute("aria-label",n.openChatActions),v.innerHTML=['<span class="kp-pencil-icon" aria-hidden="true"></span>','<span class="kp-chevron" aria-hidden="true">\u2304</span>'].join("");let L=a("div","kp-dropdown"),w=a("button","kp-dropdown-item",n.newChat);w.type="button";let F=a("button","kp-dropdown-item",n.myChats);F.type="button";let R=a("button","kp-dropdown-item",n.openAssistant);R.type="button",L.append(w,F,R),S.append(v,L);let J=a("div","kp-title-wrap"),I=a("h2","kp-title",t.title),qt=a("div","kp-subtitle",t.subtitle);J.append(I,qt);let fe=a("button","kp-close","\xD7");fe.type="button",fe.setAttribute("aria-label",t.closeAriaLabel),A.append(S,J,fe);let he=a("div","kp-body"),Se=a("div","kp-hero"),Vt=a("div","kp-hero-icon","\u2726"),_t=a("div","kp-hero-text",t.welcomeMessage);Se.append(Vt,_t);let Ke=a("div","kp-footer"),Te=a("form","kp-form"),$=a("input","kp-input");$.type="text",$.autocomplete="off",$.placeholder=t.inputPlaceholder,$.setAttribute("aria-label",t.inputPlaceholder);let me=a("button","kp-attach","\u{1F4CE}");me.type="button",me.setAttribute("aria-label","Attach file");let q=a("input","kp-file-input");q.type="file",q.style.display="none";let Ee=a("div","kp-attachment-badge");Ee.style.display="none";let Ie=a("button","kp-send","\u279C");Ie.type="submit",Ie.setAttribute("aria-label",n.send);let Kt=a("div","kp-note",n.authTokenForwarded);Te.append(me,q,$,Ie),Ke.append(Ee,Te,Kt),m.append(A,he,Ke),p||u.append(g,h,m),c.appendChild(u),he.appendChild(Se);let Ye=a("div","kp-suggestions");he.appendChild(Ye);let be=a("section","kp-my-chats-sheet"),Xe=a("div","kp-my-chats-header"),ke=a("button","kp-my-chats-nav","\u2190");ke.type="button",ke.setAttribute("aria-label",n.back);let xe=a("button","kp-my-chats-nav kp-my-chats-close","\xD7");xe.type="button",xe.setAttribute("aria-label",n.close),Xe.append(ke,xe);let Je=a("div","kp-my-chats-body"),Yt=a("div","kp-my-chats-section-label",n.recentActivity),Qe=a("div","kp-my-chats-list"),Xt=a("div","kp-my-chats-section-label",n.pinnedCollections),Ge=a("div","kp-my-chats-list");Je.append(Yt,Qe,Xt,Ge),be.append(Xe,Je),m.appendChild(be);let z={body:he,input:$,suggestions:Ye,hero:Se,kind:"panel"},T=a("section","kp-full-page");p&&T.classList.add("kp-full-page-embedded","open"),T.setAttribute("role","dialog"),p||T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",`${t.title} page`);let Ze=a("div","kp-full-page-shell"),Re=a("div","kp-full-page-header"),et=a("div","kp-full-page-brand"),Jt=a("div","kp-full-page-brand-mark","\u2726"),Qt=a("div","kp-full-page-brand-text",t.title);et.append(Jt,Qt);let tt=a("div","kp-full-page-header-actions"),Gt=a("div","kp-full-page-badge",n.assistantBadge),ye=a("button","kp-full-page-close","\xD7");ye.type="button",ye.setAttribute("aria-label",n.closeAssistantPage),tt.append(Gt,ye),Re.append(et,tt),t.embedded.showHeader||Re.classList.add("kp-hidden");let nt=a("div","kp-full-page-content"),at=a("aside","kp-full-page-sidebar"),$e=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);$e.type="button";let ot=a("div","kp-full-page-search"),ie=a("input","kp-full-page-search-input");ie.type="search",ie.placeholder=n.searchChat;let Zt=a("span","kp-full-page-search-icon","\u2315");ot.append(ie,Zt);let en=a("div","kp-full-page-section-label",n.recentActivity),st=a("div","kp-full-page-recent-list"),tn=a("div","kp-full-page-section-label",n.pinnedCollections),it=a("div","kp-full-page-pinned-list");at.append($e,ot,en,st,tn,it);let rt=a("main","kp-full-page-main"),lt=a("section","kp-full-page-panel"),ze=a("div","kp-full-page-body"),He=a("div","kp-full-page-hero"),pt=a("div","kp-full-page-hero-badge");pt.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 nn=a("div","kp-full-page-hero-text",t.welcomeMessage);He.append(pt,nn);let dt=a("div","kp-suggestions kp-full-page-suggestions");ze.append(He,dt);let ct=a("div","kp-full-page-footer"),Me=a("form","kp-form kp-full-page-form"),E=a("input","kp-input kp-full-page-input");E.type="text",E.autocomplete="off",E.placeholder=t.inputPlaceholder,E.setAttribute("aria-label",t.inputPlaceholder);let ve=a("button","kp-attach kp-full-page-attach","\u{1F4CE}");ve.type="button",ve.setAttribute("aria-label","Attach file");let V=a("input","kp-file-input");V.type="file",V.style.display="none";let Ne=a("div","kp-attachment-badge kp-full-page-attachment-badge");Ne.style.display="none";let Oe=a("button","kp-send kp-full-page-send","\u279C");Oe.type="submit",Oe.setAttribute("aria-label",n.send);let an=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Me.append(ve,V,E,Oe),ct.append(Ne,Me,an),lt.append(ze,ct),rt.appendChild(lt);let we=a("aside","kp-source-panel"),ut=a("div","kp-source-panel-header"),gt=a("div","kp-source-panel-title-wrap"),ft=a("div","kp-source-panel-title",n.allSourcesUsed),on=a("div","kp-source-panel-subtitle",n.documentsAndReferences);gt.append(ft,on);let Ce=a("button","kp-source-panel-close","\xD7");Ce.type="button",Ce.setAttribute("aria-label",n.closeSourcesPanel),ut.append(gt,Ce);let re=a("div","kp-source-panel-list"),sn=a("div","kp-source-panel-empty",n.noSources);re.appendChild(sn),we.append(ut,re),nt.append(at,rt,we),Ze.append(Re,nt),T.appendChild(Ze),u.appendChild(T);let le=a("div","kp-citation-overlay");u.appendChild(le);let P={body:ze,input:E,suggestions:dt,hero:He,kind:"full-page"},M=()=>({...t,getAccessToken:i.accessTokenProvider}),ht=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}},Q=s=>{let d=_e(s)??n.untitledSource,f=(s.text||"").trim(),k=f,b=f.split(`
1822
+ `);if(b.length>1&&b[0]){let B=b[0].trim().replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();B&&(B===d||d.indexOf(B)!==-1||B.indexOf(d)!==-1)&&(k=b.slice(1).join(`
1823
+ `).trim())}let x=Un(s.sourceDocument),y=[];(s.pageNumber||s.pageNumber===0)&&y.push(`
1783
1824
  <div class="meta-item">
1784
1825
  <span class="meta-label">Page Number</span>
1785
1826
  <span class="meta-value">${s.pageNumber}</span>
1786
1827
  </div>
1787
- `),typeof s.score=="number"&&W.push(`
1828
+ `),typeof s.score=="number"&&y.push(`
1788
1829
  <div class="meta-item">
1789
1830
  <span class="meta-label">Relevance Score</span>
1790
1831
  <span class="meta-value">${s.score.toFixed(2)}</span>
1791
1832
  </div>
1792
- `),s.sheetName&&W.push(`
1833
+ `),s.sheetName&&y.push(`
1793
1834
  <div class="meta-item">
1794
1835
  <span class="meta-label">Sheet Name</span>
1795
- <span class="meta-value">${O(s.sheetName)}</span>
1836
+ <span class="meta-value">${W(s.sheetName)}</span>
1796
1837
  </div>
1797
- `),(s.rowNumber||s.rowNumber===0)&&W.push(`
1838
+ `),(s.rowNumber||s.rowNumber===0)&&y.push(`
1798
1839
  <div class="meta-item">
1799
1840
  <span class="meta-label">Row Number</span>
1800
1841
  <span class="meta-value">${s.rowNumber}</span>
1801
1842
  </div>
1802
- `),s.knowledgeName&&W.push(`
1843
+ `),s.knowledgeName&&y.push(`
1803
1844
  <div class="meta-item">
1804
1845
  <span class="meta-label">Database Source</span>
1805
- <span class="meta-value">${O(s.knowledgeName)}</span>
1846
+ <span class="meta-value">${W(s.knowledgeName)}</span>
1806
1847
  </div>
1807
- `),W.push(`
1848
+ `),y.push(`
1808
1849
  <div class="meta-item">
1809
1850
  <span class="meta-label">Classification</span>
1810
1851
  <span class="meta-value">Uploaded Knowledge</span>
@@ -1817,7 +1858,7 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
1817
1858
  <span class="meta-label">Language</span>
1818
1859
  <span class="meta-value">English</span>
1819
1860
  </div>
1820
- `);let an=W.join(""),on=S?O(S):"No text snippet available for this citation.",sn=`
1861
+ `);let ee=y.join(""),te=k?W(k):"No text snippet available for this citation.",mn=`
1821
1862
  <div class="doc-badge-wrapper">
1822
1863
  <div class="doc-icon">\u{1F4C4}</div>
1823
1864
  <div class="doc-badge-info">
@@ -1826,7 +1867,7 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
1826
1867
  </div>
1827
1868
 
1828
1869
  <div class="doc-title-section">
1829
- <h1>${O(d)}</h1>
1870
+ <h1>${W(d)}</h1>
1830
1871
  <div class="doc-source-type">Uploaded Knowledge Resource</div>
1831
1872
  </div>
1832
1873
 
@@ -1834,7 +1875,7 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
1834
1875
 
1835
1876
  <div>
1836
1877
  <h3 class="meta-section-title">Retrieved Passage Snippet</h3>
1837
- <div class="summary-box">${on}</div>
1878
+ <div class="summary-box">${te}</div>
1838
1879
  </div>
1839
1880
 
1840
1881
  <div class="section-divider"></div>
@@ -1842,12 +1883,12 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
1842
1883
  <div>
1843
1884
  <h3 class="meta-section-title">Metadata & Classification</h3>
1844
1885
  <div class="meta-list">
1845
- ${an}
1886
+ ${ee}
1846
1887
  </div>
1847
1888
  </div>
1848
- `,Ee="";I?Ee=`<iframe src="${I}" title="Document Viewer"></iframe>`:Ee=`
1889
+ `,De="";x?De=`<iframe src="${x}" title="Document Viewer"></iframe>`:De=`
1849
1890
  <div class="viewer-toolbar">
1850
- <div class="toolbar-left">${O(d)}</div>
1891
+ <div class="toolbar-left">${W(d)}</div>
1851
1892
  <div class="toolbar-center">
1852
1893
  <button class="toolbar-btn zoom-out-btn">\u2212</button>
1853
1894
  <span class="page-indicator">Page ${s.pageNumber||1}</span>
@@ -1860,26 +1901,25 @@ function ht(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Re(e,t)
1860
1901
  <div class="viewer-body">
1861
1902
  <div class="document-sheet">
1862
1903
  <div class="sheet-header">
1863
- <span>${O(d)}</span>
1904
+ <span>${W(d)}</span>
1864
1905
  <span>Page ${s.pageNumber||1}</span>
1865
1906
  </div>
1866
- <div class="sheet-content">${O(m||"No document content retrieved.")}</div>
1907
+ <div class="sheet-content">${W(f||"No document content retrieved.")}</div>
1867
1908
  <div class="sheet-footer">
1868
1909
  <span>Confidentiality: Public</span>
1869
1910
  <span>Knowledge Platform CB</span>
1870
1911
  </div>
1871
1912
  </div>
1872
1913
  </div>
1873
- `,te.textContent="";let dt=a("header","kp-citation-overlay-header"),ut=a("div","kp-citation-overlay-brand");ut.innerHTML=`
1914
+ `,le.textContent="";let Ct=a("header","kp-citation-overlay-header"),Lt=a("div","kp-citation-overlay-brand");Lt.innerHTML=`
1874
1915
  <span class="kp-citation-overlay-brand-logo">\u2726</span>
1875
1916
  <span>Knowledge Assistant Document Viewer</span>
1876
- `;let he=a("button","kp-citation-overlay-close","\xD7");he.type="button",he.setAttribute("aria-label","Close document preview"),he.addEventListener("click",()=>{te.classList.remove("open")}),dt.append(ut,he);let gt=a("div","kp-citation-overlay-content"),ft=a("aside","kp-citation-overlay-metadata-panel");ft.innerHTML=sn;let Y=a("main","kp-citation-overlay-viewer-panel");if(Y.innerHTML=Ee,gt.append(ft,Y),te.append(dt,gt),!I){let q=1,N=Y.querySelector(".document-sheet"),rn=Y.querySelector(".zoom-in-btn"),ln=Y.querySelector(".zoom-out-btn"),pn=Y.querySelector(".print-btn");N&&(rn?.addEventListener("click",()=>{q<1.5&&(q+=.1,N.style.transform=`scale(${q})`)}),ln?.addEventListener("click",()=>{q>.6&&(q-=.1,N.style.transform=`scale(${q})`)}),pn?.addEventListener("click",()=>{window.print()}))}te.classList.add("open")},ne=(s,d)=>{if(i.sourcePanelOpen=!0,i.sourcePanelTitle=d??n.allSourcesUsed,at.textContent=i.sourcePanelTitle,ue.classList.add("open"),ee.textContent="",s.length===0){ee.appendChild(a("div","kp-source-panel-empty",n.noSources));return}for(let m of s)ee.appendChild(Sn(m,n,()=>{F(m)}))},_=()=>{i.sourcePanelOpen=!1,i.sourcePanelTitle=null,ue.classList.remove("open")};Q(E,t.initialSuggestions,async s=>{await $(s,E)}),Q(C,t.initialSuggestions,async s=>{await $(s,C)}),D(),fe(),l&&(R(),t.rag.loadHistoryOnOpen&&K(C,i.chatId));function Se(){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&&Te.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 Zt(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}At(d),se(d.body,"user",m,{strings:n,view:d,userName:await ot(),onShowSources:ne,onShowCitation:F}),d.body.scrollTop=d.body.scrollHeight;let S=a("div","kp-loading",n.thinking);d.body.appendChild(S),d.body.scrollTop=d.body.scrollHeight;try{let L=await bt(B(),{message:m,chatId:i.chatId,knowledgeNames:await dn(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&&Q(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 st(s){let d=i.fullPageOpen?C:E;await $(s,d)}async function Xt(){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 it(){if(l){_();return}i.fullPageOpen&&(i.fullPageOpen=!1,A.classList.remove("open"),f.classList.remove("hidden"),_())}function Jt(){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 Qt(){i.chatId=be(t),i.historyLoadedChatId=null,M(),oe(E),Q(E,t.initialSuggestions,async s=>{await $(s,E)}),H()}async function Gt(){i.chatId=be(t),i.historyLoadedChatId=null,oe(C),_(),Q(C,t.initialSuggestions,async s=>{await $(s,C)}),D()}async function R(){if(!t.endpoints.listChats)return D(),fe(),[];i.loadingChats=!0,D(),fe();try{let s=await kt(B());return i.chats=s,s}catch(s){return V(t,s),i.chats}finally{i.loadingChats=!1,D(),fe()}}async function Zt(s){!t.endpoints.listChats&&!t.endpoints.createChat||i.chats.some(d=>d.chatId===i.chatId)||await yt(B(),i.chatId,s?mn(s,n.newChat):void 0)}async function en(s){i.chatId=s,i.historyLoadedChatId=null,await K(C,s),D()}async function tn(s){i.chatId=s,i.historyLoadedChatId=null,await K(E,s),M()}async function nn(){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 rt(s){if(!t.endpoints.updateChat)return;let d=window.prompt(n.renamePrompt,s.title)?.trim();if(!(!d||d===s.title))try{await Ie(B(),s.chatId,{title:d}),await R()}catch(m){V(t,m)}}async function lt(s){if(t.endpoints.deleteChat)try{await vt(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 D(){St(Ye,Xe,i,n,async s=>{await en(s.chatId)},async s=>{await pt(s)},async s=>{await rt(s)},async s=>{await lt(s)})}function fe(){St(je,De,i,n,async s=>{await tn(s.chatId)},async s=>{await pt(s)},async s=>{await rt(s)},async s=>{await lt(s)})}async function pt(s){if(t.endpoints.updateChat)try{await Ie(B(),s.chatId,{pinned:!s.pinned}),await R()}catch(d){V(t,d)}}async function K(s,d){oe(s),Q(s,t.initialSuggestions,async S=>{await $(S,s)});let m=await xt(B(),d);return m.length>0&&(At(s),Rt(s.body,s.hero,s.suggestions),hn(s.body,m,{strings:n,view:s,userName:await ot(),onShowSources:ne,onShowCitation:F})),i.historyLoadedChatId=d,m}let Te={open:Se,close:j,toggle(){if(l){Se();return}if(i.open){j();return}Se()},destroy(){if(document.removeEventListener("keydown",ct),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||Et(!1)}},sendMessage:st,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",()=>Te.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){Jt();return}H()}),x.addEventListener("click",Qt),U.addEventListener("click",async()=>{await nn()}),w.addEventListener("click",()=>{if(H(),t.onOpenAssistantPage){j(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){j(),window.location.href=t.assistantPageUrl;return}Xt()}),de.addEventListener("click",it),we.addEventListener("click",()=>{Gt(),queueMicrotask(()=>T.focus())}),Z.addEventListener("input",()=>{i.chatSearchTerm=Z.value.trim().toLowerCase(),D()}),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")}}),ke.addEventListener("submit",async s=>{s.preventDefault(),await st(z.value)}),Pe.addEventListener("submit",async s=>{s.preventDefault(),await $(T.value,C)});function ct(s){if(s.key==="Escape"){if(i.sourcePanelOpen){_();return}if(i.myChatsOpen){M();return}if(i.fullPageOpen){if(l)return;it();return}i.open&&j()}}return document.addEventListener("keydown",ct),Te}async function dn(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,o,n){let r=t==="bot"?yn(o,n.citations??[]):{displayText:o,citations:n.citations??[]},l=a("div",`kp-message-row ${t}`),i=gn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),p=a("div",`kp-bubble ${t}`),c=a("div","kp-bubble-content");En(c,r.displayText),p.appendChild(c);let u=r.citations;if(u.length){let g=a("div","kp-meta",n.strings.citationsAttached(u.length));p.appendChild(g);let f=a("div","kp-source-preview"),h=a("div","kp-source-preview-title",n.strings.sourcesUsed),v=a("div","kp-source-preview-list");for(let b of u.slice(0,2)){let y=Pn(b,n.strings);y.addEventListener("click",async()=>{n.onShowCitation(b)}),v.appendChild(y)}let P=An(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(un(r.displayText,n.strings)),t==="user"?l.append(p,i):l.append(i,p),e.appendChild(l),e.scrollTop=e.scrollHeight,l}function un(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 r=a("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=a("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")}),o.append(n,r,l),o}function gn(e,t){let o=a("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":kn(e);return o.textContent=n,o.setAttribute("aria-hidden","true"),o}function fn(e,t,o){e.textContent="";for(let n of t){let r=a("button","kp-suggestion",n);r.type="button",r.addEventListener("click",async()=>{await o(n)}),e.appendChild(r)}}function Q(e,t,o){fn(e.suggestions,t,async n=>{e.input.value=n,await o(n)})}function Rt(e,t,o){let n=new Set([t,o]);for(let r of Array.from(e.children))n.has(r)||r.remove()}function At(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),Rt(e.body,e.hero,e.suggestions),e.input.value=""}function hn(e,t,o){for(let n of t)se(e,n.role==="assistant"?"bot":"user",n.text,o)}function St(e,t,o,n,r,l,i,p){if(e.textContent="",t.textContent="",o.loadingChats){e.appendChild(a("div","kp-full-page-empty",n.loadingChats));return}let c=o.chats.filter(u=>o.chatSearchTerm?u.title.toLowerCase().includes(o.chatSearchTerm):!0);if(c.length>0){let u=c.filter(f=>f.pinned),g=c.filter(f=>!f.pinned).slice(0,8);Tt(e,g,o.chatId,n,r,l,i,p),Tt(t,u,o.chatId,n,r,l,i,p),g.length===0&&e.appendChild(a("div","kp-full-page-empty",n.noRecentChats)),u.length===0&&t.appendChild(a("div","kp-full-page-empty",n.noPinnedChats));return}e.appendChild(a("div","kp-full-page-empty",n.noChats)),t.appendChild(a("div","kp-full-page-empty",n.noPinnedChats))}function Tt(e,t,o,n,r,l,i,p){for(let c of t){let u=a("div",`kp-full-page-item kp-full-page-chat-item${c.chatId===o?" active":""}`),g=a("span","kp-full-page-item-title",c.title),f=a("div","kp-chat-actions"),h=a("button","kp-chat-actions-trigger","\u22EF");h.type="button",h.setAttribute("aria-label",n.chatActions);let v=a("div","kp-chat-actions-menu"),P=a("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=a("button","kp-chat-actions-item",n.renameChat);b.type="button",b.addEventListener("click",async x=>{x.stopPropagation(),await i(c)});let y=a("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 mn(e,t){return e.trim().slice(0,60)||t}function $e(e){return e.toLowerCase().split("-")[0]||"en"}function bn(e){let t=Pt.en;return Pt[$e(e)]??t}function xn(e){return["ar","fa","he","ur"].includes($e(e))}function kn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(o=>o[0]?.toUpperCase()??"").join("")}function He(e){if(e.knowledgeName?.trim())return e.knowledgeName.trim();if(e.text){let t=e.text.split(`
1877
- `)[0]?.trim();if(t){let o=t.replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();if(o)return o}}if(e.sourceDocument&&/^https?:\/\//i.test(e.sourceDocument)){try{let t=new URL(e.sourceDocument),o=decodeURIComponent(t.pathname),n=o.substring(o.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 yn(e,t){let o=vn(e);return{displayText:o.displayText,citations:t.length>0?Ln(t,o.citations):o.citations}}function vn(e){let o=It(e).split(`
1878
- `),n=-1;for(let c=0;c<o.length;c+=1)/^#{0,6}\s*References\s*$/i.test(o[c]?.trim()??"")&&(n=c);if(n===-1)return{displayText:e,citations:[]};let r=o.slice(0,n).join(`
1879
- `).trimEnd(),l=o.slice(n+1).join(`
1880
- `).trim(),p=wn(l).map(c=>Cn(c)).filter(c=>!!c);return{displayText:r,citations:p}}function wn(e){let t=[],o="";for(let n of e.split(`
1881
- `)){let r=n.trim();if(r){if(/^\d+\.\s+/.test(r)){o&&t.push(o.trim()),o=r.replace(/^\d+\.\s+/,"");continue}o&&(o=`${o} ${r}`)}}return o&&t.push(o.trim()),t}function Cn(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 Ln(e,t){let o=[],n=new Set;for(let r of[...e,...t]){let l=`${r.knowledgeName??""}::${r.sourceDocument??""}`;n.has(l)||(n.add(l),o.push(r))}return o}function Pn(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 r=a("span","kp-source-chip-label",He(e)??t.untitledSource);return o.append(n,r),o}function An(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 r=0;r<3;r+=1){let l=a("span","kp-source-thumb stacked");l.textContent="\u2726",o.appendChild(l)}let n=a("span","kp-source-chip-label",e.showAll);return t.append(o,n),t}function Sn(e,t,o){let n=a("button","kp-source-card");n.type="button",n.setAttribute("aria-label",t.openSource),n.addEventListener("click",o);let r=a("div","kp-source-card-media"),l=a("span","kp-source-thumb kp-source-thumb-large");l.textContent="\u2726";let i=a("div","kp-source-card-title",He(e)??t.untitledSource),p=a("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 Tn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function En(e,t){e.innerHTML=Rn(It(t))}function It(e){return e.replace(/\r\n/g,`
1882
- `).replace(/<br\s*\/?>/gi,`
1883
- `)}function Rn(e){return e.split(/\n{2,}/).map(o=>o.trim()).filter(Boolean).map(In).join("")}function In(e){let t=e.split(`
1884
- `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return zn(t);if(t.every(n=>/^\d+\.\s+/.test(n)))return`<ol>${t.map(n=>`<li>${G(n.replace(/^\d+\.\s+/,""))}</li>`).join("")}</ol>`;if(t.every(n=>/^[-*]\s+/.test(n)))return`<ul>${t.map(n=>`<li>${G(n.replace(/^[-*]\s+/,""))}</li>`).join("")}</ul>`;let o=t[0]?.match(/^(#{1,6})\s+(.*)$/);if(o){let n=o[1]??"#",r=o[2]??"",l=n.length;return`<h${l}>${G(r)}</h${l}>`}return`<p>${t.map(n=>G(n)).join("<br>")}</p>`}function zn(e){let t=e.filter((i,p)=>!(p===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(i))).map(i=>$n(i));if(t.length===0)return"";let o=t[0]??[],n=t.slice(1),r=`<thead><tr>${o.map(i=>`<th>${G(i)}</th>`).join("")}</tr></thead>`,l=n.length?`<tbody>${n.map(i=>`<tr>${i.map(p=>`<td>${G(p)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${r}${l}</table></div>`}function $n(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function G(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 Et(e){typeof document>"u"||document.querySelectorAll("[data-chat-widget-host]").forEach(t=>{let o=t.shadowRoot;if(o){let n=o.querySelector(".kp-chat-widget");n&&!n.classList.contains("kp-chat-widget-embedded")&&(t.style.display=e?"none":"")}})}export{Kn as a};
1885
- //# sourceMappingURL=chunk-JHMDAOE6.js.map
1917
+ `;let Ae=a("button","kp-citation-overlay-close","\xD7");Ae.type="button",Ae.setAttribute("aria-label","Close document preview"),Ae.addEventListener("click",()=>{le.classList.remove("open")}),Ct.append(Lt,Ae);let At=a("div","kp-citation-overlay-content"),Pt=a("aside","kp-citation-overlay-metadata-panel");Pt.innerHTML=mn;let ne=a("main","kp-citation-overlay-viewer-panel");if(ne.innerHTML=De,At.append(Pt,ne),le.append(Ct,At),!x){let Y=1,B=ne.querySelector(".document-sheet"),bn=ne.querySelector(".zoom-in-btn"),kn=ne.querySelector(".zoom-out-btn"),xn=ne.querySelector(".print-btn");B&&(bn?.addEventListener("click",()=>{Y<1.5&&(Y+=.1,B.style.transform=`scale(${Y})`)}),kn?.addEventListener("click",()=>{Y>.6&&(Y-=.1,B.style.transform=`scale(${Y})`)}),xn?.addEventListener("click",()=>{window.print()}))}le.classList.add("open")},pe=(s,d)=>{if(i.sourcePanelOpen=!0,i.sourcePanelTitle=d??n.allSourcesUsed,ft.textContent=i.sourcePanelTitle,we.classList.add("open"),re.textContent="",s.length===0){re.appendChild(a("div","kp-source-panel-empty",n.noSources));return}for(let f of s)re.appendChild(On(f,n,()=>{Q(f)}))},G=()=>{i.sourcePanelOpen=!1,i.sourcePanelTitle=null,we.classList.remove("open")};oe(z,t.initialSuggestions,async s=>{await N(s,z)}),oe(P,t.initialSuggestions,async s=>{await N(s,P)}),K(),Le(),p&&(H(),t.rag.loadHistoryOnOpen&&Z(P,i.chatId));function mt(s,d,f){d.textContent=`Uploading ${s.name}...`,d.style.display="block",f.disabled=!0,Ht(M(),s).then(k=>{i.attachedFile={name:s.name,sourceUuid:k.source_uuid},d.textContent=`\u{1F4CE} ${s.name} (Attached)`}).catch(k=>{let b=j(t,k);d.textContent=`Failed to upload: ${b.message}`,setTimeout(()=>{d.style.display="none",d.textContent=""},3e3)}).finally(()=>{f.disabled=!1,q.value="",V.value=""})}me.addEventListener("click",()=>{q.click()}),q.addEventListener("change",()=>{let s=q.files?.[0];s&&mt(s,Ee,$)}),ve.addEventListener("click",()=>{V.click()}),V.addEventListener("change",()=>{let s=V.files?.[0];s&&mt(s,Ne,E)});function Ue(){if(p){i.fullPageOpen=!0,T.classList.add("open");return}i.open||(i.open=!0,i.fullPageOpen=!1,U(),T.classList.remove("open"),h.classList.add("hidden"),g.classList.add("visible"),m.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&Be.loadHistory(),queueMicrotask(()=>$.focus()))}function _(){if(p){G();return}i.open&&(O(),U(),i.open=!1,h.classList.remove("hidden"),g.classList.remove("visible"),m.classList.remove("open"),t.onClose?.())}async function N(s,d){let f=s.trim();if(!f)return;d.input.value="";try{await cn(f)}catch(b){let x=j(t,b);ge(d.body,"bot",`${n.unableToCreateChat}: ${x.message}`,{strings:n,view:d,userName:null,onShowSources:pe,onShowCitation:Q,onLike:()=>{},onDislike:()=>{}});return}qe(d),ge(d.body,"user",f,{strings:n,view:d,userName:await ht(),onShowSources:pe,onShowCitation:Q,onLike:()=>{},onDislike:()=>{}}),d.body.scrollTop=d.body.scrollHeight;let k=a("div","kp-loading",n.thinking);d.body.appendChild(k),d.body.scrollTop=d.body.scrollHeight;try{let b=await vn(t),x=i.attachedFile?[i.attachedFile.sourceUuid,...b]:b,y=await Et(M(),{message:f,chatId:i.chatId,knowledgeNames:x,...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});k.isConnected&&k.remove(),ge(d.body,"bot",y.answer,{strings:n,view:d,userName:null,citations:y.citations??[],onShowSources:pe,onShowCitation:Q,onLike:()=>{ce(t,i.chatId,y.answer,!0).catch(console.error)},onDislike:()=>{ce(t,i.chatId,y.answer,!1).catch(console.error)}}),i.historyLoadedChatId=null,await H(),y.suggestions?.length&&oe(d,y.suggestions,async ee=>{await N(ee,d)})}catch(b){let x=j(t,b);k.isConnected&&k.remove(),ge(d.body,"bot",`${n.requestFailed}: ${x.message}`,{strings:n,view:d,userName:null,onShowSources:pe,onShowCitation:Q,onLike:()=>{},onDislike:()=>{}})}}async function bt(s){let d=i.fullPageOpen?P:z;await N(s,d)}async function rn(){if(p){i.fullPageOpen=!0,T.classList.add("open"),await H(),await Z(P,i.chatId),queueMicrotask(()=>E.focus());return}i.fullPageOpen=!0,i.open=!1,O(),U(),m.classList.remove("open"),g.classList.remove("visible"),h.classList.add("hidden"),T.classList.add("open"),await H(),await Z(P,i.chatId),queueMicrotask(()=>E.focus())}function kt(){if(p){G();return}i.fullPageOpen&&(i.fullPageOpen=!1,T.classList.remove("open"),h.classList.remove("hidden"),G())}function ln(){i.menuOpen=!0,v.classList.add("open"),L.classList.add("open")}function O(){i.menuOpen=!1,v.classList.remove("open"),L.classList.remove("open")}function pn(){i.chatId=Pe(t),i.historyLoadedChatId=null,U(),ue(z),oe(z,t.initialSuggestions,async s=>{await N(s,z)}),O()}async function dn(){i.chatId=Pe(t),i.historyLoadedChatId=null,ue(P),G(),oe(P,t.initialSuggestions,async s=>{await N(s,P)}),K()}async function H(){if(!t.endpoints.listChats)return K(),Le(),[];i.loadingChats=!0,K(),Le();try{let s=await Rt(M());return i.chats=s,s}catch(s){return j(t,s),i.chats}finally{i.loadingChats=!1,K(),Le()}}async function cn(s){!t.endpoints.listChats&&!t.endpoints.createChat||i.chats.some(d=>d.chatId===i.chatId)||await $t(M(),i.chatId,s?Pn(s,n.newChat):void 0)}async function un(s){i.chatId=s,i.historyLoadedChatId=null,await Z(P,s),K()}async function gn(s){i.chatId=s,i.historyLoadedChatId=null,U(),await Z(z,s)}async function fn(){O(),await H(),i.myChatsOpen=!0,m.classList.add("kp-sheet-open"),be.classList.add("open")}function U(){i.myChatsOpen=!1,m.classList.remove("kp-sheet-open"),be.classList.remove("open")}function hn(s,d){let f=a("div","kp-overlay visible"),k=a("div","kp-panel kp-rename-dialog");k.style.cssText="position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); width:320px; height:auto; padding:24px; border-radius:16px; opacity:1; pointer-events:auto; z-index: 10000;";let b=a("h3","kp-source-preview-title");b.textContent=n.renamePrompt,b.style.marginBottom="16px",b.style.fontSize="16px";let x=a("input","kp-input");x.type="text",x.value=s.title,x.style.border="1px solid var(--kp-border-color)",x.style.padding="10px",x.style.borderRadius="8px",x.style.width="100%",x.style.marginBottom="20px";let y=a("div","kp-message-actions");y.style.justifyContent="flex-end",y.style.gap="8px";let ee=a("button","kp-message-action",n.close);ee.addEventListener("click",()=>f.remove());let te=a("button","kp-message-action active","Save");te.addEventListener("click",async()=>{te.disabled=!0,te.textContent="...",await d(x.value),f.remove()}),y.append(ee,te),k.append(b,x,y),f.appendChild(k),u.appendChild(f),x.focus()}async function xt(s){t.endpoints.updateChat&&hn(s,async d=>{let f=d.trim();if(!(!f||f===s.title))try{await We(M(),s.chatId,{title:f}),await H()}catch(k){j(t,k)}})}async function yt(s){if(t.endpoints.deleteChat)try{await zt(M(),s.chatId),i.chatId===s.chatId&&(i.chatId=Pe(t),i.historyLoadedChatId=null,ue(z),ue(P)),await H()}catch(d){j(t,d)}}function K(){Bt(st,it,i,n,async s=>{await un(s.chatId)},async s=>{await vt(s)},async s=>{await xt(s)},async s=>{await yt(s)})}function Le(){Bt(Qe,Ge,i,n,async s=>{await gn(s.chatId)},async s=>{await vt(s)},async s=>{await xt(s)},async s=>{await yt(s)})}async function vt(s){if(t.endpoints.updateChat)try{await We(M(),s.chatId,{pinned:!s.pinned}),await H()}catch(d){j(t,d)}}async function Z(s,d){ue(s),oe(s,t.initialSuggestions,async b=>{await N(b,s)});let f=a("div","kp-message kp-message-ai");f.innerHTML='<div class="kp-message-bubble"><div class="kp-typing-indicator"><span></span><span></span><span></span></div></div>',qe(s),s.body.appendChild(f);let k=await It(M(),d);return f.remove(),k.length>0&&(qe(s),Wt(s.body,s.hero,s.suggestions),An(s.body,k,{strings:n,view:s,userName:await ht(),onShowSources:pe,onShowCitation:Q,onLike:b=>{ce(t,d,b,!0).catch(console.error)},onDislike:b=>{ce(t,d,b,!1).catch(console.error)}})),i.historyLoadedChatId=d,k}let Be={open:Ue,close:_,toggle(){if(p){Ue();return}if(i.open){_();return}Ue()},destroy(){if(document.removeEventListener("keydown",wt),r.remove(),p){let s=!1;document.querySelectorAll("[data-chat-widget-host]").forEach(d=>{let f=d.shadowRoot;f&&f.querySelector(".kp-chat-widget-embedded")&&(s=!0)}),s||jt(!1)}},sendMessage:bt,setAccessTokenProvider(s){i.accessTokenProvider=s},getChatId(){return i.chatId},loadChats(){return H()},async loadHistory(){let s=i.fullPageOpen?P:z;return Z(s,i.chatId)}};h.addEventListener("click",()=>Be.toggle()),fe.addEventListener("click",_),g.addEventListener("click",_),Ce.addEventListener("click",G),ke.addEventListener("click",U),xe.addEventListener("click",U),v.addEventListener("click",s=>{if(s.stopPropagation(),!i.menuOpen){ln();return}O()}),w.addEventListener("click",pn),F.addEventListener("click",async()=>{await fn()}),R.addEventListener("click",()=>{if(O(),t.onOpenAssistantPage){_(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){_(),window.location.href=t.assistantPageUrl;return}rn()}),ye.addEventListener("click",kt),$e.addEventListener("click",()=>{dn(),queueMicrotask(()=>E.focus())}),ie.addEventListener("input",()=>{i.chatSearchTerm=ie.value.trim().toLowerCase(),K()}),m.addEventListener("click",s=>{let d=s.target;if(!(d instanceof Element)||!d.closest(".kp-chat-actions")){for(let f of Array.from(c.querySelectorAll(".kp-chat-actions.open")))f.classList.remove("open");for(let f of Array.from(c.querySelectorAll(".kp-full-page-chat-item.menu-open")))f.classList.remove("menu-open")}i.menuOpen&&!L.contains(d)&&!v.contains(d)&&O(),s.stopPropagation()}),c.addEventListener("click",s=>{let d=s.target;if(i.menuOpen&&d instanceof Node&&!L.contains(d)&&!v.contains(d)&&O(),d instanceof Element&&!d.closest(".kp-chat-actions")){for(let f of Array.from(c.querySelectorAll(".kp-chat-actions.open")))f.classList.remove("open");for(let f of Array.from(c.querySelectorAll(".kp-full-page-chat-item.menu-open")))f.classList.remove("menu-open")}}),Te.addEventListener("submit",async s=>{s.preventDefault(),await bt($.value)}),Me.addEventListener("submit",async s=>{s.preventDefault(),await N(E.value,P)});function wt(s){if(s.key==="Escape"){if(i.sourcePanelOpen){G();return}if(i.myChatsOpen){U();return}if(i.fullPageOpen){if(p)return;kt();return}i.open&&_()}}return document.addEventListener("keydown",wt),Be}async function vn(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 Pe(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 ge(e,t,o,n){let l=t==="bot"?In(o,n.citations??[]):{displayText:o,citations:n.citations??[]},p=a("div",`kp-message-row ${t}`),i=Cn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),r=a("div",`kp-bubble ${t}`),c=a("div","kp-bubble-content");Bn(c,l.displayText),r.appendChild(c);let u=l.citations;if(u.length){let g=a("div","kp-meta",n.strings.citationsAttached(u.length));r.appendChild(g);let h=a("div","kp-source-preview"),m=a("div","kp-source-preview-title",n.strings.sourcesUsed),A=a("div","kp-source-preview-list");for(let v of u.slice(0,2)){let L=Mn(v,n.strings);L.addEventListener("click",async()=>{n.onShowCitation(v)}),A.appendChild(L)}let S=Nn(n.strings);S.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),A.appendChild(S),h.append(m,A),r.appendChild(h)}return t==="bot"&&r.appendChild(wn(l.displayText,n.strings,n.onLike,n.onDislike,n.initialFeedback)),t==="user"?p.append(r,i):p.append(i,r),e.appendChild(p),e.scrollTop=e.scrollHeight,p}function wn(e,t,o,n,l){let p=a("div","kp-message-actions"),i=a("button","kp-message-action",t.copy);i.type="button",i.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(e),i.textContent=t.copied,window.setTimeout(()=>{i.textContent=t.copy},1200)}catch{i.textContent=t.copy}});let r=a("button","kp-message-action","\u{1F44D}");r.type="button",r.setAttribute("aria-label",t.helpful),l===!0&&r.classList.add("active"),r.addEventListener("click",()=>{r.classList.toggle("active"),c.classList.remove("active"),r.classList.contains("active")&&o&&o()});let c=a("button","kp-message-action","\u{1F44E}");return c.type="button",c.setAttribute("aria-label",t.notHelpful),l===!1&&c.classList.add("active"),c.addEventListener("click",()=>{c.classList.toggle("active"),r.classList.remove("active"),c.classList.contains("active")&&n&&n()}),p.append(i,r,c),p}function Cn(e,t){let o=a("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":En(e);return o.textContent=n,o.setAttribute("aria-hidden","true"),o}function Ln(e,t,o){e.textContent="";for(let n of t){let l=a("button","kp-suggestion",n);l.type="button",l.addEventListener("click",async()=>{await o(n)}),e.appendChild(l)}}function oe(e,t,o){Ln(e.suggestions,t,async n=>{e.input.value=n,await o(n)})}function Wt(e,t,o){let n=new Set([t,o]);for(let l of Array.from(e.children))n.has(l)||l.remove()}function qe(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function ue(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),Wt(e.body,e.hero,e.suggestions),e.input.value=""}function An(e,t,o){for(let n of t)ge(e,n.role==="assistant"?"bot":"user",n.text,{...o,...n.citations!==void 0?{citations:n.citations}:{},...n.isLike!==void 0?{initialFeedback:n.isLike}:{},onLike:()=>{o.onLike&&o.onLike(n.text)},onDislike:()=>{o.onDislike&&o.onDislike(n.text)}})}function Bt(e,t,o,n,l,p,i,r){if(e.textContent="",t.textContent="",o.loadingChats){e.appendChild(a("div","kp-full-page-empty",n.loadingChats));return}let c=o.chats.filter(u=>o.chatSearchTerm?u.title.toLowerCase().includes(o.chatSearchTerm):!0);if(c.length>0){let u=c.filter(h=>h.pinned),g=c.filter(h=>!h.pinned).slice(0,8);Dt(e,g,o.chatId,n,l,p,i,r),Dt(t,u,o.chatId,n,l,p,i,r),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 Dt(e,t,o,n,l,p,i,r){for(let c of t){let u=a("div",`kp-full-page-item kp-full-page-chat-item${c.chatId===o?" active":""}`),g=a("span","kp-full-page-item-title",c.title),h=a("div","kp-chat-actions"),m=a("button","kp-chat-actions-trigger","\u22EF");m.type="button",m.setAttribute("aria-label",n.chatActions);let A=a("div","kp-chat-actions-menu"),S=a("button","kp-chat-actions-item",c.pinned?n.unpinChat:n.pinChat);S.type="button",S.addEventListener("click",async w=>{w.stopPropagation(),await p(c)});let v=a("button","kp-chat-actions-item",n.renameChat);v.type="button",v.addEventListener("click",async w=>{w.stopPropagation(),await i(c)});let L=a("button","kp-chat-actions-item",n.deleteChat);L.type="button",L.addEventListener("click",async w=>{w.stopPropagation(),await r(c)}),A.append(S,v,L),h.append(m,A),m.addEventListener("click",w=>{w.stopPropagation();let F=h.classList.contains("open");for(let R of Array.from(e.querySelectorAll(".kp-chat-actions.open")))R.classList.remove("open");for(let R of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))R.classList.remove("menu-open");F||(h.classList.add("open"),u.classList.add("menu-open"))}),u.append(g,h),u.setAttribute("role","button"),u.tabIndex=0,u.addEventListener("click",async()=>{await l(c)}),u.addEventListener("keydown",async w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),await l(c))}),u.addEventListener("blur",()=>{h.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function Pn(e,t){return e.trim().slice(0,60)||t}function Ve(e){return e.toLowerCase().split("-")[0]||"en"}function Sn(e){let t=Ut.en;return Ut[Ve(e)]??t}function Tn(e){return["ar","fa","he","ur"].includes(Ve(e))}function En(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(o=>o[0]?.toUpperCase()??"").join("")}function _e(e){if(e.knowledgeName?.trim())return e.knowledgeName.trim();if(e.text){let t=e.text.split(`
1918
+ `)[0]?.trim();if(t){let o=t.replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();if(o)return o}}if(e.sourceDocument&&/^https?:\/\//i.test(e.sourceDocument)){try{let t=new URL(e.sourceDocument),o=decodeURIComponent(t.pathname),n=o.substring(o.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 o=Rn(e);return{displayText:o.displayText,citations:t.length>0?Hn(t,o.citations):o.citations}}function Rn(e){let o=Ft(e).split(`
1919
+ `),n=-1;for(let c=0;c<o.length;c+=1)/^#{0,6}\s*References\s*$/i.test(o[c]?.trim()??"")&&(n=c);if(n===-1)return{displayText:e,citations:[]};let l=o.slice(0,n).join(`
1920
+ `).trimEnd(),p=o.slice(n+1).join(`
1921
+ `).trim(),r=$n(p).map(c=>zn(c)).filter(c=>!!c);return{displayText:l,citations:r}}function $n(e){let t=[],o="";for(let n of e.split(`
1922
+ `)){let l=n.trim();if(l){if(/^\d+\.\s+/.test(l)){o&&t.push(o.trim()),o=l.replace(/^\d+\.\s+/,"");continue}o&&(o=`${o} ${l}`)}}return o&&t.push(o.trim()),t}function zn(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 Hn(e,t){let o=[],n=new Set;for(let l of[...e,...t]){let p=`${l.knowledgeName??""}::${l.sourceDocument??""}`;n.has(p)||(n.add(p),o.push(l))}return o}function Mn(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 l=a("span","kp-source-chip-label",_e(e)??t.untitledSource);return o.append(n,l),o}function Nn(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 l=0;l<3;l+=1){let p=a("span","kp-source-thumb stacked");p.textContent="\u2726",o.appendChild(p)}let n=a("span","kp-source-chip-label",e.showAll);return t.append(o,n),t}function On(e,t,o){let n=a("button","kp-source-card");n.type="button",n.setAttribute("aria-label",t.openSource),n.addEventListener("click",o);let l=a("div","kp-source-card-media"),p=a("span","kp-source-thumb kp-source-thumb-large");p.textContent="\u2726";let i=a("div","kp-source-card-title",_e(e)??t.untitledSource),r=a("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}`),r.textContent=c.join(" \u2022 "),l.appendChild(p),n.append(l,i,r),n}function Un(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function Bn(e,t){e.innerHTML=Dn(Ft(t))}function Ft(e){return e.replace(/\r\n/g,`
1923
+ `)}function Dn(e){return e.split(/\n{2,}/).map(o=>o.trim()).filter(Boolean).map(jn).join("")}function jn(e){let t=e.split(`
1924
+ `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return Wn(t);if(t.every(n=>/^\d+\.\s+/.test(n)))return`<ol>${t.map(n=>`<li>${se(n.replace(/^\d+\.\s+/,""))}</li>`).join("")}</ol>`;if(t.every(n=>/^[-*]\s+/.test(n)))return`<ul>${t.map(n=>`<li>${se(n.replace(/^[-*]\s+/,""))}</li>`).join("")}</ul>`;let o=t[0]?.match(/^(#{1,6})\s+(.*)$/);if(o){let n=o[1]??"#",l=o[2]??"",p=n.length;return`<h${p}>${se(l)}</h${p}>`}return`<p>${t.map(n=>se(n)).join("<br>")}</p>`}function Wn(e){let t=e.filter((i,r)=>!(r===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(i))).map(i=>Fn(i));if(t.length===0)return"";let o=t[0]??[],n=t.slice(1),l=`<thead><tr>${o.map(i=>`<th>${se(i)}</th>`).join("")}</tr></thead>`,p=n.length?`<tbody>${n.map(i=>`<tr>${i.map(r=>`<td>${se(r)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${l}${p}</table></div>`}function Fn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function se(e){let t=W(e);return t=t.replace(/&lt;br\s*\/?&gt;/gi,"<br>"),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 W(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function jt(e){typeof document>"u"||document.querySelectorAll("[data-chat-widget-host]").forEach(t=>{let o=t.shadowRoot;if(o){let n=o.querySelector(".kp-chat-widget");n&&!n.classList.contains("kp-chat-widget-embedded")&&(t.style.display=e?"none":"")}})}export{aa as a};
1925
+ //# sourceMappingURL=chunk-YJTDM6ZC.js.map