@nabeh/chat-widget 0.1.3 → 0.1.5

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