@useago/sdk 1.4.3 → 1.5.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/CHANGELOG.md +15 -1
- package/dist/{AgoClient-S8oeNnAE.js → AgoClient-q39FIjSC.js} +105 -81
- package/dist/AgoClient-wcPRaIMs.cjs +8 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +75 -5
- package/dist/angular.d.ts +75 -5
- package/dist/angular.js +5 -1
- package/dist/autoContinue-CcCTva-D.cjs +1 -0
- package/dist/autoContinue-D3Mmaaca.js +63 -0
- package/dist/{createConversationSession-CmBq7uGi.cjs → createConversationSession-BBYfQLLS.cjs} +1 -1
- package/dist/{createConversationSession-DoUHdVNR.js → createConversationSession-DCSWShaW.js} +1 -1
- package/dist/{createFormCollector-Bz_0IJ0Q.cjs → createFormCollector-eimwwWEi.cjs} +1 -1
- package/dist/{createFormCollector-vy-QvFja.js → createFormCollector-sB6rMccD.js} +1 -1
- package/dist/devtools.d.cts +32 -4
- package/dist/devtools.d.ts +32 -4
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.d.cts +6 -0
- package/dist/helpers.d.ts +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +101 -5
- package/dist/index.d.ts +101 -5
- package/dist/index.js +45 -43
- package/dist/react.cjs +3 -3
- package/dist/react.d.cts +40 -18
- package/dist/react.d.ts +40 -18
- package/dist/react.js +415 -471
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +32 -4
- package/dist/testing.d.ts +32 -4
- package/dist/testing.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +38 -4
- package/dist/vue.d.ts +38 -4
- package/dist/vue.js +22 -21
- package/dist/widget.cjs +1 -1
- package/dist/widget.d.cts +32 -4
- package/dist/widget.d.ts +32 -4
- package/dist/widget.js +3 -3
- package/llms-full.txt +1932 -0
- package/package.json +5 -3
- package/dist/AgoClient-CMDVqNaH.cjs +0 -8
- /package/dist/{createMockClient-bAZ9KBHC.js → createMockClient-BUc9PSbo.js} +0 -0
- /package/dist/{createMockClient-BSr-UV8R.cjs → createMockClient-CjdCqixj.cjs} +0 -0
- /package/dist/{functions-Djnq-JAo.cjs → functions-IGSjjvF4.cjs} +0 -0
package/dist/react.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("./rolldown-runtime-16Nf8qvH.cjs"),F=require("./AgoClient-
|
|
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:
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("./rolldown-runtime-16Nf8qvH.cjs"),F=require("./AgoClient-wcPRaIMs.cjs"),J=require("./autoContinue-CcCTva-D.cjs"),I=require("./createFormCollector-eimwwWEi.cjs"),V=require("./createMockClient-CjdCqixj.cjs");let s=require("react");s=W.__toESM(s,1);let o=require("react/jsx-runtime"),P=require("react-markdown");P=W.__toESM(P,1);let T=require("remark-gfm");T=W.__toESM(T,1);function q(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 z=(0,s.createContext)(null),Y=({children:e,client:t,tools:r,helpers:n,pageContext:a,...l})=>{const{client:d}=q(t?null:l),c=t||d;return(0,s.useEffect)(()=>{if(!(!r||r.length===0)){for(const g of r)c.register(g);return()=>{for(const g of r)c.unregisterFunction(g.name)}}},[c,r]),(0,s.useEffect)(()=>{if(!n)return;const g=[];return Promise.resolve().then(()=>require("./functions-IGSjjvF4.cjs")).then(f=>f.functions_exports).then(f=>{for(const[b,C]of Object.entries(n)){const j=f[b];if(!j){console.warn(`[AGO] Unknown helper: "${b}"`);continue}const h=C===!0?j:{...j,handler:C};c.register(h),g.push(h.name)}}),()=>{for(const f of g)c.unregisterFunction(f)}},[c,n]),(0,s.useEffect)(()=>{a==="auto"&&c.enableAutoPageContext()},[c,a]),(0,o.jsx)(z.Provider,{value:c,children:e})};function M(){const e=(0,s.useContext)(z);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function N(){return(0,s.useContext)(z)}function L({client:e,conversationId:t}={}){const r=N(),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),[g,f]=(0,s.useState)(!1),[b,C]=(0,s.useState)(null);(0,s.useEffect)(()=>{t&&t!==d&&(c(t),j(t))},[t]);const j=async h=>{try{l((await n.getMessages(h)).filter(y=>!y.hidden))}catch(y){C(y instanceof Error?y:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const h=u=>u==="IN_PROGRESS"||u==="WAITING_CLIENT",y=u=>{d||c(u.conversationId),f(!0),l(p=>{const m=p.findIndex(x=>x.id===u.messageId);return m>=0?p.map((x,_)=>_===m?{...x,status:"IN_PROGRESS"}:x):p.some(x=>x.role==="assistant"&&h(x.status))?p:[...p,{id:u.messageId,conversationId:u.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},S=u=>{l(p=>{const m=p.findIndex(x=>x.id===u.messageId);return m<0?p:p.map((x,_)=>_===m?{...x,content:x.content+u.content}:x)})},k=u=>{l(p=>{let m=-1;for(let x=p.length-1;x>=0;x--)if(p[x].role==="assistant"&&h(p[x].status)){m=x;break}return m<0?p:[...p.slice(0,m),{...p[m],...u},...p.slice(m+1)]})},i=u=>{l(p=>{const m=p.findIndex(x=>x.id===u.id);return m>=0?[...p.slice(0,m),u,...p.slice(m+1)]:[...p,u]}),f(!1)},v=u=>{C(new Error(u.error)),f(!1)};return n.on("message:start",y),n.on("message:chunk",S),n.on("message:answer-complete",k),n.on("message:complete",i),n.on("message:error",v),()=>{n.off("message:start",y),n.off("message:chunk",S),n.off("message:answer-complete",k),n.off("message:complete",i),n.off("message:error",v)}},[n,d]),{messages:a,isLoading:g,error:b,sendMessage:(0,s.useCallback)(async(h,y)=>{f(!0),C(null);const S={id:`temp-${Date.now()}`,conversationId:d||"",content:h,role:"user",status:"DONE",attachments:y&&y.length>0?F.attachmentsFromFiles(y):void 0,createdAt:new Date},k={id:`temp-assistant-${Date.now()}`,conversationId:d||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(i=>[...i,S,k]);try{const i=await n.sendMessage(h,{conversationId:d,files:y});return i.conversationId&&!d&&c(i.conversationId),l(v=>{const u=v.filter(m=>!m.id.startsWith("temp-")),p={...S,id:S.id.replace("temp-","user-"),conversationId:i.conversationId};return u.some(m=>m.id===i.id)?[...u,p].sort((m,x)=>new Date(m.createdAt).getTime()-new Date(x.createdAt).getTime()):[...u,p,i]}),i}catch(i){return C(i instanceof Error?i:new Error("Failed to send message")),f(!1),l(v=>v.filter(u=>!u.id.startsWith("temp-"))),null}},[n,d]),clearMessages:(0,s.useCallback)(()=>{l([]),c(void 0),C(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,g]=(0,s.useState)([]),f=(0,s.useRef)(null),b=(0,s.useRef)(null),C=(0,s.useCallback)(()=>{const i=b.current;if(!i)return;const v=110;i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight+2,v)}px`,i.style.overflowY=i.scrollHeight+2>v?"auto":"hidden"},[]),j=(0,s.useCallback)(i=>{i.preventDefault(),(l.trim()||c.length>0)&&(e(l.trim(),c.length>0?c:void 0),d(""),g([]),requestAnimationFrame(C))},[l,c,e,C]),h=(0,s.useCallback)(i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),j(i))},[j]),y=(0,s.useCallback)(i=>{const v=Array.from(i.target.files||[]);g(u=>[...u,...v])},[]),S=(0,s.useCallback)(i=>{g(v=>v.filter((u,p)=>p!==i))},[]),k=l.trim()||c.length>0;return(0,o.jsxs)("form",{onSubmit:j,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,v)=>(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:()=>S(v),"aria-label":`Remove ${i.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},v))}),(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:y,style:{display:"none"}})]}),(0,o.jsx)("textarea",{ref:b,value:l,onChange:i=>{d(i.target.value),C()},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||!k,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!k?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!k?"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}),R=(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:R(1,"20px"),h2:R(2,"18px"),h3:R(3,"16px"),h4:R(4,"15px"),h5:R(5,"14px"),h6:R(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=[T.default],O=({content:e})=>(0,o.jsx)(P.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:`
|
|
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
|
-
`})]}),B=({message:e,className:n="",showAgentName:r=!1,isLast:t=!1,onFollowUpClick:a})=>{const l=e.role==="user",d=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${n}`,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)($,{content:e.content}):d&&(0,o.jsx)(pe,{})}),t&&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:n,title:r="Chat",welcomeMessage:t="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:C,className:b="",onMessageSent:I,onMessageReceived:g})=>{const m=(0,s.useRef)(null),S=_(),w=e??S,{messages:i,isLoading:y,error:f,sendMessage:x}=L({client:e,conversationId:n});(0,s.useEffect)(()=>{if(!w||!u||u.length===0)return;let k=!1;const A=[];return Promise.all(u.map(j=>j.schema!=null?Promise.resolve(M.createFormCollector(j)):M.loadFormCollector(w,j))).then(j=>{if(!k)for(const J of j)A.push(J.install(w))}).catch(()=>{}),()=>{k=!0,A.forEach(j=>j())}},[w,u?JSON.stringify(u.map(k=>[k.name,k.schema??null,k.submit??!1,k.description??null])):""]),(0,s.useEffect)(()=>{m.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,s.useEffect)(()=>{const k=i[i.length-1];k&&k.role==="assistant"&&k.status==="DONE"&&g&&g({id:k.id,content:k.content})},[i,g]);const v=async(k,A)=>{I?.(k),await x(k,A)},h=i[i.length-1],N=y&&h?.role==="assistant"&&(h.status==="IN_PROGRESS"||h.status==="WAITING_CLIENT"),K=C===!1?void 0:C??(k=>v(k));return(0,o.jsxs)("div",{className:`ago-chat-widget ${b}`,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:t}):i.map((k,A)=>(0,o.jsx)(B,{message:k,showAgentName:p,isLast:A===i.length-1,onFollowUpClick:K},k.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)(q,{onSend:v,disabled:N,placeholder:a,allowFiles:l})]})};function G({client:e,autoLoad:n=!0}={}){const r=_(),t=e||r;if(!t)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),[C,b]=(0,s.useState)(null),I=(0,s.useCallback)(async()=>{u(!0),b(null);try{l(await t.getConversations())}catch(S){b(S instanceof Error?S:new Error("Failed to load conversations"))}finally{u(!1)}},[t]),g=(0,s.useCallback)(async S=>{u(!0),b(null);try{c(await t.getConversation(S))}catch(w){b(w instanceof Error?w:new Error("Failed to load conversation"))}finally{u(!1)}},[t]),m=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{n&&I()},[n,I]),{conversations:a,currentConversation:d,isLoading:p,error:C,selectConversation:g,startNewConversation:m,refreshConversations:I}}function me(e={}){const n=_(),r=e.client||n;if(!r)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const t=L({client:r,conversationId:e.conversationId}),a=G({client:r,autoLoad:e.autoLoad});return{messages:t.messages,isLoading:t.isLoading,error:t.error||a.error,sendMessage:t.sendMessage,clearMessages:t.clearMessages,conversationId:t.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function he(e,n){const r=E(),{name:t,description:a,parameters:l,handler:d}=typeof e=="string"?{name:e,...n}:e,c=(0,s.useRef)(d);c.current=d,(0,s.useEffect)(()=>{const p=u=>c.current(u);return r.registerFunction(t,p,{description:a,parameters:l}),()=>{r.unregisterFunction(t)}},[r,t,a,l])}function ye(e,n){const r=E(),t=(0,s.useRef)(e);t.current=e,(0,s.useEffect)(()=>(r.registerNavigationFunction(a=>t.current(a),n),()=>{r.unregisterNavigationFunction()}),[r,n])}function be(e,n){const r=E(),t=n?.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:t}),()=>{r.unregisterPageStateFunction(t)}},[r,t])}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 z(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 n=E(),r=(0,s.useRef)(z(e));r.current=z(e),(0,s.useEffect)(()=>{const t={navigated:!1,pausedTurnNavigated:!1,depth:0,runId:0,ourSendPending:!1},a=()=>n.getRegisteredFunctions().some(g=>g.name===r.current.pageStateFunctionName),l=g=>new Promise(m=>{let S=!1;const w=x=>{S||(S=!0,clearTimeout(f),n.off("context:changed",y),m(x))},i=()=>setTimeout(()=>w(g===t.runId&&a()),r.current.settleMs),y=()=>{if(g!==t.runId)return w(!1);a()&&(n.off("context:changed",y),i())},f=setTimeout(()=>w(!1),r.current.readinessTimeoutMs);a()?i():n.on("context:changed",y)}),d=async g=>{const m=++t.runId;if(!(!await l(m)||m!==t.runId)){t.depth+=1,t.ourSendPending=!0;try{await n.sendMessage(r.current.continuationPrompt,{conversationId:g,hidden:!0})}catch{t.ourSendPending=!1}}},c=g=>{r.current.navigationFunctions.includes(g.functionName)&&(t.navigated=!0)},p=n.registerResumeGate(async()=>{r.current.enabled&&t.pausedTurnNavigated&&(t.pausedTurnNavigated=!1,await l(++t.runId))}),u=()=>{t.pausedTurnNavigated=t.navigated,t.navigated=!1},C=()=>{t.ourSendPending||(t.depth=0,t.runId+=1)},b=g=>{t.ourSendPending=!1;const m=t.navigated;t.navigated=!1,r.current.enabled&&m&&(t.depth>=r.current.maxDepth||d(g.conversationId))},I=()=>{t.ourSendPending=!1};return n.on("function:invoke",c),n.on("message:start",C),n.on("message:waiting-client",u),n.on("message:complete",b),n.on("message:error",I),()=>{t.runId+=1,p(),n.off("function:invoke",c),n.off("message:start",C),n.off("message:waiting-client",u),n.off("message:complete",b),n.off("message:error",I)}},[n])}function we(e,n){const r=E(),t=(0,s.useId)(),a=n??t,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 O={missing:[],complete:!1};function Se(e){const n=E(),r=e.schema!=null,t=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,t,l,d,e.autoSubmit]),[p,u]=(0,s.useState)({collector:null,loading:!r,error:null});(0,s.useEffect)(()=>{if(r)return;let y=!1;return u({collector:null,loading:!0,error:null}),M.loadFormCollector(n,e).then(f=>{y||u({collector:f,loading:!1,error:null})}).catch(f=>{y||u({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{y=!0}},[n,r,e.name,l,d,e.autoSubmit]);const C=r?c:p.collector,b=r?!1:p.loading,I=r?null:p.error;(0,s.useEffect)(()=>{if(C)return C.install(n)},[n,C]);const g=(0,s.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[d]),m=U(C?.store??g),S=(0,s.useMemo)(()=>C?.getStatus()??O,[m,C]),w=(0,s.useMemo)(()=>({...m,...S}),[m,S]),i=(0,s.useMemo)(()=>({name:e.name,store:g,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>g.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>O}),[e.name,g]);return{...C??i,state:w,loading:b,error:I}}exports.AgoProvider=Y;exports.ChatInput=q;exports.ChatWidget=xe;exports.Markdown=$;exports.Message=B;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.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=G;exports.useFormCollector=Se;exports.useMessages=L;exports.useOptionalAgoClient=_;
|
|
7
|
+
`})]}),$=({message:e,className:t="",showAgentName:r=!1,isLast:n=!1,onFollowUpClick:a})=>{const l=e.role==="user",d=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";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,g)=>(0,o.jsx)(ge,{source:c,index:g},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)(O,{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,g)=>(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},g))})]})},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:g=!1,forms:f,onFollowUpClick:b,className:C="",onMessageSent:j,onMessageReceived:h})=>{const y=(0,s.useRef)(null),S=N(),k=e??S,{messages:i,isLoading:v,error:u,sendMessage:p}=L({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!k||!f||f.length===0)return;let w=!1;const A=[];return Promise.all(f.map(E=>E.schema!=null?Promise.resolve(I.createFormCollector(E)):I.loadFormCollector(k,E))).then(E=>{if(!w)for(const U of E)A.push(U.install(k))}).catch(()=>{}),()=>{w=!0,A.forEach(E=>E())}},[k,f?JSON.stringify(f.map(w=>[w.name,w.schema??null,w.submit??!1,w.description??null])):""]),(0,s.useEffect)(()=>{y.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,s.useEffect)(()=>{const w=i[i.length-1];w&&w.role==="assistant"&&w.status==="DONE"&&h&&h({id:w.id,content:w.content})},[i,h]);const m=async(w,A)=>{j?.(w),await p(w,A)},x=i[i.length-1],_=v&&x?.role==="assistant"&&(x.status==="IN_PROGRESS"||x.status==="WAITING_CLIENT"),K=b===!1?void 0:b??(w=>m(w));return(0,o.jsxs)("div",{className:`ago-chat-widget ${C}`,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((w,A)=>(0,o.jsx)($,{message:w,showAgentName:g,isLast:A===i.length-1,onFollowUpClick:K},w.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:y})]}),(0,o.jsx)(H,{onSend:m,disabled:_,placeholder:a,allowFiles:l})]})};function B({client:e,autoLoad:t=!0}={}){const r=N(),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),[g,f]=(0,s.useState)(!1),[b,C]=(0,s.useState)(null),j=(0,s.useCallback)(async()=>{f(!0),C(null);try{l(await n.getConversations())}catch(S){C(S instanceof Error?S:new Error("Failed to load conversations"))}finally{f(!1)}},[n]),h=(0,s.useCallback)(async S=>{f(!0),C(null);try{c(await n.getConversation(S))}catch(k){C(k instanceof Error?k:new Error("Failed to load conversation"))}finally{f(!1)}},[n]),y=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&j()},[t,j]),{conversations:a,currentConversation:d,isLoading:g,error:b,selectConversation:h,startNewConversation:y,refreshConversations:j}}function me(e={}){const t=N(),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=L({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=M(),{name:n,description:a,parameters:l,handler:d,maxResultBytes:c}=typeof e=="string"?{name:e,...t}:e,g=(0,s.useRef)(d);g.current=d,(0,s.useEffect)(()=>{const f=b=>g.current(b);return r.registerFunction(n,f,{description:a,parameters:l,maxResultBytes:c}),()=>{r.unregisterFunction(n)}},[r,n,a,l,c])}function ye(e,t){const r=M(),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=M(),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(g=>g.name===d.name)??d;return{name:d.name,description:d.description,schema:d.schema,get:d.get?()=>c().get?.():void 0,set:g=>c().set(g)}});return r.registerPageStateFunction(l,{functionName:n}),()=>{r.unregisterPageStateFunction(n)}},[r,n])}function ve(e){const t=M(),r=(0,s.useRef)(e);r.current=e,(0,s.useEffect)(()=>J.attachAutoContinueAfterNavigation(t,()=>r.current),[t])}function Ce(e,t){const r=M(),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 G(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var D={missing:[],complete:!1};function we(e){const t=M(),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?I.createFormCollector(e):null,[r,e.name,n,l,d,e.autoSubmit]),[g,f]=(0,s.useState)({collector:null,loading:!r,error:null});(0,s.useEffect)(()=>{if(r)return;let v=!1;return f({collector:null,loading:!0,error:null}),I.loadFormCollector(t,e).then(u=>{v||f({collector:u,loading:!1,error:null})}).catch(u=>{v||f({collector:null,loading:!1,error:u instanceof Error?u:new Error(String(u))})}),()=>{v=!0}},[t,r,e.name,l,d,e.autoSubmit]);const b=r?c:g.collector,C=r?!1:g.loading,j=r?null:g.error;(0,s.useEffect)(()=>{if(b)return b.install(t)},[t,b]);const h=(0,s.useMemo)(()=>I.createStore({values:e.initialValues??{},submitted:!1}),[d]),y=G(b?.store??h),S=(0,s.useMemo)(()=>b?.getStatus()??D,[y,b]),k=(0,s.useMemo)(()=>({...y,...S}),[y,S]),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:()=>D}),[e.name,h]);return{...b??i,state:k,loading:C,error:j}}exports.AgoProvider=Y;exports.ChatInput=H;exports.ChatWidget=xe;exports.Markdown=O;exports.Message=$;exports.createFormCollector=I.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=I.deriveFormStatus;exports.loadFormCollector=I.loadFormCollector;exports.useAgo=q;exports.useAgoAutoContinueAfterNavigation=ve;exports.useAgoClient=M;exports.useAgoContext=Ce;exports.useAgoFunction=he;exports.useAgoNavigation=ye;exports.useAgoPageState=be;exports.useAgoStore=G;exports.useChat=me;exports.useConversation=B;exports.useFormCollector=we;exports.useMessages=L;exports.useOptionalAgoClient=N;
|
package/dist/react.d.cts
CHANGED
|
@@ -194,7 +194,7 @@ declare class AgoClient {
|
|
|
194
194
|
* ```
|
|
195
195
|
*/
|
|
196
196
|
registerFunction(definition: ClientFunctionDefinition): void;
|
|
197
|
-
registerFunction(name: string, handler: ClientFunctionHandler, schema:
|
|
197
|
+
registerFunction(name: string, handler: ClientFunctionHandler, schema: ClientFunctionRegisterOptions): void;
|
|
198
198
|
/**
|
|
199
199
|
* Short alias for `registerFunction`. Also accepts an array of definitions.
|
|
200
200
|
*
|
|
@@ -495,14 +495,22 @@ export declare interface AgoConfig {
|
|
|
495
495
|
warnOnEmptyReply?: boolean;
|
|
496
496
|
/**
|
|
497
497
|
* How the agent loop treats client function calls (requires backend support):
|
|
498
|
-
* - `"
|
|
499
|
-
* result; the real result is only visible to the agent on later turns.
|
|
500
|
-
* - `"pause"`: the turn stops on client function call(s) with status
|
|
498
|
+
* - `"pause"` (default): the turn stops on client function call(s) with status
|
|
501
499
|
* `WAITING_CLIENT`; once every result is submitted, the SDK resumes the SAME
|
|
502
500
|
* turn via `POST /messages/{id}/continue`, so the agent sees the real results.
|
|
501
|
+
* - `"placeholder"` (legacy): the turn continues immediately on a placeholder
|
|
502
|
+
* result; the real result is only visible to the agent on later turns.
|
|
503
503
|
* Older backends ignore the flag, so `"pause"` degrades to legacy behavior.
|
|
504
504
|
*/
|
|
505
505
|
clientFunctionsMode?: ClientFunctionsMode;
|
|
506
|
+
/**
|
|
507
|
+
* Max serialized size (bytes) of a client function result before the SDK
|
|
508
|
+
* replaces it with a flagged, truncated preview. Everything a handler
|
|
509
|
+
* returns is sent into the LLM context, so this caps runaway payloads
|
|
510
|
+
* (raw API responses, full tables). Default `50000`. Override per function
|
|
511
|
+
* with `maxResultBytes` on its definition; `Infinity` disables the guard.
|
|
512
|
+
*/
|
|
513
|
+
maxFunctionResultBytes?: number;
|
|
506
514
|
}
|
|
507
515
|
|
|
508
516
|
/**
|
|
@@ -714,6 +722,12 @@ declare interface ClientFunctionDefinition {
|
|
|
714
722
|
description: string;
|
|
715
723
|
parameters: ClientFunctionSchema["parameters"];
|
|
716
724
|
handler: ClientFunctionHandler;
|
|
725
|
+
/**
|
|
726
|
+
* Max serialized result size in bytes before the SDK truncates it to a
|
|
727
|
+
* flagged preview (default: `AgoConfig.maxFunctionResultBytes`, 50 000).
|
|
728
|
+
* `Infinity` disables the guard for this function.
|
|
729
|
+
*/
|
|
730
|
+
maxResultBytes?: number;
|
|
717
731
|
}
|
|
718
732
|
|
|
719
733
|
/**
|
|
@@ -728,6 +742,20 @@ declare interface ClientFunctionInvocation {
|
|
|
728
742
|
conversationId: string;
|
|
729
743
|
}
|
|
730
744
|
|
|
745
|
+
/**
|
|
746
|
+
* Schema-plus-settings object accepted when registering a function: the schema
|
|
747
|
+
* (minus `name`) and SDK-side options that are NOT sent to the backend.
|
|
748
|
+
*/
|
|
749
|
+
declare type ClientFunctionRegisterOptions = Omit<ClientFunctionSchema, "name"> & {
|
|
750
|
+
/**
|
|
751
|
+
* Max serialized result size in bytes before the SDK truncates it to a
|
|
752
|
+
* flagged preview. Overrides the client-level default
|
|
753
|
+
* (`AgoConfig.maxFunctionResultBytes`, 50 000 by default). `Infinity`
|
|
754
|
+
* disables the guard for this function.
|
|
755
|
+
*/
|
|
756
|
+
maxResultBytes?: number;
|
|
757
|
+
};
|
|
758
|
+
|
|
731
759
|
/**
|
|
732
760
|
* Schema for a client-side function that AGO can call
|
|
733
761
|
*/
|
|
@@ -1283,20 +1311,8 @@ export declare function useAgo(config: UseAgoOptions | null): {
|
|
|
1283
1311
|
* Auto-continue the agent after it navigates, so a "go to page B and change X"
|
|
1284
1312
|
* request completes in one user gesture. Mount this once inside `AgoProvider`.
|
|
1285
1313
|
*
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
* - **Pause mode** (`clientFunctionsMode: "pause"`): the backend pauses the turn
|
|
1289
|
-
* on the navigation call (`message:waiting-client`) and the SDK resumes it once
|
|
1290
|
-
* the result is submitted. This hook only registers a *resume gate* that delays
|
|
1291
|
-
* the resume until the destination page's `useAgoPageState` registered (plus a
|
|
1292
|
-
* settle delay), so the continued turn ships the new page's `setPageState` and
|
|
1293
|
-
* current state. Same turn, no extra prompt, backend budget as the guardrail —
|
|
1294
|
-
* `continuationPrompt` and `maxDepth` are unused here.
|
|
1295
|
-
*
|
|
1296
|
-
* - **Placeholder mode** (legacy default): when the agent calls the navigation
|
|
1297
|
-
* function and that turn ends, this waits for the destination page's state to
|
|
1298
|
-
* register, then sends a hidden continuation message; the agent applies the
|
|
1299
|
-
* state in a second turn (requires backend support for the `hidden` flag).
|
|
1314
|
+
* React binding of {@link attachAutoContinueAfterNavigation} — see it for the
|
|
1315
|
+
* pause-mode / placeholder-mode mechanics.
|
|
1300
1316
|
*
|
|
1301
1317
|
* ```tsx
|
|
1302
1318
|
* function AppShell() {
|
|
@@ -1399,6 +1415,12 @@ export declare interface UseAgoFunctionOptions {
|
|
|
1399
1415
|
required?: string[];
|
|
1400
1416
|
};
|
|
1401
1417
|
handler: ClientFunctionHandler;
|
|
1418
|
+
/**
|
|
1419
|
+
* Max serialized result size in bytes before the SDK truncates it to a
|
|
1420
|
+
* flagged preview (default: `AgoConfig.maxFunctionResultBytes`, 50 000).
|
|
1421
|
+
* `Infinity` disables the guard for this function.
|
|
1422
|
+
*/
|
|
1423
|
+
maxResultBytes?: number;
|
|
1402
1424
|
}
|
|
1403
1425
|
|
|
1404
1426
|
/**
|
package/dist/react.d.ts
CHANGED
|
@@ -194,7 +194,7 @@ declare class AgoClient {
|
|
|
194
194
|
* ```
|
|
195
195
|
*/
|
|
196
196
|
registerFunction(definition: ClientFunctionDefinition): void;
|
|
197
|
-
registerFunction(name: string, handler: ClientFunctionHandler, schema:
|
|
197
|
+
registerFunction(name: string, handler: ClientFunctionHandler, schema: ClientFunctionRegisterOptions): void;
|
|
198
198
|
/**
|
|
199
199
|
* Short alias for `registerFunction`. Also accepts an array of definitions.
|
|
200
200
|
*
|
|
@@ -495,14 +495,22 @@ export declare interface AgoConfig {
|
|
|
495
495
|
warnOnEmptyReply?: boolean;
|
|
496
496
|
/**
|
|
497
497
|
* How the agent loop treats client function calls (requires backend support):
|
|
498
|
-
* - `"
|
|
499
|
-
* result; the real result is only visible to the agent on later turns.
|
|
500
|
-
* - `"pause"`: the turn stops on client function call(s) with status
|
|
498
|
+
* - `"pause"` (default): the turn stops on client function call(s) with status
|
|
501
499
|
* `WAITING_CLIENT`; once every result is submitted, the SDK resumes the SAME
|
|
502
500
|
* turn via `POST /messages/{id}/continue`, so the agent sees the real results.
|
|
501
|
+
* - `"placeholder"` (legacy): the turn continues immediately on a placeholder
|
|
502
|
+
* result; the real result is only visible to the agent on later turns.
|
|
503
503
|
* Older backends ignore the flag, so `"pause"` degrades to legacy behavior.
|
|
504
504
|
*/
|
|
505
505
|
clientFunctionsMode?: ClientFunctionsMode;
|
|
506
|
+
/**
|
|
507
|
+
* Max serialized size (bytes) of a client function result before the SDK
|
|
508
|
+
* replaces it with a flagged, truncated preview. Everything a handler
|
|
509
|
+
* returns is sent into the LLM context, so this caps runaway payloads
|
|
510
|
+
* (raw API responses, full tables). Default `50000`. Override per function
|
|
511
|
+
* with `maxResultBytes` on its definition; `Infinity` disables the guard.
|
|
512
|
+
*/
|
|
513
|
+
maxFunctionResultBytes?: number;
|
|
506
514
|
}
|
|
507
515
|
|
|
508
516
|
/**
|
|
@@ -714,6 +722,12 @@ declare interface ClientFunctionDefinition {
|
|
|
714
722
|
description: string;
|
|
715
723
|
parameters: ClientFunctionSchema["parameters"];
|
|
716
724
|
handler: ClientFunctionHandler;
|
|
725
|
+
/**
|
|
726
|
+
* Max serialized result size in bytes before the SDK truncates it to a
|
|
727
|
+
* flagged preview (default: `AgoConfig.maxFunctionResultBytes`, 50 000).
|
|
728
|
+
* `Infinity` disables the guard for this function.
|
|
729
|
+
*/
|
|
730
|
+
maxResultBytes?: number;
|
|
717
731
|
}
|
|
718
732
|
|
|
719
733
|
/**
|
|
@@ -728,6 +742,20 @@ declare interface ClientFunctionInvocation {
|
|
|
728
742
|
conversationId: string;
|
|
729
743
|
}
|
|
730
744
|
|
|
745
|
+
/**
|
|
746
|
+
* Schema-plus-settings object accepted when registering a function: the schema
|
|
747
|
+
* (minus `name`) and SDK-side options that are NOT sent to the backend.
|
|
748
|
+
*/
|
|
749
|
+
declare type ClientFunctionRegisterOptions = Omit<ClientFunctionSchema, "name"> & {
|
|
750
|
+
/**
|
|
751
|
+
* Max serialized result size in bytes before the SDK truncates it to a
|
|
752
|
+
* flagged preview. Overrides the client-level default
|
|
753
|
+
* (`AgoConfig.maxFunctionResultBytes`, 50 000 by default). `Infinity`
|
|
754
|
+
* disables the guard for this function.
|
|
755
|
+
*/
|
|
756
|
+
maxResultBytes?: number;
|
|
757
|
+
};
|
|
758
|
+
|
|
731
759
|
/**
|
|
732
760
|
* Schema for a client-side function that AGO can call
|
|
733
761
|
*/
|
|
@@ -1283,20 +1311,8 @@ export declare function useAgo(config: UseAgoOptions | null): {
|
|
|
1283
1311
|
* Auto-continue the agent after it navigates, so a "go to page B and change X"
|
|
1284
1312
|
* request completes in one user gesture. Mount this once inside `AgoProvider`.
|
|
1285
1313
|
*
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
* - **Pause mode** (`clientFunctionsMode: "pause"`): the backend pauses the turn
|
|
1289
|
-
* on the navigation call (`message:waiting-client`) and the SDK resumes it once
|
|
1290
|
-
* the result is submitted. This hook only registers a *resume gate* that delays
|
|
1291
|
-
* the resume until the destination page's `useAgoPageState` registered (plus a
|
|
1292
|
-
* settle delay), so the continued turn ships the new page's `setPageState` and
|
|
1293
|
-
* current state. Same turn, no extra prompt, backend budget as the guardrail —
|
|
1294
|
-
* `continuationPrompt` and `maxDepth` are unused here.
|
|
1295
|
-
*
|
|
1296
|
-
* - **Placeholder mode** (legacy default): when the agent calls the navigation
|
|
1297
|
-
* function and that turn ends, this waits for the destination page's state to
|
|
1298
|
-
* register, then sends a hidden continuation message; the agent applies the
|
|
1299
|
-
* state in a second turn (requires backend support for the `hidden` flag).
|
|
1314
|
+
* React binding of {@link attachAutoContinueAfterNavigation} — see it for the
|
|
1315
|
+
* pause-mode / placeholder-mode mechanics.
|
|
1300
1316
|
*
|
|
1301
1317
|
* ```tsx
|
|
1302
1318
|
* function AppShell() {
|
|
@@ -1399,6 +1415,12 @@ export declare interface UseAgoFunctionOptions {
|
|
|
1399
1415
|
required?: string[];
|
|
1400
1416
|
};
|
|
1401
1417
|
handler: ClientFunctionHandler;
|
|
1418
|
+
/**
|
|
1419
|
+
* Max serialized result size in bytes before the SDK truncates it to a
|
|
1420
|
+
* flagged preview (default: `AgoConfig.maxFunctionResultBytes`, 50 000).
|
|
1421
|
+
* `Infinity` disables the guard for this function.
|
|
1422
|
+
*/
|
|
1423
|
+
maxResultBytes?: number;
|
|
1402
1424
|
}
|
|
1403
1425
|
|
|
1404
1426
|
/**
|