@useago/sdk 1.7.2 → 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 +175 -0
- package/README.md +96 -1
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +402 -5
- package/dist/angular.d.ts +402 -5
- package/dist/angular.js +11 -7
- package/dist/{createConversationSession-DP90nY71.js → createConversationSession-B1Qn-y0I.js} +3 -3
- package/dist/createConversationSession-B3v_xOU7.cjs +1 -0
- package/dist/createFormCollector-FvwDOqnV.cjs +1 -0
- package/dist/{createFormCollector-BivHRIAe.js → createFormCollector-m79zk_NA.js} +1 -1
- package/dist/createMockClient-BEOXI8yW.cjs +1 -0
- package/dist/{createMockClient-BDLW6tVc.js → createMockClient-Beao82tu.js} +31 -18
- package/dist/devtools.cjs +61 -12
- package/dist/devtools.d.cts +403 -5
- package/dist/devtools.d.ts +403 -5
- package/dist/devtools.js +225 -73
- package/dist/errors-BLfjXnLB.js +32 -0
- package/dist/errors-o1IB5fEu.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +489 -7
- package/dist/index.d.ts +489 -7
- package/dist/index.js +124 -118
- package/dist/react.cjs +4 -4
- package/dist/react.d.cts +510 -3
- package/dist/react.d.ts +510 -3
- package/dist/react.js +1036 -752
- 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 +393 -3
- package/dist/testing.d.ts +393 -3
- 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 +615 -3
- package/dist/vue.d.ts +615 -3
- package/dist/vue.js +202 -154
- package/dist/widget.cjs +6 -4
- package/dist/widget.d.cts +733 -5
- package/dist/widget.d.ts +733 -5
- package/dist/widget.js +3996 -786
- package/llms-full.txt +264 -31
- package/package.json +1 -1
- package/dist/AgoClient-7yXQ6R3O.cjs +0 -9
- package/dist/AgoClient-DTkBRGFE.js +0 -1965
- package/dist/createConversationSession-Bv6a15E0.cjs +0 -1
- package/dist/createFormCollector-CwfiYn0V.cjs +0 -1
- package/dist/createMockClient-BSNuN3ys.cjs +0 -1
- package/dist/sheetController-CBUVOroo.js +0 -205
- package/dist/sheetController-DY-sC13T.cjs +0 -1
package/dist/index.js
CHANGED
|
@@ -1,168 +1,174 @@
|
|
|
1
|
-
import { a as w, c as
|
|
2
|
-
import { C as
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import {
|
|
6
|
-
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";
|
|
7
8
|
import "./testing.js";
|
|
8
|
-
function
|
|
9
|
+
function Ae(e) {
|
|
9
10
|
return e;
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
return e.on("message:complete",
|
|
12
|
+
function he(e, t) {
|
|
13
|
+
return e.on("message:complete", t), () => e.off("message:complete", t);
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
return e.on("message:chunk",
|
|
15
|
+
function we(e, t) {
|
|
16
|
+
return e.on("message:chunk", t), () => e.off("message:chunk", t);
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
return e.on("message:start",
|
|
18
|
+
function Ee(e, t) {
|
|
19
|
+
return e.on("message:start", t), () => e.off("message:start", t);
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
-
return e.on("message:error",
|
|
21
|
+
function Ce(e, t) {
|
|
22
|
+
return e.on("message:error", t), () => e.off("message:error", t);
|
|
22
23
|
}
|
|
23
|
-
function
|
|
24
|
-
return e.on("toolCall:received",
|
|
24
|
+
function Se(e, t) {
|
|
25
|
+
return e.on("toolCall:received", t), () => e.off("toolCall:received", t);
|
|
25
26
|
}
|
|
26
|
-
function
|
|
27
|
-
return e.on("form:submitted",
|
|
27
|
+
function ye(e, t) {
|
|
28
|
+
return e.on("form:submitted", t), () => e.off("form:submitted", t);
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
-
return e.on("form:error",
|
|
30
|
+
function be(e, t) {
|
|
31
|
+
return e.on("form:error", t), () => e.off("form:error", t);
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
-
return e.on("function:invoke",
|
|
33
|
+
function ve(e, t) {
|
|
34
|
+
return e.on("function:invoke", t), () => e.off("function:invoke", t);
|
|
34
35
|
}
|
|
35
|
-
async function*
|
|
36
|
-
const
|
|
37
|
-
let
|
|
38
|
-
const g = (
|
|
39
|
-
|
|
40
|
-
},
|
|
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({
|
|
41
42
|
type: "start",
|
|
42
|
-
data:
|
|
43
|
-
}),
|
|
43
|
+
data: n
|
|
44
|
+
}), f = (n) => g({
|
|
44
45
|
type: "chunk",
|
|
45
|
-
data:
|
|
46
|
-
}),
|
|
46
|
+
data: n
|
|
47
|
+
}), o = (n) => {
|
|
47
48
|
g({
|
|
48
49
|
type: "complete",
|
|
49
|
-
data:
|
|
50
|
-
}),
|
|
51
|
-
},
|
|
50
|
+
data: n
|
|
51
|
+
}), r = !0, a?.();
|
|
52
|
+
}, i = (n) => {
|
|
52
53
|
g({
|
|
53
54
|
type: "error",
|
|
54
|
-
data:
|
|
55
|
-
}),
|
|
56
|
-
},
|
|
55
|
+
data: n
|
|
56
|
+
}), r = !0, a?.();
|
|
57
|
+
}, d = (n) => g({
|
|
57
58
|
type: "toolCall",
|
|
58
|
-
data:
|
|
59
|
-
}),
|
|
60
|
-
|
|
59
|
+
data: n
|
|
60
|
+
}), l = () => {
|
|
61
|
+
r = !0, a?.();
|
|
61
62
|
};
|
|
62
|
-
e.on("message:start",
|
|
63
|
-
|
|
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?.();
|
|
64
65
|
});
|
|
65
66
|
try {
|
|
66
|
-
for (; !
|
|
67
|
-
|
|
68
|
-
}),
|
|
67
|
+
for (; !r || s.length > 0; ) s.length > 0 ? yield s.shift() : (await new Promise((n) => {
|
|
68
|
+
a = n;
|
|
69
|
+
}), a = null);
|
|
69
70
|
} finally {
|
|
70
|
-
e.off("message:start",
|
|
71
|
+
e.off("message:start", m), e.off("message:chunk", f), e.off("message:complete", o), e.off("message:error", i), e.off("message:stopped", l), e.off("toolCall:received", d);
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
function A(e) {
|
|
74
|
-
let
|
|
75
|
+
let t, u, s, a, r, g, m;
|
|
75
76
|
if (typeof window < "u" && window.AGO) {
|
|
76
|
-
const
|
|
77
|
-
|
|
77
|
+
const o = window.AGO;
|
|
78
|
+
t = o.basepath, u = o.widgetId, s = o.agent || o.defaultAgent, a = o.permission, r = o.email, g = o.jwt, m = o.metadata;
|
|
78
79
|
}
|
|
79
80
|
if (typeof document < "u") {
|
|
80
|
-
const
|
|
81
|
-
|
|
81
|
+
const o = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
|
|
82
|
+
t = t || o("ago-base-url"), u = u || o("ago-widget-id"), s = s || o("ago-agent") || o("ago-agent-id"), a = a || o("ago-permission"), r = r || o("ago-user-email");
|
|
82
83
|
}
|
|
83
84
|
if (typeof document < "u") {
|
|
84
|
-
const
|
|
85
|
-
for (const i of
|
|
86
|
-
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);
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
+
t = e?.baseUrl || t, u = e?.widgetId || u, s = e?.agent || e?.defaultAgentId || s, a = e?.permission || a, r = e?.userEmail || r, g = e?.userJwt || g, e?.metadata !== void 0 && (m = e.metadata);
|
|
89
90
|
const f = e?.debug;
|
|
90
|
-
return
|
|
91
|
-
baseUrl:
|
|
91
|
+
return t ? {
|
|
92
|
+
baseUrl: t,
|
|
92
93
|
widgetId: u,
|
|
93
|
-
agent:
|
|
94
|
-
permission:
|
|
95
|
-
userEmail:
|
|
94
|
+
agent: s,
|
|
95
|
+
permission: a,
|
|
96
|
+
userEmail: r,
|
|
96
97
|
userJwt: g,
|
|
98
|
+
metadata: m,
|
|
97
99
|
debug: f
|
|
98
100
|
} : null;
|
|
99
101
|
}
|
|
100
|
-
function
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
103
|
-
return new
|
|
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);
|
|
104
106
|
}
|
|
105
|
-
function
|
|
107
|
+
function Me(e, t) {
|
|
106
108
|
return {
|
|
107
109
|
...e,
|
|
108
|
-
handler:
|
|
110
|
+
handler: t
|
|
109
111
|
};
|
|
110
112
|
}
|
|
111
113
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
114
|
+
D as ActivityLedger,
|
|
115
|
+
re as AgoApiError,
|
|
116
|
+
c as AgoClient,
|
|
117
|
+
p as AgoError,
|
|
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,
|
|
127
|
+
K as FEEDBACK_REASONS,
|
|
128
|
+
Y as FunctionRegistry,
|
|
129
|
+
B as SSEHandler,
|
|
130
|
+
O as SignalCollector,
|
|
131
|
+
ne as attachAutoContinueAfterNavigation,
|
|
126
132
|
A as autoDetectConfig,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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,
|
|
144
|
+
z as formatFileSize,
|
|
145
|
+
M as getLocalStorage,
|
|
146
|
+
y as getUserLocation,
|
|
141
147
|
w as highlightElement,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
V as isStreamNetworkError,
|
|
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,
|
|
155
161
|
F as openUrl,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
P as partialDeepMatch,
|
|
163
|
+
N as safeAttachmentUrl,
|
|
164
|
+
T as scrollToElement,
|
|
165
|
+
E as setLocalStorage,
|
|
160
166
|
b as setTheme,
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
I as showConfirmDialog,
|
|
168
|
+
C as showNotification,
|
|
163
169
|
S as showToast,
|
|
164
|
-
|
|
170
|
+
_ as submitForm,
|
|
165
171
|
v as trackEvent,
|
|
166
|
-
|
|
167
|
-
|
|
172
|
+
j as validateConfig,
|
|
173
|
+
Me as withHandler
|
|
168
174
|
};
|
package/dist/react.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Pe=Object.create,G=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Oe=Object.getOwnPropertyNames,ze=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty,Le=(e,n)=>{let t={};for(var o in e)G(t,o,{get:e[o],enumerable:!0});return n||G(t,Symbol.toStringTag,{value:"Module"}),t},He=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(var r=Oe(n),c=0,i=r.length,l;c<i;c++)l=r[c],!De.call(e,l)&&l!==t&&G(e,l,{get:(u=>n[u]).bind(null,l),enumerable:!(o=We(n,l))||o.enumerable});return e},Q=(e,n,t)=>(t=e!=null?Pe(ze(e)):{},He(n||!e||!e.__esModule?G(t,"default",{value:e,enumerable:!0}):t,e));const P=require("./AgoClient-7yXQ6R3O.cjs"),qe=require("./autoContinue-CP9pJR-V.cjs"),z=require("./createFormCollector-CwfiYn0V.cjs"),Be=require("./createMockClient-BSNuN3ys.cjs"),Y=require("./sheetController-DY-sC13T.cjs");let s=require("react");s=Q(s,1);let a=require("react/jsx-runtime"),X=require("react-markdown");X=Q(X,1);let Z=require("remark-gfm");Z=Q(Z,1);function pe(e){const[n,t]=(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 c=new P.AgoClient(e);return o.current=c,c},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(r&&o.current===null&&(o.current=r,r.reviveAfterDestroy()),t(!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:n}}var ee=(0,s.createContext)(null),$e=({children:e,client:n,tools:t,helpers:o,pageContext:r,...c})=>{const{client:i}=pe(n?null:c),l=n||i;return(0,s.useEffect)(()=>{if(!(!t||t.length===0)){for(const u of t)l.register(u);return()=>{for(const u of t)l.unregisterFunction(u.name)}}},[l,t]),(0,s.useEffect)(()=>{if(!o)return;const u=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(p=>p.functions_exports).then(p=>{for(const[g,S]of Object.entries(o)){const R=p[g];if(!R){console.warn(`[AGO] Unknown helper: "${g}"`);continue}const k=S===!0?R:{...R,handler:S};l.register(k),u.push(k.name)}}),()=>{for(const p of u)l.unregisterFunction(p)}},[l,o]),(0,s.useEffect)(()=>{r==="auto"&&l.enableAutoPageContext()},[l,r]),(0,a.jsx)(ee.Provider,{value:l,children:e})};function D(){const e=(0,s.useContext)(ee);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,s.useContext)(ee)}var Ke=new Set(["awaiting-approval"]);function ge(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 Ue(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":ge(e.type)}function ce(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 ue(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 Ge(e){switch(e.kind){case"navigation":return`Navigating to ${ue(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||ue(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 xe(e={}){const{includeReasoning:n=!1,labelFor:t}=e,o=W(),r=e.client||o;if(!r)throw new P.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[c,i]=(0,s.useState)([]),l=(0,s.useRef)(new Set),u=(0,s.useRef)(void 0),p=(0,s.useRef)(t);p.current=t;const g=(0,s.useCallback)((f,A)=>{i(C=>{const d=C.findIndex(m=>m.id===f),b={...d>=0?C[d]:{id:f,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...A};return b.label=p.current?.(b)??Ge(b),d>=0?[...C.slice(0,d),b,...C.slice(d+1)]:[...C,b]})},[]);(0,s.useEffect)(()=>{const f=y=>{u.current=y.messageId},A=y=>{const N=ge(y.type);N==="reasoning"&&!n||g(y.id,{kind:N,status:ce(y.status,N),messageId:u.current,toolName:y.toolName,toolDisplayName:y.toolDisplayName,message:y.message,data:y.data,formSchema:y.formSchema,requiresApproval:N==="confirmation"||N==="form"})},C=y=>{y.invocationId&&g(y.invocationId,{kind:y.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:u.current,functionName:y.functionName,arguments:y.arguments})},d=y=>{y.invocationId&&g(y.invocationId,{kind:y.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:u.current,functionName:y.functionName,arguments:y.arguments,requiresApproval:!0})},b=y=>{if(!y.invocationId)return;const N=y.result,v=typeof y.result=="object"&&N!==null&&N.approved===!1&&N.reason==="user_rejected";g(y.invocationId,{status:y.error?"error":v?"rejected":"done",requiresApproval:!1})},m=y=>{for(const N of y.messages??[])if(N.role==="assistant")for(const v of N.toolCalls??[]){const T=Ue(v);T==="reasoning"&&!n||/waiting/i.test(v.status??"")||g(v.id,{kind:T,status:ce(v.status,T),messageId:N.id,toolName:v.toolName,toolDisplayName:v.toolDisplayName,functionName:v.functionName,arguments:v.arguments,message:v.message,data:v.data,formSchema:v.formSchema,requiresApproval:T==="confirmation"||T==="form"})}},x=y=>{i(N=>N.map(v=>v.status==="running"||v.status==="awaiting-approval"?{...v,status:y}:v))},w=()=>x("done"),j=()=>x("error");return r.on("message:start",f),r.on("toolCall:received",A),r.on("function:invoke",C),r.on("function:awaiting-approval",d),r.on("function:result",b),r.on("conversation:loaded",m),r.on("message:complete",w),r.on("message:error",j),()=>{r.off("message:start",f),r.off("toolCall:received",A),r.off("function:invoke",C),r.off("function:awaiting-approval",d),r.off("function:result",b),r.off("conversation:loaded",m),r.off("message:complete",w),r.off("message:error",j)}},[r,n,g]);const S=(0,s.useCallback)(async f=>{const A=c.find(C=>C.id===f);!A||A.status!=="awaiting-approval"||l.current.has(f)||A.kind!=="form"&&(l.current.add(f),g(f,{status:"running",requiresApproval:!1}),A.functionName?await r.approveFunction(f):await r.confirmToolCall(f))},[r,c,g]),R=(0,s.useCallback)(async f=>{const A=c.find(C=>C.id===f);!A||A.status!=="awaiting-approval"||l.current.has(f)||(l.current.add(f),g(f,{status:"rejected",requiresApproval:!1}),A.functionName?await r.rejectFunction(f):await r.rejectToolCall(f))},[r,c,g]),k=(0,s.useCallback)(async(f,A)=>{g(f,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(f,A),g(f,{status:"done"})},[r,g]),_=(0,s.useCallback)(()=>{l.current.clear(),i([])},[]);return{items:c,latest:c.length>0?c[c.length-1]:void 0,isAwaitingApproval:c.some(f=>Ke.has(f.status)),approve:S,reject:R,submitForm:k,clear:_}}function te({client:e,conversationId:n}={}){const t=W(),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,c]=(0,s.useState)([]),[i,l]=(0,s.useState)(n),[u,p]=(0,s.useState)(!1),[g,S]=(0,s.useState)(null);(0,s.useEffect)(()=>{n&&n!==i&&(l(n),R(n))},[n]);const R=async k=>{try{c((await o.getMessages(k)).filter(_=>!_.hidden))}catch(_){S(_ instanceof Error?_:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const k=m=>m==="IN_PROGRESS"||m==="WAITING_CLIENT",_=m=>{i||l(m.conversationId),p(!0),c(x=>{const w=x.findIndex(j=>j.id===m.messageId);return w>=0?x.map((j,y)=>y===w?{...j,status:"IN_PROGRESS"}:j):x.some(j=>j.role==="assistant"&&k(j.status))?x:[...x,{id:m.messageId,conversationId:m.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},f=m=>{c(x=>{const w=x.findIndex(j=>j.id===m.messageId);return w<0?x:x.map((j,y)=>y===w?{...j,content:j.content+m.content}:j)})},A=m=>{c(x=>{let w=-1;for(let j=x.length-1;j>=0;j--)if(x[j].role==="assistant"&&k(x[j].status)){w=j;break}return w<0?x:[...x.slice(0,w),{...x[w],...m},...x.slice(w+1)]})},C=m=>{c(x=>{const w=x.findIndex(j=>j.id===m.id);return w>=0?[...x.slice(0,w),m,...x.slice(w+1)]:[...x,m]}),p(!1)},d=m=>{S(new Error(m.error)),p(!1)},b=()=>{c(m=>{let x=-1;for(let w=m.length-1;w>=0;w--)if(m[w].role==="assistant"&&k(m[w].status)){x=w;break}return x<0?m:m[x].content?m.map((w,j)=>j===x?{...w,status:"CANCELED"}:w):m.filter((w,j)=>j!==x)}),p(!1)};return o.on("message:start",_),o.on("message:chunk",f),o.on("message:answer-complete",A),o.on("message:complete",C),o.on("message:error",d),o.on("message:stopped",b),()=>{o.off("message:start",_),o.off("message:chunk",f),o.off("message:answer-complete",A),o.off("message:complete",C),o.off("message:error",d),o.off("message:stopped",b)}},[o,i]),{messages:r,isLoading:u,error:g,sendMessage:(0,s.useCallback)(async(k,_)=>{p(!0),S(null);const f={id:`temp-${Date.now()}`,conversationId:i||"",content:k,role:"user",status:"DONE",attachments:_&&_.length>0?P.attachmentsFromFiles(_):void 0,createdAt:new Date},A={id:`temp-assistant-${Date.now()}`,conversationId:i||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};c(C=>[...C,f,A]);try{const C=await o.sendMessage(k,{conversationId:i,files:_});return C.conversationId&&!i&&l(C.conversationId),c(d=>{const b=d.filter(x=>!x.id.startsWith("temp-")),m={...f,id:f.id.replace("temp-","user-"),conversationId:C.conversationId};return b.some(x=>x.id===C.id)?[...b,m].sort((x,w)=>new Date(x.createdAt).getTime()-new Date(w.createdAt).getTime()):[...b,m,C]}),C}catch(C){return S(C instanceof Error?C:new Error("Failed to send message")),p(!1),c(d=>d.filter(b=>!b.id.startsWith("temp-"))),null}},[o,i]),stop:(0,s.useCallback)(async()=>{await o.stop()},[o]),clearMessages:(0,s.useCallback)(()=>{c([]),l(void 0),S(null)},[]),conversationId:i}}var de={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},Je={tabindex:"tabIndex"};function Ve(e){const n={};for(const[t,o]of Object.entries(e))n[Je[t]??t]=o;return n}function me(e){const n=e!==!1,t=n?e??{}:void 0,o=(0,s.useRef)(t?.onStateChange);o.current=t?.onStateChange;const r=(0,s.useMemo)(()=>{if(n)return Y.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(i,l)=>o.current?.(i,l)})},[n,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),c=(0,s.useSyncExternalStore)((0,s.useCallback)(i=>r?.subscribe(i)??(()=>{}),[r]),(0,s.useCallback)(()=>r?.getSnapshot()??de,[r]),(0,s.useCallback)(()=>r?.getServerSnapshot()??de,[r]));return{sheet:(0,s.useMemo)(()=>({...c,surface:{...c.surface,attrs:Ve(c.surface.attrs)}}),[c]),expand:(0,s.useCallback)(i=>r?.expand(i),[r]),collapse:(0,s.useCallback)(i=>r?.collapse(i),[r]),toggle:(0,s.useCallback)(i=>r?.toggle(i),[r])}}var Ye=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function he(e){const n=e.split(Ye);return n.length===1?e:n.map((t,o)=>o%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)},o):t.startsWith("**")?(0,a.jsx)("strong",{style:{fontWeight:600},children:t.slice(2,-2)},o):(0,a.jsx)("em",{children:t.slice(1,-1)},o))}var Xe=`
|
|
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; }
|
|
@@ -35,10 +35,10 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Pe=Object
|
|
|
35
35
|
color: var(--ago-activity-color, #5b5d5f);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,
|
|
39
|
-
`)?(0,a.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}):(0,a.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}),
|
|
38
|
+
`,ot=({label:e})=>(0,a.jsxs)("div",{className:"ago-activity",role:"status","aria-live":"polite",style:{display:"block",margin:"4px 0 0",padding:"6px 12px",borderRadius:"999px",width:"fit-content",maxWidth:"100%",fontSize:"13px",lineHeight:1.5,color:"var(--ago-activity-color, #5b5d5f)",backgroundColor:"var(--ago-activity-bg, #f1f2f3)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[(0,a.jsx)("span",{className:"ago-activity__label",children:Ce(e)},e),(0,a.jsx)("style",{children:rt})]}),we=({onSend:e,onStop:n,disabled:t=!1,placeholder:s="Type a message...",allowFiles:r=!1,className:c=""})=>{const[l,i]=(0,o.useState)(""),[d,u]=(0,o.useState)([]),p=(0,o.useRef)(null),C=(0,o.useRef)(null),A=(0,o.useCallback)(()=>{const g=C.current;if(!g)return;const h=110;g.style.height="auto",g.style.height=`${Math.min(g.scrollHeight+2,h)}px`,g.style.overflowY=g.scrollHeight+2>h?"auto":"hidden"},[]),x=(0,o.useCallback)(async g=>{if(g.preventDefault(),!l.trim()&&d.length===0)return;const h=l.trim(),v=d.length>0?d:void 0;i(""),u([]),requestAnimationFrame(A),await e(h,v)===!1&&(i(m=>m.trim()?m:h),v&&u(m=>[...v,...m]),requestAnimationFrame(A))},[l,d,e,A]),R=(0,o.useCallback)(g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),x(g))},[x]),f=(0,o.useCallback)(g=>{const h=Array.from(g.target.files||[]);u(v=>[...v,...h])},[]),w=(0,o.useCallback)(g=>{u(h=>h.filter((v,m)=>m!==g))},[]),b=l.trim()||d.length>0;return(0,a.jsxs)("form",{onSubmit:g=>{x(g)},className:`ago-chat-input ${c}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[d.length>0&&(0,a.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:d.map((g,h)=>(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,a.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.name}),(0,a.jsx)("button",{type:"button",onClick:()=>w(h),"aria-label":`Remove ${g.name}`,style:{flexShrink:0,width:"44px",height:"44px",margin:"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},h))}),(0,a.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>p.current?.click(),disabled:t,"aria-label":"Attach file",style:{flexShrink:0,minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,a.jsx)("input",{ref:p,type:"file",multiple:!0,onChange:f,style:{display:"none"}})]}),(0,a.jsx)("textarea",{ref:C,className:"ago-chat-input__field",value:l,onChange:g=>{i(g.target.value),A()},onKeyDown:R,placeholder:s,"aria-label":s,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:g=>{g.currentTarget.style.borderColor="#1b5fc4"},onBlur:g=>{g.currentTarget.style.borderColor="#dee3e8"}}),t&&n?(0,a.jsx)("button",{type:"button",onClick:n,"aria-label":"Stop generating",style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:"#03182f",color:"#fff",cursor:"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Stop"}):(0,a.jsx)("button",{type:"submit",disabled:t||!b,style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!b?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!b?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},st=({href:e,children:n,...t})=>(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:n}),at=({children:e,...n})=>(0,a.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...n,children:e}),H=(e,n)=>{const t=({children:s,...r})=>o.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:n,fontWeight:600,lineHeight:"1.3"},...r},s);return t.displayName=`MarkdownHeading${e}`,t},it=({children:e,...n})=>(0,a.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...n,children:e}),lt=({children:e,...n})=>(0,a.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...n,children:e}),ct=({children:e,...n})=>(0,a.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...n,children:e}),ut=({className:e,children:n,...t})=>e!==void 0||String(n).includes(`
|
|
39
|
+
`)?(0,a.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}):(0,a.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}),dt=({children:e,...n})=>(0,a.jsx)("pre",{style:{margin:"0 0 8px 0"},...n,children:e}),ft=({children:e,...n})=>(0,a.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...n,children:e}),pt=({children:e,...n})=>(0,a.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,a.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...n,children:e})}),gt=({children:e,...n})=>(0,a.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...n,children:e}),xt=({children:e,...n})=>(0,a.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...n,children:e}),mt=({alt:e,...n})=>(0,a.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...n}),ht=e=>(0,a.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),bt={a:st,p:at,h1:H(1,"20px"),h2:H(2,"18px"),h3:H(3,"16px"),h4:H(4,"15px"),h5:H(5,"14px"),h6:H(6,"13px"),ul:it,ol:lt,li:ct,code:ut,pre:dt,blockquote:ft,table:pt,th:gt,td:xt,img:mt,hr:ht},yt=[ee.default],ke=({content:e})=>(0,a.jsx)(Q.default,{remarkPlugins:yt,components:bt,children:e}),vt=({attachment:e,isUser:n})=>{const t=D.safeAttachmentUrl(e.url);if(D.canInlineImage(e))return(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,a.jsx)("img",{src:t,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const s=D.formatFileSize(e.fileSize),r=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,a.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,a.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),s&&(0,a.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:s})]})]}),c={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:n?"rgba(255,255,255,0.12)":"#fff",color:n?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return t?(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:c,children:r}):(0,a.jsx)("div",{style:c,children:r})},Ct=({source:e,index:n})=>{const t=(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,a.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:n+1}),(0,a.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),s={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,a.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:s,onMouseEnter:r=>{r.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:r=>{r.currentTarget.style.borderColor="#dee3e8"},children:t}):(0,a.jsx)("div",{style:s,children:t})},Se=()=>(0,a.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,a.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",opacity:.55,animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,a.jsx)("style",{children:`
|
|
40
40
|
@keyframes ago-pulse {
|
|
41
41
|
0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
|
|
42
42
|
40% { opacity: 1; transform: scale(1); }
|
|
43
43
|
}
|
|
44
|
-
`})]}),Ce=({message:e,className:n="",showAgentName:t=!1,isLast:o=!1,onFollowUpClick:r,showStreamingDots:c=!0})=>{const i=e.role==="user",l=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,a.jsxs)("div",{className:`ago-message ago-message--${e.role} ${n}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,a.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!i&&e.sources&&e.sources.length>0&&(0,a.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((u,p)=>(0,a.jsx)(xt,{source:u,index:p},u.id))}),e.attachments&&e.attachments.length>0&&(0,a.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:i?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(u=>(0,a.jsx)(gt,{attachment:u,isUser:i},u.id))}),(e.content||l&&c)&&(0,a.jsx)("div",{className:"ago-message__content",style:{maxWidth:i?"75%":"100%",padding:i?"10px 14px":"2px 8px",borderRadius:i?"16px":"0",backgroundColor:i?"#03182f":"transparent",color:i?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,a.jsx)(be,{content:e.content}):l&&c&&(0,a.jsx)(ve,{})}),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((u,p)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!r,onClick:r?()=>r(u):void 0,style:{minHeight:"44px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:r?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:g=>{g.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:g=>{g.currentTarget.style.borderColor="#dee3e8"},children:u},p))})]})},mt=(0,s.forwardRef)(function({client:n,conversationId:t,title:o="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:c="Type a message...",allowFiles:i=!1,allowStop:l=!0,height:u=500,logoUrl:p,showAgentName:g=!1,forms:S,onFollowUpClick:R,className:k="",onMessageSent:_,onMessageReceived:f,sheet:A=!1,thinkingLabel:C="Thinking...",functionLabels:d,showReasoning:b=!0},m){const x=(0,s.useRef)(null),w=(0,s.useRef)(!0),[j,y]=(0,s.useState)(!0),N=(0,s.useRef)(null),{sheet:v,expand:T,collapse:H,toggle:ne}=me(A),[je,J]=(0,s.useState)(!1),V=v.compact&&v.state==="peek",Ae=W(),q=n??Ae,{messages:M,isLoading:_e,error:re,sendMessage:Re,stop:Ie}=te({client:n,conversationId:t});(0,s.useEffect)(()=>{if(!q||!S||S.length===0)return;let h=!1;const E=[];return Promise.all(S.map(I=>I.schema!=null?Promise.resolve(z.createFormCollector(I)):z.loadFormCollector(q,I))).then(I=>{if(!h)for(const F of I)E.push(F.install(q))}).catch(()=>{}),()=>{h=!0,E.forEach(I=>I())}},[q,S?JSON.stringify(S.map(h=>[h.name,h.schema??null,h.submit??!1,h.description??null])):""]),(0,s.useEffect)(()=>{const h=x.current;!h||!w.current||(h.scrollTop=h.scrollHeight)},[M]);const Ne=()=>{const h=x.current;h&&(w.current=!0,y(!0),h.scrollTop=h.scrollHeight)};(0,s.useEffect)(()=>{const h=M[M.length-1];h&&h.role==="assistant"&&h.status==="DONE"&&f&&f({id:h.id,content:h.content})},[M,f]),(0,s.useEffect)(()=>{J(!!V)},[M.length]),(0,s.useEffect)(()=>{const h=N.current;if(!v.compact||!h)return;const E=document.documentElement;if(v.state!=="peek")return;const I=()=>{E.style.setProperty("--ago-sheet-height",`${Math.round(h.getBoundingClientRect().height)}px`)};I();const F=typeof ResizeObserver=="function"?new ResizeObserver(I):null;return F?.observe(h),()=>F?.disconnect()},[v.compact,v.state]),(0,s.useEffect)(()=>{v.compact||document.documentElement.style.removeProperty("--ago-sheet-height")},[v.compact]),(0,s.useEffect)(()=>()=>{document.documentElement.style.removeProperty("--ago-sheet-height")},[]),(0,s.useImperativeHandle)(m,()=>({expand:T,collapse:H,toggle:ne,state:v.state}),[T,H,ne,v.state]),(0,s.useEffect)(()=>{if(!v.isModal)return;const h=Symbol("ago-react-sheet");Y.lockBackgroundScroll(h);const E=I=>{if(I.key==="Escape"){H("user");return}if(I.key!=="Tab")return;const F=N.current;if(!F)return;const K=Array.from(F.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(Fe=>Fe.getClientRects().length>0);if(K.length===0){I.preventDefault();return}const ie=K[0],le=K[K.length-1],U=document.activeElement;I.shiftKey&&(U===ie||!F.contains(U))?(I.preventDefault(),le.focus()):!I.shiftKey&&(U===le||!F.contains(U))&&(I.preventDefault(),ie.focus())};return document.addEventListener("keydown",E),N.current?.focus({preventScroll:!0}),()=>{document.removeEventListener("keydown",E),Y.unlockBackgroundScroll(h)}},[v.isModal,H]);const oe=async(h,E)=>(w.current=!0,y(!0),_?.(h),await Re(h,E)!==null),O=M[M.length-1],$=_e&&O?.role==="assistant"&&(O.status==="IN_PROGRESS"||O.status==="WAITING_CLIENT"),Ee=(0,s.useCallback)(h=>{const E=h.functionName;if(!(!d||!E))return typeof d=="function"?d(E,h.arguments??{}):d[E]},[d]),{items:Me}=xe({client:q??void 0,labelFor:Ee,includeReasoning:b}),se=Me.filter(h=>O?.id!==void 0&&h.messageId===O.id),B=d===!1?void 0:se[se.length-1]?.label,ae=!!($&&B),Te=R===!1?void 0:R??(h=>oe(h));return(0,a.jsxs)("div",{ref:N,className:`ago-chat-widget ${k}`,...v.surface.attrs,"data-ago-sheet-state":v.compact?v.state:void 0,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",...v.surface.style},children:[!v.compact&&(0,a.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[p&&(0,a.jsx)("img",{src:p,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,a.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:o})]}),V&&(0,a.jsxs)("button",{type:"button",className:"ago-chat-widget__peek","aria-expanded":!1,"aria-label":"Open the conversation",onClick:()=>{J(!1),T("user")},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:"8px",padding:"14px 18px 10px",border:"none",borderBottom:"1px solid currentColor",borderBottomColor:"rgba(128,128,128,0.25)",background:"transparent",textAlign:"left",cursor:"pointer",font:"inherit",color:"inherit"},children:[(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7},children:[o,je&&(0,a.jsx)("span",{"aria-label":"New message",style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#1b5fc4"}}),(0,a.jsx)("span",{style:{marginLeft:"auto",fontSize:"14px"},"aria-hidden":!0,children:"↑"})]}),$&&!O?.content?(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[!B&&(0,a.jsx)(ve,{}),(0,a.jsx)("span",{style:{fontSize:"13px",opacity:.7,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:B?he(B):C})]}):(0,a.jsx)("span",{style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:"13px",lineHeight:1.5,color:"inherit",minHeight:"calc(2 * 1.5 * 13px)"},children:O?.content||r})]}),v.compact&&v.state==="full"&&(0,a.jsxs)("div",{className:"ago-chat-widget__sheet-header",style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px 6px 18px",borderBottom:"1px solid rgba(128,128,128,0.25)",flexShrink:0},children:[(0,a.jsx)("span",{style:{fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:o}),(0,a.jsx)("button",{type:"button","aria-label":"Collapse the conversation",onClick:()=>H("user"),style:{marginLeft:"auto",flexShrink:0,width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:"inherit",cursor:"pointer"},children:(0,a.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M6 9l6 6 6-6"})})})]}),(0,a.jsxs)("div",{style:{position:"relative",flex:1,display:V?"none":"flex",minHeight:0},children:[(0,a.jsxs)("div",{ref:x,className:"ago-chat-widget__messages",onScroll:h=>{const E=h.currentTarget,I=E.scrollHeight-E.scrollTop-E.clientHeight<=48;w.current=I,y(I)},role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,"aria-busy":$,style:{flex:1,overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:"#fbfbfb"},children:[M.length===0?(0,a.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:r}):M.map((h,E)=>(0,a.jsx)(Ce,{message:h,showAgentName:g,isLast:E===M.length-1,onFollowUpClick:Te,showStreamingDots:!ae},h.id)),ae&&(0,a.jsx)(Ze,{label:B??""}),re&&(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:re.message}),(0,a.jsx)("div",{})]}),!j&&(0,a.jsx)("button",{type:"button",className:"ago-chat-widget__jump","aria-label":"Jump to latest message",onClick:Ne,style:{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid #dee3e8",borderRadius:"50%",backgroundColor:"#fff",color:"#0b1b2b",boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:2},children:(0,a.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M12 5v14M19 12l-7 7-7-7"})})})]}),(0,a.jsx)(ye,{onSend:oe,onStop:l?()=>{Ie()}:void 0,disabled:$,placeholder:c,allowFiles:i})]})});function we(e={}){const n=W(),t=e.client??n;if(!t)throw new P.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[o,r]=(0,s.useState)(null),c=(0,s.useRef)(o);c.current=o;const i=(0,s.useRef)(e.onExpand);return i.current=e.onExpand,(0,s.useEffect)(()=>{const l=p=>{r(p),t.proactive?.shown(p)},u=({nudge:p})=>{r(g=>g?.id===p.id?null:g)};return t.on("nudge:ready",l),t.on("nudge:accepted",u),t.on("nudge:dismissed",u),()=>{t.off("nudge:ready",l),t.off("nudge:accepted",u),t.off("nudge:dismissed",u)}},[t]),{nudge:o,accept:(0,s.useCallback)(async()=>{const l=c.current;l&&(r(null),await t.proactive?.accept(l),(l.source==="agent"||l.goal)&&i.current?.(l))},[t]),dismiss:(0,s.useCallback)(()=>{const l=c.current;l&&(r(null),t.proactive?.dismiss(l))},[t])}}var ht=({client:e,onExpand:n,autoHideMs:t,position:o="bottom-right",openChatLabel:r="Open chat",className:c=""})=>{const{nudge:i,accept:l,dismiss:u}=we({client:e,onExpand:n});if((0,s.useEffect)(()=>{if(!i||!t)return;const g=setTimeout(()=>u(),t);return()=>clearTimeout(g)},[i,t,u]),!i)return null;const p=i.source==="agent"||!!i.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${c}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...o==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,a.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:u,style:{position:"absolute",top:"6px",right:"8px",border:"none",background:"transparent",color:"#6b6d6f",fontSize:"16px",lineHeight:1,cursor:"pointer",padding:"4px"},children:"×"}),(0,a.jsx)("div",{className:"ago-nudge__message",style:{paddingRight:"16px"},children:i.message}),(i.action||p)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[i.action&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{l()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:i.action.label}),p&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{l()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:r})]})]})};function ke({client:e,autoLoad:n=!0}={}){const t=W(),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,c]=(0,s.useState)([]),[i,l]=(0,s.useState)(null),[u,p]=(0,s.useState)(!1),[g,S]=(0,s.useState)(null),R=(0,s.useCallback)(async()=>{p(!0),S(null);try{const{data:f}=await o.getConversations();c(f)}catch(f){S(f instanceof Error?f:new Error("Failed to load conversations"))}finally{p(!1)}},[o]),k=(0,s.useCallback)(async f=>{p(!0),S(null);try{l(await o.getConversation(f))}catch(A){S(A instanceof Error?A:new Error("Failed to load conversation"))}finally{p(!1)}},[o]),_=(0,s.useCallback)(()=>{l(null)},[]);return(0,s.useEffect)(()=>{n&&R()},[n,R]),{conversations:r,currentConversation:i,isLoading:u,error:g,selectConversation:k,startNewConversation:_,refreshConversations:R}}function yt(e={}){const n=W(),t=e.client||n;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const o=te({client:t,conversationId:e.conversationId}),r=ke({client:t,autoLoad:e.autoLoad});return{messages:o.messages,isLoading:o.isLoading,error:o.error||r.error,sendMessage:o.sendMessage,stop:o.stop,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 bt(e,n){const t=D(),{name:o,description:r,parameters:c,handler:i,maxResultBytes:l,requiresApproval:u}=typeof e=="string"?{name:e,...n}:e,p=(0,s.useRef)(i);p.current=i,(0,s.useEffect)(()=>{const g=S=>p.current(S);return t.registerFunction(o,g,{description:r,parameters:c,maxResultBytes:l,requiresApproval:u}),()=>{t.unregisterFunction(o)}},[t,o,r,c,l,u])}function vt(e,n){const t=D(),o=(0,s.useRef)(e);o.current=e,(0,s.useEffect)(()=>(t.registerNavigationFunction(r=>o.current(r),n),()=>{t.unregisterNavigationFunction()}),[t,n])}function Ct(e,n){const t=D(),o=n?.functionName??"setPageState",r=n?.requiresApproval,c=n?.data!==void 0,i=n?.data?.description,l=n?.data?.maxResultBytes,u=n?.settleTimeoutMs,p=(0,s.useRef)(e);p.current=e;const g=(0,s.useRef)(n);g.current=n,(0,s.useEffect)(()=>{const S=p.current.map(k=>{const _=()=>p.current.find(f=>f.name===k.name)??k;return{name:k.name,description:k.description,schema:k.schema,get:k.get?()=>_().get?.():void 0,set:f=>_().set(f)}}),R=c?{description:i??"What the page is currently showing.",maxResultBytes:l,get:()=>g.current?.data?.get(),isLoading:()=>g.current?.data?.isLoading?.()??!1}:void 0;return t.registerPageStateFunction(S,{functionName:o,requiresApproval:r,data:R,settleTimeoutMs:u}),()=>{t.unregisterPageStateFunction(o)}},[t,o,r,c,i,l,u])}function wt(e){const n=D(),t=(0,s.useRef)(e);t.current=e,(0,s.useEffect)(()=>qe.attachAutoContinueAfterNavigation(n,()=>t.current),[n])}function kt(e={}){const n=W(),t=e.client||n;if(!t)throw new P.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[o,r]=(0,s.useState)(()=>t.getRecentActivity());(0,s.useEffect)(()=>{r(t.getRecentActivity());const l=()=>r(t.getRecentActivity());return t.on("activity:recorded",l),()=>t.off("activity:recorded",l)},[t]);const c=(0,s.useCallback)(l=>t.recordActivity(l),[t]),i=(0,s.useCallback)(()=>{t.clearActivity(),r([])},[t]);return{entries:o,latest:o.length>0?o[o.length-1]:void 0,record:c,clear:i}}function St(e,n){const t=D(),o=(0,s.useId)(),r=n??o,c=(0,s.useRef)(e);c.current=e;const i=typeof e=="function";(0,s.useEffect)(()=>{if(typeof c.current=="function"){const l=()=>c.current();return t.addDynamicContext(r,l),()=>{t.removeDynamicContext(r)}}return t.setContext(r,c.current),()=>{t.removeContext(r)}},[t,r,i,i?"":JSON.stringify(e)])}function Se(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var fe={missing:[],complete:!1};function jt(e){const n=D(),t=e.schema!=null,o=JSON.stringify(e.schema??null),r=e.submit,c=r?typeof r=="string"?`client:${r}`:r.via==="backend"?"backend":"handler"in r?"client:handler":`client:${r.url}`:"none",i=JSON.stringify(e.initialValues??null),l=(0,s.useMemo)(()=>t?z.createFormCollector(e):null,[t,e.name,o,c,i,e.autoSubmit]),[u,p]=(0,s.useState)({collector:null,loading:!t,error:null});(0,s.useEffect)(()=>{if(t)return;let d=!1;return p({collector:null,loading:!0,error:null}),z.loadFormCollector(n,e).then(b=>{d||p({collector:b,loading:!1,error:null})}).catch(b=>{d||p({collector:null,loading:!1,error:b instanceof Error?b:new Error(String(b))})}),()=>{d=!0}},[n,t,e.name,c,i,e.autoSubmit]);const g=t?l:u.collector,S=t?!1:u.loading,R=t?null:u.error;(0,s.useEffect)(()=>{if(g)return g.install(n)},[n,g]);const k=(0,s.useMemo)(()=>P.createStore({values:e.initialValues??{},submitted:!1}),[i]),_=Se(g?.store??k),f=(0,s.useMemo)(()=>g?.getStatus()??fe,[_,g]),A=(0,s.useMemo)(()=>({..._,...f}),[_,f]),C=(0,s.useMemo)(()=>({name:e.name,store:k,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>k.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>fe}),[e.name,k]);return{...g??C,state:A,loading:S,error:R}}exports.AgoNudge=ht;exports.AgoProvider=$e;exports.ChatInput=ye;exports.ChatWidget=mt;exports.Markdown=be;exports.Message=Ce;exports.__exportAll=Le;exports.createFormCollector=z.createFormCollector;exports.createMockClient=Be.createMockClient;exports.deriveFormStatus=z.deriveFormStatus;exports.loadFormCollector=z.loadFormCollector;exports.useAgo=pe;exports.useAgoActivity=xe;exports.useAgoActivityLog=kt;exports.useAgoAutoContinueAfterNavigation=wt;exports.useAgoClient=D;exports.useAgoContext=St;exports.useAgoFunction=bt;exports.useAgoNavigation=vt;exports.useAgoPageState=Ct;exports.useAgoStore=Se;exports.useChat=yt;exports.useConversation=ke;exports.useFormCollector=jt;exports.useMessages=te;exports.useOptionalAgoClient=W;exports.useProactiveNudge=we;exports.useSheet=me;
|
|
44
|
+
`})]}),Ae=({message:e,className:n="",showAgentName:t=!1,isLast:s=!1,onFollowUpClick:r,showStreamingDots:c=!0,feedback:l})=>{const i=e.role==="user",d=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,a.jsxs)("div",{className:`ago-message ago-message--${e.role} ${n}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,a.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!i&&e.sources&&e.sources.length>0&&(0,a.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((u,p)=>(0,a.jsx)(Ct,{source:u,index:p},u.id))}),e.attachments&&e.attachments.length>0&&(0,a.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:i?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(u=>(0,a.jsx)(vt,{attachment:u,isUser:i},u.id))}),(e.content||d&&c)&&(0,a.jsx)("div",{className:"ago-message__content",style:{maxWidth:i?"75%":"100%",padding:i?"10px 14px":"2px 8px",borderRadius:i?"16px":"0",backgroundColor:i?"#03182f":"transparent",color:i?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,a.jsx)(ke,{content:e.content}):d&&c&&(0,a.jsx)(Se,{})}),!i&&l,s&&e.followUpReplies&&e.followUpReplies.length>0&&(0,a.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((u,p)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!r,onClick:r?()=>r(u):void 0,style:{minHeight:"44px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:r?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:C=>{C.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:C=>{C.currentTarget.style.borderColor="#dee3e8"},children:u},p))})]})};function je({client:e}={}){const n=W(),t=e||n;if(!t)throw new V.AgoError("useFeedback requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","missing_client");const[s,r]=(0,o.useState)({}),[c,l]=(0,o.useState)(!1),[i,d]=(0,o.useState)(null),u=(0,o.useRef)(new Map),p=A=>{const x=(u.current.get(A)??0)+1;return u.current.set(A,x),x},C=(A,x)=>u.current.get(A)===x;return{ratings:s,submitFeedback:(0,o.useCallback)(async(A,x,R)=>{const f=p(A);l(!0),d(null);try{await t.submitFeedback(A,x,R),C(A,f)&&r(w=>({...w,[A]:x}))}catch(w){const b=w instanceof Error?w:new Error("Failed to submit feedback");throw d(b),b}finally{l(!1)}},[t]),submitConversationFeedback:(0,o.useCallback)(async(A,x,R)=>{const f=p(A);l(!0),d(null);try{const w=await t.submitConversationFeedback(A,x,R);return C(A,f)&&r(b=>({...b,[w]:x})),w}catch(w){const b=w instanceof Error?w:new Error("Failed to submit feedback");throw d(b),b}finally{l(!1)}},[t]),isSubmitting:c,error:i}}var te={helpful:"Helpful",notHelpful:"Not helpful",whatWentWrong:"What went wrong?",reasons:{inaccurate:"Inaccurate",incomplete:"Incomplete",information_not_found:"Information not found",technical_issue:"Technical issue"},commentPlaceholder:"Anything else? (optional)",send:"Send",thanks:"Thanks, this was reported."},wt={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:0,border:"none",borderRadius:"8px",background:"transparent",cursor:"pointer",lineHeight:1},_e=({messageId:e,client:n,askWhy:t=!0,labels:s,onSubmit:r,onError:c,className:l=""})=>{const i={...te,...s,reasons:{...te.reasons,...s?.reasons}},{ratings:d,submitFeedback:u}=je({client:n}),p=d[e],[C,A]=(0,o.useState)(!1),[x,R]=(0,o.useState)([]),[f,w]=(0,o.useState)(""),[b,g]=(0,o.useState)(!1),[h,v]=(0,o.useState)(!1),m=async(S,_)=>{try{return await u(e,S,_),r?.({messageId:e,rating:S,reasons:_?.reasons??[],comment:_?.comment||void 0}),!0}catch(T){return c?.(T instanceof Error?T:new Error(String(T))),!1}},j=S=>{m(S),A(S==="negative"&&t&&!b)},E=S=>{R(_=>_.includes(S)?_.filter(T=>T!==S):[..._,S])},k=x.length>0||f.trim().length>0,N=()=>{!k||h||(v(!0),m(p??"negative",{reasons:x,comment:f.trim()}).then(S=>{v(!1),S&&(g(!0),A(!1))}))};return(0,a.jsxs)("div",{className:`ago-feedback ${l}`,style:{marginTop:"6px",width:"100%",maxWidth:"85%"},children:[(0,a.jsxs)("div",{className:"ago-feedback__actions",style:{display:"flex",alignItems:"center",gap:"2px"},children:[(0,a.jsx)(xe,{direction:"up",label:i.helpful,selected:p==="positive",onClick:()=>j("positive")}),(0,a.jsx)(xe,{direction:"down",label:i.notHelpful,selected:p==="negative",onClick:()=>j("negative")})]}),b&&(0,a.jsx)("div",{className:"ago-feedback__thanks",role:"status",style:{marginTop:"6px",fontSize:"13px",color:"#6b6d6f"},children:i.thanks}),C&&!b&&(0,a.jsxs)("div",{className:"ago-feedback__panel",role:"group","aria-label":i.whatWentWrong,style:{marginTop:"8px",padding:"12px",border:"1px solid #dee3e8",borderRadius:"16px",backgroundColor:"#fff"},children:[(0,a.jsx)("div",{style:{fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"8px"},children:i.whatWentWrong}),(0,a.jsx)("div",{className:"ago-feedback__reasons",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"},children:D.FEEDBACK_REASONS.map(S=>{const _=x.includes(S);return(0,a.jsx)("button",{type:"button",className:"ago-feedback__reason","aria-pressed":_,onClick:()=>E(S),style:{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${_?"#1b5fc4":"#dee3e8"}`,backgroundColor:"transparent",color:_?"#1b5fc4":"#30373e",cursor:"pointer"},children:i.reasons[S]},S)})}),(0,a.jsx)("textarea",{className:"ago-feedback__comment",rows:2,value:f,placeholder:i.commentPlaceholder,"aria-label":i.commentPlaceholder,onChange:S=>w(S.target.value),style:{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:"#30373e",border:"1px solid #dee3e8",borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}}),(0,a.jsx)("button",{type:"button",className:"ago-feedback__send",onClick:N,disabled:!k||h,style:{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:k?"#03182f":"#b5bfc8",color:"#fff",opacity:h?.6:1,cursor:k&&!h?"pointer":"default"},children:i.send})]})]})},xe=({direction:e,label:n,selected:t,onClick:s})=>(0,a.jsx)("button",{type:"button",className:`ago-feedback__thumb ago-feedback__thumb--${e}`,"aria-label":n,"aria-pressed":t,title:n,onClick:s,style:{...wt,color:t?"#1b5fc4":"#6b6d6f"},children:(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:e==="down"?{transform:"rotate(180deg)"}:void 0,children:[(0,a.jsx)("path",{d:"M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"}),(0,a.jsx)("path",{d:"M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"})]})}),kt=(0,o.forwardRef)(function({client:n,conversationId:t,title:s="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:c="Type a message...",allowFiles:l=!1,allowStop:i=!0,height:d=500,logoUrl:u,showAgentName:p=!1,forms:C,feedback:A=!1,onFollowUpClick:x,className:R="",onMessageSent:f,onMessageReceived:w,sheet:b=!1,thinkingLabel:g="Thinking...",functionLabels:h,showReasoning:v=!0},m){const j=(0,o.useRef)(null),E=(0,o.useRef)(!0),[k,N]=(0,o.useState)(!0),S=(0,o.useRef)(null),{sheet:_,expand:T,collapse:q,toggle:se}=ve(b),[Ie,Y]=(0,o.useState)(!1),X=_.compact&&_.state==="peek",Me=W(),B=n??Me,{messages:F,isLoading:Fe,error:ae,sendMessage:Te,stop:Pe}=oe({client:n,conversationId:t});(0,o.useEffect)(()=>{if(!B||!C||C.length===0)return;let y=!1;const M=[];return Promise.all(C.map(I=>I.schema!=null?Promise.resolve(O.createFormCollector(I)):O.loadFormCollector(B,I))).then(I=>{if(!y)for(const P of I)M.push(P.install(B))}).catch(()=>{}),()=>{y=!0,M.forEach(I=>I())}},[B,C?JSON.stringify(C.map(y=>[y.name,y.schema??null,y.submit??!1,y.description??null])):""]),(0,o.useEffect)(()=>{const y=j.current;!y||!E.current||(y.scrollTop=y.scrollHeight)},[F]);const We=()=>{const y=j.current;y&&(E.current=!0,N(!0),y.scrollTop=y.scrollHeight)};(0,o.useEffect)(()=>{const y=F[F.length-1];y&&y.role==="assistant"&&y.status==="DONE"&&w&&w({id:y.id,content:y.content})},[F,w]),(0,o.useEffect)(()=>{Y(!!X)},[F.length]),(0,o.useEffect)(()=>{const y=S.current;if(!_.compact||!y)return;const M=document.documentElement;if(_.state!=="peek")return;const I=()=>{M.style.setProperty("--ago-sheet-height",`${Math.round(y.getBoundingClientRect().height)}px`)};I();const P=typeof ResizeObserver=="function"?new ResizeObserver(I):null;return P?.observe(y),()=>P?.disconnect()},[_.compact,_.state]),(0,o.useEffect)(()=>{_.compact||document.documentElement.style.removeProperty("--ago-sheet-height")},[_.compact]),(0,o.useEffect)(()=>()=>{document.documentElement.style.removeProperty("--ago-sheet-height")},[]),(0,o.useImperativeHandle)(m,()=>({expand:T,collapse:q,toggle:se,state:_.state}),[T,q,se,_.state]),(0,o.useEffect)(()=>{if(!_.isModal)return;const y=Symbol("ago-react-sheet");Z.lockBackgroundScroll(y);const M=I=>{if(I.key==="Escape"){q("user");return}if(I.key!=="Tab")return;const P=S.current;if(!P)return;const U=Array.from(P.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(Le=>Le.getClientRects().length>0);if(U.length===0){I.preventDefault();return}const ue=U[0],de=U[U.length-1],G=document.activeElement;I.shiftKey&&(G===ue||!P.contains(G))?(I.preventDefault(),de.focus()):!I.shiftKey&&(G===de||!P.contains(G))&&(I.preventDefault(),ue.focus())};return document.addEventListener("keydown",M),S.current?.focus({preventScroll:!0}),()=>{document.removeEventListener("keydown",M),Z.unlockBackgroundScroll(y)}},[_.isModal,q]);const ie=async(y,M)=>(E.current=!0,N(!0),f?.(y),await Te(y,M)!==null),z=F[F.length-1],K=Fe&&z?.role==="assistant"&&(z.status==="IN_PROGRESS"||z.status==="WAITING_CLIENT"),De=(0,o.useCallback)(y=>{const M=y.functionName;if(!(!h||!M))return typeof h=="function"?h(M,y.arguments??{}):h[M]},[h]),{items:ze}=ye({client:B??void 0,labelFor:De,includeReasoning:v}),le=ze.filter(y=>z?.id!==void 0&&y.messageId===z.id),$=h===!1?void 0:le[le.length-1]?.label,ce=!!(K&&$),Oe=x===!1?void 0:x??(y=>ie(y));return(0,a.jsxs)("div",{ref:S,className:`ago-chat-widget ${R}`,..._.surface.attrs,"data-ago-sheet-state":_.compact?_.state:void 0,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px",..._.surface.style},children:[!_.compact&&(0,a.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[u&&(0,a.jsx)("img",{src:u,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,a.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),X&&(0,a.jsxs)("button",{type:"button",className:"ago-chat-widget__peek","aria-expanded":!1,"aria-label":"Open the conversation",onClick:()=>{Y(!1),T("user")},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:"8px",padding:"14px 18px 10px",border:"none",borderBottom:"1px solid currentColor",borderBottomColor:"rgba(128,128,128,0.25)",background:"transparent",textAlign:"left",cursor:"pointer",font:"inherit",color:"inherit"},children:[(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7},children:[s,Ie&&(0,a.jsx)("span",{"aria-label":"New message",style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#1b5fc4"}}),(0,a.jsx)("span",{style:{marginLeft:"auto",fontSize:"14px"},"aria-hidden":!0,children:"↑"})]}),K&&!z?.content?(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[!$&&(0,a.jsx)(Se,{}),(0,a.jsx)("span",{style:{fontSize:"13px",opacity:.7,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:$?Ce($):g})]}):(0,a.jsx)("span",{style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:"13px",lineHeight:1.5,color:"inherit",minHeight:"calc(2 * 1.5 * 13px)"},children:z?.content||r})]}),_.compact&&_.state==="full"&&(0,a.jsxs)("div",{className:"ago-chat-widget__sheet-header",style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px 6px 18px",borderBottom:"1px solid rgba(128,128,128,0.25)",flexShrink:0},children:[(0,a.jsx)("span",{style:{fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:s}),(0,a.jsx)("button",{type:"button","aria-label":"Collapse the conversation",onClick:()=>q("user"),style:{marginLeft:"auto",flexShrink:0,width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:"inherit",cursor:"pointer"},children:(0,a.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M6 9l6 6 6-6"})})})]}),(0,a.jsxs)("div",{style:{position:"relative",flex:1,display:X?"none":"flex",minHeight:0},children:[(0,a.jsxs)("div",{ref:j,className:"ago-chat-widget__messages",onScroll:y=>{const M=y.currentTarget,I=M.scrollHeight-M.scrollTop-M.clientHeight<=48;E.current=I,N(I)},role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,"aria-busy":K,style:{flex:1,overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:"#fbfbfb"},children:[F.length===0?(0,a.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:r}):F.map((y,M)=>(0,a.jsx)(Ae,{message:y,showAgentName:p,isLast:M===F.length-1,onFollowUpClick:Oe,showStreamingDots:!ce,feedback:A&&y.role==="assistant"&&y.status==="DONE"&&y.content?(0,a.jsx)(_e,{messageId:y.id,client:n,...A===!0?{}:A}):void 0},y.id)),ce&&(0,a.jsx)(ot,{label:$??""}),ae&&(0,a.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:ae.message}),(0,a.jsx)("div",{})]}),!k&&(0,a.jsx)("button",{type:"button",className:"ago-chat-widget__jump","aria-label":"Jump to latest message",onClick:We,style:{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid #dee3e8",borderRadius:"50%",backgroundColor:"#fff",color:"#0b1b2b",boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:2},children:(0,a.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M12 5v14M19 12l-7 7-7-7"})})})]}),(0,a.jsx)(we,{onSend:ie,onStop:i?()=>{Pe()}:void 0,disabled:K,placeholder:c,allowFiles:l})]})});function Ee(e={}){const n=W(),t=e.client??n;if(!t)throw new V.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[s,r]=(0,o.useState)(null),c=(0,o.useRef)(s);c.current=s;const l=(0,o.useRef)(e.onExpand);return l.current=e.onExpand,(0,o.useEffect)(()=>{const i=u=>{r(u),t.proactive?.shown(u)},d=({nudge:u})=>{r(p=>p?.id===u.id?null:p)};return t.on("nudge:ready",i),t.on("nudge:accepted",d),t.on("nudge:dismissed",d),()=>{t.off("nudge:ready",i),t.off("nudge:accepted",d),t.off("nudge:dismissed",d)}},[t]),{nudge:s,accept:(0,o.useCallback)(async()=>{const i=c.current;i&&(r(null),await t.proactive?.accept(i),(i.source==="agent"||i.goal)&&l.current?.(i))},[t]),dismiss:(0,o.useCallback)(()=>{const i=c.current;i&&(r(null),t.proactive?.dismiss(i))},[t])}}var St=({client:e,onExpand:n,autoHideMs:t,position:s="bottom-right",openChatLabel:r="Open chat",className:c=""})=>{const{nudge:l,accept:i,dismiss:d}=Ee({client:e,onExpand:n});if((0,o.useEffect)(()=>{if(!l||!t)return;const p=setTimeout(()=>d(),t);return()=>clearTimeout(p)},[l,t,d]),!l)return null;const u=l.source==="agent"||!!l.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${c}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...s==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,a.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:d,style:{position:"absolute",top:"6px",right:"8px",border:"none",background:"transparent",color:"#6b6d6f",fontSize:"16px",lineHeight:1,cursor:"pointer",padding:"4px"},children:"×"}),(0,a.jsx)("div",{className:"ago-nudge__message",style:{paddingRight:"16px"},children:l.message}),(l.action||u)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[l.action&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{i()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:l.action.label}),u&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{i()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:r})]})]})};function Re({client:e,autoLoad:n=!0}={}){const t=W(),s=e||t;if(!s)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,c]=(0,o.useState)([]),[l,i]=(0,o.useState)(null),[d,u]=(0,o.useState)(!1),[p,C]=(0,o.useState)(null),A=(0,o.useCallback)(async()=>{u(!0),C(null);try{const{data:f}=await s.getConversations();c(f)}catch(f){C(f instanceof Error?f:new Error("Failed to load conversations"))}finally{u(!1)}},[s]),x=(0,o.useCallback)(async f=>{u(!0),C(null);try{i(await s.getConversation(f))}catch(w){C(w instanceof Error?w:new Error("Failed to load conversation"))}finally{u(!1)}},[s]),R=(0,o.useCallback)(()=>{i(null)},[]);return(0,o.useEffect)(()=>{n&&A()},[n,A]),{conversations:r,currentConversation:l,isLoading:d,error:p,selectConversation:x,startNewConversation:R,refreshConversations:A}}function At(e={}){const n=W(),t=e.client||n;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const s=oe({client:t,conversationId:e.conversationId}),r=Re({client:t,autoLoad:e.autoLoad});return{messages:s.messages,isLoading:s.isLoading,error:s.error||r.error,sendMessage:s.sendMessage,stop:s.stop,clearMessages:s.clearMessages,conversationId:s.conversationId,conversations:r.conversations,currentConversation:r.currentConversation,isConversationsLoading:r.isLoading,selectConversation:r.selectConversation,startNewConversation:r.startNewConversation,refreshConversations:r.refreshConversations}}function jt(e,n){const t=L(),{name:s,description:r,parameters:c,handler:l,maxResultBytes:i,requiresApproval:d}=typeof e=="string"?{name:e,...n}:e,u=(0,o.useRef)(l);u.current=l,(0,o.useEffect)(()=>{const p=C=>u.current(C);return t.registerFunction(s,p,{description:r,parameters:c,maxResultBytes:i,requiresApproval:d}),()=>{t.unregisterFunction(s)}},[t,s,r,c,i,d])}function _t(e,n){const t=L(),s=(0,o.useRef)(e);s.current=e,(0,o.useEffect)(()=>(t.registerNavigationFunction(r=>s.current(r),n),()=>{t.unregisterNavigationFunction()}),[t,n])}function Et(e,n){const t=L(),s=n?.functionName??"setPageState",r=n?.requiresApproval,c=n?.data!==void 0,l=n?.data?.description,i=n?.data?.maxResultBytes,d=n?.settleTimeoutMs,u=(0,o.useRef)(e);u.current=e;const p=(0,o.useRef)(n);p.current=n,(0,o.useEffect)(()=>{const C=u.current.map(x=>{const R=()=>u.current.find(f=>f.name===x.name)??x;return{name:x.name,description:x.description,schema:x.schema,clearable:x.clearable,get:x.get?()=>R().get?.():void 0,set:f=>R().set(f)}}),A=c?{description:l??"What the page is currently showing.",maxResultBytes:i,get:()=>p.current?.data?.get(),isLoading:()=>p.current?.data?.isLoading?.()??!1}:void 0;return t.registerPageStateFunction(C,{functionName:s,requiresApproval:r,data:A,settleTimeoutMs:d}),()=>{t.unregisterPageStateFunction(s)}},[t,s,r,c,l,i,d,JSON.stringify(e.map(C=>({name:C.name,description:C.description,schema:C.schema,clearable:C.clearable})))])}function Rt(e){const n=L(),t=(0,o.useRef)(e);t.current=e,(0,o.useEffect)(()=>Je.attachAutoContinueAfterNavigation(n,()=>t.current),[n])}function Nt(e={}){const n=W(),t=e.client||n;if(!t)throw new V.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[s,r]=(0,o.useState)(()=>t.getRecentActivity());(0,o.useEffect)(()=>{r(t.getRecentActivity());const i=()=>r(t.getRecentActivity());return t.on("activity:recorded",i),()=>t.off("activity:recorded",i)},[t]);const c=(0,o.useCallback)(i=>t.recordActivity(i),[t]),l=(0,o.useCallback)(()=>{t.clearActivity(),r([])},[t]);return{entries:s,latest:s.length>0?s[s.length-1]:void 0,record:c,clear:l}}function It(e,n){const t=L(),s=(0,o.useId)(),r=n??s,c=(0,o.useRef)(e);c.current=e;const l=typeof e=="function";(0,o.useEffect)(()=>{if(typeof c.current=="function"){const i=()=>c.current();return t.addDynamicContext(r,i),()=>{t.removeDynamicContext(r)}}return t.setContext(r,c.current),()=>{t.removeContext(r)}},[t,r,l,l?"":JSON.stringify(e)])}function Ne(e){return(0,o.useSyncExternalStore)(e.subscribe,e.get,e.get)}var me={missing:[],complete:!1};function Mt(e){const n=L(),t=e.schema!=null,s=JSON.stringify(e.schema??null),r=e.submit,c=r?typeof r=="string"?`client:${r}`:r.via==="backend"?"backend":"handler"in r?"client:handler":`client:${r.url}`:"none",l=JSON.stringify(e.initialValues??null),i=(0,o.useMemo)(()=>t?O.createFormCollector(e):null,[t,e.name,s,c,l,e.autoSubmit]),[d,u]=(0,o.useState)({collector:null,loading:!t,error:null});(0,o.useEffect)(()=>{if(t)return;let g=!1;return u({collector:null,loading:!0,error:null}),O.loadFormCollector(n,e).then(h=>{g||u({collector:h,loading:!1,error:null})}).catch(h=>{g||u({collector:null,loading:!1,error:h instanceof Error?h:new Error(String(h))})}),()=>{g=!0}},[n,t,e.name,c,l,e.autoSubmit]);const p=t?i:d.collector,C=t?!1:d.loading,A=t?null:d.error;(0,o.useEffect)(()=>{if(p)return p.install(n)},[n,p]);const x=(0,o.useMemo)(()=>D.createStore({values:e.initialValues??{},submitted:!1}),[l]),R=Ne(p?.store??x),f=(0,o.useMemo)(()=>p?.getStatus()??me,[R,p]),w=(0,o.useMemo)(()=>({...R,...f}),[R,f]),b=(0,o.useMemo)(()=>({name:e.name,store:x,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>x.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>me}),[e.name,x]);return{...p??b,state:w,loading:C,error:A}}exports.AgoNudge=St;exports.AgoProvider=Ye;exports.ChatInput=we;exports.ChatWidget=kt;exports.DEFAULT_MESSAGE_FEEDBACK_LABELS=te;exports.FEEDBACK_REASONS=D.FEEDBACK_REASONS;exports.Markdown=ke;exports.Message=Ae;exports.MessageFeedback=_e;exports.__exportAll=Ue;exports.createFormCollector=O.createFormCollector;exports.createMockClient=Ve.createMockClient;exports.deriveFormStatus=O.deriveFormStatus;exports.loadFormCollector=O.loadFormCollector;exports.useAgo=he;exports.useAgoActivity=ye;exports.useAgoActivityLog=Nt;exports.useAgoAutoContinueAfterNavigation=Rt;exports.useAgoClient=L;exports.useAgoContext=It;exports.useAgoFunction=jt;exports.useAgoNavigation=_t;exports.useAgoPageState=Et;exports.useAgoStore=Ne;exports.useChat=At;exports.useConversation=Re;exports.useFeedback=je;exports.useFormCollector=Mt;exports.useMessages=oe;exports.useOptionalAgoClient=W;exports.useProactiveNudge=Ee;exports.useSheet=ve;
|