@useago/sdk 1.13.3 → 1.14.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 +6 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +7 -0
- package/dist/angular.d.ts +7 -0
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-DrmOaZdO.js → createConversationSession-CybQdMpK.js} +1 -1
- package/dist/{createConversationSession-Digvn0GQ.cjs → createConversationSession-jwSXhTLe.cjs} +1 -1
- package/dist/{createFormCollector-D_5SDuk9.cjs → createFormCollector-B_hSKcLd.cjs} +1 -1
- package/dist/{createFormCollector-D6_N8wYq.js → createFormCollector-DJjms78E.js} +1 -1
- package/dist/devtools.d.cts +7 -0
- package/dist/devtools.d.ts +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -6
- package/dist/react.cjs +4 -4
- package/dist/react.d.cts +8 -1
- package/dist/react.d.ts +8 -1
- package/dist/react.js +901 -912
- package/dist/speechToText-BB25_zVM.cjs +7 -0
- package/dist/speechToText-BLvTis4S.js +1496 -0
- package/dist/testing.d.cts +7 -0
- package/dist/testing.d.ts +7 -0
- package/dist/{types-D1ZrqVhr.js → types-C39MJUE3.js} +284 -259
- package/dist/{types-DNr6XEwI.cjs → types-PGXnhAmQ.cjs} +7 -7
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +7 -0
- package/dist/vue.d.ts +7 -0
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +5 -6
- package/dist/widget.d.cts +12 -4
- package/dist/widget.d.ts +12 -4
- package/dist/widget.js +1868 -1841
- package/llms-full.txt +23 -3
- package/package.json +1 -1
- package/dist/speechToText-BV7qxqPF.js +0 -704
- package/dist/speechToText-ZciRyyJE.cjs +0 -1
package/dist/react.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var $e=Object.create,Y=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ue=Object.getOwnPropertyNames,Ge=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty,Ve=(e,r)=>{let t={};for(var s in e)Y(t,s,{get:e[s],enumerable:!0});return r||Y(t,Symbol.toStringTag,{value:"Module"}),t},Xe=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(var o=Ue(r),l=0,c=o.length,i;l<c;l++)i=o[l],!Je.call(e,i)&&i!==t&&Y(e,i,{get:(x=>r[x]).bind(null,i),enumerable:!(s=Ke(r,i))||s.enumerable});return e},oe=(e,r,t)=>(t=e!=null?$e(Ge(e)):{},Xe(r||!e||!e.__esModule?Y(t,"default",{value:e,enumerable:!0}):t,e));const L=require("./types-DNr6XEwI.cjs"),Z=require("./errors-o1IB5fEu.cjs"),Ye=require("./autoContinue-C3UsCvT5.cjs"),z=require("./createFormCollector-D_5SDuk9.cjs"),Ze=require("./createMockClient-BPt1gSve.cjs"),G=require("./speechToText-ZciRyyJE.cjs");let n=require("react");n=oe(n,1);let a=require("react/jsx-runtime"),te=require("react-markdown");te=oe(te,1);let ne=require("remark-gfm");ne=oe(ne,1);function ye(e){const[r,t]=(0,n.useState)(!1),s=(0,n.useRef)(null),o=(0,n.useMemo)(()=>{if(s.current&&(s.current.destroy(),s.current=null),!e)return null;const l=new L.AgoClient(e);return s.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(o&&s.current===null&&(s.current=o,o.reviveAfterDestroy()),t(!0),()=>{s.current?.destroy(),s.current=null}),[o]),(0,n.useEffect)(()=>{s.current&&e&&s.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,language:e.language??null,userEmail:e.userEmail,userJwt:e.userJwt,metadata:e.metadata??null,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.language,e?.userEmail,e?.userJwt,e?.metadata,e?.debug,e?.warnOnEmptyReply]),{client:o,isReady:r}}var se=(0,n.createContext)(null),Qe=({children:e,client:r,tools:t,helpers:s,pageContext:o,...l})=>{const{client:c}=ye(r?null:l),i=r||c;return(0,n.useEffect)(()=>{if(!(!t||t.length===0)){for(const x of t)i.register(x);return()=>{for(const x of t)i.unregisterFunction(x.name)}}},[i,t]),(0,n.useEffect)(()=>{if(!s)return;const x=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(d=>d.functions_exports).then(d=>{for(const[g,w]of Object.entries(s)){const m=d[g];if(!m){console.warn(`[AGO] Unknown helper: "${g}"`);continue}const f=w===!0?m:{...m,handler:w};i.register(f),x.push(f.name)}}),()=>{for(const d of x)i.unregisterFunction(d)}},[i,s]),(0,n.useEffect)(()=>{o==="auto"&&i.enableAutoPageContext()},[i,o]),(0,a.jsx)(se.Provider,{value:i,children:e})};function B(){const e=(0,n.useContext)(se);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function D(){return(0,n.useContext)(se)}var et=new Set(["awaiting-approval"]);function ve(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 tt(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":ve(e.type)}function ge(e,r){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"))&&(r==="confirmation"||r==="form")?"awaiting-approval":"running"}function xe(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,r=>r.toUpperCase()).trim()}function nt(e){switch(e.kind){case"navigation":return`Navigating to ${xe(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||xe(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 Ce(e={}){const{includeReasoning:r=!1,labelFor:t}=e,s=D(),o=e.client||s;if(!o)throw new Z.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[l,c]=(0,n.useState)([]),i=(0,n.useRef)(new Set),x=(0,n.useRef)(void 0),d=(0,n.useRef)(t);d.current=t;const g=(0,n.useCallback)((p,S)=>{c(b=>{const N=b.findIndex(y=>y.id===p),_={...N>=0?b[N]:{id:p,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...S};return _.label=d.current?.(_)??nt(_),N>=0?[...b.slice(0,N),_,...b.slice(N+1)]:[...b,_]})},[]);(0,n.useEffect)(()=>{const p=h=>{x.current=h.messageId},S=h=>{const I=ve(h.type);I==="reasoning"&&!r||g(h.id,{kind:I,status:ge(h.status,I),messageId:x.current,toolName:h.toolName,toolDisplayName:h.toolDisplayName,message:h.message,data:h.data,formSchema:h.formSchema,requiresApproval:I==="confirmation"||I==="form"})},b=h=>{h.invocationId&&g(h.invocationId,{kind:h.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:x.current,functionName:h.functionName,arguments:h.arguments})},N=h=>{h.invocationId&&g(h.invocationId,{kind:h.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:x.current,functionName:h.functionName,arguments:h.arguments,requiresApproval:!0})},_=h=>{if(!h.invocationId)return;const I=h.result,u=typeof h.result=="object"&&I!==null&&I.approved===!1&&I.reason==="user_rejected";g(h.invocationId,{status:h.error?"error":u?"rejected":"done",requiresApproval:!1})},y=h=>{for(const I of h.messages??[])if(I.role==="assistant")for(const u of I.toolCalls??[]){const A=tt(u);A==="reasoning"&&!r||/waiting/i.test(u.status??"")||g(u.id,{kind:A,status:ge(u.status,A),messageId:I.id,toolName:u.toolName,toolDisplayName:u.toolDisplayName,functionName:u.functionName,arguments:u.arguments,message:u.message,data:u.data,formSchema:u.formSchema,requiresApproval:A==="confirmation"||A==="form"})}},k=h=>{c(I=>I.map(u=>u.status==="running"||u.status==="awaiting-approval"?{...u,status:h}:u))},j=()=>k("done"),E=()=>k("error");return o.on("message:start",p),o.on("toolCall:received",S),o.on("function:invoke",b),o.on("function:awaiting-approval",N),o.on("function:result",_),o.on("conversation:loaded",y),o.on("message:complete",j),o.on("message:error",E),()=>{o.off("message:start",p),o.off("toolCall:received",S),o.off("function:invoke",b),o.off("function:awaiting-approval",N),o.off("function:result",_),o.off("conversation:loaded",y),o.off("message:complete",j),o.off("message:error",E)}},[o,r,g]);const w=(0,n.useCallback)(async p=>{const S=l.find(b=>b.id===p);!S||S.status!=="awaiting-approval"||i.current.has(p)||S.kind!=="form"&&(i.current.add(p),g(p,{status:"running",requiresApproval:!1}),S.functionName?await o.approveFunction(p):await o.confirmToolCall(p))},[o,l,g]),m=(0,n.useCallback)(async p=>{const S=l.find(b=>b.id===p);!S||S.status!=="awaiting-approval"||i.current.has(p)||(i.current.add(p),g(p,{status:"rejected",requiresApproval:!1}),S.functionName?await o.rejectFunction(p):await o.rejectToolCall(p))},[o,l,g]),f=(0,n.useCallback)(async(p,S)=>{g(p,{status:"running",requiresApproval:!1}),await o.submitToolCallForm(p,S),g(p,{status:"done"})},[o,g]),v=(0,n.useCallback)(()=>{i.current.clear(),c([])},[]);return{items:l,latest:l.length>0?l[l.length-1]:void 0,isAwaitingApproval:l.some(p=>et.has(p.status)),approve:w,reject:m,submitForm:f,clear:v}}function ae({client:e,conversationId:r}={}){const t=D(),s=e||t;if(!s)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[o,l]=(0,n.useState)([]),[c,i]=(0,n.useState)(r),[x,d]=(0,n.useState)(!1),[g,w]=(0,n.useState)(null);(0,n.useEffect)(()=>{r&&r!==c&&(i(r),m(r))},[r]);const m=async f=>{try{l((await s.getMessages(f)).filter(v=>!v.hidden))}catch(v){w(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const f=y=>y==="IN_PROGRESS"||y==="WAITING_CLIENT",v=y=>{c||i(y.conversationId),d(!0),l(k=>{const j=k.findIndex(E=>E.id===y.messageId);return j>=0?k.map((E,h)=>h===j?{...E,status:"IN_PROGRESS"}:E):k.some(E=>E.role==="assistant"&&f(E.status))?k:[...k,{id:y.messageId,conversationId:y.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},p=y=>{l(k=>{const j=k.findIndex(E=>E.id===y.messageId);return j<0?k:k.map((E,h)=>h===j?{...E,content:E.content+y.content}:E)})},S=y=>{l(k=>{let j=-1;for(let E=k.length-1;E>=0;E--)if(k[E].role==="assistant"&&f(k[E].status)){j=E;break}return j<0?k:[...k.slice(0,j),{...k[j],...y},...k.slice(j+1)]})},b=y=>{l(k=>{const j=k.findIndex(E=>E.id===y.id);return j>=0?[...k.slice(0,j),y,...k.slice(j+1)]:[...k,y]}),d(!1)},N=y=>{w(new Error(y.error)),d(!1)},_=()=>{l(y=>{let k=-1;for(let j=y.length-1;j>=0;j--)if(y[j].role==="assistant"&&f(y[j].status)){k=j;break}return k<0?y:y[k].content?y.map((j,E)=>E===k?{...j,status:"CANCELED"}:j):y.filter((j,E)=>E!==k)}),d(!1)};return s.on("message:start",v),s.on("message:chunk",p),s.on("message:answer-complete",S),s.on("message:complete",b),s.on("message:error",N),s.on("message:stopped",_),()=>{s.off("message:start",v),s.off("message:chunk",p),s.off("message:answer-complete",S),s.off("message:complete",b),s.off("message:error",N),s.off("message:stopped",_)}},[s,c]),{messages:o,isLoading:x,error:g,sendMessage:(0,n.useCallback)(async(f,v)=>{d(!0),w(null);const p={id:`temp-${Date.now()}`,conversationId:c||"",content:f,role:"user",status:"DONE",attachments:v&&v.length>0?L.attachmentsFromFiles(v):void 0,createdAt:new Date},S={id:`temp-assistant-${Date.now()}`,conversationId:c||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(b=>[...b,p,S]);try{const b=await s.sendMessage(f,{conversationId:c,files:v});return b.conversationId&&!c&&i(b.conversationId),l(N=>{const _=N.filter(k=>!k.id.startsWith("temp-")),y={...p,id:p.id.replace("temp-","user-"),conversationId:b.conversationId};return _.some(k=>k.id===b.id)?[..._,y].sort((k,j)=>new Date(k.createdAt).getTime()-new Date(j.createdAt).getTime()):[..._,y,b]}),b}catch(b){return w(b instanceof Error?b:new Error("Failed to send message")),d(!1),l(N=>N.filter(_=>!_.id.startsWith("temp-"))),null}},[s,c]),stop:(0,n.useCallback)(async()=>{await s.stop()},[s]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),w(null)},[]),conversationId:c}}var me={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},rt={tabindex:"tabIndex"};function ot(e){const r={};for(const[t,s]of Object.entries(e))r[rt[t]??t]=s;return r}function we(e){const r=e!==!1,t=r?e??{}:void 0,s=(0,n.useRef)(t?.onStateChange);s.current=t?.onStateChange;const o=(0,n.useMemo)(()=>{if(r)return G.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(c,i)=>s.current?.(c,i)})},[r,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),l=(0,n.useSyncExternalStore)((0,n.useCallback)(c=>o?.subscribe(c)??(()=>{}),[o]),(0,n.useCallback)(()=>o?.getSnapshot()??me,[o]),(0,n.useCallback)(()=>o?.getServerSnapshot()??me,[o]));return{sheet:(0,n.useMemo)(()=>({...l,surface:{...l.surface,attrs:ot(l.surface.attrs)}}),[l]),expand:(0,n.useCallback)(c=>o?.expand(c),[o]),collapse:(0,n.useCallback)(c=>o?.collapse(c),[o]),toggle:(0,n.useCallback)(c=>o?.toggle(c),[o])}}var st=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function Se(e){const r=e.split(st);return r.length===1?e:r.map((t,s)=>s%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)},s):t.startsWith("**")?(0,a.jsx)("strong",{style:{fontWeight:600},children:t.slice(2,-2)},s):(0,a.jsx)("em",{children:t.slice(1,-1)},s))}var at=`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Ve=Object.create,ne=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ye=Object.getOwnPropertyNames,Ze=Object.getPrototypeOf,Qe=Object.prototype.hasOwnProperty,et=(e,o)=>{let t={};for(var s in e)ne(t,s,{get:e[s],enumerable:!0});return o||ne(t,Symbol.toStringTag,{value:"Module"}),t},tt=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(var r=Ye(o),i=0,u=r.length,l;i<u;i++)l=r[i],!Qe.call(e,l)&&l!==t&&ne(e,l,{get:(f=>o[f]).bind(null,l),enumerable:!(s=Xe(o,l))||s.enumerable});return e},ce=(e,o,t)=>(t=e!=null?Ve(Ze(e)):{},tt(o||!e||!e.__esModule?ne(t,"default",{value:e,enumerable:!0}):t,e));const q=require("./types-PGXnhAmQ.cjs"),oe=require("./errors-o1IB5fEu.cjs"),nt=require("./autoContinue-C3UsCvT5.cjs"),$=require("./createFormCollector-B_hSKcLd.cjs"),ot=require("./createMockClient-BPt1gSve.cjs"),D=require("./speechToText-BB25_zVM.cjs");let n=require("react");n=ce(n,1);let a=require("react/jsx-runtime"),ie=require("react-markdown");ie=ce(ie,1);let le=require("remark-gfm");le=ce(le,1);function Se(e){const[o,t]=(0,n.useState)(!1),s=(0,n.useRef)(null),r=(0,n.useMemo)(()=>{if(s.current&&(s.current.destroy(),s.current=null),!e)return null;const i=new q.AgoClient(e);return s.current=i,i},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(r&&s.current===null&&(s.current=r,r.reviveAfterDestroy()),t(!0),()=>{s.current?.destroy(),s.current=null}),[r]),(0,n.useEffect)(()=>{s.current&&e&&s.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,language:e.language??null,userEmail:e.userEmail,userJwt:e.userJwt,metadata:e.metadata??null,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.language,e?.userEmail,e?.userJwt,e?.metadata,e?.debug,e?.warnOnEmptyReply]),{client:r,isReady:o}}var ue=(0,n.createContext)(null),rt=({children:e,client:o,tools:t,helpers:s,pageContext:r,...i})=>{const{client:u}=Se(o?null:i),l=o||u;return(0,n.useEffect)(()=>{if(!(!t||t.length===0)){for(const f of t)l.register(f);return()=>{for(const f of t)l.unregisterFunction(f.name)}}},[l,t]),(0,n.useEffect)(()=>{if(!s)return;const f=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(d=>d.functions_exports).then(d=>{for(const[p,x]of Object.entries(s)){const b=d[p];if(!b){console.warn(`[AGO] Unknown helper: "${p}"`);continue}const g=x===!0?b:{...b,handler:x};l.register(g),f.push(g.name)}}),()=>{for(const d of f)l.unregisterFunction(d)}},[l,s]),(0,n.useEffect)(()=>{r==="auto"&&l.enableAutoPageContext()},[l,r]),(0,a.jsx)(ue.Provider,{value:l,children:e})};function K(){const e=(0,n.useContext)(ue);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,n.useContext)(ue)}function Y(e){const o=W(),t=e??o,s=(0,n.useCallback)(i=>(t?.on("config:changed",i),()=>{t?.off("config:changed",i)}),[t]),r=()=>t?.getLanguage?.()??null;return D.uiCatalog((0,n.useSyncExternalStore)(s,r,r))}var st=new Set(["awaiting-approval"]);function je(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 at(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":je(e.type)}function ye(e,o){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"))&&(o==="confirmation"||o==="form")?"awaiting-approval":"running"}function ve(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,o=>o.toUpperCase()).trim()}function it(e){switch(e.kind){case"navigation":return`Navigating to ${ve(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||ve(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 Ae(e={}){const{includeReasoning:o=!1,labelFor:t}=e,s=W(),r=e.client||s;if(!r)throw new oe.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[i,u]=(0,n.useState)([]),l=(0,n.useRef)(new Set),f=(0,n.useRef)(void 0),d=(0,n.useRef)(t);d.current=t;const p=(0,n.useCallback)((c,h)=>{u(y=>{const _=y.findIndex(m=>m.id===c),E={..._>=0?y[_]:{id:c,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...h};return E.label=d.current?.(E)??it(E),_>=0?[...y.slice(0,_),E,...y.slice(_+1)]:[...y,E]})},[]);(0,n.useEffect)(()=>{const c=S=>{f.current=S.messageId},h=S=>{const M=je(S.type);M==="reasoning"&&!o||p(S.id,{kind:M,status:ye(S.status,M),messageId:f.current,toolName:S.toolName,toolDisplayName:S.toolDisplayName,message:S.message,data:S.data,formSchema:S.formSchema,requiresApproval:M==="confirmation"||M==="form"})},y=S=>{S.invocationId&&p(S.invocationId,{kind:S.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:f.current,functionName:S.functionName,arguments:S.arguments})},_=S=>{S.invocationId&&p(S.invocationId,{kind:S.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:f.current,functionName:S.functionName,arguments:S.arguments,requiresApproval:!0})},E=S=>{if(!S.invocationId)return;const M=S.result,I=typeof S.result=="object"&&M!==null&&M.approved===!1&&M.reason==="user_rejected";p(S.invocationId,{status:S.error?"error":I?"rejected":"done",requiresApproval:!1})},m=S=>{for(const M of S.messages??[])if(M.role==="assistant")for(const I of M.toolCalls??[]){const R=at(I);R==="reasoning"&&!o||/waiting/i.test(I.status??"")||p(I.id,{kind:R,status:ye(I.status,R),messageId:M.id,toolName:I.toolName,toolDisplayName:I.toolDisplayName,functionName:I.functionName,arguments:I.arguments,message:I.message,data:I.data,formSchema:I.formSchema,requiresApproval:R==="confirmation"||R==="form"})}},k=S=>{u(M=>M.map(I=>I.status==="running"||I.status==="awaiting-approval"?{...I,status:S}:I))},A=()=>k("done"),j=()=>k("error");return r.on("message:start",c),r.on("toolCall:received",h),r.on("function:invoke",y),r.on("function:awaiting-approval",_),r.on("function:result",E),r.on("conversation:loaded",m),r.on("message:complete",A),r.on("message:error",j),()=>{r.off("message:start",c),r.off("toolCall:received",h),r.off("function:invoke",y),r.off("function:awaiting-approval",_),r.off("function:result",E),r.off("conversation:loaded",m),r.off("message:complete",A),r.off("message:error",j)}},[r,o,p]);const x=(0,n.useCallback)(async c=>{const h=i.find(y=>y.id===c);!h||h.status!=="awaiting-approval"||l.current.has(c)||h.kind!=="form"&&(l.current.add(c),p(c,{status:"running",requiresApproval:!1}),h.functionName?await r.approveFunction(c):await r.confirmToolCall(c))},[r,i,p]),b=(0,n.useCallback)(async c=>{const h=i.find(y=>y.id===c);!h||h.status!=="awaiting-approval"||l.current.has(c)||(l.current.add(c),p(c,{status:"rejected",requiresApproval:!1}),h.functionName?await r.rejectFunction(c):await r.rejectToolCall(c))},[r,i,p]),g=(0,n.useCallback)(async(c,h)=>{p(c,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(c,h),p(c,{status:"done"})},[r,p]),C=(0,n.useCallback)(()=>{l.current.clear(),u([])},[]);return{items:i,latest:i.length>0?i[i.length-1]:void 0,isAwaitingApproval:i.some(c=>st.has(c.status)),approve:x,reject:b,submitForm:g,clear:C}}function de({client:e,conversationId:o}={}){const t=W(),s=e||t;if(!s)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,i]=(0,n.useState)([]),[u,l]=(0,n.useState)(o),[f,d]=(0,n.useState)(!1),[p,x]=(0,n.useState)(null);(0,n.useEffect)(()=>{o&&o!==u&&(l(o),b(o))},[o]);const b=async g=>{try{i((await s.getMessages(g)).filter(C=>!C.hidden))}catch(C){x(C instanceof Error?C:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const g=m=>m==="IN_PROGRESS"||m==="WAITING_CLIENT",C=m=>{u||l(m.conversationId),d(!0),i(k=>{const A=k.findIndex(j=>j.id===m.messageId);return A>=0?k.map((j,S)=>S===A?{...j,status:"IN_PROGRESS"}:j):k.some(j=>j.role==="assistant"&&g(j.status))?k:[...k,{id:m.messageId,conversationId:m.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},c=m=>{i(k=>{const A=k.findIndex(j=>j.id===m.messageId);return A<0?k:k.map((j,S)=>S===A?{...j,content:j.content+m.content}:j)})},h=m=>{i(k=>{let A=-1;for(let j=k.length-1;j>=0;j--)if(k[j].role==="assistant"&&g(k[j].status)){A=j;break}return A<0?k:[...k.slice(0,A),{...k[A],...m},...k.slice(A+1)]})},y=m=>{i(k=>{const A=k.findIndex(j=>j.id===m.id);return A>=0?[...k.slice(0,A),m,...k.slice(A+1)]:[...k,m]}),d(!1)},_=m=>{x(new Error(m.error)),d(!1)},E=()=>{i(m=>{let k=-1;for(let A=m.length-1;A>=0;A--)if(m[A].role==="assistant"&&g(m[A].status)){k=A;break}return k<0?m:m[k].content?m.map((A,j)=>j===k?{...A,status:"CANCELED"}:A):m.filter((A,j)=>j!==k)}),d(!1)};return s.on("message:start",C),s.on("message:chunk",c),s.on("message:answer-complete",h),s.on("message:complete",y),s.on("message:error",_),s.on("message:stopped",E),()=>{s.off("message:start",C),s.off("message:chunk",c),s.off("message:answer-complete",h),s.off("message:complete",y),s.off("message:error",_),s.off("message:stopped",E)}},[s,u]),{messages:r,isLoading:f,error:p,sendMessage:(0,n.useCallback)(async(g,C)=>{d(!0),x(null);const c={id:`temp-${Date.now()}`,conversationId:u||"",content:g,role:"user",status:"DONE",attachments:C&&C.length>0?q.attachmentsFromFiles(C):void 0,createdAt:new Date},h={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};i(y=>[...y,c,h]);try{const y=await s.sendMessage(g,{conversationId:u,files:C});return y.conversationId&&!u&&l(y.conversationId),i(_=>{const E=_.filter(k=>!k.id.startsWith("temp-")),m={...c,id:c.id.replace("temp-","user-"),conversationId:y.conversationId};return E.some(k=>k.id===y.id)?[...E,m].sort((k,A)=>new Date(k.createdAt).getTime()-new Date(A.createdAt).getTime()):[...E,m,y]}),y}catch(y){return x(y instanceof Error?y:new Error("Failed to send message")),d(!1),i(_=>_.filter(E=>!E.id.startsWith("temp-"))),null}},[s,u]),stop:(0,n.useCallback)(async()=>{await s.stop()},[s]),clearMessages:(0,n.useCallback)(()=>{i([]),l(void 0),x(null)},[]),conversationId:u}}var Ce={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},lt={tabindex:"tabIndex"};function ct(e){const o={};for(const[t,s]of Object.entries(e))o[lt[t]??t]=s;return o}function Ee(e){const o=e!==!1,t=o?e??{}:void 0,s=(0,n.useRef)(t?.onStateChange);s.current=t?.onStateChange;const r=(0,n.useMemo)(()=>{if(o)return D.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(u,l)=>s.current?.(u,l)})},[o,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),i=(0,n.useSyncExternalStore)((0,n.useCallback)(u=>r?.subscribe(u)??(()=>{}),[r]),(0,n.useCallback)(()=>r?.getSnapshot()??Ce,[r]),(0,n.useCallback)(()=>r?.getServerSnapshot()??Ce,[r]));return{sheet:(0,n.useMemo)(()=>({...i,surface:{...i.surface,attrs:ct(i.surface.attrs)}}),[i]),expand:(0,n.useCallback)(u=>r?.expand(u),[r]),collapse:(0,n.useCallback)(u=>r?.collapse(u),[r]),toggle:(0,n.useCallback)(u=>r?.toggle(u),[r])}}var ut=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function _e(e){const o=e.split(ut);return o.length===1?e:o.map((t,s)=>s%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)},s):t.startsWith("**")?(0,a.jsx)("strong",{style:{fontWeight:600},children:t.slice(2,-2)},s):(0,a.jsx)("em",{children:t.slice(1,-1)},s))}var dt=`
|
|
2
2
|
@keyframes ago-activity-enter {
|
|
3
3
|
from { opacity: 0; transform: translateY(4px); }
|
|
4
4
|
to { opacity: 1; transform: none; }
|
|
@@ -35,10 +35,10 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var $e=Object
|
|
|
35
35
|
color: var(--ago-activity-color, #5b5d5f);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,
|
|
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:
|
|
38
|
+
`,ft=({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:_e(e)},e),(0,a.jsx)("style",{children:dt})]}),X=typeof window>"u"?n.useEffect:n.useLayoutEffect;function Re(e){const o=W(),t=e.client??o,s=Y(t),r=(0,n.useRef)(null),i=(0,n.useRef)(),u=(0,n.useRef)(e),[l,f]=(0,n.useState)(!1),[d,p]=(0,n.useState)(""),[x,b]=(0,n.useState)(!1);return X(()=>{u.current=e}),X(()=>{if(b(!1),f(!1),u.current.onBusyChange?.(!1),!t||!r.current)return;let g=!0;const C=D.createSpeechToText({transcribe:(c,h)=>t.transcribeAudio(c,h),onText:c=>{g&&u.current.onTranscript(c)},onBusy:c=>{g&&(f(c),c&&p(""),u.current.onBusyChange?.(c))},onError:c=>{g&&p(c)},labels:D.withOverrides(s.speech,u.current.labels)});return r.current.append(C.el),i.current=C,C.setDisabled(!!u.current.disabled),t.getConfig().then(({permissions:c})=>{if(!g)return;const h=c.some(y=>y.speechToTextEnabled)&&typeof MediaRecorder<"u"&&!!navigator.mediaDevices?.getUserMedia;C.setEnabled(h),b(h)}).catch(()=>{}),()=>{g=!1,C.destroy(),u.current.onBusyChange?.(!1),C.el.remove(),i.current=void 0}},[t]),X(()=>{i.current?.setDisabled(!!e.disabled)},[e.disabled]),X(()=>{i.current?.cancel()},[e.scopeKey,t]),X(()=>{i.current?.setLabels(D.withOverrides(s.speech,e.labels))},[s,e.labels]),(0,a.jsxs)("div",{className:`ago-speech-to-text ${e.className??""}`,style:{display:x?"flex":"none",flexDirection:"column",minWidth:0,flex:l?1:void 0},children:[(0,a.jsx)("div",{ref:r}),d&&(0,a.jsx)("span",{role:"alert",style:{color:"var(--ago-muted-text-color, #6b6d6f)",fontSize:"13px"},children:d})]})}var Ne=({onSend:e,onStop:o,disabled:t=!1,placeholder:s,allowFiles:r=!1,speechToText:i=!1,client:u,scopeKey:l,className:f=""})=>{const d=Y(u),p=s??d.common.placeholder,[x,b]=(0,n.useState)(""),[g,C]=(0,n.useState)([]),[c,h]=(0,n.useState)(!1),y=(0,n.useRef)(null),_=(0,n.useRef)(null),E=!!i;(0,n.useEffect)(()=>{E||h(!1)},[E]);const m=(0,n.useCallback)(()=>{const w=_.current;if(!w)return;const N=110;w.style.height="auto",w.style.height=`${Math.min(w.scrollHeight+2,N)}px`,w.style.overflowY=w.scrollHeight+2>N?"auto":"hidden"},[]),k=(0,n.useRef)(!1);(0,n.useEffect)(()=>{k.current&&!c&&!t&&(m(),_.current?.focus()),k.current=c},[c,t,m]);const A=(0,n.useCallback)(async w=>{if(w.preventDefault(),t||c||!x.trim())return;const N=x.trim(),B=g.length>0?g:void 0;b(""),C([]),requestAnimationFrame(m),await e(N,B)===!1&&(b(O=>O.trim()?O:N),B&&C(O=>[...B,...O]),requestAnimationFrame(m))},[x,g,e,m,t,c]),j=(0,n.useCallback)(w=>{w.key==="Enter"&&!w.shiftKey&&(w.preventDefault(),A(w))},[A]),S=(0,n.useCallback)(w=>{const N=Array.from(w.target.files||[]);C(B=>[...B,...N])},[]),M=(0,n.useCallback)(w=>{C(N=>N.filter((B,O)=>O!==w))},[]),I=x.trim().length>0,R=w=>{b(N=>`${N}${N&&!/\s$/.test(N)?" ":""}${w}`)};return(0,a.jsxs)("form",{onSubmit:w=>{A(w)},className:`ago-chat-input ${f}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[g.length>0&&!c&&(0,a.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:g.map((w,N)=>(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:w.name}),(0,a.jsx)("button",{type:"button",onClick:()=>M(N),"aria-label":d.form.removeFile.replace("{filename}",()=>w.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:"×"})]},N))}),(0,a.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&!c&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>y.current?.click(),disabled:t,"aria-label":d.common.attachFile,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:y,type:"file",multiple:!0,onChange:S,style:{display:"none"}})]}),(0,a.jsx)("textarea",{ref:_,className:"ago-chat-input__field",value:x,onChange:w=>{b(w.target.value),m()},onKeyDown:j,placeholder:p,"aria-label":p,disabled:t||c,rows:1,style:{display:c?"none":void 0,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:w=>{w.currentTarget.style.borderColor="#1b5fc4"},onBlur:w=>{w.currentTarget.style.borderColor="#dee3e8"}}),i&&(0,a.jsx)(Re,{client:u,disabled:t,scopeKey:l,labels:typeof i=="object"?i.labels:void 0,onTranscript:R,onBusyChange:h}),!c&&(t&&o?(0,a.jsx)("button",{type:"button",onClick:o,"aria-label":d.common.stop,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:d.common.stopButton}):(0,a.jsx)("button",{type:"submit",disabled:t||!I,style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!I?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!I?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:d.common.send}))]})]})},pt=({href:e,children:o,...t})=>(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:o}),gt=({children:e,...o})=>(0,a.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...o,children:e}),G=(e,o)=>{const t=({children:s,...r})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:o,fontWeight:600,lineHeight:"1.3"},...r},s);return t.displayName=`MarkdownHeading${e}`,t},mt=({children:e,...o})=>(0,a.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...o,children:e}),xt=({children:e,...o})=>(0,a.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...o,children:e}),ht=({children:e,...o})=>(0,a.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...o,children:e}),bt=({className:e,children:o,...t})=>e!==void 0||String(o).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:o}):(0,a.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...t,children:o}),yt=({children:e,...o})=>(0,a.jsx)("pre",{style:{margin:"0 0 8px 0"},...o,children:e}),vt=({children:e,...o})=>(0,a.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...o,children:e}),Ct=({children:e,...o})=>(0,a.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,a.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...o,children:e})}),wt=({children:e,...o})=>(0,a.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...o,children:e}),kt=({children:e,...o})=>(0,a.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...o,children:e}),St=({alt:e,...o})=>(0,a.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...o}),jt=e=>(0,a.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),At={a:pt,p:gt,h1:G(1,"20px"),h2:G(2,"18px"),h3:G(3,"16px"),h4:G(4,"15px"),h5:G(5,"14px"),h6:G(6,"13px"),ul:mt,ol:xt,li:ht,code:bt,pre:yt,blockquote:vt,table:Ct,th:wt,td:kt,img:St,hr:jt},Et=[le.default],Ie=({content:e})=>(0,a.jsx)(ie.default,{remarkPlugins:Et,components:At,children:e}),_t=({attachment:e,isUser:o})=>{const t=q.safeAttachmentUrl(e.url);if(q.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 s=q.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}),s&&(0,a.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:s})]})]}),i={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:o?"rgba(255,255,255,0.12)":"#fff",color:o?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return t?(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:i,children:r}):(0,a.jsx)("div",{style:i,children:r})},Rt=({source:e,index:o})=>{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:o+1}),(0,a.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),s={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:s,onMouseEnter:r=>{r.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:r=>{r.currentTarget.style.borderColor="#dee3e8"},children:t}):(0,a.jsx)("div",{style:s,children:t})},Me=()=>(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:`
|
|
40
40
|
@keyframes ago-pulse {
|
|
41
41
|
0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
|
|
42
42
|
40% { opacity: 1; transform: scale(1); }
|
|
43
43
|
}
|
|
44
|
-
`})]}),_e=({message:e,className:r="",showAgentName:t=!1,isLast:s=!1,onFollowUpClick:o,showStreamingDots:l=!0,feedback:c})=>{const i=e.role==="user",x=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,a.jsxs)("div",{className:`ago-message ago-message--${e.role} ${r}`,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((d,g)=>(0,a.jsx)(kt,{source:d,index:g},d.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(d=>(0,a.jsx)(St,{attachment:d,isUser:i},d.id))}),(e.content||x&&l)&&(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)(je,{content:e.content}):x&&l&&(0,a.jsx)(Ee,{})}),!i&&c,s&&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((d,g)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!o,onClick:o?()=>o(d):void 0,style:{minHeight:"44px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:o?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:w=>{w.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:w=>{w.currentTarget.style.borderColor="#dee3e8"},children:d},g))})]})};function Re({client:e}={}){const r=D(),t=e||r;if(!t)throw new Z.AgoError("useFeedback requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","missing_client");const[s,o]=(0,n.useState)({}),[l,c]=(0,n.useState)(!1),[i,x]=(0,n.useState)(null),d=(0,n.useRef)(new Map),g=m=>{const f=(d.current.get(m)??0)+1;return d.current.set(m,f),f},w=(m,f)=>d.current.get(m)===f;return{ratings:s,submitFeedback:(0,n.useCallback)(async(m,f,v)=>{const p=g(m);c(!0),x(null);try{await t.submitFeedback(m,f,v),w(m,p)&&o(S=>({...S,[m]:f}))}catch(S){const b=S instanceof Error?S:new Error("Failed to submit feedback");throw x(b),b}finally{c(!1)}},[t]),submitConversationFeedback:(0,n.useCallback)(async(m,f,v)=>{const p=g(m);c(!0),x(null);try{const S=await t.submitConversationFeedback(m,f,v);return w(m,p)&&o(b=>({...b,[S]:f})),S}catch(S){const b=S instanceof Error?S:new Error("Failed to submit feedback");throw x(b),b}finally{c(!1)}},[t]),isSubmitting:l,error:i}}var re={helpful:"Helpful",notHelpful:"Not helpful",whatWentWrong:"What went wrong?",reasons:{inaccurate:"Inaccurate",incomplete:"Incomplete",information_not_found:"Information not found",technical_issue:"Technical issue"},commentPlaceholder:"Anything else? (optional)",send:"Send",thanks:"Thanks, this was reported."},At={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:0,border:"none",borderRadius:"8px",background:"transparent",cursor:"pointer",lineHeight:1},Ne=({messageId:e,client:r,askWhy:t=!0,labels:s,onSubmit:o,onError:l,className:c=""})=>{const i={...re,...s,reasons:{...re.reasons,...s?.reasons}},{ratings:x,submitFeedback:d}=Re({client:r}),g=x[e],[w,m]=(0,n.useState)(!1),[f,v]=(0,n.useState)([]),[p,S]=(0,n.useState)(""),[b,N]=(0,n.useState)(!1),[_,y]=(0,n.useState)(!1),k=async(u,A)=>{try{return await d(e,u,A),o?.({messageId:e,rating:u,reasons:A?.reasons??[],comment:A?.comment||void 0}),!0}catch(R){return l?.(R instanceof Error?R:new Error(String(R))),!1}},j=u=>{k(u),m(u==="negative"&&t&&!b)},E=u=>{v(A=>A.includes(u)?A.filter(R=>R!==u):[...A,u])},h=f.length>0||p.trim().length>0,I=()=>{!h||_||(y(!0),k(g??"negative",{reasons:f,comment:p.trim()}).then(u=>{y(!1),u&&(N(!0),m(!1))}))};return(0,a.jsxs)("div",{className:`ago-feedback ${c}`,style:{marginTop:"6px",width:"100%",maxWidth:"85%"},children:[(0,a.jsxs)("div",{className:"ago-feedback__actions",style:{display:"flex",alignItems:"center",gap:"2px"},children:[(0,a.jsx)(he,{direction:"up",label:i.helpful,selected:g==="positive",onClick:()=>j("positive")}),(0,a.jsx)(he,{direction:"down",label:i.notHelpful,selected:g==="negative",onClick:()=>j("negative")})]}),b&&(0,a.jsx)("div",{className:"ago-feedback__thanks",role:"status",style:{marginTop:"6px",fontSize:"13px",color:"#6b6d6f"},children:i.thanks}),w&&!b&&(0,a.jsxs)("div",{className:"ago-feedback__panel",role:"group","aria-label":i.whatWentWrong,style:{marginTop:"8px",padding:"12px",border:"1px solid #dee3e8",borderRadius:"16px",backgroundColor:"#fff"},children:[(0,a.jsx)("div",{style:{fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"8px"},children:i.whatWentWrong}),(0,a.jsx)("div",{className:"ago-feedback__reasons",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"},children:L.FEEDBACK_REASONS.map(u=>{const A=f.includes(u);return(0,a.jsx)("button",{type:"button",className:"ago-feedback__reason","aria-pressed":A,onClick:()=>E(u),style:{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${A?"#1b5fc4":"#dee3e8"}`,backgroundColor:"transparent",color:A?"#1b5fc4":"#30373e",cursor:"pointer"},children:i.reasons[u]},u)})}),(0,a.jsx)("textarea",{className:"ago-feedback__comment",rows:2,value:p,placeholder:i.commentPlaceholder,"aria-label":i.commentPlaceholder,onChange:u=>S(u.target.value),style:{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:"#30373e",border:"1px solid #dee3e8",borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}}),(0,a.jsx)("button",{type:"button",className:"ago-feedback__send",onClick:I,disabled:!h||_,style:{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:h?"#03182f":"#b5bfc8",color:"#fff",opacity:_?.6:1,cursor:h&&!_?"pointer":"default"},children:i.send})]})]})},he=({direction:e,label:r,selected:t,onClick:s})=>(0,a.jsx)("button",{type:"button",className:`ago-feedback__thumb ago-feedback__thumb--${e}`,"aria-label":r,"aria-pressed":t,title:r,onClick:s,style:{...At,color:t?"#1b5fc4":"#6b6d6f"},children:(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:e==="down"?{transform:"rotate(180deg)"}:void 0,children:[(0,a.jsx)("path",{d:"M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"}),(0,a.jsx)("path",{d:"M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"})]})}),jt=(0,n.forwardRef)(function({client:r,conversationId:t,title:s="Chat",welcomeMessage:o="Hello! How can I help you today?",placeholder:l="Type a message...",allowFiles:c=!1,speechToText:i=!1,allowStop:x=!0,height:d=500,logoUrl:g,showAgentName:w=!1,forms:m,feedback:f=!1,onFollowUpClick:v,className:p="",onMessageSent:S,onMessageReceived:b,sheet:N=!1,thinkingLabel:_="Thinking...",functionLabels:y,showReasoning:k=!0},j){const E=(0,n.useRef)(null),h=(0,n.useRef)(!0),[I,u]=(0,n.useState)(!0),A=(0,n.useRef)(null),{sheet:R,expand:P,collapse:$,toggle:ie}=we(N),[Fe,Q]=(0,n.useState)(!1),ee=R.compact&&R.state==="peek",Pe=D(),H=r??Pe,{messages:F,isLoading:De,error:le,sendMessage:We,stop:Le}=ae({client:r,conversationId:t});(0,n.useEffect)(()=>{if(!H||!m||m.length===0)return;let C=!1;const T=[];return Promise.all(m.map(M=>M.schema!=null?Promise.resolve(z.createFormCollector(M)):z.loadFormCollector(H,M))).then(M=>{if(!C)for(const W of M)T.push(W.install(H))}).catch(()=>{}),()=>{C=!0,T.forEach(M=>M())}},[H,m?JSON.stringify(m.map(C=>[C.name,C.schema??null,C.submit??!1,C.description??null])):""]),(0,n.useEffect)(()=>{const C=E.current;!C||!h.current||(C.scrollTop=C.scrollHeight)},[F]);const Oe=()=>{const C=E.current;C&&(h.current=!0,u(!0),C.scrollTop=C.scrollHeight)};(0,n.useEffect)(()=>{const C=F[F.length-1];C&&C.role==="assistant"&&C.status==="DONE"&&b&&b({id:C.id,content:C.content})},[F,b]),(0,n.useEffect)(()=>{Q(!!ee)},[F.length]),(0,n.useEffect)(()=>{const C=A.current;if(!R.compact||!C)return;const T=document.documentElement;if(R.state!=="peek")return;const M=()=>{T.style.setProperty("--ago-sheet-height",`${Math.round(C.getBoundingClientRect().height)}px`)};M();const W=typeof ResizeObserver=="function"?new ResizeObserver(M):null;return W?.observe(C),()=>W?.disconnect()},[R.compact,R.state]),(0,n.useEffect)(()=>{R.compact||document.documentElement.style.removeProperty("--ago-sheet-height")},[R.compact]),(0,n.useEffect)(()=>()=>{document.documentElement.style.removeProperty("--ago-sheet-height")},[]),(0,n.useImperativeHandle)(j,()=>({expand:P,collapse:$,toggle:ie,state:R.state}),[P,$,ie,R.state]),(0,n.useEffect)(()=>{if(!R.isModal)return;const C=Symbol("ago-react-sheet");G.lockBackgroundScroll(C);const T=M=>{if(M.key==="Escape"){$("user");return}if(M.key!=="Tab")return;const W=A.current;if(!W)return;const V=Array.from(W.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(qe=>qe.getClientRects().length>0);if(V.length===0){M.preventDefault();return}const fe=V[0],pe=V[V.length-1],X=document.activeElement;M.shiftKey&&(X===fe||!W.contains(X))?(M.preventDefault(),pe.focus()):!M.shiftKey&&(X===pe||!W.contains(X))&&(M.preventDefault(),fe.focus())};return document.addEventListener("keydown",T),A.current?.focus({preventScroll:!0}),()=>{document.removeEventListener("keydown",T),G.unlockBackgroundScroll(C)}},[R.isModal,$]);const ce=async(C,T)=>(h.current=!0,u(!0),S?.(C),await We(C,T)!==null),O=F[F.length-1],J=De&&O?.role==="assistant"&&(O.status==="IN_PROGRESS"||O.status==="WAITING_CLIENT"),ze=(0,n.useCallback)(C=>{const T=C.functionName;if(!(!y||!T))return typeof y=="function"?y(T,C.arguments??{}):y[T]},[y]),{items:Be}=Ce({client:H??void 0,labelFor:ze,includeReasoning:k}),ue=Be.filter(C=>O?.id!==void 0&&C.messageId===O.id),K=y===!1?void 0:ue[ue.length-1]?.label,de=!!(J&&K),He=v===!1?void 0:v??(C=>ce(C));return(0,a.jsxs)("div",{ref:A,className:`ago-chat-widget ${p}`,...R.surface.attrs,"data-ago-sheet-state":R.compact?R.state:void 0,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px",...R.surface.style},children:[!R.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:[g&&(0,a.jsx)("img",{src:g,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,a.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),ee&&(0,a.jsxs)("button",{type:"button",className:"ago-chat-widget__peek","aria-expanded":!1,"aria-label":"Open the conversation",onClick:()=>{Q(!1),P("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:[s,Fe&&(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:"↑"})]}),J&&!O?.content?(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[!K&&(0,a.jsx)(Ee,{}),(0,a.jsx)("span",{style:{fontSize:"13px",opacity:.7,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:K?Se(K):_})]}):(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||o})]}),R.compact&&R.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:s}),(0,a.jsx)("button",{type:"button","aria-label":"Collapse the conversation",onClick:()=>$("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:ee?"none":"flex",minHeight:0},children:[(0,a.jsxs)("div",{ref:E,className:"ago-chat-widget__messages",onScroll:C=>{const T=C.currentTarget,M=T.scrollHeight-T.scrollTop-T.clientHeight<=48;h.current=M,u(M)},role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,"aria-busy":J,style:{flex:1,overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:"#fbfbfb"},children:[F.length===0?(0,a.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:o}):F.map((C,T)=>(0,a.jsx)(_e,{message:C,showAgentName:w,isLast:T===F.length-1,onFollowUpClick:He,showStreamingDots:!de,feedback:f&&C.role==="assistant"&&C.status==="DONE"&&C.content?(0,a.jsx)(Ne,{messageId:C.id,client:r,...f===!0?{}:f}):void 0},C.id)),de&&(0,a.jsx)(it,{label:K??""}),le&&(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:le.message}),(0,a.jsx)("div",{})]}),!I&&(0,a.jsx)("button",{type:"button",className:"ago-chat-widget__jump","aria-label":"Jump to latest message",onClick:Oe,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)(Ae,{onSend:ce,onStop:x?()=>{Le()}:void 0,disabled:J,placeholder:l,allowFiles:c,speechToText:i,client:H??void 0,scopeKey:`${t??F[0]?.conversationId??""}:${R.state}`})]})});function Ie(e={}){const r=D(),t=e.client??r;if(!t)throw new Z.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[s,o]=(0,n.useState)(null),l=(0,n.useRef)(s);l.current=s;const c=(0,n.useRef)(e.onExpand);return c.current=e.onExpand,(0,n.useEffect)(()=>{const i=d=>{o(d),t.proactive?.shown(d)},x=({nudge:d})=>{o(g=>g?.id===d.id?null:g)};return t.on("nudge:ready",i),t.on("nudge:accepted",x),t.on("nudge:dismissed",x),()=>{t.off("nudge:ready",i),t.off("nudge:accepted",x),t.off("nudge:dismissed",x)}},[t]),{nudge:s,accept:(0,n.useCallback)(async()=>{const i=l.current;i&&(o(null),await t.proactive?.accept(i),(i.source==="agent"||i.goal)&&c.current?.(i))},[t]),dismiss:(0,n.useCallback)(()=>{const i=l.current;i&&(o(null),t.proactive?.dismiss(i))},[t])}}var Et=({client:e,onExpand:r,autoHideMs:t,position:s="bottom-right",openChatLabel:o="Open chat",className:l=""})=>{const{nudge:c,accept:i,dismiss:x}=Ie({client:e,onExpand:r});if((0,n.useEffect)(()=>{if(!c||!t)return;const g=setTimeout(()=>x(),t);return()=>clearTimeout(g)},[c,t,x]),!c)return null;const d=c.source==="agent"||!!c.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${l}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...s==="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:x,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:c.message}),(c.action||d)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[c.action&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{i()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:c.action.label}),d&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{i()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:o})]})]})};function Me({client:e,autoLoad:r=!0}={}){const t=D(),s=e||t;if(!s)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[o,l]=(0,n.useState)([]),[c,i]=(0,n.useState)(null),[x,d]=(0,n.useState)(!1),[g,w]=(0,n.useState)(null),m=(0,n.useCallback)(async()=>{d(!0),w(null);try{const{data:p}=await s.getConversations();l(p)}catch(p){w(p instanceof Error?p:new Error("Failed to load conversations"))}finally{d(!1)}},[s]),f=(0,n.useCallback)(async p=>{d(!0),w(null);try{i(await s.getConversation(p))}catch(S){w(S instanceof Error?S:new Error("Failed to load conversation"))}finally{d(!1)}},[s]),v=(0,n.useCallback)(()=>{i(null)},[]);return(0,n.useEffect)(()=>{r&&m()},[r,m]),{conversations:o,currentConversation:c,isLoading:x,error:g,selectConversation:f,startNewConversation:v,refreshConversations:m}}function _t(e={}){const r=D(),t=e.client||r;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const s=ae({client:t,conversationId:e.conversationId}),o=Me({client:t,autoLoad:e.autoLoad});return{messages:s.messages,isLoading:s.isLoading,error:s.error||o.error,sendMessage:s.sendMessage,stop:s.stop,clearMessages:s.clearMessages,conversationId:s.conversationId,conversations:o.conversations,currentConversation:o.currentConversation,isConversationsLoading:o.isLoading,selectConversation:o.selectConversation,startNewConversation:o.startNewConversation,refreshConversations:o.refreshConversations}}function Rt(e,r){const t=B(),{name:s,description:o,parameters:l,handler:c,maxResultBytes:i,requiresApproval:x,webmcp:d}=typeof e=="string"?{name:e,...r}:e,g=(0,n.useRef)(c);g.current=c,(0,n.useEffect)(()=>{const w=m=>g.current(m);return t.registerFunction(s,w,{description:o,parameters:l,maxResultBytes:i,requiresApproval:x,webmcp:d}),()=>{t.unregisterFunction(s)}},[t,s,o,JSON.stringify(l),i,x,JSON.stringify(d??null)])}function Nt(e,r,t){const s=B(),o=(0,n.useRef)(e);o.current=e;const l=t?.catalogue;(0,n.useEffect)(()=>(s.registerNavigationFunction(c=>o.current(c),r,{catalogue:l==="onDemand"?"onDemand":"inline"}),()=>{s.unregisterNavigationFunction()}),[s,r,l])}function It(e,r){const t=B(),s=r?.functionName??"setPageState",o=r?.requiresApproval,l=r?.data!==void 0,c=r?.data?.description,i=r?.data?.maxResultBytes,x=r?.settleTimeoutMs,d=(0,n.useRef)(e);d.current=e;const g=(0,n.useRef)(r);g.current=r,(0,n.useEffect)(()=>{const w=d.current.map(f=>{const v=()=>d.current.find(p=>p.name===f.name)??f;return{name:f.name,description:f.description,schema:f.schema,clearable:f.clearable,get:f.get?()=>v().get?.():void 0,set:p=>v().set(p)}}),m=l?{description:c??"What the page is currently showing.",maxResultBytes:i,get:()=>g.current?.data?.get(),isLoading:()=>g.current?.data?.isLoading?.()??!1}:void 0;return t.registerPageStateFunction(w,{functionName:s,requiresApproval:o,data:m,settleTimeoutMs:x}),()=>{t.unregisterPageStateFunction(s)}},[t,s,o,l,c,i,x,JSON.stringify(e.map(w=>({name:w.name,description:w.description,schema:w.schema,clearable:w.clearable})))])}function Mt(e){const r=B(),t=(0,n.useRef)(e);t.current=e,(0,n.useEffect)(()=>Ye.attachAutoContinueAfterNavigation(r,()=>t.current),[r])}function Tt(e={}){const r=D(),t=e.client||r;if(!t)throw new Z.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[s,o]=(0,n.useState)(()=>t.getRecentActivity());(0,n.useEffect)(()=>{o(t.getRecentActivity());const i=()=>o(t.getRecentActivity());return t.on("activity:recorded",i),()=>t.off("activity:recorded",i)},[t]);const l=(0,n.useCallback)(i=>t.recordActivity(i),[t]),c=(0,n.useCallback)(()=>{t.clearActivity(),o([])},[t]);return{entries:s,latest:s.length>0?s[s.length-1]:void 0,record:l,clear:c}}function Ft(e,r){const t=B(),s=(0,n.useId)(),o=r??s,l=(0,n.useRef)(e);l.current=e;const c=typeof e=="function";(0,n.useEffect)(()=>{if(typeof l.current=="function"){const i=()=>l.current();return t.addDynamicContext(o,i),()=>{t.removeDynamicContext(o)}}return t.setContext(o,l.current),()=>{t.removeContext(o)}},[t,o,c,c?"":JSON.stringify(e)])}function Te(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var be={missing:[],complete:!1};function Pt(e){const r=B(),t=e.schema!=null,s=JSON.stringify(e.schema??null),o=e.submit,l=o?typeof o=="string"?`client:${o}`:o.via==="backend"?"backend":"handler"in o?"client:handler":`client:${o.url}`:"none",c=JSON.stringify(e.initialValues??null),i=(0,n.useMemo)(()=>t?z.createFormCollector(e):null,[t,e.name,s,l,c,e.autoSubmit]),[x,d]=(0,n.useState)({collector:null,loading:!t,error:null});(0,n.useEffect)(()=>{if(t)return;let N=!1;return d({collector:null,loading:!0,error:null}),z.loadFormCollector(r,e).then(_=>{N||d({collector:_,loading:!1,error:null})}).catch(_=>{N||d({collector:null,loading:!1,error:_ instanceof Error?_:new Error(String(_))})}),()=>{N=!0}},[r,t,e.name,l,c,e.autoSubmit]);const g=t?i:x.collector,w=t?!1:x.loading,m=t?null:x.error;(0,n.useEffect)(()=>{if(g)return g.install(r)},[r,g]);const f=(0,n.useMemo)(()=>L.createStore({values:e.initialValues??{},submitted:!1}),[c]),v=Te(g?.store??f),p=(0,n.useMemo)(()=>g?.getStatus()??be,[v,g]),S=(0,n.useMemo)(()=>({...v,...p}),[v,p]),b=(0,n.useMemo)(()=>({name:e.name,store:f,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:()=>f.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>be}),[e.name,f]);return{...g??b,state:S,loading:w,error:m}}exports.AgoNudge=Et;exports.AgoProvider=Qe;exports.ChatInput=Ae;exports.ChatWidget=jt;exports.DEFAULT_MESSAGE_FEEDBACK_LABELS=re;exports.DEFAULT_SPEECH_TO_TEXT_LABELS=G.DEFAULT_SPEECH_TO_TEXT_LABELS;exports.FEEDBACK_REASONS=L.FEEDBACK_REASONS;exports.Markdown=je;exports.Message=_e;exports.MessageFeedback=Ne;exports.SpeechToTextButton=ke;exports.__exportAll=Ve;exports.createFormCollector=z.createFormCollector;exports.createMockClient=Ze.createMockClient;exports.deriveFormStatus=z.deriveFormStatus;exports.loadFormCollector=z.loadFormCollector;exports.useAgo=ye;exports.useAgoActivity=Ce;exports.useAgoActivityLog=Tt;exports.useAgoAutoContinueAfterNavigation=Mt;exports.useAgoClient=B;exports.useAgoContext=Ft;exports.useAgoFunction=Rt;exports.useAgoNavigation=Nt;exports.useAgoPageState=It;exports.useAgoStore=Te;exports.useChat=_t;exports.useConversation=Me;exports.useFeedback=Re;exports.useFormCollector=Pt;exports.useMessages=ae;exports.useOptionalAgoClient=D;exports.useProactiveNudge=Ie;exports.useSheet=we;
|
|
44
|
+
`})]}),Fe=({message:e,className:o="",showAgentName:t=!1,isLast:s=!1,onFollowUpClick:r,showStreamingDots:i=!0,feedback:u})=>{const l=e.role==="user",f=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,a.jsxs)("div",{className:`ago-message ago-message--${e.role} ${o}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&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}),!l&&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((d,p)=>(0,a.jsx)(Rt,{source:d,index:p},d.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:l?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(d=>(0,a.jsx)(_t,{attachment:d,isUser:l},d.id))}),(e.content||f&&i)&&(0,a.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,a.jsx)(Ie,{content:e.content}):f&&i&&(0,a.jsx)(Me,{})}),!l&&u,s&&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((d,p)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!r,onClick:r?()=>r(d):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:x=>{x.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:x=>{x.currentTarget.style.borderColor="#dee3e8"},children:d},p))})]})};function Te({client:e}={}){const o=W(),t=e||o;if(!t)throw new oe.AgoError("useFeedback requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","missing_client");const[s,r]=(0,n.useState)({}),[i,u]=(0,n.useState)(!1),[l,f]=(0,n.useState)(null),d=(0,n.useRef)(new Map),p=b=>{const g=(d.current.get(b)??0)+1;return d.current.set(b,g),g},x=(b,g)=>d.current.get(b)===g;return{ratings:s,submitFeedback:(0,n.useCallback)(async(b,g,C)=>{const c=p(b);u(!0),f(null);try{await t.submitFeedback(b,g,C),x(b,c)&&r(h=>({...h,[b]:g}))}catch(h){const y=h instanceof Error?h:new Error("Failed to submit feedback");throw f(y),y}finally{u(!1)}},[t]),submitConversationFeedback:(0,n.useCallback)(async(b,g,C)=>{const c=p(b);u(!0),f(null);try{const h=await t.submitConversationFeedback(b,g,C);return x(b,c)&&r(y=>({...y,[h]:g})),h}catch(h){const y=h instanceof Error?h:new Error("Failed to submit feedback");throw f(y),y}finally{u(!1)}},[t]),isSubmitting:i,error:l}}var Nt=D.en_default.feedback,It={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:0,border:"none",borderRadius:"8px",background:"transparent",cursor:"pointer",lineHeight:1},Le=({messageId:e,client:o,askWhy:t=!0,labels:s,onSubmit:r,onError:i,className:u=""})=>{const l=Y(o),f={...D.withOverrides(l.feedback,s),reasons:D.withOverrides(l.feedback.reasons,s?.reasons)},{ratings:d,submitFeedback:p}=Te({client:o}),x=d[e],[b,g]=(0,n.useState)(!1),[C,c]=(0,n.useState)([]),[h,y]=(0,n.useState)(""),[_,E]=(0,n.useState)(!1),[m,k]=(0,n.useState)(!1),A=async(R,w)=>{try{return await p(e,R,w),r?.({messageId:e,rating:R,reasons:w?.reasons??[],comment:w?.comment||void 0}),!0}catch(N){return i?.(N instanceof Error?N:new Error(String(N))),!1}},j=R=>{A(R),g(R==="negative"&&t&&!_)},S=R=>{c(w=>w.includes(R)?w.filter(N=>N!==R):[...w,R])},M=C.length>0||h.trim().length>0,I=()=>{!M||m||(k(!0),A(x??"negative",{reasons:C,comment:h.trim()}).then(R=>{k(!1),R&&(E(!0),g(!1))}))};return(0,a.jsxs)("div",{className:`ago-feedback ${u}`,style:{marginTop:"6px",width:"100%",maxWidth:"85%"},children:[(0,a.jsxs)("div",{className:"ago-feedback__actions",style:{display:"flex",alignItems:"center",gap:"2px"},children:[(0,a.jsx)(we,{direction:"up",label:f.helpful,selected:x==="positive",onClick:()=>j("positive")}),(0,a.jsx)(we,{direction:"down",label:f.notHelpful,selected:x==="negative",onClick:()=>j("negative")})]}),_&&(0,a.jsx)("div",{className:"ago-feedback__thanks",role:"status",style:{marginTop:"6px",fontSize:"13px",color:"#6b6d6f"},children:f.thanks}),b&&!_&&(0,a.jsxs)("div",{className:"ago-feedback__panel",role:"group","aria-label":f.whatWentWrong,style:{marginTop:"8px",padding:"12px",border:"1px solid #dee3e8",borderRadius:"16px",backgroundColor:"#fff"},children:[(0,a.jsx)("div",{style:{fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"8px"},children:f.whatWentWrong}),(0,a.jsx)("div",{className:"ago-feedback__reasons",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"},children:q.FEEDBACK_REASONS.map(R=>{const w=C.includes(R);return(0,a.jsx)("button",{type:"button",className:"ago-feedback__reason","aria-pressed":w,onClick:()=>S(R),style:{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${w?"#1b5fc4":"#dee3e8"}`,backgroundColor:"transparent",color:w?"#1b5fc4":"#30373e",cursor:"pointer"},children:f.reasons[R]},R)})}),(0,a.jsx)("textarea",{className:"ago-feedback__comment",rows:2,value:h,placeholder:f.commentPlaceholder,"aria-label":f.commentPlaceholder,onChange:R=>y(R.target.value),style:{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:"#30373e",border:"1px solid #dee3e8",borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}}),(0,a.jsx)("button",{type:"button",className:"ago-feedback__send",onClick:I,disabled:!M||m,style:{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:M?"#03182f":"#b5bfc8",color:"#fff",opacity:m?.6:1,cursor:M&&!m?"pointer":"default"},children:f.send})]})]})},we=({direction:e,label:o,selected:t,onClick:s})=>(0,a.jsx)("button",{type:"button",className:`ago-feedback__thumb ago-feedback__thumb--${e}`,"aria-label":o,"aria-pressed":t,title:o,onClick:s,style:{...It,color:t?"#1b5fc4":"#6b6d6f"},children:(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:e==="down"?{transform:"rotate(180deg)"}:void 0,children:[(0,a.jsx)("path",{d:"M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"}),(0,a.jsx)("path",{d:"M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"})]})}),Mt=(0,n.forwardRef)(function({client:o,conversationId:t,title:s,welcomeMessage:r,placeholder:i,allowFiles:u=!1,speechToText:l=!1,allowStop:f=!0,height:d=500,logoUrl:p,showAgentName:x=!1,forms:b,feedback:g=!1,onFollowUpClick:C,className:c="",onMessageSent:h,onMessageReceived:y,sheet:_=!1,thinkingLabel:E,functionLabels:m,showReasoning:k=!0},A){const j=Y(o),S=s??j.common.chat,M=r??j.common.welcome,I=i??j.common.placeholder,R=E??j.common.thinking,w=(0,n.useRef)(null),N=(0,n.useRef)(!0),[B,O]=(0,n.useState)(!0),Z=(0,n.useRef)(null),{sheet:T,expand:re,collapse:J,toggle:fe}=Ee(_),[Oe,se]=(0,n.useState)(!1),ae=T.compact&&T.state==="peek",ze=W(),U=o??ze,{messages:P,isLoading:Be,error:pe,sendMessage:qe,stop:He}=de({client:o,conversationId:t});(0,n.useEffect)(()=>{if(!U||!b||b.length===0)return;let v=!1;const L=[];return Promise.all(b.map(F=>F.schema!=null?Promise.resolve($.createFormCollector(F)):$.loadFormCollector(U,F))).then(F=>{if(!v)for(const z of F)L.push(z.install(U))}).catch(()=>{}),()=>{v=!0,L.forEach(F=>F())}},[U,b?JSON.stringify(b.map(v=>[v.name,v.schema??null,v.submit??!1,v.description??null])):""]),(0,n.useEffect)(()=>{const v=w.current;!v||!N.current||(v.scrollTop=v.scrollHeight)},[P]);const $e=()=>{const v=w.current;v&&(N.current=!0,O(!0),v.scrollTop=v.scrollHeight)};(0,n.useEffect)(()=>{const v=P[P.length-1];v&&v.role==="assistant"&&v.status==="DONE"&&y&&y({id:v.id,content:v.content})},[P,y]),(0,n.useEffect)(()=>{se(!!ae)},[P.length]),(0,n.useEffect)(()=>{const v=Z.current;if(!T.compact||!v)return;const L=document.documentElement;if(T.state!=="peek")return;const F=()=>{L.style.setProperty("--ago-sheet-height",`${Math.round(v.getBoundingClientRect().height)}px`)};F();const z=typeof ResizeObserver=="function"?new ResizeObserver(F):null;return z?.observe(v),()=>z?.disconnect()},[T.compact,T.state]),(0,n.useEffect)(()=>{T.compact||document.documentElement.style.removeProperty("--ago-sheet-height")},[T.compact]),(0,n.useEffect)(()=>()=>{document.documentElement.style.removeProperty("--ago-sheet-height")},[]),(0,n.useImperativeHandle)(A,()=>({expand:re,collapse:J,toggle:fe,state:T.state}),[re,J,fe,T.state]),(0,n.useEffect)(()=>{if(!T.isModal)return;const v=Symbol("ago-react-sheet");D.lockBackgroundScroll(v);const L=F=>{if(F.key==="Escape"){J("user");return}if(F.key!=="Tab")return;const z=Z.current;if(!z)return;const ee=Array.from(z.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(Je=>Je.getClientRects().length>0);if(ee.length===0){F.preventDefault();return}const he=ee[0],be=ee[ee.length-1],te=document.activeElement;F.shiftKey&&(te===he||!z.contains(te))?(F.preventDefault(),be.focus()):!F.shiftKey&&(te===be||!z.contains(te))&&(F.preventDefault(),he.focus())};return document.addEventListener("keydown",L),Z.current?.focus({preventScroll:!0}),()=>{document.removeEventListener("keydown",L),D.unlockBackgroundScroll(v)}},[T.isModal,J]);const ge=async(v,L)=>(N.current=!0,O(!0),h?.(v),await qe(v,L)!==null),H=P[P.length-1],Q=Be&&H?.role==="assistant"&&(H.status==="IN_PROGRESS"||H.status==="WAITING_CLIENT"),Ke=(0,n.useCallback)(v=>{const L=v.functionName;if(!(!m||!L))return typeof m=="function"?m(L,v.arguments??{}):m[L]},[m]),{items:Ue}=Ae({client:U??void 0,labelFor:Ke,includeReasoning:k}),me=Ue.filter(v=>H?.id!==void 0&&v.messageId===H.id),V=m===!1?void 0:me[me.length-1]?.label,xe=!!(Q&&V),Ge=C===!1?void 0:C??(v=>ge(v));return(0,a.jsxs)("div",{ref:Z,className:`ago-chat-widget ${c}`,...T.surface.attrs,"data-ago-sheet-state":T.compact?T.state:void 0,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px",...T.surface.style},children:[!T.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:S})]}),ae&&(0,a.jsxs)("button",{type:"button",className:"ago-chat-widget__peek","aria-expanded":!1,"aria-label":j.common.openConversation,onClick:()=>{se(!1),re("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:[S,Oe&&(0,a.jsx)("span",{"aria-label":j.common.newMessage,style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#1b5fc4"}}),(0,a.jsx)("span",{style:{marginLeft:"auto",fontSize:"14px"},"aria-hidden":!0,children:"↑"})]}),Q&&!H?.content?(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[!V&&(0,a.jsx)(Me,{}),(0,a.jsx)("span",{style:{fontSize:"13px",opacity:.7,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:V?_e(V):R})]}):(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:H?.content||M})]}),T.compact&&T.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:S}),(0,a.jsx)("button",{type:"button","aria-label":j.common.collapseConversation,onClick:()=>J("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:ae?"none":"flex",minHeight:0},children:[(0,a.jsxs)("div",{ref:w,className:"ago-chat-widget__messages",onScroll:v=>{const L=v.currentTarget,F=L.scrollHeight-L.scrollTop-L.clientHeight<=48;N.current=F,O(F)},role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,"aria-busy":Q,style:{flex:1,overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:"#fbfbfb"},children:[P.length===0?(0,a.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:M}):P.map((v,L)=>(0,a.jsx)(Fe,{message:v,showAgentName:x,isLast:L===P.length-1,onFollowUpClick:Ge,showStreamingDots:!xe,feedback:g&&v.role==="assistant"&&v.status==="DONE"&&v.content?(0,a.jsx)(Le,{messageId:v.id,client:o,...g===!0?{}:g}):void 0},v.id)),xe&&(0,a.jsx)(ft,{label:V??""}),pe&&(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:pe.message}),(0,a.jsx)("div",{})]}),!B&&(0,a.jsx)("button",{type:"button",className:"ago-chat-widget__jump","aria-label":j.common.jumpToLatest,onClick:$e,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)(Ne,{onSend:ge,onStop:f?()=>{He()}:void 0,disabled:Q,placeholder:I,allowFiles:u,speechToText:l,client:U??void 0,scopeKey:`${t??P[0]?.conversationId??""}:${T.state}`})]})});function Pe(e={}){const o=W(),t=e.client??o;if(!t)throw new oe.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[s,r]=(0,n.useState)(null),i=(0,n.useRef)(s);i.current=s;const u=(0,n.useRef)(e.onExpand);return u.current=e.onExpand,(0,n.useEffect)(()=>{const l=d=>{r(d),t.proactive?.shown(d)},f=({nudge:d})=>{r(p=>p?.id===d.id?null:p)};return t.on("nudge:ready",l),t.on("nudge:accepted",f),t.on("nudge:dismissed",f),()=>{t.off("nudge:ready",l),t.off("nudge:accepted",f),t.off("nudge:dismissed",f)}},[t]),{nudge:s,accept:(0,n.useCallback)(async()=>{const l=i.current;l&&(r(null),await t.proactive?.accept(l),(l.source==="agent"||l.goal)&&u.current?.(l))},[t]),dismiss:(0,n.useCallback)(()=>{const l=i.current;l&&(r(null),t.proactive?.dismiss(l))},[t])}}var Ft=({client:e,onExpand:o,autoHideMs:t,position:s="bottom-right",openChatLabel:r,className:i=""})=>{const u=Y(e),l=r??u.common.openChat,{nudge:f,accept:d,dismiss:p}=Pe({client:e,onExpand:o});if((0,n.useEffect)(()=>{if(!f||!t)return;const b=setTimeout(()=>p(),t);return()=>clearTimeout(b)},[f,t,p]),!f)return null;const x=f.source==="agent"||!!f.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${i}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...s==="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":u.widget.dismiss,onClick:p,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:f.message}),(f.action||x)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[f.action&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{d()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:f.action.label}),x&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{d()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:l})]})]})};function De({client:e,autoLoad:o=!0}={}){const t=W(),s=e||t;if(!s)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,i]=(0,n.useState)([]),[u,l]=(0,n.useState)(null),[f,d]=(0,n.useState)(!1),[p,x]=(0,n.useState)(null),b=(0,n.useCallback)(async()=>{d(!0),x(null);try{const{data:c}=await s.getConversations();i(c)}catch(c){x(c instanceof Error?c:new Error("Failed to load conversations"))}finally{d(!1)}},[s]),g=(0,n.useCallback)(async c=>{d(!0),x(null);try{l(await s.getConversation(c))}catch(h){x(h instanceof Error?h:new Error("Failed to load conversation"))}finally{d(!1)}},[s]),C=(0,n.useCallback)(()=>{l(null)},[]);return(0,n.useEffect)(()=>{o&&b()},[o,b]),{conversations:r,currentConversation:u,isLoading:f,error:p,selectConversation:g,startNewConversation:C,refreshConversations:b}}function Tt(e={}){const o=W(),t=e.client||o;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const s=de({client:t,conversationId:e.conversationId}),r=De({client:t,autoLoad:e.autoLoad});return{messages:s.messages,isLoading:s.isLoading,error:s.error||r.error,sendMessage:s.sendMessage,stop:s.stop,clearMessages:s.clearMessages,conversationId:s.conversationId,conversations:r.conversations,currentConversation:r.currentConversation,isConversationsLoading:r.isLoading,selectConversation:r.selectConversation,startNewConversation:r.startNewConversation,refreshConversations:r.refreshConversations}}function Lt(e,o){const t=K(),{name:s,description:r,parameters:i,handler:u,maxResultBytes:l,requiresApproval:f,webmcp:d}=typeof e=="string"?{name:e,...o}:e,p=(0,n.useRef)(u);p.current=u,(0,n.useEffect)(()=>{const x=b=>p.current(b);return t.registerFunction(s,x,{description:r,parameters:i,maxResultBytes:l,requiresApproval:f,webmcp:d}),()=>{t.unregisterFunction(s)}},[t,s,r,JSON.stringify(i),l,f,JSON.stringify(d??null)])}function Pt(e,o,t){const s=K(),r=(0,n.useRef)(e);r.current=e;const i=t?.catalogue;(0,n.useEffect)(()=>(s.registerNavigationFunction(u=>r.current(u),o,{catalogue:i==="onDemand"?"onDemand":"inline"}),()=>{s.unregisterNavigationFunction()}),[s,o,i])}function Dt(e,o){const t=K(),s=o?.functionName??"setPageState",r=o?.requiresApproval,i=o?.data!==void 0,u=o?.data?.description,l=o?.data?.maxResultBytes,f=o?.settleTimeoutMs,d=(0,n.useRef)(e);d.current=e;const p=(0,n.useRef)(o);p.current=o,(0,n.useEffect)(()=>{const x=d.current.map(g=>{const C=()=>d.current.find(c=>c.name===g.name)??g;return{name:g.name,description:g.description,schema:g.schema,clearable:g.clearable,get:g.get?()=>C().get?.():void 0,set:c=>C().set(c)}}),b=i?{description:u??"What the page is currently showing.",maxResultBytes:l,get:()=>p.current?.data?.get(),isLoading:()=>p.current?.data?.isLoading?.()??!1}:void 0;return t.registerPageStateFunction(x,{functionName:s,requiresApproval:r,data:b,settleTimeoutMs:f}),()=>{t.unregisterPageStateFunction(s)}},[t,s,r,i,u,l,f,JSON.stringify(e.map(x=>({name:x.name,description:x.description,schema:x.schema,clearable:x.clearable})))])}function Wt(e){const o=K(),t=(0,n.useRef)(e);t.current=e,(0,n.useEffect)(()=>nt.attachAutoContinueAfterNavigation(o,()=>t.current),[o])}function Ot(e={}){const o=W(),t=e.client||o;if(!t)throw new oe.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[s,r]=(0,n.useState)(()=>t.getRecentActivity());(0,n.useEffect)(()=>{r(t.getRecentActivity());const l=()=>r(t.getRecentActivity());return t.on("activity:recorded",l),()=>t.off("activity:recorded",l)},[t]);const i=(0,n.useCallback)(l=>t.recordActivity(l),[t]),u=(0,n.useCallback)(()=>{t.clearActivity(),r([])},[t]);return{entries:s,latest:s.length>0?s[s.length-1]:void 0,record:i,clear:u}}function zt(e,o){const t=K(),s=(0,n.useId)(),r=o??s,i=(0,n.useRef)(e);i.current=e;const u=typeof e=="function";(0,n.useEffect)(()=>{if(typeof i.current=="function"){const l=()=>i.current();return t.addDynamicContext(r,l),()=>{t.removeDynamicContext(r)}}return t.setContext(r,i.current),()=>{t.removeContext(r)}},[t,r,u,u?"":JSON.stringify(e)])}function We(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var ke={missing:[],complete:!1};function Bt(e){const o=K(),t=e.schema!=null,s=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),l=(0,n.useMemo)(()=>t?$.createFormCollector(e):null,[t,e.name,s,i,u,e.autoSubmit]),[f,d]=(0,n.useState)({collector:null,loading:!t,error:null});(0,n.useEffect)(()=>{if(t)return;let _=!1;return d({collector:null,loading:!0,error:null}),$.loadFormCollector(o,e).then(E=>{_||d({collector:E,loading:!1,error:null})}).catch(E=>{_||d({collector:null,loading:!1,error:E instanceof Error?E:new Error(String(E))})}),()=>{_=!0}},[o,t,e.name,i,u,e.autoSubmit]);const p=t?l:f.collector,x=t?!1:f.loading,b=t?null:f.error;(0,n.useEffect)(()=>{if(p)return p.install(o)},[o,p]);const g=(0,n.useMemo)(()=>q.createStore({values:e.initialValues??{},submitted:!1}),[u]),C=We(p?.store??g),c=(0,n.useMemo)(()=>p?.getStatus()??ke,[C,p]),h=(0,n.useMemo)(()=>({...C,...c}),[C,c]),y=(0,n.useMemo)(()=>({name:e.name,store:g,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:()=>g.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>ke}),[e.name,g]);return{...p??y,state:h,loading:x,error:b}}exports.AgoNudge=Ft;exports.AgoProvider=rt;exports.ChatInput=Ne;exports.ChatWidget=Mt;exports.DEFAULT_MESSAGE_FEEDBACK_LABELS=Nt;exports.DEFAULT_SPEECH_TO_TEXT_LABELS=D.DEFAULT_SPEECH_TO_TEXT_LABELS;exports.FEEDBACK_REASONS=q.FEEDBACK_REASONS;exports.Markdown=Ie;exports.Message=Fe;exports.MessageFeedback=Le;exports.SpeechToTextButton=Re;exports.__exportAll=et;exports.createFormCollector=$.createFormCollector;exports.createMockClient=ot.createMockClient;exports.deriveFormStatus=$.deriveFormStatus;exports.loadFormCollector=$.loadFormCollector;exports.useAgo=Se;exports.useAgoActivity=Ae;exports.useAgoActivityLog=Ot;exports.useAgoAutoContinueAfterNavigation=Wt;exports.useAgoClient=K;exports.useAgoContext=zt;exports.useAgoFunction=Lt;exports.useAgoNavigation=Pt;exports.useAgoPageState=Dt;exports.useAgoStore=We;exports.useChat=Tt;exports.useConversation=De;exports.useFeedback=Te;exports.useFormCollector=Bt;exports.useMessages=de;exports.useOptionalAgoClient=W;exports.useProactiveNudge=Pe;exports.useSheet=Ee;
|
package/dist/react.d.cts
CHANGED
|
@@ -303,6 +303,8 @@ declare class AgoClient {
|
|
|
303
303
|
* Show the returned text as a draft; call `sendMessage` when the user sends it.
|
|
304
304
|
*/
|
|
305
305
|
transcribeAudio(file: File, options?: TranscribeAudioOptions): Promise<AudioTranscription>;
|
|
306
|
+
/** The requested language, before UI fallback. */
|
|
307
|
+
getLanguage(): string | null;
|
|
306
308
|
/**
|
|
307
309
|
* The tenant's SDK configuration (`GET /api/sdk/v1/config`): per-permission
|
|
308
310
|
* agents, the ticket form the agent's `ago_ticketing` tool opens, and the
|
|
@@ -678,6 +680,9 @@ declare class AgoClient {
|
|
|
678
680
|
* SDK Events
|
|
679
681
|
*/
|
|
680
682
|
declare interface AgoClientEvents {
|
|
683
|
+
"config:changed": {
|
|
684
|
+
language: string | null;
|
|
685
|
+
};
|
|
681
686
|
/**
|
|
682
687
|
* The client-side context changed: a context entry or dynamic provider was
|
|
683
688
|
* added/removed, or a stateful helper (e.g. `createFormCollector`) updated its
|
|
@@ -1348,7 +1353,7 @@ export declare interface ChatWidgetProps {
|
|
|
1348
1353
|
/**
|
|
1349
1354
|
* Let the user report an answer that did not work: thumbs under each finished
|
|
1350
1355
|
* answer, and after a thumbs-down a panel to say what went wrong. Off by
|
|
1351
|
-
* default. `true` uses the
|
|
1356
|
+
* default. `true` uses the selected UI language; pass the `<MessageFeedback>` props
|
|
1352
1357
|
* to translate the strings or observe what was sent.
|
|
1353
1358
|
*
|
|
1354
1359
|
* ```tsx
|
|
@@ -2674,6 +2679,7 @@ declare interface SubmitToolCallResult {
|
|
|
2674
2679
|
|
|
2675
2680
|
/** A custom field of a ticket form. */
|
|
2676
2681
|
declare interface TicketField {
|
|
2682
|
+
prefillAliases?: string[];
|
|
2677
2683
|
id: string;
|
|
2678
2684
|
/** The key the ticketing backend expects; used as the submit key when set. */
|
|
2679
2685
|
externalId?: string;
|
|
@@ -2720,6 +2726,7 @@ declare interface TicketFieldOption {
|
|
|
2720
2726
|
|
|
2721
2727
|
/** The ticket form an agent's `ago_ticketing` tool opens in the conversation. */
|
|
2722
2728
|
declare interface TicketForm {
|
|
2729
|
+
embedDescription?: string;
|
|
2723
2730
|
id: string;
|
|
2724
2731
|
name?: string;
|
|
2725
2732
|
/** `"form"` renders the SDK's own fields; `"embed"` hosts third-party HTML. */
|
package/dist/react.d.ts
CHANGED
|
@@ -303,6 +303,8 @@ declare class AgoClient {
|
|
|
303
303
|
* Show the returned text as a draft; call `sendMessage` when the user sends it.
|
|
304
304
|
*/
|
|
305
305
|
transcribeAudio(file: File, options?: TranscribeAudioOptions): Promise<AudioTranscription>;
|
|
306
|
+
/** The requested language, before UI fallback. */
|
|
307
|
+
getLanguage(): string | null;
|
|
306
308
|
/**
|
|
307
309
|
* The tenant's SDK configuration (`GET /api/sdk/v1/config`): per-permission
|
|
308
310
|
* agents, the ticket form the agent's `ago_ticketing` tool opens, and the
|
|
@@ -678,6 +680,9 @@ declare class AgoClient {
|
|
|
678
680
|
* SDK Events
|
|
679
681
|
*/
|
|
680
682
|
declare interface AgoClientEvents {
|
|
683
|
+
"config:changed": {
|
|
684
|
+
language: string | null;
|
|
685
|
+
};
|
|
681
686
|
/**
|
|
682
687
|
* The client-side context changed: a context entry or dynamic provider was
|
|
683
688
|
* added/removed, or a stateful helper (e.g. `createFormCollector`) updated its
|
|
@@ -1348,7 +1353,7 @@ export declare interface ChatWidgetProps {
|
|
|
1348
1353
|
/**
|
|
1349
1354
|
* Let the user report an answer that did not work: thumbs under each finished
|
|
1350
1355
|
* answer, and after a thumbs-down a panel to say what went wrong. Off by
|
|
1351
|
-
* default. `true` uses the
|
|
1356
|
+
* default. `true` uses the selected UI language; pass the `<MessageFeedback>` props
|
|
1352
1357
|
* to translate the strings or observe what was sent.
|
|
1353
1358
|
*
|
|
1354
1359
|
* ```tsx
|
|
@@ -2674,6 +2679,7 @@ declare interface SubmitToolCallResult {
|
|
|
2674
2679
|
|
|
2675
2680
|
/** A custom field of a ticket form. */
|
|
2676
2681
|
declare interface TicketField {
|
|
2682
|
+
prefillAliases?: string[];
|
|
2677
2683
|
id: string;
|
|
2678
2684
|
/** The key the ticketing backend expects; used as the submit key when set. */
|
|
2679
2685
|
externalId?: string;
|
|
@@ -2720,6 +2726,7 @@ declare interface TicketFieldOption {
|
|
|
2720
2726
|
|
|
2721
2727
|
/** The ticket form an agent's `ago_ticketing` tool opens in the conversation. */
|
|
2722
2728
|
declare interface TicketForm {
|
|
2729
|
+
embedDescription?: string;
|
|
2723
2730
|
id: string;
|
|
2724
2731
|
name?: string;
|
|
2725
2732
|
/** `"form"` renders the SDK's own fields; `"embed"` hosts third-party HTML. */
|