@nabeh/chat-widget 0.1.4 → 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.
- package/dist/browser.cjs +44 -37
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.iife.js +44 -37
- package/dist/browser.iife.js.map +1 -1
- package/dist/browser.js +1 -1
- package/dist/{chunk-JHMDAOE6.js → chunk-7ZYVHTFK.js} +45 -38
- package/dist/chunk-7ZYVHTFK.js.map +1 -0
- package/dist/index.cjs +43 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.iife.js +43 -36
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-JHMDAOE6.js.map +0 -1
package/dist/browser.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ChatWidget=(()=>{var
|
|
1
|
+
"use strict";var ChatWidget=(()=>{var He=Object.defineProperty;var mn=Object.getOwnPropertyDescriptor;var bn=Object.getOwnPropertyNames;var kn=Object.prototype.hasOwnProperty;var xn=(e,t)=>{for(var a in t)He(e,a,{get:t[a],enumerable:!0})},yn=(e,t,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of bn(t))!kn.call(e,r)&&r!==a&&He(e,r,{get:()=>t[r],enumerable:!(n=mn(t,r))||n.enumerable});return e};var vn=e=>yn(He({},"__esModule",{value:!0}),e);var _n={};xn(_n,{browserGlobal:()=>Ut,createChatWidget:()=>ve,init:()=>Ot,version:()=>Mt});function xt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Ne(e,t){let a={...e};for(let n of Object.keys(t)){let r=t[n],p=a[n];if(xt(p)&&xt(r)){a[n]=Ne(p,r);continue}r!==void 0&&(a[n]=r)}return a}function yt(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 vt(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 d=l.body?.getReader(),u="";if(d)for(;;){let{done:Y,value:S}=await d.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??[],B=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:B[S]??null}));return{chatId:t.chatId,answer:f.answer,suggestions:[],citations:E}}async function wt(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(),d=Array.isArray(l)?l:l&&typeof l=="object"?l.history??l.messages??l.data??[]:[];return Array.isArray(d)?d.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 Ct(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,d=l.chatId??l.chat_id??l.id,u=l.title??l.name??l.chatId;if(typeof d!="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:d,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 Lt(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 Pt(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=yt(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 Oe={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:Oe,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0,onOpenAssistantPage:void 0};function At(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=Ne(Oe,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 St="kp-chat-widget-styles";function Tt(e,t){if(e.getElementById(St))return;let a=document.createElement("style");a.id=St,a.textContent=wn(t),e.appendChild(a)}function wn(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:
|
|
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 {
|
|
@@ -1777,34 +1784,34 @@
|
|
|
1777
1784
|
min-height: auto;
|
|
1778
1785
|
}
|
|
1779
1786
|
}
|
|
1780
|
-
`}var St={en:{openChatActions:"Open chat actions",newChat:"New Chat",myChats:"My Chats",openAssistant:"Open Knowledge Assistant",back:"Back",close:"Close",assistantBadge:"Knowledge Assistant",closeAssistantPage:"Close knowledge assistant page",searchChat:"Search Chat",recentActivity:"Recent Activity",pinnedCollections:"Pinned Collections",answersBasedOnPermissions:"Answers are generated based on your access permissions",authTokenForwarded:"Auth token is forwarded from the host app when configured.",thinking:"Thinking...",unableToCreateChat:"Unable to create chat",requestFailed:"Request failed",noRecentChats:"No recent chats yet.",noPinnedChats:"No pinned chats yet.",noChats:"No chats yet.",loadingChats:"Loading chats...",pinChat:"Pin chat",unpinChat:"Unpin chat",renameChat:"Rename",deleteChat:"Delete",chatActions:"Chat actions",renamePrompt:"Enter a new chat name",citationsAttached:e=>`${e} citation${e>1?"s":""} attached`,sourcesUsed:"Sources Used",allSourcesUsed:"All Sources Used",documentsAndReferences:"AI documents and references",showAll:"Show All",noSources:"No sources were returned for this answer.",closeSourcesPanel:"Close sources panel",openSource:"Open source",sourceScore:"Score",sourcePage:"Page",sourceSheet:"Sheet",sourceRow:"Row",sourceKnowledge:"Knowledge Base",untitledSource:"Untitled Source",copy:"Copy",copied:"Copied",helpful:"Helpful",notHelpful:"Needs work",send:"Send message",assistantAvatar:"Assistant",userAvatar:"User"},ar:{openChatActions:"\u0641\u062A\u062D \u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",newChat:"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629",myChats:"\u0645\u062D\u0627\u062F\u062B\u0627\u062A\u064A",openAssistant:"\u0641\u062A\u062D \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",back:"\u0631\u062C\u0648\u0639",close:"\u0625\u063A\u0644\u0627\u0642",assistantBadge:"\u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",closeAssistantPage:"\u0625\u063A\u0644\u0627\u0642 \u0635\u0641\u062D\u0629 \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",searchChat:"\u0627\u0628\u062D\u062B \u0641\u064A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A",recentActivity:"\u0627\u0644\u0646\u0634\u0627\u0637 \u0627\u0644\u0623\u062E\u064A\u0631",pinnedCollections:"\u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0627\u0644\u0645\u062B\u0628\u062A\u0629",answersBasedOnPermissions:"\u064A\u062A\u0645 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0625\u062C\u0627\u0628\u0627\u062A \u0628\u0646\u0627\u0621\u064B \u0639\u0644\u0649 \u0635\u0644\u0627\u062D\u064A\u0627\u062A \u0627\u0644\u0648\u0635\u0648\u0644 \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0643",authTokenForwarded:"\u064A\u062A\u0645 \u062A\u0645\u0631\u064A\u0631 \u0631\u0645\u0632 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0627\u0644\u062A\u0637\u0628\u064A\u0642 \u0627\u0644\u0645\u0636\u064A\u0641 \u0639\u0646\u062F \u0627\u0644\u0625\u0639\u062F\u0627\u062F.",thinking:"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631...",unableToCreateChat:"\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",requestFailed:"\u0641\u0634\u0644 \u0627\u0644\u0637\u0644\u0628",noRecentChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u062D\u062F\u064A\u062B\u0629 \u0628\u0639\u062F.",noPinnedChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0645\u062B\u0628\u062A\u0629 \u0628\u0639\u062F.",noChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0628\u0639\u062F.",loadingChats:"\u062C\u0627\u0631\u064D \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A...",pinChat:"\u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",unpinChat:"\u0625\u0644\u063A\u0627\u0621 \u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renameChat:"\u0625\u0639\u0627\u062F\u0629 \u062A\u0633\u0645\u064A\u0629",deleteChat:"\u062D\u0630\u0641",chatActions:"\u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renamePrompt:"\u0623\u062F\u062E\u0644 \u0627\u0633\u0645\u064B\u0627 \u062C\u062F\u064A\u062F\u064B\u0627 \u0644\u0644\u0645\u062D\u0627\u062F\u062B\u0629",citationsAttached:e=>`\u062A\u0645 \u0625\u0631\u0641\u0627\u0642 ${e} \u0645\u0631\u062C\u0639${e>1?"\u0627\u062A":""}`,sourcesUsed:"\u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",allSourcesUsed:"\u0643\u0644 \u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",documentsAndReferences:"\u0645\u0633\u062A\u0646\u062F\u0627\u062A \u0648\u0645\u0631\u0627\u062C\u0639 \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A",showAll:"\u0639\u0631\u0636 \u0627\u0644\u0643\u0644",noSources:"\u0644\u0645 \u064A\u062A\u0645 \u0625\u0631\u062C\u0627\u0639 \u0645\u0635\u0627\u062F\u0631 \u0644\u0647\u0630\u0647 \u0627\u0644\u0625\u062C\u0627\u0628\u0629.",closeSourcesPanel:"\u0625\u063A\u0644\u0627\u0642 \u0644\u0648\u062D\u0629 \u0627\u0644\u0645\u0635\u0627\u062F\u0631",openSource:"\u0641\u062A\u062D \u0627\u0644\u0645\u0635\u062F\u0631",sourceScore:"\u0627\u0644\u062F\u0631\u062C\u0629",sourcePage:"\u0627\u0644\u0635\u0641\u062D\u0629",sourceSheet:"\u0627\u0644\u0648\u0631\u0642\u0629",sourceRow:"\u0627\u0644\u0635\u0641",sourceKnowledge:"\u0642\u0627\u0639\u062F\u0629 \u0627\u0644\u0645\u0639\u0631\u0641\u0629",untitledSource:"\u0645\u0635\u062F\u0631 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646",copy:"\u0646\u0633\u062E",copied:"\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",helpful:"\u0645\u0641\u064A\u062F",notHelpful:"\u064A\u062D\u062A\u0627\u062C \u062A\u062D\u0633\u064A\u0646",send:"\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629",assistantAvatar:"\u0627\u0644\u0645\u0633\u0627\u0639\u062F",userAvatar:"\u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645"}};function xe(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=Lt(e),a=Me(t.locale),n=Tn(t.locale),r=En(a),l=t.displayMode==="embedded",i={chatId:be(t),open:!1,fullPageOpen:l,myChatsOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1,sourcePanelOpen:!1,sourcePanelTitle:null},p=document.createElement("div");p.dataset.chatWidgetHost="true",t.mount.appendChild(p);let c=p.attachShadow({mode:"open"});At(c,t.theme);let u=o("div",`kp-chat-widget ${t.position}`);u.lang=a,u.dir=r?"rtl":"ltr",l&&(u.classList.add("kp-chat-widget-embedded"),It(!0)),r&&u.classList.add("kp-rtl");let g=o("div","kp-overlay"),f=o("button","kp-launcher");f.type="button",f.setAttribute("aria-label",t.launcherAriaLabel),f.innerHTML=['<span class="kp-star-cluster" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let h=o("section","kp-panel");h.setAttribute("role","dialog"),h.setAttribute("aria-modal","true"),h.setAttribute("aria-label",t.title);let v=o("div","kp-header"),P=o("div","kp-toolbar"),b=o("button","kp-tool-button kp-menu-trigger");b.type="button",b.setAttribute("aria-label",n.openChatActions),b.innerHTML=['<span class="kp-pencil-icon" aria-hidden="true"></span>','<span class="kp-chevron" aria-hidden="true">\u2304</span>'].join("");let y=o("div","kp-dropdown"),x=o("button","kp-dropdown-item",n.newChat);x.type="button";let U=o("button","kp-dropdown-item",n.myChats);U.type="button";let w=o("button","kp-dropdown-item",n.openAssistant);w.type="button",y.append(x,U,w),P.append(b,y);let Oe=o("div","kp-title-wrap"),Ot=o("h2","kp-title",t.title),Ut=o("div","kp-subtitle",t.subtitle);Oe.append(Ot,Ut);let ie=o("button","kp-close","\xD7");ie.type="button",ie.setAttribute("aria-label",t.closeAriaLabel),v.append(P,Oe,ie);let re=o("div","kp-body"),ke=o("div","kp-hero"),Bt=o("div","kp-hero-icon","\u2726"),jt=o("div","kp-hero-text",t.welcomeMessage);ke.append(Bt,jt);let Ue=o("div","kp-footer"),ye=o("form","kp-form"),z=o("input","kp-input");z.type="text",z.autocomplete="off",z.placeholder=t.inputPlaceholder,z.setAttribute("aria-label",t.inputPlaceholder);let ve=o("button","kp-send","\u279C");ve.type="submit",ve.setAttribute("aria-label",n.send);let Wt=o("div","kp-note",n.authTokenForwarded);ye.append(z,ve),Ue.append(ye,Wt),h.append(v,re,Ue),l||u.append(g,f,h),c.appendChild(u),re.appendChild(ke);let Be=o("div","kp-suggestions");re.appendChild(Be);let le=o("section","kp-my-chats-sheet"),je=o("div","kp-my-chats-header"),pe=o("button","kp-my-chats-nav","\u2190");pe.type="button",pe.setAttribute("aria-label",n.back);let ce=o("button","kp-my-chats-nav kp-my-chats-close","\xD7");ce.type="button",ce.setAttribute("aria-label",n.close),je.append(pe,ce);let We=o("div","kp-my-chats-body"),Dt=o("div","kp-my-chats-section-label",n.recentActivity),De=o("div","kp-my-chats-list"),qt=o("div","kp-my-chats-section-label",n.pinnedCollections),qe=o("div","kp-my-chats-list");We.append(Dt,De,qt,qe),le.append(je,We),h.appendChild(le);let E={body:re,input:z,suggestions:Be,hero:ke,kind:"panel"},A=o("section","kp-full-page");l&&A.classList.add("kp-full-page-embedded","open"),A.setAttribute("role","dialog"),l||A.setAttribute("aria-modal","true"),A.setAttribute("aria-label",`${t.title} page`);let Ve=o("div","kp-full-page-shell"),we=o("div","kp-full-page-header"),Fe=o("div","kp-full-page-brand"),Vt=o("div","kp-full-page-brand-mark","\u2726"),Ft=o("div","kp-full-page-brand-text",t.title);Fe.append(Vt,Ft);let _e=o("div","kp-full-page-header-actions"),_t=o("div","kp-full-page-badge",n.assistantBadge),de=o("button","kp-full-page-close","\xD7");de.type="button",de.setAttribute("aria-label",n.closeAssistantPage),_e.append(_t,de),we.append(Fe,_e),t.embedded.showHeader||we.classList.add("kp-hidden");let Ke=o("div","kp-full-page-content"),Ye=o("aside","kp-full-page-sidebar"),Ce=o("button","kp-full-page-new-chat",`+ ${n.newChat}`);Ce.type="button";let Xe=o("div","kp-full-page-search"),Z=o("input","kp-full-page-search-input");Z.type="search",Z.placeholder=n.searchChat;let Kt=o("span","kp-full-page-search-icon","\u2315");Xe.append(Z,Kt);let Yt=o("div","kp-full-page-section-label",n.recentActivity),Ge=o("div","kp-full-page-recent-list"),Xt=o("div","kp-full-page-section-label",n.pinnedCollections),Je=o("div","kp-full-page-pinned-list");Ye.append(Ce,Xe,Yt,Ge,Xt,Je);let Qe=o("main","kp-full-page-main"),Ze=o("section","kp-full-page-panel"),Le=o("div","kp-full-page-body"),Pe=o("div","kp-full-page-hero"),et=o("div","kp-full-page-hero-badge");et.innerHTML=['<span class="kp-star-cluster kp-star-cluster-static" aria-hidden="true">','<span class="kp-star orbit-a">\u2726</span>','<span class="kp-star orbit-b">\u2726</span>','<span class="kp-star orbit-c">\u2726</span>','<span class="kp-star main">\u2726</span>',"</span>"].join("");let Gt=o("div","kp-full-page-hero-text",t.welcomeMessage);Pe.append(et,Gt);let tt=o("div","kp-suggestions kp-full-page-suggestions");Le.append(Pe,tt);let nt=o("div","kp-full-page-footer"),Ae=o("form","kp-form kp-full-page-form"),T=o("input","kp-input kp-full-page-input");T.type="text",T.autocomplete="off",T.placeholder=t.inputPlaceholder,T.setAttribute("aria-label",t.inputPlaceholder);let Se=o("button","kp-send kp-full-page-send","\u279C");Se.type="submit",Se.setAttribute("aria-label",n.send);let Jt=o("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Ae.append(T,Se),nt.append(Ae,Jt),Ze.append(Le,nt),Qe.appendChild(Ze);let ue=o("aside","kp-source-panel"),at=o("div","kp-source-panel-header"),ot=o("div","kp-source-panel-title-wrap"),st=o("div","kp-source-panel-title",n.allSourcesUsed),Qt=o("div","kp-source-panel-subtitle",n.documentsAndReferences);ot.append(st,Qt);let ge=o("button","kp-source-panel-close","\xD7");ge.type="button",ge.setAttribute("aria-label",n.closeSourcesPanel),at.append(ot,ge);let ee=o("div","kp-source-panel-list"),Zt=o("div","kp-source-panel-empty",n.noSources);ee.appendChild(Zt),ue.append(at,ee),Ke.append(Ye,Qe,ue),Ve.append(we,Ke),A.appendChild(Ve),u.appendChild(A);let te=o("div","kp-citation-overlay");u.appendChild(te);let C={body:Le,input:T,suggestions:tt,hero:Pe,kind:"full-page"},B=()=>({...t,getAccessToken:i.accessTokenProvider}),it=async()=>{if(!t.getUserContext)return null;try{let s=await t.getUserContext();return s?.displayName?.trim()||s?.email?.trim()||s?.userId?.trim()||null}catch{return null}},F=s=>{let d=Ne(s)??n.untitledSource,m=(s.text||"").trim(),S=m,L=m.split(`
|
|
1781
|
-
`);if(
|
|
1782
|
-
`).trim())}let
|
|
1787
|
+
`}var Et={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 ve(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=At(e),a=Ue(t.locale),n=En(t.locale),r=Rn(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 d=l.attachShadow({mode:"open"});Tt(d,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"),zt(!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 B=o("button","kp-dropdown-item",n.myChats);B.type="button";let E=o("button","kp-dropdown-item",n.openAssistant);E.type="button",y.append(k,B,E),P.append(b,y);let Y=o("div","kp-title-wrap"),S=o("h2","kp-title",t.title),Bt=o("div","kp-subtitle",t.subtitle);Y.append(S,Bt);let ce=o("button","kp-close","\xD7");ce.type="button",ce.setAttribute("aria-label",t.closeAriaLabel),C.append(P,Y,ce);let de=o("div","kp-body"),we=o("div","kp-hero"),Dt=o("div","kp-hero-icon","\u2726"),jt=o("div","kp-hero-text",t.welcomeMessage);we.append(Dt,jt);let De=o("div","kp-footer"),Ce=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 Le=o("button","kp-send","\u279C");Le.type="submit",Le.setAttribute("aria-label",n.send);let Wt=o("div","kp-note",n.authTokenForwarded);Ce.append(z,Le),De.append(Ce,Wt),h.append(C,de,De),p||u.append(g,f,h),d.appendChild(u),de.appendChild(we);let je=o("div","kp-suggestions");de.appendChild(je);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 qe=o("div","kp-my-chats-body"),qt=o("div","kp-my-chats-section-label",n.recentActivity),Ve=o("div","kp-my-chats-list"),Vt=o("div","kp-my-chats-section-label",n.pinnedCollections),Fe=o("div","kp-my-chats-list");qe.append(qt,Ve,Vt,Fe),ue.append(We,qe),h.appendChild(ue);let R={body:de,input:z,suggestions:je,hero:we,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 _e=o("div","kp-full-page-shell"),Pe=o("div","kp-full-page-header"),Ke=o("div","kp-full-page-brand"),Ft=o("div","kp-full-page-brand-mark","\u2726"),_t=o("div","kp-full-page-brand-text",t.title);Ke.append(Ft,_t);let Ye=o("div","kp-full-page-header-actions"),Kt=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),Ye.append(Kt,he),Pe.append(Ke,Ye),t.embedded.showHeader||Pe.classList.add("kp-hidden");let Xe=o("div","kp-full-page-content"),Ge=o("aside","kp-full-page-sidebar"),Ae=o("button","kp-full-page-new-chat",`+ ${n.newChat}`);Ae.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 Yt=o("span","kp-full-page-search-icon","\u2315");Je.append(te,Yt);let Xt=o("div","kp-full-page-section-label",n.recentActivity),Qe=o("div","kp-full-page-recent-list"),Gt=o("div","kp-full-page-section-label",n.pinnedCollections),Ze=o("div","kp-full-page-pinned-list");Ge.append(Ae,Je,Xt,Qe,Gt,Ze);let et=o("main","kp-full-page-main"),tt=o("section","kp-full-page-panel"),Se=o("div","kp-full-page-body"),Te=o("div","kp-full-page-hero"),nt=o("div","kp-full-page-hero-badge");nt.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 Jt=o("div","kp-full-page-hero-text",t.welcomeMessage);Te.append(nt,Jt);let at=o("div","kp-suggestions kp-full-page-suggestions");Se.append(Te,at);let ot=o("div","kp-full-page-footer"),Ee=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 Re=o("button","kp-send kp-full-page-send","\u279C");Re.type="submit",Re.setAttribute("aria-label",n.send);let Qt=o("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);Ee.append(T,Re),ot.append(Ee,Qt),tt.append(Se,ot),et.appendChild(tt);let me=o("aside","kp-source-panel"),st=o("div","kp-source-panel-header"),it=o("div","kp-source-panel-title-wrap"),rt=o("div","kp-source-panel-title",n.allSourcesUsed),Zt=o("div","kp-source-panel-subtitle",n.documentsAndReferences);it.append(rt,Zt);let be=o("button","kp-source-panel-close","\xD7");be.type="button",be.setAttribute("aria-label",n.closeSourcesPanel),st.append(it,be);let ne=o("div","kp-source-panel-list"),en=o("div","kp-source-panel-empty",n.noSources);ne.appendChild(en),me.append(st,ne),Xe.append(Ge,et,me),_e.append(Pe,Xe),A.appendChild(_e),u.appendChild(A);let ae=o("div","kp-citation-overlay");u.appendChild(ae);let L={body:Se,input:T,suggestions:at,hero:Te,kind:"full-page"},D=()=>({...t,getAccessToken:s.accessTokenProvider}),lt=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 c=Be(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===c||c.indexOf(O)!==-1||O.indexOf(c)!==-1)&&(v=w.slice(1).join(`
|
|
1789
|
+
`).trim())}let $=Dn(i.sourceDocument),q=[];(i.pageNumber||i.pageNumber===0)&&q.push(`
|
|
1783
1790
|
<div class="meta-item">
|
|
1784
1791
|
<span class="meta-label">Page Number</span>
|
|
1785
|
-
<span class="meta-value">${
|
|
1792
|
+
<span class="meta-value">${i.pageNumber}</span>
|
|
1786
1793
|
</div>
|
|
1787
|
-
`),typeof
|
|
1794
|
+
`),typeof i.score=="number"&&q.push(`
|
|
1788
1795
|
<div class="meta-item">
|
|
1789
1796
|
<span class="meta-label">Relevance Score</span>
|
|
1790
|
-
<span class="meta-value">${
|
|
1797
|
+
<span class="meta-value">${i.score.toFixed(2)}</span>
|
|
1791
1798
|
</div>
|
|
1792
|
-
`),
|
|
1799
|
+
`),i.sheetName&&q.push(`
|
|
1793
1800
|
<div class="meta-item">
|
|
1794
1801
|
<span class="meta-label">Sheet Name</span>
|
|
1795
|
-
<span class="meta-value">${
|
|
1802
|
+
<span class="meta-value">${U(i.sheetName)}</span>
|
|
1796
1803
|
</div>
|
|
1797
|
-
`),(
|
|
1804
|
+
`),(i.rowNumber||i.rowNumber===0)&&q.push(`
|
|
1798
1805
|
<div class="meta-item">
|
|
1799
1806
|
<span class="meta-label">Row Number</span>
|
|
1800
|
-
<span class="meta-value">${
|
|
1807
|
+
<span class="meta-value">${i.rowNumber}</span>
|
|
1801
1808
|
</div>
|
|
1802
|
-
`),
|
|
1809
|
+
`),i.knowledgeName&&q.push(`
|
|
1803
1810
|
<div class="meta-item">
|
|
1804
1811
|
<span class="meta-label">Database Source</span>
|
|
1805
|
-
<span class="meta-value">${
|
|
1812
|
+
<span class="meta-value">${U(i.knowledgeName)}</span>
|
|
1806
1813
|
</div>
|
|
1807
|
-
`),
|
|
1814
|
+
`),q.push(`
|
|
1808
1815
|
<div class="meta-item">
|
|
1809
1816
|
<span class="meta-label">Classification</span>
|
|
1810
1817
|
<span class="meta-value">Uploaded Knowledge</span>
|
|
@@ -1817,7 +1824,7 @@
|
|
|
1817
1824
|
<span class="meta-label">Language</span>
|
|
1818
1825
|
<span class="meta-value">English</span>
|
|
1819
1826
|
</div>
|
|
1820
|
-
`);let
|
|
1827
|
+
`);let cn=q.join(""),dn=v?U(v):"No text snippet available for this citation.",un=`
|
|
1821
1828
|
<div class="doc-badge-wrapper">
|
|
1822
1829
|
<div class="doc-icon">\u{1F4C4}</div>
|
|
1823
1830
|
<div class="doc-badge-info">
|
|
@@ -1826,7 +1833,7 @@
|
|
|
1826
1833
|
</div>
|
|
1827
1834
|
|
|
1828
1835
|
<div class="doc-title-section">
|
|
1829
|
-
<h1>${
|
|
1836
|
+
<h1>${U(c)}</h1>
|
|
1830
1837
|
<div class="doc-source-type">Uploaded Knowledge Resource</div>
|
|
1831
1838
|
</div>
|
|
1832
1839
|
|
|
@@ -1834,7 +1841,7 @@
|
|
|
1834
1841
|
|
|
1835
1842
|
<div>
|
|
1836
1843
|
<h3 class="meta-section-title">Retrieved Passage Snippet</h3>
|
|
1837
|
-
<div class="summary-box">${
|
|
1844
|
+
<div class="summary-box">${dn}</div>
|
|
1838
1845
|
</div>
|
|
1839
1846
|
|
|
1840
1847
|
<div class="section-divider"></div>
|
|
@@ -1842,15 +1849,15 @@
|
|
|
1842
1849
|
<div>
|
|
1843
1850
|
<h3 class="meta-section-title">Metadata & Classification</h3>
|
|
1844
1851
|
<div class="meta-list">
|
|
1845
|
-
${
|
|
1852
|
+
${cn}
|
|
1846
1853
|
</div>
|
|
1847
1854
|
</div>
|
|
1848
|
-
`,
|
|
1855
|
+
`,ze="";$?ze=`<iframe src="${$}" title="Document Viewer"></iframe>`:ze=`
|
|
1849
1856
|
<div class="viewer-toolbar">
|
|
1850
|
-
<div class="toolbar-left">${
|
|
1857
|
+
<div class="toolbar-left">${U(c)}</div>
|
|
1851
1858
|
<div class="toolbar-center">
|
|
1852
1859
|
<button class="toolbar-btn zoom-out-btn">\u2212</button>
|
|
1853
|
-
<span class="page-indicator">Page ${
|
|
1860
|
+
<span class="page-indicator">Page ${i.pageNumber||1}</span>
|
|
1854
1861
|
<button class="toolbar-btn zoom-in-btn">+</button>
|
|
1855
1862
|
</div>
|
|
1856
1863
|
<div class="toolbar-right">
|
|
@@ -1860,26 +1867,26 @@
|
|
|
1860
1867
|
<div class="viewer-body">
|
|
1861
1868
|
<div class="document-sheet">
|
|
1862
1869
|
<div class="sheet-header">
|
|
1863
|
-
<span>${
|
|
1864
|
-
<span>Page ${
|
|
1870
|
+
<span>${U(c)}</span>
|
|
1871
|
+
<span>Page ${i.pageNumber||1}</span>
|
|
1865
1872
|
</div>
|
|
1866
|
-
<div class="sheet-content">${
|
|
1873
|
+
<div class="sheet-content">${U(m||"No document content retrieved.")}</div>
|
|
1867
1874
|
<div class="sheet-footer">
|
|
1868
1875
|
<span>Confidentiality: Public</span>
|
|
1869
1876
|
<span>Knowledge Platform CB</span>
|
|
1870
1877
|
</div>
|
|
1871
1878
|
</div>
|
|
1872
1879
|
</div>
|
|
1873
|
-
`,
|
|
1880
|
+
`,ae.textContent="";let ht=o("header","kp-citation-overlay-header"),mt=o("div","kp-citation-overlay-brand");mt.innerHTML=`
|
|
1874
1881
|
<span class="kp-citation-overlay-brand-logo">\u2726</span>
|
|
1875
1882
|
<span>Knowledge Assistant Document Viewer</span>
|
|
1876
|
-
`;let he=o("button","kp-citation-overlay-close","\xD7");he.type="button",he.setAttribute("aria-label","Close document preview"),he.addEventListener("click",()=>{te.classList.remove("open")}),gt.append(ft,he);let ht=o("div","kp-citation-overlay-content"),mt=o("aside","kp-citation-overlay-metadata-panel");mt.innerHTML=dn;let Y=o("main","kp-citation-overlay-viewer-panel");if(Y.innerHTML=Re,ht.append(mt,Y),te.append(gt,ht),!I){let q=1,N=Y.querySelector(".document-sheet"),un=Y.querySelector(".zoom-in-btn"),gn=Y.querySelector(".zoom-out-btn"),fn=Y.querySelector(".print-btn");N&&(un?.addEventListener("click",()=>{q<1.5&&(q+=.1,N.style.transform=`scale(${q})`)}),gn?.addEventListener("click",()=>{q>.6&&(q-=.1,N.style.transform=`scale(${q})`)}),fn?.addEventListener("click",()=>{window.print()}))}te.classList.add("open")},ne=(s,d)=>{if(i.sourcePanelOpen=!0,i.sourcePanelTitle=d??n.allSourcesUsed,st.textContent=i.sourcePanelTitle,ue.classList.add("open"),ee.textContent="",s.length===0){ee.appendChild(o("div","kp-source-panel-empty",n.noSources));return}for(let m of s)ee.appendChild(Un(m,n,()=>{F(m)}))},_=()=>{i.sourcePanelOpen=!1,i.sourcePanelTitle=null,ue.classList.remove("open")};J(E,t.initialSuggestions,async s=>{await $(s,E)}),J(C,t.initialSuggestions,async s=>{await $(s,C)}),W(),fe(),l&&(R(),t.rag.loadHistoryOnOpen&&K(C,i.chatId));function Te(){if(l){i.fullPageOpen=!0,A.classList.add("open");return}i.open||(i.open=!0,i.fullPageOpen=!1,M(),A.classList.remove("open"),f.classList.add("hidden"),g.classList.add("visible"),h.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&Ee.loadHistory(),queueMicrotask(()=>z.focus()))}function j(){if(l){_();return}i.open&&(H(),M(),i.open=!1,f.classList.remove("hidden"),g.classList.remove("visible"),h.classList.remove("open"),t.onClose?.())}async function $(s,d){let m=s.trim();if(!m)return;d.input.value="";try{await on(m)}catch(L){let I=V(t,L);se(d.body,"bot",`${n.unableToCreateChat}: ${I.message}`,{strings:n,view:d,userName:null,onShowSources:ne,onShowCitation:F});return}Tt(d),se(d.body,"user",m,{strings:n,view:d,userName:await it(),onShowSources:ne,onShowCitation:F}),d.body.scrollTop=d.body.scrollHeight;let S=o("div","kp-loading",n.thinking);d.body.appendChild(S),d.body.scrollTop=d.body.scrollHeight;try{let L=await kt(B(),{message:m,chatId:i.chatId,knowledgeNames:await wn(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});S.isConnected&&S.remove(),se(d.body,"bot",L.answer,{strings:n,view:d,userName:null,citations:L.citations??[],onShowSources:ne,onShowCitation:F}),i.historyLoadedChatId=null,await R(),L.suggestions?.length&&J(d,L.suggestions,async I=>{await $(I,d)})}catch(L){let I=V(t,L);S.isConnected&&S.remove(),se(d.body,"bot",`${n.requestFailed}: ${I.message}`,{strings:n,view:d,userName:null,onShowSources:ne,onShowCitation:F})}}async function rt(s){let d=i.fullPageOpen?C:E;await $(s,d)}async function en(){if(l){i.fullPageOpen=!0,A.classList.add("open"),await R(),await K(C,i.chatId),queueMicrotask(()=>T.focus());return}i.fullPageOpen=!0,i.open=!1,H(),M(),h.classList.remove("open"),g.classList.remove("visible"),f.classList.add("hidden"),A.classList.add("open"),await R(),await K(C,i.chatId),queueMicrotask(()=>T.focus())}function lt(){if(l){_();return}i.fullPageOpen&&(i.fullPageOpen=!1,A.classList.remove("open"),f.classList.remove("hidden"),_())}function tn(){i.menuOpen=!0,b.classList.add("open"),y.classList.add("open")}function H(){i.menuOpen=!1,b.classList.remove("open"),y.classList.remove("open")}function nn(){i.chatId=be(t),i.historyLoadedChatId=null,M(),oe(E),J(E,t.initialSuggestions,async s=>{await $(s,E)}),H()}async function an(){i.chatId=be(t),i.historyLoadedChatId=null,oe(C),_(),J(C,t.initialSuggestions,async s=>{await $(s,C)}),W()}async function R(){if(!t.endpoints.listChats)return W(),fe(),[];i.loadingChats=!0,W(),fe();try{let s=await vt(B());return i.chats=s,s}catch(s){return V(t,s),i.chats}finally{i.loadingChats=!1,W(),fe()}}async function on(s){!t.endpoints.listChats&&!t.endpoints.createChat||i.chats.some(d=>d.chatId===i.chatId)||await wt(B(),i.chatId,s?Sn(s,n.newChat):void 0)}async function sn(s){i.chatId=s,i.historyLoadedChatId=null,await K(C,s),W()}async function rn(s){i.chatId=s,i.historyLoadedChatId=null,await K(E,s),M()}async function ln(){H(),await R(),i.myChatsOpen=!0,h.classList.add("kp-sheet-open"),le.classList.add("open")}function M(){i.myChatsOpen=!1,h.classList.remove("kp-sheet-open"),le.classList.remove("open")}async function pt(s){if(!t.endpoints.updateChat)return;let d=window.prompt(n.renamePrompt,s.title)?.trim();if(!(!d||d===s.title))try{await $e(B(),s.chatId,{title:d}),await R()}catch(m){V(t,m)}}async function ct(s){if(t.endpoints.deleteChat)try{await Ct(B(),s.chatId),i.chatId===s.chatId&&(i.chatId=be(t),i.historyLoadedChatId=null,oe(E),oe(C)),await R()}catch(d){V(t,d)}}function W(){Et(Ge,Je,i,n,async s=>{await sn(s.chatId)},async s=>{await dt(s)},async s=>{await pt(s)},async s=>{await ct(s)})}function fe(){Et(De,qe,i,n,async s=>{await rn(s.chatId)},async s=>{await dt(s)},async s=>{await pt(s)},async s=>{await ct(s)})}async function dt(s){if(t.endpoints.updateChat)try{await $e(B(),s.chatId,{pinned:!s.pinned}),await R()}catch(d){V(t,d)}}async function K(s,d){oe(s),J(s,t.initialSuggestions,async S=>{await $(S,s)});let m=await yt(B(),d);return m.length>0&&(Tt(s),zt(s.body,s.hero,s.suggestions),An(s.body,m,{strings:n,view:s,userName:await it(),onShowSources:ne,onShowCitation:F})),i.historyLoadedChatId=d,m}let Ee={open:Te,close:j,toggle(){if(l){Te();return}if(i.open){j();return}Te()},destroy(){if(document.removeEventListener("keydown",ut),p.remove(),l){let s=!1;document.querySelectorAll("[data-chat-widget-host]").forEach(d=>{let m=d.shadowRoot;m&&m.querySelector(".kp-chat-widget-embedded")&&(s=!0)}),s||It(!1)}},sendMessage:rt,setAccessTokenProvider(s){i.accessTokenProvider=s},getChatId(){return i.chatId},loadChats(){return R()},async loadHistory(){let s=i.fullPageOpen?C:E;return K(s,i.chatId)}};f.addEventListener("click",()=>Ee.toggle()),ie.addEventListener("click",j),g.addEventListener("click",j),ge.addEventListener("click",_),pe.addEventListener("click",M),ce.addEventListener("click",M),b.addEventListener("click",s=>{if(s.stopPropagation(),!i.menuOpen){tn();return}H()}),x.addEventListener("click",nn),U.addEventListener("click",async()=>{await ln()}),w.addEventListener("click",()=>{if(H(),t.onOpenAssistantPage){j(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){j(),window.location.href=t.assistantPageUrl;return}en()}),de.addEventListener("click",lt),Ce.addEventListener("click",()=>{an(),queueMicrotask(()=>T.focus())}),Z.addEventListener("input",()=>{i.chatSearchTerm=Z.value.trim().toLowerCase(),W()}),h.addEventListener("click",s=>{let d=s.target;if(!(d instanceof Element)||!d.closest(".kp-chat-actions")){for(let m of Array.from(c.querySelectorAll(".kp-chat-actions.open")))m.classList.remove("open");for(let m of Array.from(c.querySelectorAll(".kp-full-page-chat-item.menu-open")))m.classList.remove("menu-open")}i.menuOpen&&!y.contains(d)&&!b.contains(d)&&H(),s.stopPropagation()}),c.addEventListener("click",s=>{let d=s.target;if(i.menuOpen&&d instanceof Node&&!y.contains(d)&&!b.contains(d)&&H(),d instanceof Element&&!d.closest(".kp-chat-actions")){for(let m of Array.from(c.querySelectorAll(".kp-chat-actions.open")))m.classList.remove("open");for(let m of Array.from(c.querySelectorAll(".kp-full-page-chat-item.menu-open")))m.classList.remove("menu-open")}}),ye.addEventListener("submit",async s=>{s.preventDefault(),await rt(z.value)}),Ae.addEventListener("submit",async s=>{s.preventDefault(),await $(T.value,C)});function ut(s){if(s.key==="Escape"){if(i.sourcePanelOpen){_();return}if(i.myChatsOpen){M();return}if(i.fullPageOpen){if(l)return;lt();return}i.open&&j()}}return document.addEventListener("keydown",ut),Ee}async function wn(e){if(e.rag.getKnowledgeNames){let t=await e.rag.getKnowledgeNames();return Array.isArray(t)?t.filter(Boolean):[]}return(e.rag.knowledgeNames??[]).filter(Boolean)}function be(e){return e.rag.chatId?.trim()?e.rag.chatId:e.rag.chatIdFactory?e.rag.chatIdFactory():typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`kp-chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function se(e,t,a,n){let r=t==="bot"?In(a,n.citations??[]):{displayText:a,citations:n.citations??[]},l=o("div",`kp-message-row ${t}`),i=Ln(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),p=o("div",`kp-bubble ${t}`),c=o("div","kp-bubble-content");jn(c,r.displayText),p.appendChild(c);let u=r.citations;if(u.length){let g=o("div","kp-meta",n.strings.citationsAttached(u.length));p.appendChild(g);let f=o("div","kp-source-preview"),h=o("div","kp-source-preview-title",n.strings.sourcesUsed),v=o("div","kp-source-preview-list");for(let b of u.slice(0,2)){let y=Nn(b,n.strings);y.addEventListener("click",async()=>{n.onShowCitation(b)}),v.appendChild(y)}let P=On(n.strings);P.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),v.appendChild(P),f.append(h,v),p.appendChild(f)}return t==="bot"&&p.appendChild(Cn(r.displayText,n.strings)),t==="user"?l.append(p,i):l.append(i,p),e.appendChild(l),e.scrollTop=e.scrollHeight,l}function Cn(e,t){let a=o("div","kp-message-actions"),n=o("button","kp-message-action",t.copy);n.type="button",n.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(e),n.textContent=t.copied,window.setTimeout(()=>{n.textContent=t.copy},1200)}catch{n.textContent=t.copy}});let r=o("button","kp-message-action","\u{1F44D}");r.type="button",r.setAttribute("aria-label",t.helpful),r.addEventListener("click",()=>{r.classList.toggle("active"),l.classList.remove("active")});let l=o("button","kp-message-action","\u{1F44E}");return l.type="button",l.setAttribute("aria-label",t.notHelpful),l.addEventListener("click",()=>{l.classList.toggle("active"),r.classList.remove("active")}),a.append(n,r,l),a}function Ln(e,t){let a=o("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":Rn(e);return a.textContent=n,a.setAttribute("aria-hidden","true"),a}function Pn(e,t,a){e.textContent="";for(let n of t){let r=o("button","kp-suggestion",n);r.type="button",r.addEventListener("click",async()=>{await a(n)}),e.appendChild(r)}}function J(e,t,a){Pn(e.suggestions,t,async n=>{e.input.value=n,await a(n)})}function zt(e,t,a){let n=new Set([t,a]);for(let r of Array.from(e.children))n.has(r)||r.remove()}function Tt(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function oe(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),zt(e.body,e.hero,e.suggestions),e.input.value=""}function An(e,t,a){for(let n of t)se(e,n.role==="assistant"?"bot":"user",n.text,a)}function Et(e,t,a,n,r,l,i,p){if(e.textContent="",t.textContent="",a.loadingChats){e.appendChild(o("div","kp-full-page-empty",n.loadingChats));return}let c=a.chats.filter(u=>a.chatSearchTerm?u.title.toLowerCase().includes(a.chatSearchTerm):!0);if(c.length>0){let u=c.filter(f=>f.pinned),g=c.filter(f=>!f.pinned).slice(0,8);Rt(e,g,a.chatId,n,r,l,i,p),Rt(t,u,a.chatId,n,r,l,i,p),g.length===0&&e.appendChild(o("div","kp-full-page-empty",n.noRecentChats)),u.length===0&&t.appendChild(o("div","kp-full-page-empty",n.noPinnedChats));return}e.appendChild(o("div","kp-full-page-empty",n.noChats)),t.appendChild(o("div","kp-full-page-empty",n.noPinnedChats))}function Rt(e,t,a,n,r,l,i,p){for(let c of t){let u=o("div",`kp-full-page-item kp-full-page-chat-item${c.chatId===a?" active":""}`),g=o("span","kp-full-page-item-title",c.title),f=o("div","kp-chat-actions"),h=o("button","kp-chat-actions-trigger","\u22EF");h.type="button",h.setAttribute("aria-label",n.chatActions);let v=o("div","kp-chat-actions-menu"),P=o("button","kp-chat-actions-item",c.pinned?n.unpinChat:n.pinChat);P.type="button",P.addEventListener("click",async x=>{x.stopPropagation(),await l(c)});let b=o("button","kp-chat-actions-item",n.renameChat);b.type="button",b.addEventListener("click",async x=>{x.stopPropagation(),await i(c)});let y=o("button","kp-chat-actions-item",n.deleteChat);y.type="button",y.addEventListener("click",async x=>{x.stopPropagation(),await p(c)}),v.append(P,b,y),f.append(h,v),h.addEventListener("click",x=>{x.stopPropagation();let U=f.classList.contains("open");for(let w of Array.from(e.querySelectorAll(".kp-chat-actions.open")))w.classList.remove("open");for(let w of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))w.classList.remove("menu-open");U||(f.classList.add("open"),u.classList.add("menu-open"))}),u.append(g,f),u.setAttribute("role","button"),u.tabIndex=0,u.addEventListener("click",async()=>{await r(c)}),u.addEventListener("keydown",async x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),await r(c))}),u.addEventListener("blur",()=>{f.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function Sn(e,t){return e.trim().slice(0,60)||t}function Me(e){return e.toLowerCase().split("-")[0]||"en"}function Tn(e){let t=St.en;return St[Me(e)]??t}function En(e){return["ar","fa","he","ur"].includes(Me(e))}function Rn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(a=>a[0]?.toUpperCase()??"").join("")}function Ne(e){if(e.knowledgeName?.trim())return e.knowledgeName.trim();if(e.text){let t=e.text.split(`
|
|
1877
|
-
`)[0]?.trim();if(t){let a=t.replace(/\s*\|\s*Page\s*\d+\s*$/i,"").trim();if(a)return a}}if(e.sourceDocument&&/^https?:\/\//i.test(e.sourceDocument)){try{let t=new URL(e.sourceDocument),a=decodeURIComponent(t.pathname),n=a.substring(a.lastIndexOf("/")+1);if(n)return n}catch{}return e.sourceDocument}return e.sourceDocument?.trim()&&!/^c\d+$/i.test(e.sourceDocument)?e.sourceDocument.trim():null}function
|
|
1878
|
-
`),n=-1;for(let
|
|
1879
|
-
`).trimEnd(),
|
|
1880
|
-
`).trim(),p
|
|
1881
|
-
`)){let r=n.trim();if(r){if(/^\d+\.\s+/.test(r)){a&&t.push(a.trim()),a=r.replace(/^\d+\.\s+/,"");continue}a&&(a=`${a} ${r}`)}}return a&&t.push(a.trim()),t}function
|
|
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")}),ht.append(mt,xe);let bt=o("div","kp-citation-overlay-content"),kt=o("aside","kp-citation-overlay-metadata-panel");kt.innerHTML=un;let Q=o("main","kp-citation-overlay-viewer-panel");if(Q.innerHTML=ze,bt.append(kt,Q),ae.append(ht,bt),!$){let V=1,O=Q.querySelector(".document-sheet"),gn=Q.querySelector(".zoom-in-btn"),fn=Q.querySelector(".zoom-out-btn"),hn=Q.querySelector(".print-btn");O&&(gn?.addEventListener("click",()=>{V<1.5&&(V+=.1,O.style.transform=`scale(${V})`)}),fn?.addEventListener("click",()=>{V>.6&&(V-=.1,O.style.transform=`scale(${V})`)}),hn?.addEventListener("click",()=>{window.print()}))}ae.classList.add("open")},oe=(i,c)=>{if(s.sourcePanelOpen=!0,s.sourcePanelTitle=c??n.allSourcesUsed,rt.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(Bn(m,n,()=>{X(m)}))},G=()=>{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)}),W(),ke(),p&&(I(),t.rag.loadHistoryOnOpen&&J(L,s.chatId));function Ie(){if(p){s.fullPageOpen=!0,A.classList.add("open");return}s.open||(s.open=!0,s.fullPageOpen=!1,M(),A.classList.remove("open"),f.classList.add("hidden"),g.classList.add("visible"),h.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&$e.loadHistory(),queueMicrotask(()=>z.focus()))}function j(){if(p){G();return}s.open&&(N(),M(),s.open=!1,f.classList.remove("hidden"),g.classList.remove("visible"),h.classList.remove("open"),t.onClose?.())}async function H(i,c){let m=i.trim();if(!m)return;c.input.value="";try{await sn(m)}catch(w){let $=K(t,w);pe(c.body,"bot",`${n.unableToCreateChat}: ${$.message}`,{strings:n,view:c,userName:null,onShowSources:oe,onShowCitation:X,onLike:()=>{},onDislike:()=>{}});return}Rt(c),pe(c.body,"user",m,{strings:n,view:c,userName:await lt(),onShowSources:oe,onShowCitation:X,onLike:()=>{},onDislike:()=>{}}),c.body.scrollTop=c.body.scrollHeight;let v=o("div","kp-loading",n.thinking);c.body.appendChild(v),c.body.scrollTop=c.body.scrollHeight;try{let w=await vt(D(),{message:m,chatId:s.chatId,knowledgeNames:await Cn(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});v.isConnected&&v.remove(),pe(c.body,"bot",w.answer,{strings:n,view:c,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(c,w.suggestions,async $=>{await H($,c)})}catch(w){let $=K(t,w);v.isConnected&&v.remove(),pe(c.body,"bot",`${n.requestFailed}: ${$.message}`,{strings:n,view:c,userName:null,onShowSources:oe,onShowCitation:X,onLike:()=>{},onDislike:()=>{}})}}async function pt(i){let c=s.fullPageOpen?L:R;await H(i,c)}async function tn(){if(p){s.fullPageOpen=!0,A.classList.add("open"),await I(),await J(L,s.chatId),queueMicrotask(()=>T.focus());return}s.fullPageOpen=!0,s.open=!1,N(),M(),h.classList.remove("open"),g.classList.remove("visible"),f.classList.add("hidden"),A.classList.add("open"),await I(),await J(L,s.chatId),queueMicrotask(()=>T.focus())}function ct(){if(p){G();return}s.fullPageOpen&&(s.fullPageOpen=!1,A.classList.remove("open"),f.classList.remove("hidden"),G())}function nn(){s.menuOpen=!0,b.classList.add("open"),y.classList.add("open")}function N(){s.menuOpen=!1,b.classList.remove("open"),y.classList.remove("open")}function an(){s.chatId=ye(t),s.historyLoadedChatId=null,M(),le(R),Z(R,t.initialSuggestions,async i=>{await H(i,R)}),N()}async function on(){s.chatId=ye(t),s.historyLoadedChatId=null,le(L),G(),Z(L,t.initialSuggestions,async i=>{await H(i,L)}),W()}async function I(){if(!t.endpoints.listChats)return W(),ke(),[];s.loadingChats=!0,W(),ke();try{let i=await Ct(D());return s.chats=i,i}catch(i){return K(t,i),s.chats}finally{s.loadingChats=!1,W(),ke()}}async function sn(i){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(c=>c.chatId===s.chatId)||await Lt(D(),s.chatId,i?Tn(i,n.newChat):void 0)}async function rn(i){s.chatId=i,s.historyLoadedChatId=null,await J(L,i),W()}async function ln(i){s.chatId=i,s.historyLoadedChatId=null,await J(R,i),M()}async function pn(){N(),await I(),s.myChatsOpen=!0,h.classList.add("kp-sheet-open"),ue.classList.add("open")}function M(){s.myChatsOpen=!1,h.classList.remove("kp-sheet-open"),ue.classList.remove("open")}async function dt(i){if(!t.endpoints.updateChat)return;let c=window.prompt(n.renamePrompt,i.title)?.trim();if(!(!c||c===i.title))try{await Me(D(),i.chatId,{title:c}),await I()}catch(m){K(t,m)}}async function ut(i){if(t.endpoints.deleteChat)try{await Pt(D(),i.chatId),s.chatId===i.chatId&&(s.chatId=ye(t),s.historyLoadedChatId=null,le(R),le(L)),await I()}catch(c){K(t,c)}}function W(){It(Qe,Ze,s,n,async i=>{await rn(i.chatId)},async i=>{await gt(i)},async i=>{await dt(i)},async i=>{await ut(i)})}function ke(){It(Ve,Fe,s,n,async i=>{await ln(i.chatId)},async i=>{await gt(i)},async i=>{await dt(i)},async i=>{await ut(i)})}async function gt(i){if(t.endpoints.updateChat)try{await Me(D(),i.chatId,{pinned:!i.pinned}),await I()}catch(c){K(t,c)}}async function J(i,c){le(i),Z(i,t.initialSuggestions,async v=>{await H(v,i)});let m=await wt(D(),c);return m.length>0&&(Rt(i),Ht(i.body,i.hero,i.suggestions),Sn(i.body,m,{strings:n,view:i,userName:await lt(),onShowSources:oe,onShowCitation:X,onLike:v=>{re(t,c,v,!0).catch(console.error)},onDislike:v=>{re(t,c,v,!1).catch(console.error)}})),s.historyLoadedChatId=c,m}let $e={open:Ie,close:j,toggle(){if(p){Ie();return}if(s.open){j();return}Ie()},destroy(){if(document.removeEventListener("keydown",ft),l.remove(),p){let i=!1;document.querySelectorAll("[data-chat-widget-host]").forEach(c=>{let m=c.shadowRoot;m&&m.querySelector(".kp-chat-widget-embedded")&&(i=!0)}),i||zt(!1)}},sendMessage:pt,setAccessTokenProvider(i){s.accessTokenProvider=i},getChatId(){return s.chatId},loadChats(){return I()},async loadHistory(){let i=s.fullPageOpen?L:R;return J(i,s.chatId)}};f.addEventListener("click",()=>$e.toggle()),ce.addEventListener("click",j),g.addEventListener("click",j),be.addEventListener("click",G),ge.addEventListener("click",M),fe.addEventListener("click",M),b.addEventListener("click",i=>{if(i.stopPropagation(),!s.menuOpen){nn();return}N()}),k.addEventListener("click",an),B.addEventListener("click",async()=>{await pn()}),E.addEventListener("click",()=>{if(N(),t.onOpenAssistantPage){j(),t.onOpenAssistantPage();return}if(t.assistantPageUrl){j(),window.location.href=t.assistantPageUrl;return}tn()}),he.addEventListener("click",ct),Ae.addEventListener("click",()=>{on(),queueMicrotask(()=>T.focus())}),te.addEventListener("input",()=>{s.chatSearchTerm=te.value.trim().toLowerCase(),W()}),h.addEventListener("click",i=>{let c=i.target;if(!(c instanceof Element)||!c.closest(".kp-chat-actions")){for(let m of Array.from(d.querySelectorAll(".kp-chat-actions.open")))m.classList.remove("open");for(let m of Array.from(d.querySelectorAll(".kp-full-page-chat-item.menu-open")))m.classList.remove("menu-open")}s.menuOpen&&!y.contains(c)&&!b.contains(c)&&N(),i.stopPropagation()}),d.addEventListener("click",i=>{let c=i.target;if(s.menuOpen&&c instanceof Node&&!y.contains(c)&&!b.contains(c)&&N(),c instanceof Element&&!c.closest(".kp-chat-actions")){for(let m of Array.from(d.querySelectorAll(".kp-chat-actions.open")))m.classList.remove("open");for(let m of Array.from(d.querySelectorAll(".kp-full-page-chat-item.menu-open")))m.classList.remove("menu-open")}}),Ce.addEventListener("submit",async i=>{i.preventDefault(),await pt(z.value)}),Ee.addEventListener("submit",async i=>{i.preventDefault(),await H(T.value,L)});function ft(i){if(i.key==="Escape"){if(s.sourcePanelOpen){G();return}if(s.myChatsOpen){M();return}if(s.fullPageOpen){if(p)return;ct();return}s.open&&j()}}return document.addEventListener("keydown",ft),$e}async function Cn(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"?$n(a,n.citations??[]):{displayText:a,citations:n.citations??[]},p=o("div",`kp-message-row ${t}`),s=Pn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),l=o("div",`kp-bubble ${t}`),d=o("div","kp-bubble-content");jn(d,r.displayText),l.appendChild(d);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=On(b,n.strings);y.addEventListener("click",async()=>{n.onShowCitation(b)}),C.appendChild(y)}let P=Un(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(Ln(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 Ln(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 Pn(e,t){let a=o("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":In(e);return a.textContent=n,a.setAttribute("aria-hidden","true"),a}function An(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){An(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 Rt(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 Sn(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 It(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 d=a.chats.filter(u=>a.chatSearchTerm?u.title.toLowerCase().includes(a.chatSearchTerm):!0);if(d.length>0){let u=d.filter(f=>f.pinned),g=d.filter(f=>!f.pinned).slice(0,8);$t(e,g,a.chatId,n,r,p,s,l),$t(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 $t(e,t,a,n,r,p,s,l){for(let d of t){let u=o("div",`kp-full-page-item kp-full-page-chat-item${d.chatId===a?" active":""}`),g=o("span","kp-full-page-item-title",d.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",d.pinned?n.unpinChat:n.pinChat);P.type="button",P.addEventListener("click",async k=>{k.stopPropagation(),await p(d)});let b=o("button","kp-chat-actions-item",n.renameChat);b.type="button",b.addEventListener("click",async k=>{k.stopPropagation(),await s(d)});let y=o("button","kp-chat-actions-item",n.deleteChat);y.type="button",y.addEventListener("click",async k=>{k.stopPropagation(),await l(d)}),C.append(P,b,y),f.append(h,C),h.addEventListener("click",k=>{k.stopPropagation();let B=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");B||(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(d)}),u.addEventListener("keydown",async k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),await r(d))}),u.addEventListener("blur",()=>{f.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function Tn(e,t){return e.trim().slice(0,60)||t}function Ue(e){return e.toLowerCase().split("-")[0]||"en"}function En(e){let t=Et.en;return Et[Ue(e)]??t}function Rn(e){return["ar","fa","he","ur"].includes(Ue(e))}function In(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(a=>a[0]?.toUpperCase()??"").join("")}function Be(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 $n(e,t){let a=zn(e);return{displayText:a.displayText,citations:t.length>0?Mn(t,a.citations):a.citations}}function zn(e){let a=Nt(e).split(`
|
|
1885
|
+
`),n=-1;for(let d=0;d<a.length;d+=1)/^#{0,6}\s*References\s*$/i.test(a[d]?.trim()??"")&&(n=d);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=Hn(p).map(d=>Nn(d)).filter(d=>!!d);return{displayText:r,citations:l}}function Hn(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 Nn(e){let t=e.match(/https?:\/\/\S+/i);if(!t)return null;let a=t[0],n=e.slice(0,t.index).replace(/[.\s]+$/,"").trim();return{sourceDocument:a,knowledgeName:n||a}}function Mn(e,t){let a=[],n=new Set;for(let r of[...e,...t]){let p=`${r.knowledgeName??""}::${r.sourceDocument??""}`;n.has(p)||(n.add(p),a.push(r))}return a}function On(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",Be(e)??t.untitledSource);return a.append(n,r),a}function Un(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 Bn(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",Be(e)??t.untitledSource),l=o("div","kp-source-card-meta"),d=[];return typeof e.score=="number"&&d.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&d.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&d.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&d.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&d.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),l.textContent=d.join(" \u2022 "),r.appendChild(p),n.append(r,s,l),n}function Dn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function jn(e,t){e.innerHTML=Wn(Nt(t))}function Nt(e){return e.replace(/\r\n/g,`
|
|
1882
1889
|
`).replace(/<br\s*\/?>/gi,`
|
|
1883
|
-
`)}function Wn(e){return e.split(/\n{2,}/).map(a=>a.trim()).filter(Boolean).map(
|
|
1884
|
-
`).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return
|
|
1890
|
+
`)}function Wn(e){return e.split(/\n{2,}/).map(a=>a.trim()).filter(Boolean).map(qn).join("")}function qn(e){let t=e.split(`
|
|
1891
|
+
`).map(n=>n.trimEnd());if(t.every(n=>/^\s*\|.*\|\s*$/.test(n))&&t.length>=2)return Vn(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 Vn(e){let t=e.filter((s,l)=>!(l===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(s))).map(s=>Fn(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 Fn(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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function zt(e){typeof document>"u"||document.querySelectorAll("[data-chat-widget-host]").forEach(t=>{let a=t.shadowRoot;if(a){let n=a.querySelector(".kp-chat-widget");n&&!n.classList.contains("kp-chat-widget-embedded")&&(t.style.display=e?"none":"")}})}var Mt="0.1.0",Ot=ve,Ut={init:Ot,createChatWidget:ve,version:Mt};typeof window<"u"&&(window.ChatWidget=Ut);return vn(_n);})();
|
|
1885
1892
|
//# sourceMappingURL=browser.iife.js.map
|