@useago/sdk 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AgoClient-BrhKkDWt.js → AgoClient-BdtuHX7k.js} +49 -25
- package/dist/{AgoClient-B2BU8tfB.cjs → AgoClient-CRAnT4qE.cjs} +4 -4
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +12 -0
- package/dist/angular.d.ts +12 -0
- package/dist/angular.js +4 -1
- package/dist/{createConversationSession-Cin8dVNq.cjs → createConversationSession-B8zfTL78.cjs} +1 -1
- package/dist/{createConversationSession-ByePKfus.js → createConversationSession-CWpf4u6I.js} +1 -1
- package/dist/{createFormCollector-BYKe5Uxm.js → createFormCollector-B4n0_diV.js} +1 -1
- package/dist/{createFormCollector-CpYX_5PT.cjs → createFormCollector-BB_l0Sia.cjs} +1 -1
- package/dist/{createMockClient-DwdxNwEn.js → createMockClient-d-arlmCq.js} +19 -17
- package/dist/createMockClient-ucPENDzz.cjs +1 -0
- package/dist/devtools.d.cts +10 -0
- package/dist/devtools.d.ts +10 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +4 -4
- package/dist/react.cjs +3 -3
- package/dist/react.d.cts +10 -0
- package/dist/react.d.ts +10 -0
- package/dist/react.js +135 -128
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +10 -0
- package/dist/testing.d.ts +10 -0
- package/dist/testing.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +10 -0
- package/dist/vue.d.ts +10 -0
- package/dist/vue.js +14 -14
- package/dist/widget.cjs +1 -1
- package/dist/widget.d.cts +10 -0
- package/dist/widget.d.ts +10 -0
- package/dist/widget.js +3 -3
- package/package.json +1 -1
- package/dist/createMockClient-zHQ0cjUH.cjs +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -157,6 +157,12 @@ export declare class AgoClient {
|
|
|
157
157
|
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
158
158
|
/**
|
|
159
159
|
* Register a navigation function that lets AGO navigate users to different pages.
|
|
160
|
+
*
|
|
161
|
+
* Also registers a dynamic context entry (`current-page`) that reports the page
|
|
162
|
+
* the user is currently on, by route name, on every message. This is what lets
|
|
163
|
+
* the agent know *where* it is after it navigates (e.g. so auto-continuation
|
|
164
|
+
* can apply page state on the destination), not just how to navigate away.
|
|
165
|
+
*
|
|
160
166
|
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
161
167
|
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
162
168
|
*/
|
|
@@ -165,6 +171,10 @@ export declare class AgoClient {
|
|
|
165
171
|
path: string;
|
|
166
172
|
description: string;
|
|
167
173
|
}>): void;
|
|
174
|
+
/**
|
|
175
|
+
* Unregister the navigation function and its `current-page` context provider.
|
|
176
|
+
*/
|
|
177
|
+
unregisterNavigationFunction(): void;
|
|
168
178
|
/**
|
|
169
179
|
* Register a "page state" function that lets AGO change the current page's
|
|
170
180
|
* state (filters, sort, view mode, selection…) and reads the current state
|
package/dist/index.d.ts
CHANGED
|
@@ -157,6 +157,12 @@ export declare class AgoClient {
|
|
|
157
157
|
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
158
158
|
/**
|
|
159
159
|
* Register a navigation function that lets AGO navigate users to different pages.
|
|
160
|
+
*
|
|
161
|
+
* Also registers a dynamic context entry (`current-page`) that reports the page
|
|
162
|
+
* the user is currently on, by route name, on every message. This is what lets
|
|
163
|
+
* the agent know *where* it is after it navigates (e.g. so auto-continuation
|
|
164
|
+
* can apply page state on the destination), not just how to navigate away.
|
|
165
|
+
*
|
|
160
166
|
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
161
167
|
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
162
168
|
*/
|
|
@@ -165,6 +171,10 @@ export declare class AgoClient {
|
|
|
165
171
|
path: string;
|
|
166
172
|
description: string;
|
|
167
173
|
}>): void;
|
|
174
|
+
/**
|
|
175
|
+
* Unregister the navigation function and its `current-page` context provider.
|
|
176
|
+
*/
|
|
177
|
+
unregisterNavigationFunction(): void;
|
|
168
178
|
/**
|
|
169
179
|
* Register a "page state" function that lets AGO change the current page's
|
|
170
180
|
* state (filters, sort, view mode, selection…) and reads the current state
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as h, c as A, d as y, f as C, i as E, l as S, m as b, o as v, p as F, r as M, s as I, t as k, u as T } from "./functions-CApuQZ2b.js";
|
|
2
|
-
import { _ as G, a as O, c as _, d as q, f as x, g as L, h as N, l as D, m as d, n as H, o as J, p as R, r as j, s as z, t as c, u as B } from "./AgoClient-
|
|
3
|
-
import { i as $, n as K, r as Q, t as V } from "./createFormCollector-
|
|
4
|
-
import { t as X } from "./createConversationSession-
|
|
5
|
-
import { t as Z } from "./createMockClient-
|
|
2
|
+
import { _ as G, a as O, c as _, d as q, f as x, g as L, h as N, l as D, m as d, n as H, o as J, p as R, r as j, s as z, t as c, u as B } from "./AgoClient-BdtuHX7k.js";
|
|
3
|
+
import { i as $, n as K, r as Q, t as V } from "./createFormCollector-B4n0_diV.js";
|
|
4
|
+
import { t as X } from "./createConversationSession-CWpf4u6I.js";
|
|
5
|
+
import { t as Z } from "./createMockClient-d-arlmCq.js";
|
|
6
6
|
import "./testing.js";
|
|
7
7
|
function oe(e) {
|
|
8
8
|
return e;
|
package/dist/react.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./rolldown-runtime-16Nf8qvH.cjs"),
|
|
2
|
-
`)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),oe=({children:e,...t})=>(0,o.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),se=({children:e,...t})=>(0,o.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,o.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),ae=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ie=({children:e,...t})=>(0,o.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,o.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ce=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),de={a:X,p:Q,h1:A(1,"20px"),h2:A(2,"18px"),h3:A(3,"16px"),h4:A(4,"15px"),h5:A(5,"14px"),h6:A(6,"13px"),ul:Z,ol:ee,li:te,code:ne,pre:re,blockquote:oe,table:se,th:ae,td:ie,img:le,hr:ce},ue=[N.default],q=({content:e})=>(0,o.jsx)(_.default,{remarkPlugins:ue,components:de,children:e}),fe=({attachment:e,isUser:t})=>{const r=
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./rolldown-runtime-16Nf8qvH.cjs"),R=require("./AgoClient-CRAnT4qE.cjs"),M=require("./createFormCollector-BB_l0Sia.cjs"),V=require("./createMockClient-ucPENDzz.cjs");let s=require("react");s=T.__toESM(s,1);let o=require("react/jsx-runtime"),_=require("react-markdown");_=T.__toESM(_,1);let N=require("remark-gfm");N=T.__toESM(N,1);function O(e){const[t,r]=(0,s.useState)(!1),n=(0,s.useRef)(null),a=(0,s.useMemo)(()=>{if(n.current&&(n.current.destroy(),n.current=null),!e)return null;const l=new R.AgoClient(e);return n.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(r(!0),()=>{n.current?.destroy(),n.current=null}),[a]),(0,s.useEffect)(()=>{n.current&&e&&n.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var D=(0,s.createContext)(null),Y=({children:e,client:t,tools:r,helpers:n,pageContext:a,...l})=>{const{client:d}=O(t?null:l),c=t||d;return(0,s.useEffect)(()=>{if(!(!r||r.length===0)){for(const p of r)c.register(p);return()=>{for(const p of r)c.unregisterFunction(p.name)}}},[c,r]),(0,s.useEffect)(()=>{if(!n)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(f=>f.functions_exports).then(f=>{for(const[v,x]of Object.entries(n)){const y=f[v];if(!y){console.warn(`[AGO] Unknown helper: "${v}"`);continue}const h=x===!0?y:{...y,handler:x};c.register(h),p.push(h.name)}}),()=>{for(const f of p)c.unregisterFunction(f)}},[c,n]),(0,s.useEffect)(()=>{a==="auto"&&c.enableAutoPageContext()},[c,a]),(0,o.jsx)(D.Provider,{value:c,children:e})};function I(){const e=(0,s.useContext)(D);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function F(){return(0,s.useContext)(D)}function z({client:e,conversationId:t}={}){const r=F(),n=e||r;if(!n)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(t),[p,f]=(0,s.useState)(!1),[v,x]=(0,s.useState)(null);(0,s.useEffect)(()=>{t&&t!==d&&(c(t),y(t))},[t]);const y=async h=>{try{l((await n.getMessages(h)).filter(m=>!m.hidden))}catch(m){x(m instanceof Error?m:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const h=g=>{d||c(g.conversationId),f(!0),l(u=>u.some(b=>b.role==="assistant"&&b.status==="IN_PROGRESS")?u:[...u,{id:g.messageId,conversationId:g.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}])},m=g=>{l(u=>{const b=u[u.length-1];return b&&b.id===g.messageId?[...u.slice(0,-1),{...b,content:b.content+g.content}]:u})},C=g=>{l(u=>{let b=-1;for(let k=u.length-1;k>=0;k--)if(u[k].role==="assistant"&&u[k].status==="IN_PROGRESS"){b=k;break}return b<0?u:[...u.slice(0,b),{...u[b],...g},...u.slice(b+1)]})},w=g=>{l(u=>{const b=u.findIndex(k=>k.id===g.id);return b>=0?[...u.slice(0,b),g,...u.slice(b+1)]:[...u,g]}),f(!1)},i=g=>{x(new Error(g.error)),f(!1)};return n.on("message:start",h),n.on("message:chunk",m),n.on("message:answer-complete",C),n.on("message:complete",w),n.on("message:error",i),()=>{n.off("message:start",h),n.off("message:chunk",m),n.off("message:answer-complete",C),n.off("message:complete",w),n.off("message:error",i)}},[n,d]),{messages:a,isLoading:p,error:v,sendMessage:(0,s.useCallback)(async(h,m)=>{f(!0),x(null);const C={id:`temp-${Date.now()}`,conversationId:d||"",content:h,role:"user",status:"DONE",attachments:m&&m.length>0?R.attachmentsFromFiles(m):void 0,createdAt:new Date},w={id:`temp-assistant-${Date.now()}`,conversationId:d||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(i=>[...i,C,w]);try{const i=await n.sendMessage(h,{conversationId:d,files:m});return i.conversationId&&!d&&c(i.conversationId),l(g=>{const u=g.filter(k=>!k.id.startsWith("temp-")),b={...C,id:C.id.replace("temp-","user-"),conversationId:i.conversationId};return u.some(k=>k.id===i.id)?[...u,b].sort((k,P)=>new Date(k.createdAt).getTime()-new Date(P.createdAt).getTime()):[...u,b,i]}),i}catch(i){return x(i instanceof Error?i:new Error("Failed to send message")),f(!1),l(g=>g.filter(u=>!u.id.startsWith("temp-"))),null}},[n,d]),clearMessages:(0,s.useCallback)(()=>{l([]),c(void 0),x(null)},[]),conversationId:d}}var H=({onSend:e,disabled:t=!1,placeholder:r="Type a message...",allowFiles:n=!1,className:a=""})=>{const[l,d]=(0,s.useState)(""),[c,p]=(0,s.useState)([]),f=(0,s.useRef)(null),v=(0,s.useRef)(null),x=(0,s.useCallback)(()=>{const i=v.current;if(!i)return;const g=110;i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight+2,g)}px`,i.style.overflowY=i.scrollHeight+2>g?"auto":"hidden"},[]),y=(0,s.useCallback)(i=>{i.preventDefault(),(l.trim()||c.length>0)&&(e(l.trim(),c.length>0?c:void 0),d(""),p([]),requestAnimationFrame(x))},[l,c,e,x]),h=(0,s.useCallback)(i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),y(i))},[y]),m=(0,s.useCallback)(i=>{const g=Array.from(i.target.files||[]);p(u=>[...u,...g])},[]),C=(0,s.useCallback)(i=>{p(g=>g.filter((u,b)=>b!==i))},[]),w=l.trim()||c.length>0;return(0,o.jsxs)("form",{onSubmit:y,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[c.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((i,g)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.name}),(0,o.jsx)("button",{type:"button",onClick:()=>C(g),"aria-label":`Remove ${i.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},g))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[n&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>f.current?.click(),disabled:t,"aria-label":"Attach file",style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:f,type:"file",multiple:!0,onChange:m,style:{display:"none"}})]}),(0,o.jsx)("textarea",{ref:v,value:l,onChange:i=>{d(i.target.value),x()},onKeyDown:h,placeholder:r,"aria-label":r,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:i=>{i.currentTarget.style.borderColor="#1b5fc4"},onBlur:i=>{i.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!w,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!w?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!w?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...r})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...r,children:t}),Q=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),A=(e,t)=>{const r=({children:n,...a})=>s.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},n);return r.displayName=`MarkdownHeading${e}`,r},Z=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),te=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),ne=({className:e,children:t,...r})=>e!==void 0||String(t).includes(`
|
|
2
|
+
`)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),oe=({children:e,...t})=>(0,o.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),se=({children:e,...t})=>(0,o.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,o.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),ae=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ie=({children:e,...t})=>(0,o.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,o.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ce=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),de={a:X,p:Q,h1:A(1,"20px"),h2:A(2,"18px"),h3:A(3,"16px"),h4:A(4,"15px"),h5:A(5,"14px"),h6:A(6,"13px"),ul:Z,ol:ee,li:te,code:ne,pre:re,blockquote:oe,table:se,th:ae,td:ie,img:le,hr:ce},ue=[N.default],q=({content:e})=>(0,o.jsx)(_.default,{remarkPlugins:ue,components:de,children:e}),fe=({attachment:e,isUser:t})=>{const r=R.safeAttachmentUrl(e.url);if(R.canInlineImage(e))return(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,o.jsx)("img",{src:r,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const n=R.formatFileSize(e.fileSize),a=(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,o.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,o.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),n&&(0,o.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:n})]})]}),l={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:t?"rgba(255,255,255,0.12)":"#fff",color:t?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return r?(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:l,children:a}):(0,o.jsx)("div",{style:l,children:a})},ge=({source:e,index:t})=>{const r=(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,o.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:t+1}),(0,o.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),n={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,o.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:n,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:r}):(0,o.jsx)("div",{style:n,children:r})},pe=()=>(0,o.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,o.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,o.jsx)("style",{children:`
|
|
3
3
|
@keyframes ago-pulse {
|
|
4
4
|
0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
|
|
5
5
|
40% { opacity: 1; transform: scale(1); }
|
|
6
6
|
}
|
|
7
|
-
`})]}),$=({message:e,className:t="",showAgentName:r=!1,isLast:n=!1,onFollowUpClick:a})=>{const l=e.role==="user",d=e.status==="IN_PROGRESS";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&r&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((c,p)=>(0,o.jsx)(ge,{source:c,index:p},c.id))}),e.attachments&&e.attachments.length>0&&(0,o.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:l?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(c=>(0,o.jsx)(fe,{attachment:c,isUser:l},c.id))}),(e.content||d)&&(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(q,{content:e.content}):d&&(0,o.jsx)(pe,{})}),n&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:u=>{u.currentTarget.style.borderColor="#dee3e8"},children:c},p))})]})},xe=({client:e,conversationId:t,title:r="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:d=500,logoUrl:c,showAgentName:p=!1,forms:u,onFollowUpClick:b,className:x="",onMessageSent:y,onMessageReceived:h})=>{const m=(0,s.useRef)(null),C=R(),v=e??C,{messages:i,isLoading:g,error:f,sendMessage:w}=z({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!v||!u||u.length===0)return;let S=!1;const I=[];return Promise.all(u.map(j=>j.schema!=null?Promise.resolve(M.createFormCollector(j)):M.loadFormCollector(v,j))).then(j=>{if(!S)for(const V of j)I.push(V.install(v))}).catch(()=>{}),()=>{S=!0,I.forEach(j=>j())}},[v,u?JSON.stringify(u.map(S=>[S.name,S.schema??null,S.submit??!1,S.description??null])):""]),(0,s.useEffect)(()=>{m.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,s.useEffect)(()=>{const S=i[i.length-1];S&&S.role==="assistant"&&S.status==="DONE"&&h&&h({id:S.id,content:S.content})},[i,h]);const k=async(S,I)=>{y?.(S),await w(S,I)},P=i[i.length-1],K=g&&P?.role==="assistant"&&P.status==="IN_PROGRESS",J=b===!1?void 0:b??(S=>k(S));return(0,o.jsxs)("div",{className:`ago-chat-widget ${x}`,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[c&&(0,o.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:r})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[i.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:n}):i.map((S,I)=>(0,o.jsx)($,{message:S,showAgentName:p,isLast:I===i.length-1,onFollowUpClick:J},S.id)),f&&(0,o.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:f.message}),(0,o.jsx)("div",{ref:m})]}),(0,o.jsx)(O,{onSend:k,disabled:K,placeholder:a,allowFiles:l})]})};function B({client:e,autoLoad:t=!0}={}){const r=R(),n=e||r;if(!n)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[p,u]=(0,s.useState)(!1),[b,x]=(0,s.useState)(null),y=(0,s.useCallback)(async()=>{u(!0),x(null);try{l(await n.getConversations())}catch(C){x(C instanceof Error?C:new Error("Failed to load conversations"))}finally{u(!1)}},[n]),h=(0,s.useCallback)(async C=>{u(!0),x(null);try{c(await n.getConversation(C))}catch(v){x(v instanceof Error?v:new Error("Failed to load conversation"))}finally{u(!1)}},[n]),m=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&y()},[t,y]),{conversations:a,currentConversation:d,isLoading:p,error:b,selectConversation:h,startNewConversation:m,refreshConversations:y}}function me(e={}){const t=R(),r=e.client||t;if(!r)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const n=z({client:r,conversationId:e.conversationId}),a=B({client:r,autoLoad:e.autoLoad});return{messages:n.messages,isLoading:n.isLoading,error:n.error||a.error,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function he(e,t){const r=E(),{name:n,description:a,parameters:l,handler:d}=typeof e=="string"?{name:e,...t}:e,c=(0,s.useRef)(d);c.current=d,(0,s.useEffect)(()=>{const p=u=>c.current(u);return r.registerFunction(n,p,{description:a,parameters:l}),()=>{r.unregisterFunction(n)}},[r,n,a,l])}function ye(e,t){const r=E(),n=(0,s.useRef)(e);n.current=e,(0,s.useEffect)(()=>(r.registerNavigationFunction(a=>n.current(a),t),()=>{r.unregisterFunction("navigateToPage")}),[r,t])}function be(e,t){const r=E(),n=t?.functionName??"setPageState",a=(0,s.useRef)(e);a.current=e,(0,s.useEffect)(()=>{const l=a.current.map(d=>{const c=()=>a.current.find(p=>p.name===d.name)??d;return{name:d.name,description:d.description,schema:d.schema,get:d.get?()=>c().get?.():void 0,set:p=>c().set(p)}});return r.registerPageStateFunction(l,{functionName:n}),()=>{r.unregisterPageStateFunction(n)}},[r,n])}var ve="You have navigated the user to a new page. That page now exposes its editable state through the available setPageState function, and its current values in the page context. If the user's latest request also asked to change something on this page, call setPageState now to apply exactly those changes and nothing else. Otherwise, reply with a short confirmation only.";function W(e){return{navigationFunctions:e?.navigationFunctions??["navigateToPage"],pageStateFunctionName:e?.pageStateFunctionName??"setPageState",continuationPrompt:e?.continuationPrompt??ve,maxDepth:e?.maxDepth??1,readinessTimeoutMs:e?.readinessTimeoutMs??4e3,settleMs:e?.settleMs??150,enabled:e?.enabled??!0}}function Ce(e){const t=E(),r=(0,s.useRef)(W(e));r.current=W(e),(0,s.useEffect)(()=>{const n={navigated:!1,depth:0,runId:0,ourSendPending:!1},a=()=>t.getRegisteredFunctions().some(x=>x.name===r.current.pageStateFunctionName),l=x=>new Promise(y=>{let h=!1;const m=g=>{h||(h=!0,clearTimeout(i),t.off("context:changed",v),y(g))},C=()=>setTimeout(()=>m(x===n.runId&&a()),r.current.settleMs),v=()=>{if(x!==n.runId)return m(!1);a()&&(t.off("context:changed",v),C())},i=setTimeout(()=>m(!1),r.current.readinessTimeoutMs);a()?C():t.on("context:changed",v)}),d=async x=>{const y=++n.runId;if(!(!await l(y)||y!==n.runId)){n.depth+=1,n.ourSendPending=!0;try{await t.sendMessage(r.current.continuationPrompt,{conversationId:x,hidden:!0})}catch{n.ourSendPending=!1}}},c=x=>{r.current.navigationFunctions.includes(x.functionName)&&(n.navigated=!0)},p=()=>{n.ourSendPending||(n.depth=0,n.runId+=1)},u=x=>{n.ourSendPending=!1;const y=n.navigated;n.navigated=!1,r.current.enabled&&y&&(n.depth>=r.current.maxDepth||d(x.conversationId))},b=()=>{n.ourSendPending=!1};return t.on("function:invoke",c),t.on("message:start",p),t.on("message:complete",u),t.on("message:error",b),()=>{n.runId+=1,t.off("function:invoke",c),t.off("message:start",p),t.off("message:complete",u),t.off("message:error",b)}},[t])}function we(e,t){const r=E(),n=(0,s.useId)(),a=t??n,l=(0,s.useRef)(e);l.current=e;const d=typeof e=="function";(0,s.useEffect)(()=>{if(typeof l.current=="function"){const c=()=>l.current();return r.addDynamicContext(a,c),()=>{r.removeDynamicContext(a)}}return r.setContext(a,l.current),()=>{r.removeContext(a)}},[r,a,d,d?"":JSON.stringify(e)])}function U(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var L={missing:[],complete:!1};function Se(e){const t=E(),r=e.schema!=null,n=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",d=JSON.stringify(e.initialValues??null),c=(0,s.useMemo)(()=>r?M.createFormCollector(e):null,[r,e.name,n,l,d,e.autoSubmit]),[p,u]=(0,s.useState)({collector:null,loading:!r,error:null});(0,s.useEffect)(()=>{if(r)return;let g=!1;return u({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(f=>{g||u({collector:f,loading:!1,error:null})}).catch(f=>{g||u({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{g=!0}},[t,r,e.name,l,d,e.autoSubmit]);const b=r?c:p.collector,x=r?!1:p.loading,y=r?null:p.error;(0,s.useEffect)(()=>{if(b)return b.install(t)},[t,b]);const h=(0,s.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[d]),m=U(b?.store??h),C=(0,s.useMemo)(()=>b?.getStatus()??L,[m,b]),v=(0,s.useMemo)(()=>({...m,...C}),[m,C]),i=(0,s.useMemo)(()=>({name:e.name,store:h,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>h.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>L}),[e.name,h]);return{...b??i,state:v,loading:x,error:y}}exports.AgoProvider=Y;exports.ChatInput=O;exports.ChatWidget=xe;exports.Markdown=q;exports.Message=$;exports.createFormCollector=M.createFormCollector;exports.createMockClient=G.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=H;exports.useAgoAutoContinueAfterNavigation=Ce;exports.useAgoClient=E;exports.useAgoContext=we;exports.useAgoFunction=he;exports.useAgoNavigation=ye;exports.useAgoPageState=be;exports.useAgoStore=U;exports.useChat=me;exports.useConversation=B;exports.useFormCollector=Se;exports.useMessages=z;exports.useOptionalAgoClient=R;
|
|
7
|
+
`})]}),$=({message:e,className:t="",showAgentName:r=!1,isLast:n=!1,onFollowUpClick:a})=>{const l=e.role==="user",d=e.status==="IN_PROGRESS";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&r&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((c,p)=>(0,o.jsx)(ge,{source:c,index:p},c.id))}),e.attachments&&e.attachments.length>0&&(0,o.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:l?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(c=>(0,o.jsx)(fe,{attachment:c,isUser:l},c.id))}),(e.content||d)&&(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(q,{content:e.content}):d&&(0,o.jsx)(pe,{})}),n&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:f=>{f.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:f=>{f.currentTarget.style.borderColor="#dee3e8"},children:c},p))})]})},xe=({client:e,conversationId:t,title:r="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:d=500,logoUrl:c,showAgentName:p=!1,forms:f,onFollowUpClick:v,className:x="",onMessageSent:y,onMessageReceived:h})=>{const m=(0,s.useRef)(null),C=F(),w=e??C,{messages:i,isLoading:g,error:u,sendMessage:b}=z({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!w||!f||f.length===0)return;let S=!1;const E=[];return Promise.all(f.map(j=>j.schema!=null?Promise.resolve(M.createFormCollector(j)):M.loadFormCollector(w,j))).then(j=>{if(!S)for(const J of j)E.push(J.install(w))}).catch(()=>{}),()=>{S=!0,E.forEach(j=>j())}},[w,f?JSON.stringify(f.map(S=>[S.name,S.schema??null,S.submit??!1,S.description??null])):""]),(0,s.useEffect)(()=>{m.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,s.useEffect)(()=>{const S=i[i.length-1];S&&S.role==="assistant"&&S.status==="DONE"&&h&&h({id:S.id,content:S.content})},[i,h]);const k=async(S,E)=>{y?.(S),await b(S,E)},P=i[i.length-1],K=g&&P?.role==="assistant"&&P.status==="IN_PROGRESS",G=v===!1?void 0:v??(S=>k(S));return(0,o.jsxs)("div",{className:`ago-chat-widget ${x}`,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[c&&(0,o.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:r})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[i.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:n}):i.map((S,E)=>(0,o.jsx)($,{message:S,showAgentName:p,isLast:E===i.length-1,onFollowUpClick:G},S.id)),u&&(0,o.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:u.message}),(0,o.jsx)("div",{ref:m})]}),(0,o.jsx)(H,{onSend:k,disabled:K,placeholder:a,allowFiles:l})]})};function B({client:e,autoLoad:t=!0}={}){const r=F(),n=e||r;if(!n)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[p,f]=(0,s.useState)(!1),[v,x]=(0,s.useState)(null),y=(0,s.useCallback)(async()=>{f(!0),x(null);try{l(await n.getConversations())}catch(C){x(C instanceof Error?C:new Error("Failed to load conversations"))}finally{f(!1)}},[n]),h=(0,s.useCallback)(async C=>{f(!0),x(null);try{c(await n.getConversation(C))}catch(w){x(w instanceof Error?w:new Error("Failed to load conversation"))}finally{f(!1)}},[n]),m=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&y()},[t,y]),{conversations:a,currentConversation:d,isLoading:p,error:v,selectConversation:h,startNewConversation:m,refreshConversations:y}}function me(e={}){const t=F(),r=e.client||t;if(!r)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const n=z({client:r,conversationId:e.conversationId}),a=B({client:r,autoLoad:e.autoLoad});return{messages:n.messages,isLoading:n.isLoading,error:n.error||a.error,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function he(e,t){const r=I(),{name:n,description:a,parameters:l,handler:d}=typeof e=="string"?{name:e,...t}:e,c=(0,s.useRef)(d);c.current=d,(0,s.useEffect)(()=>{const p=f=>c.current(f);return r.registerFunction(n,p,{description:a,parameters:l}),()=>{r.unregisterFunction(n)}},[r,n,a,l])}function ye(e,t){const r=I(),n=(0,s.useRef)(e);n.current=e,(0,s.useEffect)(()=>(r.registerNavigationFunction(a=>n.current(a),t),()=>{r.unregisterNavigationFunction()}),[r,t])}function be(e,t){const r=I(),n=t?.functionName??"setPageState",a=(0,s.useRef)(e);a.current=e,(0,s.useEffect)(()=>{const l=a.current.map(d=>{const c=()=>a.current.find(p=>p.name===d.name)??d;return{name:d.name,description:d.description,schema:d.schema,get:d.get?()=>c().get?.():void 0,set:p=>c().set(p)}});return r.registerPageStateFunction(l,{functionName:n}),()=>{r.unregisterPageStateFunction(n)}},[r,n])}var ve="You have navigated the user to a new page. That page now exposes its editable state through the available setPageState function, and its current values in the page context. If the user's latest request also asked to change something on this page, call setPageState now to apply exactly those changes and nothing else. Otherwise, reply with a short confirmation only.";function W(e){return{navigationFunctions:e?.navigationFunctions??["navigateToPage"],pageStateFunctionName:e?.pageStateFunctionName??"setPageState",continuationPrompt:e?.continuationPrompt??ve,maxDepth:e?.maxDepth??1,readinessTimeoutMs:e?.readinessTimeoutMs??4e3,settleMs:e?.settleMs??150,enabled:e?.enabled??!0}}function we(e){const t=I(),r=(0,s.useRef)(W(e));r.current=W(e),(0,s.useEffect)(()=>{const n={navigated:!1,depth:0,runId:0,ourSendPending:!1},a=()=>t.getRegisteredFunctions().some(x=>x.name===r.current.pageStateFunctionName),l=x=>new Promise(y=>{let h=!1;const m=g=>{h||(h=!0,clearTimeout(i),t.off("context:changed",w),y(g))},C=()=>setTimeout(()=>m(x===n.runId&&a()),r.current.settleMs),w=()=>{if(x!==n.runId)return m(!1);a()&&(t.off("context:changed",w),C())},i=setTimeout(()=>m(!1),r.current.readinessTimeoutMs);a()?C():t.on("context:changed",w)}),d=async x=>{const y=++n.runId;if(!(!await l(y)||y!==n.runId)){n.depth+=1,n.ourSendPending=!0;try{await t.sendMessage(r.current.continuationPrompt,{conversationId:x,hidden:!0})}catch{n.ourSendPending=!1}}},c=x=>{r.current.navigationFunctions.includes(x.functionName)&&(n.navigated=!0)},p=()=>{n.ourSendPending||(n.depth=0,n.runId+=1)},f=x=>{n.ourSendPending=!1;const y=n.navigated;n.navigated=!1,r.current.enabled&&y&&(n.depth>=r.current.maxDepth||d(x.conversationId))},v=()=>{n.ourSendPending=!1};return t.on("function:invoke",c),t.on("message:start",p),t.on("message:complete",f),t.on("message:error",v),()=>{n.runId+=1,t.off("function:invoke",c),t.off("message:start",p),t.off("message:complete",f),t.off("message:error",v)}},[t])}function Ce(e,t){const r=I(),n=(0,s.useId)(),a=t??n,l=(0,s.useRef)(e);l.current=e;const d=typeof e=="function";(0,s.useEffect)(()=>{if(typeof l.current=="function"){const c=()=>l.current();return r.addDynamicContext(a,c),()=>{r.removeDynamicContext(a)}}return r.setContext(a,l.current),()=>{r.removeContext(a)}},[r,a,d,d?"":JSON.stringify(e)])}function U(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var L={missing:[],complete:!1};function Se(e){const t=I(),r=e.schema!=null,n=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",d=JSON.stringify(e.initialValues??null),c=(0,s.useMemo)(()=>r?M.createFormCollector(e):null,[r,e.name,n,l,d,e.autoSubmit]),[p,f]=(0,s.useState)({collector:null,loading:!r,error:null});(0,s.useEffect)(()=>{if(r)return;let g=!1;return f({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(u=>{g||f({collector:u,loading:!1,error:null})}).catch(u=>{g||f({collector:null,loading:!1,error:u instanceof Error?u:new Error(String(u))})}),()=>{g=!0}},[t,r,e.name,l,d,e.autoSubmit]);const v=r?c:p.collector,x=r?!1:p.loading,y=r?null:p.error;(0,s.useEffect)(()=>{if(v)return v.install(t)},[t,v]);const h=(0,s.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[d]),m=U(v?.store??h),C=(0,s.useMemo)(()=>v?.getStatus()??L,[m,v]),w=(0,s.useMemo)(()=>({...m,...C}),[m,C]),i=(0,s.useMemo)(()=>({name:e.name,store:h,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>h.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>L}),[e.name,h]);return{...v??i,state:w,loading:x,error:y}}exports.AgoProvider=Y;exports.ChatInput=H;exports.ChatWidget=xe;exports.Markdown=q;exports.Message=$;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=O;exports.useAgoAutoContinueAfterNavigation=we;exports.useAgoClient=I;exports.useAgoContext=Ce;exports.useAgoFunction=he;exports.useAgoNavigation=ye;exports.useAgoPageState=be;exports.useAgoStore=U;exports.useChat=me;exports.useConversation=B;exports.useFormCollector=Se;exports.useMessages=z;exports.useOptionalAgoClient=F;
|
package/dist/react.d.cts
CHANGED
|
@@ -165,6 +165,12 @@ declare class AgoClient {
|
|
|
165
165
|
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
166
166
|
/**
|
|
167
167
|
* Register a navigation function that lets AGO navigate users to different pages.
|
|
168
|
+
*
|
|
169
|
+
* Also registers a dynamic context entry (`current-page`) that reports the page
|
|
170
|
+
* the user is currently on, by route name, on every message. This is what lets
|
|
171
|
+
* the agent know *where* it is after it navigates (e.g. so auto-continuation
|
|
172
|
+
* can apply page state on the destination), not just how to navigate away.
|
|
173
|
+
*
|
|
168
174
|
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
169
175
|
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
170
176
|
*/
|
|
@@ -173,6 +179,10 @@ declare class AgoClient {
|
|
|
173
179
|
path: string;
|
|
174
180
|
description: string;
|
|
175
181
|
}>): void;
|
|
182
|
+
/**
|
|
183
|
+
* Unregister the navigation function and its `current-page` context provider.
|
|
184
|
+
*/
|
|
185
|
+
unregisterNavigationFunction(): void;
|
|
176
186
|
/**
|
|
177
187
|
* Register a "page state" function that lets AGO change the current page's
|
|
178
188
|
* state (filters, sort, view mode, selection…) and reads the current state
|
package/dist/react.d.ts
CHANGED
|
@@ -165,6 +165,12 @@ declare class AgoClient {
|
|
|
165
165
|
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
166
166
|
/**
|
|
167
167
|
* Register a navigation function that lets AGO navigate users to different pages.
|
|
168
|
+
*
|
|
169
|
+
* Also registers a dynamic context entry (`current-page`) that reports the page
|
|
170
|
+
* the user is currently on, by route name, on every message. This is what lets
|
|
171
|
+
* the agent know *where* it is after it navigates (e.g. so auto-continuation
|
|
172
|
+
* can apply page state on the destination), not just how to navigate away.
|
|
173
|
+
*
|
|
168
174
|
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
169
175
|
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
170
176
|
*/
|
|
@@ -173,6 +179,10 @@ declare class AgoClient {
|
|
|
173
179
|
path: string;
|
|
174
180
|
description: string;
|
|
175
181
|
}>): void;
|
|
182
|
+
/**
|
|
183
|
+
* Unregister the navigation function and its `current-page` context provider.
|
|
184
|
+
*/
|
|
185
|
+
unregisterNavigationFunction(): void;
|
|
176
186
|
/**
|
|
177
187
|
* Register a "page state" function that lets AGO change the current page's
|
|
178
188
|
* state (filters, sort, view mode, selection…) and reads the current state
|