@useago/sdk 1.0.11 → 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 +388 -295
- 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 +23 -0
- package/dist/widget.d.ts +23 -0
- package/dist/widget.js +460 -387
- 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 n=0;for(;n<a.length;){const i=a[n];if(i.trim()===""){n++;continue}const
|
|
4
|
-
`)))),o.appendChild(
|
|
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;
|
|
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
|
|
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
|
|