kyt-chat 1.0.5 → 1.0.6
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/kyt-chat.iife.js
CHANGED
|
@@ -483,4 +483,4 @@ Error generating stack: `+e.message+`
|
|
|
483
483
|
}
|
|
484
484
|
.kyt-bubble-btn { bottom: 16px; right: 16px; }
|
|
485
485
|
}
|
|
486
|
-
`}var f=!1;function p(e){if(f)return;f=!0;let t=document.createElement(`style`);t.setAttribute(`data-kyt`,`1`),t.textContent=d(e),document.head.appendChild(t)}function m(){return Math.random().toString(36).slice(2)}var h=new Map;function g(e){return e.topicId??e.queryUrl}function _(e){let t=g(e),[n,r]=(0,u.useState)(()=>h.get(t)??[]),[i,a]=(0,u.useState)(!1),[o,s]=(0,u.useState)(null),c=(0,u.useRef)(null),l=(0,u.useCallback)(e=>{r(n=>{let r=e(n);return h.set(t,r),r})},[t]);return{messages:n,loading:i,error:o,sendMessage:(0,u.useCallback)(async t=>{let n=t.trim();if(!(!n||i)){s(null),l(e=>[...e,{id:m(),role:`user`,text:n}]),a(!0),c.current?.abort(),c.current=new AbortController;try{let t=await(await fetch(e.queryUrl,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({input:n,...e.topicId?{topic_id:e.topicId}:{}}),signal:c.current.signal})).json();l(e=>[...e,{id:m(),role:`assistant`,text:t.answer??`No response.`,confidence:t.confidence,sources:t.sources,extra_sources:t.extra_sources}])}catch(e){if(e.name===`AbortError`)return;let t=e instanceof Error?e.message:`Something went wrong.`;s(t),l(e=>[...e,{id:m(),role:`assistant`,text:t,confidence:`low`}])}finally{a(!1)}}},[e,i]),reset:(0,u.useCallback)(()=>{c.current?.abort(),h.delete(t),r([]),s(null),a(!1)},[t])}}var v=t((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),y=t(((e,t)=>{t.exports=v()}))();function b(e){let t=Math.floor(e);return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`}function x({url:e,label:t}){return e?(0,y.jsxs)(`a`,{className:`kyt-source-btn`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:[(0,y.jsxs)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:[(0,y.jsx)(`path`,{d:`M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6`}),(0,y.jsx)(`polyline`,{points:`15 3 21 3 21 9`}),(0,y.jsx)(`line`,{x1:`10`,y1:`14`,x2:`21`,y2:`3`})]}),t]}):null}function ee({s:e}){let t=e.source_type===`external`,n=e.url??``,r=n.includes(`#`)?`Jump to section`:`Go to source`;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsx)(`span`,{className:`kyt-card-type kyt-t-${t?`external`:`website`}`,children:t?`EXTERNAL`:`WEBSITE`}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[e.summary&&(0,y.jsx)(`div`,{className:`kyt-card-summary`,children:e.summary}),(0,y.jsx)(`div`,{className:`kyt-card-actions`,children:(0,y.jsx)(x,{url:n,label:r})})]})]})}function S({s:e}){let t=e.url||e.storage_url||void 0;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsx)(`span`,{className:`kyt-card-type kyt-t-pdf`,children:`PDF`}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[e.summary&&(0,y.jsx)(`div`,{className:`kyt-card-summary`,children:e.summary}),(0,y.jsxs)(`div`,{className:`kyt-card-actions`,children:[e.pdf_page!=null&&(0,y.jsxs)(`span`,{className:`kyt-pdf-page-badge`,children:[`📄 Page `,e.pdf_page]}),(0,y.jsx)(x,{url:t,label:e.pdf_page==null?`Open PDF`:`Open page ${e.pdf_page}`})]})]})]})}function C({s:e}){let t=e.start_time===null||e.start_time===void 0,n=t?0:e.start_time??0,r=e.drive_embed_url??``;r&&(r=r.split(`?`)[0].split(`#`)[0],!t&&n>0&&(r=r.includes(`drive.google.com`)?`${r}?start=${n}`:`${r}#t=${n}`));let i=r.includes(`drive.google.com`),a=t?`Watch video`:`Jump to ${b(n)}`;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsx)(`span`,{className:`kyt-card-type kyt-t-video`,children:`VIDEO`}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[r&&(0,y.jsx)(`div`,{className:`kyt-video-embed-wrapper`,children:i?(0,y.jsx)(`iframe`,{src:r,allowFullScreen:!0,loading:`lazy`,allow:`fullscreen`,style:{border:0}}):(0,y.jsx)(`video`,{controls:!0,preload:`none`,"data-start":!t&&n>0?n:void 0,children:(0,y.jsx)(`source`,{src:r})})}),(0,y.jsxs)(`div`,{className:`kyt-card-actions`,children:[!t&&n>0&&(0,y.jsxs)(`span`,{className:`kyt-timestamp-chip`,children:[`⏱ `,b(n)]}),(0,y.jsx)(x,{url:r||void 0,label:a}),e.url&&e.url!==r&&(0,y.jsx)(x,{url:e.url,label:`Go to source`})]}),e.content_snippet&&(0,y.jsxs)(`div`,{className:`kyt-transcript-snippet`,children:[`"`,e.content_snippet,`…"`]})]})]})}function te({s:e}){let t=e.storage_url??void 0,n=e.storage_url??e.url??``;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsx)(`span`,{className:`kyt-card-type kyt-t-social`,children:`IMAGE`}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[t&&(0,y.jsx)(`div`,{className:`kyt-card-img-wrap`,children:(0,y.jsx)(`img`,{src:t,alt:e.source_label})}),e.summary&&(0,y.jsx)(`div`,{className:`kyt-card-summary`,children:e.summary}),(0,y.jsx)(`div`,{className:`kyt-card-actions`,children:(0,y.jsx)(x,{url:n||void 0,label:`View image`})})]})]})}function ne({s:e}){let t=(e.source_label??``).toLowerCase(),n=t.includes(`x`)||t.includes(`twitter`)?`𝕏`:t.includes(`linkedin`)?`in`:`◎`,r=e.content_snippet??e.summary??``;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsxs)(`span`,{className:`kyt-card-type kyt-t-social`,children:[n,` SOCIAL`]}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[r&&(0,y.jsx)(`div`,{className:`kyt-card-summary`,children:r}),(0,y.jsx)(`div`,{className:`kyt-card-actions`,children:(0,y.jsx)(x,{url:e.url,label:`View post`})})]})]})}function re({s:e}){return e.source_type===`video`?(0,y.jsx)(C,{s:e}):e.source_type===`pdf`?(0,y.jsx)(S,{s:e}):e.source_type===`image`?(0,y.jsx)(te,{s:e}):e.source_type===`social`?(0,y.jsx)(ne,{s:e}):(0,y.jsx)(ee,{s:e})}function w(e){return e.source_type===`video`?`video::${e.source_label}::${e.start_time??`desc`}`:e.source_type===`pdf`?`pdf::${e.source_label}::${e.pdf_page??`all`}`:e.source_type===`image`?`image::${e.storage_url??e.url??e.source_label}`:`${e.source_type}::${e.url??e.source_label}`}function ie(e){let t=new Set;return e.filter(e=>{let n=w(e);return t.has(n)?!1:(t.add(n),!0)})}function ae({sources:e,extra_sources:t=[]}){let[n,r]=(0,u.useState)(!1),i=ie(e),a=ie(t);return i.length?(0,y.jsxs)(`div`,{className:`kyt-sources-row`,children:[(0,y.jsxs)(`div`,{className:`kyt-sources-header`,children:[`Sources (`,i.length,a.length?`+`:``,`)`]}),(0,y.jsxs)(`div`,{className:`kyt-source-cards`,children:[i.map((e,t)=>(0,y.jsx)(re,{s:e},t)),a.length>0&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`button`,{className:`kyt-extra-toggle`,onClick:()=>r(e=>!e),children:n?`Show less`:`+ ${a.length} more source${a.length>1?`s`:``}`}),n&&(0,y.jsx)(`div`,{className:`kyt-extra-cards`,children:a.map((e,t)=>(0,y.jsx)(re,{s:e},t))})]})]})]}):null}function oe(e){return e.replace(/\*\*(.*?)\*\*/g,`<strong>$1</strong>`).replace(/\n/g,`<br>`)}function se({config:e,onClose:t,showHeader:n=!0,bubbleMode:r=!1,pendingFaq:i,onFaqSent:a}){let{messages:o,loading:s,sendMessage:c,reset:l}=_(e),[d,f]=(0,u.useState)(``),p=(0,u.useRef)(null),m=(0,u.useRef)(null),h=e.theme??`dark`,g=e.faqs??[],v=e.title??`Ask anything`,b=e.placeholder??`Type your question…`,x=e.welcomeMessage??`Ask a question to get started.`,ee=e.avatarLabel??`AI`,S=e.hint??``;(0,u.useEffect)(()=>{p.current?.scrollIntoView({behavior:`smooth`})},[o,s]);let C=(0,u.useRef)(void 0);(0,u.useEffect)(()=>{i&&i!==C.current&&(C.current=i,c(i),a?.())},[i,c,a]);let te=()=>{!d.trim()||s||(c(d),f(``),m.current?.focus())},ne=e=>{c(e),f(``)};return(0,y.jsx)(`div`,{className:`kyt-root${h===`light`?` kyt-light`:``}`,style:{height:`100%`,display:`flex`,flexDirection:`column`},children:(0,y.jsxs)(`div`,{className:`kyt-page`,children:[n&&(0,y.jsxs)(`header`,{className:`kyt-header`,children:[(0,y.jsx)(`span`,{className:`kyt-header-title`,children:v}),(0,y.jsxs)(`div`,{className:`kyt-header-right`,children:[(0,y.jsxs)(`div`,{className:`kyt-live`,children:[(0,y.jsx)(`div`,{className:`kyt-live-dot`}),`Live`]}),(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:l,title:`Clear chat`,"aria-label":`Clear chat`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z`})})}),t&&(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:t,"aria-label":`Close chat`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})})})]})]}),(0,y.jsxs)(`div`,{className:`kyt-body`,children:[!r&&g.length>0&&(0,y.jsxs)(`aside`,{className:`kyt-sidebar`,children:[(0,y.jsx)(`div`,{className:`kyt-sidebar-label`,children:`Suggested Questions`}),(0,y.jsx)(`div`,{className:`kyt-faq-list`,children:g.map((e,t)=>(0,y.jsx)(`button`,{className:`kyt-faq-btn`,onClick:()=>ne(e),children:e},t))})]}),(0,y.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,overflow:`hidden`},children:[(0,y.jsxs)(`div`,{className:`kyt-messages`,children:[o.length===0&&(0,y.jsxs)(`div`,{className:`kyt-welcome`,children:[(0,y.jsx)(`div`,{className:`kyt-welcome-icon`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`28`,height:`28`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z`})})}),(0,y.jsx)(`h2`,{children:v}),(0,y.jsx)(`p`,{children:x})]}),o.map(e=>(0,y.jsx)(ce,{msg:e,avatarLabel:ee},e.id)),s&&(0,y.jsxs)(`div`,{className:`kyt-msg kyt-msg-assistant`,children:[(0,y.jsx)(`div`,{className:`kyt-avatar`,children:ee[0]}),(0,y.jsxs)(`div`,{className:`kyt-typing`,children:[(0,y.jsx)(`div`,{className:`kyt-dot`}),(0,y.jsx)(`div`,{className:`kyt-dot`}),(0,y.jsx)(`div`,{className:`kyt-dot`})]})]}),(0,y.jsx)(`div`,{ref:p})]}),(0,y.jsxs)(`div`,{className:`kyt-input-bar`,children:[(0,y.jsxs)(`div`,{className:`kyt-input-row`,children:[(0,y.jsx)(`input`,{ref:m,className:`kyt-input`,value:d,placeholder:b,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),te())},disabled:s}),(0,y.jsx)(`button`,{className:`kyt-send-btn`,onClick:te,disabled:s||!d.trim(),"aria-label":`Send`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,children:(0,y.jsx)(`path`,{d:`M2 21l21-9L2 3v7l15 2-15 2z`})})})]}),S&&(0,y.jsx)(`div`,{className:`kyt-hint`,children:S})]})]})]})]})})}function ce({msg:e,avatarLabel:t}){if(e.role===`user`)return(0,y.jsx)(`div`,{className:`kyt-msg kyt-msg-user`,children:(0,y.jsx)(`div`,{className:`kyt-bubble kyt-bubble-user`,dangerouslySetInnerHTML:{__html:oe(e.text)}})});let n=e.confidence===`high`?`kyt-conf kyt-conf-high`:e.confidence===`low`?`kyt-conf kyt-conf-low`:`kyt-conf kyt-conf-medium`;return(0,y.jsxs)(`div`,{className:`kyt-msg kyt-msg-assistant`,style:{flexDirection:`column`},children:[(0,y.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,gap:10},children:[(0,y.jsx)(`div`,{className:`kyt-avatar`,children:t[0]}),(0,y.jsxs)(`div`,{className:`kyt-bubble kyt-bubble-assistant`,children:[(0,y.jsx)(`span`,{dangerouslySetInnerHTML:{__html:oe(e.text)}}),e.confidence&&(0,y.jsx)(`span`,{className:n,children:e.confidence.toUpperCase()})]})]}),e.sources&&e.sources.length>0&&(0,y.jsx)(ae,{sources:e.sources,extra_sources:e.extra_sources})]})}function le({config:e}){let[t,n]=(0,u.useState)(!1),[r,i]=(0,u.useState)(!1),[a,o]=(0,u.useState)(!1),[s,c]=(0,u.useState)(),l=e.primaryColor??`#1565c0`,d=e.faqs??[],{reset:f}=_(e);(0,u.useEffect)(()=>{p(l)},[l]);let m=()=>{n(!1),i(!1),o(!1)},h=e=>{c({text:e,id:Date.now()}),o(!1)};return(0,y.jsxs)(`div`,{className:`kyt-root`,children:[t&&r&&(0,y.jsx)(`div`,{className:`kyt-bubble-expanded-backdrop`,onClick:m}),t&&(0,y.jsxs)(`div`,{className:r?`kyt-bubble-expanded`:`kyt-bubble-compact`,children:[(0,y.jsxs)(`div`,{className:`kyt-bubble-header`,style:{background:l},children:[(0,y.jsx)(`span`,{className:`kyt-bubble-header-title`,children:e.title??`Ask anything`}),(0,y.jsxs)(`div`,{className:`kyt-bubble-header-actions`,children:[(0,y.jsxs)(`div`,{className:`kyt-live`,style:{marginRight:4},children:[(0,y.jsx)(`div`,{className:`kyt-live-dot`}),`Live`]}),(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:f,title:`Clear chat`,"aria-label":`Clear chat`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z`})})}),d.length>0&&(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:()=>o(e=>!e),title:`Suggested questions`,"aria-label":`Suggested questions`,children:`💡`}),(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:()=>i(e=>!e),title:r?`Compact`:`Expand`,"aria-label":r?`Compact`:`Expand`,children:r?(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z`})}):(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z`})})}),(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:m,"aria-label":`Close chat`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})})})]})]}),(0,y.jsxs)(`div`,{style:{flex:1,overflow:`hidden`,display:`flex`,flexDirection:`column`,position:`relative`},children:[(0,y.jsx)(se,{config:e,showHeader:!1,bubbleMode:!0,pendingFaq:s?.text,onFaqSent:()=>c(void 0)}),a&&d.length>0&&(0,y.jsxs)(`div`,{className:`kyt-faq-drawer`,children:[(0,y.jsxs)(`div`,{className:`kyt-faq-drawer-header`,children:[(0,y.jsx)(`span`,{className:`kyt-faq-drawer-label`,children:`Suggested`}),(0,y.jsx)(`button`,{className:`kyt-faq-drawer-close`,onClick:()=>o(!1),"aria-label":`Close`,children:`✕`})]}),(0,y.jsx)(`div`,{className:`kyt-faq-drawer-list`,children:d.map((e,t)=>(0,y.jsx)(`button`,{className:`kyt-faq-drawer-btn`,onClick:()=>h(e),children:e},t))})]})]})]}),!r&&(0,y.jsx)(`button`,{className:`kyt-bubble-btn`,style:{background:l},onClick:()=>n(e=>!e),"aria-label":t?`Close chat`:`Open chat`,children:t?(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,children:(0,y.jsx)(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})}):(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,children:(0,y.jsx)(`path`,{d:`M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z`})})})]})}function ue({config:e,style:t,className:n}){return(0,u.useEffect)(()=>{p(e.primaryColor??`#1565c0`)},[e.primaryColor]),(0,y.jsx)(`div`,{style:{height:`100%`,width:`100%`,...t},className:n,children:(0,y.jsx)(se,{config:e,showHeader:!0})})}function T(e){let t=document.querySelector(e);if(!t)throw Error(`kyt-chat: no element found for selector "${e}"`);return t}function E(e,t){p(e.primaryColor??`#1565c0`),(0,l.createRoot)(T(t)).render((0,u.createElement)(le,{config:e}))}function de(e,t){p(e.primaryColor??`#1565c0`);let n=T(t);n.style.height=n.style.height||`100vh`,n.style.display=`flex`,n.style.flexDirection=`column`,(0,l.createRoot)(n).render((0,u.createElement)(ue,{config:e,style:{height:`100%`,flex:1}}))}function fe(e,t,n=`bubble`){n===`chat`?de(e,t):E(e,t)}return e.mount=fe,e.mountBubble=E,e.mountChat=de,e})({});
|
|
486
|
+
`}var f=!1;function p(e){if(f)return;f=!0;let t=document.createElement(`style`);t.setAttribute(`data-kyt`,`1`),t.textContent=d(e),document.head.appendChild(t)}function m(){return Math.random().toString(36).slice(2)}var h=new Map;function g(e){return e.topicId??e.queryUrl}function _(e){let t=g(e),[n,r]=(0,u.useState)(()=>h.get(t)??[]),[i,a]=(0,u.useState)(!1),[o,s]=(0,u.useState)(null),c=(0,u.useRef)(null),l=(0,u.useCallback)(e=>{r(n=>{let r=e(n);return h.set(t,r),r})},[t]);return{messages:n,loading:i,error:o,sendMessage:(0,u.useCallback)(async t=>{let n=t.trim();if(!(!n||i)){s(null),l(e=>[...e,{id:m(),role:`user`,text:n}]),a(!0),c.current?.abort(),c.current=new AbortController;try{let t=await(await fetch(e.queryUrl,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({input:n,...e.topicId?{topic_id:e.topicId}:{}}),signal:c.current.signal})).json();l(e=>[...e,{id:m(),role:`assistant`,text:t.answer??`No response.`,confidence:t.confidence,sources:t.sources,extra_sources:t.extra_sources}])}catch(e){if(e.name===`AbortError`)return;let t=e instanceof Error?e.message:`Something went wrong.`;s(t),l(e=>[...e,{id:m(),role:`assistant`,text:t,confidence:`low`}])}finally{a(!1)}}},[e,i]),reset:(0,u.useCallback)(()=>{c.current?.abort(),h.delete(t),r([]),s(null),a(!1)},[t])}}var v=t((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),y=t(((e,t)=>{t.exports=v()}))();function b(e){let t=Math.floor(e);return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`}function x({url:e,label:t}){return e?(0,y.jsxs)(`a`,{className:`kyt-source-btn`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:[(0,y.jsxs)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:[(0,y.jsx)(`path`,{d:`M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6`}),(0,y.jsx)(`polyline`,{points:`15 3 21 3 21 9`}),(0,y.jsx)(`line`,{x1:`10`,y1:`14`,x2:`21`,y2:`3`})]}),t]}):null}function ee({s:e}){let t=e.source_type===`external`,n=e.url??``,r=n.includes(`#`)?`Jump to section`:`Go to source`;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsx)(`span`,{className:`kyt-card-type kyt-t-${t?`external`:`website`}`,children:t?`EXTERNAL`:`WEBSITE`}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[e.summary&&(0,y.jsx)(`div`,{className:`kyt-card-summary`,children:e.summary}),(0,y.jsx)(`div`,{className:`kyt-card-actions`,children:(0,y.jsx)(x,{url:n,label:r})})]})]})}function S({s:e}){let t=e.url||e.storage_url||void 0;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsx)(`span`,{className:`kyt-card-type kyt-t-pdf`,children:`PDF`}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[e.summary&&(0,y.jsx)(`div`,{className:`kyt-card-summary`,children:e.summary}),(0,y.jsxs)(`div`,{className:`kyt-card-actions`,children:[e.pdf_page!=null&&(0,y.jsxs)(`span`,{className:`kyt-pdf-page-badge`,children:[`📄 Page `,e.pdf_page]}),(0,y.jsx)(x,{url:t,label:e.pdf_page==null?`Open PDF`:`Open page ${e.pdf_page}`})]})]})]})}function C({s:e}){let t=e.start_time===null||e.start_time===void 0,n=t?0:e.start_time??0,r=e.drive_embed_url??``;r&&(r=r.split(`?`)[0].split(`#`)[0],!t&&n>0&&(r=r.includes(`drive.google.com`)?`${r}?start=${n}`:`${r}#t=${n}`));let i=r.includes(`drive.google.com`),a=t?`Watch video`:`Jump to ${b(n)}`;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsx)(`span`,{className:`kyt-card-type kyt-t-video`,children:`VIDEO`}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[r&&(0,y.jsx)(`div`,{className:`kyt-video-embed-wrapper`,children:i?(0,y.jsx)(`iframe`,{src:r,allowFullScreen:!0,loading:`lazy`,allow:`fullscreen`,style:{border:0}}):(0,y.jsx)(`video`,{controls:!0,preload:`none`,"data-start":!t&&n>0?n:void 0,children:(0,y.jsx)(`source`,{src:r})})}),(0,y.jsxs)(`div`,{className:`kyt-card-actions`,children:[!t&&n>0&&(0,y.jsxs)(`span`,{className:`kyt-timestamp-chip`,children:[`⏱ `,b(n)]}),(0,y.jsx)(x,{url:r||void 0,label:a}),e.url&&e.url!==r&&(0,y.jsx)(x,{url:e.url,label:`Go to source`})]}),e.content_snippet&&(0,y.jsxs)(`div`,{className:`kyt-transcript-snippet`,children:[`"`,e.content_snippet,`…"`]})]})]})}function te({s:e}){let t=e.storage_url??void 0,n=e.storage_url??e.url??``;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsx)(`span`,{className:`kyt-card-type kyt-t-social`,children:`IMAGE`}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[t&&(0,y.jsx)(`div`,{className:`kyt-card-img-wrap`,children:(0,y.jsx)(`img`,{src:t,alt:e.source_label})}),e.summary&&(0,y.jsx)(`div`,{className:`kyt-card-summary`,children:e.summary}),(0,y.jsx)(`div`,{className:`kyt-card-actions`,children:(0,y.jsx)(x,{url:n||void 0,label:`View image`})})]})]})}function ne({s:e}){let t=(e.source_label??``).toLowerCase(),n=t.includes(`x`)||t.includes(`twitter`)?`𝕏`:t.includes(`linkedin`)?`in`:`◎`,r=e.content_snippet??e.summary??``;return(0,y.jsxs)(`div`,{className:`kyt-source-card`,children:[(0,y.jsxs)(`div`,{className:`kyt-card-header`,children:[(0,y.jsxs)(`span`,{className:`kyt-card-type kyt-t-social`,children:[n,` SOCIAL`]}),(0,y.jsx)(`span`,{className:`kyt-card-label`,children:e.source_label.replace(/_/g,` `)})]}),(0,y.jsxs)(`div`,{className:`kyt-card-body`,children:[r&&(0,y.jsx)(`div`,{className:`kyt-card-summary`,children:r}),(0,y.jsx)(`div`,{className:`kyt-card-actions`,children:(0,y.jsx)(x,{url:e.url,label:`View post`})})]})]})}function re({s:e}){return e.source_type===`video`?(0,y.jsx)(C,{s:e}):e.source_type===`pdf`?(0,y.jsx)(S,{s:e}):e.source_type===`image`?(0,y.jsx)(te,{s:e}):e.source_type===`social`?(0,y.jsx)(ne,{s:e}):(0,y.jsx)(ee,{s:e})}function w(e){return e.source_type===`video`?`video::${e.source_label}::${e.start_time??`desc`}`:e.source_type===`pdf`?`pdf::${e.source_label}::${e.pdf_page??`all`}`:e.source_type===`image`?`image::${e.storage_url??e.url??e.source_label}`:`${e.source_type}::${e.url??e.source_label}`}function ie(e){let t=new Set;return e.filter(e=>{let n=w(e);return t.has(n)?!1:(t.add(n),!0)})}function ae({sources:e,extra_sources:t=[]}){let[n,r]=(0,u.useState)(!1),i=ie(e),a=ie(t);return i.length?(0,y.jsxs)(`div`,{className:`kyt-sources-row`,children:[(0,y.jsxs)(`div`,{className:`kyt-sources-header`,children:[`Sources (`,i.length,a.length?`+`:``,`)`]}),(0,y.jsxs)(`div`,{className:`kyt-source-cards`,children:[i.map((e,t)=>(0,y.jsx)(re,{s:e},t)),a.length>0&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`button`,{className:`kyt-extra-toggle`,onClick:()=>r(e=>!e),children:n?`Show less`:`+ ${a.length} more source${a.length>1?`s`:``}`}),n&&(0,y.jsx)(`div`,{className:`kyt-extra-cards`,children:a.map((e,t)=>(0,y.jsx)(re,{s:e},t))})]})]})]}):null}function oe(e){return e.replace(/\*\*(.*?)\*\*/g,`<strong>$1</strong>`).replace(/\n/g,`<br>`)}function se({config:e,onClose:t,showHeader:n=!0,bubbleMode:r=!1,pendingFaq:i,onFaqSent:a,clearTrigger:o}){let{messages:s,loading:c,sendMessage:l,reset:d}=_(e),f=(0,u.useRef)(void 0);(0,u.useEffect)(()=>{o!==void 0&&o!==f.current&&f.current!==void 0&&d(),f.current=o},[o,d]);let[p,m]=(0,u.useState)(``),h=(0,u.useRef)(null),g=(0,u.useRef)(null),v=e.theme??`dark`,b=e.faqs??[],x=e.title??`Ask anything`,ee=e.placeholder??`Type your question…`,S=e.welcomeMessage??`Ask a question to get started.`,C=e.avatarLabel??`AI`,te=e.hint??``;(0,u.useEffect)(()=>{h.current?.scrollIntoView({behavior:`smooth`})},[s,c]);let ne=(0,u.useRef)(void 0);(0,u.useEffect)(()=>{i&&i!==ne.current&&(ne.current=i,l(i),a?.())},[i,l,a]);let re=()=>{!p.trim()||c||(l(p),m(``),g.current?.focus())},w=e=>{l(e),m(``)};return(0,y.jsx)(`div`,{className:`kyt-root${v===`light`?` kyt-light`:``}`,style:{height:`100%`,display:`flex`,flexDirection:`column`},children:(0,y.jsxs)(`div`,{className:`kyt-page`,children:[n&&(0,y.jsxs)(`header`,{className:`kyt-header`,children:[(0,y.jsx)(`span`,{className:`kyt-header-title`,children:x}),(0,y.jsxs)(`div`,{className:`kyt-header-right`,children:[(0,y.jsxs)(`div`,{className:`kyt-live`,children:[(0,y.jsx)(`div`,{className:`kyt-live-dot`}),`Live`]}),(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:d,title:`Clear chat`,"aria-label":`Clear chat`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z`})})}),t&&(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:t,"aria-label":`Close chat`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})})})]})]}),(0,y.jsxs)(`div`,{className:`kyt-body`,children:[!r&&b.length>0&&(0,y.jsxs)(`aside`,{className:`kyt-sidebar`,children:[(0,y.jsx)(`div`,{className:`kyt-sidebar-label`,children:`Suggested Questions`}),(0,y.jsx)(`div`,{className:`kyt-faq-list`,children:b.map((e,t)=>(0,y.jsx)(`button`,{className:`kyt-faq-btn`,onClick:()=>w(e),children:e},t))})]}),(0,y.jsxs)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,overflow:`hidden`},children:[(0,y.jsxs)(`div`,{className:`kyt-messages`,children:[s.length===0&&(0,y.jsxs)(`div`,{className:`kyt-welcome`,children:[(0,y.jsx)(`div`,{className:`kyt-welcome-icon`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`28`,height:`28`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z`})})}),(0,y.jsx)(`h2`,{children:x}),(0,y.jsx)(`p`,{children:S})]}),s.map(e=>(0,y.jsx)(ce,{msg:e,avatarLabel:C},e.id)),c&&(0,y.jsxs)(`div`,{className:`kyt-msg kyt-msg-assistant`,children:[(0,y.jsx)(`div`,{className:`kyt-avatar`,children:C[0]}),(0,y.jsxs)(`div`,{className:`kyt-typing`,children:[(0,y.jsx)(`div`,{className:`kyt-dot`}),(0,y.jsx)(`div`,{className:`kyt-dot`}),(0,y.jsx)(`div`,{className:`kyt-dot`})]})]}),(0,y.jsx)(`div`,{ref:h})]}),(0,y.jsxs)(`div`,{className:`kyt-input-bar`,children:[(0,y.jsxs)(`div`,{className:`kyt-input-row`,children:[(0,y.jsx)(`input`,{ref:g,className:`kyt-input`,value:p,placeholder:ee,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),re())},disabled:c}),(0,y.jsx)(`button`,{className:`kyt-send-btn`,onClick:re,disabled:c||!p.trim(),"aria-label":`Send`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,children:(0,y.jsx)(`path`,{d:`M2 21l21-9L2 3v7l15 2-15 2z`})})})]}),te&&(0,y.jsx)(`div`,{className:`kyt-hint`,children:te})]})]})]})]})})}function ce({msg:e,avatarLabel:t}){if(e.role===`user`)return(0,y.jsx)(`div`,{className:`kyt-msg kyt-msg-user`,children:(0,y.jsx)(`div`,{className:`kyt-bubble kyt-bubble-user`,dangerouslySetInnerHTML:{__html:oe(e.text)}})});let n=e.confidence===`high`?`kyt-conf kyt-conf-high`:e.confidence===`low`?`kyt-conf kyt-conf-low`:`kyt-conf kyt-conf-medium`;return(0,y.jsxs)(`div`,{className:`kyt-msg kyt-msg-assistant`,style:{flexDirection:`column`},children:[(0,y.jsxs)(`div`,{style:{display:`flex`,alignItems:`flex-start`,gap:10},children:[(0,y.jsx)(`div`,{className:`kyt-avatar`,children:t[0]}),(0,y.jsxs)(`div`,{className:`kyt-bubble kyt-bubble-assistant`,children:[(0,y.jsx)(`span`,{dangerouslySetInnerHTML:{__html:oe(e.text)}}),e.confidence&&(0,y.jsx)(`span`,{className:n,children:e.confidence.toUpperCase()})]})]}),e.sources&&e.sources.length>0&&(0,y.jsx)(ae,{sources:e.sources,extra_sources:e.extra_sources})]})}function le({config:e}){let[t,n]=(0,u.useState)(!1),[r,i]=(0,u.useState)(!1),[a,o]=(0,u.useState)(!1),[s,c]=(0,u.useState)(),[l,d]=(0,u.useState)(0),f=e.primaryColor??`#1565c0`,m=e.faqs??[];(0,u.useEffect)(()=>{p(f)},[f]);let h=()=>{n(!1),i(!1),o(!1)},g=e=>{c({text:e,id:Date.now()}),o(!1)};return(0,y.jsxs)(`div`,{className:`kyt-root`,children:[t&&r&&(0,y.jsx)(`div`,{className:`kyt-bubble-expanded-backdrop`,onClick:h}),t&&(0,y.jsxs)(`div`,{className:r?`kyt-bubble-expanded`:`kyt-bubble-compact`,children:[(0,y.jsxs)(`div`,{className:`kyt-bubble-header`,style:{background:f},children:[(0,y.jsx)(`span`,{className:`kyt-bubble-header-title`,children:e.title??`Ask anything`}),(0,y.jsxs)(`div`,{className:`kyt-bubble-header-actions`,children:[(0,y.jsxs)(`div`,{className:`kyt-live`,style:{marginRight:4},children:[(0,y.jsx)(`div`,{className:`kyt-live-dot`}),`Live`]}),(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:()=>d(e=>e+1),title:`Clear chat`,"aria-label":`Clear chat`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z`})})}),` `,m.length>0&&(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:()=>o(e=>!e),title:`Suggested questions`,"aria-label":`Suggested questions`,children:`💡`}),(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:()=>i(e=>!e),title:r?`Compact`:`Expand`,"aria-label":r?`Compact`:`Expand`,children:r?(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z`})}):(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z`})})}),(0,y.jsx)(`button`,{className:`kyt-hdr-btn`,onClick:h,"aria-label":`Close chat`,children:(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`white`,children:(0,y.jsx)(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})})})]})]}),(0,y.jsxs)(`div`,{style:{flex:1,overflow:`hidden`,display:`flex`,flexDirection:`column`,position:`relative`},children:[(0,y.jsx)(se,{config:e,showHeader:!1,bubbleMode:!0,pendingFaq:s?.text,onFaqSent:()=>c(void 0),clearTrigger:l}),a&&m.length>0&&(0,y.jsxs)(`div`,{className:`kyt-faq-drawer`,children:[(0,y.jsxs)(`div`,{className:`kyt-faq-drawer-header`,children:[(0,y.jsx)(`span`,{className:`kyt-faq-drawer-label`,children:`Suggested`}),(0,y.jsx)(`button`,{className:`kyt-faq-drawer-close`,onClick:()=>o(!1),"aria-label":`Close`,children:`✕`})]}),(0,y.jsx)(`div`,{className:`kyt-faq-drawer-list`,children:m.map((e,t)=>(0,y.jsx)(`button`,{className:`kyt-faq-drawer-btn`,onClick:()=>g(e),children:e},t))})]})]})]}),!r&&(0,y.jsx)(`button`,{className:`kyt-bubble-btn`,style:{background:f},onClick:()=>n(e=>!e),"aria-label":t?`Close chat`:`Open chat`,children:t?(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,children:(0,y.jsx)(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})}):(0,y.jsx)(`svg`,{viewBox:`0 0 24 24`,children:(0,y.jsx)(`path`,{d:`M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z`})})})]})}function ue({config:e,style:t,className:n}){return(0,u.useEffect)(()=>{p(e.primaryColor??`#1565c0`)},[e.primaryColor]),(0,y.jsx)(`div`,{style:{height:`100%`,width:`100%`,...t},className:n,children:(0,y.jsx)(se,{config:e,showHeader:!0})})}function T(e){let t=document.querySelector(e);if(!t)throw Error(`kyt-chat: no element found for selector "${e}"`);return t}function E(e,t){p(e.primaryColor??`#1565c0`),(0,l.createRoot)(T(t)).render((0,u.createElement)(le,{config:e}))}function de(e,t){p(e.primaryColor??`#1565c0`);let n=T(t);n.style.height=n.style.height||`100vh`,n.style.display=`flex`,n.style.flexDirection=`column`,(0,l.createRoot)(n).render((0,u.createElement)(ue,{config:e,style:{height:`100%`,flex:1}}))}function fe(e,t,n=`bubble`){n===`chat`?de(e,t):E(e,t)}return e.mount=fe,e.mountBubble=E,e.mountChat=de,e})({});
|
package/dist/kyt-chat.js
CHANGED
|
@@ -8826,26 +8826,30 @@ function ie({ sources: e, extra_sources: t = [] }) {
|
|
|
8826
8826
|
function ae(e) {
|
|
8827
8827
|
return e.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>").replace(/\n/g, "<br>");
|
|
8828
8828
|
}
|
|
8829
|
-
function oe({ config: e, onClose: t, showHeader: n = !0, bubbleMode: r = !1, pendingFaq: i, onFaqSent: a }) {
|
|
8830
|
-
let { messages:
|
|
8829
|
+
function oe({ config: e, onClose: t, showHeader: n = !0, bubbleMode: r = !1, pendingFaq: i, onFaqSent: a, clearTrigger: o }) {
|
|
8830
|
+
let { messages: s, loading: c, sendMessage: u, reset: d } = g(e), f = (0, l.useRef)(void 0);
|
|
8831
8831
|
(0, l.useEffect)(() => {
|
|
8832
|
-
|
|
8833
|
-
}, [o,
|
|
8834
|
-
let
|
|
8832
|
+
o !== void 0 && o !== f.current && f.current !== void 0 && d(), f.current = o;
|
|
8833
|
+
}, [o, d]);
|
|
8834
|
+
let [p, m] = (0, l.useState)(""), h = (0, l.useRef)(null), _ = (0, l.useRef)(null), y = e.theme ?? "dark", b = e.faqs ?? [], x = e.title ?? "Ask anything", ee = e.placeholder ?? "Type your question…", S = e.welcomeMessage ?? "Ask a question to get started.", C = e.avatarLabel ?? "AI", te = e.hint ?? "";
|
|
8835
8835
|
(0, l.useEffect)(() => {
|
|
8836
|
-
|
|
8836
|
+
h.current?.scrollIntoView({ behavior: "smooth" });
|
|
8837
|
+
}, [s, c]);
|
|
8838
|
+
let ne = (0, l.useRef)(void 0);
|
|
8839
|
+
(0, l.useEffect)(() => {
|
|
8840
|
+
i && i !== ne.current && (ne.current = i, u(i), a?.());
|
|
8837
8841
|
}, [
|
|
8838
8842
|
i,
|
|
8839
|
-
|
|
8843
|
+
u,
|
|
8840
8844
|
a
|
|
8841
8845
|
]);
|
|
8842
|
-
let
|
|
8843
|
-
!
|
|
8844
|
-
},
|
|
8845
|
-
|
|
8846
|
+
let re = () => {
|
|
8847
|
+
!p.trim() || c || (u(p), m(""), _.current?.focus());
|
|
8848
|
+
}, w = (e) => {
|
|
8849
|
+
u(e), m("");
|
|
8846
8850
|
};
|
|
8847
8851
|
return /* @__PURE__ */ (0, v.jsx)("div", {
|
|
8848
|
-
className: `kyt-root${
|
|
8852
|
+
className: `kyt-root${y === "light" ? " kyt-light" : ""}`,
|
|
8849
8853
|
style: {
|
|
8850
8854
|
height: "100%",
|
|
8851
8855
|
display: "flex",
|
|
@@ -8857,7 +8861,7 @@ function oe({ config: e, onClose: t, showHeader: n = !0, bubbleMode: r = !1, pen
|
|
|
8857
8861
|
className: "kyt-header",
|
|
8858
8862
|
children: [/* @__PURE__ */ (0, v.jsx)("span", {
|
|
8859
8863
|
className: "kyt-header-title",
|
|
8860
|
-
children:
|
|
8864
|
+
children: x
|
|
8861
8865
|
}), /* @__PURE__ */ (0, v.jsxs)("div", {
|
|
8862
8866
|
className: "kyt-header-right",
|
|
8863
8867
|
children: [
|
|
@@ -8867,7 +8871,7 @@ function oe({ config: e, onClose: t, showHeader: n = !0, bubbleMode: r = !1, pen
|
|
|
8867
8871
|
}),
|
|
8868
8872
|
/* @__PURE__ */ (0, v.jsx)("button", {
|
|
8869
8873
|
className: "kyt-hdr-btn",
|
|
8870
|
-
onClick:
|
|
8874
|
+
onClick: d,
|
|
8871
8875
|
title: "Clear chat",
|
|
8872
8876
|
"aria-label": "Clear chat",
|
|
8873
8877
|
children: /* @__PURE__ */ (0, v.jsx)("svg", {
|
|
@@ -8894,16 +8898,16 @@ function oe({ config: e, onClose: t, showHeader: n = !0, bubbleMode: r = !1, pen
|
|
|
8894
8898
|
})]
|
|
8895
8899
|
}), /* @__PURE__ */ (0, v.jsxs)("div", {
|
|
8896
8900
|
className: "kyt-body",
|
|
8897
|
-
children: [!r &&
|
|
8901
|
+
children: [!r && b.length > 0 && /* @__PURE__ */ (0, v.jsxs)("aside", {
|
|
8898
8902
|
className: "kyt-sidebar",
|
|
8899
8903
|
children: [/* @__PURE__ */ (0, v.jsx)("div", {
|
|
8900
8904
|
className: "kyt-sidebar-label",
|
|
8901
8905
|
children: "Suggested Questions"
|
|
8902
8906
|
}), /* @__PURE__ */ (0, v.jsx)("div", {
|
|
8903
8907
|
className: "kyt-faq-list",
|
|
8904
|
-
children:
|
|
8908
|
+
children: b.map((e, t) => /* @__PURE__ */ (0, v.jsx)("button", {
|
|
8905
8909
|
className: "kyt-faq-btn",
|
|
8906
|
-
onClick: () =>
|
|
8910
|
+
onClick: () => w(e),
|
|
8907
8911
|
children: e
|
|
8908
8912
|
}, t))
|
|
8909
8913
|
})]
|
|
@@ -8917,7 +8921,7 @@ function oe({ config: e, onClose: t, showHeader: n = !0, bubbleMode: r = !1, pen
|
|
|
8917
8921
|
children: [/* @__PURE__ */ (0, v.jsxs)("div", {
|
|
8918
8922
|
className: "kyt-messages",
|
|
8919
8923
|
children: [
|
|
8920
|
-
|
|
8924
|
+
s.length === 0 && /* @__PURE__ */ (0, v.jsxs)("div", {
|
|
8921
8925
|
className: "kyt-welcome",
|
|
8922
8926
|
children: [
|
|
8923
8927
|
/* @__PURE__ */ (0, v.jsx)("div", {
|
|
@@ -8930,19 +8934,19 @@ function oe({ config: e, onClose: t, showHeader: n = !0, bubbleMode: r = !1, pen
|
|
|
8930
8934
|
children: /* @__PURE__ */ (0, v.jsx)("path", { d: "M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z" })
|
|
8931
8935
|
})
|
|
8932
8936
|
}),
|
|
8933
|
-
/* @__PURE__ */ (0, v.jsx)("h2", { children:
|
|
8934
|
-
/* @__PURE__ */ (0, v.jsx)("p", { children:
|
|
8937
|
+
/* @__PURE__ */ (0, v.jsx)("h2", { children: x }),
|
|
8938
|
+
/* @__PURE__ */ (0, v.jsx)("p", { children: S })
|
|
8935
8939
|
]
|
|
8936
8940
|
}),
|
|
8937
|
-
|
|
8941
|
+
s.map((e) => /* @__PURE__ */ (0, v.jsx)(se, {
|
|
8938
8942
|
msg: e,
|
|
8939
|
-
avatarLabel:
|
|
8943
|
+
avatarLabel: C
|
|
8940
8944
|
}, e.id)),
|
|
8941
|
-
|
|
8945
|
+
c && /* @__PURE__ */ (0, v.jsxs)("div", {
|
|
8942
8946
|
className: "kyt-msg kyt-msg-assistant",
|
|
8943
8947
|
children: [/* @__PURE__ */ (0, v.jsx)("div", {
|
|
8944
8948
|
className: "kyt-avatar",
|
|
8945
|
-
children:
|
|
8949
|
+
children: C[0]
|
|
8946
8950
|
}), /* @__PURE__ */ (0, v.jsxs)("div", {
|
|
8947
8951
|
className: "kyt-typing",
|
|
8948
8952
|
children: [
|
|
@@ -8952,35 +8956,35 @@ function oe({ config: e, onClose: t, showHeader: n = !0, bubbleMode: r = !1, pen
|
|
|
8952
8956
|
]
|
|
8953
8957
|
})]
|
|
8954
8958
|
}),
|
|
8955
|
-
/* @__PURE__ */ (0, v.jsx)("div", { ref:
|
|
8959
|
+
/* @__PURE__ */ (0, v.jsx)("div", { ref: h })
|
|
8956
8960
|
]
|
|
8957
8961
|
}), /* @__PURE__ */ (0, v.jsxs)("div", {
|
|
8958
8962
|
className: "kyt-input-bar",
|
|
8959
8963
|
children: [/* @__PURE__ */ (0, v.jsxs)("div", {
|
|
8960
8964
|
className: "kyt-input-row",
|
|
8961
8965
|
children: [/* @__PURE__ */ (0, v.jsx)("input", {
|
|
8962
|
-
ref:
|
|
8966
|
+
ref: _,
|
|
8963
8967
|
className: "kyt-input",
|
|
8964
|
-
value:
|
|
8965
|
-
placeholder:
|
|
8966
|
-
onChange: (e) =>
|
|
8968
|
+
value: p,
|
|
8969
|
+
placeholder: ee,
|
|
8970
|
+
onChange: (e) => m(e.target.value),
|
|
8967
8971
|
onKeyDown: (e) => {
|
|
8968
|
-
e.key === "Enter" && !e.shiftKey && (e.preventDefault(),
|
|
8972
|
+
e.key === "Enter" && !e.shiftKey && (e.preventDefault(), re());
|
|
8969
8973
|
},
|
|
8970
|
-
disabled:
|
|
8974
|
+
disabled: c
|
|
8971
8975
|
}), /* @__PURE__ */ (0, v.jsx)("button", {
|
|
8972
8976
|
className: "kyt-send-btn",
|
|
8973
|
-
onClick:
|
|
8974
|
-
disabled:
|
|
8977
|
+
onClick: re,
|
|
8978
|
+
disabled: c || !p.trim(),
|
|
8975
8979
|
"aria-label": "Send",
|
|
8976
8980
|
children: /* @__PURE__ */ (0, v.jsx)("svg", {
|
|
8977
8981
|
viewBox: "0 0 24 24",
|
|
8978
8982
|
children: /* @__PURE__ */ (0, v.jsx)("path", { d: "M2 21l21-9L2 3v7l15 2-15 2z" })
|
|
8979
8983
|
})
|
|
8980
8984
|
})]
|
|
8981
|
-
}),
|
|
8985
|
+
}), te && /* @__PURE__ */ (0, v.jsx)("div", {
|
|
8982
8986
|
className: "kyt-hint",
|
|
8983
|
-
children:
|
|
8987
|
+
children: te
|
|
8984
8988
|
})]
|
|
8985
8989
|
})]
|
|
8986
8990
|
})]
|
|
@@ -9025,13 +9029,13 @@ function se({ msg: e, avatarLabel: t }) {
|
|
|
9025
9029
|
//#endregion
|
|
9026
9030
|
//#region ../../src/components/KytChatBubble.tsx
|
|
9027
9031
|
function ce({ config: e }) {
|
|
9028
|
-
let [t, n] = (0, l.useState)(!1), [r, i] = (0, l.useState)(!1), [a, o] = (0, l.useState)(!1), [s, c] = (0, l.useState)(), u = e.primaryColor ?? "#1565c0",
|
|
9032
|
+
let [t, n] = (0, l.useState)(!1), [r, i] = (0, l.useState)(!1), [a, o] = (0, l.useState)(!1), [s, c] = (0, l.useState)(), [u, d] = (0, l.useState)(0), p = e.primaryColor ?? "#1565c0", m = e.faqs ?? [];
|
|
9029
9033
|
(0, l.useEffect)(() => {
|
|
9030
|
-
f(
|
|
9031
|
-
}, [
|
|
9032
|
-
let
|
|
9034
|
+
f(p);
|
|
9035
|
+
}, [p]);
|
|
9036
|
+
let h = () => {
|
|
9033
9037
|
n(!1), i(!1), o(!1);
|
|
9034
|
-
},
|
|
9038
|
+
}, g = (e) => {
|
|
9035
9039
|
c({
|
|
9036
9040
|
text: e,
|
|
9037
9041
|
id: Date.now()
|
|
@@ -9042,13 +9046,13 @@ function ce({ config: e }) {
|
|
|
9042
9046
|
children: [
|
|
9043
9047
|
t && r && /* @__PURE__ */ (0, v.jsx)("div", {
|
|
9044
9048
|
className: "kyt-bubble-expanded-backdrop",
|
|
9045
|
-
onClick:
|
|
9049
|
+
onClick: h
|
|
9046
9050
|
}),
|
|
9047
9051
|
t && /* @__PURE__ */ (0, v.jsxs)("div", {
|
|
9048
9052
|
className: r ? "kyt-bubble-expanded" : "kyt-bubble-compact",
|
|
9049
9053
|
children: [/* @__PURE__ */ (0, v.jsxs)("div", {
|
|
9050
9054
|
className: "kyt-bubble-header",
|
|
9051
|
-
style: { background:
|
|
9055
|
+
style: { background: p },
|
|
9052
9056
|
children: [/* @__PURE__ */ (0, v.jsx)("span", {
|
|
9053
9057
|
className: "kyt-bubble-header-title",
|
|
9054
9058
|
children: e.title ?? "Ask anything"
|
|
@@ -9062,7 +9066,7 @@ function ce({ config: e }) {
|
|
|
9062
9066
|
}),
|
|
9063
9067
|
/* @__PURE__ */ (0, v.jsx)("button", {
|
|
9064
9068
|
className: "kyt-hdr-btn",
|
|
9065
|
-
onClick:
|
|
9069
|
+
onClick: () => d((e) => e + 1),
|
|
9066
9070
|
title: "Clear chat",
|
|
9067
9071
|
"aria-label": "Clear chat",
|
|
9068
9072
|
children: /* @__PURE__ */ (0, v.jsx)("svg", {
|
|
@@ -9073,7 +9077,8 @@ function ce({ config: e }) {
|
|
|
9073
9077
|
children: /* @__PURE__ */ (0, v.jsx)("path", { d: "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" })
|
|
9074
9078
|
})
|
|
9075
9079
|
}),
|
|
9076
|
-
|
|
9080
|
+
" ",
|
|
9081
|
+
m.length > 0 && /* @__PURE__ */ (0, v.jsx)("button", {
|
|
9077
9082
|
className: "kyt-hdr-btn",
|
|
9078
9083
|
onClick: () => o((e) => !e),
|
|
9079
9084
|
title: "Suggested questions",
|
|
@@ -9101,7 +9106,7 @@ function ce({ config: e }) {
|
|
|
9101
9106
|
}),
|
|
9102
9107
|
/* @__PURE__ */ (0, v.jsx)("button", {
|
|
9103
9108
|
className: "kyt-hdr-btn",
|
|
9104
|
-
onClick:
|
|
9109
|
+
onClick: h,
|
|
9105
9110
|
"aria-label": "Close chat",
|
|
9106
9111
|
children: /* @__PURE__ */ (0, v.jsx)("svg", {
|
|
9107
9112
|
viewBox: "0 0 24 24",
|
|
@@ -9126,8 +9131,9 @@ function ce({ config: e }) {
|
|
|
9126
9131
|
showHeader: !1,
|
|
9127
9132
|
bubbleMode: !0,
|
|
9128
9133
|
pendingFaq: s?.text,
|
|
9129
|
-
onFaqSent: () => c(void 0)
|
|
9130
|
-
|
|
9134
|
+
onFaqSent: () => c(void 0),
|
|
9135
|
+
clearTrigger: u
|
|
9136
|
+
}), a && m.length > 0 && /* @__PURE__ */ (0, v.jsxs)("div", {
|
|
9131
9137
|
className: "kyt-faq-drawer",
|
|
9132
9138
|
children: [/* @__PURE__ */ (0, v.jsxs)("div", {
|
|
9133
9139
|
className: "kyt-faq-drawer-header",
|
|
@@ -9142,9 +9148,9 @@ function ce({ config: e }) {
|
|
|
9142
9148
|
})]
|
|
9143
9149
|
}), /* @__PURE__ */ (0, v.jsx)("div", {
|
|
9144
9150
|
className: "kyt-faq-drawer-list",
|
|
9145
|
-
children:
|
|
9151
|
+
children: m.map((e, t) => /* @__PURE__ */ (0, v.jsx)("button", {
|
|
9146
9152
|
className: "kyt-faq-drawer-btn",
|
|
9147
|
-
onClick: () =>
|
|
9153
|
+
onClick: () => g(e),
|
|
9148
9154
|
children: e
|
|
9149
9155
|
}, t))
|
|
9150
9156
|
})]
|
|
@@ -9153,7 +9159,7 @@ function ce({ config: e }) {
|
|
|
9153
9159
|
}),
|
|
9154
9160
|
!r && /* @__PURE__ */ (0, v.jsx)("button", {
|
|
9155
9161
|
className: "kyt-bubble-btn",
|
|
9156
|
-
style: { background:
|
|
9162
|
+
style: { background: p },
|
|
9157
9163
|
onClick: () => n((e) => !e),
|
|
9158
9164
|
"aria-label": t ? "Close chat" : "Open chat",
|
|
9159
9165
|
children: t ? /* @__PURE__ */ (0, v.jsx)("svg", {
|
|
@@ -3,16 +3,11 @@ interface Props {
|
|
|
3
3
|
config: KytConfig;
|
|
4
4
|
onClose?: () => void;
|
|
5
5
|
showHeader?: boolean;
|
|
6
|
-
/** When true: hides the FAQ sidebar (used by KytChatBubble) */
|
|
7
6
|
bubbleMode?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Set this to a question string to trigger sending it programmatically.
|
|
10
|
-
* Change the value each time you want to send (use a unique key like `q + Date.now()`).
|
|
11
|
-
*/
|
|
12
7
|
pendingFaq?: string;
|
|
13
|
-
/** Called after pendingFaq has been sent */
|
|
14
8
|
onFaqSent?: () => void;
|
|
9
|
+
clearTrigger?: number;
|
|
15
10
|
}
|
|
16
|
-
export declare function ChatCore({ config, onClose, showHeader, bubbleMode, pendingFaq, onFaqSent }: Props): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare function ChatCore({ config, onClose, showHeader, bubbleMode, pendingFaq, onFaqSent, clearTrigger }: Props): import("react/jsx-runtime").JSX.Element;
|
|
17
12
|
export {};
|
|
18
13
|
//# sourceMappingURL=ChatCore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatCore.d.ts","sourceRoot":"","sources":["../../../../../src/components/ChatCore.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAW,MAAM,UAAU,CAAA;AAIlD,UAAU,KAAK;IACb,MAAM,EAAE,SAAS,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB
|
|
1
|
+
{"version":3,"file":"ChatCore.d.ts","sourceRoot":"","sources":["../../../../../src/components/ChatCore.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAW,MAAM,UAAU,CAAA;AAIlD,UAAU,KAAK;IACb,MAAM,EAAE,SAAS,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAQD,wBAAgB,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,UAAiB,EAAE,UAAkB,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,KAAK,2CAoK9H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KytChatBubble.d.ts","sourceRoot":"","sources":["../../../../../src/components/KytChatBubble.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"KytChatBubble.d.ts","sourceRoot":"","sources":["../../../../../src/components/KytChatBubble.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIzC,UAAU,KAAK;IACb,MAAM,EAAE,SAAS,CAAA;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,2CA+H9C"}
|