@useago/sdk 1.0.11 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.cjs CHANGED
@@ -1,7 +1,7 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),J=require("./AgoClient-B3-WGVne.cjs"),M=require("./createFormCollector-BI3DXaew.cjs"),V=require("./createMockClient-zHQ0cjUH.cjs");let n=require("react");n=P.__toESM(n,1);let s=require("react/jsx-runtime"),F=require("react-markdown");F=P.__toESM(F,1);let N=require("remark-gfm");N=P.__toESM(N,1);function D(e){const[t,o]=(0,n.useState)(!1),r=(0,n.useRef)(null),l=(0,n.useMemo)(()=>{if(r.current&&(r.current.destroy(),r.current=null),!e)return null;const i=new J.AgoClient(e);return r.current=i,i},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(o(!0),()=>{r.current?.destroy(),r.current=null}),[l]),(0,n.useEffect)(()=>{r.current&&e&&r.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:l,isReady:t}}var T=(0,n.createContext)(null),G=({children:e,client:t,tools:o,helpers:r,pageContext:l,...i})=>{const{client:f}=D(t?null:i),c=t||f;return(0,n.useEffect)(()=>{if(!(!o||o.length===0)){for(const p of o)c.register(p);return()=>{for(const p of o)c.unregisterFunction(p.name)}}},[c,o]),(0,n.useEffect)(()=>{if(!r)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(u=>u.functions_exports).then(u=>{for(const[b,m]of Object.entries(r)){const S=u[b];if(!S){console.warn(`[AGO] Unknown helper: "${b}"`);continue}const x=m===!0?S:{...S,handler:m};c.register(x),p.push(x.name)}}),()=>{for(const u of p)c.unregisterFunction(u)}},[c,r]),(0,n.useEffect)(()=>{l==="auto"&&c.enableAutoPageContext()},[c,l]),(0,s.jsx)(T.Provider,{value:c,children:e})};function R(){const e=(0,n.useContext)(T);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function A(){return(0,n.useContext)(T)}function L({client:e,conversationId:t}={}){const o=A(),r=e||o;if(!r)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[l,i]=(0,n.useState)([]),[f,c]=(0,n.useState)(t),[p,u]=(0,n.useState)(!1),[b,m]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&t!==f&&(c(t),S(t))},[t]);const S=async x=>{try{i(await r.getMessages(x))}catch(v){m(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const x=g=>{f||c(g.conversationId)},v=g=>{i(d=>{const h=d[d.length-1];return h&&h.id===g.messageId?[...d.slice(0,-1),{...h,content:h.content+g.content}]:d})},C=g=>{i(d=>{let h=-1;for(let k=d.length-1;k>=0;k--)if(d[k].role==="assistant"&&d[k].status==="IN_PROGRESS"){h=k;break}return h<0?d:[...d.slice(0,h),{...d[h],...g},...d.slice(h+1)]})},w=g=>{i(d=>{const h=d.findIndex(k=>k.id===g.id);return h>=0?[...d.slice(0,h),g,...d.slice(h+1)]:[...d,g]}),u(!1)},a=g=>{m(new Error(g.error)),u(!1)};return r.on("message:start",x),r.on("message:chunk",v),r.on("message:answer-complete",C),r.on("message:complete",w),r.on("message:error",a),()=>{r.off("message:start",x),r.off("message:chunk",v),r.off("message:answer-complete",C),r.off("message:complete",w),r.off("message:error",a)}},[r,f]),{messages:l,isLoading:p,error:b,sendMessage:(0,n.useCallback)(async(x,v)=>{u(!0),m(null);const C={id:`temp-${Date.now()}`,conversationId:f||"",content:x,role:"user",status:"DONE",createdAt:new Date},w={id:`temp-assistant-${Date.now()}`,conversationId:f||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};i(a=>[...a,C,w]);try{const a=await r.sendMessage(x,{conversationId:f,files:v});return a.conversationId&&!f&&c(a.conversationId),i(g=>{const d=g.filter(k=>!k.id.startsWith("temp-")),h={...C,id:C.id.replace("temp-","user-"),conversationId:a.conversationId};return d.some(k=>k.id===a.id)?[...d,h].sort((k,_)=>new Date(k.createdAt).getTime()-new Date(_.createdAt).getTime()):[...d,h,a]}),a}catch(a){return m(a instanceof Error?a:new Error("Failed to send message")),u(!1),i(g=>g.filter(d=>!d.id.startsWith("temp-"))),null}},[r,f]),clearMessages:(0,n.useCallback)(()=>{i([]),c(void 0),m(null)},[]),conversationId:f}}var H=({onSend:e,disabled:t=!1,placeholder:o="Type a message...",allowFiles:r=!1,className:l=""})=>{const[i,f]=(0,n.useState)(""),[c,p]=(0,n.useState)([]),u=(0,n.useRef)(null),b=(0,n.useRef)(null),m=(0,n.useCallback)(()=>{const a=b.current;if(!a)return;const g=110;a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight+2,g)}px`,a.style.overflowY=a.scrollHeight+2>g?"auto":"hidden"},[]),S=(0,n.useCallback)(a=>{a.preventDefault(),(i.trim()||c.length>0)&&(e(i.trim(),c.length>0?c:void 0),f(""),p([]),requestAnimationFrame(m))},[i,c,e,m]),x=(0,n.useCallback)(a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),S(a))},[S]),v=(0,n.useCallback)(a=>{const g=Array.from(a.target.files||[]);p(d=>[...d,...g])},[]),C=(0,n.useCallback)(a=>{p(g=>g.filter((d,h)=>h!==a))},[]),w=i.trim()||c.length>0;return(0,s.jsxs)("form",{onSubmit:S,className:`ago-chat-input ${l}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[c.length>0&&(0,s.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((a,g)=>(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,s.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),(0,s.jsx)("button",{type:"button",onClick:()=>C(g),"aria-label":`Remove ${a.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},g))}),(0,s.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.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,s.jsx)("input",{ref:u,type:"file",multiple:!0,onChange:v,style:{display:"none"}})]}),(0,s.jsx)("textarea",{ref:b,value:i,onChange:a=>{f(a.target.value),m()},onKeyDown:x,placeholder:o,"aria-label":o,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:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onBlur:a=>{a.currentTarget.style.borderColor="#dee3e8"}}),(0,s.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"})]})]})},Y=({href:e,children:t,...o})=>(0,s.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...o,children:t}),X=({children:e,...t})=>(0,s.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const o=({children:r,...l})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...l},r);return o.displayName=`MarkdownHeading${e}`,o},Q=({children:e,...t})=>(0,s.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,s.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,s.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...o})=>e!==void 0||String(t).includes(`
2
- `)?(0,s.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...o,children:t}):(0,s.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...o,children:t}),re=({children:e,...t})=>(0,s.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),ne=({children:e,...t})=>(0,s.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),oe=({children:e,...t})=>(0,s.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,s.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),se=({children:e,...t})=>(0,s.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ae=({children:e,...t})=>(0,s.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,s.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ie=e=>(0,s.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),ce={a:Y,p:X,h1:I(1,"20px"),h2:I(2,"18px"),h3:I(3,"16px"),h4:I(4,"15px"),h5:I(5,"14px"),h6:I(6,"13px"),ul:Q,ol:Z,li:ee,code:te,pre:re,blockquote:ne,table:oe,th:se,td:ae,img:le,hr:ie},de=[N.default],z=({content:e})=>(0,s.jsx)(F.default,{remarkPlugins:de,components:ce,children:e}),ue=({source:e,index:t})=>{const o=(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,s.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,s.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),r={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,s.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:r,onMouseEnter:l=>{l.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:l=>{l.currentTarget.style.borderColor="#dee3e8"},children:o}):(0,s.jsx)("div",{style:r,children:o})},fe=()=>(0,s.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,s.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,s.jsx)("style",{children:`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),R=require("./AgoClient-CzSmJQxl.cjs"),j=require("./createFormCollector-BB3Uscuo.cjs"),V=require("./createMockClient-zHQ0cjUH.cjs");let s=require("react");s=P.__toESM(s,1);let r=require("react/jsx-runtime"),N=require("react-markdown");N=P.__toESM(N,1);let z=require("remark-gfm");z=P.__toESM(z,1);function H(e){const[t,o]=(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 i=new R.AgoClient(e);return n.current=i,i},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(o(!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 T=(0,s.createContext)(null),G=({children:e,client:t,tools:o,helpers:n,pageContext:a,...i})=>{const{client:f}=H(t?null:i),c=t||f;return(0,s.useEffect)(()=>{if(!(!o||o.length===0)){for(const g of o)c.register(g);return()=>{for(const g of o)c.unregisterFunction(g.name)}}},[c,o]),(0,s.useEffect)(()=>{if(!n)return;const g=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(u=>u.functions_exports).then(u=>{for(const[v,m]of Object.entries(n)){const S=u[v];if(!S){console.warn(`[AGO] Unknown helper: "${v}"`);continue}const x=m===!0?S:{...S,handler:m};c.register(x),g.push(x.name)}}),()=>{for(const u of g)c.unregisterFunction(u)}},[c,n]),(0,s.useEffect)(()=>{a==="auto"&&c.enableAutoPageContext()},[c,a]),(0,r.jsx)(T.Provider,{value:c,children:e})};function A(){const e=(0,s.useContext)(T);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function _(){return(0,s.useContext)(T)}function W({client:e,conversationId:t}={}){const o=_(),n=e||o;if(!n)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,i]=(0,s.useState)([]),[f,c]=(0,s.useState)(t),[g,u]=(0,s.useState)(!1),[v,m]=(0,s.useState)(null);(0,s.useEffect)(()=>{t&&t!==f&&(c(t),S(t))},[t]);const S=async x=>{try{i(await n.getMessages(x))}catch(h){m(h instanceof Error?h:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const x=p=>{f||c(p.conversationId)},h=p=>{i(d=>{const y=d[d.length-1];return y&&y.id===p.messageId?[...d.slice(0,-1),{...y,content:y.content+p.content}]:d})},C=p=>{i(d=>{let y=-1;for(let k=d.length-1;k>=0;k--)if(d[k].role==="assistant"&&d[k].status==="IN_PROGRESS"){y=k;break}return y<0?d:[...d.slice(0,y),{...d[y],...p},...d.slice(y+1)]})},w=p=>{i(d=>{const y=d.findIndex(k=>k.id===p.id);return y>=0?[...d.slice(0,y),p,...d.slice(y+1)]:[...d,p]}),u(!1)},l=p=>{m(new Error(p.error)),u(!1)};return n.on("message:start",x),n.on("message:chunk",h),n.on("message:answer-complete",C),n.on("message:complete",w),n.on("message:error",l),()=>{n.off("message:start",x),n.off("message:chunk",h),n.off("message:answer-complete",C),n.off("message:complete",w),n.off("message:error",l)}},[n,f]),{messages:a,isLoading:g,error:v,sendMessage:(0,s.useCallback)(async(x,h)=>{u(!0),m(null);const C={id:`temp-${Date.now()}`,conversationId:f||"",content:x,role:"user",status:"DONE",attachments:h&&h.length>0?R.attachmentsFromFiles(h):void 0,createdAt:new Date},w={id:`temp-assistant-${Date.now()}`,conversationId:f||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};i(l=>[...l,C,w]);try{const l=await n.sendMessage(x,{conversationId:f,files:h});return l.conversationId&&!f&&c(l.conversationId),i(p=>{const d=p.filter(k=>!k.id.startsWith("temp-")),y={...C,id:C.id.replace("temp-","user-"),conversationId:l.conversationId};return d.some(k=>k.id===l.id)?[...d,y].sort((k,F)=>new Date(k.createdAt).getTime()-new Date(F.createdAt).getTime()):[...d,y,l]}),l}catch(l){return m(l instanceof Error?l:new Error("Failed to send message")),u(!1),i(p=>p.filter(d=>!d.id.startsWith("temp-"))),null}},[n,f]),clearMessages:(0,s.useCallback)(()=>{i([]),c(void 0),m(null)},[]),conversationId:f}}var L=({onSend:e,disabled:t=!1,placeholder:o="Type a message...",allowFiles:n=!1,className:a=""})=>{const[i,f]=(0,s.useState)(""),[c,g]=(0,s.useState)([]),u=(0,s.useRef)(null),v=(0,s.useRef)(null),m=(0,s.useCallback)(()=>{const l=v.current;if(!l)return;const p=110;l.style.height="auto",l.style.height=`${Math.min(l.scrollHeight+2,p)}px`,l.style.overflowY=l.scrollHeight+2>p?"auto":"hidden"},[]),S=(0,s.useCallback)(l=>{l.preventDefault(),(i.trim()||c.length>0)&&(e(i.trim(),c.length>0?c:void 0),f(""),g([]),requestAnimationFrame(m))},[i,c,e,m]),x=(0,s.useCallback)(l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),S(l))},[S]),h=(0,s.useCallback)(l=>{const p=Array.from(l.target.files||[]);g(d=>[...d,...p])},[]),C=(0,s.useCallback)(l=>{g(p=>p.filter((d,y)=>y!==l))},[]),w=i.trim()||c.length>0;return(0,r.jsxs)("form",{onSubmit:S,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,r.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((l,p)=>(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,r.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l.name}),(0,r.jsx)("button",{type:"button",onClick:()=>C(p),"aria-label":`Remove ${l.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},p))}),(0,r.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[n&&(0,r.jsxs)(r.Fragment,{children:[(0,r.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,r.jsx)("input",{ref:u,type:"file",multiple:!0,onChange:h,style:{display:"none"}})]}),(0,r.jsx)("textarea",{ref:v,value:i,onChange:l=>{f(l.target.value),m()},onKeyDown:x,placeholder:o,"aria-label":o,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:l=>{l.currentTarget.style.borderColor="#1b5fc4"},onBlur:l=>{l.currentTarget.style.borderColor="#dee3e8"}}),(0,r.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"})]})]})},Y=({href:e,children:t,...o})=>(0,r.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...o,children:t}),X=({children:e,...t})=>(0,r.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const o=({children:n,...a})=>s.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},n);return o.displayName=`MarkdownHeading${e}`,o},Q=({children:e,...t})=>(0,r.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,r.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,r.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...o})=>e!==void 0||String(t).includes(`
2
+ `)?(0,r.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...o,children:t}):(0,r.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...o,children:t}),re=({children:e,...t})=>(0,r.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),ne=({children:e,...t})=>(0,r.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),oe=({children:e,...t})=>(0,r.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,r.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),se=({children:e,...t})=>(0,r.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ae=({children:e,...t})=>(0,r.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,r.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ie=e=>(0,r.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),ce={a:Y,p:X,h1:I(1,"20px"),h2:I(2,"18px"),h3:I(3,"16px"),h4:I(4,"15px"),h5:I(5,"14px"),h6:I(6,"13px"),ul:Q,ol:Z,li:ee,code:te,pre:re,blockquote:ne,table:oe,th:se,td:ae,img:le,hr:ie},de=[z.default],q=({content:e})=>(0,r.jsx)(N.default,{remarkPlugins:de,components:ce,children:e}),ue=({attachment:e,isUser:t})=>{const o=R.safeAttachmentUrl(e.url);if(R.canInlineImage(e))return(0,r.jsx)("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,r.jsx)("img",{src:o,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,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,r.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,r.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),n&&(0,r.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:n})]})]}),i={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 o?(0,r.jsx)("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:i,children:a}):(0,r.jsx)("div",{style:i,children:a})},fe=({source:e,index:t})=>{const o=(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,r.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,r.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,r.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:o}):(0,r.jsx)("div",{style:n,children:o})},pe=()=>(0,r.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,r.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,r.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
- `})]}),W=({message:e,className:t="",showAgentName:o=!1,isLast:r=!1,onFollowUpClick:l})=>{const i=e.role==="user",f=e.status==="IN_PROGRESS";return(0,s.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&o&&e.agent&&(0,s.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}),!i&&e.sources&&e.sources.length>0&&(0,s.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,s.jsx)(ue,{source:c,index:p},c.id))}),(0,s.jsx)("div",{className:"ago-message__content",style:{maxWidth:i?"75%":"100%",padding:i?"10px 14px":"2px 8px",borderRadius:i?"16px":"0",backgroundColor:i?"#03182f":"transparent",color:i?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,s.jsx)(z,{content:e.content}):f&&(0,s.jsx)(fe,{})}),r&&e.followUpReplies&&e.followUpReplies.length>0&&(0,s.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,p)=>(0,s.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!l,onClick:l?()=>l(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:l?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:u=>{u.currentTarget.style.borderColor="#dee3e8"},children:c},p))})]})},ge=({client:e,conversationId:t,title:o="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:l="Type a message...",allowFiles:i=!1,height:f=500,logoUrl:c,showAgentName:p=!1,forms:u,onFollowUpClick:b,className:m="",onMessageSent:S,onMessageReceived:x})=>{const v=(0,n.useRef)(null),C=A(),w=e??C,{messages:a,isLoading:g,error:d,sendMessage:h}=L({client:e,conversationId:t});(0,n.useEffect)(()=>{if(!w||!u||u.length===0)return;let y=!1;const j=[];return Promise.all(u.map(E=>E.schema!=null?Promise.resolve(M.createFormCollector(E)):M.loadFormCollector(w,E))).then(E=>{if(!y)for(const U of E)j.push(U.install(w))}).catch(()=>{}),()=>{y=!0,j.forEach(E=>E())}},[w,u?JSON.stringify(u.map(y=>[y.name,y.schema??null,y.submit??!1,y.description??null])):""]),(0,n.useEffect)(()=>{v.current?.scrollIntoView({behavior:"smooth"})},[a]),(0,n.useEffect)(()=>{const y=a[a.length-1];y&&y.role==="assistant"&&y.status==="DONE"&&x&&x({id:y.id,content:y.content})},[a,x]);const k=async(y,j)=>{S?.(y),await h(y,j)},_=a[a.length-1],B=g&&_?.role==="assistant"&&_.status==="IN_PROGRESS",K=b===!1?void 0:b??(y=>k(y));return(0,s.jsxs)("div",{className:`ago-chat-widget ${m}`,style:{display:"flex",flexDirection:"column",height:typeof f=="number"?`${f}px`:f,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,s.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,s.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,s.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:o})]}),(0,s.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:[a.length===0?(0,s.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:r}):a.map((y,j)=>(0,s.jsx)(W,{message:y,showAgentName:p,isLast:j===a.length-1,onFollowUpClick:K},y.id)),d&&(0,s.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:d.message}),(0,s.jsx)("div",{ref:v})]}),(0,s.jsx)(H,{onSend:k,disabled:B,placeholder:l,allowFiles:i})]})};function O({client:e,autoLoad:t=!0}={}){const o=A(),r=e||o;if(!r)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[l,i]=(0,n.useState)([]),[f,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(!1),[b,m]=(0,n.useState)(null),S=(0,n.useCallback)(async()=>{u(!0),m(null);try{i(await r.getConversations())}catch(C){m(C instanceof Error?C:new Error("Failed to load conversations"))}finally{u(!1)}},[r]),x=(0,n.useCallback)(async C=>{u(!0),m(null);try{c(await r.getConversation(C))}catch(w){m(w instanceof Error?w:new Error("Failed to load conversation"))}finally{u(!1)}},[r]),v=(0,n.useCallback)(()=>{c(null)},[]);return(0,n.useEffect)(()=>{t&&S()},[t,S]),{conversations:l,currentConversation:f,isLoading:p,error:b,selectConversation:x,startNewConversation:v,refreshConversations:S}}function pe(e={}){const t=A(),o=e.client||t;if(!o)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const r=L({client:o,conversationId:e.conversationId}),l=O({client:o,autoLoad:e.autoLoad});return{messages:r.messages,isLoading:r.isLoading,error:r.error||l.error,sendMessage:r.sendMessage,clearMessages:r.clearMessages,conversationId:r.conversationId,conversations:l.conversations,currentConversation:l.currentConversation,isConversationsLoading:l.isLoading,selectConversation:l.selectConversation,startNewConversation:l.startNewConversation,refreshConversations:l.refreshConversations}}function xe(e,t){const o=R(),{name:r,description:l,parameters:i,handler:f}=typeof e=="string"?{name:e,...t}:e,c=(0,n.useRef)(f);c.current=f,(0,n.useEffect)(()=>{const p=u=>c.current(u);return o.registerFunction(r,p,{description:l,parameters:i}),()=>{o.unregisterFunction(r)}},[o,r,l,i])}function me(e,t){const o=R(),r=(0,n.useRef)(e);r.current=e,(0,n.useEffect)(()=>(o.registerNavigationFunction(l=>r.current(l),t),()=>{o.unregisterFunction("navigateToPage")}),[o,t])}function he(e,t){const o=R(),r=(0,n.useId)(),l=t??r,i=(0,n.useRef)(e);i.current=e;const f=typeof e=="function";(0,n.useEffect)(()=>{if(typeof i.current=="function"){const c=()=>i.current();return o.addDynamicContext(l,c),()=>{o.removeDynamicContext(l)}}return o.setContext(l,i.current),()=>{o.removeContext(l)}},[o,l,f,f?"":JSON.stringify(e)])}function $(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var q={missing:[],complete:!1};function ye(e){const t=R(),o=e.schema!=null,r=JSON.stringify(e.schema??null),l=e.submit,i=l?typeof l=="string"?`client:${l}`:l.via==="backend"?"backend":"handler"in l?"client:handler":`client:${l.url}`:"none",f=JSON.stringify(e.initialValues??null),c=(0,n.useMemo)(()=>o?M.createFormCollector(e):null,[o,e.name,r,i,f,e.autoSubmit]),[p,u]=(0,n.useState)({collector:null,loading:!o,error:null});(0,n.useEffect)(()=>{if(o)return;let g=!1;return u({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(d=>{g||u({collector:d,loading:!1,error:null})}).catch(d=>{g||u({collector:null,loading:!1,error:d instanceof Error?d:new Error(String(d))})}),()=>{g=!0}},[t,o,e.name,i,f,e.autoSubmit]);const b=o?c:p.collector,m=o?!1:p.loading,S=o?null:p.error;(0,n.useEffect)(()=>{if(b)return b.install(t)},[t,b]);const x=(0,n.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[f]),v=$(b?.store??x),C=(0,n.useMemo)(()=>b?.getStatus()??q,[v,b]),w=(0,n.useMemo)(()=>({...v,...C}),[v,C]),a=(0,n.useMemo)(()=>({name:e.name,store:x,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>x.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>q}),[e.name,x]);return{...b??a,state:w,loading:m,error:S}}exports.AgoProvider=G;exports.ChatInput=H;exports.ChatWidget=ge;exports.Markdown=z;exports.Message=W;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=D;exports.useAgoClient=R;exports.useAgoContext=he;exports.useAgoFunction=xe;exports.useAgoNavigation=me;exports.useAgoStore=$;exports.useChat=pe;exports.useConversation=O;exports.useFormCollector=ye;exports.useMessages=L;exports.useOptionalAgoClient=A;
7
+ `})]}),O=({message:e,className:t="",showAgentName:o=!1,isLast:n=!1,onFollowUpClick:a})=>{const i=e.role==="user",f=e.status==="IN_PROGRESS";return(0,r.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&o&&e.agent&&(0,r.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}),!i&&e.sources&&e.sources.length>0&&(0,r.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,g)=>(0,r.jsx)(fe,{source:c,index:g},c.id))}),e.attachments&&e.attachments.length>0&&(0,r.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:i?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(c=>(0,r.jsx)(ue,{attachment:c,isUser:i},c.id))}),(e.content||f)&&(0,r.jsx)("div",{className:"ago-message__content",style:{maxWidth:i?"75%":"100%",padding:i?"10px 14px":"2px 8px",borderRadius:i?"16px":"0",backgroundColor:i?"#03182f":"transparent",color:i?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,r.jsx)(q,{content:e.content}):f&&(0,r.jsx)(pe,{})}),n&&e.followUpReplies&&e.followUpReplies.length>0&&(0,r.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,g)=>(0,r.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},g))})]})},ge=({client:e,conversationId:t,title:o="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:i=!1,height:f=500,logoUrl:c,showAgentName:g=!1,forms:u,onFollowUpClick:v,className:m="",onMessageSent:S,onMessageReceived:x})=>{const h=(0,s.useRef)(null),C=_(),w=e??C,{messages:l,isLoading:p,error:d,sendMessage:y}=W({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!w||!u||u.length===0)return;let b=!1;const E=[];return Promise.all(u.map(M=>M.schema!=null?Promise.resolve(j.createFormCollector(M)):j.loadFormCollector(w,M))).then(M=>{if(!b)for(const J of M)E.push(J.install(w))}).catch(()=>{}),()=>{b=!0,E.forEach(M=>M())}},[w,u?JSON.stringify(u.map(b=>[b.name,b.schema??null,b.submit??!1,b.description??null])):""]),(0,s.useEffect)(()=>{h.current?.scrollIntoView({behavior:"smooth"})},[l]),(0,s.useEffect)(()=>{const b=l[l.length-1];b&&b.role==="assistant"&&b.status==="DONE"&&x&&x({id:b.id,content:b.content})},[l,x]);const k=async(b,E)=>{S?.(b),await y(b,E)},F=l[l.length-1],K=p&&F?.role==="assistant"&&F.status==="IN_PROGRESS",U=v===!1?void 0:v??(b=>k(b));return(0,r.jsxs)("div",{className:`ago-chat-widget ${m}`,style:{display:"flex",flexDirection:"column",height:typeof f=="number"?`${f}px`:f,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,r.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,r.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,r.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:o})]}),(0,r.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:[l.length===0?(0,r.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:n}):l.map((b,E)=>(0,r.jsx)(O,{message:b,showAgentName:g,isLast:E===l.length-1,onFollowUpClick:U},b.id)),d&&(0,r.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:d.message}),(0,r.jsx)("div",{ref:h})]}),(0,r.jsx)(L,{onSend:k,disabled:K,placeholder:a,allowFiles:i})]})};function $({client:e,autoLoad:t=!0}={}){const o=_(),n=e||o;if(!n)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,i]=(0,s.useState)([]),[f,c]=(0,s.useState)(null),[g,u]=(0,s.useState)(!1),[v,m]=(0,s.useState)(null),S=(0,s.useCallback)(async()=>{u(!0),m(null);try{i(await n.getConversations())}catch(C){m(C instanceof Error?C:new Error("Failed to load conversations"))}finally{u(!1)}},[n]),x=(0,s.useCallback)(async C=>{u(!0),m(null);try{c(await n.getConversation(C))}catch(w){m(w instanceof Error?w:new Error("Failed to load conversation"))}finally{u(!1)}},[n]),h=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&S()},[t,S]),{conversations:a,currentConversation:f,isLoading:g,error:v,selectConversation:x,startNewConversation:h,refreshConversations:S}}function xe(e={}){const t=_(),o=e.client||t;if(!o)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const n=W({client:o,conversationId:e.conversationId}),a=$({client:o,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 me(e,t){const o=A(),{name:n,description:a,parameters:i,handler:f}=typeof e=="string"?{name:e,...t}:e,c=(0,s.useRef)(f);c.current=f,(0,s.useEffect)(()=>{const g=u=>c.current(u);return o.registerFunction(n,g,{description:a,parameters:i}),()=>{o.unregisterFunction(n)}},[o,n,a,i])}function he(e,t){const o=A(),n=(0,s.useRef)(e);n.current=e,(0,s.useEffect)(()=>(o.registerNavigationFunction(a=>n.current(a),t),()=>{o.unregisterFunction("navigateToPage")}),[o,t])}function ye(e,t){const o=A(),n=(0,s.useId)(),a=t??n,i=(0,s.useRef)(e);i.current=e;const f=typeof e=="function";(0,s.useEffect)(()=>{if(typeof i.current=="function"){const c=()=>i.current();return o.addDynamicContext(a,c),()=>{o.removeDynamicContext(a)}}return o.setContext(a,i.current),()=>{o.removeContext(a)}},[o,a,f,f?"":JSON.stringify(e)])}function B(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var D={missing:[],complete:!1};function be(e){const t=A(),o=e.schema!=null,n=JSON.stringify(e.schema??null),a=e.submit,i=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",f=JSON.stringify(e.initialValues??null),c=(0,s.useMemo)(()=>o?j.createFormCollector(e):null,[o,e.name,n,i,f,e.autoSubmit]),[g,u]=(0,s.useState)({collector:null,loading:!o,error:null});(0,s.useEffect)(()=>{if(o)return;let p=!1;return u({collector:null,loading:!0,error:null}),j.loadFormCollector(t,e).then(d=>{p||u({collector:d,loading:!1,error:null})}).catch(d=>{p||u({collector:null,loading:!1,error:d instanceof Error?d:new Error(String(d))})}),()=>{p=!0}},[t,o,e.name,i,f,e.autoSubmit]);const v=o?c:g.collector,m=o?!1:g.loading,S=o?null:g.error;(0,s.useEffect)(()=>{if(v)return v.install(t)},[t,v]);const x=(0,s.useMemo)(()=>j.createStore({values:e.initialValues??{},submitted:!1}),[f]),h=B(v?.store??x),C=(0,s.useMemo)(()=>v?.getStatus()??D,[h,v]),w=(0,s.useMemo)(()=>({...h,...C}),[h,C]),l=(0,s.useMemo)(()=>({name:e.name,store:x,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>x.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>D}),[e.name,x]);return{...v??l,state:w,loading:m,error:S}}exports.AgoProvider=G;exports.ChatInput=L;exports.ChatWidget=ge;exports.Markdown=q;exports.Message=O;exports.createFormCollector=j.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=j.deriveFormStatus;exports.loadFormCollector=j.loadFormCollector;exports.useAgo=H;exports.useAgoClient=A;exports.useAgoContext=ye;exports.useAgoFunction=me;exports.useAgoNavigation=he;exports.useAgoStore=B;exports.useChat=xe;exports.useConversation=$;exports.useFormCollector=be;exports.useMessages=W;exports.useOptionalAgoClient=_;
package/dist/react.d.cts CHANGED
@@ -9,6 +9,27 @@ export declare interface AgoAgent {
9
9
  displayName?: string;
10
10
  }
11
11
 
12
+ /**
13
+ * An uploaded file attached to a message.
14
+ *
15
+ * `url` is a presigned, time-limited URL the backend generates per request (or a
16
+ * local `blob:` URL for an optimistic preview). `isSafeImage` is the backend's
17
+ * verdict that the file is a real, script-free image safe to embed inline; the
18
+ * UI only renders an `<img>` when it is true and otherwise shows a download link.
19
+ */
20
+ declare interface AgoAttachment {
21
+ id: string;
22
+ name: string;
23
+ /** MIME type reported by the backend (e.g. `image/png`). */
24
+ contentType?: string;
25
+ /** Size in bytes. */
26
+ fileSize?: number;
27
+ /** Presigned download/preview URL, or a local `blob:` URL before upload. */
28
+ url?: string;
29
+ /** True only when the backend verified the file is a safe inline image. */
30
+ isSafeImage: boolean;
31
+ }
32
+
12
33
  /**
13
34
  * Main SDK client for AGO Chat integration
14
35
  */
@@ -378,6 +399,8 @@ export declare interface AgoMessage {
378
399
  sources?: AgoSource[];
379
400
  toolCalls?: ToolCallData[];
380
401
  followUpReplies?: string[];
402
+ /** Uploaded files on this message (usually the user's). */
403
+ attachments?: AgoAttachment[];
381
404
  createdAt: Date;
382
405
  }
383
406
 
package/dist/react.d.ts CHANGED
@@ -9,6 +9,27 @@ export declare interface AgoAgent {
9
9
  displayName?: string;
10
10
  }
11
11
 
12
+ /**
13
+ * An uploaded file attached to a message.
14
+ *
15
+ * `url` is a presigned, time-limited URL the backend generates per request (or a
16
+ * local `blob:` URL for an optimistic preview). `isSafeImage` is the backend's
17
+ * verdict that the file is a real, script-free image safe to embed inline; the
18
+ * UI only renders an `<img>` when it is true and otherwise shows a download link.
19
+ */
20
+ declare interface AgoAttachment {
21
+ id: string;
22
+ name: string;
23
+ /** MIME type reported by the backend (e.g. `image/png`). */
24
+ contentType?: string;
25
+ /** Size in bytes. */
26
+ fileSize?: number;
27
+ /** Presigned download/preview URL, or a local `blob:` URL before upload. */
28
+ url?: string;
29
+ /** True only when the backend verified the file is a safe inline image. */
30
+ isSafeImage: boolean;
31
+ }
32
+
12
33
  /**
13
34
  * Main SDK client for AGO Chat integration
14
35
  */
@@ -378,6 +399,8 @@ export declare interface AgoMessage {
378
399
  sources?: AgoSource[];
379
400
  toolCalls?: ToolCallData[];
380
401
  followUpReplies?: string[];
402
+ /** Uploaded files on this message (usually the user's). */
403
+ attachments?: AgoAttachment[];
381
404
  createdAt: Date;
382
405
  }
383
406