@nabeh/chat-widget 0.1.8 → 0.1.9

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/index.d.cts CHANGED
@@ -77,6 +77,7 @@ type ChatWidgetConfig = {
77
77
  deleteLastQa?: string;
78
78
  feedback?: string;
79
79
  upload?: string;
80
+ index?: string;
80
81
  };
81
82
  mount?: HTMLElement;
82
83
  displayMode?: ChatWidgetDisplayMode;
package/dist/index.d.ts CHANGED
@@ -77,6 +77,7 @@ type ChatWidgetConfig = {
77
77
  deleteLastQa?: string;
78
78
  feedback?: string;
79
79
  upload?: string;
80
+ index?: string;
80
81
  };
81
82
  mount?: HTMLElement;
82
83
  displayMode?: ChatWidgetDisplayMode;
@@ -1,4 +1,4 @@
1
- "use strict";var ChatWidget=(()=>{var je=Object.defineProperty;var wn=Object.getOwnPropertyDescriptor;var Cn=Object.getOwnPropertyNames;var Ln=Object.prototype.hasOwnProperty;var An=(e,t)=>{for(var o in t)je(e,o,{get:t[o],enumerable:!0})},Pn=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Cn(t))!Ln.call(e,r)&&r!==o&&je(e,r,{get:()=>t[r],enumerable:!(n=wn(t,r))||n.enumerable});return e};var Sn=e=>Pn(je({},"__esModule",{value:!0}),e);var Qn={};An(Qn,{createChatWidget:()=>Ft});function Tt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function We(e,t){let o={...e};for(let n of Object.keys(t)){let r=t[n],d=o[n];if(Tt(d)&&Tt(r)){o[n]=We(d,r);continue}r!==void 0&&(o[n]=r)}return o}function Et(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 G(e,t,o){return{"Content-Type":"application/json",...e.customHeaders,...o?{"X-Chat-User-Context":o}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function W(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function 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 It(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await W(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:G(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:Q,value:R}=await c.read();if(Q)break;R&&(u+=new TextDecoder("utf-8").decode(R,{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??[],y=m?.page_numbers??[],L=m?.sheet_names??[],w=m?.row_numbers??[],V=m?.knowledge_names??[],$=A.map((Q,R)=>({sourceDocument:Q,score:S[R]??null,pageNumber:y[R]??null,sheetName:L[R]??null,rowNumber:w[R]??null,knowledgeName:V[R]??null}));return{chatId:t.chatId,answer:h.answer,suggestions:[],citations:$}}async function Rt(e,t){if(!e.endpoints.history)return[];let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),d=/(\{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(d,{method:"GET",headers:G(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 $t(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,o=await W(e),n=await fetch(de(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:G(e,t,o)});if(!n.ok)throw new Error(`Chat list endpoint returned ${n.status}.`);let r=await n.json(),d=Array.isArray(r)?r:r&&typeof r=="object"?r.chats??r.data??r.items??[]:[];return Array.isArray(d)?d.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 zt(e,t,o){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let r=e.getAccessToken?await e.getAccessToken():null,d=await W(e),i=await fetch(de(e.apiBaseUrl,n),{method:"POST",headers:G(e,r,d),body:JSON.stringify({chatId:t,...o?{title:o}:{}})});if(!i.ok)throw new Error(`Create chat endpoint returned ${i.status}.`)}async function Fe(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,r=await W(e),d=ae(e,e.endpoints.updateChat,{chatId:t}),i=await fetch(d,{method:"PUT",headers:G(e,n,r),body:JSON.stringify(o)});if(!i.ok)throw new Error(`Update chat endpoint returned ${i.status}.`)}async function Ut(e,t){if(!e.endpoints.deleteChat)return;let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),r=ae(e,e.endpoints.deleteChat,{chatId:t}),d=await fetch(r,{method:"DELETE",headers:G(e,o,n)});if(!d.ok)throw new Error(`Delete chat endpoint returned ${d.status}.`)}function F(e,t){let o=Et(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,d=await W(e),i=ae(e,e.endpoints.feedback,{chatId:t}),l=await fetch(i,{method:"POST",headers:G(e,r,d),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 W(e),r=ae(e,e.endpoints.upload),d=new FormData;d.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:d});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 qe={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:qe,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0,assistantAvatarUrl:""};function Ht(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=We(qe,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,assistantAvatarUrl:e.assistantAvatarUrl??C.assistantAvatarUrl,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 Mt="kp-chat-widget-styles";function Ot(e,t){if(e.getElementById(Mt))return;let o=document.createElement("style");o.id=Mt,o.textContent=Tn(t),e.appendChild(o)}function Tn(e){return`
1
+ "use strict";var ChatWidget=(()=>{var Fe=Object.defineProperty;var Ln=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var Pn=Object.prototype.hasOwnProperty;var Sn=(e,t)=>{for(var a in t)Fe(e,a,{get:t[a],enumerable:!0})},Tn=(e,t,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of An(t))!Pn.call(e,r)&&r!==a&&Fe(e,r,{get:()=>t[r],enumerable:!(n=Ln(t,r))||n.enumerable});return e};var En=e=>Tn(Fe({},"__esModule",{value:!0}),e);var ea={};Sn(ea,{createChatWidget:()=>Ft});function Et(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function qe(e,t){let a={...e};for(let n of Object.keys(t)){let r=t[n],p=a[n];if(Et(p)&&Et(r)){a[n]=qe(p,r);continue}r!==void 0&&(a[n]=r)}return a}function It(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function ue(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}function Z(e,t,a){return{"Content-Type":"application/json",...e.customHeaders,...a?{"X-Chat-User-Context":a}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function _(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function Q(e,t,a={}){let n=t.replace(/\{chatId\}/g,encodeURIComponent(a.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(a.chatId??""));return ue(e.apiBaseUrl,n)}async function $(e,t){let a=`Failed to ${t}. Please try again.`;e.status===400?a="Invalid request. Please check your input and try again.":e.status===401?a="Authentication failed. Please log in again.":e.status===403?a="You do not have permission to perform this action.":e.status===404?a="The requested resource was not found.":e.status===429?a="Too many requests. Please wait a moment and try again.":e.status>=500&&(a="The server is currently experiencing issues. Please try again later.");try{let n=await e.json();n&&typeof n=="object"&&(typeof n.message=="string"?a=n.message:typeof n.error=="string"&&(a=n.error))}catch{}throw new Error(a)}async function Rt(e,t){let a=e.getAccessToken?await e.getAccessToken():null,n=await _(e),r=Q(e,e.endpoints.ask,{chatId:t.chatId}),p={message:t.message,query:t.message,chat_id:t.chatId,knowledgeNames:t.knowledgeNames,knowledge_names:t.knowledgeNames,editLastQa:t.editLastQa??!1,edit_last_qa:t.editLastQa??!1,enableReferences:t.enableReferences??!0,enable_references:t.enableReferences??!0},s=await fetch(r,{method:"POST",headers:Z(e,a,n),body:JSON.stringify(p)});s.ok||await $(s,"send message");let d=s.body?.getReader(),u="";if(d)for(;;){let{done:T,value:E}=await d.read();if(T)break;E&&(u+=new TextDecoder("utf-8").decode(E,{stream:!0}))}else u=await s.text();let c;try{c=JSON.parse(u)}catch{return{chatId:t.chatId,answer:u,suggestions:[],citations:[]}}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 g=c[0];if(!g?.answer||typeof g.answer!="string")throw new Error("Chat backend response is missing a valid answer.");let f=g.content,m=f?.source_documents??[],A=f?.scores??[],S=f?.page_numbers??[],y=f?.sheet_names??[],L=f?.row_numbers??[],w=f?.knowledge_names??[],V=m.map((T,E)=>({sourceDocument:T,score:A[E]??null,pageNumber:S[E]??null,sheetName:y[E]??null,rowNumber:L[E]??null,knowledgeName:w[E]??null}));return{chatId:t.chatId,answer:g.answer,suggestions:[],citations:V}}async function zt(e,t){if(!e.endpoints.history)return[];let a=e.getAccessToken?await e.getAccessToken():null,n=await _(e),p=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?Q(e,e.endpoints.history,{chatId:t}):(()=>{let c=new URL(ue(e.apiBaseUrl,e.endpoints.history));return c.searchParams.set("chat_id",t),c.toString()})(),s=await fetch(p,{method:"GET",headers:Z(e,a,n)});s.ok||await $(s,"fetch chat history");let d=await s.json(),u=Array.isArray(d)?d:d&&typeof d=="object"?d.history??d.messages??d.data??[]:[];return Array.isArray(u)?u.map(c=>{if(!c||typeof c!="object")return null;let g=c;if(typeof g.question=="string"&&typeof g.answer=="string")return[{role:"user",text:g.question},{role:"assistant",text:g.answer}];let f=g.role??g.type??g.sender??g.author,m=g.text??g.message??g.content??g.answer;if(typeof m!="string")return null;let A=typeof f=="string"?f.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(c=>!!c):[]}async function Mt(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,a=await _(e),n=await fetch(ue(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:Z(e,t,a)});n.ok||await $(n,"fetch chats");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(s=>{if(!s||typeof s!="object")return null;let d=s,u=d.chatId??d.chat_id??d.id,c=d.title??d.name??d.chatId;if(typeof u!="string"||typeof c!="string")return null;let g=typeof d.createdAt=="string"?d.createdAt:typeof d.created_at=="string"?d.created_at:null,f=typeof d.updatedAt=="string"?d.updatedAt:typeof d.updated_at=="string"?d.updated_at:null,m={chatId:u,title:c,pinned:typeof d.pinned=="boolean"?d.pinned:!1};return g&&(m.createdAt=g),f&&(m.updatedAt=f),m}).filter(s=>!!s):[]}async function Ut(e,t,a){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let r=e.getAccessToken?await e.getAccessToken():null,p=await _(e),s=await fetch(ue(e.apiBaseUrl,n),{method:"POST",headers:Z(e,r,p),body:JSON.stringify({chatId:t,chat_id:t,...a?{title:a}:{}})});s.ok||await $(s,"create chat")}async function Ve(e,t,a){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,r=await _(e),p=Q(e,e.endpoints.updateChat,{chatId:t}),s=await fetch(p,{method:"PUT",headers:Z(e,n,r),body:JSON.stringify(a)});s.ok||await $(s,"update chat")}async function Ht(e,t){if(!e.endpoints.deleteChat)return;let a=e.getAccessToken?await e.getAccessToken():null,n=await _(e),r=Q(e,e.endpoints.deleteChat,{chatId:t}),p=await fetch(r,{method:"DELETE",headers:Z(e,a,n)});p.ok||await $(p,"delete chat")}function F(e,t){let a=It(t);return e.onError?.(a),a}async function ge(e,t,a,n){if(!e.endpoints.feedback)return;let r=e.getAccessToken?await e.getAccessToken():null,p=await _(e),s=Q(e,e.endpoints.feedback,{chatId:t}),d=await fetch(s,{method:"POST",headers:Z(e,r,p),body:JSON.stringify({message:a,isLike:n})});d.ok||await $(d,"submit feedback")}async function $t(e,t){if(!e.endpoints.upload)throw new Error("Upload endpoint is not configured.");let a=e.getAccessToken?await e.getAccessToken():null,n=await _(e),r=Q(e,e.endpoints.upload),p=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`kp-src-${Date.now()}-${Math.random().toString(36).slice(2,10)}`,s=new FormData;s.append("source_uuid",p),s.append("file",t),s.append("organizations","string"),s.append("functional_topics","string"),s.append("content_type","string"),s.append("publication_date","string"),s.append("arabic_title","string"),s.append("confidentiality","Secret"),s.append("english_title","string"),s.append("external_document_id","string"),s.append("external_organizations","string"),s.append("external_contributors","string"),s.append("geographic_classification","string"),s.append("validity_period","0"),s.append("primary_contact_person","string"),s.append("arabic_summary","string"),s.append("callback_url","string"),s.append("vision_2030_alignment","string"),s.append("english_summary","string"),s.append("contributors","string"),s.append("tags","string"),s.append("thematic_topics","string"),s.append("file_language","string");let d={...e.customHeaders,...n?{"X-Chat-User-Context":n}:{},...a?{Authorization:`Bearer ${a}`}:{}},u=await fetch(r,{method:"POST",headers:d,body:s});if(u.ok||await $(u,"upload file"),p&&e.endpoints.index){let g=Q(e,e.endpoints.index),f=await fetch(g,{method:"POST",headers:{...d,"Content-Type":"application/json"},body:JSON.stringify({callback_url:"https://example.com/",source_uuid:p,force_reindex:!1})});f.ok||await $(f,"index file")}let c={source_uuid:p};try{c={...c,...await u.json()}}catch{}return c}var Ke={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:Ke,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0,assistantAvatarUrl:""};function Nt(e){if(!e.apiBaseUrl?.trim())throw new Error("Chat widget config requires a non-empty apiBaseUrl.");if(!e.endpoints?.ask?.trim())throw new Error("Chat widget config requires endpoints.ask to be provided.");let t=e.mount??document.body,a=qe(Ke,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,assistantAvatarUrl:e.assistantAvatarUrl??C.assistantAvatarUrl,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:a,getAccessToken:e.getAccessToken,getUserContext:e.getUserContext,onOpen:e.onOpen,onClose:e.onClose,onError:e.onError,onOpenAssistantPage:e.onOpenAssistantPage}}function o(e,t,a){let n=document.createElement(e);return t&&(n.className=t),a!==void 0&&(n.textContent=a),n}var Bt="kp-chat-widget-styles";function Ot(e,t){if(e.getElementById(Bt))return;let a=document.createElement("style");a.id=Bt,a.textContent=In(t),e.appendChild(a)}function In(e){return`
2
2
  :host {
3
3
  all: initial;
4
4
  }
@@ -1237,9 +1237,6 @@
1237
1237
  background: #ffffff;
1238
1238
  }
1239
1239
 
1240
- .kp-rtl .kp-form {
1241
- flex-direction: row-reverse;
1242
- }
1243
1240
 
1244
1241
  .kp-input {
1245
1242
  flex: 1;
@@ -1346,24 +1343,65 @@
1346
1343
  }
1347
1344
  }
1348
1345
 
1346
+ .kp-full-page-menu-btn {
1347
+ display: none;
1348
+ background: none;
1349
+ border: none;
1350
+ font-size: 24px;
1351
+ color: #374151;
1352
+ cursor: pointer;
1353
+ margin-inline-end: 12px;
1354
+ padding: 4px;
1355
+ line-height: 1;
1356
+ }
1357
+
1349
1358
  @media (max-width: 860px) {
1359
+ .kp-full-page-menu-btn {
1360
+ display: block;
1361
+ }
1362
+
1350
1363
  .kp-full-page-content {
1351
- grid-template-columns: 1fr;
1352
- grid-template-rows: auto 1fr;
1364
+ display: flex;
1365
+ flex-direction: column;
1353
1366
  }
1354
1367
 
1355
1368
  .kp-full-page-content:has(.kp-source-panel.open) {
1369
+ display: grid;
1356
1370
  grid-template-columns: 1fr;
1357
- grid-template-rows: auto 1fr auto;
1371
+ grid-template-rows: 1fr auto;
1358
1372
  }
1359
1373
 
1360
1374
  .kp-full-page-sidebar {
1375
+ position: fixed;
1376
+ top: 0;
1377
+ left: -100%;
1378
+ width: 280px;
1379
+ height: 100%;
1380
+ max-height: 100vh !important;
1381
+ z-index: 1000;
1382
+ background: #ffffff;
1383
+ box-shadow: 4px 0 24px rgba(0,0,0,0.1);
1384
+ transition: left 0.3s ease;
1361
1385
  flex: none;
1362
- max-height: 140px;
1386
+ }
1387
+
1388
+ .kp-full-page-sidebar.open {
1389
+ left: 0;
1390
+ }
1391
+
1392
+ .kp-rtl .kp-full-page-sidebar {
1393
+ left: auto;
1394
+ right: -100%;
1395
+ transition: right 0.3s ease;
1396
+ box-shadow: -4px 0 24px rgba(0,0,0,0.1);
1397
+ }
1398
+
1399
+ .kp-rtl .kp-full-page-sidebar.open {
1400
+ right: 0;
1363
1401
  }
1364
1402
 
1365
1403
  .kp-full-page-embedded .kp-full-page-sidebar {
1366
- max-height: none;
1404
+ /* max-height: none; handled by !important above */
1367
1405
  }
1368
1406
 
1369
1407
  .kp-source-panel.open {
@@ -1818,32 +1856,64 @@
1818
1856
  min-height: auto;
1819
1857
  }
1820
1858
  }
1821
- `}var Bt={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 Ft(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=Ht(e),o=_e(t.locale),n=Nn(t.locale),r=Hn(o),d=t.displayMode==="embedded",i={chatId:Pe(t),open:!1,fullPageOpen:d,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"});Ot(c,t.theme);let u=a("div",`kp-chat-widget ${t.position}`);u.lang=o,u.dir=r?"rtl":"ltr",d&&(u.classList.add("kp-chat-widget-embedded"),Wt(!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"),y=a("button","kp-tool-button kp-menu-trigger");y.type="button",y.setAttribute("aria-label",n.openChatActions),y.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 V=a("button","kp-dropdown-item",n.myChats);V.type="button";let $=a("button","kp-dropdown-item",n.openAssistant);$.type="button",L.append(w,V,$),S.append(y,L);let Q=a("div","kp-title-wrap"),R=a("h2","kp-title",t.title),_t=a("div","kp-subtitle",t.subtitle);Q.append(R,_t);let fe=a("button","kp-close","\xD7");fe.type="button",fe.setAttribute("aria-label",t.closeAriaLabel),A.append(S,Q,fe);let he=a("div","kp-body"),Se=a("div","kp-hero"),Kt=a("div","kp-hero-icon","\u2726"),Yt=a("div","kp-hero-text",t.welcomeMessage);Se.append(Kt,Yt);let Ye=a("div","kp-footer"),Te=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 me=a("button","kp-attach","\u{1F4CE}");me.type="button",me.setAttribute("aria-label","Attach file");let _=a("input","kp-file-input");_.type="file",_.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 Xt=a("div","kp-note",n.authTokenForwarded);Te.append(me,_,z,Ie),Ye.append(Ee,Te,Xt),m.append(A,he,Ye),d||u.append(g,h,m),c.appendChild(u),he.appendChild(Se);let Xe=a("div","kp-suggestions");he.appendChild(Xe);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 Ge=a("div","kp-my-chats-body"),Jt=a("div","kp-my-chats-section-label",n.recentActivity),Qe=a("div","kp-my-chats-list"),Gt=a("div","kp-my-chats-section-label",n.pinnedCollections),Ze=a("div","kp-my-chats-list");Ge.append(Jt,Qe,Gt,Ze),be.append(Je,Ge),m.appendChild(be);let U={body:he,input:z,suggestions:Xe,hero:Se,kind:"panel"},T=a("section","kp-full-page");d&&T.classList.add("kp-full-page-embedded","open"),T.setAttribute("role","dialog"),d||T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",`${t.title} page`);let et=a("div","kp-full-page-shell"),Re=a("div","kp-full-page-header"),tt=a("div","kp-full-page-brand"),Qt=a("div","kp-full-page-brand-mark","\u2726"),Zt=a("div","kp-full-page-brand-text",t.title);tt.append(Qt,Zt);let nt=a("div","kp-full-page-header-actions"),en=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),nt.append(en,ye),Re.append(tt,nt),t.embedded.showHeader||Re.classList.add("kp-hidden");let at=a("div","kp-full-page-content"),ot=a("aside","kp-full-page-sidebar"),$e=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);$e.type="button";let st=a("div","kp-full-page-search"),ie=a("input","kp-full-page-search-input");ie.type="search",ie.placeholder=n.searchChat;let tn=a("span","kp-full-page-search-icon","\u2315");st.append(ie,tn);let nn=a("div","kp-full-page-section-label",n.recentActivity),it=a("div","kp-full-page-recent-list"),an=a("div","kp-full-page-section-label",n.pinnedCollections),rt=a("div","kp-full-page-pinned-list");ot.append($e,st,nn,it,an,rt);let lt=a("main","kp-full-page-main"),pt=a("section","kp-full-page-panel"),ze=a("div","kp-full-page-body"),Ue=a("div","kp-full-page-hero"),dt=a("div","kp-full-page-hero-badge");dt.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 on=a("div","kp-full-page-hero-text",t.welcomeMessage);Ue.append(dt,on);let ct=a("div","kp-suggestions kp-full-page-suggestions");ze.append(Ue,ct);let ut=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 K=a("input","kp-file-input");K.type="file",K.style.display="none";let He=a("div","kp-attachment-badge kp-full-page-attachment-badge");He.style.display="none";let Me=a("button","kp-send kp-full-page-send","\u279C");Me.type="submit",Me.setAttribute("aria-label",n.send);let sn=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Ne.append(ve,K,E,Me),ut.append(He,Ne,sn),pt.append(ze,ut),lt.appendChild(pt);let we=a("aside","kp-source-panel"),gt=a("div","kp-source-panel-header"),ft=a("div","kp-source-panel-title-wrap"),ht=a("div","kp-source-panel-title",n.allSourcesUsed),rn=a("div","kp-source-panel-subtitle",n.documentsAndReferences);ft.append(ht,rn);let Ce=a("button","kp-source-panel-close","\xD7");Ce.type="button",Ce.setAttribute("aria-label",n.closeSourcesPanel),gt.append(ft,Ce);let re=a("div","kp-source-panel-list"),ln=a("div","kp-source-panel-empty",n.noSources);re.appendChild(ln),we.append(gt,re),at.append(ot,lt,we),et.append(Re,at),T.appendChild(et),u.appendChild(T);let le=a("div","kp-citation-overlay");u.appendChild(le);let P={body:ze,input:E,suggestions:ct,hero:Ue,kind:"full-page"},H=()=>({...t,getAccessToken:i.accessTokenProvider}),mt=async()=>{if(!t.getUserContext)return{displayName:null,avatarUrl:null};try{let s=await t.getUserContext();return s?{displayName:[s.firstName,s.lastName].filter(Boolean).join(" ")||s.displayName?.trim()||s.email?.trim()||s.userId?.trim()||null,avatarUrl:s.avatarUrl??null}:{displayName:null,avatarUrl:null}}catch{return{displayName:null,avatarUrl:null}}},Z=s=>{let p=Ke(s)??n.untitledSource,f=(s.text||"").trim(),k=f,x=f.split(`
1822
- `);if(x.length>1&&x[0]){let j=x[0].trim().replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();j&&(j===p||p.indexOf(j)!==-1||j.indexOf(p)!==-1)&&(k=x.slice(1).join(`
1823
- `).trim())}let b=_n(s.sourceDocument),v=[];(s.pageNumber||s.pageNumber===0)&&v.push(`
1859
+
1860
+ .kp-floating-menu-wrap {
1861
+ display: none;
1862
+ }
1863
+ .kp-floating-menu-btn {
1864
+ background: none;
1865
+ border: none;
1866
+ color: #374151;
1867
+ cursor: pointer;
1868
+ padding: 8px;
1869
+ display: flex;
1870
+ align-items: center;
1871
+ justify-content: center;
1872
+ border-radius: 8px;
1873
+ }
1874
+ .kp-floating-menu-btn:hover {
1875
+ background: rgba(0,0,0,0.05);
1876
+ }
1877
+ @media (max-width: 860px) {
1878
+ .kp-floating-menu-wrap {
1879
+ display: flex;
1880
+ padding: 12px 16px 0;
1881
+ flex: none;
1882
+ background: #ffffff;
1883
+ }
1884
+ .kp-full-page-embedded .kp-full-page-shell {
1885
+ gap: 0;
1886
+ }
1887
+ .kp-full-page-body {
1888
+ padding-top: 12px;
1889
+ }
1890
+ }
1891
+ `}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 Ft(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=Nt(e),a=Xe(t.locale),n=Nn(t.locale),r=Bn(a),p=t.displayMode==="embedded",s={chatId:Ee(t),open:!1,fullPageOpen:p,myChatsOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1,sourcePanelOpen:!1,sourcePanelTitle:null,attachedFile:null},d=document.createElement("div");d.dataset.chatWidgetHost="true",t.mount.appendChild(d);let u=d.attachShadow({mode:"open"});Ot(u,t.theme);let c=o("div",`kp-chat-widget ${t.position}`);c.lang=a,c.dir=r?"rtl":"ltr",p&&(c.classList.add("kp-chat-widget-embedded"),_t(!0)),r&&c.classList.add("kp-rtl");let g=o("div","kp-overlay"),f=o("button","kp-launcher");f.type="button",f.setAttribute("aria-label",t.launcherAriaLabel),f.innerHTML=['<span class="kp-star-cluster" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let m=o("section","kp-panel");m.setAttribute("role","dialog"),m.setAttribute("aria-modal","true"),m.setAttribute("aria-label",t.title);let A=o("div","kp-header"),S=o("div","kp-toolbar"),y=o("button","kp-tool-button kp-menu-trigger");y.type="button",y.setAttribute("aria-label",n.openChatActions),y.innerHTML=['<span class="kp-pencil-icon" aria-hidden="true"></span>','<span class="kp-chevron" aria-hidden="true">\u2304</span>'].join("");let L=o("div","kp-dropdown"),w=o("button","kp-dropdown-item",n.newChat);w.type="button";let V=o("button","kp-dropdown-item",n.myChats);V.type="button";let T=o("button","kp-dropdown-item",n.openAssistant);T.type="button",L.append(w,V,T),S.append(y,L);let E=o("div","kp-title-wrap"),Kt=o("h2","kp-title",t.title),Yt=o("div","kp-subtitle",t.subtitle);E.append(Kt,Yt);let me=o("button","kp-close","\xD7");me.type="button",me.setAttribute("aria-label",t.closeAriaLabel),A.append(S,E,me);let be=o("div","kp-body"),Ie=o("div","kp-hero"),Xt=o("div","kp-hero-icon","\u2726"),Jt=o("div","kp-hero-text",t.welcomeMessage);Ie.append(Xt,Jt);let Ge=o("div","kp-footer"),Re=o("form","kp-form"),M=o("input","kp-input");M.type="text",M.autocomplete="off",M.placeholder=t.inputPlaceholder,M.setAttribute("aria-label",t.inputPlaceholder);let ke=o("button","kp-attach","\u{1F4CE}");ke.type="button",ke.setAttribute("aria-label","Attach file");let K=o("input","kp-file-input");K.type="file",K.style.display="none";let ze=o("div","kp-attachment-badge");ze.style.display="none";let Me=o("button","kp-send","\u279C");Me.type="submit",Me.setAttribute("aria-label",n.send);let Gt=o("div","kp-note",n.authTokenForwarded);Re.append(ke,K,M,Me),Ge.append(ze,Re,Gt),m.append(A,be,Ge),p||c.append(g,f,m),u.appendChild(c),be.appendChild(Ie);let Qe=o("div","kp-suggestions");be.appendChild(Qe);let xe=o("section","kp-my-chats-sheet"),Ze=o("div","kp-my-chats-header"),ye=o("button","kp-my-chats-nav","\u2190");ye.type="button",ye.setAttribute("aria-label",n.back);let ve=o("button","kp-my-chats-nav kp-my-chats-close","\xD7");ve.type="button",ve.setAttribute("aria-label",n.close),Ze.append(ye,ve);let et=o("div","kp-my-chats-body"),Qt=o("div","kp-my-chats-section-label",n.recentActivity),tt=o("div","kp-my-chats-list"),Zt=o("div","kp-my-chats-section-label",n.pinnedCollections),nt=o("div","kp-my-chats-list");et.append(Qt,tt,Zt,nt),xe.append(Ze,et),m.appendChild(xe);let U={body:be,input:M,suggestions:Qe,hero:Ie,kind:"panel"},I=o("section","kp-full-page");p&&I.classList.add("kp-full-page-embedded","open"),I.setAttribute("role","dialog"),p||I.setAttribute("aria-modal","true"),I.setAttribute("aria-label",`${t.title} page`);let Ue=o("div","kp-full-page-shell"),we=o("div","kp-full-page-header"),at=o("div","kp-full-page-brand"),en=o("div","kp-full-page-brand-mark","\u2726"),tn=o("div","kp-full-page-brand-text",t.title),ie=o("button","kp-full-page-menu-btn");ie.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>',ie.type="button",ie.setAttribute("aria-label","Toggle sidebar"),ie.addEventListener("click",()=>{re.classList.toggle("open")}),at.append(ie,en,tn);let ot=o("div","kp-full-page-header-actions"),nn=o("div","kp-full-page-badge",n.assistantBadge),Ce=o("button","kp-full-page-close","\xD7");if(Ce.type="button",Ce.setAttribute("aria-label",n.closeAssistantPage),ot.append(nn,Ce),we.append(at,ot),!t.embedded.showHeader){we.classList.add("kp-hidden");let i=o("div","kp-floating-menu-wrap"),l=o("button","kp-floating-menu-btn");l.innerHTML='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>',l.type="button",l.setAttribute("aria-label","Toggle sidebar"),l.addEventListener("click",()=>{re.classList.toggle("open")}),i.append(l),Ue.insertBefore(i,we.nextSibling)}let st=o("div","kp-full-page-content"),re=o("aside","kp-full-page-sidebar"),He=o("button","kp-full-page-new-chat",`+ ${n.newChat}`);He.type="button";let it=o("div","kp-full-page-search"),le=o("input","kp-full-page-search-input");le.type="search",le.placeholder=n.searchChat;let an=o("span","kp-full-page-search-icon","\u2315");it.append(le,an);let on=o("div","kp-full-page-section-label",n.recentActivity),rt=o("div","kp-full-page-recent-list"),sn=o("div","kp-full-page-section-label",n.pinnedCollections),lt=o("div","kp-full-page-pinned-list");re.append(He,it,on,rt,sn,lt);let pt=o("main","kp-full-page-main"),dt=o("section","kp-full-page-panel"),$e=o("div","kp-full-page-body"),Ne=o("div","kp-full-page-hero"),ct=o("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 rn=o("div","kp-full-page-hero-text",t.welcomeMessage);Ne.append(ct,rn);let ut=o("div","kp-suggestions kp-full-page-suggestions");$e.append(Ne,ut);let gt=o("div","kp-full-page-footer"),Be=o("form","kp-form kp-full-page-form"),R=o("input","kp-input kp-full-page-input");R.type="text",R.autocomplete="off",R.placeholder=t.inputPlaceholder,R.setAttribute("aria-label",t.inputPlaceholder);let Le=o("button","kp-attach kp-full-page-attach","\u{1F4CE}");Le.type="button",Le.setAttribute("aria-label","Attach file");let Y=o("input","kp-file-input");Y.type="file",Y.style.display="none";let Oe=o("div","kp-attachment-badge kp-full-page-attachment-badge");Oe.style.display="none";let De=o("button","kp-send kp-full-page-send","\u279C");De.type="submit",De.setAttribute("aria-label",n.send);let ln=o("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Be.append(Le,Y,R,De),gt.append(Oe,Be,ln),dt.append($e,gt),pt.appendChild(dt);let Ae=o("aside","kp-source-panel"),ft=o("div","kp-source-panel-header"),ht=o("div","kp-source-panel-title-wrap"),mt=o("div","kp-source-panel-title",n.allSourcesUsed),pn=o("div","kp-source-panel-subtitle",n.documentsAndReferences);ht.append(mt,pn);let Pe=o("button","kp-source-panel-close","\xD7");Pe.type="button",Pe.setAttribute("aria-label",n.closeSourcesPanel),ft.append(ht,Pe);let pe=o("div","kp-source-panel-list"),dn=o("div","kp-source-panel-empty",n.noSources);pe.appendChild(dn),Ae.append(ft,pe),st.append(re,pt,Ae),Ue.append(we,st),I.appendChild(Ue),c.appendChild(I);let de=o("div","kp-citation-overlay");c.appendChild(de);let P={body:$e,input:R,suggestions:ut,hero:Ne,kind:"full-page"},N=()=>({...t,getAccessToken:s.accessTokenProvider}),bt=async()=>{if(!t.getUserContext)return{displayName:null,avatarUrl:null};try{let i=await t.getUserContext();return i?{displayName:[i.firstName,i.lastName].filter(Boolean).join(" ")||i.displayName?.trim()||i.email?.trim()||i.userId?.trim()||null,avatarUrl:i.avatarUrl??null}:{displayName:null,avatarUrl:null}}catch{return{displayName:null,avatarUrl:null}}},ee=i=>{let l=Je(i)??n.untitledSource,h=(i.text||"").trim(),k=h,x=h.split(`
1892
+ `);if(x.length>1&&x[0]){let W=x[0].trim().replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();W&&(W===l||l.indexOf(W)!==-1||W.indexOf(l)!==-1)&&(k=x.slice(1).join(`
1893
+ `).trim())}let b=Yn(i.sourceDocument),v=[];(i.pageNumber||i.pageNumber===0)&&v.push(`
1824
1894
  <div class="meta-item">
1825
1895
  <span class="meta-label">Page Number</span>
1826
- <span class="meta-value">${s.pageNumber}</span>
1896
+ <span class="meta-value">${i.pageNumber}</span>
1827
1897
  </div>
1828
- `),typeof s.score=="number"&&v.push(`
1898
+ `),typeof i.score=="number"&&v.push(`
1829
1899
  <div class="meta-item">
1830
1900
  <span class="meta-label">Relevance Score</span>
1831
- <span class="meta-value">${s.score.toFixed(2)}</span>
1901
+ <span class="meta-value">${i.score.toFixed(2)}</span>
1832
1902
  </div>
1833
- `),s.sheetName&&v.push(`
1903
+ `),i.sheetName&&v.push(`
1834
1904
  <div class="meta-item">
1835
1905
  <span class="meta-label">Sheet Name</span>
1836
- <span class="meta-value">${q(s.sheetName)}</span>
1906
+ <span class="meta-value">${q(i.sheetName)}</span>
1837
1907
  </div>
1838
- `),(s.rowNumber||s.rowNumber===0)&&v.push(`
1908
+ `),(i.rowNumber||i.rowNumber===0)&&v.push(`
1839
1909
  <div class="meta-item">
1840
1910
  <span class="meta-label">Row Number</span>
1841
- <span class="meta-value">${s.rowNumber}</span>
1911
+ <span class="meta-value">${i.rowNumber}</span>
1842
1912
  </div>
1843
- `),s.knowledgeName&&v.push(`
1913
+ `),i.knowledgeName&&v.push(`
1844
1914
  <div class="meta-item">
1845
1915
  <span class="meta-label">Database Source</span>
1846
- <span class="meta-value">${q(s.knowledgeName)}</span>
1916
+ <span class="meta-value">${q(i.knowledgeName)}</span>
1847
1917
  </div>
1848
1918
  `),v.push(`
1849
1919
  <div class="meta-item">
@@ -1858,7 +1928,7 @@
1858
1928
  <span class="meta-label">Language</span>
1859
1929
  <span class="meta-value">English</span>
1860
1930
  </div>
1861
- `);let I=v.join(""),D=k?q(k):"No text snippet available for this citation.",kn=`
1931
+ `);let z=v.join(""),j=k?q(k):"No text snippet available for this citation.",yn=`
1862
1932
  <div class="doc-badge-wrapper">
1863
1933
  <div class="doc-icon">\u{1F4C4}</div>
1864
1934
  <div class="doc-badge-info">
@@ -1867,7 +1937,7 @@
1867
1937
  </div>
1868
1938
 
1869
1939
  <div class="doc-title-section">
1870
- <h1>${q(p)}</h1>
1940
+ <h1>${q(l)}</h1>
1871
1941
  <div class="doc-source-type">Uploaded Knowledge Resource</div>
1872
1942
  </div>
1873
1943
 
@@ -1875,7 +1945,7 @@
1875
1945
 
1876
1946
  <div>
1877
1947
  <h3 class="meta-section-title">Retrieved Passage Snippet</h3>
1878
- <div class="summary-box">${D}</div>
1948
+ <div class="summary-box">${j}</div>
1879
1949
  </div>
1880
1950
 
1881
1951
  <div class="section-divider"></div>
@@ -1883,15 +1953,15 @@
1883
1953
  <div>
1884
1954
  <h3 class="meta-section-title">Metadata & Classification</h3>
1885
1955
  <div class="meta-list">
1886
- ${I}
1956
+ ${z}
1887
1957
  </div>
1888
1958
  </div>
1889
- `,De="";b?De=`<iframe src="${b}" title="Document Viewer"></iframe>`:De=`
1959
+ `,_e="";b?_e=`<iframe src="${b}" title="Document Viewer"></iframe>`:_e=`
1890
1960
  <div class="viewer-toolbar">
1891
- <div class="toolbar-left">${q(p)}</div>
1961
+ <div class="toolbar-left">${q(l)}</div>
1892
1962
  <div class="toolbar-center">
1893
1963
  <button class="toolbar-btn zoom-out-btn">\u2212</button>
1894
- <span class="page-indicator">Page ${s.pageNumber||1}</span>
1964
+ <span class="page-indicator">Page ${i.pageNumber||1}</span>
1895
1965
  <button class="toolbar-btn zoom-in-btn">+</button>
1896
1966
  </div>
1897
1967
  <div class="toolbar-right">
@@ -1901,25 +1971,25 @@
1901
1971
  <div class="viewer-body">
1902
1972
  <div class="document-sheet">
1903
1973
  <div class="sheet-header">
1904
- <span>${q(p)}</span>
1905
- <span>Page ${s.pageNumber||1}</span>
1974
+ <span>${q(l)}</span>
1975
+ <span>Page ${i.pageNumber||1}</span>
1906
1976
  </div>
1907
- <div class="sheet-content">${q(f||"No document content retrieved.")}</div>
1977
+ <div class="sheet-content">${q(h||"No document content retrieved.")}</div>
1908
1978
  <div class="sheet-footer">
1909
1979
  <span>Confidentiality: Public</span>
1910
1980
  <span>Knowledge Platform CB</span>
1911
1981
  </div>
1912
1982
  </div>
1913
1983
  </div>
1914
- `,le.textContent="";let Lt=a("header","kp-citation-overlay-header"),At=a("div","kp-citation-overlay-brand");At.innerHTML=`
1984
+ `,de.textContent="";let At=o("header","kp-citation-overlay-header"),Pt=o("div","kp-citation-overlay-brand");Pt.innerHTML=`
1915
1985
  <span class="kp-citation-overlay-brand-logo">\u2726</span>
1916
1986
  <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")}),Lt.append(At,Ae);let Pt=a("div","kp-citation-overlay-content"),St=a("aside","kp-citation-overlay-metadata-panel");St.innerHTML=kn;let ne=a("main","kp-citation-overlay-viewer-panel");if(ne.innerHTML=De,Pt.append(St,ne),le.append(Lt,Pt),!b){let J=1,j=ne.querySelector(".document-sheet"),xn=ne.querySelector(".zoom-in-btn"),yn=ne.querySelector(".zoom-out-btn"),vn=ne.querySelector(".print-btn");j&&(xn?.addEventListener("click",()=>{J<1.5&&(J+=.1,j.style.transform=`scale(${J})`)}),yn?.addEventListener("click",()=>{J>.6&&(J-=.1,j.style.transform=`scale(${J})`)}),vn?.addEventListener("click",()=>{window.print()}))}le.classList.add("open")},pe=(s,p)=>{if(i.sourcePanelOpen=!0,i.sourcePanelTitle=p??n.allSourcesUsed,ht.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(Vn(f,n,()=>{Z(f)}))},ee=()=>{i.sourcePanelOpen=!1,i.sourcePanelTitle=null,we.classList.remove("open")};oe(U,t.initialSuggestions,async s=>{await M(s,U)}),oe(P,t.initialSuggestions,async s=>{await M(s,P)}),X(),Le(),d&&(N(),t.rag.loadHistoryOnOpen&&te(P,i.chatId));function bt(s,p,f){p.textContent=`Uploading ${s.name}...`,p.style.display="block",f.disabled=!0,Nt(H(),s).then(k=>{i.attachedFile={name:s.name,sourceUuid:k.source_uuid},p.textContent=`\u{1F4CE} ${s.name} (Attached)`}).catch(k=>{let x=F(t,k);p.textContent=`Failed to upload: ${x.message}`,setTimeout(()=>{p.style.display="none",p.textContent=""},3e3)}).finally(()=>{f.disabled=!1,_.value="",K.value=""})}me.addEventListener("click",()=>{_.click()}),_.addEventListener("change",()=>{let s=_.files?.[0];s&&bt(s,Ee,z)}),ve.addEventListener("click",()=>{K.click()}),K.addEventListener("change",()=>{let s=K.files?.[0];s&&bt(s,He,E)});function Oe(){if(d){i.fullPageOpen=!0,T.classList.add("open");return}i.open||(i.open=!0,i.fullPageOpen=!1,B(),T.classList.remove("open"),h.classList.add("hidden"),g.classList.add("visible"),m.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&Be.loadHistory(),queueMicrotask(()=>z.focus()))}function Y(){if(d){ee();return}i.open&&(O(),B(),i.open=!1,h.classList.remove("hidden"),g.classList.remove("visible"),m.classList.remove("open"),t.onClose?.())}async function M(s,p){let f=s.trim();if(!f)return;p.input.value="";try{await gn(f)}catch(b){let v=F(t,b);ge(p.body,"bot",`${n.unableToCreateChat}: ${v.message}`,{strings:n,view:p,userName:null,assistantAvatarUrl:t.assistantAvatarUrl,onShowSources:pe,onShowCitation:Z,onLike:()=>{},onDislike:()=>{}});return}Ve(p);let k=await mt();ge(p.body,"user",f,{strings:n,view:p,userName:k.displayName,userAvatarUrl:k.avatarUrl,assistantAvatarUrl:t.assistantAvatarUrl,onShowSources:pe,onShowCitation:Z,onLike:()=>{},onDislike:()=>{}}),p.body.scrollTop=p.body.scrollHeight;let x=a("div","kp-loading",n.thinking);p.body.appendChild(x),p.body.scrollTop=p.body.scrollHeight;try{let b=await En(t),v=i.attachedFile?[i.attachedFile.sourceUuid,...b]:b,I=await It(H(),{message:f,chatId:i.chatId,knowledgeNames:v,...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});x.isConnected&&x.remove(),ge(p.body,"bot",I.answer,{strings:n,view:p,userName:k.displayName,userAvatarUrl:k.avatarUrl,assistantAvatarUrl:t.assistantAvatarUrl,citations:I.citations??[],onShowSources:pe,onShowCitation:Z,onLike:()=>{ce(t,i.chatId,I.answer,!0).catch(console.error)},onDislike:()=>{ce(t,i.chatId,I.answer,!1).catch(console.error)}}),i.historyLoadedChatId=null,await N(),I.suggestions?.length&&oe(p,I.suggestions,async D=>{await M(D,p)})}catch(b){let v=F(t,b);x.isConnected&&x.remove(),ge(p.body,"bot",`${n.requestFailed}: ${v.message}`,{strings:n,view:p,userName:k.displayName,userAvatarUrl:k.avatarUrl,assistantAvatarUrl:t.assistantAvatarUrl,onShowSources:pe,onShowCitation:Z,onLike:()=>{},onDislike:()=>{}})}}async function kt(s){let p=i.fullPageOpen?P:U;await M(s,p)}async function pn(){if(d){i.fullPageOpen=!0,T.classList.add("open"),await N(),await te(P,i.chatId),queueMicrotask(()=>E.focus());return}i.fullPageOpen=!0,i.open=!1,O(),B(),m.classList.remove("open"),g.classList.remove("visible"),h.classList.add("hidden"),T.classList.add("open"),await N(),await te(P,i.chatId),queueMicrotask(()=>E.focus())}function xt(){if(d){ee();return}i.fullPageOpen&&(i.fullPageOpen=!1,T.classList.remove("open"),h.classList.remove("hidden"),ee())}function dn(){i.menuOpen=!0,y.classList.add("open"),L.classList.add("open")}function O(){i.menuOpen=!1,y.classList.remove("open"),L.classList.remove("open")}function cn(){i.chatId=Pe(t),i.historyLoadedChatId=null,B(),ue(U),oe(U,t.initialSuggestions,async s=>{await M(s,U)}),O()}async function un(){i.chatId=Pe(t),i.historyLoadedChatId=null,ue(P),ee(),oe(P,t.initialSuggestions,async s=>{await M(s,P)}),X()}async function N(){if(!t.endpoints.listChats)return X(),Le(),[];i.loadingChats=!0,X(),Le();try{let s=await $t(H());return i.chats=s,s}catch(s){return F(t,s),i.chats}finally{i.loadingChats=!1,X(),Le()}}async function gn(s){!t.endpoints.listChats&&!t.endpoints.createChat||i.chats.some(p=>p.chatId===i.chatId)||await zt(H(),i.chatId,s?Un(s,n.newChat):void 0)}async function fn(s){i.chatId=s,i.historyLoadedChatId=null,await te(P,s),X()}async function hn(s){i.chatId=s,i.historyLoadedChatId=null,B(),await te(U,s)}async function mn(){O(),await N(),i.myChatsOpen=!0,m.classList.add("kp-sheet-open"),be.classList.add("open")}function B(){i.myChatsOpen=!1,m.classList.remove("kp-sheet-open"),be.classList.remove("open")}function bn(s,p){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 x=a("h3","kp-source-preview-title");x.textContent=n.renamePrompt,x.style.marginBottom="16px",x.style.fontSize="16px";let b=a("input","kp-input");b.type="text",b.value=s.title,b.style.border="1px solid var(--kp-border-color)",b.style.padding="10px",b.style.borderRadius="8px",b.style.width="100%",b.style.marginBottom="20px";let v=a("div","kp-message-actions");v.style.justifyContent="flex-end",v.style.gap="8px";let I=a("button","kp-message-action",n.close);I.addEventListener("click",()=>f.remove());let D=a("button","kp-message-action active","Save");D.addEventListener("click",async()=>{D.disabled=!0,D.textContent="...",await p(b.value),f.remove()}),v.append(I,D),k.append(x,b,v),f.appendChild(k),u.appendChild(f),b.focus()}async function yt(s){t.endpoints.updateChat&&bn(s,async p=>{let f=p.trim();if(!(!f||f===s.title))try{await Fe(H(),s.chatId,{title:f}),await N()}catch(k){F(t,k)}})}async function vt(s){if(t.endpoints.deleteChat)try{await Ut(H(),s.chatId),i.chatId===s.chatId&&(i.chatId=Pe(t),i.historyLoadedChatId=null,ue(U),ue(P)),await N()}catch(p){F(t,p)}}function X(){Dt(it,rt,i,n,async s=>{await fn(s.chatId)},async s=>{await wt(s)},async s=>{await yt(s)},async s=>{await vt(s)})}function Le(){Dt(Qe,Ze,i,n,async s=>{await hn(s.chatId)},async s=>{await wt(s)},async s=>{await yt(s)},async s=>{await vt(s)})}async function wt(s){if(t.endpoints.updateChat)try{await Fe(H(),s.chatId,{pinned:!s.pinned}),await N()}catch(p){F(t,p)}}async function te(s,p){ue(s),oe(s,t.initialSuggestions,async x=>{await M(x,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>',Ve(s),s.body.appendChild(f);let k=await Rt(H(),p);if(f.remove(),k.length>0){Ve(s),qt(s.body,s.hero,s.suggestions);let x=await mt();zn(s.body,k,{strings:n,view:s,userName:x.displayName,userAvatarUrl:x.avatarUrl,assistantAvatarUrl:t.assistantAvatarUrl,onShowSources:pe,onShowCitation:Z,onLike:b=>{ce(t,p,b,!0).catch(console.error)},onDislike:b=>{ce(t,p,b,!1).catch(console.error)}})}return i.historyLoadedChatId=p,k}let Be={open:Oe,close:Y,toggle(){if(d){Oe();return}if(i.open){Y();return}Oe()},destroy(){if(document.removeEventListener("keydown",Ct),l.remove(),d){let s=!1;document.querySelectorAll("[data-chat-widget-host]").forEach(p=>{let f=p.shadowRoot;f&&f.querySelector(".kp-chat-widget-embedded")&&(s=!0)}),s||Wt(!1)}},sendMessage:kt,setAccessTokenProvider(s){i.accessTokenProvider=s},getChatId(){return i.chatId},loadChats(){return N()},async loadHistory(){let s=i.fullPageOpen?P:U;return te(s,i.chatId)}};h.addEventListener("click",()=>Be.toggle()),fe.addEventListener("click",Y),g.addEventListener("click",Y),Ce.addEventListener("click",ee),ke.addEventListener("click",B),xe.addEventListener("click",B),y.addEventListener("click",s=>{if(s.stopPropagation(),!i.menuOpen){dn();return}O()}),w.addEventListener("click",cn),V.addEventListener("click",async()=>{await mn()}),$.addEventListener("click",()=>{if(O(),t.onOpenAssistantPage){Y(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){Y(),window.location.href=t.assistantPageUrl;return}pn()}),ye.addEventListener("click",xt),$e.addEventListener("click",()=>{un(),queueMicrotask(()=>E.focus())}),ie.addEventListener("input",()=>{i.chatSearchTerm=ie.value.trim().toLowerCase(),X()}),m.addEventListener("click",s=>{let p=s.target;if(!(p instanceof Element)||!p.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(p)&&!y.contains(p)&&O(),s.stopPropagation()}),c.addEventListener("click",s=>{let p=s.target;if(i.menuOpen&&p instanceof Node&&!L.contains(p)&&!y.contains(p)&&O(),p instanceof Element&&!p.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 kt(z.value)}),Ne.addEventListener("submit",async s=>{s.preventDefault(),await M(E.value,P)});function Ct(s){if(s.key==="Escape"){if(i.sourcePanelOpen){ee();return}if(i.myChatsOpen){B();return}if(i.fullPageOpen){if(d)return;xt();return}i.open&&Y()}}return document.addEventListener("keydown",Ct),Be}async function En(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"?On(o,n.citations??[]):{displayText:o,citations:n.citations??[]},d=a("div",`kp-message-row ${t}`),i=Rn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t,t==="bot"?n.assistantAvatarUrl:n.userAvatarUrl),l=a("div",`kp-bubble ${t}`),c=a("div","kp-bubble-content");Kn(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 y of u.slice(0,2)){let L=Fn(y,n.strings);L.addEventListener("click",async()=>{n.onShowCitation(y)}),A.appendChild(L)}let S=qn(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(In(r.displayText,n.strings,n.onLike,n.onDislike,n.initialFeedback)),t==="user"?d.append(l,i):d.append(i,l),e.appendChild(d),e.scrollTop=e.scrollHeight,d}function In(e,t,o,n,r){let d=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()}),d.append(i,l,c),d}function Rn(e,t,o){let n=a("div",`kp-avatar ${t}`);if(o){let r=a("img","kp-avatar-img");r.src=o,r.alt=e,r.style.width="100%",r.style.height="100%",r.style.objectFit="cover",r.style.borderRadius="50%",n.appendChild(r)}else{let r=t==="bot"?"\u2726":Mn(e);n.textContent=r}return n.setAttribute("aria-hidden","true"),n}function $n(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){$n(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 Ve(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 zn(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 Dt(e,t,o,n,r,d,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);jt(e,g,o.chatId,n,r,d,i,l),jt(t,u,o.chatId,n,r,d,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 jt(e,t,o,n,r,d,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 d(c)});let y=a("button","kp-chat-actions-item",n.renameChat);y.type="button",y.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,y,L),h.append(m,A),m.addEventListener("click",w=>{w.stopPropagation();let V=h.classList.contains("open");for(let $ of Array.from(e.querySelectorAll(".kp-chat-actions.open")))$.classList.remove("open");for(let $ of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))$.classList.remove("menu-open");V||(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 Un(e,t){return e.trim().slice(0,60)||t}function _e(e){return e.toLowerCase().split("-")[0]||"en"}function Nn(e){let t=Bt.en;return Bt[_e(e)]??t}function Hn(e){return["ar","fa","he","ur"].includes(_e(e))}function Mn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(o=>o[0]?.toUpperCase()??"").join("")}function Ke(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 On(e,t){let o=Bn(e);return{displayText:o.displayText,citations:t.length>0?Wn(t,o.citations):o.citations}}function Bn(e){let o=Vt(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 r=o.slice(0,n).join(`
1920
- `).trimEnd(),d=o.slice(n+1).join(`
1921
- `).trim(),l=Dn(d).map(c=>jn(c)).filter(c=>!!c);return{displayText:r,citations:l}}function Dn(e){let t=[],o="";for(let n of e.split(`
1922
- `)){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 jn(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 Wn(e,t){let o=[],n=new Set;for(let r of[...e,...t]){let d=`${r.knowledgeName??""}::${r.sourceDocument??""}`;n.has(d)||(n.add(d),o.push(r))}return o}function Fn(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",Ke(e)??t.untitledSource);return o.append(n,r),o}function qn(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 d=a("span","kp-source-thumb stacked");d.textContent="\u2726",o.appendChild(d)}let n=a("span","kp-source-chip-label",e.showAll);return t.append(o,n),t}function Vn(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"),d=a("span","kp-source-thumb kp-source-thumb-large");d.textContent="\u2726";let i=a("div","kp-source-card-title",Ke(e)??t.untitledSource),l=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}`),l.textContent=c.join(" \u2022 "),r.appendChild(d),n.append(r,i,l),n}function _n(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function Kn(e,t){e.innerHTML=Yn(Vt(t))}function Vt(e){return e.replace(/\r\n/g,`
1923
- `)}function Yn(e){return e.split(/\n{2,}/).map(o=>o.trim()).filter(Boolean).map(Xn).join("")}function Xn(e){let t=e.split(`
1924
- `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return Jn(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]??"#",r=o[2]??"",d=n.length;return`<h${d}>${se(r)}</h${d}>`}return`<p>${t.map(n=>se(n)).join("<br>")}</p>`}function Jn(e){let t=e.filter((i,l)=>!(l===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(i))).map(i=>Gn(i));if(t.length===0)return"";let o=t[0]??[],n=t.slice(1),r=`<thead><tr>${o.map(i=>`<th>${se(i)}</th>`).join("")}</tr></thead>`,d=n.length?`<tbody>${n.map(i=>`<tr>${i.map(l=>`<td>${se(l)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${r}${d}</table></div>`}function Gn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function se(e){let t=q(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 q(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Wt(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":"")}})}return Sn(Qn);})();
1987
+ `;let Te=o("button","kp-citation-overlay-close","\xD7");Te.type="button",Te.setAttribute("aria-label","Close document preview"),Te.addEventListener("click",()=>{de.classList.remove("open")}),At.append(Pt,Te);let St=o("div","kp-citation-overlay-content"),Tt=o("aside","kp-citation-overlay-metadata-panel");Tt.innerHTML=yn;let ae=o("main","kp-citation-overlay-viewer-panel");if(ae.innerHTML=_e,St.append(Tt,ae),de.append(At,St),!b){let G=1,W=ae.querySelector(".document-sheet"),vn=ae.querySelector(".zoom-in-btn"),wn=ae.querySelector(".zoom-out-btn"),Cn=ae.querySelector(".print-btn");W&&(vn?.addEventListener("click",()=>{G<1.5&&(G+=.1,W.style.transform=`scale(${G})`)}),wn?.addEventListener("click",()=>{G>.6&&(G-=.1,W.style.transform=`scale(${G})`)}),Cn?.addEventListener("click",()=>{window.print()}))}de.classList.add("open")},ce=(i,l)=>{if(s.sourcePanelOpen=!0,s.sourcePanelTitle=l??n.allSourcesUsed,mt.textContent=s.sourcePanelTitle,Ae.classList.add("open"),pe.textContent="",i.length===0){pe.appendChild(o("div","kp-source-panel-empty",n.noSources));return}for(let h of i)pe.appendChild(Kn(h,n,()=>{ee(h)}))},te=()=>{s.sourcePanelOpen=!1,s.sourcePanelTitle=null,Ae.classList.remove("open")};oe(U,t.initialSuggestions,async i=>{await B(i,U)}),oe(P,t.initialSuggestions,async i=>{await B(i,P)}),J(),Se(),p&&(H(),t.rag.loadHistoryOnOpen&&ne(P,s.chatId));function kt(i,l,h){l.textContent=`Uploading ${i.name}...`,l.style.display="block",h.disabled=!0,$t(N(),i).then(k=>{s.attachedFile={name:i.name,sourceUuid:k.source_uuid},l.textContent=`\u{1F4CE} ${i.name} (Attached)`}).catch(k=>{let x=F(t,k);l.textContent=`Failed to upload: ${x.message}`,setTimeout(()=>{l.style.display="none",l.textContent=""},3e3)}).finally(()=>{h.disabled=!1,K.value="",Y.value=""})}ke.addEventListener("click",()=>{K.click()}),K.addEventListener("change",()=>{let i=K.files?.[0];i&&kt(i,ze,M)}),Le.addEventListener("click",()=>{Y.click()}),Y.addEventListener("change",()=>{let i=Y.files?.[0];i&&kt(i,Oe,R)});function je(){if(p){s.fullPageOpen=!0,I.classList.add("open");return}s.open||(s.open=!0,s.fullPageOpen=!1,D(),I.classList.remove("open"),f.classList.add("hidden"),g.classList.add("visible"),m.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&We.loadHistory(),queueMicrotask(()=>M.focus()))}function X(){if(p){te();return}s.open&&(O(),D(),s.open=!1,f.classList.remove("hidden"),g.classList.remove("visible"),m.classList.remove("open"),t.onClose?.())}async function B(i,l){let h=i.trim();if(!h)return;l.input.value="";try{await hn(h)}catch(b){let v=F(t,b);he(l.body,"bot",`${n.unableToCreateChat}: ${v.message}`,{strings:n,view:l,userName:null,assistantAvatarUrl:t.assistantAvatarUrl,onShowSources:ce,onShowCitation:ee,onLike:()=>{},onDislike:()=>{}});return}Ye(l);let k=await bt();he(l.body,"user",h,{strings:n,view:l,userName:k.displayName,userAvatarUrl:k.avatarUrl,assistantAvatarUrl:t.assistantAvatarUrl,onShowSources:ce,onShowCitation:ee,onLike:()=>{},onDislike:()=>{}}),l.body.scrollTop=l.body.scrollHeight;let x=o("div","kp-loading",n.thinking);l.body.appendChild(x),l.body.scrollTop=l.body.scrollHeight;try{let b=await Rn(t),v=s.attachedFile?[s.attachedFile.sourceUuid,...b]:b,z=await Rt(N(),{message:h,chatId:s.chatId,knowledgeNames:v,...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});x.isConnected&&x.remove(),he(l.body,"bot",z.answer,{strings:n,view:l,userName:k.displayName,userAvatarUrl:k.avatarUrl,assistantAvatarUrl:t.assistantAvatarUrl,citations:z.citations??[],onShowSources:ce,onShowCitation:ee,onLike:()=>{ge(t,s.chatId,z.answer,!0).catch(console.error)},onDislike:()=>{ge(t,s.chatId,z.answer,!1).catch(console.error)}}),s.historyLoadedChatId=null,await H(),z.suggestions?.length&&oe(l,z.suggestions,async j=>{await B(j,l)})}catch(b){let v=F(t,b);x.isConnected&&x.remove(),he(l.body,"bot",`${n.requestFailed}: ${v.message}`,{strings:n,view:l,userName:k.displayName,userAvatarUrl:k.avatarUrl,assistantAvatarUrl:t.assistantAvatarUrl,onShowSources:ce,onShowCitation:ee,onLike:()=>{},onDislike:()=>{}})}}async function xt(i){let l=s.fullPageOpen?P:U;await B(i,l)}async function cn(){if(p){s.fullPageOpen=!0,I.classList.add("open"),await H(),await ne(P,s.chatId),queueMicrotask(()=>R.focus());return}s.fullPageOpen=!0,s.open=!1,O(),D(),m.classList.remove("open"),g.classList.remove("visible"),f.classList.add("hidden"),I.classList.add("open"),await H(),await ne(P,s.chatId),queueMicrotask(()=>R.focus())}function yt(){if(p){te();return}s.fullPageOpen&&(s.fullPageOpen=!1,I.classList.remove("open"),f.classList.remove("hidden"),te())}function un(){s.menuOpen=!0,y.classList.add("open"),L.classList.add("open")}function O(){s.menuOpen=!1,y.classList.remove("open"),L.classList.remove("open")}function gn(){s.chatId=Ee(t),s.historyLoadedChatId=null,D(),fe(U),oe(U,t.initialSuggestions,async i=>{await B(i,U)}),O()}async function fn(){s.chatId=Ee(t),s.historyLoadedChatId=null,fe(P),te(),oe(P,t.initialSuggestions,async i=>{await B(i,P)}),J()}async function H(){if(!t.endpoints.listChats)return J(),Se(),[];s.loadingChats=!0,J(),Se();try{let i=await Mt(N());return s.chats=i,i}catch(i){return F(t,i),s.chats}finally{s.loadingChats=!1,J(),Se()}}async function hn(i){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(l=>l.chatId===s.chatId)||await Ut(N(),s.chatId,i?$n(i,n.newChat):void 0)}async function mn(i){s.chatId=i,s.historyLoadedChatId=null,await ne(P,i),J()}async function bn(i){s.chatId=i,s.historyLoadedChatId=null,D(),await ne(U,i)}async function kn(){O(),await H(),s.myChatsOpen=!0,m.classList.add("kp-sheet-open"),xe.classList.add("open")}function D(){s.myChatsOpen=!1,m.classList.remove("kp-sheet-open"),xe.classList.remove("open")}function xn(i,l){let h=o("div","kp-overlay visible"),k=o("div","kp-rename-dialog");k.style.cssText="position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); width:320px; background:var(--kp-panel-background); box-shadow:var(--kp-shadow); padding:24px; border-radius:16px; opacity:1; pointer-events:auto; z-index: 10000; display:flex; flex-direction:column; height:min-content; box-sizing:border-box;";let x=o("h3","kp-source-preview-title");x.textContent=n.renamePrompt,x.style.marginBottom="16px",x.style.fontSize="16px";let b=o("input","kp-input");b.type="text",b.value=i.title,b.style.border="1px solid var(--kp-border-color)",b.style.padding="10px",b.style.borderRadius="8px",b.style.width="100%",b.style.marginBottom="20px",b.style.flex="none",b.style.height="40px";let v=o("div","kp-message-actions");v.style.justifyContent="flex-end",v.style.gap="8px";let z=o("button","kp-message-action",n.close);z.addEventListener("click",()=>h.remove());let j=o("button","kp-message-action active","Save");j.addEventListener("click",async()=>{j.disabled=!0,j.textContent="...",await l(b.value),h.remove()}),v.append(z,j),k.append(x,b,v),h.appendChild(k),c.appendChild(h),b.focus()}async function vt(i){t.endpoints.updateChat&&xn(i,async l=>{let h=l.trim();if(!(!h||h===i.title))try{await Ve(N(),i.chatId,{title:h}),await H()}catch(k){F(t,k)}})}async function wt(i){if(t.endpoints.deleteChat)try{await Ht(N(),i.chatId),s.chatId===i.chatId&&(s.chatId=Ee(t),s.historyLoadedChatId=null,fe(U),fe(P)),await H()}catch(l){F(t,l)}}function J(){jt(rt,lt,s,n,async i=>{await mn(i.chatId),re.classList.remove("open")},async i=>{await Ct(i)},async i=>{await vt(i)},async i=>{await wt(i)})}function Se(){jt(tt,nt,s,n,async i=>{await bn(i.chatId)},async i=>{await Ct(i)},async i=>{await vt(i)},async i=>{await wt(i)})}async function Ct(i){if(t.endpoints.updateChat)try{await Ve(N(),i.chatId,{pinned:!i.pinned}),await H()}catch(l){F(t,l)}}async function ne(i,l){fe(i),oe(i,t.initialSuggestions,async x=>{await B(x,i)});let h=o("div","kp-message kp-message-ai");h.innerHTML='<div class="kp-message-bubble"><div class="kp-typing-indicator"><span></span><span></span><span></span></div></div>',Ye(i),i.body.appendChild(h);let k=await zt(N(),l);if(h.remove(),k.length>0){Ye(i),qt(i.body,i.hero,i.suggestions);let x=await bt();Hn(i.body,k,{strings:n,view:i,userName:x.displayName,userAvatarUrl:x.avatarUrl,assistantAvatarUrl:t.assistantAvatarUrl,onShowSources:ce,onShowCitation:ee,onLike:b=>{ge(t,l,b,!0).catch(console.error)},onDislike:b=>{ge(t,l,b,!1).catch(console.error)}})}return s.historyLoadedChatId=l,k}let We={open:je,close:X,toggle(){if(p){je();return}if(s.open){X();return}je()},destroy(){if(document.removeEventListener("keydown",Lt),d.remove(),p){let i=!1;document.querySelectorAll("[data-chat-widget-host]").forEach(l=>{let h=l.shadowRoot;h&&h.querySelector(".kp-chat-widget-embedded")&&(i=!0)}),i||_t(!1)}},sendMessage:xt,setAccessTokenProvider(i){s.accessTokenProvider=i},getChatId(){return s.chatId},loadChats(){return H()},async loadHistory(){let i=s.fullPageOpen?P:U;return ne(i,s.chatId)}};f.addEventListener("click",()=>We.toggle()),me.addEventListener("click",X),g.addEventListener("click",X),Pe.addEventListener("click",te),ye.addEventListener("click",D),ve.addEventListener("click",D),y.addEventListener("click",i=>{if(i.stopPropagation(),!s.menuOpen){un();return}O()}),w.addEventListener("click",gn),V.addEventListener("click",async()=>{await kn()}),T.addEventListener("click",()=>{if(O(),t.onOpenAssistantPage){X(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){X(),window.location.href=t.assistantPageUrl;return}cn()}),Ce.addEventListener("click",yt),He.addEventListener("click",()=>{fn(),queueMicrotask(()=>R.focus())}),le.addEventListener("input",()=>{s.chatSearchTerm=le.value.trim().toLowerCase(),J()}),m.addEventListener("click",i=>{let l=i.target;if(!(l instanceof Element)||!l.closest(".kp-chat-actions")){for(let h of Array.from(u.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(u.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}s.menuOpen&&!L.contains(l)&&!y.contains(l)&&O(),i.stopPropagation()}),u.addEventListener("click",i=>{let l=i.target;if(s.menuOpen&&l instanceof Node&&!L.contains(l)&&!y.contains(l)&&O(),l instanceof Element&&!l.closest(".kp-chat-actions")){for(let h of Array.from(u.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(u.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}}),Re.addEventListener("submit",async i=>{i.preventDefault(),await xt(M.value)}),Be.addEventListener("submit",async i=>{i.preventDefault(),await B(R.value,P)});function Lt(i){if(i.key==="Escape"){if(s.sourcePanelOpen){te();return}if(s.myChatsOpen){D();return}if(s.fullPageOpen){if(p)return;yt();return}s.open&&X()}}return document.addEventListener("keydown",Lt),We}async function Rn(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 Ee(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 he(e,t,a,n){let r=t==="bot"?Dn(a,n.citations??[]):{displayText:a,citations:n.citations??[]},p=o("div",`kp-message-row ${t}`),s=Mn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t,t==="bot"?n.assistantAvatarUrl:n.userAvatarUrl),d=o("div",`kp-bubble ${t}`),u=o("div","kp-bubble-content");Xn(u,r.displayText),d.appendChild(u);let c=r.citations;if(c.length){let g=o("div","kp-meta",n.strings.citationsAttached(c.length));d.appendChild(g);let f=o("div","kp-source-preview"),m=o("div","kp-source-preview-title",n.strings.sourcesUsed),A=o("div","kp-source-preview-list");for(let y of c.slice(0,2)){let L=qn(y,n.strings);L.addEventListener("click",async()=>{n.onShowCitation(y)}),A.appendChild(L)}let S=Vn(n.strings);S.addEventListener("click",async()=>{n.onShowSources(c,n.strings.allSourcesUsed)}),A.appendChild(S),f.append(m,A),d.appendChild(f)}return t==="bot"&&d.appendChild(zn(r.displayText,n.strings,n.onLike,n.onDislike,n.initialFeedback)),t==="user"?p.append(d,s):p.append(s,d),e.appendChild(p),e.scrollTop=e.scrollHeight,p}function zn(e,t,a,n,r){let p=o("div","kp-message-actions"),s='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>',d='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>',u='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"></path></svg>',c='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-3"></path></svg>',g=o("button","kp-message-action");g.innerHTML=s,g.type="button",g.setAttribute("title",t.copy),g.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(e),g.innerHTML=d,window.setTimeout(()=>{g.innerHTML=s},1200)}catch{g.innerHTML=s}});let f=o("button","kp-message-action");f.innerHTML=u,f.type="button",f.setAttribute("aria-label",t.helpful),r===!0&&f.classList.add("active"),f.addEventListener("click",()=>{f.classList.toggle("active"),m.classList.remove("active"),f.classList.contains("active")&&a&&a()});let m=o("button","kp-message-action");return m.innerHTML=c,m.type="button",m.setAttribute("aria-label",t.notHelpful),r===!1&&m.classList.add("active"),m.addEventListener("click",()=>{m.classList.toggle("active"),f.classList.remove("active"),m.classList.contains("active")&&n&&n()}),p.append(g,f,m),p}function Mn(e,t,a){let n=o("div",`kp-avatar ${t}`);if(a){let r=o("img","kp-avatar-img");r.src=a,r.alt=e,r.style.width="100%",r.style.height="100%",r.style.objectFit="cover",r.style.borderRadius="50%",n.appendChild(r)}else{let r=t==="bot"?"\u2726":On(e);n.textContent=r}return n.setAttribute("aria-hidden","true"),n}function Un(e,t,a){e.textContent="";for(let n of t){let r=o("button","kp-suggestion",n);r.type="button",r.addEventListener("click",async()=>{await a(n)}),e.appendChild(r)}}function oe(e,t,a){Un(e.suggestions,t,async n=>{e.input.value=n,await a(n)})}function qt(e,t,a){let n=new Set([t,a]);for(let r of Array.from(e.children))n.has(r)||r.remove()}function Ye(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function fe(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 Hn(e,t,a){for(let n of t)he(e,n.role==="assistant"?"bot":"user",n.text,{...a,...n.citations!==void 0?{citations:n.citations}:{},...n.isLike!==void 0?{initialFeedback:n.isLike}:{},onLike:()=>{a.onLike&&a.onLike(n.text)},onDislike:()=>{a.onDislike&&a.onDislike(n.text)}})}function jt(e,t,a,n,r,p,s,d){if(e.textContent="",t.textContent="",a.loadingChats){e.appendChild(o("div","kp-full-page-empty",n.loadingChats));return}let u=a.chats.filter(c=>a.chatSearchTerm?c.title.toLowerCase().includes(a.chatSearchTerm):!0);if(u.length>0){let c=u.filter(f=>f.pinned),g=u.filter(f=>!f.pinned).slice(0,8);Wt(e,g,a.chatId,n,r,p,s,d),Wt(t,c,a.chatId,n,r,p,s,d),g.length===0&&e.appendChild(o("div","kp-full-page-empty",n.noRecentChats)),c.length===0&&t.appendChild(o("div","kp-full-page-empty",n.noPinnedChats));return}e.appendChild(o("div","kp-full-page-empty",n.noChats)),t.appendChild(o("div","kp-full-page-empty",n.noPinnedChats))}function Wt(e,t,a,n,r,p,s,d){for(let u of t){let c=o("div",`kp-full-page-item kp-full-page-chat-item${u.chatId===a?" active":""}`),g=o("span","kp-full-page-item-title",u.title),f=o("div","kp-chat-actions"),m=o("button","kp-chat-actions-trigger","\u22EF");m.type="button",m.setAttribute("aria-label",n.chatActions);let A=o("div","kp-chat-actions-menu"),S=o("button","kp-chat-actions-item",u.pinned?n.unpinChat:n.pinChat);S.type="button",S.addEventListener("click",async w=>{w.stopPropagation(),await p(u)});let y=o("button","kp-chat-actions-item",n.renameChat);y.type="button",y.addEventListener("click",async w=>{w.stopPropagation(),await s(u)});let L=o("button","kp-chat-actions-item",n.deleteChat);L.type="button",L.addEventListener("click",async w=>{w.stopPropagation(),await d(u)}),A.append(S,y,L),f.append(m,A),m.addEventListener("click",w=>{w.stopPropagation();let V=f.classList.contains("open");for(let T of Array.from(e.querySelectorAll(".kp-chat-actions.open")))T.classList.remove("open");for(let T of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))T.classList.remove("menu-open");V||(f.classList.add("open"),c.classList.add("menu-open"))}),c.append(g,f),c.setAttribute("role","button"),c.tabIndex=0,c.addEventListener("click",async()=>{await r(u)}),c.addEventListener("keydown",async w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),await r(u))}),c.addEventListener("blur",()=>{f.classList.remove("open"),c.classList.remove("menu-open")}),e.appendChild(c)}}function $n(e,t){return e.trim().slice(0,60)||t}function Xe(e){return e.toLowerCase().split("-")[0]||"en"}function Nn(e){let t=Dt.en;return Dt[Xe(e)]??t}function Bn(e){return["ar","fa","he","ur"].includes(Xe(e))}function On(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(a=>a[0]?.toUpperCase()??"").join("")}function Je(e){if(e.knowledgeName?.trim())return e.knowledgeName.trim();if(e.text){let t=e.text.split(`
1988
+ `)[0]?.trim();if(t){let a=t.replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();if(a)return a}}if(e.sourceDocument&&/^https?:\/\//i.test(e.sourceDocument)){try{let t=new URL(e.sourceDocument),a=decodeURIComponent(t.pathname),n=a.substring(a.lastIndexOf("/")+1);if(n)return n}catch{}return e.sourceDocument}return e.sourceDocument?.trim()&&!/^c\d+$/i.test(e.sourceDocument)?e.sourceDocument.trim():null}function Dn(e,t){let a=jn(e);return{displayText:a.displayText,citations:t.length>0?Fn(t,a.citations):a.citations}}function jn(e){let a=Vt(e).split(`
1989
+ `),n=-1;for(let u=0;u<a.length;u+=1)/^#{0,6}\s*References\s*$/i.test(a[u]?.trim()??"")&&(n=u);if(n===-1)return{displayText:e,citations:[]};let r=a.slice(0,n).join(`
1990
+ `).trimEnd(),p=a.slice(n+1).join(`
1991
+ `).trim(),d=Wn(p).map(u=>_n(u)).filter(u=>!!u);return{displayText:r,citations:d}}function Wn(e){let t=[],a="";for(let n of e.split(`
1992
+ `)){let r=n.trim();if(r){if(/^\d+\.\s+/.test(r)){a&&t.push(a.trim()),a=r.replace(/^\d+\.\s+/,"");continue}a&&(a=`${a} ${r}`)}}return a&&t.push(a.trim()),t}function _n(e){let t=e.match(/https?:\/\/\S+/i);if(!t)return null;let a=t[0],n=e.slice(0,t.index).replace(/[.\s]+$/,"").trim();return{sourceDocument:a,knowledgeName:n||a}}function Fn(e,t){let a=[],n=new Set;for(let r of[...e,...t]){let p=`${r.knowledgeName??""}::${r.sourceDocument??""}`;n.has(p)||(n.add(p),a.push(r))}return a}function qn(e,t){let a=o("button","kp-source-chip");a.type="button",a.setAttribute("aria-label",t.openSource);let n=o("span","kp-source-thumb");n.textContent="\u2726";let r=o("span","kp-source-chip-label",Je(e)??t.untitledSource);return a.append(n,r),a}function Vn(e){let t=o("button","kp-source-chip kp-source-chip-more");t.type="button";let a=o("span","kp-source-thumb-stack");for(let r=0;r<3;r+=1){let p=o("span","kp-source-thumb stacked");p.textContent="\u2726",a.appendChild(p)}let n=o("span","kp-source-chip-label",e.showAll);return t.append(a,n),t}function Kn(e,t,a){let n=o("button","kp-source-card");n.type="button",n.setAttribute("aria-label",t.openSource),n.addEventListener("click",a);let r=o("div","kp-source-card-media"),p=o("span","kp-source-thumb kp-source-thumb-large");p.textContent="\u2726";let s=o("div","kp-source-card-title",Je(e)??t.untitledSource),d=o("div","kp-source-card-meta"),u=[];return typeof e.score=="number"&&u.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&u.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&u.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&u.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&u.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),d.textContent=u.join(" \u2022 "),r.appendChild(p),n.append(r,s,d),n}function Yn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function Xn(e,t){e.innerHTML=Jn(Vt(t))}function Vt(e){return e.replace(/\r\n/g,`
1993
+ `)}function Jn(e){return e.split(/\n{2,}/).map(a=>a.trim()).filter(Boolean).map(Gn).join("")}function Gn(e){let t=e.split(`
1994
+ `).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return Qn(t);if(t.every(n=>/^\d+\.\s+/.test(n)))return`<ol>${t.map(n=>`<li>${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 a=t[0]?.match(/^(#{1,6})\s+(.*)$/);if(a){let n=a[1]??"#",r=a[2]??"",p=n.length;return`<h${p}>${se(r)}</h${p}>`}return`<p>${t.map(n=>se(n)).join("<br>")}</p>`}function Qn(e){let t=e.filter((s,d)=>!(d===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(s))).map(s=>Zn(s));if(t.length===0)return"";let a=t[0]??[],n=t.slice(1),r=`<thead><tr>${a.map(s=>`<th>${se(s)}</th>`).join("")}</tr></thead>`,p=n.length?`<tbody>${n.map(s=>`<tr>${s.map(d=>`<td>${se(d)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${r}${p}</table></div>`}function Zn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function se(e){let t=q(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 q(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function _t(e){typeof document>"u"||document.querySelectorAll("[data-chat-widget-host]").forEach(t=>{let a=t.shadowRoot;if(a){let n=a.querySelector(".kp-chat-widget");n&&!n.classList.contains("kp-chat-widget-embedded")&&(t.style.display=e?"none":"")}})}return En(ea);})();
1925
1995
  //# sourceMappingURL=index.iife.js.map