@useago/sdk 1.5.0 → 1.5.3

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 (46) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/AgoClient-BGkFSNZF.cjs +8 -0
  3. package/dist/AgoClient-CW-BLT1_.js +1542 -0
  4. package/dist/angular.cjs +1 -1
  5. package/dist/angular.d.cts +390 -2
  6. package/dist/angular.d.ts +390 -2
  7. package/dist/angular.js +1 -1
  8. package/dist/createConversationSession-BCb0D6bt.cjs +1 -0
  9. package/dist/{createConversationSession-DCSWShaW.js → createConversationSession-C7cnnWKW.js} +3 -3
  10. package/dist/createFormCollector-iCDwAwYJ.js +279 -0
  11. package/dist/createFormCollector-t_fGyuTD.cjs +1 -0
  12. package/dist/createMockClient-Br0TWgLO.js +97 -0
  13. package/dist/createMockClient-BwNLPjeT.cjs +1 -0
  14. package/dist/devtools.d.cts +390 -2
  15. package/dist/devtools.d.ts +390 -2
  16. package/dist/helpers.d.cts +5 -0
  17. package/dist/helpers.d.ts +5 -0
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.d.cts +605 -4
  20. package/dist/index.d.ts +605 -4
  21. package/dist/index.js +95 -90
  22. package/dist/react.cjs +3 -3
  23. package/dist/react.d.cts +561 -4
  24. package/dist/react.d.ts +561 -4
  25. package/dist/react.js +849 -517
  26. package/dist/testing.cjs +1 -1
  27. package/dist/testing.d.cts +390 -2
  28. package/dist/testing.d.ts +390 -2
  29. package/dist/testing.js +1 -1
  30. package/dist/vue.cjs +1 -1
  31. package/dist/vue.d.cts +411 -2
  32. package/dist/vue.d.ts +411 -2
  33. package/dist/vue.js +133 -110
  34. package/dist/widget.cjs +4 -4
  35. package/dist/widget.d.cts +387 -2
  36. package/dist/widget.d.ts +387 -2
  37. package/dist/widget.js +437 -423
  38. package/llms-full.txt +74 -2
  39. package/package.json +1 -1
  40. package/dist/AgoClient-q39FIjSC.js +0 -912
  41. package/dist/AgoClient-wcPRaIMs.cjs +0 -8
  42. package/dist/createConversationSession-BBYfQLLS.cjs +0 -1
  43. package/dist/createFormCollector-eimwwWEi.cjs +0 -1
  44. package/dist/createFormCollector-sB6rMccD.js +0 -299
  45. package/dist/createMockClient-BUc9PSbo.js +0 -79
  46. package/dist/createMockClient-CjdCqixj.cjs +0 -1
package/dist/index.js CHANGED
@@ -1,159 +1,164 @@
1
- import { a as h, c as A, d as C, f as y, i as E, l as S, m as b, o as v, p as F, r as M, s as I, t as k, u as T } from "./functions-CApuQZ2b.js";
2
- import { _ as G, a as N, c as O, d as _, f as q, g as x, h as L, l as D, m as d, n as H, o as J, p as R, r as j, s as z, t as c, u as B } from "./AgoClient-q39FIjSC.js";
3
- import { t as $ } from "./autoContinue-D3Mmaaca.js";
4
- import { i as Q, n as V, r as W, t as X } from "./createFormCollector-sB6rMccD.js";
5
- import { t as Z } from "./createConversationSession-DCSWShaW.js";
6
- import { t as oe } from "./createMockClient-BUc9PSbo.js";
1
+ import { a as w, c as A, d as C, f as y, i as S, l as b, m as E, o as v, p as F, r as M, s as I, t as k, u as T } from "./functions-CApuQZ2b.js";
2
+ import { C as x, S as G, _ as N, a as O, b as d, c as _, d as q, f as D, g as L, h as P, l as R, m as H, n as J, o as j, p as z, r as B, s as W, t as c, u as $, v as K, x as Q, y as V } from "./AgoClient-CW-BLT1_.js";
3
+ import { t as Y } from "./autoContinue-D3Mmaaca.js";
4
+ import { t as ee } from "./createConversationSession-C7cnnWKW.js";
5
+ import { n as oe, r as re, t as ae } from "./createFormCollector-iCDwAwYJ.js";
6
+ import { t as se } from "./createMockClient-Br0TWgLO.js";
7
7
  import "./testing.js";
8
- function re(e) {
8
+ function ue(e) {
9
9
  return e;
10
10
  }
11
- function ne(e, o) {
12
- return e.on("message:complete", o), () => e.off("message:complete", o);
11
+ function ge(e, t) {
12
+ return e.on("message:complete", t), () => e.off("message:complete", t);
13
13
  }
14
- function ae(e, o) {
15
- return e.on("message:chunk", o), () => e.off("message:chunk", o);
14
+ function fe(e, t) {
15
+ return e.on("message:chunk", t), () => e.off("message:chunk", t);
16
16
  }
17
- function se(e, o) {
18
- return e.on("message:start", o), () => e.off("message:start", o);
17
+ function me(e, t) {
18
+ return e.on("message:start", t), () => e.off("message:start", t);
19
19
  }
20
- function ie(e, o) {
21
- return e.on("message:error", o), () => e.off("message:error", o);
20
+ function le(e, t) {
21
+ return e.on("message:error", t), () => e.off("message:error", t);
22
22
  }
23
- function ue(e, o) {
24
- return e.on("toolCall:received", o), () => e.off("toolCall:received", o);
23
+ function de(e, t) {
24
+ return e.on("toolCall:received", t), () => e.off("toolCall:received", t);
25
25
  }
26
- function ge(e, o) {
27
- return e.on("form:submitted", o), () => e.off("form:submitted", o);
26
+ function ce(e, t) {
27
+ return e.on("form:submitted", t), () => e.off("form:submitted", t);
28
28
  }
29
- function fe(e, o) {
30
- return e.on("form:error", o), () => e.off("form:error", o);
29
+ function pe(e, t) {
30
+ return e.on("form:error", t), () => e.off("form:error", t);
31
31
  }
32
- function me(e, o) {
33
- return e.on("function:invoke", o), () => e.off("function:invoke", o);
32
+ function he(e, t) {
33
+ return e.on("function:invoke", t), () => e.off("function:invoke", t);
34
34
  }
35
- async function* le(e, o, u) {
36
- const n = [];
37
- let r = null, a = !1;
35
+ async function* we(e, t, u) {
36
+ const a = [];
37
+ let r = null, n = !1;
38
38
  const g = (s) => {
39
- n.push(s), r?.();
39
+ a.push(s), r?.();
40
40
  }, f = (s) => g({
41
41
  type: "start",
42
42
  data: s
43
- }), t = (s) => g({
43
+ }), o = (s) => g({
44
44
  type: "chunk",
45
45
  data: s
46
46
  }), i = (s) => {
47
47
  g({
48
48
  type: "complete",
49
49
  data: s
50
- }), a = !0, r?.();
50
+ }), n = !0, r?.();
51
51
  }, m = (s) => {
52
52
  g({
53
53
  type: "error",
54
54
  data: s
55
- }), a = !0, r?.();
55
+ }), n = !0, r?.();
56
56
  }, l = (s) => g({
57
57
  type: "toolCall",
58
58
  data: s
59
59
  });
60
- e.on("message:start", f), e.on("message:chunk", t), e.on("message:complete", i), e.on("message:error", m), e.on("toolCall:received", l), e.sendMessage(o, u).catch(() => {
61
- a = !0, r?.();
60
+ e.on("message:start", f), e.on("message:chunk", o), e.on("message:complete", i), e.on("message:error", m), e.on("toolCall:received", l), e.sendMessage(t, u).catch(() => {
61
+ n = !0, r?.();
62
62
  });
63
63
  try {
64
- for (; !a || n.length > 0; ) n.length > 0 ? yield n.shift() : (await new Promise((s) => {
64
+ for (; !n || a.length > 0; ) a.length > 0 ? yield a.shift() : (await new Promise((s) => {
65
65
  r = s;
66
66
  }), r = null);
67
67
  } finally {
68
- e.off("message:start", f), e.off("message:chunk", t), e.off("message:complete", i), e.off("message:error", m), e.off("toolCall:received", l);
68
+ e.off("message:start", f), e.off("message:chunk", o), e.off("message:complete", i), e.off("message:error", m), e.off("toolCall:received", l);
69
69
  }
70
70
  }
71
71
  function p(e) {
72
- let o, u, n, r, a, g;
72
+ let t, u, a, r, n, g;
73
73
  if (typeof window < "u" && window.AGO) {
74
- const t = window.AGO;
75
- o = t.basepath, u = t.widgetId, n = t.agent || t.defaultAgent, r = t.permission, a = t.email, g = t.jwt;
74
+ const o = window.AGO;
75
+ t = o.basepath, u = o.widgetId, a = o.agent || o.defaultAgent, r = o.permission, n = o.email, g = o.jwt;
76
76
  }
77
77
  if (typeof document < "u") {
78
- const t = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
79
- o = o || t("ago-base-url"), u = u || t("ago-widget-id"), n = n || t("ago-agent") || t("ago-agent-id"), r = r || t("ago-permission"), a = a || t("ago-user-email");
78
+ const o = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
79
+ t = t || o("ago-base-url"), u = u || o("ago-widget-id"), a = a || o("ago-agent") || o("ago-agent-id"), r = r || o("ago-permission"), n = n || o("ago-user-email");
80
80
  }
81
81
  if (typeof document < "u") {
82
- const t = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
83
- for (const i of t)
84
- i && (o = o || i.getAttribute("data-ago-base-url") || void 0, u = u || i.getAttribute("data-ago-widget-id") || void 0, n = n || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, r = r || i.getAttribute("data-ago-permission") || void 0, a = a || i.getAttribute("data-ago-user-email") || void 0);
82
+ const o = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
83
+ for (const i of o)
84
+ i && (t = t || i.getAttribute("data-ago-base-url") || void 0, u = u || i.getAttribute("data-ago-widget-id") || void 0, a = a || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, r = r || i.getAttribute("data-ago-permission") || void 0, n = n || i.getAttribute("data-ago-user-email") || void 0);
85
85
  }
86
- o = e?.baseUrl || o, u = e?.widgetId || u, n = e?.agent || e?.defaultAgentId || n, r = e?.permission || r, a = e?.userEmail || a, g = e?.userJwt || g;
86
+ t = e?.baseUrl || t, u = e?.widgetId || u, a = e?.agent || e?.defaultAgentId || a, r = e?.permission || r, n = e?.userEmail || n, g = e?.userJwt || g;
87
87
  const f = e?.debug;
88
- return o ? {
89
- baseUrl: o,
88
+ return t ? {
89
+ baseUrl: t,
90
90
  widgetId: u,
91
- agent: n,
91
+ agent: a,
92
92
  permission: r,
93
- userEmail: a,
93
+ userEmail: n,
94
94
  userJwt: g,
95
95
  debug: f
96
96
  } : null;
97
97
  }
98
- function de(e) {
99
- const o = p(e);
100
- if (!o) throw new d('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.', "config_missing_base_url");
101
- return new c(o);
98
+ function Ae(e) {
99
+ const t = p(e);
100
+ if (!t) throw new d('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.', "config_missing_base_url");
101
+ return new c(t);
102
102
  }
103
- function ce(e, o) {
103
+ function Ce(e, t) {
104
104
  return {
105
105
  ...e,
106
- handler: o
106
+ handler: t
107
107
  };
108
108
  }
109
109
  export {
110
- R as AgoApiError,
110
+ V as AgoApiError,
111
111
  c as AgoClient,
112
112
  d as AgoError,
113
- L as AgoFunctionError,
114
- x as AgoNetworkError,
115
- G as AgoStreamError,
116
- B as ClientContextRegistry,
117
- j as EventEmitter,
118
- _ as FunctionRegistry,
119
- O as SSEHandler,
120
- $ as attachAutoContinueAfterNavigation,
113
+ Q as AgoFunctionError,
114
+ G as AgoNetworkError,
115
+ x as AgoStreamError,
116
+ $ as ClientContextRegistry,
117
+ B as EventEmitter,
118
+ N as FunctionRegistry,
119
+ _ as SSEHandler,
120
+ L as SignalCollector,
121
+ Y as attachAutoContinueAfterNavigation,
121
122
  p as autoDetectConfig,
122
- N as canInlineImage,
123
+ O as canInlineImage,
123
124
  k as copyToClipboard,
124
- de as createAgo,
125
- Z as createConversationSession,
126
- X as createFormCollector,
127
- le as createMessageStream,
128
- oe as createMockClient,
129
- Q as createStore,
130
- re as defineFunction,
131
- V as deriveFormStatus,
132
- J as formatFileSize,
125
+ Ae as createAgo,
126
+ q as createAgoProactive,
127
+ ee as createConversationSession,
128
+ ae as createFormCollector,
129
+ we as createMessageStream,
130
+ se as createMockClient,
131
+ P as createStore,
132
+ ue as defineFunction,
133
+ oe as deriveFormStatus,
134
+ j as formatFileSize,
133
135
  M as getLocalStorage,
134
- E as getUserLocation,
135
- h as highlightElement,
136
- D as isStreamNetworkError,
137
- W as loadFormCollector,
138
- q as logger,
139
- fe as onFormError,
140
- ge as onFormSubmitted,
141
- me as onFunctionInvoke,
142
- ne as onMessage,
143
- ae as onMessageChunk,
144
- ie as onMessageError,
145
- se as onMessageStart,
146
- ue as onToolCall,
136
+ S as getUserLocation,
137
+ w as highlightElement,
138
+ R as isStreamNetworkError,
139
+ re as loadFormCollector,
140
+ K as logger,
141
+ D as matchesRoutePattern,
142
+ z as matchesWhen,
143
+ pe as onFormError,
144
+ ce as onFormSubmitted,
145
+ he as onFunctionInvoke,
146
+ ge as onMessage,
147
+ fe as onMessageChunk,
148
+ le as onMessageError,
149
+ me as onMessageStart,
150
+ de as onToolCall,
147
151
  v as openUrl,
148
- z as safeAttachmentUrl,
152
+ H as partialDeepMatch,
153
+ W as safeAttachmentUrl,
149
154
  I as scrollToElement,
150
155
  A as setLocalStorage,
151
- S as setTheme,
156
+ b as setTheme,
152
157
  T as showConfirmDialog,
153
158
  C as showNotification,
154
159
  y as showToast,
155
160
  F as submitForm,
156
- b as trackEvent,
157
- H as validateConfig,
158
- ce as withHandler
161
+ E as trackEvent,
162
+ J as validateConfig,
163
+ Ce as withHandler
159
164
  };
package/dist/react.cjs CHANGED
@@ -1,7 +1,7 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("./rolldown-runtime-16Nf8qvH.cjs"),F=require("./AgoClient-wcPRaIMs.cjs"),J=require("./autoContinue-CcCTva-D.cjs"),I=require("./createFormCollector-eimwwWEi.cjs"),V=require("./createMockClient-CjdCqixj.cjs");let s=require("react");s=W.__toESM(s,1);let o=require("react/jsx-runtime"),P=require("react-markdown");P=W.__toESM(P,1);let T=require("remark-gfm");T=W.__toESM(T,1);function q(e){const[t,r]=(0,s.useState)(!1),n=(0,s.useRef)(null),a=(0,s.useMemo)(()=>{if(n.current&&(n.current.destroy(),n.current=null),!e)return null;const l=new F.AgoClient(e);return n.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(r(!0),()=>{n.current?.destroy(),n.current=null}),[a]),(0,s.useEffect)(()=>{n.current&&e&&n.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var z=(0,s.createContext)(null),Y=({children:e,client:t,tools:r,helpers:n,pageContext:a,...l})=>{const{client:d}=q(t?null:l),c=t||d;return(0,s.useEffect)(()=>{if(!(!r||r.length===0)){for(const g of r)c.register(g);return()=>{for(const g of r)c.unregisterFunction(g.name)}}},[c,r]),(0,s.useEffect)(()=>{if(!n)return;const g=[];return Promise.resolve().then(()=>require("./functions-IGSjjvF4.cjs")).then(f=>f.functions_exports).then(f=>{for(const[b,C]of Object.entries(n)){const j=f[b];if(!j){console.warn(`[AGO] Unknown helper: "${b}"`);continue}const h=C===!0?j:{...j,handler:C};c.register(h),g.push(h.name)}}),()=>{for(const f of g)c.unregisterFunction(f)}},[c,n]),(0,s.useEffect)(()=>{a==="auto"&&c.enableAutoPageContext()},[c,a]),(0,o.jsx)(z.Provider,{value:c,children:e})};function M(){const e=(0,s.useContext)(z);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function N(){return(0,s.useContext)(z)}function L({client:e,conversationId:t}={}){const r=N(),n=e||r;if(!n)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(t),[g,f]=(0,s.useState)(!1),[b,C]=(0,s.useState)(null);(0,s.useEffect)(()=>{t&&t!==d&&(c(t),j(t))},[t]);const j=async h=>{try{l((await n.getMessages(h)).filter(y=>!y.hidden))}catch(y){C(y instanceof Error?y:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const h=u=>u==="IN_PROGRESS"||u==="WAITING_CLIENT",y=u=>{d||c(u.conversationId),f(!0),l(p=>{const m=p.findIndex(x=>x.id===u.messageId);return m>=0?p.map((x,_)=>_===m?{...x,status:"IN_PROGRESS"}:x):p.some(x=>x.role==="assistant"&&h(x.status))?p:[...p,{id:u.messageId,conversationId:u.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},S=u=>{l(p=>{const m=p.findIndex(x=>x.id===u.messageId);return m<0?p:p.map((x,_)=>_===m?{...x,content:x.content+u.content}:x)})},k=u=>{l(p=>{let m=-1;for(let x=p.length-1;x>=0;x--)if(p[x].role==="assistant"&&h(p[x].status)){m=x;break}return m<0?p:[...p.slice(0,m),{...p[m],...u},...p.slice(m+1)]})},i=u=>{l(p=>{const m=p.findIndex(x=>x.id===u.id);return m>=0?[...p.slice(0,m),u,...p.slice(m+1)]:[...p,u]}),f(!1)},v=u=>{C(new Error(u.error)),f(!1)};return n.on("message:start",y),n.on("message:chunk",S),n.on("message:answer-complete",k),n.on("message:complete",i),n.on("message:error",v),()=>{n.off("message:start",y),n.off("message:chunk",S),n.off("message:answer-complete",k),n.off("message:complete",i),n.off("message:error",v)}},[n,d]),{messages:a,isLoading:g,error:b,sendMessage:(0,s.useCallback)(async(h,y)=>{f(!0),C(null);const S={id:`temp-${Date.now()}`,conversationId:d||"",content:h,role:"user",status:"DONE",attachments:y&&y.length>0?F.attachmentsFromFiles(y):void 0,createdAt:new Date},k={id:`temp-assistant-${Date.now()}`,conversationId:d||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(i=>[...i,S,k]);try{const i=await n.sendMessage(h,{conversationId:d,files:y});return i.conversationId&&!d&&c(i.conversationId),l(v=>{const u=v.filter(m=>!m.id.startsWith("temp-")),p={...S,id:S.id.replace("temp-","user-"),conversationId:i.conversationId};return u.some(m=>m.id===i.id)?[...u,p].sort((m,x)=>new Date(m.createdAt).getTime()-new Date(x.createdAt).getTime()):[...u,p,i]}),i}catch(i){return C(i instanceof Error?i:new Error("Failed to send message")),f(!1),l(v=>v.filter(u=>!u.id.startsWith("temp-"))),null}},[n,d]),clearMessages:(0,s.useCallback)(()=>{l([]),c(void 0),C(null)},[]),conversationId:d}}var H=({onSend:e,disabled:t=!1,placeholder:r="Type a message...",allowFiles:n=!1,className:a=""})=>{const[l,d]=(0,s.useState)(""),[c,g]=(0,s.useState)([]),f=(0,s.useRef)(null),b=(0,s.useRef)(null),C=(0,s.useCallback)(()=>{const i=b.current;if(!i)return;const v=110;i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight+2,v)}px`,i.style.overflowY=i.scrollHeight+2>v?"auto":"hidden"},[]),j=(0,s.useCallback)(i=>{i.preventDefault(),(l.trim()||c.length>0)&&(e(l.trim(),c.length>0?c:void 0),d(""),g([]),requestAnimationFrame(C))},[l,c,e,C]),h=(0,s.useCallback)(i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),j(i))},[j]),y=(0,s.useCallback)(i=>{const v=Array.from(i.target.files||[]);g(u=>[...u,...v])},[]),S=(0,s.useCallback)(i=>{g(v=>v.filter((u,p)=>p!==i))},[]),k=l.trim()||c.length>0;return(0,o.jsxs)("form",{onSubmit:j,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[c.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((i,v)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.name}),(0,o.jsx)("button",{type:"button",onClick:()=>S(v),"aria-label":`Remove ${i.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},v))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[n&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>f.current?.click(),disabled:t,"aria-label":"Attach file",style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:f,type:"file",multiple:!0,onChange:y,style:{display:"none"}})]}),(0,o.jsx)("textarea",{ref:b,value:l,onChange:i=>{d(i.target.value),C()},onKeyDown:h,placeholder:r,"aria-label":r,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:i=>{i.currentTarget.style.borderColor="#1b5fc4"},onBlur:i=>{i.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!k,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!k?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!k?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...r})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...r,children:t}),Q=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),R=(e,t)=>{const r=({children:n,...a})=>s.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},n);return r.displayName=`MarkdownHeading${e}`,r},Z=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),te=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),ne=({className:e,children:t,...r})=>e!==void 0||String(t).includes(`
2
- `)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),oe=({children:e,...t})=>(0,o.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),se=({children:e,...t})=>(0,o.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,o.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),ae=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ie=({children:e,...t})=>(0,o.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,o.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ce=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),de={a:X,p:Q,h1:R(1,"20px"),h2:R(2,"18px"),h3:R(3,"16px"),h4:R(4,"15px"),h5:R(5,"14px"),h6:R(6,"13px"),ul:Z,ol:ee,li:te,code:ne,pre:re,blockquote:oe,table:se,th:ae,td:ie,img:le,hr:ce},ue=[T.default],O=({content:e})=>(0,o.jsx)(P.default,{remarkPlugins:ue,components:de,children:e}),fe=({attachment:e,isUser:t})=>{const r=F.safeAttachmentUrl(e.url);if(F.canInlineImage(e))return(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,o.jsx)("img",{src:r,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const n=F.formatFileSize(e.fileSize),a=(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,o.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,o.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),n&&(0,o.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:n})]})]}),l={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:t?"rgba(255,255,255,0.12)":"#fff",color:t?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return r?(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:l,children:a}):(0,o.jsx)("div",{style:l,children:a})},ge=({source:e,index:t})=>{const r=(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,o.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:t+1}),(0,o.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),n={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,o.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:n,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:r}):(0,o.jsx)("div",{style:n,children:r})},pe=()=>(0,o.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,o.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,o.jsx)("style",{children:`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("./rolldown-runtime-16Nf8qvH.cjs"),R=require("./AgoClient-BGkFSNZF.cjs"),Z=require("./autoContinue-CcCTva-D.cjs"),_=require("./createFormCollector-t_fGyuTD.cjs"),Q=require("./createMockClient-BwNLPjeT.cjs");let s=require("react");s=D.__toESM(s,1);let a=require("react/jsx-runtime"),P=require("react-markdown");P=D.__toESM(P,1);let W=require("remark-gfm");W=D.__toESM(W,1);function O(e){const[r,t]=(0,s.useState)(!1),o=(0,s.useRef)(null),n=(0,s.useMemo)(()=>{if(o.current&&(o.current.destroy(),o.current=null),!e)return null;const l=new R.AgoClient(e);return o.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(n&&o.current===null&&(o.current=n,n.reviveAfterDestroy()),t(!0),()=>{o.current?.destroy(),o.current=null}),[n]),(0,s.useEffect)(()=>{o.current&&e&&o.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:n,isReady:r}}var q=(0,s.createContext)(null),ee=({children:e,client:r,tools:t,helpers:o,pageContext:n,...l})=>{const{client:u}=O(r?null:l),i=r||u;return(0,s.useEffect)(()=>{if(!(!t||t.length===0)){for(const g of t)i.register(g);return()=>{for(const g of t)i.unregisterFunction(g.name)}}},[i,t]),(0,s.useEffect)(()=>{if(!o)return;const g=[];return Promise.resolve().then(()=>require("./functions-IGSjjvF4.cjs")).then(d=>d.functions_exports).then(d=>{for(const[m,S]of Object.entries(o)){const I=d[m];if(!I){console.warn(`[AGO] Unknown helper: "${m}"`);continue}const k=S===!0?I:{...I,handler:S};i.register(k),g.push(k.name)}}),()=>{for(const d of g)i.unregisterFunction(d)}},[i,o]),(0,s.useEffect)(()=>{n==="auto"&&i.enableAutoPageContext()},[i,n]),(0,a.jsx)(q.Provider,{value:i,children:e})};function M(){const e=(0,s.useContext)(q);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function F(){return(0,s.useContext)(q)}function z({client:e,conversationId:r}={}){const t=F(),o=e||t;if(!o)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[n,l]=(0,s.useState)([]),[u,i]=(0,s.useState)(r),[g,d]=(0,s.useState)(!1),[m,S]=(0,s.useState)(null);(0,s.useEffect)(()=>{r&&r!==u&&(i(r),I(r))},[r]);const I=async k=>{try{l((await o.getMessages(k)).filter(A=>!A.hidden))}catch(A){S(A instanceof Error?A:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const k=f=>f==="IN_PROGRESS"||f==="WAITING_CLIENT",A=f=>{u||i(f.conversationId),d(!0),l(y=>{const w=y.findIndex(C=>C.id===f.messageId);return w>=0?y.map((C,E)=>E===w?{...C,status:"IN_PROGRESS"}:C):y.some(C=>C.role==="assistant"&&k(C.status))?y:[...y,{id:f.messageId,conversationId:f.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},p=f=>{l(y=>{const w=y.findIndex(C=>C.id===f.messageId);return w<0?y:y.map((C,E)=>E===w?{...C,content:C.content+f.content}:C)})},h=f=>{l(y=>{let w=-1;for(let C=y.length-1;C>=0;C--)if(y[C].role==="assistant"&&k(y[C].status)){w=C;break}return w<0?y:[...y.slice(0,w),{...y[w],...f},...y.slice(w+1)]})},c=f=>{l(y=>{const w=y.findIndex(C=>C.id===f.id);return w>=0?[...y.slice(0,w),f,...y.slice(w+1)]:[...y,f]}),d(!1)},v=f=>{S(new Error(f.error)),d(!1)};return o.on("message:start",A),o.on("message:chunk",p),o.on("message:answer-complete",h),o.on("message:complete",c),o.on("message:error",v),()=>{o.off("message:start",A),o.off("message:chunk",p),o.off("message:answer-complete",h),o.off("message:complete",c),o.off("message:error",v)}},[o,u]),{messages:n,isLoading:g,error:m,sendMessage:(0,s.useCallback)(async(k,A)=>{d(!0),S(null);const p={id:`temp-${Date.now()}`,conversationId:u||"",content:k,role:"user",status:"DONE",attachments:A&&A.length>0?R.attachmentsFromFiles(A):void 0,createdAt:new Date},h={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(c=>[...c,p,h]);try{const c=await o.sendMessage(k,{conversationId:u,files:A});return c.conversationId&&!u&&i(c.conversationId),l(v=>{const f=v.filter(w=>!w.id.startsWith("temp-")),y={...p,id:p.id.replace("temp-","user-"),conversationId:c.conversationId};return f.some(w=>w.id===c.id)?[...f,y].sort((w,C)=>new Date(w.createdAt).getTime()-new Date(C.createdAt).getTime()):[...f,y,c]}),c}catch(c){return S(c instanceof Error?c:new Error("Failed to send message")),d(!1),l(v=>v.filter(f=>!f.id.startsWith("temp-"))),null}},[o,u]),clearMessages:(0,s.useCallback)(()=>{l([]),i(void 0),S(null)},[]),conversationId:u}}var B=({onSend:e,disabled:r=!1,placeholder:t="Type a message...",allowFiles:o=!1,className:n=""})=>{const[l,u]=(0,s.useState)(""),[i,g]=(0,s.useState)([]),d=(0,s.useRef)(null),m=(0,s.useRef)(null),S=(0,s.useCallback)(()=>{const c=m.current;if(!c)return;const v=110;c.style.height="auto",c.style.height=`${Math.min(c.scrollHeight+2,v)}px`,c.style.overflowY=c.scrollHeight+2>v?"auto":"hidden"},[]),I=(0,s.useCallback)(c=>{c.preventDefault(),(l.trim()||i.length>0)&&(e(l.trim(),i.length>0?i:void 0),u(""),g([]),requestAnimationFrame(S))},[l,i,e,S]),k=(0,s.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),I(c))},[I]),A=(0,s.useCallback)(c=>{const v=Array.from(c.target.files||[]);g(f=>[...f,...v])},[]),p=(0,s.useCallback)(c=>{g(v=>v.filter((f,y)=>y!==c))},[]),h=l.trim()||i.length>0;return(0,a.jsxs)("form",{onSubmit:I,className:`ago-chat-input ${n}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[i.length>0&&(0,a.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((c,v)=>(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:c.name}),(0,a.jsx)("button",{type:"button",onClick:()=>p(v),"aria-label":`Remove ${c.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},v))}),(0,a.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[o&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:r,"aria-label":"Attach file",style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:r?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,a.jsx)("input",{ref:d,type:"file",multiple:!0,onChange:A,style:{display:"none"}})]}),(0,a.jsx)("textarea",{ref:m,value:l,onChange:c=>{u(c.target.value),S()},onKeyDown:k,placeholder:t,"aria-label":t,disabled:r,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.currentTarget.style.borderColor="#dee3e8"}}),(0,a.jsx)("button",{type:"submit",disabled:r||!h,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:r||!h?"#b5bfc8":"#03182f",color:"#fff",cursor:r||!h?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},te=({href:e,children:r,...t})=>(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:r}),ne=({children:e,...r})=>(0,a.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...r,children:e}),T=(e,r)=>{const t=({children:o,...n})=>s.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:r,fontWeight:600,lineHeight:"1.3"},...n},o);return t.displayName=`MarkdownHeading${e}`,t},re=({children:e,...r})=>(0,a.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...r,children:e}),oe=({children:e,...r})=>(0,a.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...r,children:e}),se=({children:e,...r})=>(0,a.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...r,children:e}),ae=({className:e,children:r,...t})=>e!==void 0||String(r).includes(`
2
+ `)?(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}),ie=({children:e,...r})=>(0,a.jsx)("pre",{style:{margin:"0 0 8px 0"},...r,children:e}),le=({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}),ce=({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})}),ue=({children:e,...r})=>(0,a.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...r,children:e}),de=({children:e,...r})=>(0,a.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...r,children:e}),fe=({alt:e,...r})=>(0,a.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...r}),ge=e=>(0,a.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),pe={a:te,p:ne,h1:T(1,"20px"),h2:T(2,"18px"),h3:T(3,"16px"),h4:T(4,"15px"),h5:T(5,"14px"),h6:T(6,"13px"),ul:re,ol:oe,li:se,code:ae,pre:ie,blockquote:le,table:ce,th:ue,td:de,img:fe,hr:ge},me=[W.default],U=({content:e})=>(0,a.jsx)(P.default,{remarkPlugins:me,components:pe,children:e}),xe=({attachment:e,isUser:r})=>{const t=R.safeAttachmentUrl(e.url);if(R.canInlineImage(e))return(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,a.jsx)("img",{src:t,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const o=R.formatFileSize(e.fileSize),n=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,a.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,a.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),o&&(0,a.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:o})]})]}),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:n}):(0,a.jsx)("div",{style:l,children:n})},he=({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})]}),o={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,a.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:o,onMouseEnter:n=>{n.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:n=>{n.currentTarget.style.borderColor="#dee3e8"},children:t}):(0,a.jsx)("div",{style:o,children:t})},ye=()=>(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:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,a.jsx)("style",{children:`
3
3
  @keyframes ago-pulse {
4
4
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
5
5
  40% { opacity: 1; transform: scale(1); }
6
6
  }
7
- `})]}),$=({message:e,className:t="",showAgentName:r=!1,isLast:n=!1,onFollowUpClick:a})=>{const l=e.role==="user",d=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&r&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((c,g)=>(0,o.jsx)(ge,{source:c,index:g},c.id))}),e.attachments&&e.attachments.length>0&&(0,o.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:l?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(c=>(0,o.jsx)(fe,{attachment:c,isUser:l},c.id))}),(e.content||d)&&(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(O,{content:e.content}):d&&(0,o.jsx)(pe,{})}),n&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,g)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:f=>{f.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:f=>{f.currentTarget.style.borderColor="#dee3e8"},children:c},g))})]})},xe=({client:e,conversationId:t,title:r="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:d=500,logoUrl:c,showAgentName:g=!1,forms:f,onFollowUpClick:b,className:C="",onMessageSent:j,onMessageReceived:h})=>{const y=(0,s.useRef)(null),S=N(),k=e??S,{messages:i,isLoading:v,error:u,sendMessage:p}=L({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!k||!f||f.length===0)return;let w=!1;const A=[];return Promise.all(f.map(E=>E.schema!=null?Promise.resolve(I.createFormCollector(E)):I.loadFormCollector(k,E))).then(E=>{if(!w)for(const U of E)A.push(U.install(k))}).catch(()=>{}),()=>{w=!0,A.forEach(E=>E())}},[k,f?JSON.stringify(f.map(w=>[w.name,w.schema??null,w.submit??!1,w.description??null])):""]),(0,s.useEffect)(()=>{y.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,s.useEffect)(()=>{const w=i[i.length-1];w&&w.role==="assistant"&&w.status==="DONE"&&h&&h({id:w.id,content:w.content})},[i,h]);const m=async(w,A)=>{j?.(w),await p(w,A)},x=i[i.length-1],_=v&&x?.role==="assistant"&&(x.status==="IN_PROGRESS"||x.status==="WAITING_CLIENT"),K=b===!1?void 0:b??(w=>m(w));return(0,o.jsxs)("div",{className:`ago-chat-widget ${C}`,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[c&&(0,o.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:r})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[i.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:n}):i.map((w,A)=>(0,o.jsx)($,{message:w,showAgentName:g,isLast:A===i.length-1,onFollowUpClick:K},w.id)),u&&(0,o.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:u.message}),(0,o.jsx)("div",{ref:y})]}),(0,o.jsx)(H,{onSend:m,disabled:_,placeholder:a,allowFiles:l})]})};function B({client:e,autoLoad:t=!0}={}){const r=N(),n=e||r;if(!n)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[g,f]=(0,s.useState)(!1),[b,C]=(0,s.useState)(null),j=(0,s.useCallback)(async()=>{f(!0),C(null);try{l(await n.getConversations())}catch(S){C(S instanceof Error?S:new Error("Failed to load conversations"))}finally{f(!1)}},[n]),h=(0,s.useCallback)(async S=>{f(!0),C(null);try{c(await n.getConversation(S))}catch(k){C(k instanceof Error?k:new Error("Failed to load conversation"))}finally{f(!1)}},[n]),y=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&j()},[t,j]),{conversations:a,currentConversation:d,isLoading:g,error:b,selectConversation:h,startNewConversation:y,refreshConversations:j}}function me(e={}){const t=N(),r=e.client||t;if(!r)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const n=L({client:r,conversationId:e.conversationId}),a=B({client:r,autoLoad:e.autoLoad});return{messages:n.messages,isLoading:n.isLoading,error:n.error||a.error,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function he(e,t){const r=M(),{name:n,description:a,parameters:l,handler:d,maxResultBytes:c}=typeof e=="string"?{name:e,...t}:e,g=(0,s.useRef)(d);g.current=d,(0,s.useEffect)(()=>{const f=b=>g.current(b);return r.registerFunction(n,f,{description:a,parameters:l,maxResultBytes:c}),()=>{r.unregisterFunction(n)}},[r,n,a,l,c])}function ye(e,t){const r=M(),n=(0,s.useRef)(e);n.current=e,(0,s.useEffect)(()=>(r.registerNavigationFunction(a=>n.current(a),t),()=>{r.unregisterNavigationFunction()}),[r,t])}function be(e,t){const r=M(),n=t?.functionName??"setPageState",a=(0,s.useRef)(e);a.current=e,(0,s.useEffect)(()=>{const l=a.current.map(d=>{const c=()=>a.current.find(g=>g.name===d.name)??d;return{name:d.name,description:d.description,schema:d.schema,get:d.get?()=>c().get?.():void 0,set:g=>c().set(g)}});return r.registerPageStateFunction(l,{functionName:n}),()=>{r.unregisterPageStateFunction(n)}},[r,n])}function ve(e){const t=M(),r=(0,s.useRef)(e);r.current=e,(0,s.useEffect)(()=>J.attachAutoContinueAfterNavigation(t,()=>r.current),[t])}function Ce(e,t){const r=M(),n=(0,s.useId)(),a=t??n,l=(0,s.useRef)(e);l.current=e;const d=typeof e=="function";(0,s.useEffect)(()=>{if(typeof l.current=="function"){const c=()=>l.current();return r.addDynamicContext(a,c),()=>{r.removeDynamicContext(a)}}return r.setContext(a,l.current),()=>{r.removeContext(a)}},[r,a,d,d?"":JSON.stringify(e)])}function G(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var D={missing:[],complete:!1};function we(e){const t=M(),r=e.schema!=null,n=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",d=JSON.stringify(e.initialValues??null),c=(0,s.useMemo)(()=>r?I.createFormCollector(e):null,[r,e.name,n,l,d,e.autoSubmit]),[g,f]=(0,s.useState)({collector:null,loading:!r,error:null});(0,s.useEffect)(()=>{if(r)return;let v=!1;return f({collector:null,loading:!0,error:null}),I.loadFormCollector(t,e).then(u=>{v||f({collector:u,loading:!1,error:null})}).catch(u=>{v||f({collector:null,loading:!1,error:u instanceof Error?u:new Error(String(u))})}),()=>{v=!0}},[t,r,e.name,l,d,e.autoSubmit]);const b=r?c:g.collector,C=r?!1:g.loading,j=r?null:g.error;(0,s.useEffect)(()=>{if(b)return b.install(t)},[t,b]);const h=(0,s.useMemo)(()=>I.createStore({values:e.initialValues??{},submitted:!1}),[d]),y=G(b?.store??h),S=(0,s.useMemo)(()=>b?.getStatus()??D,[y,b]),k=(0,s.useMemo)(()=>({...y,...S}),[y,S]),i=(0,s.useMemo)(()=>({name:e.name,store:h,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>h.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>D}),[e.name,h]);return{...b??i,state:k,loading:C,error:j}}exports.AgoProvider=Y;exports.ChatInput=H;exports.ChatWidget=xe;exports.Markdown=O;exports.Message=$;exports.createFormCollector=I.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=I.deriveFormStatus;exports.loadFormCollector=I.loadFormCollector;exports.useAgo=q;exports.useAgoAutoContinueAfterNavigation=ve;exports.useAgoClient=M;exports.useAgoContext=Ce;exports.useAgoFunction=he;exports.useAgoNavigation=ye;exports.useAgoPageState=be;exports.useAgoStore=G;exports.useChat=me;exports.useConversation=B;exports.useFormCollector=we;exports.useMessages=L;exports.useOptionalAgoClient=N;
7
+ `})]}),G=({message:e,className:r="",showAgentName:t=!1,isLast:o=!1,onFollowUpClick:n})=>{const l=e.role==="user",u=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:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&t&&e.agent&&(0,a.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,a.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((i,g)=>(0,a.jsx)(he,{source:i,index:g},i.id))}),e.attachments&&e.attachments.length>0&&(0,a.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:l?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(i=>(0,a.jsx)(xe,{attachment:i,isUser:l},i.id))}),(e.content||u)&&(0,a.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,a.jsx)(U,{content:e.content}):u&&(0,a.jsx)(ye,{})}),o&&e.followUpReplies&&e.followUpReplies.length>0&&(0,a.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((i,g)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!n,onClick:n?()=>n(i):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:n?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:d=>{d.currentTarget.style.borderColor="#dee3e8"},children:i},g))})]})},be=({client:e,conversationId:r,title:t="Chat",welcomeMessage:o="Hello! How can I help you today?",placeholder:n="Type a message...",allowFiles:l=!1,height:u=500,logoUrl:i,showAgentName:g=!1,forms:d,onFollowUpClick:m,className:S="",onMessageSent:I,onMessageReceived:k})=>{const A=(0,s.useRef)(null),p=F(),h=e??p,{messages:c,isLoading:v,error:f,sendMessage:y}=z({client:e,conversationId:r});(0,s.useEffect)(()=>{if(!h||!d||d.length===0)return;let x=!1;const j=[];return Promise.all(d.map(N=>N.schema!=null?Promise.resolve(_.createFormCollector(N)):_.loadFormCollector(h,N))).then(N=>{if(!x)for(const X of N)j.push(X.install(h))}).catch(()=>{}),()=>{x=!0,j.forEach(N=>N())}},[h,d?JSON.stringify(d.map(x=>[x.name,x.schema??null,x.submit??!1,x.description??null])):""]),(0,s.useEffect)(()=>{A.current?.scrollIntoView({behavior:"smooth"})},[c]),(0,s.useEffect)(()=>{const x=c[c.length-1];x&&x.role==="assistant"&&x.status==="DONE"&&k&&k({id:x.id,content:x.content})},[c,k]);const w=async(x,j)=>{I?.(x),await y(x,j)},C=c[c.length-1],E=v&&C?.role==="assistant"&&(C.status==="IN_PROGRESS"||C.status==="WAITING_CLIENT"),b=m===!1?void 0:m??(x=>w(x));return(0,a.jsxs)("div",{className:`ago-chat-widget ${S}`,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,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:[i&&(0,a.jsx)("img",{src:i,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,a.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:t})]}),(0,a.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[c.length===0?(0,a.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:o}):c.map((x,j)=>(0,a.jsx)(G,{message:x,showAgentName:g,isLast:j===c.length-1,onFollowUpClick:b},x.id)),f&&(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:f.message}),(0,a.jsx)("div",{ref:A})]}),(0,a.jsx)(B,{onSend:w,disabled:E,placeholder:n,allowFiles:l})]})};function K(e={}){const r=F(),t=e.client??r;if(!t)throw new R.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[o,n]=(0,s.useState)(null),l=(0,s.useRef)(o);l.current=o;const u=(0,s.useRef)(e.onExpand);return u.current=e.onExpand,(0,s.useEffect)(()=>{const i=d=>{n(d),t.proactive?.shown(d)},g=({nudge:d})=>{n(m=>m?.id===d.id?null:m)};return t.on("nudge:ready",i),t.on("nudge:accepted",g),t.on("nudge:dismissed",g),()=>{t.off("nudge:ready",i),t.off("nudge:accepted",g),t.off("nudge:dismissed",g)}},[t]),{nudge:o,accept:(0,s.useCallback)(async()=>{const i=l.current;i&&(n(null),await t.proactive?.accept(i),(i.source==="agent"||i.goal)&&u.current?.(i))},[t]),dismiss:(0,s.useCallback)(()=>{const i=l.current;i&&(n(null),t.proactive?.dismiss(i))},[t])}}var ve=({client:e,onExpand:r,autoHideMs:t,position:o="bottom-right",openChatLabel:n="Open chat",className:l=""})=>{const{nudge:u,accept:i,dismiss:g}=K({client:e,onExpand:r});if((0,s.useEffect)(()=>{if(!u||!t)return;const m=setTimeout(()=>g(),t);return()=>clearTimeout(m)},[u,t,g]),!u)return null;const d=u.source==="agent"||!!u.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${l}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...o==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,a.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:g,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:u.message}),(u.action||d)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[u.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:u.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:n})]})]})};function J({client:e,autoLoad:r=!0}={}){const t=F(),o=e||t;if(!o)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[n,l]=(0,s.useState)([]),[u,i]=(0,s.useState)(null),[g,d]=(0,s.useState)(!1),[m,S]=(0,s.useState)(null),I=(0,s.useCallback)(async()=>{d(!0),S(null);try{l(await o.getConversations())}catch(p){S(p instanceof Error?p:new Error("Failed to load conversations"))}finally{d(!1)}},[o]),k=(0,s.useCallback)(async p=>{d(!0),S(null);try{i(await o.getConversation(p))}catch(h){S(h instanceof Error?h:new Error("Failed to load conversation"))}finally{d(!1)}},[o]),A=(0,s.useCallback)(()=>{i(null)},[]);return(0,s.useEffect)(()=>{r&&I()},[r,I]),{conversations:n,currentConversation:u,isLoading:g,error:m,selectConversation:k,startNewConversation:A,refreshConversations:I}}function Ce(e={}){const r=F(),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 o=z({client:t,conversationId:e.conversationId}),n=J({client:t,autoLoad:e.autoLoad});return{messages:o.messages,isLoading:o.isLoading,error:o.error||n.error,sendMessage:o.sendMessage,clearMessages:o.clearMessages,conversationId:o.conversationId,conversations:n.conversations,currentConversation:n.currentConversation,isConversationsLoading:n.isLoading,selectConversation:n.selectConversation,startNewConversation:n.startNewConversation,refreshConversations:n.refreshConversations}}function we(e,r){const t=M(),{name:o,description:n,parameters:l,handler:u,maxResultBytes:i,requiresApproval:g}=typeof e=="string"?{name:e,...r}:e,d=(0,s.useRef)(u);d.current=u,(0,s.useEffect)(()=>{const m=S=>d.current(S);return t.registerFunction(o,m,{description:n,parameters:l,maxResultBytes:i,requiresApproval:g}),()=>{t.unregisterFunction(o)}},[t,o,n,l,i,g])}function Se(e,r){const t=M(),o=(0,s.useRef)(e);o.current=e,(0,s.useEffect)(()=>(t.registerNavigationFunction(n=>o.current(n),r),()=>{t.unregisterNavigationFunction()}),[t,r])}function ke(e,r){const t=M(),o=r?.functionName??"setPageState",n=r?.requiresApproval,l=(0,s.useRef)(e);l.current=e,(0,s.useEffect)(()=>{const u=l.current.map(i=>{const g=()=>l.current.find(d=>d.name===i.name)??i;return{name:i.name,description:i.description,schema:i.schema,get:i.get?()=>g().get?.():void 0,set:d=>g().set(d)}});return t.registerPageStateFunction(u,{functionName:o,requiresApproval:n}),()=>{t.unregisterPageStateFunction(o)}},[t,o,n])}function Ae(e){const r=M(),t=(0,s.useRef)(e);t.current=e,(0,s.useEffect)(()=>Z.attachAutoContinueAfterNavigation(r,()=>t.current),[r])}var je=new Set(["awaiting-approval"]);function V(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 Ie(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":V(e.type)}function L(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 $(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 Ne(e){switch(e.kind){case"navigation":return`Navigating to ${$(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||$(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function Ee(e={}){const{includeReasoning:r=!1,labelFor:t}=e,o=F(),n=e.client||o;if(!n)throw new R.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[l,u]=(0,s.useState)([]),i=(0,s.useRef)(new Set),g=(0,s.useRef)(void 0),d=(0,s.useRef)(t);d.current=t;const m=(0,s.useCallback)((p,h)=>{u(c=>{const v=c.findIndex(y=>y.id===p),f={...v>=0?c[v]:{id:p,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...h};return f.label=d.current?.(f)??Ne(f),v>=0?[...c.slice(0,v),f,...c.slice(v+1)]:[...c,f]})},[]);(0,s.useEffect)(()=>{const p=b=>{g.current=b.messageId},h=b=>{const x=V(b.type);x==="reasoning"&&!r||m(b.id,{kind:x,status:L(b.status,x),messageId:g.current,toolName:b.toolName,toolDisplayName:b.toolDisplayName,message:b.message,data:b.data,formSchema:b.formSchema,requiresApproval:x==="confirmation"||x==="form"})},c=b=>{b.invocationId&&m(b.invocationId,{kind:b.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:g.current,functionName:b.functionName,arguments:b.arguments})},v=b=>{b.invocationId&&m(b.invocationId,{kind:b.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:g.current,functionName:b.functionName,arguments:b.arguments,requiresApproval:!0})},f=b=>{if(!b.invocationId)return;const x=b.result,j=typeof b.result=="object"&&x!==null&&x.approved===!1&&x.reason==="user_rejected";m(b.invocationId,{status:b.error?"error":j?"rejected":"done",requiresApproval:!1})},y=b=>{for(const x of b.messages??[])if(x.role==="assistant")for(const j of x.toolCalls??[]){const N=Ie(j);N==="reasoning"&&!r||/waiting/i.test(j.status??"")||m(j.id,{kind:N,status:L(j.status,N),messageId:x.id,toolName:j.toolName,toolDisplayName:j.toolDisplayName,functionName:j.functionName,arguments:j.arguments,message:j.message,data:j.data,formSchema:j.formSchema,requiresApproval:N==="confirmation"||N==="form"})}},w=b=>{u(x=>x.map(j=>j.status==="running"||j.status==="awaiting-approval"?{...j,status:b}:j))},C=()=>w("done"),E=()=>w("error");return n.on("message:start",p),n.on("toolCall:received",h),n.on("function:invoke",c),n.on("function:awaiting-approval",v),n.on("function:result",f),n.on("conversation:loaded",y),n.on("message:complete",C),n.on("message:error",E),()=>{n.off("message:start",p),n.off("toolCall:received",h),n.off("function:invoke",c),n.off("function:awaiting-approval",v),n.off("function:result",f),n.off("conversation:loaded",y),n.off("message:complete",C),n.off("message:error",E)}},[n,r,m]);const S=(0,s.useCallback)(async p=>{const h=l.find(c=>c.id===p);!h||h.status!=="awaiting-approval"||i.current.has(p)||h.kind!=="form"&&(i.current.add(p),m(p,{status:"running",requiresApproval:!1}),h.functionName?await n.approveFunction(p):await n.confirmToolCall(p))},[n,l,m]),I=(0,s.useCallback)(async p=>{const h=l.find(c=>c.id===p);!h||h.status!=="awaiting-approval"||i.current.has(p)||(i.current.add(p),m(p,{status:"rejected",requiresApproval:!1}),h.functionName?await n.rejectFunction(p):await n.rejectToolCall(p))},[n,l,m]),k=(0,s.useCallback)(async(p,h)=>{m(p,{status:"running",requiresApproval:!1}),await n.submitToolCallForm(p,h),m(p,{status:"done"})},[n,m]),A=(0,s.useCallback)(()=>{i.current.clear(),u([])},[]);return{items:l,latest:l.length>0?l[l.length-1]:void 0,isAwaitingApproval:l.some(p=>je.has(p.status)),approve:S,reject:I,submitForm:k,clear:A}}function Re(e,r){const t=M(),o=(0,s.useId)(),n=r??o,l=(0,s.useRef)(e);l.current=e;const u=typeof e=="function";(0,s.useEffect)(()=>{if(typeof l.current=="function"){const i=()=>l.current();return t.addDynamicContext(n,i),()=>{t.removeDynamicContext(n)}}return t.setContext(n,l.current),()=>{t.removeContext(n)}},[t,n,u,u?"":JSON.stringify(e)])}function Y(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var H={missing:[],complete:!1};function _e(e){const r=M(),t=e.schema!=null,o=JSON.stringify(e.schema??null),n=e.submit,l=n?typeof n=="string"?`client:${n}`:n.via==="backend"?"backend":"handler"in n?"client:handler":`client:${n.url}`:"none",u=JSON.stringify(e.initialValues??null),i=(0,s.useMemo)(()=>t?_.createFormCollector(e):null,[t,e.name,o,l,u,e.autoSubmit]),[g,d]=(0,s.useState)({collector:null,loading:!t,error:null});(0,s.useEffect)(()=>{if(t)return;let v=!1;return d({collector:null,loading:!0,error:null}),_.loadFormCollector(r,e).then(f=>{v||d({collector:f,loading:!1,error:null})}).catch(f=>{v||d({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{v=!0}},[r,t,e.name,l,u,e.autoSubmit]);const m=t?i:g.collector,S=t?!1:g.loading,I=t?null:g.error;(0,s.useEffect)(()=>{if(m)return m.install(r)},[r,m]);const k=(0,s.useMemo)(()=>R.createStore({values:e.initialValues??{},submitted:!1}),[u]),A=Y(m?.store??k),p=(0,s.useMemo)(()=>m?.getStatus()??H,[A,m]),h=(0,s.useMemo)(()=>({...A,...p}),[A,p]),c=(0,s.useMemo)(()=>({name:e.name,store:k,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>k.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>H}),[e.name,k]);return{...m??c,state:h,loading:S,error:I}}exports.AgoNudge=ve;exports.AgoProvider=ee;exports.ChatInput=B;exports.ChatWidget=be;exports.Markdown=U;exports.Message=G;exports.createFormCollector=_.createFormCollector;exports.createMockClient=Q.createMockClient;exports.deriveFormStatus=_.deriveFormStatus;exports.loadFormCollector=_.loadFormCollector;exports.useAgo=O;exports.useAgoActivity=Ee;exports.useAgoAutoContinueAfterNavigation=Ae;exports.useAgoClient=M;exports.useAgoContext=Re;exports.useAgoFunction=we;exports.useAgoNavigation=Se;exports.useAgoPageState=ke;exports.useAgoStore=Y;exports.useChat=Ce;exports.useConversation=J;exports.useFormCollector=_e;exports.useMessages=z;exports.useOptionalAgoClient=F;exports.useProactiveNudge=K;