@useago/sdk 1.0.6 → 1.0.8
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/README.md +53 -0
- package/dist/{AgoClient--y10UXUV.cjs → AgoClient-B3-WGVne.cjs} +3 -3
- package/dist/{AgoClient-DYdIe_R4.js → AgoClient-QcTtrN7u.js} +3 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +24 -0
- package/dist/angular.d.ts +24 -0
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-lJWANT6T.cjs → createConversationSession-BwYNMZWq.cjs} +1 -1
- package/dist/{createConversationSession-Boi0PjDU.js → createConversationSession-DrCMdwkV.js} +1 -1
- package/dist/createFormCollector-BHHEW6uX.cjs +1 -0
- package/dist/createFormCollector-QyojCH_-.js +297 -0
- package/dist/devtools.d.cts +24 -0
- package/dist/devtools.d.ts +24 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +53 -45
- package/dist/react.cjs +2 -2
- package/dist/react.d.cts +41 -0
- package/dist/react.d.ts +41 -0
- package/dist/react.js +43 -41
- package/dist/testing.d.cts +24 -0
- package/dist/testing.d.ts +24 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +24 -0
- package/dist/vue.d.ts +24 -0
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +63 -0
- package/dist/widget.d.ts +63 -0
- package/dist/widget.js +362 -310
- package/package.json +1 -1
- package/dist/createFormCollector-BUqSA2Qw.js +0 -257
- package/dist/createFormCollector-CSG5ioym.cjs +0 -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 De=require("./AgoClient-B3-WGVne.cjs"),Me=require("./createFormCollector-BHHEW6uX.cjs"),rt=require("./createConversationSession-BwYNMZWq.cjs");var at={"&":"&","<":"<",">":">",'"':""","'":"'"};function U(o){return o.replace(/[&<>"']/g,n=>at[n])}function Fe(o){const n=o.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)?n:null}var We='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Q="";function F(o){const n=[],a=u=>(n.push(u),`${Q}${n.length-1}${Q}`);let t=o;return t=t.replace(/`([^`]+)`/g,(u,s)=>a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${We}">${U(s)}</code>`)),t=t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(u,s,f)=>{const l=Fe(f);return l?a(`<img alt="${U(s)}" src="${U(l)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):u}),t=t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(u,s,f)=>{const l=Fe(f);return l?a(`<a href="${U(l)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${F(s)}</a>`):u}),t=U(t),t=t.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>"),t=t.replace(new RegExp(`${Q}(\\d+)${Q}`,"g"),(u,s)=>n[Number(s)]),t}function R(o,n,a){const t=document.createElement(o);return Object.assign(t.style,n),a!==void 0&&(t.innerHTML=a),t}var Pe=/^ {0,3}([-*_])( *\1){2,} *$/,Ge=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,je=/^ {0,3}(```+|~~~+)/,Z=/^ {0,3}>\s?/,W=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,it=["20px","18px","16px","15px","14px","13px"],he=o=>o.match(/^\s*/)?.[0].length??0;function st(o){return o.trim()===""||Pe.test(o)||Ge.test(o)||je.test(o)||Z.test(o)||W.test(o)}function qe(o){const n=o[0].match(W),a=n[1].length,t=/\d/.test(n[2]),u=R(t?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:t?"decimal":"disc",listStylePosition:"outside"});let s=0;for(;s<o.length;){const f=o[s].match(W),l=[];for(s++;s<o.length&&he(o[s])>a;)l.push(o[s]),s++;const p=R("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),c=f[3].match(/^\[([ xX])\]\s+(.*)$/);c?(p.style.listStyleType="none",p.style.marginLeft="-20px",p.innerHTML=`<span style="margin-right:6px">${c[1].toLowerCase()==="x"?"☑":"☐"}</span>${F(c[2])}`):p.innerHTML=F(f[3]),l.filter(m=>W.test(m)).length>0&&p.appendChild(qe(l.filter(m=>m.trim()!==""))),u.appendChild(p)}return u}function lt(o){const n=l=>l.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(p=>p.trim()),a=R("div",{overflowX:"auto",margin:"0 0 8px 0"}),t=R("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),u=document.createElement("thead"),s=document.createElement("tr");for(const l of n(o[0]))s.appendChild(R("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},F(l)));u.appendChild(s),t.appendChild(u);const f=document.createElement("tbody");for(const l of o.slice(2)){const p=document.createElement("tr");for(const c of n(l))p.appendChild(R("td",{border:"1px solid #dee3e8",padding:"6px 10px"},F(c)));f.appendChild(p)}return t.appendChild(f),a.appendChild(t),a}var dt=o=>!!o&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);function J(o){const n=document.createDocumentFragment(),a=o.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let t=0;for(;t<
|
|
4
|
-
`)))),n.appendChild(
|
|
5
|
-
`))),n.appendChild(h);continue}if(i.includes("|")&&Je(r[t+1])){const c=[i,r[t+1]];for(t+=2;t<r.length&&r[t].includes("|")&&r[t].trim();)c.push(r[t]),t++;n.appendChild(Ze(c));continue}if(P.test(i)){const c=[],h=fe(i);for(;t<r.length&&r[t].trim()!=="";)if(P.test(r[t])||fe(r[t])>h)c.push(r[t]),t++;else break;n.appendChild(ze(c));continue}const p=[i];for(t++;t<r.length&&!Ye(r[t]);)p.push(r[t]),t++;n.appendChild(_("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>M(c)).join("<br>")))}const u=n.lastElementChild;return u&&(u.style.marginBottom="0"),n}var ue='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Ie={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"},ge="var(--ago-brand-color, #03182f)",he="var(--ago-brand-text-color, #fff)",et="var(--ago-header-background, var(--ago-brand-color, #03182f))",Le="var(--ago-header-text-color, #e8f0fe)",j="var(--ago-panel-background, #fff)",tt="var(--ago-messages-background, #fbfbfb)",Y="var(--ago-text-color, #30373e)",nt="var(--ago-muted-text-color, #6b6d6f)",$="var(--ago-border-color, #dee3e8)",pe="var(--ago-accent-color, #1b5fc4)",ot="var(--ago-radius, 16px)",Ne="var(--ago-message-radius, 16px)";function rt(o,n){if(n)for(const r of Object.keys(Ie)){const t=n[r];t!=null&&o.style.setProperty(Ie[r],t)}}function y(o,n){Object.assign(o.style,n)}function x(o={}){const n=document.createElement("div");return y(n,o),n}var Oe="ago-chat-widget-keyframes";function at(){if(typeof document>"u"||document.getElementById(Oe))return;const o=document.createElement("style");o.id=Oe,o.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(o)}function it(o){const n=typeof o=="string"?document.querySelector(o):o;if(!n)throw new Error(`mountChatWidget: target "${String(o)}" not found.`);return n}function st(o,n){const{title:r="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:i=!1,height:f=500,placement:s="inline",width:p=400,defaultOpen:c=!1,logoUrl:h,showAgentName:L=!1,theme:m,loadThreads:R=!1,forms:q,onFollowUpClick:B,onMessageSent:N,onMessageReceived:me}=n;if(!n.client&&!n.config?.baseUrl)throw new ke.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const g=n.client??new ke.AgoClient(n.config),xe=it(o),z=s==="left"||s==="right",He=z&&(n.launcher??!0);let H=z?c:!0;const ee=n.persistConversation,X=ee?Ke.createConversationSession(ee===!0?{}:ee):void 0;let k=n.conversationId??X?.getLastActiveThread()??void 0,d=[],O=!1,W=null;const K=[],F=x({display:"flex",flexDirection:"column",height:z?"100%":typeof f=="number"?`${f}px`:f,border:`1px solid ${$}`,borderRadius:ot,overflow:"hidden",backgroundColor:j,fontFamily:ue,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});F.className="ago-chat-widget",rt(F,m);const G=x({padding:"14px 16px",borderBottom:`1px solid ${$}`,backgroundColor:et,color:Le,display:"flex",alignItems:"center",gap:"10px"});if(G.className="ago-chat-widget__header",h){const e=document.createElement("img");e.src=h,e.alt="Logo",y(e,{height:"24px",width:"auto"}),G.appendChild(e)}const te=document.createElement("h3");if(te.textContent=r,y(te,{margin:"0",fontSize:"15px",fontWeight:"600"}),G.appendChild(te),z){const e=document.createElement("button");e.type="button",e.className="ago-chat-widget__close",e.setAttribute("aria-label","Close"),e.textContent="×",y(e,{marginLeft:"auto",background:"transparent",border:"none",color:Le,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),e.addEventListener("click",()=>de()),G.appendChild(e)}const I=x({flex:"1",overflow:"auto",padding:"16px",backgroundColor:tt});I.className="ago-chat-widget__messages";const{inputRow:Fe,setDisabled:Ue,focus:ne}=lt({placeholder:u,allowFiles:i,onSend:(e,a)=>{ae(e,a)}});at(),F.append(G,I,Fe);let V=F,T,E;const oe=s==="left"?"left":"right";if(z&&(T=x({position:"fixed",top:"0",bottom:"0",[oe]:"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"}),T.className="ago-chat-widget-panel",y(F,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[oe==="left"?"borderRight":"borderLeft"]:`1px solid ${$}`}),T.appendChild(F),V=T),He){if(E=document.createElement("button"),E.type="button",E.className="ago-chat-widget-launcher",E.setAttribute("aria-label",`Open ${r}`),y(E,{position:"fixed",bottom:"20px",[oe]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:ge,color:he,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:ue}),h){const e=document.createElement("img");e.src=h,e.alt="",y(e,{width:"26px",height:"26px",objectFit:"contain"}),E.appendChild(e)}else E.appendChild(qe());E.addEventListener("click",()=>le())}xe.appendChild(V),E&&xe.appendChild(E),se();const be=B!==!1,Ce=B===!1?void 0:B??(e=>{ae(e)});function Pe(e,a){const l=e.role==="user",S=x({display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"});if(S.className=`ago-message ago-message--${e.role}`,!l&&L&&e.agent){const b=x({fontSize:"13px",fontWeight:"500",color:Y,marginBottom:"6px",padding:"0 4px"});b.className="ago-message__agent",b.textContent=e.agent.displayName||e.agent.name,S.appendChild(b)}if(!l&&e.sources&&e.sources.length>0){const b=x({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});b.className="ago-message__sources",e.sources.forEach((C,w)=>{const D=C.url?document.createElement("a"):document.createElement("div");C.url&&D instanceof HTMLAnchorElement&&(D.href=C.url,D.target="_blank",D.rel="noopener noreferrer"),y(D,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${$}`,borderRadius:"8px",backgroundColor:j,textDecoration:"none",color:Y,fontSize:"12px",overflow:"hidden"});const Re=x({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${pe}`,color:pe,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Re.textContent=String(w+1);const ce=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});ce.textContent=C.title,ce.title=C.title,D.append(Re,ce),b.appendChild(D)}),S.appendChild(b)}const v=x({maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?Ne:"0",backgroundColor:l?ge:"transparent",color:l?he:Y,wordBreak:"break-word",fontSize:"14px",lineHeight:"1.6"});if(v.className="ago-message__content",e.content?v.appendChild(J(e.content)):e.status==="IN_PROGRESS"&&v.appendChild(Xe()),S.appendChild(v),a&&e.followUpReplies&&e.followUpReplies.length>0){const b=x({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});b.className="ago-message__followups";for(const C of e.followUpReplies){const w=document.createElement("button");w.type="button",w.className="ago-message__followup-btn",w.textContent=C,w.disabled=!be,y(w,{padding:"6px 14px",fontSize:"14px",borderRadius:Ne,border:`1px solid ${$}`,backgroundColor:j,color:Y,cursor:be?"pointer":"default",transition:"border-color 0.15s"}),Ce&&w.addEventListener("click",()=>Ce(C)),w.addEventListener("mouseenter",()=>{w.style.borderColor=pe}),w.addEventListener("mouseleave",()=>{w.style.borderColor=$}),b.appendChild(w)}S.appendChild(b)}return S}function A(){if(I.replaceChildren(),d.length===0){const a=x({textAlign:"center",color:nt,padding:"24px 16px",fontSize:"14px",lineHeight:"1.5"});a.appendChild(J(t)),I.appendChild(a)}else d.forEach((a,l)=>{I.appendChild(Pe(a,l===d.length-1))});if(W){const a=x({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});a.textContent=W,I.appendChild(a)}I.scrollTop=I.scrollHeight;const e=d[d.length-1];Ue(O&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function We(){for(let e=d.length-1;e>=0;e--){const a=d[e];if(a.role==="assistant"&&a.status==="IN_PROGRESS")return a}}const ve=e=>{k||(k=e.conversationId)},we=e=>{const a=We();a&&(a.content+=e.content,A())},ye=e=>{const a=d.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");a>=0?d[a]=e:d.push(e),A(),ne()},Ee=e=>{const a=d.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");a>=0?d[a]=e:d.push(e),O=!1,A(),e.status==="DONE"&&me?.({id:e.id,content:e.content})},Se=e=>{W=e.error,O=!1,d=d.filter(a=>!a.id.startsWith("temp-")),A()};g.on("message:start",ve),g.on("message:chunk",we),g.on("message:answer-complete",ye),g.on("message:complete",Ee),g.on("message:error",Se);const re=[];let _e=!1;for(const e of q??[])e.schema!=null?re.push($e.createFormCollector(e).install(g)):$e.loadFormCollector(g,e).then(a=>{_e||re.push(a.install(g))}).catch(()=>{});async function ae(e,a){const l=e.trim();if(!l&&!a?.length||O)return;N?.(l),O=!0,W=null;const S=Date.now();d.push({id:`temp-user-${S}`,conversationId:k||"",content:l,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${S}`,conversationId:k||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),A();try{const v=await g.sendMessage(l,{conversationId:k,files:a});v.conversationId&&(k||(k=v.conversationId),X?.setActiveThread(v.conversationId,v.createdAt));const b=d.find(C=>C.id===`temp-user-${S}`);if(b&&(b.id=`user-${S}`,b.conversationId=v.conversationId),!d.some(C=>C.id===v.id)){const C=d.findIndex(w=>w.id===`temp-assistant-${S}`);C>=0?d[C]=v:d.push(v)}d=d.filter(C=>!C.id.startsWith("temp-")),O=!1,A(),R&&ie()}catch(v){W=v instanceof Error?v.message:"Failed to send message",O=!1,d=d.filter(b=>!b.id.startsWith("temp-")),A()}}async function ie(){try{const e=await g.getConversations();K.splice(0,K.length,...e)}catch{}return K}async function Ge(e){try{const a=(await g.getConversation(e))?.messages??[];a.length>0&&d.length===0&&(d=a,A())}catch{d.length===0&&(X?.clear(),k=void 0)}}return A(),ne(),k&&Ge(k),R&&ie(),{client:g,element:V,sendMessage:ae,...z?{open:le,close:de,toggle:je}:{},session:X,threads:K,refreshThreads:ie,destroy(){g.off("message:start",ve),g.off("message:chunk",we),g.off("message:answer-complete",ye),g.off("message:complete",Ee),g.off("message:error",Se),_e=!0,re.forEach(e=>e()),V.remove(),E?.remove(),n.client||g.destroy()}};function se(){if(!T)return;const e=s==="left"?"translateX(-100%)":"translateX(100%)";T.style.transform=H?"translateX(0)":e,T.setAttribute("aria-hidden",H?"false":"true"),E&&(E.style.display=H?"none":"flex")}function le(){H=!0,se(),ne()}function de(){H=!1,se()}function je(){H?de():le()}function qe(){const e="http://www.w3.org/2000/svg",a=document.createElementNS(e,"svg");a.setAttribute("width","26"),a.setAttribute("height","26"),a.setAttribute("viewBox","0 0 24 24"),a.setAttribute("fill","none");const l=document.createElementNS(e,"path");return l.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"),l.setAttribute("stroke","currentColor"),l.setAttribute("stroke-width","2"),l.setAttribute("stroke-linecap","round"),l.setAttribute("stroke-linejoin","round"),a.appendChild(l),a}function Xe(){const e=x({display:"flex",gap:"4px",padding:"4px 0"});for(let a=0;a<3;a++){const l=x({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${a*.2}s`});e.appendChild(l)}return e}}function lt(o){let n=[];const r=document.createElement("form");y(r,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${$}`,backgroundColor:j}),r.className="ago-chat-input";const t=x({display:"flex",flexWrap:"wrap",gap:"6px"}),u=x({display:"flex",gap:"8px",alignItems:"flex-end"}),i=document.createElement("textarea");i.placeholder=o.placeholder,i.rows=1,y(i,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",fontSize:"14px",fontFamily:ue,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const f=document.createElement("button");f.type="submit",f.textContent="Send",y(f,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:ge,color:he,fontSize:"14px",fontWeight:"500",cursor:"pointer"});let s=null,p=null;o.allowFiles&&(s=document.createElement("input"),s.type="file",s.multiple=!0,y(s,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",y(p,{padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",backgroundColor:j,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>s?.click()),s.addEventListener("change",()=>{n=[...n,...Array.from(s?.files??[])],c()}));function c(){t.replaceChildren(),n.forEach((m,R)=>{const q=x({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${$}`,borderRadius:"8px",fontSize:"12px"}),B=document.createElement("span");B.textContent=m.name;const N=document.createElement("button");N.type="button",N.textContent="×",y(N,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),N.addEventListener("click",()=>{n=n.filter((me,g)=>g!==R),c()}),q.append(B,N),t.appendChild(q)})}const h=()=>{const m=i.value,R=n;return i.value="",n=[],c(),{content:m,files:R}},L=()=>{const{content:m,files:R}=h();(m.trim()||R.length>0)&&o.onSend(m.trim(),R.length>0?R:void 0)};return r.addEventListener("submit",m=>{m.preventDefault(),L()}),i.addEventListener("keydown",m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),L())}),p&&u.appendChild(p),u.append(i,f),s&&r.appendChild(s),r.append(t,u),{inputRow:r,getValueAndClear:h,setDisabled:m=>{i.disabled=m,f.disabled=m,f.style.opacity=m?"0.6":"1",f.style.cursor=m?"not-allowed":"pointer"},focus:()=>i.focus()}}exports.mountChatWidget=st;exports.renderMarkdown=J;
|
|
3
|
+
`);let t=0;for(;t<a.length;){const s=a[t];if(s.trim()===""){t++;continue}const f=s.match(je);if(f){const c=f[1][0],m=[];for(t++;t<a.length&&!new RegExp(`^ {0,3}${c==="`"?"`{3,}":"~{3,}"}\\s*$`).test(a[t]);)m.push(a[t]),t++;t++;const N=R("pre",{margin:"0 0 8px 0"});N.appendChild(R("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:We,whiteSpace:"pre"},U(m.join(`
|
|
4
|
+
`)))),n.appendChild(N);continue}if(Pe.test(s)){n.appendChild(R("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),t++;continue}const l=s.match(Ge);if(l){const c=l[1].length;n.appendChild(R(`h${c}`,{margin:"16px 0 8px 0",fontSize:it[c-1],fontWeight:"600",lineHeight:"1.3"},F(l[2]))),t++;continue}if(Z.test(s)){const c=[];for(;t<a.length&&Z.test(a[t]);)c.push(a[t].replace(Z,"")),t++;const m=R("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});m.appendChild(J(c.join(`
|
|
5
|
+
`))),n.appendChild(m);continue}if(s.includes("|")&&dt(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++;n.appendChild(lt(c));continue}if(W.test(s)){const c=[],m=he(s);for(;t<a.length&&a[t].trim()!=="";)if(W.test(a[t])||he(a[t])>m)c.push(a[t]),t++;else break;n.appendChild(qe(c));continue}const p=[s];for(t++;t<a.length&&!st(a[t]);)p.push(a[t]),t++;n.appendChild(R("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>F(c)).join("<br>")))}const u=n.lastElementChild;return u&&(u.style.marginBottom="0"),n}var xe='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Be={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"},be="var(--ago-brand-color, #03182f)",Ce="var(--ago-brand-text-color, #fff)",ct="var(--ago-header-background, var(--ago-brand-color, #03182f))",ze="var(--ago-header-text-color, #e8f0fe)",j="var(--ago-panel-background, #fff)",pt="var(--ago-messages-background, #fbfbfb)",Y="var(--ago-text-color, #30373e)",ft="var(--ago-muted-text-color, #6b6d6f)",I="var(--ago-border-color, #dee3e8)",ge="var(--ago-accent-color, #1b5fc4)",ut="var(--ago-radius, 16px)",me="var(--ago-message-radius, 16px)";function gt(o,n){if(n)for(const a of Object.keys(Be)){const t=n[a];t!=null&&o.style.setProperty(Be[a],t)}}function E(o,n){Object.assign(o.style,n)}function b(o={}){const n=document.createElement("div");return E(n,o),n}var He="Form submitted.";function mt(o){if(typeof o=="string")return o||null;if(!o||typeof o!="object")return null;const n=o;if(typeof n.message=="string"&&n.message)return n.message;const a=n.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 Ue="ago-chat-widget-keyframes";function ht(){if(typeof document>"u"||document.getElementById(Ue))return;const o=document.createElement("style");o.id=Ue,o.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(o)}function xt(o){const n=typeof o=="string"?document.querySelector(o):o;if(!n)throw new Error(`mountChatWidget: target "${String(o)}" not found.`);return n}function bt(o,n){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:m,showAgentName:N=!1,theme:h,loadThreads:_=!1,forms:q,formSubmittedMessage:L=He,onFollowUpClick:$,onMessageSent:ye,onMessageReceived:ee,onFormSubmitted:te,onFormError:ne}=n;if(!n.client&&!n.config?.baseUrl)throw new De.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const g=n.client??new De.AgoClient(n.config),ve=xt(o),B=l==="left"||l==="right",Xe=B&&(n.launcher??!0);let z=B?c:!0;const oe=n.persistConversation,X=oe?rt.createConversationSession(oe===!0?{}:oe):void 0;let k=n.conversationId??X?.getLastActiveThread()??void 0,d=[],O=!1,P=null;const Ee=[];function Ke(e){if(typeof L=="function"){const i=L(e);if(typeof i=="string"&&i)return i}const r=mt(e);return r||(typeof L=="string"?L:He)}const K=[],H=b({display:"flex",flexDirection:"column",height:B?"100%":typeof f=="number"?`${f}px`:f,border:`1px solid ${I}`,borderRadius:ut,overflow:"hidden",backgroundColor:j,fontFamily:xe,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});H.className="ago-chat-widget",gt(H,h);const G=b({padding:"14px 16px",borderBottom:`1px solid ${I}`,backgroundColor:ct,color:ze,display:"flex",alignItems:"center",gap:"10px"});if(G.className="ago-chat-widget__header",m){const e=document.createElement("img");e.src=m,e.alt="Logo",E(e,{height:"24px",width:"auto"}),G.appendChild(e)}const re=document.createElement("h3");if(re.textContent=a,E(re,{margin:"0",fontSize:"15px",fontWeight:"600"}),G.appendChild(re),B){const e=document.createElement("button");e.type="button",e.className="ago-chat-widget__close",e.setAttribute("aria-label","Close"),e.textContent="×",E(e,{marginLeft:"auto",background:"transparent",border:"none",color:ze,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),e.addEventListener("click",()=>fe()),G.appendChild(e)}const T=b({flex:"1",overflow:"auto",padding:"16px",backgroundColor:pt});T.className="ago-chat-widget__messages";const{inputRow:Ve,setDisabled:Qe,focus:ae}=Ct({placeholder:u,allowFiles:s,onSend:(e,r)=>{le(e,r)}});ht(),H.append(G,T,Ve);let V=H,D,S;const ie=l==="left"?"left":"right";if(B&&(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 ${I}`}),D.appendChild(H),V=D),Xe){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}),m){const e=document.createElement("img");e.src=m,e.alt="",E(e,{width:"26px",height:"26px",objectFit:"contain"}),S.appendChild(e)}else S.appendChild(nt());S.addEventListener("click",()=>pe())}ve.appendChild(V),S&&ve.appendChild(S),ce();const we=$!==!1,Se=$===!1?void 0:$??(e=>{le(e)});function Ye(e,r){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:Y,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 M=y.url?document.createElement("a"):document.createElement("div");y.url&&M instanceof HTMLAnchorElement&&(M.href=y.url,M.target="_blank",M.rel="noopener noreferrer"),E(M,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${I}`,borderRadius:"8px",backgroundColor:j,textDecoration:"none",color:Y,fontSize:"12px",overflow:"hidden"});const Oe=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"});Oe.textContent=String(w+1);const ue=b({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});ue.textContent=y.title,ue.title=y.title,M.append(Oe,ue),C.appendChild(M)}),x.appendChild(C)}const v=b({maxWidth:i?"75%":"100%",padding:i?"10px 14px":"2px 8px",borderRadius:i?me:"0",backgroundColor:i?be:"transparent",color:i?Ce:Y,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(v.className="ago-message__content",e.content?v.appendChild(J(e.content)):e.status==="IN_PROGRESS"&&v.appendChild(ot()),x.appendChild(v),r&&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=!we,E(w,{padding:"6px 14px",fontSize:"14px",borderRadius:me,border:`1px solid ${I}`,backgroundColor:j,color:Y,cursor:we?"pointer":"default",transition:"border-color 0.15s"}),Se&&w.addEventListener("click",()=>Se(y)),w.addEventListener("mouseenter",()=>{w.style.borderColor=ge}),w.addEventListener("mouseleave",()=>{w.style.borderColor=I}),C.appendChild(w)}x.appendChild(C)}return x}function Ze(e){const r=b({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:me,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});r.className="ago-form-notice",r.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,r.append(i,x),r}function A(){if(T.replaceChildren(),d.length===0){const r=b({textAlign:"center",color:ft,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});r.appendChild(J(t)),T.appendChild(r)}else d.forEach((r,i)=>{T.appendChild(Ye(r,i===d.length-1))});for(const r of Ee)T.appendChild(Ze(r));if(P){const r=b({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});r.textContent=P,T.appendChild(r)}T.scrollTop=T.scrollHeight;const e=d[d.length-1];Qe(O&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function Je(){for(let e=d.length-1;e>=0;e--){const r=d[e];if(r.role==="assistant"&&r.status==="IN_PROGRESS")return r}}const Re=e=>{k||(k=e.conversationId)},_e=e=>{const r=Je();r&&(r.content+=e.content,A())},ke=e=>{const r=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");r>=0?d[r]=e:d.push(e),A(),ae()},Ae=e=>{const r=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");r>=0?d[r]=e:d.push(e),O=!1,A(),e.status==="DONE"&&ee?.({id:e.id,content:e.content})},Ie=e=>{P=e.error,O=!1,d=d.filter(r=>!r.id.startsWith("temp-")),A()};g.on("message:start",Re),g.on("message:chunk",_e),g.on("message:answer-complete",ke),g.on("message:complete",Ae),g.on("message:error",Ie);const $e=e=>te?.(e),Te=e=>ne?.(e);te&&g.on("form:submitted",$e),ne&&g.on("form:error",Te);const se=[];let Ne=!1;const Le=e=>{if(Ne)return;se.push(e.install(g));let r=e.store.get().submitted;const i=e.store.subscribe(x=>{x.submitted&&!r&&(Ee.push(Ke(x.submitResult)),A()),r=x.submitted});se.push(i)};for(const e of q??[])e.schema!=null?Le(Me.createFormCollector(e)):Me.loadFormCollector(g,e).then(r=>Le(r)).catch(()=>{});async function le(e,r){const i=e.trim();if(!i&&!r?.length||O)return;ye?.(i),O=!0,P=null;const x=Date.now();d.push({id:`temp-user-${x}`,conversationId:k||"",content:i,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${x}`,conversationId:k||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),A();try{const v=await g.sendMessage(i,{conversationId:k,files:r});v.conversationId&&(k||(k=v.conversationId),X?.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-")),O=!1,A(),_&&de()}catch(v){P=v instanceof Error?v.message:"Failed to send message",O=!1,d=d.filter(C=>!C.id.startsWith("temp-")),A()}}async function de(){try{const e=await g.getConversations();K.splice(0,K.length,...e)}catch{}return K}async function et(e){try{const r=(await g.getConversation(e))?.messages??[];r.length>0&&d.length===0&&(d=r,A())}catch{d.length===0&&(X?.clear(),k=void 0)}}return A(),ae(),k&&et(k),_&&de(),{client:g,element:V,sendMessage:le,...B?{open:pe,close:fe,toggle:tt}:{},session:X,threads:K,refreshThreads:de,destroy(){g.off("message:start",Re),g.off("message:chunk",_e),g.off("message:answer-complete",ke),g.off("message:complete",Ae),g.off("message:error",Ie),te&&g.off("form:submitted",$e),ne&&g.off("form:error",Te),Ne=!0,se.forEach(e=>e()),V.remove(),S?.remove(),n.client||g.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 tt(){z?fe():pe()}function nt(){const e="http://www.w3.org/2000/svg",r=document.createElementNS(e,"svg");r.setAttribute("width","26"),r.setAttribute("height","26"),r.setAttribute("viewBox","0 0 24 24"),r.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"),r.appendChild(i),r}function ot(){const e=b({display:"flex",gap:"4px",padding:"4px 0"});for(let r=0;r<3;r++){const i=b({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${r*.2}s`});e.appendChild(i)}return e}}function Ct(o){let n=[];const a=document.createElement("form");E(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${I}`,backgroundColor:j}),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=o.placeholder,s.rows=1,E(s,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${I}`,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;o.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 ${I}`,borderRadius:"12px",backgroundColor:j,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>l?.click()),l.addEventListener("change",()=>{n=[...n,...Array.from(l?.files??[])],c()}));function c(){t.replaceChildren(),n.forEach((h,_)=>{const q=b({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${I}`,borderRadius:"8px",fontSize:"12px"}),L=document.createElement("span");L.textContent=h.name;const $=document.createElement("button");$.type="button",$.textContent="×",E($,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),$.addEventListener("click",()=>{n=n.filter((ye,ee)=>ee!==_),c()}),q.append(L,$),t.appendChild(q)})}const m=()=>{const h=s.value,_=n;return s.value="",n=[],c(),{content:h,files:_}},N=()=>{const{content:h,files:_}=m();(h.trim()||_.length>0)&&o.onSend(h.trim(),_.length>0?_:void 0)};return a.addEventListener("submit",h=>{h.preventDefault(),N()}),s.addEventListener("keydown",h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),N())}),p&&u.appendChild(p),u.append(s,f),l&&a.appendChild(l),a.append(t,u),{inputRow:a,getValueAndClear:m,setDisabled:h=>{s.disabled=h,f.disabled=h,f.style.opacity=h?"0.6":"1",f.style.cursor=h?"not-allowed":"pointer"},focus:()=>s.focus()}}exports.mountChatWidget=bt;exports.renderMarkdown=J;
|
package/dist/widget.d.cts
CHANGED
|
@@ -176,6 +176,7 @@ declare class AgoClient {
|
|
|
176
176
|
* call it when their store updates so observers like the dev panel stay live.
|
|
177
177
|
*/
|
|
178
178
|
notifyContextChanged(): void;
|
|
179
|
+
/* Excluded from this release type: emitFormEvent */
|
|
179
180
|
/**
|
|
180
181
|
* Enable automatic capture of the current browser page (URL + title).
|
|
181
182
|
* Injected as a dynamic context entry named `browser-page`.
|
|
@@ -290,6 +291,27 @@ declare interface AgoClientEvents {
|
|
|
290
291
|
result: unknown;
|
|
291
292
|
error?: string;
|
|
292
293
|
};
|
|
294
|
+
/**
|
|
295
|
+
* A form collector submitted successfully. `result` is the raw submit response
|
|
296
|
+
* (POST body / handler return value / backend relay result) — the third-party
|
|
297
|
+
* API's answer. `values` is the submitted field set, `name` the collector name.
|
|
298
|
+
*/
|
|
299
|
+
"form:submitted": {
|
|
300
|
+
name: string;
|
|
301
|
+
values: Record<string, unknown>;
|
|
302
|
+
result: unknown;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* A form collector submit was attempted and failed at the network/server level
|
|
306
|
+
* (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
|
|
307
|
+
* pre-checks (missing required fields, no submit target) are NOT errors and do
|
|
308
|
+
* not fire this — they are returned to the caller as `{ ok: false }`.
|
|
309
|
+
*/
|
|
310
|
+
"form:error": {
|
|
311
|
+
name: string;
|
|
312
|
+
values: Record<string, unknown>;
|
|
313
|
+
error: string;
|
|
314
|
+
};
|
|
293
315
|
"connection:status": {
|
|
294
316
|
connected: boolean;
|
|
295
317
|
};
|
|
@@ -574,6 +596,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
|
|
|
574
596
|
submit?: SubmitConfig<V>;
|
|
575
597
|
/** Pre-filled values. */
|
|
576
598
|
initialValues?: Partial<V>;
|
|
599
|
+
/**
|
|
600
|
+
* Submit on its own as soon as every required field is filled, without waiting
|
|
601
|
+
* for the agent or a UI button. The form submits at most once. Defaults to
|
|
602
|
+
* `true` whenever a `submit` target is set: when on, no `submit_<name>` function
|
|
603
|
+
* is exposed, the form submits itself, and the agent never confirms a submit.
|
|
604
|
+
* Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
|
|
605
|
+
* submit only on an explicit call). Has no effect on a collect-only form (no
|
|
606
|
+
* `submit` target); setting it `true` there is ignored with a warning.
|
|
607
|
+
*/
|
|
608
|
+
autoSubmit?: boolean;
|
|
577
609
|
}
|
|
578
610
|
|
|
579
611
|
/**
|
|
@@ -595,6 +627,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
595
627
|
schema: FormCollectorSchema;
|
|
596
628
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
597
629
|
submit?: SubmitConfig<V>;
|
|
630
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
631
|
+
autoSubmit?: boolean;
|
|
598
632
|
}
|
|
599
633
|
|
|
600
634
|
/**
|
|
@@ -787,6 +821,16 @@ export declare interface MountChatWidgetOptions {
|
|
|
787
821
|
* fetch the definition from the backend ({@link loadFormCollector}).
|
|
788
822
|
*/
|
|
789
823
|
forms?: Array<CreateFormCollectorOptions | LoadFormCollectorOptions>;
|
|
824
|
+
/**
|
|
825
|
+
* The confirmation notice shown in the chat once a form is submitted (auto-submit
|
|
826
|
+
* or a manual `submit_<name>`), a small success block appended below the
|
|
827
|
+
* conversation. By default the notice shows a `message` string returned by the
|
|
828
|
+
* submit response (POST body / handler result / backend relay) when present, and
|
|
829
|
+
* otherwise falls back to this string ("Form submitted." by default). Pass a
|
|
830
|
+
* function to build the text from the raw submit response yourself; return a
|
|
831
|
+
* nullish value to fall back to the default text.
|
|
832
|
+
*/
|
|
833
|
+
formSubmittedMessage?: string | ((result: unknown) => string | null | undefined);
|
|
790
834
|
/**
|
|
791
835
|
* How clicking a suggested follow-up reply behaves. Defaults to sending the
|
|
792
836
|
* reply as a new user message. Pass a handler to override, or `false` to
|
|
@@ -800,6 +844,25 @@ export declare interface MountChatWidgetOptions {
|
|
|
800
844
|
id: string;
|
|
801
845
|
content: string;
|
|
802
846
|
}) => void;
|
|
847
|
+
/**
|
|
848
|
+
* Called when a form collector submits successfully. `result` is the raw submit
|
|
849
|
+
* response (the third-party API's answer); `values` are the submitted fields.
|
|
850
|
+
* Forwards the client's `form:submitted` event.
|
|
851
|
+
*/
|
|
852
|
+
onFormSubmitted?: (data: {
|
|
853
|
+
name: string;
|
|
854
|
+
values: Record<string, unknown>;
|
|
855
|
+
result: unknown;
|
|
856
|
+
}) => void;
|
|
857
|
+
/**
|
|
858
|
+
* Called when a form collector submit fails at the network/server level.
|
|
859
|
+
* Forwards the client's `form:error` event. No notice is shown in the chat.
|
|
860
|
+
*/
|
|
861
|
+
onFormError?: (data: {
|
|
862
|
+
name: string;
|
|
863
|
+
values: Record<string, unknown>;
|
|
864
|
+
error: string;
|
|
865
|
+
}) => void;
|
|
803
866
|
}
|
|
804
867
|
|
|
805
868
|
/**
|
package/dist/widget.d.ts
CHANGED
|
@@ -176,6 +176,7 @@ declare class AgoClient {
|
|
|
176
176
|
* call it when their store updates so observers like the dev panel stay live.
|
|
177
177
|
*/
|
|
178
178
|
notifyContextChanged(): void;
|
|
179
|
+
/* Excluded from this release type: emitFormEvent */
|
|
179
180
|
/**
|
|
180
181
|
* Enable automatic capture of the current browser page (URL + title).
|
|
181
182
|
* Injected as a dynamic context entry named `browser-page`.
|
|
@@ -290,6 +291,27 @@ declare interface AgoClientEvents {
|
|
|
290
291
|
result: unknown;
|
|
291
292
|
error?: string;
|
|
292
293
|
};
|
|
294
|
+
/**
|
|
295
|
+
* A form collector submitted successfully. `result` is the raw submit response
|
|
296
|
+
* (POST body / handler return value / backend relay result) — the third-party
|
|
297
|
+
* API's answer. `values` is the submitted field set, `name` the collector name.
|
|
298
|
+
*/
|
|
299
|
+
"form:submitted": {
|
|
300
|
+
name: string;
|
|
301
|
+
values: Record<string, unknown>;
|
|
302
|
+
result: unknown;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* A form collector submit was attempted and failed at the network/server level
|
|
306
|
+
* (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
|
|
307
|
+
* pre-checks (missing required fields, no submit target) are NOT errors and do
|
|
308
|
+
* not fire this — they are returned to the caller as `{ ok: false }`.
|
|
309
|
+
*/
|
|
310
|
+
"form:error": {
|
|
311
|
+
name: string;
|
|
312
|
+
values: Record<string, unknown>;
|
|
313
|
+
error: string;
|
|
314
|
+
};
|
|
293
315
|
"connection:status": {
|
|
294
316
|
connected: boolean;
|
|
295
317
|
};
|
|
@@ -574,6 +596,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
|
|
|
574
596
|
submit?: SubmitConfig<V>;
|
|
575
597
|
/** Pre-filled values. */
|
|
576
598
|
initialValues?: Partial<V>;
|
|
599
|
+
/**
|
|
600
|
+
* Submit on its own as soon as every required field is filled, without waiting
|
|
601
|
+
* for the agent or a UI button. The form submits at most once. Defaults to
|
|
602
|
+
* `true` whenever a `submit` target is set: when on, no `submit_<name>` function
|
|
603
|
+
* is exposed, the form submits itself, and the agent never confirms a submit.
|
|
604
|
+
* Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
|
|
605
|
+
* submit only on an explicit call). Has no effect on a collect-only form (no
|
|
606
|
+
* `submit` target); setting it `true` there is ignored with a warning.
|
|
607
|
+
*/
|
|
608
|
+
autoSubmit?: boolean;
|
|
577
609
|
}
|
|
578
610
|
|
|
579
611
|
/**
|
|
@@ -595,6 +627,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
595
627
|
schema: FormCollectorSchema;
|
|
596
628
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
597
629
|
submit?: SubmitConfig<V>;
|
|
630
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
631
|
+
autoSubmit?: boolean;
|
|
598
632
|
}
|
|
599
633
|
|
|
600
634
|
/**
|
|
@@ -787,6 +821,16 @@ export declare interface MountChatWidgetOptions {
|
|
|
787
821
|
* fetch the definition from the backend ({@link loadFormCollector}).
|
|
788
822
|
*/
|
|
789
823
|
forms?: Array<CreateFormCollectorOptions | LoadFormCollectorOptions>;
|
|
824
|
+
/**
|
|
825
|
+
* The confirmation notice shown in the chat once a form is submitted (auto-submit
|
|
826
|
+
* or a manual `submit_<name>`), a small success block appended below the
|
|
827
|
+
* conversation. By default the notice shows a `message` string returned by the
|
|
828
|
+
* submit response (POST body / handler result / backend relay) when present, and
|
|
829
|
+
* otherwise falls back to this string ("Form submitted." by default). Pass a
|
|
830
|
+
* function to build the text from the raw submit response yourself; return a
|
|
831
|
+
* nullish value to fall back to the default text.
|
|
832
|
+
*/
|
|
833
|
+
formSubmittedMessage?: string | ((result: unknown) => string | null | undefined);
|
|
790
834
|
/**
|
|
791
835
|
* How clicking a suggested follow-up reply behaves. Defaults to sending the
|
|
792
836
|
* reply as a new user message. Pass a handler to override, or `false` to
|
|
@@ -800,6 +844,25 @@ export declare interface MountChatWidgetOptions {
|
|
|
800
844
|
id: string;
|
|
801
845
|
content: string;
|
|
802
846
|
}) => void;
|
|
847
|
+
/**
|
|
848
|
+
* Called when a form collector submits successfully. `result` is the raw submit
|
|
849
|
+
* response (the third-party API's answer); `values` are the submitted fields.
|
|
850
|
+
* Forwards the client's `form:submitted` event.
|
|
851
|
+
*/
|
|
852
|
+
onFormSubmitted?: (data: {
|
|
853
|
+
name: string;
|
|
854
|
+
values: Record<string, unknown>;
|
|
855
|
+
result: unknown;
|
|
856
|
+
}) => void;
|
|
857
|
+
/**
|
|
858
|
+
* Called when a form collector submit fails at the network/server level.
|
|
859
|
+
* Forwards the client's `form:error` event. No notice is shown in the chat.
|
|
860
|
+
*/
|
|
861
|
+
onFormError?: (data: {
|
|
862
|
+
name: string;
|
|
863
|
+
values: Record<string, unknown>;
|
|
864
|
+
error: string;
|
|
865
|
+
}) => void;
|
|
803
866
|
}
|
|
804
867
|
|
|
805
868
|
/**
|