@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.
- package/CHANGELOG.md +104 -0
- package/README.md +53 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +313 -0
- package/dist/angular.d.ts +313 -0
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-BaaXBQ5b.js → createConversationSession-B1Qn-y0I.js} +1 -1
- package/dist/{createConversationSession-CU0b-t1W.cjs → createConversationSession-B3v_xOU7.cjs} +1 -1
- package/dist/{createFormCollector-DfN1xZBy.cjs → createFormCollector-FvwDOqnV.cjs} +1 -1
- package/dist/{createFormCollector-Cf7kGhCB.js → createFormCollector-m79zk_NA.js} +1 -1
- package/dist/createMockClient-BEOXI8yW.cjs +1 -0
- package/dist/{createMockClient-5YF-ZbVu.js → createMockClient-Beao82tu.js} +15 -3
- package/dist/devtools.d.cts +313 -0
- package/dist/devtools.d.ts +313 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +389 -4
- package/dist/index.d.ts +389 -4
- package/dist/index.js +118 -114
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +313 -0
- package/dist/react.d.ts +313 -0
- package/dist/react.js +8 -6
- package/dist/sheetController-BThJRtOu.cjs +1 -0
- package/dist/sheetController-aEKXIvjk.js +343 -0
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +313 -0
- package/dist/testing.d.ts +313 -0
- package/dist/testing.js +1 -1
- package/dist/types-Ct1hlKwg.js +2408 -0
- package/dist/types-mcW8vB1U.cjs +10 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +505 -0
- package/dist/vue.d.ts +505 -0
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +6 -4
- package/dist/widget.d.cts +585 -2
- package/dist/widget.d.ts +585 -2
- package/dist/widget.js +3985 -995
- package/llms-full.txt +125 -6
- package/package.json +1 -1
- package/dist/createMockClient-BZbOe-23.cjs +0 -1
- package/dist/sheetController-CBUVOroo.js +0 -205
- package/dist/sheetController-DY-sC13T.cjs +0 -1
- package/dist/types-CPga11Of.js +0 -2068
- package/dist/types-D3YQl1jx.cjs +0 -9
package/dist/index.js
CHANGED
|
@@ -1,170 +1,174 @@
|
|
|
1
|
-
import { a as w, c as
|
|
2
|
-
import { _ as
|
|
3
|
-
import { a as
|
|
4
|
-
import { t as
|
|
5
|
-
import { t as
|
|
6
|
-
import { n as
|
|
7
|
-
import { t as
|
|
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
|
|
9
|
+
function Ae(e) {
|
|
10
10
|
return e;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
return e.on("message:complete",
|
|
12
|
+
function he(e, t) {
|
|
13
|
+
return e.on("message:complete", t), () => e.off("message:complete", t);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
return e.on("message:chunk",
|
|
15
|
+
function we(e, t) {
|
|
16
|
+
return e.on("message:chunk", t), () => e.off("message:chunk", t);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return e.on("message:start",
|
|
18
|
+
function Ee(e, t) {
|
|
19
|
+
return e.on("message:start", t), () => e.off("message:start", t);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
return e.on("message:error",
|
|
21
|
+
function Ce(e, t) {
|
|
22
|
+
return e.on("message:error", t), () => e.off("message:error", t);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
return e.on("toolCall:received",
|
|
24
|
+
function Se(e, t) {
|
|
25
|
+
return e.on("toolCall:received", t), () => e.off("toolCall:received", t);
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
return e.on("form:submitted",
|
|
27
|
+
function ye(e, t) {
|
|
28
|
+
return e.on("form:submitted", t), () => e.off("form:submitted", t);
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
return e.on("form:error",
|
|
30
|
+
function be(e, t) {
|
|
31
|
+
return e.on("form:error", t), () => e.off("form:error", t);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
return e.on("function:invoke",
|
|
33
|
+
function ve(e, t) {
|
|
34
|
+
return e.on("function:invoke", t), () => e.off("function:invoke", t);
|
|
35
35
|
}
|
|
36
|
-
async function*
|
|
37
|
-
const
|
|
38
|
-
let
|
|
39
|
-
const g = (
|
|
40
|
-
|
|
41
|
-
}, m = (
|
|
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:
|
|
44
|
-
}),
|
|
43
|
+
data: n
|
|
44
|
+
}), f = (n) => g({
|
|
45
45
|
type: "chunk",
|
|
46
|
-
data:
|
|
47
|
-
}),
|
|
46
|
+
data: n
|
|
47
|
+
}), o = (n) => {
|
|
48
48
|
g({
|
|
49
49
|
type: "complete",
|
|
50
|
-
data:
|
|
51
|
-
}),
|
|
52
|
-
},
|
|
50
|
+
data: n
|
|
51
|
+
}), r = !0, a?.();
|
|
52
|
+
}, i = (n) => {
|
|
53
53
|
g({
|
|
54
54
|
type: "error",
|
|
55
|
-
data:
|
|
56
|
-
}),
|
|
57
|
-
},
|
|
55
|
+
data: n
|
|
56
|
+
}), r = !0, a?.();
|
|
57
|
+
}, d = (n) => g({
|
|
58
58
|
type: "toolCall",
|
|
59
|
-
data:
|
|
60
|
-
}),
|
|
61
|
-
|
|
59
|
+
data: n
|
|
60
|
+
}), l = () => {
|
|
61
|
+
r = !0, a?.();
|
|
62
62
|
};
|
|
63
|
-
e.on("message:start", m), e.on("message:chunk",
|
|
64
|
-
|
|
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 (; !
|
|
68
|
-
|
|
69
|
-
}),
|
|
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",
|
|
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
|
|
75
|
+
let t, u, s, a, r, g, m;
|
|
76
76
|
if (typeof window < "u" && window.AGO) {
|
|
77
|
-
const
|
|
78
|
-
|
|
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
|
|
82
|
-
|
|
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
|
|
86
|
-
for (const i of
|
|
87
|
-
i && (
|
|
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
|
-
|
|
90
|
-
const
|
|
91
|
-
return
|
|
92
|
-
baseUrl:
|
|
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:
|
|
95
|
-
permission:
|
|
96
|
-
userEmail:
|
|
94
|
+
agent: s,
|
|
95
|
+
permission: a,
|
|
96
|
+
userEmail: r,
|
|
97
97
|
userJwt: g,
|
|
98
|
-
|
|
98
|
+
metadata: m,
|
|
99
|
+
debug: f
|
|
99
100
|
} : null;
|
|
100
101
|
}
|
|
101
|
-
function
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
104
|
-
return new c(
|
|
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
|
|
107
|
+
function Me(e, t) {
|
|
107
108
|
return {
|
|
108
109
|
...e,
|
|
109
|
-
handler:
|
|
110
|
+
handler: t
|
|
110
111
|
};
|
|
111
112
|
}
|
|
112
113
|
export {
|
|
113
114
|
D as ActivityLedger,
|
|
114
|
-
|
|
115
|
+
re as AgoApiError,
|
|
115
116
|
c as AgoClient,
|
|
116
117
|
p as AgoError,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
Y as FunctionRegistry,
|
|
129
|
+
B as SSEHandler,
|
|
130
|
+
O as SignalCollector,
|
|
131
|
+
ne as attachAutoContinueAfterNavigation,
|
|
128
132
|
A as autoDetectConfig,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
146
|
+
y as getUserLocation,
|
|
143
147
|
w as highlightElement,
|
|
144
148
|
V as isStreamNetworkError,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
159
|
-
|
|
162
|
+
P as partialDeepMatch,
|
|
163
|
+
N as safeAttachmentUrl,
|
|
160
164
|
T as scrollToElement,
|
|
161
|
-
|
|
165
|
+
E as setLocalStorage,
|
|
162
166
|
b as setTheme,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
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; }
|