@useago/sdk 1.0.10 → 1.0.11
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/dist/react.cjs +3 -3
- package/dist/react.js +363 -341
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +25 -2
- package/dist/widget.d.ts +25 -2
- package/dist/widget.js +460 -412
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { i as
|
|
3
|
-
import { t as
|
|
4
|
-
import G, { createContext as V, useCallback as
|
|
5
|
-
import { Fragment as
|
|
1
|
+
import { t as q } from "./AgoClient-QcTtrN7u.js";
|
|
2
|
+
import { i as J, n as Me, r as z, t as W } from "./createFormCollector-CFt1_QSL.js";
|
|
3
|
+
import { t as Re } from "./createMockClient-DwdxNwEn.js";
|
|
4
|
+
import G, { createContext as V, useCallback as I, useContext as $, useEffect as k, useId as j, useMemo as T, useRef as A, useState as M, useSyncExternalStore as Y } from "react";
|
|
5
|
+
import { Fragment as X, jsx as a, jsxs as R } from "react/jsx-runtime";
|
|
6
6
|
import Q from "react-markdown";
|
|
7
7
|
import Z from "remark-gfm";
|
|
8
8
|
function ee(e) {
|
|
9
|
-
const [t, r] = M(!1), n =
|
|
9
|
+
const [t, r] = M(!1), n = A(null), s = T(() => {
|
|
10
10
|
if (n.current && (n.current.destroy(), n.current = null), !e) return null;
|
|
11
|
-
const
|
|
12
|
-
return n.current =
|
|
11
|
+
const i = new q(e);
|
|
12
|
+
return n.current = i, i;
|
|
13
13
|
}, [e?.baseUrl, e?.widgetId]);
|
|
14
|
-
return
|
|
14
|
+
return k(() => (r(!0), () => {
|
|
15
15
|
n.current?.destroy(), n.current = null;
|
|
16
|
-
}), [
|
|
16
|
+
}), [s]), k(() => {
|
|
17
17
|
n.current && e && n.current.updateConfig({
|
|
18
18
|
agent: e.agent,
|
|
19
19
|
defaultAgentId: e.defaultAgentId,
|
|
@@ -32,180 +32,186 @@ function ee(e) {
|
|
|
32
32
|
e?.debug,
|
|
33
33
|
e?.warnOnEmptyReply
|
|
34
34
|
]), {
|
|
35
|
-
client:
|
|
35
|
+
client: s,
|
|
36
36
|
isReady: t
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
var D = V(null), Te = ({ children: e, client: t, tools: r, helpers: n, pageContext:
|
|
40
|
-
const { client:
|
|
41
|
-
return
|
|
39
|
+
var D = V(null), Te = ({ children: e, client: t, tools: r, helpers: n, pageContext: s, ...i }) => {
|
|
40
|
+
const { client: u } = ee(t ? null : i), l = t || u;
|
|
41
|
+
return k(() => {
|
|
42
42
|
if (!(!r || r.length === 0)) {
|
|
43
|
-
for (const f of r)
|
|
43
|
+
for (const f of r) l.register(f);
|
|
44
44
|
return () => {
|
|
45
|
-
for (const f of r)
|
|
45
|
+
for (const f of r) l.unregisterFunction(f.name);
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
}, [
|
|
48
|
+
}, [l, r]), k(() => {
|
|
49
49
|
if (!n) return;
|
|
50
50
|
const f = [];
|
|
51
|
-
return import("./functions-CApuQZ2b.js").then((
|
|
52
|
-
for (const [
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
55
|
-
console.warn(`[AGO] Unknown helper: "${
|
|
51
|
+
return import("./functions-CApuQZ2b.js").then((d) => d.n).then((d) => {
|
|
52
|
+
for (const [y, m] of Object.entries(n)) {
|
|
53
|
+
const C = d[y];
|
|
54
|
+
if (!C) {
|
|
55
|
+
console.warn(`[AGO] Unknown helper: "${y}"`);
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
const
|
|
59
|
-
...
|
|
60
|
-
handler:
|
|
58
|
+
const g = m === !0 ? C : {
|
|
59
|
+
...C,
|
|
60
|
+
handler: m
|
|
61
61
|
};
|
|
62
|
-
|
|
62
|
+
l.register(g), f.push(g.name);
|
|
63
63
|
}
|
|
64
64
|
}), () => {
|
|
65
|
-
for (const
|
|
65
|
+
for (const d of f) l.unregisterFunction(d);
|
|
66
66
|
};
|
|
67
|
-
}, [
|
|
68
|
-
|
|
69
|
-
}, [
|
|
70
|
-
value:
|
|
67
|
+
}, [l, n]), k(() => {
|
|
68
|
+
s === "auto" && l.enableAutoPageContext();
|
|
69
|
+
}, [l, s]), /* @__PURE__ */ a(D.Provider, {
|
|
70
|
+
value: l,
|
|
71
71
|
children: e
|
|
72
72
|
});
|
|
73
73
|
};
|
|
74
74
|
function P() {
|
|
75
|
-
const e =
|
|
75
|
+
const e = $(D);
|
|
76
76
|
if (!e) throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');
|
|
77
77
|
return e;
|
|
78
78
|
}
|
|
79
79
|
function L() {
|
|
80
|
-
return
|
|
80
|
+
return $(D);
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function O({ client: e, conversationId: t } = {}) {
|
|
83
83
|
const r = L(), n = e || r;
|
|
84
84
|
if (!n) throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
|
|
85
|
-
const [
|
|
86
|
-
|
|
87
|
-
t && t !==
|
|
85
|
+
const [s, i] = M([]), [u, l] = M(t), [f, d] = M(!1), [y, m] = M(null);
|
|
86
|
+
k(() => {
|
|
87
|
+
t && t !== u && (l(t), C(t));
|
|
88
88
|
}, [t]);
|
|
89
|
-
const
|
|
89
|
+
const C = async (g) => {
|
|
90
90
|
try {
|
|
91
|
-
|
|
91
|
+
i(await n.getMessages(g));
|
|
92
92
|
} catch (b) {
|
|
93
|
-
|
|
93
|
+
m(b instanceof Error ? b : /* @__PURE__ */ new Error("Failed to load messages"));
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
-
return
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
}, b = (
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
return
|
|
103
|
-
...
|
|
104
|
-
content:
|
|
105
|
-
}] :
|
|
96
|
+
return k(() => {
|
|
97
|
+
const g = (p) => {
|
|
98
|
+
u || l(p.conversationId);
|
|
99
|
+
}, b = (p) => {
|
|
100
|
+
i((c) => {
|
|
101
|
+
const x = c[c.length - 1];
|
|
102
|
+
return x && x.id === p.messageId ? [...c.slice(0, -1), {
|
|
103
|
+
...x,
|
|
104
|
+
content: x.content + p.content
|
|
105
|
+
}] : c;
|
|
106
106
|
});
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
let
|
|
110
|
-
for (let
|
|
111
|
-
|
|
107
|
+
}, v = (p) => {
|
|
108
|
+
i((c) => {
|
|
109
|
+
let x = -1;
|
|
110
|
+
for (let S = c.length - 1; S >= 0; S--) if (c[S].role === "assistant" && c[S].status === "IN_PROGRESS") {
|
|
111
|
+
x = S;
|
|
112
112
|
break;
|
|
113
113
|
}
|
|
114
|
-
return
|
|
115
|
-
...
|
|
114
|
+
return x < 0 ? c : [
|
|
115
|
+
...c.slice(0, x),
|
|
116
116
|
{
|
|
117
|
-
...
|
|
118
|
-
...
|
|
117
|
+
...c[x],
|
|
118
|
+
...p
|
|
119
119
|
},
|
|
120
|
-
...
|
|
120
|
+
...c.slice(x + 1)
|
|
121
121
|
];
|
|
122
122
|
});
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
return
|
|
127
|
-
...
|
|
128
|
-
|
|
129
|
-
...
|
|
130
|
-
] : [...
|
|
131
|
-
}),
|
|
132
|
-
},
|
|
133
|
-
|
|
123
|
+
}, w = (p) => {
|
|
124
|
+
i((c) => {
|
|
125
|
+
const x = c.findIndex((S) => S.id === p.id);
|
|
126
|
+
return x >= 0 ? [
|
|
127
|
+
...c.slice(0, x),
|
|
128
|
+
p,
|
|
129
|
+
...c.slice(x + 1)
|
|
130
|
+
] : [...c, p];
|
|
131
|
+
}), d(!1);
|
|
132
|
+
}, o = (p) => {
|
|
133
|
+
m(new Error(p.error)), d(!1);
|
|
134
134
|
};
|
|
135
|
-
return n.on("message:start",
|
|
136
|
-
n.off("message:start",
|
|
135
|
+
return n.on("message:start", g), n.on("message:chunk", b), n.on("message:answer-complete", v), n.on("message:complete", w), n.on("message:error", o), () => {
|
|
136
|
+
n.off("message:start", g), n.off("message:chunk", b), n.off("message:answer-complete", v), n.off("message:complete", w), n.off("message:error", o);
|
|
137
137
|
};
|
|
138
|
-
}, [n,
|
|
139
|
-
messages:
|
|
138
|
+
}, [n, u]), {
|
|
139
|
+
messages: s,
|
|
140
140
|
isLoading: f,
|
|
141
|
-
error:
|
|
142
|
-
sendMessage:
|
|
143
|
-
|
|
144
|
-
const
|
|
141
|
+
error: y,
|
|
142
|
+
sendMessage: I(async (g, b) => {
|
|
143
|
+
d(!0), m(null);
|
|
144
|
+
const v = {
|
|
145
145
|
id: `temp-${Date.now()}`,
|
|
146
|
-
conversationId:
|
|
147
|
-
content:
|
|
146
|
+
conversationId: u || "",
|
|
147
|
+
content: g,
|
|
148
148
|
role: "user",
|
|
149
149
|
status: "DONE",
|
|
150
150
|
createdAt: /* @__PURE__ */ new Date()
|
|
151
|
-
},
|
|
151
|
+
}, w = {
|
|
152
152
|
id: `temp-assistant-${Date.now()}`,
|
|
153
|
-
conversationId:
|
|
153
|
+
conversationId: u || "",
|
|
154
154
|
content: "",
|
|
155
155
|
role: "assistant",
|
|
156
156
|
status: "IN_PROGRESS",
|
|
157
157
|
createdAt: /* @__PURE__ */ new Date()
|
|
158
158
|
};
|
|
159
|
-
|
|
160
|
-
...
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
i((o) => [
|
|
160
|
+
...o,
|
|
161
|
+
v,
|
|
162
|
+
w
|
|
163
163
|
]);
|
|
164
164
|
try {
|
|
165
|
-
const
|
|
166
|
-
conversationId:
|
|
165
|
+
const o = await n.sendMessage(g, {
|
|
166
|
+
conversationId: u,
|
|
167
167
|
files: b
|
|
168
168
|
});
|
|
169
|
-
return
|
|
170
|
-
const
|
|
171
|
-
...
|
|
172
|
-
id:
|
|
173
|
-
conversationId:
|
|
169
|
+
return o.conversationId && !u && l(o.conversationId), i((p) => {
|
|
170
|
+
const c = p.filter((S) => !S.id.startsWith("temp-")), x = {
|
|
171
|
+
...v,
|
|
172
|
+
id: v.id.replace("temp-", "user-"),
|
|
173
|
+
conversationId: o.conversationId
|
|
174
174
|
};
|
|
175
|
-
return
|
|
176
|
-
...
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
return c.some((S) => S.id === o.id) ? [...c, x].sort((S, _) => new Date(S.createdAt).getTime() - new Date(_.createdAt).getTime()) : [
|
|
176
|
+
...c,
|
|
177
|
+
x,
|
|
178
|
+
o
|
|
179
179
|
];
|
|
180
|
-
}),
|
|
181
|
-
} catch (
|
|
182
|
-
return
|
|
180
|
+
}), o;
|
|
181
|
+
} catch (o) {
|
|
182
|
+
return m(o instanceof Error ? o : /* @__PURE__ */ new Error("Failed to send message")), d(!1), i((p) => p.filter((c) => !c.id.startsWith("temp-"))), null;
|
|
183
183
|
}
|
|
184
|
-
}, [n,
|
|
185
|
-
clearMessages:
|
|
186
|
-
|
|
184
|
+
}, [n, u]),
|
|
185
|
+
clearMessages: I(() => {
|
|
186
|
+
i([]), l(void 0), m(null);
|
|
187
187
|
}, []),
|
|
188
|
-
conversationId:
|
|
188
|
+
conversationId: u
|
|
189
189
|
};
|
|
190
190
|
}
|
|
191
|
-
var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", allowFiles: n = !1, className:
|
|
192
|
-
const [
|
|
193
|
-
|
|
191
|
+
var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", allowFiles: n = !1, className: s = "" }) => {
|
|
192
|
+
const [i, u] = M(""), [l, f] = M([]), d = A(null), y = A(null), m = I(() => {
|
|
193
|
+
const o = y.current;
|
|
194
|
+
if (!o) return;
|
|
195
|
+
const p = 110;
|
|
196
|
+
o.style.height = "auto", o.style.height = `${Math.min(o.scrollHeight + 2, p)}px`, o.style.overflowY = o.scrollHeight + 2 > p ? "auto" : "hidden";
|
|
197
|
+
}, []), C = I((o) => {
|
|
198
|
+
o.preventDefault(), (i.trim() || l.length > 0) && (e(i.trim(), l.length > 0 ? l : void 0), u(""), f([]), requestAnimationFrame(m));
|
|
194
199
|
}, [
|
|
195
|
-
a,
|
|
196
200
|
i,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
f((
|
|
205
|
-
}, []),
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
201
|
+
l,
|
|
202
|
+
e,
|
|
203
|
+
m
|
|
204
|
+
]), g = I((o) => {
|
|
205
|
+
o.key === "Enter" && !o.shiftKey && (o.preventDefault(), C(o));
|
|
206
|
+
}, [C]), b = I((o) => {
|
|
207
|
+
const p = Array.from(o.target.files || []);
|
|
208
|
+
f((c) => [...c, ...p]);
|
|
209
|
+
}, []), v = I((o) => {
|
|
210
|
+
f((p) => p.filter((c, x) => x !== o));
|
|
211
|
+
}, []), w = i.trim() || l.length > 0;
|
|
212
|
+
return /* @__PURE__ */ R("form", {
|
|
213
|
+
onSubmit: C,
|
|
214
|
+
className: `ago-chat-input ${s}`,
|
|
209
215
|
style: {
|
|
210
216
|
display: "flex",
|
|
211
217
|
flexDirection: "column",
|
|
@@ -214,14 +220,14 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
214
220
|
borderTop: "1px solid #dee3e8",
|
|
215
221
|
backgroundColor: "#fff"
|
|
216
222
|
},
|
|
217
|
-
children: [
|
|
223
|
+
children: [l.length > 0 && /* @__PURE__ */ a("div", {
|
|
218
224
|
className: "ago-chat-input__files",
|
|
219
225
|
style: {
|
|
220
226
|
display: "flex",
|
|
221
227
|
flexWrap: "wrap",
|
|
222
228
|
gap: "6px"
|
|
223
229
|
},
|
|
224
|
-
children:
|
|
230
|
+
children: l.map((o, p) => /* @__PURE__ */ R("div", {
|
|
225
231
|
style: {
|
|
226
232
|
display: "flex",
|
|
227
233
|
alignItems: "center",
|
|
@@ -232,17 +238,18 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
232
238
|
fontSize: "12px",
|
|
233
239
|
color: "#30373e"
|
|
234
240
|
},
|
|
235
|
-
children: [/* @__PURE__ */
|
|
241
|
+
children: [/* @__PURE__ */ a("span", {
|
|
236
242
|
style: {
|
|
237
243
|
maxWidth: "120px",
|
|
238
244
|
overflow: "hidden",
|
|
239
245
|
textOverflow: "ellipsis",
|
|
240
246
|
whiteSpace: "nowrap"
|
|
241
247
|
},
|
|
242
|
-
children:
|
|
243
|
-
}), /* @__PURE__ */
|
|
248
|
+
children: o.name
|
|
249
|
+
}), /* @__PURE__ */ a("button", {
|
|
244
250
|
type: "button",
|
|
245
|
-
onClick: () =>
|
|
251
|
+
onClick: () => v(p),
|
|
252
|
+
"aria-label": `Remove ${o.name}`,
|
|
246
253
|
style: {
|
|
247
254
|
border: "none",
|
|
248
255
|
background: "none",
|
|
@@ -254,18 +261,19 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
254
261
|
},
|
|
255
262
|
children: "×"
|
|
256
263
|
})]
|
|
257
|
-
},
|
|
258
|
-
}), /* @__PURE__ */
|
|
264
|
+
}, p))
|
|
265
|
+
}), /* @__PURE__ */ R("div", {
|
|
259
266
|
style: {
|
|
260
267
|
display: "flex",
|
|
261
268
|
gap: "8px",
|
|
262
269
|
alignItems: "flex-end"
|
|
263
270
|
},
|
|
264
271
|
children: [
|
|
265
|
-
n && /* @__PURE__ */
|
|
272
|
+
n && /* @__PURE__ */ R(X, { children: [/* @__PURE__ */ a("button", {
|
|
266
273
|
type: "button",
|
|
267
|
-
onClick: () =>
|
|
274
|
+
onClick: () => d.current?.click(),
|
|
268
275
|
disabled: t,
|
|
276
|
+
"aria-label": "Attach file",
|
|
269
277
|
style: {
|
|
270
278
|
padding: "8px",
|
|
271
279
|
border: "1px solid #dee3e8",
|
|
@@ -277,18 +285,22 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
277
285
|
lineHeight: 1
|
|
278
286
|
},
|
|
279
287
|
children: "+"
|
|
280
|
-
}), /* @__PURE__ */
|
|
281
|
-
ref:
|
|
288
|
+
}), /* @__PURE__ */ a("input", {
|
|
289
|
+
ref: d,
|
|
282
290
|
type: "file",
|
|
283
291
|
multiple: !0,
|
|
284
|
-
onChange:
|
|
292
|
+
onChange: b,
|
|
285
293
|
style: { display: "none" }
|
|
286
294
|
})] }),
|
|
287
|
-
/* @__PURE__ */
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
295
|
+
/* @__PURE__ */ a("textarea", {
|
|
296
|
+
ref: y,
|
|
297
|
+
value: i,
|
|
298
|
+
onChange: (o) => {
|
|
299
|
+
u(o.target.value), m();
|
|
300
|
+
},
|
|
301
|
+
onKeyDown: g,
|
|
291
302
|
placeholder: r,
|
|
303
|
+
"aria-label": r,
|
|
292
304
|
disabled: t,
|
|
293
305
|
rows: 1,
|
|
294
306
|
style: {
|
|
@@ -298,29 +310,33 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
298
310
|
borderRadius: "20px",
|
|
299
311
|
resize: "none",
|
|
300
312
|
outline: "none",
|
|
313
|
+
boxSizing: "border-box",
|
|
314
|
+
maxHeight: "110px",
|
|
315
|
+
overflowY: "hidden",
|
|
301
316
|
fontFamily: "inherit",
|
|
302
317
|
fontSize: "16px",
|
|
318
|
+
lineHeight: 1.4,
|
|
303
319
|
color: "#30373e",
|
|
304
320
|
backgroundColor: "#f8f8f8",
|
|
305
321
|
transition: "border-color 0.15s"
|
|
306
322
|
},
|
|
307
|
-
onFocus: (
|
|
308
|
-
|
|
323
|
+
onFocus: (o) => {
|
|
324
|
+
o.currentTarget.style.borderColor = "#1b5fc4";
|
|
309
325
|
},
|
|
310
|
-
onBlur: (
|
|
311
|
-
|
|
326
|
+
onBlur: (o) => {
|
|
327
|
+
o.currentTarget.style.borderColor = "#dee3e8";
|
|
312
328
|
}
|
|
313
329
|
}),
|
|
314
|
-
/* @__PURE__ */
|
|
330
|
+
/* @__PURE__ */ a("button", {
|
|
315
331
|
type: "submit",
|
|
316
|
-
disabled: t || !
|
|
332
|
+
disabled: t || !w,
|
|
317
333
|
style: {
|
|
318
334
|
padding: "10px 18px",
|
|
319
335
|
border: "none",
|
|
320
336
|
borderRadius: "20px",
|
|
321
|
-
backgroundColor: t || !
|
|
337
|
+
backgroundColor: t || !w ? "#b5bfc8" : "#03182f",
|
|
322
338
|
color: "#fff",
|
|
323
|
-
cursor: t || !
|
|
339
|
+
cursor: t || !w ? "not-allowed" : "pointer",
|
|
324
340
|
fontWeight: 500,
|
|
325
341
|
fontSize: "16px",
|
|
326
342
|
transition: "background-color 0.15s"
|
|
@@ -330,7 +346,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
330
346
|
]
|
|
331
347
|
})]
|
|
332
348
|
});
|
|
333
|
-
}, ne = ({ href: e, children: t, ...r }) => /* @__PURE__ */
|
|
349
|
+
}, ne = ({ href: e, children: t, ...r }) => /* @__PURE__ */ a("a", {
|
|
334
350
|
href: e,
|
|
335
351
|
target: "_blank",
|
|
336
352
|
rel: "noopener noreferrer",
|
|
@@ -340,7 +356,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
340
356
|
},
|
|
341
357
|
...r,
|
|
342
358
|
children: t
|
|
343
|
-
}), re = ({ children: e, ...t }) => /* @__PURE__ */
|
|
359
|
+
}), re = ({ children: e, ...t }) => /* @__PURE__ */ a("p", {
|
|
344
360
|
style: {
|
|
345
361
|
margin: "0 0 8px 0",
|
|
346
362
|
lineHeight: "1.6"
|
|
@@ -348,17 +364,17 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
348
364
|
...t,
|
|
349
365
|
children: e
|
|
350
366
|
}), N = (e, t) => {
|
|
351
|
-
const r = ({ children: n, ...
|
|
367
|
+
const r = ({ children: n, ...s }) => G.createElement(`h${e}`, {
|
|
352
368
|
style: {
|
|
353
369
|
margin: "16px 0 8px 0",
|
|
354
370
|
fontSize: t,
|
|
355
371
|
fontWeight: 600,
|
|
356
372
|
lineHeight: "1.3"
|
|
357
373
|
},
|
|
358
|
-
...
|
|
374
|
+
...s
|
|
359
375
|
}, n);
|
|
360
376
|
return r.displayName = `MarkdownHeading${e}`, r;
|
|
361
|
-
}, oe = ({ children: e, ...t }) => /* @__PURE__ */
|
|
377
|
+
}, oe = ({ children: e, ...t }) => /* @__PURE__ */ a("ul", {
|
|
362
378
|
style: {
|
|
363
379
|
margin: "0 0 8px 0",
|
|
364
380
|
paddingLeft: "20px",
|
|
@@ -367,7 +383,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
367
383
|
},
|
|
368
384
|
...t,
|
|
369
385
|
children: e
|
|
370
|
-
}), se = ({ children: e, ...t }) => /* @__PURE__ */
|
|
386
|
+
}), se = ({ children: e, ...t }) => /* @__PURE__ */ a("ol", {
|
|
371
387
|
style: {
|
|
372
388
|
margin: "0 0 8px 0",
|
|
373
389
|
paddingLeft: "20px",
|
|
@@ -376,7 +392,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
376
392
|
},
|
|
377
393
|
...t,
|
|
378
394
|
children: e
|
|
379
|
-
}), ae = ({ children: e, ...t }) => /* @__PURE__ */
|
|
395
|
+
}), ae = ({ children: e, ...t }) => /* @__PURE__ */ a("li", {
|
|
380
396
|
style: {
|
|
381
397
|
display: "list-item",
|
|
382
398
|
margin: "2px 0",
|
|
@@ -385,7 +401,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
385
401
|
...t,
|
|
386
402
|
children: e
|
|
387
403
|
}), ie = ({ className: e, children: t, ...r }) => e !== void 0 || String(t).includes(`
|
|
388
|
-
`) ? /* @__PURE__ */
|
|
404
|
+
`) ? /* @__PURE__ */ a("code", {
|
|
389
405
|
style: {
|
|
390
406
|
display: "block",
|
|
391
407
|
background: "#f5f5f5",
|
|
@@ -397,7 +413,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
397
413
|
},
|
|
398
414
|
...r,
|
|
399
415
|
children: t
|
|
400
|
-
}) : /* @__PURE__ */
|
|
416
|
+
}) : /* @__PURE__ */ a("code", {
|
|
401
417
|
style: {
|
|
402
418
|
background: "#f0f2f5",
|
|
403
419
|
padding: "2px 5px",
|
|
@@ -407,11 +423,11 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
407
423
|
},
|
|
408
424
|
...r,
|
|
409
425
|
children: t
|
|
410
|
-
}), le = ({ children: e, ...t }) => /* @__PURE__ */
|
|
426
|
+
}), le = ({ children: e, ...t }) => /* @__PURE__ */ a("pre", {
|
|
411
427
|
style: { margin: "0 0 8px 0" },
|
|
412
428
|
...t,
|
|
413
429
|
children: e
|
|
414
|
-
}), ce = ({ children: e, ...t }) => /* @__PURE__ */
|
|
430
|
+
}), ce = ({ children: e, ...t }) => /* @__PURE__ */ a("blockquote", {
|
|
415
431
|
style: {
|
|
416
432
|
borderLeft: "4px solid #dee3e8",
|
|
417
433
|
paddingLeft: "12px",
|
|
@@ -421,12 +437,12 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
421
437
|
},
|
|
422
438
|
...t,
|
|
423
439
|
children: e
|
|
424
|
-
}), de = ({ children: e, ...t }) => /* @__PURE__ */
|
|
440
|
+
}), de = ({ children: e, ...t }) => /* @__PURE__ */ a("div", {
|
|
425
441
|
style: {
|
|
426
442
|
overflowX: "auto",
|
|
427
443
|
margin: "0 0 8px 0"
|
|
428
444
|
},
|
|
429
|
-
children: /* @__PURE__ */
|
|
445
|
+
children: /* @__PURE__ */ a("table", {
|
|
430
446
|
style: {
|
|
431
447
|
borderCollapse: "collapse",
|
|
432
448
|
width: "100%",
|
|
@@ -435,7 +451,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
435
451
|
...t,
|
|
436
452
|
children: e
|
|
437
453
|
})
|
|
438
|
-
}), ue = ({ children: e, ...t }) => /* @__PURE__ */
|
|
454
|
+
}), ue = ({ children: e, ...t }) => /* @__PURE__ */ a("th", {
|
|
439
455
|
style: {
|
|
440
456
|
border: "1px solid #dee3e8",
|
|
441
457
|
padding: "6px 10px",
|
|
@@ -445,14 +461,14 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
445
461
|
},
|
|
446
462
|
...t,
|
|
447
463
|
children: e
|
|
448
|
-
}), pe = ({ children: e, ...t }) => /* @__PURE__ */
|
|
464
|
+
}), pe = ({ children: e, ...t }) => /* @__PURE__ */ a("td", {
|
|
449
465
|
style: {
|
|
450
466
|
border: "1px solid #dee3e8",
|
|
451
467
|
padding: "6px 10px"
|
|
452
468
|
},
|
|
453
469
|
...t,
|
|
454
470
|
children: e
|
|
455
|
-
}), fe = ({ alt: e, ...t }) => /* @__PURE__ */
|
|
471
|
+
}), fe = ({ alt: e, ...t }) => /* @__PURE__ */ a("img", {
|
|
456
472
|
alt: e ?? "",
|
|
457
473
|
style: {
|
|
458
474
|
maxWidth: "100%",
|
|
@@ -460,7 +476,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
460
476
|
margin: "4px 0"
|
|
461
477
|
},
|
|
462
478
|
...t
|
|
463
|
-
}), ge = (e) => /* @__PURE__ */
|
|
479
|
+
}), ge = (e) => /* @__PURE__ */ a("hr", {
|
|
464
480
|
style: {
|
|
465
481
|
border: "none",
|
|
466
482
|
borderTop: "1px solid #dee3e8",
|
|
@@ -487,12 +503,12 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
487
503
|
td: pe,
|
|
488
504
|
img: fe,
|
|
489
505
|
hr: ge
|
|
490
|
-
}, xe = [Z], he = ({ content: e }) => /* @__PURE__ */
|
|
506
|
+
}, xe = [Z], he = ({ content: e }) => /* @__PURE__ */ a(Q, {
|
|
491
507
|
remarkPlugins: xe,
|
|
492
508
|
components: me,
|
|
493
509
|
children: e
|
|
494
510
|
}), ye = ({ source: e, index: t }) => {
|
|
495
|
-
const r = /* @__PURE__ */
|
|
511
|
+
const r = /* @__PURE__ */ R("div", {
|
|
496
512
|
style: {
|
|
497
513
|
display: "flex",
|
|
498
514
|
alignItems: "center",
|
|
@@ -500,7 +516,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
500
516
|
width: "100%",
|
|
501
517
|
minWidth: 0
|
|
502
518
|
},
|
|
503
|
-
children: [/* @__PURE__ */
|
|
519
|
+
children: [/* @__PURE__ */ a("div", {
|
|
504
520
|
style: {
|
|
505
521
|
flexShrink: 0,
|
|
506
522
|
width: "18px",
|
|
@@ -516,7 +532,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
516
532
|
backgroundColor: "#f0f4ff"
|
|
517
533
|
},
|
|
518
534
|
children: t + 1
|
|
519
|
-
}), /* @__PURE__ */
|
|
535
|
+
}), /* @__PURE__ */ a("div", {
|
|
520
536
|
style: {
|
|
521
537
|
fontSize: "12px",
|
|
522
538
|
overflow: "hidden",
|
|
@@ -540,23 +556,23 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
540
556
|
minWidth: 0,
|
|
541
557
|
transition: "border-color 0.15s"
|
|
542
558
|
};
|
|
543
|
-
return e.url ? /* @__PURE__ */
|
|
559
|
+
return e.url ? /* @__PURE__ */ a("a", {
|
|
544
560
|
href: e.url,
|
|
545
561
|
target: "_blank",
|
|
546
562
|
rel: "noopener noreferrer",
|
|
547
563
|
style: n,
|
|
548
|
-
onMouseEnter: (
|
|
549
|
-
|
|
564
|
+
onMouseEnter: (s) => {
|
|
565
|
+
s.currentTarget.style.borderColor = "#1b5fc4";
|
|
550
566
|
},
|
|
551
|
-
onMouseLeave: (
|
|
552
|
-
|
|
567
|
+
onMouseLeave: (s) => {
|
|
568
|
+
s.currentTarget.style.borderColor = "#dee3e8";
|
|
553
569
|
},
|
|
554
570
|
children: r
|
|
555
|
-
}) : /* @__PURE__ */
|
|
571
|
+
}) : /* @__PURE__ */ a("div", {
|
|
556
572
|
style: n,
|
|
557
573
|
children: r
|
|
558
574
|
});
|
|
559
|
-
}, be = () => /* @__PURE__ */
|
|
575
|
+
}, be = () => /* @__PURE__ */ R("div", {
|
|
560
576
|
style: {
|
|
561
577
|
display: "flex",
|
|
562
578
|
gap: "4px",
|
|
@@ -566,31 +582,31 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
566
582
|
0,
|
|
567
583
|
1,
|
|
568
584
|
2
|
|
569
|
-
].map((e) => /* @__PURE__ */
|
|
585
|
+
].map((e) => /* @__PURE__ */ a("div", { style: {
|
|
570
586
|
width: "6px",
|
|
571
587
|
height: "6px",
|
|
572
588
|
borderRadius: "50%",
|
|
573
589
|
backgroundColor: "#b5bfc8",
|
|
574
590
|
animation: "ago-pulse 1.2s ease-in-out infinite",
|
|
575
591
|
animationDelay: `${e * 0.2}s`
|
|
576
|
-
} }, e)), /* @__PURE__ */
|
|
592
|
+
} }, e)), /* @__PURE__ */ a("style", { children: `
|
|
577
593
|
@keyframes ago-pulse {
|
|
578
594
|
0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
|
|
579
595
|
40% { opacity: 1; transform: scale(1); }
|
|
580
596
|
}
|
|
581
597
|
` })]
|
|
582
|
-
}), ve = ({ message: e, className: t = "", showAgentName: r = !1, isLast: n = !1, onFollowUpClick:
|
|
583
|
-
const
|
|
584
|
-
return /* @__PURE__ */
|
|
598
|
+
}), ve = ({ message: e, className: t = "", showAgentName: r = !1, isLast: n = !1, onFollowUpClick: s }) => {
|
|
599
|
+
const i = e.role === "user", u = e.status === "IN_PROGRESS";
|
|
600
|
+
return /* @__PURE__ */ R("div", {
|
|
585
601
|
className: `ago-message ago-message--${e.role} ${t}`,
|
|
586
602
|
style: {
|
|
587
603
|
display: "flex",
|
|
588
604
|
flexDirection: "column",
|
|
589
|
-
alignItems:
|
|
605
|
+
alignItems: i ? "flex-end" : "flex-start",
|
|
590
606
|
marginBottom: "16px"
|
|
591
607
|
},
|
|
592
608
|
children: [
|
|
593
|
-
!
|
|
609
|
+
!i && r && e.agent && /* @__PURE__ */ a("div", {
|
|
594
610
|
className: "ago-message__agent",
|
|
595
611
|
style: {
|
|
596
612
|
display: "flex",
|
|
@@ -604,7 +620,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
604
620
|
},
|
|
605
621
|
children: e.agent.displayName || e.agent.name
|
|
606
622
|
}),
|
|
607
|
-
!
|
|
623
|
+
!i && e.sources && e.sources.length > 0 && /* @__PURE__ */ a("div", {
|
|
608
624
|
className: "ago-message__sources",
|
|
609
625
|
style: {
|
|
610
626
|
display: "grid",
|
|
@@ -614,26 +630,26 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
614
630
|
width: "100%",
|
|
615
631
|
maxWidth: "85%"
|
|
616
632
|
},
|
|
617
|
-
children: e.sources.map((
|
|
618
|
-
source:
|
|
633
|
+
children: e.sources.map((l, f) => /* @__PURE__ */ a(ye, {
|
|
634
|
+
source: l,
|
|
619
635
|
index: f
|
|
620
|
-
},
|
|
636
|
+
}, l.id))
|
|
621
637
|
}),
|
|
622
|
-
/* @__PURE__ */
|
|
638
|
+
/* @__PURE__ */ a("div", {
|
|
623
639
|
className: "ago-message__content",
|
|
624
640
|
style: {
|
|
625
|
-
maxWidth:
|
|
626
|
-
padding:
|
|
627
|
-
borderRadius:
|
|
628
|
-
backgroundColor:
|
|
629
|
-
color:
|
|
641
|
+
maxWidth: i ? "75%" : "100%",
|
|
642
|
+
padding: i ? "10px 14px" : "2px 8px",
|
|
643
|
+
borderRadius: i ? "16px" : "0",
|
|
644
|
+
backgroundColor: i ? "#03182f" : "transparent",
|
|
645
|
+
color: i ? "#fff" : "#30373e",
|
|
630
646
|
wordBreak: "break-word",
|
|
631
647
|
fontSize: "16px",
|
|
632
648
|
lineHeight: "1.6"
|
|
633
649
|
},
|
|
634
|
-
children: e.content ? /* @__PURE__ */
|
|
650
|
+
children: e.content ? /* @__PURE__ */ a(he, { content: e.content }) : u && /* @__PURE__ */ a(be, {})
|
|
635
651
|
}),
|
|
636
|
-
n && e.followUpReplies && e.followUpReplies.length > 0 && /* @__PURE__ */
|
|
652
|
+
n && e.followUpReplies && e.followUpReplies.length > 0 && /* @__PURE__ */ a("div", {
|
|
637
653
|
className: "ago-message__followups",
|
|
638
654
|
style: {
|
|
639
655
|
display: "flex",
|
|
@@ -641,71 +657,72 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
641
657
|
gap: "8px",
|
|
642
658
|
marginTop: "10px"
|
|
643
659
|
},
|
|
644
|
-
children: e.followUpReplies.map((
|
|
660
|
+
children: e.followUpReplies.map((l, f) => /* @__PURE__ */ a("button", {
|
|
645
661
|
type: "button",
|
|
646
662
|
className: "ago-message__followup-btn",
|
|
647
|
-
disabled: !
|
|
648
|
-
onClick:
|
|
663
|
+
disabled: !s,
|
|
664
|
+
onClick: s ? () => s(l) : void 0,
|
|
649
665
|
style: {
|
|
666
|
+
minHeight: "36px",
|
|
650
667
|
padding: "6px 14px",
|
|
651
668
|
fontSize: "13px",
|
|
652
669
|
borderRadius: "16px",
|
|
653
670
|
border: "1px solid #dee3e8",
|
|
654
671
|
backgroundColor: "#fff",
|
|
655
672
|
color: "#30373e",
|
|
656
|
-
cursor:
|
|
673
|
+
cursor: s ? "pointer" : "default",
|
|
657
674
|
transition: "border-color 0.15s"
|
|
658
675
|
},
|
|
659
|
-
onMouseEnter: (
|
|
660
|
-
|
|
676
|
+
onMouseEnter: (d) => {
|
|
677
|
+
d.currentTarget.style.borderColor = "#1b5fc4";
|
|
661
678
|
},
|
|
662
|
-
onMouseLeave: (
|
|
663
|
-
|
|
679
|
+
onMouseLeave: (d) => {
|
|
680
|
+
d.currentTarget.style.borderColor = "#dee3e8";
|
|
664
681
|
},
|
|
665
|
-
children:
|
|
682
|
+
children: l
|
|
666
683
|
}, f))
|
|
667
684
|
})
|
|
668
685
|
]
|
|
669
686
|
});
|
|
670
|
-
}, _e = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder:
|
|
671
|
-
const b =
|
|
687
|
+
}, _e = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: s = "Type a message...", allowFiles: i = !1, height: u = 500, logoUrl: l, showAgentName: f = !1, forms: d, onFollowUpClick: y, className: m = "", onMessageSent: C, onMessageReceived: g }) => {
|
|
688
|
+
const b = A(null), v = L(), w = e ?? v, { messages: o, isLoading: p, error: c, sendMessage: x } = O({
|
|
672
689
|
client: e,
|
|
673
690
|
conversationId: t
|
|
674
691
|
});
|
|
675
|
-
|
|
676
|
-
if (!
|
|
677
|
-
let
|
|
678
|
-
const
|
|
679
|
-
return Promise.all(
|
|
680
|
-
if (!
|
|
681
|
-
for (const U of
|
|
692
|
+
k(() => {
|
|
693
|
+
if (!w || !d || d.length === 0) return;
|
|
694
|
+
let h = !1;
|
|
695
|
+
const F = [];
|
|
696
|
+
return Promise.all(d.map((E) => E.schema != null ? Promise.resolve(W(E)) : z(w, E))).then((E) => {
|
|
697
|
+
if (!h)
|
|
698
|
+
for (const U of E) F.push(U.install(w));
|
|
682
699
|
}).catch(() => {
|
|
683
700
|
}), () => {
|
|
684
|
-
|
|
701
|
+
h = !0, F.forEach((E) => E());
|
|
685
702
|
};
|
|
686
|
-
}, [
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
])) : ""]),
|
|
703
|
+
}, [w, d ? JSON.stringify(d.map((h) => [
|
|
704
|
+
h.name,
|
|
705
|
+
h.schema ?? null,
|
|
706
|
+
h.submit ?? !1,
|
|
707
|
+
h.description ?? null
|
|
708
|
+
])) : ""]), k(() => {
|
|
692
709
|
b.current?.scrollIntoView({ behavior: "smooth" });
|
|
693
|
-
}, [
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
id:
|
|
697
|
-
content:
|
|
710
|
+
}, [o]), k(() => {
|
|
711
|
+
const h = o[o.length - 1];
|
|
712
|
+
h && h.role === "assistant" && h.status === "DONE" && g && g({
|
|
713
|
+
id: h.id,
|
|
714
|
+
content: h.content
|
|
698
715
|
});
|
|
699
|
-
}, [
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
}, _ =
|
|
703
|
-
return /* @__PURE__ */
|
|
704
|
-
className: `ago-chat-widget ${
|
|
716
|
+
}, [o, g]);
|
|
717
|
+
const S = async (h, F) => {
|
|
718
|
+
C?.(h), await x(h, F);
|
|
719
|
+
}, _ = o[o.length - 1], B = p && _?.role === "assistant" && _.status === "IN_PROGRESS", K = y === !1 ? void 0 : y ?? ((h) => S(h));
|
|
720
|
+
return /* @__PURE__ */ R("div", {
|
|
721
|
+
className: `ago-chat-widget ${m}`,
|
|
705
722
|
style: {
|
|
706
723
|
display: "flex",
|
|
707
724
|
flexDirection: "column",
|
|
708
|
-
height: typeof
|
|
725
|
+
height: typeof u == "number" ? `${u}px` : u,
|
|
709
726
|
border: "1px solid #dee3e8",
|
|
710
727
|
borderRadius: "16px",
|
|
711
728
|
overflow: "hidden",
|
|
@@ -715,7 +732,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
715
732
|
boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
|
|
716
733
|
},
|
|
717
734
|
children: [
|
|
718
|
-
/* @__PURE__ */
|
|
735
|
+
/* @__PURE__ */ R("div", {
|
|
719
736
|
className: "ago-chat-widget__header",
|
|
720
737
|
style: {
|
|
721
738
|
padding: "14px 16px",
|
|
@@ -726,14 +743,14 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
726
743
|
alignItems: "center",
|
|
727
744
|
gap: "10px"
|
|
728
745
|
},
|
|
729
|
-
children: [
|
|
730
|
-
src:
|
|
746
|
+
children: [l && /* @__PURE__ */ a("img", {
|
|
747
|
+
src: l,
|
|
731
748
|
alt: "Logo",
|
|
732
749
|
style: {
|
|
733
750
|
height: "24px",
|
|
734
751
|
width: "auto"
|
|
735
752
|
}
|
|
736
|
-
}), /* @__PURE__ */
|
|
753
|
+
}), /* @__PURE__ */ a("h3", {
|
|
737
754
|
style: {
|
|
738
755
|
margin: 0,
|
|
739
756
|
fontSize: "15px",
|
|
@@ -742,8 +759,12 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
742
759
|
children: r
|
|
743
760
|
})]
|
|
744
761
|
}),
|
|
745
|
-
/* @__PURE__ */
|
|
762
|
+
/* @__PURE__ */ R("div", {
|
|
746
763
|
className: "ago-chat-widget__messages",
|
|
764
|
+
role: "log",
|
|
765
|
+
"aria-live": "polite",
|
|
766
|
+
"aria-relevant": "additions text",
|
|
767
|
+
"aria-atomic": !1,
|
|
747
768
|
style: {
|
|
748
769
|
flex: 1,
|
|
749
770
|
overflow: "auto",
|
|
@@ -751,7 +772,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
751
772
|
backgroundColor: "#fbfbfb"
|
|
752
773
|
},
|
|
753
774
|
children: [
|
|
754
|
-
|
|
775
|
+
o.length === 0 ? /* @__PURE__ */ a("div", {
|
|
755
776
|
style: {
|
|
756
777
|
textAlign: "center",
|
|
757
778
|
color: "#6b6d6f",
|
|
@@ -760,13 +781,14 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
760
781
|
lineHeight: "1.5"
|
|
761
782
|
},
|
|
762
783
|
children: n
|
|
763
|
-
}) :
|
|
764
|
-
message:
|
|
784
|
+
}) : o.map((h, F) => /* @__PURE__ */ a(ve, {
|
|
785
|
+
message: h,
|
|
765
786
|
showAgentName: f,
|
|
766
|
-
isLast:
|
|
787
|
+
isLast: F === o.length - 1,
|
|
767
788
|
onFollowUpClick: K
|
|
768
|
-
},
|
|
769
|
-
|
|
789
|
+
}, h.id)),
|
|
790
|
+
c && /* @__PURE__ */ a("div", {
|
|
791
|
+
role: "alert",
|
|
770
792
|
style: {
|
|
771
793
|
padding: "10px 14px",
|
|
772
794
|
backgroundColor: "#fef2f2",
|
|
@@ -776,16 +798,16 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
776
798
|
fontSize: "13px",
|
|
777
799
|
border: "1px solid #fecaca"
|
|
778
800
|
},
|
|
779
|
-
children:
|
|
801
|
+
children: c.message
|
|
780
802
|
}),
|
|
781
|
-
/* @__PURE__ */
|
|
803
|
+
/* @__PURE__ */ a("div", { ref: b })
|
|
782
804
|
]
|
|
783
805
|
}),
|
|
784
|
-
/* @__PURE__ */
|
|
785
|
-
onSend:
|
|
806
|
+
/* @__PURE__ */ a(te, {
|
|
807
|
+
onSend: S,
|
|
786
808
|
disabled: B,
|
|
787
|
-
placeholder:
|
|
788
|
-
allowFiles:
|
|
809
|
+
placeholder: s,
|
|
810
|
+
allowFiles: i
|
|
789
811
|
})
|
|
790
812
|
]
|
|
791
813
|
});
|
|
@@ -793,175 +815,175 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
793
815
|
function we({ client: e, autoLoad: t = !0 } = {}) {
|
|
794
816
|
const r = L(), n = e || r;
|
|
795
817
|
if (!n) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
|
|
796
|
-
const [
|
|
797
|
-
|
|
818
|
+
const [s, i] = M([]), [u, l] = M(null), [f, d] = M(!1), [y, m] = M(null), C = I(async () => {
|
|
819
|
+
d(!0), m(null);
|
|
798
820
|
try {
|
|
799
|
-
|
|
800
|
-
} catch (
|
|
801
|
-
v
|
|
821
|
+
i(await n.getConversations());
|
|
822
|
+
} catch (v) {
|
|
823
|
+
m(v instanceof Error ? v : /* @__PURE__ */ new Error("Failed to load conversations"));
|
|
802
824
|
} finally {
|
|
803
|
-
|
|
825
|
+
d(!1);
|
|
804
826
|
}
|
|
805
|
-
}, [n]),
|
|
806
|
-
|
|
827
|
+
}, [n]), g = I(async (v) => {
|
|
828
|
+
d(!0), m(null);
|
|
807
829
|
try {
|
|
808
|
-
|
|
809
|
-
} catch (
|
|
810
|
-
|
|
830
|
+
l(await n.getConversation(v));
|
|
831
|
+
} catch (w) {
|
|
832
|
+
m(w instanceof Error ? w : /* @__PURE__ */ new Error("Failed to load conversation"));
|
|
811
833
|
} finally {
|
|
812
|
-
|
|
834
|
+
d(!1);
|
|
813
835
|
}
|
|
814
|
-
}, [n]), b =
|
|
815
|
-
|
|
836
|
+
}, [n]), b = I(() => {
|
|
837
|
+
l(null);
|
|
816
838
|
}, []);
|
|
817
|
-
return
|
|
818
|
-
t &&
|
|
819
|
-
}, [t,
|
|
820
|
-
conversations:
|
|
821
|
-
currentConversation:
|
|
839
|
+
return k(() => {
|
|
840
|
+
t && C();
|
|
841
|
+
}, [t, C]), {
|
|
842
|
+
conversations: s,
|
|
843
|
+
currentConversation: u,
|
|
822
844
|
isLoading: f,
|
|
823
|
-
error:
|
|
824
|
-
selectConversation:
|
|
845
|
+
error: y,
|
|
846
|
+
selectConversation: g,
|
|
825
847
|
startNewConversation: b,
|
|
826
|
-
refreshConversations:
|
|
848
|
+
refreshConversations: C
|
|
827
849
|
};
|
|
828
850
|
}
|
|
829
851
|
function Pe(e = {}) {
|
|
830
852
|
const t = L(), r = e.client || t;
|
|
831
853
|
if (!r) throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
|
|
832
|
-
const n =
|
|
854
|
+
const n = O({
|
|
833
855
|
client: r,
|
|
834
856
|
conversationId: e.conversationId
|
|
835
|
-
}),
|
|
857
|
+
}), s = we({
|
|
836
858
|
client: r,
|
|
837
859
|
autoLoad: e.autoLoad
|
|
838
860
|
});
|
|
839
861
|
return {
|
|
840
862
|
messages: n.messages,
|
|
841
863
|
isLoading: n.isLoading,
|
|
842
|
-
error: n.error ||
|
|
864
|
+
error: n.error || s.error,
|
|
843
865
|
sendMessage: n.sendMessage,
|
|
844
866
|
clearMessages: n.clearMessages,
|
|
845
867
|
conversationId: n.conversationId,
|
|
846
|
-
conversations:
|
|
847
|
-
currentConversation:
|
|
848
|
-
isConversationsLoading:
|
|
849
|
-
selectConversation:
|
|
850
|
-
startNewConversation:
|
|
851
|
-
refreshConversations:
|
|
868
|
+
conversations: s.conversations,
|
|
869
|
+
currentConversation: s.currentConversation,
|
|
870
|
+
isConversationsLoading: s.isLoading,
|
|
871
|
+
selectConversation: s.selectConversation,
|
|
872
|
+
startNewConversation: s.startNewConversation,
|
|
873
|
+
refreshConversations: s.refreshConversations
|
|
852
874
|
};
|
|
853
875
|
}
|
|
854
876
|
function Le(e, t) {
|
|
855
|
-
const r = P(), { name: n, description:
|
|
877
|
+
const r = P(), { name: n, description: s, parameters: i, handler: u } = typeof e == "string" ? {
|
|
856
878
|
name: e,
|
|
857
879
|
...t
|
|
858
|
-
} : e,
|
|
859
|
-
|
|
860
|
-
const f = (
|
|
880
|
+
} : e, l = A(u);
|
|
881
|
+
l.current = u, k(() => {
|
|
882
|
+
const f = (d) => l.current(d);
|
|
861
883
|
return r.registerFunction(n, f, {
|
|
862
|
-
description:
|
|
863
|
-
parameters:
|
|
884
|
+
description: s,
|
|
885
|
+
parameters: i
|
|
864
886
|
}), () => {
|
|
865
887
|
r.unregisterFunction(n);
|
|
866
888
|
};
|
|
867
889
|
}, [
|
|
868
890
|
r,
|
|
869
891
|
n,
|
|
870
|
-
|
|
871
|
-
|
|
892
|
+
s,
|
|
893
|
+
i
|
|
872
894
|
]);
|
|
873
895
|
}
|
|
874
896
|
function De(e, t) {
|
|
875
|
-
const r = P(), n =
|
|
876
|
-
n.current = e,
|
|
897
|
+
const r = P(), n = A(e);
|
|
898
|
+
n.current = e, k(() => (r.registerNavigationFunction((s) => n.current(s), t), () => {
|
|
877
899
|
r.unregisterFunction("navigateToPage");
|
|
878
900
|
}), [r, t]);
|
|
879
901
|
}
|
|
880
|
-
function
|
|
881
|
-
const r = P(), n = j(),
|
|
882
|
-
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
if (typeof
|
|
886
|
-
const
|
|
887
|
-
return r.addDynamicContext(
|
|
888
|
-
r.removeDynamicContext(
|
|
902
|
+
function He(e, t) {
|
|
903
|
+
const r = P(), n = j(), s = t ?? n, i = A(e);
|
|
904
|
+
i.current = e;
|
|
905
|
+
const u = typeof e == "function";
|
|
906
|
+
k(() => {
|
|
907
|
+
if (typeof i.current == "function") {
|
|
908
|
+
const l = () => i.current();
|
|
909
|
+
return r.addDynamicContext(s, l), () => {
|
|
910
|
+
r.removeDynamicContext(s);
|
|
889
911
|
};
|
|
890
912
|
}
|
|
891
|
-
return r.setContext(
|
|
892
|
-
r.removeContext(
|
|
913
|
+
return r.setContext(s, i.current), () => {
|
|
914
|
+
r.removeContext(s);
|
|
893
915
|
};
|
|
894
916
|
}, [
|
|
895
917
|
r,
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
918
|
+
s,
|
|
919
|
+
u,
|
|
920
|
+
u ? "" : JSON.stringify(e)
|
|
899
921
|
]);
|
|
900
922
|
}
|
|
901
923
|
function Ce(e) {
|
|
902
|
-
return
|
|
924
|
+
return Y(e.subscribe, e.get, e.get);
|
|
903
925
|
}
|
|
904
|
-
var
|
|
926
|
+
var H = {
|
|
905
927
|
missing: [],
|
|
906
928
|
complete: !1
|
|
907
929
|
};
|
|
908
930
|
function ze(e) {
|
|
909
|
-
const t = P(), r = e.schema != null, n = JSON.stringify(e.schema ?? null),
|
|
931
|
+
const t = P(), r = e.schema != null, n = JSON.stringify(e.schema ?? null), s = e.submit, i = s ? typeof s == "string" ? `client:${s}` : s.via === "backend" ? "backend" : "handler" in s ? "client:handler" : `client:${s.url}` : "none", u = JSON.stringify(e.initialValues ?? null), l = T(() => r ? W(e) : null, [
|
|
910
932
|
r,
|
|
911
933
|
e.name,
|
|
912
934
|
n,
|
|
913
|
-
|
|
914
|
-
|
|
935
|
+
i,
|
|
936
|
+
u,
|
|
915
937
|
e.autoSubmit
|
|
916
|
-
]), [f,
|
|
938
|
+
]), [f, d] = M({
|
|
917
939
|
collector: null,
|
|
918
940
|
loading: !r,
|
|
919
941
|
error: null
|
|
920
942
|
});
|
|
921
|
-
|
|
943
|
+
k(() => {
|
|
922
944
|
if (r) return;
|
|
923
|
-
let
|
|
924
|
-
return
|
|
945
|
+
let p = !1;
|
|
946
|
+
return d({
|
|
925
947
|
collector: null,
|
|
926
948
|
loading: !0,
|
|
927
949
|
error: null
|
|
928
|
-
}), z(t, e).then((
|
|
929
|
-
|
|
930
|
-
collector:
|
|
950
|
+
}), z(t, e).then((c) => {
|
|
951
|
+
p || d({
|
|
952
|
+
collector: c,
|
|
931
953
|
loading: !1,
|
|
932
954
|
error: null
|
|
933
955
|
});
|
|
934
|
-
}).catch((
|
|
935
|
-
|
|
956
|
+
}).catch((c) => {
|
|
957
|
+
p || d({
|
|
936
958
|
collector: null,
|
|
937
959
|
loading: !1,
|
|
938
|
-
error:
|
|
960
|
+
error: c instanceof Error ? c : new Error(String(c))
|
|
939
961
|
});
|
|
940
962
|
}), () => {
|
|
941
|
-
|
|
963
|
+
p = !0;
|
|
942
964
|
};
|
|
943
965
|
}, [
|
|
944
966
|
t,
|
|
945
967
|
r,
|
|
946
968
|
e.name,
|
|
947
|
-
|
|
948
|
-
|
|
969
|
+
i,
|
|
970
|
+
u,
|
|
949
971
|
e.autoSubmit
|
|
950
972
|
]);
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
if (
|
|
954
|
-
return
|
|
955
|
-
}, [t,
|
|
956
|
-
const
|
|
973
|
+
const y = r ? l : f.collector, m = r ? !1 : f.loading, C = r ? null : f.error;
|
|
974
|
+
k(() => {
|
|
975
|
+
if (y)
|
|
976
|
+
return y.install(t);
|
|
977
|
+
}, [t, y]);
|
|
978
|
+
const g = T(() => J({
|
|
957
979
|
values: e.initialValues ?? {},
|
|
958
980
|
submitted: !1
|
|
959
|
-
}), [
|
|
981
|
+
}), [u]), b = Ce(y?.store ?? g), v = T(() => y?.getStatus() ?? H, [b, y]), w = T(() => ({
|
|
960
982
|
...b,
|
|
961
|
-
...
|
|
962
|
-
}), [b,
|
|
983
|
+
...v
|
|
984
|
+
}), [b, v]), o = T(() => ({
|
|
963
985
|
name: e.name,
|
|
964
|
-
store:
|
|
986
|
+
store: g,
|
|
965
987
|
functions: [],
|
|
966
988
|
contextKey: `form:${e.name}`,
|
|
967
989
|
contextProvider: () => ({
|
|
@@ -976,18 +998,18 @@ function ze(e) {
|
|
|
976
998
|
ok: !1,
|
|
977
999
|
error: "Form definition not loaded yet."
|
|
978
1000
|
}),
|
|
979
|
-
getValues: () =>
|
|
1001
|
+
getValues: () => g.get().values,
|
|
980
1002
|
setValues: () => {
|
|
981
1003
|
},
|
|
982
1004
|
reset: () => {
|
|
983
1005
|
},
|
|
984
|
-
getStatus: () =>
|
|
985
|
-
}), [e.name,
|
|
1006
|
+
getStatus: () => H
|
|
1007
|
+
}), [e.name, g]);
|
|
986
1008
|
return {
|
|
987
|
-
...
|
|
988
|
-
state:
|
|
989
|
-
loading:
|
|
990
|
-
error:
|
|
1009
|
+
...y ?? o,
|
|
1010
|
+
state: w,
|
|
1011
|
+
loading: m,
|
|
1012
|
+
error: C
|
|
991
1013
|
};
|
|
992
1014
|
}
|
|
993
1015
|
export {
|
|
@@ -996,19 +1018,19 @@ export {
|
|
|
996
1018
|
_e as ChatWidget,
|
|
997
1019
|
he as Markdown,
|
|
998
1020
|
ve as Message,
|
|
999
|
-
|
|
1000
|
-
|
|
1021
|
+
W as createFormCollector,
|
|
1022
|
+
Re as createMockClient,
|
|
1001
1023
|
Me as deriveFormStatus,
|
|
1002
1024
|
z as loadFormCollector,
|
|
1003
1025
|
ee as useAgo,
|
|
1004
1026
|
P as useAgoClient,
|
|
1005
|
-
|
|
1027
|
+
He as useAgoContext,
|
|
1006
1028
|
Le as useAgoFunction,
|
|
1007
1029
|
De as useAgoNavigation,
|
|
1008
1030
|
Ce as useAgoStore,
|
|
1009
1031
|
Pe as useChat,
|
|
1010
1032
|
we as useConversation,
|
|
1011
1033
|
ze as useFormCollector,
|
|
1012
|
-
|
|
1034
|
+
O as useMessages,
|
|
1013
1035
|
L as useOptionalAgoClient
|
|
1014
1036
|
};
|