@nabeh/chat-widget 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var We=Object.defineProperty;var An=Object.getOwnPropertyDescriptor;var Pn=Object.getOwnPropertyNames;var Sn=Object.prototype.hasOwnProperty;var Tn=(e,t)=>{for(var o in t)We(e,o,{get:t[o],enumerable:!0})},En=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Pn(t))!Sn.call(e,r)&&r!==o&&We(e,r,{get:()=>t[r],enumerable:!(n=An(t,r))||n.enumerable});return e};var In=e=>En(We({},"__esModule",{value:!0}),e);var ta={};Tn(ta,{browserGlobal:()=>Yt,createChatWidget:()=>Se,init:()=>Kt,version:()=>_t});module.exports=In(ta);function Et(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Fe(e,t){let o={...e};for(let n of Object.keys(t)){let r=t[n],p=o[n];if(Et(p)&&Et(r)){o[n]=Fe(p,r);continue}r!==void 0&&(o[n]=r)}return o}function It(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 Rt(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await D(e),r=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},l=await fetch(r,{method:"POST",headers:X(e,o,n),body:JSON.stringify(i)});if(!l.ok)throw new Error(`Chat backend returned ${l.status}.`);let c=l.body?.getReader(),u="";if(c)for(;;){let{done:G,value:I}=await c.read();if(G)break;I&&(u+=new TextDecoder("utf-8").decode(I,{stream:!0}))}else u=await l.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((G,I)=>({sourceDocument:G,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 $t(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 l=await i.json(),c=Array.isArray(l)?l:l&&typeof l=="object"?l.history??l.messages??l.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 zt(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 r=await n.json(),p=Array.isArray(r)?r:r&&typeof r=="object"?r.chats??r.data??r.items??[]:[];return Array.isArray(p)?p.map(i=>{if(!i||typeof i!="object")return null;let l=i,c=l.chatId??l.chat_id??l.id,u=l.title??l.name??l.chatId;if(typeof c!="string"||typeof u!="string")return null;let g=typeof l.createdAt=="string"?l.createdAt:typeof l.created_at=="string"?l.created_at:null,h=typeof l.updatedAt=="string"?l.updatedAt:typeof l.updated_at=="string"?l.updated_at:null,m={chatId:c,title:u,pinned:typeof l.pinned=="boolean"?l.pinned:!1};return g&&(m.createdAt=g),h&&(m.updatedAt=h),m}).filter(i=>!!i):[]}async function Ht(e,t,o){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let r=e.getAccessToken?await e.getAccessToken():null,p=await D(e),i=await fetch(de(e.apiBaseUrl,n),{method:"POST",headers:X(e,r,p),body:JSON.stringify({chatId:t,...o?{title:o}:{}})});if(!i.ok)throw new Error(`Create chat endpoint returned ${i.status}.`)}async function qe(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,r=await D(e),p=ae(e,e.endpoints.updateChat,{chatId:t}),i=await fetch(p,{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 Mt(e,t){if(!e.endpoints.deleteChat)return;let o=e.getAccessToken?await e.getAccessToken():null,n=await D(e),r=ae(e,e.endpoints.deleteChat,{chatId:t}),p=await fetch(r,{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=It(t);return e.onError?.(o),o}async function ce(e,t,o,n){if(!e.endpoints.feedback)return;let r=e.getAccessToken?await e.getAccessToken():null,p=await D(e),i=ae(e,e.endpoints.feedback,{chatId:t}),l=await fetch(i,{method:"POST",headers:X(e,r,p),body:JSON.stringify({message:o,isLike:n})});if(!l.ok)throw new Error(`Feedback endpoint returned ${l.status}.`)}async function Nt(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),r=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}`}:{}},l=await fetch(r,{method:"POST",headers:i,body:p});if(!l.ok){let c=`Upload endpoint returned ${l.status}.`;try{let u=await l.json();u.message?c=`Failed to upload: ${u.message}`:u.error&&(c=`Failed to upload: ${u.error}`)}catch{}throw new Error(c)}return l.json()}var Ve={accent:"#0f766e",accentSoft:"#ecfeff",panelBackground:"#ffffff",surfaceBackground:"#f8fafc",text:"#1f2937",mutedText:"#64748b",borderColor:"#dbe4ee",shadow:"0 24px 64px rgba(15, 23, 42, 0.20)",zIndex:2147483e3,fontFamily:'"Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif'},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:Ve,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0};function Ot(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=Fe(Ve,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 Ut="kp-chat-widget-styles";function Bt(e,t){if(e.getElementById(Ut))return;let o=document.createElement("style");o.id=Ut,o.textContent=Rn(t),e.appendChild(o)}function Rn(e){return`
1
+ "use strict";var We=Object.defineProperty;var Pn=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var Sn=Object.prototype.hasOwnProperty;var Tn=(e,t)=>{for(var o in t)We(e,o,{get:t[o],enumerable:!0})},En=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of An(t))!Sn.call(e,r)&&r!==o&&We(e,r,{get:()=>t[r],enumerable:!(n=Pn(t,r))||n.enumerable});return e};var In=e=>En(We({},"__esModule",{value:!0}),e);var ta={};Tn(ta,{browserGlobal:()=>Yt,createChatWidget:()=>Se,init:()=>Kt,version:()=>_t});module.exports=In(ta);function Et(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Fe(e,t){let o={...e};for(let n of Object.keys(t)){let r=t[n],p=o[n];if(Et(p)&&Et(r)){o[n]=Fe(p,r);continue}r!==void 0&&(o[n]=r)}return o}function It(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 Rt(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await D(e),r=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},l=await fetch(r,{method:"POST",headers:X(e,o,n),body:JSON.stringify(i)});if(!l.ok)throw new Error(`Chat backend returned ${l.status}.`);let c=l.body?.getReader(),u="";if(c)for(;;){let{done:G,value:I}=await c.read();if(G)break;I&&(u+=new TextDecoder("utf-8").decode(I,{stream:!0}))}else u=await l.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,P=m?.source_documents??[],S=m?.scores??[],v=m?.page_numbers??[],L=m?.sheet_names??[],w=m?.row_numbers??[],F=m?.knowledge_names??[],R=P.map((G,I)=>({sourceDocument:G,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 $t(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 l=await i.json(),c=Array.isArray(l)?l:l&&typeof l=="object"?l.history??l.messages??l.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 P=typeof h=="string"?h.toLowerCase():"assistant";return[{role:P==="user"||P==="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 zt(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 r=await n.json(),p=Array.isArray(r)?r:r&&typeof r=="object"?r.chats??r.data??r.items??[]:[];return Array.isArray(p)?p.map(i=>{if(!i||typeof i!="object")return null;let l=i,c=l.chatId??l.chat_id??l.id,u=l.title??l.name??l.chatId;if(typeof c!="string"||typeof u!="string")return null;let g=typeof l.createdAt=="string"?l.createdAt:typeof l.created_at=="string"?l.created_at:null,h=typeof l.updatedAt=="string"?l.updatedAt:typeof l.updated_at=="string"?l.updated_at:null,m={chatId:c,title:u,pinned:typeof l.pinned=="boolean"?l.pinned:!1};return g&&(m.createdAt=g),h&&(m.updatedAt=h),m}).filter(i=>!!i):[]}async function Ht(e,t,o){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let r=e.getAccessToken?await e.getAccessToken():null,p=await D(e),i=await fetch(de(e.apiBaseUrl,n),{method:"POST",headers:X(e,r,p),body:JSON.stringify({chatId:t,...o?{title:o}:{}})});if(!i.ok)throw new Error(`Create chat endpoint returned ${i.status}.`)}async function qe(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,r=await D(e),p=ae(e,e.endpoints.updateChat,{chatId:t}),i=await fetch(p,{method:"PUT",headers:X(e,n,r),body:JSON.stringify(o)});if(!i.ok)throw new Error(`Update chat endpoint returned ${i.status}.`)}async function Mt(e,t){if(!e.endpoints.deleteChat)return;let o=e.getAccessToken?await e.getAccessToken():null,n=await D(e),r=ae(e,e.endpoints.deleteChat,{chatId:t}),p=await fetch(r,{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=It(t);return e.onError?.(o),o}async function ce(e,t,o,n){if(!e.endpoints.feedback)return;let r=e.getAccessToken?await e.getAccessToken():null,p=await D(e),i=ae(e,e.endpoints.feedback,{chatId:t}),l=await fetch(i,{method:"POST",headers:X(e,r,p),body:JSON.stringify({message:o,isLike:n})});if(!l.ok)throw new Error(`Feedback endpoint returned ${l.status}.`)}async function Nt(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),r=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}`}:{}},l=await fetch(r,{method:"POST",headers:i,body:p});if(!l.ok){let c=`Upload endpoint returned ${l.status}.`;try{let u=await l.json();u.message?c=`Failed to upload: ${u.message}`:u.error&&(c=`Failed to upload: ${u.error}`)}catch{}throw new Error(c)}return l.json()}var Ve={accent:"#0f766e",accentSoft:"#ecfeff",panelBackground:"#ffffff",surfaceBackground:"#f8fafc",text:"#1f2937",mutedText:"#64748b",borderColor:"#dbe4ee",shadow:"0 24px 64px rgba(15, 23, 42, 0.20)",zIndex:2147483e3,fontFamily:'"Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif'},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:Ve,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0};function Ot(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=Fe(Ve,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 Ut="kp-chat-widget-styles";function Bt(e,t){if(e.getElementById(Ut))return;let o=document.createElement("style");o.id=Ut,o.textContent=Rn(t),e.appendChild(o)}function Rn(e){return`
2
2
  :host {
3
3
  all: initial;
4
4
  }
@@ -1818,7 +1818,7 @@
1818
1818
  min-height: auto;
1819
1819
  }
1820
1820
  }
1821
- `}var Dt={en:{openChatActions:"Open chat actions",newChat:"New Chat",myChats:"My Chats",openAssistant:"Open Knowledge Assistant",back:"Back",close:"Close",assistantBadge:"Knowledge Assistant",closeAssistantPage:"Close knowledge assistant page",searchChat:"Search Chat",recentActivity:"Recent Activity",pinnedCollections:"Pinned Collections",answersBasedOnPermissions:"Answers are generated based on your access permissions",authTokenForwarded:"Auth token is forwarded from the host app when configured.",thinking:"Thinking...",unableToCreateChat:"Unable to create chat",requestFailed:"Request failed",noRecentChats:"No recent chats yet.",noPinnedChats:"No pinned chats yet.",noChats:"No chats yet.",loadingChats:"Loading chats...",pinChat:"Pin chat",unpinChat:"Unpin chat",renameChat:"Rename",deleteChat:"Delete",chatActions:"Chat actions",renamePrompt:"Enter a new chat name",citationsAttached:e=>`${e} citation${e>1?"s":""} attached`,sourcesUsed:"Sources Used",allSourcesUsed:"All Sources Used",documentsAndReferences:"AI documents and references",showAll:"Show All",noSources:"No sources were returned for this answer.",closeSourcesPanel:"Close sources panel",openSource:"Open source",sourceScore:"Score",sourcePage:"Page",sourceSheet:"Sheet",sourceRow:"Row",sourceKnowledge:"Knowledge Base",untitledSource:"Untitled Source",copy:"Copy",copied:"Copied",helpful:"Helpful",notHelpful:"Needs work",send:"Send message",assistantAvatar:"Assistant",userAvatar:"User"},ar:{openChatActions:"\u0641\u062A\u062D \u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",newChat:"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629",myChats:"\u0645\u062D\u0627\u062F\u062B\u0627\u062A\u064A",openAssistant:"\u0641\u062A\u062D \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",back:"\u0631\u062C\u0648\u0639",close:"\u0625\u063A\u0644\u0627\u0642",assistantBadge:"\u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",closeAssistantPage:"\u0625\u063A\u0644\u0627\u0642 \u0635\u0641\u062D\u0629 \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",searchChat:"\u0627\u0628\u062D\u062B \u0641\u064A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A",recentActivity:"\u0627\u0644\u0646\u0634\u0627\u0637 \u0627\u0644\u0623\u062E\u064A\u0631",pinnedCollections:"\u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0627\u0644\u0645\u062B\u0628\u062A\u0629",answersBasedOnPermissions:"\u064A\u062A\u0645 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0625\u062C\u0627\u0628\u0627\u062A \u0628\u0646\u0627\u0621\u064B \u0639\u0644\u0649 \u0635\u0644\u0627\u062D\u064A\u0627\u062A \u0627\u0644\u0648\u0635\u0648\u0644 \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0643",authTokenForwarded:"\u064A\u062A\u0645 \u062A\u0645\u0631\u064A\u0631 \u0631\u0645\u0632 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0627\u0644\u062A\u0637\u0628\u064A\u0642 \u0627\u0644\u0645\u0636\u064A\u0641 \u0639\u0646\u062F \u0627\u0644\u0625\u0639\u062F\u0627\u062F.",thinking:"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631...",unableToCreateChat:"\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",requestFailed:"\u0641\u0634\u0644 \u0627\u0644\u0637\u0644\u0628",noRecentChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u062D\u062F\u064A\u062B\u0629 \u0628\u0639\u062F.",noPinnedChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0645\u062B\u0628\u062A\u0629 \u0628\u0639\u062F.",noChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0628\u0639\u062F.",loadingChats:"\u062C\u0627\u0631\u064D \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A...",pinChat:"\u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",unpinChat:"\u0625\u0644\u063A\u0627\u0621 \u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renameChat:"\u0625\u0639\u0627\u062F\u0629 \u062A\u0633\u0645\u064A\u0629",deleteChat:"\u062D\u0630\u0641",chatActions:"\u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renamePrompt:"\u0623\u062F\u062E\u0644 \u0627\u0633\u0645\u064B\u0627 \u062C\u062F\u064A\u062F\u064B\u0627 \u0644\u0644\u0645\u062D\u0627\u062F\u062B\u0629",citationsAttached:e=>`\u062A\u0645 \u0625\u0631\u0641\u0627\u0642 ${e} \u0645\u0631\u062C\u0639${e>1?"\u0627\u062A":""}`,sourcesUsed:"\u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",allSourcesUsed:"\u0643\u0644 \u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",documentsAndReferences:"\u0645\u0633\u062A\u0646\u062F\u0627\u062A \u0648\u0645\u0631\u0627\u062C\u0639 \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A",showAll:"\u0639\u0631\u0636 \u0627\u0644\u0643\u0644",noSources:"\u0644\u0645 \u064A\u062A\u0645 \u0625\u0631\u062C\u0627\u0639 \u0645\u0635\u0627\u062F\u0631 \u0644\u0647\u0630\u0647 \u0627\u0644\u0625\u062C\u0627\u0628\u0629.",closeSourcesPanel:"\u0625\u063A\u0644\u0627\u0642 \u0644\u0648\u062D\u0629 \u0627\u0644\u0645\u0635\u0627\u062F\u0631",openSource:"\u0641\u062A\u062D \u0627\u0644\u0645\u0635\u062F\u0631",sourceScore:"\u0627\u0644\u062F\u0631\u062C\u0629",sourcePage:"\u0627\u0644\u0635\u0641\u062D\u0629",sourceSheet:"\u0627\u0644\u0648\u0631\u0642\u0629",sourceRow:"\u0627\u0644\u0635\u0641",sourceKnowledge:"\u0642\u0627\u0639\u062F\u0629 \u0627\u0644\u0645\u0639\u0631\u0641\u0629",untitledSource:"\u0645\u0635\u062F\u0631 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646",copy:"\u0646\u0633\u062E",copied:"\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",helpful:"\u0645\u0641\u064A\u062F",notHelpful:"\u064A\u062D\u062A\u0627\u062C \u062A\u062D\u0633\u064A\u0646",send:"\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629",assistantAvatar:"\u0627\u0644\u0645\u0633\u0627\u0639\u062F",userAvatar:"\u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645"}};function Se(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=Ot(e),o=Ke(t.locale),n=Un(t.locale),r=Bn(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},l=document.createElement("div");l.dataset.chatWidgetHost="true",t.mount.appendChild(l);let c=l.attachShadow({mode:"open"});Bt(c,t.theme);let u=a("div",`kp-chat-widget ${t.position}`);u.lang=o,u.dir=r?"rtl":"ltr",p&&(u.classList.add("kp-chat-widget-embedded"),Ft(!0)),r&&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 G=a("div","kp-title-wrap"),I=a("h2","kp-title",t.title),Xt=a("div","kp-subtitle",t.subtitle);G.append(I,Xt);let fe=a("button","kp-close","\xD7");fe.type="button",fe.setAttribute("aria-label",t.closeAriaLabel),A.append(S,G,fe);let he=a("div","kp-body"),Te=a("div","kp-hero"),Gt=a("div","kp-hero-icon","\u2726"),Jt=a("div","kp-hero-text",t.welcomeMessage);Te.append(Gt,Jt);let Xe=a("div","kp-footer"),Ee=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 Ie=a("div","kp-attachment-badge");Ie.style.display="none";let Re=a("button","kp-send","\u279C");Re.type="submit",Re.setAttribute("aria-label",n.send);let Qt=a("div","kp-note",n.authTokenForwarded);Ee.append(me,q,$,Re),Xe.append(Ie,Ee,Qt),m.append(A,he,Xe),p||u.append(g,h,m),c.appendChild(u),he.appendChild(Te);let Ge=a("div","kp-suggestions");he.appendChild(Ge);let be=a("section","kp-my-chats-sheet"),Je=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),Je.append(ke,xe);let Qe=a("div","kp-my-chats-body"),Zt=a("div","kp-my-chats-section-label",n.recentActivity),Ze=a("div","kp-my-chats-list"),en=a("div","kp-my-chats-section-label",n.pinnedCollections),et=a("div","kp-my-chats-list");Qe.append(Zt,Ze,en,et),be.append(Je,Qe),m.appendChild(be);let z={body:he,input:$,suggestions:Ge,hero:Te,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 tt=a("div","kp-full-page-shell"),$e=a("div","kp-full-page-header"),nt=a("div","kp-full-page-brand"),tn=a("div","kp-full-page-brand-mark","\u2726"),nn=a("div","kp-full-page-brand-text",t.title);nt.append(tn,nn);let at=a("div","kp-full-page-header-actions"),an=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),at.append(an,ye),$e.append(nt,at),t.embedded.showHeader||$e.classList.add("kp-hidden");let ot=a("div","kp-full-page-content"),st=a("aside","kp-full-page-sidebar"),ze=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);ze.type="button";let it=a("div","kp-full-page-search"),ie=a("input","kp-full-page-search-input");ie.type="search",ie.placeholder=n.searchChat;let on=a("span","kp-full-page-search-icon","\u2315");it.append(ie,on);let sn=a("div","kp-full-page-section-label",n.recentActivity),rt=a("div","kp-full-page-recent-list"),rn=a("div","kp-full-page-section-label",n.pinnedCollections),lt=a("div","kp-full-page-pinned-list");st.append(ze,it,sn,rt,rn,lt);let pt=a("main","kp-full-page-main"),dt=a("section","kp-full-page-panel"),He=a("div","kp-full-page-body"),Me=a("div","kp-full-page-hero"),ct=a("div","kp-full-page-hero-badge");ct.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 ln=a("div","kp-full-page-hero-text",t.welcomeMessage);Me.append(ct,ln);let ut=a("div","kp-suggestions kp-full-page-suggestions");He.append(Me,ut);let gt=a("div","kp-full-page-footer"),Ne=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 Oe=a("div","kp-attachment-badge kp-full-page-attachment-badge");Oe.style.display="none";let Ue=a("button","kp-send kp-full-page-send","\u279C");Ue.type="submit",Ue.setAttribute("aria-label",n.send);let pn=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Ne.append(ve,V,E,Ue),gt.append(Oe,Ne,pn),dt.append(He,gt),pt.appendChild(dt);let we=a("aside","kp-source-panel"),ft=a("div","kp-source-panel-header"),ht=a("div","kp-source-panel-title-wrap"),mt=a("div","kp-source-panel-title",n.allSourcesUsed),dn=a("div","kp-source-panel-subtitle",n.documentsAndReferences);ht.append(mt,dn);let Ce=a("button","kp-source-panel-close","\xD7");Ce.type="button",Ce.setAttribute("aria-label",n.closeSourcesPanel),ft.append(ht,Ce);let re=a("div","kp-source-panel-list"),cn=a("div","kp-source-panel-empty",n.noSources);re.appendChild(cn),we.append(ft,re),ot.append(st,pt,we),tt.append($e,ot),T.appendChild(tt),u.appendChild(T);let le=a("div","kp-citation-overlay");u.appendChild(le);let P={body:He,input:E,suggestions:ut,hero:Me,kind:"full-page"},M=()=>({...t,getAccessToken:i.accessTokenProvider}),bt=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}},J=s=>{let d=Ye(s)??n.untitledSource,f=(s.text||"").trim(),k=f,b=f.split(`
1821
+ `}var Dt={en:{openChatActions:"Open chat actions",newChat:"New Chat",myChats:"My Chats",openAssistant:"Open Knowledge Assistant",back:"Back",close:"Close",assistantBadge:"Knowledge Assistant",closeAssistantPage:"Close knowledge assistant page",searchChat:"Search Chat",recentActivity:"Recent Activity",pinnedCollections:"Pinned Collections",answersBasedOnPermissions:"Answers are generated based on your access permissions",authTokenForwarded:"Auth token is forwarded from the host app when configured.",thinking:"Thinking...",unableToCreateChat:"Unable to create chat",requestFailed:"Request failed",noRecentChats:"No recent chats yet.",noPinnedChats:"No pinned chats yet.",noChats:"No chats yet.",loadingChats:"Loading chats...",pinChat:"Pin chat",unpinChat:"Unpin chat",renameChat:"Rename",deleteChat:"Delete",chatActions:"Chat actions",renamePrompt:"Enter a new chat name",citationsAttached:e=>`${e} citation${e>1?"s":""} attached`,sourcesUsed:"Sources Used",allSourcesUsed:"All Sources Used",documentsAndReferences:"AI documents and references",showAll:"Show All",noSources:"No sources were returned for this answer.",closeSourcesPanel:"Close sources panel",openSource:"Open source",sourceScore:"Score",sourcePage:"Page",sourceSheet:"Sheet",sourceRow:"Row",sourceKnowledge:"Knowledge Base",untitledSource:"Untitled Source",copy:"Copy",copied:"Copied",helpful:"Helpful",notHelpful:"Needs work",send:"Send message",assistantAvatar:"Assistant",userAvatar:"User"},ar:{openChatActions:"\u0641\u062A\u062D \u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",newChat:"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629",myChats:"\u0645\u062D\u0627\u062F\u062B\u0627\u062A\u064A",openAssistant:"\u0641\u062A\u062D \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",back:"\u0631\u062C\u0648\u0639",close:"\u0625\u063A\u0644\u0627\u0642",assistantBadge:"\u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",closeAssistantPage:"\u0625\u063A\u0644\u0627\u0642 \u0635\u0641\u062D\u0629 \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",searchChat:"\u0627\u0628\u062D\u062B \u0641\u064A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A",recentActivity:"\u0627\u0644\u0646\u0634\u0627\u0637 \u0627\u0644\u0623\u062E\u064A\u0631",pinnedCollections:"\u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0627\u0644\u0645\u062B\u0628\u062A\u0629",answersBasedOnPermissions:"\u064A\u062A\u0645 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0625\u062C\u0627\u0628\u0627\u062A \u0628\u0646\u0627\u0621\u064B \u0639\u0644\u0649 \u0635\u0644\u0627\u062D\u064A\u0627\u062A \u0627\u0644\u0648\u0635\u0648\u0644 \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0643",authTokenForwarded:"\u064A\u062A\u0645 \u062A\u0645\u0631\u064A\u0631 \u0631\u0645\u0632 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0627\u0644\u062A\u0637\u0628\u064A\u0642 \u0627\u0644\u0645\u0636\u064A\u0641 \u0639\u0646\u062F \u0627\u0644\u0625\u0639\u062F\u0627\u062F.",thinking:"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631...",unableToCreateChat:"\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",requestFailed:"\u0641\u0634\u0644 \u0627\u0644\u0637\u0644\u0628",noRecentChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u062D\u062F\u064A\u062B\u0629 \u0628\u0639\u062F.",noPinnedChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0645\u062B\u0628\u062A\u0629 \u0628\u0639\u062F.",noChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0628\u0639\u062F.",loadingChats:"\u062C\u0627\u0631\u064D \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A...",pinChat:"\u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",unpinChat:"\u0625\u0644\u063A\u0627\u0621 \u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renameChat:"\u0625\u0639\u0627\u062F\u0629 \u062A\u0633\u0645\u064A\u0629",deleteChat:"\u062D\u0630\u0641",chatActions:"\u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renamePrompt:"\u0623\u062F\u062E\u0644 \u0627\u0633\u0645\u064B\u0627 \u062C\u062F\u064A\u062F\u064B\u0627 \u0644\u0644\u0645\u062D\u0627\u062F\u062B\u0629",citationsAttached:e=>`\u062A\u0645 \u0625\u0631\u0641\u0627\u0642 ${e} \u0645\u0631\u062C\u0639${e>1?"\u0627\u062A":""}`,sourcesUsed:"\u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",allSourcesUsed:"\u0643\u0644 \u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",documentsAndReferences:"\u0645\u0633\u062A\u0646\u062F\u0627\u062A \u0648\u0645\u0631\u0627\u062C\u0639 \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A",showAll:"\u0639\u0631\u0636 \u0627\u0644\u0643\u0644",noSources:"\u0644\u0645 \u064A\u062A\u0645 \u0625\u0631\u062C\u0627\u0639 \u0645\u0635\u0627\u062F\u0631 \u0644\u0647\u0630\u0647 \u0627\u0644\u0625\u062C\u0627\u0628\u0629.",closeSourcesPanel:"\u0625\u063A\u0644\u0627\u0642 \u0644\u0648\u062D\u0629 \u0627\u0644\u0645\u0635\u0627\u062F\u0631",openSource:"\u0641\u062A\u062D \u0627\u0644\u0645\u0635\u062F\u0631",sourceScore:"\u0627\u0644\u062F\u0631\u062C\u0629",sourcePage:"\u0627\u0644\u0635\u0641\u062D\u0629",sourceSheet:"\u0627\u0644\u0648\u0631\u0642\u0629",sourceRow:"\u0627\u0644\u0635\u0641",sourceKnowledge:"\u0642\u0627\u0639\u062F\u0629 \u0627\u0644\u0645\u0639\u0631\u0641\u0629",untitledSource:"\u0645\u0635\u062F\u0631 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646",copy:"\u0646\u0633\u062E",copied:"\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",helpful:"\u0645\u0641\u064A\u062F",notHelpful:"\u064A\u062D\u062A\u0627\u062C \u062A\u062D\u0633\u064A\u0646",send:"\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629",assistantAvatar:"\u0627\u0644\u0645\u0633\u0627\u0639\u062F",userAvatar:"\u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645"}};function Se(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=Ot(e),o=Ke(t.locale),n=Un(t.locale),r=Bn(o),p=t.displayMode==="embedded",i={chatId:Ae(t),open:!1,fullPageOpen:p,myChatsOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1,sourcePanelOpen:!1,sourcePanelTitle:null,attachedFile:null},l=document.createElement("div");l.dataset.chatWidgetHost="true",t.mount.appendChild(l);let c=l.attachShadow({mode:"open"});Bt(c,t.theme);let u=a("div",`kp-chat-widget ${t.position}`);u.lang=o,u.dir=r?"rtl":"ltr",p&&(u.classList.add("kp-chat-widget-embedded"),Ft(!0)),r&&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 P=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 G=a("div","kp-title-wrap"),I=a("h2","kp-title",t.title),Xt=a("div","kp-subtitle",t.subtitle);G.append(I,Xt);let fe=a("button","kp-close","\xD7");fe.type="button",fe.setAttribute("aria-label",t.closeAriaLabel),P.append(S,G,fe);let he=a("div","kp-body"),Te=a("div","kp-hero"),Gt=a("div","kp-hero-icon","\u2726"),Jt=a("div","kp-hero-text",t.welcomeMessage);Te.append(Gt,Jt);let Xe=a("div","kp-footer"),Ee=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 Ie=a("div","kp-attachment-badge");Ie.style.display="none";let Re=a("button","kp-send","\u279C");Re.type="submit",Re.setAttribute("aria-label",n.send);let Qt=a("div","kp-note",n.authTokenForwarded);Ee.append(me,q,$,Re),Xe.append(Ie,Ee,Qt),m.append(P,he,Xe),p||u.append(g,h,m),c.appendChild(u),he.appendChild(Te);let Ge=a("div","kp-suggestions");he.appendChild(Ge);let be=a("section","kp-my-chats-sheet"),Je=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),Je.append(ke,xe);let Qe=a("div","kp-my-chats-body"),Zt=a("div","kp-my-chats-section-label",n.recentActivity),Ze=a("div","kp-my-chats-list"),en=a("div","kp-my-chats-section-label",n.pinnedCollections),et=a("div","kp-my-chats-list");Qe.append(Zt,Ze,en,et),be.append(Je,Qe),m.appendChild(be);let z={body:he,input:$,suggestions:Ge,hero:Te,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 tt=a("div","kp-full-page-shell"),$e=a("div","kp-full-page-header"),nt=a("div","kp-full-page-brand"),tn=a("div","kp-full-page-brand-mark","\u2726"),nn=a("div","kp-full-page-brand-text",t.title);nt.append(tn,nn);let at=a("div","kp-full-page-header-actions"),an=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),at.append(an,ye),$e.append(nt,at),t.embedded.showHeader||$e.classList.add("kp-hidden");let ot=a("div","kp-full-page-content"),st=a("aside","kp-full-page-sidebar"),ze=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);ze.type="button";let it=a("div","kp-full-page-search"),ie=a("input","kp-full-page-search-input");ie.type="search",ie.placeholder=n.searchChat;let on=a("span","kp-full-page-search-icon","\u2315");it.append(ie,on);let sn=a("div","kp-full-page-section-label",n.recentActivity),rt=a("div","kp-full-page-recent-list"),rn=a("div","kp-full-page-section-label",n.pinnedCollections),lt=a("div","kp-full-page-pinned-list");st.append(ze,it,sn,rt,rn,lt);let pt=a("main","kp-full-page-main"),dt=a("section","kp-full-page-panel"),He=a("div","kp-full-page-body"),Me=a("div","kp-full-page-hero"),ct=a("div","kp-full-page-hero-badge");ct.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 ln=a("div","kp-full-page-hero-text",t.welcomeMessage);Me.append(ct,ln);let ut=a("div","kp-suggestions kp-full-page-suggestions");He.append(Me,ut);let gt=a("div","kp-full-page-footer"),Ne=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 Oe=a("div","kp-attachment-badge kp-full-page-attachment-badge");Oe.style.display="none";let Ue=a("button","kp-send kp-full-page-send","\u279C");Ue.type="submit",Ue.setAttribute("aria-label",n.send);let pn=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Ne.append(ve,V,E,Ue),gt.append(Oe,Ne,pn),dt.append(He,gt),pt.appendChild(dt);let we=a("aside","kp-source-panel"),ft=a("div","kp-source-panel-header"),ht=a("div","kp-source-panel-title-wrap"),mt=a("div","kp-source-panel-title",n.allSourcesUsed),dn=a("div","kp-source-panel-subtitle",n.documentsAndReferences);ht.append(mt,dn);let Ce=a("button","kp-source-panel-close","\xD7");Ce.type="button",Ce.setAttribute("aria-label",n.closeSourcesPanel),ft.append(ht,Ce);let re=a("div","kp-source-panel-list"),cn=a("div","kp-source-panel-empty",n.noSources);re.appendChild(cn),we.append(ft,re),ot.append(st,pt,we),tt.append($e,ot),T.appendChild(tt),u.appendChild(T);let le=a("div","kp-citation-overlay");u.appendChild(le);let A={body:He,input:E,suggestions:ut,hero:Me,kind:"full-page"},M=()=>({...t,getAccessToken:i.accessTokenProvider}),bt=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}},J=s=>{let d=Ye(s)??n.untitledSource,f=(s.text||"").trim(),k=f,b=f.split(`
1822
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
1823
  `).trim())}let x=Xn(s.sourceDocument),y=[];(s.pageNumber||s.pageNumber===0)&&y.push(`
1824
1824
  <div class="meta-item">
@@ -1911,10 +1911,10 @@
1911
1911
  </div>
1912
1912
  </div>
1913
1913
  </div>
1914
- `,le.textContent="";let At=a("header","kp-citation-overlay-header"),Pt=a("div","kp-citation-overlay-brand");Pt.innerHTML=`
1914
+ `,le.textContent="";let Pt=a("header","kp-citation-overlay-header"),At=a("div","kp-citation-overlay-brand");At.innerHTML=`
1915
1915
  <span class="kp-citation-overlay-brand-logo">\u2726</span>
1916
1916
  <span>Knowledge Assistant Document Viewer</span>
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")}),At.append(Pt,Ae);let St=a("div","kp-citation-overlay-content"),Tt=a("aside","kp-citation-overlay-metadata-panel");Tt.innerHTML=vn;let ne=a("main","kp-citation-overlay-viewer-panel");if(ne.innerHTML=je,St.append(Tt,ne),le.append(At,St),!x){let Y=1,B=ne.querySelector(".document-sheet"),wn=ne.querySelector(".zoom-in-btn"),Cn=ne.querySelector(".zoom-out-btn"),Ln=ne.querySelector(".print-btn");B&&(wn?.addEventListener("click",()=>{Y<1.5&&(Y+=.1,B.style.transform=`scale(${Y})`)}),Cn?.addEventListener("click",()=>{Y>.6&&(Y-=.1,B.style.transform=`scale(${Y})`)}),Ln?.addEventListener("click",()=>{window.print()}))}le.classList.add("open")},pe=(s,d)=>{if(i.sourcePanelOpen=!0,i.sourcePanelTitle=d??n.allSourcesUsed,mt.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(Yn(f,n,()=>{J(f)}))},Q=()=>{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 kt(s,d,f){d.textContent=`Uploading ${s.name}...`,d.style.display="block",f.disabled=!0,Nt(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&&kt(s,Ie,$)}),ve.addEventListener("click",()=>{V.click()}),V.addEventListener("change",()=>{let s=V.files?.[0];s&&kt(s,Oe,E)});function Be(){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&&De.loadHistory(),queueMicrotask(()=>$.focus()))}function _(){if(p){Q();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 mn(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:J,onLike:()=>{},onDislike:()=>{}});return}_e(d),ge(d.body,"user",f,{strings:n,view:d,userName:await bt(),onShowSources:pe,onShowCitation:J,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 $n(t),x=i.attachedFile?[i.attachedFile.sourceUuid,...b]:b,y=await Rt(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:J,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:J,onLike:()=>{},onDislike:()=>{}})}}async function xt(s){let d=i.fullPageOpen?P:z;await N(s,d)}async function un(){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 yt(){if(p){Q();return}i.fullPageOpen&&(i.fullPageOpen=!1,T.classList.remove("open"),h.classList.remove("hidden"),Q())}function gn(){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 fn(){i.chatId=Pe(t),i.historyLoadedChatId=null,U(),ue(z),oe(z,t.initialSuggestions,async s=>{await N(s,z)}),O()}async function hn(){i.chatId=Pe(t),i.historyLoadedChatId=null,ue(P),Q(),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 zt(M());return i.chats=s,s}catch(s){return j(t,s),i.chats}finally{i.loadingChats=!1,K(),Le()}}async function mn(s){!t.endpoints.listChats&&!t.endpoints.createChat||i.chats.some(d=>d.chatId===i.chatId)||await Ht(M(),i.chatId,s?On(s,n.newChat):void 0)}async function bn(s){i.chatId=s,i.historyLoadedChatId=null,await Z(P,s),K()}async function kn(s){i.chatId=s,i.historyLoadedChatId=null,U(),await Z(z,s)}async function xn(){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 yn(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 vt(s){t.endpoints.updateChat&&yn(s,async d=>{let f=d.trim();if(!(!f||f===s.title))try{await qe(M(),s.chatId,{title:f}),await H()}catch(k){j(t,k)}})}async function wt(s){if(t.endpoints.deleteChat)try{await Mt(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(){jt(rt,lt,i,n,async s=>{await bn(s.chatId)},async s=>{await Ct(s)},async s=>{await vt(s)},async s=>{await wt(s)})}function Le(){jt(Ze,et,i,n,async s=>{await kn(s.chatId)},async s=>{await Ct(s)},async s=>{await vt(s)},async s=>{await wt(s)})}async function Ct(s){if(t.endpoints.updateChat)try{await qe(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>',_e(s),s.body.appendChild(f);let k=await $t(M(),d);return f.remove(),k.length>0&&(_e(s),qt(s.body,s.hero,s.suggestions),Nn(s.body,k,{strings:n,view:s,userName:await bt(),onShowSources:pe,onShowCitation:J,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 De={open:Be,close:_,toggle(){if(p){Be();return}if(i.open){_();return}Be()},destroy(){if(document.removeEventListener("keydown",Lt),l.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||Ft(!1)}},sendMessage:xt,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",()=>De.toggle()),fe.addEventListener("click",_),g.addEventListener("click",_),Ce.addEventListener("click",Q),ke.addEventListener("click",U),xe.addEventListener("click",U),v.addEventListener("click",s=>{if(s.stopPropagation(),!i.menuOpen){gn();return}O()}),w.addEventListener("click",fn),F.addEventListener("click",async()=>{await xn()}),R.addEventListener("click",()=>{if(O(),t.onOpenAssistantPage){_(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){_(),window.location.href=t.assistantPageUrl;return}un()}),ye.addEventListener("click",yt),ze.addEventListener("click",()=>{hn(),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")}}),Ee.addEventListener("submit",async s=>{s.preventDefault(),await xt($.value)}),Ne.addEventListener("submit",async s=>{s.preventDefault(),await N(E.value,P)});function Lt(s){if(s.key==="Escape"){if(i.sourcePanelOpen){Q();return}if(i.myChatsOpen){U();return}if(i.fullPageOpen){if(p)return;yt();return}i.open&&_()}}return document.addEventListener("keydown",Lt),De}async function $n(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 r=t==="bot"?jn(o,n.citations??[]):{displayText:o,citations:n.citations??[]},p=a("div",`kp-message-row ${t}`),i=Hn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),l=a("div",`kp-bubble ${t}`),c=a("div","kp-bubble-content");Gn(c,r.displayText),l.appendChild(c);let u=r.citations;if(u.length){let g=a("div","kp-meta",n.strings.citationsAttached(u.length));l.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=_n(v,n.strings);L.addEventListener("click",async()=>{n.onShowCitation(v)}),A.appendChild(L)}let S=Kn(n.strings);S.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),A.appendChild(S),h.append(m,A),l.appendChild(h)}return t==="bot"&&l.appendChild(zn(r.displayText,n.strings,n.onLike,n.onDislike,n.initialFeedback)),t==="user"?p.append(l,i):p.append(i,l),e.appendChild(p),e.scrollTop=e.scrollHeight,p}function zn(e,t,o,n,r){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 l=a("button","kp-message-action","\u{1F44D}");l.type="button",l.setAttribute("aria-label",t.helpful),r===!0&&l.classList.add("active"),l.addEventListener("click",()=>{l.classList.toggle("active"),c.classList.remove("active"),l.classList.contains("active")&&o&&o()});let c=a("button","kp-message-action","\u{1F44E}");return c.type="button",c.setAttribute("aria-label",t.notHelpful),r===!1&&c.classList.add("active"),c.addEventListener("click",()=>{c.classList.toggle("active"),l.classList.remove("active"),c.classList.contains("active")&&n&&n()}),p.append(i,l,c),p}function Hn(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 Mn(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 oe(e,t,o){Mn(e.suggestions,t,async n=>{e.input.value=n,await o(n)})}function qt(e,t,o){let n=new Set([t,o]);for(let r of Array.from(e.children))n.has(r)||r.remove()}function _e(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),qt(e.body,e.hero,e.suggestions),e.input.value=""}function Nn(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 jt(e,t,o,n,r,p,i,l){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);Wt(e,g,o.chatId,n,r,p,i,l),Wt(t,u,o.chatId,n,r,p,i,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 Wt(e,t,o,n,r,p,i,l){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 l(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 r(c)}),u.addEventListener("keydown",async w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),await r(c))}),u.addEventListener("blur",()=>{h.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function On(e,t){return e.trim().slice(0,60)||t}function Ke(e){return e.toLowerCase().split("-")[0]||"en"}function Un(e){let t=Dt.en;return Dt[Ke(e)]??t}function Bn(e){return["ar","fa","he","ur"].includes(Ke(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 Ye(e){if(e.knowledgeName?.trim())return e.knowledgeName.trim();if(e.text){let t=e.text.split(`
1917
+ `;let Pe=a("button","kp-citation-overlay-close","\xD7");Pe.type="button",Pe.setAttribute("aria-label","Close document preview"),Pe.addEventListener("click",()=>{le.classList.remove("open")}),Pt.append(At,Pe);let St=a("div","kp-citation-overlay-content"),Tt=a("aside","kp-citation-overlay-metadata-panel");Tt.innerHTML=vn;let ne=a("main","kp-citation-overlay-viewer-panel");if(ne.innerHTML=je,St.append(Tt,ne),le.append(Pt,St),!x){let Y=1,B=ne.querySelector(".document-sheet"),wn=ne.querySelector(".zoom-in-btn"),Cn=ne.querySelector(".zoom-out-btn"),Ln=ne.querySelector(".print-btn");B&&(wn?.addEventListener("click",()=>{Y<1.5&&(Y+=.1,B.style.transform=`scale(${Y})`)}),Cn?.addEventListener("click",()=>{Y>.6&&(Y-=.1,B.style.transform=`scale(${Y})`)}),Ln?.addEventListener("click",()=>{window.print()}))}le.classList.add("open")},pe=(s,d)=>{if(i.sourcePanelOpen=!0,i.sourcePanelTitle=d??n.allSourcesUsed,mt.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(Yn(f,n,()=>{J(f)}))},Q=()=>{i.sourcePanelOpen=!1,i.sourcePanelTitle=null,we.classList.remove("open")};oe(z,t.initialSuggestions,async s=>{await N(s,z)}),oe(A,t.initialSuggestions,async s=>{await N(s,A)}),K(),Le(),p&&(H(),t.rag.loadHistoryOnOpen&&Z(A,i.chatId));function kt(s,d,f){d.textContent=`Uploading ${s.name}...`,d.style.display="block",f.disabled=!0,Nt(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&&kt(s,Ie,$)}),ve.addEventListener("click",()=>{V.click()}),V.addEventListener("change",()=>{let s=V.files?.[0];s&&kt(s,Oe,E)});function Be(){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&&De.loadHistory(),queueMicrotask(()=>$.focus()))}function _(){if(p){Q();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 mn(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:J,onLike:()=>{},onDislike:()=>{}});return}_e(d),ge(d.body,"user",f,{strings:n,view:d,userName:await bt(),onShowSources:pe,onShowCitation:J,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 $n(t),x=i.attachedFile?[i.attachedFile.sourceUuid,...b]:b,y=await Rt(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:J,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:J,onLike:()=>{},onDislike:()=>{}})}}async function xt(s){let d=i.fullPageOpen?A:z;await N(s,d)}async function un(){if(p){i.fullPageOpen=!0,T.classList.add("open"),await H(),await Z(A,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(A,i.chatId),queueMicrotask(()=>E.focus())}function yt(){if(p){Q();return}i.fullPageOpen&&(i.fullPageOpen=!1,T.classList.remove("open"),h.classList.remove("hidden"),Q())}function gn(){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 fn(){i.chatId=Ae(t),i.historyLoadedChatId=null,U(),ue(z),oe(z,t.initialSuggestions,async s=>{await N(s,z)}),O()}async function hn(){i.chatId=Ae(t),i.historyLoadedChatId=null,ue(A),Q(),oe(A,t.initialSuggestions,async s=>{await N(s,A)}),K()}async function H(){if(!t.endpoints.listChats)return K(),Le(),[];i.loadingChats=!0,K(),Le();try{let s=await zt(M());return i.chats=s,s}catch(s){return j(t,s),i.chats}finally{i.loadingChats=!1,K(),Le()}}async function mn(s){!t.endpoints.listChats&&!t.endpoints.createChat||i.chats.some(d=>d.chatId===i.chatId)||await Ht(M(),i.chatId,s?On(s,n.newChat):void 0)}async function bn(s){i.chatId=s,i.historyLoadedChatId=null,await Z(A,s),K()}async function kn(s){i.chatId=s,i.historyLoadedChatId=null,U(),await Z(z,s)}async function xn(){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 yn(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 vt(s){t.endpoints.updateChat&&yn(s,async d=>{let f=d.trim();if(!(!f||f===s.title))try{await qe(M(),s.chatId,{title:f}),await H()}catch(k){j(t,k)}})}async function wt(s){if(t.endpoints.deleteChat)try{await Mt(M(),s.chatId),i.chatId===s.chatId&&(i.chatId=Ae(t),i.historyLoadedChatId=null,ue(z),ue(A)),await H()}catch(d){j(t,d)}}function K(){jt(rt,lt,i,n,async s=>{await bn(s.chatId)},async s=>{await Ct(s)},async s=>{await vt(s)},async s=>{await wt(s)})}function Le(){jt(Ze,et,i,n,async s=>{await kn(s.chatId)},async s=>{await Ct(s)},async s=>{await vt(s)},async s=>{await wt(s)})}async function Ct(s){if(t.endpoints.updateChat)try{await qe(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>',_e(s),s.body.appendChild(f);let k=await $t(M(),d);return f.remove(),k.length>0&&(_e(s),qt(s.body,s.hero,s.suggestions),Nn(s.body,k,{strings:n,view:s,userName:await bt(),onShowSources:pe,onShowCitation:J,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 De={open:Be,close:_,toggle(){if(p){Be();return}if(i.open){_();return}Be()},destroy(){if(document.removeEventListener("keydown",Lt),l.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||Ft(!1)}},sendMessage:xt,setAccessTokenProvider(s){i.accessTokenProvider=s},getChatId(){return i.chatId},loadChats(){return H()},async loadHistory(){let s=i.fullPageOpen?A:z;return Z(s,i.chatId)}};h.addEventListener("click",()=>De.toggle()),fe.addEventListener("click",_),g.addEventListener("click",_),Ce.addEventListener("click",Q),ke.addEventListener("click",U),xe.addEventListener("click",U),v.addEventListener("click",s=>{if(s.stopPropagation(),!i.menuOpen){gn();return}O()}),w.addEventListener("click",fn),F.addEventListener("click",async()=>{await xn()}),R.addEventListener("click",()=>{if(O(),t.onOpenAssistantPage){_(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){_(),window.location.href=t.assistantPageUrl;return}un()}),ye.addEventListener("click",yt),ze.addEventListener("click",()=>{hn(),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")}}),Ee.addEventListener("submit",async s=>{s.preventDefault(),await xt($.value)}),Ne.addEventListener("submit",async s=>{s.preventDefault(),await N(E.value,A)});function Lt(s){if(s.key==="Escape"){if(i.sourcePanelOpen){Q();return}if(i.myChatsOpen){U();return}if(i.fullPageOpen){if(p)return;yt();return}i.open&&_()}}return document.addEventListener("keydown",Lt),De}async function $n(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 Ae(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 r=t==="bot"?jn(o,n.citations??[]):{displayText:o,citations:n.citations??[]},p=a("div",`kp-message-row ${t}`),i=Hn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),l=a("div",`kp-bubble ${t}`),c=a("div","kp-bubble-content");Gn(c,r.displayText),l.appendChild(c);let u=r.citations;if(u.length){let g=a("div","kp-meta",n.strings.citationsAttached(u.length));l.appendChild(g);let h=a("div","kp-source-preview"),m=a("div","kp-source-preview-title",n.strings.sourcesUsed),P=a("div","kp-source-preview-list");for(let v of u.slice(0,2)){let L=_n(v,n.strings);L.addEventListener("click",async()=>{n.onShowCitation(v)}),P.appendChild(L)}let S=Kn(n.strings);S.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),P.appendChild(S),h.append(m,P),l.appendChild(h)}return t==="bot"&&l.appendChild(zn(r.displayText,n.strings,n.onLike,n.onDislike,n.initialFeedback)),t==="user"?p.append(l,i):p.append(i,l),e.appendChild(p),e.scrollTop=e.scrollHeight,p}function zn(e,t,o,n,r){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 l=a("button","kp-message-action","\u{1F44D}");l.type="button",l.setAttribute("aria-label",t.helpful),r===!0&&l.classList.add("active"),l.addEventListener("click",()=>{l.classList.toggle("active"),c.classList.remove("active"),l.classList.contains("active")&&o&&o()});let c=a("button","kp-message-action","\u{1F44E}");return c.type="button",c.setAttribute("aria-label",t.notHelpful),r===!1&&c.classList.add("active"),c.addEventListener("click",()=>{c.classList.toggle("active"),l.classList.remove("active"),c.classList.contains("active")&&n&&n()}),p.append(i,l,c),p}function Hn(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 Mn(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 oe(e,t,o){Mn(e.suggestions,t,async n=>{e.input.value=n,await o(n)})}function qt(e,t,o){let n=new Set([t,o]);for(let r of Array.from(e.children))n.has(r)||r.remove()}function _e(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),qt(e.body,e.hero,e.suggestions),e.input.value=""}function Nn(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 jt(e,t,o,n,r,p,i,l){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);Wt(e,g,o.chatId,n,r,p,i,l),Wt(t,u,o.chatId,n,r,p,i,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 Wt(e,t,o,n,r,p,i,l){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 P=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 l(c)}),P.append(S,v,L),h.append(m,P),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 r(c)}),u.addEventListener("keydown",async w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),await r(c))}),u.addEventListener("blur",()=>{h.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function On(e,t){return e.trim().slice(0,60)||t}function Ke(e){return e.toLowerCase().split("-")[0]||"en"}function Un(e){let t=Dt.en;return Dt[Ke(e)]??t}function Bn(e){return["ar","fa","he","ur"].includes(Ke(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 Ye(e){if(e.knowledgeName?.trim())return e.knowledgeName.trim();if(e.text){let t=e.text.split(`
1918
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 jn(e,t){let o=Wn(e);return{displayText:o.displayText,citations:t.length>0?Vn(t,o.citations):o.citations}}function Wn(e){let o=Vt(e).split(`
1919
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 r=o.slice(0,n).join(`
1920
1920
  `).trimEnd(),p=o.slice(n+1).join(`