@useago/sdk 1.12.0 → 1.13.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +71 -4
  2. package/README.md +73 -0
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +97 -28
  5. package/dist/angular.d.ts +97 -28
  6. package/dist/angular.js +4 -1
  7. package/dist/{createConversationSession-B1Qn-y0I.js → createConversationSession-BfJg0WyA.js} +1 -1
  8. package/dist/{createConversationSession-B3v_xOU7.cjs → createConversationSession-CiOXKWl0.cjs} +1 -1
  9. package/dist/{createFormCollector-m79zk_NA.js → createFormCollector-DN1xjAv5.js} +1 -1
  10. package/dist/{createFormCollector-FvwDOqnV.cjs → createFormCollector-DnQl77Ko.cjs} +1 -1
  11. package/dist/createMockClient-BPt1gSve.cjs +1 -0
  12. package/dist/{createMockClient-Beao82tu.js → createMockClient-YoYr3pQr.js} +1 -0
  13. package/dist/devtools.cjs +4 -4
  14. package/dist/devtools.d.cts +95 -28
  15. package/dist/devtools.d.ts +95 -28
  16. package/dist/devtools.js +87 -84
  17. package/dist/helpers.d.cts +42 -12
  18. package/dist/helpers.d.ts +42 -12
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.cts +101 -35
  21. package/dist/index.d.ts +101 -35
  22. package/dist/index.js +44 -43
  23. package/dist/react.cjs +4 -4
  24. package/dist/react.d.cts +147 -28
  25. package/dist/react.d.ts +147 -28
  26. package/dist/react.js +814 -727
  27. package/dist/speechToText-BV7qxqPF.js +704 -0
  28. package/dist/speechToText-ZciRyyJE.cjs +1 -0
  29. package/dist/testing.cjs +1 -1
  30. package/dist/testing.d.cts +95 -28
  31. package/dist/testing.d.ts +95 -28
  32. package/dist/testing.js +1 -1
  33. package/dist/{types-Ct1hlKwg.js → types-Q7t1peH-.js} +595 -419
  34. package/dist/types-a7teDBnC.cjs +10 -0
  35. package/dist/vue.cjs +1 -1
  36. package/dist/vue.d.cts +105 -28
  37. package/dist/vue.d.ts +105 -28
  38. package/dist/vue.js +103 -101
  39. package/dist/widget.cjs +6 -6
  40. package/dist/widget.d.cts +127 -28
  41. package/dist/widget.d.ts +127 -28
  42. package/dist/widget.js +1717 -1772
  43. package/llms-full.txt +129 -1
  44. package/package.json +1 -1
  45. package/dist/createMockClient-BEOXI8yW.cjs +0 -1
  46. package/dist/sheetController-BThJRtOu.cjs +0 -1
  47. package/dist/sheetController-aEKXIvjk.js +0 -343
  48. package/dist/types-mcW8vB1U.cjs +0 -10
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { a as w, c as E, d as C, f as S, i as y, l as b, m as v, o as F, p as _, r as M, s as T, t as R, u as I } from "./functions-tzyOZNp6.js";
2
- import { C as D, S as L, _ as O, b as k, c as N, d as G, f as x, g as q, h as P, i as X, l as B, m as H, n as c, o as J, p as W, r as j, s as z, t as K, u as V, v as Y, w as $, x as Q, y as Z } from "./types-Ct1hlKwg.js";
1
+ import { a as w, c as E, d as C, f as S, i as y, l as b, m as F, o as v, p as _, r as M, s as T, t as R, u as I } from "./functions-tzyOZNp6.js";
2
+ import { C as D, S as L, _ as O, b as k, c as N, d as G, f as x, g as q, h as P, i as X, l as B, m as H, n as c, o as J, p as W, r as j, s as z, t as K, u as V, v as Y, w as $, x as Q, y as Z } from "./types-Q7t1peH-.js";
3
3
  import { a as te, i as oe, n as p, r as ae, t as re } from "./errors-BLfjXnLB.js";
4
- import { t as ne } from "./autoContinue-CC8K9mBU.js";
5
- import { t as ue } from "./createConversationSession-B1Qn-y0I.js";
6
- import { n as me, r as fe, t as de } from "./createFormCollector-m79zk_NA.js";
7
- import { t as ce } from "./createMockClient-Beao82tu.js";
4
+ import { t as se } from "./autoContinue-CC8K9mBU.js";
5
+ import { t as ge } from "./createConversationSession-BfJg0WyA.js";
6
+ import { n as me, r as fe, t as le } from "./createFormCollector-DN1xjAv5.js";
7
+ import { t as ce } from "./createMockClient-YoYr3pQr.js";
8
8
  import "./testing.js";
9
9
  function Ae(e) {
10
10
  return e;
@@ -30,71 +30,72 @@ function ye(e, t) {
30
30
  function be(e, t) {
31
31
  return e.on("form:error", t), () => e.off("form:error", t);
32
32
  }
33
- function ve(e, t) {
33
+ function Fe(e, t) {
34
34
  return e.on("function:invoke", t), () => e.off("function:invoke", t);
35
35
  }
36
- async function* Fe(e, t, u) {
37
- const s = [];
36
+ async function* ve(e, t, g) {
37
+ const n = [];
38
38
  let a = null, r = !1;
39
- const g = (n) => {
40
- s.push(n), a?.();
41
- }, m = (n) => g({
39
+ const u = (s) => {
40
+ n.push(s), a?.();
41
+ }, m = (s) => u({
42
42
  type: "start",
43
- data: n
44
- }), f = (n) => g({
43
+ data: s
44
+ }), f = (s) => u({
45
45
  type: "chunk",
46
- data: n
47
- }), o = (n) => {
48
- g({
46
+ data: s
47
+ }), o = (s) => {
48
+ u({
49
49
  type: "complete",
50
- data: n
50
+ data: s
51
51
  }), r = !0, a?.();
52
- }, i = (n) => {
53
- g({
52
+ }, i = (s) => {
53
+ u({
54
54
  type: "error",
55
- data: n
55
+ data: s
56
56
  }), r = !0, a?.();
57
- }, d = (n) => g({
57
+ }, l = (s) => u({
58
58
  type: "toolCall",
59
- data: n
60
- }), l = () => {
59
+ data: s
60
+ }), d = () => {
61
61
  r = !0, a?.();
62
62
  };
63
- e.on("message:start", m), e.on("message:chunk", f), e.on("message:complete", o), e.on("message:error", i), e.on("message:stopped", l), e.on("toolCall:received", d), e.sendMessage(t, u).catch(() => {
63
+ e.on("message:start", m), e.on("message:chunk", f), e.on("message:complete", o), e.on("message:error", i), e.on("message:stopped", d), e.on("toolCall:received", l), e.sendMessage(t, g).catch(() => {
64
64
  r = !0, a?.();
65
65
  });
66
66
  try {
67
- for (; !r || s.length > 0; ) s.length > 0 ? yield s.shift() : (await new Promise((n) => {
68
- a = n;
67
+ for (; !r || n.length > 0; ) n.length > 0 ? yield n.shift() : (await new Promise((s) => {
68
+ a = s;
69
69
  }), a = null);
70
70
  } finally {
71
- e.off("message:start", m), e.off("message:chunk", f), e.off("message:complete", o), e.off("message:error", i), e.off("message:stopped", l), e.off("toolCall:received", d);
71
+ e.off("message:start", m), e.off("message:chunk", f), e.off("message:complete", o), e.off("message:error", i), e.off("message:stopped", d), e.off("toolCall:received", l);
72
72
  }
73
73
  }
74
74
  function A(e) {
75
- let t, u, s, a, r, g, m;
75
+ let t, g, n, a, r, u, m;
76
76
  if (typeof window < "u" && window.AGO) {
77
77
  const o = window.AGO;
78
- t = o.basepath, u = o.widgetId, s = o.agent || o.defaultAgent, a = o.permission, r = o.email, g = o.jwt, m = o.metadata;
78
+ t = o.basepath, g = o.widgetId, n = o.agent || o.defaultAgent, a = o.permission, r = o.email, u = o.jwt, m = o.metadata;
79
79
  }
80
80
  if (typeof document < "u") {
81
81
  const o = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
82
- t = t || o("ago-base-url"), u = u || o("ago-widget-id"), s = s || o("ago-agent") || o("ago-agent-id"), a = a || o("ago-permission"), r = r || o("ago-user-email");
82
+ t = t || o("ago-base-url"), g = g || o("ago-widget-id"), n = n || o("ago-agent") || o("ago-agent-id"), a = a || o("ago-permission"), r = r || o("ago-user-email");
83
83
  }
84
84
  if (typeof document < "u") {
85
85
  const o = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
86
86
  for (const i of o)
87
- i && (t = t || i.getAttribute("data-ago-base-url") || void 0, u = u || i.getAttribute("data-ago-widget-id") || void 0, s = s || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, a = a || i.getAttribute("data-ago-permission") || void 0, r = r || i.getAttribute("data-ago-user-email") || void 0);
87
+ i && (t = t || i.getAttribute("data-ago-base-url") || void 0, g = g || i.getAttribute("data-ago-widget-id") || void 0, n = n || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, a = a || i.getAttribute("data-ago-permission") || void 0, r = r || i.getAttribute("data-ago-user-email") || void 0);
88
88
  }
89
- t = e?.baseUrl || t, u = e?.widgetId || u, s = e?.agent || e?.defaultAgentId || s, a = e?.permission || a, r = e?.userEmail || r, g = e?.userJwt || g, e?.metadata !== void 0 && (m = e.metadata);
89
+ t = e?.baseUrl || t, g = e?.widgetId || g, n = e?.agent || e?.defaultAgentId || n, a = e?.permission || a, r = e?.userEmail || r, u = e?.userJwt || u, e?.metadata !== void 0 && (m = e.metadata);
90
90
  const f = e?.debug;
91
91
  return t ? {
92
92
  baseUrl: t,
93
- widgetId: u,
94
- agent: s,
93
+ widgetId: g,
94
+ agent: n,
95
95
  permission: a,
96
+ language: e?.language,
96
97
  userEmail: r,
97
- userJwt: g,
98
+ userJwt: u,
98
99
  metadata: m,
99
100
  debug: f
100
101
  } : null;
@@ -128,15 +129,15 @@ export {
128
129
  Y as FunctionRegistry,
129
130
  B as SSEHandler,
130
131
  O as SignalCollector,
131
- ne as attachAutoContinueAfterNavigation,
132
+ se as attachAutoContinueAfterNavigation,
132
133
  A as autoDetectConfig,
133
134
  J as canInlineImage,
134
135
  R as copyToClipboard,
135
136
  _e as createAgo,
136
137
  x as createAgoProactive,
137
- ue as createConversationSession,
138
- de as createFormCollector,
139
- Fe as createMessageStream,
138
+ ge as createConversationSession,
139
+ le as createFormCollector,
140
+ ve as createMessageStream,
140
141
  ce as createMockClient,
141
142
  q as createStore,
142
143
  Ae as defineFunction,
@@ -152,13 +153,13 @@ export {
152
153
  H as matchesWhen,
153
154
  be as onFormError,
154
155
  ye as onFormSubmitted,
155
- ve as onFunctionInvoke,
156
+ Fe as onFunctionInvoke,
156
157
  he as onMessage,
157
158
  we as onMessageChunk,
158
159
  Ce as onMessageError,
159
160
  Ee as onMessageStart,
160
161
  Se as onToolCall,
161
- F as openUrl,
162
+ v as openUrl,
162
163
  P as partialDeepMatch,
163
164
  N as safeAttachmentUrl,
164
165
  T as scrollToElement,
@@ -168,7 +169,7 @@ export {
168
169
  C as showNotification,
169
170
  S as showToast,
170
171
  _ as submitForm,
171
- v as trackEvent,
172
+ F as trackEvent,
172
173
  j as validateConfig,
173
174
  Me as withHandler
174
175
  };
package/dist/react.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var He=Object.create,J=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Be=Object.getOwnPropertyNames,$e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty,Ue=(e,n)=>{let t={};for(var s in e)J(t,s,{get:e[s],enumerable:!0});return n||J(t,Symbol.toStringTag,{value:"Module"}),t},Ge=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(var r=Be(n),c=0,l=r.length,i;c<l;c++)i=r[c],!Ke.call(e,i)&&i!==t&&J(e,i,{get:(d=>n[d]).bind(null,i),enumerable:!(s=qe(n,i))||s.enumerable});return e},ne=(e,n,t)=>(t=e!=null?He($e(e)):{},Ge(n||!e||!e.__esModule?J(t,"default",{value:e,enumerable:!0}):t,e));const D=require("./types-mcW8vB1U.cjs"),V=require("./errors-o1IB5fEu.cjs"),Je=require("./autoContinue-CP9pJR-V.cjs"),O=require("./createFormCollector-FvwDOqnV.cjs"),Ve=require("./createMockClient-BEOXI8yW.cjs"),Z=require("./sheetController-BThJRtOu.cjs");let o=require("react");o=ne(o,1);let a=require("react/jsx-runtime"),Q=require("react-markdown");Q=ne(Q,1);let ee=require("remark-gfm");ee=ne(ee,1);function he(e){const[n,t]=(0,o.useState)(!1),s=(0,o.useRef)(null),r=(0,o.useMemo)(()=>{if(s.current&&(s.current.destroy(),s.current=null),!e)return null;const c=new D.AgoClient(e);return s.current=c,c},[e?.baseUrl,e?.widgetId]);return(0,o.useEffect)(()=>(r&&s.current===null&&(s.current=r,r.reviveAfterDestroy()),t(!0),()=>{s.current?.destroy(),s.current=null}),[r]),(0,o.useEffect)(()=>{s.current&&e&&s.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,metadata:e.metadata??null,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.metadata,e?.debug,e?.warnOnEmptyReply]),{client:r,isReady:n}}var re=(0,o.createContext)(null),Ye=({children:e,client:n,tools:t,helpers:s,pageContext:r,...c})=>{const{client:l}=he(n?null:c),i=n||l;return(0,o.useEffect)(()=>{if(!(!t||t.length===0)){for(const d of t)i.register(d);return()=>{for(const d of t)i.unregisterFunction(d.name)}}},[i,t]),(0,o.useEffect)(()=>{if(!s)return;const d=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(u=>u.functions_exports).then(u=>{for(const[p,C]of Object.entries(s)){const A=u[p];if(!A){console.warn(`[AGO] Unknown helper: "${p}"`);continue}const x=C===!0?A:{...A,handler:C};i.register(x),d.push(x.name)}}),()=>{for(const u of d)i.unregisterFunction(u)}},[i,s]),(0,o.useEffect)(()=>{r==="auto"&&i.enableAutoPageContext()},[i,r]),(0,a.jsx)(re.Provider,{value:i,children:e})};function L(){const e=(0,o.useContext)(re);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,o.useContext)(re)}var Xe=new Set(["awaiting-approval"]);function be(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 Ze(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":be(e.type)}function fe(e,n){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(n==="confirmation"||n==="form")?"awaiting-approval":"running"}function pe(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase()).trim()}function Qe(e){switch(e.kind){case"navigation":return`Navigating to ${pe(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||pe(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 ye(e={}){const{includeReasoning:n=!1,labelFor:t}=e,s=W(),r=e.client||s;if(!r)throw new V.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[c,l]=(0,o.useState)([]),i=(0,o.useRef)(new Set),d=(0,o.useRef)(void 0),u=(0,o.useRef)(t);u.current=t;const p=(0,o.useCallback)((f,w)=>{l(b=>{const g=b.findIndex(v=>v.id===f),h={...g>=0?b[g]:{id:f,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...w};return h.label=u.current?.(h)??Qe(h),g>=0?[...b.slice(0,g),h,...b.slice(g+1)]:[...b,h]})},[]);(0,o.useEffect)(()=>{const f=k=>{d.current=k.messageId},w=k=>{const N=be(k.type);N==="reasoning"&&!n||p(k.id,{kind:N,status:fe(k.status,N),messageId:d.current,toolName:k.toolName,toolDisplayName:k.toolDisplayName,message:k.message,data:k.data,formSchema:k.formSchema,requiresApproval:N==="confirmation"||N==="form"})},b=k=>{k.invocationId&&p(k.invocationId,{kind:k.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:d.current,functionName:k.functionName,arguments:k.arguments})},g=k=>{k.invocationId&&p(k.invocationId,{kind:k.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:d.current,functionName:k.functionName,arguments:k.arguments,requiresApproval:!0})},h=k=>{if(!k.invocationId)return;const N=k.result,S=typeof k.result=="object"&&N!==null&&N.approved===!1&&N.reason==="user_rejected";p(k.invocationId,{status:k.error?"error":S?"rejected":"done",requiresApproval:!1})},v=k=>{for(const N of k.messages??[])if(N.role==="assistant")for(const S of N.toolCalls??[]){const _=Ze(S);_==="reasoning"&&!n||/waiting/i.test(S.status??"")||p(S.id,{kind:_,status:fe(S.status,_),messageId:N.id,toolName:S.toolName,toolDisplayName:S.toolDisplayName,functionName:S.functionName,arguments:S.arguments,message:S.message,data:S.data,formSchema:S.formSchema,requiresApproval:_==="confirmation"||_==="form"})}},m=k=>{l(N=>N.map(S=>S.status==="running"||S.status==="awaiting-approval"?{...S,status:k}:S))},j=()=>m("done"),E=()=>m("error");return r.on("message:start",f),r.on("toolCall:received",w),r.on("function:invoke",b),r.on("function:awaiting-approval",g),r.on("function:result",h),r.on("conversation:loaded",v),r.on("message:complete",j),r.on("message:error",E),()=>{r.off("message:start",f),r.off("toolCall:received",w),r.off("function:invoke",b),r.off("function:awaiting-approval",g),r.off("function:result",h),r.off("conversation:loaded",v),r.off("message:complete",j),r.off("message:error",E)}},[r,n,p]);const C=(0,o.useCallback)(async f=>{const w=c.find(b=>b.id===f);!w||w.status!=="awaiting-approval"||i.current.has(f)||w.kind!=="form"&&(i.current.add(f),p(f,{status:"running",requiresApproval:!1}),w.functionName?await r.approveFunction(f):await r.confirmToolCall(f))},[r,c,p]),A=(0,o.useCallback)(async f=>{const w=c.find(b=>b.id===f);!w||w.status!=="awaiting-approval"||i.current.has(f)||(i.current.add(f),p(f,{status:"rejected",requiresApproval:!1}),w.functionName?await r.rejectFunction(f):await r.rejectToolCall(f))},[r,c,p]),x=(0,o.useCallback)(async(f,w)=>{p(f,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(f,w),p(f,{status:"done"})},[r,p]),R=(0,o.useCallback)(()=>{i.current.clear(),l([])},[]);return{items:c,latest:c.length>0?c[c.length-1]:void 0,isAwaitingApproval:c.some(f=>Xe.has(f.status)),approve:C,reject:A,submitForm:x,clear:R}}function oe({client:e,conversationId:n}={}){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,c]=(0,o.useState)([]),[l,i]=(0,o.useState)(n),[d,u]=(0,o.useState)(!1),[p,C]=(0,o.useState)(null);(0,o.useEffect)(()=>{n&&n!==l&&(i(n),A(n))},[n]);const A=async x=>{try{c((await s.getMessages(x)).filter(R=>!R.hidden))}catch(R){C(R instanceof Error?R:new Error("Failed to load messages"))}};return(0,o.useEffect)(()=>{const x=v=>v==="IN_PROGRESS"||v==="WAITING_CLIENT",R=v=>{l||i(v.conversationId),u(!0),c(m=>{const j=m.findIndex(E=>E.id===v.messageId);return j>=0?m.map((E,k)=>k===j?{...E,status:"IN_PROGRESS"}:E):m.some(E=>E.role==="assistant"&&x(E.status))?m:[...m,{id:v.messageId,conversationId:v.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},f=v=>{c(m=>{const j=m.findIndex(E=>E.id===v.messageId);return j<0?m:m.map((E,k)=>k===j?{...E,content:E.content+v.content}:E)})},w=v=>{c(m=>{let j=-1;for(let E=m.length-1;E>=0;E--)if(m[E].role==="assistant"&&x(m[E].status)){j=E;break}return j<0?m:[...m.slice(0,j),{...m[j],...v},...m.slice(j+1)]})},b=v=>{c(m=>{const j=m.findIndex(E=>E.id===v.id);return j>=0?[...m.slice(0,j),v,...m.slice(j+1)]:[...m,v]}),u(!1)},g=v=>{C(new Error(v.error)),u(!1)},h=()=>{c(v=>{let m=-1;for(let j=v.length-1;j>=0;j--)if(v[j].role==="assistant"&&x(v[j].status)){m=j;break}return m<0?v:v[m].content?v.map((j,E)=>E===m?{...j,status:"CANCELED"}:j):v.filter((j,E)=>E!==m)}),u(!1)};return s.on("message:start",R),s.on("message:chunk",f),s.on("message:answer-complete",w),s.on("message:complete",b),s.on("message:error",g),s.on("message:stopped",h),()=>{s.off("message:start",R),s.off("message:chunk",f),s.off("message:answer-complete",w),s.off("message:complete",b),s.off("message:error",g),s.off("message:stopped",h)}},[s,l]),{messages:r,isLoading:d,error:p,sendMessage:(0,o.useCallback)(async(x,R)=>{u(!0),C(null);const f={id:`temp-${Date.now()}`,conversationId:l||"",content:x,role:"user",status:"DONE",attachments:R&&R.length>0?D.attachmentsFromFiles(R):void 0,createdAt:new Date},w={id:`temp-assistant-${Date.now()}`,conversationId:l||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};c(b=>[...b,f,w]);try{const b=await s.sendMessage(x,{conversationId:l,files:R});return b.conversationId&&!l&&i(b.conversationId),c(g=>{const h=g.filter(m=>!m.id.startsWith("temp-")),v={...f,id:f.id.replace("temp-","user-"),conversationId:b.conversationId};return h.some(m=>m.id===b.id)?[...h,v].sort((m,j)=>new Date(m.createdAt).getTime()-new Date(j.createdAt).getTime()):[...h,v,b]}),b}catch(b){return C(b instanceof Error?b:new Error("Failed to send message")),u(!1),c(g=>g.filter(h=>!h.id.startsWith("temp-"))),null}},[s,l]),stop:(0,o.useCallback)(async()=>{await s.stop()},[s]),clearMessages:(0,o.useCallback)(()=>{c([]),i(void 0),C(null)},[]),conversationId:l}}var ge={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},et={tabindex:"tabIndex"};function tt(e){const n={};for(const[t,s]of Object.entries(e))n[et[t]??t]=s;return n}function ve(e){const n=e!==!1,t=n?e??{}:void 0,s=(0,o.useRef)(t?.onStateChange);s.current=t?.onStateChange;const r=(0,o.useMemo)(()=>{if(n)return Z.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(l,i)=>s.current?.(l,i)})},[n,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),c=(0,o.useSyncExternalStore)((0,o.useCallback)(l=>r?.subscribe(l)??(()=>{}),[r]),(0,o.useCallback)(()=>r?.getSnapshot()??ge,[r]),(0,o.useCallback)(()=>r?.getServerSnapshot()??ge,[r]));return{sheet:(0,o.useMemo)(()=>({...c,surface:{...c.surface,attrs:tt(c.surface.attrs)}}),[c]),expand:(0,o.useCallback)(l=>r?.expand(l),[r]),collapse:(0,o.useCallback)(l=>r?.collapse(l),[r]),toggle:(0,o.useCallback)(l=>r?.toggle(l),[r])}}var nt=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function Ce(e){const n=e.split(nt);return n.length===1?e:n.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 rt=`
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-a7teDBnC.cjs"),Z=require("./errors-o1IB5fEu.cjs"),Ye=require("./autoContinue-CP9pJR-V.cjs"),z=require("./createFormCollector-DnQl77Ko.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,b]of Object.entries(s)){const m=d[g];if(!m){console.warn(`[AGO] Unknown helper: "${g}"`);continue}const f=b===!0?m:{...m,handler:b};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(y=>{const N=y.findIndex(v=>v.id===p),_={...N>=0?y[N]:{id:p,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...S};return _.label=d.current?.(_)??nt(_),N>=0?[...y.slice(0,N),_,...y.slice(N+1)]:[...y,_]})},[]);(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"})},y=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})},v=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",y),o.on("function:awaiting-approval",N),o.on("function:result",_),o.on("conversation:loaded",v),o.on("message:complete",j),o.on("message:error",E),()=>{o.off("message:start",p),o.off("toolCall:received",S),o.off("function:invoke",y),o.off("function:awaiting-approval",N),o.off("function:result",_),o.off("conversation:loaded",v),o.off("message:complete",j),o.off("message:error",E)}},[o,r,g]);const b=(0,n.useCallback)(async p=>{const S=l.find(y=>y.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(y=>y.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]),C=(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:b,reject:m,submitForm:f,clear:C}}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,b]=(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(C=>!C.hidden))}catch(C){b(C instanceof Error?C:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const f=v=>v==="IN_PROGRESS"||v==="WAITING_CLIENT",C=v=>{c||i(v.conversationId),d(!0),l(k=>{const j=k.findIndex(E=>E.id===v.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:v.messageId,conversationId:v.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},p=v=>{l(k=>{const j=k.findIndex(E=>E.id===v.messageId);return j<0?k:k.map((E,h)=>h===j?{...E,content:E.content+v.content}:E)})},S=v=>{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],...v},...k.slice(j+1)]})},y=v=>{l(k=>{const j=k.findIndex(E=>E.id===v.id);return j>=0?[...k.slice(0,j),v,...k.slice(j+1)]:[...k,v]}),d(!1)},N=v=>{b(new Error(v.error)),d(!1)},_=()=>{l(v=>{let k=-1;for(let j=v.length-1;j>=0;j--)if(v[j].role==="assistant"&&f(v[j].status)){k=j;break}return k<0?v:v[k].content?v.map((j,E)=>E===k?{...j,status:"CANCELED"}:j):v.filter((j,E)=>E!==k)}),d(!1)};return s.on("message:start",C),s.on("message:chunk",p),s.on("message:answer-complete",S),s.on("message:complete",y),s.on("message:error",N),s.on("message:stopped",_),()=>{s.off("message:start",C),s.off("message:chunk",p),s.off("message:answer-complete",S),s.off("message:complete",y),s.off("message:error",N),s.off("message:stopped",_)}},[s,c]),{messages:o,isLoading:x,error:g,sendMessage:(0,n.useCallback)(async(f,C)=>{d(!0),b(null);const p={id:`temp-${Date.now()}`,conversationId:c||"",content:f,role:"user",status:"DONE",attachments:C&&C.length>0?L.attachmentsFromFiles(C):void 0,createdAt:new Date},S={id:`temp-assistant-${Date.now()}`,conversationId:c||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(y=>[...y,p,S]);try{const y=await s.sendMessage(f,{conversationId:c,files:C});return y.conversationId&&!c&&i(y.conversationId),l(N=>{const _=N.filter(k=>!k.id.startsWith("temp-")),v={...p,id:p.id.replace("temp-","user-"),conversationId:y.conversationId};return _.some(k=>k.id===y.id)?[..._,v].sort((k,j)=>new Date(k.createdAt).getTime()-new Date(j.createdAt).getTime()):[..._,v,y]}),y}catch(y){return b(y instanceof Error?y: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),b(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=`
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 He=Object
35
35
  color: var(--ago-activity-color, #5b5d5f);
36
36
  }
37
37
  }
38
- `,ot=({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:Ce(e)},e),(0,a.jsx)("style",{children:rt})]}),we=({onSend:e,onStop:n,disabled:t=!1,placeholder:s="Type a message...",allowFiles:r=!1,className:c=""})=>{const[l,i]=(0,o.useState)(""),[d,u]=(0,o.useState)([]),p=(0,o.useRef)(null),C=(0,o.useRef)(null),A=(0,o.useCallback)(()=>{const g=C.current;if(!g)return;const h=110;g.style.height="auto",g.style.height=`${Math.min(g.scrollHeight+2,h)}px`,g.style.overflowY=g.scrollHeight+2>h?"auto":"hidden"},[]),x=(0,o.useCallback)(async g=>{if(g.preventDefault(),!l.trim()&&d.length===0)return;const h=l.trim(),v=d.length>0?d:void 0;i(""),u([]),requestAnimationFrame(A),await e(h,v)===!1&&(i(m=>m.trim()?m:h),v&&u(m=>[...v,...m]),requestAnimationFrame(A))},[l,d,e,A]),R=(0,o.useCallback)(g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),x(g))},[x]),f=(0,o.useCallback)(g=>{const h=Array.from(g.target.files||[]);u(v=>[...v,...h])},[]),w=(0,o.useCallback)(g=>{u(h=>h.filter((v,m)=>m!==g))},[]),b=l.trim()||d.length>0;return(0,a.jsxs)("form",{onSubmit:g=>{x(g)},className:`ago-chat-input ${c}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[d.length>0&&(0,a.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:d.map((g,h)=>(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:g.name}),(0,a.jsx)("button",{type:"button",onClick:()=>w(h),"aria-label":`Remove ${g.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:"×"})]},h))}),(0,a.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>p.current?.click(),disabled:t,"aria-label":"Attach file",style:{flexShrink:0,minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,a.jsx)("input",{ref:p,type:"file",multiple:!0,onChange:f,style:{display:"none"}})]}),(0,a.jsx)("textarea",{ref:C,className:"ago-chat-input__field",value:l,onChange:g=>{i(g.target.value),A()},onKeyDown:R,placeholder:s,"aria-label":s,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:g=>{g.currentTarget.style.borderColor="#1b5fc4"},onBlur:g=>{g.currentTarget.style.borderColor="#dee3e8"}}),t&&n?(0,a.jsx)("button",{type:"button",onClick:n,"aria-label":"Stop generating",style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:"#03182f",color:"#fff",cursor:"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Stop"}):(0,a.jsx)("button",{type:"submit",disabled:t||!b,style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!b?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!b?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},st=({href:e,children:n,...t})=>(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:n}),at=({children:e,...n})=>(0,a.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...n,children:e}),H=(e,n)=>{const t=({children:s,...r})=>o.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:n,fontWeight:600,lineHeight:"1.3"},...r},s);return t.displayName=`MarkdownHeading${e}`,t},it=({children:e,...n})=>(0,a.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...n,children:e}),lt=({children:e,...n})=>(0,a.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...n,children:e}),ct=({children:e,...n})=>(0,a.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...n,children:e}),ut=({className:e,children:n,...t})=>e!==void 0||String(n).includes(`
39
- `)?(0,a.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}):(0,a.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}),dt=({children:e,...n})=>(0,a.jsx)("pre",{style:{margin:"0 0 8px 0"},...n,children:e}),ft=({children:e,...n})=>(0,a.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...n,children:e}),pt=({children:e,...n})=>(0,a.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,a.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...n,children:e})}),gt=({children:e,...n})=>(0,a.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...n,children:e}),xt=({children:e,...n})=>(0,a.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...n,children:e}),mt=({alt:e,...n})=>(0,a.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...n}),ht=e=>(0,a.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),bt={a:st,p:at,h1:H(1,"20px"),h2:H(2,"18px"),h3:H(3,"16px"),h4:H(4,"15px"),h5:H(5,"14px"),h6:H(6,"13px"),ul:it,ol:lt,li:ct,code:ut,pre:dt,blockquote:ft,table:pt,th:gt,td:xt,img:mt,hr:ht},yt=[ee.default],ke=({content:e})=>(0,a.jsx)(Q.default,{remarkPlugins:yt,components:bt,children:e}),vt=({attachment:e,isUser:n})=>{const t=D.safeAttachmentUrl(e.url);if(D.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=D.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})]})]}),c={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:n?"rgba(255,255,255,0.12)":"#fff",color:n?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return t?(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:c,children:r}):(0,a.jsx)("div",{style:c,children:r})},Ct=({source:e,index:n})=>{const t=(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,a.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:n+1}),(0,a.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),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})},Se=()=>(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:`
38
+ `,it=({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:Se(e)},e),(0,a.jsx)("style",{children:at})]}),U=typeof window>"u"?n.useEffect:n.useLayoutEffect;function ke(e){const r=D(),t=e.client??r,s=(0,n.useRef)(null),o=(0,n.useRef)(),l=(0,n.useRef)(e),[c,i]=(0,n.useState)(!1),[x,d]=(0,n.useState)(""),[g,b]=(0,n.useState)(!1);return U(()=>{l.current=e}),U(()=>{if(b(!1),i(!1),l.current.onBusyChange?.(!1),!t||!s.current)return;let m=!0;const f=G.createSpeechToText({transcribe:(C,p)=>t.transcribeAudio(C,p),onText:C=>{m&&l.current.onTranscript(C)},onBusy:C=>{m&&(i(C),C&&d(""),l.current.onBusyChange?.(C))},onError:C=>{m&&d(C)},labels:l.current.labels});return s.current.append(f.el),o.current=f,f.setDisabled(!!l.current.disabled),t.getConfig().then(({permissions:C})=>{if(!m)return;const p=C.some(S=>S.speechToTextEnabled)&&typeof MediaRecorder<"u"&&!!navigator.mediaDevices?.getUserMedia;f.setEnabled(p),b(p)}).catch(()=>{}),()=>{m=!1,f.destroy(),l.current.onBusyChange?.(!1),f.el.remove(),o.current=void 0}},[t]),U(()=>{o.current?.setDisabled(!!e.disabled)},[e.disabled]),U(()=>{o.current?.cancel()},[e.scopeKey,t]),U(()=>{o.current?.setLabels(e.labels)},[e.labels]),(0,a.jsxs)("div",{className:`ago-speech-to-text ${e.className??""}`,style:{display:g?"flex":"none",flexDirection:"column",minWidth:0,flex:c?1:void 0},children:[(0,a.jsx)("div",{ref:s}),x&&(0,a.jsx)("span",{role:"alert",style:{color:"var(--ago-muted-text-color, #6b6d6f)",fontSize:"13px"},children:x})]})}var Ae=({onSend:e,onStop:r,disabled:t=!1,placeholder:s="Type a message...",allowFiles:o=!1,speechToText:l=!1,client:c,scopeKey:i,className:x=""})=>{const[d,g]=(0,n.useState)(""),[b,m]=(0,n.useState)([]),[f,C]=(0,n.useState)(!1),p=(0,n.useRef)(null),S=(0,n.useRef)(null),y=!!l;(0,n.useEffect)(()=>{y||C(!1)},[y]);const N=(0,n.useCallback)(()=>{const u=S.current;if(!u)return;const A=110;u.style.height="auto",u.style.height=`${Math.min(u.scrollHeight+2,A)}px`,u.style.overflowY=u.scrollHeight+2>A?"auto":"hidden"},[]),_=(0,n.useRef)(!1);(0,n.useEffect)(()=>{_.current&&!f&&!t&&(N(),S.current?.focus()),_.current=f},[f,t,N]);const v=(0,n.useCallback)(async u=>{if(u.preventDefault(),t||f||!d.trim()&&b.length===0)return;const A=d.trim(),R=b.length>0?b:void 0;g(""),m([]),requestAnimationFrame(N),await e(A,R)===!1&&(g(P=>P.trim()?P:A),R&&m(P=>[...R,...P]),requestAnimationFrame(N))},[d,b,e,N,t,f]),k=(0,n.useCallback)(u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),v(u))},[v]),j=(0,n.useCallback)(u=>{const A=Array.from(u.target.files||[]);m(R=>[...R,...A])},[]),E=(0,n.useCallback)(u=>{m(A=>A.filter((R,P)=>P!==u))},[]),h=d.trim()||b.length>0,I=u=>{g(A=>`${A}${A&&!/\s$/.test(A)?" ":""}${u}`)};return(0,a.jsxs)("form",{onSubmit:u=>{v(u)},className:`ago-chat-input ${x}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[b.length>0&&!f&&(0,a.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:b.map((u,A)=>(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:u.name}),(0,a.jsx)("button",{type:"button",onClick:()=>E(A),"aria-label":`Remove ${u.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:"×"})]},A))}),(0,a.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[o&&!f&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>p.current?.click(),disabled:t,"aria-label":"Attach file",style:{flexShrink:0,minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,a.jsx)("input",{ref:p,type:"file",multiple:!0,onChange:j,style:{display:"none"}})]}),(0,a.jsx)("textarea",{ref:S,className:"ago-chat-input__field",value:d,onChange:u=>{g(u.target.value),N()},onKeyDown:k,placeholder:s,"aria-label":s,disabled:t||f,rows:1,style:{display:f?"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:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onBlur:u=>{u.currentTarget.style.borderColor="#dee3e8"}}),l&&(0,a.jsx)(ke,{client:c,disabled:t,scopeKey:i,labels:typeof l=="object"?l.labels:void 0,onTranscript:I,onBusyChange:C}),!f&&(t&&r?(0,a.jsx)("button",{type:"button",onClick:r,"aria-label":"Stop generating",style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:"#03182f",color:"#fff",cursor:"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Stop"}):(0,a.jsx)("button",{type:"submit",disabled:t||!h,style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!h?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!h?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"}))]})]})},lt=({href:e,children:r,...t})=>(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:r}),ct=({children:e,...r})=>(0,a.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...r,children:e}),q=(e,r)=>{const t=({children:s,...o})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:r,fontWeight:600,lineHeight:"1.3"},...o},s);return t.displayName=`MarkdownHeading${e}`,t},ut=({children:e,...r})=>(0,a.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...r,children:e}),dt=({children:e,...r})=>(0,a.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...r,children:e}),ft=({children:e,...r})=>(0,a.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...r,children:e}),pt=({className:e,children:r,...t})=>e!==void 0||String(r).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:r}):(0,a.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...t,children:r}),gt=({children:e,...r})=>(0,a.jsx)("pre",{style:{margin:"0 0 8px 0"},...r,children:e}),xt=({children:e,...r})=>(0,a.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...r,children:e}),mt=({children:e,...r})=>(0,a.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,a.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...r,children:e})}),ht=({children:e,...r})=>(0,a.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...r,children:e}),bt=({children:e,...r})=>(0,a.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...r,children:e}),yt=({alt:e,...r})=>(0,a.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...r}),vt=e=>(0,a.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),Ct={a:lt,p:ct,h1:q(1,"20px"),h2:q(2,"18px"),h3:q(3,"16px"),h4:q(4,"15px"),h5:q(5,"14px"),h6:q(6,"13px"),ul:ut,ol:dt,li:ft,code:pt,pre:gt,blockquote:xt,table:mt,th:ht,td:bt,img:yt,hr:vt},wt=[ne.default],je=({content:e})=>(0,a.jsx)(te.default,{remarkPlugins:wt,components:Ct,children:e}),St=({attachment:e,isUser:r})=>{const t=L.safeAttachmentUrl(e.url);if(L.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=L.formatFileSize(e.fileSize),o=(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})]})]}),l={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:r?"rgba(255,255,255,0.12)":"#fff",color:r?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return t?(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:l,children:o}):(0,a.jsx)("div",{style:l,children:o})},kt=({source:e,index:r})=>{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:r+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:o=>{o.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:o=>{o.currentTarget.style.borderColor="#dee3e8"},children:t}):(0,a.jsx)("div",{style:s,children:t})},Ee=()=>(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
- `})]}),Ae=({message:e,className:n="",showAgentName:t=!1,isLast:s=!1,onFollowUpClick:r,showStreamingDots:c=!0,feedback:l})=>{const i=e.role==="user",d=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,a.jsxs)("div",{className:`ago-message ago-message--${e.role} ${n}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,a.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!i&&e.sources&&e.sources.length>0&&(0,a.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((u,p)=>(0,a.jsx)(Ct,{source:u,index:p},u.id))}),e.attachments&&e.attachments.length>0&&(0,a.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:i?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(u=>(0,a.jsx)(vt,{attachment:u,isUser:i},u.id))}),(e.content||d&&c)&&(0,a.jsx)("div",{className:"ago-message__content",style:{maxWidth:i?"75%":"100%",padding:i?"10px 14px":"2px 8px",borderRadius:i?"16px":"0",backgroundColor:i?"#03182f":"transparent",color:i?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,a.jsx)(ke,{content:e.content}):d&&c&&(0,a.jsx)(Se,{})}),!i&&l,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((u,p)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!r,onClick:r?()=>r(u):void 0,style:{minHeight:"44px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:r?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:C=>{C.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:C=>{C.currentTarget.style.borderColor="#dee3e8"},children:u},p))})]})};function je({client:e}={}){const n=W(),t=e||n;if(!t)throw new V.AgoError("useFeedback requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","missing_client");const[s,r]=(0,o.useState)({}),[c,l]=(0,o.useState)(!1),[i,d]=(0,o.useState)(null),u=(0,o.useRef)(new Map),p=A=>{const x=(u.current.get(A)??0)+1;return u.current.set(A,x),x},C=(A,x)=>u.current.get(A)===x;return{ratings:s,submitFeedback:(0,o.useCallback)(async(A,x,R)=>{const f=p(A);l(!0),d(null);try{await t.submitFeedback(A,x,R),C(A,f)&&r(w=>({...w,[A]:x}))}catch(w){const b=w instanceof Error?w:new Error("Failed to submit feedback");throw d(b),b}finally{l(!1)}},[t]),submitConversationFeedback:(0,o.useCallback)(async(A,x,R)=>{const f=p(A);l(!0),d(null);try{const w=await t.submitConversationFeedback(A,x,R);return C(A,f)&&r(b=>({...b,[w]:x})),w}catch(w){const b=w instanceof Error?w:new Error("Failed to submit feedback");throw d(b),b}finally{l(!1)}},[t]),isSubmitting:c,error:i}}var te={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."},wt={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},_e=({messageId:e,client:n,askWhy:t=!0,labels:s,onSubmit:r,onError:c,className:l=""})=>{const i={...te,...s,reasons:{...te.reasons,...s?.reasons}},{ratings:d,submitFeedback:u}=je({client:n}),p=d[e],[C,A]=(0,o.useState)(!1),[x,R]=(0,o.useState)([]),[f,w]=(0,o.useState)(""),[b,g]=(0,o.useState)(!1),[h,v]=(0,o.useState)(!1),m=async(S,_)=>{try{return await u(e,S,_),r?.({messageId:e,rating:S,reasons:_?.reasons??[],comment:_?.comment||void 0}),!0}catch(T){return c?.(T instanceof Error?T:new Error(String(T))),!1}},j=S=>{m(S),A(S==="negative"&&t&&!b)},E=S=>{R(_=>_.includes(S)?_.filter(T=>T!==S):[..._,S])},k=x.length>0||f.trim().length>0,N=()=>{!k||h||(v(!0),m(p??"negative",{reasons:x,comment:f.trim()}).then(S=>{v(!1),S&&(g(!0),A(!1))}))};return(0,a.jsxs)("div",{className:`ago-feedback ${l}`,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)(xe,{direction:"up",label:i.helpful,selected:p==="positive",onClick:()=>j("positive")}),(0,a.jsx)(xe,{direction:"down",label:i.notHelpful,selected:p==="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}),C&&!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:D.FEEDBACK_REASONS.map(S=>{const _=x.includes(S);return(0,a.jsx)("button",{type:"button",className:"ago-feedback__reason","aria-pressed":_,onClick:()=>E(S),style:{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${_?"#1b5fc4":"#dee3e8"}`,backgroundColor:"transparent",color:_?"#1b5fc4":"#30373e",cursor:"pointer"},children:i.reasons[S]},S)})}),(0,a.jsx)("textarea",{className:"ago-feedback__comment",rows:2,value:f,placeholder:i.commentPlaceholder,"aria-label":i.commentPlaceholder,onChange:S=>w(S.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:N,disabled:!k||h,style:{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:k?"#03182f":"#b5bfc8",color:"#fff",opacity:h?.6:1,cursor:k&&!h?"pointer":"default"},children:i.send})]})]})},xe=({direction:e,label:n,selected:t,onClick:s})=>(0,a.jsx)("button",{type:"button",className:`ago-feedback__thumb ago-feedback__thumb--${e}`,"aria-label":n,"aria-pressed":t,title:n,onClick:s,style:{...wt,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"})]})}),kt=(0,o.forwardRef)(function({client:n,conversationId:t,title:s="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:c="Type a message...",allowFiles:l=!1,allowStop:i=!0,height:d=500,logoUrl:u,showAgentName:p=!1,forms:C,feedback:A=!1,onFollowUpClick:x,className:R="",onMessageSent:f,onMessageReceived:w,sheet:b=!1,thinkingLabel:g="Thinking...",functionLabels:h,showReasoning:v=!0},m){const j=(0,o.useRef)(null),E=(0,o.useRef)(!0),[k,N]=(0,o.useState)(!0),S=(0,o.useRef)(null),{sheet:_,expand:T,collapse:q,toggle:se}=ve(b),[Ie,Y]=(0,o.useState)(!1),X=_.compact&&_.state==="peek",Me=W(),B=n??Me,{messages:F,isLoading:Fe,error:ae,sendMessage:Te,stop:Pe}=oe({client:n,conversationId:t});(0,o.useEffect)(()=>{if(!B||!C||C.length===0)return;let y=!1;const M=[];return Promise.all(C.map(I=>I.schema!=null?Promise.resolve(O.createFormCollector(I)):O.loadFormCollector(B,I))).then(I=>{if(!y)for(const P of I)M.push(P.install(B))}).catch(()=>{}),()=>{y=!0,M.forEach(I=>I())}},[B,C?JSON.stringify(C.map(y=>[y.name,y.schema??null,y.submit??!1,y.description??null])):""]),(0,o.useEffect)(()=>{const y=j.current;!y||!E.current||(y.scrollTop=y.scrollHeight)},[F]);const We=()=>{const y=j.current;y&&(E.current=!0,N(!0),y.scrollTop=y.scrollHeight)};(0,o.useEffect)(()=>{const y=F[F.length-1];y&&y.role==="assistant"&&y.status==="DONE"&&w&&w({id:y.id,content:y.content})},[F,w]),(0,o.useEffect)(()=>{Y(!!X)},[F.length]),(0,o.useEffect)(()=>{const y=S.current;if(!_.compact||!y)return;const M=document.documentElement;if(_.state!=="peek")return;const I=()=>{M.style.setProperty("--ago-sheet-height",`${Math.round(y.getBoundingClientRect().height)}px`)};I();const P=typeof ResizeObserver=="function"?new ResizeObserver(I):null;return P?.observe(y),()=>P?.disconnect()},[_.compact,_.state]),(0,o.useEffect)(()=>{_.compact||document.documentElement.style.removeProperty("--ago-sheet-height")},[_.compact]),(0,o.useEffect)(()=>()=>{document.documentElement.style.removeProperty("--ago-sheet-height")},[]),(0,o.useImperativeHandle)(m,()=>({expand:T,collapse:q,toggle:se,state:_.state}),[T,q,se,_.state]),(0,o.useEffect)(()=>{if(!_.isModal)return;const y=Symbol("ago-react-sheet");Z.lockBackgroundScroll(y);const M=I=>{if(I.key==="Escape"){q("user");return}if(I.key!=="Tab")return;const P=S.current;if(!P)return;const U=Array.from(P.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(Le=>Le.getClientRects().length>0);if(U.length===0){I.preventDefault();return}const ue=U[0],de=U[U.length-1],G=document.activeElement;I.shiftKey&&(G===ue||!P.contains(G))?(I.preventDefault(),de.focus()):!I.shiftKey&&(G===de||!P.contains(G))&&(I.preventDefault(),ue.focus())};return document.addEventListener("keydown",M),S.current?.focus({preventScroll:!0}),()=>{document.removeEventListener("keydown",M),Z.unlockBackgroundScroll(y)}},[_.isModal,q]);const ie=async(y,M)=>(E.current=!0,N(!0),f?.(y),await Te(y,M)!==null),z=F[F.length-1],K=Fe&&z?.role==="assistant"&&(z.status==="IN_PROGRESS"||z.status==="WAITING_CLIENT"),De=(0,o.useCallback)(y=>{const M=y.functionName;if(!(!h||!M))return typeof h=="function"?h(M,y.arguments??{}):h[M]},[h]),{items:ze}=ye({client:B??void 0,labelFor:De,includeReasoning:v}),le=ze.filter(y=>z?.id!==void 0&&y.messageId===z.id),$=h===!1?void 0:le[le.length-1]?.label,ce=!!(K&&$),Oe=x===!1?void 0:x??(y=>ie(y));return(0,a.jsxs)("div",{ref:S,className:`ago-chat-widget ${R}`,..._.surface.attrs,"data-ago-sheet-state":_.compact?_.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",..._.surface.style},children:[!_.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:[u&&(0,a.jsx)("img",{src:u,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,a.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),X&&(0,a.jsxs)("button",{type:"button",className:"ago-chat-widget__peek","aria-expanded":!1,"aria-label":"Open the conversation",onClick:()=>{Y(!1),T("user")},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:"8px",padding:"14px 18px 10px",border:"none",borderBottom:"1px solid currentColor",borderBottomColor:"rgba(128,128,128,0.25)",background:"transparent",textAlign:"left",cursor:"pointer",font:"inherit",color:"inherit"},children:[(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7},children:[s,Ie&&(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:"↑"})]}),K&&!z?.content?(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[!$&&(0,a.jsx)(Se,{}),(0,a.jsx)("span",{style:{fontSize:"13px",opacity:.7,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:$?Ce($):g})]}):(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:z?.content||r})]}),_.compact&&_.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:()=>q("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:X?"none":"flex",minHeight:0},children:[(0,a.jsxs)("div",{ref:j,className:"ago-chat-widget__messages",onScroll:y=>{const M=y.currentTarget,I=M.scrollHeight-M.scrollTop-M.clientHeight<=48;E.current=I,N(I)},role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,"aria-busy":K,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:r}):F.map((y,M)=>(0,a.jsx)(Ae,{message:y,showAgentName:p,isLast:M===F.length-1,onFollowUpClick:Oe,showStreamingDots:!ce,feedback:A&&y.role==="assistant"&&y.status==="DONE"&&y.content?(0,a.jsx)(_e,{messageId:y.id,client:n,...A===!0?{}:A}):void 0},y.id)),ce&&(0,a.jsx)(ot,{label:$??""}),ae&&(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:ae.message}),(0,a.jsx)("div",{})]}),!k&&(0,a.jsx)("button",{type:"button",className:"ago-chat-widget__jump","aria-label":"Jump to latest message",onClick:We,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)(we,{onSend:ie,onStop:i?()=>{Pe()}:void 0,disabled:K,placeholder:c,allowFiles:l})]})});function Ee(e={}){const n=W(),t=e.client??n;if(!t)throw new V.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[s,r]=(0,o.useState)(null),c=(0,o.useRef)(s);c.current=s;const l=(0,o.useRef)(e.onExpand);return l.current=e.onExpand,(0,o.useEffect)(()=>{const i=u=>{r(u),t.proactive?.shown(u)},d=({nudge:u})=>{r(p=>p?.id===u.id?null:p)};return t.on("nudge:ready",i),t.on("nudge:accepted",d),t.on("nudge:dismissed",d),()=>{t.off("nudge:ready",i),t.off("nudge:accepted",d),t.off("nudge:dismissed",d)}},[t]),{nudge:s,accept:(0,o.useCallback)(async()=>{const i=c.current;i&&(r(null),await t.proactive?.accept(i),(i.source==="agent"||i.goal)&&l.current?.(i))},[t]),dismiss:(0,o.useCallback)(()=>{const i=c.current;i&&(r(null),t.proactive?.dismiss(i))},[t])}}var St=({client:e,onExpand:n,autoHideMs:t,position:s="bottom-right",openChatLabel:r="Open chat",className:c=""})=>{const{nudge:l,accept:i,dismiss:d}=Ee({client:e,onExpand:n});if((0,o.useEffect)(()=>{if(!l||!t)return;const p=setTimeout(()=>d(),t);return()=>clearTimeout(p)},[l,t,d]),!l)return null;const u=l.source==="agent"||!!l.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${c}`,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:d,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:l.message}),(l.action||u)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[l.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:l.action.label}),u&&(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:r})]})]})};function Re({client:e,autoLoad:n=!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,c]=(0,o.useState)([]),[l,i]=(0,o.useState)(null),[d,u]=(0,o.useState)(!1),[p,C]=(0,o.useState)(null),A=(0,o.useCallback)(async()=>{u(!0),C(null);try{const{data:f}=await s.getConversations();c(f)}catch(f){C(f instanceof Error?f:new Error("Failed to load conversations"))}finally{u(!1)}},[s]),x=(0,o.useCallback)(async f=>{u(!0),C(null);try{i(await s.getConversation(f))}catch(w){C(w instanceof Error?w:new Error("Failed to load conversation"))}finally{u(!1)}},[s]),R=(0,o.useCallback)(()=>{i(null)},[]);return(0,o.useEffect)(()=>{n&&A()},[n,A]),{conversations:r,currentConversation:l,isLoading:d,error:p,selectConversation:x,startNewConversation:R,refreshConversations:A}}function At(e={}){const n=W(),t=e.client||n;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const s=oe({client:t,conversationId:e.conversationId}),r=Re({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 jt(e,n){const t=L(),{name:s,description:r,parameters:c,handler:l,maxResultBytes:i,requiresApproval:d}=typeof e=="string"?{name:e,...n}:e,u=(0,o.useRef)(l);u.current=l,(0,o.useEffect)(()=>{const p=C=>u.current(C);return t.registerFunction(s,p,{description:r,parameters:c,maxResultBytes:i,requiresApproval:d}),()=>{t.unregisterFunction(s)}},[t,s,r,c,i,d])}function _t(e,n){const t=L(),s=(0,o.useRef)(e);s.current=e,(0,o.useEffect)(()=>(t.registerNavigationFunction(r=>s.current(r),n),()=>{t.unregisterNavigationFunction()}),[t,n])}function Et(e,n){const t=L(),s=n?.functionName??"setPageState",r=n?.requiresApproval,c=n?.data!==void 0,l=n?.data?.description,i=n?.data?.maxResultBytes,d=n?.settleTimeoutMs,u=(0,o.useRef)(e);u.current=e;const p=(0,o.useRef)(n);p.current=n,(0,o.useEffect)(()=>{const C=u.current.map(x=>{const R=()=>u.current.find(f=>f.name===x.name)??x;return{name:x.name,description:x.description,schema:x.schema,clearable:x.clearable,get:x.get?()=>R().get?.():void 0,set:f=>R().set(f)}}),A=c?{description:l??"What the page is currently showing.",maxResultBytes:i,get:()=>p.current?.data?.get(),isLoading:()=>p.current?.data?.isLoading?.()??!1}:void 0;return t.registerPageStateFunction(C,{functionName:s,requiresApproval:r,data:A,settleTimeoutMs:d}),()=>{t.unregisterPageStateFunction(s)}},[t,s,r,c,l,i,d,JSON.stringify(e.map(C=>({name:C.name,description:C.description,schema:C.schema,clearable:C.clearable})))])}function Rt(e){const n=L(),t=(0,o.useRef)(e);t.current=e,(0,o.useEffect)(()=>Je.attachAutoContinueAfterNavigation(n,()=>t.current),[n])}function Nt(e={}){const n=W(),t=e.client||n;if(!t)throw new V.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[s,r]=(0,o.useState)(()=>t.getRecentActivity());(0,o.useEffect)(()=>{r(t.getRecentActivity());const i=()=>r(t.getRecentActivity());return t.on("activity:recorded",i),()=>t.off("activity:recorded",i)},[t]);const c=(0,o.useCallback)(i=>t.recordActivity(i),[t]),l=(0,o.useCallback)(()=>{t.clearActivity(),r([])},[t]);return{entries:s,latest:s.length>0?s[s.length-1]:void 0,record:c,clear:l}}function It(e,n){const t=L(),s=(0,o.useId)(),r=n??s,c=(0,o.useRef)(e);c.current=e;const l=typeof e=="function";(0,o.useEffect)(()=>{if(typeof c.current=="function"){const i=()=>c.current();return t.addDynamicContext(r,i),()=>{t.removeDynamicContext(r)}}return t.setContext(r,c.current),()=>{t.removeContext(r)}},[t,r,l,l?"":JSON.stringify(e)])}function Ne(e){return(0,o.useSyncExternalStore)(e.subscribe,e.get,e.get)}var me={missing:[],complete:!1};function Mt(e){const n=L(),t=e.schema!=null,s=JSON.stringify(e.schema??null),r=e.submit,c=r?typeof r=="string"?`client:${r}`:r.via==="backend"?"backend":"handler"in r?"client:handler":`client:${r.url}`:"none",l=JSON.stringify(e.initialValues??null),i=(0,o.useMemo)(()=>t?O.createFormCollector(e):null,[t,e.name,s,c,l,e.autoSubmit]),[d,u]=(0,o.useState)({collector:null,loading:!t,error:null});(0,o.useEffect)(()=>{if(t)return;let g=!1;return u({collector:null,loading:!0,error:null}),O.loadFormCollector(n,e).then(h=>{g||u({collector:h,loading:!1,error:null})}).catch(h=>{g||u({collector:null,loading:!1,error:h instanceof Error?h:new Error(String(h))})}),()=>{g=!0}},[n,t,e.name,c,l,e.autoSubmit]);const p=t?i:d.collector,C=t?!1:d.loading,A=t?null:d.error;(0,o.useEffect)(()=>{if(p)return p.install(n)},[n,p]);const x=(0,o.useMemo)(()=>D.createStore({values:e.initialValues??{},submitted:!1}),[l]),R=Ne(p?.store??x),f=(0,o.useMemo)(()=>p?.getStatus()??me,[R,p]),w=(0,o.useMemo)(()=>({...R,...f}),[R,f]),b=(0,o.useMemo)(()=>({name:e.name,store:x,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:()=>x.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>me}),[e.name,x]);return{...p??b,state:w,loading:C,error:A}}exports.AgoNudge=St;exports.AgoProvider=Ye;exports.ChatInput=we;exports.ChatWidget=kt;exports.DEFAULT_MESSAGE_FEEDBACK_LABELS=te;exports.FEEDBACK_REASONS=D.FEEDBACK_REASONS;exports.Markdown=ke;exports.Message=Ae;exports.MessageFeedback=_e;exports.__exportAll=Ue;exports.createFormCollector=O.createFormCollector;exports.createMockClient=Ve.createMockClient;exports.deriveFormStatus=O.deriveFormStatus;exports.loadFormCollector=O.loadFormCollector;exports.useAgo=he;exports.useAgoActivity=ye;exports.useAgoActivityLog=Nt;exports.useAgoAutoContinueAfterNavigation=Rt;exports.useAgoClient=L;exports.useAgoContext=It;exports.useAgoFunction=jt;exports.useAgoNavigation=_t;exports.useAgoPageState=Et;exports.useAgoStore=Ne;exports.useChat=At;exports.useConversation=Re;exports.useFeedback=je;exports.useFormCollector=Mt;exports.useMessages=oe;exports.useOptionalAgoClient=W;exports.useProactiveNudge=Ee;exports.useSheet=ve;
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:b=>{b.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:b=>{b.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},b=(m,f)=>d.current.get(m)===f;return{ratings:s,submitFeedback:(0,n.useCallback)(async(m,f,C)=>{const p=g(m);c(!0),x(null);try{await t.submitFeedback(m,f,C),b(m,p)&&o(S=>({...S,[m]:f}))}catch(S){const y=S instanceof Error?S:new Error("Failed to submit feedback");throw x(y),y}finally{c(!1)}},[t]),submitConversationFeedback:(0,n.useCallback)(async(m,f,C)=>{const p=g(m);c(!0),x(null);try{const S=await t.submitConversationFeedback(m,f,C);return b(m,p)&&o(y=>({...y,[S]:f})),S}catch(S){const y=S instanceof Error?S:new Error("Failed to submit feedback");throw x(y),y}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],[b,m]=(0,n.useState)(!1),[f,C]=(0,n.useState)([]),[p,S]=(0,n.useState)(""),[y,N]=(0,n.useState)(!1),[_,v]=(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&&!y)},E=u=>{C(A=>A.includes(u)?A.filter(R=>R!==u):[...A,u])},h=f.length>0||p.trim().length>0,I=()=>{!h||_||(v(!0),k(g??"negative",{reasons:f,comment:p.trim()}).then(u=>{v(!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")})]}),y&&(0,a.jsx)("div",{className:"ago-feedback__thanks",role:"status",style:{marginTop:"6px",fontSize:"13px",color:"#6b6d6f"},children:i.thanks}),b&&!y&&(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:b=!1,forms:m,feedback:f=!1,onFollowUpClick:C,className:p="",onMessageSent:S,onMessageReceived:y,sheet:N=!1,thinkingLabel:_="Thinking...",functionLabels:v,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 w=!1;const T=[];return Promise.all(m.map(M=>M.schema!=null?Promise.resolve(z.createFormCollector(M)):z.loadFormCollector(H,M))).then(M=>{if(!w)for(const W of M)T.push(W.install(H))}).catch(()=>{}),()=>{w=!0,T.forEach(M=>M())}},[H,m?JSON.stringify(m.map(w=>[w.name,w.schema??null,w.submit??!1,w.description??null])):""]),(0,n.useEffect)(()=>{const w=E.current;!w||!h.current||(w.scrollTop=w.scrollHeight)},[F]);const Oe=()=>{const w=E.current;w&&(h.current=!0,u(!0),w.scrollTop=w.scrollHeight)};(0,n.useEffect)(()=>{const w=F[F.length-1];w&&w.role==="assistant"&&w.status==="DONE"&&y&&y({id:w.id,content:w.content})},[F,y]),(0,n.useEffect)(()=>{Q(!!ee)},[F.length]),(0,n.useEffect)(()=>{const w=A.current;if(!R.compact||!w)return;const T=document.documentElement;if(R.state!=="peek")return;const M=()=>{T.style.setProperty("--ago-sheet-height",`${Math.round(w.getBoundingClientRect().height)}px`)};M();const W=typeof ResizeObserver=="function"?new ResizeObserver(M):null;return W?.observe(w),()=>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 w=Symbol("ago-react-sheet");G.lockBackgroundScroll(w);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(w)}},[R.isModal,$]);const ce=async(w,T)=>(h.current=!0,u(!0),S?.(w),await We(w,T)!==null),O=F[F.length-1],J=De&&O?.role==="assistant"&&(O.status==="IN_PROGRESS"||O.status==="WAITING_CLIENT"),ze=(0,n.useCallback)(w=>{const T=w.functionName;if(!(!v||!T))return typeof v=="function"?v(T,w.arguments??{}):v[T]},[v]),{items:Be}=Ce({client:H??void 0,labelFor:ze,includeReasoning:k}),ue=Be.filter(w=>O?.id!==void 0&&w.messageId===O.id),K=v===!1?void 0:ue[ue.length-1]?.label,de=!!(J&&K),He=C===!1?void 0:C??(w=>ce(w));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:w=>{const T=w.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((w,T)=>(0,a.jsx)(_e,{message:w,showAgentName:b,isLast:T===F.length-1,onFollowUpClick:He,showStreamingDots:!de,feedback:f&&w.role==="assistant"&&w.status==="DONE"&&w.content?(0,a.jsx)(Ne,{messageId:w.id,client:r,...f===!0?{}:f}):void 0},w.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,b]=(0,n.useState)(null),m=(0,n.useCallback)(async()=>{d(!0),b(null);try{const{data:p}=await s.getConversations();l(p)}catch(p){b(p instanceof Error?p:new Error("Failed to load conversations"))}finally{d(!1)}},[s]),f=(0,n.useCallback)(async p=>{d(!0),b(null);try{i(await s.getConversation(p))}catch(S){b(S instanceof Error?S:new Error("Failed to load conversation"))}finally{d(!1)}},[s]),C=(0,n.useCallback)(()=>{i(null)},[]);return(0,n.useEffect)(()=>{r&&m()},[r,m]),{conversations:o,currentConversation:c,isLoading:x,error:g,selectConversation:f,startNewConversation:C,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 b=m=>g.current(m);return t.registerFunction(s,b,{description:o,parameters:l,maxResultBytes:i,requiresApproval:x,webmcp:d}),()=>{t.unregisterFunction(s)}},[t,s,o,l,i,x,JSON.stringify(d??null)])}function Nt(e,r){const t=B(),s=(0,n.useRef)(e);s.current=e,(0,n.useEffect)(()=>(t.registerNavigationFunction(o=>s.current(o),r),()=>{t.unregisterNavigationFunction()}),[t,r])}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 b=d.current.map(f=>{const C=()=>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?()=>C().get?.():void 0,set:p=>C().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(b,{functionName:s,requiresApproval:o,data:m,settleTimeoutMs:x}),()=>{t.unregisterPageStateFunction(s)}},[t,s,o,l,c,i,x,JSON.stringify(e.map(b=>({name:b.name,description:b.description,schema:b.schema,clearable:b.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,b=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]),C=Te(g?.store??f),p=(0,n.useMemo)(()=>g?.getStatus()??be,[C,g]),S=(0,n.useMemo)(()=>({...C,...p}),[C,p]),y=(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??y,state:S,loading:b,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;