@useago/sdk 1.0.10 → 1.0.11
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/react.cjs +3 -3
- package/dist/react.js +363 -341
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +25 -2
- package/dist/widget.d.ts +25 -2
- package/dist/widget.js +460 -412
- package/package.json +1 -1
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 Ge=require("./AgoClient-B3-WGVne.cjs"),je=require("./createFormCollector-BI3DXaew.cjs"),xt=require("./createConversationSession-C0diFTUk.cjs");var bt={"&":"&","<":"<",">":">",'"':""","'":"'"};function K(r){return r.replace(/[&<>"']/g,o=>bt[o])}function qe(r){const o=r.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var Je='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',le="";function P(r){const o=[],a=u=>(o.push(u),`${le}${o.length-1}${le}`);let n=r;return n=n.replace(/`([^`]+)`/g,(u,i)=>a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Je}">${K(i)}</code>`)),n=n.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(u,i,v)=>{const p=qe(v);return p?a(`<img alt="${K(i)}" src="${K(p)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):u}),n=n.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(u,i,v)=>{const p=qe(v);return p?a(`<a href="${K(p)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${P(i)}</a>`):u}),n=K(n),n=n.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),n=n.replace(new RegExp(`${le}(\\d+)${le}`,"g"),(u,i)=>o[Number(i)]),n}function N(r,o,a){const n=document.createElement(r);return Object.assign(n.style,o),a!==void 0&&(n.innerHTML=a),n}var et=/^ {0,3}([-*_])( *\1){2,} *$/,tt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,nt=/^ {0,3}(```+|~~~+)/,ce=/^ {0,3}>\s?/,V=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,vt=["20px","18px","16px","15px","14px","13px"],Re=r=>r.match(/^\s*/)?.[0].length??0;function Ct(r){return r.trim()===""||et.test(r)||tt.test(r)||nt.test(r)||ce.test(r)||V.test(r)}function ot(r){const o=r[0].match(V),a=o[1].length,n=/\d/.test(o[2]),u=N(n?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:n?"decimal":"disc",listStylePosition:"outside"});let i=0;for(;i<r.length;){const v=r[i].match(V),p=[];for(i++;i<r.length&&Re(r[i])>a;)p.push(r[i]),i++;const b=N("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),d=v[3].match(/^\[([ xX])\]\s+(.*)$/);d?(b.style.listStyleType="none",b.style.marginLeft="-20px",b.innerHTML=`<span style="margin-right:6px">${d[1].toLowerCase()==="x"?"☑":"☐"}</span>${P(d[2])}`):b.innerHTML=P(v[3]),p.filter(g=>V.test(g)).length>0&&b.appendChild(ot(p.filter(g=>g.trim()!==""))),u.appendChild(b)}return u}function yt(r){const o=p=>p.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(b=>b.trim()),a=N("div",{overflowX:"auto",margin:"0 0 8px 0"}),n=N("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),u=document.createElement("thead"),i=document.createElement("tr");for(const p of o(r[0]))i.appendChild(N("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},P(p)));u.appendChild(i),n.appendChild(u);const v=document.createElement("tbody");for(const p of r.slice(2)){const b=document.createElement("tr");for(const d of o(p))b.appendChild(N("td",{border:"1px solid #dee3e8",padding:"6px 10px"},P(d)));v.appendChild(b)}return n.appendChild(v),a.appendChild(n),a}var wt=r=>!!r&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(r);function fe(r){const o=document.createDocumentFragment(),a=r.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let
|
|
4
|
-
`)))),o.appendChild(
|
|
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 v=i.match(nt);if(v){const d=v[1][0],g=[];for(n++;n<a.length&&!new RegExp(`^ {0,3}${d==="`"?"`{3,}":"~{3,}"}\\s*$`).test(a[n]);)g.push(a[n]),n++;n++;const M=N("pre",{margin:"0 0 8px 0"});M.appendChild(N("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:Je,whiteSpace:"pre"},K(g.join(`
|
|
4
|
+
`)))),o.appendChild(M);continue}if(et.test(i)){o.appendChild(N("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),n++;continue}const p=i.match(tt);if(p){const d=p[1].length;o.appendChild(N(`h${d}`,{margin:"16px 0 8px 0",fontSize:vt[d-1],fontWeight:"600",lineHeight:"1.3"},P(p[2]))),n++;continue}if(ce.test(i)){const d=[];for(;n<a.length&&ce.test(a[n]);)d.push(a[n].replace(ce,"")),n++;const g=N("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});g.appendChild(fe(d.join(`
|
|
5
|
+
`))),o.appendChild(g);continue}if(i.includes("|")&&wt(a[n+1])){const d=[i,a[n+1]];for(n+=2;n<a.length&&a[n].includes("|")&&a[n].trim();)d.push(a[n]),n++;o.appendChild(yt(d));continue}if(V.test(i)){const d=[],g=Re(i);for(;n<a.length&&a[n].trim()!=="";)if(V.test(a[n])||Re(a[n])>g)d.push(a[n]),n++;else break;o.appendChild(ot(d));continue}const b=[i];for(n++;n<a.length&&!Ct(a[n]);)b.push(a[n]),n++;o.appendChild(N("p",{margin:"0 0 8px 0",lineHeight:"1.6"},b.map(d=>P(d)).join("<br>")))}const u=o.lastElementChild;return u&&(u.style.marginBottom="0"),o}var _e='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Xe={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color",agentBubbleBg:"--ago-agent-bubble-background"},pe="var(--ago-brand-color, #03182f)",ke="var(--ago-brand-text-color, #fff)",Et="var(--ago-header-background, var(--ago-brand-color, #03182f))",Ke="var(--ago-header-text-color, #e8f0fe)",ee="var(--ago-panel-background, #fff)",Ve="var(--ago-messages-background, #fbfbfb)",de="var(--ago-text-color, #30373e)",St="var(--ago-muted-text-color, #6b6d6f)",O="var(--ago-border-color, #dee3e8)",Ee="var(--ago-accent-color, #1b5fc4)",Ye="var(--ago-agent-bubble-background, #f1f3f5)",Rt="var(--ago-radius, 16px)",Se="var(--ago-message-radius, 16px)",_t="var(--ago-message-radius, 20px)";function kt(r,o){if(o)for(const a of Object.keys(Xe)){const n=o[a];n!=null&&r.style.setProperty(Xe[a],n)}}function E(r,o){Object.assign(r.style,o)}function x(r={}){const o=document.createElement("div");return E(o,r),o}var Ze="Form submitted.";function At(r){if(typeof r=="string")return r||null;if(!r||typeof r!="object")return null;const o=r;if(typeof o.message=="string"&&o.message)return o.message;const a=o.result;if(typeof a=="string"&&a)return a;if(a&&typeof a=="object"){const n=a.message;if(typeof n=="string"&&n)return n}return null}var Qe="ago-chat-widget-keyframes";function It(){if(typeof document>"u"||document.getElementById(Qe))return;const r=document.createElement("style");r.id=Qe,r.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }",document.head.appendChild(r)}function Nt(r){const o=typeof r=="string"?document.querySelector(r):r;if(!o)throw new Error(`mountChatWidget: target "${String(r)}" not found.`);return o}function $t(r,o){const{title:a="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:i=!1,height:v=500,placement:p="inline",width:b=400,defaultOpen:d=!1,logoUrl:g,showAgentName:M=!1,agentBubble:$=!1,bubbleStyle:T="default",showHeader:Y=!0,theme:te,loadThreads:Z=!1,forms:m,formSubmittedMessage:C=Ze,onFollowUpClick:G,onMessageSent:ne,onMessageReceived:B,onFormSubmitted:oe,onFormError:Q}=o,re=typeof n=="string"?{message:n,mode:"static"}:n,Ae=re.message,Ie=re.mode??"static",rt="speed"in re&&re.speed||45;if(!o.client&&!o.config?.baseUrl)throw new Ge.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const h=o.client??new Ge.AgoClient(o.config),Ne=Nt(r),j=p==="left"||p==="right",at=j&&(o.launcher??!0);let q=j?d:!0;const ue=o.persistConversation,ae=ue?xt.createConversationSession(ue===!0?{}:ue):void 0;let L=o.conversationId??ae?.getLastActiveThread()??void 0,l=[],H=!1,J=null,D;const $e=[];function it(e){if(typeof C=="function"){const s=C(e);if(typeof s=="string"&&s)return s}const t=At(e);return t||(typeof C=="string"?C:Ze)}const ie=[],X=x({display:"flex",flexDirection:"column",height:j?"100%":typeof v=="number"?`${v}px`:v,border:`1px solid ${O}`,borderRadius:Rt,overflow:"hidden",backgroundColor:ee,fontFamily:_e,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});X.className="ago-chat-widget",kt(X,te);let z;if(Y){if(z=x({padding:"14px 16px",borderBottom:`1px solid ${O}`,backgroundColor:Et,color:Ke,display:"flex",alignItems:"center",gap:"10px"}),z.className="ago-chat-widget__header",g){const t=document.createElement("img");t.src=g,t.alt="Logo",E(t,{height:"24px",width:"auto"}),z.appendChild(t)}const e=document.createElement("h3");if(e.textContent=a,E(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),z.appendChild(e),j){const t=document.createElement("button");t.type="button",t.className="ago-chat-widget__close",t.setAttribute("aria-label","Close"),t.textContent="×",E(t,{marginLeft:"auto",background:"transparent",border:"none",color:Ke,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),t.addEventListener("click",()=>ye()),z.appendChild(t)}}const R=x({flex:"1",overflow:"auto",padding:"16px",backgroundColor:Ve});R.className="ago-chat-widget__messages",R.setAttribute("role","log"),R.setAttribute("aria-live","polite"),R.setAttribute("aria-relevant","additions text"),R.setAttribute("aria-atomic","false");const{inputRow:st,setDisabled:lt,focus:ge}=Tt({placeholder:u,allowFiles:i,onSend:(e,t)=>{xe(e,t)}});It(),X.append(...z?[z]:[],R,st);let se=X,U,_;const me=p==="left"?"left":"right";if(j&&(U=x({position:"fixed",top:"0",bottom:"0",[me]:"0",width:typeof b=="number"?`${b}px`:b,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),U.className="ago-chat-widget-panel",E(X,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[me==="left"?"borderRight":"borderLeft"]:`1px solid ${O}`}),U.appendChild(X),se=U),at){if(_=document.createElement("button"),_.type="button",_.className="ago-chat-widget-launcher",_.setAttribute("aria-label",`Open ${a}`),E(_,{position:"fixed",bottom:"20px",[me]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:pe,color:ke,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:_e}),g){const e=document.createElement("img");e.src=g,e.alt="",E(e,{width:"26px",height:"26px",objectFit:"contain"}),_.appendChild(e)}else _.appendChild(mt());_.addEventListener("click",()=>Ce())}Ne.appendChild(se),_&&Ne.appendChild(_),ve();const Te=G!==!1,Le=G===!1?void 0:G??(e=>{xe(e)});function dt(e,t,s=!0){const c=e.role==="user",f=T==="imessage",w=x({display:"flex",flexDirection:"column",alignItems:c?"flex-end":"flex-start",marginBottom:f&&!s?"2px":"16px"});if(w.className=`ago-message ago-message--${e.role}`,!c&&M&&e.agent){const y=x({fontSize:"13px",fontWeight:"500",color:de,marginBottom:"6px",padding:"0 4px"});y.className="ago-message__agent",y.textContent=e.agent.displayName||e.agent.name,w.appendChild(y)}if(!c&&e.sources&&e.sources.length>0){const y=x({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});y.className="ago-message__sources",e.sources.forEach((S,I)=>{const W=S.url?document.createElement("a"):document.createElement("div");S.url&&W instanceof HTMLAnchorElement&&(W.href=S.url,W.target="_blank",W.rel="noopener noreferrer"),E(W,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${O}`,borderRadius:"8px",backgroundColor:ee,textDecoration:"none",color:de,fontSize:"12px",overflow:"hidden"});const Pe=x({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${Ee}`,color:Ee,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Pe.textContent=String(I+1);const we=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});we.textContent=S.title,we.title=S.title,W.append(Pe,we),y.appendChild(W)}),w.appendChild(y)}const A=c||$||f,F=x({maxWidth:f||c?"75%":A?"85%":"100%",padding:A?"10px 14px":"2px 8px",borderRadius:f?_t:A?Se:"0",backgroundColor:c?pe:A?Ye:"transparent",color:c?ke:de,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(F.className="ago-message__content",f&&s){F.style.position="relative";const y=x({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:c?pe:Ye});y.className="ago-message__tail";const S=x({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:Ve});S.className="ago-message__tail-mask",c?(y.style.right="-8px",y.style.borderBottomLeftRadius="16px 14px",S.style.right="-10px",S.style.borderBottomLeftRadius="10px"):(y.style.left="-7px",y.style.borderBottomRightRadius="16px 14px",S.style.left="-10px",S.style.borderBottomRightRadius="10px"),F.append(y,S)}if(e.content?F.appendChild(fe(e.content)):e.status==="IN_PROGRESS"&&F.appendChild(ht()),w.appendChild(F),t&&e.followUpReplies&&e.followUpReplies.length>0){const y=x({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});y.className="ago-message__followups";for(const S of e.followUpReplies){const I=document.createElement("button");I.type="button",I.className="ago-message__followup-btn",I.textContent=S,I.disabled=!Te,E(I,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:Se,border:`1px solid ${O}`,backgroundColor:ee,color:de,cursor:Te?"pointer":"default",transition:"border-color 0.15s"}),Le&&I.addEventListener("click",()=>Le(S)),I.addEventListener("mouseenter",()=>{I.style.borderColor=Ee}),I.addEventListener("mouseleave",()=>{I.style.borderColor=O}),y.appendChild(I)}w.appendChild(y)}return w}function ct(e){const t=x({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:Se,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});t.className="ago-form-notice",t.setAttribute("role","status");const s=document.createElement("span");s.textContent="✓",s.setAttribute("aria-hidden","true"),E(s,{fontWeight:"700"});const c=document.createElement("span");return c.textContent=e,t.append(s,c),t}function k(){if(R.replaceChildren(),l.length===0){if(Ie==="static"){const t=x({textAlign:"center",color:St,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});t.appendChild(fe(Ae)),R.appendChild(t)}}else l.forEach((t,s)=>{const c=s===l.length-1||l[s+1].role!==t.role;R.appendChild(dt(t,s===l.length-1,c))});for(const t of $e)R.appendChild(ct(t));if(J){const t=x({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});t.setAttribute("role","alert"),t.textContent=J,R.appendChild(t)}R.scrollTop=R.scrollHeight;const e=l[l.length-1];lt(H&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function pt(){for(let e=l.length-1;e>=0;e--){const t=l[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const Oe=e=>{L||(L=e.conversationId)},Me=e=>{const t=pt();t&&(t.content+=e.content,k())},Be=e=>{const t=l.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");t>=0?l[t]=e:l.push(e),k(),ge()},De=e=>{const t=l.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");t>=0?l[t]=e:l.push(e),H=!1,k(),e.status==="DONE"&&B?.({id:e.id,content:e.content})},Fe=e=>{J=e.error,H=!1,l=l.filter(t=>!t.id.startsWith("temp-")),k()};function ft(e){const t={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l.push(t),k();const s=e.match(/\S+\s*/g)??[e];let c=0;D=setInterval(()=>{if(c>=s.length){clearInterval(D),D=void 0,t.status="DONE",k();return}t.content+=s[c],c++,k()},rt)}h.on("message:start",Oe),h.on("message:chunk",Me),h.on("message:answer-complete",Be),h.on("message:complete",De),h.on("message:error",Fe);const He=e=>oe?.(e),ze=e=>Q?.(e);oe&&h.on("form:submitted",He),Q&&h.on("form:error",ze);const he=[];let Ue=!1;const We=e=>{if(Ue)return;he.push(e.install(h));let t=e.store.get().submitted;const s=e.store.subscribe(c=>{c.submitted&&!t&&($e.push(it(c.submitResult)),k()),t=c.submitted});he.push(s)};for(const e of m??[])e.schema!=null?We(je.createFormCollector(e)):je.loadFormCollector(h,e).then(t=>We(t)).catch(()=>{});async function xe(e,t){const s=e.trim();if(!s&&!t?.length||H)return;if(ne?.(s),H=!0,J=null,D){clearInterval(D),D=void 0;const f=l.find(w=>w.id.startsWith("ago-intro-"));f&&!f.content?l=l.filter(w=>w!==f):f&&(f.status="DONE")}const c=Date.now();l.push({id:`temp-user-${c}`,conversationId:L||"",content:s,role:"user",status:"DONE",createdAt:new Date}),l.push({id:`temp-assistant-${c}`,conversationId:L||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),k();try{const f=await h.sendMessage(s,{conversationId:L,files:t});f.conversationId&&(L||(L=f.conversationId),ae?.setActiveThread(f.conversationId,f.createdAt));const w=l.find(A=>A.id===`temp-user-${c}`);if(w&&(w.id=`user-${c}`,w.conversationId=f.conversationId),!l.some(A=>A.id===f.id)){const A=l.findIndex(F=>F.id===`temp-assistant-${c}`);A>=0?l[A]=f:l.push(f)}l=l.filter(A=>!A.id.startsWith("temp-")),H=!1,k(),Z&&be()}catch(f){J=f instanceof Error?f.message:"Failed to send message",H=!1,l=l.filter(w=>!w.id.startsWith("temp-")),k()}}async function be(){try{const e=await h.getConversations();ie.splice(0,ie.length,...e)}catch{}return ie}async function ut(e){try{const t=(await h.getConversation(e))?.messages??[];t.length>0&&l.length===0&&(l=t,k())}catch{l.length===0&&(ae?.clear(),L=void 0)}}return k(),ge(),L?ut(L):Ie==="streaming"&&ft(Ae),Z&&be(),{client:h,element:se,sendMessage:xe,...j?{open:Ce,close:ye,toggle:gt}:{},session:ae,threads:ie,refreshThreads:be,destroy(){D&&clearInterval(D),h.off("message:start",Oe),h.off("message:chunk",Me),h.off("message:answer-complete",Be),h.off("message:complete",De),h.off("message:error",Fe),oe&&h.off("form:submitted",He),Q&&h.off("form:error",ze),Ue=!0,he.forEach(e=>e()),se.remove(),_?.remove(),o.client||h.destroy()}};function ve(){if(!U)return;const e=p==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=q?"translateX(0)":e,U.setAttribute("aria-hidden",q?"false":"true"),_&&(_.style.display=q?"none":"flex")}function Ce(){q=!0,ve(),ge()}function ye(){q=!1,ve()}function gt(){q?ye():Ce()}function mt(){const e="http://www.w3.org/2000/svg",t=document.createElementNS(e,"svg");t.setAttribute("width","26"),t.setAttribute("height","26"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("fill","none");const s=document.createElementNS(e,"path");return s.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-width","2"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),t.appendChild(s),t}function ht(){const e=x({display:"flex",gap:"4px",padding:"4px 0"});for(let t=0;t<3;t++){const s=x({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${t*.2}s`});e.appendChild(s)}return e}}function Tt(r){let o=[];const a=document.createElement("form");E(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${O}`,backgroundColor:ee}),a.className="ago-chat-input";const n=x({display:"flex",flexWrap:"wrap",gap:"6px"}),u=x({display:"flex",gap:"8px",alignItems:"flex-end"}),i=document.createElement("textarea");i.placeholder=r.placeholder,i.setAttribute("aria-label",r.placeholder),i.rows=1,E(i,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${O}`,borderRadius:"12px",fontSize:"16px",fontFamily:_e,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const v=()=>{i.style.height="auto";const C=Math.min(i.scrollHeight+2,110);i.style.height=`${C}px`,i.style.overflowY=i.scrollHeight+2>110?"auto":"hidden"};i.addEventListener("input",()=>{v(),M()});const p='<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>',b='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',d=document.createElement("button");d.type="submit",d.setAttribute("aria-label","Send"),d.innerHTML=p,E(d,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:pe,color:ke,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let g=!1;const M=()=>{const m=i.value.trim()!==""||o.length>0,C=g||!m;d.disabled=C,d.innerHTML=g?b:p,d.style.opacity=C&&!g?"0.5":"1",d.style.cursor=C?"default":"pointer"};let $=null,T=null;r.allowFiles&&($=document.createElement("input"),$.type="file",$.multiple=!0,E($,{display:"none"}),T=document.createElement("button"),T.type="button",T.setAttribute("aria-label","Attach file"),T.textContent="📎",E(T,{padding:"10px 12px",border:`1px solid ${O}`,borderRadius:"12px",backgroundColor:ee,cursor:"pointer",fontSize:"14px"}),T.addEventListener("click",()=>$?.click()),$.addEventListener("change",()=>{o=[...o,...Array.from($?.files??[])],Y()}));function Y(){n.replaceChildren(),o.forEach((m,C)=>{const G=x({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${O}`,borderRadius:"8px",fontSize:"12px"}),ne=document.createElement("span");ne.textContent=m.name;const B=document.createElement("button");B.type="button",B.setAttribute("aria-label",`Remove ${m.name}`),B.textContent="×",E(B,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),B.addEventListener("click",()=>{o=o.filter((oe,Q)=>Q!==C),Y()}),G.append(ne,B),n.appendChild(G)}),M()}const te=()=>{const m=i.value,C=o;return i.value="",v(),o=[],Y(),{content:m,files:C}},Z=()=>{const{content:m,files:C}=te();(m.trim()||C.length>0)&&r.onSend(m.trim(),C.length>0?C:void 0)};return a.addEventListener("submit",m=>{m.preventDefault(),Z()}),i.addEventListener("keydown",m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),Z())}),T&&u.appendChild(T),u.append(i,d),$&&a.appendChild($),a.append(n,u),M(),{inputRow:a,getValueAndClear:te,setDisabled:m=>{i.disabled=m,g=m,M()},focus:()=>i.focus()}}exports.mountChatWidget=$t;exports.renderMarkdown=fe;
|
package/dist/widget.d.cts
CHANGED
|
@@ -777,8 +777,13 @@ export declare interface MountChatWidgetOptions {
|
|
|
777
777
|
persistConversation?: boolean | Partial<ConversationSessionOptions>;
|
|
778
778
|
/** Widget title shown in the header. */
|
|
779
779
|
title?: string;
|
|
780
|
-
/**
|
|
781
|
-
|
|
780
|
+
/**
|
|
781
|
+
* Greeting shown before any conversation has started. A plain string renders
|
|
782
|
+
* the classic centered empty-state; pass a {@link WelcomeMessage} object with
|
|
783
|
+
* `mode: "streaming"` to type it out as a real assistant bubble on a fresh
|
|
784
|
+
* visit instead.
|
|
785
|
+
*/
|
|
786
|
+
welcomeMessage?: WelcomeMessage;
|
|
782
787
|
/** Input placeholder. */
|
|
783
788
|
placeholder?: string;
|
|
784
789
|
/** Enable file attachments. */
|
|
@@ -1023,6 +1028,24 @@ declare interface ToolCallData {
|
|
|
1023
1028
|
|
|
1024
1029
|
declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
|
|
1025
1030
|
|
|
1031
|
+
/**
|
|
1032
|
+
* The greeting shown before any conversation has started. Pass a plain string
|
|
1033
|
+
* for the classic centered empty-state placeholder, or an object to control how
|
|
1034
|
+
* it is presented:
|
|
1035
|
+
*
|
|
1036
|
+
* - `mode: "static"` (default): the centered, muted empty-state text. It is not
|
|
1037
|
+
* a real message and disappears once the conversation starts.
|
|
1038
|
+
* - `mode: "streaming"`: the greeting is delivered as a real assistant message
|
|
1039
|
+
* bubble, typed out token-by-token, that stays in the thread. It only plays on
|
|
1040
|
+
* a fresh visit (skipped when a thread is being resumed), and `speed` sets the
|
|
1041
|
+
* per-token interval in milliseconds (default `45`).
|
|
1042
|
+
*/
|
|
1043
|
+
export declare type WelcomeMessage = string | {
|
|
1044
|
+
message: string;
|
|
1045
|
+
mode?: "static" | "streaming";
|
|
1046
|
+
speed?: number;
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1026
1049
|
/**
|
|
1027
1050
|
* Theme overrides for {@link mountChatWidget}. *
|
|
1028
1051
|
* @see The `--ago-*` token reference in `docs/general/widget.md`.
|
package/dist/widget.d.ts
CHANGED
|
@@ -777,8 +777,13 @@ export declare interface MountChatWidgetOptions {
|
|
|
777
777
|
persistConversation?: boolean | Partial<ConversationSessionOptions>;
|
|
778
778
|
/** Widget title shown in the header. */
|
|
779
779
|
title?: string;
|
|
780
|
-
/**
|
|
781
|
-
|
|
780
|
+
/**
|
|
781
|
+
* Greeting shown before any conversation has started. A plain string renders
|
|
782
|
+
* the classic centered empty-state; pass a {@link WelcomeMessage} object with
|
|
783
|
+
* `mode: "streaming"` to type it out as a real assistant bubble on a fresh
|
|
784
|
+
* visit instead.
|
|
785
|
+
*/
|
|
786
|
+
welcomeMessage?: WelcomeMessage;
|
|
782
787
|
/** Input placeholder. */
|
|
783
788
|
placeholder?: string;
|
|
784
789
|
/** Enable file attachments. */
|
|
@@ -1023,6 +1028,24 @@ declare interface ToolCallData {
|
|
|
1023
1028
|
|
|
1024
1029
|
declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
|
|
1025
1030
|
|
|
1031
|
+
/**
|
|
1032
|
+
* The greeting shown before any conversation has started. Pass a plain string
|
|
1033
|
+
* for the classic centered empty-state placeholder, or an object to control how
|
|
1034
|
+
* it is presented:
|
|
1035
|
+
*
|
|
1036
|
+
* - `mode: "static"` (default): the centered, muted empty-state text. It is not
|
|
1037
|
+
* a real message and disappears once the conversation starts.
|
|
1038
|
+
* - `mode: "streaming"`: the greeting is delivered as a real assistant message
|
|
1039
|
+
* bubble, typed out token-by-token, that stays in the thread. It only plays on
|
|
1040
|
+
* a fresh visit (skipped when a thread is being resumed), and `speed` sets the
|
|
1041
|
+
* per-token interval in milliseconds (default `45`).
|
|
1042
|
+
*/
|
|
1043
|
+
export declare type WelcomeMessage = string | {
|
|
1044
|
+
message: string;
|
|
1045
|
+
mode?: "static" | "streaming";
|
|
1046
|
+
speed?: number;
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1026
1049
|
/**
|
|
1027
1050
|
* Theme overrides for {@link mountChatWidget}. *
|
|
1028
1051
|
* @see The `--ago-*` token reference in `docs/general/widget.md`.
|