@useago/sdk 1.0.10 → 1.0.11

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 o=require("react/jsx-runtime"),F=require("react-markdown");F=P.__toESM(F,1);let N=require("remark-gfm");N=P.__toESM(N,1);function q(e){const[t,s]=(0,n.useState)(!1),r=(0,n.useRef)(null),a=(0,n.useMemo)(()=>{if(r.current&&(r.current.destroy(),r.current=null),!e)return null;const l=new J.AgoClient(e);return r.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(s(!0),()=>{r.current?.destroy(),r.current=null}),[a]),(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:a,isReady:t}}var T=(0,n.createContext)(null),G=({children:e,client:t,tools:s,helpers:r,pageContext:a,...l})=>{const{client:u}=q(t?null:l),i=t||u;return(0,n.useEffect)(()=>{if(!(!s||s.length===0)){for(const p of s)i.register(p);return()=>{for(const p of s)i.unregisterFunction(p.name)}}},[i,s]),(0,n.useEffect)(()=>{if(!r)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(d=>d.functions_exports).then(d=>{for(const[h,C]of Object.entries(r)){const k=d[h];if(!k){console.warn(`[AGO] Unknown helper: "${h}"`);continue}const m=C===!0?k:{...k,handler:C};i.register(m),p.push(m.name)}}),()=>{for(const d of p)i.unregisterFunction(d)}},[i,r]),(0,n.useEffect)(()=>{a==="auto"&&i.enableAutoPageContext()},[i,a]),(0,o.jsx)(T.Provider,{value:i,children:e})};function A(){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 R(){return(0,n.useContext)(T)}function L({client:e,conversationId:t}={}){const s=R(),r=e||s;if(!r)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(t),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&t!==u&&(i(t),k(t))},[t]);const k=async m=>{try{l(await r.getMessages(m))}catch(v){C(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const m=x=>{u||i(x.conversationId)},v=x=>{l(f=>{const w=f[f.length-1];return w&&w.id===x.messageId?[...f.slice(0,-1),{...w,content:w.content+x.content}]:f})},c=x=>{l(f=>{let w=-1;for(let S=f.length-1;S>=0;S--)if(f[S].role==="assistant"&&f[S].status==="IN_PROGRESS"){w=S;break}return w<0?f:[...f.slice(0,w),{...f[w],...x},...f.slice(w+1)]})},y=x=>{l(f=>{const w=f.findIndex(S=>S.id===x.id);return w>=0?[...f.slice(0,w),x,...f.slice(w+1)]:[...f,x]}),d(!1)},g=x=>{C(new Error(x.error)),d(!1)};return r.on("message:start",m),r.on("message:chunk",v),r.on("message:answer-complete",c),r.on("message:complete",y),r.on("message:error",g),()=>{r.off("message:start",m),r.off("message:chunk",v),r.off("message:answer-complete",c),r.off("message:complete",y),r.off("message:error",g)}},[r,u]),{messages:a,isLoading:p,error:h,sendMessage:(0,n.useCallback)(async(m,v)=>{d(!0),C(null);const c={id:`temp-${Date.now()}`,conversationId:u||"",content:m,role:"user",status:"DONE",createdAt:new Date},y={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(g=>[...g,c,y]);try{const g=await r.sendMessage(m,{conversationId:u,files:v});return g.conversationId&&!u&&i(g.conversationId),l(x=>{const f=x.filter(S=>!S.id.startsWith("temp-")),w={...c,id:c.id.replace("temp-","user-"),conversationId:g.conversationId};return f.some(S=>S.id===g.id)?[...f,w].sort((S,_)=>new Date(S.createdAt).getTime()-new Date(_.createdAt).getTime()):[...f,w,g]}),g}catch(g){return C(g instanceof Error?g:new Error("Failed to send message")),d(!1),l(x=>x.filter(f=>!f.id.startsWith("temp-"))),null}},[r,u]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),C(null)},[]),conversationId:u}}var W=({onSend:e,disabled:t=!1,placeholder:s="Type a message...",allowFiles:r=!1,className:a=""})=>{const[l,u]=(0,n.useState)(""),[i,p]=(0,n.useState)([]),d=(0,n.useRef)(null),h=(0,n.useCallback)(c=>{c.preventDefault(),(l.trim()||i.length>0)&&(e(l.trim(),i.length>0?i:void 0),u(""),p([]))},[l,i,e]),C=(0,n.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),h(c))},[h]),k=(0,n.useCallback)(c=>{const y=Array.from(c.target.files||[]);p(g=>[...g,...y])},[]),m=(0,n.useCallback)(c=>{p(y=>y.filter((g,x)=>x!==c))},[]),v=l.trim()||i.length>0;return(0,o.jsxs)("form",{onSubmit:h,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[i.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((c,y)=>(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:c.name}),(0,o.jsx)("button",{type:"button",onClick:()=>m(y),style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},y))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:t,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:d,type:"file",multiple:!0,onChange:k,style:{display:"none"}})]}),(0,o.jsx)("textarea",{value:l,onChange:c=>u(c.target.value),onKeyDown:C,placeholder:s,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",fontFamily:"inherit",fontSize:"16px",color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.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,...s})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...s,children:t}),Y=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const s=({children:r,...a})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},r);return s.displayName=`MarkdownHeading${e}`,s},Q=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...s})=>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'},...s,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...s,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),ne=({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}),oe=({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})}),se=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ae=({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}),ie=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),ce={a:X,p:Y,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,o.jsx)(F.default,{remarkPlugins:de,components:ce,children:e}),ue=({source:e,index:t})=>{const s=(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})]}),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,o.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:r,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:s}):(0,o.jsx)("div",{style:r,children:s})},fe=()=>(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 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:`
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
- `})]}),O=({message:e,className:t="",showAgentName:s=!1,isLast:r=!1,onFollowUpClick:a})=>{const l=e.role==="user",u=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&&s&&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((i,p)=>(0,o.jsx)(ue,{source:i,index:p},i.id))}),(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)(z,{content:e.content}):u&&(0,o.jsx)(fe,{})}),r&&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((i,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(i):void 0,style:{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:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:d=>{d.currentTarget.style.borderColor="#dee3e8"},children:i},p))})]})},ge=({client:e,conversationId:t,title:s="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:u=500,logoUrl:i,showAgentName:p=!1,forms:d,onFollowUpClick:h,className:C="",onMessageSent:k,onMessageReceived:m})=>{const v=(0,n.useRef)(null),c=R(),y=e??c,{messages:g,isLoading:x,error:f,sendMessage:w}=L({client:e,conversationId:t});(0,n.useEffect)(()=>{if(!y||!d||d.length===0)return;let b=!1;const j=[];return Promise.all(d.map(E=>E.schema!=null?Promise.resolve(M.createFormCollector(E)):M.loadFormCollector(y,E))).then(E=>{if(!b)for(const U of E)j.push(U.install(y))}).catch(()=>{}),()=>{b=!0,j.forEach(E=>E())}},[y,d?JSON.stringify(d.map(b=>[b.name,b.schema??null,b.submit??!1,b.description??null])):""]),(0,n.useEffect)(()=>{v.current?.scrollIntoView({behavior:"smooth"})},[g]),(0,n.useEffect)(()=>{const b=g[g.length-1];b&&b.role==="assistant"&&b.status==="DONE"&&m&&m({id:b.id,content:b.content})},[g,m]);const S=async(b,j)=>{k?.(b),await w(b,j)},_=g[g.length-1],B=x&&_?.role==="assistant"&&_.status==="IN_PROGRESS",K=h===!1?void 0:h??(b=>S(b));return(0,o.jsxs)("div",{className:`ago-chat-widget ${C}`,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,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:[i&&(0,o.jsx)("img",{src:i,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[g.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:r}):g.map((b,j)=>(0,o.jsx)(O,{message:b,showAgentName:p,isLast:j===g.length-1,onFollowUpClick:K},b.id)),f&&(0,o.jsx)("div",{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:v})]}),(0,o.jsx)(W,{onSend:S,disabled:B,placeholder:a,allowFiles:l})]})};function H({client:e,autoLoad:t=!0}={}){const s=R(),r=e||s;if(!r)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(null),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null),k=(0,n.useCallback)(async()=>{d(!0),C(null);try{l(await r.getConversations())}catch(c){C(c instanceof Error?c:new Error("Failed to load conversations"))}finally{d(!1)}},[r]),m=(0,n.useCallback)(async c=>{d(!0),C(null);try{i(await r.getConversation(c))}catch(y){C(y instanceof Error?y:new Error("Failed to load conversation"))}finally{d(!1)}},[r]),v=(0,n.useCallback)(()=>{i(null)},[]);return(0,n.useEffect)(()=>{t&&k()},[t,k]),{conversations:a,currentConversation:u,isLoading:p,error:h,selectConversation:m,startNewConversation:v,refreshConversations:k}}function pe(e={}){const t=R(),s=e.client||t;if(!s)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const r=L({client:s,conversationId:e.conversationId}),a=H({client:s,autoLoad:e.autoLoad});return{messages:r.messages,isLoading:r.isLoading,error:r.error||a.error,sendMessage:r.sendMessage,clearMessages:r.clearMessages,conversationId:r.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function xe(e,t){const s=A(),{name:r,description:a,parameters:l,handler:u}=typeof e=="string"?{name:e,...t}:e,i=(0,n.useRef)(u);i.current=u,(0,n.useEffect)(()=>{const p=d=>i.current(d);return s.registerFunction(r,p,{description:a,parameters:l}),()=>{s.unregisterFunction(r)}},[s,r,a,l])}function me(e,t){const s=A(),r=(0,n.useRef)(e);r.current=e,(0,n.useEffect)(()=>(s.registerNavigationFunction(a=>r.current(a),t),()=>{s.unregisterFunction("navigateToPage")}),[s,t])}function he(e,t){const s=A(),r=(0,n.useId)(),a=t??r,l=(0,n.useRef)(e);l.current=e;const u=typeof e=="function";(0,n.useEffect)(()=>{if(typeof l.current=="function"){const i=()=>l.current();return s.addDynamicContext(a,i),()=>{s.removeDynamicContext(a)}}return s.setContext(a,l.current),()=>{s.removeContext(a)}},[s,a,u,u?"":JSON.stringify(e)])}function $(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var D={missing:[],complete:!1};function ye(e){const t=A(),s=e.schema!=null,r=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",u=JSON.stringify(e.initialValues??null),i=(0,n.useMemo)(()=>s?M.createFormCollector(e):null,[s,e.name,r,l,u,e.autoSubmit]),[p,d]=(0,n.useState)({collector:null,loading:!s,error:null});(0,n.useEffect)(()=>{if(s)return;let x=!1;return d({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(f=>{x||d({collector:f,loading:!1,error:null})}).catch(f=>{x||d({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{x=!0}},[t,s,e.name,l,u,e.autoSubmit]);const h=s?i:p.collector,C=s?!1:p.loading,k=s?null:p.error;(0,n.useEffect)(()=>{if(h)return h.install(t)},[t,h]);const m=(0,n.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[u]),v=$(h?.store??m),c=(0,n.useMemo)(()=>h?.getStatus()??D,[v,h]),y=(0,n.useMemo)(()=>({...v,...c}),[v,c]),g=(0,n.useMemo)(()=>({name:e.name,store:m,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>m.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>D}),[e.name,m]);return{...h??g,state:y,loading:C,error:k}}exports.AgoProvider=G;exports.ChatInput=W;exports.ChatWidget=ge;exports.Markdown=z;exports.Message=O;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=q;exports.useAgoClient=A;exports.useAgoContext=he;exports.useAgoFunction=xe;exports.useAgoNavigation=me;exports.useAgoStore=$;exports.useChat=pe;exports.useConversation=H;exports.useFormCollector=ye;exports.useMessages=L;exports.useOptionalAgoClient=R;
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;