@nabeh/chat-widget 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  type WidgetPosition = "bottom-right" | "bottom-left";
2
+ type ChatWidgetDisplayMode = "widget" | "embedded";
2
3
  type ChatWidgetTheme = {
3
4
  accent: string;
4
5
  accentSoft: string;
@@ -70,6 +71,7 @@ type ChatWidgetConfig = {
70
71
  deleteLastQa?: string;
71
72
  };
72
73
  mount?: HTMLElement;
74
+ displayMode?: ChatWidgetDisplayMode;
73
75
  position?: WidgetPosition;
74
76
  title?: string;
75
77
  subtitle?: string;
@@ -88,6 +90,11 @@ type ChatWidgetConfig = {
88
90
  onOpen?: () => void;
89
91
  onClose?: () => void;
90
92
  onError?: (error: Error) => void;
93
+ onOpenAssistantPage?: () => Promise<void> | void;
94
+ assistantPageUrl?: string;
95
+ embedded?: {
96
+ showHeader?: boolean;
97
+ };
91
98
  };
92
99
  type ChatWidgetInstance = {
93
100
  open: () => void;
@@ -108,4 +115,4 @@ type BrowserGlobal = {
108
115
 
109
116
  declare function createChatWidget(config: ChatWidgetConfig): ChatWidgetInstance;
110
117
 
111
- export { type BrowserGlobal, type ChatListItem, type ChatWidgetConfig, type ChatWidgetInstance, type ChatWidgetTheme, type SendMessageRequest, type SendMessageResponse, type UserContext, type WidgetPosition, createChatWidget };
118
+ export { type BrowserGlobal, type ChatListItem, type ChatWidgetConfig, type ChatWidgetDisplayMode, type ChatWidgetInstance, type ChatWidgetTheme, type SendMessageRequest, type SendMessageResponse, type UserContext, type WidgetPosition, createChatWidget };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  type WidgetPosition = "bottom-right" | "bottom-left";
2
+ type ChatWidgetDisplayMode = "widget" | "embedded";
2
3
  type ChatWidgetTheme = {
3
4
  accent: string;
4
5
  accentSoft: string;
@@ -70,6 +71,7 @@ type ChatWidgetConfig = {
70
71
  deleteLastQa?: string;
71
72
  };
72
73
  mount?: HTMLElement;
74
+ displayMode?: ChatWidgetDisplayMode;
73
75
  position?: WidgetPosition;
74
76
  title?: string;
75
77
  subtitle?: string;
@@ -88,6 +90,11 @@ type ChatWidgetConfig = {
88
90
  onOpen?: () => void;
89
91
  onClose?: () => void;
90
92
  onError?: (error: Error) => void;
93
+ onOpenAssistantPage?: () => Promise<void> | void;
94
+ assistantPageUrl?: string;
95
+ embedded?: {
96
+ showHeader?: boolean;
97
+ };
91
98
  };
92
99
  type ChatWidgetInstance = {
93
100
  open: () => void;
@@ -108,4 +115,4 @@ type BrowserGlobal = {
108
115
 
109
116
  declare function createChatWidget(config: ChatWidgetConfig): ChatWidgetInstance;
110
117
 
111
- export { type BrowserGlobal, type ChatListItem, type ChatWidgetConfig, type ChatWidgetInstance, type ChatWidgetTheme, type SendMessageRequest, type SendMessageResponse, type UserContext, type WidgetPosition, createChatWidget };
118
+ export { type BrowserGlobal, type ChatListItem, type ChatWidgetConfig, type ChatWidgetDisplayMode, type ChatWidgetInstance, type ChatWidgetTheme, type SendMessageRequest, type SendMessageResponse, type UserContext, type WidgetPosition, createChatWidget };
@@ -1,4 +1,4 @@
1
- "use strict";var ChatWidget=(()=>{var ye=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Xt=Object.prototype.hasOwnProperty;var Yt=(e,t)=>{for(var o in t)ye(e,o,{get:t[o],enumerable:!0})},Jt=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Kt(t))!Xt.call(e,i)&&i!==o&&ye(e,i,{get:()=>t[i],enumerable:!(n=Ft(t,i))||n.enumerable});return e};var Gt=e=>Jt(ye({},"__esModule",{value:!0}),e);var Ln={};Yt(Ln,{createChatWidget:()=>mt});function nt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function we(e,t){let o={...e};for(let n of Object.keys(t)){let i=t[n],s=o[n];if(nt(s)&&nt(i)){o[n]=we(s,i);continue}i!==void 0&&(o[n]=i)}return o}function ot(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Unexpected widget error")}function X(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}function O(e,t,o){return{"Content-Type":"application/json",...e.customHeaders,...o?{"X-Chat-User-Context":o}:{},...t?{Authorization:`Bearer ${t}`}:{}}}async function W(e){if(!e.getUserContext)return null;let t=await e.getUserContext();return t?JSON.stringify(t):null}function le(e,t,o={}){let n=t.replace(/\{chatId\}/g,encodeURIComponent(o.chatId??"")).replace(/:chatId\b/g,encodeURIComponent(o.chatId??""));return X(e.apiBaseUrl,n)}async function at(e,t){let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),i=le(e,e.endpoints.ask,{chatId:t.chatId}),d=/(\{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:O(e,o,n),body:JSON.stringify(d)});if(!p.ok)throw new Error(`Chat backend returned ${p.status}.`);let l=await p.json();if(!Array.isArray(l)){if(!l.answer||typeof l.answer!="string")throw new Error("Chat backend response is missing a valid answer.");return{chatId:l.chatId??t.chatId,answer:l.answer,suggestions:l.suggestions??[],citations:l.citations??[]}}let u=l[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??[],m=g?.scores??[],y=g?.page_numbers??[],b=g?.sheet_names??[],x=g?.row_numbers??[],v=g?.knowledge_names??[],k=f.map(($,C)=>({sourceDocument:$,score:m[C]??null,pageNumber:y[C]??null,sheetName:b[C]??null,rowNumber:x[C]??null,knowledgeName:v[C]??null}));return{chatId:t.chatId,answer:u.answer,suggestions:[],citations:k}}async function st(e,t){if(!e.endpoints.history)return[];let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),s=/(\{chatId\}|:chatId\b)/.test(e.endpoints.history)?le(e,e.endpoints.history,{chatId:t}):(()=>{let u=new URL(X(e.apiBaseUrl,e.endpoints.history));return u.searchParams.set("chat_id",t),u.toString()})(),d=await fetch(s,{method:"GET",headers:O(e,o,n)});if(!d.ok)throw new Error(`Chat history endpoint returned ${d.status}.`);let p=await d.json(),l=Array.isArray(p)?p:p&&typeof p=="object"?p.history??p.messages??p.data??[]:[];return Array.isArray(l)?l.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,m=g.text??g.message??g.content??g.answer;if(typeof m!="string")return null;let y=typeof f=="string"?f.toLowerCase():"assistant";return[{role:y==="user"||y==="human"?"user":"assistant",text:m}]}).flat().filter(u=>!!u):[]}async function rt(e){if(!e.endpoints.listChats)return[];let t=e.getAccessToken?await e.getAccessToken():null,o=await W(e),n=await fetch(X(e.apiBaseUrl,e.endpoints.listChats),{method:"GET",headers:O(e,t,o)});if(!n.ok)throw new Error(`Chat list endpoint returned ${n.status}.`);let i=await n.json(),s=Array.isArray(i)?i:i&&typeof i=="object"?i.chats??i.data??i.items??[]:[];return Array.isArray(s)?s.map(d=>{if(!d||typeof d!="object")return null;let p=d,l=p.chatId??p.chat_id??p.id,u=p.title??p.name??p.chatId;if(typeof l!="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,m={chatId:l,title:u,pinned:typeof p.pinned=="boolean"?p.pinned:!1};return g&&(m.createdAt=g),f&&(m.updatedAt=f),m}).filter(d=>!!d):[]}async function it(e,t,o){let n=e.endpoints.createChat??e.endpoints.listChats;if(!n)return;let i=e.getAccessToken?await e.getAccessToken():null,s=await W(e),d=await fetch(X(e.apiBaseUrl,n),{method:"POST",headers:O(e,i,s),body:JSON.stringify({chatId:t,...o?{title:o}:{}})});if(!d.ok)throw new Error(`Create chat endpoint returned ${d.status}.`)}async function ve(e,t,o){if(!e.endpoints.updateChat)return;let n=e.getAccessToken?await e.getAccessToken():null,i=await W(e),s=le(e,e.endpoints.updateChat,{chatId:t}),d=await fetch(s,{method:"PATCH",headers:O(e,n,i),body:JSON.stringify(o)});if(!d.ok)throw new Error(`Update chat endpoint returned ${d.status}.`)}async function pt(e,t){if(!e.endpoints.deleteChat)return;let o=e.getAccessToken?await e.getAccessToken():null,n=await W(e),i=le(e,e.endpoints.deleteChat,{chatId:t}),s=await fetch(i,{method:"DELETE",headers:O(e,o,n)});if(!s.ok)throw new Error(`Delete chat endpoint returned ${s.status}.`)}function U(e,t){let o=ot(t);return e.onError?.(o),o}var Ce={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'},w={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:{},rag:{knowledgeNames:[],enableReferences:!0,loadHistoryOnOpen:!1},theme:Ce,getAccessToken:void 0,getUserContext:void 0,onOpen:void 0,onClose:void 0,onError:void 0};function lt(e){if(!e.apiBaseUrl?.trim())throw new Error("Chat widget config requires a non-empty apiBaseUrl.");if(!e.endpoints?.ask?.trim())throw new Error("Chat widget config requires endpoints.ask to be provided.");let t=e.mount??document.body,o=we(Ce,e.theme??{});return{apiBaseUrl:e.apiBaseUrl,endpoints:{...e.endpoints},mount:t,position:e.position??w.position,title:e.title??w.title,subtitle:e.subtitle??w.subtitle,welcomeMessage:e.welcomeMessage??w.welcomeMessage,inputPlaceholder:e.inputPlaceholder??w.inputPlaceholder,launcherAriaLabel:e.launcherAriaLabel??w.launcherAriaLabel,closeAriaLabel:e.closeAriaLabel??w.closeAriaLabel,initialSuggestions:e.initialSuggestions??w.initialSuggestions,sourceApp:e.sourceApp??w.sourceApp,locale:e.locale??w.locale,customHeaders:e.customHeaders??w.customHeaders,rag:{...w.rag,...e.rag??{}},theme:o,getAccessToken:e.getAccessToken,getUserContext:e.getUserContext,onOpen:e.onOpen,onClose:e.onClose,onError:e.onError}}function a(e,t,o){let n=document.createElement(e);return t&&(n.className=t),o!==void 0&&(n.textContent=o),n}var ct="kp-chat-widget-styles";function dt(e,t){if(e.getElementById(ct))return;let o=document.createElement("style");o.id=ct,o.textContent=Qt(t),e.appendChild(o)}function Qt(e){return`
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`
2
2
  :host {
3
3
  all: initial;
4
4
  }
@@ -25,6 +25,15 @@
25
25
  box-sizing: border-box;
26
26
  }
27
27
 
28
+ .kp-chat-widget.kp-chat-widget-embedded {
29
+ position: relative;
30
+ inset: auto;
31
+ width: 100%;
32
+ height: 100%;
33
+ min-height: 640px;
34
+ display: block;
35
+ }
36
+
28
37
  *,
29
38
  *::before,
30
39
  *::after {
@@ -37,6 +46,11 @@
37
46
  right: auto;
38
47
  }
39
48
 
49
+ .kp-chat-widget.kp-chat-widget-embedded.bottom-left {
50
+ left: auto;
51
+ right: auto;
52
+ }
53
+
40
54
  .kp-rtl .kp-dropdown-item,
41
55
  .kp-rtl .kp-suggestion,
42
56
  .kp-rtl .kp-input,
@@ -195,6 +209,18 @@
195
209
  overflow: hidden;
196
210
  }
197
211
 
212
+ .kp-full-page.kp-full-page-embedded {
213
+ position: relative;
214
+ inset: auto;
215
+ opacity: 1;
216
+ pointer-events: auto;
217
+ transform: none;
218
+ min-height: 100%;
219
+ height: 100%;
220
+ z-index: auto;
221
+ background: transparent;
222
+ }
223
+
198
224
  .kp-full-page.open {
199
225
  opacity: 1;
200
226
  pointer-events: auto;
@@ -210,6 +236,13 @@
210
236
  overflow: hidden;
211
237
  }
212
238
 
239
+ .kp-full-page-embedded .kp-full-page-shell {
240
+ height: 100%;
241
+ min-height: 100%;
242
+ padding: 0;
243
+ gap: 12px;
244
+ }
245
+
213
246
  .kp-full-page-header {
214
247
  display: flex;
215
248
  align-items: center;
@@ -219,6 +252,10 @@
219
252
  flex: none;
220
253
  }
221
254
 
255
+ .kp-hidden {
256
+ display: none !important;
257
+ }
258
+
222
259
  .kp-full-page-brand {
223
260
  display: flex;
224
261
  align-items: center;
@@ -286,6 +323,10 @@
286
323
  align-items: stretch;
287
324
  }
288
325
 
326
+ .kp-full-page-embedded .kp-full-page-content {
327
+ height: 100%;
328
+ }
329
+
289
330
  .kp-full-page-sidebar,
290
331
  .kp-full-page-panel,
291
332
  .kp-source-panel {
@@ -1280,6 +1321,10 @@
1280
1321
  max-height: 260px;
1281
1322
  }
1282
1323
 
1324
+ .kp-full-page-embedded .kp-full-page-sidebar {
1325
+ max-height: none;
1326
+ }
1327
+
1283
1328
  .kp-source-panel.open {
1284
1329
  position: static;
1285
1330
  inset: auto;
@@ -1296,6 +1341,13 @@
1296
1341
  bottom: 16px;
1297
1342
  }
1298
1343
 
1344
+ .kp-chat-widget.kp-chat-widget-embedded,
1345
+ .kp-chat-widget.kp-chat-widget-embedded.bottom-left {
1346
+ left: auto;
1347
+ right: auto;
1348
+ bottom: auto;
1349
+ }
1350
+
1299
1351
  .kp-panel,
1300
1352
  .kp-chat-widget.bottom-left .kp-panel {
1301
1353
  inset: 0;
@@ -1314,6 +1366,10 @@
1314
1366
  padding: 14px;
1315
1367
  }
1316
1368
 
1369
+ .kp-full-page-embedded .kp-full-page-shell {
1370
+ padding: 0;
1371
+ }
1372
+
1317
1373
  .kp-full-page-header {
1318
1374
  padding: 0;
1319
1375
  }
@@ -1373,15 +1429,15 @@
1373
1429
  40% { transform: translate(16px, -13px) scale(0.92); opacity: 0.96; }
1374
1430
  62% { transform: translate(2px, -2px) scale(1); opacity: 0.98; }
1375
1431
  }
1376
- `}var ut={en:{openChatActions:"Open chat actions",newChat:"New Chat",myChats:"My Chats",openAssistant:"Open Knowledge Assistant",back:"Back",close:"Close",assistantBadge:"Knowledge Assistant",closeAssistantPage:"Close knowledge assistant page",searchChat:"Search Chat",recentActivity:"Recent Activity",pinnedCollections:"Pinned Collections",answersBasedOnPermissions:"Answers are generated based on your access permissions",authTokenForwarded:"Auth token is forwarded from the host app when configured.",thinking:"Thinking...",unableToCreateChat:"Unable to create chat",requestFailed:"Request failed",noRecentChats:"No recent chats yet.",noPinnedChats:"No pinned chats yet.",noChats:"No chats yet.",loadingChats:"Loading chats...",pinChat:"Pin chat",unpinChat:"Unpin chat",renameChat:"Rename",deleteChat:"Delete",chatActions:"Chat actions",renamePrompt:"Enter a new chat name",citationsAttached:e=>`${e} citation${e>1?"s":""} attached`,sourcesUsed:"Sources Used",allSourcesUsed:"All Sources Used",documentsAndReferences:"AI documents and references",showAll:"Show All",noSources:"No sources were returned for this answer.",closeSourcesPanel:"Close sources panel",openSource:"Open source",sourceScore:"Score",sourcePage:"Page",sourceSheet:"Sheet",sourceRow:"Row",sourceKnowledge:"Knowledge Base",untitledSource:"Untitled Source",copy:"Copy",copied:"Copied",helpful:"Helpful",notHelpful:"Needs work",send:"Send message",assistantAvatar:"Assistant",userAvatar:"User"},ar:{openChatActions:"\u0641\u062A\u062D \u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",newChat:"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629",myChats:"\u0645\u062D\u0627\u062F\u062B\u0627\u062A\u064A",openAssistant:"\u0641\u062A\u062D \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",back:"\u0631\u062C\u0648\u0639",close:"\u0625\u063A\u0644\u0627\u0642",assistantBadge:"\u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",closeAssistantPage:"\u0625\u063A\u0644\u0627\u0642 \u0635\u0641\u062D\u0629 \u0645\u0633\u0627\u0639\u062F \u0627\u0644\u0645\u0639\u0631\u0641\u0629",searchChat:"\u0627\u0628\u062D\u062B \u0641\u064A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A",recentActivity:"\u0627\u0644\u0646\u0634\u0627\u0637 \u0627\u0644\u0623\u062E\u064A\u0631",pinnedCollections:"\u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0627\u0644\u0645\u062B\u0628\u062A\u0629",answersBasedOnPermissions:"\u064A\u062A\u0645 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0625\u062C\u0627\u0628\u0627\u062A \u0628\u0646\u0627\u0621\u064B \u0639\u0644\u0649 \u0635\u0644\u0627\u062D\u064A\u0627\u062A \u0627\u0644\u0648\u0635\u0648\u0644 \u0627\u0644\u062E\u0627\u0635\u0629 \u0628\u0643",authTokenForwarded:"\u064A\u062A\u0645 \u062A\u0645\u0631\u064A\u0631 \u0631\u0645\u0632 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0627\u0644\u062A\u0637\u0628\u064A\u0642 \u0627\u0644\u0645\u0636\u064A\u0641 \u0639\u0646\u062F \u0627\u0644\u0625\u0639\u062F\u0627\u062F.",thinking:"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631...",unableToCreateChat:"\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",requestFailed:"\u0641\u0634\u0644 \u0627\u0644\u0637\u0644\u0628",noRecentChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u062D\u062F\u064A\u062B\u0629 \u0628\u0639\u062F.",noPinnedChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0645\u062B\u0628\u062A\u0629 \u0628\u0639\u062F.",noChats:"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A \u0628\u0639\u062F.",loadingChats:"\u062C\u0627\u0631\u064D \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0627\u062A...",pinChat:"\u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",unpinChat:"\u0625\u0644\u063A\u0627\u0621 \u062A\u062B\u0628\u064A\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renameChat:"\u0625\u0639\u0627\u062F\u0629 \u062A\u0633\u0645\u064A\u0629",deleteChat:"\u062D\u0630\u0641",chatActions:"\u0625\u062C\u0631\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629",renamePrompt:"\u0623\u062F\u062E\u0644 \u0627\u0633\u0645\u064B\u0627 \u062C\u062F\u064A\u062F\u064B\u0627 \u0644\u0644\u0645\u062D\u0627\u062F\u062B\u0629",citationsAttached:e=>`\u062A\u0645 \u0625\u0631\u0641\u0627\u0642 ${e} \u0645\u0631\u062C\u0639${e>1?"\u0627\u062A":""}`,sourcesUsed:"\u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",allSourcesUsed:"\u0643\u0644 \u0627\u0644\u0645\u0635\u0627\u062F\u0631 \u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645\u0629",documentsAndReferences:"\u0645\u0633\u062A\u0646\u062F\u0627\u062A \u0648\u0645\u0631\u0627\u062C\u0639 \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A",showAll:"\u0639\u0631\u0636 \u0627\u0644\u0643\u0644",noSources:"\u0644\u0645 \u064A\u062A\u0645 \u0625\u0631\u062C\u0627\u0639 \u0645\u0635\u0627\u062F\u0631 \u0644\u0647\u0630\u0647 \u0627\u0644\u0625\u062C\u0627\u0628\u0629.",closeSourcesPanel:"\u0625\u063A\u0644\u0627\u0642 \u0644\u0648\u062D\u0629 \u0627\u0644\u0645\u0635\u0627\u062F\u0631",openSource:"\u0641\u062A\u062D \u0627\u0644\u0645\u0635\u062F\u0631",sourceScore:"\u0627\u0644\u062F\u0631\u062C\u0629",sourcePage:"\u0627\u0644\u0635\u0641\u062D\u0629",sourceSheet:"\u0627\u0644\u0648\u0631\u0642\u0629",sourceRow:"\u0627\u0644\u0635\u0641",sourceKnowledge:"\u0642\u0627\u0639\u062F\u0629 \u0627\u0644\u0645\u0639\u0631\u0641\u0629",untitledSource:"\u0645\u0635\u062F\u0631 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646",copy:"\u0646\u0633\u062E",copied:"\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",helpful:"\u0645\u0641\u064A\u062F",notHelpful:"\u064A\u062D\u062A\u0627\u062C \u062A\u062D\u0633\u064A\u0646",send:"\u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629",assistantAvatar:"\u0627\u0644\u0645\u0633\u0627\u0639\u062F",userAvatar:"\u0627\u0644\u0645\u0633\u062A\u062E\u062F\u0645"}};function mt(e){if(typeof document>"u")throw new Error("Chat widget can only be initialized in a browser.");let t=lt(e),o=Le(t.locale),n=sn(t.locale),i=rn(o),s={chatId:ce(t),open:!1,fullPageOpen:!1,myChatsOpen:!1,accessTokenProvider:t.getAccessToken,historyLoadedChatId:null,menuOpen:!1,chats:[],chatSearchTerm:"",loadingChats:!1,sourcePanelOpen:!1,sourcePanelTitle:null},d=document.createElement("div");d.dataset.chatWidgetHost="true",t.mount.appendChild(d);let p=d.attachShadow({mode:"open"});dt(p,t.theme);let l=a("div",`kp-chat-widget ${t.position}`);l.lang=o,l.dir=i?"rtl":"ltr",i&&l.classList.add("kp-rtl");let u=a("div","kp-overlay"),g=a("button","kp-launcher");g.type="button",g.setAttribute("aria-label",t.launcherAriaLabel),g.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 f=a("section","kp-panel");f.setAttribute("role","dialog"),f.setAttribute("aria-modal","true"),f.setAttribute("aria-label",t.title);let m=a("div","kp-header"),y=a("div","kp-toolbar"),b=a("button","kp-tool-button kp-menu-trigger");b.type="button",b.setAttribute("aria-label",n.openChatActions),b.innerHTML=['<span class="kp-pencil-icon" aria-hidden="true"></span>','<span class="kp-chevron" aria-hidden="true">\u2304</span>'].join("");let x=a("div","kp-dropdown"),v=a("button","kp-dropdown-item",n.newChat);v.type="button";let k=a("button","kp-dropdown-item",n.myChats);k.type="button";let $=a("button","kp-dropdown-item",n.openAssistant);$.type="button",x.append(v,k,$),y.append(b,x);let C=a("div","kp-title-wrap"),wt=a("h2","kp-title",t.title),vt=a("div","kp-subtitle",t.subtitle);C.append(wt,vt);let Q=a("button","kp-close","\xD7");Q.type="button",Q.setAttribute("aria-label",t.closeAriaLabel),m.append(y,C,Q);let Z=a("div","kp-body"),de=a("div","kp-hero"),Ct=a("div","kp-hero-icon","\u2726"),Lt=a("div","kp-hero-text",t.welcomeMessage);de.append(Ct,Lt);let Ae=a("div","kp-footer"),ue=a("form","kp-form"),S=a("input","kp-input");S.type="text",S.autocomplete="off",S.placeholder=t.inputPlaceholder,S.setAttribute("aria-label",t.inputPlaceholder);let ge=a("button","kp-send","\u279C");ge.type="submit",ge.setAttribute("aria-label",n.send);let At=a("div","kp-note",n.authTokenForwarded);ue.append(S,ge),Ae.append(ue,At),f.append(m,Z,Ae),l.append(u,g,f),p.appendChild(l),Z.appendChild(de);let Pe=a("div","kp-suggestions");Z.appendChild(Pe);let ee=a("section","kp-my-chats-sheet"),Se=a("div","kp-my-chats-header"),te=a("button","kp-my-chats-nav","\u2190");te.type="button",te.setAttribute("aria-label",n.back);let ne=a("button","kp-my-chats-nav kp-my-chats-close","\xD7");ne.type="button",ne.setAttribute("aria-label",n.close),Se.append(te,ne);let Te=a("div","kp-my-chats-body"),Pt=a("div","kp-my-chats-section-label",n.recentActivity),Ie=a("div","kp-my-chats-list"),St=a("div","kp-my-chats-section-label",n.pinnedCollections),Ee=a("div","kp-my-chats-list");Te.append(Pt,Ie,St,Ee),ee.append(Se,Te),f.appendChild(ee);let A={body:Z,input:S,suggestions:Pe,hero:de,kind:"panel"},T=a("section","kp-full-page");T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",`${t.title} page`);let Re=a("div","kp-full-page-shell"),$e=a("div","kp-full-page-header"),He=a("div","kp-full-page-brand"),Tt=a("div","kp-full-page-brand-mark","\u2726"),It=a("div","kp-full-page-brand-text",t.title);He.append(Tt,It);let ze=a("div","kp-full-page-header-actions"),Et=a("div","kp-full-page-badge",n.assistantBadge),oe=a("button","kp-full-page-close","\xD7");oe.type="button",oe.setAttribute("aria-label",n.closeAssistantPage),ze.append(Et,oe),$e.append(He,ze);let Me=a("div","kp-full-page-content"),Ne=a("aside","kp-full-page-sidebar"),fe=a("button","kp-full-page-new-chat",`+ ${n.newChat}`);fe.type="button";let Be=a("div","kp-full-page-search"),V=a("input","kp-full-page-search-input");V.type="search",V.placeholder=n.searchChat;let Rt=a("span","kp-full-page-search-icon","\u2315");Be.append(V,Rt);let $t=a("div","kp-full-page-section-label",n.recentActivity),Ue=a("div","kp-full-page-recent-list"),Ht=a("div","kp-full-page-section-label",n.pinnedCollections),Oe=a("div","kp-full-page-pinned-list");Ne.append(fe,Be,$t,Ue,Ht,Oe);let We=a("main","kp-full-page-main"),je=a("section","kp-full-page-panel"),he=a("div","kp-full-page-body"),me=a("div","kp-full-page-hero"),De=a("div","kp-full-page-hero-badge");De.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 zt=a("div","kp-full-page-hero-text",t.welcomeMessage);me.append(De,zt);let Ve=a("div","kp-suggestions kp-full-page-suggestions");he.append(me,Ve);let qe=a("div","kp-full-page-footer"),be=a("form","kp-form kp-full-page-form"),P=a("input","kp-input kp-full-page-input");P.type="text",P.autocomplete="off",P.placeholder=t.inputPlaceholder,P.setAttribute("aria-label",t.inputPlaceholder);let ke=a("button","kp-send kp-full-page-send","\u279C");ke.type="submit",ke.setAttribute("aria-label",n.send);let Mt=a("div","kp-note kp-full-page-note",n.answersBasedOnPermissions);be.append(P,ke),qe.append(be,Mt),je.append(he,qe),We.appendChild(je);let ae=a("aside","kp-source-panel"),_e=a("div","kp-source-panel-header"),Fe=a("div","kp-source-panel-title-wrap"),Ke=a("div","kp-source-panel-title",n.allSourcesUsed),Nt=a("div","kp-source-panel-subtitle",n.documentsAndReferences);Fe.append(Ke,Nt);let se=a("button","kp-source-panel-close","\xD7");se.type="button",se.setAttribute("aria-label",n.closeSourcesPanel),_e.append(Fe,se);let q=a("div","kp-source-panel-list"),Bt=a("div","kp-source-panel-empty",n.noSources);q.appendChild(Bt),ae.append(_e,q),Me.append(Ne,We,ae),Re.append($e,Me),T.appendChild(Re),l.appendChild(T);let L={body:he,input:P,suggestions:Ve,hero:me,kind:"full-page"},H=()=>({...t,getAccessToken:s.accessTokenProvider}),Xe=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}},_=(r,c)=>{if(s.sourcePanelOpen=!0,s.sourcePanelTitle=c??n.allSourcesUsed,Ke.textContent=s.sourcePanelTitle,ae.classList.add("open"),q.textContent="",r.length===0){q.appendChild(a("div","kp-source-panel-empty",n.noSources));return}for(let h of r)q.appendChild(mn(h,n))},re=()=>{s.sourcePanelOpen=!1,s.sourcePanelTitle=null,ae.classList.remove("open")};j(A,t.initialSuggestions,async r=>{await I(r,A)}),j(L,t.initialSuggestions,async r=>{await I(r,L)}),N(),ie();function Ye(){s.open||(s.open=!0,s.fullPageOpen=!1,E(),T.classList.remove("open"),g.classList.add("hidden"),u.classList.add("visible"),f.classList.add("open"),t.onOpen?.(),t.rag.loadHistoryOnOpen&&xe.loadHistory(),queueMicrotask(()=>S.focus()))}function F(){s.open&&(z(),E(),s.open=!1,g.classList.remove("hidden"),u.classList.remove("visible"),f.classList.remove("open"),t.onClose?.())}async function I(r,c){let h=r.trim();if(!h)return;c.input.value="";try{await Dt(h)}catch(R){let K=U(t,R);J(c.body,"bot",`${n.unableToCreateChat}: ${K.message}`,{strings:n,view:c,userName:null,onShowSources:_});return}gt(c),J(c.body,"user",h,{strings:n,view:c,userName:await Xe(),onShowSources:_}),c.body.scrollTop=c.body.scrollHeight;let B=a("div","kp-loading",n.thinking);c.body.appendChild(B),c.body.scrollTop=c.body.scrollHeight;try{let R=await at(H(),{message:h,chatId:s.chatId,knowledgeNames:await Zt(t),...t.rag.enableReferences!==void 0?{enableReferences:t.rag.enableReferences}:{}});B.isConnected&&B.remove(),J(c.body,"bot",R.answer,{strings:n,view:c,userName:null,citations:R.citations??[],onShowSources:_}),s.historyLoadedChatId=null,await M(),R.suggestions?.length&&j(c,R.suggestions,async K=>{await I(K,c)})}catch(R){let K=U(t,R);B.isConnected&&B.remove(),J(c.body,"bot",`${n.requestFailed}: ${K.message}`,{strings:n,view:c,userName:null,onShowSources:_})}}async function Je(r){let c=s.fullPageOpen?L:A;await I(r,c)}async function Ut(){s.fullPageOpen=!0,s.open=!1,z(),E(),f.classList.remove("open"),u.classList.remove("visible"),g.classList.add("hidden"),T.classList.add("open"),await M(),await pe(L,s.chatId),queueMicrotask(()=>P.focus())}function Ge(){s.fullPageOpen&&(s.fullPageOpen=!1,T.classList.remove("open"),g.classList.remove("hidden"),re())}function Ot(){s.menuOpen=!0,b.classList.add("open"),x.classList.add("open")}function z(){s.menuOpen=!1,b.classList.remove("open"),x.classList.remove("open")}function Wt(){s.chatId=ce(t),s.historyLoadedChatId=null,E(),Y(A),j(A,t.initialSuggestions,async r=>{await I(r,A)}),z()}async function jt(){s.chatId=ce(t),s.historyLoadedChatId=null,Y(L),re(),j(L,t.initialSuggestions,async r=>{await I(r,L)}),N()}async function M(){if(!t.endpoints.listChats)return N(),ie(),[];s.loadingChats=!0,N(),ie();try{let r=await rt(H());return s.chats=r,r}catch(r){return U(t,r),s.chats}finally{s.loadingChats=!1,N(),ie()}}async function Dt(r){!t.endpoints.listChats&&!t.endpoints.createChat||s.chats.some(c=>c.chatId===s.chatId)||await it(H(),s.chatId,r?an(r,n.newChat):void 0)}async function Vt(r){s.chatId=r,s.historyLoadedChatId=null,await pe(L,r),N()}async function qt(r){s.chatId=r,s.historyLoadedChatId=null,await pe(A,r),E()}async function _t(){z(),await M(),s.myChatsOpen=!0,f.classList.add("kp-sheet-open"),ee.classList.add("open")}function E(){s.myChatsOpen=!1,f.classList.remove("kp-sheet-open"),ee.classList.remove("open")}async function Qe(r){if(!t.endpoints.updateChat)return;let c=window.prompt(n.renamePrompt,r.title)?.trim();if(!(!c||c===r.title))try{await ve(H(),r.chatId,{title:c}),await M()}catch(h){U(t,h)}}async function Ze(r){if(t.endpoints.deleteChat)try{await pt(H(),r.chatId),s.chatId===r.chatId&&(s.chatId=ce(t),s.historyLoadedChatId=null,Y(A),Y(L)),await M()}catch(c){U(t,c)}}function N(){ft(Ue,Oe,s,n,async r=>{await Vt(r.chatId)},async r=>{await et(r)},async r=>{await Qe(r)},async r=>{await Ze(r)})}function ie(){ft(Ie,Ee,s,n,async r=>{await qt(r.chatId)},async r=>{await et(r)},async r=>{await Qe(r)},async r=>{await Ze(r)})}async function et(r){if(t.endpoints.updateChat)try{await ve(H(),r.chatId,{pinned:!r.pinned}),await M()}catch(c){U(t,c)}}async function pe(r,c){Y(r),j(r,t.initialSuggestions,async B=>{await I(B,r)});let h=await st(H(),c);return h.length>0&&(gt(r),bt(r.body,r.hero,r.suggestions),on(r.body,h,{strings:n,view:r,userName:await Xe(),onShowSources:_})),s.historyLoadedChatId=c,h}let xe={open:Ye,close:F,toggle(){if(s.open){F();return}Ye()},destroy(){document.removeEventListener("keydown",tt),d.remove()},sendMessage:Je,setAccessTokenProvider(r){s.accessTokenProvider=r},getChatId(){return s.chatId},loadChats(){return M()},async loadHistory(){let r=s.fullPageOpen?L:A;return pe(r,s.chatId)}};g.addEventListener("click",()=>xe.toggle()),Q.addEventListener("click",F),u.addEventListener("click",F),se.addEventListener("click",re),te.addEventListener("click",E),ne.addEventListener("click",E),b.addEventListener("click",r=>{if(r.stopPropagation(),!s.menuOpen){Ot();return}z()}),v.addEventListener("click",Wt),k.addEventListener("click",async()=>{await _t()}),$.addEventListener("click",()=>{Ut()}),oe.addEventListener("click",Ge),fe.addEventListener("click",()=>{jt(),queueMicrotask(()=>P.focus())}),V.addEventListener("input",()=>{s.chatSearchTerm=V.value.trim().toLowerCase(),N()}),f.addEventListener("click",r=>{let c=r.target;if(!(c instanceof Element)||!c.closest(".kp-chat-actions")){for(let h of Array.from(p.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(p.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}s.menuOpen&&!x.contains(c)&&!b.contains(c)&&z(),r.stopPropagation()}),p.addEventListener("click",r=>{let c=r.target;if(s.menuOpen&&c instanceof Node&&!x.contains(c)&&!b.contains(c)&&z(),c instanceof Element&&!c.closest(".kp-chat-actions")){for(let h of Array.from(p.querySelectorAll(".kp-chat-actions.open")))h.classList.remove("open");for(let h of Array.from(p.querySelectorAll(".kp-full-page-chat-item.menu-open")))h.classList.remove("menu-open")}}),ue.addEventListener("submit",async r=>{r.preventDefault(),await Je(S.value)}),be.addEventListener("submit",async r=>{r.preventDefault(),await I(P.value,L)});function tt(r){if(r.key==="Escape"){if(s.sourcePanelOpen){re();return}if(s.myChatsOpen){E();return}if(s.fullPageOpen){Ge();return}s.open&&F()}}return document.addEventListener("keydown",tt),xe}async function Zt(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 J(e,t,o,n){let i=t==="bot"?ln(o,n.citations??[]):{displayText:o,citations:n.citations??[]},s=a("div",`kp-message-row ${t}`),d=tn(t==="bot"?n.strings.assistantAvatar:n.userName??n.strings.userAvatar,t),p=a("div",`kp-bubble ${t}`),l=a("div","kp-bubble-content");xn(l,i.displayText),p.appendChild(l);let u=i.citations;if(u.length){let g=a("div","kp-meta",n.strings.citationsAttached(u.length));p.appendChild(g);let f=a("div","kp-source-preview"),m=a("div","kp-source-preview-title",n.strings.sourcesUsed),y=a("div","kp-source-preview-list");for(let x of u.slice(0,2)){let v=fn(x,n.strings);v.addEventListener("click",async()=>{xt(x,n.strings)}),y.appendChild(v)}let b=hn(n.strings);b.addEventListener("click",async()=>{n.onShowSources(u,n.strings.allSourcesUsed)}),y.appendChild(b),f.append(m,y),p.appendChild(f)}return t==="bot"&&p.appendChild(en(i.displayText,n.strings)),t==="user"?s.append(p,d):s.append(d,p),e.appendChild(s),e.scrollTop=e.scrollHeight,s}function en(e,t){let o=a("div","kp-message-actions"),n=a("button","kp-message-action",t.copy);n.type="button",n.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(e),n.textContent=t.copied,window.setTimeout(()=>{n.textContent=t.copy},1200)}catch{n.textContent=t.copy}});let i=a("button","kp-message-action","\u{1F44D}");i.type="button",i.setAttribute("aria-label",t.helpful),i.addEventListener("click",()=>{i.classList.toggle("active"),s.classList.remove("active")});let s=a("button","kp-message-action","\u{1F44E}");return s.type="button",s.setAttribute("aria-label",t.notHelpful),s.addEventListener("click",()=>{s.classList.toggle("active"),i.classList.remove("active")}),o.append(n,i,s),o}function tn(e,t){let o=a("div",`kp-avatar ${t}`),n=t==="bot"?"\u2726":pn(e);return o.textContent=n,o.setAttribute("aria-hidden","true"),o}function nn(e,t,o){e.textContent="";for(let n of t){let i=a("button","kp-suggestion",n);i.type="button",i.addEventListener("click",async()=>{await o(n)}),e.appendChild(i)}}function j(e,t,o){nn(e.suggestions,t,async n=>{e.input.value=n,await o(n)})}function bt(e,t,o){let n=new Set([t,o]);for(let i of Array.from(e.children))n.has(i)||i.remove()}function gt(e){e.body.classList.add("kp-conversation-active"),e.hero.remove(),e.suggestions.remove()}function Y(e){e.body.classList.remove("kp-conversation-active"),e.hero.isConnected||e.body.prepend(e.hero),e.suggestions.isConnected||e.body.appendChild(e.suggestions),bt(e.body,e.hero,e.suggestions),e.input.value=""}function on(e,t,o){for(let n of t)J(e,n.role==="assistant"?"bot":"user",n.text,o)}function ft(e,t,o,n,i,s,d,p){if(e.textContent="",t.textContent="",o.loadingChats){e.appendChild(a("div","kp-full-page-empty",n.loadingChats));return}let l=o.chats.filter(u=>o.chatSearchTerm?u.title.toLowerCase().includes(o.chatSearchTerm):!0);if(l.length>0){let u=l.filter(f=>f.pinned),g=l.filter(f=>!f.pinned).slice(0,8);ht(e,g,o.chatId,n,i,s,d,p),ht(t,u,o.chatId,n,i,s,d,p),g.length===0&&e.appendChild(a("div","kp-full-page-empty",n.noRecentChats)),u.length===0&&t.appendChild(a("div","kp-full-page-empty",n.noPinnedChats));return}e.appendChild(a("div","kp-full-page-empty",n.noChats)),t.appendChild(a("div","kp-full-page-empty",n.noPinnedChats))}function ht(e,t,o,n,i,s,d,p){for(let l of t){let u=a("div",`kp-full-page-item kp-full-page-chat-item${l.chatId===o?" active":""}`),g=a("span","kp-full-page-item-title",l.title),f=a("div","kp-chat-actions"),m=a("button","kp-chat-actions-trigger","\u22EF");m.type="button",m.setAttribute("aria-label",n.chatActions);let y=a("div","kp-chat-actions-menu"),b=a("button","kp-chat-actions-item",l.pinned?n.unpinChat:n.pinChat);b.type="button",b.addEventListener("click",async k=>{k.stopPropagation(),await s(l)});let x=a("button","kp-chat-actions-item",n.renameChat);x.type="button",x.addEventListener("click",async k=>{k.stopPropagation(),await d(l)});let v=a("button","kp-chat-actions-item",n.deleteChat);v.type="button",v.addEventListener("click",async k=>{k.stopPropagation(),await p(l)}),y.append(b,x,v),f.append(m,y),m.addEventListener("click",k=>{k.stopPropagation();let $=f.classList.contains("open");for(let C of Array.from(e.querySelectorAll(".kp-chat-actions.open")))C.classList.remove("open");for(let C of Array.from(e.querySelectorAll(".kp-full-page-chat-item.menu-open")))C.classList.remove("menu-open");$||(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(l)}),u.addEventListener("keydown",async k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),await i(l))}),u.addEventListener("blur",()=>{f.classList.remove("open"),u.classList.remove("menu-open")}),e.appendChild(u)}}function an(e,t){return e.trim().slice(0,60)||t}function Le(e){return e.toLowerCase().split("-")[0]||"en"}function sn(e){let t=ut.en;return ut[Le(e)]??t}function rn(e){return["ar","fa","he","ur"].includes(Le(e))}function pn(e){let t=e.split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?"U":t.map(o=>o[0]?.toUpperCase()??"").join("")}function kt(e){return e.knowledgeName?.trim()||e.sourceDocument?.trim()||null}function ln(e,t){let o=cn(e);return{displayText:o.displayText,citations:t.length>0?gn(t,o.citations):o.citations}}function cn(e){let o=yt(e).split(`
1377
- `),n=-1;for(let l=0;l<o.length;l+=1)/^#{0,6}\s*References\s*$/i.test(o[l]?.trim()??"")&&(n=l);if(n===-1)return{displayText:e,citations:[]};let i=o.slice(0,n).join(`
1378
- `).trimEnd(),s=o.slice(n+1).join(`
1379
- `).trim(),p=dn(s).map(l=>un(l)).filter(l=>!!l);return{displayText:i,citations:p}}function dn(e){let t=[],o="";for(let n of e.split(`
1380
- `)){let i=n.trim();if(i){if(/^\d+\.\s+/.test(i)){o&&t.push(o.trim()),o=i.replace(/^\d+\.\s+/,"");continue}o&&(o=`${o} ${i}`)}}return o&&t.push(o.trim()),t}function un(e){let t=e.match(/https?:\/\/\S+/i);if(!t)return null;let o=t[0],n=e.slice(0,t.index).replace(/[.\s]+$/,"").trim();return{sourceDocument:o,knowledgeName:n||o}}function gn(e,t){let o=[],n=new Set;for(let i of[...e,...t]){let s=`${i.knowledgeName??""}::${i.sourceDocument??""}`;n.has(s)||(n.add(s),o.push(i))}return o}function fn(e,t){let o=a("button","kp-source-chip");o.type="button",o.setAttribute("aria-label",t.openSource);let n=a("span","kp-source-thumb");n.textContent="\u2726";let i=a("span","kp-source-chip-label",kt(e)??t.untitledSource);return o.append(n,i),o}function hn(e){let t=a("button","kp-source-chip kp-source-chip-more");t.type="button";let o=a("span","kp-source-thumb-stack");for(let i=0;i<3;i+=1){let s=a("span","kp-source-thumb stacked");s.textContent="\u2726",o.appendChild(s)}let n=a("span","kp-source-chip-label",e.showAll);return t.append(o,n),t}function mn(e,t){let o=a("button","kp-source-card");o.type="button",o.setAttribute("aria-label",t.openSource),o.addEventListener("click",()=>{xt(e,t)});let n=a("div","kp-source-card-media"),i=a("span","kp-source-thumb kp-source-thumb-large");i.textContent="\u2726";let s=a("div","kp-source-card-title",kt(e)??t.untitledSource),d=a("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}`),d.textContent=p.join(" \u2022 "),n.appendChild(i),o.append(n,s,d),o}function xt(e,t){let o=e.sourceDocument?.trim()||e.knowledgeName?.trim()||t.untitledSource,n=bn(e.sourceDocument);if(n){window.open(n,"_blank","noopener,noreferrer");return}let i=window.open("","_blank","noopener,noreferrer");if(!i)return;let s=G(o),d=kn(e,t).map(p=>`<li>${G(p)}</li>`).join("");i.document.write(`<!doctype html>
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>
1381
1437
  <html lang="en">
1382
1438
  <head>
1383
1439
  <meta charset="utf-8">
1384
- <title>${s}</title>
1440
+ <title>${l}</title>
1385
1441
  <style>
1386
1442
  body { font-family: Arial, sans-serif; margin: 32px; color: #1f2937; }
1387
1443
  .card { max-width: 720px; padding: 24px; border: 1px solid #dbe4ee; border-radius: 16px; background: #fff; }
@@ -1392,13 +1448,13 @@
1392
1448
  </head>
1393
1449
  <body>
1394
1450
  <div class="card">
1395
- <h1>${s}</h1>
1396
- <p>${G(t.documentsAndReferences)}</p>
1397
- <ul>${d||`<li>${G(t.noSources)}</li>`}</ul>
1451
+ <h1>${l}</h1>
1452
+ <p>${Z(t.documentsAndReferences)}</p>
1453
+ <ul>${s||`<li>${Z(t.noSources)}</li>`}</ul>
1398
1454
  </div>
1399
1455
  </body>
1400
- </html>`),i.document.close()}function bn(e){if(!e)return null;let t=e.trim();return/^https?:\/\//i.test(t)?t:null}function kn(e,t){let o=[];return e.sourceDocument&&o.push(e.sourceDocument),typeof e.score=="number"&&o.push(`${t.sourceScore}: ${e.score.toFixed(2)}`),typeof e.pageNumber=="number"&&o.push(`${t.sourcePage}: ${e.pageNumber}`),e.sheetName&&o.push(`${t.sourceSheet}: ${e.sheetName}`),typeof e.rowNumber=="number"&&o.push(`${t.sourceRow}: ${e.rowNumber}`),e.knowledgeName&&o.push(`${t.sourceKnowledge}: ${e.knowledgeName}`),o}function xn(e,t){e.innerHTML=yn(yt(t))}function yt(e){return e.replace(/\r\n/g,`
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,`
1401
1457
  `).replace(/<br\s*\/?>/gi,`
1402
- `)}function yn(e){return e.split(/\n{2,}/).map(o=>o.trim()).filter(Boolean).map(wn).join("")}function wn(e){let t=e.split(`
1403
- `).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>${D(n.replace(/^\d+\.\s+/,""))}</li>`).join("")}</ol>`;if(t.every(n=>/^[-*]\s+/.test(n)))return`<ul>${t.map(n=>`<li>${D(n.replace(/^[-*]\s+/,""))}</li>`).join("")}</ul>`;let o=t[0]?.match(/^(#{1,6})\s+(.*)$/);if(o){let n=o[1]??"#",i=o[2]??"",s=n.length;return`<h${s}>${D(i)}</h${s}>`}return`<p>${t.map(n=>D(n)).join("<br>")}</p>`}function vn(e){let t=e.filter((d,p)=>!(p===1&&/^\s*\|?(\s*:?-{3,}:?\s*\|)+\s*$/.test(d))).map(d=>Cn(d));if(t.length===0)return"";let o=t[0]??[],n=t.slice(1),i=`<thead><tr>${o.map(d=>`<th>${D(d)}</th>`).join("")}</tr></thead>`,s=n.length?`<tbody>${n.map(d=>`<tr>${d.map(p=>`<td>${D(p)}</td>`).join("")}</tr>`).join("")}</tbody>`:"";return`<div class="kp-table-wrap"><table>${i}${s}</table></div>`}function Cn(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}function D(e){let t=G(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 G(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}return Gt(Ln);})();
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);})();
1404
1460
  //# sourceMappingURL=index.iife.js.map