@useago/sdk 1.0.9 → 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/devtools.cjs +7 -7
- package/dist/devtools.d.cts +11 -0
- package/dist/devtools.d.ts +11 -0
- package/dist/devtools.js +57 -54
- package/dist/react.cjs +3 -3
- package/dist/react.js +363 -341
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +33 -2
- package/dist/widget.d.ts +33 -2
- package/dist/widget.js +473 -403
- 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(h);continue}if(s.includes("|")&&ct(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(dt(c));continue}if(W.test(s)){const c=[],h=he(s);for(;t<a.length&&a[t].trim()!=="";)if(W.test(a[t])||he(a[t])>h)c.push(a[t]),t++;else break;o.appendChild(je(c));continue}const p=[s];for(t++;t<a.length&&!lt(a[t]);)p.push(a[t]),t++;o.appendChild(R("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>M(c)).join("<br>")))}const u=o.lastElementChild;return u&&(u.style.marginBottom="0"),o}var xe='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Me={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"},be="var(--ago-brand-color, #03182f)",Ce="var(--ago-brand-text-color, #fff)",pt="var(--ago-header-background, var(--ago-brand-color, #03182f))",Fe="var(--ago-header-text-color, #e8f0fe)",X="var(--ago-panel-background, #fff)",ft="var(--ago-messages-background, #fbfbfb)",J="var(--ago-text-color, #30373e)",ut="var(--ago-muted-text-color, #6b6d6f)",A="var(--ago-border-color, #dee3e8)",ge="var(--ago-accent-color, #1b5fc4)",gt="var(--ago-agent-bubble-background, #f1f3f5)",mt="var(--ago-radius, 16px)",me="var(--ago-message-radius, 16px)";function ht(r,o){if(o)for(const a of Object.keys(Me)){const t=o[a];t!=null&&r.style.setProperty(Me[a],t)}}function E(r,o){Object.assign(r.style,o)}function b(r={}){const o=document.createElement("div");return E(o,r),o}var ze="Form submitted.";function xt(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 He="ago-chat-widget-keyframes";function bt(){if(typeof document>"u"||document.getElementById(He))return;const r=document.createElement("style");r.id=He,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 Ct(r){const o=typeof r=="string"?document.querySelector(r):r;if(!o)throw new Error(`mountChatWidget: target "${String(r)}" not found.`);return o}function yt(r,o){const{title:a="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:s=!1,height:f=500,placement:l="inline",width:p=400,defaultOpen:c=!1,logoUrl:h,showAgentName:N=!1,agentBubble:g=!1,showHeader:I=!0,theme:K,loadThreads:P=!1,forms:T,formSubmittedMessage:G=ze,onFollowUpClick:j,onMessageSent:qe,onMessageReceived:Xe,onFormSubmitted:ne,onFormError:oe}=o;if(!o.client&&!o.config?.baseUrl)throw new Oe.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const m=o.client??new Oe.AgoClient(o.config),ye=Ct(r),F=l==="left"||l==="right",Ke=F&&(o.launcher??!0);let z=F?c:!0;const re=o.persistConversation,V=re?at.createConversationSession(re===!0?{}:re):void 0;let _=o.conversationId??V?.getLastActiveThread()??void 0,d=[],L=!1,q=null;const ve=[];function Ve(e){if(typeof G=="function"){const i=G(e);if(typeof i=="string"&&i)return i}const n=xt(e);return n||(typeof G=="string"?G:ze)}const Q=[],H=b({display:"flex",flexDirection:"column",height:F?"100%":typeof f=="number"?`${f}px`:f,border:`1px solid ${A}`,borderRadius:mt,overflow:"hidden",backgroundColor:X,fontFamily:xe,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});H.className="ago-chat-widget",ht(H,K);let O;if(I){if(O=b({padding:"14px 16px",borderBottom:`1px solid ${A}`,backgroundColor:pt,color:Fe,display:"flex",alignItems:"center",gap:"10px"}),O.className="ago-chat-widget__header",h){const n=document.createElement("img");n.src=h,n.alt="Logo",E(n,{height:"24px",width:"auto"}),O.appendChild(n)}const e=document.createElement("h3");if(e.textContent=a,E(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),O.appendChild(e),F){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",E(n,{marginLeft:"auto",background:"transparent",border:"none",color:Fe,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),n.addEventListener("click",()=>fe()),O.appendChild(n)}}const $=b({flex:"1",overflow:"auto",padding:"16px",backgroundColor:ft});$.className="ago-chat-widget__messages";const{inputRow:Qe,setDisabled:Ye,focus:ae}=vt({placeholder:u,allowFiles:s,onSend:(e,n)=>{le(e,n)}});bt(),H.append(...O?[O]:[],$,Qe);let Y=H,D,S;const ie=l==="left"?"left":"right";if(F&&(D=b({position:"fixed",top:"0",bottom:"0",[ie]:"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"}),D.className="ago-chat-widget-panel",E(H,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ie==="left"?"borderRight":"borderLeft"]:`1px solid ${A}`}),D.appendChild(H),Y=D),Ke){if(S=document.createElement("button"),S.type="button",S.className="ago-chat-widget-launcher",S.setAttribute("aria-label",`Open ${a}`),E(S,{position:"fixed",bottom:"20px",[ie]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:be,color:Ce,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:xe}),h){const e=document.createElement("img");e.src=h,e.alt="",E(e,{width:"26px",height:"26px",objectFit:"contain"}),S.appendChild(e)}else S.appendChild(ot());S.addEventListener("click",()=>pe())}ye.appendChild(Y),S&&ye.appendChild(S),ce();const Ee=j!==!1,we=j===!1?void 0:j??(e=>{le(e)});function Ze(e,n){const i=e.role==="user",x=b({display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"});if(x.className=`ago-message ago-message--${e.role}`,!i&&N&&e.agent){const C=b({fontSize:"13px",fontWeight:"500",color:J,marginBottom:"6px",padding:"0 4px"});C.className="ago-message__agent",C.textContent=e.agent.displayName||e.agent.name,x.appendChild(C)}if(!i&&e.sources&&e.sources.length>0){const C=b({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});C.className="ago-message__sources",e.sources.forEach((y,w)=>{const B=y.url?document.createElement("a"):document.createElement("div");y.url&&B instanceof HTMLAnchorElement&&(B.href=y.url,B.target="_blank",B.rel="noopener noreferrer"),E(B,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${A}`,borderRadius:"8px",backgroundColor:X,textDecoration:"none",color:J,fontSize:"12px",overflow:"hidden"});const Le=b({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${ge}`,color:ge,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Le.textContent=String(w+1);const ue=b({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});ue.textContent=y.title,ue.title=y.title,B.append(Le,ue),C.appendChild(B)}),x.appendChild(C)}const v=b({maxWidth:i?"75%":g?"85%":"100%",padding:i||g?"10px 14px":"2px 8px",borderRadius:i||g?me:"0",backgroundColor:i?be:g?gt:"transparent",color:i?Ce:J,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(v.className="ago-message__content",e.content?v.appendChild(te(e.content)):e.status==="IN_PROGRESS"&&v.appendChild(rt()),x.appendChild(v),n&&e.followUpReplies&&e.followUpReplies.length>0){const C=b({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});C.className="ago-message__followups";for(const y of e.followUpReplies){const w=document.createElement("button");w.type="button",w.className="ago-message__followup-btn",w.textContent=y,w.disabled=!Ee,E(w,{padding:"6px 14px",fontSize:"14px",borderRadius:me,border:`1px solid ${A}`,backgroundColor:X,color:J,cursor:Ee?"pointer":"default",transition:"border-color 0.15s"}),we&&w.addEventListener("click",()=>we(y)),w.addEventListener("mouseenter",()=>{w.style.borderColor=ge}),w.addEventListener("mouseleave",()=>{w.style.borderColor=A}),C.appendChild(w)}x.appendChild(C)}return x}function Je(e){const n=b({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:me,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"),E(i,{fontWeight:"700"});const x=document.createElement("span");return x.textContent=e,n.append(i,x),n}function k(){if($.replaceChildren(),d.length===0){const n=b({textAlign:"center",color:ut,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});n.appendChild(te(t)),$.appendChild(n)}else d.forEach((n,i)=>{$.appendChild(Ze(n,i===d.length-1))});for(const n of ve)$.appendChild(Je(n));if(q){const n=b({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});n.textContent=q,$.appendChild(n)}$.scrollTop=$.scrollHeight;const e=d[d.length-1];Ye(L&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function et(){for(let e=d.length-1;e>=0;e--){const n=d[e];if(n.role==="assistant"&&n.status==="IN_PROGRESS")return n}}const Se=e=>{_||(_=e.conversationId)},Re=e=>{const n=et();n&&(n.content+=e.content,k())},_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),k(),ae()},ke=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),L=!1,k(),e.status==="DONE"&&Xe?.({id:e.id,content:e.content})},Ae=e=>{q=e.error,L=!1,d=d.filter(n=>!n.id.startsWith("temp-")),k()};m.on("message:start",Se),m.on("message:chunk",Re),m.on("message:answer-complete",_e),m.on("message:complete",ke),m.on("message:error",Ae);const Ie=e=>ne?.(e),$e=e=>oe?.(e);ne&&m.on("form:submitted",Ie),oe&&m.on("form:error",$e);const se=[];let Ne=!1;const Te=e=>{if(Ne)return;se.push(e.install(m));let n=e.store.get().submitted;const i=e.store.subscribe(x=>{x.submitted&&!n&&(ve.push(Ve(x.submitResult)),k()),n=x.submitted});se.push(i)};for(const e of T??[])e.schema!=null?Te(De.createFormCollector(e)):De.loadFormCollector(m,e).then(n=>Te(n)).catch(()=>{});async function le(e,n){const i=e.trim();if(!i&&!n?.length||L)return;qe?.(i),L=!0,q=null;const x=Date.now();d.push({id:`temp-user-${x}`,conversationId:_||"",content:i,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${x}`,conversationId:_||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),k();try{const v=await m.sendMessage(i,{conversationId:_,files:n});v.conversationId&&(_||(_=v.conversationId),V?.setActiveThread(v.conversationId,v.createdAt));const C=d.find(y=>y.id===`temp-user-${x}`);if(C&&(C.id=`user-${x}`,C.conversationId=v.conversationId),!d.some(y=>y.id===v.id)){const y=d.findIndex(w=>w.id===`temp-assistant-${x}`);y>=0?d[y]=v:d.push(v)}d=d.filter(y=>!y.id.startsWith("temp-")),L=!1,k(),P&&de()}catch(v){q=v instanceof Error?v.message:"Failed to send message",L=!1,d=d.filter(C=>!C.id.startsWith("temp-")),k()}}async function de(){try{const e=await m.getConversations();Q.splice(0,Q.length,...e)}catch{}return Q}async function tt(e){try{const n=(await m.getConversation(e))?.messages??[];n.length>0&&d.length===0&&(d=n,k())}catch{d.length===0&&(V?.clear(),_=void 0)}}return k(),ae(),_&&tt(_),P&&de(),{client:m,element:Y,sendMessage:le,...F?{open:pe,close:fe,toggle:nt}:{},session:V,threads:Q,refreshThreads:de,destroy(){m.off("message:start",Se),m.off("message:chunk",Re),m.off("message:answer-complete",_e),m.off("message:complete",ke),m.off("message:error",Ae),ne&&m.off("form:submitted",Ie),oe&&m.off("form:error",$e),Ne=!0,se.forEach(e=>e()),Y.remove(),S?.remove(),o.client||m.destroy()}};function ce(){if(!D)return;const e=l==="left"?"translateX(-100%)":"translateX(100%)";D.style.transform=z?"translateX(0)":e,D.setAttribute("aria-hidden",z?"false":"true"),S&&(S.style.display=z?"none":"flex")}function pe(){z=!0,ce(),ae()}function fe(){z=!1,ce()}function nt(){z?fe():pe()}function ot(){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 rt(){const e=b({display:"flex",gap:"4px",padding:"4px 0"});for(let n=0;n<3;n++){const i=b({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 vt(r){let o=[];const a=document.createElement("form");E(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${A}`,backgroundColor:X}),a.className="ago-chat-input";const t=b({display:"flex",flexWrap:"wrap",gap:"6px"}),u=b({display:"flex",gap:"8px",alignItems:"flex-end"}),s=document.createElement("textarea");s.placeholder=r.placeholder,s.rows=1,E(s,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${A}`,borderRadius:"12px",fontSize:"16px",fontFamily:xe,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const f=document.createElement("button");f.type="submit",f.textContent="Send",E(f,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:be,color:Ce,fontSize:"16px",fontWeight:"500",cursor:"pointer"});let l=null,p=null;r.allowFiles&&(l=document.createElement("input"),l.type="file",l.multiple=!0,E(l,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",E(p,{padding:"10px 12px",border:`1px solid ${A}`,borderRadius:"12px",backgroundColor:X,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((g,I)=>{const K=b({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${A}`,borderRadius:"8px",fontSize:"12px"}),P=document.createElement("span");P.textContent=g.name;const T=document.createElement("button");T.type="button",T.textContent="×",E(T,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),T.addEventListener("click",()=>{o=o.filter((G,j)=>j!==I),c()}),K.append(P,T),t.appendChild(K)})}const h=()=>{const g=s.value,I=o;return s.value="",o=[],c(),{content:g,files:I}},N=()=>{const{content:g,files:I}=h();(g.trim()||I.length>0)&&r.onSend(g.trim(),I.length>0?I:void 0)};return a.addEventListener("submit",g=>{g.preventDefault(),N()}),s.addEventListener("keydown",g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),N())}),p&&u.appendChild(p),u.append(s,f),l&&a.appendChild(l),a.append(t,u),{inputRow:a,getValueAndClear:h,setDisabled:g=>{s.disabled=g,f.disabled=g,f.style.opacity=g?"0.6":"1",f.style.cursor=g?"not-allowed":"pointer"},focus:()=>s.focus()}}exports.mountChatWidget=yt;exports.renderMarkdown=te;
|
|
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. */
|
|
@@ -819,6 +824,14 @@ export declare interface MountChatWidgetOptions {
|
|
|
819
824
|
showAgentName?: boolean;
|
|
820
825
|
/** Render assistant messages inside a filled bubble (themed via `agentBubbleBg`). Defaults to `false`. */
|
|
821
826
|
agentBubble?: boolean;
|
|
827
|
+
/**
|
|
828
|
+
* Bubble shape preset. `"imessage"` bubbles both sides (assistant messages get
|
|
829
|
+
* the filled `agentBubbleBg` bubble too) and draws the iMessage "tail" curl on
|
|
830
|
+
* the last bubble of each same-sender run. Defaults to `"default"` (current
|
|
831
|
+
* look). Colors stay themed: user bubble `brand`, assistant bubble
|
|
832
|
+
* `agentBubbleBg`, and the tail mask follows `messagesBg`.
|
|
833
|
+
*/
|
|
834
|
+
bubbleStyle?: "default" | "imessage";
|
|
822
835
|
/**
|
|
823
836
|
* Show the header bar (title, logo, and the side-panel close "×"). Set `false`
|
|
824
837
|
* to drop it, e.g. when the host page already frames the widget. Defaults to
|
|
@@ -1015,6 +1028,24 @@ declare interface ToolCallData {
|
|
|
1015
1028
|
|
|
1016
1029
|
declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
|
|
1017
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
|
+
|
|
1018
1049
|
/**
|
|
1019
1050
|
* Theme overrides for {@link mountChatWidget}. *
|
|
1020
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. */
|
|
@@ -819,6 +824,14 @@ export declare interface MountChatWidgetOptions {
|
|
|
819
824
|
showAgentName?: boolean;
|
|
820
825
|
/** Render assistant messages inside a filled bubble (themed via `agentBubbleBg`). Defaults to `false`. */
|
|
821
826
|
agentBubble?: boolean;
|
|
827
|
+
/**
|
|
828
|
+
* Bubble shape preset. `"imessage"` bubbles both sides (assistant messages get
|
|
829
|
+
* the filled `agentBubbleBg` bubble too) and draws the iMessage "tail" curl on
|
|
830
|
+
* the last bubble of each same-sender run. Defaults to `"default"` (current
|
|
831
|
+
* look). Colors stay themed: user bubble `brand`, assistant bubble
|
|
832
|
+
* `agentBubbleBg`, and the tail mask follows `messagesBg`.
|
|
833
|
+
*/
|
|
834
|
+
bubbleStyle?: "default" | "imessage";
|
|
822
835
|
/**
|
|
823
836
|
* Show the header bar (title, logo, and the side-panel close "×"). Set `false`
|
|
824
837
|
* to drop it, e.g. when the host page already frames the widget. Defaults to
|
|
@@ -1015,6 +1028,24 @@ declare interface ToolCallData {
|
|
|
1015
1028
|
|
|
1016
1029
|
declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
|
|
1017
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
|
+
|
|
1018
1049
|
/**
|
|
1019
1050
|
* Theme overrides for {@link mountChatWidget}. *
|
|
1020
1051
|
* @see The `--ago-*` token reference in `docs/general/widget.md`.
|