@rizal_ncc/agent-client 1.4.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/LICENSE +21 -0
- package/README.md +142 -0
- package/dist/ai-img.svg +54 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +155 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.mjs +600 -0
- package/dist/react.mjs.map +1 -0
- package/dist/style.css +1 -0
- package/dist/types/adapters/react.d.ts +43 -0
- package/dist/types/core/chatbot.d.ts +16 -0
- package/dist/types/core/errors.d.ts +4 -0
- package/dist/types/core/types.d.ts +89 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/lib/recommendation-pagination.d.ts +2 -0
- package/dist/types/lib/tool-results.d.ts +6 -0
- package/dist/types/react.d.ts +3 -0
- package/package.json +72 -0
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
import { jsxs as r, jsx as e, Fragment as me } from "react/jsx-runtime";
|
|
2
|
+
import { useState as E, useRef as fe, useMemo as q, useCallback as k, useEffect as L } from "react";
|
|
3
|
+
import { extractRecommendationOutput as Ce, extractRecommendationItems as Be, ChatbotCore as Ee } from "./index.mjs";
|
|
4
|
+
function Se(n) {
|
|
5
|
+
if (!n || typeof n != "object")
|
|
6
|
+
return null;
|
|
7
|
+
const t = n;
|
|
8
|
+
return typeof t.title != "string" || typeof t.url != "string" ? null : {
|
|
9
|
+
id: typeof t.id == "number" || typeof t.id == "string" || t.id === null ? t.id : null,
|
|
10
|
+
title: t.title,
|
|
11
|
+
description: typeof t.description == "string" ? t.description : "",
|
|
12
|
+
url: t.url,
|
|
13
|
+
type: typeof t.type == "string" ? t.type : "Course",
|
|
14
|
+
status: typeof t.status == "string" || t.status === null ? t.status : null,
|
|
15
|
+
progress: typeof t.progress == "number" || t.progress === null ? t.progress : null,
|
|
16
|
+
is_eligible: !!t.is_eligible,
|
|
17
|
+
in_playlist: !!t.in_playlist
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function Re(n, t) {
|
|
21
|
+
const o = Array.isArray(n) ? [...n] : [];
|
|
22
|
+
for (const h of t) {
|
|
23
|
+
const u = Se(h);
|
|
24
|
+
u && o.push(u);
|
|
25
|
+
}
|
|
26
|
+
return o;
|
|
27
|
+
}
|
|
28
|
+
const je = {};
|
|
29
|
+
function ze(n) {
|
|
30
|
+
const t = fe(null), [o, h] = E({
|
|
31
|
+
messages: [],
|
|
32
|
+
isLoading: !1
|
|
33
|
+
});
|
|
34
|
+
L(() => {
|
|
35
|
+
const m = new Ee(n);
|
|
36
|
+
t.current = m;
|
|
37
|
+
const A = m.subscribe((S) => {
|
|
38
|
+
h(S);
|
|
39
|
+
});
|
|
40
|
+
return () => {
|
|
41
|
+
A(), m.destroy(), t.current = null;
|
|
42
|
+
};
|
|
43
|
+
}, [n]);
|
|
44
|
+
const u = k(async (m) => {
|
|
45
|
+
if (t.current)
|
|
46
|
+
return t.current.sendMessage(m);
|
|
47
|
+
}, []), _ = k(() => {
|
|
48
|
+
t.current && t.current.stop();
|
|
49
|
+
}, []), w = k(
|
|
50
|
+
(m, A) => {
|
|
51
|
+
t.current && t.current.updateMessageById(m, A);
|
|
52
|
+
},
|
|
53
|
+
[]
|
|
54
|
+
);
|
|
55
|
+
return {
|
|
56
|
+
...o,
|
|
57
|
+
sendMessage: u,
|
|
58
|
+
stop: _,
|
|
59
|
+
updateMessageById: w
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function pe(n) {
|
|
63
|
+
if (!n)
|
|
64
|
+
return;
|
|
65
|
+
if (typeof n == "string")
|
|
66
|
+
return n.trim() || void 0;
|
|
67
|
+
const t = await n();
|
|
68
|
+
return typeof t == "string" && t.trim() || void 0;
|
|
69
|
+
}
|
|
70
|
+
function U(n) {
|
|
71
|
+
return n.replace(/\/+$/, "");
|
|
72
|
+
}
|
|
73
|
+
function Ie(n) {
|
|
74
|
+
const t = n.trim().replace("#", "");
|
|
75
|
+
if (![3, 6].includes(t.length) || !/^[a-fA-F0-9]+$/.test(t))
|
|
76
|
+
return null;
|
|
77
|
+
const o = t.length === 3 ? t.split("").map((w) => `${w}${w}`).join("") : t, h = Number.parseInt(o.slice(0, 2), 16), u = Number.parseInt(o.slice(2, 4), 16), _ = Number.parseInt(o.slice(4, 6), 16);
|
|
78
|
+
return `${h}, ${u}, ${_}`;
|
|
79
|
+
}
|
|
80
|
+
function Fe(n) {
|
|
81
|
+
const t = Ie(n);
|
|
82
|
+
if (t)
|
|
83
|
+
return t;
|
|
84
|
+
const o = n.match(/rgba?\(([^)]+)\)/i);
|
|
85
|
+
if (!o)
|
|
86
|
+
return "17, 104, 187";
|
|
87
|
+
const h = o[1].split(",").slice(0, 3).map((u) => Number.parseFloat(u.trim())).filter((u) => Number.isFinite(u));
|
|
88
|
+
return h.length !== 3 ? "17, 104, 187" : `${h[0]}, ${h[1]}, ${h[2]}`;
|
|
89
|
+
}
|
|
90
|
+
function Pe(n, t) {
|
|
91
|
+
return t && t.trim() ? Te(t.trim()) : U(n).endsWith("/api") ? "/v2/ai-agent/respond/" : "/api/v2/ai-agent/respond/";
|
|
92
|
+
}
|
|
93
|
+
function Te(n) {
|
|
94
|
+
return n ? n.startsWith("/") ? n : `/${n}` : "/api/v2/ai-agent/respond/";
|
|
95
|
+
}
|
|
96
|
+
function Oe({
|
|
97
|
+
generateResponse: n,
|
|
98
|
+
baseURL: t,
|
|
99
|
+
accessToken: o,
|
|
100
|
+
agent: h = "home-assistant",
|
|
101
|
+
metadata: u,
|
|
102
|
+
requestHeaders: _,
|
|
103
|
+
respondPath: w = "/api/v2/ai-agent/respond/",
|
|
104
|
+
suggestedMessages: m = [],
|
|
105
|
+
headerTitle: A = "BAWANA Assistant",
|
|
106
|
+
headerDescription: S = "Online and ready to help",
|
|
107
|
+
assistantAvatar: R,
|
|
108
|
+
assistantAvatarUrl: j = "/ai-img.svg",
|
|
109
|
+
assistantInitials: z = "AI",
|
|
110
|
+
userInitials: _e = "YOU",
|
|
111
|
+
initials: I = !0,
|
|
112
|
+
primaryColor: D = "#1168bb",
|
|
113
|
+
primaryForeground: ee = "#ffffff",
|
|
114
|
+
onMessage: te,
|
|
115
|
+
onError: G,
|
|
116
|
+
className: ye = "",
|
|
117
|
+
placeholder: Ne = "Ask the assistant...",
|
|
118
|
+
sendLabel: ae = "Send",
|
|
119
|
+
stopLabel: ne = "Stop",
|
|
120
|
+
layout: y = "inline",
|
|
121
|
+
open: se,
|
|
122
|
+
defaultOpen: $,
|
|
123
|
+
onOpenChange: J,
|
|
124
|
+
panelHeight: F,
|
|
125
|
+
floatingPosition: ve = "bottom-right",
|
|
126
|
+
zIndex: re = 60,
|
|
127
|
+
openLabel: P = "Open chat",
|
|
128
|
+
closeLabel: T = "Close chat"
|
|
129
|
+
}) {
|
|
130
|
+
const [V, K] = E(""), [ie, N] = E(""), [M, le] = E({}), [be, W] = E(() => y === "inline" ? !0 : typeof $ == "boolean" ? $ : !1), oe = fe(null), ce = q(
|
|
131
|
+
() => u || je,
|
|
132
|
+
[u]
|
|
133
|
+
), de = q(
|
|
134
|
+
() => Array.isArray(m) ? m.filter(
|
|
135
|
+
(a) => typeof a == "string" && a.trim().length > 0
|
|
136
|
+
) : [],
|
|
137
|
+
[m]
|
|
138
|
+
), he = k(
|
|
139
|
+
async ({ messages: a, signal: s }) => {
|
|
140
|
+
var H;
|
|
141
|
+
if (typeof n == "function")
|
|
142
|
+
return n({ messages: a, signal: s });
|
|
143
|
+
if (!t || !t.trim())
|
|
144
|
+
throw new Error(
|
|
145
|
+
"AiAgentChat requires `baseURL` when `generateResponse` is not provided."
|
|
146
|
+
);
|
|
147
|
+
const d = await pe(o);
|
|
148
|
+
if (!d)
|
|
149
|
+
throw new Error(
|
|
150
|
+
"AiAgentChat requires `accessToken` when `generateResponse` is not provided."
|
|
151
|
+
);
|
|
152
|
+
const l = new Headers(_);
|
|
153
|
+
l.set("content-type", "application/json"), l.set("authorization", `Bearer ${d}`);
|
|
154
|
+
const v = [...a].reverse().find((Y) => Y.role === "user"), b = (v == null ? void 0 : v.content) || "", i = Pe(t, w), C = await fetch(
|
|
155
|
+
`${U(t)}${i}`,
|
|
156
|
+
{
|
|
157
|
+
method: "POST",
|
|
158
|
+
headers: l,
|
|
159
|
+
body: JSON.stringify({
|
|
160
|
+
agent: h,
|
|
161
|
+
message: b,
|
|
162
|
+
metadata: ce
|
|
163
|
+
}),
|
|
164
|
+
signal: s
|
|
165
|
+
}
|
|
166
|
+
), p = await C.json();
|
|
167
|
+
if (!C.ok) {
|
|
168
|
+
const Y = typeof p == "object" && p ? "detail" in p && typeof p.detail == "string" ? p.detail : "message" in p && typeof p.message == "string" ? p.message : "" : "";
|
|
169
|
+
throw new Error(
|
|
170
|
+
`AI Agent request failed (${C.status})${Y ? `: ${Y}` : ""}`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const f = p, B = Ce(f);
|
|
174
|
+
return {
|
|
175
|
+
content: f.message,
|
|
176
|
+
toolResults: f.tool_results,
|
|
177
|
+
recommendations: Be(f),
|
|
178
|
+
recommendationNext: (H = B == null ? void 0 : B.next) != null ? H : null
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
[
|
|
182
|
+
o,
|
|
183
|
+
h,
|
|
184
|
+
t,
|
|
185
|
+
n,
|
|
186
|
+
_,
|
|
187
|
+
w,
|
|
188
|
+
ce
|
|
189
|
+
]
|
|
190
|
+
), ke = q(
|
|
191
|
+
() => ({
|
|
192
|
+
generateResponse: he,
|
|
193
|
+
onMessage: te,
|
|
194
|
+
onError: (a, s) => {
|
|
195
|
+
N(a.message), typeof G == "function" && G(a, s);
|
|
196
|
+
}
|
|
197
|
+
}),
|
|
198
|
+
[G, te, he]
|
|
199
|
+
), { messages: Z, isLoading: c, sendMessage: O, stop: we, updateMessageById: ue } = ze(ke), Ae = k(
|
|
200
|
+
async (a) => {
|
|
201
|
+
a.preventDefault();
|
|
202
|
+
const s = V.trim();
|
|
203
|
+
if (!(!s.length || c)) {
|
|
204
|
+
N(""), K("");
|
|
205
|
+
try {
|
|
206
|
+
await O(s);
|
|
207
|
+
} catch (d) {
|
|
208
|
+
const l = d instanceof Error ? d.message : "Failed to send message.";
|
|
209
|
+
N(l);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
[V, c, O]
|
|
214
|
+
), $e = k(
|
|
215
|
+
async (a) => {
|
|
216
|
+
if (!c) {
|
|
217
|
+
N(""), K("");
|
|
218
|
+
try {
|
|
219
|
+
await O(a);
|
|
220
|
+
} catch (s) {
|
|
221
|
+
const d = s instanceof Error ? s.message : "Failed to send message.";
|
|
222
|
+
N(d);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
[c, O]
|
|
227
|
+
), Me = Z.some((a) => a.role === "user"), x = typeof se == "boolean", g = y === "inline" ? !0 : x ? se : be, ge = k(
|
|
228
|
+
(a) => {
|
|
229
|
+
y !== "inline" && (x || W(a), typeof J == "function" && J(a));
|
|
230
|
+
},
|
|
231
|
+
[x, y, J]
|
|
232
|
+
);
|
|
233
|
+
L(() => {
|
|
234
|
+
if (!x) {
|
|
235
|
+
if (y === "inline") {
|
|
236
|
+
W(!0);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (typeof $ == "boolean") {
|
|
240
|
+
W($);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
W(!1);
|
|
244
|
+
}
|
|
245
|
+
}, [$, x, y]), L(() => {
|
|
246
|
+
const a = oe.current;
|
|
247
|
+
a && (a.scrollTop = a.scrollHeight);
|
|
248
|
+
}, [Z, c]);
|
|
249
|
+
const xe = k(
|
|
250
|
+
async (a, s) => {
|
|
251
|
+
if (!s || M[a])
|
|
252
|
+
return;
|
|
253
|
+
if (!t || !t.trim()) {
|
|
254
|
+
N("Cannot load more: baseURL is missing.");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const d = await pe(o);
|
|
258
|
+
if (!d) {
|
|
259
|
+
N("Cannot load more: accessToken is missing.");
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
le((l) => ({ ...l, [a]: !0 }));
|
|
263
|
+
try {
|
|
264
|
+
const l = new Headers(_);
|
|
265
|
+
l.set("authorization", `Bearer ${d}`);
|
|
266
|
+
const v = new URL(
|
|
267
|
+
s,
|
|
268
|
+
`${U(t)}/`
|
|
269
|
+
).toString(), b = await fetch(v, {
|
|
270
|
+
method: "GET",
|
|
271
|
+
headers: l
|
|
272
|
+
}), i = await b.json();
|
|
273
|
+
if (!b.ok) {
|
|
274
|
+
const f = typeof (i == null ? void 0 : i.detail) == "string" ? i.detail : typeof (i == null ? void 0 : i.message) == "string" ? i.message : "";
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Load more failed (${b.status})${f ? `: ${f}` : ""}`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
const C = Array.isArray(i == null ? void 0 : i.results) ? i.results : [], p = typeof (i == null ? void 0 : i.next) == "string" || (i == null ? void 0 : i.next) === null ? i.next : null;
|
|
280
|
+
ue(a, (f) => {
|
|
281
|
+
const B = Array.isArray(f.recommendations) ? f.recommendations : [], H = Re(B, C);
|
|
282
|
+
return {
|
|
283
|
+
...f,
|
|
284
|
+
recommendations: H,
|
|
285
|
+
recommendationNext: p
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
} catch (l) {
|
|
289
|
+
N(
|
|
290
|
+
l instanceof Error ? l.message : "Failed to load more recommendations."
|
|
291
|
+
);
|
|
292
|
+
} finally {
|
|
293
|
+
le((l) => ({ ...l, [a]: !1 }));
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
[
|
|
297
|
+
o,
|
|
298
|
+
t,
|
|
299
|
+
M,
|
|
300
|
+
_,
|
|
301
|
+
ue
|
|
302
|
+
]
|
|
303
|
+
), Q = q(
|
|
304
|
+
() => ({
|
|
305
|
+
"--chat-primary": D,
|
|
306
|
+
"--chat-primary-rgb": Fe(D),
|
|
307
|
+
"--chat-primary-foreground": ee,
|
|
308
|
+
...typeof F == "string" && F.trim() ? { "--chat-panel-height": F.trim() } : {},
|
|
309
|
+
"--chat-shell-z-index": re
|
|
310
|
+
}),
|
|
311
|
+
[F, D, ee, re]
|
|
312
|
+
), X = /* @__PURE__ */ r("section", { className: `ai-agent-chat ${ye}`.trim(), children: [
|
|
313
|
+
/* @__PURE__ */ r("header", { className: "ai-agent-chat__header", children: [
|
|
314
|
+
/* @__PURE__ */ e("div", { className: "ai-agent-chat__header-avatar", "aria-hidden": "true", children: R || (j ? /* @__PURE__ */ e("img", { src: j, alt: "" }) : I ? z : "") }),
|
|
315
|
+
/* @__PURE__ */ r("div", { className: "ai-agent-chat__header-copy", children: [
|
|
316
|
+
/* @__PURE__ */ e("strong", { children: A }),
|
|
317
|
+
/* @__PURE__ */ e("span", { children: S })
|
|
318
|
+
] })
|
|
319
|
+
] }),
|
|
320
|
+
/* @__PURE__ */ r(
|
|
321
|
+
"div",
|
|
322
|
+
{
|
|
323
|
+
className: "ai-agent-chat__messages",
|
|
324
|
+
role: "log",
|
|
325
|
+
"aria-live": "polite",
|
|
326
|
+
ref: oe,
|
|
327
|
+
children: [
|
|
328
|
+
!Z.length && !c ? /* @__PURE__ */ r("div", { className: "ai-agent-chat__empty", "aria-hidden": "true", children: [
|
|
329
|
+
/* @__PURE__ */ e("div", { className: "ai-agent-chat__empty-icon", children: /* @__PURE__ */ r("svg", { viewBox: "0 0 24 24", focusable: "false", children: [
|
|
330
|
+
/* @__PURE__ */ e("path", { d: "M12 2.5a.75.75 0 0 1 .73.57l1.02 4a.75.75 0 0 0 .53.53l4 1.02a.75.75 0 0 1 0 1.46l-4 1.02a.75.75 0 0 0-.53.53l-1.02 4a.75.75 0 0 1-1.46 0l-1.02-4a.75.75 0 0 0-.53-.53l-4-1.02a.75.75 0 0 1 0-1.46l4-1.02a.75.75 0 0 0 .53-.53l1.02-4A.75.75 0 0 1 12 2.5Z" }),
|
|
331
|
+
/* @__PURE__ */ e("path", { d: "M18.5 15a.75.75 0 0 1 .73.57l.35 1.37a.75.75 0 0 0 .53.53l1.37.35a.75.75 0 0 1 0 1.46l-1.37.35a.75.75 0 0 0-.53.53l-.35 1.37a.75.75 0 0 1-1.46 0l-.35-1.37a.75.75 0 0 0-.53-.53l-1.37-.35a.75.75 0 0 1 0-1.46l1.37-.35a.75.75 0 0 0 .53-.53l.35-1.37a.75.75 0 0 1 .73-.57Z" })
|
|
332
|
+
] }) }),
|
|
333
|
+
/* @__PURE__ */ e("strong", { children: "Start a conversation" }),
|
|
334
|
+
/* @__PURE__ */ e("span", { children: "Ask about courses, recommendations, or learning plans." })
|
|
335
|
+
] }) : null,
|
|
336
|
+
Z.map((a) => /* @__PURE__ */ r(
|
|
337
|
+
"article",
|
|
338
|
+
{
|
|
339
|
+
className: `ai-agent-chat__message ai-agent-chat__message--${a.role}`,
|
|
340
|
+
children: [
|
|
341
|
+
I ? /* @__PURE__ */ e("span", { className: "ai-agent-chat__message-role", children: a.role === "assistant" ? z : _e }) : null,
|
|
342
|
+
/* @__PURE__ */ e("p", { children: a.content }),
|
|
343
|
+
Array.isArray(a.recommendations) && a.recommendations.length > 0 ? /* @__PURE__ */ r("div", { className: "ai-agent-chat__recommendation-block", children: [
|
|
344
|
+
/* @__PURE__ */ r("div", { className: "chat-carousel", children: [
|
|
345
|
+
a.recommendations.map((s) => {
|
|
346
|
+
const d = typeof s.status == "string" && s.status.trim() ? s.status.trim() : "", l = typeof s.type == "string" && s.type.trim() ? s.type.trim() : "", v = typeof s.progress == "number" && Number.isFinite(s.progress), b = v ? Math.min(
|
|
347
|
+
100,
|
|
348
|
+
Math.max(0, Math.round(s.progress))
|
|
349
|
+
) : 0;
|
|
350
|
+
return /* @__PURE__ */ r(
|
|
351
|
+
"a",
|
|
352
|
+
{
|
|
353
|
+
className: "chat-carousel-card",
|
|
354
|
+
href: s.url || "#",
|
|
355
|
+
target: "_blank",
|
|
356
|
+
rel: "noreferrer",
|
|
357
|
+
children: [
|
|
358
|
+
/* @__PURE__ */ r("div", { className: "chat-carousel-card-header", children: [
|
|
359
|
+
l ? /* @__PURE__ */ e("span", { className: "chat-carousel-chip chat-carousel-chip--type", children: l }) : null,
|
|
360
|
+
d ? /* @__PURE__ */ e(
|
|
361
|
+
"span",
|
|
362
|
+
{
|
|
363
|
+
className: "chat-carousel-chip chat-carousel-chip--status",
|
|
364
|
+
"data-status": d.toLowerCase(),
|
|
365
|
+
children: d
|
|
366
|
+
}
|
|
367
|
+
) : null,
|
|
368
|
+
s.in_playlist ? /* @__PURE__ */ e("span", { className: "chat-carousel-chip chat-carousel-chip--muted", children: "In playlist" }) : null
|
|
369
|
+
] }),
|
|
370
|
+
/* @__PURE__ */ r("div", { className: "chat-carousel-card-content", children: [
|
|
371
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-card-title", children: s.title || "Untitled Course" }),
|
|
372
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-card-desc", children: s.description || "" })
|
|
373
|
+
] }),
|
|
374
|
+
/* @__PURE__ */ r("div", { className: "chat-carousel-card-footer", children: [
|
|
375
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-meta", children: v ? /* @__PURE__ */ r(me, { children: [
|
|
376
|
+
/* @__PURE__ */ r("span", { className: "chat-carousel-meta-text", children: [
|
|
377
|
+
b,
|
|
378
|
+
"% complete"
|
|
379
|
+
] }),
|
|
380
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-progress", children: /* @__PURE__ */ e(
|
|
381
|
+
"div",
|
|
382
|
+
{
|
|
383
|
+
className: "chat-carousel-progress-bar",
|
|
384
|
+
style: { width: `${b}%` }
|
|
385
|
+
}
|
|
386
|
+
) })
|
|
387
|
+
] }) : null }),
|
|
388
|
+
/* @__PURE__ */ r("div", { className: "chat-carousel-cta", children: [
|
|
389
|
+
/* @__PURE__ */ e("span", { children: "View course" }),
|
|
390
|
+
/* @__PURE__ */ e("span", { className: "chat-carousel-cta-icon" })
|
|
391
|
+
] })
|
|
392
|
+
] })
|
|
393
|
+
]
|
|
394
|
+
},
|
|
395
|
+
`${s.id || s.title}`
|
|
396
|
+
);
|
|
397
|
+
}),
|
|
398
|
+
M[a.id] ? Array.from({ length: 3 }).map((s, d) => /* @__PURE__ */ r(
|
|
399
|
+
"div",
|
|
400
|
+
{
|
|
401
|
+
className: "chat-carousel-card chat-carousel-card--skeleton",
|
|
402
|
+
"aria-hidden": "true",
|
|
403
|
+
children: [
|
|
404
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-skeleton-line chat-carousel-skeleton-line--chip" }),
|
|
405
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-skeleton-line chat-carousel-skeleton-line--title" }),
|
|
406
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-skeleton-line chat-carousel-skeleton-line--desc" }),
|
|
407
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-skeleton-line chat-carousel-skeleton-line--desc-short" }),
|
|
408
|
+
/* @__PURE__ */ e("div", { className: "chat-carousel-skeleton-line chat-carousel-skeleton-line--cta" })
|
|
409
|
+
]
|
|
410
|
+
},
|
|
411
|
+
`skeleton-${a.id}-${d}`
|
|
412
|
+
)) : null
|
|
413
|
+
] }),
|
|
414
|
+
a.recommendationNext ? /* @__PURE__ */ e(
|
|
415
|
+
"button",
|
|
416
|
+
{
|
|
417
|
+
type: "button",
|
|
418
|
+
className: "ai-agent-chat__loadmore",
|
|
419
|
+
onClick: () => void xe(
|
|
420
|
+
a.id,
|
|
421
|
+
a.recommendationNext
|
|
422
|
+
),
|
|
423
|
+
disabled: !!M[a.id],
|
|
424
|
+
children: M[a.id] ? /* @__PURE__ */ r(me, { children: [
|
|
425
|
+
/* @__PURE__ */ e(
|
|
426
|
+
"span",
|
|
427
|
+
{
|
|
428
|
+
className: "ai-agent-chat__spinner",
|
|
429
|
+
"aria-hidden": "true"
|
|
430
|
+
}
|
|
431
|
+
),
|
|
432
|
+
"Loading..."
|
|
433
|
+
] }) : "Load more"
|
|
434
|
+
}
|
|
435
|
+
) : null
|
|
436
|
+
] }) : null
|
|
437
|
+
]
|
|
438
|
+
},
|
|
439
|
+
a.id
|
|
440
|
+
)),
|
|
441
|
+
c ? /* @__PURE__ */ r("article", { className: "ai-agent-chat__message ai-agent-chat__message--assistant ai-agent-chat__message--typing", children: [
|
|
442
|
+
I ? /* @__PURE__ */ e("span", { className: "ai-agent-chat__message-role", children: z }) : null,
|
|
443
|
+
/* @__PURE__ */ r("p", { className: "ai-agent-chat__typing", children: [
|
|
444
|
+
/* @__PURE__ */ e("span", { className: "ai-agent-chat__typing-dot", "aria-hidden": "true" }),
|
|
445
|
+
/* @__PURE__ */ e("span", { className: "ai-agent-chat__typing-dot", "aria-hidden": "true" }),
|
|
446
|
+
/* @__PURE__ */ e("span", { className: "ai-agent-chat__typing-dot", "aria-hidden": "true" })
|
|
447
|
+
] })
|
|
448
|
+
] }) : null
|
|
449
|
+
]
|
|
450
|
+
}
|
|
451
|
+
),
|
|
452
|
+
!Me && de.length > 0 ? /* @__PURE__ */ e("div", { className: "ai-agent-chat__suggestions", children: de.map((a) => /* @__PURE__ */ e(
|
|
453
|
+
"button",
|
|
454
|
+
{
|
|
455
|
+
type: "button",
|
|
456
|
+
onClick: () => void $e(a),
|
|
457
|
+
disabled: c,
|
|
458
|
+
children: a
|
|
459
|
+
},
|
|
460
|
+
a
|
|
461
|
+
)) }) : null,
|
|
462
|
+
/* @__PURE__ */ r("form", { className: "ai-agent-chat__composer", onSubmit: Ae, children: [
|
|
463
|
+
/* @__PURE__ */ e(
|
|
464
|
+
"input",
|
|
465
|
+
{
|
|
466
|
+
value: V,
|
|
467
|
+
onChange: (a) => K(a.target.value),
|
|
468
|
+
placeholder: Ne,
|
|
469
|
+
disabled: c
|
|
470
|
+
}
|
|
471
|
+
),
|
|
472
|
+
/* @__PURE__ */ e(
|
|
473
|
+
"button",
|
|
474
|
+
{
|
|
475
|
+
type: c ? "button" : "submit",
|
|
476
|
+
onClick: c ? we : void 0,
|
|
477
|
+
className: `ai-agent-chat__action ${c ? "is-stop" : "is-send"}`,
|
|
478
|
+
disabled: !c && !V.trim().length,
|
|
479
|
+
"aria-label": c ? ne : ae,
|
|
480
|
+
title: c ? ne : ae,
|
|
481
|
+
children: c ? /* @__PURE__ */ e(
|
|
482
|
+
"svg",
|
|
483
|
+
{
|
|
484
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
485
|
+
viewBox: "0 0 20 20",
|
|
486
|
+
fill: "currentColor",
|
|
487
|
+
children: /* @__PURE__ */ e("path", { d: "M5.25 3A2.25 2.25 0 0 0 3 5.25v9.5A2.25 2.25 0 0 0 5.25 17h9.5A2.25 2.25 0 0 0 17 14.75v-9.5A2.25 2.25 0 0 0 14.75 3h-9.5Z" })
|
|
488
|
+
}
|
|
489
|
+
) : /* @__PURE__ */ e(
|
|
490
|
+
"svg",
|
|
491
|
+
{
|
|
492
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
493
|
+
viewBox: "0 0 20 20",
|
|
494
|
+
fill: "currentColor",
|
|
495
|
+
children: /* @__PURE__ */ e("path", { d: "M3.105 2.288a.75.75 0 0 0-.826.95l1.414 4.926A1.5 1.5 0 0 0 5.135 9.25h6.115a.75.75 0 0 1 0 1.5H5.135a1.5 1.5 0 0 0-1.442 1.086l-1.414 4.926a.75.75 0 0 0 .826.95 28.897 28.897 0 0 0 15.293-7.155.75.75 0 0 0 0-1.114A28.897 28.897 0 0 0 3.105 2.288Z" })
|
|
496
|
+
}
|
|
497
|
+
)
|
|
498
|
+
}
|
|
499
|
+
)
|
|
500
|
+
] }),
|
|
501
|
+
ie ? /* @__PURE__ */ e("p", { className: "ai-agent-chat__error", children: ie }) : null
|
|
502
|
+
] });
|
|
503
|
+
return y === "floating" ? /* @__PURE__ */ r(
|
|
504
|
+
"div",
|
|
505
|
+
{
|
|
506
|
+
className: `ai-agent-chat-shell ai-agent-chat-shell--floating ai-agent-chat-shell--${ve} ${g ? "ai-agent-chat-shell--open" : "ai-agent-chat-shell--closed"}`.trim(),
|
|
507
|
+
style: Q,
|
|
508
|
+
children: [
|
|
509
|
+
/* @__PURE__ */ e("div", { className: "ai-agent-chat-shell__panel", children: X }),
|
|
510
|
+
/* @__PURE__ */ r(
|
|
511
|
+
"button",
|
|
512
|
+
{
|
|
513
|
+
type: "button",
|
|
514
|
+
className: `ai-agent-chat-shell__toggle ai-agent-chat-shell__toggle--floating ${g ? "is-open" : ""}`.trim(),
|
|
515
|
+
onClick: () => ge(!g),
|
|
516
|
+
"aria-expanded": g,
|
|
517
|
+
"aria-label": g ? T : P,
|
|
518
|
+
title: g ? T : P,
|
|
519
|
+
children: [
|
|
520
|
+
/* @__PURE__ */ r(
|
|
521
|
+
"svg",
|
|
522
|
+
{
|
|
523
|
+
className: "ai-agent-chat-shell__toggle-icon ai-agent-chat-shell__toggle-icon--open",
|
|
524
|
+
viewBox: "0 0 24 24",
|
|
525
|
+
fill: "none",
|
|
526
|
+
stroke: "currentColor",
|
|
527
|
+
strokeWidth: "2",
|
|
528
|
+
strokeLinecap: "round",
|
|
529
|
+
strokeLinejoin: "round",
|
|
530
|
+
"aria-hidden": "true",
|
|
531
|
+
focusable: "false",
|
|
532
|
+
children: [
|
|
533
|
+
/* @__PURE__ */ e("path", { d: "M12 6V2H8" }),
|
|
534
|
+
/* @__PURE__ */ e("path", { d: "M15 11v2" }),
|
|
535
|
+
/* @__PURE__ */ e("path", { d: "M2 12h2" }),
|
|
536
|
+
/* @__PURE__ */ e("path", { d: "M20 12h2" }),
|
|
537
|
+
/* @__PURE__ */ e("path", { d: "M20 16a2 2 0 0 1-2 2H8.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 4 20.286V8a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2z" }),
|
|
538
|
+
/* @__PURE__ */ e("path", { d: "M9 11v2" })
|
|
539
|
+
]
|
|
540
|
+
}
|
|
541
|
+
),
|
|
542
|
+
/* @__PURE__ */ r(
|
|
543
|
+
"svg",
|
|
544
|
+
{
|
|
545
|
+
className: "ai-agent-chat-shell__toggle-icon ai-agent-chat-shell__toggle-icon--close",
|
|
546
|
+
viewBox: "0 0 24 24",
|
|
547
|
+
fill: "none",
|
|
548
|
+
stroke: "currentColor",
|
|
549
|
+
strokeWidth: "2",
|
|
550
|
+
strokeLinecap: "round",
|
|
551
|
+
strokeLinejoin: "round",
|
|
552
|
+
"aria-hidden": "true",
|
|
553
|
+
focusable: "false",
|
|
554
|
+
children: [
|
|
555
|
+
/* @__PURE__ */ e("path", { d: "M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z" }),
|
|
556
|
+
/* @__PURE__ */ e("path", { d: "m14.5 8.5-5 5" }),
|
|
557
|
+
/* @__PURE__ */ e("path", { d: "m9.5 8.5 5 5" })
|
|
558
|
+
]
|
|
559
|
+
}
|
|
560
|
+
)
|
|
561
|
+
]
|
|
562
|
+
}
|
|
563
|
+
)
|
|
564
|
+
]
|
|
565
|
+
}
|
|
566
|
+
) : y === "dropdown" ? /* @__PURE__ */ r(
|
|
567
|
+
"div",
|
|
568
|
+
{
|
|
569
|
+
className: `ai-agent-chat-shell ai-agent-chat-shell--dropdown ${g ? "ai-agent-chat-shell--open" : "ai-agent-chat-shell--closed"}`.trim(),
|
|
570
|
+
style: Q,
|
|
571
|
+
children: [
|
|
572
|
+
/* @__PURE__ */ r(
|
|
573
|
+
"button",
|
|
574
|
+
{
|
|
575
|
+
type: "button",
|
|
576
|
+
className: `ai-agent-chat-shell__toggle ai-agent-chat-shell__toggle--dropdown ${g ? "is-open" : ""}`.trim(),
|
|
577
|
+
onClick: () => ge(!g),
|
|
578
|
+
"aria-expanded": g,
|
|
579
|
+
"aria-label": g ? T : P,
|
|
580
|
+
title: g ? T : P,
|
|
581
|
+
children: [
|
|
582
|
+
/* @__PURE__ */ e("span", { className: "ai-agent-chat-shell__toggle-avatar", "aria-hidden": "true", children: R || (j ? /* @__PURE__ */ e("img", { src: j, alt: "" }) : I ? z : "") }),
|
|
583
|
+
/* @__PURE__ */ r("span", { className: "ai-agent-chat-shell__toggle-copy", children: [
|
|
584
|
+
/* @__PURE__ */ e("strong", { children: A }),
|
|
585
|
+
/* @__PURE__ */ e("span", { children: S })
|
|
586
|
+
] }),
|
|
587
|
+
/* @__PURE__ */ e("span", { className: "ai-agent-chat-shell__caret", "aria-hidden": "true" })
|
|
588
|
+
]
|
|
589
|
+
}
|
|
590
|
+
),
|
|
591
|
+
/* @__PURE__ */ e("div", { className: `ai-agent-chat-shell__panel ${g ? "is-open" : ""}`.trim(), children: X })
|
|
592
|
+
]
|
|
593
|
+
}
|
|
594
|
+
) : /* @__PURE__ */ e("div", { className: "ai-agent-chat-shell ai-agent-chat-shell--inline", style: Q, children: X });
|
|
595
|
+
}
|
|
596
|
+
export {
|
|
597
|
+
Oe as AiAgentChat,
|
|
598
|
+
ze as useAiAgentChat
|
|
599
|
+
};
|
|
600
|
+
//# sourceMappingURL=react.mjs.map
|