@useago/sdk 1.5.6 → 1.7.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 +223 -0
- package/README.md +59 -0
- package/dist/AgoClient-BHegN73y.cjs +9 -0
- package/dist/{AgoClient-B_R_qi2s.js → AgoClient-PWPaekcg.js} +656 -387
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +230 -5
- package/dist/angular.d.ts +230 -5
- package/dist/angular.js +10 -1
- package/dist/{createConversationSession-Dqh7NXK4.cjs → createConversationSession-BbUUukV0.cjs} +1 -1
- package/dist/{createConversationSession-CdtI4vrf.js → createConversationSession-BkruoOVm.js} +1 -1
- package/dist/{createFormCollector-BjO3oB63.cjs → createFormCollector-C1ixsjV0.cjs} +1 -1
- package/dist/{createFormCollector-YwaZ78wU.js → createFormCollector-CvVFNkp6.js} +1 -1
- package/dist/{createMockClient-DcuNlufr.js → createMockClient-BDLW6tVc.js} +5 -2
- package/dist/createMockClient-BSNuN3ys.cjs +1 -0
- package/dist/devtools.d.cts +220 -5
- package/dist/devtools.d.ts +220 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +238 -6
- package/dist/index.d.ts +238 -6
- package/dist/index.js +111 -109
- package/dist/react.cjs +40 -3
- package/dist/react.d.cts +419 -7
- package/dist/react.d.ts +419 -7
- package/dist/react.js +1195 -743
- package/dist/sheetController-CBUVOroo.js +205 -0
- package/dist/sheetController-DY-sC13T.cjs +1 -0
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +220 -5
- package/dist/testing.d.ts +220 -5
- package/dist/testing.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +235 -5
- package/dist/vue.d.ts +235 -5
- package/dist/vue.js +121 -100
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +328 -5
- package/dist/widget.d.ts +328 -5
- package/dist/widget.js +721 -629
- package/llms-full.txt +202 -14
- package/package.json +1 -1
- package/dist/AgoClient-DLB9icvv.cjs +0 -8
- package/dist/createMockClient-Dw-cyISN.cjs +0 -1
package/dist/react.cjs
CHANGED
|
@@ -1,7 +1,44 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Q=Object.create,T=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=Object.getOwnPropertyNames,ne=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty,oe=(e,n)=>{let t={};for(var o in e)T(t,o,{get:e[o],enumerable:!0});return n||T(t,Symbol.toStringTag,{value:"Module"}),t},se=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(var r=te(n),i=0,u=r.length,s;i<u;i++)s=r[i],!re.call(e,s)&&s!==t&&T(e,s,{get:(f=>n[f]).bind(null,s),enumerable:!(o=ee(n,s))||o.enumerable});return e},O=(e,n,t)=>(t=e!=null?Q(ne(e)):{},se(n||!e||!e.__esModule?T(t,"default",{value:e,enumerable:!0}):t,e));const _=require("./AgoClient-DLB9icvv.cjs"),ae=require("./autoContinue-CP9pJR-V.cjs"),M=require("./createFormCollector-BjO3oB63.cjs"),ie=require("./createMockClient-Dw-cyISN.cjs");let a=require("react");a=O(a,1);let l=require("react/jsx-runtime"),D=require("react-markdown");D=O(D,1);let W=require("remark-gfm");W=O(W,1);function B(e){const[n,t]=(0,a.useState)(!1),o=(0,a.useRef)(null),r=(0,a.useMemo)(()=>{if(o.current&&(o.current.destroy(),o.current=null),!e)return null;const i=new _.AgoClient(e);return o.current=i,i},[e?.baseUrl,e?.widgetId]);return(0,a.useEffect)(()=>(r&&o.current===null&&(o.current=r,r.reviveAfterDestroy()),t(!0),()=>{o.current?.destroy(),o.current=null}),[r]),(0,a.useEffect)(()=>{o.current&&e&&o.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:r,isReady:n}}var q=(0,a.createContext)(null),le=({children:e,client:n,tools:t,helpers:o,pageContext:r,...i})=>{const{client:u}=B(n?null:i),s=n||u;return(0,a.useEffect)(()=>{if(!(!t||t.length===0)){for(const f of t)s.register(f);return()=>{for(const f of t)s.unregisterFunction(f.name)}}},[s,t]),(0,a.useEffect)(()=>{if(!o)return;const f=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(d=>d.functions_exports).then(d=>{for(const[m,S]of Object.entries(o)){const I=d[m];if(!I){console.warn(`[AGO] Unknown helper: "${m}"`);continue}const A=S===!0?I:{...I,handler:S};s.register(A),f.push(A.name)}}),()=>{for(const d of f)s.unregisterFunction(d)}},[s,o]),(0,a.useEffect)(()=>{r==="auto"&&s.enableAutoPageContext()},[s,r]),(0,l.jsx)(q.Provider,{value:s,children:e})};function F(){const e=(0,a.useContext)(q);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function E(){return(0,a.useContext)(q)}function z({client:e,conversationId:n}={}){const t=E(),o=e||t;if(!o)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,i]=(0,a.useState)([]),[u,s]=(0,a.useState)(n),[f,d]=(0,a.useState)(!1),[m,S]=(0,a.useState)(null);(0,a.useEffect)(()=>{n&&n!==u&&(s(n),I(n))},[n]);const I=async A=>{try{i((await o.getMessages(A)).filter(k=>!k.hidden))}catch(k){S(k instanceof Error?k:new Error("Failed to load messages"))}};return(0,a.useEffect)(()=>{const A=p=>p==="IN_PROGRESS"||p==="WAITING_CLIENT",k=p=>{u||s(p.conversationId),d(!0),i(y=>{const w=y.findIndex(C=>C.id===p.messageId);return w>=0?y.map((C,R)=>R===w?{...C,status:"IN_PROGRESS"}:C):y.some(C=>C.role==="assistant"&&A(C.status))?y:[...y,{id:p.messageId,conversationId:p.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},g=p=>{i(y=>{const w=y.findIndex(C=>C.id===p.messageId);return w<0?y:y.map((C,R)=>R===w?{...C,content:C.content+p.content}:C)})},h=p=>{i(y=>{let w=-1;for(let C=y.length-1;C>=0;C--)if(y[C].role==="assistant"&&A(y[C].status)){w=C;break}return w<0?y:[...y.slice(0,w),{...y[w],...p},...y.slice(w+1)]})},c=p=>{i(y=>{const w=y.findIndex(C=>C.id===p.id);return w>=0?[...y.slice(0,w),p,...y.slice(w+1)]:[...y,p]}),d(!1)},b=p=>{S(new Error(p.error)),d(!1)};return o.on("message:start",k),o.on("message:chunk",g),o.on("message:answer-complete",h),o.on("message:complete",c),o.on("message:error",b),()=>{o.off("message:start",k),o.off("message:chunk",g),o.off("message:answer-complete",h),o.off("message:complete",c),o.off("message:error",b)}},[o,u]),{messages:r,isLoading:f,error:m,sendMessage:(0,a.useCallback)(async(A,k)=>{d(!0),S(null);const g={id:`temp-${Date.now()}`,conversationId:u||"",content:A,role:"user",status:"DONE",attachments:k&&k.length>0?_.attachmentsFromFiles(k):void 0,createdAt:new Date},h={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};i(c=>[...c,g,h]);try{const c=await o.sendMessage(A,{conversationId:u,files:k});return c.conversationId&&!u&&s(c.conversationId),i(b=>{const p=b.filter(w=>!w.id.startsWith("temp-")),y={...g,id:g.id.replace("temp-","user-"),conversationId:c.conversationId};return p.some(w=>w.id===c.id)?[...p,y].sort((w,C)=>new Date(w.createdAt).getTime()-new Date(C.createdAt).getTime()):[...p,y,c]}),c}catch(c){return S(c instanceof Error?c:new Error("Failed to send message")),d(!1),i(b=>b.filter(p=>!p.id.startsWith("temp-"))),null}},[o,u]),clearMessages:(0,a.useCallback)(()=>{i([]),s(void 0),S(null)},[]),conversationId:u}}var U=({onSend:e,disabled:n=!1,placeholder:t="Type a message...",allowFiles:o=!1,className:r=""})=>{const[i,u]=(0,a.useState)(""),[s,f]=(0,a.useState)([]),d=(0,a.useRef)(null),m=(0,a.useRef)(null),S=(0,a.useCallback)(()=>{const c=m.current;if(!c)return;const b=110;c.style.height="auto",c.style.height=`${Math.min(c.scrollHeight+2,b)}px`,c.style.overflowY=c.scrollHeight+2>b?"auto":"hidden"},[]),I=(0,a.useCallback)(c=>{c.preventDefault(),(i.trim()||s.length>0)&&(e(i.trim(),s.length>0?s:void 0),u(""),f([]),requestAnimationFrame(S))},[i,s,e,S]),A=(0,a.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),I(c))},[I]),k=(0,a.useCallback)(c=>{const b=Array.from(c.target.files||[]);f(p=>[...p,...b])},[]),g=(0,a.useCallback)(c=>{f(b=>b.filter((p,y)=>y!==c))},[]),h=i.trim()||s.length>0;return(0,l.jsxs)("form",{onSubmit:I,className:`ago-chat-input ${r}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[s.length>0&&(0,l.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:s.map((c,b)=>(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,l.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.name}),(0,l.jsx)("button",{type:"button",onClick:()=>g(b),"aria-label":`Remove ${c.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},b))}),(0,l.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[o&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:n,"aria-label":"Attach file",style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:n?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,l.jsx)("input",{ref:d,type:"file",multiple:!0,onChange:k,style:{display:"none"}})]}),(0,l.jsx)("textarea",{ref:m,value:i,onChange:c=>{u(c.target.value),S()},onKeyDown:A,placeholder:t,"aria-label":t,disabled:n,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:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.currentTarget.style.borderColor="#dee3e8"}}),(0,l.jsx)("button",{type:"submit",disabled:n||!h,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:n||!h?"#b5bfc8":"#03182f",color:"#fff",cursor:n||!h?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},ce=({href:e,children:n,...t})=>(0,l.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:n}),ue=({children:e,...n})=>(0,l.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...n,children:e}),P=(e,n)=>{const t=({children:o,...r})=>a.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:n,fontWeight:600,lineHeight:"1.3"},...r},o);return t.displayName=`MarkdownHeading${e}`,t},de=({children:e,...n})=>(0,l.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...n,children:e}),fe=({children:e,...n})=>(0,l.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...n,children:e}),ge=({children:e,...n})=>(0,l.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...n,children:e}),pe=({className:e,children:n,...t})=>e!==void 0||String(n).includes(`
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Pe=Object.create,G=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Oe=Object.getOwnPropertyNames,ze=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty,Le=(e,n)=>{let t={};for(var o in e)G(t,o,{get:e[o],enumerable:!0});return n||G(t,Symbol.toStringTag,{value:"Module"}),t},He=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(var r=Oe(n),c=0,i=r.length,l;c<i;c++)l=r[c],!De.call(e,l)&&l!==t&&G(e,l,{get:(u=>n[u]).bind(null,l),enumerable:!(o=We(n,l))||o.enumerable});return e},Q=(e,n,t)=>(t=e!=null?Pe(ze(e)):{},He(n||!e||!e.__esModule?G(t,"default",{value:e,enumerable:!0}):t,e));const P=require("./AgoClient-BHegN73y.cjs"),qe=require("./autoContinue-CP9pJR-V.cjs"),z=require("./createFormCollector-C1ixsjV0.cjs"),Be=require("./createMockClient-BSNuN3ys.cjs"),Y=require("./sheetController-DY-sC13T.cjs");let s=require("react");s=Q(s,1);let a=require("react/jsx-runtime"),X=require("react-markdown");X=Q(X,1);let Z=require("remark-gfm");Z=Q(Z,1);function pe(e){const[n,t]=(0,s.useState)(!1),o=(0,s.useRef)(null),r=(0,s.useMemo)(()=>{if(o.current&&(o.current.destroy(),o.current=null),!e)return null;const c=new P.AgoClient(e);return o.current=c,c},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(r&&o.current===null&&(o.current=r,r.reviveAfterDestroy()),t(!0),()=>{o.current?.destroy(),o.current=null}),[r]),(0,s.useEffect)(()=>{o.current&&e&&o.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:r,isReady:n}}var ee=(0,s.createContext)(null),$e=({children:e,client:n,tools:t,helpers:o,pageContext:r,...c})=>{const{client:i}=pe(n?null:c),l=n||i;return(0,s.useEffect)(()=>{if(!(!t||t.length===0)){for(const u of t)l.register(u);return()=>{for(const u of t)l.unregisterFunction(u.name)}}},[l,t]),(0,s.useEffect)(()=>{if(!o)return;const u=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(p=>p.functions_exports).then(p=>{for(const[g,S]of Object.entries(o)){const R=p[g];if(!R){console.warn(`[AGO] Unknown helper: "${g}"`);continue}const k=S===!0?R:{...R,handler:S};l.register(k),u.push(k.name)}}),()=>{for(const p of u)l.unregisterFunction(p)}},[l,o]),(0,s.useEffect)(()=>{r==="auto"&&l.enableAutoPageContext()},[l,r]),(0,a.jsx)(ee.Provider,{value:l,children:e})};function D(){const e=(0,s.useContext)(ee);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function W(){return(0,s.useContext)(ee)}var Ke=new Set(["awaiting-approval"]);function ge(e){switch(e){case"progress_indicator":return"progress";case"reasoning":return"reasoning";case"confirmation_input":return"confirmation";case"form":return"form";default:return"status"}}function Ue(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":ge(e.type)}function ce(e,n){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(n==="confirmation"||n==="form")?"awaiting-approval":"running"}function ue(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase()).trim()}function Ge(e){switch(e.kind){case"navigation":return`Navigating to ${ue(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||ue(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function xe(e={}){const{includeReasoning:n=!1,labelFor:t}=e,o=W(),r=e.client||o;if(!r)throw new P.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[c,i]=(0,s.useState)([]),l=(0,s.useRef)(new Set),u=(0,s.useRef)(void 0),p=(0,s.useRef)(t);p.current=t;const g=(0,s.useCallback)((f,A)=>{i(C=>{const d=C.findIndex(m=>m.id===f),b={...d>=0?C[d]:{id:f,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...A};return b.label=p.current?.(b)??Ge(b),d>=0?[...C.slice(0,d),b,...C.slice(d+1)]:[...C,b]})},[]);(0,s.useEffect)(()=>{const f=y=>{u.current=y.messageId},A=y=>{const N=ge(y.type);N==="reasoning"&&!n||g(y.id,{kind:N,status:ce(y.status,N),messageId:u.current,toolName:y.toolName,toolDisplayName:y.toolDisplayName,message:y.message,data:y.data,formSchema:y.formSchema,requiresApproval:N==="confirmation"||N==="form"})},C=y=>{y.invocationId&&g(y.invocationId,{kind:y.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:u.current,functionName:y.functionName,arguments:y.arguments})},d=y=>{y.invocationId&&g(y.invocationId,{kind:y.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:u.current,functionName:y.functionName,arguments:y.arguments,requiresApproval:!0})},b=y=>{if(!y.invocationId)return;const N=y.result,v=typeof y.result=="object"&&N!==null&&N.approved===!1&&N.reason==="user_rejected";g(y.invocationId,{status:y.error?"error":v?"rejected":"done",requiresApproval:!1})},m=y=>{for(const N of y.messages??[])if(N.role==="assistant")for(const v of N.toolCalls??[]){const T=Ue(v);T==="reasoning"&&!n||/waiting/i.test(v.status??"")||g(v.id,{kind:T,status:ce(v.status,T),messageId:N.id,toolName:v.toolName,toolDisplayName:v.toolDisplayName,functionName:v.functionName,arguments:v.arguments,message:v.message,data:v.data,formSchema:v.formSchema,requiresApproval:T==="confirmation"||T==="form"})}},x=y=>{i(N=>N.map(v=>v.status==="running"||v.status==="awaiting-approval"?{...v,status:y}:v))},w=()=>x("done"),j=()=>x("error");return r.on("message:start",f),r.on("toolCall:received",A),r.on("function:invoke",C),r.on("function:awaiting-approval",d),r.on("function:result",b),r.on("conversation:loaded",m),r.on("message:complete",w),r.on("message:error",j),()=>{r.off("message:start",f),r.off("toolCall:received",A),r.off("function:invoke",C),r.off("function:awaiting-approval",d),r.off("function:result",b),r.off("conversation:loaded",m),r.off("message:complete",w),r.off("message:error",j)}},[r,n,g]);const S=(0,s.useCallback)(async f=>{const A=c.find(C=>C.id===f);!A||A.status!=="awaiting-approval"||l.current.has(f)||A.kind!=="form"&&(l.current.add(f),g(f,{status:"running",requiresApproval:!1}),A.functionName?await r.approveFunction(f):await r.confirmToolCall(f))},[r,c,g]),R=(0,s.useCallback)(async f=>{const A=c.find(C=>C.id===f);!A||A.status!=="awaiting-approval"||l.current.has(f)||(l.current.add(f),g(f,{status:"rejected",requiresApproval:!1}),A.functionName?await r.rejectFunction(f):await r.rejectToolCall(f))},[r,c,g]),k=(0,s.useCallback)(async(f,A)=>{g(f,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(f,A),g(f,{status:"done"})},[r,g]),_=(0,s.useCallback)(()=>{l.current.clear(),i([])},[]);return{items:c,latest:c.length>0?c[c.length-1]:void 0,isAwaitingApproval:c.some(f=>Ke.has(f.status)),approve:S,reject:R,submitForm:k,clear:_}}function te({client:e,conversationId:n}={}){const t=W(),o=e||t;if(!o)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,c]=(0,s.useState)([]),[i,l]=(0,s.useState)(n),[u,p]=(0,s.useState)(!1),[g,S]=(0,s.useState)(null);(0,s.useEffect)(()=>{n&&n!==i&&(l(n),R(n))},[n]);const R=async k=>{try{c((await o.getMessages(k)).filter(_=>!_.hidden))}catch(_){S(_ instanceof Error?_:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const k=m=>m==="IN_PROGRESS"||m==="WAITING_CLIENT",_=m=>{i||l(m.conversationId),p(!0),c(x=>{const w=x.findIndex(j=>j.id===m.messageId);return w>=0?x.map((j,y)=>y===w?{...j,status:"IN_PROGRESS"}:j):x.some(j=>j.role==="assistant"&&k(j.status))?x:[...x,{id:m.messageId,conversationId:m.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},f=m=>{c(x=>{const w=x.findIndex(j=>j.id===m.messageId);return w<0?x:x.map((j,y)=>y===w?{...j,content:j.content+m.content}:j)})},A=m=>{c(x=>{let w=-1;for(let j=x.length-1;j>=0;j--)if(x[j].role==="assistant"&&k(x[j].status)){w=j;break}return w<0?x:[...x.slice(0,w),{...x[w],...m},...x.slice(w+1)]})},C=m=>{c(x=>{const w=x.findIndex(j=>j.id===m.id);return w>=0?[...x.slice(0,w),m,...x.slice(w+1)]:[...x,m]}),p(!1)},d=m=>{S(new Error(m.error)),p(!1)},b=()=>{c(m=>{let x=-1;for(let w=m.length-1;w>=0;w--)if(m[w].role==="assistant"&&k(m[w].status)){x=w;break}return x<0?m:m[x].content?m.map((w,j)=>j===x?{...w,status:"CANCELED"}:w):m.filter((w,j)=>j!==x)}),p(!1)};return o.on("message:start",_),o.on("message:chunk",f),o.on("message:answer-complete",A),o.on("message:complete",C),o.on("message:error",d),o.on("message:stopped",b),()=>{o.off("message:start",_),o.off("message:chunk",f),o.off("message:answer-complete",A),o.off("message:complete",C),o.off("message:error",d),o.off("message:stopped",b)}},[o,i]),{messages:r,isLoading:u,error:g,sendMessage:(0,s.useCallback)(async(k,_)=>{p(!0),S(null);const f={id:`temp-${Date.now()}`,conversationId:i||"",content:k,role:"user",status:"DONE",attachments:_&&_.length>0?P.attachmentsFromFiles(_):void 0,createdAt:new Date},A={id:`temp-assistant-${Date.now()}`,conversationId:i||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};c(C=>[...C,f,A]);try{const C=await o.sendMessage(k,{conversationId:i,files:_});return C.conversationId&&!i&&l(C.conversationId),c(d=>{const b=d.filter(x=>!x.id.startsWith("temp-")),m={...f,id:f.id.replace("temp-","user-"),conversationId:C.conversationId};return b.some(x=>x.id===C.id)?[...b,m].sort((x,w)=>new Date(x.createdAt).getTime()-new Date(w.createdAt).getTime()):[...b,m,C]}),C}catch(C){return S(C instanceof Error?C:new Error("Failed to send message")),p(!1),c(d=>d.filter(b=>!b.id.startsWith("temp-"))),null}},[o,i]),stop:(0,s.useCallback)(async()=>{await o.stop()},[o]),clearMessages:(0,s.useCallback)(()=>{c([]),l(void 0),S(null)},[]),conversationId:i}}var de={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},Je={tabindex:"tabIndex"};function Ve(e){const n={};for(const[t,o]of Object.entries(e))n[Je[t]??t]=o;return n}function me(e){const n=e!==!1,t=n?e??{}:void 0,o=(0,s.useRef)(t?.onStateChange);o.current=t?.onStateChange;const r=(0,s.useMemo)(()=>{if(n)return Y.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(i,l)=>o.current?.(i,l)})},[n,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),c=(0,s.useSyncExternalStore)((0,s.useCallback)(i=>r?.subscribe(i)??(()=>{}),[r]),(0,s.useCallback)(()=>r?.getSnapshot()??de,[r]),(0,s.useCallback)(()=>r?.getServerSnapshot()??de,[r]));return{sheet:(0,s.useMemo)(()=>({...c,surface:{...c.surface,attrs:Ve(c.surface.attrs)}}),[c]),expand:(0,s.useCallback)(i=>r?.expand(i),[r]),collapse:(0,s.useCallback)(i=>r?.collapse(i),[r]),toggle:(0,s.useCallback)(i=>r?.toggle(i),[r])}}var Ye=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function he(e){const n=e.split(Ye);return n.length===1?e:n.map((t,o)=>o%2===0||!t?t:t.startsWith("`")?(0,a.jsx)("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",padding:"0 3px",borderRadius:"3px",backgroundColor:"rgba(0, 0, 0, 0.06)"},children:t.slice(1,-1)},o):t.startsWith("**")?(0,a.jsx)("strong",{style:{fontWeight:600},children:t.slice(2,-2)},o):(0,a.jsx)("em",{children:t.slice(1,-1)},o))}var Xe=`
|
|
2
|
+
@keyframes ago-activity-enter {
|
|
3
|
+
from { opacity: 0; transform: translateY(4px); }
|
|
4
|
+
to { opacity: 1; transform: none; }
|
|
5
|
+
}
|
|
6
|
+
@keyframes ago-activity-sweep {
|
|
7
|
+
from { background-position: 200% 0; }
|
|
8
|
+
to { background-position: -200% 0; }
|
|
9
|
+
}
|
|
10
|
+
.ago-activity__label {
|
|
11
|
+
animation: ago-activity-enter 260ms ease-out both;
|
|
12
|
+
}
|
|
13
|
+
@supports ((background-clip: text) or (-webkit-background-clip: text)) {
|
|
14
|
+
.ago-activity__label {
|
|
15
|
+
background-image: linear-gradient(
|
|
16
|
+
90deg,
|
|
17
|
+
var(--ago-activity-color, #5b5d5f) 0%,
|
|
18
|
+
var(--ago-activity-color, #5b5d5f) 35%,
|
|
19
|
+
var(--ago-activity-sheen, #adb1b5) 50%,
|
|
20
|
+
var(--ago-activity-color, #5b5d5f) 65%,
|
|
21
|
+
var(--ago-activity-color, #5b5d5f) 100%
|
|
22
|
+
);
|
|
23
|
+
background-size: 200% 100%;
|
|
24
|
+
-webkit-background-clip: text;
|
|
25
|
+
background-clip: text;
|
|
26
|
+
color: transparent;
|
|
27
|
+
animation:
|
|
28
|
+
ago-activity-enter 260ms ease-out both,
|
|
29
|
+
ago-activity-sweep 2.4s linear infinite;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
@media (prefers-reduced-motion: reduce) {
|
|
33
|
+
.ago-activity__label {
|
|
34
|
+
animation: none;
|
|
35
|
+
color: var(--ago-activity-color, #5b5d5f);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`,Ze=({label:e})=>(0,a.jsxs)("div",{className:"ago-activity",role:"status","aria-live":"polite",style:{display:"block",margin:"4px 0 0",padding:"6px 12px",borderRadius:"999px",width:"fit-content",maxWidth:"100%",fontSize:"13px",lineHeight:1.5,color:"var(--ago-activity-color, #5b5d5f)",backgroundColor:"var(--ago-activity-bg, #f1f2f3)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[(0,a.jsx)("span",{className:"ago-activity__label",children:he(e)},e),(0,a.jsx)("style",{children:Xe})]}),ye=({onSend:e,onStop:n,disabled:t=!1,placeholder:o="Type a message...",allowFiles:r=!1,className:c=""})=>{const[i,l]=(0,s.useState)(""),[u,p]=(0,s.useState)([]),g=(0,s.useRef)(null),S=(0,s.useRef)(null),R=(0,s.useCallback)(()=>{const d=S.current;if(!d)return;const b=110;d.style.height="auto",d.style.height=`${Math.min(d.scrollHeight+2,b)}px`,d.style.overflowY=d.scrollHeight+2>b?"auto":"hidden"},[]),k=(0,s.useCallback)(async d=>{if(d.preventDefault(),!i.trim()&&u.length===0)return;const b=i.trim(),m=u.length>0?u:void 0;l(""),p([]),requestAnimationFrame(R),await e(b,m)===!1&&(l(x=>x.trim()?x:b),m&&p(x=>[...m,...x]),requestAnimationFrame(R))},[i,u,e,R]),_=(0,s.useCallback)(d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),k(d))},[k]),f=(0,s.useCallback)(d=>{const b=Array.from(d.target.files||[]);p(m=>[...m,...b])},[]),A=(0,s.useCallback)(d=>{p(b=>b.filter((m,x)=>x!==d))},[]),C=i.trim()||u.length>0;return(0,a.jsxs)("form",{onSubmit:d=>{k(d)},className:`ago-chat-input ${c}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[u.length>0&&(0,a.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:u.map((d,b)=>(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,a.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.name}),(0,a.jsx)("button",{type:"button",onClick:()=>A(b),"aria-label":`Remove ${d.name}`,style:{flexShrink:0,width:"44px",height:"44px",margin:"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},b))}),(0,a.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>g.current?.click(),disabled:t,"aria-label":"Attach file",style:{flexShrink:0,minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,a.jsx)("input",{ref:g,type:"file",multiple:!0,onChange:f,style:{display:"none"}})]}),(0,a.jsx)("textarea",{ref:S,className:"ago-chat-input__field",value:i,onChange:d=>{l(d.target.value),R()},onKeyDown:_,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:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onBlur:d=>{d.currentTarget.style.borderColor="#dee3e8"}}),t&&n?(0,a.jsx)("button",{type:"button",onClick:n,"aria-label":"Stop generating",style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:"#03182f",color:"#fff",cursor:"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Stop"}):(0,a.jsx)("button",{type:"submit",disabled:t||!C,style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!C?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!C?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},Qe=({href:e,children:n,...t})=>(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:n}),et=({children:e,...n})=>(0,a.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...n,children:e}),L=(e,n)=>{const t=({children:o,...r})=>s.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:n,fontWeight:600,lineHeight:"1.3"},...r},o);return t.displayName=`MarkdownHeading${e}`,t},tt=({children:e,...n})=>(0,a.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...n,children:e}),nt=({children:e,...n})=>(0,a.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...n,children:e}),rt=({children:e,...n})=>(0,a.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...n,children:e}),ot=({className:e,children:n,...t})=>e!==void 0||String(n).includes(`
|
|
39
|
+
`)?(0,a.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}):(0,a.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}),st=({children:e,...n})=>(0,a.jsx)("pre",{style:{margin:"0 0 8px 0"},...n,children:e}),at=({children:e,...n})=>(0,a.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...n,children:e}),it=({children:e,...n})=>(0,a.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,a.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...n,children:e})}),lt=({children:e,...n})=>(0,a.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...n,children:e}),ct=({children:e,...n})=>(0,a.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...n,children:e}),ut=({alt:e,...n})=>(0,a.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...n}),dt=e=>(0,a.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),ft={a:Qe,p:et,h1:L(1,"20px"),h2:L(2,"18px"),h3:L(3,"16px"),h4:L(4,"15px"),h5:L(5,"14px"),h6:L(6,"13px"),ul:tt,ol:nt,li:rt,code:ot,pre:st,blockquote:at,table:it,th:lt,td:ct,img:ut,hr:dt},pt=[Z.default],be=({content:e})=>(0,a.jsx)(X.default,{remarkPlugins:pt,components:ft,children:e}),gt=({attachment:e,isUser:n})=>{const t=P.safeAttachmentUrl(e.url);if(P.canInlineImage(e))return(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,a.jsx)("img",{src:t,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const o=P.formatFileSize(e.fileSize),r=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,a.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,a.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),o&&(0,a.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:o})]})]}),c={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:n?"rgba(255,255,255,0.12)":"#fff",color:n?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return t?(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:c,children:r}):(0,a.jsx)("div",{style:c,children:r})},xt=({source:e,index:n})=>{const t=(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,a.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:n+1}),(0,a.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),o={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,a.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:o,onMouseEnter:r=>{r.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:r=>{r.currentTarget.style.borderColor="#dee3e8"},children:t}):(0,a.jsx)("div",{style:o,children:t})},ve=()=>(0,a.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,a.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",opacity:.55,animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,a.jsx)("style",{children:`
|
|
3
40
|
@keyframes ago-pulse {
|
|
4
41
|
0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
|
|
5
42
|
40% { opacity: 1; transform: scale(1); }
|
|
6
43
|
}
|
|
7
|
-
`})]}),K=({message:e,className:n="",showAgentName:t=!1,isLast:o=!1,onFollowUpClick:r})=>{const i=e.role==="user",u=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,l.jsxs)("div",{className:`ago-message ago-message--${e.role} ${n}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,l.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,l.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((s,f)=>(0,l.jsx)(ke,{source:s,index:f},s.id))}),e.attachments&&e.attachments.length>0&&(0,l.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(s=>(0,l.jsx)(Ae,{attachment:s,isUser:i},s.id))}),(e.content||u)&&(0,l.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,l.jsx)(G,{content:e.content}):u&&(0,l.jsx)(je,{})}),o&&e.followUpReplies&&e.followUpReplies.length>0&&(0,l.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((s,f)=>(0,l.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!r,onClick:r?()=>r(s):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:r?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:d=>{d.currentTarget.style.borderColor="#dee3e8"},children:s},f))})]})},Ie=({client:e,conversationId:n,title:t="Chat",welcomeMessage:o="Hello! How can I help you today?",placeholder:r="Type a message...",allowFiles:i=!1,height:u=500,logoUrl:s,showAgentName:f=!1,forms:d,onFollowUpClick:m,className:S="",onMessageSent:I,onMessageReceived:A})=>{const k=(0,a.useRef)(null),g=E(),h=e??g,{messages:c,isLoading:b,error:p,sendMessage:y}=z({client:e,conversationId:n});(0,a.useEffect)(()=>{if(!h||!d||d.length===0)return;let x=!1;const j=[];return Promise.all(d.map(N=>N.schema!=null?Promise.resolve(M.createFormCollector(N)):M.loadFormCollector(h,N))).then(N=>{if(!x)for(const Z of N)j.push(Z.install(h))}).catch(()=>{}),()=>{x=!0,j.forEach(N=>N())}},[h,d?JSON.stringify(d.map(x=>[x.name,x.schema??null,x.submit??!1,x.description??null])):""]),(0,a.useEffect)(()=>{k.current?.scrollIntoView({behavior:"smooth"})},[c]),(0,a.useEffect)(()=>{const x=c[c.length-1];x&&x.role==="assistant"&&x.status==="DONE"&&A&&A({id:x.id,content:x.content})},[c,A]);const w=async(x,j)=>{I?.(x),await y(x,j)},C=c[c.length-1],R=b&&C?.role==="assistant"&&(C.status==="IN_PROGRESS"||C.status==="WAITING_CLIENT"),v=m===!1?void 0:m??(x=>w(x));return(0,l.jsxs)("div",{className:`ago-chat-widget ${S}`,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,l.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:[s&&(0,l.jsx)("img",{src:s,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,l.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:t})]}),(0,l.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:[c.length===0?(0,l.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:o}):c.map((x,j)=>(0,l.jsx)(K,{message:x,showAgentName:f,isLast:j===c.length-1,onFollowUpClick:v},x.id)),p&&(0,l.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:p.message}),(0,l.jsx)("div",{ref:k})]}),(0,l.jsx)(U,{onSend:w,disabled:R,placeholder:r,allowFiles:i})]})};function J(e={}){const n=E(),t=e.client??n;if(!t)throw new _.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[o,r]=(0,a.useState)(null),i=(0,a.useRef)(o);i.current=o;const u=(0,a.useRef)(e.onExpand);return u.current=e.onExpand,(0,a.useEffect)(()=>{const s=d=>{r(d),t.proactive?.shown(d)},f=({nudge:d})=>{r(m=>m?.id===d.id?null:m)};return t.on("nudge:ready",s),t.on("nudge:accepted",f),t.on("nudge:dismissed",f),()=>{t.off("nudge:ready",s),t.off("nudge:accepted",f),t.off("nudge:dismissed",f)}},[t]),{nudge:o,accept:(0,a.useCallback)(async()=>{const s=i.current;s&&(r(null),await t.proactive?.accept(s),(s.source==="agent"||s.goal)&&u.current?.(s))},[t]),dismiss:(0,a.useCallback)(()=>{const s=i.current;s&&(r(null),t.proactive?.dismiss(s))},[t])}}var Ne=({client:e,onExpand:n,autoHideMs:t,position:o="bottom-right",openChatLabel:r="Open chat",className:i=""})=>{const{nudge:u,accept:s,dismiss:f}=J({client:e,onExpand:n});if((0,a.useEffect)(()=>{if(!u||!t)return;const m=setTimeout(()=>f(),t);return()=>clearTimeout(m)},[u,t,f]),!u)return null;const d=u.source==="agent"||!!u.goal;return(0,l.jsxs)("div",{className:`ago-nudge ${i}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...o==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,l.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:f,style:{position:"absolute",top:"6px",right:"8px",border:"none",background:"transparent",color:"#6b6d6f",fontSize:"16px",lineHeight:1,cursor:"pointer",padding:"4px"},children:"×"}),(0,l.jsx)("div",{className:"ago-nudge__message",style:{paddingRight:"16px"},children:u.message}),(u.action||d)&&(0,l.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[u.action&&(0,l.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{s()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:u.action.label}),d&&(0,l.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{s()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:r})]})]})};function V({client:e,autoLoad:n=!0}={}){const t=E(),o=e||t;if(!o)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,i]=(0,a.useState)([]),[u,s]=(0,a.useState)(null),[f,d]=(0,a.useState)(!1),[m,S]=(0,a.useState)(null),I=(0,a.useCallback)(async()=>{d(!0),S(null);try{const{data:g}=await o.getConversations();i(g)}catch(g){S(g instanceof Error?g:new Error("Failed to load conversations"))}finally{d(!1)}},[o]),A=(0,a.useCallback)(async g=>{d(!0),S(null);try{s(await o.getConversation(g))}catch(h){S(h instanceof Error?h:new Error("Failed to load conversation"))}finally{d(!1)}},[o]),k=(0,a.useCallback)(()=>{s(null)},[]);return(0,a.useEffect)(()=>{n&&I()},[n,I]),{conversations:r,currentConversation:u,isLoading:f,error:m,selectConversation:A,startNewConversation:k,refreshConversations:I}}function _e(e={}){const n=E(),t=e.client||n;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const o=z({client:t,conversationId:e.conversationId}),r=V({client:t,autoLoad:e.autoLoad});return{messages:o.messages,isLoading:o.isLoading,error:o.error||r.error,sendMessage:o.sendMessage,clearMessages:o.clearMessages,conversationId:o.conversationId,conversations:r.conversations,currentConversation:r.currentConversation,isConversationsLoading:r.isLoading,selectConversation:r.selectConversation,startNewConversation:r.startNewConversation,refreshConversations:r.refreshConversations}}function Re(e,n){const t=F(),{name:o,description:r,parameters:i,handler:u,maxResultBytes:s,requiresApproval:f}=typeof e=="string"?{name:e,...n}:e,d=(0,a.useRef)(u);d.current=u,(0,a.useEffect)(()=>{const m=S=>d.current(S);return t.registerFunction(o,m,{description:r,parameters:i,maxResultBytes:s,requiresApproval:f}),()=>{t.unregisterFunction(o)}},[t,o,r,i,s,f])}function Ee(e,n){const t=F(),o=(0,a.useRef)(e);o.current=e,(0,a.useEffect)(()=>(t.registerNavigationFunction(r=>o.current(r),n),()=>{t.unregisterNavigationFunction()}),[t,n])}function Me(e,n){const t=F(),o=n?.functionName??"setPageState",r=n?.requiresApproval,i=(0,a.useRef)(e);i.current=e,(0,a.useEffect)(()=>{const u=i.current.map(s=>{const f=()=>i.current.find(d=>d.name===s.name)??s;return{name:s.name,description:s.description,schema:s.schema,get:s.get?()=>f().get?.():void 0,set:d=>f().set(d)}});return t.registerPageStateFunction(u,{functionName:o,requiresApproval:r}),()=>{t.unregisterPageStateFunction(o)}},[t,o,r])}function Fe(e){const n=F(),t=(0,a.useRef)(e);t.current=e,(0,a.useEffect)(()=>ae.attachAutoContinueAfterNavigation(n,()=>t.current),[n])}var Pe=new Set(["awaiting-approval"]);function Y(e){switch(e){case"progress_indicator":return"progress";case"reasoning":return"reasoning";case"confirmation_input":return"confirmation";case"form":return"form";default:return"status"}}function Te(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":Y(e.type)}function L(e,n){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(n==="confirmation"||n==="form")?"awaiting-approval":"running"}function $(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase()).trim()}function De(e){switch(e.kind){case"navigation":return`Navigating to ${$(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||$(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function We(e={}){const{includeReasoning:n=!1,labelFor:t}=e,o=E(),r=e.client||o;if(!r)throw new _.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[i,u]=(0,a.useState)([]),s=(0,a.useRef)(new Set),f=(0,a.useRef)(void 0),d=(0,a.useRef)(t);d.current=t;const m=(0,a.useCallback)((g,h)=>{u(c=>{const b=c.findIndex(y=>y.id===g),p={...b>=0?c[b]:{id:g,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...h};return p.label=d.current?.(p)??De(p),b>=0?[...c.slice(0,b),p,...c.slice(b+1)]:[...c,p]})},[]);(0,a.useEffect)(()=>{const g=v=>{f.current=v.messageId},h=v=>{const x=Y(v.type);x==="reasoning"&&!n||m(v.id,{kind:x,status:L(v.status,x),messageId:f.current,toolName:v.toolName,toolDisplayName:v.toolDisplayName,message:v.message,data:v.data,formSchema:v.formSchema,requiresApproval:x==="confirmation"||x==="form"})},c=v=>{v.invocationId&&m(v.invocationId,{kind:v.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:f.current,functionName:v.functionName,arguments:v.arguments})},b=v=>{v.invocationId&&m(v.invocationId,{kind:v.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:f.current,functionName:v.functionName,arguments:v.arguments,requiresApproval:!0})},p=v=>{if(!v.invocationId)return;const x=v.result,j=typeof v.result=="object"&&x!==null&&x.approved===!1&&x.reason==="user_rejected";m(v.invocationId,{status:v.error?"error":j?"rejected":"done",requiresApproval:!1})},y=v=>{for(const x of v.messages??[])if(x.role==="assistant")for(const j of x.toolCalls??[]){const N=Te(j);N==="reasoning"&&!n||/waiting/i.test(j.status??"")||m(j.id,{kind:N,status:L(j.status,N),messageId:x.id,toolName:j.toolName,toolDisplayName:j.toolDisplayName,functionName:j.functionName,arguments:j.arguments,message:j.message,data:j.data,formSchema:j.formSchema,requiresApproval:N==="confirmation"||N==="form"})}},w=v=>{u(x=>x.map(j=>j.status==="running"||j.status==="awaiting-approval"?{...j,status:v}:j))},C=()=>w("done"),R=()=>w("error");return r.on("message:start",g),r.on("toolCall:received",h),r.on("function:invoke",c),r.on("function:awaiting-approval",b),r.on("function:result",p),r.on("conversation:loaded",y),r.on("message:complete",C),r.on("message:error",R),()=>{r.off("message:start",g),r.off("toolCall:received",h),r.off("function:invoke",c),r.off("function:awaiting-approval",b),r.off("function:result",p),r.off("conversation:loaded",y),r.off("message:complete",C),r.off("message:error",R)}},[r,n,m]);const S=(0,a.useCallback)(async g=>{const h=i.find(c=>c.id===g);!h||h.status!=="awaiting-approval"||s.current.has(g)||h.kind!=="form"&&(s.current.add(g),m(g,{status:"running",requiresApproval:!1}),h.functionName?await r.approveFunction(g):await r.confirmToolCall(g))},[r,i,m]),I=(0,a.useCallback)(async g=>{const h=i.find(c=>c.id===g);!h||h.status!=="awaiting-approval"||s.current.has(g)||(s.current.add(g),m(g,{status:"rejected",requiresApproval:!1}),h.functionName?await r.rejectFunction(g):await r.rejectToolCall(g))},[r,i,m]),A=(0,a.useCallback)(async(g,h)=>{m(g,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(g,h),m(g,{status:"done"})},[r,m]),k=(0,a.useCallback)(()=>{s.current.clear(),u([])},[]);return{items:i,latest:i.length>0?i[i.length-1]:void 0,isAwaitingApproval:i.some(g=>Pe.has(g.status)),approve:S,reject:I,submitForm:A,clear:k}}function Oe(e={}){const n=E(),t=e.client||n;if(!t)throw new _.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[o,r]=(0,a.useState)(()=>t.getRecentActivity());(0,a.useEffect)(()=>{r(t.getRecentActivity());const s=()=>r(t.getRecentActivity());return t.on("activity:recorded",s),()=>t.off("activity:recorded",s)},[t]);const i=(0,a.useCallback)(s=>t.recordActivity(s),[t]),u=(0,a.useCallback)(()=>{t.clearActivity(),r([])},[t]);return{entries:o,latest:o.length>0?o[o.length-1]:void 0,record:i,clear:u}}function qe(e,n){const t=F(),o=(0,a.useId)(),r=n??o,i=(0,a.useRef)(e);i.current=e;const u=typeof e=="function";(0,a.useEffect)(()=>{if(typeof i.current=="function"){const s=()=>i.current();return t.addDynamicContext(r,s),()=>{t.removeDynamicContext(r)}}return t.setContext(r,i.current),()=>{t.removeContext(r)}},[t,r,u,u?"":JSON.stringify(e)])}function X(e){return(0,a.useSyncExternalStore)(e.subscribe,e.get,e.get)}var H={missing:[],complete:!1};function ze(e){const n=F(),t=e.schema!=null,o=JSON.stringify(e.schema??null),r=e.submit,i=r?typeof r=="string"?`client:${r}`:r.via==="backend"?"backend":"handler"in r?"client:handler":`client:${r.url}`:"none",u=JSON.stringify(e.initialValues??null),s=(0,a.useMemo)(()=>t?M.createFormCollector(e):null,[t,e.name,o,i,u,e.autoSubmit]),[f,d]=(0,a.useState)({collector:null,loading:!t,error:null});(0,a.useEffect)(()=>{if(t)return;let b=!1;return d({collector:null,loading:!0,error:null}),M.loadFormCollector(n,e).then(p=>{b||d({collector:p,loading:!1,error:null})}).catch(p=>{b||d({collector:null,loading:!1,error:p instanceof Error?p:new Error(String(p))})}),()=>{b=!0}},[n,t,e.name,i,u,e.autoSubmit]);const m=t?s:f.collector,S=t?!1:f.loading,I=t?null:f.error;(0,a.useEffect)(()=>{if(m)return m.install(n)},[n,m]);const A=(0,a.useMemo)(()=>_.createStore({values:e.initialValues??{},submitted:!1}),[u]),k=X(m?.store??A),g=(0,a.useMemo)(()=>m?.getStatus()??H,[k,m]),h=(0,a.useMemo)(()=>({...k,...g}),[k,g]),c=(0,a.useMemo)(()=>({name:e.name,store:A,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>A.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>H}),[e.name,A]);return{...m??c,state:h,loading:S,error:I}}exports.AgoNudge=Ne;exports.AgoProvider=le;exports.ChatInput=U;exports.ChatWidget=Ie;exports.Markdown=G;exports.Message=K;exports.__exportAll=oe;exports.createFormCollector=M.createFormCollector;exports.createMockClient=ie.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=B;exports.useAgoActivity=We;exports.useAgoActivityLog=Oe;exports.useAgoAutoContinueAfterNavigation=Fe;exports.useAgoClient=F;exports.useAgoContext=qe;exports.useAgoFunction=Re;exports.useAgoNavigation=Ee;exports.useAgoPageState=Me;exports.useAgoStore=X;exports.useChat=_e;exports.useConversation=V;exports.useFormCollector=ze;exports.useMessages=z;exports.useOptionalAgoClient=E;exports.useProactiveNudge=J;
|
|
44
|
+
`})]}),Ce=({message:e,className:n="",showAgentName:t=!1,isLast:o=!1,onFollowUpClick:r,showStreamingDots:c=!0})=>{const i=e.role==="user",l=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,a.jsxs)("div",{className:`ago-message ago-message--${e.role} ${n}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,a.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,a.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((u,p)=>(0,a.jsx)(xt,{source:u,index:p},u.id))}),e.attachments&&e.attachments.length>0&&(0,a.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(u=>(0,a.jsx)(gt,{attachment:u,isUser:i},u.id))}),(e.content||l&&c)&&(0,a.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,a.jsx)(be,{content:e.content}):l&&c&&(0,a.jsx)(ve,{})}),o&&e.followUpReplies&&e.followUpReplies.length>0&&(0,a.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((u,p)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!r,onClick:r?()=>r(u):void 0,style:{minHeight:"44px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:r?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:g=>{g.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:g=>{g.currentTarget.style.borderColor="#dee3e8"},children:u},p))})]})},mt=(0,s.forwardRef)(function({client:n,conversationId:t,title:o="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:c="Type a message...",allowFiles:i=!1,allowStop:l=!0,height:u=500,logoUrl:p,showAgentName:g=!1,forms:S,onFollowUpClick:R,className:k="",onMessageSent:_,onMessageReceived:f,sheet:A=!1,thinkingLabel:C="Thinking...",functionLabels:d,showReasoning:b=!0},m){const x=(0,s.useRef)(null),w=(0,s.useRef)(!0),[j,y]=(0,s.useState)(!0),N=(0,s.useRef)(null),{sheet:v,expand:T,collapse:H,toggle:ne}=me(A),[je,J]=(0,s.useState)(!1),V=v.compact&&v.state==="peek",Ae=W(),q=n??Ae,{messages:M,isLoading:_e,error:re,sendMessage:Re,stop:Ie}=te({client:n,conversationId:t});(0,s.useEffect)(()=>{if(!q||!S||S.length===0)return;let h=!1;const E=[];return Promise.all(S.map(I=>I.schema!=null?Promise.resolve(z.createFormCollector(I)):z.loadFormCollector(q,I))).then(I=>{if(!h)for(const F of I)E.push(F.install(q))}).catch(()=>{}),()=>{h=!0,E.forEach(I=>I())}},[q,S?JSON.stringify(S.map(h=>[h.name,h.schema??null,h.submit??!1,h.description??null])):""]),(0,s.useEffect)(()=>{const h=x.current;!h||!w.current||(h.scrollTop=h.scrollHeight)},[M]);const Ne=()=>{const h=x.current;h&&(w.current=!0,y(!0),h.scrollTop=h.scrollHeight)};(0,s.useEffect)(()=>{const h=M[M.length-1];h&&h.role==="assistant"&&h.status==="DONE"&&f&&f({id:h.id,content:h.content})},[M,f]),(0,s.useEffect)(()=>{J(!!V)},[M.length]),(0,s.useEffect)(()=>{const h=N.current;if(!v.compact||!h)return;const E=document.documentElement;if(v.state!=="peek")return;const I=()=>{E.style.setProperty("--ago-sheet-height",`${Math.round(h.getBoundingClientRect().height)}px`)};I();const F=typeof ResizeObserver=="function"?new ResizeObserver(I):null;return F?.observe(h),()=>F?.disconnect()},[v.compact,v.state]),(0,s.useEffect)(()=>{v.compact||document.documentElement.style.removeProperty("--ago-sheet-height")},[v.compact]),(0,s.useEffect)(()=>()=>{document.documentElement.style.removeProperty("--ago-sheet-height")},[]),(0,s.useImperativeHandle)(m,()=>({expand:T,collapse:H,toggle:ne,state:v.state}),[T,H,ne,v.state]),(0,s.useEffect)(()=>{if(!v.isModal)return;const h=Symbol("ago-react-sheet");Y.lockBackgroundScroll(h);const E=I=>{if(I.key==="Escape"){H("user");return}if(I.key!=="Tab")return;const F=N.current;if(!F)return;const K=Array.from(F.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(Fe=>Fe.getClientRects().length>0);if(K.length===0){I.preventDefault();return}const ie=K[0],le=K[K.length-1],U=document.activeElement;I.shiftKey&&(U===ie||!F.contains(U))?(I.preventDefault(),le.focus()):!I.shiftKey&&(U===le||!F.contains(U))&&(I.preventDefault(),ie.focus())};return document.addEventListener("keydown",E),N.current?.focus({preventScroll:!0}),()=>{document.removeEventListener("keydown",E),Y.unlockBackgroundScroll(h)}},[v.isModal,H]);const oe=async(h,E)=>(w.current=!0,y(!0),_?.(h),await Re(h,E)!==null),O=M[M.length-1],$=_e&&O?.role==="assistant"&&(O.status==="IN_PROGRESS"||O.status==="WAITING_CLIENT"),Ee=(0,s.useCallback)(h=>{const E=h.functionName;if(!(!d||!E))return typeof d=="function"?d(E,h.arguments??{}):d[E]},[d]),{items:Me}=xe({client:q??void 0,labelFor:Ee,includeReasoning:b}),se=Me.filter(h=>O?.id!==void 0&&h.messageId===O.id),B=d===!1?void 0:se[se.length-1]?.label,ae=!!($&&B),Te=R===!1?void 0:R??(h=>oe(h));return(0,a.jsxs)("div",{ref:N,className:`ago-chat-widget ${k}`,...v.surface.attrs,"data-ago-sheet-state":v.compact?v.state:void 0,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px",...v.surface.style},children:[!v.compact&&(0,a.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:[p&&(0,a.jsx)("img",{src:p,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,a.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:o})]}),V&&(0,a.jsxs)("button",{type:"button",className:"ago-chat-widget__peek","aria-expanded":!1,"aria-label":"Open the conversation",onClick:()=>{J(!1),T("user")},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:"8px",padding:"14px 18px 10px",border:"none",borderBottom:"1px solid currentColor",borderBottomColor:"rgba(128,128,128,0.25)",background:"transparent",textAlign:"left",cursor:"pointer",font:"inherit",color:"inherit"},children:[(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7},children:[o,je&&(0,a.jsx)("span",{"aria-label":"New message",style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#1b5fc4"}}),(0,a.jsx)("span",{style:{marginLeft:"auto",fontSize:"14px"},"aria-hidden":!0,children:"↑"})]}),$&&!O?.content?(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[!B&&(0,a.jsx)(ve,{}),(0,a.jsx)("span",{style:{fontSize:"13px",opacity:.7,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:B?he(B):C})]}):(0,a.jsx)("span",{style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:"13px",lineHeight:1.5,color:"inherit",minHeight:"calc(2 * 1.5 * 13px)"},children:O?.content||r})]}),v.compact&&v.state==="full"&&(0,a.jsxs)("div",{className:"ago-chat-widget__sheet-header",style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px 6px 18px",borderBottom:"1px solid rgba(128,128,128,0.25)",flexShrink:0},children:[(0,a.jsx)("span",{style:{fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:o}),(0,a.jsx)("button",{type:"button","aria-label":"Collapse the conversation",onClick:()=>H("user"),style:{marginLeft:"auto",flexShrink:0,width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:"inherit",cursor:"pointer"},children:(0,a.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M6 9l6 6 6-6"})})})]}),(0,a.jsxs)("div",{style:{position:"relative",flex:1,display:V?"none":"flex",minHeight:0},children:[(0,a.jsxs)("div",{ref:x,className:"ago-chat-widget__messages",onScroll:h=>{const E=h.currentTarget,I=E.scrollHeight-E.scrollTop-E.clientHeight<=48;w.current=I,y(I)},role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,"aria-busy":$,style:{flex:1,overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:"#fbfbfb"},children:[M.length===0?(0,a.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:r}):M.map((h,E)=>(0,a.jsx)(Ce,{message:h,showAgentName:g,isLast:E===M.length-1,onFollowUpClick:Te,showStreamingDots:!ae},h.id)),ae&&(0,a.jsx)(Ze,{label:B??""}),re&&(0,a.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:re.message}),(0,a.jsx)("div",{})]}),!j&&(0,a.jsx)("button",{type:"button",className:"ago-chat-widget__jump","aria-label":"Jump to latest message",onClick:Ne,style:{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid #dee3e8",borderRadius:"50%",backgroundColor:"#fff",color:"#0b1b2b",boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:2},children:(0,a.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M12 5v14M19 12l-7 7-7-7"})})})]}),(0,a.jsx)(ye,{onSend:oe,onStop:l?()=>{Ie()}:void 0,disabled:$,placeholder:c,allowFiles:i})]})});function we(e={}){const n=W(),t=e.client??n;if(!t)throw new P.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[o,r]=(0,s.useState)(null),c=(0,s.useRef)(o);c.current=o;const i=(0,s.useRef)(e.onExpand);return i.current=e.onExpand,(0,s.useEffect)(()=>{const l=p=>{r(p),t.proactive?.shown(p)},u=({nudge:p})=>{r(g=>g?.id===p.id?null:g)};return t.on("nudge:ready",l),t.on("nudge:accepted",u),t.on("nudge:dismissed",u),()=>{t.off("nudge:ready",l),t.off("nudge:accepted",u),t.off("nudge:dismissed",u)}},[t]),{nudge:o,accept:(0,s.useCallback)(async()=>{const l=c.current;l&&(r(null),await t.proactive?.accept(l),(l.source==="agent"||l.goal)&&i.current?.(l))},[t]),dismiss:(0,s.useCallback)(()=>{const l=c.current;l&&(r(null),t.proactive?.dismiss(l))},[t])}}var ht=({client:e,onExpand:n,autoHideMs:t,position:o="bottom-right",openChatLabel:r="Open chat",className:c=""})=>{const{nudge:i,accept:l,dismiss:u}=we({client:e,onExpand:n});if((0,s.useEffect)(()=>{if(!i||!t)return;const g=setTimeout(()=>u(),t);return()=>clearTimeout(g)},[i,t,u]),!i)return null;const p=i.source==="agent"||!!i.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${c}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...o==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,a.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:u,style:{position:"absolute",top:"6px",right:"8px",border:"none",background:"transparent",color:"#6b6d6f",fontSize:"16px",lineHeight:1,cursor:"pointer",padding:"4px"},children:"×"}),(0,a.jsx)("div",{className:"ago-nudge__message",style:{paddingRight:"16px"},children:i.message}),(i.action||p)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[i.action&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{l()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:i.action.label}),p&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{l()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:r})]})]})};function ke({client:e,autoLoad:n=!0}={}){const t=W(),o=e||t;if(!o)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,c]=(0,s.useState)([]),[i,l]=(0,s.useState)(null),[u,p]=(0,s.useState)(!1),[g,S]=(0,s.useState)(null),R=(0,s.useCallback)(async()=>{p(!0),S(null);try{const{data:f}=await o.getConversations();c(f)}catch(f){S(f instanceof Error?f:new Error("Failed to load conversations"))}finally{p(!1)}},[o]),k=(0,s.useCallback)(async f=>{p(!0),S(null);try{l(await o.getConversation(f))}catch(A){S(A instanceof Error?A:new Error("Failed to load conversation"))}finally{p(!1)}},[o]),_=(0,s.useCallback)(()=>{l(null)},[]);return(0,s.useEffect)(()=>{n&&R()},[n,R]),{conversations:r,currentConversation:i,isLoading:u,error:g,selectConversation:k,startNewConversation:_,refreshConversations:R}}function yt(e={}){const n=W(),t=e.client||n;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const o=te({client:t,conversationId:e.conversationId}),r=ke({client:t,autoLoad:e.autoLoad});return{messages:o.messages,isLoading:o.isLoading,error:o.error||r.error,sendMessage:o.sendMessage,stop:o.stop,clearMessages:o.clearMessages,conversationId:o.conversationId,conversations:r.conversations,currentConversation:r.currentConversation,isConversationsLoading:r.isLoading,selectConversation:r.selectConversation,startNewConversation:r.startNewConversation,refreshConversations:r.refreshConversations}}function bt(e,n){const t=D(),{name:o,description:r,parameters:c,handler:i,maxResultBytes:l,requiresApproval:u}=typeof e=="string"?{name:e,...n}:e,p=(0,s.useRef)(i);p.current=i,(0,s.useEffect)(()=>{const g=S=>p.current(S);return t.registerFunction(o,g,{description:r,parameters:c,maxResultBytes:l,requiresApproval:u}),()=>{t.unregisterFunction(o)}},[t,o,r,c,l,u])}function vt(e,n){const t=D(),o=(0,s.useRef)(e);o.current=e,(0,s.useEffect)(()=>(t.registerNavigationFunction(r=>o.current(r),n),()=>{t.unregisterNavigationFunction()}),[t,n])}function Ct(e,n){const t=D(),o=n?.functionName??"setPageState",r=n?.requiresApproval,c=n?.data!==void 0,i=n?.data?.description,l=n?.data?.maxResultBytes,u=n?.settleTimeoutMs,p=(0,s.useRef)(e);p.current=e;const g=(0,s.useRef)(n);g.current=n,(0,s.useEffect)(()=>{const S=p.current.map(k=>{const _=()=>p.current.find(f=>f.name===k.name)??k;return{name:k.name,description:k.description,schema:k.schema,get:k.get?()=>_().get?.():void 0,set:f=>_().set(f)}}),R=c?{description:i??"What the page is currently showing.",maxResultBytes:l,get:()=>g.current?.data?.get(),isLoading:()=>g.current?.data?.isLoading?.()??!1}:void 0;return t.registerPageStateFunction(S,{functionName:o,requiresApproval:r,data:R,settleTimeoutMs:u}),()=>{t.unregisterPageStateFunction(o)}},[t,o,r,c,i,l,u])}function wt(e){const n=D(),t=(0,s.useRef)(e);t.current=e,(0,s.useEffect)(()=>qe.attachAutoContinueAfterNavigation(n,()=>t.current),[n])}function kt(e={}){const n=W(),t=e.client||n;if(!t)throw new P.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[o,r]=(0,s.useState)(()=>t.getRecentActivity());(0,s.useEffect)(()=>{r(t.getRecentActivity());const l=()=>r(t.getRecentActivity());return t.on("activity:recorded",l),()=>t.off("activity:recorded",l)},[t]);const c=(0,s.useCallback)(l=>t.recordActivity(l),[t]),i=(0,s.useCallback)(()=>{t.clearActivity(),r([])},[t]);return{entries:o,latest:o.length>0?o[o.length-1]:void 0,record:c,clear:i}}function St(e,n){const t=D(),o=(0,s.useId)(),r=n??o,c=(0,s.useRef)(e);c.current=e;const i=typeof e=="function";(0,s.useEffect)(()=>{if(typeof c.current=="function"){const l=()=>c.current();return t.addDynamicContext(r,l),()=>{t.removeDynamicContext(r)}}return t.setContext(r,c.current),()=>{t.removeContext(r)}},[t,r,i,i?"":JSON.stringify(e)])}function Se(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var fe={missing:[],complete:!1};function jt(e){const n=D(),t=e.schema!=null,o=JSON.stringify(e.schema??null),r=e.submit,c=r?typeof r=="string"?`client:${r}`:r.via==="backend"?"backend":"handler"in r?"client:handler":`client:${r.url}`:"none",i=JSON.stringify(e.initialValues??null),l=(0,s.useMemo)(()=>t?z.createFormCollector(e):null,[t,e.name,o,c,i,e.autoSubmit]),[u,p]=(0,s.useState)({collector:null,loading:!t,error:null});(0,s.useEffect)(()=>{if(t)return;let d=!1;return p({collector:null,loading:!0,error:null}),z.loadFormCollector(n,e).then(b=>{d||p({collector:b,loading:!1,error:null})}).catch(b=>{d||p({collector:null,loading:!1,error:b instanceof Error?b:new Error(String(b))})}),()=>{d=!0}},[n,t,e.name,c,i,e.autoSubmit]);const g=t?l:u.collector,S=t?!1:u.loading,R=t?null:u.error;(0,s.useEffect)(()=>{if(g)return g.install(n)},[n,g]);const k=(0,s.useMemo)(()=>P.createStore({values:e.initialValues??{},submitted:!1}),[i]),_=Se(g?.store??k),f=(0,s.useMemo)(()=>g?.getStatus()??fe,[_,g]),A=(0,s.useMemo)(()=>({..._,...f}),[_,f]),C=(0,s.useMemo)(()=>({name:e.name,store:k,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>k.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>fe}),[e.name,k]);return{...g??C,state:A,loading:S,error:R}}exports.AgoNudge=ht;exports.AgoProvider=$e;exports.ChatInput=ye;exports.ChatWidget=mt;exports.Markdown=be;exports.Message=Ce;exports.__exportAll=Le;exports.createFormCollector=z.createFormCollector;exports.createMockClient=Be.createMockClient;exports.deriveFormStatus=z.deriveFormStatus;exports.loadFormCollector=z.loadFormCollector;exports.useAgo=pe;exports.useAgoActivity=xe;exports.useAgoActivityLog=kt;exports.useAgoAutoContinueAfterNavigation=wt;exports.useAgoClient=D;exports.useAgoContext=St;exports.useAgoFunction=bt;exports.useAgoNavigation=vt;exports.useAgoPageState=Ct;exports.useAgoStore=Se;exports.useChat=yt;exports.useConversation=ke;exports.useFormCollector=jt;exports.useMessages=te;exports.useOptionalAgoClient=W;exports.useProactiveNudge=we;exports.useSheet=me;
|