@useago/sdk 1.5.2 → 1.5.4

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