@useago/sdk 1.5.3 → 1.5.5
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/CHANGELOG.md +33 -0
- package/README.md +10 -0
- package/dist/AgoClient-BI5esqbd.js +1694 -0
- package/dist/AgoClient-CQh8YovA.cjs +8 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +70 -3
- package/dist/angular.d.ts +70 -3
- package/dist/angular.js +3 -3
- package/dist/{createConversationSession-BCb0D6bt.cjs → createConversationSession-0zVkMdYj.cjs} +1 -1
- package/dist/{createConversationSession-C7cnnWKW.js → createConversationSession-BlYTpxwz.js} +1 -1
- package/dist/{createFormCollector-iCDwAwYJ.js → createFormCollector-Bgs94NyR.js} +1 -1
- package/dist/{createFormCollector-t_fGyuTD.cjs → createFormCollector-DiCe_8ik.cjs} +1 -1
- package/dist/devtools.d.cts +69 -2
- package/dist/devtools.d.ts +69 -2
- package/dist/functions-CPs7omgM.cjs +1 -0
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +90 -2
- package/dist/index.d.ts +90 -2
- package/dist/index.js +64 -62
- package/dist/react.cjs +3 -3
- package/dist/react.d.cts +83 -2
- package/dist/react.d.ts +83 -2
- package/dist/react.js +240 -219
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +69 -2
- package/dist/testing.d.ts +69 -2
- package/dist/testing.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +69 -2
- package/dist/vue.d.ts +69 -2
- package/dist/vue.js +2 -2
- package/dist/widget.cjs +2 -2
- package/dist/widget.d.cts +69 -2
- package/dist/widget.d.ts +69 -2
- package/dist/widget.js +4 -4
- package/llms-full.txt +29 -0
- package/package.json +1 -1
- package/dist/AgoClient-BGkFSNZF.cjs +0 -8
- package/dist/AgoClient-CW-BLT1_.js +0 -1542
- package/dist/functions-IGSjjvF4.cjs +0 -1
- package/dist/rolldown-runtime-16Nf8qvH.cjs +0 -1
- /package/dist/{autoContinue-D3Mmaaca.js → autoContinue-CC8K9mBU.js} +0 -0
- /package/dist/{autoContinue-CcCTva-D.cjs → autoContinue-CP9pJR-V.cjs} +0 -0
- /package/dist/{createMockClient-Br0TWgLO.js → createMockClient-DcuNlufr.js} +0 -0
- /package/dist/{createMockClient-BwNLPjeT.cjs → createMockClient-Dw-cyISN.cjs} +0 -0
- /package/dist/{functions-CApuQZ2b.js → functions-tzyOZNp6.js} +0 -0
package/dist/widget.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("./AgoClient-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("./AgoClient-CQh8YovA.cjs"),Xt=require("./createConversationSession-0zVkMdYj.cjs"),mt=require("./createFormCollector-DiCe_8ik.cjs");var Yt='"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',Ie=`var(--ago-font, ${Yt})`,gt={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"},_e="var(--ago-brand-color, #03182f)",Le="var(--ago-brand-text-color, #fff)",Qt="var(--ago-header-background, var(--ago-brand-color, #03182f))",ht="var(--ago-header-text-color, #e8f0fe)",te="var(--ago-panel-background, #fff)",Ct="var(--ago-messages-background, #fbfbfb)",ee="var(--ago-text-color, #30373e)",Et="var(--ago-muted-text-color, #6b6d6f)",N="var(--ago-border-color, #dee3e8)",Fe="var(--ago-accent-color, #1b5fc4)",xt="var(--ago-agent-bubble-background, #f1f3f5)",Zt="var(--ago-radius, 16px)",Pe="var(--ago-message-radius, 16px)",Jt="var(--ago-message-radius, 20px)";function en(t,o){if(o)for(const i of Object.keys(gt)){const r=o[i];r!=null&&t.style.setProperty(gt[i],r)}}function v(t,o){Object.assign(t.style,o)}function h(t={}){const o=document.createElement("div");return v(o,t),o}var bt="ago-chat-widget-keyframes";function tn(){if(typeof document>"u"||document.getElementById(bt))return;const t=document.createElement("style");t.id=bt,t.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(t)}function nn(t){let o=[];const i=document.createElement("form");v(i,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${N}`,backgroundColor:te}),i.className="ago-chat-input";const r=h({display:"flex",flexWrap:"wrap",gap:"6px"}),b=h({display:"flex",gap:"8px",alignItems:"flex-end"}),a=document.createElement("textarea");a.placeholder=t.placeholder,a.setAttribute("aria-label",t.placeholder),a.rows=1,v(a,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${N}`,borderRadius:"12px",fontSize:"16px",fontFamily:Ie,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const C=()=>{a.style.height="auto";const c=Math.min(a.scrollHeight+2,110);a.style.height=`${c}px`,a.style.overflowY=a.scrollHeight+2>110?"auto":"hidden"};a.addEventListener("input",()=>{C(),I()});const m='<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>',x='<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>',p=document.createElement("button");p.type="submit",p.setAttribute("aria-label","Send"),p.innerHTML=m,v(p,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:_e,color:Le,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let f=!1;const I=()=>{const l=a.value.trim()!==""||o.length>0,c=f||!l;p.disabled=c,p.innerHTML=f?x:m,p.style.opacity=c&&!f?"0.5":"1",p.style.cursor=c?"default":"pointer"};let R=null,A=null;t.allowFiles&&(R=document.createElement("input"),R.type="file",R.multiple=!0,v(R,{display:"none"}),A=document.createElement("button"),A.type="button",A.setAttribute("aria-label","Attach file"),A.textContent="📎",v(A,{padding:"10px 12px",border:`1px solid ${N}`,borderRadius:"12px",backgroundColor:te,cursor:"pointer",fontSize:"14px"}),A.addEventListener("click",()=>R?.click()),R.addEventListener("change",()=>{o=[...o,...Array.from(R?.files??[])],Q()}));function Q(){r.replaceChildren(),o.forEach((l,c)=>{const w=h({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${N}`,borderRadius:"8px",fontSize:"12px"}),B=document.createElement("span");B.textContent=l.name;const k=document.createElement("button");k.type="button",k.setAttribute("aria-label",`Remove ${l.name}`),k.textContent="×",v(k,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),k.addEventListener("click",()=>{o=o.filter((j,V)=>V!==c),Q()}),w.append(B,k),r.appendChild(w)}),I()}const D=()=>{const l=a.value,c=o;return a.value="",C(),o=[],Q(),{content:l,files:c}},g=()=>{const{content:l,files:c}=D();(l.trim()||c.length>0)&&t.onSend(l.trim(),c.length>0?c:void 0)};return i.addEventListener("submit",l=>{l.preventDefault(),g()}),a.addEventListener("keydown",l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),g())}),A&&b.appendChild(A),b.append(a,p),R&&i.appendChild(R),i.append(r,b),I(),{inputRow:i,getValueAndClear:D,setDisabled:l=>{a.disabled=l,f=l,I()},focus:()=>a.focus()}}var on={"&":"&","<":"<",">":">",'"':""","'":"'"};function ae(t){return t.replace(/[&<>"']/g,o=>on[o])}function vt(t){const o=t.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var St='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Re="";function ne(t){const o=[],i=b=>(o.push(b),`${Re}${o.length-1}${Re}`);let r=t;return r=r.replace(/`([^`]+)`/g,(b,a)=>i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${St}">${ae(a)}</code>`)),r=r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=vt(C);return m?i(`<img alt="${ae(a)}" src="${ae(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):b}),r=r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=vt(C);return m?i(`<a href="${ae(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${ne(a)}</a>`):b}),r=ae(r),r=r.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>"),r=r.replace(new RegExp(`${Re}(\\d+)${Re}`,"g"),(b,a)=>o[Number(a)]),r}function O(t,o,i){const r=document.createElement(t);return Object.assign(r.style,o),i!==void 0&&(r.innerHTML=i),r}var Rt=/^ {0,3}([-*_])( *\1){2,} *$/,kt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,It=/^ {0,3}(```+|~~~+)/,Ae=/^ {0,3}>\s?/,le=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,rn=["20px","18px","16px","15px","14px","13px"],He=t=>t.match(/^\s*/)?.[0].length??0;function an(t){return t.trim()===""||Rt.test(t)||kt.test(t)||It.test(t)||Ae.test(t)||le.test(t)}function At(t){const o=t[0].match(le),i=o[1].length,r=/\d/.test(o[2]),b=O(r?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:r?"decimal":"disc",listStylePosition:"outside"});let a=0;for(;a<t.length;){const C=t[a].match(le),m=[];for(a++;a<t.length&&He(t[a])>i;)m.push(t[a]),a++;const x=O("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),p=C[3].match(/^\[([ xX])\]\s+(.*)$/);p?(x.style.listStyleType="none",x.style.marginLeft="-20px",x.innerHTML=`<span style="margin-right:6px">${p[1].toLowerCase()==="x"?"☑":"☐"}</span>${ne(p[2])}`):x.innerHTML=ne(C[3]),m.filter(f=>le.test(f)).length>0&&x.appendChild(At(m.filter(f=>f.trim()!==""))),b.appendChild(x)}return b}function sn(t){const o=m=>m.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(x=>x.trim()),i=O("div",{overflowX:"auto",margin:"0 0 8px 0"}),r=O("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),b=document.createElement("thead"),a=document.createElement("tr");for(const m of o(t[0]))a.appendChild(O("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},ne(m)));b.appendChild(a),r.appendChild(b);const C=document.createElement("tbody");for(const m of t.slice(2)){const x=document.createElement("tr");for(const p of o(m))x.appendChild(O("td",{border:"1px solid #dee3e8",padding:"6px 10px"},ne(p)));C.appendChild(x)}return r.appendChild(C),i.appendChild(r),i}var ln=t=>!!t&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(t);function Ne(t){const o=document.createDocumentFragment(),i=t.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
3
|
`);let r=0;for(;r<i.length;){const a=i[r];if(a.trim()===""){r++;continue}const C=a.match(It);if(C){const p=C[1][0],f=[];for(r++;r<i.length&&!new RegExp(`^ {0,3}${p==="`"?"`{3,}":"~{3,}"}\\s*$`).test(i[r]);)f.push(i[r]),r++;r++;const I=O("pre",{margin:"0 0 8px 0"});I.appendChild(O("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:St,whiteSpace:"pre"},ae(f.join(`
|
|
4
4
|
`)))),o.appendChild(I);continue}if(Rt.test(a)){o.appendChild(O("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),r++;continue}const m=a.match(kt);if(m){const p=m[1].length;o.appendChild(O(`h${p}`,{margin:"16px 0 8px 0",fontSize:rn[p-1],fontWeight:"600",lineHeight:"1.3"},ne(m[2]))),r++;continue}if(Ae.test(a)){const p=[];for(;r<i.length&&Ae.test(i[r]);)p.push(i[r].replace(Ae,"")),r++;const f=O("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});f.appendChild(Ne(p.join(`
|
|
5
|
-
`))),o.appendChild(f);continue}if(a.includes("|")&&ln(i[r+1])){const p=[a,i[r+1]];for(r+=2;r<i.length&&i[r].includes("|")&&i[r].trim();)p.push(i[r]),r++;o.appendChild(sn(p));continue}if(le.test(a)){const p=[],f=He(a);for(;r<i.length&&i[r].trim()!=="";)if(le.test(i[r])||He(i[r])>f)p.push(i[r]),r++;else break;o.appendChild(At(p));continue}const x=[a];for(r++;r<i.length&&!an(i[r]);)x.push(i[r]),r++;o.appendChild(O("p",{margin:"0 0 8px 0",lineHeight:"1.6"},x.map(p=>ne(p)).join("<br>")))}const b=o.lastElementChild;return b&&(b.style.marginBottom="0"),o}function dn(t,o){const{isLast:i,isLastOfBlock:r,bubbleStyle:b,showAgentName:a,agentBubble:C,followUpEnabled:m,followUpHandler:x,isMobile:p}=o,f=t.role==="user",I=b==="imessage",R=h({display:"flex",flexDirection:"column",alignItems:f?"flex-end":"flex-start",marginBottom:I&&!r?"2px":"16px"});if(R.className=`ago-message ago-message--${t.role}`,!f&&a&&t.agent){const g=h({fontSize:"13px",fontWeight:"500",color:ee,marginBottom:"6px",padding:"0 4px"});g.className="ago-message__agent",g.textContent=t.agent.displayName||t.agent.name,R.appendChild(g)}if(!f&&t.sources&&t.sources.length>0){const g=h({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});g.className="ago-message__sources",t.sources.forEach((l,c)=>{const w=l.url?document.createElement("a"):document.createElement("div");l.url&&w instanceof HTMLAnchorElement&&(w.href=l.url,w.target="_blank",w.rel="noopener noreferrer"),v(w,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${N}`,borderRadius:"8px",backgroundColor:te,textDecoration:"none",color:ee,fontSize:"12px",overflow:"hidden"});const B=h({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${Fe}`,color:Fe,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});B.textContent=String(c+1);const k=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});k.textContent=l.title,k.title=l.title,w.append(B,k),g.appendChild(w)}),R.appendChild(g)}if(t.attachments&&t.attachments.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:f?"flex-end":"flex-start",maxWidth:"75%"});g.className="ago-message__attachments";for(const l of t.attachments){const c=se.safeAttachmentUrl(l.url);if(se.canInlineImage(l)&&c){const M=document.createElement("a");M.href=c,M.target="_blank",M.rel="noopener noreferrer",v(M,{display:"inline-block",textDecoration:"none"});const q=document.createElement("img");q.src=c,q.alt=l.name,q.loading="lazy",v(q,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${N}`,display:"block"}),M.appendChild(q),g.appendChild(M);continue}const w=c?document.createElement("a"):document.createElement("div");c&&w instanceof HTMLAnchorElement&&(w.href=c,w.target="_blank",w.rel="noopener noreferrer"),v(w,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${N}`,backgroundColor:f?"rgba(255,255,255,0.12)":te,color:f?Le:ee,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const B=document.createElement("span");B.textContent="📄",B.setAttribute("aria-hidden","true"),v(B,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const k=h({display:"flex",flexDirection:"column",minWidth:"0"}),j=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});j.textContent=l.name,j.title=l.name,k.appendChild(j);const V=se.formatFileSize(l.fileSize);if(V){const M=h({fontSize:"11px",color:Et});M.textContent=V,k.appendChild(M)}w.append(B,k),g.appendChild(w)}R.appendChild(g)}const A=f||C||I,Q=!!t.content||t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",D=h({maxWidth:A?I||f?p?"88%":"75%":p?"92%":"85%":"100%",padding:A?"10px 14px":"2px 8px",borderRadius:I?Jt:A?Pe:"0",backgroundColor:f?_e:A?xt:"transparent",color:f?Le:ee,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(D.className="ago-message__content",I&&r){D.style.position="relative";const g=h({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:f?_e:xt});g.className="ago-message__tail";const l=h({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:Ct});l.className="ago-message__tail-mask",f?(g.style.right="-8px",g.style.borderBottomLeftRadius="16px 14px",l.style.right="-10px",l.style.borderBottomLeftRadius="10px"):(g.style.left="-7px",g.style.borderBottomRightRadius="16px 14px",l.style.left="-10px",l.style.borderBottomRightRadius="10px"),D.append(g,l)}if(t.content?D.appendChild(Ne(t.content)):(t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT")&&D.appendChild(pn()),Q&&R.appendChild(D),i&&t.followUpReplies&&t.followUpReplies.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});g.className="ago-message__followups";for(const l of t.followUpReplies){const c=document.createElement("button");c.type="button",c.className="ago-message__followup-btn",c.textContent=l,c.disabled=!m,v(c,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:Pe,border:`1px solid ${N}`,backgroundColor:te,color:ee,cursor:m?"pointer":"default",transition:"border-color 0.15s"}),x&&c.addEventListener("click",()=>x(l)),c.addEventListener("mouseenter",()=>{c.style.borderColor=Fe}),c.addEventListener("mouseleave",()=>{c.style.borderColor=N}),g.appendChild(c)}R.appendChild(g)}return R}function cn(t){const o=h({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:Pe,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});o.className="ago-form-notice",o.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),v(i,{fontWeight:"700"});const r=document.createElement("span");return r.textContent=t,o.append(i,r),o}function pn(){const t=h({display:"flex",gap:"4px",padding:"4px 0"});for(let o=0;o<3;o++){const i=h({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${o*.2}s`});t.appendChild(i)}return t}function fn(){const t="http://www.w3.org/2000/svg",o=document.createElementNS(t,"svg");o.setAttribute("width","26"),o.setAttribute("height","26"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none");const i=document.createElementNS(t,"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"),o.appendChild(i),o}var yt="Form submitted.";function un(t){if(typeof t=="string")return t||null;if(!t||typeof t!="object")return null;const o=t;if(typeof o.message=="string"&&o.message)return o.message;const i=o.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const r=i.message;if(typeof r=="string"&&r)return r}return null}var mn=0,We=0,Ue=0;function wt(){if(We++>0)return;Ue=window.scrollY;const{style:t}=document.body;t.position="fixed",t.top=`-${Ue}px`,t.left="0",t.right="0",t.width="100%",document.documentElement.style.overflow="hidden"}function ke(){if(We===0||--We>0)return;const{style:t}=document.body;t.removeProperty("position"),t.removeProperty("top"),t.removeProperty("left"),t.removeProperty("right"),t.removeProperty("width"),document.documentElement.style.removeProperty("overflow"),window.scrollTo(0,Ue)}function gn(t){const o=typeof t=="string"?document.querySelector(t):t;if(!o)throw new Error(`mountChatWidget: target "${String(t)}" not found.`);return o}function hn(t,o){const{title:i="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:b="Type a message...",allowFiles:a=!1,height:C=500,placement:m="inline",width:x=400,defaultOpen:p=!1,logoUrl:f,showAgentName:I=!1,agentBubble:R=!1,bubbleStyle:A="default",showHeader:Q=!0,theme:D,loadThreads:g=!1,forms:l,formSubmittedMessage:c=yt,onFollowUpClick:w,onMessageSent:B,onMessageReceived:k,onFormSubmitted:j,onFormError:V,onOpen:M,onClose:q}=o,oe=typeof r=="string"?{message:r,mode:"static"}:r,Ge=oe.message,je=oe.mode??"static",_t="speed"in oe&&oe.speed||45,Ve="followUpReplies"in oe&&oe.followUpReplies||void 0;if(!o.client&&!o.config?.baseUrl)throw new se.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const E=o.client??new se.AgoClient(o.config),qe=gn(t),z=m==="left"||m==="right",Lt=z&&(o.launcher??!0);let Z=z?p:!0,ge=!1;const Nt=o.mobile?.breakpoint??768,Te=o.mobile?.trigger??"tap",Ke=typeof window<"u"&&!!window.matchMedia,T=Ke?window.matchMedia(`(max-width: ${Nt}px)`):void 0,Tt=Ke?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,re=!z&&!!T,$e=o.persistConversation,he=$e?Xt.createConversationSession($e===!0?{}:$e):void 0;let H=o.conversationId??he?.getLastActiveThread()??void 0,u=[],J=!1,de=null,K;const Xe=[];function $t(e){if(typeof c=="function"){const s=c(e);if(typeof s=="string"&&s)return s}const n=un(e);return n||(typeof c=="string"?c:yt)}const xe=[],d=h({display:"flex",flexDirection:"column",height:z?"100%":typeof C=="number"?`${C}px`:C,border:`1px solid ${N}`,borderRadius:Zt,overflow:"hidden",backgroundColor:te,fontFamily:Ie,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",en(d,D);let F;if(Q){if(F=h({padding:"14px 16px",borderBottom:`1px solid ${N}`,backgroundColor:Qt,color:ht,display:"flex",alignItems:"center",gap:"10px"}),F.className="ago-chat-widget__header",f){const n=document.createElement("img");n.src=f,n.alt="Logo",v(n,{height:"24px",width:"auto"}),F.appendChild(n)}const e=document.createElement("h3");if(e.textContent=i,v(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),F.appendChild(e),z){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",v(n,{marginLeft:"auto",background:"transparent",border:"none",color:ht,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),n.addEventListener("click",()=>ze()),F.appendChild(n)}}const _=h({flex:"1",overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:Ct});_.className="ago-chat-widget__messages",_.setAttribute("role","log"),_.setAttribute("aria-live","polite"),_.setAttribute("aria-relevant","additions text"),_.setAttribute("aria-atomic","false");const{inputRow:Be,setDisabled:Bt,focus:be}=nn({placeholder:b,allowFiles:a,onSend:(e,n)=>{Ce(e,n)}});tn(),d.append(...F?[F]:[],_,Be);let ve=d,U,$;const ye=m==="left"?"left":"right";if(z&&(U=h({position:"fixed",top:"0",bottom:"0",[ye]:"0",width:typeof x=="number"?`${x}px`:x,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",v(d,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ye==="left"?"borderRight":"borderLeft"]:`1px solid ${N}`}),U.appendChild(d),ve=U),Lt){if($=document.createElement("button"),$.type="button",$.className="ago-chat-widget-launcher",$.setAttribute("aria-label",`Open ${i}`),v($,{position:"fixed",bottom:"20px",[ye]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:_e,color:Le,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:Ie}),f){const e=document.createElement("img");e.src=f,e.alt="",v(e,{width:"26px",height:"26px",objectFit:"contain"}),$.appendChild(e)}else $.appendChild(fn());$.addEventListener("click",()=>De())}const ce=re?`ago-vt-${++mn}`:"",Ye=52;let W=!1,pe=0,ie=0,P,fe,X;const we={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};qe.appendChild(ve),$&&qe.appendChild($),Ee(),re&&(P=Vt(),d.insertBefore(P,d.firstChild),fe=document.createElement("style"),fe.id=ce,fe.textContent=`::view-transition-group(${ce}),::view-transition-group(${ce}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(fe),(Te==="focus"||Te==="tap")&&(d.addEventListener("pointerdown",e=>{if(W||!T?.matches)return;const n=Be.contains(e.target);if(Te==="tap"){if((e.target instanceof Element?e.target:null)?.closest("button,a[href],[role='button']"))return}else if(!n)return;n&&e.preventDefault(),ue()},!0),d.addEventListener("focusin",e=>{T?.matches&&Be.contains(e.target)&&ue()})),document.addEventListener("keydown",at)),T&&T.addEventListener("change",st);const Mt=w!==!1,Ot=w===!1?void 0:w??(e=>{re&&T?.matches&&!W?ue().then(()=>Ce(e)):Ce(e)});function L(){if(_.replaceChildren(),u.length===0){if(je==="static"){const n=h({textAlign:"center",color:Et,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});n.appendChild(Ne(Ge)),_.appendChild(n)}}else u.forEach((n,s)=>{const S=s===u.length-1||u[s+1].role!==n.role;_.appendChild(dn(n,{isLast:s===u.length-1,isLastOfBlock:S,bubbleStyle:A,showAgentName:I,agentBubble:R,followUpEnabled:Mt,followUpHandler:Ot,isMobile:!!T?.matches}))});for(const n of Xe)_.appendChild(cn(n));if(de){const n=h({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});n.setAttribute("role","alert"),n.textContent=de,_.appendChild(n)}_.scrollTop=_.scrollHeight;const e=u[u.length-1];Bt(J&&e?.role==="assistant"&&(e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT"))}function Dt(){for(let e=u.length-1;e>=0;e--){const n=u[e];if(n.role==="assistant"&&(n.status==="IN_PROGRESS"||n.status==="WAITING_CLIENT"))return n}}const Qe=e=>{H||(H=e.conversationId)},Ze=e=>{const n=Dt();n&&(n.content+=e.content,L())},Je=e=>{const n=u.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");n>=0?u[n]=e:u.push(e),L(),be()},et=e=>{const n=u.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");n>=0?u[n]=e:u.push(e),J=!1,L(),e.status==="DONE"&&k?.({id:e.id,content:e.content})},tt=e=>{de=e.error,J=!1,u=u.filter(n=>!n.id.startsWith("temp-")),L()};function zt(e){const n={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};u.push(n),L();const s=e.match(/\S+\s*/g)??[e];let S=0;K=setInterval(()=>{if(S>=s.length){clearInterval(K),K=void 0,n.status="DONE",Ve&&(n.followUpReplies=Ve),L();return}n.content+=s[S],S++,L()},_t)}E.on("message:start",Qe),E.on("message:chunk",Ze),E.on("message:answer-complete",Je),E.on("message:complete",et),E.on("message:error",tt);const nt=e=>j?.(e),ot=e=>V?.(e);j&&E.on("form:submitted",nt),V&&E.on("form:error",ot);const Me=[];let rt=!1;const it=e=>{if(rt)return;Me.push(e.install(E));let n=e.store.get().submitted;const s=e.store.subscribe(S=>{S.submitted&&!n&&(Xe.push($t(S.submitResult)),L()),n=S.submitted});Me.push(s)};for(const e of l??[])e.schema!=null?it(mt.createFormCollector(e)):mt.loadFormCollector(E,e).then(n=>it(n)).catch(()=>{});async function Ce(e,n){const s=e.trim();if(!s&&!n?.length||J)return;if(B?.(s),J=!0,de=null,K){clearInterval(K),K=void 0;const y=u.find(G=>G.id.startsWith("ago-intro-"));y&&!y.content?u=u.filter(G=>G!==y):y&&(y.status="DONE")}const S=Date.now();u.push({id:`temp-user-${S}`,conversationId:H||"",content:s,role:"user",status:"DONE",attachments:n&&n.length>0?se.attachmentsFromFiles(n):void 0,createdAt:new Date}),u.push({id:`temp-assistant-${S}`,conversationId:H||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),L();try{const y=await E.sendMessage(s,{conversationId:H,files:n});y.conversationId&&(H||(H=y.conversationId),he?.setActiveThread(y.conversationId,y.createdAt));const G=u.find(Y=>Y.id===`temp-user-${S}`);if(G&&(G.id=`user-${S}`,G.conversationId=y.conversationId),!u.some(Y=>Y.id===y.id)){const Y=u.findIndex(Kt=>Kt.id===`temp-assistant-${S}`);Y>=0?u[Y]=y:u.push(y)}u=u.filter(Y=>!Y.id.startsWith("temp-")),y.status!=="WAITING_CLIENT"&&(J=!1),L(),g&&Oe()}catch(y){de=y instanceof Error?y.message:"Failed to send message",J=!1,u=u.filter(G=>!G.id.startsWith("temp-")),L()}}async function Oe(){try{const e=await E.getConversations();xe.splice(0,xe.length,...e)}catch{}return xe}async function Ft(e){try{const n=(await E.getConversation(e))?.messages??[];n.length>0&&u.length===0&&(u=n,L())}catch{u.length===0&&(he?.clear(),H=void 0)}}return L(),re&&T?.matches||be(),H?Ft(H):je==="streaming"&&zt(Ge),g&&Oe(),{client:E,element:ve,sendMessage:Ce,...z||re?{open:Ht,close:Wt,toggle:Ut}:{},session:he,threads:xe,refreshThreads:Oe,destroy(){K&&clearInterval(K),E.off("message:start",Qe),E.off("message:chunk",Ze),E.off("message:answer-complete",Je),E.off("message:complete",et),E.off("message:error",tt),j&&E.off("form:submitted",nt),V&&E.off("form:error",ot),rt=!0,Me.forEach(e=>e()),ve.remove(),$?.remove(),P?.remove(),fe?.remove(),X?.remove(),T?.removeEventListener("change",st),re&&(document.removeEventListener("keydown",at),ct(),W&&ke()),ge&&(ge=!1,ke()),o.client||E.destroy()}};function Ee(){if(!U)return;{const s=ye==="left"?"border-right":"border-left";T?.matches?(U.style.width="100%",d.style.borderRadius="0",d.style.removeProperty(s)):(U.style.width=typeof x=="number"?`${x}px`:x,d.style.setProperty(s,`1px solid ${N}`))}const e=m==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=Z?"translateX(0)":e,U.setAttribute("aria-hidden",Z?"false":"true"),$&&($.style.display=Z?"none":"flex");const n=Z&&!!T?.matches;n!==ge&&(ge=n,n?wt():ke())}function De(){Z=!0,Ee(),be(),M?.()}function ze(){Z=!1,Ee(),q?.()}function Pt(){Z?ze():De()}function Ht(){z?De():ue()}function Wt(){z?ze():me()}function Ut(){z?Pt():W?me():ue()}function Gt(){return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(e=>e.getClientRects().length>0)}function at(e){if(!W)return;if(e.key==="Escape"){me();return}if(e.key!=="Tab")return;const n=Gt();if(n.length===0){e.preventDefault();return}const s=n[0],S=n[n.length-1],y=document.activeElement;e.shiftKey&&(y===s||!d.contains(y))?(e.preventDefault(),S.focus()):!e.shiftKey&&(y===S||!d.contains(y))&&(e.preventDefault(),s.focus())}function st(e){z?Ee():!e.matches&&W&&me(),L()}function lt(){return window.visualViewport?.height??window.innerHeight}function dt(){const e=window.visualViewport,n=e?.offsetTop??0,s=e?.height??pe,S=Math.min(0,n+s-pe);d.style.top=`${S}px`,P&&(P.style.top=`${n}px`)}function Se(){ie||(ie=requestAnimationFrame(()=>{ie=0,dt()}))}function jt(){window.visualViewport?.addEventListener("resize",Se),window.visualViewport?.addEventListener("scroll",Se)}function ct(){window.visualViewport?.removeEventListener("resize",Se),window.visualViewport?.removeEventListener("scroll",Se),ie&&(cancelAnimationFrame(ie),ie=0)}function pt(){_.scrollTop=_.scrollHeight}function Vt(){const e=h({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${Ye}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:te,borderBottom:`1px solid ${N}`,zIndex:"2147483001",fontFamily:Ie});if(e.className="ago-chat-widget-mobile-bar",f){const s=document.createElement("img");s.src=f,s.alt="",v(s,{height:"28px",width:"auto"}),e.appendChild(s)}else if(i){const s=document.createElement("span");s.textContent=i,v(s,{fontSize:"15px",fontWeight:"600",color:ee,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),e.appendChild(s)}else e.appendChild(h({}));const n=document.createElement("button");return n.type="button",n.setAttribute("aria-label","Close"),n.textContent="×",v(n,{border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:ee,cursor:"pointer",padding:"4px 8px"}),n.addEventListener("click",()=>{me()}),e.appendChild(n),e}function qt(){return typeof document.startViewTransition=="function"&&!Tt?.matches&&!!T?.matches}function ft(e){const n=document;if(qt()&&n.startViewTransition){d.style.setProperty("view-transition-name",ce),P?.style.setProperty("view-transition-name",`${ce}-bar`);const s=()=>{d.style.removeProperty("view-transition-name"),P?.style.removeProperty("view-transition-name")};return n.startViewTransition(e).finished.then(s,s)}return e(),Promise.resolve()}function ut(e){if(e)X&&d.parentElement?.insertBefore(X,d),v(d,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",height:"var(--ago-vh, 100dvh)",zIndex:"2147483000",border:"none",borderRadius:"0",boxShadow:"none",paddingTop:`calc(${Ye}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("aria-label",i),wt(),F&&(F.style.display="none"),P&&(P.style.display="flex");else{X?.remove(),X=void 0;for(const n of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])d.style.removeProperty(n);d.style.height=we.height,d.style.border=we.border,d.style.borderRadius=we.borderRadius,d.style.boxShadow=we.boxShadow,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),ke(),F&&(F.style.display="flex"),P&&(P.style.display="none")}}function ue(){if(W||!T?.matches)return Promise.resolve();const e=d.getBoundingClientRect();if(e.height>=lt()*.8)return Promise.resolve();W=!0,X=h({width:`${e.width}px`,height:`${e.height}px`}),X.className="ago-chat-widget-spacer",X.setAttribute("aria-hidden","true"),pe=lt(),d.style.setProperty("--ago-vh",`${pe}px`),dt(),jt();const n=ft(()=>ut(!0));return n.then(()=>{pt(),be()}),pt(),M?.(),n}function me(){if(!W)return Promise.resolve();W=!1,ct(),d.querySelector("textarea")?.blur();const e=ft(()=>ut(!1));return e.then(()=>d.style.removeProperty("--ago-vh")),pe=0,q?.(),e}}exports.mountChatWidget=hn;exports.renderMarkdown=Ne;
|
|
5
|
+
`))),o.appendChild(f);continue}if(a.includes("|")&&ln(i[r+1])){const p=[a,i[r+1]];for(r+=2;r<i.length&&i[r].includes("|")&&i[r].trim();)p.push(i[r]),r++;o.appendChild(sn(p));continue}if(le.test(a)){const p=[],f=He(a);for(;r<i.length&&i[r].trim()!=="";)if(le.test(i[r])||He(i[r])>f)p.push(i[r]),r++;else break;o.appendChild(At(p));continue}const x=[a];for(r++;r<i.length&&!an(i[r]);)x.push(i[r]),r++;o.appendChild(O("p",{margin:"0 0 8px 0",lineHeight:"1.6"},x.map(p=>ne(p)).join("<br>")))}const b=o.lastElementChild;return b&&(b.style.marginBottom="0"),o}function dn(t,o){const{isLast:i,isLastOfBlock:r,bubbleStyle:b,showAgentName:a,agentBubble:C,followUpEnabled:m,followUpHandler:x,isMobile:p}=o,f=t.role==="user",I=b==="imessage",R=h({display:"flex",flexDirection:"column",alignItems:f?"flex-end":"flex-start",marginBottom:I&&!r?"2px":"16px"});if(R.className=`ago-message ago-message--${t.role}`,!f&&a&&t.agent){const g=h({fontSize:"13px",fontWeight:"500",color:ee,marginBottom:"6px",padding:"0 4px"});g.className="ago-message__agent",g.textContent=t.agent.displayName||t.agent.name,R.appendChild(g)}if(!f&&t.sources&&t.sources.length>0){const g=h({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});g.className="ago-message__sources",t.sources.forEach((l,c)=>{const w=l.url?document.createElement("a"):document.createElement("div");l.url&&w instanceof HTMLAnchorElement&&(w.href=l.url,w.target="_blank",w.rel="noopener noreferrer"),v(w,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${N}`,borderRadius:"8px",backgroundColor:te,textDecoration:"none",color:ee,fontSize:"12px",overflow:"hidden"});const B=h({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${Fe}`,color:Fe,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});B.textContent=String(c+1);const k=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});k.textContent=l.title,k.title=l.title,w.append(B,k),g.appendChild(w)}),R.appendChild(g)}if(t.attachments&&t.attachments.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:f?"flex-end":"flex-start",maxWidth:"75%"});g.className="ago-message__attachments";for(const l of t.attachments){const c=se.safeAttachmentUrl(l.url);if(se.canInlineImage(l)&&c){const M=document.createElement("a");M.href=c,M.target="_blank",M.rel="noopener noreferrer",v(M,{display:"inline-block",textDecoration:"none"});const q=document.createElement("img");q.src=c,q.alt=l.name,q.loading="lazy",v(q,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${N}`,display:"block"}),M.appendChild(q),g.appendChild(M);continue}const w=c?document.createElement("a"):document.createElement("div");c&&w instanceof HTMLAnchorElement&&(w.href=c,w.target="_blank",w.rel="noopener noreferrer"),v(w,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${N}`,backgroundColor:f?"rgba(255,255,255,0.12)":te,color:f?Le:ee,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const B=document.createElement("span");B.textContent="📄",B.setAttribute("aria-hidden","true"),v(B,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const k=h({display:"flex",flexDirection:"column",minWidth:"0"}),j=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});j.textContent=l.name,j.title=l.name,k.appendChild(j);const V=se.formatFileSize(l.fileSize);if(V){const M=h({fontSize:"11px",color:Et});M.textContent=V,k.appendChild(M)}w.append(B,k),g.appendChild(w)}R.appendChild(g)}const A=f||C||I,Q=!!t.content||t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",D=h({maxWidth:A?I||f?p?"88%":"75%":p?"92%":"85%":"100%",padding:A?"10px 14px":"2px 8px",borderRadius:I?Jt:A?Pe:"0",backgroundColor:f?_e:A?xt:"transparent",color:f?Le:ee,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(D.className="ago-message__content",I&&r){D.style.position="relative";const g=h({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:f?_e:xt});g.className="ago-message__tail";const l=h({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:Ct});l.className="ago-message__tail-mask",f?(g.style.right="-8px",g.style.borderBottomLeftRadius="16px 14px",l.style.right="-10px",l.style.borderBottomLeftRadius="10px"):(g.style.left="-7px",g.style.borderBottomRightRadius="16px 14px",l.style.left="-10px",l.style.borderBottomRightRadius="10px"),D.append(g,l)}if(t.content?D.appendChild(Ne(t.content)):(t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT")&&D.appendChild(pn()),Q&&R.appendChild(D),i&&t.followUpReplies&&t.followUpReplies.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});g.className="ago-message__followups";for(const l of t.followUpReplies){const c=document.createElement("button");c.type="button",c.className="ago-message__followup-btn",c.textContent=l,c.disabled=!m,v(c,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:Pe,border:`1px solid ${N}`,backgroundColor:te,color:ee,cursor:m?"pointer":"default",transition:"border-color 0.15s"}),x&&c.addEventListener("click",()=>x(l)),c.addEventListener("mouseenter",()=>{c.style.borderColor=Fe}),c.addEventListener("mouseleave",()=>{c.style.borderColor=N}),g.appendChild(c)}R.appendChild(g)}return R}function cn(t){const o=h({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:Pe,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});o.className="ago-form-notice",o.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),v(i,{fontWeight:"700"});const r=document.createElement("span");return r.textContent=t,o.append(i,r),o}function pn(){const t=h({display:"flex",gap:"4px",padding:"4px 0"});for(let o=0;o<3;o++){const i=h({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${o*.2}s`});t.appendChild(i)}return t}function fn(){const t="http://www.w3.org/2000/svg",o=document.createElementNS(t,"svg");o.setAttribute("width","26"),o.setAttribute("height","26"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none");const i=document.createElementNS(t,"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"),o.appendChild(i),o}var yt="Form submitted.";function un(t){if(typeof t=="string")return t||null;if(!t||typeof t!="object")return null;const o=t;if(typeof o.message=="string"&&o.message)return o.message;const i=o.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const r=i.message;if(typeof r=="string"&&r)return r}return null}var mn=0,We=0,Ue=0;function wt(){if(We++>0)return;Ue=window.scrollY;const{style:t}=document.body;t.position="fixed",t.top=`-${Ue}px`,t.left="0",t.right="0",t.width="100%",document.documentElement.style.overflow="hidden"}function ke(){if(We===0||--We>0)return;const{style:t}=document.body;t.removeProperty("position"),t.removeProperty("top"),t.removeProperty("left"),t.removeProperty("right"),t.removeProperty("width"),document.documentElement.style.removeProperty("overflow"),window.scrollTo(0,Ue)}function gn(t){const o=typeof t=="string"?document.querySelector(t):t;if(!o)throw new Error(`mountChatWidget: target "${String(t)}" not found.`);return o}function hn(t,o){const{title:i="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:b="Type a message...",allowFiles:a=!1,height:C=500,placement:m="inline",width:x=400,defaultOpen:p=!1,logoUrl:f,showAgentName:I=!1,agentBubble:R=!1,bubbleStyle:A="default",showHeader:Q=!0,theme:D,loadThreads:g=!1,forms:l,formSubmittedMessage:c=yt,onFollowUpClick:w,onMessageSent:B,onMessageReceived:k,onFormSubmitted:j,onFormError:V,onOpen:M,onClose:q}=o,oe=typeof r=="string"?{message:r,mode:"static"}:r,Ge=oe.message,je=oe.mode??"static",_t="speed"in oe&&oe.speed||45,Ve="followUpReplies"in oe&&oe.followUpReplies||void 0;if(!o.client&&!o.config?.baseUrl)throw new se.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const E=o.client??new se.AgoClient(o.config),qe=gn(t),z=m==="left"||m==="right",Lt=z&&(o.launcher??!0);let Z=z?p:!0,ge=!1;const Nt=o.mobile?.breakpoint??768,Te=o.mobile?.trigger??"tap",Ke=typeof window<"u"&&!!window.matchMedia,T=Ke?window.matchMedia(`(max-width: ${Nt}px)`):void 0,Tt=Ke?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,re=!z&&!!T,$e=o.persistConversation,he=$e?Xt.createConversationSession($e===!0?{}:$e):void 0;let H=o.conversationId??he?.getLastActiveThread()??void 0,u=[],J=!1,de=null,K;const Xe=[];function $t(e){if(typeof c=="function"){const s=c(e);if(typeof s=="string"&&s)return s}const n=un(e);return n||(typeof c=="string"?c:yt)}const xe=[],d=h({display:"flex",flexDirection:"column",height:z?"100%":typeof C=="number"?`${C}px`:C,border:`1px solid ${N}`,borderRadius:Zt,overflow:"hidden",backgroundColor:te,fontFamily:Ie,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",en(d,D);let F;if(Q){if(F=h({padding:"14px 16px",borderBottom:`1px solid ${N}`,backgroundColor:Qt,color:ht,display:"flex",alignItems:"center",gap:"10px"}),F.className="ago-chat-widget__header",f){const n=document.createElement("img");n.src=f,n.alt="Logo",v(n,{height:"24px",width:"auto"}),F.appendChild(n)}const e=document.createElement("h3");if(e.textContent=i,v(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),F.appendChild(e),z){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",v(n,{marginLeft:"auto",background:"transparent",border:"none",color:ht,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),n.addEventListener("click",()=>ze()),F.appendChild(n)}}const _=h({flex:"1",overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:Ct});_.className="ago-chat-widget__messages",_.setAttribute("role","log"),_.setAttribute("aria-live","polite"),_.setAttribute("aria-relevant","additions text"),_.setAttribute("aria-atomic","false");const{inputRow:Be,setDisabled:Bt,focus:be}=nn({placeholder:b,allowFiles:a,onSend:(e,n)=>{Ce(e,n)}});tn(),d.append(...F?[F]:[],_,Be);let ve=d,U,$;const ye=m==="left"?"left":"right";if(z&&(U=h({position:"fixed",top:"0",bottom:"0",[ye]:"0",width:typeof x=="number"?`${x}px`:x,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",v(d,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ye==="left"?"borderRight":"borderLeft"]:`1px solid ${N}`}),U.appendChild(d),ve=U),Lt){if($=document.createElement("button"),$.type="button",$.className="ago-chat-widget-launcher",$.setAttribute("aria-label",`Open ${i}`),v($,{position:"fixed",bottom:"20px",[ye]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:_e,color:Le,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:Ie}),f){const e=document.createElement("img");e.src=f,e.alt="",v(e,{width:"26px",height:"26px",objectFit:"contain"}),$.appendChild(e)}else $.appendChild(fn());$.addEventListener("click",()=>De())}const ce=re?`ago-vt-${++mn}`:"",Ye=52;let W=!1,pe=0,ie=0,P,fe,X;const we={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};qe.appendChild(ve),$&&qe.appendChild($),Ee(),re&&(P=Vt(),d.insertBefore(P,d.firstChild),fe=document.createElement("style"),fe.id=ce,fe.textContent=`::view-transition-group(${ce}),::view-transition-group(${ce}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(fe),(Te==="focus"||Te==="tap")&&(d.addEventListener("pointerdown",e=>{if(W||!T?.matches)return;const n=Be.contains(e.target);if(Te==="tap"){if((e.target instanceof Element?e.target:null)?.closest("button,a[href],[role='button']"))return}else if(!n)return;n&&e.preventDefault(),ue()},!0),d.addEventListener("focusin",e=>{T?.matches&&Be.contains(e.target)&&ue()})),document.addEventListener("keydown",at)),T&&T.addEventListener("change",st);const Mt=w!==!1,Ot=w===!1?void 0:w??(e=>{re&&T?.matches&&!W?ue().then(()=>Ce(e)):Ce(e)});function L(){if(_.replaceChildren(),u.length===0){if(je==="static"){const n=h({textAlign:"center",color:Et,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});n.appendChild(Ne(Ge)),_.appendChild(n)}}else u.forEach((n,s)=>{const S=s===u.length-1||u[s+1].role!==n.role;_.appendChild(dn(n,{isLast:s===u.length-1,isLastOfBlock:S,bubbleStyle:A,showAgentName:I,agentBubble:R,followUpEnabled:Mt,followUpHandler:Ot,isMobile:!!T?.matches}))});for(const n of Xe)_.appendChild(cn(n));if(de){const n=h({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});n.setAttribute("role","alert"),n.textContent=de,_.appendChild(n)}_.scrollTop=_.scrollHeight;const e=u[u.length-1];Bt(J&&e?.role==="assistant"&&(e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT"))}function Dt(){for(let e=u.length-1;e>=0;e--){const n=u[e];if(n.role==="assistant"&&(n.status==="IN_PROGRESS"||n.status==="WAITING_CLIENT"))return n}}const Qe=e=>{H||(H=e.conversationId)},Ze=e=>{const n=Dt();n&&(n.content+=e.content,L())},Je=e=>{const n=u.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");n>=0?u[n]=e:u.push(e),L(),be()},et=e=>{const n=u.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");n>=0?u[n]=e:u.push(e),J=!1,L(),e.status==="DONE"&&k?.({id:e.id,content:e.content})},tt=e=>{de=e.error,J=!1,u=u.filter(n=>!n.id.startsWith("temp-")),L()};function zt(e){const n={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};u.push(n),L();const s=e.match(/\S+\s*/g)??[e];let S=0;K=setInterval(()=>{if(S>=s.length){clearInterval(K),K=void 0,n.status="DONE",Ve&&(n.followUpReplies=Ve),L();return}n.content+=s[S],S++,L()},_t)}E.on("message:start",Qe),E.on("message:chunk",Ze),E.on("message:answer-complete",Je),E.on("message:complete",et),E.on("message:error",tt);const nt=e=>j?.(e),ot=e=>V?.(e);j&&E.on("form:submitted",nt),V&&E.on("form:error",ot);const Me=[];let rt=!1;const it=e=>{if(rt)return;Me.push(e.install(E));let n=e.store.get().submitted;const s=e.store.subscribe(S=>{S.submitted&&!n&&(Xe.push($t(S.submitResult)),L()),n=S.submitted});Me.push(s)};for(const e of l??[])e.schema!=null?it(mt.createFormCollector(e)):mt.loadFormCollector(E,e).then(n=>it(n)).catch(()=>{});async function Ce(e,n){const s=e.trim();if(!s&&!n?.length||J)return;if(B?.(s),J=!0,de=null,K){clearInterval(K),K=void 0;const y=u.find(G=>G.id.startsWith("ago-intro-"));y&&!y.content?u=u.filter(G=>G!==y):y&&(y.status="DONE")}const S=Date.now();u.push({id:`temp-user-${S}`,conversationId:H||"",content:s,role:"user",status:"DONE",attachments:n&&n.length>0?se.attachmentsFromFiles(n):void 0,createdAt:new Date}),u.push({id:`temp-assistant-${S}`,conversationId:H||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),L();try{const y=await E.sendMessage(s,{conversationId:H,files:n});y.conversationId&&(H||(H=y.conversationId),he?.setActiveThread(y.conversationId,y.createdAt));const G=u.find(Y=>Y.id===`temp-user-${S}`);if(G&&(G.id=`user-${S}`,G.conversationId=y.conversationId),!u.some(Y=>Y.id===y.id)){const Y=u.findIndex(Kt=>Kt.id===`temp-assistant-${S}`);Y>=0?u[Y]=y:u.push(y)}u=u.filter(Y=>!Y.id.startsWith("temp-")),y.status!=="WAITING_CLIENT"&&(J=!1),L(),g&&Oe()}catch(y){de=y instanceof Error?y.message:"Failed to send message",J=!1,u=u.filter(G=>!G.id.startsWith("temp-")),L()}}async function Oe(){try{const{data:e}=await E.getConversations();xe.splice(0,xe.length,...e)}catch{}return xe}async function Ft(e){try{const n=(await E.getConversation(e))?.messages??[];n.length>0&&u.length===0&&(u=n,L())}catch{u.length===0&&(he?.clear(),H=void 0)}}return L(),re&&T?.matches||be(),H?Ft(H):je==="streaming"&&zt(Ge),g&&Oe(),{client:E,element:ve,sendMessage:Ce,...z||re?{open:Ht,close:Wt,toggle:Ut}:{},session:he,threads:xe,refreshThreads:Oe,destroy(){K&&clearInterval(K),E.off("message:start",Qe),E.off("message:chunk",Ze),E.off("message:answer-complete",Je),E.off("message:complete",et),E.off("message:error",tt),j&&E.off("form:submitted",nt),V&&E.off("form:error",ot),rt=!0,Me.forEach(e=>e()),ve.remove(),$?.remove(),P?.remove(),fe?.remove(),X?.remove(),T?.removeEventListener("change",st),re&&(document.removeEventListener("keydown",at),ct(),W&&ke()),ge&&(ge=!1,ke()),o.client||E.destroy()}};function Ee(){if(!U)return;{const s=ye==="left"?"border-right":"border-left";T?.matches?(U.style.width="100%",d.style.borderRadius="0",d.style.removeProperty(s)):(U.style.width=typeof x=="number"?`${x}px`:x,d.style.setProperty(s,`1px solid ${N}`))}const e=m==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=Z?"translateX(0)":e,U.setAttribute("aria-hidden",Z?"false":"true"),$&&($.style.display=Z?"none":"flex");const n=Z&&!!T?.matches;n!==ge&&(ge=n,n?wt():ke())}function De(){Z=!0,Ee(),be(),M?.()}function ze(){Z=!1,Ee(),q?.()}function Pt(){Z?ze():De()}function Ht(){z?De():ue()}function Wt(){z?ze():me()}function Ut(){z?Pt():W?me():ue()}function Gt(){return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(e=>e.getClientRects().length>0)}function at(e){if(!W)return;if(e.key==="Escape"){me();return}if(e.key!=="Tab")return;const n=Gt();if(n.length===0){e.preventDefault();return}const s=n[0],S=n[n.length-1],y=document.activeElement;e.shiftKey&&(y===s||!d.contains(y))?(e.preventDefault(),S.focus()):!e.shiftKey&&(y===S||!d.contains(y))&&(e.preventDefault(),s.focus())}function st(e){z?Ee():!e.matches&&W&&me(),L()}function lt(){return window.visualViewport?.height??window.innerHeight}function dt(){const e=window.visualViewport,n=e?.offsetTop??0,s=e?.height??pe,S=Math.min(0,n+s-pe);d.style.top=`${S}px`,P&&(P.style.top=`${n}px`)}function Se(){ie||(ie=requestAnimationFrame(()=>{ie=0,dt()}))}function jt(){window.visualViewport?.addEventListener("resize",Se),window.visualViewport?.addEventListener("scroll",Se)}function ct(){window.visualViewport?.removeEventListener("resize",Se),window.visualViewport?.removeEventListener("scroll",Se),ie&&(cancelAnimationFrame(ie),ie=0)}function pt(){_.scrollTop=_.scrollHeight}function Vt(){const e=h({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${Ye}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:te,borderBottom:`1px solid ${N}`,zIndex:"2147483001",fontFamily:Ie});if(e.className="ago-chat-widget-mobile-bar",f){const s=document.createElement("img");s.src=f,s.alt="",v(s,{height:"28px",width:"auto"}),e.appendChild(s)}else if(i){const s=document.createElement("span");s.textContent=i,v(s,{fontSize:"15px",fontWeight:"600",color:ee,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),e.appendChild(s)}else e.appendChild(h({}));const n=document.createElement("button");return n.type="button",n.setAttribute("aria-label","Close"),n.textContent="×",v(n,{border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:ee,cursor:"pointer",padding:"4px 8px"}),n.addEventListener("click",()=>{me()}),e.appendChild(n),e}function qt(){return typeof document.startViewTransition=="function"&&!Tt?.matches&&!!T?.matches}function ft(e){const n=document;if(qt()&&n.startViewTransition){d.style.setProperty("view-transition-name",ce),P?.style.setProperty("view-transition-name",`${ce}-bar`);const s=()=>{d.style.removeProperty("view-transition-name"),P?.style.removeProperty("view-transition-name")};return n.startViewTransition(e).finished.then(s,s)}return e(),Promise.resolve()}function ut(e){if(e)X&&d.parentElement?.insertBefore(X,d),v(d,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",height:"var(--ago-vh, 100dvh)",zIndex:"2147483000",border:"none",borderRadius:"0",boxShadow:"none",paddingTop:`calc(${Ye}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("aria-label",i),wt(),F&&(F.style.display="none"),P&&(P.style.display="flex");else{X?.remove(),X=void 0;for(const n of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])d.style.removeProperty(n);d.style.height=we.height,d.style.border=we.border,d.style.borderRadius=we.borderRadius,d.style.boxShadow=we.boxShadow,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),ke(),F&&(F.style.display="flex"),P&&(P.style.display="none")}}function ue(){if(W||!T?.matches)return Promise.resolve();const e=d.getBoundingClientRect();if(e.height>=lt()*.8)return Promise.resolve();W=!0,X=h({width:`${e.width}px`,height:`${e.height}px`}),X.className="ago-chat-widget-spacer",X.setAttribute("aria-hidden","true"),pe=lt(),d.style.setProperty("--ago-vh",`${pe}px`),dt(),jt();const n=ft(()=>ut(!0));return n.then(()=>{pt(),be()}),pt(),M?.(),n}function me(){if(!W)return Promise.resolve();W=!1,ct(),d.querySelector("textarea")?.blur();const e=ft(()=>ut(!1));return e.then(()=>d.style.removeProperty("--ago-vh")),pe=0,q?.(),e}}exports.mountChatWidget=hn;exports.renderMarkdown=Ne;
|
package/dist/widget.d.cts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
declare interface ActivityEntry {
|
|
2
|
+
ts: number;
|
|
3
|
+
actor: "user" | "agent";
|
|
4
|
+
name: string;
|
|
5
|
+
summary: string;
|
|
6
|
+
data?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare interface ActivityInput {
|
|
10
|
+
actor?: "user" | "agent";
|
|
11
|
+
name: string;
|
|
12
|
+
summary: string;
|
|
13
|
+
data?: Record<string, unknown>;
|
|
14
|
+
ts?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
/**
|
|
2
18
|
* Agent information
|
|
3
19
|
*/
|
|
@@ -36,6 +52,8 @@ declare class AgoClient {
|
|
|
36
52
|
private functionRegistry;
|
|
37
53
|
private contextRegistry;
|
|
38
54
|
private eventEmitter;
|
|
55
|
+
private activityLedger;
|
|
56
|
+
private lastSentPageState;
|
|
39
57
|
private config;
|
|
40
58
|
/** Conversations already warned about an empty reply (one warning each). */
|
|
41
59
|
private warnedEmptyConversations;
|
|
@@ -122,9 +140,14 @@ declare class AgoClient {
|
|
|
122
140
|
*/
|
|
123
141
|
rejectFunction(invocationId: string): Promise<void>;
|
|
124
142
|
/**
|
|
125
|
-
* Get
|
|
143
|
+
* Get a page of conversations, newest-first. `pageSize` is capped at 100 by
|
|
144
|
+
* the backend (default 50). Returns the `{ data, has_more, total }` envelope
|
|
145
|
+
* so callers can page; `total` counts across all pages.
|
|
126
146
|
*/
|
|
127
|
-
getConversations(
|
|
147
|
+
getConversations(options?: {
|
|
148
|
+
page?: number;
|
|
149
|
+
pageSize?: number;
|
|
150
|
+
}): Promise<PaginatedResult<Conversation>>;
|
|
128
151
|
/**
|
|
129
152
|
* Get a specific conversation with messages
|
|
130
153
|
*/
|
|
@@ -346,6 +369,19 @@ declare class AgoClient {
|
|
|
346
369
|
* Get the current context snapshot.
|
|
347
370
|
*/
|
|
348
371
|
getContextSnapshot(): ContextSnapshot | null;
|
|
372
|
+
private buildSendContext;
|
|
373
|
+
/**
|
|
374
|
+
* Record something the user just did so the agent is aware of it on the next
|
|
375
|
+
* message. `actor` defaults to `"user"`. Keep `summary` short and high-signal
|
|
376
|
+
* (no raw payloads, secrets, or PII).
|
|
377
|
+
*/
|
|
378
|
+
recordActivity(entry: ActivityInput): void;
|
|
379
|
+
/** Recent user + agent actions, oldest first (a copy). */
|
|
380
|
+
getRecentActivity(): ActivityEntry[];
|
|
381
|
+
clearActivity(): void;
|
|
382
|
+
private addActivity;
|
|
383
|
+
private recordAgentAction;
|
|
384
|
+
private registerActivityContext;
|
|
349
385
|
/**
|
|
350
386
|
* Subscribe to an event
|
|
351
387
|
*/
|
|
@@ -457,6 +493,15 @@ declare interface AgoClientEvents {
|
|
|
457
493
|
* notably `createFormCollector` — can replay them to restore their state.
|
|
458
494
|
*/
|
|
459
495
|
"conversation:loaded": Conversation;
|
|
496
|
+
/**
|
|
497
|
+
* The conversation's title was generated and streamed during a live turn
|
|
498
|
+
* (the backend emits it once, at the end of the first turn). Lets the UI
|
|
499
|
+
* update a header without a refetch.
|
|
500
|
+
*/
|
|
501
|
+
"conversation:title": {
|
|
502
|
+
conversationId: string;
|
|
503
|
+
title: string;
|
|
504
|
+
};
|
|
460
505
|
"toolCall:received": ToolCallData;
|
|
461
506
|
"toolCall:form": ToolCallData;
|
|
462
507
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -517,6 +562,8 @@ declare interface AgoClientEvents {
|
|
|
517
562
|
"nudge:accepted": {
|
|
518
563
|
nudge: ProactiveNudgeInstance;
|
|
519
564
|
};
|
|
565
|
+
/** A user- or agent-action was recorded into the activity ledger. */
|
|
566
|
+
"activity:recorded": ActivityEntry;
|
|
520
567
|
}
|
|
521
568
|
|
|
522
569
|
/**
|
|
@@ -578,6 +625,14 @@ declare interface AgoConfig {
|
|
|
578
625
|
* with `maxResultBytes` on its definition; `Infinity` disables the guard.
|
|
579
626
|
*/
|
|
580
627
|
maxFunctionResultBytes?: number;
|
|
628
|
+
/**
|
|
629
|
+
* Max number of recent actions kept in the in-memory activity ledger that
|
|
630
|
+
* rides along as the `activity:recent` context entry. Older entries drop
|
|
631
|
+
* first. Default `10`. Larger values give the agent more history at the cost
|
|
632
|
+
* of tokens on every message. Each entry's `data` is also size-clamped (long
|
|
633
|
+
* strings truncated, large arrays capped) so one event can't bloat the context.
|
|
634
|
+
*/
|
|
635
|
+
maxActivityEntries?: number;
|
|
581
636
|
/**
|
|
582
637
|
* Enable the proactive mode: declarative triggers evaluated client-side
|
|
583
638
|
* against friction signals (dwell/idle time, rage clicks, route bounces…)
|
|
@@ -1330,6 +1385,16 @@ declare type NudgeAction = {
|
|
|
1330
1385
|
setPageState: Record<string, unknown>;
|
|
1331
1386
|
};
|
|
1332
1387
|
|
|
1388
|
+
/**
|
|
1389
|
+
* A page of list results, mirroring the API's `{ data, has_more, total }`
|
|
1390
|
+
* envelope. `total` is the count across all pages, not just this page.
|
|
1391
|
+
*/
|
|
1392
|
+
declare interface PaginatedResult<T> {
|
|
1393
|
+
data: T[];
|
|
1394
|
+
hasMore: boolean;
|
|
1395
|
+
total: number;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1333
1398
|
/**
|
|
1334
1399
|
* Controller returned by {@link createAgoProactive} (also available as
|
|
1335
1400
|
* `client.proactive`).
|
|
@@ -1610,6 +1675,8 @@ declare interface SSEChunkData {
|
|
|
1610
1675
|
thread?: {
|
|
1611
1676
|
id: string;
|
|
1612
1677
|
};
|
|
1678
|
+
/** Generated conversation title, streamed once at the end of the first turn. */
|
|
1679
|
+
title?: string;
|
|
1613
1680
|
agent?: {
|
|
1614
1681
|
id: string;
|
|
1615
1682
|
name: string;
|
package/dist/widget.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
declare interface ActivityEntry {
|
|
2
|
+
ts: number;
|
|
3
|
+
actor: "user" | "agent";
|
|
4
|
+
name: string;
|
|
5
|
+
summary: string;
|
|
6
|
+
data?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare interface ActivityInput {
|
|
10
|
+
actor?: "user" | "agent";
|
|
11
|
+
name: string;
|
|
12
|
+
summary: string;
|
|
13
|
+
data?: Record<string, unknown>;
|
|
14
|
+
ts?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
/**
|
|
2
18
|
* Agent information
|
|
3
19
|
*/
|
|
@@ -36,6 +52,8 @@ declare class AgoClient {
|
|
|
36
52
|
private functionRegistry;
|
|
37
53
|
private contextRegistry;
|
|
38
54
|
private eventEmitter;
|
|
55
|
+
private activityLedger;
|
|
56
|
+
private lastSentPageState;
|
|
39
57
|
private config;
|
|
40
58
|
/** Conversations already warned about an empty reply (one warning each). */
|
|
41
59
|
private warnedEmptyConversations;
|
|
@@ -122,9 +140,14 @@ declare class AgoClient {
|
|
|
122
140
|
*/
|
|
123
141
|
rejectFunction(invocationId: string): Promise<void>;
|
|
124
142
|
/**
|
|
125
|
-
* Get
|
|
143
|
+
* Get a page of conversations, newest-first. `pageSize` is capped at 100 by
|
|
144
|
+
* the backend (default 50). Returns the `{ data, has_more, total }` envelope
|
|
145
|
+
* so callers can page; `total` counts across all pages.
|
|
126
146
|
*/
|
|
127
|
-
getConversations(
|
|
147
|
+
getConversations(options?: {
|
|
148
|
+
page?: number;
|
|
149
|
+
pageSize?: number;
|
|
150
|
+
}): Promise<PaginatedResult<Conversation>>;
|
|
128
151
|
/**
|
|
129
152
|
* Get a specific conversation with messages
|
|
130
153
|
*/
|
|
@@ -346,6 +369,19 @@ declare class AgoClient {
|
|
|
346
369
|
* Get the current context snapshot.
|
|
347
370
|
*/
|
|
348
371
|
getContextSnapshot(): ContextSnapshot | null;
|
|
372
|
+
private buildSendContext;
|
|
373
|
+
/**
|
|
374
|
+
* Record something the user just did so the agent is aware of it on the next
|
|
375
|
+
* message. `actor` defaults to `"user"`. Keep `summary` short and high-signal
|
|
376
|
+
* (no raw payloads, secrets, or PII).
|
|
377
|
+
*/
|
|
378
|
+
recordActivity(entry: ActivityInput): void;
|
|
379
|
+
/** Recent user + agent actions, oldest first (a copy). */
|
|
380
|
+
getRecentActivity(): ActivityEntry[];
|
|
381
|
+
clearActivity(): void;
|
|
382
|
+
private addActivity;
|
|
383
|
+
private recordAgentAction;
|
|
384
|
+
private registerActivityContext;
|
|
349
385
|
/**
|
|
350
386
|
* Subscribe to an event
|
|
351
387
|
*/
|
|
@@ -457,6 +493,15 @@ declare interface AgoClientEvents {
|
|
|
457
493
|
* notably `createFormCollector` — can replay them to restore their state.
|
|
458
494
|
*/
|
|
459
495
|
"conversation:loaded": Conversation;
|
|
496
|
+
/**
|
|
497
|
+
* The conversation's title was generated and streamed during a live turn
|
|
498
|
+
* (the backend emits it once, at the end of the first turn). Lets the UI
|
|
499
|
+
* update a header without a refetch.
|
|
500
|
+
*/
|
|
501
|
+
"conversation:title": {
|
|
502
|
+
conversationId: string;
|
|
503
|
+
title: string;
|
|
504
|
+
};
|
|
460
505
|
"toolCall:received": ToolCallData;
|
|
461
506
|
"toolCall:form": ToolCallData;
|
|
462
507
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -517,6 +562,8 @@ declare interface AgoClientEvents {
|
|
|
517
562
|
"nudge:accepted": {
|
|
518
563
|
nudge: ProactiveNudgeInstance;
|
|
519
564
|
};
|
|
565
|
+
/** A user- or agent-action was recorded into the activity ledger. */
|
|
566
|
+
"activity:recorded": ActivityEntry;
|
|
520
567
|
}
|
|
521
568
|
|
|
522
569
|
/**
|
|
@@ -578,6 +625,14 @@ declare interface AgoConfig {
|
|
|
578
625
|
* with `maxResultBytes` on its definition; `Infinity` disables the guard.
|
|
579
626
|
*/
|
|
580
627
|
maxFunctionResultBytes?: number;
|
|
628
|
+
/**
|
|
629
|
+
* Max number of recent actions kept in the in-memory activity ledger that
|
|
630
|
+
* rides along as the `activity:recent` context entry. Older entries drop
|
|
631
|
+
* first. Default `10`. Larger values give the agent more history at the cost
|
|
632
|
+
* of tokens on every message. Each entry's `data` is also size-clamped (long
|
|
633
|
+
* strings truncated, large arrays capped) so one event can't bloat the context.
|
|
634
|
+
*/
|
|
635
|
+
maxActivityEntries?: number;
|
|
581
636
|
/**
|
|
582
637
|
* Enable the proactive mode: declarative triggers evaluated client-side
|
|
583
638
|
* against friction signals (dwell/idle time, rage clicks, route bounces…)
|
|
@@ -1330,6 +1385,16 @@ declare type NudgeAction = {
|
|
|
1330
1385
|
setPageState: Record<string, unknown>;
|
|
1331
1386
|
};
|
|
1332
1387
|
|
|
1388
|
+
/**
|
|
1389
|
+
* A page of list results, mirroring the API's `{ data, has_more, total }`
|
|
1390
|
+
* envelope. `total` is the count across all pages, not just this page.
|
|
1391
|
+
*/
|
|
1392
|
+
declare interface PaginatedResult<T> {
|
|
1393
|
+
data: T[];
|
|
1394
|
+
hasMore: boolean;
|
|
1395
|
+
total: number;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1333
1398
|
/**
|
|
1334
1399
|
* Controller returned by {@link createAgoProactive} (also available as
|
|
1335
1400
|
* `client.proactive`).
|
|
@@ -1610,6 +1675,8 @@ declare interface SSEChunkData {
|
|
|
1610
1675
|
thread?: {
|
|
1611
1676
|
id: string;
|
|
1612
1677
|
};
|
|
1678
|
+
/** Generated conversation title, streamed once at the end of the first turn. */
|
|
1679
|
+
title?: string;
|
|
1613
1680
|
agent?: {
|
|
1614
1681
|
id: string;
|
|
1615
1682
|
name: string;
|
package/dist/widget.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as qt, b as Kt, i as Xt, o as Yt, s as Qt, t as Zt } from "./AgoClient-
|
|
2
|
-
import { t as Jt } from "./createConversationSession-
|
|
3
|
-
import { r as en, t as tn } from "./createFormCollector-
|
|
1
|
+
import { a as qt, b as Kt, i as Xt, o as Yt, s as Qt, t as Zt } from "./AgoClient-BI5esqbd.js";
|
|
2
|
+
import { t as Jt } from "./createConversationSession-BlYTpxwz.js";
|
|
3
|
+
import { r as en, t as tn } from "./createFormCollector-Bgs94NyR.js";
|
|
4
4
|
var nn = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', ke = `var(--ago-font, ${nn})`, ut = {
|
|
5
5
|
font: "--ago-font",
|
|
6
6
|
radius: "--ago-radius",
|
|
@@ -910,7 +910,7 @@ function kn(t, o) {
|
|
|
910
910
|
}
|
|
911
911
|
async function Be() {
|
|
912
912
|
try {
|
|
913
|
-
const e = await E.getConversations();
|
|
913
|
+
const { data: e } = await E.getConversations();
|
|
914
914
|
he.splice(0, he.length, ...e);
|
|
915
915
|
} catch {
|
|
916
916
|
}
|
package/llms-full.txt
CHANGED
|
@@ -1389,6 +1389,11 @@ It's fire-and-forget: the handler applies each `set()` locally and returns
|
|
|
1389
1389
|
the next message. React/Vue offer `useAgoPageState(controls, opts?)` with
|
|
1390
1390
|
lifecycle cleanup; Angular exposes `agoService.registerPageStateFunction(...)`.
|
|
1391
1391
|
|
|
1392
|
+
The SDK also tells the agent **what changed**: on each message it diffs the page
|
|
1393
|
+
state against the previous message and adds a `state:delta` entry listing the
|
|
1394
|
+
fields that changed. A navigation (a different page) resets the baseline instead
|
|
1395
|
+
of reporting a diff, so a page switch never shows up as a spurious change.
|
|
1396
|
+
|
|
1392
1397
|
### Navigate then change the page in one go
|
|
1393
1398
|
|
|
1394
1399
|
A request like "open the invoices page and show only the overdue ones" needs two
|
|
@@ -1617,6 +1622,29 @@ client.enableAutoPageContext();
|
|
|
1617
1622
|
|
|
1618
1623
|
(In React, set `<AgoProvider pageContext="auto">`.)
|
|
1619
1624
|
|
|
1625
|
+
### Activity ledger
|
|
1626
|
+
|
|
1627
|
+
Tell the agent what the user (or the agent) just did, so it can reason about
|
|
1628
|
+
recent actions. Call `recordActivity` for meaningful user actions; the agent's
|
|
1629
|
+
own client-function calls (navigation, page-state changes, custom functions) are
|
|
1630
|
+
recorded automatically.
|
|
1631
|
+
|
|
1632
|
+
```ts
|
|
1633
|
+
client.recordActivity({
|
|
1634
|
+
name: "order.shipped",
|
|
1635
|
+
summary: 'User changed order #123 from "Pending" to "Shipped"',
|
|
1636
|
+
});
|
|
1637
|
+
```
|
|
1638
|
+
|
|
1639
|
+
The recent window (last 10 by default, oldest dropped first) rides along as the
|
|
1640
|
+
`activity:recent` context entry. Change the size with `maxActivityEntries` in the
|
|
1641
|
+
config. `actor` defaults to `"user"`; keep `summary` short and high-signal (no raw
|
|
1642
|
+
payloads or secrets). Each entry's `data` is size-clamped before it is stored (long
|
|
1643
|
+
strings truncated with a `…[truncated N chars]` marker, large arrays capped), so one
|
|
1644
|
+
event can't bloat the context. Read or clear the log with
|
|
1645
|
+
`client.getRecentActivity()` / `client.clearActivity()`, observe it via
|
|
1646
|
+
`client.on("activity:recorded", …)`, or use the React `useAgoActivityLog()` hook.
|
|
1647
|
+
|
|
1620
1648
|
### Per framework
|
|
1621
1649
|
|
|
1622
1650
|
| Framework | Idiomatic API |
|
|
@@ -1681,6 +1709,7 @@ const final = await client.waitFor("message:complete", { timeout: 10_000 });
|
|
|
1681
1709
|
| `function:invoke` | `{ invocationId, functionName, arguments, conversationId }` |
|
|
1682
1710
|
| `function:awaiting-approval` | `{ invocationId, functionName, arguments, conversationId }`: a client function call is held pending user approval (pause mode + an `approvalPolicy`/`requiresApproval` match). The turn stays at `WAITING_CLIENT`; call `approveFunction(invocationId)` to run it and resume, or `rejectFunction(invocationId)` to decline. See [Approval gate](functions-and-context.md#approval-gate-ask-before-running) |
|
|
1683
1711
|
| `function:result` | `{ invocationId, result, error? }` |
|
|
1712
|
+
| `activity:recorded` | `ActivityEntry`: a user- or agent-action was recorded into the activity ledger (via `recordActivity`, or auto-recorded when the agent calls a client function). See [Activity ledger](functions-and-context.md#activity-ledger) |
|
|
1684
1713
|
| `form:submitted` | `{ name, values, result }`: a form collector submitted successfully; `result` is the submit response (the third-party API's answer) |
|
|
1685
1714
|
| `form:error` | `{ name, values, error }`: a form collector submit failed at the network/server level (HTTP non-2xx or a thrown handler/fetch). Validation pre-checks (missing fields, no submit target) do not fire this |
|
|
1686
1715
|
| `connection:status` | `{ connected }` |
|
package/package.json
CHANGED