@useago/sdk 1.9.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +53 -0
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +313 -0
  5. package/dist/angular.d.ts +313 -0
  6. package/dist/angular.js +1 -1
  7. package/dist/{createConversationSession-BaaXBQ5b.js → createConversationSession-B1Qn-y0I.js} +1 -1
  8. package/dist/{createConversationSession-CU0b-t1W.cjs → createConversationSession-B3v_xOU7.cjs} +1 -1
  9. package/dist/{createFormCollector-DfN1xZBy.cjs → createFormCollector-FvwDOqnV.cjs} +1 -1
  10. package/dist/{createFormCollector-Cf7kGhCB.js → createFormCollector-m79zk_NA.js} +1 -1
  11. package/dist/createMockClient-BEOXI8yW.cjs +1 -0
  12. package/dist/{createMockClient-5YF-ZbVu.js → createMockClient-Beao82tu.js} +15 -3
  13. package/dist/devtools.d.cts +313 -0
  14. package/dist/devtools.d.ts +313 -0
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.d.cts +389 -4
  17. package/dist/index.d.ts +389 -4
  18. package/dist/index.js +118 -114
  19. package/dist/react.cjs +1 -1
  20. package/dist/react.d.cts +313 -0
  21. package/dist/react.d.ts +313 -0
  22. package/dist/react.js +8 -6
  23. package/dist/sheetController-BThJRtOu.cjs +1 -0
  24. package/dist/sheetController-aEKXIvjk.js +343 -0
  25. package/dist/testing.cjs +1 -1
  26. package/dist/testing.d.cts +313 -0
  27. package/dist/testing.d.ts +313 -0
  28. package/dist/testing.js +1 -1
  29. package/dist/types-Ct1hlKwg.js +2408 -0
  30. package/dist/types-mcW8vB1U.cjs +10 -0
  31. package/dist/vue.cjs +1 -1
  32. package/dist/vue.d.cts +505 -0
  33. package/dist/vue.d.ts +505 -0
  34. package/dist/vue.js +1 -1
  35. package/dist/widget.cjs +6 -4
  36. package/dist/widget.d.cts +585 -2
  37. package/dist/widget.d.ts +585 -2
  38. package/dist/widget.js +3985 -995
  39. package/llms-full.txt +125 -6
  40. package/package.json +1 -1
  41. package/dist/createMockClient-BZbOe-23.cjs +0 -1
  42. package/dist/sheetController-CBUVOroo.js +0 -205
  43. package/dist/sheetController-DY-sC13T.cjs +0 -1
  44. package/dist/types-CPga11Of.js +0 -2068
  45. package/dist/types-D3YQl1jx.cjs +0 -9
package/dist/index.js CHANGED
@@ -1,170 +1,174 @@
1
- import { a as w, c as C, d as E, f as y, i as S, l as b, m as v, o as F, p as I, r as M, s as T, t as _, u as U } from "./functions-tzyOZNp6.js";
2
- import { _ as N, b as D, c as L, d as O, f as R, g as x, h as G, i as q, l as P, m as B, n as c, o as H, p as J, r as j, s as z, t as K, u as V, v as W, x as X, y as Y } from "./types-CPga11Of.js";
3
- import { a as Q, i as Z, n as p, r as ee, t as oe } from "./errors-BLfjXnLB.js";
4
- import { t as re } from "./autoContinue-CC8K9mBU.js";
5
- import { t as ne } from "./createConversationSession-BaaXBQ5b.js";
6
- import { n as ie, r as ue, t as ge } from "./createFormCollector-Cf7kGhCB.js";
7
- import { t as fe } from "./createMockClient-5YF-ZbVu.js";
1
+ import { a as w, c as E, d as C, f as S, i as y, l as b, m as v, o as F, p as _, r as M, s as T, t as R, u as I } from "./functions-tzyOZNp6.js";
2
+ import { C as D, S as L, _ as O, b as k, c as N, d as G, f as x, g as q, h as P, i as X, l as B, m as H, n as c, o as J, p as W, r as j, s as z, t as K, u as V, v as Y, w as $, x as Q, y as Z } from "./types-Ct1hlKwg.js";
3
+ import { a as te, i as oe, n as p, r as ae, t as re } from "./errors-BLfjXnLB.js";
4
+ import { t as ne } from "./autoContinue-CC8K9mBU.js";
5
+ import { t as ue } from "./createConversationSession-B1Qn-y0I.js";
6
+ import { n as me, r as fe, t as de } from "./createFormCollector-m79zk_NA.js";
7
+ import { t as ce } from "./createMockClient-Beao82tu.js";
8
8
  import "./testing.js";
9
- function de(e) {
9
+ function Ae(e) {
10
10
  return e;
11
11
  }
12
- function ce(e, o) {
13
- return e.on("message:complete", o), () => e.off("message:complete", o);
12
+ function he(e, t) {
13
+ return e.on("message:complete", t), () => e.off("message:complete", t);
14
14
  }
15
- function pe(e, o) {
16
- return e.on("message:chunk", o), () => e.off("message:chunk", o);
15
+ function we(e, t) {
16
+ return e.on("message:chunk", t), () => e.off("message:chunk", t);
17
17
  }
18
- function Ae(e, o) {
19
- return e.on("message:start", o), () => e.off("message:start", o);
18
+ function Ee(e, t) {
19
+ return e.on("message:start", t), () => e.off("message:start", t);
20
20
  }
21
- function he(e, o) {
22
- return e.on("message:error", o), () => e.off("message:error", o);
21
+ function Ce(e, t) {
22
+ return e.on("message:error", t), () => e.off("message:error", t);
23
23
  }
24
- function we(e, o) {
25
- return e.on("toolCall:received", o), () => e.off("toolCall:received", o);
24
+ function Se(e, t) {
25
+ return e.on("toolCall:received", t), () => e.off("toolCall:received", t);
26
26
  }
27
- function Ce(e, o) {
28
- return e.on("form:submitted", o), () => e.off("form:submitted", o);
27
+ function ye(e, t) {
28
+ return e.on("form:submitted", t), () => e.off("form:submitted", t);
29
29
  }
30
- function Ee(e, o) {
31
- return e.on("form:error", o), () => e.off("form:error", o);
30
+ function be(e, t) {
31
+ return e.on("form:error", t), () => e.off("form:error", t);
32
32
  }
33
- function ye(e, o) {
34
- return e.on("function:invoke", o), () => e.off("function:invoke", o);
33
+ function ve(e, t) {
34
+ return e.on("function:invoke", t), () => e.off("function:invoke", t);
35
35
  }
36
- async function* Se(e, o, u) {
37
- const n = [];
38
- let r = null, a = !1;
39
- const g = (s) => {
40
- n.push(s), r?.();
41
- }, m = (s) => g({
36
+ async function* Fe(e, t, u) {
37
+ const s = [];
38
+ let a = null, r = !1;
39
+ const g = (n) => {
40
+ s.push(n), a?.();
41
+ }, m = (n) => g({
42
42
  type: "start",
43
- data: s
44
- }), t = (s) => g({
43
+ data: n
44
+ }), f = (n) => g({
45
45
  type: "chunk",
46
- data: s
47
- }), i = (s) => {
46
+ data: n
47
+ }), o = (n) => {
48
48
  g({
49
49
  type: "complete",
50
- data: s
51
- }), a = !0, r?.();
52
- }, f = (s) => {
50
+ data: n
51
+ }), r = !0, a?.();
52
+ }, i = (n) => {
53
53
  g({
54
54
  type: "error",
55
- data: s
56
- }), a = !0, r?.();
57
- }, l = (s) => g({
55
+ data: n
56
+ }), r = !0, a?.();
57
+ }, d = (n) => g({
58
58
  type: "toolCall",
59
- data: s
60
- }), d = () => {
61
- a = !0, r?.();
59
+ data: n
60
+ }), l = () => {
61
+ r = !0, a?.();
62
62
  };
63
- e.on("message:start", m), e.on("message:chunk", t), e.on("message:complete", i), e.on("message:error", f), e.on("message:stopped", d), e.on("toolCall:received", l), e.sendMessage(o, u).catch(() => {
64
- a = !0, r?.();
63
+ e.on("message:start", m), e.on("message:chunk", f), e.on("message:complete", o), e.on("message:error", i), e.on("message:stopped", l), e.on("toolCall:received", d), e.sendMessage(t, u).catch(() => {
64
+ r = !0, a?.();
65
65
  });
66
66
  try {
67
- for (; !a || n.length > 0; ) n.length > 0 ? yield n.shift() : (await new Promise((s) => {
68
- r = s;
69
- }), r = null);
67
+ for (; !r || s.length > 0; ) s.length > 0 ? yield s.shift() : (await new Promise((n) => {
68
+ a = n;
69
+ }), a = null);
70
70
  } finally {
71
- e.off("message:start", m), e.off("message:chunk", t), e.off("message:complete", i), e.off("message:error", f), e.off("message:stopped", d), e.off("toolCall:received", l);
71
+ e.off("message:start", m), e.off("message:chunk", f), e.off("message:complete", o), e.off("message:error", i), e.off("message:stopped", l), e.off("toolCall:received", d);
72
72
  }
73
73
  }
74
74
  function A(e) {
75
- let o, u, n, r, a, g;
75
+ let t, u, s, a, r, g, m;
76
76
  if (typeof window < "u" && window.AGO) {
77
- const t = window.AGO;
78
- o = t.basepath, u = t.widgetId, n = t.agent || t.defaultAgent, r = t.permission, a = t.email, g = t.jwt;
77
+ const o = window.AGO;
78
+ t = o.basepath, u = o.widgetId, s = o.agent || o.defaultAgent, a = o.permission, r = o.email, g = o.jwt, m = o.metadata;
79
79
  }
80
80
  if (typeof document < "u") {
81
- const t = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
82
- 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");
81
+ const o = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
82
+ t = t || o("ago-base-url"), u = u || o("ago-widget-id"), s = s || o("ago-agent") || o("ago-agent-id"), a = a || o("ago-permission"), r = r || o("ago-user-email");
83
83
  }
84
84
  if (typeof document < "u") {
85
- const t = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
86
- for (const i of t)
87
- 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);
85
+ const o = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
86
+ for (const i of o)
87
+ i && (t = t || i.getAttribute("data-ago-base-url") || void 0, u = u || i.getAttribute("data-ago-widget-id") || void 0, s = s || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, a = a || i.getAttribute("data-ago-permission") || void 0, r = r || i.getAttribute("data-ago-user-email") || void 0);
88
88
  }
89
- 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;
90
- const m = e?.debug;
91
- return o ? {
92
- baseUrl: o,
89
+ t = e?.baseUrl || t, u = e?.widgetId || u, s = e?.agent || e?.defaultAgentId || s, a = e?.permission || a, r = e?.userEmail || r, g = e?.userJwt || g, e?.metadata !== void 0 && (m = e.metadata);
90
+ const f = e?.debug;
91
+ return t ? {
92
+ baseUrl: t,
93
93
  widgetId: u,
94
- agent: n,
95
- permission: r,
96
- userEmail: a,
94
+ agent: s,
95
+ permission: a,
96
+ userEmail: r,
97
97
  userJwt: g,
98
- debug: m
98
+ metadata: m,
99
+ debug: f
99
100
  } : null;
100
101
  }
101
- function be(e) {
102
- const o = A(e);
103
- if (!o) throw new p('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.', "config_missing_base_url");
104
- return new c(o);
102
+ function _e(e) {
103
+ const t = A(e);
104
+ if (!t) throw new p('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.', "config_missing_base_url");
105
+ return new c(t);
105
106
  }
106
- function ve(e, o) {
107
+ function Me(e, t) {
107
108
  return {
108
109
  ...e,
109
- handler: o
110
+ handler: t
110
111
  };
111
112
  }
112
113
  export {
113
114
  D as ActivityLedger,
114
- oe as AgoApiError,
115
+ re as AgoApiError,
115
116
  c as AgoClient,
116
117
  p as AgoError,
117
- ee as AgoFunctionError,
118
- Z as AgoNetworkError,
119
- Q as AgoStreamError,
120
- O as ClientContextRegistry,
121
- X as DEFAULT_MAX_ACTIVITY_ENTRIES,
122
- q as EventEmitter,
118
+ ae as AgoFunctionError,
119
+ oe as AgoNetworkError,
120
+ te as AgoStreamError,
121
+ G as ClientContextRegistry,
122
+ $ as DEFAULT_MAX_ACTIVITY_ENTRIES,
123
+ Z as DEFAULT_MAX_ERRORS,
124
+ k as DEFAULT_MAX_ERROR_AGE_MS,
125
+ Q as ErrorWatcher,
126
+ X as EventEmitter,
123
127
  K as FEEDBACK_REASONS,
124
- W as FunctionRegistry,
125
- P as SSEHandler,
126
- N as SignalCollector,
127
- re as attachAutoContinueAfterNavigation,
128
+ Y as FunctionRegistry,
129
+ B as SSEHandler,
130
+ O as SignalCollector,
131
+ ne as attachAutoContinueAfterNavigation,
128
132
  A as autoDetectConfig,
129
- H as canInlineImage,
130
- _ as copyToClipboard,
131
- be as createAgo,
132
- R as createAgoProactive,
133
- ne as createConversationSession,
134
- ge as createFormCollector,
135
- Se as createMessageStream,
136
- fe as createMockClient,
137
- x as createStore,
138
- de as defineFunction,
139
- ie as deriveFormStatus,
133
+ J as canInlineImage,
134
+ R as copyToClipboard,
135
+ _e as createAgo,
136
+ x as createAgoProactive,
137
+ ue as createConversationSession,
138
+ de as createFormCollector,
139
+ Fe as createMessageStream,
140
+ ce as createMockClient,
141
+ q as createStore,
142
+ Ae as defineFunction,
143
+ me as deriveFormStatus,
140
144
  z as formatFileSize,
141
145
  M as getLocalStorage,
142
- S as getUserLocation,
146
+ y as getUserLocation,
143
147
  w as highlightElement,
144
148
  V as isStreamNetworkError,
145
- ue as loadFormCollector,
146
- Y as logger,
147
- J as matchesRoutePattern,
148
- B as matchesWhen,
149
- Ee as onFormError,
150
- Ce as onFormSubmitted,
151
- ye as onFunctionInvoke,
152
- ce as onMessage,
153
- pe as onMessageChunk,
154
- he as onMessageError,
155
- Ae as onMessageStart,
156
- we as onToolCall,
149
+ fe as loadFormCollector,
150
+ L as logger,
151
+ W as matchesRoutePattern,
152
+ H as matchesWhen,
153
+ be as onFormError,
154
+ ye as onFormSubmitted,
155
+ ve as onFunctionInvoke,
156
+ he as onMessage,
157
+ we as onMessageChunk,
158
+ Ce as onMessageError,
159
+ Ee as onMessageStart,
160
+ Se as onToolCall,
157
161
  F as openUrl,
158
- G as partialDeepMatch,
159
- L as safeAttachmentUrl,
162
+ P as partialDeepMatch,
163
+ N as safeAttachmentUrl,
160
164
  T as scrollToElement,
161
- C as setLocalStorage,
165
+ E as setLocalStorage,
162
166
  b as setTheme,
163
- U as showConfirmDialog,
164
- E as showNotification,
165
- y as showToast,
166
- I as submitForm,
167
+ I as showConfirmDialog,
168
+ C as showNotification,
169
+ S as showToast,
170
+ _ as submitForm,
167
171
  v as trackEvent,
168
172
  j as validateConfig,
169
- ve as withHandler
173
+ Me as withHandler
170
174
  };
package/dist/react.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var He=Object.create,J=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Be=Object.getOwnPropertyNames,$e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty,Ue=(e,n)=>{let t={};for(var s in e)J(t,s,{get:e[s],enumerable:!0});return n||J(t,Symbol.toStringTag,{value:"Module"}),t},Ge=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(var r=Be(n),c=0,l=r.length,i;c<l;c++)i=r[c],!Ke.call(e,i)&&i!==t&&J(e,i,{get:(d=>n[d]).bind(null,i),enumerable:!(s=qe(n,i))||s.enumerable});return e},ne=(e,n,t)=>(t=e!=null?He($e(e)):{},Ge(n||!e||!e.__esModule?J(t,"default",{value:e,enumerable:!0}):t,e));const D=require("./types-D3YQl1jx.cjs"),V=require("./errors-o1IB5fEu.cjs"),Je=require("./autoContinue-CP9pJR-V.cjs"),O=require("./createFormCollector-DfN1xZBy.cjs"),Ve=require("./createMockClient-BZbOe-23.cjs"),Z=require("./sheetController-DY-sC13T.cjs");let o=require("react");o=ne(o,1);let a=require("react/jsx-runtime"),Q=require("react-markdown");Q=ne(Q,1);let ee=require("remark-gfm");ee=ne(ee,1);function he(e){const[n,t]=(0,o.useState)(!1),s=(0,o.useRef)(null),r=(0,o.useMemo)(()=>{if(s.current&&(s.current.destroy(),s.current=null),!e)return null;const c=new D.AgoClient(e);return s.current=c,c},[e?.baseUrl,e?.widgetId]);return(0,o.useEffect)(()=>(r&&s.current===null&&(s.current=r,r.reviveAfterDestroy()),t(!0),()=>{s.current?.destroy(),s.current=null}),[r]),(0,o.useEffect)(()=>{s.current&&e&&s.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,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 re=(0,o.createContext)(null),Ye=({children:e,client:n,tools:t,helpers:s,pageContext:r,...c})=>{const{client:l}=he(n?null:c),i=n||l;return(0,o.useEffect)(()=>{if(!(!t||t.length===0)){for(const d of t)i.register(d);return()=>{for(const d of t)i.unregisterFunction(d.name)}}},[i,t]),(0,o.useEffect)(()=>{if(!s)return;const d=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(u=>u.functions_exports).then(u=>{for(const[p,C]of Object.entries(s)){const A=u[p];if(!A){console.warn(`[AGO] Unknown helper: "${p}"`);continue}const x=C===!0?A:{...A,handler:C};i.register(x),d.push(x.name)}}),()=>{for(const u of d)i.unregisterFunction(u)}},[i,s]),(0,o.useEffect)(()=>{r==="auto"&&i.enableAutoPageContext()},[i,r]),(0,a.jsx)(re.Provider,{value:i,children:e})};function L(){const e=(0,o.useContext)(re);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function W(){return(0,o.useContext)(re)}var Xe=new Set(["awaiting-approval"]);function be(e){switch(e){case"progress_indicator":return"progress";case"reasoning":return"reasoning";case"confirmation_input":return"confirmation";case"form":return"form";default:return"status"}}function Ze(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":be(e.type)}function fe(e,n){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(n==="confirmation"||n==="form")?"awaiting-approval":"running"}function pe(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase()).trim()}function Qe(e){switch(e.kind){case"navigation":return`Navigating to ${pe(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||pe(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function ye(e={}){const{includeReasoning:n=!1,labelFor:t}=e,s=W(),r=e.client||s;if(!r)throw new V.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[c,l]=(0,o.useState)([]),i=(0,o.useRef)(new Set),d=(0,o.useRef)(void 0),u=(0,o.useRef)(t);u.current=t;const p=(0,o.useCallback)((f,w)=>{l(b=>{const g=b.findIndex(v=>v.id===f),h={...g>=0?b[g]:{id:f,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...w};return h.label=u.current?.(h)??Qe(h),g>=0?[...b.slice(0,g),h,...b.slice(g+1)]:[...b,h]})},[]);(0,o.useEffect)(()=>{const f=k=>{d.current=k.messageId},w=k=>{const N=be(k.type);N==="reasoning"&&!n||p(k.id,{kind:N,status:fe(k.status,N),messageId:d.current,toolName:k.toolName,toolDisplayName:k.toolDisplayName,message:k.message,data:k.data,formSchema:k.formSchema,requiresApproval:N==="confirmation"||N==="form"})},b=k=>{k.invocationId&&p(k.invocationId,{kind:k.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:d.current,functionName:k.functionName,arguments:k.arguments})},g=k=>{k.invocationId&&p(k.invocationId,{kind:k.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:d.current,functionName:k.functionName,arguments:k.arguments,requiresApproval:!0})},h=k=>{if(!k.invocationId)return;const N=k.result,S=typeof k.result=="object"&&N!==null&&N.approved===!1&&N.reason==="user_rejected";p(k.invocationId,{status:k.error?"error":S?"rejected":"done",requiresApproval:!1})},v=k=>{for(const N of k.messages??[])if(N.role==="assistant")for(const S of N.toolCalls??[]){const _=Ze(S);_==="reasoning"&&!n||/waiting/i.test(S.status??"")||p(S.id,{kind:_,status:fe(S.status,_),messageId:N.id,toolName:S.toolName,toolDisplayName:S.toolDisplayName,functionName:S.functionName,arguments:S.arguments,message:S.message,data:S.data,formSchema:S.formSchema,requiresApproval:_==="confirmation"||_==="form"})}},m=k=>{l(N=>N.map(S=>S.status==="running"||S.status==="awaiting-approval"?{...S,status:k}:S))},j=()=>m("done"),E=()=>m("error");return r.on("message:start",f),r.on("toolCall:received",w),r.on("function:invoke",b),r.on("function:awaiting-approval",g),r.on("function:result",h),r.on("conversation:loaded",v),r.on("message:complete",j),r.on("message:error",E),()=>{r.off("message:start",f),r.off("toolCall:received",w),r.off("function:invoke",b),r.off("function:awaiting-approval",g),r.off("function:result",h),r.off("conversation:loaded",v),r.off("message:complete",j),r.off("message:error",E)}},[r,n,p]);const C=(0,o.useCallback)(async f=>{const w=c.find(b=>b.id===f);!w||w.status!=="awaiting-approval"||i.current.has(f)||w.kind!=="form"&&(i.current.add(f),p(f,{status:"running",requiresApproval:!1}),w.functionName?await r.approveFunction(f):await r.confirmToolCall(f))},[r,c,p]),A=(0,o.useCallback)(async f=>{const w=c.find(b=>b.id===f);!w||w.status!=="awaiting-approval"||i.current.has(f)||(i.current.add(f),p(f,{status:"rejected",requiresApproval:!1}),w.functionName?await r.rejectFunction(f):await r.rejectToolCall(f))},[r,c,p]),x=(0,o.useCallback)(async(f,w)=>{p(f,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(f,w),p(f,{status:"done"})},[r,p]),R=(0,o.useCallback)(()=>{i.current.clear(),l([])},[]);return{items:c,latest:c.length>0?c[c.length-1]:void 0,isAwaitingApproval:c.some(f=>Xe.has(f.status)),approve:C,reject:A,submitForm:x,clear:R}}function oe({client:e,conversationId:n}={}){const t=W(),s=e||t;if(!s)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,c]=(0,o.useState)([]),[l,i]=(0,o.useState)(n),[d,u]=(0,o.useState)(!1),[p,C]=(0,o.useState)(null);(0,o.useEffect)(()=>{n&&n!==l&&(i(n),A(n))},[n]);const A=async x=>{try{c((await s.getMessages(x)).filter(R=>!R.hidden))}catch(R){C(R instanceof Error?R:new Error("Failed to load messages"))}};return(0,o.useEffect)(()=>{const x=v=>v==="IN_PROGRESS"||v==="WAITING_CLIENT",R=v=>{l||i(v.conversationId),u(!0),c(m=>{const j=m.findIndex(E=>E.id===v.messageId);return j>=0?m.map((E,k)=>k===j?{...E,status:"IN_PROGRESS"}:E):m.some(E=>E.role==="assistant"&&x(E.status))?m:[...m,{id:v.messageId,conversationId:v.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},f=v=>{c(m=>{const j=m.findIndex(E=>E.id===v.messageId);return j<0?m:m.map((E,k)=>k===j?{...E,content:E.content+v.content}:E)})},w=v=>{c(m=>{let j=-1;for(let E=m.length-1;E>=0;E--)if(m[E].role==="assistant"&&x(m[E].status)){j=E;break}return j<0?m:[...m.slice(0,j),{...m[j],...v},...m.slice(j+1)]})},b=v=>{c(m=>{const j=m.findIndex(E=>E.id===v.id);return j>=0?[...m.slice(0,j),v,...m.slice(j+1)]:[...m,v]}),u(!1)},g=v=>{C(new Error(v.error)),u(!1)},h=()=>{c(v=>{let m=-1;for(let j=v.length-1;j>=0;j--)if(v[j].role==="assistant"&&x(v[j].status)){m=j;break}return m<0?v:v[m].content?v.map((j,E)=>E===m?{...j,status:"CANCELED"}:j):v.filter((j,E)=>E!==m)}),u(!1)};return s.on("message:start",R),s.on("message:chunk",f),s.on("message:answer-complete",w),s.on("message:complete",b),s.on("message:error",g),s.on("message:stopped",h),()=>{s.off("message:start",R),s.off("message:chunk",f),s.off("message:answer-complete",w),s.off("message:complete",b),s.off("message:error",g),s.off("message:stopped",h)}},[s,l]),{messages:r,isLoading:d,error:p,sendMessage:(0,o.useCallback)(async(x,R)=>{u(!0),C(null);const f={id:`temp-${Date.now()}`,conversationId:l||"",content:x,role:"user",status:"DONE",attachments:R&&R.length>0?D.attachmentsFromFiles(R):void 0,createdAt:new Date},w={id:`temp-assistant-${Date.now()}`,conversationId:l||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};c(b=>[...b,f,w]);try{const b=await s.sendMessage(x,{conversationId:l,files:R});return b.conversationId&&!l&&i(b.conversationId),c(g=>{const h=g.filter(m=>!m.id.startsWith("temp-")),v={...f,id:f.id.replace("temp-","user-"),conversationId:b.conversationId};return h.some(m=>m.id===b.id)?[...h,v].sort((m,j)=>new Date(m.createdAt).getTime()-new Date(j.createdAt).getTime()):[...h,v,b]}),b}catch(b){return C(b instanceof Error?b:new Error("Failed to send message")),u(!1),c(g=>g.filter(h=>!h.id.startsWith("temp-"))),null}},[s,l]),stop:(0,o.useCallback)(async()=>{await s.stop()},[s]),clearMessages:(0,o.useCallback)(()=>{c([]),i(void 0),C(null)},[]),conversationId:l}}var ge={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},et={tabindex:"tabIndex"};function tt(e){const n={};for(const[t,s]of Object.entries(e))n[et[t]??t]=s;return n}function ve(e){const n=e!==!1,t=n?e??{}:void 0,s=(0,o.useRef)(t?.onStateChange);s.current=t?.onStateChange;const r=(0,o.useMemo)(()=>{if(n)return Z.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(l,i)=>s.current?.(l,i)})},[n,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),c=(0,o.useSyncExternalStore)((0,o.useCallback)(l=>r?.subscribe(l)??(()=>{}),[r]),(0,o.useCallback)(()=>r?.getSnapshot()??ge,[r]),(0,o.useCallback)(()=>r?.getServerSnapshot()??ge,[r]));return{sheet:(0,o.useMemo)(()=>({...c,surface:{...c.surface,attrs:tt(c.surface.attrs)}}),[c]),expand:(0,o.useCallback)(l=>r?.expand(l),[r]),collapse:(0,o.useCallback)(l=>r?.collapse(l),[r]),toggle:(0,o.useCallback)(l=>r?.toggle(l),[r])}}var nt=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function Ce(e){const n=e.split(nt);return n.length===1?e:n.map((t,s)=>s%2===0||!t?t:t.startsWith("`")?(0,a.jsx)("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",padding:"0 3px",borderRadius:"3px",backgroundColor:"rgba(0, 0, 0, 0.06)"},children:t.slice(1,-1)},s):t.startsWith("**")?(0,a.jsx)("strong",{style:{fontWeight:600},children:t.slice(2,-2)},s):(0,a.jsx)("em",{children:t.slice(1,-1)},s))}var rt=`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var He=Object.create,J=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Be=Object.getOwnPropertyNames,$e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty,Ue=(e,n)=>{let t={};for(var s in e)J(t,s,{get:e[s],enumerable:!0});return n||J(t,Symbol.toStringTag,{value:"Module"}),t},Ge=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(var r=Be(n),c=0,l=r.length,i;c<l;c++)i=r[c],!Ke.call(e,i)&&i!==t&&J(e,i,{get:(d=>n[d]).bind(null,i),enumerable:!(s=qe(n,i))||s.enumerable});return e},ne=(e,n,t)=>(t=e!=null?He($e(e)):{},Ge(n||!e||!e.__esModule?J(t,"default",{value:e,enumerable:!0}):t,e));const D=require("./types-mcW8vB1U.cjs"),V=require("./errors-o1IB5fEu.cjs"),Je=require("./autoContinue-CP9pJR-V.cjs"),O=require("./createFormCollector-FvwDOqnV.cjs"),Ve=require("./createMockClient-BEOXI8yW.cjs"),Z=require("./sheetController-BThJRtOu.cjs");let o=require("react");o=ne(o,1);let a=require("react/jsx-runtime"),Q=require("react-markdown");Q=ne(Q,1);let ee=require("remark-gfm");ee=ne(ee,1);function he(e){const[n,t]=(0,o.useState)(!1),s=(0,o.useRef)(null),r=(0,o.useMemo)(()=>{if(s.current&&(s.current.destroy(),s.current=null),!e)return null;const c=new D.AgoClient(e);return s.current=c,c},[e?.baseUrl,e?.widgetId]);return(0,o.useEffect)(()=>(r&&s.current===null&&(s.current=r,r.reviveAfterDestroy()),t(!0),()=>{s.current?.destroy(),s.current=null}),[r]),(0,o.useEffect)(()=>{s.current&&e&&s.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,metadata:e.metadata??null,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.metadata,e?.debug,e?.warnOnEmptyReply]),{client:r,isReady:n}}var re=(0,o.createContext)(null),Ye=({children:e,client:n,tools:t,helpers:s,pageContext:r,...c})=>{const{client:l}=he(n?null:c),i=n||l;return(0,o.useEffect)(()=>{if(!(!t||t.length===0)){for(const d of t)i.register(d);return()=>{for(const d of t)i.unregisterFunction(d.name)}}},[i,t]),(0,o.useEffect)(()=>{if(!s)return;const d=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(u=>u.functions_exports).then(u=>{for(const[p,C]of Object.entries(s)){const A=u[p];if(!A){console.warn(`[AGO] Unknown helper: "${p}"`);continue}const x=C===!0?A:{...A,handler:C};i.register(x),d.push(x.name)}}),()=>{for(const u of d)i.unregisterFunction(u)}},[i,s]),(0,o.useEffect)(()=>{r==="auto"&&i.enableAutoPageContext()},[i,r]),(0,a.jsx)(re.Provider,{value:i,children:e})};function L(){const e=(0,o.useContext)(re);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function W(){return(0,o.useContext)(re)}var Xe=new Set(["awaiting-approval"]);function be(e){switch(e){case"progress_indicator":return"progress";case"reasoning":return"reasoning";case"confirmation_input":return"confirmation";case"form":return"form";default:return"status"}}function Ze(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":be(e.type)}function fe(e,n){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(n==="confirmation"||n==="form")?"awaiting-approval":"running"}function pe(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase()).trim()}function Qe(e){switch(e.kind){case"navigation":return`Navigating to ${pe(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||pe(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function ye(e={}){const{includeReasoning:n=!1,labelFor:t}=e,s=W(),r=e.client||s;if(!r)throw new V.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[c,l]=(0,o.useState)([]),i=(0,o.useRef)(new Set),d=(0,o.useRef)(void 0),u=(0,o.useRef)(t);u.current=t;const p=(0,o.useCallback)((f,w)=>{l(b=>{const g=b.findIndex(v=>v.id===f),h={...g>=0?b[g]:{id:f,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...w};return h.label=u.current?.(h)??Qe(h),g>=0?[...b.slice(0,g),h,...b.slice(g+1)]:[...b,h]})},[]);(0,o.useEffect)(()=>{const f=k=>{d.current=k.messageId},w=k=>{const N=be(k.type);N==="reasoning"&&!n||p(k.id,{kind:N,status:fe(k.status,N),messageId:d.current,toolName:k.toolName,toolDisplayName:k.toolDisplayName,message:k.message,data:k.data,formSchema:k.formSchema,requiresApproval:N==="confirmation"||N==="form"})},b=k=>{k.invocationId&&p(k.invocationId,{kind:k.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:d.current,functionName:k.functionName,arguments:k.arguments})},g=k=>{k.invocationId&&p(k.invocationId,{kind:k.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:d.current,functionName:k.functionName,arguments:k.arguments,requiresApproval:!0})},h=k=>{if(!k.invocationId)return;const N=k.result,S=typeof k.result=="object"&&N!==null&&N.approved===!1&&N.reason==="user_rejected";p(k.invocationId,{status:k.error?"error":S?"rejected":"done",requiresApproval:!1})},v=k=>{for(const N of k.messages??[])if(N.role==="assistant")for(const S of N.toolCalls??[]){const _=Ze(S);_==="reasoning"&&!n||/waiting/i.test(S.status??"")||p(S.id,{kind:_,status:fe(S.status,_),messageId:N.id,toolName:S.toolName,toolDisplayName:S.toolDisplayName,functionName:S.functionName,arguments:S.arguments,message:S.message,data:S.data,formSchema:S.formSchema,requiresApproval:_==="confirmation"||_==="form"})}},m=k=>{l(N=>N.map(S=>S.status==="running"||S.status==="awaiting-approval"?{...S,status:k}:S))},j=()=>m("done"),E=()=>m("error");return r.on("message:start",f),r.on("toolCall:received",w),r.on("function:invoke",b),r.on("function:awaiting-approval",g),r.on("function:result",h),r.on("conversation:loaded",v),r.on("message:complete",j),r.on("message:error",E),()=>{r.off("message:start",f),r.off("toolCall:received",w),r.off("function:invoke",b),r.off("function:awaiting-approval",g),r.off("function:result",h),r.off("conversation:loaded",v),r.off("message:complete",j),r.off("message:error",E)}},[r,n,p]);const C=(0,o.useCallback)(async f=>{const w=c.find(b=>b.id===f);!w||w.status!=="awaiting-approval"||i.current.has(f)||w.kind!=="form"&&(i.current.add(f),p(f,{status:"running",requiresApproval:!1}),w.functionName?await r.approveFunction(f):await r.confirmToolCall(f))},[r,c,p]),A=(0,o.useCallback)(async f=>{const w=c.find(b=>b.id===f);!w||w.status!=="awaiting-approval"||i.current.has(f)||(i.current.add(f),p(f,{status:"rejected",requiresApproval:!1}),w.functionName?await r.rejectFunction(f):await r.rejectToolCall(f))},[r,c,p]),x=(0,o.useCallback)(async(f,w)=>{p(f,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(f,w),p(f,{status:"done"})},[r,p]),R=(0,o.useCallback)(()=>{i.current.clear(),l([])},[]);return{items:c,latest:c.length>0?c[c.length-1]:void 0,isAwaitingApproval:c.some(f=>Xe.has(f.status)),approve:C,reject:A,submitForm:x,clear:R}}function oe({client:e,conversationId:n}={}){const t=W(),s=e||t;if(!s)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,c]=(0,o.useState)([]),[l,i]=(0,o.useState)(n),[d,u]=(0,o.useState)(!1),[p,C]=(0,o.useState)(null);(0,o.useEffect)(()=>{n&&n!==l&&(i(n),A(n))},[n]);const A=async x=>{try{c((await s.getMessages(x)).filter(R=>!R.hidden))}catch(R){C(R instanceof Error?R:new Error("Failed to load messages"))}};return(0,o.useEffect)(()=>{const x=v=>v==="IN_PROGRESS"||v==="WAITING_CLIENT",R=v=>{l||i(v.conversationId),u(!0),c(m=>{const j=m.findIndex(E=>E.id===v.messageId);return j>=0?m.map((E,k)=>k===j?{...E,status:"IN_PROGRESS"}:E):m.some(E=>E.role==="assistant"&&x(E.status))?m:[...m,{id:v.messageId,conversationId:v.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},f=v=>{c(m=>{const j=m.findIndex(E=>E.id===v.messageId);return j<0?m:m.map((E,k)=>k===j?{...E,content:E.content+v.content}:E)})},w=v=>{c(m=>{let j=-1;for(let E=m.length-1;E>=0;E--)if(m[E].role==="assistant"&&x(m[E].status)){j=E;break}return j<0?m:[...m.slice(0,j),{...m[j],...v},...m.slice(j+1)]})},b=v=>{c(m=>{const j=m.findIndex(E=>E.id===v.id);return j>=0?[...m.slice(0,j),v,...m.slice(j+1)]:[...m,v]}),u(!1)},g=v=>{C(new Error(v.error)),u(!1)},h=()=>{c(v=>{let m=-1;for(let j=v.length-1;j>=0;j--)if(v[j].role==="assistant"&&x(v[j].status)){m=j;break}return m<0?v:v[m].content?v.map((j,E)=>E===m?{...j,status:"CANCELED"}:j):v.filter((j,E)=>E!==m)}),u(!1)};return s.on("message:start",R),s.on("message:chunk",f),s.on("message:answer-complete",w),s.on("message:complete",b),s.on("message:error",g),s.on("message:stopped",h),()=>{s.off("message:start",R),s.off("message:chunk",f),s.off("message:answer-complete",w),s.off("message:complete",b),s.off("message:error",g),s.off("message:stopped",h)}},[s,l]),{messages:r,isLoading:d,error:p,sendMessage:(0,o.useCallback)(async(x,R)=>{u(!0),C(null);const f={id:`temp-${Date.now()}`,conversationId:l||"",content:x,role:"user",status:"DONE",attachments:R&&R.length>0?D.attachmentsFromFiles(R):void 0,createdAt:new Date},w={id:`temp-assistant-${Date.now()}`,conversationId:l||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};c(b=>[...b,f,w]);try{const b=await s.sendMessage(x,{conversationId:l,files:R});return b.conversationId&&!l&&i(b.conversationId),c(g=>{const h=g.filter(m=>!m.id.startsWith("temp-")),v={...f,id:f.id.replace("temp-","user-"),conversationId:b.conversationId};return h.some(m=>m.id===b.id)?[...h,v].sort((m,j)=>new Date(m.createdAt).getTime()-new Date(j.createdAt).getTime()):[...h,v,b]}),b}catch(b){return C(b instanceof Error?b:new Error("Failed to send message")),u(!1),c(g=>g.filter(h=>!h.id.startsWith("temp-"))),null}},[s,l]),stop:(0,o.useCallback)(async()=>{await s.stop()},[s]),clearMessages:(0,o.useCallback)(()=>{c([]),i(void 0),C(null)},[]),conversationId:l}}var ge={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},et={tabindex:"tabIndex"};function tt(e){const n={};for(const[t,s]of Object.entries(e))n[et[t]??t]=s;return n}function ve(e){const n=e!==!1,t=n?e??{}:void 0,s=(0,o.useRef)(t?.onStateChange);s.current=t?.onStateChange;const r=(0,o.useMemo)(()=>{if(n)return Z.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(l,i)=>s.current?.(l,i)})},[n,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),c=(0,o.useSyncExternalStore)((0,o.useCallback)(l=>r?.subscribe(l)??(()=>{}),[r]),(0,o.useCallback)(()=>r?.getSnapshot()??ge,[r]),(0,o.useCallback)(()=>r?.getServerSnapshot()??ge,[r]));return{sheet:(0,o.useMemo)(()=>({...c,surface:{...c.surface,attrs:tt(c.surface.attrs)}}),[c]),expand:(0,o.useCallback)(l=>r?.expand(l),[r]),collapse:(0,o.useCallback)(l=>r?.collapse(l),[r]),toggle:(0,o.useCallback)(l=>r?.toggle(l),[r])}}var nt=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function Ce(e){const n=e.split(nt);return n.length===1?e:n.map((t,s)=>s%2===0||!t?t:t.startsWith("`")?(0,a.jsx)("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",padding:"0 3px",borderRadius:"3px",backgroundColor:"rgba(0, 0, 0, 0.06)"},children:t.slice(1,-1)},s):t.startsWith("**")?(0,a.jsx)("strong",{style:{fontWeight:600},children:t.slice(2,-2)},s):(0,a.jsx)("em",{children:t.slice(1,-1)},s))}var rt=`
2
2
  @keyframes ago-activity-enter {
3
3
  from { opacity: 0; transform: translateY(4px); }
4
4
  to { opacity: 1; transform: none; }