@useago/sdk 1.0.10 → 1.1.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/{AgoClient-QcTtrN7u.js → AgoClient-Cwx_eYSu.js} +182 -131
- package/dist/AgoClient-CzSmJQxl.cjs +6 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +23 -0
- package/dist/angular.d.ts +23 -0
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-CR-71aLR.js → createConversationSession-B3h567tt.js} +1 -1
- package/dist/{createConversationSession-C0diFTUk.cjs → createConversationSession-DV0Xp_3O.cjs} +1 -1
- package/dist/{createFormCollector-BI3DXaew.cjs → createFormCollector-BB3Uscuo.cjs} +1 -1
- package/dist/{createFormCollector-CFt1_QSL.js → createFormCollector-CyWisAkI.js} +1 -1
- package/dist/devtools.d.cts +23 -0
- package/dist/devtools.d.ts +23 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +58 -55
- package/dist/react.cjs +3 -3
- package/dist/react.d.cts +23 -0
- package/dist/react.d.ts +23 -0
- package/dist/react.js +482 -367
- package/dist/testing.d.cts +23 -0
- package/dist/testing.d.ts +23 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +119 -0
- package/dist/vue.d.ts +119 -0
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +48 -2
- package/dist/widget.d.ts +48 -2
- package/dist/widget.js +538 -417
- package/package.json +1 -1
- package/dist/AgoClient-B3-WGVne.cjs +0 -6
package/dist/widget.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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={"&":"&","<":"<",">":">",'"':""","'":"'"};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,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let
|
|
4
|
-
`)))),o.appendChild(B);continue}if(
|
|
5
|
-
`))),o.appendChild(x);continue}if(s.includes("|")&&ht(a[t+1])){const c=[s,a[t+1]];for(t+=2;t<a.length&&a[t].includes("|")&&a[t].trim();)c.push(a[t]),t++;o.appendChild(mt(c));continue}if(q.test(s)){const c=[],x=ye(s);for(;t<a.length&&a[t].trim()!=="";)if(q.test(a[t])||ye(a[t])>x)c.push(a[t]),t++;else break;o.appendChild(Ye(c));continue}const p=[s];for(t++;t<a.length&&!gt(a[t]);)p.push(a[t]),t++;o.appendChild(k("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>H(c)).join("<br>")))}const g=o.lastElementChild;return g&&(g.style.marginBottom="0"),o}var ve='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Ue={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"},oe="var(--ago-brand-color, #03182f)",Ee="var(--ago-brand-text-color, #fff)",xt="var(--ago-header-background, var(--ago-brand-color, #03182f))",We="var(--ago-header-text-color, #e8f0fe)",K="var(--ago-panel-background, #fff)",Pe="var(--ago-messages-background, #fbfbfb)",te="var(--ago-text-color, #30373e)",bt="var(--ago-muted-text-color, #6b6d6f)",N="var(--ago-border-color, #dee3e8)",be="var(--ago-accent-color, #1b5fc4)",Ge="var(--ago-agent-bubble-background, #f1f3f5)",Ct="var(--ago-radius, 16px)",Ce="var(--ago-message-radius, 16px)";function yt(r,o){if(o)for(const a of Object.keys(Ue)){const t=o[a];t!=null&&r.style.setProperty(Ue[a],t)}}function v(r,o){Object.assign(r.style,o)}function h(r={}){const o=document.createElement("div");return v(o,r),o}var je="Form submitted.";function vt(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 t=a.message;if(typeof t=="string"&&t)return t}return null}var qe="ago-chat-widget-keyframes";function Et(){if(typeof document>"u"||document.getElementById(qe))return;const r=document.createElement("style");r.id=qe,r.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(r)}function wt(r){const o=typeof r=="string"?document.querySelector(r):r;if(!o)throw new Error(`mountChatWidget: target "${String(r)}" not found.`);return o}function St(r,o){const{title:a="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:g="Type a message...",allowFiles:s=!1,height:u=500,placement:l="inline",width:p=400,defaultOpen:c=!1,logoUrl:x,showAgentName:B=!1,agentBubble:b=!1,bubbleStyle:L="default",showHeader:V=!0,theme:Q,loadThreads:O=!1,forms:we,formSubmittedMessage:U=je,onFollowUpClick:ae,onMessageSent:Ze,onMessageReceived:Je,onFormSubmitted:se,onFormError:ie}=o;if(!o.client&&!o.config?.baseUrl)throw new Fe.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const m=o.client??new Fe.AgoClient(o.config),Se=wt(r),W=l==="left"||l==="right",et=W&&(o.launcher??!0);let P=W?c:!0;const le=o.persistConversation,Y=le?pt.createConversationSession(le===!0?{}:le):void 0;let A=o.conversationId??Y?.getLastActiveThread()??void 0,d=[],D=!1,X=null;const Re=[];function tt(e){if(typeof U=="function"){const i=U(e);if(typeof i=="string"&&i)return i}const n=vt(e);return n||(typeof U=="string"?U:je)}const Z=[],G=h({display:"flex",flexDirection:"column",height:W?"100%":typeof u=="number"?`${u}px`:u,border:`1px solid ${N}`,borderRadius:Ct,overflow:"hidden",backgroundColor:K,fontFamily:ve,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});G.className="ago-chat-widget",yt(G,Q);let M;if(V){if(M=h({padding:"14px 16px",borderBottom:`1px solid ${N}`,backgroundColor:xt,color:We,display:"flex",alignItems:"center",gap:"10px"}),M.className="ago-chat-widget__header",x){const n=document.createElement("img");n.src=x,n.alt="Logo",v(n,{height:"24px",width:"auto"}),M.appendChild(n)}const e=document.createElement("h3");if(e.textContent=a,v(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),M.appendChild(e),W){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",v(n,{marginLeft:"auto",background:"transparent",border:"none",color:We,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),n.addEventListener("click",()=>he()),M.appendChild(n)}}const T=h({flex:"1",overflow:"auto",padding:"16px",backgroundColor:Pe});T.className="ago-chat-widget__messages";const{inputRow:nt,setDisabled:ot,focus:de}=Rt({placeholder:g,allowFiles:s,onSend:(e,n)=>{fe(e,n)}});Et(),G.append(...M?[M]:[],T,nt);let J=G,F,w;const ce=l==="left"?"left":"right";if(W&&(F=h({position:"fixed",top:"0",bottom:"0",[ce]:"0",width:typeof p=="number"?`${p}px`:p,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),F.className="ago-chat-widget-panel",v(G,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ce==="left"?"borderRight":"borderLeft"]:`1px solid ${N}`}),F.appendChild(G),J=F),et){if(w=document.createElement("button"),w.type="button",w.className="ago-chat-widget-launcher",w.setAttribute("aria-label",`Open ${a}`),v(w,{position:"fixed",bottom:"20px",[ce]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:oe,color:Ee,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:ve}),x){const e=document.createElement("img");e.src=x,e.alt="",v(e,{width:"26px",height:"26px",objectFit:"contain"}),w.appendChild(e)}else w.appendChild(dt());w.addEventListener("click",()=>me())}Se.appendChild(J),w&&Se.appendChild(w),ge();const _e=ae!==!1,ke=ae===!1?void 0:ae??(e=>{fe(e)});function rt(e,n,i=!0){const f=e.role==="user",y=L==="imessage",_=h({display:"flex",flexDirection:"column",alignItems:f?"flex-end":"flex-start",marginBottom:y&&!i?"2px":"16px"});if(_.className=`ago-message ago-message--${e.role}`,!f&&B&&e.agent){const C=h({fontSize:"13px",fontWeight:"500",color:te,marginBottom:"6px",padding:"0 4px"});C.className="ago-message__agent",C.textContent=e.agent.displayName||e.agent.name,_.appendChild(C)}if(!f&&e.sources&&e.sources.length>0){const C=h({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});C.className="ago-message__sources",e.sources.forEach((E,R)=>{const z=E.url?document.createElement("a"):document.createElement("div");E.url&&z instanceof HTMLAnchorElement&&(z.href=E.url,z.target="_blank",z.rel="noopener noreferrer"),v(z,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${N}`,borderRadius:"8px",backgroundColor:K,textDecoration:"none",color:te,fontSize:"12px",overflow:"hidden"});const Me=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"});Me.textContent=String(R+1);const xe=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});xe.textContent=E.title,xe.title=E.title,z.append(Me,xe),C.appendChild(z)}),_.appendChild(C)}const S=f||b||y,$=h({maxWidth:y||f?"75%":S?"85%":"100%",padding:S?"10px 14px":"2px 8px",borderRadius:S?Ce:"0",backgroundColor:f?oe:S?Ge:"transparent",color:f?Ee:te,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if($.className="ago-message__content",y&&i){$.style.position="relative",f?$.style.borderBottomRightRadius="4px":$.style.borderBottomLeftRadius="4px";const C=h({position:"absolute",zIndex:"0",bottom:"0",width:"20px",height:"20px",background:f?oe:Ge});C.className="ago-message__tail";const E=h({position:"absolute",zIndex:"1",bottom:"0",width:"10px",height:"20px",background:Pe});E.className="ago-message__tail-mask",f?(C.style.right="-8px",C.style.borderBottomLeftRadius="15px",E.style.right="-10px",E.style.borderBottomLeftRadius="10px"):(C.style.left="-7px",C.style.borderBottomRightRadius="15px",E.style.left="-10px",E.style.borderBottomRightRadius="10px"),$.append(C,E)}if(e.content?$.appendChild(re(e.content)):e.status==="IN_PROGRESS"&&$.appendChild(ct()),_.appendChild($),n&&e.followUpReplies&&e.followUpReplies.length>0){const C=h({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});C.className="ago-message__followups";for(const E of e.followUpReplies){const R=document.createElement("button");R.type="button",R.className="ago-message__followup-btn",R.textContent=E,R.disabled=!_e,v(R,{padding:"6px 14px",fontSize:"14px",borderRadius:Ce,border:`1px solid ${N}`,backgroundColor:K,color:te,cursor:_e?"pointer":"default",transition:"border-color 0.15s"}),ke&&R.addEventListener("click",()=>ke(E)),R.addEventListener("mouseenter",()=>{R.style.borderColor=be}),R.addEventListener("mouseleave",()=>{R.style.borderColor=N}),C.appendChild(R)}_.appendChild(C)}return _}function at(e){const n=h({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:Ce,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});n.className="ago-form-notice",n.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),v(i,{fontWeight:"700"});const f=document.createElement("span");return f.textContent=e,n.append(i,f),n}function I(){if(T.replaceChildren(),d.length===0){const n=h({textAlign:"center",color:bt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});n.appendChild(re(t)),T.appendChild(n)}else d.forEach((n,i)=>{const f=i===d.length-1||d[i+1].role!==n.role;T.appendChild(rt(n,i===d.length-1,f))});for(const n of Re)T.appendChild(at(n));if(X){const n=h({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});n.textContent=X,T.appendChild(n)}T.scrollTop=T.scrollHeight;const e=d[d.length-1];ot(D&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function st(){for(let e=d.length-1;e>=0;e--){const n=d[e];if(n.role==="assistant"&&n.status==="IN_PROGRESS")return n}}const Ae=e=>{A||(A=e.conversationId)},Ie=e=>{const n=st();n&&(n.content+=e.content,I())},$e=e=>{const n=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");n>=0?d[n]=e:d.push(e),I(),de()},Ne=e=>{const n=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");n>=0?d[n]=e:d.push(e),D=!1,I(),e.status==="DONE"&&Je?.({id:e.id,content:e.content})},Le=e=>{X=e.error,D=!1,d=d.filter(n=>!n.id.startsWith("temp-")),I()};m.on("message:start",Ae),m.on("message:chunk",Ie),m.on("message:answer-complete",$e),m.on("message:complete",Ne),m.on("message:error",Le);const Te=e=>se?.(e),Oe=e=>ie?.(e);se&&m.on("form:submitted",Te),ie&&m.on("form:error",Oe);const pe=[];let Be=!1;const De=e=>{if(Be)return;pe.push(e.install(m));let n=e.store.get().submitted;const i=e.store.subscribe(f=>{f.submitted&&!n&&(Re.push(tt(f.submitResult)),I()),n=f.submitted});pe.push(i)};for(const e of we??[])e.schema!=null?De(ze.createFormCollector(e)):ze.loadFormCollector(m,e).then(n=>De(n)).catch(()=>{});async function fe(e,n){const i=e.trim();if(!i&&!n?.length||D)return;Ze?.(i),D=!0,X=null;const f=Date.now();d.push({id:`temp-user-${f}`,conversationId:A||"",content:i,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${f}`,conversationId:A||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),I();try{const y=await m.sendMessage(i,{conversationId:A,files:n});y.conversationId&&(A||(A=y.conversationId),Y?.setActiveThread(y.conversationId,y.createdAt));const _=d.find(S=>S.id===`temp-user-${f}`);if(_&&(_.id=`user-${f}`,_.conversationId=y.conversationId),!d.some(S=>S.id===y.id)){const S=d.findIndex($=>$.id===`temp-assistant-${f}`);S>=0?d[S]=y:d.push(y)}d=d.filter(S=>!S.id.startsWith("temp-")),D=!1,I(),O&&ue()}catch(y){X=y instanceof Error?y.message:"Failed to send message",D=!1,d=d.filter(_=>!_.id.startsWith("temp-")),I()}}async function ue(){try{const e=await m.getConversations();Z.splice(0,Z.length,...e)}catch{}return Z}async function it(e){try{const n=(await m.getConversation(e))?.messages??[];n.length>0&&d.length===0&&(d=n,I())}catch{d.length===0&&(Y?.clear(),A=void 0)}}return I(),de(),A&&it(A),O&&ue(),{client:m,element:J,sendMessage:fe,...W?{open:me,close:he,toggle:lt}:{},session:Y,threads:Z,refreshThreads:ue,destroy(){m.off("message:start",Ae),m.off("message:chunk",Ie),m.off("message:answer-complete",$e),m.off("message:complete",Ne),m.off("message:error",Le),se&&m.off("form:submitted",Te),ie&&m.off("form:error",Oe),Be=!0,pe.forEach(e=>e()),J.remove(),w?.remove(),o.client||m.destroy()}};function ge(){if(!F)return;const e=l==="left"?"translateX(-100%)":"translateX(100%)";F.style.transform=P?"translateX(0)":e,F.setAttribute("aria-hidden",P?"false":"true"),w&&(w.style.display=P?"none":"flex")}function me(){P=!0,ge(),de()}function he(){P=!1,ge()}function lt(){P?he():me()}function dt(){const e="http://www.w3.org/2000/svg",n=document.createElementNS(e,"svg");n.setAttribute("width","26"),n.setAttribute("height","26"),n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("fill","none");const i=document.createElementNS(e,"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"),n.appendChild(i),n}function ct(){const e=h({display:"flex",gap:"4px",padding:"4px 0"});for(let n=0;n<3;n++){const i=h({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${n*.2}s`});e.appendChild(i)}return e}}function Rt(r){let o=[];const a=document.createElement("form");v(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${N}`,backgroundColor:K}),a.className="ago-chat-input";const t=h({display:"flex",flexWrap:"wrap",gap:"6px"}),g=h({display:"flex",gap:"8px",alignItems:"flex-end"}),s=document.createElement("textarea");s.placeholder=r.placeholder,s.rows=1,v(s,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${N}`,borderRadius:"12px",fontSize:"16px",fontFamily:ve,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const u=document.createElement("button");u.type="submit",u.textContent="Send",v(u,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:oe,color:Ee,fontSize:"16px",fontWeight:"500",cursor:"pointer"});let l=null,p=null;r.allowFiles&&(l=document.createElement("input"),l.type="file",l.multiple=!0,v(l,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",v(p,{padding:"10px 12px",border:`1px solid ${N}`,borderRadius:"12px",backgroundColor:K,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>l?.click()),l.addEventListener("change",()=>{o=[...o,...Array.from(l?.files??[])],c()}));function c(){t.replaceChildren(),o.forEach((b,L)=>{const V=h({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${N}`,borderRadius:"8px",fontSize:"12px"}),Q=document.createElement("span");Q.textContent=b.name;const O=document.createElement("button");O.type="button",O.textContent="×",v(O,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),O.addEventListener("click",()=>{o=o.filter((we,U)=>U!==L),c()}),V.append(Q,O),t.appendChild(V)})}const x=()=>{const b=s.value,L=o;return s.value="",o=[],c(),{content:b,files:L}},B=()=>{const{content:b,files:L}=x();(b.trim()||L.length>0)&&r.onSend(b.trim(),L.length>0?L:void 0)};return a.addEventListener("submit",b=>{b.preventDefault(),B()}),s.addEventListener("keydown",b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),B())}),p&&g.appendChild(p),g.append(s,u),l&&a.appendChild(l),a.append(t,g),{inputRow:a,getValueAndClear:x,setDisabled:b=>{s.disabled=b,u.disabled=b,u.style.opacity=b?"0.6":"1",u.style.cursor=b?"not-allowed":"pointer"},focus:()=>s.focus()}}exports.mountChatWidget=St;exports.renderMarkdown=re;
|
|
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;
|
package/dist/widget.d.cts
CHANGED
|
@@ -7,6 +7,27 @@ declare interface AgoAgent {
|
|
|
7
7
|
displayName?: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* An uploaded file attached to a message.
|
|
12
|
+
*
|
|
13
|
+
* `url` is a presigned, time-limited URL the backend generates per request (or a
|
|
14
|
+
* local `blob:` URL for an optimistic preview). `isSafeImage` is the backend's
|
|
15
|
+
* verdict that the file is a real, script-free image safe to embed inline; the
|
|
16
|
+
* UI only renders an `<img>` when it is true and otherwise shows a download link.
|
|
17
|
+
*/
|
|
18
|
+
declare interface AgoAttachment {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
/** MIME type reported by the backend (e.g. `image/png`). */
|
|
22
|
+
contentType?: string;
|
|
23
|
+
/** Size in bytes. */
|
|
24
|
+
fileSize?: number;
|
|
25
|
+
/** Presigned download/preview URL, or a local `blob:` URL before upload. */
|
|
26
|
+
url?: string;
|
|
27
|
+
/** True only when the backend verified the file is a safe inline image. */
|
|
28
|
+
isSafeImage: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
10
31
|
/**
|
|
11
32
|
* Main SDK client for AGO Chat integration
|
|
12
33
|
*/
|
|
@@ -363,6 +384,8 @@ declare interface AgoMessage {
|
|
|
363
384
|
sources?: AgoSource[];
|
|
364
385
|
toolCalls?: ToolCallData[];
|
|
365
386
|
followUpReplies?: string[];
|
|
387
|
+
/** Uploaded files on this message (usually the user's). */
|
|
388
|
+
attachments?: AgoAttachment[];
|
|
366
389
|
createdAt: Date;
|
|
367
390
|
}
|
|
368
391
|
|
|
@@ -777,8 +800,13 @@ export declare interface MountChatWidgetOptions {
|
|
|
777
800
|
persistConversation?: boolean | Partial<ConversationSessionOptions>;
|
|
778
801
|
/** Widget title shown in the header. */
|
|
779
802
|
title?: string;
|
|
780
|
-
/**
|
|
781
|
-
|
|
803
|
+
/**
|
|
804
|
+
* Greeting shown before any conversation has started. A plain string renders
|
|
805
|
+
* the classic centered empty-state; pass a {@link WelcomeMessage} object with
|
|
806
|
+
* `mode: "streaming"` to type it out as a real assistant bubble on a fresh
|
|
807
|
+
* visit instead.
|
|
808
|
+
*/
|
|
809
|
+
welcomeMessage?: WelcomeMessage;
|
|
782
810
|
/** Input placeholder. */
|
|
783
811
|
placeholder?: string;
|
|
784
812
|
/** Enable file attachments. */
|
|
@@ -1023,6 +1051,24 @@ declare interface ToolCallData {
|
|
|
1023
1051
|
|
|
1024
1052
|
declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
|
|
1025
1053
|
|
|
1054
|
+
/**
|
|
1055
|
+
* The greeting shown before any conversation has started. Pass a plain string
|
|
1056
|
+
* for the classic centered empty-state placeholder, or an object to control how
|
|
1057
|
+
* it is presented:
|
|
1058
|
+
*
|
|
1059
|
+
* - `mode: "static"` (default): the centered, muted empty-state text. It is not
|
|
1060
|
+
* a real message and disappears once the conversation starts.
|
|
1061
|
+
* - `mode: "streaming"`: the greeting is delivered as a real assistant message
|
|
1062
|
+
* bubble, typed out token-by-token, that stays in the thread. It only plays on
|
|
1063
|
+
* a fresh visit (skipped when a thread is being resumed), and `speed` sets the
|
|
1064
|
+
* per-token interval in milliseconds (default `45`).
|
|
1065
|
+
*/
|
|
1066
|
+
export declare type WelcomeMessage = string | {
|
|
1067
|
+
message: string;
|
|
1068
|
+
mode?: "static" | "streaming";
|
|
1069
|
+
speed?: number;
|
|
1070
|
+
};
|
|
1071
|
+
|
|
1026
1072
|
/**
|
|
1027
1073
|
* Theme overrides for {@link mountChatWidget}. *
|
|
1028
1074
|
* @see The `--ago-*` token reference in `docs/general/widget.md`.
|
package/dist/widget.d.ts
CHANGED
|
@@ -7,6 +7,27 @@ declare interface AgoAgent {
|
|
|
7
7
|
displayName?: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* An uploaded file attached to a message.
|
|
12
|
+
*
|
|
13
|
+
* `url` is a presigned, time-limited URL the backend generates per request (or a
|
|
14
|
+
* local `blob:` URL for an optimistic preview). `isSafeImage` is the backend's
|
|
15
|
+
* verdict that the file is a real, script-free image safe to embed inline; the
|
|
16
|
+
* UI only renders an `<img>` when it is true and otherwise shows a download link.
|
|
17
|
+
*/
|
|
18
|
+
declare interface AgoAttachment {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
/** MIME type reported by the backend (e.g. `image/png`). */
|
|
22
|
+
contentType?: string;
|
|
23
|
+
/** Size in bytes. */
|
|
24
|
+
fileSize?: number;
|
|
25
|
+
/** Presigned download/preview URL, or a local `blob:` URL before upload. */
|
|
26
|
+
url?: string;
|
|
27
|
+
/** True only when the backend verified the file is a safe inline image. */
|
|
28
|
+
isSafeImage: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
10
31
|
/**
|
|
11
32
|
* Main SDK client for AGO Chat integration
|
|
12
33
|
*/
|
|
@@ -363,6 +384,8 @@ declare interface AgoMessage {
|
|
|
363
384
|
sources?: AgoSource[];
|
|
364
385
|
toolCalls?: ToolCallData[];
|
|
365
386
|
followUpReplies?: string[];
|
|
387
|
+
/** Uploaded files on this message (usually the user's). */
|
|
388
|
+
attachments?: AgoAttachment[];
|
|
366
389
|
createdAt: Date;
|
|
367
390
|
}
|
|
368
391
|
|
|
@@ -777,8 +800,13 @@ export declare interface MountChatWidgetOptions {
|
|
|
777
800
|
persistConversation?: boolean | Partial<ConversationSessionOptions>;
|
|
778
801
|
/** Widget title shown in the header. */
|
|
779
802
|
title?: string;
|
|
780
|
-
/**
|
|
781
|
-
|
|
803
|
+
/**
|
|
804
|
+
* Greeting shown before any conversation has started. A plain string renders
|
|
805
|
+
* the classic centered empty-state; pass a {@link WelcomeMessage} object with
|
|
806
|
+
* `mode: "streaming"` to type it out as a real assistant bubble on a fresh
|
|
807
|
+
* visit instead.
|
|
808
|
+
*/
|
|
809
|
+
welcomeMessage?: WelcomeMessage;
|
|
782
810
|
/** Input placeholder. */
|
|
783
811
|
placeholder?: string;
|
|
784
812
|
/** Enable file attachments. */
|
|
@@ -1023,6 +1051,24 @@ declare interface ToolCallData {
|
|
|
1023
1051
|
|
|
1024
1052
|
declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
|
|
1025
1053
|
|
|
1054
|
+
/**
|
|
1055
|
+
* The greeting shown before any conversation has started. Pass a plain string
|
|
1056
|
+
* for the classic centered empty-state placeholder, or an object to control how
|
|
1057
|
+
* it is presented:
|
|
1058
|
+
*
|
|
1059
|
+
* - `mode: "static"` (default): the centered, muted empty-state text. It is not
|
|
1060
|
+
* a real message and disappears once the conversation starts.
|
|
1061
|
+
* - `mode: "streaming"`: the greeting is delivered as a real assistant message
|
|
1062
|
+
* bubble, typed out token-by-token, that stays in the thread. It only plays on
|
|
1063
|
+
* a fresh visit (skipped when a thread is being resumed), and `speed` sets the
|
|
1064
|
+
* per-token interval in milliseconds (default `45`).
|
|
1065
|
+
*/
|
|
1066
|
+
export declare type WelcomeMessage = string | {
|
|
1067
|
+
message: string;
|
|
1068
|
+
mode?: "static" | "streaming";
|
|
1069
|
+
speed?: number;
|
|
1070
|
+
};
|
|
1071
|
+
|
|
1026
1072
|
/**
|
|
1027
1073
|
* Theme overrides for {@link mountChatWidget}. *
|
|
1028
1074
|
* @see The `--ago-*` token reference in `docs/general/widget.md`.
|