@useago/sdk 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/widget.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const re=require("./AgoClient-D4EL6nva.cjs"),ae=require("./createFormCollector-Wb8Rr-U2.cjs"),ie=require("./createConversationSession-DtaeA418.cjs");var Y='"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';function m(s,n){Object.assign(s.style,n)}function c(s={}){const n=document.createElement("div");return m(n,s),n}var V="ago-chat-widget-keyframes";function se(){if(typeof document>"u"||document.getElementById(V))return;const s=document.createElement("style");s.id=V,s.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(s)}function le(s){const n=typeof s=="string"?document.querySelector(s):s;if(!n)throw new Error(`mountChatWidget: target "${String(s)}" not found.`);return n}function de(s,n){const{title:v="Chat",welcomeMessage:_="Hello! How can I help you today?",placeholder:N="Type a message...",allowFiles:g=!1,height:x=500,logoUrl:f,showAgentName:b=!1,loadThreads:I=!1,forms:A,onFollowUpClick:R,onMessageSent:i,onMessageReceived:C}=n;if(!n.client&&!n.config?.baseUrl)throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");const l=n.client??new re.AgoClient(n.config),T=le(s),y=n.persistConversation,D=y?ie.createConversationSession(y===!0?{}:y):void 0;let u=n.conversationId??D?.getLastActiveThread()??void 0,o=[],k=!1,W=null;const F=[],z=c({display:"flex",flexDirection:"column",height:typeof x=="number"?`${x}px`:x,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:Y,boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});z.className="ago-chat-widget";const L=c({padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"});if(L.className="ago-chat-widget__header",f){const e=document.createElement("img");e.src=f,e.alt="Logo",m(e,{height:"24px",width:"auto"}),L.appendChild(e)}const M=document.createElement("h3");M.textContent=v,m(M,{margin:"0",fontSize:"15px",fontWeight:"600"}),L.appendChild(M);const E=c({flex:"1",overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"});E.className="ago-chat-widget__messages";const{inputRow:J,setDisabled:Q,focus:X}=ce({placeholder:N,allowFiles:g,onSend:(e,t)=>{H(e,t)}});se(),z.append(L,E,J),T.appendChild(z);const O=R!==!1,$=R===!1?void 0:R??(e=>{H(e)});function Z(e){const t=e.role==="user",d=c({display:"flex",flexDirection:"column",alignItems:t?"flex-end":"flex-start",marginBottom:"16px"});if(d.className=`ago-message ago-message--${e.role}`,!t&&b&&e.agent){const r=c({fontSize:"13px",fontWeight:"500",color:"#30373e",marginBottom:"6px",padding:"0 4px"});r.className="ago-message__agent",r.textContent=e.agent.displayName||e.agent.name,d.appendChild(r)}if(!t&&e.sources&&e.sources.length>0){const r=c({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});r.className="ago-message__sources",e.sources.forEach((p,a)=>{const w=p.url?document.createElement("a"):document.createElement("div");p.url&&w instanceof HTMLAnchorElement&&(w.href=p.url,w.target="_blank",w.rel="noopener noreferrer"),m(w,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",textDecoration:"none",color:"#30373e",fontSize:"12px",overflow:"hidden"});const K=c({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});K.textContent=String(a+1);const B=c({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});B.textContent=p.title,B.title=p.title,w.append(K,B),r.appendChild(w)}),d.appendChild(r)}const h=c({maxWidth:t?"75%":"100%",padding:t?"10px 14px":"2px 8px",borderRadius:t?"16px":"0",backgroundColor:t?"#03182f":"transparent",color:t?"#fff":"#30373e",wordBreak:"break-word",fontSize:"14px",lineHeight:"1.6",whiteSpace:"pre-wrap"});if(h.className="ago-message__content",e.content?h.textContent=e.content:e.status==="IN_PROGRESS"&&h.appendChild(oe()),d.appendChild(h),e.followUpReplies&&e.followUpReplies.length>0){const r=c({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});r.className="ago-message__followups";for(const p of e.followUpReplies){const a=document.createElement("button");a.type="button",a.className="ago-message__followup-btn",a.textContent=p,a.disabled=!O,m(a,{padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:O?"pointer":"default",transition:"border-color 0.15s"}),$&&a.addEventListener("click",()=>$(p)),a.addEventListener("mouseenter",()=>{a.style.borderColor="#1b5fc4"}),a.addEventListener("mouseleave",()=>{a.style.borderColor="#dee3e8"}),r.appendChild(a)}d.appendChild(r)}return d}function S(){if(E.replaceChildren(),o.length===0){const e=c({textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"14px",lineHeight:"1.5"});e.textContent=_,E.appendChild(e)}else for(const e of o)E.appendChild(Z(e));if(W){const e=c({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});e.textContent=W,E.appendChild(e)}E.scrollTop=E.scrollHeight,Q(k)}function ee(){for(let e=o.length-1;e>=0;e--){const t=o[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const q=e=>{u||(u=e.conversationId)},P=e=>{const t=ee();t&&(t.content+=e.content,S())},G=e=>{const t=o.findIndex(d=>d.id===e.id||d.role==="assistant"&&d.status==="IN_PROGRESS");t>=0?o[t]=e:o.push(e),k=!1,S(),e.status==="DONE"&&C?.({id:e.id,content:e.content})},j=e=>{W=e.error,k=!1,o=o.filter(t=>!t.id.startsWith("temp-")),S()};l.on("message:start",q),l.on("message:chunk",P),l.on("message:complete",G),l.on("message:error",j);const te=(A??[]).map(e=>ae.createFormCollector(e).install(l));async function H(e,t){const d=e.trim();if(!d&&!t?.length||k)return;i?.(d),k=!0,W=null;const h=Date.now();o.push({id:`temp-user-${h}`,conversationId:u||"",content:d,role:"user",status:"DONE",createdAt:new Date}),o.push({id:`temp-assistant-${h}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),S();try{const r=await l.sendMessage(d,{conversationId:u,files:t});r.conversationId&&(u||(u=r.conversationId),D?.setActiveThread(r.conversationId,r.createdAt));const p=o.find(a=>a.id===`temp-user-${h}`);if(p&&(p.id=`user-${h}`,p.conversationId=r.conversationId),!o.some(a=>a.id===r.id)){const a=o.findIndex(w=>w.id===`temp-assistant-${h}`);a>=0?o[a]=r:o.push(r)}o=o.filter(a=>!a.id.startsWith("temp-")),k=!1,S(),I&&U()}catch(r){W=r instanceof Error?r.message:"Failed to send message",k=!1,o=o.filter(p=>!p.id.startsWith("temp-")),S()}}async function U(){try{const e=await l.getConversations();F.splice(0,F.length,...e)}catch{}return F}async function ne(e){try{const t=(await l.getConversation(e))?.messages??[];t.length>0&&o.length===0&&(o=t,S())}catch{o.length===0&&(D?.clear(),u=void 0)}}return S(),X(),u&&ne(u),I&&U(),{client:l,element:z,sendMessage:H,session:D,threads:F,refreshThreads:U,destroy(){l.off("message:start",q),l.off("message:chunk",P),l.off("message:complete",G),l.off("message:error",j),te.forEach(e=>e()),z.remove(),n.client||l.destroy()}};function oe(){const e=c({display:"flex",gap:"4px",padding:"4px 0"});for(let t=0;t<3;t++){const d=c({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${t*.2}s`});e.appendChild(d)}return e}}function ce(s){let n=[];const v=document.createElement("form");m(v,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"}),v.className="ago-chat-input";const _=c({display:"flex",flexWrap:"wrap",gap:"6px"}),N=c({display:"flex",gap:"8px",alignItems:"flex-end"}),g=document.createElement("textarea");g.placeholder=s.placeholder,g.rows=1,m(g,{flex:"1",resize:"none",padding:"10px 12px",border:"1px solid #dee3e8",borderRadius:"12px",fontSize:"14px",fontFamily:Y,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const x=document.createElement("button");x.type="submit",x.textContent="Send",m(x,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:"#03182f",color:"#fff",fontSize:"14px",fontWeight:"500",cursor:"pointer"});let f=null,b=null;s.allowFiles&&(f=document.createElement("input"),f.type="file",f.multiple=!0,m(f,{display:"none"}),b=document.createElement("button"),b.type="button",b.textContent="📎",m(b,{padding:"10px 12px",border:"1px solid #dee3e8",borderRadius:"12px",backgroundColor:"#fff",cursor:"pointer",fontSize:"14px"}),b.addEventListener("click",()=>f?.click()),f.addEventListener("change",()=>{n=[...n,...Array.from(f?.files??[])],I()}));function I(){_.replaceChildren(),n.forEach((i,C)=>{const l=c({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:"1px solid #dee3e8",borderRadius:"8px",fontSize:"12px"}),T=document.createElement("span");T.textContent=i.name;const y=document.createElement("button");y.type="button",y.textContent="×",m(y,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),y.addEventListener("click",()=>{n=n.filter((D,u)=>u!==C),I()}),l.append(T,y),_.appendChild(l)})}const A=()=>{const i=g.value,C=n;return g.value="",n=[],I(),{content:i,files:C}},R=()=>{const{content:i,files:C}=A();(i.trim()||C.length>0)&&s.onSend(i.trim(),C.length>0?C:void 0)};return v.addEventListener("submit",i=>{i.preventDefault(),R()}),g.addEventListener("keydown",i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),R())}),b&&N.appendChild(b),N.append(g,x),f&&v.appendChild(f),v.append(_,N),{inputRow:v,getValueAndClear:A,setDisabled:i=>{g.disabled=i,x.disabled=i,x.style.opacity=i?"0.6":"1",x.style.cursor=i?"not-allowed":"pointer"},focus:()=>g.focus()}}exports.mountChatWidget=de;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ue=require("./AgoClient-D4EL6nva.cjs"),ge=require("./createFormCollector-Wb8Rr-U2.cjs"),xe=require("./createConversationSession-DtaeA418.cjs");var oe='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',ee={font:"--ago-font",radius:"--ago-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"},ne="var(--ago-brand-color, #03182f)",re="var(--ago-brand-text-color, #fff)",me="var(--ago-header-background, var(--ago-brand-color, #03182f))",he="var(--ago-header-text-color, #e8f0fe)",L="var(--ago-panel-background, #fff)",be="var(--ago-messages-background, #fbfbfb)",z="var(--ago-text-color, #30373e)",Ce="var(--ago-muted-text-color, #6b6d6f)",E="var(--ago-border-color, #dee3e8)",G="var(--ago-accent-color, #1b5fc4)",K="var(--ago-radius, 16px)";function ve(i,o){if(o)for(const u of Object.keys(ee)){const w=o[u];w!=null&&i.style.setProperty(ee[u],w)}}function m(i,o){Object.assign(i.style,o)}function c(i={}){const o=document.createElement("div");return m(o,i),o}var te="ago-chat-widget-keyframes";function ye(){if(typeof document>"u"||document.getElementById(te))return;const i=document.createElement("style");i.id=te,i.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(i)}function Ee(i){const o=typeof i=="string"?document.querySelector(i):i;if(!o)throw new Error(`mountChatWidget: target "${String(i)}" not found.`);return o}function we(i,o){const{title:u="Chat",welcomeMessage:w="Hello! How can I help you today?",placeholder:T="Type a message...",allowFiles:g=!1,height:x=500,logoUrl:f,showAgentName:C=!1,theme:A,loadThreads:D=!1,forms:B,onFollowUpClick:s,onMessageSent:v,onMessageReceived:$}=o;if(!o.client&&!o.config?.baseUrl)throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");const l=o.client??new ue.AgoClient(o.config),k=Ee(i),M=o.persistConversation,I=M?xe.createConversationSession(M===!0?{}:M):void 0;let h=o.conversationId??I?.getLastActiveThread()??void 0,n=[],_=!1,N=null;const U=[],O=c({display:"flex",flexDirection:"column",height:typeof x=="number"?`${x}px`:x,border:`1px solid ${E}`,borderRadius:K,overflow:"hidden",backgroundColor:L,fontFamily:oe,boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});O.className="ago-chat-widget",ve(O,A);const W=c({padding:"14px 16px",borderBottom:`1px solid ${E}`,backgroundColor:me,color:he,display:"flex",alignItems:"center",gap:"10px"});if(W.className="ago-chat-widget__header",f){const e=document.createElement("img");e.src=f,e.alt="Logo",m(e,{height:"24px",width:"auto"}),W.appendChild(e)}const H=document.createElement("h3");H.textContent=u,m(H,{margin:"0",fontSize:"15px",fontWeight:"600"}),W.appendChild(H);const S=c({flex:"1",overflow:"auto",padding:"16px",backgroundColor:be});S.className="ago-chat-widget__messages";const{inputRow:ae,setDisabled:se,focus:ie}=Se({placeholder:T,allowFiles:g,onSend:(e,t)=>{F(e,t)}});ye(),O.append(W,S,ae),k.appendChild(O);const j=s!==!1,X=s===!1?void 0:s??(e=>{F(e)});function le(e){const t=e.role==="user",d=c({display:"flex",flexDirection:"column",alignItems:t?"flex-end":"flex-start",marginBottom:"16px"});if(d.className=`ago-message ago-message--${e.role}`,!t&&C&&e.agent){const r=c({fontSize:"13px",fontWeight:"500",color:z,marginBottom:"6px",padding:"0 4px"});r.className="ago-message__agent",r.textContent=e.agent.displayName||e.agent.name,d.appendChild(r)}if(!t&&e.sources&&e.sources.length>0){const r=c({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});r.className="ago-message__sources",e.sources.forEach((p,a)=>{const y=p.url?document.createElement("a"):document.createElement("div");p.url&&y instanceof HTMLAnchorElement&&(y.href=p.url,y.target="_blank",y.rel="noopener noreferrer"),m(y,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${E}`,borderRadius:"8px",backgroundColor:L,textDecoration:"none",color:z,fontSize:"12px",overflow:"hidden"});const Z=c({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${G}`,color:G,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Z.textContent=String(a+1);const q=c({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});q.textContent=p.title,q.title=p.title,y.append(Z,q),r.appendChild(y)}),d.appendChild(r)}const b=c({maxWidth:t?"75%":"100%",padding:t?"10px 14px":"2px 8px",borderRadius:t?K:"0",backgroundColor:t?ne:"transparent",color:t?re:z,wordBreak:"break-word",fontSize:"14px",lineHeight:"1.6",whiteSpace:"pre-wrap"});if(b.className="ago-message__content",e.content?b.textContent=e.content:e.status==="IN_PROGRESS"&&b.appendChild(fe()),d.appendChild(b),e.followUpReplies&&e.followUpReplies.length>0){const r=c({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});r.className="ago-message__followups";for(const p of e.followUpReplies){const a=document.createElement("button");a.type="button",a.className="ago-message__followup-btn",a.textContent=p,a.disabled=!j,m(a,{padding:"6px 14px",fontSize:"13px",borderRadius:K,border:`1px solid ${E}`,backgroundColor:L,color:z,cursor:j?"pointer":"default",transition:"border-color 0.15s"}),X&&a.addEventListener("click",()=>X(p)),a.addEventListener("mouseenter",()=>{a.style.borderColor=G}),a.addEventListener("mouseleave",()=>{a.style.borderColor=E}),r.appendChild(a)}d.appendChild(r)}return d}function R(){if(S.replaceChildren(),n.length===0){const e=c({textAlign:"center",color:Ce,padding:"24px 16px",fontSize:"14px",lineHeight:"1.5"});e.textContent=w,S.appendChild(e)}else for(const e of n)S.appendChild(le(e));if(N){const e=c({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});e.textContent=N,S.appendChild(e)}S.scrollTop=S.scrollHeight,se(_)}function de(){for(let e=n.length-1;e>=0;e--){const t=n[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const V=e=>{h||(h=e.conversationId)},Y=e=>{const t=de();t&&(t.content+=e.content,R())},J=e=>{const t=n.findIndex(d=>d.id===e.id||d.role==="assistant"&&d.status==="IN_PROGRESS");t>=0?n[t]=e:n.push(e),_=!1,R(),e.status==="DONE"&&$?.({id:e.id,content:e.content})},Q=e=>{N=e.error,_=!1,n=n.filter(t=>!t.id.startsWith("temp-")),R()};l.on("message:start",V),l.on("message:chunk",Y),l.on("message:complete",J),l.on("message:error",Q);const ce=(B??[]).map(e=>ge.createFormCollector(e).install(l));async function F(e,t){const d=e.trim();if(!d&&!t?.length||_)return;v?.(d),_=!0,N=null;const b=Date.now();n.push({id:`temp-user-${b}`,conversationId:h||"",content:d,role:"user",status:"DONE",createdAt:new Date}),n.push({id:`temp-assistant-${b}`,conversationId:h||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),R();try{const r=await l.sendMessage(d,{conversationId:h,files:t});r.conversationId&&(h||(h=r.conversationId),I?.setActiveThread(r.conversationId,r.createdAt));const p=n.find(a=>a.id===`temp-user-${b}`);if(p&&(p.id=`user-${b}`,p.conversationId=r.conversationId),!n.some(a=>a.id===r.id)){const a=n.findIndex(y=>y.id===`temp-assistant-${b}`);a>=0?n[a]=r:n.push(r)}n=n.filter(a=>!a.id.startsWith("temp-")),_=!1,R(),D&&P()}catch(r){N=r instanceof Error?r.message:"Failed to send message",_=!1,n=n.filter(p=>!p.id.startsWith("temp-")),R()}}async function P(){try{const e=await l.getConversations();U.splice(0,U.length,...e)}catch{}return U}async function pe(e){try{const t=(await l.getConversation(e))?.messages??[];t.length>0&&n.length===0&&(n=t,R())}catch{n.length===0&&(I?.clear(),h=void 0)}}return R(),ie(),h&&pe(h),D&&P(),{client:l,element:O,sendMessage:F,session:I,threads:U,refreshThreads:P,destroy(){l.off("message:start",V),l.off("message:chunk",Y),l.off("message:complete",J),l.off("message:error",Q),ce.forEach(e=>e()),O.remove(),o.client||l.destroy()}};function fe(){const e=c({display:"flex",gap:"4px",padding:"4px 0"});for(let t=0;t<3;t++){const d=c({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${t*.2}s`});e.appendChild(d)}return e}}function Se(i){let o=[];const u=document.createElement("form");m(u,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${E}`,backgroundColor:L}),u.className="ago-chat-input";const w=c({display:"flex",flexWrap:"wrap",gap:"6px"}),T=c({display:"flex",gap:"8px",alignItems:"flex-end"}),g=document.createElement("textarea");g.placeholder=i.placeholder,g.rows=1,m(g,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${E}`,borderRadius:"12px",fontSize:"14px",fontFamily:oe,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const x=document.createElement("button");x.type="submit",x.textContent="Send",m(x,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:ne,color:re,fontSize:"14px",fontWeight:"500",cursor:"pointer"});let f=null,C=null;i.allowFiles&&(f=document.createElement("input"),f.type="file",f.multiple=!0,m(f,{display:"none"}),C=document.createElement("button"),C.type="button",C.textContent="📎",m(C,{padding:"10px 12px",border:`1px solid ${E}`,borderRadius:"12px",backgroundColor:L,cursor:"pointer",fontSize:"14px"}),C.addEventListener("click",()=>f?.click()),f.addEventListener("change",()=>{o=[...o,...Array.from(f?.files??[])],A()}));function A(){w.replaceChildren(),o.forEach((s,v)=>{const $=c({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${E}`,borderRadius:"8px",fontSize:"12px"}),l=document.createElement("span");l.textContent=s.name;const k=document.createElement("button");k.type="button",k.textContent="×",m(k,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),k.addEventListener("click",()=>{o=o.filter((M,I)=>I!==v),A()}),$.append(l,k),w.appendChild($)})}const D=()=>{const s=g.value,v=o;return g.value="",o=[],A(),{content:s,files:v}},B=()=>{const{content:s,files:v}=D();(s.trim()||v.length>0)&&i.onSend(s.trim(),v.length>0?v:void 0)};return u.addEventListener("submit",s=>{s.preventDefault(),B()}),g.addEventListener("keydown",s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),B())}),C&&T.appendChild(C),T.append(g,x),f&&u.appendChild(f),u.append(w,T),{inputRow:u,getValueAndClear:D,setDisabled:s=>{g.disabled=s,x.disabled=s,x.style.opacity=s?"0.6":"1",x.style.cursor=s?"not-allowed":"pointer"},focus:()=>g.focus()}}exports.mountChatWidget=we;
package/dist/widget.d.cts CHANGED
@@ -606,6 +606,10 @@ export declare interface MountChatWidgetOptions {
606
606
  logoUrl?: string;
607
607
  /** Show the agent name above assistant messages. Defaults to `false`. */
608
608
  showAgentName?: boolean;
609
+ /**
610
+ * Theme overrides so the panel blends into the host page.
611
+ */
612
+ theme?: WidgetTheme;
609
613
  /**
610
614
  * Load the visitor's conversation list into `widget.threads` on mount and refresh
611
615
  * it after each turn (one `GET /conversations` per load). Off by default to avoid
@@ -688,4 +692,35 @@ declare interface ToolCallData {
688
692
 
689
693
  declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
690
694
 
695
+ /**
696
+ * Theme overrides for {@link mountChatWidget}. *
697
+ * @see The `--ago-*` token reference in `docs/widget.md`.
698
+ */
699
+ export declare interface WidgetTheme {
700
+ /** Font family for the whole panel. Pass `"inherit"` to adopt the page font. (`--ago-font`) */
701
+ font?: string;
702
+ /** Corner radius of the panel, user bubbles, and suggested-reply pills. (`--ago-radius`) */
703
+ radius?: string;
704
+ /** Brand color: user message bubbles and the send button (and the header, unless `headerBg` is set). (`--ago-brand-color`) */
705
+ brand?: string;
706
+ /** Text/icon color shown on top of `brand`. (`--ago-brand-text-color`) */
707
+ brandText?: string;
708
+ /** Header background. Defaults to `brand`. (`--ago-header-background`) */
709
+ headerBg?: string;
710
+ /** Header title color. (`--ago-header-text-color`) */
711
+ headerText?: string;
712
+ /** Panel surface: container, input row, suggested-reply pills, source cards. (`--ago-panel-background`) */
713
+ panelBg?: string;
714
+ /** Background of the scrolling messages area. (`--ago-messages-background`) */
715
+ messagesBg?: string;
716
+ /** Primary body text color (assistant messages, agent name, source labels). (`--ago-text-color`) */
717
+ text?: string;
718
+ /** Muted text color (the empty-state welcome message). (`--ago-muted-text-color`) */
719
+ mutedText?: string;
720
+ /** Border color used for the panel, input, pills, and cards. (`--ago-border-color`) */
721
+ border?: string;
722
+ /** Secondary accent: source badges and suggested-reply hover outline. (`--ago-accent-color`) */
723
+ accent?: string;
724
+ }
725
+
691
726
  export { }
package/dist/widget.d.ts CHANGED
@@ -606,6 +606,10 @@ export declare interface MountChatWidgetOptions {
606
606
  logoUrl?: string;
607
607
  /** Show the agent name above assistant messages. Defaults to `false`. */
608
608
  showAgentName?: boolean;
609
+ /**
610
+ * Theme overrides so the panel blends into the host page.
611
+ */
612
+ theme?: WidgetTheme;
609
613
  /**
610
614
  * Load the visitor's conversation list into `widget.threads` on mount and refresh
611
615
  * it after each turn (one `GET /conversations` per load). Off by default to avoid
@@ -688,4 +692,35 @@ declare interface ToolCallData {
688
692
 
689
693
  declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
690
694
 
695
+ /**
696
+ * Theme overrides for {@link mountChatWidget}. *
697
+ * @see The `--ago-*` token reference in `docs/widget.md`.
698
+ */
699
+ export declare interface WidgetTheme {
700
+ /** Font family for the whole panel. Pass `"inherit"` to adopt the page font. (`--ago-font`) */
701
+ font?: string;
702
+ /** Corner radius of the panel, user bubbles, and suggested-reply pills. (`--ago-radius`) */
703
+ radius?: string;
704
+ /** Brand color: user message bubbles and the send button (and the header, unless `headerBg` is set). (`--ago-brand-color`) */
705
+ brand?: string;
706
+ /** Text/icon color shown on top of `brand`. (`--ago-brand-text-color`) */
707
+ brandText?: string;
708
+ /** Header background. Defaults to `brand`. (`--ago-header-background`) */
709
+ headerBg?: string;
710
+ /** Header title color. (`--ago-header-text-color`) */
711
+ headerText?: string;
712
+ /** Panel surface: container, input row, suggested-reply pills, source cards. (`--ago-panel-background`) */
713
+ panelBg?: string;
714
+ /** Background of the scrolling messages area. (`--ago-messages-background`) */
715
+ messagesBg?: string;
716
+ /** Primary body text color (assistant messages, agent name, source labels). (`--ago-text-color`) */
717
+ text?: string;
718
+ /** Muted text color (the empty-state welcome message). (`--ago-muted-text-color`) */
719
+ mutedText?: string;
720
+ /** Border color used for the panel, input, pills, and cards. (`--ago-border-color`) */
721
+ border?: string;
722
+ /** Secondary accent: source badges and suggested-reply hover outline. (`--ago-accent-color`) */
723
+ accent?: string;
724
+ }
725
+
691
726
  export { }
package/dist/widget.js CHANGED
@@ -1,94 +1,114 @@
1
- import { t as re } from "./AgoClient-rvTz2thR.js";
2
- import { t as ae } from "./createFormCollector-BwvkKi48.js";
3
- import { t as ie } from "./createConversationSession-D9FesBQS.js";
4
- var Y = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
5
- function x(s, n) {
6
- Object.assign(s.style, n);
1
+ import { t as ge } from "./AgoClient-rvTz2thR.js";
2
+ import { t as ue } from "./createFormCollector-BwvkKi48.js";
3
+ import { t as xe } from "./createConversationSession-D9FesBQS.js";
4
+ var oe = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', ee = {
5
+ font: "--ago-font",
6
+ radius: "--ago-radius",
7
+ brand: "--ago-brand-color",
8
+ brandText: "--ago-brand-text-color",
9
+ headerBg: "--ago-header-background",
10
+ headerText: "--ago-header-text-color",
11
+ panelBg: "--ago-panel-background",
12
+ messagesBg: "--ago-messages-background",
13
+ text: "--ago-text-color",
14
+ mutedText: "--ago-muted-text-color",
15
+ border: "--ago-border-color",
16
+ accent: "--ago-accent-color"
17
+ }, ne = "var(--ago-brand-color, #03182f)", re = "var(--ago-brand-text-color, #fff)", me = "var(--ago-header-background, var(--ago-brand-color, #03182f))", he = "var(--ago-header-text-color, #e8f0fe)", L = "var(--ago-panel-background, #fff)", be = "var(--ago-messages-background, #fbfbfb)", H = "var(--ago-text-color, #30373e)", ve = "var(--ago-muted-text-color, #6b6d6f)", E = "var(--ago-border-color, #dee3e8)", K = "var(--ago-accent-color, #1b5fc4)", X = "var(--ago-radius, 16px)";
18
+ function Ce(i, o) {
19
+ if (o)
20
+ for (const g of Object.keys(ee)) {
21
+ const w = o[g];
22
+ w != null && i.style.setProperty(ee[g], w);
23
+ }
24
+ }
25
+ function m(i, o) {
26
+ Object.assign(i.style, o);
7
27
  }
8
- function c(s = {}) {
9
- const n = document.createElement("div");
10
- return x(n, s), n;
28
+ function c(i = {}) {
29
+ const o = document.createElement("div");
30
+ return m(o, i), o;
11
31
  }
12
- var V = "ago-chat-widget-keyframes";
13
- function se() {
14
- if (typeof document > "u" || document.getElementById(V)) return;
15
- const s = document.createElement("style");
16
- s.id = V, s.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(s);
32
+ var te = "ago-chat-widget-keyframes";
33
+ function ye() {
34
+ if (typeof document > "u" || document.getElementById(te)) return;
35
+ const i = document.createElement("style");
36
+ i.id = te, i.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(i);
17
37
  }
18
- function le(s) {
19
- const n = typeof s == "string" ? document.querySelector(s) : s;
20
- if (!n) throw new Error(`mountChatWidget: target "${String(s)}" not found.`);
21
- return n;
38
+ function Ee(i) {
39
+ const o = typeof i == "string" ? document.querySelector(i) : i;
40
+ if (!o) throw new Error(`mountChatWidget: target "${String(i)}" not found.`);
41
+ return o;
22
42
  }
23
- function ue(s, n) {
24
- const { title: v = "Chat", welcomeMessage: _ = "Hello! How can I help you today?", placeholder: N = "Type a message...", allowFiles: g = !1, height: m = 500, logoUrl: f, showAgentName: b = !1, loadThreads: I = !1, forms: A, onFollowUpClick: R, onMessageSent: i, onMessageReceived: C } = n;
25
- if (!n.client && !n.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
26
- const l = n.client ?? new re(n.config), L = le(s), y = n.persistConversation, D = y ? ie(y === !0 ? {} : y) : void 0;
27
- let u = n.conversationId ?? D?.getLastActiveThread() ?? void 0, o = [], k = !1, z = null;
28
- const T = [], W = c({
43
+ function _e(i, o) {
44
+ const { title: g = "Chat", welcomeMessage: w = "Hello! How can I help you today?", placeholder: T = "Type a message...", allowFiles: u = !1, height: x = 500, logoUrl: f, showAgentName: v = !1, theme: A, loadThreads: D = !1, forms: B, onFollowUpClick: s, onMessageSent: C, onMessageReceived: $ } = o;
45
+ if (!o.client && !o.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
46
+ const l = o.client ?? new ge(o.config), k = Ee(i), U = o.persistConversation, I = U ? xe(U === !0 ? {} : U) : void 0;
47
+ let h = o.conversationId ?? I?.getLastActiveThread() ?? void 0, n = [], _ = !1, N = null;
48
+ const M = [], O = c({
29
49
  display: "flex",
30
50
  flexDirection: "column",
31
- height: typeof m == "number" ? `${m}px` : m,
32
- border: "1px solid #dee3e8",
33
- borderRadius: "16px",
51
+ height: typeof x == "number" ? `${x}px` : x,
52
+ border: `1px solid ${E}`,
53
+ borderRadius: X,
34
54
  overflow: "hidden",
35
- backgroundColor: "#fff",
36
- fontFamily: Y,
55
+ backgroundColor: L,
56
+ fontFamily: oe,
37
57
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
38
58
  });
39
- W.className = "ago-chat-widget";
40
- const F = c({
59
+ O.className = "ago-chat-widget", Ce(O, A);
60
+ const z = c({
41
61
  padding: "14px 16px",
42
- borderBottom: "1px solid #dee3e8",
43
- backgroundColor: "#03182f",
44
- color: "#e8f0fe",
62
+ borderBottom: `1px solid ${E}`,
63
+ backgroundColor: me,
64
+ color: he,
45
65
  display: "flex",
46
66
  alignItems: "center",
47
67
  gap: "10px"
48
68
  });
49
- if (F.className = "ago-chat-widget__header", f) {
69
+ if (z.className = "ago-chat-widget__header", f) {
50
70
  const e = document.createElement("img");
51
- e.src = f, e.alt = "Logo", x(e, {
71
+ e.src = f, e.alt = "Logo", m(e, {
52
72
  height: "24px",
53
73
  width: "auto"
54
- }), F.appendChild(e);
74
+ }), z.appendChild(e);
55
75
  }
56
- const M = document.createElement("h3");
57
- M.textContent = v, x(M, {
76
+ const W = document.createElement("h3");
77
+ W.textContent = g, m(W, {
58
78
  margin: "0",
59
79
  fontSize: "15px",
60
80
  fontWeight: "600"
61
- }), F.appendChild(M);
62
- const E = c({
81
+ }), z.appendChild(W);
82
+ const R = c({
63
83
  flex: "1",
64
84
  overflow: "auto",
65
85
  padding: "16px",
66
- backgroundColor: "#fbfbfb"
86
+ backgroundColor: be
67
87
  });
68
- E.className = "ago-chat-widget__messages";
69
- const { inputRow: J, setDisabled: Q, focus: X } = de({
70
- placeholder: N,
71
- allowFiles: g,
88
+ R.className = "ago-chat-widget__messages";
89
+ const { inputRow: ae, setDisabled: se, focus: ie } = we({
90
+ placeholder: T,
91
+ allowFiles: u,
72
92
  onSend: (e, t) => {
73
- H(e, t);
93
+ F(e, t);
74
94
  }
75
95
  });
76
- se(), W.append(F, E, J), L.appendChild(W);
77
- const O = R !== !1, $ = R === !1 ? void 0 : R ?? ((e) => {
78
- H(e);
96
+ ye(), O.append(z, R, ae), k.appendChild(O);
97
+ const j = s !== !1, V = s === !1 ? void 0 : s ?? ((e) => {
98
+ F(e);
79
99
  });
80
- function Z(e) {
100
+ function le(e) {
81
101
  const t = e.role === "user", d = c({
82
102
  display: "flex",
83
103
  flexDirection: "column",
84
104
  alignItems: t ? "flex-end" : "flex-start",
85
105
  marginBottom: "16px"
86
106
  });
87
- if (d.className = `ago-message ago-message--${e.role}`, !t && b && e.agent) {
107
+ if (d.className = `ago-message ago-message--${e.role}`, !t && v && e.agent) {
88
108
  const r = c({
89
109
  fontSize: "13px",
90
110
  fontWeight: "500",
91
- color: "#30373e",
111
+ color: H,
92
112
  marginBottom: "6px",
93
113
  padding: "0 4px"
94
114
  });
@@ -104,27 +124,27 @@ function ue(s, n) {
104
124
  maxWidth: "85%"
105
125
  });
106
126
  r.className = "ago-message__sources", e.sources.forEach((p, a) => {
107
- const w = p.url ? document.createElement("a") : document.createElement("div");
108
- p.url && w instanceof HTMLAnchorElement && (w.href = p.url, w.target = "_blank", w.rel = "noopener noreferrer"), x(w, {
127
+ const y = p.url ? document.createElement("a") : document.createElement("div");
128
+ p.url && y instanceof HTMLAnchorElement && (y.href = p.url, y.target = "_blank", y.rel = "noopener noreferrer"), m(y, {
109
129
  display: "flex",
110
130
  alignItems: "center",
111
131
  gap: "8px",
112
132
  padding: "8px 10px",
113
- border: "1px solid #dee3e8",
133
+ border: `1px solid ${E}`,
114
134
  borderRadius: "8px",
115
- backgroundColor: "#fff",
135
+ backgroundColor: L,
116
136
  textDecoration: "none",
117
- color: "#30373e",
137
+ color: H,
118
138
  fontSize: "12px",
119
139
  overflow: "hidden"
120
140
  });
121
- const q = c({
141
+ const Z = c({
122
142
  flexShrink: "0",
123
143
  width: "18px",
124
144
  height: "18px",
125
145
  borderRadius: "3px",
126
- border: "1px solid #1b5fc4",
127
- color: "#1b5fc4",
146
+ border: `1px solid ${K}`,
147
+ color: K,
128
148
  fontSize: "11px",
129
149
  fontWeight: "500",
130
150
  display: "flex",
@@ -132,27 +152,27 @@ function ue(s, n) {
132
152
  justifyContent: "center",
133
153
  backgroundColor: "#f0f4ff"
134
154
  });
135
- q.textContent = String(a + 1);
136
- const B = c({
155
+ Z.textContent = String(a + 1);
156
+ const P = c({
137
157
  overflow: "hidden",
138
158
  textOverflow: "ellipsis",
139
159
  whiteSpace: "nowrap"
140
160
  });
141
- B.textContent = p.title, B.title = p.title, w.append(q, B), r.appendChild(w);
161
+ P.textContent = p.title, P.title = p.title, y.append(Z, P), r.appendChild(y);
142
162
  }), d.appendChild(r);
143
163
  }
144
- const h = c({
164
+ const b = c({
145
165
  maxWidth: t ? "75%" : "100%",
146
166
  padding: t ? "10px 14px" : "2px 8px",
147
- borderRadius: t ? "16px" : "0",
148
- backgroundColor: t ? "#03182f" : "transparent",
149
- color: t ? "#fff" : "#30373e",
167
+ borderRadius: t ? X : "0",
168
+ backgroundColor: t ? ne : "transparent",
169
+ color: t ? re : H,
150
170
  wordBreak: "break-word",
151
171
  fontSize: "14px",
152
172
  lineHeight: "1.6",
153
173
  whiteSpace: "pre-wrap"
154
174
  });
155
- if (h.className = "ago-message__content", e.content ? h.textContent = e.content : e.status === "IN_PROGRESS" && h.appendChild(oe()), d.appendChild(h), e.followUpReplies && e.followUpReplies.length > 0) {
175
+ if (b.className = "ago-message__content", e.content ? b.textContent = e.content : e.status === "IN_PROGRESS" && b.appendChild(fe()), d.appendChild(b), e.followUpReplies && e.followUpReplies.length > 0) {
156
176
  const r = c({
157
177
  display: "flex",
158
178
  flexWrap: "wrap",
@@ -162,19 +182,19 @@ function ue(s, n) {
162
182
  r.className = "ago-message__followups";
163
183
  for (const p of e.followUpReplies) {
164
184
  const a = document.createElement("button");
165
- a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !O, x(a, {
185
+ a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !j, m(a, {
166
186
  padding: "6px 14px",
167
187
  fontSize: "13px",
168
- borderRadius: "16px",
169
- border: "1px solid #dee3e8",
170
- backgroundColor: "#fff",
171
- color: "#30373e",
172
- cursor: O ? "pointer" : "default",
188
+ borderRadius: X,
189
+ border: `1px solid ${E}`,
190
+ backgroundColor: L,
191
+ color: H,
192
+ cursor: j ? "pointer" : "default",
173
193
  transition: "border-color 0.15s"
174
- }), $ && a.addEventListener("click", () => $(p)), a.addEventListener("mouseenter", () => {
175
- a.style.borderColor = "#1b5fc4";
194
+ }), V && a.addEventListener("click", () => V(p)), a.addEventListener("mouseenter", () => {
195
+ a.style.borderColor = K;
176
196
  }), a.addEventListener("mouseleave", () => {
177
- a.style.borderColor = "#dee3e8";
197
+ a.style.borderColor = E;
178
198
  }), r.appendChild(a);
179
199
  }
180
200
  d.appendChild(r);
@@ -182,17 +202,17 @@ function ue(s, n) {
182
202
  return d;
183
203
  }
184
204
  function S() {
185
- if (E.replaceChildren(), o.length === 0) {
205
+ if (R.replaceChildren(), n.length === 0) {
186
206
  const e = c({
187
207
  textAlign: "center",
188
- color: "#6b6d6f",
208
+ color: ve,
189
209
  padding: "24px 16px",
190
210
  fontSize: "14px",
191
211
  lineHeight: "1.5"
192
212
  });
193
- e.textContent = _, E.appendChild(e);
194
- } else for (const e of o) E.appendChild(Z(e));
195
- if (z) {
213
+ e.textContent = w, R.appendChild(e);
214
+ } else for (const e of n) R.appendChild(le(e));
215
+ if (N) {
196
216
  const e = c({
197
217
  padding: "10px 14px",
198
218
  backgroundColor: "#fef2f2",
@@ -202,47 +222,47 @@ function ue(s, n) {
202
222
  fontSize: "13px",
203
223
  border: "1px solid #fecaca"
204
224
  });
205
- e.textContent = z, E.appendChild(e);
225
+ e.textContent = N, R.appendChild(e);
206
226
  }
207
- E.scrollTop = E.scrollHeight, Q(k);
227
+ R.scrollTop = R.scrollHeight, se(_);
208
228
  }
209
- function ee() {
210
- for (let e = o.length - 1; e >= 0; e--) {
211
- const t = o[e];
229
+ function de() {
230
+ for (let e = n.length - 1; e >= 0; e--) {
231
+ const t = n[e];
212
232
  if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
213
233
  }
214
234
  }
215
- const P = (e) => {
216
- u || (u = e.conversationId);
217
- }, G = (e) => {
218
- const t = ee();
235
+ const q = (e) => {
236
+ h || (h = e.conversationId);
237
+ }, Y = (e) => {
238
+ const t = de();
219
239
  t && (t.content += e.content, S());
220
- }, K = (e) => {
221
- const t = o.findIndex((d) => d.id === e.id || d.role === "assistant" && d.status === "IN_PROGRESS");
222
- t >= 0 ? o[t] = e : o.push(e), k = !1, S(), e.status === "DONE" && C?.({
240
+ }, J = (e) => {
241
+ const t = n.findIndex((d) => d.id === e.id || d.role === "assistant" && d.status === "IN_PROGRESS");
242
+ t >= 0 ? n[t] = e : n.push(e), _ = !1, S(), e.status === "DONE" && $?.({
223
243
  id: e.id,
224
244
  content: e.content
225
245
  });
226
- }, j = (e) => {
227
- z = e.error, k = !1, o = o.filter((t) => !t.id.startsWith("temp-")), S();
246
+ }, Q = (e) => {
247
+ N = e.error, _ = !1, n = n.filter((t) => !t.id.startsWith("temp-")), S();
228
248
  };
229
- l.on("message:start", P), l.on("message:chunk", G), l.on("message:complete", K), l.on("message:error", j);
230
- const te = (A ?? []).map((e) => ae(e).install(l));
231
- async function H(e, t) {
249
+ l.on("message:start", q), l.on("message:chunk", Y), l.on("message:complete", J), l.on("message:error", Q);
250
+ const ce = (B ?? []).map((e) => ue(e).install(l));
251
+ async function F(e, t) {
232
252
  const d = e.trim();
233
- if (!d && !t?.length || k) return;
234
- i?.(d), k = !0, z = null;
235
- const h = Date.now();
236
- o.push({
237
- id: `temp-user-${h}`,
238
- conversationId: u || "",
253
+ if (!d && !t?.length || _) return;
254
+ C?.(d), _ = !0, N = null;
255
+ const b = Date.now();
256
+ n.push({
257
+ id: `temp-user-${b}`,
258
+ conversationId: h || "",
239
259
  content: d,
240
260
  role: "user",
241
261
  status: "DONE",
242
262
  createdAt: /* @__PURE__ */ new Date()
243
- }), o.push({
244
- id: `temp-assistant-${h}`,
245
- conversationId: u || "",
263
+ }), n.push({
264
+ id: `temp-assistant-${b}`,
265
+ conversationId: h || "",
246
266
  content: "",
247
267
  role: "assistant",
248
268
  status: "IN_PROGRESS",
@@ -250,48 +270,48 @@ function ue(s, n) {
250
270
  }), S();
251
271
  try {
252
272
  const r = await l.sendMessage(d, {
253
- conversationId: u,
273
+ conversationId: h,
254
274
  files: t
255
275
  });
256
- r.conversationId && (u || (u = r.conversationId), D?.setActiveThread(r.conversationId, r.createdAt));
257
- const p = o.find((a) => a.id === `temp-user-${h}`);
258
- if (p && (p.id = `user-${h}`, p.conversationId = r.conversationId), !o.some((a) => a.id === r.id)) {
259
- const a = o.findIndex((w) => w.id === `temp-assistant-${h}`);
260
- a >= 0 ? o[a] = r : o.push(r);
276
+ r.conversationId && (h || (h = r.conversationId), I?.setActiveThread(r.conversationId, r.createdAt));
277
+ const p = n.find((a) => a.id === `temp-user-${b}`);
278
+ if (p && (p.id = `user-${b}`, p.conversationId = r.conversationId), !n.some((a) => a.id === r.id)) {
279
+ const a = n.findIndex((y) => y.id === `temp-assistant-${b}`);
280
+ a >= 0 ? n[a] = r : n.push(r);
261
281
  }
262
- o = o.filter((a) => !a.id.startsWith("temp-")), k = !1, S(), I && U();
282
+ n = n.filter((a) => !a.id.startsWith("temp-")), _ = !1, S(), D && G();
263
283
  } catch (r) {
264
- z = r instanceof Error ? r.message : "Failed to send message", k = !1, o = o.filter((p) => !p.id.startsWith("temp-")), S();
284
+ N = r instanceof Error ? r.message : "Failed to send message", _ = !1, n = n.filter((p) => !p.id.startsWith("temp-")), S();
265
285
  }
266
286
  }
267
- async function U() {
287
+ async function G() {
268
288
  try {
269
289
  const e = await l.getConversations();
270
- T.splice(0, T.length, ...e);
290
+ M.splice(0, M.length, ...e);
271
291
  } catch {
272
292
  }
273
- return T;
293
+ return M;
274
294
  }
275
- async function ne(e) {
295
+ async function pe(e) {
276
296
  try {
277
297
  const t = (await l.getConversation(e))?.messages ?? [];
278
- t.length > 0 && o.length === 0 && (o = t, S());
298
+ t.length > 0 && n.length === 0 && (n = t, S());
279
299
  } catch {
280
- o.length === 0 && (D?.clear(), u = void 0);
300
+ n.length === 0 && (I?.clear(), h = void 0);
281
301
  }
282
302
  }
283
- return S(), X(), u && ne(u), I && U(), {
303
+ return S(), ie(), h && pe(h), D && G(), {
284
304
  client: l,
285
- element: W,
286
- sendMessage: H,
287
- session: D,
288
- threads: T,
289
- refreshThreads: U,
305
+ element: O,
306
+ sendMessage: F,
307
+ session: I,
308
+ threads: M,
309
+ refreshThreads: G,
290
310
  destroy() {
291
- l.off("message:start", P), l.off("message:chunk", G), l.off("message:complete", K), l.off("message:error", j), te.forEach((e) => e()), W.remove(), n.client || l.destroy();
311
+ l.off("message:start", q), l.off("message:chunk", Y), l.off("message:complete", J), l.off("message:error", Q), ce.forEach((e) => e()), O.remove(), o.client || l.destroy();
292
312
  }
293
313
  };
294
- function oe() {
314
+ function fe() {
295
315
  const e = c({
296
316
  display: "flex",
297
317
  gap: "4px",
@@ -311,108 +331,108 @@ function ue(s, n) {
311
331
  return e;
312
332
  }
313
333
  }
314
- function de(s) {
315
- let n = [];
316
- const v = document.createElement("form");
317
- x(v, {
334
+ function we(i) {
335
+ let o = [];
336
+ const g = document.createElement("form");
337
+ m(g, {
318
338
  display: "flex",
319
339
  flexDirection: "column",
320
340
  gap: "8px",
321
341
  padding: "12px",
322
- borderTop: "1px solid #dee3e8",
323
- backgroundColor: "#fff"
324
- }), v.className = "ago-chat-input";
325
- const _ = c({
342
+ borderTop: `1px solid ${E}`,
343
+ backgroundColor: L
344
+ }), g.className = "ago-chat-input";
345
+ const w = c({
326
346
  display: "flex",
327
347
  flexWrap: "wrap",
328
348
  gap: "6px"
329
- }), N = c({
349
+ }), T = c({
330
350
  display: "flex",
331
351
  gap: "8px",
332
352
  alignItems: "flex-end"
333
- }), g = document.createElement("textarea");
334
- g.placeholder = s.placeholder, g.rows = 1, x(g, {
353
+ }), u = document.createElement("textarea");
354
+ u.placeholder = i.placeholder, u.rows = 1, m(u, {
335
355
  flex: "1",
336
356
  resize: "none",
337
357
  padding: "10px 12px",
338
- border: "1px solid #dee3e8",
358
+ border: `1px solid ${E}`,
339
359
  borderRadius: "12px",
340
360
  fontSize: "14px",
341
- fontFamily: Y,
361
+ fontFamily: oe,
342
362
  lineHeight: "1.4",
343
363
  maxHeight: "120px",
344
364
  outline: "none"
345
365
  });
346
- const m = document.createElement("button");
347
- m.type = "submit", m.textContent = "Send", x(m, {
366
+ const x = document.createElement("button");
367
+ x.type = "submit", x.textContent = "Send", m(x, {
348
368
  padding: "10px 16px",
349
369
  border: "none",
350
370
  borderRadius: "12px",
351
- backgroundColor: "#03182f",
352
- color: "#fff",
371
+ backgroundColor: ne,
372
+ color: re,
353
373
  fontSize: "14px",
354
374
  fontWeight: "500",
355
375
  cursor: "pointer"
356
376
  });
357
- let f = null, b = null;
358
- s.allowFiles && (f = document.createElement("input"), f.type = "file", f.multiple = !0, x(f, { display: "none" }), b = document.createElement("button"), b.type = "button", b.textContent = "📎", x(b, {
377
+ let f = null, v = null;
378
+ i.allowFiles && (f = document.createElement("input"), f.type = "file", f.multiple = !0, m(f, { display: "none" }), v = document.createElement("button"), v.type = "button", v.textContent = "📎", m(v, {
359
379
  padding: "10px 12px",
360
- border: "1px solid #dee3e8",
380
+ border: `1px solid ${E}`,
361
381
  borderRadius: "12px",
362
- backgroundColor: "#fff",
382
+ backgroundColor: L,
363
383
  cursor: "pointer",
364
384
  fontSize: "14px"
365
- }), b.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
366
- n = [...n, ...Array.from(f?.files ?? [])], I();
385
+ }), v.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
386
+ o = [...o, ...Array.from(f?.files ?? [])], A();
367
387
  }));
368
- function I() {
369
- _.replaceChildren(), n.forEach((i, C) => {
370
- const l = c({
388
+ function A() {
389
+ w.replaceChildren(), o.forEach((s, C) => {
390
+ const $ = c({
371
391
  display: "flex",
372
392
  alignItems: "center",
373
393
  gap: "4px",
374
394
  padding: "4px 8px",
375
395
  backgroundColor: "#f0f4ff",
376
- border: "1px solid #dee3e8",
396
+ border: `1px solid ${E}`,
377
397
  borderRadius: "8px",
378
398
  fontSize: "12px"
379
- }), L = document.createElement("span");
380
- L.textContent = i.name;
381
- const y = document.createElement("button");
382
- y.type = "button", y.textContent = "×", x(y, {
399
+ }), l = document.createElement("span");
400
+ l.textContent = s.name;
401
+ const k = document.createElement("button");
402
+ k.type = "button", k.textContent = "×", m(k, {
383
403
  border: "none",
384
404
  background: "transparent",
385
405
  cursor: "pointer",
386
406
  fontSize: "14px",
387
407
  lineHeight: "1"
388
- }), y.addEventListener("click", () => {
389
- n = n.filter((D, u) => u !== C), I();
390
- }), l.append(L, y), _.appendChild(l);
408
+ }), k.addEventListener("click", () => {
409
+ o = o.filter((U, I) => I !== C), A();
410
+ }), $.append(l, k), w.appendChild($);
391
411
  });
392
412
  }
393
- const A = () => {
394
- const i = g.value, C = n;
395
- return g.value = "", n = [], I(), {
396
- content: i,
413
+ const D = () => {
414
+ const s = u.value, C = o;
415
+ return u.value = "", o = [], A(), {
416
+ content: s,
397
417
  files: C
398
418
  };
399
- }, R = () => {
400
- const { content: i, files: C } = A();
401
- (i.trim() || C.length > 0) && s.onSend(i.trim(), C.length > 0 ? C : void 0);
419
+ }, B = () => {
420
+ const { content: s, files: C } = D();
421
+ (s.trim() || C.length > 0) && i.onSend(s.trim(), C.length > 0 ? C : void 0);
402
422
  };
403
- return v.addEventListener("submit", (i) => {
404
- i.preventDefault(), R();
405
- }), g.addEventListener("keydown", (i) => {
406
- i.key === "Enter" && !i.shiftKey && (i.preventDefault(), R());
407
- }), b && N.appendChild(b), N.append(g, m), f && v.appendChild(f), v.append(_, N), {
408
- inputRow: v,
409
- getValueAndClear: A,
410
- setDisabled: (i) => {
411
- g.disabled = i, m.disabled = i, m.style.opacity = i ? "0.6" : "1", m.style.cursor = i ? "not-allowed" : "pointer";
423
+ return g.addEventListener("submit", (s) => {
424
+ s.preventDefault(), B();
425
+ }), u.addEventListener("keydown", (s) => {
426
+ s.key === "Enter" && !s.shiftKey && (s.preventDefault(), B());
427
+ }), v && T.appendChild(v), T.append(u, x), f && g.appendChild(f), g.append(w, T), {
428
+ inputRow: g,
429
+ getValueAndClear: D,
430
+ setDisabled: (s) => {
431
+ u.disabled = s, x.disabled = s, x.style.opacity = s ? "0.6" : "1", x.style.cursor = s ? "not-allowed" : "pointer";
412
432
  },
413
- focus: () => g.focus()
433
+ focus: () => u.focus()
414
434
  };
415
435
  }
416
436
  export {
417
- ue as mountChatWidget
437
+ _e as mountChatWidget
418
438
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useago/sdk",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "JavaScript SDK for AGO Chat integration",
5
5
  "type": "module",
6
6
  "sideEffects": false,