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