@useago/sdk 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.cjs CHANGED
@@ -1,7 +1,7 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./rolldown-runtime-16Nf8qvH.cjs"),F=require("./AgoClient-CRAnT4qE.cjs"),M=require("./createFormCollector-BB_l0Sia.cjs"),G=require("./createMockClient-ucPENDzz.cjs");let s=require("react");s=T.__toESM(s,1);let o=require("react/jsx-runtime"),_=require("react-markdown");_=T.__toESM(_,1);let N=require("remark-gfm");N=T.__toESM(N,1);function H(e){const[t,r]=(0,s.useState)(!1),n=(0,s.useRef)(null),a=(0,s.useMemo)(()=>{if(n.current&&(n.current.destroy(),n.current=null),!e)return null;const l=new F.AgoClient(e);return n.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(r(!0),()=>{n.current?.destroy(),n.current=null}),[a]),(0,s.useEffect)(()=>{n.current&&e&&n.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var D=(0,s.createContext)(null),Y=({children:e,client:t,tools:r,helpers:n,pageContext:a,...l})=>{const{client:d}=H(t?null:l),c=t||d;return(0,s.useEffect)(()=>{if(!(!r||r.length===0)){for(const p of r)c.register(p);return()=>{for(const p of r)c.unregisterFunction(p.name)}}},[c,r]),(0,s.useEffect)(()=>{if(!n)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(u=>u.functions_exports).then(u=>{for(const[b,x]of Object.entries(n)){const y=u[b];if(!y){console.warn(`[AGO] Unknown helper: "${b}"`);continue}const h=x===!0?y:{...y,handler:x};c.register(h),p.push(h.name)}}),()=>{for(const u of p)c.unregisterFunction(u)}},[c,n]),(0,s.useEffect)(()=>{a==="auto"&&c.enableAutoPageContext()},[c,a]),(0,o.jsx)(D.Provider,{value:c,children:e})};function E(){const e=(0,s.useContext)(D);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function R(){return(0,s.useContext)(D)}function z({client:e,conversationId:t}={}){const r=R(),n=e||r;if(!n)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(t),[p,u]=(0,s.useState)(!1),[b,x]=(0,s.useState)(null);(0,s.useEffect)(()=>{t&&t!==d&&(c(t),y(t))},[t]);const y=async h=>{try{l((await n.getMessages(h)).filter(m=>!m.hidden))}catch(m){x(m instanceof Error?m:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const h=g=>{d||c(g.conversationId)},m=g=>{l(f=>{const w=f[f.length-1];return w&&w.id===g.messageId?[...f.slice(0,-1),{...w,content:w.content+g.content}]:f})},C=g=>{l(f=>{let w=-1;for(let k=f.length-1;k>=0;k--)if(f[k].role==="assistant"&&f[k].status==="IN_PROGRESS"){w=k;break}return w<0?f:[...f.slice(0,w),{...f[w],...g},...f.slice(w+1)]})},v=g=>{l(f=>{const w=f.findIndex(k=>k.id===g.id);return w>=0?[...f.slice(0,w),g,...f.slice(w+1)]:[...f,g]}),u(!1)},i=g=>{x(new Error(g.error)),u(!1)};return n.on("message:start",h),n.on("message:chunk",m),n.on("message:answer-complete",C),n.on("message:complete",v),n.on("message:error",i),()=>{n.off("message:start",h),n.off("message:chunk",m),n.off("message:answer-complete",C),n.off("message:complete",v),n.off("message:error",i)}},[n,d]),{messages:a,isLoading:p,error:b,sendMessage:(0,s.useCallback)(async(h,m)=>{u(!0),x(null);const C={id:`temp-${Date.now()}`,conversationId:d||"",content:h,role:"user",status:"DONE",attachments:m&&m.length>0?F.attachmentsFromFiles(m):void 0,createdAt:new Date},v={id:`temp-assistant-${Date.now()}`,conversationId:d||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(i=>[...i,C,v]);try{const i=await n.sendMessage(h,{conversationId:d,files:m});return i.conversationId&&!d&&c(i.conversationId),l(g=>{const f=g.filter(k=>!k.id.startsWith("temp-")),w={...C,id:C.id.replace("temp-","user-"),conversationId:i.conversationId};return f.some(k=>k.id===i.id)?[...f,w].sort((k,P)=>new Date(k.createdAt).getTime()-new Date(P.createdAt).getTime()):[...f,w,i]}),i}catch(i){return x(i instanceof Error?i:new Error("Failed to send message")),u(!1),l(g=>g.filter(f=>!f.id.startsWith("temp-"))),null}},[n,d]),clearMessages:(0,s.useCallback)(()=>{l([]),c(void 0),x(null)},[]),conversationId:d}}var O=({onSend:e,disabled:t=!1,placeholder:r="Type a message...",allowFiles:n=!1,className:a=""})=>{const[l,d]=(0,s.useState)(""),[c,p]=(0,s.useState)([]),u=(0,s.useRef)(null),b=(0,s.useRef)(null),x=(0,s.useCallback)(()=>{const i=b.current;if(!i)return;const g=110;i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight+2,g)}px`,i.style.overflowY=i.scrollHeight+2>g?"auto":"hidden"},[]),y=(0,s.useCallback)(i=>{i.preventDefault(),(l.trim()||c.length>0)&&(e(l.trim(),c.length>0?c:void 0),d(""),p([]),requestAnimationFrame(x))},[l,c,e,x]),h=(0,s.useCallback)(i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),y(i))},[y]),m=(0,s.useCallback)(i=>{const g=Array.from(i.target.files||[]);p(f=>[...f,...g])},[]),C=(0,s.useCallback)(i=>{p(g=>g.filter((f,w)=>w!==i))},[]),v=l.trim()||c.length>0;return(0,o.jsxs)("form",{onSubmit:y,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[c.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((i,g)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.name}),(0,o.jsx)("button",{type:"button",onClick:()=>C(g),"aria-label":`Remove ${i.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},g))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[n&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>u.current?.click(),disabled:t,"aria-label":"Attach file",style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:u,type:"file",multiple:!0,onChange:m,style:{display:"none"}})]}),(0,o.jsx)("textarea",{ref:b,value:l,onChange:i=>{d(i.target.value),x()},onKeyDown:h,placeholder:r,"aria-label":r,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:i=>{i.currentTarget.style.borderColor="#1b5fc4"},onBlur:i=>{i.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!v,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!v?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!v?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...r})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...r,children:t}),Q=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),A=(e,t)=>{const r=({children:n,...a})=>s.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},n);return r.displayName=`MarkdownHeading${e}`,r},Z=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),te=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),ne=({className:e,children:t,...r})=>e!==void 0||String(t).includes(`
2
- `)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),oe=({children:e,...t})=>(0,o.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),se=({children:e,...t})=>(0,o.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,o.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),ae=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ie=({children:e,...t})=>(0,o.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,o.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ce=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),de={a:X,p:Q,h1:A(1,"20px"),h2:A(2,"18px"),h3:A(3,"16px"),h4:A(4,"15px"),h5:A(5,"14px"),h6:A(6,"13px"),ul:Z,ol:ee,li:te,code:ne,pre:re,blockquote:oe,table:se,th:ae,td:ie,img:le,hr:ce},ue=[N.default],q=({content:e})=>(0,o.jsx)(_.default,{remarkPlugins:ue,components:de,children:e}),fe=({attachment:e,isUser:t})=>{const r=F.safeAttachmentUrl(e.url);if(F.canInlineImage(e))return(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,o.jsx)("img",{src:r,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const n=F.formatFileSize(e.fileSize),a=(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,o.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,o.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),n&&(0,o.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:n})]})]}),l={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:t?"rgba(255,255,255,0.12)":"#fff",color:t?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return r?(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:l,children:a}):(0,o.jsx)("div",{style:l,children:a})},ge=({source:e,index:t})=>{const r=(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,o.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:t+1}),(0,o.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),n={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,o.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:n,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:r}):(0,o.jsx)("div",{style:n,children:r})},pe=()=>(0,o.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,o.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,o.jsx)("style",{children:`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./rolldown-runtime-16Nf8qvH.cjs"),R=require("./AgoClient-CRAnT4qE.cjs"),M=require("./createFormCollector-BB_l0Sia.cjs"),V=require("./createMockClient-ucPENDzz.cjs");let s=require("react");s=T.__toESM(s,1);let o=require("react/jsx-runtime"),_=require("react-markdown");_=T.__toESM(_,1);let N=require("remark-gfm");N=T.__toESM(N,1);function O(e){const[t,r]=(0,s.useState)(!1),n=(0,s.useRef)(null),a=(0,s.useMemo)(()=>{if(n.current&&(n.current.destroy(),n.current=null),!e)return null;const l=new R.AgoClient(e);return n.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(r(!0),()=>{n.current?.destroy(),n.current=null}),[a]),(0,s.useEffect)(()=>{n.current&&e&&n.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var D=(0,s.createContext)(null),Y=({children:e,client:t,tools:r,helpers:n,pageContext:a,...l})=>{const{client:d}=O(t?null:l),c=t||d;return(0,s.useEffect)(()=>{if(!(!r||r.length===0)){for(const p of r)c.register(p);return()=>{for(const p of r)c.unregisterFunction(p.name)}}},[c,r]),(0,s.useEffect)(()=>{if(!n)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(f=>f.functions_exports).then(f=>{for(const[v,x]of Object.entries(n)){const y=f[v];if(!y){console.warn(`[AGO] Unknown helper: "${v}"`);continue}const h=x===!0?y:{...y,handler:x};c.register(h),p.push(h.name)}}),()=>{for(const f of p)c.unregisterFunction(f)}},[c,n]),(0,s.useEffect)(()=>{a==="auto"&&c.enableAutoPageContext()},[c,a]),(0,o.jsx)(D.Provider,{value:c,children:e})};function I(){const e=(0,s.useContext)(D);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function F(){return(0,s.useContext)(D)}function z({client:e,conversationId:t}={}){const r=F(),n=e||r;if(!n)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(t),[p,f]=(0,s.useState)(!1),[v,x]=(0,s.useState)(null);(0,s.useEffect)(()=>{t&&t!==d&&(c(t),y(t))},[t]);const y=async h=>{try{l((await n.getMessages(h)).filter(m=>!m.hidden))}catch(m){x(m instanceof Error?m:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const h=g=>{d||c(g.conversationId),f(!0),l(u=>u.some(b=>b.role==="assistant"&&b.status==="IN_PROGRESS")?u:[...u,{id:g.messageId,conversationId:g.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}])},m=g=>{l(u=>{const b=u[u.length-1];return b&&b.id===g.messageId?[...u.slice(0,-1),{...b,content:b.content+g.content}]:u})},C=g=>{l(u=>{let b=-1;for(let k=u.length-1;k>=0;k--)if(u[k].role==="assistant"&&u[k].status==="IN_PROGRESS"){b=k;break}return b<0?u:[...u.slice(0,b),{...u[b],...g},...u.slice(b+1)]})},w=g=>{l(u=>{const b=u.findIndex(k=>k.id===g.id);return b>=0?[...u.slice(0,b),g,...u.slice(b+1)]:[...u,g]}),f(!1)},i=g=>{x(new Error(g.error)),f(!1)};return n.on("message:start",h),n.on("message:chunk",m),n.on("message:answer-complete",C),n.on("message:complete",w),n.on("message:error",i),()=>{n.off("message:start",h),n.off("message:chunk",m),n.off("message:answer-complete",C),n.off("message:complete",w),n.off("message:error",i)}},[n,d]),{messages:a,isLoading:p,error:v,sendMessage:(0,s.useCallback)(async(h,m)=>{f(!0),x(null);const C={id:`temp-${Date.now()}`,conversationId:d||"",content:h,role:"user",status:"DONE",attachments:m&&m.length>0?R.attachmentsFromFiles(m):void 0,createdAt:new Date},w={id:`temp-assistant-${Date.now()}`,conversationId:d||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(i=>[...i,C,w]);try{const i=await n.sendMessage(h,{conversationId:d,files:m});return i.conversationId&&!d&&c(i.conversationId),l(g=>{const u=g.filter(k=>!k.id.startsWith("temp-")),b={...C,id:C.id.replace("temp-","user-"),conversationId:i.conversationId};return u.some(k=>k.id===i.id)?[...u,b].sort((k,P)=>new Date(k.createdAt).getTime()-new Date(P.createdAt).getTime()):[...u,b,i]}),i}catch(i){return x(i instanceof Error?i:new Error("Failed to send message")),f(!1),l(g=>g.filter(u=>!u.id.startsWith("temp-"))),null}},[n,d]),clearMessages:(0,s.useCallback)(()=>{l([]),c(void 0),x(null)},[]),conversationId:d}}var H=({onSend:e,disabled:t=!1,placeholder:r="Type a message...",allowFiles:n=!1,className:a=""})=>{const[l,d]=(0,s.useState)(""),[c,p]=(0,s.useState)([]),f=(0,s.useRef)(null),v=(0,s.useRef)(null),x=(0,s.useCallback)(()=>{const i=v.current;if(!i)return;const g=110;i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight+2,g)}px`,i.style.overflowY=i.scrollHeight+2>g?"auto":"hidden"},[]),y=(0,s.useCallback)(i=>{i.preventDefault(),(l.trim()||c.length>0)&&(e(l.trim(),c.length>0?c:void 0),d(""),p([]),requestAnimationFrame(x))},[l,c,e,x]),h=(0,s.useCallback)(i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),y(i))},[y]),m=(0,s.useCallback)(i=>{const g=Array.from(i.target.files||[]);p(u=>[...u,...g])},[]),C=(0,s.useCallback)(i=>{p(g=>g.filter((u,b)=>b!==i))},[]),w=l.trim()||c.length>0;return(0,o.jsxs)("form",{onSubmit:y,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[c.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((i,g)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.name}),(0,o.jsx)("button",{type:"button",onClick:()=>C(g),"aria-label":`Remove ${i.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},g))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[n&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>f.current?.click(),disabled:t,"aria-label":"Attach file",style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:f,type:"file",multiple:!0,onChange:m,style:{display:"none"}})]}),(0,o.jsx)("textarea",{ref:v,value:l,onChange:i=>{d(i.target.value),x()},onKeyDown:h,placeholder:r,"aria-label":r,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:i=>{i.currentTarget.style.borderColor="#1b5fc4"},onBlur:i=>{i.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!w,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!w?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!w?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...r})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...r,children:t}),Q=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),A=(e,t)=>{const r=({children:n,...a})=>s.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},n);return r.displayName=`MarkdownHeading${e}`,r},Z=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),te=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),ne=({className:e,children:t,...r})=>e!==void 0||String(t).includes(`
2
+ `)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),oe=({children:e,...t})=>(0,o.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),se=({children:e,...t})=>(0,o.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,o.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),ae=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ie=({children:e,...t})=>(0,o.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,o.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ce=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),de={a:X,p:Q,h1:A(1,"20px"),h2:A(2,"18px"),h3:A(3,"16px"),h4:A(4,"15px"),h5:A(5,"14px"),h6:A(6,"13px"),ul:Z,ol:ee,li:te,code:ne,pre:re,blockquote:oe,table:se,th:ae,td:ie,img:le,hr:ce},ue=[N.default],q=({content:e})=>(0,o.jsx)(_.default,{remarkPlugins:ue,components:de,children:e}),fe=({attachment:e,isUser:t})=>{const r=R.safeAttachmentUrl(e.url);if(R.canInlineImage(e))return(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,o.jsx)("img",{src:r,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const n=R.formatFileSize(e.fileSize),a=(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,o.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,o.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),n&&(0,o.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:n})]})]}),l={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:t?"rgba(255,255,255,0.12)":"#fff",color:t?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return r?(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:l,children:a}):(0,o.jsx)("div",{style:l,children:a})},ge=({source:e,index:t})=>{const r=(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,o.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:t+1}),(0,o.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),n={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,o.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:n,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:r}):(0,o.jsx)("div",{style:n,children:r})},pe=()=>(0,o.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,o.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,o.jsx)("style",{children:`
3
3
  @keyframes ago-pulse {
4
4
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
5
5
  40% { opacity: 1; transform: scale(1); }
6
6
  }
7
- `})]}),$=({message:e,className:t="",showAgentName:r=!1,isLast:n=!1,onFollowUpClick:a})=>{const l=e.role==="user",d=e.status==="IN_PROGRESS";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&r&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((c,p)=>(0,o.jsx)(ge,{source:c,index:p},c.id))}),e.attachments&&e.attachments.length>0&&(0,o.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:l?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(c=>(0,o.jsx)(fe,{attachment:c,isUser:l},c.id))}),(e.content||d)&&(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(q,{content:e.content}):d&&(0,o.jsx)(pe,{})}),n&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:u=>{u.currentTarget.style.borderColor="#dee3e8"},children:c},p))})]})},xe=({client:e,conversationId:t,title:r="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:d=500,logoUrl:c,showAgentName:p=!1,forms:u,onFollowUpClick:b,className:x="",onMessageSent:y,onMessageReceived:h})=>{const m=(0,s.useRef)(null),C=R(),v=e??C,{messages:i,isLoading:g,error:f,sendMessage:w}=z({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!v||!u||u.length===0)return;let S=!1;const I=[];return Promise.all(u.map(j=>j.schema!=null?Promise.resolve(M.createFormCollector(j)):M.loadFormCollector(v,j))).then(j=>{if(!S)for(const V of j)I.push(V.install(v))}).catch(()=>{}),()=>{S=!0,I.forEach(j=>j())}},[v,u?JSON.stringify(u.map(S=>[S.name,S.schema??null,S.submit??!1,S.description??null])):""]),(0,s.useEffect)(()=>{m.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,s.useEffect)(()=>{const S=i[i.length-1];S&&S.role==="assistant"&&S.status==="DONE"&&h&&h({id:S.id,content:S.content})},[i,h]);const k=async(S,I)=>{y?.(S),await w(S,I)},P=i[i.length-1],K=g&&P?.role==="assistant"&&P.status==="IN_PROGRESS",J=b===!1?void 0:b??(S=>k(S));return(0,o.jsxs)("div",{className:`ago-chat-widget ${x}`,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[c&&(0,o.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:r})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[i.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:n}):i.map((S,I)=>(0,o.jsx)($,{message:S,showAgentName:p,isLast:I===i.length-1,onFollowUpClick:J},S.id)),f&&(0,o.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:f.message}),(0,o.jsx)("div",{ref:m})]}),(0,o.jsx)(O,{onSend:k,disabled:K,placeholder:a,allowFiles:l})]})};function B({client:e,autoLoad:t=!0}={}){const r=R(),n=e||r;if(!n)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[p,u]=(0,s.useState)(!1),[b,x]=(0,s.useState)(null),y=(0,s.useCallback)(async()=>{u(!0),x(null);try{l(await n.getConversations())}catch(C){x(C instanceof Error?C:new Error("Failed to load conversations"))}finally{u(!1)}},[n]),h=(0,s.useCallback)(async C=>{u(!0),x(null);try{c(await n.getConversation(C))}catch(v){x(v instanceof Error?v:new Error("Failed to load conversation"))}finally{u(!1)}},[n]),m=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&y()},[t,y]),{conversations:a,currentConversation:d,isLoading:p,error:b,selectConversation:h,startNewConversation:m,refreshConversations:y}}function me(e={}){const t=R(),r=e.client||t;if(!r)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const n=z({client:r,conversationId:e.conversationId}),a=B({client:r,autoLoad:e.autoLoad});return{messages:n.messages,isLoading:n.isLoading,error:n.error||a.error,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function he(e,t){const r=E(),{name:n,description:a,parameters:l,handler:d}=typeof e=="string"?{name:e,...t}:e,c=(0,s.useRef)(d);c.current=d,(0,s.useEffect)(()=>{const p=u=>c.current(u);return r.registerFunction(n,p,{description:a,parameters:l}),()=>{r.unregisterFunction(n)}},[r,n,a,l])}function ye(e,t){const r=E(),n=(0,s.useRef)(e);n.current=e,(0,s.useEffect)(()=>(r.registerNavigationFunction(a=>n.current(a),t),()=>{r.unregisterNavigationFunction()}),[r,t])}function be(e,t){const r=E(),n=t?.functionName??"setPageState",a=(0,s.useRef)(e);a.current=e,(0,s.useEffect)(()=>{const l=a.current.map(d=>{const c=()=>a.current.find(p=>p.name===d.name)??d;return{name:d.name,description:d.description,schema:d.schema,get:d.get?()=>c().get?.():void 0,set:p=>c().set(p)}});return r.registerPageStateFunction(l,{functionName:n}),()=>{r.unregisterPageStateFunction(n)}},[r,n])}var ve="You have navigated the user to a new page. That page now exposes its editable state through the available setPageState function, and its current values in the page context. If the user's latest request also asked to change something on this page, call setPageState now to apply exactly those changes and nothing else. Otherwise, reply with a short confirmation only.";function W(e){return{navigationFunctions:e?.navigationFunctions??["navigateToPage"],pageStateFunctionName:e?.pageStateFunctionName??"setPageState",continuationPrompt:e?.continuationPrompt??ve,maxDepth:e?.maxDepth??1,readinessTimeoutMs:e?.readinessTimeoutMs??4e3,settleMs:e?.settleMs??150,enabled:e?.enabled??!0}}function Ce(e){const t=E(),r=(0,s.useRef)(W(e));r.current=W(e),(0,s.useEffect)(()=>{const n={navigated:!1,depth:0,runId:0,ourSendPending:!1},a=()=>t.getRegisteredFunctions().some(x=>x.name===r.current.pageStateFunctionName),l=x=>new Promise(y=>{let h=!1;const m=g=>{h||(h=!0,clearTimeout(i),t.off("context:changed",v),y(g))},C=()=>setTimeout(()=>m(x===n.runId&&a()),r.current.settleMs),v=()=>{if(x!==n.runId)return m(!1);a()&&(t.off("context:changed",v),C())},i=setTimeout(()=>m(!1),r.current.readinessTimeoutMs);a()?C():t.on("context:changed",v)}),d=async x=>{const y=++n.runId;if(!(!await l(y)||y!==n.runId)){n.depth+=1,n.ourSendPending=!0;try{await t.sendMessage(r.current.continuationPrompt,{conversationId:x,hidden:!0})}catch{n.ourSendPending=!1}}},c=x=>{r.current.navigationFunctions.includes(x.functionName)&&(n.navigated=!0)},p=()=>{n.ourSendPending||(n.depth=0,n.runId+=1)},u=x=>{n.ourSendPending=!1;const y=n.navigated;n.navigated=!1,r.current.enabled&&y&&(n.depth>=r.current.maxDepth||d(x.conversationId))},b=()=>{n.ourSendPending=!1};return t.on("function:invoke",c),t.on("message:start",p),t.on("message:complete",u),t.on("message:error",b),()=>{n.runId+=1,t.off("function:invoke",c),t.off("message:start",p),t.off("message:complete",u),t.off("message:error",b)}},[t])}function we(e,t){const r=E(),n=(0,s.useId)(),a=t??n,l=(0,s.useRef)(e);l.current=e;const d=typeof e=="function";(0,s.useEffect)(()=>{if(typeof l.current=="function"){const c=()=>l.current();return r.addDynamicContext(a,c),()=>{r.removeDynamicContext(a)}}return r.setContext(a,l.current),()=>{r.removeContext(a)}},[r,a,d,d?"":JSON.stringify(e)])}function U(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var L={missing:[],complete:!1};function Se(e){const t=E(),r=e.schema!=null,n=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",d=JSON.stringify(e.initialValues??null),c=(0,s.useMemo)(()=>r?M.createFormCollector(e):null,[r,e.name,n,l,d,e.autoSubmit]),[p,u]=(0,s.useState)({collector:null,loading:!r,error:null});(0,s.useEffect)(()=>{if(r)return;let g=!1;return u({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(f=>{g||u({collector:f,loading:!1,error:null})}).catch(f=>{g||u({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{g=!0}},[t,r,e.name,l,d,e.autoSubmit]);const b=r?c:p.collector,x=r?!1:p.loading,y=r?null:p.error;(0,s.useEffect)(()=>{if(b)return b.install(t)},[t,b]);const h=(0,s.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[d]),m=U(b?.store??h),C=(0,s.useMemo)(()=>b?.getStatus()??L,[m,b]),v=(0,s.useMemo)(()=>({...m,...C}),[m,C]),i=(0,s.useMemo)(()=>({name:e.name,store:h,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>h.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>L}),[e.name,h]);return{...b??i,state:v,loading:x,error:y}}exports.AgoProvider=Y;exports.ChatInput=O;exports.ChatWidget=xe;exports.Markdown=q;exports.Message=$;exports.createFormCollector=M.createFormCollector;exports.createMockClient=G.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=H;exports.useAgoAutoContinueAfterNavigation=Ce;exports.useAgoClient=E;exports.useAgoContext=we;exports.useAgoFunction=he;exports.useAgoNavigation=ye;exports.useAgoPageState=be;exports.useAgoStore=U;exports.useChat=me;exports.useConversation=B;exports.useFormCollector=Se;exports.useMessages=z;exports.useOptionalAgoClient=R;
7
+ `})]}),$=({message:e,className:t="",showAgentName:r=!1,isLast:n=!1,onFollowUpClick:a})=>{const l=e.role==="user",d=e.status==="IN_PROGRESS";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&r&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((c,p)=>(0,o.jsx)(ge,{source:c,index:p},c.id))}),e.attachments&&e.attachments.length>0&&(0,o.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:l?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(c=>(0,o.jsx)(fe,{attachment:c,isUser:l},c.id))}),(e.content||d)&&(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(q,{content:e.content}):d&&(0,o.jsx)(pe,{})}),n&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:f=>{f.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:f=>{f.currentTarget.style.borderColor="#dee3e8"},children:c},p))})]})},xe=({client:e,conversationId:t,title:r="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:d=500,logoUrl:c,showAgentName:p=!1,forms:f,onFollowUpClick:v,className:x="",onMessageSent:y,onMessageReceived:h})=>{const m=(0,s.useRef)(null),C=F(),w=e??C,{messages:i,isLoading:g,error:u,sendMessage:b}=z({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!w||!f||f.length===0)return;let S=!1;const E=[];return Promise.all(f.map(j=>j.schema!=null?Promise.resolve(M.createFormCollector(j)):M.loadFormCollector(w,j))).then(j=>{if(!S)for(const J of j)E.push(J.install(w))}).catch(()=>{}),()=>{S=!0,E.forEach(j=>j())}},[w,f?JSON.stringify(f.map(S=>[S.name,S.schema??null,S.submit??!1,S.description??null])):""]),(0,s.useEffect)(()=>{m.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,s.useEffect)(()=>{const S=i[i.length-1];S&&S.role==="assistant"&&S.status==="DONE"&&h&&h({id:S.id,content:S.content})},[i,h]);const k=async(S,E)=>{y?.(S),await b(S,E)},P=i[i.length-1],K=g&&P?.role==="assistant"&&P.status==="IN_PROGRESS",G=v===!1?void 0:v??(S=>k(S));return(0,o.jsxs)("div",{className:`ago-chat-widget ${x}`,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[c&&(0,o.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:r})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[i.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:n}):i.map((S,E)=>(0,o.jsx)($,{message:S,showAgentName:p,isLast:E===i.length-1,onFollowUpClick:G},S.id)),u&&(0,o.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:u.message}),(0,o.jsx)("div",{ref:m})]}),(0,o.jsx)(H,{onSend:k,disabled:K,placeholder:a,allowFiles:l})]})};function B({client:e,autoLoad:t=!0}={}){const r=F(),n=e||r;if(!n)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[p,f]=(0,s.useState)(!1),[v,x]=(0,s.useState)(null),y=(0,s.useCallback)(async()=>{f(!0),x(null);try{l(await n.getConversations())}catch(C){x(C instanceof Error?C:new Error("Failed to load conversations"))}finally{f(!1)}},[n]),h=(0,s.useCallback)(async C=>{f(!0),x(null);try{c(await n.getConversation(C))}catch(w){x(w instanceof Error?w:new Error("Failed to load conversation"))}finally{f(!1)}},[n]),m=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&y()},[t,y]),{conversations:a,currentConversation:d,isLoading:p,error:v,selectConversation:h,startNewConversation:m,refreshConversations:y}}function me(e={}){const t=F(),r=e.client||t;if(!r)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const n=z({client:r,conversationId:e.conversationId}),a=B({client:r,autoLoad:e.autoLoad});return{messages:n.messages,isLoading:n.isLoading,error:n.error||a.error,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function he(e,t){const r=I(),{name:n,description:a,parameters:l,handler:d}=typeof e=="string"?{name:e,...t}:e,c=(0,s.useRef)(d);c.current=d,(0,s.useEffect)(()=>{const p=f=>c.current(f);return r.registerFunction(n,p,{description:a,parameters:l}),()=>{r.unregisterFunction(n)}},[r,n,a,l])}function ye(e,t){const r=I(),n=(0,s.useRef)(e);n.current=e,(0,s.useEffect)(()=>(r.registerNavigationFunction(a=>n.current(a),t),()=>{r.unregisterNavigationFunction()}),[r,t])}function be(e,t){const r=I(),n=t?.functionName??"setPageState",a=(0,s.useRef)(e);a.current=e,(0,s.useEffect)(()=>{const l=a.current.map(d=>{const c=()=>a.current.find(p=>p.name===d.name)??d;return{name:d.name,description:d.description,schema:d.schema,get:d.get?()=>c().get?.():void 0,set:p=>c().set(p)}});return r.registerPageStateFunction(l,{functionName:n}),()=>{r.unregisterPageStateFunction(n)}},[r,n])}var ve="You have navigated the user to a new page. That page now exposes its editable state through the available setPageState function, and its current values in the page context. If the user's latest request also asked to change something on this page, call setPageState now to apply exactly those changes and nothing else. Otherwise, reply with a short confirmation only.";function W(e){return{navigationFunctions:e?.navigationFunctions??["navigateToPage"],pageStateFunctionName:e?.pageStateFunctionName??"setPageState",continuationPrompt:e?.continuationPrompt??ve,maxDepth:e?.maxDepth??1,readinessTimeoutMs:e?.readinessTimeoutMs??4e3,settleMs:e?.settleMs??150,enabled:e?.enabled??!0}}function we(e){const t=I(),r=(0,s.useRef)(W(e));r.current=W(e),(0,s.useEffect)(()=>{const n={navigated:!1,depth:0,runId:0,ourSendPending:!1},a=()=>t.getRegisteredFunctions().some(x=>x.name===r.current.pageStateFunctionName),l=x=>new Promise(y=>{let h=!1;const m=g=>{h||(h=!0,clearTimeout(i),t.off("context:changed",w),y(g))},C=()=>setTimeout(()=>m(x===n.runId&&a()),r.current.settleMs),w=()=>{if(x!==n.runId)return m(!1);a()&&(t.off("context:changed",w),C())},i=setTimeout(()=>m(!1),r.current.readinessTimeoutMs);a()?C():t.on("context:changed",w)}),d=async x=>{const y=++n.runId;if(!(!await l(y)||y!==n.runId)){n.depth+=1,n.ourSendPending=!0;try{await t.sendMessage(r.current.continuationPrompt,{conversationId:x,hidden:!0})}catch{n.ourSendPending=!1}}},c=x=>{r.current.navigationFunctions.includes(x.functionName)&&(n.navigated=!0)},p=()=>{n.ourSendPending||(n.depth=0,n.runId+=1)},f=x=>{n.ourSendPending=!1;const y=n.navigated;n.navigated=!1,r.current.enabled&&y&&(n.depth>=r.current.maxDepth||d(x.conversationId))},v=()=>{n.ourSendPending=!1};return t.on("function:invoke",c),t.on("message:start",p),t.on("message:complete",f),t.on("message:error",v),()=>{n.runId+=1,t.off("function:invoke",c),t.off("message:start",p),t.off("message:complete",f),t.off("message:error",v)}},[t])}function Ce(e,t){const r=I(),n=(0,s.useId)(),a=t??n,l=(0,s.useRef)(e);l.current=e;const d=typeof e=="function";(0,s.useEffect)(()=>{if(typeof l.current=="function"){const c=()=>l.current();return r.addDynamicContext(a,c),()=>{r.removeDynamicContext(a)}}return r.setContext(a,l.current),()=>{r.removeContext(a)}},[r,a,d,d?"":JSON.stringify(e)])}function U(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var L={missing:[],complete:!1};function Se(e){const t=I(),r=e.schema!=null,n=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",d=JSON.stringify(e.initialValues??null),c=(0,s.useMemo)(()=>r?M.createFormCollector(e):null,[r,e.name,n,l,d,e.autoSubmit]),[p,f]=(0,s.useState)({collector:null,loading:!r,error:null});(0,s.useEffect)(()=>{if(r)return;let g=!1;return f({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(u=>{g||f({collector:u,loading:!1,error:null})}).catch(u=>{g||f({collector:null,loading:!1,error:u instanceof Error?u:new Error(String(u))})}),()=>{g=!0}},[t,r,e.name,l,d,e.autoSubmit]);const v=r?c:p.collector,x=r?!1:p.loading,y=r?null:p.error;(0,s.useEffect)(()=>{if(v)return v.install(t)},[t,v]);const h=(0,s.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[d]),m=U(v?.store??h),C=(0,s.useMemo)(()=>v?.getStatus()??L,[m,v]),w=(0,s.useMemo)(()=>({...m,...C}),[m,C]),i=(0,s.useMemo)(()=>({name:e.name,store:h,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>h.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>L}),[e.name,h]);return{...v??i,state:w,loading:x,error:y}}exports.AgoProvider=Y;exports.ChatInput=H;exports.ChatWidget=xe;exports.Markdown=q;exports.Message=$;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=O;exports.useAgoAutoContinueAfterNavigation=we;exports.useAgoClient=I;exports.useAgoContext=Ce;exports.useAgoFunction=he;exports.useAgoNavigation=ye;exports.useAgoPageState=be;exports.useAgoStore=U;exports.useChat=me;exports.useConversation=B;exports.useFormCollector=Se;exports.useMessages=z;exports.useOptionalAgoClient=F;
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as j, i as G, o as V, s as Y, t as X } from "./AgoClient-BdtuHX7k.js";
1
+ import { a as J, i as j, o as V, s as Y, t as X } from "./AgoClient-BdtuHX7k.js";
2
2
  import { i as Q, n as Ne, r as H, t as O } from "./createFormCollector-B4n0_diV.js";
3
3
  import { t as _e } from "./createMockClient-d-arlmCq.js";
4
4
  import Z, { createContext as ee, useCallback as R, useContext as $, useEffect as C, useId as te, useMemo as N, useRef as A, useState as I, useSyncExternalStore as ne } from "react";
@@ -48,11 +48,11 @@ var z = ee(null), He = ({ children: e, client: t, tools: r, helpers: n, pageCont
48
48
  }, [l, r]), C(() => {
49
49
  if (!n) return;
50
50
  const g = [];
51
- return import("./functions-CApuQZ2b.js").then((d) => d.n).then((d) => {
52
- for (const [y, p] of Object.entries(n)) {
53
- const x = d[y];
51
+ return import("./functions-CApuQZ2b.js").then((u) => u.n).then((u) => {
52
+ for (const [b, p] of Object.entries(n)) {
53
+ const x = u[b];
54
54
  if (!x) {
55
- console.warn(`[AGO] Unknown helper: "${y}"`);
55
+ console.warn(`[AGO] Unknown helper: "${b}"`);
56
56
  continue;
57
57
  }
58
58
  const h = p === !0 ? x : {
@@ -62,7 +62,7 @@ var z = ee(null), He = ({ children: e, client: t, tools: r, helpers: n, pageCont
62
62
  l.register(h), g.push(h.name);
63
63
  }
64
64
  }), () => {
65
- for (const d of g) l.unregisterFunction(d);
65
+ for (const u of g) l.unregisterFunction(u);
66
66
  };
67
67
  }, [l, n]), C(() => {
68
68
  o === "auto" && l.enableAutoPageContext();
@@ -82,7 +82,7 @@ function D() {
82
82
  function U({ client: e, conversationId: t } = {}) {
83
83
  const r = D(), n = e || r;
84
84
  if (!n) throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
85
- const [o, i] = I([]), [c, l] = I(t), [g, d] = I(!1), [y, p] = I(null);
85
+ const [o, i] = I([]), [c, l] = I(t), [g, u] = I(!1), [b, p] = I(null);
86
86
  C(() => {
87
87
  t && t !== c && (l(t), x(t));
88
88
  }, [t]);
@@ -95,61 +95,68 @@ function U({ client: e, conversationId: t } = {}) {
95
95
  };
96
96
  return C(() => {
97
97
  const h = (f) => {
98
- c || l(f.conversationId);
98
+ c || l(f.conversationId), u(!0), i((d) => d.some((y) => y.role === "assistant" && y.status === "IN_PROGRESS") ? d : [...d, {
99
+ id: f.messageId,
100
+ conversationId: f.conversationId,
101
+ content: "",
102
+ role: "assistant",
103
+ status: "IN_PROGRESS",
104
+ createdAt: /* @__PURE__ */ new Date()
105
+ }]);
99
106
  }, m = (f) => {
100
- i((u) => {
101
- const w = u[u.length - 1];
102
- return w && w.id === f.messageId ? [...u.slice(0, -1), {
103
- ...w,
104
- content: w.content + f.content
105
- }] : u;
107
+ i((d) => {
108
+ const y = d[d.length - 1];
109
+ return y && y.id === f.messageId ? [...d.slice(0, -1), {
110
+ ...y,
111
+ content: y.content + f.content
112
+ }] : d;
106
113
  });
107
- }, v = (f) => {
108
- i((u) => {
109
- let w = -1;
110
- for (let k = u.length - 1; k >= 0; k--) if (u[k].role === "assistant" && u[k].status === "IN_PROGRESS") {
111
- w = k;
114
+ }, w = (f) => {
115
+ i((d) => {
116
+ let y = -1;
117
+ for (let k = d.length - 1; k >= 0; k--) if (d[k].role === "assistant" && d[k].status === "IN_PROGRESS") {
118
+ y = k;
112
119
  break;
113
120
  }
114
- return w < 0 ? u : [
115
- ...u.slice(0, w),
121
+ return y < 0 ? d : [
122
+ ...d.slice(0, y),
116
123
  {
117
- ...u[w],
124
+ ...d[y],
118
125
  ...f
119
126
  },
120
- ...u.slice(w + 1)
127
+ ...d.slice(y + 1)
121
128
  ];
122
129
  });
123
- }, b = (f) => {
124
- i((u) => {
125
- const w = u.findIndex((k) => k.id === f.id);
126
- return w >= 0 ? [
127
- ...u.slice(0, w),
130
+ }, v = (f) => {
131
+ i((d) => {
132
+ const y = d.findIndex((k) => k.id === f.id);
133
+ return y >= 0 ? [
134
+ ...d.slice(0, y),
128
135
  f,
129
- ...u.slice(w + 1)
130
- ] : [...u, f];
131
- }), d(!1);
136
+ ...d.slice(y + 1)
137
+ ] : [...d, f];
138
+ }), u(!1);
132
139
  }, a = (f) => {
133
- p(new Error(f.error)), d(!1);
140
+ p(new Error(f.error)), u(!1);
134
141
  };
135
- return n.on("message:start", h), n.on("message:chunk", m), n.on("message:answer-complete", v), n.on("message:complete", b), n.on("message:error", a), () => {
136
- n.off("message:start", h), n.off("message:chunk", m), n.off("message:answer-complete", v), n.off("message:complete", b), n.off("message:error", a);
142
+ return n.on("message:start", h), n.on("message:chunk", m), n.on("message:answer-complete", w), n.on("message:complete", v), n.on("message:error", a), () => {
143
+ n.off("message:start", h), n.off("message:chunk", m), n.off("message:answer-complete", w), n.off("message:complete", v), n.off("message:error", a);
137
144
  };
138
145
  }, [n, c]), {
139
146
  messages: o,
140
147
  isLoading: g,
141
- error: y,
148
+ error: b,
142
149
  sendMessage: R(async (h, m) => {
143
- d(!0), p(null);
144
- const v = {
150
+ u(!0), p(null);
151
+ const w = {
145
152
  id: `temp-${Date.now()}`,
146
153
  conversationId: c || "",
147
154
  content: h,
148
155
  role: "user",
149
156
  status: "DONE",
150
- attachments: m && m.length > 0 ? G(m) : void 0,
157
+ attachments: m && m.length > 0 ? j(m) : void 0,
151
158
  createdAt: /* @__PURE__ */ new Date()
152
- }, b = {
159
+ }, v = {
153
160
  id: `temp-assistant-${Date.now()}`,
154
161
  conversationId: c || "",
155
162
  content: "",
@@ -159,8 +166,8 @@ function U({ client: e, conversationId: t } = {}) {
159
166
  };
160
167
  i((a) => [
161
168
  ...a,
162
- v,
163
- b
169
+ w,
170
+ v
164
171
  ]);
165
172
  try {
166
173
  const a = await n.sendMessage(h, {
@@ -168,19 +175,19 @@ function U({ client: e, conversationId: t } = {}) {
168
175
  files: m
169
176
  });
170
177
  return a.conversationId && !c && l(a.conversationId), i((f) => {
171
- const u = f.filter((k) => !k.id.startsWith("temp-")), w = {
172
- ...v,
173
- id: v.id.replace("temp-", "user-"),
178
+ const d = f.filter((k) => !k.id.startsWith("temp-")), y = {
179
+ ...w,
180
+ id: w.id.replace("temp-", "user-"),
174
181
  conversationId: a.conversationId
175
182
  };
176
- return u.some((k) => k.id === a.id) ? [...u, w].sort((k, _) => new Date(k.createdAt).getTime() - new Date(_.createdAt).getTime()) : [
177
- ...u,
178
- w,
183
+ return d.some((k) => k.id === a.id) ? [...d, y].sort((k, _) => new Date(k.createdAt).getTime() - new Date(_.createdAt).getTime()) : [
184
+ ...d,
185
+ y,
179
186
  a
180
187
  ];
181
188
  }), a;
182
189
  } catch (a) {
183
- return p(a instanceof Error ? a : /* @__PURE__ */ new Error("Failed to send message")), d(!1), i((f) => f.filter((u) => !u.id.startsWith("temp-"))), null;
190
+ return p(a instanceof Error ? a : /* @__PURE__ */ new Error("Failed to send message")), u(!1), i((f) => f.filter((d) => !d.id.startsWith("temp-"))), null;
184
191
  }
185
192
  }, [n, c]),
186
193
  clearMessages: R(() => {
@@ -190,8 +197,8 @@ function U({ client: e, conversationId: t } = {}) {
190
197
  };
191
198
  }
192
199
  var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", allowFiles: n = !1, className: o = "" }) => {
193
- const [i, c] = I(""), [l, g] = I([]), d = A(null), y = A(null), p = R(() => {
194
- const a = y.current;
200
+ const [i, c] = I(""), [l, g] = I([]), u = A(null), b = A(null), p = R(() => {
201
+ const a = b.current;
195
202
  if (!a) return;
196
203
  const f = 110;
197
204
  a.style.height = "auto", a.style.height = `${Math.min(a.scrollHeight + 2, f)}px`, a.style.overflowY = a.scrollHeight + 2 > f ? "auto" : "hidden";
@@ -206,10 +213,10 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
206
213
  a.key === "Enter" && !a.shiftKey && (a.preventDefault(), x(a));
207
214
  }, [x]), m = R((a) => {
208
215
  const f = Array.from(a.target.files || []);
209
- g((u) => [...u, ...f]);
210
- }, []), v = R((a) => {
211
- g((f) => f.filter((u, w) => w !== a));
212
- }, []), b = i.trim() || l.length > 0;
216
+ g((d) => [...d, ...f]);
217
+ }, []), w = R((a) => {
218
+ g((f) => f.filter((d, y) => y !== a));
219
+ }, []), v = i.trim() || l.length > 0;
213
220
  return /* @__PURE__ */ M("form", {
214
221
  onSubmit: x,
215
222
  className: `ago-chat-input ${o}`,
@@ -249,7 +256,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
249
256
  children: a.name
250
257
  }), /* @__PURE__ */ s("button", {
251
258
  type: "button",
252
- onClick: () => v(f),
259
+ onClick: () => w(f),
253
260
  "aria-label": `Remove ${a.name}`,
254
261
  style: {
255
262
  border: "none",
@@ -272,7 +279,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
272
279
  children: [
273
280
  n && /* @__PURE__ */ M(B, { children: [/* @__PURE__ */ s("button", {
274
281
  type: "button",
275
- onClick: () => d.current?.click(),
282
+ onClick: () => u.current?.click(),
276
283
  disabled: t,
277
284
  "aria-label": "Attach file",
278
285
  style: {
@@ -287,14 +294,14 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
287
294
  },
288
295
  children: "+"
289
296
  }), /* @__PURE__ */ s("input", {
290
- ref: d,
297
+ ref: u,
291
298
  type: "file",
292
299
  multiple: !0,
293
300
  onChange: m,
294
301
  style: { display: "none" }
295
302
  })] }),
296
303
  /* @__PURE__ */ s("textarea", {
297
- ref: y,
304
+ ref: b,
298
305
  value: i,
299
306
  onChange: (a) => {
300
307
  c(a.target.value), p();
@@ -330,14 +337,14 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
330
337
  }),
331
338
  /* @__PURE__ */ s("button", {
332
339
  type: "submit",
333
- disabled: t || !b,
340
+ disabled: t || !v,
334
341
  style: {
335
342
  padding: "10px 18px",
336
343
  border: "none",
337
344
  borderRadius: "20px",
338
- backgroundColor: t || !b ? "#b5bfc8" : "#03182f",
345
+ backgroundColor: t || !v ? "#b5bfc8" : "#03182f",
339
346
  color: "#fff",
340
- cursor: t || !b ? "not-allowed" : "pointer",
347
+ cursor: t || !v ? "not-allowed" : "pointer",
341
348
  fontWeight: 500,
342
349
  fontSize: "16px",
343
350
  transition: "background-color 0.15s"
@@ -364,7 +371,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
364
371
  },
365
372
  ...t,
366
373
  children: e
367
- }), P = (e, t) => {
374
+ }), F = (e, t) => {
368
375
  const r = ({ children: n, ...o }) => Z.createElement(`h${e}`, {
369
376
  style: {
370
377
  margin: "16px 0 8px 0",
@@ -487,12 +494,12 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
487
494
  }), ve = {
488
495
  a: ie,
489
496
  p: le,
490
- h1: P(1, "20px"),
491
- h2: P(2, "18px"),
492
- h3: P(3, "16px"),
493
- h4: P(4, "15px"),
494
- h5: P(5, "14px"),
495
- h6: P(6, "13px"),
497
+ h1: F(1, "20px"),
498
+ h2: F(2, "18px"),
499
+ h3: F(3, "16px"),
500
+ h4: F(4, "15px"),
501
+ h5: F(5, "14px"),
502
+ h6: F(6, "13px"),
496
503
  ul: ce,
497
504
  ol: de,
498
505
  li: ue,
@@ -510,7 +517,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
510
517
  children: e
511
518
  }), Ce = ({ attachment: e, isUser: t }) => {
512
519
  const r = Y(e.url);
513
- if (j(e)) return /* @__PURE__ */ s("a", {
520
+ if (J(e)) return /* @__PURE__ */ s("a", {
514
521
  href: r,
515
522
  target: "_blank",
516
523
  rel: "noopener noreferrer",
@@ -766,34 +773,34 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
766
773
  cursor: o ? "pointer" : "default",
767
774
  transition: "border-color 0.15s"
768
775
  },
769
- onMouseEnter: (d) => {
770
- d.currentTarget.style.borderColor = "#1b5fc4";
776
+ onMouseEnter: (u) => {
777
+ u.currentTarget.style.borderColor = "#1b5fc4";
771
778
  },
772
- onMouseLeave: (d) => {
773
- d.currentTarget.style.borderColor = "#dee3e8";
779
+ onMouseLeave: (u) => {
780
+ u.currentTarget.style.borderColor = "#dee3e8";
774
781
  },
775
782
  children: l
776
783
  }, g))
777
784
  })
778
785
  ]
779
786
  });
780
- }, Oe = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: i = !1, height: c = 500, logoUrl: l, showAgentName: g = !1, forms: d, onFollowUpClick: y, className: p = "", onMessageSent: x, onMessageReceived: h }) => {
781
- const m = A(null), v = D(), b = e ?? v, { messages: a, isLoading: f, error: u, sendMessage: w } = U({
787
+ }, Oe = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: i = !1, height: c = 500, logoUrl: l, showAgentName: g = !1, forms: u, onFollowUpClick: b, className: p = "", onMessageSent: x, onMessageReceived: h }) => {
788
+ const m = A(null), w = D(), v = e ?? w, { messages: a, isLoading: f, error: d, sendMessage: y } = U({
782
789
  client: e,
783
790
  conversationId: t
784
791
  });
785
792
  C(() => {
786
- if (!b || !d || d.length === 0) return;
793
+ if (!v || !u || u.length === 0) return;
787
794
  let S = !1;
788
- const F = [];
789
- return Promise.all(d.map((E) => E.schema != null ? Promise.resolve(O(E)) : H(b, E))).then((E) => {
795
+ const P = [];
796
+ return Promise.all(u.map((E) => E.schema != null ? Promise.resolve(O(E)) : H(v, E))).then((E) => {
790
797
  if (!S)
791
- for (const J of E) F.push(J.install(b));
798
+ for (const G of E) P.push(G.install(v));
792
799
  }).catch(() => {
793
800
  }), () => {
794
- S = !0, F.forEach((E) => E());
801
+ S = !0, P.forEach((E) => E());
795
802
  };
796
- }, [b, d ? JSON.stringify(d.map((S) => [
803
+ }, [v, u ? JSON.stringify(u.map((S) => [
797
804
  S.name,
798
805
  S.schema ?? null,
799
806
  S.submit ?? !1,
@@ -807,9 +814,9 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
807
814
  content: S.content
808
815
  });
809
816
  }, [a, h]);
810
- const k = async (S, F) => {
811
- x?.(S), await w(S, F);
812
- }, _ = a[a.length - 1], K = f && _?.role === "assistant" && _.status === "IN_PROGRESS", q = y === !1 ? void 0 : y ?? ((S) => k(S));
817
+ const k = async (S, P) => {
818
+ x?.(S), await y(S, P);
819
+ }, _ = a[a.length - 1], K = f && _?.role === "assistant" && _.status === "IN_PROGRESS", q = b === !1 ? void 0 : b ?? ((S) => k(S));
813
820
  return /* @__PURE__ */ M("div", {
814
821
  className: `ago-chat-widget ${p}`,
815
822
  style: {
@@ -874,13 +881,13 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
874
881
  lineHeight: "1.5"
875
882
  },
876
883
  children: n
877
- }) : a.map((S, F) => /* @__PURE__ */ s(Me, {
884
+ }) : a.map((S, P) => /* @__PURE__ */ s(Me, {
878
885
  message: S,
879
886
  showAgentName: g,
880
- isLast: F === a.length - 1,
887
+ isLast: P === a.length - 1,
881
888
  onFollowUpClick: q
882
889
  }, S.id)),
883
- u && /* @__PURE__ */ s("div", {
890
+ d && /* @__PURE__ */ s("div", {
884
891
  role: "alert",
885
892
  style: {
886
893
  padding: "10px 14px",
@@ -891,7 +898,7 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
891
898
  fontSize: "13px",
892
899
  border: "1px solid #fecaca"
893
900
  },
894
- children: u.message
901
+ children: d.message
895
902
  }),
896
903
  /* @__PURE__ */ s("div", { ref: m })
897
904
  ]
@@ -908,23 +915,23 @@ var se = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
908
915
  function Re({ client: e, autoLoad: t = !0 } = {}) {
909
916
  const r = D(), n = e || r;
910
917
  if (!n) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
911
- const [o, i] = I([]), [c, l] = I(null), [g, d] = I(!1), [y, p] = I(null), x = R(async () => {
912
- d(!0), p(null);
918
+ const [o, i] = I([]), [c, l] = I(null), [g, u] = I(!1), [b, p] = I(null), x = R(async () => {
919
+ u(!0), p(null);
913
920
  try {
914
921
  i(await n.getConversations());
915
- } catch (v) {
916
- p(v instanceof Error ? v : /* @__PURE__ */ new Error("Failed to load conversations"));
922
+ } catch (w) {
923
+ p(w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to load conversations"));
917
924
  } finally {
918
- d(!1);
925
+ u(!1);
919
926
  }
920
- }, [n]), h = R(async (v) => {
921
- d(!0), p(null);
927
+ }, [n]), h = R(async (w) => {
928
+ u(!0), p(null);
922
929
  try {
923
- l(await n.getConversation(v));
924
- } catch (b) {
925
- p(b instanceof Error ? b : /* @__PURE__ */ new Error("Failed to load conversation"));
930
+ l(await n.getConversation(w));
931
+ } catch (v) {
932
+ p(v instanceof Error ? v : /* @__PURE__ */ new Error("Failed to load conversation"));
926
933
  } finally {
927
- d(!1);
934
+ u(!1);
928
935
  }
929
936
  }, [n]), m = R(() => {
930
937
  l(null);
@@ -935,7 +942,7 @@ function Re({ client: e, autoLoad: t = !0 } = {}) {
935
942
  conversations: o,
936
943
  currentConversation: c,
937
944
  isLoading: g,
938
- error: y,
945
+ error: b,
939
946
  selectConversation: h,
940
947
  startNewConversation: m,
941
948
  refreshConversations: x
@@ -972,7 +979,7 @@ function Be(e, t) {
972
979
  ...t
973
980
  } : e, l = A(c);
974
981
  l.current = c, C(() => {
975
- const g = (d) => l.current(d);
982
+ const g = (u) => l.current(u);
976
983
  return r.registerFunction(n, g, {
977
984
  description: o,
978
985
  parameters: i
@@ -1033,12 +1040,12 @@ function qe(e) {
1033
1040
  }, o = () => t.getRegisteredFunctions().some((p) => p.name === r.current.pageStateFunctionName), i = (p) => new Promise((x) => {
1034
1041
  let h = !1;
1035
1042
  const m = (f) => {
1036
- h || (h = !0, clearTimeout(a), t.off("context:changed", b), x(f));
1037
- }, v = () => setTimeout(() => m(p === n.runId && o()), r.current.settleMs), b = () => {
1043
+ h || (h = !0, clearTimeout(a), t.off("context:changed", v), x(f));
1044
+ }, w = () => setTimeout(() => m(p === n.runId && o()), r.current.settleMs), v = () => {
1038
1045
  if (p !== n.runId) return m(!1);
1039
- o() && (t.off("context:changed", b), v());
1046
+ o() && (t.off("context:changed", v), w());
1040
1047
  }, a = setTimeout(() => m(!1), r.current.readinessTimeoutMs);
1041
- o() ? v() : t.on("context:changed", b);
1048
+ o() ? w() : t.on("context:changed", v);
1042
1049
  }), c = async (p) => {
1043
1050
  const x = ++n.runId;
1044
1051
  if (!(!await i(x) || x !== n.runId)) {
@@ -1056,19 +1063,19 @@ function qe(e) {
1056
1063
  r.current.navigationFunctions.includes(p.functionName) && (n.navigated = !0);
1057
1064
  }, g = () => {
1058
1065
  n.ourSendPending || (n.depth = 0, n.runId += 1);
1059
- }, d = (p) => {
1066
+ }, u = (p) => {
1060
1067
  n.ourSendPending = !1;
1061
1068
  const x = n.navigated;
1062
1069
  n.navigated = !1, r.current.enabled && x && (n.depth >= r.current.maxDepth || c(p.conversationId));
1063
- }, y = () => {
1070
+ }, b = () => {
1064
1071
  n.ourSendPending = !1;
1065
1072
  };
1066
- return t.on("function:invoke", l), t.on("message:start", g), t.on("message:complete", d), t.on("message:error", y), () => {
1067
- n.runId += 1, t.off("function:invoke", l), t.off("message:start", g), t.off("message:complete", d), t.off("message:error", y);
1073
+ return t.on("function:invoke", l), t.on("message:start", g), t.on("message:complete", u), t.on("message:error", b), () => {
1074
+ n.runId += 1, t.off("function:invoke", l), t.off("message:start", g), t.off("message:complete", u), t.off("message:error", b);
1068
1075
  };
1069
1076
  }, [t]);
1070
1077
  }
1071
- function Je(e, t) {
1078
+ function Ge(e, t) {
1072
1079
  const r = T(), n = te(), o = t ?? n, i = A(e);
1073
1080
  i.current = e;
1074
1081
  const c = typeof e == "function";
@@ -1096,7 +1103,7 @@ var W = {
1096
1103
  missing: [],
1097
1104
  complete: !1
1098
1105
  };
1099
- function je(e) {
1106
+ function Je(e) {
1100
1107
  const t = T(), r = e.schema != null, n = JSON.stringify(e.schema ?? null), o = e.submit, i = o ? typeof o == "string" ? `client:${o}` : o.via === "backend" ? "backend" : "handler" in o ? "client:handler" : `client:${o.url}` : "none", c = JSON.stringify(e.initialValues ?? null), l = N(() => r ? O(e) : null, [
1101
1108
  r,
1102
1109
  e.name,
@@ -1104,7 +1111,7 @@ function je(e) {
1104
1111
  i,
1105
1112
  c,
1106
1113
  e.autoSubmit
1107
- ]), [g, d] = I({
1114
+ ]), [g, u] = I({
1108
1115
  collector: null,
1109
1116
  loading: !r,
1110
1117
  error: null
@@ -1112,21 +1119,21 @@ function je(e) {
1112
1119
  C(() => {
1113
1120
  if (r) return;
1114
1121
  let f = !1;
1115
- return d({
1122
+ return u({
1116
1123
  collector: null,
1117
1124
  loading: !0,
1118
1125
  error: null
1119
- }), H(t, e).then((u) => {
1120
- f || d({
1121
- collector: u,
1126
+ }), H(t, e).then((d) => {
1127
+ f || u({
1128
+ collector: d,
1122
1129
  loading: !1,
1123
1130
  error: null
1124
1131
  });
1125
- }).catch((u) => {
1126
- f || d({
1132
+ }).catch((d) => {
1133
+ f || u({
1127
1134
  collector: null,
1128
1135
  loading: !1,
1129
- error: u instanceof Error ? u : new Error(String(u))
1136
+ error: d instanceof Error ? d : new Error(String(d))
1130
1137
  });
1131
1138
  }), () => {
1132
1139
  f = !0;
@@ -1139,18 +1146,18 @@ function je(e) {
1139
1146
  c,
1140
1147
  e.autoSubmit
1141
1148
  ]);
1142
- const y = r ? l : g.collector, p = r ? !1 : g.loading, x = r ? null : g.error;
1149
+ const b = r ? l : g.collector, p = r ? !1 : g.loading, x = r ? null : g.error;
1143
1150
  C(() => {
1144
- if (y)
1145
- return y.install(t);
1146
- }, [t, y]);
1151
+ if (b)
1152
+ return b.install(t);
1153
+ }, [t, b]);
1147
1154
  const h = N(() => Q({
1148
1155
  values: e.initialValues ?? {},
1149
1156
  submitted: !1
1150
- }), [c]), m = Ee(y?.store ?? h), v = N(() => y?.getStatus() ?? W, [m, y]), b = N(() => ({
1157
+ }), [c]), m = Ee(b?.store ?? h), w = N(() => b?.getStatus() ?? W, [m, b]), v = N(() => ({
1151
1158
  ...m,
1152
- ...v
1153
- }), [m, v]), a = N(() => ({
1159
+ ...w
1160
+ }), [m, w]), a = N(() => ({
1154
1161
  name: e.name,
1155
1162
  store: h,
1156
1163
  functions: [],
@@ -1175,8 +1182,8 @@ function je(e) {
1175
1182
  getStatus: () => W
1176
1183
  }), [e.name, h]);
1177
1184
  return {
1178
- ...y ?? a,
1179
- state: b,
1185
+ ...b ?? a,
1186
+ state: v,
1180
1187
  loading: p,
1181
1188
  error: x
1182
1189
  };
@@ -1194,14 +1201,14 @@ export {
1194
1201
  ae as useAgo,
1195
1202
  qe as useAgoAutoContinueAfterNavigation,
1196
1203
  T as useAgoClient,
1197
- Je as useAgoContext,
1204
+ Ge as useAgoContext,
1198
1205
  Be as useAgoFunction,
1199
1206
  Ue as useAgoNavigation,
1200
1207
  Ke as useAgoPageState,
1201
1208
  Ee as useAgoStore,
1202
1209
  $e as useChat,
1203
1210
  Re as useConversation,
1204
- je as useFormCollector,
1211
+ Je as useFormCollector,
1205
1212
  U as useMessages,
1206
1213
  D as useOptionalAgoClient
1207
1214
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useago/sdk",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Create In-APP AI agents that answers question and performs actions. Works with React, Vue, Angular and vanilla JS/TS.",
5
5
  "type": "module",
6
6
  "sideEffects": false,