@useago/sdk 1.0.11 → 1.2.0

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 CHANGED
@@ -1,5 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ge=require("./AgoClient-B3-WGVne.cjs"),je=require("./createFormCollector-BI3DXaew.cjs"),xt=require("./createConversationSession-C0diFTUk.cjs");var bt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function K(r){return r.replace(/[&<>"']/g,o=>bt[o])}function qe(r){const o=r.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var Je='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',le="";function P(r){const o=[],a=u=>(o.push(u),`${le}${o.length-1}${le}`);let n=r;return n=n.replace(/`([^`]+)`/g,(u,i)=>a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Je}">${K(i)}</code>`)),n=n.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(u,i,v)=>{const p=qe(v);return p?a(`<img alt="${K(i)}" src="${K(p)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):u}),n=n.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(u,i,v)=>{const p=qe(v);return p?a(`<a href="${K(p)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${P(i)}</a>`):u}),n=K(n),n=n.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>"),n=n.replace(new RegExp(`${le}(\\d+)${le}`,"g"),(u,i)=>o[Number(i)]),n}function N(r,o,a){const n=document.createElement(r);return Object.assign(n.style,o),a!==void 0&&(n.innerHTML=a),n}var et=/^ {0,3}([-*_])( *\1){2,} *$/,tt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,nt=/^ {0,3}(```+|~~~+)/,ce=/^ {0,3}>\s?/,V=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,vt=["20px","18px","16px","15px","14px","13px"],Re=r=>r.match(/^\s*/)?.[0].length??0;function Ct(r){return r.trim()===""||et.test(r)||tt.test(r)||nt.test(r)||ce.test(r)||V.test(r)}function ot(r){const o=r[0].match(V),a=o[1].length,n=/\d/.test(o[2]),u=N(n?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:n?"decimal":"disc",listStylePosition:"outside"});let i=0;for(;i<r.length;){const v=r[i].match(V),p=[];for(i++;i<r.length&&Re(r[i])>a;)p.push(r[i]),i++;const b=N("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),d=v[3].match(/^\[([ xX])\]\s+(.*)$/);d?(b.style.listStyleType="none",b.style.marginLeft="-20px",b.innerHTML=`<span style="margin-right:6px">${d[1].toLowerCase()==="x"?"☑":"☐"}</span>${P(d[2])}`):b.innerHTML=P(v[3]),p.filter(g=>V.test(g)).length>0&&b.appendChild(ot(p.filter(g=>g.trim()!==""))),u.appendChild(b)}return u}function yt(r){const o=p=>p.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(b=>b.trim()),a=N("div",{overflowX:"auto",margin:"0 0 8px 0"}),n=N("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),u=document.createElement("thead"),i=document.createElement("tr");for(const p of o(r[0]))i.appendChild(N("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},P(p)));u.appendChild(i),n.appendChild(u);const v=document.createElement("tbody");for(const p of r.slice(2)){const b=document.createElement("tr");for(const d of o(p))b.appendChild(N("td",{border:"1px solid #dee3e8",padding:"6px 10px"},P(d)));v.appendChild(b)}return n.appendChild(v),a.appendChild(n),a}var wt=r=>!!r&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(r);function fe(r){const o=document.createDocumentFragment(),a=r.replace(/\r\n?/g,`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const oe=require("./AgoClient-CzSmJQxl.cjs"),rt=require("./createFormCollector-BB3Uscuo.cjs"),zt=require("./createConversationSession-DV0Xp_3O.cjs");var Ht='"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',we=`var(--ago-font, ${Ht})`,it={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"},Ee="var(--ago-brand-color, #03182f)",Se="var(--ago-brand-text-color, #fff)",Ft="var(--ago-header-background, var(--ago-brand-color, #03182f))",at="var(--ago-header-text-color, #e8f0fe)",J="var(--ago-panel-background, #fff)",pt="var(--ago-messages-background, #fbfbfb)",Z="var(--ago-text-color, #30373e)",ft="var(--ago-muted-text-color, #6b6d6f)",$="var(--ago-border-color, #dee3e8)",Ne="var(--ago-accent-color, #1b5fc4)",st="var(--ago-agent-bubble-background, #f1f3f5)",Pt="var(--ago-radius, 16px)",Te="var(--ago-message-radius, 16px)",Wt="var(--ago-message-radius, 20px)";function Ut(t,o){if(o)for(const i of Object.keys(it)){const r=o[i];r!=null&&t.style.setProperty(it[i],r)}}function y(t,o){Object.assign(t.style,o)}function x(t={}){const o=document.createElement("div");return y(o,t),o}var lt="ago-chat-widget-keyframes";function Gt(){if(typeof document>"u"||document.getElementById(lt))return;const t=document.createElement("style");t.id=lt,t.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(t)}function jt(t){let o=[];const i=document.createElement("form");y(i,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${$}`,backgroundColor:J}),i.className="ago-chat-input";const r=x({display:"flex",flexWrap:"wrap",gap:"6px"}),v=x({display:"flex",gap:"8px",alignItems:"flex-end"}),a=document.createElement("textarea");a.placeholder=t.placeholder,a.setAttribute("aria-label",t.placeholder),a.rows=1,y(a,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",fontSize:"16px",fontFamily:we,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const C=()=>{a.style.height="auto";const f=Math.min(a.scrollHeight+2,110);a.style.height=`${f}px`,a.style.overflowY=a.scrollHeight+2>110?"auto":"hidden"};a.addEventListener("input",()=>{C(),R()});const u='<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>',b='<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>',s=document.createElement("button");s.type="submit",s.setAttribute("aria-label","Send"),s.innerHTML=u,y(s,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:Ee,color:Se,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let m=!1;const R=()=>{const l=a.value.trim()!==""||o.length>0,f=m||!l;s.disabled=f,s.innerHTML=m?b:u,s.style.opacity=f&&!m?"0.5":"1",s.style.cursor=f?"default":"pointer"};let k=null,T=null;t.allowFiles&&(k=document.createElement("input"),k.type="file",k.multiple=!0,y(k,{display:"none"}),T=document.createElement("button"),T.type="button",T.setAttribute("aria-label","Attach file"),T.textContent="📎",y(T,{padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",backgroundColor:J,cursor:"pointer",fontSize:"14px"}),T.addEventListener("click",()=>k?.click()),k.addEventListener("change",()=>{o=[...o,...Array.from(k?.files??[])],O()}));function O(){r.replaceChildren(),o.forEach((l,f)=>{const I=x({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${$}`,borderRadius:"8px",fontSize:"12px"}),B=document.createElement("span");B.textContent=l.name;const M=document.createElement("button");M.type="button",M.setAttribute("aria-label",`Remove ${l.name}`),M.textContent="×",y(M,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),M.addEventListener("click",()=>{o=o.filter((Q,_)=>_!==f),O()}),I.append(B,M),r.appendChild(I)}),R()}const g=()=>{const l=a.value,f=o;return a.value="",C(),o=[],O(),{content:l,files:f}},h=()=>{const{content:l,files:f}=g();(l.trim()||f.length>0)&&t.onSend(l.trim(),f.length>0?f:void 0)};return i.addEventListener("submit",l=>{l.preventDefault(),h()}),a.addEventListener("keydown",l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),h())}),T&&v.appendChild(T),v.append(a,s),k&&i.appendChild(k),i.append(r,v),R(),{inputRow:i,getValueAndClear:g,setDisabled:l=>{a.disabled=l,m=l,R()},focus:()=>a.focus()}}var qt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function ne(t){return t.replace(/[&<>"']/g,o=>qt[o])}function dt(t){const o=t.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var ut='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',ye="";function ee(t){const o=[],i=v=>(o.push(v),`${ye}${o.length-1}${ye}`);let r=t;return r=r.replace(/`([^`]+)`/g,(v,a)=>i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ut}">${ne(a)}</code>`)),r=r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(v,a,C)=>{const u=dt(C);return u?i(`<img alt="${ne(a)}" src="${ne(u)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):v}),r=r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(v,a,C)=>{const u=dt(C);return u?i(`<a href="${ne(u)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${ee(a)}</a>`):v}),r=ne(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(`${ye}(\\d+)${ye}`,"g"),(v,a)=>o[Number(a)]),r}function D(t,o,i){const r=document.createElement(t);return Object.assign(r.style,o),i!==void 0&&(r.innerHTML=i),r}var mt=/^ {0,3}([-*_])( *\1){2,} *$/,gt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,ht=/^ {0,3}(```+|~~~+)/,Ce=/^ {0,3}>\s?/,re=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Vt=["20px","18px","16px","15px","14px","13px"],Oe=t=>t.match(/^\s*/)?.[0].length??0;function Kt(t){return t.trim()===""||mt.test(t)||gt.test(t)||ht.test(t)||Ce.test(t)||re.test(t)}function xt(t){const o=t[0].match(re),i=o[1].length,r=/\d/.test(o[2]),v=D(r?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:r?"decimal":"disc",listStylePosition:"outside"});let a=0;for(;a<t.length;){const C=t[a].match(re),u=[];for(a++;a<t.length&&Oe(t[a])>i;)u.push(t[a]),a++;const b=D("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),s=C[3].match(/^\[([ xX])\]\s+(.*)$/);s?(b.style.listStyleType="none",b.style.marginLeft="-20px",b.innerHTML=`<span style="margin-right:6px">${s[1].toLowerCase()==="x"?"☑":"☐"}</span>${ee(s[2])}`):b.innerHTML=ee(C[3]),u.filter(m=>re.test(m)).length>0&&b.appendChild(xt(u.filter(m=>m.trim()!==""))),v.appendChild(b)}return v}function Xt(t){const o=u=>u.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(b=>b.trim()),i=D("div",{overflowX:"auto",margin:"0 0 8px 0"}),r=D("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),v=document.createElement("thead"),a=document.createElement("tr");for(const u of o(t[0]))a.appendChild(D("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},ee(u)));v.appendChild(a),r.appendChild(v);const C=document.createElement("tbody");for(const u of t.slice(2)){const b=document.createElement("tr");for(const s of o(u))b.appendChild(D("td",{border:"1px solid #dee3e8",padding:"6px 10px"},ee(s)));C.appendChild(b)}return r.appendChild(C),i.appendChild(r),i}var Qt=t=>!!t&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(t);function Re(t){const o=document.createDocumentFragment(),i=t.replace(/\r\n?/g,`
2
2
  `).split(`
3
- `);let n=0;for(;n<a.length;){const i=a[n];if(i.trim()===""){n++;continue}const v=i.match(nt);if(v){const d=v[1][0],g=[];for(n++;n<a.length&&!new RegExp(`^ {0,3}${d==="`"?"`{3,}":"~{3,}"}\\s*$`).test(a[n]);)g.push(a[n]),n++;n++;const M=N("pre",{margin:"0 0 8px 0"});M.appendChild(N("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:Je,whiteSpace:"pre"},K(g.join(`
4
- `)))),o.appendChild(M);continue}if(et.test(i)){o.appendChild(N("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),n++;continue}const p=i.match(tt);if(p){const d=p[1].length;o.appendChild(N(`h${d}`,{margin:"16px 0 8px 0",fontSize:vt[d-1],fontWeight:"600",lineHeight:"1.3"},P(p[2]))),n++;continue}if(ce.test(i)){const d=[];for(;n<a.length&&ce.test(a[n]);)d.push(a[n].replace(ce,"")),n++;const g=N("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});g.appendChild(fe(d.join(`
5
- `))),o.appendChild(g);continue}if(i.includes("|")&&wt(a[n+1])){const d=[i,a[n+1]];for(n+=2;n<a.length&&a[n].includes("|")&&a[n].trim();)d.push(a[n]),n++;o.appendChild(yt(d));continue}if(V.test(i)){const d=[],g=Re(i);for(;n<a.length&&a[n].trim()!=="";)if(V.test(a[n])||Re(a[n])>g)d.push(a[n]),n++;else break;o.appendChild(ot(d));continue}const b=[i];for(n++;n<a.length&&!Ct(a[n]);)b.push(a[n]),n++;o.appendChild(N("p",{margin:"0 0 8px 0",lineHeight:"1.6"},b.map(d=>P(d)).join("<br>")))}const u=o.lastElementChild;return u&&(u.style.marginBottom="0"),o}var _e='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Xe={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"},pe="var(--ago-brand-color, #03182f)",ke="var(--ago-brand-text-color, #fff)",Et="var(--ago-header-background, var(--ago-brand-color, #03182f))",Ke="var(--ago-header-text-color, #e8f0fe)",ee="var(--ago-panel-background, #fff)",Ve="var(--ago-messages-background, #fbfbfb)",de="var(--ago-text-color, #30373e)",St="var(--ago-muted-text-color, #6b6d6f)",O="var(--ago-border-color, #dee3e8)",Ee="var(--ago-accent-color, #1b5fc4)",Ye="var(--ago-agent-bubble-background, #f1f3f5)",Rt="var(--ago-radius, 16px)",Se="var(--ago-message-radius, 16px)",_t="var(--ago-message-radius, 20px)";function kt(r,o){if(o)for(const a of Object.keys(Xe)){const n=o[a];n!=null&&r.style.setProperty(Xe[a],n)}}function E(r,o){Object.assign(r.style,o)}function x(r={}){const o=document.createElement("div");return E(o,r),o}var Ze="Form submitted.";function At(r){if(typeof r=="string")return r||null;if(!r||typeof r!="object")return null;const o=r;if(typeof o.message=="string"&&o.message)return o.message;const a=o.result;if(typeof a=="string"&&a)return a;if(a&&typeof a=="object"){const n=a.message;if(typeof n=="string"&&n)return n}return null}var Qe="ago-chat-widget-keyframes";function It(){if(typeof document>"u"||document.getElementById(Qe))return;const r=document.createElement("style");r.id=Qe,r.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(r)}function Nt(r){const o=typeof r=="string"?document.querySelector(r):r;if(!o)throw new Error(`mountChatWidget: target "${String(r)}" not found.`);return o}function $t(r,o){const{title:a="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:i=!1,height:v=500,placement:p="inline",width:b=400,defaultOpen:d=!1,logoUrl:g,showAgentName:M=!1,agentBubble:$=!1,bubbleStyle:T="default",showHeader:Y=!0,theme:te,loadThreads:Z=!1,forms:m,formSubmittedMessage:C=Ze,onFollowUpClick:G,onMessageSent:ne,onMessageReceived:B,onFormSubmitted:oe,onFormError:Q}=o,re=typeof n=="string"?{message:n,mode:"static"}:n,Ae=re.message,Ie=re.mode??"static",rt="speed"in re&&re.speed||45;if(!o.client&&!o.config?.baseUrl)throw new Ge.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const h=o.client??new Ge.AgoClient(o.config),Ne=Nt(r),j=p==="left"||p==="right",at=j&&(o.launcher??!0);let q=j?d:!0;const ue=o.persistConversation,ae=ue?xt.createConversationSession(ue===!0?{}:ue):void 0;let L=o.conversationId??ae?.getLastActiveThread()??void 0,l=[],H=!1,J=null,D;const $e=[];function it(e){if(typeof C=="function"){const s=C(e);if(typeof s=="string"&&s)return s}const t=At(e);return t||(typeof C=="string"?C:Ze)}const ie=[],X=x({display:"flex",flexDirection:"column",height:j?"100%":typeof v=="number"?`${v}px`:v,border:`1px solid ${O}`,borderRadius:Rt,overflow:"hidden",backgroundColor:ee,fontFamily:_e,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});X.className="ago-chat-widget",kt(X,te);let z;if(Y){if(z=x({padding:"14px 16px",borderBottom:`1px solid ${O}`,backgroundColor:Et,color:Ke,display:"flex",alignItems:"center",gap:"10px"}),z.className="ago-chat-widget__header",g){const t=document.createElement("img");t.src=g,t.alt="Logo",E(t,{height:"24px",width:"auto"}),z.appendChild(t)}const e=document.createElement("h3");if(e.textContent=a,E(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),z.appendChild(e),j){const t=document.createElement("button");t.type="button",t.className="ago-chat-widget__close",t.setAttribute("aria-label","Close"),t.textContent="×",E(t,{marginLeft:"auto",background:"transparent",border:"none",color:Ke,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),t.addEventListener("click",()=>ye()),z.appendChild(t)}}const R=x({flex:"1",overflow:"auto",padding:"16px",backgroundColor:Ve});R.className="ago-chat-widget__messages",R.setAttribute("role","log"),R.setAttribute("aria-live","polite"),R.setAttribute("aria-relevant","additions text"),R.setAttribute("aria-atomic","false");const{inputRow:st,setDisabled:lt,focus:ge}=Tt({placeholder:u,allowFiles:i,onSend:(e,t)=>{xe(e,t)}});It(),X.append(...z?[z]:[],R,st);let se=X,U,_;const me=p==="left"?"left":"right";if(j&&(U=x({position:"fixed",top:"0",bottom:"0",[me]:"0",width:typeof b=="number"?`${b}px`:b,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",E(X,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[me==="left"?"borderRight":"borderLeft"]:`1px solid ${O}`}),U.appendChild(X),se=U),at){if(_=document.createElement("button"),_.type="button",_.className="ago-chat-widget-launcher",_.setAttribute("aria-label",`Open ${a}`),E(_,{position:"fixed",bottom:"20px",[me]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:pe,color:ke,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:_e}),g){const e=document.createElement("img");e.src=g,e.alt="",E(e,{width:"26px",height:"26px",objectFit:"contain"}),_.appendChild(e)}else _.appendChild(mt());_.addEventListener("click",()=>Ce())}Ne.appendChild(se),_&&Ne.appendChild(_),ve();const Te=G!==!1,Le=G===!1?void 0:G??(e=>{xe(e)});function dt(e,t,s=!0){const c=e.role==="user",f=T==="imessage",w=x({display:"flex",flexDirection:"column",alignItems:c?"flex-end":"flex-start",marginBottom:f&&!s?"2px":"16px"});if(w.className=`ago-message ago-message--${e.role}`,!c&&M&&e.agent){const y=x({fontSize:"13px",fontWeight:"500",color:de,marginBottom:"6px",padding:"0 4px"});y.className="ago-message__agent",y.textContent=e.agent.displayName||e.agent.name,w.appendChild(y)}if(!c&&e.sources&&e.sources.length>0){const y=x({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});y.className="ago-message__sources",e.sources.forEach((S,I)=>{const W=S.url?document.createElement("a"):document.createElement("div");S.url&&W instanceof HTMLAnchorElement&&(W.href=S.url,W.target="_blank",W.rel="noopener noreferrer"),E(W,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${O}`,borderRadius:"8px",backgroundColor:ee,textDecoration:"none",color:de,fontSize:"12px",overflow:"hidden"});const Pe=x({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${Ee}`,color:Ee,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Pe.textContent=String(I+1);const we=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});we.textContent=S.title,we.title=S.title,W.append(Pe,we),y.appendChild(W)}),w.appendChild(y)}const A=c||$||f,F=x({maxWidth:f||c?"75%":A?"85%":"100%",padding:A?"10px 14px":"2px 8px",borderRadius:f?_t:A?Se:"0",backgroundColor:c?pe:A?Ye:"transparent",color:c?ke:de,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(F.className="ago-message__content",f&&s){F.style.position="relative";const y=x({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:c?pe:Ye});y.className="ago-message__tail";const S=x({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:Ve});S.className="ago-message__tail-mask",c?(y.style.right="-8px",y.style.borderBottomLeftRadius="16px 14px",S.style.right="-10px",S.style.borderBottomLeftRadius="10px"):(y.style.left="-7px",y.style.borderBottomRightRadius="16px 14px",S.style.left="-10px",S.style.borderBottomRightRadius="10px"),F.append(y,S)}if(e.content?F.appendChild(fe(e.content)):e.status==="IN_PROGRESS"&&F.appendChild(ht()),w.appendChild(F),t&&e.followUpReplies&&e.followUpReplies.length>0){const y=x({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});y.className="ago-message__followups";for(const S of e.followUpReplies){const I=document.createElement("button");I.type="button",I.className="ago-message__followup-btn",I.textContent=S,I.disabled=!Te,E(I,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:Se,border:`1px solid ${O}`,backgroundColor:ee,color:de,cursor:Te?"pointer":"default",transition:"border-color 0.15s"}),Le&&I.addEventListener("click",()=>Le(S)),I.addEventListener("mouseenter",()=>{I.style.borderColor=Ee}),I.addEventListener("mouseleave",()=>{I.style.borderColor=O}),y.appendChild(I)}w.appendChild(y)}return w}function ct(e){const t=x({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:Se,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});t.className="ago-form-notice",t.setAttribute("role","status");const s=document.createElement("span");s.textContent="✓",s.setAttribute("aria-hidden","true"),E(s,{fontWeight:"700"});const c=document.createElement("span");return c.textContent=e,t.append(s,c),t}function k(){if(R.replaceChildren(),l.length===0){if(Ie==="static"){const t=x({textAlign:"center",color:St,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});t.appendChild(fe(Ae)),R.appendChild(t)}}else l.forEach((t,s)=>{const c=s===l.length-1||l[s+1].role!==t.role;R.appendChild(dt(t,s===l.length-1,c))});for(const t of $e)R.appendChild(ct(t));if(J){const t=x({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});t.setAttribute("role","alert"),t.textContent=J,R.appendChild(t)}R.scrollTop=R.scrollHeight;const e=l[l.length-1];lt(H&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function pt(){for(let e=l.length-1;e>=0;e--){const t=l[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const Oe=e=>{L||(L=e.conversationId)},Me=e=>{const t=pt();t&&(t.content+=e.content,k())},Be=e=>{const t=l.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");t>=0?l[t]=e:l.push(e),k(),ge()},De=e=>{const t=l.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");t>=0?l[t]=e:l.push(e),H=!1,k(),e.status==="DONE"&&B?.({id:e.id,content:e.content})},Fe=e=>{J=e.error,H=!1,l=l.filter(t=>!t.id.startsWith("temp-")),k()};function ft(e){const t={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l.push(t),k();const s=e.match(/\S+\s*/g)??[e];let c=0;D=setInterval(()=>{if(c>=s.length){clearInterval(D),D=void 0,t.status="DONE",k();return}t.content+=s[c],c++,k()},rt)}h.on("message:start",Oe),h.on("message:chunk",Me),h.on("message:answer-complete",Be),h.on("message:complete",De),h.on("message:error",Fe);const He=e=>oe?.(e),ze=e=>Q?.(e);oe&&h.on("form:submitted",He),Q&&h.on("form:error",ze);const he=[];let Ue=!1;const We=e=>{if(Ue)return;he.push(e.install(h));let t=e.store.get().submitted;const s=e.store.subscribe(c=>{c.submitted&&!t&&($e.push(it(c.submitResult)),k()),t=c.submitted});he.push(s)};for(const e of m??[])e.schema!=null?We(je.createFormCollector(e)):je.loadFormCollector(h,e).then(t=>We(t)).catch(()=>{});async function xe(e,t){const s=e.trim();if(!s&&!t?.length||H)return;if(ne?.(s),H=!0,J=null,D){clearInterval(D),D=void 0;const f=l.find(w=>w.id.startsWith("ago-intro-"));f&&!f.content?l=l.filter(w=>w!==f):f&&(f.status="DONE")}const c=Date.now();l.push({id:`temp-user-${c}`,conversationId:L||"",content:s,role:"user",status:"DONE",createdAt:new Date}),l.push({id:`temp-assistant-${c}`,conversationId:L||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),k();try{const f=await h.sendMessage(s,{conversationId:L,files:t});f.conversationId&&(L||(L=f.conversationId),ae?.setActiveThread(f.conversationId,f.createdAt));const w=l.find(A=>A.id===`temp-user-${c}`);if(w&&(w.id=`user-${c}`,w.conversationId=f.conversationId),!l.some(A=>A.id===f.id)){const A=l.findIndex(F=>F.id===`temp-assistant-${c}`);A>=0?l[A]=f:l.push(f)}l=l.filter(A=>!A.id.startsWith("temp-")),H=!1,k(),Z&&be()}catch(f){J=f instanceof Error?f.message:"Failed to send message",H=!1,l=l.filter(w=>!w.id.startsWith("temp-")),k()}}async function be(){try{const e=await h.getConversations();ie.splice(0,ie.length,...e)}catch{}return ie}async function ut(e){try{const t=(await h.getConversation(e))?.messages??[];t.length>0&&l.length===0&&(l=t,k())}catch{l.length===0&&(ae?.clear(),L=void 0)}}return k(),ge(),L?ut(L):Ie==="streaming"&&ft(Ae),Z&&be(),{client:h,element:se,sendMessage:xe,...j?{open:Ce,close:ye,toggle:gt}:{},session:ae,threads:ie,refreshThreads:be,destroy(){D&&clearInterval(D),h.off("message:start",Oe),h.off("message:chunk",Me),h.off("message:answer-complete",Be),h.off("message:complete",De),h.off("message:error",Fe),oe&&h.off("form:submitted",He),Q&&h.off("form:error",ze),Ue=!0,he.forEach(e=>e()),se.remove(),_?.remove(),o.client||h.destroy()}};function ve(){if(!U)return;const e=p==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=q?"translateX(0)":e,U.setAttribute("aria-hidden",q?"false":"true"),_&&(_.style.display=q?"none":"flex")}function Ce(){q=!0,ve(),ge()}function ye(){q=!1,ve()}function gt(){q?ye():Ce()}function mt(){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","26"),t.setAttribute("height","26"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("fill","none");const s=document.createElementNS(e,"path");return s.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"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-width","2"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),t.appendChild(s),t}function ht(){const e=x({display:"flex",gap:"4px",padding:"4px 0"});for(let t=0;t<3;t++){const s=x({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${t*.2}s`});e.appendChild(s)}return e}}function Tt(r){let o=[];const a=document.createElement("form");E(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${O}`,backgroundColor:ee}),a.className="ago-chat-input";const n=x({display:"flex",flexWrap:"wrap",gap:"6px"}),u=x({display:"flex",gap:"8px",alignItems:"flex-end"}),i=document.createElement("textarea");i.placeholder=r.placeholder,i.setAttribute("aria-label",r.placeholder),i.rows=1,E(i,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${O}`,borderRadius:"12px",fontSize:"16px",fontFamily:_e,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const v=()=>{i.style.height="auto";const C=Math.min(i.scrollHeight+2,110);i.style.height=`${C}px`,i.style.overflowY=i.scrollHeight+2>110?"auto":"hidden"};i.addEventListener("input",()=>{v(),M()});const p='<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>',b='<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>',d=document.createElement("button");d.type="submit",d.setAttribute("aria-label","Send"),d.innerHTML=p,E(d,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:pe,color:ke,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let g=!1;const M=()=>{const m=i.value.trim()!==""||o.length>0,C=g||!m;d.disabled=C,d.innerHTML=g?b:p,d.style.opacity=C&&!g?"0.5":"1",d.style.cursor=C?"default":"pointer"};let $=null,T=null;r.allowFiles&&($=document.createElement("input"),$.type="file",$.multiple=!0,E($,{display:"none"}),T=document.createElement("button"),T.type="button",T.setAttribute("aria-label","Attach file"),T.textContent="📎",E(T,{padding:"10px 12px",border:`1px solid ${O}`,borderRadius:"12px",backgroundColor:ee,cursor:"pointer",fontSize:"14px"}),T.addEventListener("click",()=>$?.click()),$.addEventListener("change",()=>{o=[...o,...Array.from($?.files??[])],Y()}));function Y(){n.replaceChildren(),o.forEach((m,C)=>{const G=x({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${O}`,borderRadius:"8px",fontSize:"12px"}),ne=document.createElement("span");ne.textContent=m.name;const B=document.createElement("button");B.type="button",B.setAttribute("aria-label",`Remove ${m.name}`),B.textContent="×",E(B,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),B.addEventListener("click",()=>{o=o.filter((oe,Q)=>Q!==C),Y()}),G.append(ne,B),n.appendChild(G)}),M()}const te=()=>{const m=i.value,C=o;return i.value="",v(),o=[],Y(),{content:m,files:C}},Z=()=>{const{content:m,files:C}=te();(m.trim()||C.length>0)&&r.onSend(m.trim(),C.length>0?C:void 0)};return a.addEventListener("submit",m=>{m.preventDefault(),Z()}),i.addEventListener("keydown",m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),Z())}),T&&u.appendChild(T),u.append(i,d),$&&a.appendChild($),a.append(n,u),M(),{inputRow:a,getValueAndClear:te,setDisabled:m=>{i.disabled=m,g=m,M()},focus:()=>i.focus()}}exports.mountChatWidget=$t;exports.renderMarkdown=fe;
3
+ `);let r=0;for(;r<i.length;){const a=i[r];if(a.trim()===""){r++;continue}const C=a.match(ht);if(C){const s=C[1][0],m=[];for(r++;r<i.length&&!new RegExp(`^ {0,3}${s==="`"?"`{3,}":"~{3,}"}\\s*$`).test(i[r]);)m.push(i[r]),r++;r++;const R=D("pre",{margin:"0 0 8px 0"});R.appendChild(D("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:ut,whiteSpace:"pre"},ne(m.join(`
4
+ `)))),o.appendChild(R);continue}if(mt.test(a)){o.appendChild(D("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),r++;continue}const u=a.match(gt);if(u){const s=u[1].length;o.appendChild(D(`h${s}`,{margin:"16px 0 8px 0",fontSize:Vt[s-1],fontWeight:"600",lineHeight:"1.3"},ee(u[2]))),r++;continue}if(Ce.test(a)){const s=[];for(;r<i.length&&Ce.test(i[r]);)s.push(i[r].replace(Ce,"")),r++;const m=D("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});m.appendChild(Re(s.join(`
5
+ `))),o.appendChild(m);continue}if(a.includes("|")&&Qt(i[r+1])){const s=[a,i[r+1]];for(r+=2;r<i.length&&i[r].includes("|")&&i[r].trim();)s.push(i[r]),r++;o.appendChild(Xt(s));continue}if(re.test(a)){const s=[],m=Oe(a);for(;r<i.length&&i[r].trim()!=="";)if(re.test(i[r])||Oe(i[r])>m)s.push(i[r]),r++;else break;o.appendChild(xt(s));continue}const b=[a];for(r++;r<i.length&&!Kt(i[r]);)b.push(i[r]),r++;o.appendChild(D("p",{margin:"0 0 8px 0",lineHeight:"1.6"},b.map(s=>ee(s)).join("<br>")))}const v=o.lastElementChild;return v&&(v.style.marginBottom="0"),o}function Yt(t,o){const{isLast:i,isLastOfBlock:r,bubbleStyle:v,showAgentName:a,agentBubble:C,followUpEnabled:u,followUpHandler:b}=o,s=t.role==="user",m=v==="imessage",R=x({display:"flex",flexDirection:"column",alignItems:s?"flex-end":"flex-start",marginBottom:m&&!r?"2px":"16px"});if(R.className=`ago-message ago-message--${t.role}`,!s&&a&&t.agent){const g=x({fontSize:"13px",fontWeight:"500",color:Z,marginBottom:"6px",padding:"0 4px"});g.className="ago-message__agent",g.textContent=t.agent.displayName||t.agent.name,R.appendChild(g)}if(!s&&t.sources&&t.sources.length>0){const g=x({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});g.className="ago-message__sources",t.sources.forEach((h,l)=>{const f=h.url?document.createElement("a"):document.createElement("div");h.url&&f instanceof HTMLAnchorElement&&(f.href=h.url,f.target="_blank",f.rel="noopener noreferrer"),y(f,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${$}`,borderRadius:"8px",backgroundColor:J,textDecoration:"none",color:Z,fontSize:"12px",overflow:"hidden"});const I=x({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${Ne}`,color:Ne,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});I.textContent=String(l+1);const B=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});B.textContent=h.title,B.title=h.title,f.append(I,B),g.appendChild(f)}),R.appendChild(g)}if(t.attachments&&t.attachments.length>0){const g=x({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:s?"flex-end":"flex-start",maxWidth:"75%"});g.className="ago-message__attachments";for(const h of t.attachments){const l=oe.safeAttachmentUrl(h.url);if(oe.canInlineImage(h)&&l){const _=document.createElement("a");_.href=l,_.target="_blank",_.rel="noopener noreferrer",y(_,{display:"inline-block",textDecoration:"none"});const j=document.createElement("img");j.src=l,j.alt=h.name,j.loading="lazy",y(j,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${$}`,display:"block"}),_.appendChild(j),g.appendChild(_);continue}const f=l?document.createElement("a"):document.createElement("div");l&&f instanceof HTMLAnchorElement&&(f.href=l,f.target="_blank",f.rel="noopener noreferrer"),y(f,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${$}`,backgroundColor:s?"rgba(255,255,255,0.12)":J,color:s?Se:Z,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const I=document.createElement("span");I.textContent="📄",I.setAttribute("aria-hidden","true"),y(I,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const B=x({display:"flex",flexDirection:"column",minWidth:"0"}),M=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});M.textContent=h.name,M.title=h.name,B.appendChild(M);const Q=oe.formatFileSize(h.fileSize);if(Q){const _=x({fontSize:"11px",color:ft});_.textContent=Q,B.appendChild(_)}f.append(I,B),g.appendChild(f)}R.appendChild(g)}const k=s||C||m,T=!!t.content||t.status==="IN_PROGRESS",O=x({maxWidth:m||s?"75%":k?"85%":"100%",padding:k?"10px 14px":"2px 8px",borderRadius:m?Wt:k?Te:"0",backgroundColor:s?Ee:k?st:"transparent",color:s?Se:Z,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(O.className="ago-message__content",m&&r){O.style.position="relative";const g=x({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:s?Ee:st});g.className="ago-message__tail";const h=x({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:pt});h.className="ago-message__tail-mask",s?(g.style.right="-8px",g.style.borderBottomLeftRadius="16px 14px",h.style.right="-10px",h.style.borderBottomLeftRadius="10px"):(g.style.left="-7px",g.style.borderBottomRightRadius="16px 14px",h.style.left="-10px",h.style.borderBottomRightRadius="10px"),O.append(g,h)}if(t.content?O.appendChild(Re(t.content)):t.status==="IN_PROGRESS"&&O.appendChild(Jt()),T&&R.appendChild(O),i&&t.followUpReplies&&t.followUpReplies.length>0){const g=x({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});g.className="ago-message__followups";for(const h of t.followUpReplies){const l=document.createElement("button");l.type="button",l.className="ago-message__followup-btn",l.textContent=h,l.disabled=!u,y(l,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:Te,border:`1px solid ${$}`,backgroundColor:J,color:Z,cursor:u?"pointer":"default",transition:"border-color 0.15s"}),b&&l.addEventListener("click",()=>b(h)),l.addEventListener("mouseenter",()=>{l.style.borderColor=Ne}),l.addEventListener("mouseleave",()=>{l.style.borderColor=$}),g.appendChild(l)}R.appendChild(g)}return R}function Zt(t){const o=x({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:Te,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"),y(i,{fontWeight:"700"});const r=document.createElement("span");return r.textContent=t,o.append(i,r),o}function Jt(){const t=x({display:"flex",gap:"4px",padding:"4px 0"});for(let o=0;o<3;o++){const i=x({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${o*.2}s`});t.appendChild(i)}return t}function en(){const t="http://www.w3.org/2000/svg",o=document.createElementNS(t,"svg");o.setAttribute("width","26"),o.setAttribute("height","26"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none");const i=document.createElementNS(t,"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 ct="Form submitted.";function tn(t){if(typeof t=="string")return t||null;if(!t||typeof t!="object")return null;const o=t;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 nn=0;function on(t){const o=typeof t=="string"?document.querySelector(t):t;if(!o)throw new Error(`mountChatWidget: target "${String(t)}" not found.`);return o}function rn(t,o){const{title:i="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:v="Type a message...",allowFiles:a=!1,height:C=500,placement:u="inline",width:b=400,defaultOpen:s=!1,logoUrl:m,showAgentName:R=!1,agentBubble:k=!1,bubbleStyle:T="default",showHeader:O=!0,theme:g,loadThreads:h=!1,forms:l,formSubmittedMessage:f=ct,onFollowUpClick:I,onMessageSent:B,onMessageReceived:M,onFormSubmitted:Q,onFormError:_,onOpen:j,onClose:Be}=o,ce=typeof r=="string"?{message:r,mode:"static"}:r,Me=ce.message,De=ce.mode??"static",bt="speed"in ce&&ce.speed||45;if(!o.client&&!o.config?.baseUrl)throw new oe.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const E=o.client??new oe.AgoClient(o.config),ze=on(t),z=u==="left"||u==="right",vt=z&&(o.launcher??!0);let te=z?s:!0;const yt=o.mobile?.breakpoint??768,wt=o.mobile?.trigger??"focus",He=typeof window<"u"&&!!window.matchMedia,F=He?window.matchMedia(`(max-width: ${yt}px)`):void 0,Ct=He?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,ie=!z&&!!F,ke=o.persistConversation,pe=ke?zt.createConversationSession(ke===!0?{}:ke):void 0;let P=o.conversationId??pe?.getLastActiveThread()??void 0,p=[],Y=!1,ae=null,q;const Fe=[];function Et(e){if(typeof f=="function"){const c=f(e);if(typeof c=="string"&&c)return c}const n=tn(e);return n||(typeof f=="string"?f:ct)}const fe=[],d=x({display:"flex",flexDirection:"column",height:z?"100%":typeof C=="number"?`${C}px`:C,border:`1px solid ${$}`,borderRadius:Pt,overflow:"hidden",backgroundColor:J,fontFamily:we,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",Ut(d,g);let H;if(O){if(H=x({padding:"14px 16px",borderBottom:`1px solid ${$}`,backgroundColor:Ft,color:at,display:"flex",alignItems:"center",gap:"10px"}),H.className="ago-chat-widget__header",m){const n=document.createElement("img");n.src=m,n.alt="Logo",y(n,{height:"24px",width:"auto"}),H.appendChild(n)}const e=document.createElement("h3");if(e.textContent=i,y(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),H.appendChild(e),z){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",y(n,{marginLeft:"auto",background:"transparent",border:"none",color:at,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),n.addEventListener("click",()=>Le()),H.appendChild(n)}}const A=x({flex:"1",overflow:"auto",padding:"16px",backgroundColor:pt});A.className="ago-chat-widget__messages",A.setAttribute("role","log"),A.setAttribute("aria-live","polite"),A.setAttribute("aria-relevant","additions text"),A.setAttribute("aria-atomic","false");const{inputRow:Pe,setDisabled:St,focus:ue}=jt({placeholder:v,allowFiles:a,onSend:(e,n)=>{Ae(e,n)}});Gt(),d.append(...H?[H]:[],A,Pe);let me=d,W,L;const ge=u==="left"?"left":"right";if(z&&(W=x({position:"fixed",top:"0",bottom:"0",[ge]:"0",width:typeof b=="number"?`${b}px`:b,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),W.className="ago-chat-widget-panel",y(d,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ge==="left"?"borderRight":"borderLeft"]:`1px solid ${$}`}),W.appendChild(d),me=W),vt){if(L=document.createElement("button"),L.type="button",L.className="ago-chat-widget-launcher",L.setAttribute("aria-label",`Open ${i}`),y(L,{position:"fixed",bottom:"20px",[ge]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:Ee,color:Se,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:we}),m){const e=document.createElement("img");e.src=m,e.alt="",y(e,{width:"26px",height:"26px",objectFit:"contain"}),L.appendChild(e)}else L.appendChild(en());L.addEventListener("click",()=>$e())}const se=ie?`ago-vt-${++nn}`:"",We=52;let V=!1,U,le,K;const he={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};ze.appendChild(me),L&&ze.appendChild(L),xe(),ie&&(U=Bt(),d.insertBefore(U,d.firstChild),le=document.createElement("style"),le.id=se,le.textContent=`::view-transition-group(${se}),::view-transition-group(${se}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(le),wt==="focus"&&(d.addEventListener("pointerdown",e=>{V||!F?.matches||Pe.contains(e.target)&&(e.preventDefault(),ve())},!0),d.addEventListener("focusin",()=>{F?.matches&&ve()})),document.addEventListener("keydown",Ze)),F&&F.addEventListener("change",Je);const Rt=I!==!1,kt=I===!1?void 0:I??(e=>{Ae(e)});function N(){if(A.replaceChildren(),p.length===0){if(De==="static"){const n=x({textAlign:"center",color:ft,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});n.appendChild(Re(Me)),A.appendChild(n)}}else p.forEach((n,c)=>{const S=c===p.length-1||p[c+1].role!==n.role;A.appendChild(Yt(n,{isLast:c===p.length-1,isLastOfBlock:S,bubbleStyle:T,showAgentName:R,agentBubble:k,followUpEnabled:Rt,followUpHandler:kt}))});for(const n of Fe)A.appendChild(Zt(n));if(ae){const n=x({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});n.setAttribute("role","alert"),n.textContent=ae,A.appendChild(n)}A.scrollTop=A.scrollHeight;const e=p[p.length-1];St(Y&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function _t(){for(let e=p.length-1;e>=0;e--){const n=p[e];if(n.role==="assistant"&&n.status==="IN_PROGRESS")return n}}const Ue=e=>{P||(P=e.conversationId)},Ge=e=>{const n=_t();n&&(n.content+=e.content,N())},je=e=>{const n=p.findIndex(c=>c.id===e.id||c.role==="assistant"&&c.status==="IN_PROGRESS");n>=0?p[n]=e:p.push(e),N(),ue()},qe=e=>{const n=p.findIndex(c=>c.id===e.id||c.role==="assistant"&&c.status==="IN_PROGRESS");n>=0?p[n]=e:p.push(e),Y=!1,N(),e.status==="DONE"&&M?.({id:e.id,content:e.content})},Ve=e=>{ae=e.error,Y=!1,p=p.filter(n=>!n.id.startsWith("temp-")),N()};function At(e){const n={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};p.push(n),N();const c=e.match(/\S+\s*/g)??[e];let S=0;q=setInterval(()=>{if(S>=c.length){clearInterval(q),q=void 0,n.status="DONE",N();return}n.content+=c[S],S++,N()},bt)}E.on("message:start",Ue),E.on("message:chunk",Ge),E.on("message:answer-complete",je),E.on("message:complete",qe),E.on("message:error",Ve);const Ke=e=>Q?.(e),Xe=e=>_?.(e);Q&&E.on("form:submitted",Ke),_&&E.on("form:error",Xe);const _e=[];let Qe=!1;const Ye=e=>{if(Qe)return;_e.push(e.install(E));let n=e.store.get().submitted;const c=e.store.subscribe(S=>{S.submitted&&!n&&(Fe.push(Et(S.submitResult)),N()),n=S.submitted});_e.push(c)};for(const e of l??[])e.schema!=null?Ye(rt.createFormCollector(e)):rt.loadFormCollector(E,e).then(n=>Ye(n)).catch(()=>{});async function Ae(e,n){const c=e.trim();if(!c&&!n?.length||Y)return;if(B?.(c),Y=!0,ae=null,q){clearInterval(q),q=void 0;const w=p.find(G=>G.id.startsWith("ago-intro-"));w&&!w.content?p=p.filter(G=>G!==w):w&&(w.status="DONE")}const S=Date.now();p.push({id:`temp-user-${S}`,conversationId:P||"",content:c,role:"user",status:"DONE",attachments:n&&n.length>0?oe.attachmentsFromFiles(n):void 0,createdAt:new Date}),p.push({id:`temp-assistant-${S}`,conversationId:P||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),N();try{const w=await E.sendMessage(c,{conversationId:P,files:n});w.conversationId&&(P||(P=w.conversationId),pe?.setActiveThread(w.conversationId,w.createdAt));const G=p.find(X=>X.id===`temp-user-${S}`);if(G&&(G.id=`user-${S}`,G.conversationId=w.conversationId),!p.some(X=>X.id===w.id)){const X=p.findIndex(Dt=>Dt.id===`temp-assistant-${S}`);X>=0?p[X]=w:p.push(w)}p=p.filter(X=>!X.id.startsWith("temp-")),Y=!1,N(),h&&Ie()}catch(w){ae=w instanceof Error?w.message:"Failed to send message",Y=!1,p=p.filter(G=>!G.id.startsWith("temp-")),N()}}async function Ie(){try{const e=await E.getConversations();fe.splice(0,fe.length,...e)}catch{}return fe}async function It(e){try{const n=(await E.getConversation(e))?.messages??[];n.length>0&&p.length===0&&(p=n,N())}catch{p.length===0&&(pe?.clear(),P=void 0)}}return N(),ie&&F?.matches||ue(),P?It(P):De==="streaming"&&At(Me),h&&Ie(),{client:E,element:me,sendMessage:Ae,...z||ie?{open:Lt,close:Nt,toggle:Tt}:{},session:pe,threads:fe,refreshThreads:Ie,destroy(){q&&clearInterval(q),E.off("message:start",Ue),E.off("message:chunk",Ge),E.off("message:answer-complete",je),E.off("message:complete",qe),E.off("message:error",Ve),Q&&E.off("form:submitted",Ke),_&&E.off("form:error",Xe),Qe=!0,_e.forEach(e=>e()),me.remove(),L?.remove(),U?.remove(),le?.remove(),K?.remove(),F?.removeEventListener("change",Je),ie&&(document.removeEventListener("keydown",Ze),window.visualViewport?.removeEventListener("resize",be),document.documentElement.style.removeProperty("overflow")),o.client||E.destroy()}};function xe(){if(!W)return;{const n=ge==="left"?"border-right":"border-left";F?.matches?(W.style.width="100%",d.style.borderRadius="0",d.style.removeProperty(n)):(W.style.width=typeof b=="number"?`${b}px`:b,d.style.setProperty(n,`1px solid ${$}`))}const e=u==="left"?"translateX(-100%)":"translateX(100%)";W.style.transform=te?"translateX(0)":e,W.setAttribute("aria-hidden",te?"false":"true"),L&&(L.style.display=te?"none":"flex")}function $e(){te=!0,xe(),ue(),j?.()}function Le(){te=!1,xe(),Be?.()}function $t(){te?Le():$e()}function Lt(){z?$e():ve()}function Nt(){z?Le():de()}function Tt(){z?$t():V?de():ve()}function Ot(){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 Ze(e){if(!V)return;if(e.key==="Escape"){de();return}if(e.key!=="Tab")return;const n=Ot();if(n.length===0){e.preventDefault();return}const c=n[0],S=n[n.length-1],w=document.activeElement;e.shiftKey&&(w===c||!d.contains(w))?(e.preventDefault(),S.focus()):!e.shiftKey&&(w===S||!d.contains(w))&&(e.preventDefault(),c.focus())}function Je(e){z?xe():!e.matches&&V&&de()}function et(){return window.visualViewport?.height??window.innerHeight}function be(){d.style.setProperty("--ago-vh",`${et()}px`)}function tt(){A.scrollTop=A.scrollHeight}function Bt(){const e=x({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${We}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:J,borderBottom:`1px solid ${$}`,zIndex:"2147483001",fontFamily:we});if(e.className="ago-chat-widget-mobile-bar",m){const c=document.createElement("img");c.src=m,c.alt="",y(c,{height:"28px",width:"auto"}),e.appendChild(c)}else if(i){const c=document.createElement("span");c.textContent=i,y(c,{fontSize:"15px",fontWeight:"600",color:Z,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),e.appendChild(c)}else e.appendChild(x({}));const n=document.createElement("button");return n.type="button",n.setAttribute("aria-label","Close"),n.textContent="×",y(n,{border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:Z,cursor:"pointer",padding:"4px 8px"}),n.addEventListener("click",()=>{de()}),e.appendChild(n),e}function Mt(){return typeof document.startViewTransition=="function"&&!Ct?.matches&&!!F?.matches}function nt(e){const n=document;if(Mt()&&n.startViewTransition){d.style.setProperty("view-transition-name",se),U?.style.setProperty("view-transition-name",`${se}-bar`);const c=()=>{d.style.removeProperty("view-transition-name"),U?.style.removeProperty("view-transition-name")};return n.startViewTransition(e).finished.then(c,c)}return e(),Promise.resolve()}function ot(e){if(e)K&&d.parentElement?.insertBefore(K,d),y(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(${We}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",H&&(H.style.display="none"),U&&(U.style.display="flex");else{K?.remove(),K=void 0;for(const n of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])d.style.removeProperty(n);d.style.height=he.height,d.style.border=he.border,d.style.borderRadius=he.borderRadius,d.style.boxShadow=he.boxShadow,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),document.documentElement.style.removeProperty("overflow"),H&&(H.style.display="flex"),U&&(U.style.display="none")}}function ve(){if(V||!F?.matches)return Promise.resolve();const e=d.getBoundingClientRect();if(e.height>=et()*.8)return Promise.resolve();V=!0,K=x({width:`${e.width}px`,height:`${e.height}px`}),K.className="ago-chat-widget-spacer",K.setAttribute("aria-hidden","true"),be(),window.visualViewport?.addEventListener("resize",be);const n=nt(()=>ot(!0));return n.then(()=>{tt(),ue()}),tt(),j?.(),n}function de(){if(!V)return Promise.resolve();V=!1,window.visualViewport?.removeEventListener("resize",be),d.querySelector("textarea")?.blur();const e=nt(()=>ot(!1));return e.then(()=>d.style.removeProperty("--ago-vh")),Be?.(),e}}exports.mountChatWidget=rn;exports.renderMarkdown=Re;
package/dist/widget.d.cts CHANGED
@@ -7,6 +7,27 @@ declare interface AgoAgent {
7
7
  displayName?: string;
8
8
  }
9
9
 
10
+ /**
11
+ * An uploaded file attached to a message.
12
+ *
13
+ * `url` is a presigned, time-limited URL the backend generates per request (or a
14
+ * local `blob:` URL for an optimistic preview). `isSafeImage` is the backend's
15
+ * verdict that the file is a real, script-free image safe to embed inline; the
16
+ * UI only renders an `<img>` when it is true and otherwise shows a download link.
17
+ */
18
+ declare interface AgoAttachment {
19
+ id: string;
20
+ name: string;
21
+ /** MIME type reported by the backend (e.g. `image/png`). */
22
+ contentType?: string;
23
+ /** Size in bytes. */
24
+ fileSize?: number;
25
+ /** Presigned download/preview URL, or a local `blob:` URL before upload. */
26
+ url?: string;
27
+ /** True only when the backend verified the file is a safe inline image. */
28
+ isSafeImage: boolean;
29
+ }
30
+
10
31
  /**
11
32
  * Main SDK client for AGO Chat integration
12
33
  */
@@ -363,6 +384,8 @@ declare interface AgoMessage {
363
384
  sources?: AgoSource[];
364
385
  toolCalls?: ToolCallData[];
365
386
  followUpReplies?: string[];
387
+ /** Uploaded files on this message (usually the user's). */
388
+ attachments?: AgoAttachment[];
366
389
  createdAt: Date;
367
390
  }
368
391
 
@@ -375,17 +398,6 @@ declare interface AgoSource {
375
398
  url?: string;
376
399
  }
377
400
 
378
- /**
379
- * Widget configuration types.
380
- *
381
- * These types describe the `window.AGO` configuration object
382
- * used by the embeddable chat widget snippet.
383
- *
384
- * @example
385
- * ```ts
386
- * import type { AgoWidgetConfig } from "@useago/sdk/widget";
387
- * ```
388
- */
389
401
  export declare interface AgoWidgetColors {
390
402
  button?: string;
391
403
  header?: string;
@@ -415,7 +427,7 @@ export declare interface AgoWidgetConfig {
415
427
  metadata?: Record<string, unknown>;
416
428
  }
417
429
 
418
- /** Handle returned by {@link mountChatWidget}. */
430
+ /** Handle returned by `mountChatWidget`. */
419
431
  export declare interface ChatWidgetHandle {
420
432
  /** The AGO client backing the widget. */
421
433
  client: AgoClient;
@@ -424,8 +436,9 @@ export declare interface ChatWidgetHandle {
424
436
  /** Programmatically send a message (same path as the input). */
425
437
  sendMessage: (content: string, files?: File[]) => Promise<void>;
426
438
  /**
427
- * Open / close / toggle the side panel. Present only for
428
- * `placement: "left" | "right"` (an inline panel is always visible).
439
+ * Open / close / toggle the panel. Present for `placement: "left" | "right"`,
440
+ * and for `placement: "inline"` in a browser (where they expand / collapse the
441
+ * mobile full-screen sheet; no-ops on a desktop viewport).
429
442
  */
430
443
  open?: () => void;
431
444
  close?: () => void;
@@ -755,7 +768,7 @@ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCEL
755
768
  export declare function mountChatWidget(target: string | HTMLElement, options: MountChatWidgetOptions): ChatWidgetHandle;
756
769
 
757
770
  /**
758
- * Options for {@link mountChatWidget} — the framework-agnostic (pure TS/JS)
771
+ * Options for `mountChatWidget` — the framework-agnostic (pure TS/JS)
759
772
  * equivalent of the React `<ChatWidget>` component. Same features: conversational
760
773
  * forms (form creator) and clickable suggested replies.
761
774
  */
@@ -844,6 +857,31 @@ export declare interface MountChatWidgetOptions {
844
857
  * Theme overrides so the panel blends into the host page.
845
858
  */
846
859
  theme?: WidgetTheme;
860
+ /**
861
+ * Tune the automatic mobile full-screen behavior. The widget already fills the
862
+ * screen on small viewports without any config; this object only exists to
863
+ * adjust the breakpoint or hand control back to you.
864
+ *
865
+ * - With `placement: "inline"`: a compact card morphs to a fixed full-screen
866
+ * sheet (with a logo + close bar) when the input is engaged, and back. The
867
+ * morph is skipped automatically when the card is already full-bleed (≈full
868
+ * viewport height), so a dedicated full-page chat is left untouched. The
869
+ * morph uses the View Transitions API where available and falls back to an
870
+ * instant swap. `open()`/`close()`/`toggle()` are available on the handle
871
+ * (no-ops on a desktop viewport).
872
+ * - With `placement: "left" | "right"`: the side panel squares off to a true
873
+ * full-screen sheet on mobile (the slide-in/out mechanics are unchanged).
874
+ */
875
+ mobile?: {
876
+ /** Max viewport width (px) treated as "mobile". Defaults to `768`. */
877
+ breakpoint?: number;
878
+ /**
879
+ * Inline placement only: how the card enters full screen. `"focus"` (default)
880
+ * expands when the input is tapped/focused; `"manual"` expands only via
881
+ * `widget.open()`. Ignored for side placements (driven by the launcher).
882
+ */
883
+ trigger?: "focus" | "manual";
884
+ };
847
885
  /**
848
886
  * Load the visitor's conversation list into `widget.threads` on mount and refresh
849
887
  * it after each turn (one `GET /conversations` per load). Off by default to avoid
@@ -876,6 +914,16 @@ export declare interface MountChatWidgetOptions {
876
914
  * render the suggestions as non-interactive.
877
915
  */
878
916
  onFollowUpClick?: ((reply: string) => void) | false;
917
+ /**
918
+ * Called when the panel opens: a side panel opening, or an inline card
919
+ * expanding to full screen on mobile.
920
+ */
921
+ onOpen?: () => void;
922
+ /**
923
+ * Called when the panel closes: a side panel closing, or an inline card
924
+ * collapsing from full screen on mobile.
925
+ */
926
+ onClose?: () => void;
879
927
  /** Called when the user sends a message. */
880
928
  onMessageSent?: (content: string) => void;
881
929
  /** Called when an assistant message completes. */
@@ -1047,7 +1095,8 @@ export declare type WelcomeMessage = string | {
1047
1095
  };
1048
1096
 
1049
1097
  /**
1050
- * Theme overrides for {@link mountChatWidget}. *
1098
+ * Theme overrides for `mountChatWidget`. The keys map to `--ago-*` custom
1099
+ * properties (see `THEME_VARS` in `./styles`).
1051
1100
  * @see The `--ago-*` token reference in `docs/general/widget.md`.
1052
1101
  */
1053
1102
  export declare interface WidgetTheme {
package/dist/widget.d.ts CHANGED
@@ -7,6 +7,27 @@ declare interface AgoAgent {
7
7
  displayName?: string;
8
8
  }
9
9
 
10
+ /**
11
+ * An uploaded file attached to a message.
12
+ *
13
+ * `url` is a presigned, time-limited URL the backend generates per request (or a
14
+ * local `blob:` URL for an optimistic preview). `isSafeImage` is the backend's
15
+ * verdict that the file is a real, script-free image safe to embed inline; the
16
+ * UI only renders an `<img>` when it is true and otherwise shows a download link.
17
+ */
18
+ declare interface AgoAttachment {
19
+ id: string;
20
+ name: string;
21
+ /** MIME type reported by the backend (e.g. `image/png`). */
22
+ contentType?: string;
23
+ /** Size in bytes. */
24
+ fileSize?: number;
25
+ /** Presigned download/preview URL, or a local `blob:` URL before upload. */
26
+ url?: string;
27
+ /** True only when the backend verified the file is a safe inline image. */
28
+ isSafeImage: boolean;
29
+ }
30
+
10
31
  /**
11
32
  * Main SDK client for AGO Chat integration
12
33
  */
@@ -363,6 +384,8 @@ declare interface AgoMessage {
363
384
  sources?: AgoSource[];
364
385
  toolCalls?: ToolCallData[];
365
386
  followUpReplies?: string[];
387
+ /** Uploaded files on this message (usually the user's). */
388
+ attachments?: AgoAttachment[];
366
389
  createdAt: Date;
367
390
  }
368
391
 
@@ -375,17 +398,6 @@ declare interface AgoSource {
375
398
  url?: string;
376
399
  }
377
400
 
378
- /**
379
- * Widget configuration types.
380
- *
381
- * These types describe the `window.AGO` configuration object
382
- * used by the embeddable chat widget snippet.
383
- *
384
- * @example
385
- * ```ts
386
- * import type { AgoWidgetConfig } from "@useago/sdk/widget";
387
- * ```
388
- */
389
401
  export declare interface AgoWidgetColors {
390
402
  button?: string;
391
403
  header?: string;
@@ -415,7 +427,7 @@ export declare interface AgoWidgetConfig {
415
427
  metadata?: Record<string, unknown>;
416
428
  }
417
429
 
418
- /** Handle returned by {@link mountChatWidget}. */
430
+ /** Handle returned by `mountChatWidget`. */
419
431
  export declare interface ChatWidgetHandle {
420
432
  /** The AGO client backing the widget. */
421
433
  client: AgoClient;
@@ -424,8 +436,9 @@ export declare interface ChatWidgetHandle {
424
436
  /** Programmatically send a message (same path as the input). */
425
437
  sendMessage: (content: string, files?: File[]) => Promise<void>;
426
438
  /**
427
- * Open / close / toggle the side panel. Present only for
428
- * `placement: "left" | "right"` (an inline panel is always visible).
439
+ * Open / close / toggle the panel. Present for `placement: "left" | "right"`,
440
+ * and for `placement: "inline"` in a browser (where they expand / collapse the
441
+ * mobile full-screen sheet; no-ops on a desktop viewport).
429
442
  */
430
443
  open?: () => void;
431
444
  close?: () => void;
@@ -755,7 +768,7 @@ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCEL
755
768
  export declare function mountChatWidget(target: string | HTMLElement, options: MountChatWidgetOptions): ChatWidgetHandle;
756
769
 
757
770
  /**
758
- * Options for {@link mountChatWidget} — the framework-agnostic (pure TS/JS)
771
+ * Options for `mountChatWidget` — the framework-agnostic (pure TS/JS)
759
772
  * equivalent of the React `<ChatWidget>` component. Same features: conversational
760
773
  * forms (form creator) and clickable suggested replies.
761
774
  */
@@ -844,6 +857,31 @@ export declare interface MountChatWidgetOptions {
844
857
  * Theme overrides so the panel blends into the host page.
845
858
  */
846
859
  theme?: WidgetTheme;
860
+ /**
861
+ * Tune the automatic mobile full-screen behavior. The widget already fills the
862
+ * screen on small viewports without any config; this object only exists to
863
+ * adjust the breakpoint or hand control back to you.
864
+ *
865
+ * - With `placement: "inline"`: a compact card morphs to a fixed full-screen
866
+ * sheet (with a logo + close bar) when the input is engaged, and back. The
867
+ * morph is skipped automatically when the card is already full-bleed (≈full
868
+ * viewport height), so a dedicated full-page chat is left untouched. The
869
+ * morph uses the View Transitions API where available and falls back to an
870
+ * instant swap. `open()`/`close()`/`toggle()` are available on the handle
871
+ * (no-ops on a desktop viewport).
872
+ * - With `placement: "left" | "right"`: the side panel squares off to a true
873
+ * full-screen sheet on mobile (the slide-in/out mechanics are unchanged).
874
+ */
875
+ mobile?: {
876
+ /** Max viewport width (px) treated as "mobile". Defaults to `768`. */
877
+ breakpoint?: number;
878
+ /**
879
+ * Inline placement only: how the card enters full screen. `"focus"` (default)
880
+ * expands when the input is tapped/focused; `"manual"` expands only via
881
+ * `widget.open()`. Ignored for side placements (driven by the launcher).
882
+ */
883
+ trigger?: "focus" | "manual";
884
+ };
847
885
  /**
848
886
  * Load the visitor's conversation list into `widget.threads` on mount and refresh
849
887
  * it after each turn (one `GET /conversations` per load). Off by default to avoid
@@ -876,6 +914,16 @@ export declare interface MountChatWidgetOptions {
876
914
  * render the suggestions as non-interactive.
877
915
  */
878
916
  onFollowUpClick?: ((reply: string) => void) | false;
917
+ /**
918
+ * Called when the panel opens: a side panel opening, or an inline card
919
+ * expanding to full screen on mobile.
920
+ */
921
+ onOpen?: () => void;
922
+ /**
923
+ * Called when the panel closes: a side panel closing, or an inline card
924
+ * collapsing from full screen on mobile.
925
+ */
926
+ onClose?: () => void;
879
927
  /** Called when the user sends a message. */
880
928
  onMessageSent?: (content: string) => void;
881
929
  /** Called when an assistant message completes. */
@@ -1047,7 +1095,8 @@ export declare type WelcomeMessage = string | {
1047
1095
  };
1048
1096
 
1049
1097
  /**
1050
- * Theme overrides for {@link mountChatWidget}. *
1098
+ * Theme overrides for `mountChatWidget`. The keys map to `--ago-*` custom
1099
+ * properties (see `THEME_VARS` in `./styles`).
1051
1100
  * @see The `--ago-*` token reference in `docs/general/widget.md`.
1052
1101
  */
1053
1102
  export declare interface WidgetTheme {