@useago/sdk 1.3.1 → 1.3.2
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/widget.cjs +4 -4
- package/dist/widget.d.cts +6 -4
- package/dist/widget.d.ts +6 -4
- package/dist/widget.js +114 -109
- package/package.json +1 -1
package/dist/widget.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("./AgoClient-CzSmJQxl.cjs"),
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("./AgoClient-CzSmJQxl.cjs"),ct=require("./createFormCollector-BB3Uscuo.cjs"),Gt=require("./createConversationSession-DV0Xp_3O.cjs");var jt='"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',Re=`var(--ago-font, ${jt})`,pt={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color",agentBubbleBg:"--ago-agent-bubble-background"},Ae="var(--ago-brand-color, #03182f)",_e="var(--ago-brand-text-color, #fff)",Vt="var(--ago-header-background, var(--ago-brand-color, #03182f))",ft="var(--ago-header-text-color, #e8f0fe)",ee="var(--ago-panel-background, #fff)",xt="var(--ago-messages-background, #fbfbfb)",J="var(--ago-text-color, #30373e)",bt="var(--ago-muted-text-color, #6b6d6f)",L="var(--ago-border-color, #dee3e8)",De="var(--ago-accent-color, #1b5fc4)",ut="var(--ago-agent-bubble-background, #f1f3f5)",qt="var(--ago-radius, 16px)",ze="var(--ago-message-radius, 16px)",Kt="var(--ago-message-radius, 20px)";function Xt(n,o){if(o)for(const i of Object.keys(pt)){const r=o[i];r!=null&&n.style.setProperty(pt[i],r)}}function v(n,o){Object.assign(n.style,o)}function h(n={}){const o=document.createElement("div");return v(o,n),o}var mt="ago-chat-widget-keyframes";function Qt(){if(typeof document>"u"||document.getElementById(mt))return;const n=document.createElement("style");n.id=mt,n.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }",document.head.appendChild(n)}function Yt(n){let o=[];const i=document.createElement("form");v(i,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${L}`,backgroundColor:ee}),i.className="ago-chat-input";const r=h({display:"flex",flexWrap:"wrap",gap:"6px"}),b=h({display:"flex",gap:"8px",alignItems:"flex-end"}),a=document.createElement("textarea");a.placeholder=n.placeholder,a.setAttribute("aria-label",n.placeholder),a.rows=1,v(a,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${L}`,borderRadius:"12px",fontSize:"16px",fontFamily:Re,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const C=()=>{a.style.height="auto";const c=Math.min(a.scrollHeight+2,110);a.style.height=`${c}px`,a.style.overflowY=a.scrollHeight+2>110?"auto":"hidden"};a.addEventListener("input",()=>{C(),A()});const m='<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>',x='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',p=document.createElement("button");p.type="submit",p.setAttribute("aria-label","Send"),p.innerHTML=m,v(p,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:Ae,color:_e,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let f=!1;const A=()=>{const s=a.value.trim()!==""||o.length>0,c=f||!s;p.disabled=c,p.innerHTML=f?x:m,p.style.opacity=c&&!f?"0.5":"1",p.style.cursor=c?"default":"pointer"};let R=null,_=null;n.allowFiles&&(R=document.createElement("input"),R.type="file",R.multiple=!0,v(R,{display:"none"}),_=document.createElement("button"),_.type="button",_.setAttribute("aria-label","Attach file"),_.textContent="📎",v(_,{padding:"10px 12px",border:`1px solid ${L}`,borderRadius:"12px",backgroundColor:ee,cursor:"pointer",fontSize:"14px"}),_.addEventListener("click",()=>R?.click()),R.addEventListener("change",()=>{o=[...o,...Array.from(R?.files??[])],Y()}));function Y(){r.replaceChildren(),o.forEach((s,c)=>{const y=h({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${L}`,borderRadius:"8px",fontSize:"12px"}),T=document.createElement("span");T.textContent=s.name;const k=document.createElement("button");k.type="button",k.setAttribute("aria-label",`Remove ${s.name}`),k.textContent="×",v(k,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),k.addEventListener("click",()=>{o=o.filter((j,V)=>V!==c),Y()}),y.append(T,k),r.appendChild(y)}),A()}const D=()=>{const s=a.value,c=o;return a.value="",C(),o=[],Y(),{content:s,files:c}},g=()=>{const{content:s,files:c}=D();(s.trim()||c.length>0)&&n.onSend(s.trim(),c.length>0?c:void 0)};return i.addEventListener("submit",s=>{s.preventDefault(),g()}),a.addEventListener("keydown",s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),g())}),_&&b.appendChild(_),b.append(a,p),R&&i.appendChild(R),i.append(r,b),A(),{inputRow:i,getValueAndClear:D,setDisabled:s=>{a.disabled=s,f=s,A()},focus:()=>a.focus()}}var Zt={"&":"&","<":"<",">":">",'"':""","'":"'"};function ae(n){return n.replace(/[&<>"']/g,o=>Zt[o])}function gt(n){const o=n.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var vt='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Se="";function te(n){const o=[],i=b=>(o.push(b),`${Se}${o.length-1}${Se}`);let r=n;return r=r.replace(/`([^`]+)`/g,(b,a)=>i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${vt}">${ae(a)}</code>`)),r=r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=gt(C);return m?i(`<img alt="${ae(a)}" src="${ae(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):b}),r=r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=gt(C);return m?i(`<a href="${ae(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`):b}),r=ae(r),r=r.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),r=r.replace(new RegExp(`${Se}(\\d+)${Se}`,"g"),(b,a)=>o[Number(a)]),r}function B(n,o,i){const r=document.createElement(n);return Object.assign(r.style,o),i!==void 0&&(r.innerHTML=i),r}var yt=/^ {0,3}([-*_])( *\1){2,} *$/,wt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,Ct=/^ {0,3}(```+|~~~+)/,ke=/^ {0,3}>\s?/,le=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Jt=["20px","18px","16px","15px","14px","13px"],Fe=n=>n.match(/^\s*/)?.[0].length??0;function en(n){return n.trim()===""||yt.test(n)||wt.test(n)||Ct.test(n)||ke.test(n)||le.test(n)}function Et(n){const o=n[0].match(le),i=o[1].length,r=/\d/.test(o[2]),b=B(r?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:r?"decimal":"disc",listStylePosition:"outside"});let a=0;for(;a<n.length;){const C=n[a].match(le),m=[];for(a++;a<n.length&&Fe(n[a])>i;)m.push(n[a]),a++;const x=B("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),p=C[3].match(/^\[([ xX])\]\s+(.*)$/);p?(x.style.listStyleType="none",x.style.marginLeft="-20px",x.innerHTML=`<span style="margin-right:6px">${p[1].toLowerCase()==="x"?"☑":"☐"}</span>${te(p[2])}`):x.innerHTML=te(C[3]),m.filter(f=>le.test(f)).length>0&&x.appendChild(Et(m.filter(f=>f.trim()!==""))),b.appendChild(x)}return b}function tn(n){const o=m=>m.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(x=>x.trim()),i=B("div",{overflowX:"auto",margin:"0 0 8px 0"}),r=B("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),b=document.createElement("thead"),a=document.createElement("tr");for(const m of o(n[0]))a.appendChild(B("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},te(m)));b.appendChild(a),r.appendChild(b);const C=document.createElement("tbody");for(const m of n.slice(2)){const x=document.createElement("tr");for(const p of o(m))x.appendChild(B("td",{border:"1px solid #dee3e8",padding:"6px 10px"},te(p)));C.appendChild(x)}return r.appendChild(C),i.appendChild(r),i}var nn=n=>!!n&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(n);function Ie(n){const o=document.createDocumentFragment(),i=n.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let r=0;for(;r<i.length;){const a=i[r];if(a.trim()===""){r++;continue}const C=a.match(
|
|
4
|
-
`)))),o.appendChild(A);continue}if(
|
|
5
|
-
`))),o.appendChild(f);continue}if(a.includes("|")&&nn(i[r+1])){const p=[a,i[r+1]];for(r+=2;r<i.length&&i[r].includes("|")&&i[r].trim();)p.push(i[r]),r++;o.appendChild(tn(p));continue}if(le.test(a)){const p=[],f=ze(a);for(;r<i.length&&i[r].trim()!=="";)if(le.test(i[r])||ze(i[r])>f)p.push(i[r]),r++;else break;o.appendChild(Ct(p));continue}const x=[a];for(r++;r<i.length&&!en(i[r]);)x.push(i[r]),r++;o.appendChild(B("p",{margin:"0 0 8px 0",lineHeight:"1.6"},x.map(p=>te(p)).join("<br>")))}const b=o.lastElementChild;return b&&(b.style.marginBottom="0"),o}function on(n,o){const{isLast:i,isLastOfBlock:r,bubbleStyle:b,showAgentName:a,agentBubble:C,followUpEnabled:m,followUpHandler:x,isMobile:p}=o,f=n.role==="user",A=b==="imessage",R=h({display:"flex",flexDirection:"column",alignItems:f?"flex-end":"flex-start",marginBottom:A&&!r?"2px":"16px"});if(R.className=`ago-message ago-message--${n.role}`,!f&&a&&n.agent){const g=h({fontSize:"13px",fontWeight:"500",color:J,marginBottom:"6px",padding:"0 4px"});g.className="ago-message__agent",g.textContent=n.agent.displayName||n.agent.name,R.appendChild(g)}if(!f&&n.sources&&n.sources.length>0){const g=h({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});g.className="ago-message__sources",n.sources.forEach((s,c)=>{const y=s.url?document.createElement("a"):document.createElement("div");s.url&&y instanceof HTMLAnchorElement&&(y.href=s.url,y.target="_blank",y.rel="noopener noreferrer"),v(y,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${L}`,borderRadius:"8px",backgroundColor:ee,textDecoration:"none",color:J,fontSize:"12px",overflow:"hidden"});const T=h({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${Be}`,color:Be,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});T.textContent=String(c+1);const k=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});k.textContent=s.title,k.title=s.title,y.append(T,k),g.appendChild(y)}),R.appendChild(g)}if(n.attachments&&n.attachments.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:f?"flex-end":"flex-start",maxWidth:"75%"});g.className="ago-message__attachments";for(const s of n.attachments){const c=se.safeAttachmentUrl(s.url);if(se.canInlineImage(s)&&c){const M=document.createElement("a");M.href=c,M.target="_blank",M.rel="noopener noreferrer",v(M,{display:"inline-block",textDecoration:"none"});const q=document.createElement("img");q.src=c,q.alt=s.name,q.loading="lazy",v(q,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${L}`,display:"block"}),M.appendChild(q),g.appendChild(M);continue}const y=c?document.createElement("a"):document.createElement("div");c&&y instanceof HTMLAnchorElement&&(y.href=c,y.target="_blank",y.rel="noopener noreferrer"),v(y,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${L}`,backgroundColor:f?"rgba(255,255,255,0.12)":ee,color:f?_e:J,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const T=document.createElement("span");T.textContent="📄",T.setAttribute("aria-hidden","true"),v(T,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const k=h({display:"flex",flexDirection:"column",minWidth:"0"}),j=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});j.textContent=s.name,j.title=s.name,k.appendChild(j);const V=se.formatFileSize(s.fileSize);if(V){const M=h({fontSize:"11px",color:xt});M.textContent=V,k.appendChild(M)}y.append(T,k),g.appendChild(y)}R.appendChild(g)}const _=f||C||A,Y=!!n.content||n.status==="IN_PROGRESS",D=h({maxWidth:_?A||f?p?"88%":"75%":p?"92%":"85%":"100%",padding:_?"10px 14px":"2px 8px",borderRadius:A?Kt:_?De:"0",backgroundColor:f?Ae:_?ft:"transparent",color:f?_e:J,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(D.className="ago-message__content",A&&r){D.style.position="relative";const g=h({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:f?Ae:ft});g.className="ago-message__tail";const s=h({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:ht});s.className="ago-message__tail-mask",f?(g.style.right="-8px",g.style.borderBottomLeftRadius="16px 14px",s.style.right="-10px",s.style.borderBottomLeftRadius="10px"):(g.style.left="-7px",g.style.borderBottomRightRadius="16px 14px",s.style.left="-10px",s.style.borderBottomRightRadius="10px"),D.append(g,s)}if(n.content?D.appendChild(Ie(n.content)):n.status==="IN_PROGRESS"&&D.appendChild(an()),Y&&R.appendChild(D),i&&n.followUpReplies&&n.followUpReplies.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});g.className="ago-message__followups";for(const s of n.followUpReplies){const c=document.createElement("button");c.type="button",c.className="ago-message__followup-btn",c.textContent=s,c.disabled=!m,v(c,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:De,border:`1px solid ${L}`,backgroundColor:ee,color:J,cursor:m?"pointer":"default",transition:"border-color 0.15s"}),x&&c.addEventListener("click",()=>x(s)),c.addEventListener("mouseenter",()=>{c.style.borderColor=Be}),c.addEventListener("mouseleave",()=>{c.style.borderColor=L}),g.appendChild(c)}R.appendChild(g)}return R}function rn(n){const o=h({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:De,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});o.className="ago-form-notice",o.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),v(i,{fontWeight:"700"});const r=document.createElement("span");return r.textContent=n,o.append(i,r),o}function an(){const n=h({display:"flex",gap:"4px",padding:"4px 0"});for(let o=0;o<3;o++){const i=h({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${o*.2}s`});n.appendChild(i)}return n}function sn(){const n="http://www.w3.org/2000/svg",o=document.createElementNS(n,"svg");o.setAttribute("width","26"),o.setAttribute("height","26"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none");const i=document.createElementNS(n,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),o.appendChild(i),o}var gt="Form submitted.";function ln(n){if(typeof n=="string")return n||null;if(!n||typeof n!="object")return null;const o=n;if(typeof o.message=="string"&&o.message)return o.message;const i=o.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const r=i.message;if(typeof r=="string"&&r)return r}return null}var dn=0;function cn(n){const o=typeof n=="string"?document.querySelector(n):n;if(!o)throw new Error(`mountChatWidget: target "${String(n)}" not found.`);return o}function pn(n,o){const{title:i="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:b="Type a message...",allowFiles:a=!1,height:C=500,placement:m="inline",width:x=400,defaultOpen:p=!1,logoUrl:f,showAgentName:A=!1,agentBubble:R=!1,bubbleStyle:_="default",showHeader:Y=!0,theme:D,loadThreads:g=!1,forms:s,formSubmittedMessage:c=gt,onFollowUpClick:y,onMessageSent:T,onMessageReceived:k,onFormSubmitted:j,onFormError:V,onOpen:M,onClose:q}=o,ne=typeof r=="string"?{message:r,mode:"static"}:r,Fe=ne.message,He=ne.mode??"static",Et="speed"in ne&&ne.speed||45,Pe="followUpReplies"in ne&&ne.followUpReplies||void 0;if(!o.client&&!o.config?.baseUrl)throw new se.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const E=o.client??new se.AgoClient(o.config),Ue=cn(n),z=m==="left"||m==="right",St=z&&(o.launcher??!0);let oe=z?p:!0;const Rt=o.mobile?.breakpoint??768,kt=o.mobile?.trigger??"focus",We=typeof window<"u"&&!!window.matchMedia,O=We?window.matchMedia(`(max-width: ${Rt}px)`):void 0,At=We?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,re=!z&&!!O,$e=o.persistConversation,ge=$e?Gt.createConversationSession($e===!0?{}:$e):void 0;let P=o.conversationId??ge?.getLastActiveThread()??void 0,u=[],Z=!1,de=null,K;const Ge=[];function _t(e){if(typeof c=="function"){const l=c(e);if(typeof l=="string"&&l)return l}const t=ln(e);return t||(typeof c=="string"?c:gt)}const he=[],d=h({display:"flex",flexDirection:"column",height:z?"100%":typeof C=="number"?`${C}px`:C,border:`1px solid ${L}`,borderRadius:qt,overflow:"hidden",backgroundColor:ee,fontFamily:Re,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",Xt(d,D);let F;if(Y){if(F=h({padding:"14px 16px",borderBottom:`1px solid ${L}`,backgroundColor:Vt,color:pt,display:"flex",alignItems:"center",gap:"10px"}),F.className="ago-chat-widget__header",f){const t=document.createElement("img");t.src=f,t.alt="Logo",v(t,{height:"24px",width:"auto"}),F.appendChild(t)}const e=document.createElement("h3");if(e.textContent=i,v(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),F.appendChild(e),z){const t=document.createElement("button");t.type="button",t.className="ago-chat-widget__close",t.setAttribute("aria-label","Close"),t.textContent="×",v(t,{marginLeft:"auto",background:"transparent",border:"none",color:pt,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),t.addEventListener("click",()=>Oe()),F.appendChild(t)}}const I=h({flex:"1",overflow:"auto",padding:"16px",backgroundColor:ht});I.className="ago-chat-widget__messages",I.setAttribute("role","log"),I.setAttribute("aria-live","polite"),I.setAttribute("aria-relevant","additions text"),I.setAttribute("aria-atomic","false");const{inputRow:Le,setDisabled:It,focus:xe}=Yt({placeholder:b,allowFiles:a,onSend:(e,t)=>{we(e,t)}});Qt(),d.append(...F?[F]:[],I,Le);let be=d,U,N;const ve=m==="left"?"left":"right";if(z&&(U=h({position:"fixed",top:"0",bottom:"0",[ve]:"0",width:typeof x=="number"?`${x}px`:x,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),U.className="ago-chat-widget-panel",v(d,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ve==="left"?"borderRight":"borderLeft"]:`1px solid ${L}`}),U.appendChild(d),be=U),St){if(N=document.createElement("button"),N.type="button",N.className="ago-chat-widget-launcher",N.setAttribute("aria-label",`Open ${i}`),v(N,{position:"fixed",bottom:"20px",[ve]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:Ae,color:_e,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:Re}),f){const e=document.createElement("img");e.src=f,e.alt="",v(e,{width:"26px",height:"26px",objectFit:"contain"}),N.appendChild(e)}else N.appendChild(sn());N.addEventListener("click",()=>Me())}const ce=re?`ago-vt-${++dn}`:"",je=52;let W=!1,pe=0,ie=0,H,fe,X;const ye={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};Ue.appendChild(be),N&&Ue.appendChild(N),Ce(),re&&(H=Pt(),d.insertBefore(H,d.firstChild),fe=document.createElement("style"),fe.id=ce,fe.textContent=`::view-transition-group(${ce}),::view-transition-group(${ce}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(fe),kt==="focus"&&(d.addEventListener("pointerdown",e=>{W||!O?.matches||Le.contains(e.target)&&(e.preventDefault(),ue())},!0),d.addEventListener("focusin",e=>{O?.matches&&Le.contains(e.target)&&ue()})),document.addEventListener("keydown",tt)),O&&O.addEventListener("change",nt);const $t=y!==!1,Lt=y===!1?void 0:y??(e=>{re&&O?.matches&&!W?ue().then(()=>we(e)):we(e)});function $(){if(I.replaceChildren(),u.length===0){if(He==="static"){const t=h({textAlign:"center",color:xt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});t.appendChild(Ie(Fe)),I.appendChild(t)}}else u.forEach((t,l)=>{const S=l===u.length-1||u[l+1].role!==t.role;I.appendChild(on(t,{isLast:l===u.length-1,isLastOfBlock:S,bubbleStyle:_,showAgentName:A,agentBubble:R,followUpEnabled:$t,followUpHandler:Lt,isMobile:!!O?.matches}))});for(const t of Ge)I.appendChild(rn(t));if(de){const t=h({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});t.setAttribute("role","alert"),t.textContent=de,I.appendChild(t)}I.scrollTop=I.scrollHeight;const e=u[u.length-1];It(Z&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function Nt(){for(let e=u.length-1;e>=0;e--){const t=u[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const Ve=e=>{P||(P=e.conversationId)},qe=e=>{const t=Nt();t&&(t.content+=e.content,$())},Ke=e=>{const t=u.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");t>=0?u[t]=e:u.push(e),$(),xe()},Xe=e=>{const t=u.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");t>=0?u[t]=e:u.push(e),Z=!1,$(),e.status==="DONE"&&k?.({id:e.id,content:e.content})},Qe=e=>{de=e.error,Z=!1,u=u.filter(t=>!t.id.startsWith("temp-")),$()};function Tt(e){const t={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};u.push(t),$();const l=e.match(/\S+\s*/g)??[e];let S=0;K=setInterval(()=>{if(S>=l.length){clearInterval(K),K=void 0,t.status="DONE",Pe&&(t.followUpReplies=Pe),$();return}t.content+=l[S],S++,$()},Et)}E.on("message:start",Ve),E.on("message:chunk",qe),E.on("message:answer-complete",Ke),E.on("message:complete",Xe),E.on("message:error",Qe);const Ye=e=>j?.(e),Ze=e=>V?.(e);j&&E.on("form:submitted",Ye),V&&E.on("form:error",Ze);const Ne=[];let Je=!1;const et=e=>{if(Je)return;Ne.push(e.install(E));let t=e.store.get().submitted;const l=e.store.subscribe(S=>{S.submitted&&!t&&(Ge.push(_t(S.submitResult)),$()),t=S.submitted});Ne.push(l)};for(const e of s??[])e.schema!=null?et(dt.createFormCollector(e)):dt.loadFormCollector(E,e).then(t=>et(t)).catch(()=>{});async function we(e,t){const l=e.trim();if(!l&&!t?.length||Z)return;if(T?.(l),Z=!0,de=null,K){clearInterval(K),K=void 0;const w=u.find(G=>G.id.startsWith("ago-intro-"));w&&!w.content?u=u.filter(G=>G!==w):w&&(w.status="DONE")}const S=Date.now();u.push({id:`temp-user-${S}`,conversationId:P||"",content:l,role:"user",status:"DONE",attachments:t&&t.length>0?se.attachmentsFromFiles(t):void 0,createdAt:new Date}),u.push({id:`temp-assistant-${S}`,conversationId:P||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),$();try{const w=await E.sendMessage(l,{conversationId:P,files:t});w.conversationId&&(P||(P=w.conversationId),ge?.setActiveThread(w.conversationId,w.createdAt));const G=u.find(Q=>Q.id===`temp-user-${S}`);if(G&&(G.id=`user-${S}`,G.conversationId=w.conversationId),!u.some(Q=>Q.id===w.id)){const Q=u.findIndex(Wt=>Wt.id===`temp-assistant-${S}`);Q>=0?u[Q]=w:u.push(w)}u=u.filter(Q=>!Q.id.startsWith("temp-")),Z=!1,$(),g&&Te()}catch(w){de=w instanceof Error?w.message:"Failed to send message",Z=!1,u=u.filter(G=>!G.id.startsWith("temp-")),$()}}async function Te(){try{const e=await E.getConversations();he.splice(0,he.length,...e)}catch{}return he}async function Mt(e){try{const t=(await E.getConversation(e))?.messages??[];t.length>0&&u.length===0&&(u=t,$())}catch{u.length===0&&(ge?.clear(),P=void 0)}}return $(),re&&O?.matches||xe(),P?Mt(P):He==="streaming"&&Tt(Fe),g&&Te(),{client:E,element:be,sendMessage:we,...z||re?{open:Bt,close:Dt,toggle:zt}:{},session:ge,threads:he,refreshThreads:Te,destroy(){K&&clearInterval(K),E.off("message:start",Ve),E.off("message:chunk",qe),E.off("message:answer-complete",Ke),E.off("message:complete",Xe),E.off("message:error",Qe),j&&E.off("form:submitted",Ye),V&&E.off("form:error",Ze),Je=!0,Ne.forEach(e=>e()),be.remove(),N?.remove(),H?.remove(),fe?.remove(),X?.remove(),O?.removeEventListener("change",nt),re&&(document.removeEventListener("keydown",tt),it(),document.documentElement.style.removeProperty("overflow")),o.client||E.destroy()}};function Ce(){if(!U)return;{const t=ve==="left"?"border-right":"border-left";O?.matches?(U.style.width="100%",d.style.borderRadius="0",d.style.removeProperty(t)):(U.style.width=typeof x=="number"?`${x}px`:x,d.style.setProperty(t,`1px solid ${L}`))}const e=m==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=oe?"translateX(0)":e,U.setAttribute("aria-hidden",oe?"false":"true"),N&&(N.style.display=oe?"none":"flex")}function Me(){oe=!0,Ce(),xe(),M?.()}function Oe(){oe=!1,Ce(),q?.()}function Ot(){oe?Oe():Me()}function Bt(){z?Me():ue()}function Dt(){z?Oe():me()}function zt(){z?Ot():W?me():ue()}function Ft(){return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(e=>e.getClientRects().length>0)}function tt(e){if(!W)return;if(e.key==="Escape"){me();return}if(e.key!=="Tab")return;const t=Ft();if(t.length===0){e.preventDefault();return}const l=t[0],S=t[t.length-1],w=document.activeElement;e.shiftKey&&(w===l||!d.contains(w))?(e.preventDefault(),S.focus()):!e.shiftKey&&(w===S||!d.contains(w))&&(e.preventDefault(),l.focus())}function nt(e){z?Ce():!e.matches&&W&&me(),$()}function ot(){return window.visualViewport?.height??window.innerHeight}function rt(){const e=window.visualViewport,t=e?.offsetTop??0,l=e?.height??pe,S=Math.min(0,t+l-pe);d.style.top=`${S}px`,H&&(H.style.top=`${t}px`)}function Ee(){ie||(ie=requestAnimationFrame(()=>{ie=0,rt()}))}function Ht(){window.visualViewport?.addEventListener("resize",Ee),window.visualViewport?.addEventListener("scroll",Ee)}function it(){window.visualViewport?.removeEventListener("resize",Ee),window.visualViewport?.removeEventListener("scroll",Ee),ie&&(cancelAnimationFrame(ie),ie=0)}function at(){I.scrollTop=I.scrollHeight}function Pt(){const e=h({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${je}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:ee,borderBottom:`1px solid ${L}`,zIndex:"2147483001",fontFamily:Re});if(e.className="ago-chat-widget-mobile-bar",f){const l=document.createElement("img");l.src=f,l.alt="",v(l,{height:"28px",width:"auto"}),e.appendChild(l)}else if(i){const l=document.createElement("span");l.textContent=i,v(l,{fontSize:"15px",fontWeight:"600",color:J,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),e.appendChild(l)}else e.appendChild(h({}));const t=document.createElement("button");return t.type="button",t.setAttribute("aria-label","Close"),t.textContent="×",v(t,{border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:J,cursor:"pointer",padding:"4px 8px"}),t.addEventListener("click",()=>{me()}),e.appendChild(t),e}function Ut(){return typeof document.startViewTransition=="function"&&!At?.matches&&!!O?.matches}function st(e){const t=document;if(Ut()&&t.startViewTransition){d.style.setProperty("view-transition-name",ce),H?.style.setProperty("view-transition-name",`${ce}-bar`);const l=()=>{d.style.removeProperty("view-transition-name"),H?.style.removeProperty("view-transition-name")};return t.startViewTransition(e).finished.then(l,l)}return e(),Promise.resolve()}function lt(e){if(e)X&&d.parentElement?.insertBefore(X,d),v(d,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",height:"var(--ago-vh, 100dvh)",zIndex:"2147483000",border:"none",borderRadius:"0",boxShadow:"none",paddingTop:`calc(${je}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("aria-label",i),document.documentElement.style.overflow="hidden",F&&(F.style.display="none"),H&&(H.style.display="flex");else{X?.remove(),X=void 0;for(const t of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])d.style.removeProperty(t);d.style.height=ye.height,d.style.border=ye.border,d.style.borderRadius=ye.borderRadius,d.style.boxShadow=ye.boxShadow,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),document.documentElement.style.removeProperty("overflow"),F&&(F.style.display="flex"),H&&(H.style.display="none")}}function ue(){if(W||!O?.matches)return Promise.resolve();const e=d.getBoundingClientRect();if(e.height>=ot()*.8)return Promise.resolve();W=!0,X=h({width:`${e.width}px`,height:`${e.height}px`}),X.className="ago-chat-widget-spacer",X.setAttribute("aria-hidden","true"),pe=ot(),d.style.setProperty("--ago-vh",`${pe}px`),rt(),Ht();const t=st(()=>lt(!0));return t.then(()=>{at(),xe()}),at(),M?.(),t}function me(){if(!W)return Promise.resolve();W=!1,it(),d.querySelector("textarea")?.blur();const e=st(()=>lt(!1));return e.then(()=>d.style.removeProperty("--ago-vh")),pe=0,q?.(),e}}exports.mountChatWidget=pn;exports.renderMarkdown=Ie;
|
|
3
|
+
`);let r=0;for(;r<i.length;){const a=i[r];if(a.trim()===""){r++;continue}const C=a.match(Ct);if(C){const p=C[1][0],f=[];for(r++;r<i.length&&!new RegExp(`^ {0,3}${p==="`"?"`{3,}":"~{3,}"}\\s*$`).test(i[r]);)f.push(i[r]),r++;r++;const A=B("pre",{margin:"0 0 8px 0"});A.appendChild(B("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:vt,whiteSpace:"pre"},ae(f.join(`
|
|
4
|
+
`)))),o.appendChild(A);continue}if(yt.test(a)){o.appendChild(B("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),r++;continue}const m=a.match(wt);if(m){const p=m[1].length;o.appendChild(B(`h${p}`,{margin:"16px 0 8px 0",fontSize:Jt[p-1],fontWeight:"600",lineHeight:"1.3"},te(m[2]))),r++;continue}if(ke.test(a)){const p=[];for(;r<i.length&&ke.test(i[r]);)p.push(i[r].replace(ke,"")),r++;const f=B("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});f.appendChild(Ie(p.join(`
|
|
5
|
+
`))),o.appendChild(f);continue}if(a.includes("|")&&nn(i[r+1])){const p=[a,i[r+1]];for(r+=2;r<i.length&&i[r].includes("|")&&i[r].trim();)p.push(i[r]),r++;o.appendChild(tn(p));continue}if(le.test(a)){const p=[],f=Fe(a);for(;r<i.length&&i[r].trim()!=="";)if(le.test(i[r])||Fe(i[r])>f)p.push(i[r]),r++;else break;o.appendChild(Et(p));continue}const x=[a];for(r++;r<i.length&&!en(i[r]);)x.push(i[r]),r++;o.appendChild(B("p",{margin:"0 0 8px 0",lineHeight:"1.6"},x.map(p=>te(p)).join("<br>")))}const b=o.lastElementChild;return b&&(b.style.marginBottom="0"),o}function on(n,o){const{isLast:i,isLastOfBlock:r,bubbleStyle:b,showAgentName:a,agentBubble:C,followUpEnabled:m,followUpHandler:x,isMobile:p}=o,f=n.role==="user",A=b==="imessage",R=h({display:"flex",flexDirection:"column",alignItems:f?"flex-end":"flex-start",marginBottom:A&&!r?"2px":"16px"});if(R.className=`ago-message ago-message--${n.role}`,!f&&a&&n.agent){const g=h({fontSize:"13px",fontWeight:"500",color:J,marginBottom:"6px",padding:"0 4px"});g.className="ago-message__agent",g.textContent=n.agent.displayName||n.agent.name,R.appendChild(g)}if(!f&&n.sources&&n.sources.length>0){const g=h({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});g.className="ago-message__sources",n.sources.forEach((s,c)=>{const y=s.url?document.createElement("a"):document.createElement("div");s.url&&y instanceof HTMLAnchorElement&&(y.href=s.url,y.target="_blank",y.rel="noopener noreferrer"),v(y,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${L}`,borderRadius:"8px",backgroundColor:ee,textDecoration:"none",color:J,fontSize:"12px",overflow:"hidden"});const T=h({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${De}`,color:De,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});T.textContent=String(c+1);const k=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});k.textContent=s.title,k.title=s.title,y.append(T,k),g.appendChild(y)}),R.appendChild(g)}if(n.attachments&&n.attachments.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:f?"flex-end":"flex-start",maxWidth:"75%"});g.className="ago-message__attachments";for(const s of n.attachments){const c=se.safeAttachmentUrl(s.url);if(se.canInlineImage(s)&&c){const M=document.createElement("a");M.href=c,M.target="_blank",M.rel="noopener noreferrer",v(M,{display:"inline-block",textDecoration:"none"});const q=document.createElement("img");q.src=c,q.alt=s.name,q.loading="lazy",v(q,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${L}`,display:"block"}),M.appendChild(q),g.appendChild(M);continue}const y=c?document.createElement("a"):document.createElement("div");c&&y instanceof HTMLAnchorElement&&(y.href=c,y.target="_blank",y.rel="noopener noreferrer"),v(y,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${L}`,backgroundColor:f?"rgba(255,255,255,0.12)":ee,color:f?_e:J,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const T=document.createElement("span");T.textContent="📄",T.setAttribute("aria-hidden","true"),v(T,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const k=h({display:"flex",flexDirection:"column",minWidth:"0"}),j=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});j.textContent=s.name,j.title=s.name,k.appendChild(j);const V=se.formatFileSize(s.fileSize);if(V){const M=h({fontSize:"11px",color:bt});M.textContent=V,k.appendChild(M)}y.append(T,k),g.appendChild(y)}R.appendChild(g)}const _=f||C||A,Y=!!n.content||n.status==="IN_PROGRESS",D=h({maxWidth:_?A||f?p?"88%":"75%":p?"92%":"85%":"100%",padding:_?"10px 14px":"2px 8px",borderRadius:A?Kt:_?ze:"0",backgroundColor:f?Ae:_?ut:"transparent",color:f?_e:J,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(D.className="ago-message__content",A&&r){D.style.position="relative";const g=h({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:f?Ae:ut});g.className="ago-message__tail";const s=h({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:xt});s.className="ago-message__tail-mask",f?(g.style.right="-8px",g.style.borderBottomLeftRadius="16px 14px",s.style.right="-10px",s.style.borderBottomLeftRadius="10px"):(g.style.left="-7px",g.style.borderBottomRightRadius="16px 14px",s.style.left="-10px",s.style.borderBottomRightRadius="10px"),D.append(g,s)}if(n.content?D.appendChild(Ie(n.content)):n.status==="IN_PROGRESS"&&D.appendChild(an()),Y&&R.appendChild(D),i&&n.followUpReplies&&n.followUpReplies.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});g.className="ago-message__followups";for(const s of n.followUpReplies){const c=document.createElement("button");c.type="button",c.className="ago-message__followup-btn",c.textContent=s,c.disabled=!m,v(c,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:ze,border:`1px solid ${L}`,backgroundColor:ee,color:J,cursor:m?"pointer":"default",transition:"border-color 0.15s"}),x&&c.addEventListener("click",()=>x(s)),c.addEventListener("mouseenter",()=>{c.style.borderColor=De}),c.addEventListener("mouseleave",()=>{c.style.borderColor=L}),g.appendChild(c)}R.appendChild(g)}return R}function rn(n){const o=h({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:ze,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});o.className="ago-form-notice",o.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),v(i,{fontWeight:"700"});const r=document.createElement("span");return r.textContent=n,o.append(i,r),o}function an(){const n=h({display:"flex",gap:"4px",padding:"4px 0"});for(let o=0;o<3;o++){const i=h({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${o*.2}s`});n.appendChild(i)}return n}function sn(){const n="http://www.w3.org/2000/svg",o=document.createElementNS(n,"svg");o.setAttribute("width","26"),o.setAttribute("height","26"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none");const i=document.createElementNS(n,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),o.appendChild(i),o}var ht="Form submitted.";function ln(n){if(typeof n=="string")return n||null;if(!n||typeof n!="object")return null;const o=n;if(typeof o.message=="string"&&o.message)return o.message;const i=o.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const r=i.message;if(typeof r=="string"&&r)return r}return null}var dn=0;function cn(n){const o=typeof n=="string"?document.querySelector(n):n;if(!o)throw new Error(`mountChatWidget: target "${String(n)}" not found.`);return o}function pn(n,o){const{title:i="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:b="Type a message...",allowFiles:a=!1,height:C=500,placement:m="inline",width:x=400,defaultOpen:p=!1,logoUrl:f,showAgentName:A=!1,agentBubble:R=!1,bubbleStyle:_="default",showHeader:Y=!0,theme:D,loadThreads:g=!1,forms:s,formSubmittedMessage:c=ht,onFollowUpClick:y,onMessageSent:T,onMessageReceived:k,onFormSubmitted:j,onFormError:V,onOpen:M,onClose:q}=o,ne=typeof r=="string"?{message:r,mode:"static"}:r,He=ne.message,Pe=ne.mode??"static",St="speed"in ne&&ne.speed||45,Ue="followUpReplies"in ne&&ne.followUpReplies||void 0;if(!o.client&&!o.config?.baseUrl)throw new se.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const E=o.client??new se.AgoClient(o.config),We=cn(n),z=m==="left"||m==="right",Rt=z&&(o.launcher??!0);let oe=z?p:!0;const kt=o.mobile?.breakpoint??768,$e=o.mobile?.trigger??"tap",Ge=typeof window<"u"&&!!window.matchMedia,O=Ge?window.matchMedia(`(max-width: ${kt}px)`):void 0,At=Ge?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,re=!z&&!!O,Le=o.persistConversation,ge=Le?Gt.createConversationSession(Le===!0?{}:Le):void 0;let P=o.conversationId??ge?.getLastActiveThread()??void 0,u=[],Z=!1,de=null,K;const je=[];function _t(e){if(typeof c=="function"){const l=c(e);if(typeof l=="string"&&l)return l}const t=ln(e);return t||(typeof c=="string"?c:ht)}const he=[],d=h({display:"flex",flexDirection:"column",height:z?"100%":typeof C=="number"?`${C}px`:C,border:`1px solid ${L}`,borderRadius:qt,overflow:"hidden",backgroundColor:ee,fontFamily:Re,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",Xt(d,D);let F;if(Y){if(F=h({padding:"14px 16px",borderBottom:`1px solid ${L}`,backgroundColor:Vt,color:ft,display:"flex",alignItems:"center",gap:"10px"}),F.className="ago-chat-widget__header",f){const t=document.createElement("img");t.src=f,t.alt="Logo",v(t,{height:"24px",width:"auto"}),F.appendChild(t)}const e=document.createElement("h3");if(e.textContent=i,v(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),F.appendChild(e),z){const t=document.createElement("button");t.type="button",t.className="ago-chat-widget__close",t.setAttribute("aria-label","Close"),t.textContent="×",v(t,{marginLeft:"auto",background:"transparent",border:"none",color:ft,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),t.addEventListener("click",()=>Be()),F.appendChild(t)}}const I=h({flex:"1",overflow:"auto",padding:"16px",backgroundColor:xt});I.className="ago-chat-widget__messages",I.setAttribute("role","log"),I.setAttribute("aria-live","polite"),I.setAttribute("aria-relevant","additions text"),I.setAttribute("aria-atomic","false");const{inputRow:Ne,setDisabled:It,focus:xe}=Yt({placeholder:b,allowFiles:a,onSend:(e,t)=>{we(e,t)}});Qt(),d.append(...F?[F]:[],I,Ne);let be=d,U,N;const ve=m==="left"?"left":"right";if(z&&(U=h({position:"fixed",top:"0",bottom:"0",[ve]:"0",width:typeof x=="number"?`${x}px`:x,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),U.className="ago-chat-widget-panel",v(d,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ve==="left"?"borderRight":"borderLeft"]:`1px solid ${L}`}),U.appendChild(d),be=U),Rt){if(N=document.createElement("button"),N.type="button",N.className="ago-chat-widget-launcher",N.setAttribute("aria-label",`Open ${i}`),v(N,{position:"fixed",bottom:"20px",[ve]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:Ae,color:_e,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:Re}),f){const e=document.createElement("img");e.src=f,e.alt="",v(e,{width:"26px",height:"26px",objectFit:"contain"}),N.appendChild(e)}else N.appendChild(sn());N.addEventListener("click",()=>Oe())}const ce=re?`ago-vt-${++dn}`:"",Ve=52;let W=!1,pe=0,ie=0,H,fe,X;const ye={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};We.appendChild(be),N&&We.appendChild(N),Ce(),re&&(H=Pt(),d.insertBefore(H,d.firstChild),fe=document.createElement("style"),fe.id=ce,fe.textContent=`::view-transition-group(${ce}),::view-transition-group(${ce}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(fe),($e==="focus"||$e==="tap")&&(d.addEventListener("pointerdown",e=>{if(W||!O?.matches)return;const t=Ne.contains(e.target);if($e==="tap"){if((e.target instanceof Element?e.target:null)?.closest("button,a[href],[role='button']"))return}else if(!t)return;t&&e.preventDefault(),ue()},!0),d.addEventListener("focusin",e=>{O?.matches&&Ne.contains(e.target)&&ue()})),document.addEventListener("keydown",nt)),O&&O.addEventListener("change",ot);const $t=y!==!1,Lt=y===!1?void 0:y??(e=>{re&&O?.matches&&!W?ue().then(()=>we(e)):we(e)});function $(){if(I.replaceChildren(),u.length===0){if(Pe==="static"){const t=h({textAlign:"center",color:bt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});t.appendChild(Ie(He)),I.appendChild(t)}}else u.forEach((t,l)=>{const S=l===u.length-1||u[l+1].role!==t.role;I.appendChild(on(t,{isLast:l===u.length-1,isLastOfBlock:S,bubbleStyle:_,showAgentName:A,agentBubble:R,followUpEnabled:$t,followUpHandler:Lt,isMobile:!!O?.matches}))});for(const t of je)I.appendChild(rn(t));if(de){const t=h({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});t.setAttribute("role","alert"),t.textContent=de,I.appendChild(t)}I.scrollTop=I.scrollHeight;const e=u[u.length-1];It(Z&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function Nt(){for(let e=u.length-1;e>=0;e--){const t=u[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const qe=e=>{P||(P=e.conversationId)},Ke=e=>{const t=Nt();t&&(t.content+=e.content,$())},Xe=e=>{const t=u.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");t>=0?u[t]=e:u.push(e),$(),xe()},Qe=e=>{const t=u.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");t>=0?u[t]=e:u.push(e),Z=!1,$(),e.status==="DONE"&&k?.({id:e.id,content:e.content})},Ye=e=>{de=e.error,Z=!1,u=u.filter(t=>!t.id.startsWith("temp-")),$()};function Tt(e){const t={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};u.push(t),$();const l=e.match(/\S+\s*/g)??[e];let S=0;K=setInterval(()=>{if(S>=l.length){clearInterval(K),K=void 0,t.status="DONE",Ue&&(t.followUpReplies=Ue),$();return}t.content+=l[S],S++,$()},St)}E.on("message:start",qe),E.on("message:chunk",Ke),E.on("message:answer-complete",Xe),E.on("message:complete",Qe),E.on("message:error",Ye);const Ze=e=>j?.(e),Je=e=>V?.(e);j&&E.on("form:submitted",Ze),V&&E.on("form:error",Je);const Te=[];let et=!1;const tt=e=>{if(et)return;Te.push(e.install(E));let t=e.store.get().submitted;const l=e.store.subscribe(S=>{S.submitted&&!t&&(je.push(_t(S.submitResult)),$()),t=S.submitted});Te.push(l)};for(const e of s??[])e.schema!=null?tt(ct.createFormCollector(e)):ct.loadFormCollector(E,e).then(t=>tt(t)).catch(()=>{});async function we(e,t){const l=e.trim();if(!l&&!t?.length||Z)return;if(T?.(l),Z=!0,de=null,K){clearInterval(K),K=void 0;const w=u.find(G=>G.id.startsWith("ago-intro-"));w&&!w.content?u=u.filter(G=>G!==w):w&&(w.status="DONE")}const S=Date.now();u.push({id:`temp-user-${S}`,conversationId:P||"",content:l,role:"user",status:"DONE",attachments:t&&t.length>0?se.attachmentsFromFiles(t):void 0,createdAt:new Date}),u.push({id:`temp-assistant-${S}`,conversationId:P||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),$();try{const w=await E.sendMessage(l,{conversationId:P,files:t});w.conversationId&&(P||(P=w.conversationId),ge?.setActiveThread(w.conversationId,w.createdAt));const G=u.find(Q=>Q.id===`temp-user-${S}`);if(G&&(G.id=`user-${S}`,G.conversationId=w.conversationId),!u.some(Q=>Q.id===w.id)){const Q=u.findIndex(Wt=>Wt.id===`temp-assistant-${S}`);Q>=0?u[Q]=w:u.push(w)}u=u.filter(Q=>!Q.id.startsWith("temp-")),Z=!1,$(),g&&Me()}catch(w){de=w instanceof Error?w.message:"Failed to send message",Z=!1,u=u.filter(G=>!G.id.startsWith("temp-")),$()}}async function Me(){try{const e=await E.getConversations();he.splice(0,he.length,...e)}catch{}return he}async function Mt(e){try{const t=(await E.getConversation(e))?.messages??[];t.length>0&&u.length===0&&(u=t,$())}catch{u.length===0&&(ge?.clear(),P=void 0)}}return $(),re&&O?.matches||xe(),P?Mt(P):Pe==="streaming"&&Tt(He),g&&Me(),{client:E,element:be,sendMessage:we,...z||re?{open:Bt,close:Dt,toggle:zt}:{},session:ge,threads:he,refreshThreads:Me,destroy(){K&&clearInterval(K),E.off("message:start",qe),E.off("message:chunk",Ke),E.off("message:answer-complete",Xe),E.off("message:complete",Qe),E.off("message:error",Ye),j&&E.off("form:submitted",Ze),V&&E.off("form:error",Je),et=!0,Te.forEach(e=>e()),be.remove(),N?.remove(),H?.remove(),fe?.remove(),X?.remove(),O?.removeEventListener("change",ot),re&&(document.removeEventListener("keydown",nt),at(),document.documentElement.style.removeProperty("overflow")),o.client||E.destroy()}};function Ce(){if(!U)return;{const t=ve==="left"?"border-right":"border-left";O?.matches?(U.style.width="100%",d.style.borderRadius="0",d.style.removeProperty(t)):(U.style.width=typeof x=="number"?`${x}px`:x,d.style.setProperty(t,`1px solid ${L}`))}const e=m==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=oe?"translateX(0)":e,U.setAttribute("aria-hidden",oe?"false":"true"),N&&(N.style.display=oe?"none":"flex")}function Oe(){oe=!0,Ce(),xe(),M?.()}function Be(){oe=!1,Ce(),q?.()}function Ot(){oe?Be():Oe()}function Bt(){z?Oe():ue()}function Dt(){z?Be():me()}function zt(){z?Ot():W?me():ue()}function Ft(){return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(e=>e.getClientRects().length>0)}function nt(e){if(!W)return;if(e.key==="Escape"){me();return}if(e.key!=="Tab")return;const t=Ft();if(t.length===0){e.preventDefault();return}const l=t[0],S=t[t.length-1],w=document.activeElement;e.shiftKey&&(w===l||!d.contains(w))?(e.preventDefault(),S.focus()):!e.shiftKey&&(w===S||!d.contains(w))&&(e.preventDefault(),l.focus())}function ot(e){z?Ce():!e.matches&&W&&me(),$()}function rt(){return window.visualViewport?.height??window.innerHeight}function it(){const e=window.visualViewport,t=e?.offsetTop??0,l=e?.height??pe,S=Math.min(0,t+l-pe);d.style.top=`${S}px`,H&&(H.style.top=`${t}px`)}function Ee(){ie||(ie=requestAnimationFrame(()=>{ie=0,it()}))}function Ht(){window.visualViewport?.addEventListener("resize",Ee),window.visualViewport?.addEventListener("scroll",Ee)}function at(){window.visualViewport?.removeEventListener("resize",Ee),window.visualViewport?.removeEventListener("scroll",Ee),ie&&(cancelAnimationFrame(ie),ie=0)}function st(){I.scrollTop=I.scrollHeight}function Pt(){const e=h({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${Ve}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:ee,borderBottom:`1px solid ${L}`,zIndex:"2147483001",fontFamily:Re});if(e.className="ago-chat-widget-mobile-bar",f){const l=document.createElement("img");l.src=f,l.alt="",v(l,{height:"28px",width:"auto"}),e.appendChild(l)}else if(i){const l=document.createElement("span");l.textContent=i,v(l,{fontSize:"15px",fontWeight:"600",color:J,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),e.appendChild(l)}else e.appendChild(h({}));const t=document.createElement("button");return t.type="button",t.setAttribute("aria-label","Close"),t.textContent="×",v(t,{border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:J,cursor:"pointer",padding:"4px 8px"}),t.addEventListener("click",()=>{me()}),e.appendChild(t),e}function Ut(){return typeof document.startViewTransition=="function"&&!At?.matches&&!!O?.matches}function lt(e){const t=document;if(Ut()&&t.startViewTransition){d.style.setProperty("view-transition-name",ce),H?.style.setProperty("view-transition-name",`${ce}-bar`);const l=()=>{d.style.removeProperty("view-transition-name"),H?.style.removeProperty("view-transition-name")};return t.startViewTransition(e).finished.then(l,l)}return e(),Promise.resolve()}function dt(e){if(e)X&&d.parentElement?.insertBefore(X,d),v(d,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",height:"var(--ago-vh, 100dvh)",zIndex:"2147483000",border:"none",borderRadius:"0",boxShadow:"none",paddingTop:`calc(${Ve}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("aria-label",i),document.documentElement.style.overflow="hidden",F&&(F.style.display="none"),H&&(H.style.display="flex");else{X?.remove(),X=void 0;for(const t of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])d.style.removeProperty(t);d.style.height=ye.height,d.style.border=ye.border,d.style.borderRadius=ye.borderRadius,d.style.boxShadow=ye.boxShadow,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),document.documentElement.style.removeProperty("overflow"),F&&(F.style.display="flex"),H&&(H.style.display="none")}}function ue(){if(W||!O?.matches)return Promise.resolve();const e=d.getBoundingClientRect();if(e.height>=rt()*.8)return Promise.resolve();W=!0,X=h({width:`${e.width}px`,height:`${e.height}px`}),X.className="ago-chat-widget-spacer",X.setAttribute("aria-hidden","true"),pe=rt(),d.style.setProperty("--ago-vh",`${pe}px`),it(),Ht();const t=lt(()=>dt(!0));return t.then(()=>{st(),xe()}),st(),M?.(),t}function me(){if(!W)return Promise.resolve();W=!1,at(),d.querySelector("textarea")?.blur();const e=lt(()=>dt(!1));return e.then(()=>d.style.removeProperty("--ago-vh")),pe=0,q?.(),e}}exports.mountChatWidget=pn;exports.renderMarkdown=Ie;
|
package/dist/widget.d.cts
CHANGED
|
@@ -876,11 +876,13 @@ export declare interface MountChatWidgetOptions {
|
|
|
876
876
|
/** Max viewport width (px) treated as "mobile". Defaults to `768`. */
|
|
877
877
|
breakpoint?: number;
|
|
878
878
|
/**
|
|
879
|
-
* Inline placement only: how the card enters full screen.
|
|
880
|
-
* expands when the
|
|
881
|
-
* `
|
|
879
|
+
* Inline placement only: how the card enters full screen.
|
|
880
|
+
* - `"tap"` (default): expands when anywhere on the compact card is tapped
|
|
881
|
+
* - `"focus"`: expands only when the input is tapped/focused.
|
|
882
|
+
* - `"manual"`: expands only via `widget.open()`.
|
|
883
|
+
* Ignored for side placements (driven by the launcher).
|
|
882
884
|
*/
|
|
883
|
-
trigger?: "focus" | "manual";
|
|
885
|
+
trigger?: "tap" | "focus" | "manual";
|
|
884
886
|
};
|
|
885
887
|
/**
|
|
886
888
|
* Load the visitor's conversation list into `widget.threads` on mount and refresh
|
package/dist/widget.d.ts
CHANGED
|
@@ -876,11 +876,13 @@ export declare interface MountChatWidgetOptions {
|
|
|
876
876
|
/** Max viewport width (px) treated as "mobile". Defaults to `768`. */
|
|
877
877
|
breakpoint?: number;
|
|
878
878
|
/**
|
|
879
|
-
* Inline placement only: how the card enters full screen.
|
|
880
|
-
* expands when the
|
|
881
|
-
* `
|
|
879
|
+
* Inline placement only: how the card enters full screen.
|
|
880
|
+
* - `"tap"` (default): expands when anywhere on the compact card is tapped
|
|
881
|
+
* - `"focus"`: expands only when the input is tapped/focused.
|
|
882
|
+
* - `"manual"`: expands only via `widget.open()`.
|
|
883
|
+
* Ignored for side placements (driven by the launcher).
|
|
882
884
|
*/
|
|
883
|
-
trigger?: "focus" | "manual";
|
|
885
|
+
trigger?: "tap" | "focus" | "manual";
|
|
884
886
|
};
|
|
885
887
|
/**
|
|
886
888
|
* Load the visitor's conversation list into `widget.threads` on mount and refresh
|
package/dist/widget.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as Ut, i as Wt, m as Gt, o as Vt, s as jt, t as qt } from "./AgoClient-Cwx_eYSu.js";
|
|
2
2
|
import { r as Kt, t as Xt } from "./createFormCollector-CyWisAkI.js";
|
|
3
3
|
import { t as Qt } from "./createConversationSession-B3h567tt.js";
|
|
4
|
-
var Yt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', Se = `var(--ago-font, ${Yt})`,
|
|
4
|
+
var Yt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', Se = `var(--ago-font, ${Yt})`, dt = {
|
|
5
5
|
font: "--ago-font",
|
|
6
6
|
radius: "--ago-radius",
|
|
7
7
|
messageRadius: "--ago-message-radius",
|
|
@@ -16,12 +16,12 @@ var Yt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto
|
|
|
16
16
|
border: "--ago-border-color",
|
|
17
17
|
accent: "--ago-accent-color",
|
|
18
18
|
agentBubbleBg: "--ago-agent-bubble-background"
|
|
19
|
-
}, ke = "var(--ago-brand-color, #03182f)", Ae = "var(--ago-brand-text-color, #fff)", Zt = "var(--ago-header-background, var(--ago-brand-color, #03182f))",
|
|
19
|
+
}, ke = "var(--ago-brand-color, #03182f)", Ae = "var(--ago-brand-text-color, #fff)", Zt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", ct = "var(--ago-header-text-color, #e8f0fe)", ee = "var(--ago-panel-background, #fff)", gt = "var(--ago-messages-background, #fbfbfb)", J = "var(--ago-text-color, #30373e)", ht = "var(--ago-muted-text-color, #6b6d6f)", L = "var(--ago-border-color, #dee3e8)", Me = "var(--ago-accent-color, #1b5fc4)", pt = "var(--ago-agent-bubble-background, #f1f3f5)", Jt = "var(--ago-radius, 16px)", Oe = "var(--ago-message-radius, 16px)", en = "var(--ago-message-radius, 20px)";
|
|
20
20
|
function tn(n, o) {
|
|
21
21
|
if (o)
|
|
22
|
-
for (const i of Object.keys(
|
|
22
|
+
for (const i of Object.keys(dt)) {
|
|
23
23
|
const r = o[i];
|
|
24
|
-
r != null && n.style.setProperty(
|
|
24
|
+
r != null && n.style.setProperty(dt[i], r);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
function v(n, o) {
|
|
@@ -31,11 +31,11 @@ function h(n = {}) {
|
|
|
31
31
|
const o = document.createElement("div");
|
|
32
32
|
return v(o, n), o;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var ft = "ago-chat-widget-keyframes";
|
|
35
35
|
function nn() {
|
|
36
|
-
if (typeof document > "u" || document.getElementById(
|
|
36
|
+
if (typeof document > "u" || document.getElementById(ft)) return;
|
|
37
37
|
const n = document.createElement("style");
|
|
38
|
-
n.id =
|
|
38
|
+
n.id = ft, n.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }", document.head.appendChild(n);
|
|
39
39
|
}
|
|
40
40
|
function on(n) {
|
|
41
41
|
let o = [];
|
|
@@ -167,19 +167,19 @@ var rn = {
|
|
|
167
167
|
function ae(n) {
|
|
168
168
|
return n.replace(/[&<>"']/g, (o) => rn[o]);
|
|
169
169
|
}
|
|
170
|
-
function
|
|
170
|
+
function ut(n) {
|
|
171
171
|
const o = n.trim();
|
|
172
172
|
return /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o) || !/^[a-z][a-z0-9+.-]*:/i.test(o) ? o : null;
|
|
173
173
|
}
|
|
174
|
-
var
|
|
174
|
+
var xt = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', Ee = "";
|
|
175
175
|
function te(n) {
|
|
176
176
|
const o = [], i = (b) => (o.push(b), `${Ee}${o.length - 1}${Ee}`);
|
|
177
177
|
let r = n;
|
|
178
|
-
return r = r.replace(/`([^`]+)`/g, (b, a) => i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${
|
|
179
|
-
const m =
|
|
178
|
+
return r = r.replace(/`([^`]+)`/g, (b, a) => i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${xt}">${ae(a)}</code>`)), r = r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (b, a, C) => {
|
|
179
|
+
const m = ut(C);
|
|
180
180
|
return m ? i(`<img alt="${ae(a)}" src="${ae(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : b;
|
|
181
181
|
}), r = r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (b, a, C) => {
|
|
182
|
-
const m =
|
|
182
|
+
const m = ut(C);
|
|
183
183
|
return m ? i(`<a href="${ae(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`) : b;
|
|
184
184
|
}), r = ae(r), r = r.replace(/\*\*([^*]+?)\*\*/g, "<strong>$1</strong>").replace(/__([^_]+?)__/g, "<strong>$1</strong>").replace(/~~([^~]+?)~~/g, "<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g, "$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g, "$1<em>$2</em>"), r = r.replace(new RegExp(`${Ee}(\\d+)${Ee}`, "g"), (b, a) => o[Number(a)]), r;
|
|
185
185
|
}
|
|
@@ -187,18 +187,18 @@ function O(n, o, i) {
|
|
|
187
187
|
const r = document.createElement(n);
|
|
188
188
|
return Object.assign(r.style, o), i !== void 0 && (r.innerHTML = i), r;
|
|
189
189
|
}
|
|
190
|
-
var
|
|
190
|
+
var bt = /^ {0,3}([-*_])( *\1){2,} *$/, vt = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, yt = /^ {0,3}(```+|~~~+)/, Re = /^ {0,3}>\s?/, se = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, an = [
|
|
191
191
|
"20px",
|
|
192
192
|
"18px",
|
|
193
193
|
"16px",
|
|
194
194
|
"15px",
|
|
195
195
|
"14px",
|
|
196
196
|
"13px"
|
|
197
|
-
],
|
|
197
|
+
], De = (n) => n.match(/^\s*/)?.[0].length ?? 0;
|
|
198
198
|
function sn(n) {
|
|
199
|
-
return n.trim() === "" ||
|
|
199
|
+
return n.trim() === "" || bt.test(n) || vt.test(n) || yt.test(n) || Re.test(n) || se.test(n);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function wt(n) {
|
|
202
202
|
const o = n[0].match(se), i = o[1].length, r = /\d/.test(o[2]), b = O(r ? "ol" : "ul", {
|
|
203
203
|
margin: "0 0 8px 0",
|
|
204
204
|
paddingLeft: "20px",
|
|
@@ -208,14 +208,14 @@ function yt(n) {
|
|
|
208
208
|
let a = 0;
|
|
209
209
|
for (; a < n.length; ) {
|
|
210
210
|
const C = n[a].match(se), m = [];
|
|
211
|
-
for (a++; a < n.length &&
|
|
211
|
+
for (a++; a < n.length && De(n[a]) > i; )
|
|
212
212
|
m.push(n[a]), a++;
|
|
213
213
|
const x = O("li", {
|
|
214
214
|
display: "list-item",
|
|
215
215
|
margin: "2px 0",
|
|
216
216
|
lineHeight: "1.6"
|
|
217
217
|
}), p = C[3].match(/^\[([ xX])\]\s+(.*)$/);
|
|
218
|
-
p ? (x.style.listStyleType = "none", x.style.marginLeft = "-20px", x.innerHTML = `<span style="margin-right:6px">${p[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${te(p[2])}`) : x.innerHTML = te(C[3]), m.filter((f) => se.test(f)).length > 0 && x.appendChild(
|
|
218
|
+
p ? (x.style.listStyleType = "none", x.style.marginLeft = "-20px", x.innerHTML = `<span style="margin-right:6px">${p[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${te(p[2])}`) : x.innerHTML = te(C[3]), m.filter((f) => se.test(f)).length > 0 && x.appendChild(wt(m.filter((f) => f.trim() !== ""))), b.appendChild(x);
|
|
219
219
|
}
|
|
220
220
|
return b;
|
|
221
221
|
}
|
|
@@ -248,7 +248,7 @@ function ln(n) {
|
|
|
248
248
|
return r.appendChild(C), i.appendChild(r), i;
|
|
249
249
|
}
|
|
250
250
|
var dn = (n) => !!n && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(n);
|
|
251
|
-
function
|
|
251
|
+
function ze(n) {
|
|
252
252
|
const o = document.createDocumentFragment(), i = n.replace(/\r\n?/g, `
|
|
253
253
|
`).split(`
|
|
254
254
|
`);
|
|
@@ -259,7 +259,7 @@ function De(n) {
|
|
|
259
259
|
r++;
|
|
260
260
|
continue;
|
|
261
261
|
}
|
|
262
|
-
const C = a.match(
|
|
262
|
+
const C = a.match(yt);
|
|
263
263
|
if (C) {
|
|
264
264
|
const p = C[1][0], f = [];
|
|
265
265
|
for (r++; r < i.length && !new RegExp(`^ {0,3}${p === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(i[r]); )
|
|
@@ -273,13 +273,13 @@ function De(n) {
|
|
|
273
273
|
borderRadius: "6px",
|
|
274
274
|
fontSize: "13px",
|
|
275
275
|
overflowX: "auto",
|
|
276
|
-
fontFamily:
|
|
276
|
+
fontFamily: xt,
|
|
277
277
|
whiteSpace: "pre"
|
|
278
278
|
}, ae(f.join(`
|
|
279
279
|
`)))), o.appendChild(A);
|
|
280
280
|
continue;
|
|
281
281
|
}
|
|
282
|
-
if (
|
|
282
|
+
if (bt.test(a)) {
|
|
283
283
|
o.appendChild(O("hr", {
|
|
284
284
|
border: "none",
|
|
285
285
|
borderTop: "1px solid #dee3e8",
|
|
@@ -287,7 +287,7 @@ function De(n) {
|
|
|
287
287
|
})), r++;
|
|
288
288
|
continue;
|
|
289
289
|
}
|
|
290
|
-
const m = a.match(
|
|
290
|
+
const m = a.match(vt);
|
|
291
291
|
if (m) {
|
|
292
292
|
const p = m[1].length;
|
|
293
293
|
o.appendChild(O(`h${p}`, {
|
|
@@ -309,7 +309,7 @@ function De(n) {
|
|
|
309
309
|
fontStyle: "italic",
|
|
310
310
|
color: "#6b6d6f"
|
|
311
311
|
});
|
|
312
|
-
f.appendChild(
|
|
312
|
+
f.appendChild(ze(p.join(`
|
|
313
313
|
`))), o.appendChild(f);
|
|
314
314
|
continue;
|
|
315
315
|
}
|
|
@@ -321,12 +321,12 @@ function De(n) {
|
|
|
321
321
|
continue;
|
|
322
322
|
}
|
|
323
323
|
if (se.test(a)) {
|
|
324
|
-
const p = [], f =
|
|
324
|
+
const p = [], f = De(a);
|
|
325
325
|
for (; r < i.length && i[r].trim() !== ""; )
|
|
326
|
-
if (se.test(i[r]) ||
|
|
326
|
+
if (se.test(i[r]) || De(i[r]) > f)
|
|
327
327
|
p.push(i[r]), r++;
|
|
328
328
|
else break;
|
|
329
|
-
o.appendChild(
|
|
329
|
+
o.appendChild(wt(p));
|
|
330
330
|
continue;
|
|
331
331
|
}
|
|
332
332
|
const x = [a];
|
|
@@ -386,8 +386,8 @@ function cn(n, o) {
|
|
|
386
386
|
width: "18px",
|
|
387
387
|
height: "18px",
|
|
388
388
|
borderRadius: "3px",
|
|
389
|
-
border: `1px solid ${
|
|
390
|
-
color:
|
|
389
|
+
border: `1px solid ${Me}`,
|
|
390
|
+
color: Me,
|
|
391
391
|
fontSize: "11px",
|
|
392
392
|
fontWeight: "500",
|
|
393
393
|
display: "flex",
|
|
@@ -468,7 +468,7 @@ function cn(n, o) {
|
|
|
468
468
|
if (j) {
|
|
469
469
|
const B = h({
|
|
470
470
|
fontSize: "11px",
|
|
471
|
-
color:
|
|
471
|
+
color: ht
|
|
472
472
|
});
|
|
473
473
|
B.textContent = j, k.appendChild(B);
|
|
474
474
|
}
|
|
@@ -479,8 +479,8 @@ function cn(n, o) {
|
|
|
479
479
|
const _ = f || C || A, Y = !!n.content || n.status === "IN_PROGRESS", D = h({
|
|
480
480
|
maxWidth: _ ? A || f ? p ? "88%" : "75%" : p ? "92%" : "85%" : "100%",
|
|
481
481
|
padding: _ ? "10px 14px" : "2px 8px",
|
|
482
|
-
borderRadius: A ? en : _ ?
|
|
483
|
-
backgroundColor: f ? ke : _ ?
|
|
482
|
+
borderRadius: A ? en : _ ? Oe : "0",
|
|
483
|
+
backgroundColor: f ? ke : _ ? pt : "transparent",
|
|
484
484
|
color: f ? Ae : J,
|
|
485
485
|
overflowWrap: "break-word",
|
|
486
486
|
textWrap: "pretty",
|
|
@@ -495,7 +495,7 @@ function cn(n, o) {
|
|
|
495
495
|
bottom: "-2px",
|
|
496
496
|
width: "20px",
|
|
497
497
|
height: "20px",
|
|
498
|
-
background: f ? ke :
|
|
498
|
+
background: f ? ke : pt
|
|
499
499
|
});
|
|
500
500
|
g.className = "ago-message__tail";
|
|
501
501
|
const s = h({
|
|
@@ -504,11 +504,11 @@ function cn(n, o) {
|
|
|
504
504
|
bottom: "-2px",
|
|
505
505
|
width: "10px",
|
|
506
506
|
height: "20px",
|
|
507
|
-
background:
|
|
507
|
+
background: gt
|
|
508
508
|
});
|
|
509
509
|
s.className = "ago-message__tail-mask", f ? (g.style.right = "-8px", g.style.borderBottomLeftRadius = "16px 14px", s.style.right = "-10px", s.style.borderBottomLeftRadius = "10px") : (g.style.left = "-7px", g.style.borderBottomRightRadius = "16px 14px", s.style.left = "-10px", s.style.borderBottomRightRadius = "10px"), D.append(g, s);
|
|
510
510
|
}
|
|
511
|
-
if (n.content ? D.appendChild(
|
|
511
|
+
if (n.content ? D.appendChild(ze(n.content)) : n.status === "IN_PROGRESS" && D.appendChild(fn()), Y && R.appendChild(D), i && n.followUpReplies && n.followUpReplies.length > 0) {
|
|
512
512
|
const g = h({
|
|
513
513
|
display: "flex",
|
|
514
514
|
flexWrap: "wrap",
|
|
@@ -522,14 +522,14 @@ function cn(n, o) {
|
|
|
522
522
|
minHeight: "36px",
|
|
523
523
|
padding: "6px 14px",
|
|
524
524
|
fontSize: "14px",
|
|
525
|
-
borderRadius:
|
|
525
|
+
borderRadius: Oe,
|
|
526
526
|
border: `1px solid ${L}`,
|
|
527
527
|
backgroundColor: ee,
|
|
528
528
|
color: J,
|
|
529
529
|
cursor: m ? "pointer" : "default",
|
|
530
530
|
transition: "border-color 0.15s"
|
|
531
531
|
}), x && c.addEventListener("click", () => x(s)), c.addEventListener("mouseenter", () => {
|
|
532
|
-
c.style.borderColor =
|
|
532
|
+
c.style.borderColor = Me;
|
|
533
533
|
}), c.addEventListener("mouseleave", () => {
|
|
534
534
|
c.style.borderColor = L;
|
|
535
535
|
}), g.appendChild(c);
|
|
@@ -546,7 +546,7 @@ function pn(n) {
|
|
|
546
546
|
padding: "10px 14px",
|
|
547
547
|
backgroundColor: "#f0fdf4",
|
|
548
548
|
color: "#15803d",
|
|
549
|
-
borderRadius:
|
|
549
|
+
borderRadius: Oe,
|
|
550
550
|
marginTop: "8px",
|
|
551
551
|
fontSize: "13px",
|
|
552
552
|
border: "1px solid #bbf7d0"
|
|
@@ -582,7 +582,7 @@ function un() {
|
|
|
582
582
|
const i = document.createElementNS(n, "path");
|
|
583
583
|
return i.setAttribute("d", "M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"), i.setAttribute("stroke", "currentColor"), i.setAttribute("stroke-width", "2"), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), o.appendChild(i), o;
|
|
584
584
|
}
|
|
585
|
-
var
|
|
585
|
+
var mt = "Form submitted.";
|
|
586
586
|
function mn(n) {
|
|
587
587
|
if (typeof n == "string") return n || null;
|
|
588
588
|
if (!n || typeof n != "object") return null;
|
|
@@ -603,23 +603,23 @@ function hn(n) {
|
|
|
603
603
|
return o;
|
|
604
604
|
}
|
|
605
605
|
function wn(n, o) {
|
|
606
|
-
const { title: i = "Chat", welcomeMessage: r = "Hello! How can I help you today?", placeholder: b = "Type a message...", allowFiles: a = !1, height: C = 500, placement: m = "inline", width: x = 400, defaultOpen: p = !1, logoUrl: f, showAgentName: A = !1, agentBubble: R = !1, bubbleStyle: _ = "default", showHeader: Y = !0, theme: D, loadThreads: g = !1, forms: s, formSubmittedMessage: c =
|
|
606
|
+
const { title: i = "Chat", welcomeMessage: r = "Hello! How can I help you today?", placeholder: b = "Type a message...", allowFiles: a = !1, height: C = 500, placement: m = "inline", width: x = 400, defaultOpen: p = !1, logoUrl: f, showAgentName: A = !1, agentBubble: R = !1, bubbleStyle: _ = "default", showHeader: Y = !0, theme: D, loadThreads: g = !1, forms: s, formSubmittedMessage: c = mt, onFollowUpClick: y, onMessageSent: T, onMessageReceived: k, onFormSubmitted: V, onFormError: j, onOpen: B, onClose: q } = o, ne = typeof r == "string" ? {
|
|
607
607
|
message: r,
|
|
608
608
|
mode: "static"
|
|
609
|
-
} : r,
|
|
609
|
+
} : r, Fe = ne.message, He = ne.mode ?? "static", Ct = "speed" in ne && ne.speed || 45, Pe = "followUpReplies" in ne && ne.followUpReplies || void 0;
|
|
610
610
|
if (!o.client && !o.config?.baseUrl) throw new Gt("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
|
|
611
|
-
const E = o.client ?? new qt(o.config),
|
|
611
|
+
const E = o.client ?? new qt(o.config), Ue = hn(n), z = m === "left" || m === "right", Et = z && (o.launcher ?? !0);
|
|
612
612
|
let oe = z ? p : !0;
|
|
613
|
-
const
|
|
613
|
+
const St = o.mobile?.breakpoint ?? 768, _e = o.mobile?.trigger ?? "tap", We = typeof window < "u" && !!window.matchMedia, M = We ? window.matchMedia(`(max-width: ${St}px)`) : void 0, Rt = We ? window.matchMedia("(prefers-reduced-motion: reduce)") : void 0, re = !z && !!M, Ie = o.persistConversation, me = Ie ? Qt(Ie === !0 ? {} : Ie) : void 0;
|
|
614
614
|
let P = o.conversationId ?? me?.getLastActiveThread() ?? void 0, u = [], Z = !1, le = null, K;
|
|
615
|
-
const
|
|
615
|
+
const Ge = [];
|
|
616
616
|
function kt(e) {
|
|
617
617
|
if (typeof c == "function") {
|
|
618
618
|
const l = c(e);
|
|
619
619
|
if (typeof l == "string" && l) return l;
|
|
620
620
|
}
|
|
621
621
|
const t = mn(e);
|
|
622
|
-
return t || (typeof c == "string" ? c :
|
|
622
|
+
return t || (typeof c == "string" ? c : mt);
|
|
623
623
|
}
|
|
624
624
|
const ge = [], d = h({
|
|
625
625
|
display: "flex",
|
|
@@ -640,7 +640,7 @@ function wn(n, o) {
|
|
|
640
640
|
padding: "14px 16px",
|
|
641
641
|
borderBottom: `1px solid ${L}`,
|
|
642
642
|
backgroundColor: Zt,
|
|
643
|
-
color:
|
|
643
|
+
color: ct,
|
|
644
644
|
display: "flex",
|
|
645
645
|
alignItems: "center",
|
|
646
646
|
gap: "10px"
|
|
@@ -662,29 +662,29 @@ function wn(n, o) {
|
|
|
662
662
|
marginLeft: "auto",
|
|
663
663
|
background: "transparent",
|
|
664
664
|
border: "none",
|
|
665
|
-
color:
|
|
665
|
+
color: ct,
|
|
666
666
|
fontSize: "22px",
|
|
667
667
|
lineHeight: "1",
|
|
668
668
|
cursor: "pointer",
|
|
669
669
|
padding: "0 2px"
|
|
670
|
-
}), t.addEventListener("click", () =>
|
|
670
|
+
}), t.addEventListener("click", () => Be()), F.appendChild(t);
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
673
|
const I = h({
|
|
674
674
|
flex: "1",
|
|
675
675
|
overflow: "auto",
|
|
676
676
|
padding: "16px",
|
|
677
|
-
backgroundColor:
|
|
677
|
+
backgroundColor: gt
|
|
678
678
|
});
|
|
679
679
|
I.className = "ago-chat-widget__messages", I.setAttribute("role", "log"), I.setAttribute("aria-live", "polite"), I.setAttribute("aria-relevant", "additions text"), I.setAttribute("aria-atomic", "false");
|
|
680
|
-
const { inputRow:
|
|
680
|
+
const { inputRow: $e, setDisabled: At, focus: he } = on({
|
|
681
681
|
placeholder: b,
|
|
682
682
|
allowFiles: a,
|
|
683
683
|
onSend: (e, t) => {
|
|
684
684
|
ye(e, t);
|
|
685
685
|
}
|
|
686
686
|
});
|
|
687
|
-
nn(), d.append(...F ? [F] : [], I,
|
|
687
|
+
nn(), d.append(...F ? [F] : [], I, $e);
|
|
688
688
|
let xe = d, U, N;
|
|
689
689
|
const be = m === "left" ? "left" : "right";
|
|
690
690
|
if (z && (U = h({
|
|
@@ -705,7 +705,7 @@ function wn(n, o) {
|
|
|
705
705
|
border: "none",
|
|
706
706
|
boxShadow: "none",
|
|
707
707
|
[be === "left" ? "borderRight" : "borderLeft"]: `1px solid ${L}`
|
|
708
|
-
}), U.appendChild(d), xe = U),
|
|
708
|
+
}), U.appendChild(d), xe = U), Et) {
|
|
709
709
|
if (N = document.createElement("button"), N.type = "button", N.className = "ago-chat-widget-launcher", N.setAttribute("aria-label", `Open ${i}`), v(N, {
|
|
710
710
|
position: "fixed",
|
|
711
711
|
bottom: "20px",
|
|
@@ -731,9 +731,9 @@ function wn(n, o) {
|
|
|
731
731
|
objectFit: "contain"
|
|
732
732
|
}), N.appendChild(e);
|
|
733
733
|
} else N.appendChild(un());
|
|
734
|
-
N.addEventListener("click", () =>
|
|
734
|
+
N.addEventListener("click", () => Te());
|
|
735
735
|
}
|
|
736
|
-
const de = re ? `ago-vt-${++gn}` : "",
|
|
736
|
+
const de = re ? `ago-vt-${++gn}` : "", Ve = 52;
|
|
737
737
|
let W = !1, ce = 0, ie = 0, H, pe, X;
|
|
738
738
|
const ve = {
|
|
739
739
|
height: d.style.height,
|
|
@@ -741,25 +741,30 @@ function wn(n, o) {
|
|
|
741
741
|
borderRadius: d.style.borderRadius,
|
|
742
742
|
boxShadow: d.style.boxShadow
|
|
743
743
|
};
|
|
744
|
-
|
|
745
|
-
W || !M?.matches
|
|
744
|
+
Ue.appendChild(xe), N && Ue.appendChild(N), we(), re && (H = Ft(), d.insertBefore(H, d.firstChild), pe = document.createElement("style"), pe.id = de, pe.textContent = `::view-transition-group(${de}),::view-transition-group(${de}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`, document.head.appendChild(pe), (_e === "focus" || _e === "tap") && (d.addEventListener("pointerdown", (e) => {
|
|
745
|
+
if (W || !M?.matches) return;
|
|
746
|
+
const t = $e.contains(e.target);
|
|
747
|
+
if (_e === "tap") {
|
|
748
|
+
if ((e.target instanceof Element ? e.target : null)?.closest("button,a[href],[role='button']")) return;
|
|
749
|
+
} else if (!t) return;
|
|
750
|
+
t && e.preventDefault(), fe();
|
|
746
751
|
}, !0), d.addEventListener("focusin", (e) => {
|
|
747
|
-
M?.matches &&
|
|
748
|
-
})), document.addEventListener("keydown",
|
|
752
|
+
M?.matches && $e.contains(e.target) && fe();
|
|
753
|
+
})), document.addEventListener("keydown", tt)), M && M.addEventListener("change", nt);
|
|
749
754
|
const _t = y !== !1, It = y === !1 ? void 0 : y ?? ((e) => {
|
|
750
755
|
re && M?.matches && !W ? fe().then(() => ye(e)) : ye(e);
|
|
751
756
|
});
|
|
752
757
|
function $() {
|
|
753
758
|
if (I.replaceChildren(), u.length === 0) {
|
|
754
|
-
if (
|
|
759
|
+
if (He === "static") {
|
|
755
760
|
const t = h({
|
|
756
761
|
textAlign: "center",
|
|
757
|
-
color:
|
|
762
|
+
color: ht,
|
|
758
763
|
padding: "24px 16px",
|
|
759
764
|
fontSize: "16px",
|
|
760
765
|
lineHeight: "1.5"
|
|
761
766
|
});
|
|
762
|
-
t.appendChild(
|
|
767
|
+
t.appendChild(ze(Fe)), I.appendChild(t);
|
|
763
768
|
}
|
|
764
769
|
} else u.forEach((t, l) => {
|
|
765
770
|
const S = l === u.length - 1 || u[l + 1].role !== t.role;
|
|
@@ -774,7 +779,7 @@ function wn(n, o) {
|
|
|
774
779
|
isMobile: !!M?.matches
|
|
775
780
|
}));
|
|
776
781
|
});
|
|
777
|
-
for (const t of
|
|
782
|
+
for (const t of Ge) I.appendChild(pn(t));
|
|
778
783
|
if (le) {
|
|
779
784
|
const t = h({
|
|
780
785
|
padding: "10px 14px",
|
|
@@ -797,21 +802,21 @@ function wn(n, o) {
|
|
|
797
802
|
if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
|
|
798
803
|
}
|
|
799
804
|
}
|
|
800
|
-
const
|
|
805
|
+
const je = (e) => {
|
|
801
806
|
P || (P = e.conversationId);
|
|
802
|
-
},
|
|
807
|
+
}, qe = (e) => {
|
|
803
808
|
const t = $t();
|
|
804
809
|
t && (t.content += e.content, $());
|
|
805
|
-
},
|
|
810
|
+
}, Ke = (e) => {
|
|
806
811
|
const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
|
|
807
812
|
t >= 0 ? u[t] = e : u.push(e), $(), he();
|
|
808
|
-
},
|
|
813
|
+
}, Xe = (e) => {
|
|
809
814
|
const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
|
|
810
815
|
t >= 0 ? u[t] = e : u.push(e), Z = !1, $(), e.status === "DONE" && k?.({
|
|
811
816
|
id: e.id,
|
|
812
817
|
content: e.content
|
|
813
818
|
});
|
|
814
|
-
},
|
|
819
|
+
}, Qe = (e) => {
|
|
815
820
|
le = e.error, Z = !1, u = u.filter((t) => !t.id.startsWith("temp-")), $();
|
|
816
821
|
};
|
|
817
822
|
function Lt(e) {
|
|
@@ -828,27 +833,27 @@ function wn(n, o) {
|
|
|
828
833
|
let S = 0;
|
|
829
834
|
K = setInterval(() => {
|
|
830
835
|
if (S >= l.length) {
|
|
831
|
-
clearInterval(K), K = void 0, t.status = "DONE",
|
|
836
|
+
clearInterval(K), K = void 0, t.status = "DONE", Pe && (t.followUpReplies = Pe), $();
|
|
832
837
|
return;
|
|
833
838
|
}
|
|
834
839
|
t.content += l[S], S++, $();
|
|
835
|
-
},
|
|
840
|
+
}, Ct);
|
|
836
841
|
}
|
|
837
|
-
E.on("message:start",
|
|
838
|
-
const
|
|
839
|
-
V && E.on("form:submitted",
|
|
840
|
-
const
|
|
841
|
-
let
|
|
842
|
-
const
|
|
843
|
-
if (
|
|
844
|
-
|
|
842
|
+
E.on("message:start", je), E.on("message:chunk", qe), E.on("message:answer-complete", Ke), E.on("message:complete", Xe), E.on("message:error", Qe);
|
|
843
|
+
const Ye = (e) => V?.(e), Ze = (e) => j?.(e);
|
|
844
|
+
V && E.on("form:submitted", Ye), j && E.on("form:error", Ze);
|
|
845
|
+
const Le = [];
|
|
846
|
+
let Je = !1;
|
|
847
|
+
const et = (e) => {
|
|
848
|
+
if (Je) return;
|
|
849
|
+
Le.push(e.install(E));
|
|
845
850
|
let t = e.store.get().submitted;
|
|
846
851
|
const l = e.store.subscribe((S) => {
|
|
847
|
-
S.submitted && !t && (
|
|
852
|
+
S.submitted && !t && (Ge.push(kt(S.submitResult)), $()), t = S.submitted;
|
|
848
853
|
});
|
|
849
|
-
|
|
854
|
+
Le.push(l);
|
|
850
855
|
};
|
|
851
|
-
for (const e of s ?? []) e.schema != null ?
|
|
856
|
+
for (const e of s ?? []) e.schema != null ? et(Xt(e)) : Kt(E, e).then((t) => et(t)).catch(() => {
|
|
852
857
|
});
|
|
853
858
|
async function ye(e, t) {
|
|
854
859
|
const l = e.trim();
|
|
@@ -886,12 +891,12 @@ function wn(n, o) {
|
|
|
886
891
|
const Q = u.findIndex((Pt) => Pt.id === `temp-assistant-${S}`);
|
|
887
892
|
Q >= 0 ? u[Q] = w : u.push(w);
|
|
888
893
|
}
|
|
889
|
-
u = u.filter((Q) => !Q.id.startsWith("temp-")), Z = !1, $(), g &&
|
|
894
|
+
u = u.filter((Q) => !Q.id.startsWith("temp-")), Z = !1, $(), g && Ne();
|
|
890
895
|
} catch (w) {
|
|
891
896
|
le = w instanceof Error ? w.message : "Failed to send message", Z = !1, u = u.filter((G) => !G.id.startsWith("temp-")), $();
|
|
892
897
|
}
|
|
893
898
|
}
|
|
894
|
-
async function
|
|
899
|
+
async function Ne() {
|
|
895
900
|
try {
|
|
896
901
|
const e = await E.getConversations();
|
|
897
902
|
ge.splice(0, ge.length, ...e);
|
|
@@ -907,7 +912,7 @@ function wn(n, o) {
|
|
|
907
912
|
u.length === 0 && (me?.clear(), P = void 0);
|
|
908
913
|
}
|
|
909
914
|
}
|
|
910
|
-
return $(), re && M?.matches || he(), P ? Nt(P) :
|
|
915
|
+
return $(), re && M?.matches || he(), P ? Nt(P) : He === "streaming" && Lt(Fe), g && Ne(), {
|
|
911
916
|
client: E,
|
|
912
917
|
element: xe,
|
|
913
918
|
sendMessage: ye,
|
|
@@ -918,9 +923,9 @@ function wn(n, o) {
|
|
|
918
923
|
} : {},
|
|
919
924
|
session: me,
|
|
920
925
|
threads: ge,
|
|
921
|
-
refreshThreads:
|
|
926
|
+
refreshThreads: Ne,
|
|
922
927
|
destroy() {
|
|
923
|
-
K && clearInterval(K), E.off("message:start",
|
|
928
|
+
K && clearInterval(K), E.off("message:start", je), E.off("message:chunk", qe), E.off("message:answer-complete", Ke), E.off("message:complete", Xe), E.off("message:error", Qe), V && E.off("form:submitted", Ye), j && E.off("form:error", Ze), Je = !0, Le.forEach((e) => e()), xe.remove(), N?.remove(), H?.remove(), pe?.remove(), X?.remove(), M?.removeEventListener("change", nt), re && (document.removeEventListener("keydown", tt), it(), document.documentElement.style.removeProperty("overflow")), o.client || E.destroy();
|
|
924
929
|
}
|
|
925
930
|
};
|
|
926
931
|
function we() {
|
|
@@ -932,20 +937,20 @@ function wn(n, o) {
|
|
|
932
937
|
const e = m === "left" ? "translateX(-100%)" : "translateX(100%)";
|
|
933
938
|
U.style.transform = oe ? "translateX(0)" : e, U.setAttribute("aria-hidden", oe ? "false" : "true"), N && (N.style.display = oe ? "none" : "flex");
|
|
934
939
|
}
|
|
935
|
-
function
|
|
940
|
+
function Te() {
|
|
936
941
|
oe = !0, we(), he(), B?.();
|
|
937
942
|
}
|
|
938
|
-
function
|
|
943
|
+
function Be() {
|
|
939
944
|
oe = !1, we(), q?.();
|
|
940
945
|
}
|
|
941
946
|
function Tt() {
|
|
942
|
-
oe ?
|
|
947
|
+
oe ? Be() : Te();
|
|
943
948
|
}
|
|
944
949
|
function Bt() {
|
|
945
|
-
z ?
|
|
950
|
+
z ? Te() : fe();
|
|
946
951
|
}
|
|
947
952
|
function Mt() {
|
|
948
|
-
z ?
|
|
953
|
+
z ? Be() : ue();
|
|
949
954
|
}
|
|
950
955
|
function Ot() {
|
|
951
956
|
z ? Tt() : W ? ue() : fe();
|
|
@@ -953,7 +958,7 @@ function wn(n, o) {
|
|
|
953
958
|
function Dt() {
|
|
954
959
|
return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter((e) => e.getClientRects().length > 0);
|
|
955
960
|
}
|
|
956
|
-
function
|
|
961
|
+
function tt(e) {
|
|
957
962
|
if (!W) return;
|
|
958
963
|
if (e.key === "Escape") {
|
|
959
964
|
ue();
|
|
@@ -968,28 +973,28 @@ function wn(n, o) {
|
|
|
968
973
|
const l = t[0], S = t[t.length - 1], w = document.activeElement;
|
|
969
974
|
e.shiftKey && (w === l || !d.contains(w)) ? (e.preventDefault(), S.focus()) : !e.shiftKey && (w === S || !d.contains(w)) && (e.preventDefault(), l.focus());
|
|
970
975
|
}
|
|
971
|
-
function
|
|
976
|
+
function nt(e) {
|
|
972
977
|
z ? we() : !e.matches && W && ue(), $();
|
|
973
978
|
}
|
|
974
|
-
function
|
|
979
|
+
function ot() {
|
|
975
980
|
return window.visualViewport?.height ?? window.innerHeight;
|
|
976
981
|
}
|
|
977
|
-
function
|
|
982
|
+
function rt() {
|
|
978
983
|
const e = window.visualViewport, t = e?.offsetTop ?? 0, l = e?.height ?? ce, S = Math.min(0, t + l - ce);
|
|
979
984
|
d.style.top = `${S}px`, H && (H.style.top = `${t}px`);
|
|
980
985
|
}
|
|
981
986
|
function Ce() {
|
|
982
987
|
ie || (ie = requestAnimationFrame(() => {
|
|
983
|
-
ie = 0,
|
|
988
|
+
ie = 0, rt();
|
|
984
989
|
}));
|
|
985
990
|
}
|
|
986
991
|
function zt() {
|
|
987
992
|
window.visualViewport?.addEventListener("resize", Ce), window.visualViewport?.addEventListener("scroll", Ce);
|
|
988
993
|
}
|
|
989
|
-
function
|
|
994
|
+
function it() {
|
|
990
995
|
window.visualViewport?.removeEventListener("resize", Ce), window.visualViewport?.removeEventListener("scroll", Ce), ie && (cancelAnimationFrame(ie), ie = 0);
|
|
991
996
|
}
|
|
992
|
-
function
|
|
997
|
+
function at() {
|
|
993
998
|
I.scrollTop = I.scrollHeight;
|
|
994
999
|
}
|
|
995
1000
|
function Ft() {
|
|
@@ -998,7 +1003,7 @@ function wn(n, o) {
|
|
|
998
1003
|
top: "0",
|
|
999
1004
|
left: "0",
|
|
1000
1005
|
right: "0",
|
|
1001
|
-
height: `calc(${
|
|
1006
|
+
height: `calc(${Ve}px + env(safe-area-inset-top))`,
|
|
1002
1007
|
display: "none",
|
|
1003
1008
|
alignItems: "center",
|
|
1004
1009
|
justifyContent: "space-between",
|
|
@@ -1041,7 +1046,7 @@ function wn(n, o) {
|
|
|
1041
1046
|
function Ht() {
|
|
1042
1047
|
return typeof document.startViewTransition == "function" && !Rt?.matches && !!M?.matches;
|
|
1043
1048
|
}
|
|
1044
|
-
function
|
|
1049
|
+
function st(e) {
|
|
1045
1050
|
const t = document;
|
|
1046
1051
|
if (Ht() && t.startViewTransition) {
|
|
1047
1052
|
d.style.setProperty("view-transition-name", de), H?.style.setProperty("view-transition-name", `${de}-bar`);
|
|
@@ -1052,7 +1057,7 @@ function wn(n, o) {
|
|
|
1052
1057
|
}
|
|
1053
1058
|
return e(), Promise.resolve();
|
|
1054
1059
|
}
|
|
1055
|
-
function
|
|
1060
|
+
function lt(e) {
|
|
1056
1061
|
if (e)
|
|
1057
1062
|
X && d.parentElement?.insertBefore(X, d), v(d, {
|
|
1058
1063
|
position: "fixed",
|
|
@@ -1065,7 +1070,7 @@ function wn(n, o) {
|
|
|
1065
1070
|
border: "none",
|
|
1066
1071
|
borderRadius: "0",
|
|
1067
1072
|
boxShadow: "none",
|
|
1068
|
-
paddingTop: `calc(${
|
|
1073
|
+
paddingTop: `calc(${Ve}px + env(safe-area-inset-top))`,
|
|
1069
1074
|
paddingBottom: "env(safe-area-inset-bottom)"
|
|
1070
1075
|
}), d.setAttribute("role", "dialog"), d.setAttribute("aria-modal", "true"), d.setAttribute("aria-label", i), document.documentElement.style.overflow = "hidden", F && (F.style.display = "none"), H && (H.style.display = "flex");
|
|
1071
1076
|
else {
|
|
@@ -1086,24 +1091,24 @@ function wn(n, o) {
|
|
|
1086
1091
|
function fe() {
|
|
1087
1092
|
if (W || !M?.matches) return Promise.resolve();
|
|
1088
1093
|
const e = d.getBoundingClientRect();
|
|
1089
|
-
if (e.height >=
|
|
1094
|
+
if (e.height >= ot() * 0.8) return Promise.resolve();
|
|
1090
1095
|
W = !0, X = h({
|
|
1091
1096
|
width: `${e.width}px`,
|
|
1092
1097
|
height: `${e.height}px`
|
|
1093
|
-
}), X.className = "ago-chat-widget-spacer", X.setAttribute("aria-hidden", "true"), ce =
|
|
1094
|
-
const t =
|
|
1098
|
+
}), X.className = "ago-chat-widget-spacer", X.setAttribute("aria-hidden", "true"), ce = ot(), d.style.setProperty("--ago-vh", `${ce}px`), rt(), zt();
|
|
1099
|
+
const t = st(() => lt(!0));
|
|
1095
1100
|
return t.then(() => {
|
|
1096
|
-
|
|
1097
|
-
}),
|
|
1101
|
+
at(), he();
|
|
1102
|
+
}), at(), B?.(), t;
|
|
1098
1103
|
}
|
|
1099
1104
|
function ue() {
|
|
1100
1105
|
if (!W) return Promise.resolve();
|
|
1101
|
-
W = !1,
|
|
1102
|
-
const e =
|
|
1106
|
+
W = !1, it(), d.querySelector("textarea")?.blur();
|
|
1107
|
+
const e = st(() => lt(!1));
|
|
1103
1108
|
return e.then(() => d.style.removeProperty("--ago-vh")), ce = 0, q?.(), e;
|
|
1104
1109
|
}
|
|
1105
1110
|
}
|
|
1106
1111
|
export {
|
|
1107
1112
|
wn as mountChatWidget,
|
|
1108
|
-
|
|
1113
|
+
ze as renderMarkdown
|
|
1109
1114
|
};
|
package/package.json
CHANGED