@useago/sdk 1.1.0 → 1.3.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/index.d.cts CHANGED
@@ -453,17 +453,6 @@ export declare class AgoStreamError extends AgoError {
453
453
  constructor(message: string, code?: string);
454
454
  }
455
455
 
456
- /**
457
- * Widget configuration types.
458
- *
459
- * These types describe the `window.AGO` configuration object
460
- * used by the embeddable chat widget snippet.
461
- *
462
- * @example
463
- * ```ts
464
- * import type { AgoWidgetConfig } from "@useago/sdk/widget";
465
- * ```
466
- */
467
456
  export declare interface AgoWidgetColors {
468
457
  button?: string;
469
458
  header?: string;
package/dist/index.d.ts CHANGED
@@ -453,17 +453,6 @@ export declare class AgoStreamError extends AgoError {
453
453
  constructor(message: string, code?: string);
454
454
  }
455
455
 
456
- /**
457
- * Widget configuration types.
458
- *
459
- * These types describe the `window.AGO` configuration object
460
- * used by the embeddable chat widget snippet.
461
- *
462
- * @example
463
- * ```ts
464
- * import type { AgoWidgetConfig } from "@useago/sdk/widget";
465
- * ```
466
- */
467
456
  export declare interface AgoWidgetColors {
468
457
  button?: string;
469
458
  header?: string;
package/dist/widget.cjs CHANGED
@@ -1,5 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("./AgoClient-CzSmJQxl.cjs"),Ye=require("./createFormCollector-BB3Uscuo.cjs"),Et=require("./createConversationSession-DV0Xp_3O.cjs");var St={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function Q(r){return r.replace(/[&<>"']/g,o=>St[o])}function Ze(r){const o=r.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var at='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',ge="";function j(r){const o=[],a=m=>(o.push(m),`${ge}${o.length-1}${ge}`);let n=r;return n=n.replace(/`([^`]+)`/g,(m,i)=>a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${at}">${Q(i)}</code>`)),n=n.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(m,i,E)=>{const p=Ze(E);return p?a(`<img alt="${Q(i)}" src="${Q(p)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):m}),n=n.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(m,i,E)=>{const p=Ze(E);return p?a(`<a href="${Q(p)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${j(i)}</a>`):m}),n=Q(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(`${ge}(\\d+)${ge}`,"g"),(m,i)=>o[Number(i)]),n}function T(r,o,a){const n=document.createElement(r);return Object.assign(n.style,o),a!==void 0&&(n.innerHTML=a),n}var it=/^ {0,3}([-*_])( *\1){2,} *$/,st=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,lt=/^ {0,3}(```+|~~~+)/,me=/^ {0,3}>\s?/,ee=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Rt=["20px","18px","16px","15px","14px","13px"],Te=r=>r.match(/^\s*/)?.[0].length??0;function _t(r){return r.trim()===""||it.test(r)||st.test(r)||lt.test(r)||me.test(r)||ee.test(r)}function dt(r){const o=r[0].match(ee),a=o[1].length,n=/\d/.test(o[2]),m=T(n?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:n?"decimal":"disc",listStylePosition:"outside"});let i=0;for(;i<r.length;){const E=r[i].match(ee),p=[];for(i++;i<r.length&&Te(r[i])>a;)p.push(r[i]),i++;const v=T("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),d=E[3].match(/^\[([ xX])\]\s+(.*)$/);d?(v.style.listStyleType="none",v.style.marginLeft="-20px",v.innerHTML=`<span style="margin-right:6px">${d[1].toLowerCase()==="x"?"☑":"☐"}</span>${j(d[2])}`):v.innerHTML=j(E[3]),p.filter(x=>ee.test(x)).length>0&&v.appendChild(dt(p.filter(x=>x.trim()!==""))),m.appendChild(v)}return m}function kt(r){const o=p=>p.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(v=>v.trim()),a=T("div",{overflowX:"auto",margin:"0 0 8px 0"}),n=T("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),m=document.createElement("thead"),i=document.createElement("tr");for(const p of o(r[0]))i.appendChild(T("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},j(p)));m.appendChild(i),n.appendChild(m);const E=document.createElement("tbody");for(const p of r.slice(2)){const v=document.createElement("tr");for(const d of o(p))v.appendChild(T("td",{border:"1px solid #dee3e8",padding:"6px 10px"},j(d)));E.appendChild(v)}return n.appendChild(E),a.appendChild(n),a}var At=r=>!!r&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(r);function be(r){const o=document.createDocumentFragment(),a=r.replace(/\r\n?/g,`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ae=require("./AgoClient-CzSmJQxl.cjs"),dt=require("./createFormCollector-BB3Uscuo.cjs"),Gt=require("./createConversationSession-DV0Xp_3O.cjs");var jt='"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',Se=`var(--ago-font, ${jt})`,ct={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"},ke="var(--ago-brand-color, #03182f)",Ae="var(--ago-brand-text-color, #fff)",Vt="var(--ago-header-background, var(--ago-brand-color, #03182f))",pt="var(--ago-header-text-color, #e8f0fe)",ee="var(--ago-panel-background, #fff)",ht="var(--ago-messages-background, #fbfbfb)",J="var(--ago-text-color, #30373e)",xt="var(--ago-muted-text-color, #6b6d6f)",L="var(--ago-border-color, #dee3e8)",Be="var(--ago-accent-color, #1b5fc4)",ft="var(--ago-agent-bubble-background, #f1f3f5)",qt="var(--ago-radius, 16px)",De="var(--ago-message-radius, 16px)",Kt="var(--ago-message-radius, 20px)";function Xt(n,o){if(o)for(const i of Object.keys(ct)){const r=o[i];r!=null&&n.style.setProperty(ct[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 ut="ago-chat-widget-keyframes";function Qt(){if(typeof document>"u"||document.getElementById(ut))return;const n=document.createElement("style");n.id=ut,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:Se,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:ke,color:Ae,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((G,j)=>j!==c),Y()}),y.append(T,k),r.appendChild(y)}),A()}const B=()=>{const s=a.value,c=o;return a.value="",C(),o=[],Y(),{content:s,files:c}},g=()=>{const{content:s,files:c}=B();(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:B,setDisabled:s=>{a.disabled=s,f=s,A()},focus:()=>a.focus()}}var Zt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function ie(n){return n.replace(/[&<>"']/g,o=>Zt[o])}function mt(n){const o=n.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var bt='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Ee="";function te(n){const o=[],i=b=>(o.push(b),`${Ee}${o.length-1}${Ee}`);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:${bt}">${ie(a)}</code>`)),r=r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=mt(C);return m?i(`<img alt="${ie(a)}" src="${ie(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):b}),r=r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=mt(C);return m?i(`<a href="${ie(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`):b}),r=ie(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}function O(n,o,i){const r=document.createElement(n);return Object.assign(r.style,o),i!==void 0&&(r.innerHTML=i),r}var vt=/^ {0,3}([-*_])( *\1){2,} *$/,yt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,wt=/^ {0,3}(```+|~~~+)/,Re=/^ {0,3}>\s?/,se=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Jt=["20px","18px","16px","15px","14px","13px"],ze=n=>n.match(/^\s*/)?.[0].length??0;function en(n){return n.trim()===""||vt.test(n)||yt.test(n)||wt.test(n)||Re.test(n)||se.test(n)}function Ct(n){const o=n[0].match(se),i=o[1].length,r=/\d/.test(o[2]),b=O(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(se),m=[];for(a++;a<n.length&&ze(n[a])>i;)m.push(n[a]),a++;const x=O("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=>se.test(f)).length>0&&x.appendChild(Ct(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=O("div",{overflowX:"auto",margin:"0 0 8px 0"}),r=O("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),b=document.createElement("thead"),a=document.createElement("tr");for(const m of o(n[0]))a.appendChild(O("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(O("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 _e(n){const o=document.createDocumentFragment(),i=n.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 E=i.match(lt);if(E){const d=E[1][0],x=[];for(n++;n<a.length&&!new RegExp(`^ {0,3}${d==="`"?"`{3,}":"~{3,}"}\\s*$`).test(a[n]);)x.push(a[n]),n++;n++;const B=T("pre",{margin:"0 0 8px 0"});B.appendChild(T("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:at,whiteSpace:"pre"},Q(x.join(`
4
- `)))),o.appendChild(B);continue}if(it.test(i)){o.appendChild(T("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),n++;continue}const p=i.match(st);if(p){const d=p[1].length;o.appendChild(T(`h${d}`,{margin:"16px 0 8px 0",fontSize:Rt[d-1],fontWeight:"600",lineHeight:"1.3"},j(p[2]))),n++;continue}if(me.test(i)){const d=[];for(;n<a.length&&me.test(a[n]);)d.push(a[n].replace(me,"")),n++;const x=T("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});x.appendChild(be(d.join(`
5
- `))),o.appendChild(x);continue}if(i.includes("|")&&At(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(kt(d));continue}if(ee.test(i)){const d=[],x=Te(i);for(;n<a.length&&a[n].trim()!=="";)if(ee.test(a[n])||Te(a[n])>x)d.push(a[n]),n++;else break;o.appendChild(dt(d));continue}const v=[i];for(n++;n<a.length&&!_t(a[n]);)v.push(a[n]),n++;o.appendChild(T("p",{margin:"0 0 8px 0",lineHeight:"1.6"},v.map(d=>j(d)).join("<br>")))}const m=o.lastElementChild;return m&&(m.style.marginBottom="0"),o}var Le='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Qe={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"},he="var(--ago-brand-color, #03182f)",xe="var(--ago-brand-text-color, #fff)",It="var(--ago-header-background, var(--ago-brand-color, #03182f))",Je="var(--ago-header-text-color, #e8f0fe)",J="var(--ago-panel-background, #fff)",et="var(--ago-messages-background, #fbfbfb)",ie="var(--ago-text-color, #30373e)",tt="var(--ago-muted-text-color, #6b6d6f)",$="var(--ago-border-color, #dee3e8)",Ne="var(--ago-accent-color, #1b5fc4)",nt="var(--ago-agent-bubble-background, #f1f3f5)",Nt="var(--ago-radius, 16px)",$e="var(--ago-message-radius, 16px)",$t="var(--ago-message-radius, 20px)";function Tt(r,o){if(o)for(const a of Object.keys(Qe)){const n=o[a];n!=null&&r.style.setProperty(Qe[a],n)}}function w(r,o){Object.assign(r.style,o)}function f(r={}){const o=document.createElement("div");return w(o,r),o}var ot="Form submitted.";function Lt(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 rt="ago-chat-widget-keyframes";function Ot(){if(typeof document>"u"||document.getElementById(rt))return;const r=document.createElement("style");r.id=rt,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 Dt(r){const o=typeof r=="string"?document.querySelector(r):r;if(!o)throw new Error(`mountChatWidget: target "${String(r)}" not found.`);return o}function Bt(r,o){const{title:a="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:m="Type a message...",allowFiles:i=!1,height:E=500,placement:p="inline",width:v=400,defaultOpen:d=!1,logoUrl:x,showAgentName:B=!1,agentBubble:L=!1,bubbleStyle:O="default",showHeader:te=!0,theme:se,loadThreads:ne=!1,forms:b,formSubmittedMessage:S=ot,onFollowUpClick:q,onMessageSent:le,onMessageReceived:z,onFormSubmitted:de,onFormError:oe}=o,ce=typeof n=="string"?{message:n,mode:"static"}:n,Oe=ce.message,De=ce.mode??"static",ct="speed"in ce&&ce.speed||45;if(!o.client&&!o.config?.baseUrl)throw new Z.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const C=o.client??new Z.AgoClient(o.config),Be=Dt(r),X=p==="left"||p==="right",pt=X&&(o.launcher??!0);let K=X?d:!0;const Ce=o.persistConversation,pe=Ce?Et.createConversationSession(Ce===!0?{}:Ce):void 0;let D=o.conversationId??pe?.getLastActiveThread()??void 0,l=[],H=!1,re=null,F;const Me=[];function ft(e){if(typeof S=="function"){const s=S(e);if(typeof s=="string"&&s)return s}const t=Lt(e);return t||(typeof S=="string"?S:ot)}const fe=[],V=f({display:"flex",flexDirection:"column",height:X?"100%":typeof E=="number"?`${E}px`:E,border:`1px solid ${$}`,borderRadius:Nt,overflow:"hidden",backgroundColor:J,fontFamily:Le,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});V.className="ago-chat-widget",Tt(V,se);let W;if(te){if(W=f({padding:"14px 16px",borderBottom:`1px solid ${$}`,backgroundColor:It,color:Je,display:"flex",alignItems:"center",gap:"10px"}),W.className="ago-chat-widget__header",x){const t=document.createElement("img");t.src=x,t.alt="Logo",w(t,{height:"24px",width:"auto"}),W.appendChild(t)}const e=document.createElement("h3");if(e.textContent=a,w(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),W.appendChild(e),X){const t=document.createElement("button");t.type="button",t.className="ago-chat-widget__close",t.setAttribute("aria-label","Close"),t.textContent="×",w(t,{marginLeft:"auto",background:"transparent",border:"none",color:Je,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),t.addEventListener("click",()=>ke()),W.appendChild(t)}}const k=f({flex:"1",overflow:"auto",padding:"16px",backgroundColor:et});k.className="ago-chat-widget__messages",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),k.setAttribute("aria-relevant","additions text"),k.setAttribute("aria-atomic","false");const{inputRow:ut,setDisabled:gt,focus:ve}=Mt({placeholder:m,allowFiles:i,onSend:(e,t)=>{Ee(e,t)}});Ot(),V.append(...W?[W]:[],k,ut);let ue=V,U,A;const ye=p==="left"?"left":"right";if(X&&(U=f({position:"fixed",top:"0",bottom:"0",[ye]:"0",width:typeof v=="number"?`${v}px`:v,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",w(V,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ye==="left"?"borderRight":"borderLeft"]:`1px solid ${$}`}),U.appendChild(V),ue=U),pt){if(A=document.createElement("button"),A.type="button",A.className="ago-chat-widget-launcher",A.setAttribute("aria-label",`Open ${a}`),w(A,{position:"fixed",bottom:"20px",[ye]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:he,color:xe,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:Le}),x){const e=document.createElement("img");e.src=x,e.alt="",w(e,{width:"26px",height:"26px",objectFit:"contain"}),A.appendChild(e)}else A.appendChild(yt());A.addEventListener("click",()=>_e())}Be.appendChild(ue),A&&Be.appendChild(A),Re();const ze=q!==!1,Fe=q===!1?void 0:q??(e=>{Ee(e)});function mt(e,t,s=!0){const c=e.role==="user",u=O==="imessage",R=f({display:"flex",flexDirection:"column",alignItems:c?"flex-end":"flex-start",marginBottom:u&&!s?"2px":"16px"});if(R.className=`ago-message ago-message--${e.role}`,!c&&B&&e.agent){const g=f({fontSize:"13px",fontWeight:"500",color:ie,marginBottom:"6px",padding:"0 4px"});g.className="ago-message__agent",g.textContent=e.agent.displayName||e.agent.name,R.appendChild(g)}if(!c&&e.sources&&e.sources.length>0){const g=f({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});g.className="ago-message__sources",e.sources.forEach((h,y)=>{const _=h.url?document.createElement("a"):document.createElement("div");h.url&&_ instanceof HTMLAnchorElement&&(_.href=h.url,_.target="_blank",_.rel="noopener noreferrer"),w(_,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${$}`,borderRadius:"8px",backgroundColor:J,textDecoration:"none",color:ie,fontSize:"12px",overflow:"hidden"});const P=f({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"});P.textContent=String(y+1);const G=f({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});G.textContent=h.title,G.title=h.title,_.append(P,G),g.appendChild(_)}),R.appendChild(g)}if(e.attachments&&e.attachments.length>0){const g=f({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:c?"flex-end":"flex-start",maxWidth:"75%"});g.className="ago-message__attachments";for(const h of e.attachments){const y=Z.safeAttachmentUrl(h.url);if(Z.canInlineImage(h)&&y){const M=document.createElement("a");M.href=y,M.target="_blank",M.rel="noopener noreferrer",w(M,{display:"inline-block",textDecoration:"none"});const ae=document.createElement("img");ae.src=y,ae.alt=h.name,ae.loading="lazy",w(ae,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${$}`,display:"block"}),M.appendChild(ae),g.appendChild(M);continue}const _=y?document.createElement("a"):document.createElement("div");y&&_ instanceof HTMLAnchorElement&&(_.href=y,_.target="_blank",_.rel="noopener noreferrer"),w(_,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${$}`,backgroundColor:c?"rgba(255,255,255,0.12)":J,color:c?xe:ie,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const P=document.createElement("span");P.textContent="📄",P.setAttribute("aria-hidden","true"),w(P,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const G=f({display:"flex",flexDirection:"column",minWidth:"0"}),Ie=f({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});Ie.textContent=h.name,Ie.title=h.name,G.appendChild(Ie);const Ve=Z.formatFileSize(h.fileSize);if(Ve){const M=f({fontSize:"11px",color:tt});M.textContent=Ve,G.appendChild(M)}_.append(P,G),g.appendChild(_)}R.appendChild(g)}const N=c||L||u,Ae=!!e.content||e.status==="IN_PROGRESS",Y=f({maxWidth:u||c?"75%":N?"85%":"100%",padding:N?"10px 14px":"2px 8px",borderRadius:u?$t:N?$e:"0",backgroundColor:c?he:N?nt:"transparent",color:c?xe:ie,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(Y.className="ago-message__content",u&&s){Y.style.position="relative";const g=f({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:c?he:nt});g.className="ago-message__tail";const h=f({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:et});h.className="ago-message__tail-mask",c?(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"),Y.append(g,h)}if(e.content?Y.appendChild(be(e.content)):e.status==="IN_PROGRESS"&&Y.appendChild(wt()),Ae&&R.appendChild(Y),t&&e.followUpReplies&&e.followUpReplies.length>0){const g=f({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});g.className="ago-message__followups";for(const h of e.followUpReplies){const y=document.createElement("button");y.type="button",y.className="ago-message__followup-btn",y.textContent=h,y.disabled=!ze,w(y,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:$e,border:`1px solid ${$}`,backgroundColor:J,color:ie,cursor:ze?"pointer":"default",transition:"border-color 0.15s"}),Fe&&y.addEventListener("click",()=>Fe(h)),y.addEventListener("mouseenter",()=>{y.style.borderColor=Ne}),y.addEventListener("mouseleave",()=>{y.style.borderColor=$}),g.appendChild(y)}R.appendChild(g)}return R}function ht(e){const t=f({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:$e,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"),w(s,{fontWeight:"700"});const c=document.createElement("span");return c.textContent=e,t.append(s,c),t}function I(){if(k.replaceChildren(),l.length===0){if(De==="static"){const t=f({textAlign:"center",color:tt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});t.appendChild(be(Oe)),k.appendChild(t)}}else l.forEach((t,s)=>{const c=s===l.length-1||l[s+1].role!==t.role;k.appendChild(mt(t,s===l.length-1,c))});for(const t of Me)k.appendChild(ht(t));if(re){const t=f({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});t.setAttribute("role","alert"),t.textContent=re,k.appendChild(t)}k.scrollTop=k.scrollHeight;const e=l[l.length-1];gt(H&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function xt(){for(let e=l.length-1;e>=0;e--){const t=l[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const He=e=>{D||(D=e.conversationId)},We=e=>{const t=xt();t&&(t.content+=e.content,I())},Ue=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),I(),ve()},Pe=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,I(),e.status==="DONE"&&z?.({id:e.id,content:e.content})},Ge=e=>{re=e.error,H=!1,l=l.filter(t=>!t.id.startsWith("temp-")),I()};function bt(e){const t={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l.push(t),I();const s=e.match(/\S+\s*/g)??[e];let c=0;F=setInterval(()=>{if(c>=s.length){clearInterval(F),F=void 0,t.status="DONE",I();return}t.content+=s[c],c++,I()},ct)}C.on("message:start",He),C.on("message:chunk",We),C.on("message:answer-complete",Ue),C.on("message:complete",Pe),C.on("message:error",Ge);const je=e=>de?.(e),qe=e=>oe?.(e);de&&C.on("form:submitted",je),oe&&C.on("form:error",qe);const we=[];let Xe=!1;const Ke=e=>{if(Xe)return;we.push(e.install(C));let t=e.store.get().submitted;const s=e.store.subscribe(c=>{c.submitted&&!t&&(Me.push(ft(c.submitResult)),I()),t=c.submitted});we.push(s)};for(const e of b??[])e.schema!=null?Ke(Ye.createFormCollector(e)):Ye.loadFormCollector(C,e).then(t=>Ke(t)).catch(()=>{});async function Ee(e,t){const s=e.trim();if(!s&&!t?.length||H)return;if(le?.(s),H=!0,re=null,F){clearInterval(F),F=void 0;const u=l.find(R=>R.id.startsWith("ago-intro-"));u&&!u.content?l=l.filter(R=>R!==u):u&&(u.status="DONE")}const c=Date.now();l.push({id:`temp-user-${c}`,conversationId:D||"",content:s,role:"user",status:"DONE",attachments:t&&t.length>0?Z.attachmentsFromFiles(t):void 0,createdAt:new Date}),l.push({id:`temp-assistant-${c}`,conversationId:D||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),I();try{const u=await C.sendMessage(s,{conversationId:D,files:t});u.conversationId&&(D||(D=u.conversationId),pe?.setActiveThread(u.conversationId,u.createdAt));const R=l.find(N=>N.id===`temp-user-${c}`);if(R&&(R.id=`user-${c}`,R.conversationId=u.conversationId),!l.some(N=>N.id===u.id)){const N=l.findIndex(Ae=>Ae.id===`temp-assistant-${c}`);N>=0?l[N]=u:l.push(u)}l=l.filter(N=>!N.id.startsWith("temp-")),H=!1,I(),ne&&Se()}catch(u){re=u instanceof Error?u.message:"Failed to send message",H=!1,l=l.filter(R=>!R.id.startsWith("temp-")),I()}}async function Se(){try{const e=await C.getConversations();fe.splice(0,fe.length,...e)}catch{}return fe}async function Ct(e){try{const t=(await C.getConversation(e))?.messages??[];t.length>0&&l.length===0&&(l=t,I())}catch{l.length===0&&(pe?.clear(),D=void 0)}}return I(),ve(),D?Ct(D):De==="streaming"&&bt(Oe),ne&&Se(),{client:C,element:ue,sendMessage:Ee,...X?{open:_e,close:ke,toggle:vt}:{},session:pe,threads:fe,refreshThreads:Se,destroy(){F&&clearInterval(F),C.off("message:start",He),C.off("message:chunk",We),C.off("message:answer-complete",Ue),C.off("message:complete",Pe),C.off("message:error",Ge),de&&C.off("form:submitted",je),oe&&C.off("form:error",qe),Xe=!0,we.forEach(e=>e()),ue.remove(),A?.remove(),o.client||C.destroy()}};function Re(){if(!U)return;const e=p==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=K?"translateX(0)":e,U.setAttribute("aria-hidden",K?"false":"true"),A&&(A.style.display=K?"none":"flex")}function _e(){K=!0,Re(),ve()}function ke(){K=!1,Re()}function vt(){K?ke():_e()}function yt(){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 wt(){const e=f({display:"flex",gap:"4px",padding:"4px 0"});for(let t=0;t<3;t++){const s=f({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 Mt(r){let o=[];const a=document.createElement("form");w(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${$}`,backgroundColor:J}),a.className="ago-chat-input";const n=f({display:"flex",flexWrap:"wrap",gap:"6px"}),m=f({display:"flex",gap:"8px",alignItems:"flex-end"}),i=document.createElement("textarea");i.placeholder=r.placeholder,i.setAttribute("aria-label",r.placeholder),i.rows=1,w(i,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",fontSize:"16px",fontFamily:Le,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const E=()=>{i.style.height="auto";const S=Math.min(i.scrollHeight+2,110);i.style.height=`${S}px`,i.style.overflowY=i.scrollHeight+2>110?"auto":"hidden"};i.addEventListener("input",()=>{E(),B()});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>',v='<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,w(d,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:he,color:xe,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let x=!1;const B=()=>{const b=i.value.trim()!==""||o.length>0,S=x||!b;d.disabled=S,d.innerHTML=x?v:p,d.style.opacity=S&&!x?"0.5":"1",d.style.cursor=S?"default":"pointer"};let L=null,O=null;r.allowFiles&&(L=document.createElement("input"),L.type="file",L.multiple=!0,w(L,{display:"none"}),O=document.createElement("button"),O.type="button",O.setAttribute("aria-label","Attach file"),O.textContent="📎",w(O,{padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",backgroundColor:J,cursor:"pointer",fontSize:"14px"}),O.addEventListener("click",()=>L?.click()),L.addEventListener("change",()=>{o=[...o,...Array.from(L?.files??[])],te()}));function te(){n.replaceChildren(),o.forEach((b,S)=>{const q=f({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${$}`,borderRadius:"8px",fontSize:"12px"}),le=document.createElement("span");le.textContent=b.name;const z=document.createElement("button");z.type="button",z.setAttribute("aria-label",`Remove ${b.name}`),z.textContent="×",w(z,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),z.addEventListener("click",()=>{o=o.filter((de,oe)=>oe!==S),te()}),q.append(le,z),n.appendChild(q)}),B()}const se=()=>{const b=i.value,S=o;return i.value="",E(),o=[],te(),{content:b,files:S}},ne=()=>{const{content:b,files:S}=se();(b.trim()||S.length>0)&&r.onSend(b.trim(),S.length>0?S:void 0)};return a.addEventListener("submit",b=>{b.preventDefault(),ne()}),i.addEventListener("keydown",b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),ne())}),O&&m.appendChild(O),m.append(i,d),L&&a.appendChild(L),a.append(n,m),B(),{inputRow:a,getValueAndClear:se,setDisabled:b=>{i.disabled=b,x=b,B()},focus:()=>i.focus()}}exports.mountChatWidget=Bt;exports.renderMarkdown=be;
3
+ `);let r=0;for(;r<i.length;){const a=i[r];if(a.trim()===""){r++;continue}const C=a.match(wt);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=O("pre",{margin:"0 0 8px 0"});A.appendChild(O("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:bt,whiteSpace:"pre"},ie(f.join(`
4
+ `)))),o.appendChild(A);continue}if(vt.test(a)){o.appendChild(O("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),r++;continue}const m=a.match(yt);if(m){const p=m[1].length;o.appendChild(O(`h${p}`,{margin:"16px 0 8px 0",fontSize:Jt[p-1],fontWeight:"600",lineHeight:"1.3"},te(m[2]))),r++;continue}if(Re.test(a)){const p=[];for(;r<i.length&&Re.test(i[r]);)p.push(i[r].replace(Re,"")),r++;const f=O("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});f.appendChild(_e(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(se.test(a)){const p=[],f=ze(a);for(;r<i.length&&i[r].trim()!=="";)if(se.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(O("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=ae.safeAttachmentUrl(s.url);if(ae.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 V=document.createElement("img");V.src=c,V.alt=s.name,V.loading="lazy",v(V,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${L}`,display:"block"}),M.appendChild(V),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?Ae: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"}),G=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});G.textContent=s.name,G.title=s.name,k.appendChild(G);const j=ae.formatFileSize(s.fileSize);if(j){const M=h({fontSize:"11px",color:xt});M.textContent=j,k.appendChild(M)}y.append(T,k),g.appendChild(y)}R.appendChild(g)}const _=f||C||A,Y=!!n.content||n.status==="IN_PROGRESS",B=h({maxWidth:_?A||f?p?"88%":"75%":p?"92%":"85%":"100%",padding:_?"10px 14px":"2px 8px",borderRadius:A?Kt:_?De:"0",backgroundColor:f?ke:_?ft:"transparent",color:f?Ae:J,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(B.className="ago-message__content",A&&r){B.style.position="relative";const g=h({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:f?ke: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"),B.append(g,s)}if(n.content?B.appendChild(_e(n.content)):n.status==="IN_PROGRESS"&&B.appendChild(an()),Y&&R.appendChild(B),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:B,loadThreads:g=!1,forms:s,formSubmittedMessage:c=gt,onFollowUpClick:y,onMessageSent:T,onMessageReceived:k,onFormSubmitted:G,onFormError:j,onOpen:M,onClose:V}=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 ae.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const E=o.client??new ae.AgoClient(o.config),Ue=cn(n),D=m==="left"||m==="right",St=D&&(o.launcher??!0);let oe=D?p:!0;const Rt=o.mobile?.breakpoint??768,kt=o.mobile?.trigger??"focus",We=typeof window<"u"&&!!window.matchMedia,z=We?window.matchMedia(`(max-width: ${Rt}px)`):void 0,At=We?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,le=!D&&!!z,Ie=o.persistConversation,me=Ie?Gt.createConversationSession(Ie===!0?{}:Ie):void 0;let P=o.conversationId??me?.getLastActiveThread()??void 0,u=[],Z=!1,de=null,q;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 ge=[],d=h({display:"flex",flexDirection:"column",height:D?"100%":typeof C=="number"?`${C}px`:C,border:`1px solid ${L}`,borderRadius:qt,overflow:"hidden",backgroundColor:ee,fontFamily:Se,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",Xt(d,B);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),D){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:$e,setDisabled:It,focus:he}=Yt({placeholder:b,allowFiles:a,onSend:(e,t)=>{Ne(e,t)}});Qt(),d.append(...F?[F]:[],I,$e);let xe=d,U,N;const be=m==="left"?"left":"right";if(D&&(U=h({position:"fixed",top:"0",bottom:"0",[be]:"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",[be==="left"?"borderRight":"borderLeft"]:`1px solid ${L}`}),U.appendChild(d),xe=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",[be]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:ke,color:Ae,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:Se}),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=le?`ago-vt-${++dn}`:"",je=52;let K=!1,pe=0,re=0,H,fe,X;const ve={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};Ue.appendChild(xe),N&&Ue.appendChild(N),ye(),le&&(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=>{K||!z?.matches||$e.contains(e.target)&&(e.preventDefault(),Ce())},!0),d.addEventListener("focusin",e=>{z?.matches&&$e.contains(e.target)&&Ce()})),document.addEventListener("keydown",tt)),z&&z.addEventListener("change",nt);const $t=y!==!1,Lt=y===!1?void 0:y??(e=>{Ne(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(_e(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:!!z?.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),$(),he()},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;q=setInterval(()=>{if(S>=l.length){clearInterval(q),q=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=>G?.(e),Ze=e=>j?.(e);G&&E.on("form:submitted",Ye),j&&E.on("form:error",Ze);const Le=[];let Je=!1;const et=e=>{if(Je)return;Le.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});Le.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 Ne(e,t){const l=e.trim();if(!l&&!t?.length||Z)return;if(T?.(l),Z=!0,de=null,q){clearInterval(q),q=void 0;const w=u.find(W=>W.id.startsWith("ago-intro-"));w&&!w.content?u=u.filter(W=>W!==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?ae.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),me?.setActiveThread(w.conversationId,w.createdAt));const W=u.find(Q=>Q.id===`temp-user-${S}`);if(W&&(W.id=`user-${S}`,W.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(W=>!W.id.startsWith("temp-")),$()}}async function Te(){try{const e=await E.getConversations();ge.splice(0,ge.length,...e)}catch{}return ge}async function Mt(e){try{const t=(await E.getConversation(e))?.messages??[];t.length>0&&u.length===0&&(u=t,$())}catch{u.length===0&&(me?.clear(),P=void 0)}}return $(),le&&z?.matches||he(),P?Mt(P):He==="streaming"&&Tt(Fe),g&&Te(),{client:E,element:xe,sendMessage:Ne,...D||le?{open:Bt,close:Dt,toggle:zt}:{},session:me,threads:ge,refreshThreads:Te,destroy(){q&&clearInterval(q),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),G&&E.off("form:submitted",Ye),j&&E.off("form:error",Ze),Je=!0,Le.forEach(e=>e()),xe.remove(),N?.remove(),H?.remove(),fe?.remove(),X?.remove(),z?.removeEventListener("change",nt),le&&(document.removeEventListener("keydown",tt),it(),document.documentElement.style.removeProperty("overflow")),o.client||E.destroy()}};function ye(){if(!U)return;{const t=be==="left"?"border-right":"border-left";z?.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,ye(),he(),M?.()}function Oe(){oe=!1,ye(),V?.()}function Ot(){oe?Oe():Me()}function Bt(){D?Me():Ce()}function Dt(){D?Oe():ue()}function zt(){D?Ot():K?ue():Ce()}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(!K)return;if(e.key==="Escape"){ue();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){D?ye():!e.matches&&K&&ue(),$()}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 we(){re||(re=requestAnimationFrame(()=>{re=0,rt()}))}function Ht(){window.visualViewport?.addEventListener("resize",we),window.visualViewport?.addEventListener("scroll",we)}function it(){window.visualViewport?.removeEventListener("resize",we),window.visualViewport?.removeEventListener("scroll",we),re&&(cancelAnimationFrame(re),re=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:Se});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",()=>{ue()}),e.appendChild(t),e}function Ut(){return typeof document.startViewTransition=="function"&&!At?.matches&&!!z?.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=ve.height,d.style.border=ve.border,d.style.borderRadius=ve.borderRadius,d.style.boxShadow=ve.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 Ce(){if(K||!z?.matches)return Promise.resolve();const e=d.getBoundingClientRect();if(e.height>=ot()*.8)return Promise.resolve();K=!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(),he()}),at(),M?.(),t}function ue(){if(!K)return Promise.resolve();K=!1,it(),d.querySelector("textarea")?.blur();const e=st(()=>lt(!1));return e.then(()=>d.style.removeProperty("--ago-vh")),pe=0,V?.(),e}}exports.mountChatWidget=pn;exports.renderMarkdown=_e;
package/dist/widget.d.cts CHANGED
@@ -398,17 +398,6 @@ declare interface AgoSource {
398
398
  url?: string;
399
399
  }
400
400
 
401
- /**
402
- * Widget configuration types.
403
- *
404
- * These types describe the `window.AGO` configuration object
405
- * used by the embeddable chat widget snippet.
406
- *
407
- * @example
408
- * ```ts
409
- * import type { AgoWidgetConfig } from "@useago/sdk/widget";
410
- * ```
411
- */
412
401
  export declare interface AgoWidgetColors {
413
402
  button?: string;
414
403
  header?: string;
@@ -438,7 +427,7 @@ export declare interface AgoWidgetConfig {
438
427
  metadata?: Record<string, unknown>;
439
428
  }
440
429
 
441
- /** Handle returned by {@link mountChatWidget}. */
430
+ /** Handle returned by `mountChatWidget`. */
442
431
  export declare interface ChatWidgetHandle {
443
432
  /** The AGO client backing the widget. */
444
433
  client: AgoClient;
@@ -447,8 +436,9 @@ export declare interface ChatWidgetHandle {
447
436
  /** Programmatically send a message (same path as the input). */
448
437
  sendMessage: (content: string, files?: File[]) => Promise<void>;
449
438
  /**
450
- * Open / close / toggle the side panel. Present only for
451
- * `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).
452
442
  */
453
443
  open?: () => void;
454
444
  close?: () => void;
@@ -778,7 +768,7 @@ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCEL
778
768
  export declare function mountChatWidget(target: string | HTMLElement, options: MountChatWidgetOptions): ChatWidgetHandle;
779
769
 
780
770
  /**
781
- * Options for {@link mountChatWidget} — the framework-agnostic (pure TS/JS)
771
+ * Options for `mountChatWidget` — the framework-agnostic (pure TS/JS)
782
772
  * equivalent of the React `<ChatWidget>` component. Same features: conversational
783
773
  * forms (form creator) and clickable suggested replies.
784
774
  */
@@ -867,6 +857,31 @@ export declare interface MountChatWidgetOptions {
867
857
  * Theme overrides so the panel blends into the host page.
868
858
  */
869
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
+ };
870
885
  /**
871
886
  * Load the visitor's conversation list into `widget.threads` on mount and refresh
872
887
  * it after each turn (one `GET /conversations` per load). Off by default to avoid
@@ -899,6 +914,16 @@ export declare interface MountChatWidgetOptions {
899
914
  * render the suggestions as non-interactive.
900
915
  */
901
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;
902
927
  /** Called when the user sends a message. */
903
928
  onMessageSent?: (content: string) => void;
904
929
  /** Called when an assistant message completes. */
@@ -1067,10 +1092,20 @@ export declare type WelcomeMessage = string | {
1067
1092
  message: string;
1068
1093
  mode?: "static" | "streaming";
1069
1094
  speed?: number;
1095
+ /**
1096
+ * Suggested follow-up replies rendered as clickable pills under the
1097
+ * greeting once it finishes typing. Only applies to `mode: "streaming"`
1098
+ * (the static empty-state has no message bubble to attach them to).
1099
+ * Clicking one behaves exactly like a backend follow-up reply: it sends
1100
+ * the text as the first message, unless {@link MountChatWidgetOptions.onFollowUpClick}
1101
+ * intercepts or disables it.
1102
+ */
1103
+ followUpReplies?: string[];
1070
1104
  };
1071
1105
 
1072
1106
  /**
1073
- * Theme overrides for {@link mountChatWidget}. *
1107
+ * Theme overrides for `mountChatWidget`. The keys map to `--ago-*` custom
1108
+ * properties (see `THEME_VARS` in `./styles`).
1074
1109
  * @see The `--ago-*` token reference in `docs/general/widget.md`.
1075
1110
  */
1076
1111
  export declare interface WidgetTheme {
package/dist/widget.d.ts CHANGED
@@ -398,17 +398,6 @@ declare interface AgoSource {
398
398
  url?: string;
399
399
  }
400
400
 
401
- /**
402
- * Widget configuration types.
403
- *
404
- * These types describe the `window.AGO` configuration object
405
- * used by the embeddable chat widget snippet.
406
- *
407
- * @example
408
- * ```ts
409
- * import type { AgoWidgetConfig } from "@useago/sdk/widget";
410
- * ```
411
- */
412
401
  export declare interface AgoWidgetColors {
413
402
  button?: string;
414
403
  header?: string;
@@ -438,7 +427,7 @@ export declare interface AgoWidgetConfig {
438
427
  metadata?: Record<string, unknown>;
439
428
  }
440
429
 
441
- /** Handle returned by {@link mountChatWidget}. */
430
+ /** Handle returned by `mountChatWidget`. */
442
431
  export declare interface ChatWidgetHandle {
443
432
  /** The AGO client backing the widget. */
444
433
  client: AgoClient;
@@ -447,8 +436,9 @@ export declare interface ChatWidgetHandle {
447
436
  /** Programmatically send a message (same path as the input). */
448
437
  sendMessage: (content: string, files?: File[]) => Promise<void>;
449
438
  /**
450
- * Open / close / toggle the side panel. Present only for
451
- * `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).
452
442
  */
453
443
  open?: () => void;
454
444
  close?: () => void;
@@ -778,7 +768,7 @@ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCEL
778
768
  export declare function mountChatWidget(target: string | HTMLElement, options: MountChatWidgetOptions): ChatWidgetHandle;
779
769
 
780
770
  /**
781
- * Options for {@link mountChatWidget} — the framework-agnostic (pure TS/JS)
771
+ * Options for `mountChatWidget` — the framework-agnostic (pure TS/JS)
782
772
  * equivalent of the React `<ChatWidget>` component. Same features: conversational
783
773
  * forms (form creator) and clickable suggested replies.
784
774
  */
@@ -867,6 +857,31 @@ export declare interface MountChatWidgetOptions {
867
857
  * Theme overrides so the panel blends into the host page.
868
858
  */
869
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
+ };
870
885
  /**
871
886
  * Load the visitor's conversation list into `widget.threads` on mount and refresh
872
887
  * it after each turn (one `GET /conversations` per load). Off by default to avoid
@@ -899,6 +914,16 @@ export declare interface MountChatWidgetOptions {
899
914
  * render the suggestions as non-interactive.
900
915
  */
901
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;
902
927
  /** Called when the user sends a message. */
903
928
  onMessageSent?: (content: string) => void;
904
929
  /** Called when an assistant message completes. */
@@ -1067,10 +1092,20 @@ export declare type WelcomeMessage = string | {
1067
1092
  message: string;
1068
1093
  mode?: "static" | "streaming";
1069
1094
  speed?: number;
1095
+ /**
1096
+ * Suggested follow-up replies rendered as clickable pills under the
1097
+ * greeting once it finishes typing. Only applies to `mode: "streaming"`
1098
+ * (the static empty-state has no message bubble to attach them to).
1099
+ * Clicking one behaves exactly like a backend follow-up reply: it sends
1100
+ * the text as the first message, unless {@link MountChatWidgetOptions.onFollowUpClick}
1101
+ * intercepts or disables it.
1102
+ */
1103
+ followUpReplies?: string[];
1070
1104
  };
1071
1105
 
1072
1106
  /**
1073
- * Theme overrides for {@link mountChatWidget}. *
1107
+ * Theme overrides for `mountChatWidget`. The keys map to `--ago-*` custom
1108
+ * properties (see `THEME_VARS` in `./styles`).
1074
1109
  * @see The `--ago-*` token reference in `docs/general/widget.md`.
1075
1110
  */
1076
1111
  export declare interface WidgetTheme {