@object-ui/plugin-chatbot 5.4.2 → 6.0.1
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 +37 -0
- package/README.md +43 -0
- package/dist/index.js +1311 -581
- package/dist/index.umd.cjs +1 -1
- package/dist/packages/plugin-chatbot/src/AiPendingActionsInbox.d.ts +38 -0
- package/dist/packages/plugin-chatbot/src/AiPendingActionsInbox.d.ts.map +1 -0
- package/dist/packages/plugin-chatbot/src/ChatbotEnhanced.d.ts +27 -0
- package/dist/packages/plugin-chatbot/src/ChatbotEnhanced.d.ts.map +1 -1
- package/dist/packages/plugin-chatbot/src/index.d.ts +7 -1
- package/dist/packages/plugin-chatbot/src/index.d.ts.map +1 -1
- package/dist/packages/plugin-chatbot/src/mapMessages.d.ts.map +1 -1
- package/dist/packages/plugin-chatbot/src/useHitlInChat.d.ts +66 -0
- package/dist/packages/plugin-chatbot/src/useHitlInChat.d.ts.map +1 -0
- package/dist/packages/plugin-chatbot/src/usePendingActions.d.ts +120 -0
- package/dist/packages/plugin-chatbot/src/usePendingActions.d.ts.map +1 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,58 +1,82 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
2
|
import { Children as t, Fragment as n, createContext as r, isValidElement as i, memo as a, useCallback as o, useContext as s, useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import { AlertCircle as
|
|
5
|
-
import { Fragment as
|
|
6
|
-
import { useChat as
|
|
7
|
-
import { DefaultChatTransport as
|
|
8
|
-
import * as
|
|
9
|
-
import { useObjectTranslation as
|
|
10
|
-
import { StickToBottom as
|
|
11
|
-
import { cva as
|
|
12
|
-
import { Slot as
|
|
13
|
-
import { Streamdown as
|
|
14
|
-
import { nanoid as
|
|
15
|
-
import { codeToHtml as
|
|
16
|
-
import { useControllableState as
|
|
17
|
-
import { motion as
|
|
18
|
-
import { ComponentRegistry as
|
|
3
|
+
import { Alert as f, AlertDescription as p, Avatar as m, AvatarFallback as h, AvatarImage as g, Badge as _, Button as v, Card as y, CardContent as b, CardDescription as x, CardHeader as S, CardTitle as C, Collapsible as w, CollapsibleContent as T, CollapsibleTrigger as E, Command as D, CommandEmpty as O, CommandGroup as k, CommandInput as A, CommandItem as j, CommandList as M, CommandSeparator as N, DropdownMenu as P, DropdownMenuContent as F, DropdownMenuItem as I, DropdownMenuTrigger as L, Empty as ee, EmptyDescription as te, EmptyHeader as ne, EmptyMedia as re, EmptyTitle as ie, HoverCard as R, HoverCardContent as ae, HoverCardTrigger as z, Input as oe, Label as B, ScrollArea as se, ScrollBar as ce, Select as le, SelectContent as ue, SelectItem as de, SelectTrigger as fe, SelectValue as pe, Separator as me, Sheet as he, SheetContent as ge, SheetDescription as _e, SheetHeader as ve, SheetTitle as ye, Skeleton as be, Table as xe, TableBody as Se, TableCell as V, TableHead as H, TableHeader as Ce, TableRow as we, Tabs as Te, TabsList as Ee, TabsTrigger as De, Textarea as Oe, Tooltip as ke, TooltipContent as Ae, TooltipProvider as je, TooltipTrigger as Me, cn as U } from "@object-ui/components";
|
|
4
|
+
import { AlertCircle as Ne, ArrowDownIcon as Pe, BookIcon as Fe, Bot as Ie, BrainIcon as Le, Check as Re, CheckCircle2 as ze, CheckCircleIcon as Be, CheckIcon as Ve, ChevronDownIcon as He, ChevronLeftIcon as Ue, ChevronRightIcon as We, CircleIcon as Ge, Clock as Ke, ClockIcon as qe, Copy as Je, CopyIcon as Ye, CornerDownLeftIcon as Xe, Eye as Ze, ImageIcon as Qe, Inbox as $e, Loader2Icon as et, Maximize2 as tt, MessageCircle as nt, MicIcon as rt, Minimize2 as it, PaperclipIcon as at, PlusIcon as ot, RefreshCw as st, Send as ct, SquareIcon as lt, WrenchIcon as ut, X as dt, XCircle as W, XCircleIcon as ft, XIcon as G } from "lucide-react";
|
|
5
|
+
import { Fragment as K, jsx as q, jsxs as J } from "react/jsx-runtime";
|
|
6
|
+
import { useChat as pt } from "@ai-sdk/react";
|
|
7
|
+
import { DefaultChatTransport as mt } from "ai";
|
|
8
|
+
import * as ht from "react-dom";
|
|
9
|
+
import { useObjectTranslation as gt } from "@object-ui/react";
|
|
10
|
+
import { StickToBottom as _t, useStickToBottomContext as vt } from "use-stick-to-bottom";
|
|
11
|
+
import { cva as yt } from "class-variance-authority";
|
|
12
|
+
import { Slot as bt } from "@radix-ui/react-slot";
|
|
13
|
+
import { Streamdown as xt } from "streamdown";
|
|
14
|
+
import { nanoid as St } from "nanoid";
|
|
15
|
+
import { codeToHtml as Ct } from "shiki";
|
|
16
|
+
import { useControllableState as wt } from "@radix-ui/react-use-controllable-state";
|
|
17
|
+
import { motion as Tt } from "motion/react";
|
|
18
|
+
import { ComponentRegistry as Et } from "@object-ui/core";
|
|
19
19
|
//#region \0rolldown/runtime.js
|
|
20
|
-
var
|
|
20
|
+
var Dt = Object.defineProperty, Ot = (e, t) => {
|
|
21
21
|
let n = {};
|
|
22
|
-
for (var r in e)
|
|
22
|
+
for (var r in e) Dt(n, r, {
|
|
23
23
|
get: e[r],
|
|
24
24
|
enumerable: !0
|
|
25
25
|
});
|
|
26
|
-
return t ||
|
|
26
|
+
return t || Dt(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
27
27
|
};
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/utils.ts
|
|
30
|
-
function
|
|
30
|
+
function kt(e = "msg") {
|
|
31
31
|
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `${e}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
32
32
|
}
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region src/mapMessages.ts
|
|
35
|
-
function
|
|
35
|
+
function At(e, t) {
|
|
36
36
|
return typeof e.content == "string" ? e.content : t.filter((e) => e.type === "text").map((e) => e.text ?? "").join("");
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function jt(e) {
|
|
39
39
|
let t = e.filter((e) => e.type === "reasoning" || e.type === "reasoning-delta").map((e) => e.text ?? "").join("\n").trim();
|
|
40
40
|
return t.length > 0 ? t : void 0;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function Mt(e) {
|
|
43
|
+
let t = (e) => {
|
|
44
|
+
if (e && typeof e == "object") return e;
|
|
45
|
+
if (typeof e != "string") return;
|
|
46
|
+
let t = e.trim();
|
|
47
|
+
if (t.startsWith("{")) try {
|
|
48
|
+
let e = JSON.parse(t);
|
|
49
|
+
return e && typeof e == "object" ? e : void 0;
|
|
50
|
+
} catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}, n = [e];
|
|
54
|
+
e && typeof e == "object" && "value" in e && n.push(e.value);
|
|
55
|
+
for (let e of n) {
|
|
56
|
+
let n = t(e);
|
|
57
|
+
if (!n) continue;
|
|
58
|
+
let r = n.status, i = n.pendingActionId;
|
|
59
|
+
if (r === "pending_approval" && typeof i == "string" && i.length > 0) return {
|
|
60
|
+
pendingActionId: i,
|
|
61
|
+
raw: n
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function Nt(e) {
|
|
43
66
|
return e.filter((e) => e.type === "dynamic-tool" ? !0 : typeof e.type == "string" && e.type.startsWith("tool-")).map((e) => {
|
|
44
|
-
let t = e.type === "dynamic-tool" ? e.toolName ?? "tool" : typeof e.type == "string" ? e.type.replace(/^tool-/, "") : "tool";
|
|
67
|
+
let t = e.type === "dynamic-tool" ? e.toolName ?? "tool" : typeof e.type == "string" ? e.type.replace(/^tool-/, "") : "tool", n = e.output ?? e.result, r = Mt(n), i = e.state, a = r && i !== "output-error" ? "approval-requested" : i;
|
|
45
68
|
return {
|
|
46
69
|
toolCallId: e.toolCallId ?? e.id ?? `${e.type ?? "tool"}-${Math.random().toString(36).slice(2, 8)}`,
|
|
47
70
|
toolName: t,
|
|
48
71
|
args: e.input ?? e.args,
|
|
49
|
-
result:
|
|
72
|
+
result: n,
|
|
50
73
|
errorText: e.errorText,
|
|
51
|
-
state:
|
|
74
|
+
state: a,
|
|
75
|
+
pendingActionId: r?.pendingActionId
|
|
52
76
|
};
|
|
53
77
|
});
|
|
54
78
|
}
|
|
55
|
-
function
|
|
79
|
+
function Pt(e) {
|
|
56
80
|
let t = e.filter((e) => e.type === "source-url" || e.type === "source").map((e) => ({
|
|
57
81
|
id: e.id,
|
|
58
82
|
title: e.title,
|
|
@@ -60,26 +84,26 @@ function tt(e) {
|
|
|
60
84
|
})).filter((e) => !!e.url);
|
|
61
85
|
return t.length > 0 ? t : void 0;
|
|
62
86
|
}
|
|
63
|
-
function
|
|
64
|
-
let n = Array.isArray(e.parts) ? e.parts : [], r =
|
|
87
|
+
function Ft(e, t = {}) {
|
|
88
|
+
let n = Array.isArray(e.parts) ? e.parts : [], r = Nt(n), i = Array.isArray(e.toolInvocations) ? e.toolInvocations : [];
|
|
65
89
|
return {
|
|
66
90
|
id: e.id ?? `msg-${Math.random().toString(36).slice(2, 8)}`,
|
|
67
91
|
role: e.role ?? "assistant",
|
|
68
|
-
content:
|
|
69
|
-
reasoning:
|
|
92
|
+
content: At(e, n),
|
|
93
|
+
reasoning: jt(n),
|
|
70
94
|
toolInvocations: r.length > 0 ? r : i,
|
|
71
|
-
sources:
|
|
95
|
+
sources: Pt(n),
|
|
72
96
|
streaming: t.streaming
|
|
73
97
|
};
|
|
74
98
|
}
|
|
75
|
-
function
|
|
99
|
+
function It(e, t = {}) {
|
|
76
100
|
if (!Array.isArray(e) || e.length === 0) return [];
|
|
77
101
|
let n = e.length - 1;
|
|
78
|
-
return e.map((e, r) =>
|
|
102
|
+
return e.map((e, r) => Ft(e, { streaming: !!t.isStreaming && r === n && e.role === "assistant" }));
|
|
79
103
|
}
|
|
80
104
|
//#endregion
|
|
81
105
|
//#region src/useObjectChat.ts
|
|
82
|
-
function
|
|
106
|
+
function Lt(e) {
|
|
83
107
|
return (e ?? []).map((e, t) => ({
|
|
84
108
|
id: e.id || `msg-${t}`,
|
|
85
109
|
role: e.role || "user",
|
|
@@ -90,17 +114,17 @@ function it(e) {
|
|
|
90
114
|
toolInvocations: e.toolInvocations
|
|
91
115
|
}));
|
|
92
116
|
}
|
|
93
|
-
function
|
|
94
|
-
let { api: t, initialMessages: n, conversationId: r, systemPrompt: i, model: a, streamingEnabled: s = !0, headers: f, body: p, maxToolRoundtrips: m = 5, onError: h, showTimestamp: g, autoResponse: _, autoResponseText: v, autoResponseDelay: y = 1e3, onSend: b } = e, x = u(t ? "api" : "local").current === "api", S = l(() =>
|
|
117
|
+
function Y(e = {}) {
|
|
118
|
+
let { api: t, initialMessages: n, conversationId: r, systemPrompt: i, model: a, streamingEnabled: s = !0, headers: f, body: p, maxToolRoundtrips: m = 5, onError: h, showTimestamp: g, autoResponse: _, autoResponseText: v, autoResponseDelay: y = 1e3, onSend: b } = e, x = u(t ? "api" : "local").current === "api", S = l(() => Lt(n).map((e) => ({
|
|
95
119
|
id: e.id,
|
|
96
120
|
role: e.role,
|
|
97
121
|
parts: [{
|
|
98
122
|
type: "text",
|
|
99
123
|
text: e.content ?? ""
|
|
100
124
|
}]
|
|
101
|
-
})), []), C =
|
|
125
|
+
})), []), C = pt({
|
|
102
126
|
transport: l(() => {
|
|
103
|
-
if (x) return new
|
|
127
|
+
if (x) return new mt({
|
|
104
128
|
api: t,
|
|
105
129
|
headers: { ...f },
|
|
106
130
|
body: {
|
|
@@ -125,11 +149,11 @@ function K(e = {}) {
|
|
|
125
149
|
onError: x ? (e) => {
|
|
126
150
|
h?.(e);
|
|
127
151
|
} : void 0
|
|
128
|
-
}), [w, T] = d(() =>
|
|
152
|
+
}), [w, T] = d(() => Lt(n)), [E, D] = d(!1), [O, k] = d(""), [A, j] = d(""), M = u(null);
|
|
129
153
|
if (c(() => () => {
|
|
130
154
|
M.current &&= (clearTimeout(M.current), null);
|
|
131
155
|
}, []), x) {
|
|
132
|
-
let { messages: e, status: t, error: n, sendMessage: r, regenerate: i, stop: a, setMessages: s } = C, c = t === "submitted" || t === "streaming", l =
|
|
156
|
+
let { messages: e, status: t, error: n, sendMessage: r, regenerate: i, stop: a, setMessages: s } = C, c = t === "submitted" || t === "streaming", l = It(e, { isStreaming: c }).map((t, n) => ({
|
|
133
157
|
...t,
|
|
134
158
|
metadata: e[n]?.metadata
|
|
135
159
|
}));
|
|
@@ -141,7 +165,7 @@ function K(e = {}) {
|
|
|
141
165
|
let t = e.trim();
|
|
142
166
|
if (!t) return;
|
|
143
167
|
let n = [...l, {
|
|
144
|
-
id:
|
|
168
|
+
id: kt("msg"),
|
|
145
169
|
role: "user",
|
|
146
170
|
content: t
|
|
147
171
|
}];
|
|
@@ -174,7 +198,7 @@ function K(e = {}) {
|
|
|
174
198
|
sendMessage: o((e) => {
|
|
175
199
|
if (!e.trim()) return;
|
|
176
200
|
let t = {
|
|
177
|
-
id:
|
|
201
|
+
id: kt("msg"),
|
|
178
202
|
role: "user",
|
|
179
203
|
content: e.trim(),
|
|
180
204
|
timestamp: g ? (/* @__PURE__ */ new Date()).toLocaleTimeString() : void 0
|
|
@@ -184,7 +208,7 @@ function K(e = {}) {
|
|
|
184
208
|
return b?.(e.trim(), r), r;
|
|
185
209
|
}), k(""), _ && (D(!0), M.current = setTimeout(() => {
|
|
186
210
|
let e = {
|
|
187
|
-
id:
|
|
211
|
+
id: kt("msg"),
|
|
188
212
|
role: "assistant",
|
|
189
213
|
content: v || "Thank you for your message!",
|
|
190
214
|
timestamp: g ? (/* @__PURE__ */ new Date()).toLocaleTimeString() : void 0
|
|
@@ -213,7 +237,7 @@ function K(e = {}) {
|
|
|
213
237
|
}
|
|
214
238
|
//#endregion
|
|
215
239
|
//#region src/useAgents.ts
|
|
216
|
-
function
|
|
240
|
+
function Rt(e) {
|
|
217
241
|
return e.filter((e) => typeof e?.name == "string" && e.name.length > 0).map((e) => ({
|
|
218
242
|
name: e.name,
|
|
219
243
|
label: e.label || e.name,
|
|
@@ -222,7 +246,7 @@ function at(e) {
|
|
|
222
246
|
active: e.active !== !1
|
|
223
247
|
}));
|
|
224
248
|
}
|
|
225
|
-
function
|
|
249
|
+
function zt(e = {}) {
|
|
226
250
|
let { apiBase: t, headers: n, enabled: r = !0, fallback: i = [] } = e, [a, s] = d(i), [l, f] = d(!1), [p, m] = d(void 0), [h, g] = d(0), _ = u(n);
|
|
227
251
|
return _.current = n, c(() => {
|
|
228
252
|
if (!r || !t) return;
|
|
@@ -242,7 +266,7 @@ function ot(e = {}) {
|
|
|
242
266
|
return e.json();
|
|
243
267
|
}).then((e) => {
|
|
244
268
|
if (n) return;
|
|
245
|
-
let t =
|
|
269
|
+
let t = Rt(Array.isArray(e) ? e : e?.agents ?? []);
|
|
246
270
|
s(t.length > 0 ? t : i);
|
|
247
271
|
}).catch((e) => {
|
|
248
272
|
n || e.name === "AbortError" || (m(e), s(i));
|
|
@@ -264,8 +288,8 @@ function ot(e = {}) {
|
|
|
264
288
|
}
|
|
265
289
|
//#endregion
|
|
266
290
|
//#region src/FloatingChatbotProvider.tsx
|
|
267
|
-
var
|
|
268
|
-
function
|
|
291
|
+
var Bt = e.createContext(null);
|
|
292
|
+
function Vt({ defaultOpen: t = !1, children: n }) {
|
|
269
293
|
let [r, i] = e.useState(t), [a, o] = e.useState(!1), s = e.useMemo(() => ({
|
|
270
294
|
isOpen: r,
|
|
271
295
|
isFullscreen: a,
|
|
@@ -276,21 +300,21 @@ function ct({ defaultOpen: t = !1, children: n }) {
|
|
|
276
300
|
toggle: () => i((e) => !e),
|
|
277
301
|
toggleFullscreen: () => o((e) => !e)
|
|
278
302
|
}), [r, a]);
|
|
279
|
-
return /* @__PURE__ */
|
|
303
|
+
return /* @__PURE__ */ q(Bt.Provider, {
|
|
280
304
|
value: s,
|
|
281
305
|
children: n
|
|
282
306
|
});
|
|
283
307
|
}
|
|
284
|
-
function
|
|
285
|
-
let t = e.useContext(
|
|
308
|
+
function Ht() {
|
|
309
|
+
let t = e.useContext(Bt);
|
|
286
310
|
if (!t) throw Error("useFloatingChatbot must be used within a <FloatingChatbotProvider>");
|
|
287
311
|
return t;
|
|
288
312
|
}
|
|
289
313
|
//#endregion
|
|
290
314
|
//#region src/FloatingChatbotTrigger.tsx
|
|
291
|
-
function
|
|
315
|
+
function Ut() {
|
|
292
316
|
try {
|
|
293
|
-
let { t: e } =
|
|
317
|
+
let { t: e } = gt();
|
|
294
318
|
return (t, n) => {
|
|
295
319
|
let r = e(`common.${t}`);
|
|
296
320
|
return !r || r === `common.${t}` ? n : r;
|
|
@@ -299,11 +323,11 @@ function lt() {
|
|
|
299
323
|
return (e, t) => t;
|
|
300
324
|
}
|
|
301
325
|
}
|
|
302
|
-
function
|
|
303
|
-
let { isOpen: r, toggle: i } =
|
|
304
|
-
return /* @__PURE__ */
|
|
326
|
+
function Wt({ position: e = "bottom-right", size: t = 56, className: n }) {
|
|
327
|
+
let { isOpen: r, toggle: i } = Ht(), a = Ut();
|
|
328
|
+
return /* @__PURE__ */ q(v, {
|
|
305
329
|
onClick: i,
|
|
306
|
-
className:
|
|
330
|
+
className: U("fixed z-50 rounded-full shadow-lg transition-transform hover:scale-105", e === "bottom-right" ? "right-6 bottom-20 sm:bottom-6" : "left-6 bottom-20 sm:bottom-6", n),
|
|
307
331
|
style: {
|
|
308
332
|
width: t,
|
|
309
333
|
height: t
|
|
@@ -311,13 +335,13 @@ function ut({ position: e = "bottom-right", size: t = 56, className: n }) {
|
|
|
311
335
|
size: "icon",
|
|
312
336
|
"aria-label": r ? a("closeChat", "Close chat") : a("openChat", "Open chat"),
|
|
313
337
|
"data-testid": "floating-chatbot-trigger",
|
|
314
|
-
children:
|
|
338
|
+
children: q(r ? dt : nt, { className: "h-6 w-6" })
|
|
315
339
|
});
|
|
316
340
|
}
|
|
317
341
|
//#endregion
|
|
318
342
|
//#region src/FloatingChatbotPanel.tsx
|
|
319
|
-
function
|
|
320
|
-
let { isOpen: s, isFullscreen: c, close: l, toggleFullscreen: u } =
|
|
343
|
+
function Gt({ title: e = "Chat", position: t = "bottom-right", width: n = 400, height: r = 520, children: i, className: a, headerExtra: o }) {
|
|
344
|
+
let { isOpen: s, isFullscreen: c, close: l, toggleFullscreen: u } = Ht();
|
|
321
345
|
if (!s) return null;
|
|
322
346
|
let d = c ? {
|
|
323
347
|
inset: 0,
|
|
@@ -328,46 +352,46 @@ function dt({ title: e = "Chat", position: t = "bottom-right", width: n = 400, h
|
|
|
328
352
|
height: r,
|
|
329
353
|
maxHeight: "calc(100vh - 100px)"
|
|
330
354
|
};
|
|
331
|
-
return /* @__PURE__ */
|
|
332
|
-
className:
|
|
355
|
+
return /* @__PURE__ */ J("div", {
|
|
356
|
+
className: U("fixed z-50 flex flex-col rounded-lg border bg-background shadow-xl overflow-hidden transition-all", c ? "inset-0 rounded-none" : t === "bottom-right" ? "right-6 bottom-20" : "left-6 bottom-20", a),
|
|
333
357
|
style: d,
|
|
334
358
|
role: "dialog",
|
|
335
359
|
"aria-label": e,
|
|
336
360
|
"data-testid": "floating-chatbot-panel",
|
|
337
|
-
children: [/* @__PURE__ */
|
|
361
|
+
children: [/* @__PURE__ */ J("div", {
|
|
338
362
|
className: "flex items-center justify-between gap-2 px-4 py-2 border-b bg-muted/40",
|
|
339
363
|
children: [
|
|
340
|
-
/* @__PURE__ */
|
|
364
|
+
/* @__PURE__ */ q("span", {
|
|
341
365
|
className: "text-sm font-medium truncate shrink-0",
|
|
342
366
|
children: e
|
|
343
367
|
}),
|
|
344
|
-
o ? /* @__PURE__ */
|
|
368
|
+
o ? /* @__PURE__ */ q("div", {
|
|
345
369
|
className: "flex-1 min-w-0 flex items-center justify-end mr-1",
|
|
346
370
|
"data-testid": "floating-chatbot-header-extra",
|
|
347
371
|
children: o
|
|
348
372
|
}) : null,
|
|
349
|
-
/* @__PURE__ */
|
|
373
|
+
/* @__PURE__ */ J("div", {
|
|
350
374
|
className: "flex items-center gap-1 shrink-0",
|
|
351
|
-
children: [/* @__PURE__ */
|
|
375
|
+
children: [/* @__PURE__ */ q(v, {
|
|
352
376
|
variant: "ghost",
|
|
353
377
|
size: "icon",
|
|
354
378
|
className: "h-7 w-7",
|
|
355
379
|
onClick: u,
|
|
356
380
|
"aria-label": c ? "Exit fullscreen" : "Fullscreen",
|
|
357
381
|
"data-testid": "floating-chatbot-fullscreen",
|
|
358
|
-
children:
|
|
359
|
-
}), /* @__PURE__ */
|
|
382
|
+
children: q(c ? it : tt, { className: "h-4 w-4" })
|
|
383
|
+
}), /* @__PURE__ */ q(v, {
|
|
360
384
|
variant: "ghost",
|
|
361
385
|
size: "icon",
|
|
362
386
|
className: "h-7 w-7",
|
|
363
387
|
onClick: l,
|
|
364
388
|
"aria-label": "Close chat",
|
|
365
389
|
"data-testid": "floating-chatbot-close",
|
|
366
|
-
children: /* @__PURE__ */
|
|
390
|
+
children: /* @__PURE__ */ q(dt, { className: "h-4 w-4" })
|
|
367
391
|
})]
|
|
368
392
|
})
|
|
369
393
|
]
|
|
370
|
-
}), /* @__PURE__ */
|
|
394
|
+
}), /* @__PURE__ */ q("div", {
|
|
371
395
|
className: "flex-1 overflow-hidden",
|
|
372
396
|
children: i
|
|
373
397
|
})]
|
|
@@ -375,99 +399,99 @@ function dt({ title: e = "Chat", position: t = "bottom-right", width: n = 400, h
|
|
|
375
399
|
}
|
|
376
400
|
//#endregion
|
|
377
401
|
//#region src/elements/conversation.tsx
|
|
378
|
-
var
|
|
379
|
-
className:
|
|
402
|
+
var Kt = ({ className: e, ...t }) => /* @__PURE__ */ q(_t, {
|
|
403
|
+
className: U("relative flex-1 overflow-y-hidden", e),
|
|
380
404
|
initial: "smooth",
|
|
381
405
|
resize: "smooth",
|
|
382
406
|
role: "log",
|
|
383
407
|
...t
|
|
384
|
-
}),
|
|
385
|
-
className:
|
|
408
|
+
}), qt = ({ className: e, ...t }) => /* @__PURE__ */ q(_t.Content, {
|
|
409
|
+
className: U("flex flex-col gap-8 p-4", e),
|
|
386
410
|
...t
|
|
387
|
-
}),
|
|
388
|
-
className:
|
|
411
|
+
}), Jt = ({ className: e, title: t = "No messages yet", description: n = "Start a conversation to see messages here", icon: r, children: i, ...a }) => /* @__PURE__ */ q("div", {
|
|
412
|
+
className: U("flex size-full flex-col items-center justify-center gap-3 p-8 text-center", e),
|
|
389
413
|
...a,
|
|
390
|
-
children: i ?? /* @__PURE__ */
|
|
414
|
+
children: i ?? /* @__PURE__ */ J(K, { children: [r && /* @__PURE__ */ q("div", {
|
|
391
415
|
className: "text-muted-foreground",
|
|
392
416
|
children: r
|
|
393
|
-
}), /* @__PURE__ */
|
|
417
|
+
}), /* @__PURE__ */ J("div", {
|
|
394
418
|
className: "space-y-1",
|
|
395
|
-
children: [/* @__PURE__ */
|
|
419
|
+
children: [/* @__PURE__ */ q("h3", {
|
|
396
420
|
className: "font-medium text-sm",
|
|
397
421
|
children: t
|
|
398
|
-
}), n && /* @__PURE__ */
|
|
422
|
+
}), n && /* @__PURE__ */ q("p", {
|
|
399
423
|
className: "text-muted-foreground text-sm",
|
|
400
424
|
children: n
|
|
401
425
|
})]
|
|
402
426
|
})] })
|
|
403
|
-
}),
|
|
404
|
-
let { isAtBottom: n, scrollToBottom: r } =
|
|
427
|
+
}), Yt = ({ className: e, ...t }) => {
|
|
428
|
+
let { isAtBottom: n, scrollToBottom: r } = vt(), i = o(() => {
|
|
405
429
|
r();
|
|
406
430
|
}, [r]);
|
|
407
|
-
return !n && /* @__PURE__ */
|
|
408
|
-
className:
|
|
431
|
+
return !n && /* @__PURE__ */ q(v, {
|
|
432
|
+
className: U("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full", e),
|
|
409
433
|
onClick: i,
|
|
410
434
|
size: "icon",
|
|
411
435
|
type: "button",
|
|
412
436
|
variant: "outline",
|
|
413
437
|
...t,
|
|
414
|
-
children: /* @__PURE__ */
|
|
438
|
+
children: /* @__PURE__ */ q(Pe, { className: "size-4" })
|
|
415
439
|
});
|
|
416
|
-
},
|
|
440
|
+
}, Xt = yt("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1", {
|
|
417
441
|
variants: { orientation: {
|
|
418
442
|
horizontal: "[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
|
|
419
443
|
vertical: "flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"
|
|
420
444
|
} },
|
|
421
445
|
defaultVariants: { orientation: "horizontal" }
|
|
422
446
|
});
|
|
423
|
-
function
|
|
424
|
-
return /* @__PURE__ */
|
|
447
|
+
function Zt({ className: e, orientation: t, ...n }) {
|
|
448
|
+
return /* @__PURE__ */ q("div", {
|
|
425
449
|
role: "group",
|
|
426
450
|
"data-slot": "button-group",
|
|
427
451
|
"data-orientation": t,
|
|
428
|
-
className:
|
|
452
|
+
className: U(Xt({ orientation: t }), e),
|
|
429
453
|
...n
|
|
430
454
|
});
|
|
431
455
|
}
|
|
432
|
-
function
|
|
433
|
-
return /* @__PURE__ */
|
|
434
|
-
className:
|
|
456
|
+
function Qt({ className: e, asChild: t = !1, ...n }) {
|
|
457
|
+
return /* @__PURE__ */ q(t ? bt : "div", {
|
|
458
|
+
className: U("flex items-center gap-2 rounded-md border bg-muted px-4 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", e),
|
|
435
459
|
...n
|
|
436
460
|
});
|
|
437
461
|
}
|
|
438
462
|
//#endregion
|
|
439
463
|
//#region src/elements/message.tsx
|
|
440
|
-
var
|
|
441
|
-
className:
|
|
464
|
+
var $t = ({ className: e, from: t, ...n }) => /* @__PURE__ */ q("div", {
|
|
465
|
+
className: U("group flex w-full max-w-[95%] flex-col gap-2", t === "user" ? "is-user ml-auto justify-end" : "is-assistant", e),
|
|
442
466
|
...n
|
|
443
|
-
}),
|
|
444
|
-
className:
|
|
467
|
+
}), en = ({ children: e, className: t, ...n }) => /* @__PURE__ */ q("div", {
|
|
468
|
+
className: U("is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm", "group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground", "group-[.is-assistant]:text-foreground", t),
|
|
445
469
|
...n,
|
|
446
470
|
children: e
|
|
447
|
-
}),
|
|
448
|
-
className:
|
|
471
|
+
}), tn = ({ className: e, children: t, ...n }) => /* @__PURE__ */ q("div", {
|
|
472
|
+
className: U("flex items-center gap-1", e),
|
|
449
473
|
...n,
|
|
450
474
|
children: t
|
|
451
|
-
}),
|
|
452
|
-
let o = /* @__PURE__ */
|
|
475
|
+
}), nn = ({ tooltip: e, children: t, label: n, variant: r = "ghost", size: i = "icon", ...a }) => {
|
|
476
|
+
let o = /* @__PURE__ */ J(v, {
|
|
453
477
|
size: i,
|
|
454
478
|
type: "button",
|
|
455
479
|
variant: r,
|
|
456
480
|
...a,
|
|
457
|
-
children: [t, /* @__PURE__ */
|
|
481
|
+
children: [t, /* @__PURE__ */ q("span", {
|
|
458
482
|
className: "sr-only",
|
|
459
483
|
children: n || e
|
|
460
484
|
})]
|
|
461
485
|
});
|
|
462
|
-
return e ? /* @__PURE__ */
|
|
486
|
+
return e ? /* @__PURE__ */ q(je, { children: /* @__PURE__ */ J(ke, { children: [/* @__PURE__ */ q(Me, {
|
|
463
487
|
asChild: !0,
|
|
464
488
|
children: o
|
|
465
|
-
}), /* @__PURE__ */
|
|
466
|
-
},
|
|
467
|
-
let e = s(
|
|
489
|
+
}), /* @__PURE__ */ q(Ae, { children: /* @__PURE__ */ q("p", { children: e }) })] }) }) : o;
|
|
490
|
+
}, rn = r(null), X = () => {
|
|
491
|
+
let e = s(rn);
|
|
468
492
|
if (!e) throw Error("MessageBranch components must be used within MessageBranch");
|
|
469
493
|
return e;
|
|
470
|
-
},
|
|
494
|
+
}, an = ({ defaultBranch: e = 0, onBranchChange: t, className: n, ...r }) => {
|
|
471
495
|
let [i, a] = d(e), [o, s] = d([]), c = (e) => {
|
|
472
496
|
a(e), t?.(e);
|
|
473
497
|
}, l = {
|
|
@@ -482,36 +506,36 @@ var yt = ({ className: e, from: t, ...n }) => /* @__PURE__ */ V("div", {
|
|
|
482
506
|
branches: o,
|
|
483
507
|
setBranches: s
|
|
484
508
|
};
|
|
485
|
-
return /* @__PURE__ */
|
|
509
|
+
return /* @__PURE__ */ q(rn.Provider, {
|
|
486
510
|
value: l,
|
|
487
|
-
children: /* @__PURE__ */
|
|
488
|
-
className:
|
|
511
|
+
children: /* @__PURE__ */ q("div", {
|
|
512
|
+
className: U("grid w-full gap-2 [&>div]:pb-0", n),
|
|
489
513
|
...r
|
|
490
514
|
})
|
|
491
515
|
});
|
|
492
|
-
},
|
|
493
|
-
let { currentBranch: n, setBranches: r, branches: i } =
|
|
516
|
+
}, on = ({ children: e, ...t }) => {
|
|
517
|
+
let { currentBranch: n, setBranches: r, branches: i } = X(), a = Array.isArray(e) ? e : [e];
|
|
494
518
|
return c(() => {
|
|
495
519
|
i.length !== a.length && r(a);
|
|
496
520
|
}, [
|
|
497
521
|
a,
|
|
498
522
|
i,
|
|
499
523
|
r
|
|
500
|
-
]), a.map((e, r) => /* @__PURE__ */
|
|
501
|
-
className:
|
|
524
|
+
]), a.map((e, r) => /* @__PURE__ */ q("div", {
|
|
525
|
+
className: U("grid gap-2 overflow-hidden [&>div]:pb-0", r === n ? "block" : "hidden"),
|
|
502
526
|
...t,
|
|
503
527
|
children: e
|
|
504
528
|
}, e.key));
|
|
505
|
-
},
|
|
506
|
-
let { totalBranches: r } =
|
|
507
|
-
return r <= 1 ? null : /* @__PURE__ */
|
|
529
|
+
}, sn = ({ className: e, from: t, ...n }) => {
|
|
530
|
+
let { totalBranches: r } = X();
|
|
531
|
+
return r <= 1 ? null : /* @__PURE__ */ q(Zt, {
|
|
508
532
|
className: "[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md",
|
|
509
533
|
orientation: "horizontal",
|
|
510
534
|
...n
|
|
511
535
|
});
|
|
512
|
-
},
|
|
513
|
-
let { goToPrevious: n, totalBranches: r } =
|
|
514
|
-
return /* @__PURE__ */
|
|
536
|
+
}, cn = ({ children: e, ...t }) => {
|
|
537
|
+
let { goToPrevious: n, totalBranches: r } = X();
|
|
538
|
+
return /* @__PURE__ */ q(v, {
|
|
515
539
|
"aria-label": "Previous branch",
|
|
516
540
|
disabled: r <= 1,
|
|
517
541
|
onClick: n,
|
|
@@ -519,11 +543,11 @@ var yt = ({ className: e, from: t, ...n }) => /* @__PURE__ */ V("div", {
|
|
|
519
543
|
type: "button",
|
|
520
544
|
variant: "ghost",
|
|
521
545
|
...t,
|
|
522
|
-
children: e ?? /* @__PURE__ */
|
|
546
|
+
children: e ?? /* @__PURE__ */ q(Ue, { size: 14 })
|
|
523
547
|
});
|
|
524
|
-
},
|
|
525
|
-
let { goToNext: r, totalBranches: i } =
|
|
526
|
-
return /* @__PURE__ */
|
|
548
|
+
}, ln = ({ children: e, className: t, ...n }) => {
|
|
549
|
+
let { goToNext: r, totalBranches: i } = X();
|
|
550
|
+
return /* @__PURE__ */ q(v, {
|
|
527
551
|
"aria-label": "Next branch",
|
|
528
552
|
disabled: i <= 1,
|
|
529
553
|
onClick: r,
|
|
@@ -531,12 +555,12 @@ var yt = ({ className: e, from: t, ...n }) => /* @__PURE__ */ V("div", {
|
|
|
531
555
|
type: "button",
|
|
532
556
|
variant: "ghost",
|
|
533
557
|
...n,
|
|
534
|
-
children: e ?? /* @__PURE__ */
|
|
558
|
+
children: e ?? /* @__PURE__ */ q(We, { size: 14 })
|
|
535
559
|
});
|
|
536
|
-
},
|
|
537
|
-
let { currentBranch: n, totalBranches: r } =
|
|
538
|
-
return /* @__PURE__ */
|
|
539
|
-
className:
|
|
560
|
+
}, un = ({ className: e, ...t }) => {
|
|
561
|
+
let { currentBranch: n, totalBranches: r } = X();
|
|
562
|
+
return /* @__PURE__ */ J(Qt, {
|
|
563
|
+
className: U("border-none bg-transparent text-muted-foreground shadow-none", e),
|
|
540
564
|
...t,
|
|
541
565
|
children: [
|
|
542
566
|
n + 1,
|
|
@@ -544,23 +568,23 @@ var yt = ({ className: e, from: t, ...n }) => /* @__PURE__ */ V("div", {
|
|
|
544
568
|
r
|
|
545
569
|
]
|
|
546
570
|
});
|
|
547
|
-
},
|
|
548
|
-
className:
|
|
571
|
+
}, dn = a(({ className: e, ...t }) => /* @__PURE__ */ q(xt, {
|
|
572
|
+
className: U("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", e),
|
|
549
573
|
...t
|
|
550
574
|
}), (e, t) => e.children === t.children);
|
|
551
|
-
|
|
552
|
-
function
|
|
575
|
+
dn.displayName = "MessageResponse";
|
|
576
|
+
function fn({ data: e, className: t, onRemove: n, ...r }) {
|
|
553
577
|
let i = e.filename || "", a = (e.mediaType?.startsWith("image/") && e.url ? "image" : "file") == "image", o = i || (a ? "Image" : "Attachment");
|
|
554
|
-
return /* @__PURE__ */
|
|
555
|
-
className:
|
|
578
|
+
return /* @__PURE__ */ q("div", {
|
|
579
|
+
className: U("group relative size-24 overflow-hidden rounded-lg", t),
|
|
556
580
|
...r,
|
|
557
|
-
children: a ? /* @__PURE__ */
|
|
581
|
+
children: a ? /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ q("img", {
|
|
558
582
|
alt: i || "attachment",
|
|
559
583
|
className: "size-full object-cover",
|
|
560
584
|
height: 100,
|
|
561
585
|
src: e.url,
|
|
562
586
|
width: 100
|
|
563
|
-
}), n && /* @__PURE__ */
|
|
587
|
+
}), n && /* @__PURE__ */ J(v, {
|
|
564
588
|
"aria-label": "Remove attachment",
|
|
565
589
|
className: "absolute top-2 right-2 size-6 rounded-full bg-background/80 p-0 opacity-0 backdrop-blur-sm transition-opacity hover:bg-background group-hover:opacity-100 [&>svg]:size-3",
|
|
566
590
|
onClick: (e) => {
|
|
@@ -568,17 +592,17 @@ function At({ data: e, className: t, onRemove: n, ...r }) {
|
|
|
568
592
|
},
|
|
569
593
|
type: "button",
|
|
570
594
|
variant: "ghost",
|
|
571
|
-
children: [/* @__PURE__ */
|
|
595
|
+
children: [/* @__PURE__ */ q(G, {}), /* @__PURE__ */ q("span", {
|
|
572
596
|
className: "sr-only",
|
|
573
597
|
children: "Remove"
|
|
574
598
|
})]
|
|
575
|
-
})] }) : /* @__PURE__ */
|
|
599
|
+
})] }) : /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ J(ke, { children: [/* @__PURE__ */ q(Me, {
|
|
576
600
|
asChild: !0,
|
|
577
|
-
children: /* @__PURE__ */
|
|
601
|
+
children: /* @__PURE__ */ q("div", {
|
|
578
602
|
className: "flex size-full shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",
|
|
579
|
-
children: /* @__PURE__ */
|
|
603
|
+
children: /* @__PURE__ */ q(at, { className: "size-4" })
|
|
580
604
|
})
|
|
581
|
-
}), /* @__PURE__ */
|
|
605
|
+
}), /* @__PURE__ */ q(Ae, { children: /* @__PURE__ */ q("p", { children: o }) })] }), n && /* @__PURE__ */ J(v, {
|
|
582
606
|
"aria-label": "Remove attachment",
|
|
583
607
|
className: "size-6 shrink-0 rounded-full p-0 opacity-0 transition-opacity hover:bg-accent group-hover:opacity-100 [&>svg]:size-3",
|
|
584
608
|
onClick: (e) => {
|
|
@@ -586,36 +610,36 @@ function At({ data: e, className: t, onRemove: n, ...r }) {
|
|
|
586
610
|
},
|
|
587
611
|
type: "button",
|
|
588
612
|
variant: "ghost",
|
|
589
|
-
children: [/* @__PURE__ */
|
|
613
|
+
children: [/* @__PURE__ */ q(G, {}), /* @__PURE__ */ q("span", {
|
|
590
614
|
className: "sr-only",
|
|
591
615
|
children: "Remove"
|
|
592
616
|
})]
|
|
593
617
|
})] })
|
|
594
618
|
});
|
|
595
619
|
}
|
|
596
|
-
function
|
|
597
|
-
return e ? /* @__PURE__ */
|
|
598
|
-
className:
|
|
620
|
+
function pn({ children: e, className: t, ...n }) {
|
|
621
|
+
return e ? /* @__PURE__ */ q("div", {
|
|
622
|
+
className: U("ml-auto flex w-fit flex-wrap items-start gap-2", t),
|
|
599
623
|
...n,
|
|
600
624
|
children: e
|
|
601
625
|
}) : null;
|
|
602
626
|
}
|
|
603
|
-
var
|
|
604
|
-
className:
|
|
627
|
+
var mn = ({ className: e, children: t, ...n }) => /* @__PURE__ */ q("div", {
|
|
628
|
+
className: U("mt-4 flex w-full items-center justify-between gap-4", e),
|
|
605
629
|
...n,
|
|
606
630
|
children: t
|
|
607
631
|
});
|
|
608
632
|
//#endregion
|
|
609
633
|
//#region src/elements/ui/input-group.tsx
|
|
610
|
-
function
|
|
611
|
-
return /* @__PURE__ */
|
|
634
|
+
function hn({ className: e, ...t }) {
|
|
635
|
+
return /* @__PURE__ */ q("div", {
|
|
612
636
|
"data-slot": "input-group",
|
|
613
637
|
role: "group",
|
|
614
|
-
className:
|
|
638
|
+
className: U("group/input-group relative flex w-full items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none dark:bg-input/30", "h-9 min-w-0 has-[>textarea]:h-auto", "has-[>[data-align=inline-start]]:[&>input]:pl-2", "has-[>[data-align=inline-end]]:[&>input]:pr-2", "has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3", "has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3", "has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50", "has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40", e),
|
|
615
639
|
...t
|
|
616
640
|
});
|
|
617
641
|
}
|
|
618
|
-
var
|
|
642
|
+
var gn = yt("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4", {
|
|
619
643
|
variants: { align: {
|
|
620
644
|
"inline-start": "order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]",
|
|
621
645
|
"inline-end": "order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]",
|
|
@@ -624,19 +648,19 @@ var Pt = U("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 tex
|
|
|
624
648
|
} },
|
|
625
649
|
defaultVariants: { align: "inline-start" }
|
|
626
650
|
});
|
|
627
|
-
function
|
|
628
|
-
return /* @__PURE__ */
|
|
651
|
+
function _n({ className: e, align: t = "inline-start", ...n }) {
|
|
652
|
+
return /* @__PURE__ */ q("div", {
|
|
629
653
|
role: "group",
|
|
630
654
|
"data-slot": "input-group-addon",
|
|
631
655
|
"data-align": t,
|
|
632
|
-
className:
|
|
656
|
+
className: U(gn({ align: t }), e),
|
|
633
657
|
onClick: (e) => {
|
|
634
658
|
e.target.closest("button") || e.currentTarget.parentElement?.querySelector("input")?.focus();
|
|
635
659
|
},
|
|
636
660
|
...n
|
|
637
661
|
});
|
|
638
662
|
}
|
|
639
|
-
var
|
|
663
|
+
var vn = yt("flex items-center gap-2 text-sm shadow-none", {
|
|
640
664
|
variants: { size: {
|
|
641
665
|
xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",
|
|
642
666
|
sm: "h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5",
|
|
@@ -645,38 +669,38 @@ var It = U("flex items-center gap-2 text-sm shadow-none", {
|
|
|
645
669
|
} },
|
|
646
670
|
defaultVariants: { size: "xs" }
|
|
647
671
|
});
|
|
648
|
-
function
|
|
649
|
-
return /* @__PURE__ */
|
|
672
|
+
function yn({ className: e, type: t = "button", variant: n = "ghost", size: r = "xs", ...i }) {
|
|
673
|
+
return /* @__PURE__ */ q(v, {
|
|
650
674
|
type: t,
|
|
651
675
|
"data-size": r,
|
|
652
676
|
variant: n,
|
|
653
|
-
className:
|
|
677
|
+
className: U(vn({ size: r }), e),
|
|
654
678
|
...i
|
|
655
679
|
});
|
|
656
680
|
}
|
|
657
|
-
function
|
|
658
|
-
return /* @__PURE__ */
|
|
681
|
+
function bn({ className: e, ...t }) {
|
|
682
|
+
return /* @__PURE__ */ q(Oe, {
|
|
659
683
|
"data-slot": "input-group-control",
|
|
660
|
-
className:
|
|
684
|
+
className: U("flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent", e),
|
|
661
685
|
...t
|
|
662
686
|
});
|
|
663
687
|
}
|
|
664
688
|
//#endregion
|
|
665
689
|
//#region src/elements/prompt-input.tsx
|
|
666
|
-
var
|
|
667
|
-
let e = s(
|
|
690
|
+
var xn = r(null), Sn = r(null), Cn = () => {
|
|
691
|
+
let e = s(xn);
|
|
668
692
|
if (!e) throw Error("Wrap your component inside <PromptInputProvider> to use usePromptInputController().");
|
|
669
693
|
return e;
|
|
670
|
-
},
|
|
671
|
-
let e = s(
|
|
694
|
+
}, wn = () => s(xn), Tn = () => {
|
|
695
|
+
let e = s(Sn);
|
|
672
696
|
if (!e) throw Error("Wrap your component inside <PromptInputProvider> to use useProviderAttachments().");
|
|
673
697
|
return e;
|
|
674
|
-
},
|
|
675
|
-
function
|
|
698
|
+
}, En = () => s(Sn);
|
|
699
|
+
function Dn({ initialInput: e = "", children: t }) {
|
|
676
700
|
let [n, r] = d(e), i = o(() => r(""), []), [a, s] = d([]), f = u(null), p = u(() => {}), m = o((e) => {
|
|
677
701
|
let t = Array.from(e);
|
|
678
702
|
t.length !== 0 && s((e) => e.concat(t.map((e) => ({
|
|
679
|
-
id:
|
|
703
|
+
id: St(),
|
|
680
704
|
type: "file",
|
|
681
705
|
url: URL.createObjectURL(e),
|
|
682
706
|
mediaType: e.type,
|
|
@@ -727,41 +751,41 @@ function Wt({ initialInput: e = "", children: t }) {
|
|
|
727
751
|
y,
|
|
728
752
|
b
|
|
729
753
|
]);
|
|
730
|
-
return /* @__PURE__ */
|
|
754
|
+
return /* @__PURE__ */ q(xn.Provider, {
|
|
731
755
|
value: x,
|
|
732
|
-
children: /* @__PURE__ */
|
|
756
|
+
children: /* @__PURE__ */ q(Sn.Provider, {
|
|
733
757
|
value: y,
|
|
734
758
|
children: t
|
|
735
759
|
})
|
|
736
760
|
});
|
|
737
761
|
}
|
|
738
|
-
var
|
|
739
|
-
let e =
|
|
762
|
+
var On = r(null), Z = () => {
|
|
763
|
+
let e = En(), t = s(On), n = e ?? t;
|
|
740
764
|
if (!n) throw Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");
|
|
741
765
|
return n;
|
|
742
766
|
};
|
|
743
|
-
function
|
|
767
|
+
function kn({ data: e, className: t, ...n }) {
|
|
744
768
|
let r = Z(), i = e.filename || "", a = (e.mediaType?.startsWith("image/") && e.url ? "image" : "file") == "image", o = i || (a ? "Image" : "Attachment");
|
|
745
|
-
return /* @__PURE__ */
|
|
769
|
+
return /* @__PURE__ */ J(Xn, { children: [/* @__PURE__ */ q(z, {
|
|
746
770
|
asChild: !0,
|
|
747
|
-
children: /* @__PURE__ */
|
|
748
|
-
className:
|
|
771
|
+
children: /* @__PURE__ */ J("div", {
|
|
772
|
+
className: U("group relative flex h-8 cursor-pointer select-none items-center gap-1.5 rounded-md border border-border px-1.5 font-medium text-sm transition-all hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50", t),
|
|
749
773
|
...n,
|
|
750
|
-
children: [/* @__PURE__ */
|
|
774
|
+
children: [/* @__PURE__ */ J("div", {
|
|
751
775
|
className: "relative size-5 shrink-0",
|
|
752
|
-
children: [/* @__PURE__ */
|
|
776
|
+
children: [/* @__PURE__ */ q("div", {
|
|
753
777
|
className: "absolute inset-0 flex size-5 items-center justify-center overflow-hidden rounded bg-background transition-opacity group-hover:opacity-0",
|
|
754
|
-
children: a ? /* @__PURE__ */
|
|
778
|
+
children: a ? /* @__PURE__ */ q("img", {
|
|
755
779
|
alt: i || "attachment",
|
|
756
780
|
className: "size-5 object-cover",
|
|
757
781
|
height: 20,
|
|
758
782
|
src: e.url,
|
|
759
783
|
width: 20
|
|
760
|
-
}) : /* @__PURE__ */
|
|
784
|
+
}) : /* @__PURE__ */ q("div", {
|
|
761
785
|
className: "flex size-5 items-center justify-center text-muted-foreground",
|
|
762
|
-
children: /* @__PURE__ */
|
|
786
|
+
children: /* @__PURE__ */ q(at, { className: "size-3" })
|
|
763
787
|
})
|
|
764
|
-
}), /* @__PURE__ */
|
|
788
|
+
}), /* @__PURE__ */ J(v, {
|
|
765
789
|
"aria-label": "Remove attachment",
|
|
766
790
|
className: "absolute inset-0 size-5 cursor-pointer rounded p-0 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 [&>svg]:size-2.5",
|
|
767
791
|
onClick: (t) => {
|
|
@@ -769,37 +793,37 @@ function Kt({ data: e, className: t, ...n }) {
|
|
|
769
793
|
},
|
|
770
794
|
type: "button",
|
|
771
795
|
variant: "ghost",
|
|
772
|
-
children: [/* @__PURE__ */
|
|
796
|
+
children: [/* @__PURE__ */ q(G, {}), /* @__PURE__ */ q("span", {
|
|
773
797
|
className: "sr-only",
|
|
774
798
|
children: "Remove"
|
|
775
799
|
})]
|
|
776
800
|
})]
|
|
777
|
-
}), /* @__PURE__ */
|
|
801
|
+
}), /* @__PURE__ */ q("span", {
|
|
778
802
|
className: "flex-1 truncate",
|
|
779
803
|
children: o
|
|
780
804
|
})]
|
|
781
805
|
}, e.id)
|
|
782
|
-
}), /* @__PURE__ */
|
|
806
|
+
}), /* @__PURE__ */ q(Qn, {
|
|
783
807
|
className: "w-auto p-2",
|
|
784
|
-
children: /* @__PURE__ */
|
|
808
|
+
children: /* @__PURE__ */ J("div", {
|
|
785
809
|
className: "w-auto space-y-3",
|
|
786
|
-
children: [a && /* @__PURE__ */
|
|
810
|
+
children: [a && /* @__PURE__ */ q("div", {
|
|
787
811
|
className: "flex max-h-96 w-96 items-center justify-center overflow-hidden rounded-md border",
|
|
788
|
-
children: /* @__PURE__ */
|
|
812
|
+
children: /* @__PURE__ */ q("img", {
|
|
789
813
|
alt: i || "attachment preview",
|
|
790
814
|
className: "max-h-full max-w-full object-contain",
|
|
791
815
|
height: 384,
|
|
792
816
|
src: e.url,
|
|
793
817
|
width: 448
|
|
794
818
|
})
|
|
795
|
-
}), /* @__PURE__ */
|
|
819
|
+
}), /* @__PURE__ */ q("div", {
|
|
796
820
|
className: "flex items-center gap-2.5",
|
|
797
|
-
children: /* @__PURE__ */
|
|
821
|
+
children: /* @__PURE__ */ J("div", {
|
|
798
822
|
className: "min-w-0 flex-1 space-y-1 px-0.5",
|
|
799
|
-
children: [/* @__PURE__ */
|
|
823
|
+
children: [/* @__PURE__ */ q("h4", {
|
|
800
824
|
className: "truncate font-semibold text-sm leading-none",
|
|
801
825
|
children: i || (a ? "Image" : "Attachment")
|
|
802
|
-
}), e.mediaType && /* @__PURE__ */
|
|
826
|
+
}), e.mediaType && /* @__PURE__ */ q("p", {
|
|
803
827
|
className: "truncate font-mono text-muted-foreground text-xs",
|
|
804
828
|
children: e.mediaType
|
|
805
829
|
})]
|
|
@@ -808,29 +832,29 @@ function Kt({ data: e, className: t, ...n }) {
|
|
|
808
832
|
})
|
|
809
833
|
})] });
|
|
810
834
|
}
|
|
811
|
-
function
|
|
835
|
+
function An({ children: e, className: t, ...r }) {
|
|
812
836
|
let i = Z();
|
|
813
|
-
return i.files.length ? /* @__PURE__ */
|
|
814
|
-
className:
|
|
837
|
+
return i.files.length ? /* @__PURE__ */ q("div", {
|
|
838
|
+
className: U("flex flex-wrap items-center gap-2 p-3 w-full", t),
|
|
815
839
|
...r,
|
|
816
|
-
children: i.files.map((t) => /* @__PURE__ */
|
|
840
|
+
children: i.files.map((t) => /* @__PURE__ */ q(n, { children: e(t) }, t.id))
|
|
817
841
|
}) : null;
|
|
818
842
|
}
|
|
819
|
-
var
|
|
843
|
+
var jn = ({ label: e = "Add photos or files", ...t }) => {
|
|
820
844
|
let n = Z();
|
|
821
|
-
return /* @__PURE__ */
|
|
845
|
+
return /* @__PURE__ */ J(I, {
|
|
822
846
|
...t,
|
|
823
847
|
onSelect: (e) => {
|
|
824
848
|
e.preventDefault(), n.openFileDialog();
|
|
825
849
|
},
|
|
826
850
|
children: [
|
|
827
|
-
/* @__PURE__ */
|
|
851
|
+
/* @__PURE__ */ q(Qe, { className: "mr-2 size-4" }),
|
|
828
852
|
" ",
|
|
829
853
|
e
|
|
830
854
|
]
|
|
831
855
|
});
|
|
832
|
-
},
|
|
833
|
-
let g =
|
|
856
|
+
}, Mn = ({ className: e, accept: t, multiple: n, globalDrop: r, syncHiddenInput: i, maxFiles: a, maxFileSize: s, onError: f, onSubmit: p, children: m, ...h }) => {
|
|
857
|
+
let g = wn(), _ = !!g, v = u(null), y = u(null), [b, x] = d([]), S = _ ? g.attachments.files : b, C = u(S);
|
|
834
858
|
C.current = S;
|
|
835
859
|
let w = o(() => {
|
|
836
860
|
v.current?.click();
|
|
@@ -865,7 +889,7 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
865
889
|
});
|
|
866
890
|
let i = [];
|
|
867
891
|
for (let e of n) i.push({
|
|
868
|
-
id:
|
|
892
|
+
id: St(),
|
|
869
893
|
type: "file",
|
|
870
894
|
url: URL.createObjectURL(e),
|
|
871
895
|
mediaType: e.type,
|
|
@@ -941,7 +965,7 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
941
965
|
A,
|
|
942
966
|
j,
|
|
943
967
|
M
|
|
944
|
-
]), I = /* @__PURE__ */
|
|
968
|
+
]), I = /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ q("input", {
|
|
945
969
|
accept: t,
|
|
946
970
|
"aria-label": "Upload files",
|
|
947
971
|
className: "hidden",
|
|
@@ -950,8 +974,8 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
950
974
|
ref: v,
|
|
951
975
|
title: "Upload files",
|
|
952
976
|
type: "file"
|
|
953
|
-
}), /* @__PURE__ */
|
|
954
|
-
className:
|
|
977
|
+
}), /* @__PURE__ */ q("form", {
|
|
978
|
+
className: U("w-full", e),
|
|
955
979
|
onSubmit: (e) => {
|
|
956
980
|
e.preventDefault();
|
|
957
981
|
let t = e.currentTarget, n = _ ? g.textInput.value : new FormData(t).get("message") || "";
|
|
@@ -978,20 +1002,20 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
978
1002
|
},
|
|
979
1003
|
ref: y,
|
|
980
1004
|
...h,
|
|
981
|
-
children: /* @__PURE__ */
|
|
1005
|
+
children: /* @__PURE__ */ q(hn, {
|
|
982
1006
|
className: "overflow-hidden",
|
|
983
1007
|
children: m
|
|
984
1008
|
})
|
|
985
1009
|
})] });
|
|
986
|
-
return _ ? I : /* @__PURE__ */
|
|
1010
|
+
return _ ? I : /* @__PURE__ */ q(On.Provider, {
|
|
987
1011
|
value: F,
|
|
988
1012
|
children: I
|
|
989
1013
|
});
|
|
990
|
-
},
|
|
991
|
-
className:
|
|
1014
|
+
}, Nn = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1015
|
+
className: U("contents", e),
|
|
992
1016
|
...t
|
|
993
|
-
}),
|
|
994
|
-
let i =
|
|
1017
|
+
}), Pn = ({ onChange: e, className: t, placeholder: n = "What would you like to know?", ...r }) => {
|
|
1018
|
+
let i = wn(), a = Z(), [o, s] = d(!1), c = (e) => {
|
|
995
1019
|
if (e.key === "Enter") {
|
|
996
1020
|
if (o || e.nativeEvent.isComposing || e.shiftKey) return;
|
|
997
1021
|
e.preventDefault();
|
|
@@ -1019,8 +1043,8 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1019
1043
|
i.textInput.setInput(t.currentTarget.value), e?.(t);
|
|
1020
1044
|
}
|
|
1021
1045
|
} : { onChange: e };
|
|
1022
|
-
return /* @__PURE__ */
|
|
1023
|
-
className:
|
|
1046
|
+
return /* @__PURE__ */ q(bn, {
|
|
1047
|
+
className: U("field-sizing-content max-h-48 min-h-16", t),
|
|
1024
1048
|
name: "message",
|
|
1025
1049
|
onCompositionEnd: () => s(!1),
|
|
1026
1050
|
onCompositionStart: () => s(!0),
|
|
@@ -1030,52 +1054,52 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1030
1054
|
...r,
|
|
1031
1055
|
...u
|
|
1032
1056
|
});
|
|
1033
|
-
},
|
|
1057
|
+
}, Fn = ({ className: e, ...t }) => /* @__PURE__ */ q(_n, {
|
|
1034
1058
|
align: "block-end",
|
|
1035
|
-
className:
|
|
1059
|
+
className: U("order-first flex-wrap gap-1", e),
|
|
1036
1060
|
...t
|
|
1037
|
-
}),
|
|
1061
|
+
}), In = ({ className: e, ...t }) => /* @__PURE__ */ q(_n, {
|
|
1038
1062
|
align: "block-end",
|
|
1039
|
-
className:
|
|
1063
|
+
className: U("justify-between gap-1", e),
|
|
1040
1064
|
...t
|
|
1041
|
-
}),
|
|
1042
|
-
className:
|
|
1065
|
+
}), Ln = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1066
|
+
className: U("flex items-center gap-1", e),
|
|
1043
1067
|
...t
|
|
1044
|
-
}),
|
|
1068
|
+
}), Rn = ({ variant: e = "ghost", className: n, size: r, ...i }) => {
|
|
1045
1069
|
let a = r ?? (t.count(i.children) > 1 ? "sm" : "icon-sm");
|
|
1046
|
-
return /* @__PURE__ */
|
|
1047
|
-
className:
|
|
1070
|
+
return /* @__PURE__ */ q(yn, {
|
|
1071
|
+
className: U(n),
|
|
1048
1072
|
size: a,
|
|
1049
1073
|
type: "button",
|
|
1050
1074
|
variant: e,
|
|
1051
1075
|
...i
|
|
1052
1076
|
});
|
|
1053
|
-
},
|
|
1077
|
+
}, zn = (e) => /* @__PURE__ */ q(P, { ...e }), Bn = ({ className: e, children: t, ...n }) => /* @__PURE__ */ q(L, {
|
|
1054
1078
|
asChild: !0,
|
|
1055
|
-
children: /* @__PURE__ */
|
|
1079
|
+
children: /* @__PURE__ */ q(Rn, {
|
|
1056
1080
|
className: e,
|
|
1057
1081
|
...n,
|
|
1058
|
-
children: t ?? /* @__PURE__ */
|
|
1082
|
+
children: t ?? /* @__PURE__ */ q(ot, { className: "size-4" })
|
|
1059
1083
|
})
|
|
1060
|
-
}),
|
|
1084
|
+
}), Vn = ({ className: e, ...t }) => /* @__PURE__ */ q(F, {
|
|
1061
1085
|
align: "start",
|
|
1062
|
-
className:
|
|
1086
|
+
className: U(e),
|
|
1063
1087
|
...t
|
|
1064
|
-
}),
|
|
1065
|
-
className:
|
|
1088
|
+
}), Hn = ({ className: e, ...t }) => /* @__PURE__ */ q(I, {
|
|
1089
|
+
className: U(e),
|
|
1066
1090
|
...t
|
|
1067
|
-
}),
|
|
1068
|
-
let o = /* @__PURE__ */
|
|
1069
|
-
return r === "submitted" ? o = /* @__PURE__ */
|
|
1091
|
+
}), Un = ({ className: e, variant: t = "default", size: n = "icon-sm", status: r, children: i, ...a }) => {
|
|
1092
|
+
let o = /* @__PURE__ */ q(Xe, { className: "size-4" });
|
|
1093
|
+
return r === "submitted" ? o = /* @__PURE__ */ q(et, { className: "size-4 animate-spin" }) : r === "streaming" ? o = /* @__PURE__ */ q(lt, { className: "size-4" }) : r === "error" && (o = /* @__PURE__ */ q(G, { className: "size-4" })), /* @__PURE__ */ q(yn, {
|
|
1070
1094
|
"aria-label": "Submit",
|
|
1071
|
-
className:
|
|
1095
|
+
className: U(e),
|
|
1072
1096
|
size: n,
|
|
1073
1097
|
type: "submit",
|
|
1074
1098
|
variant: t,
|
|
1075
1099
|
...a,
|
|
1076
1100
|
children: i ?? o
|
|
1077
1101
|
});
|
|
1078
|
-
},
|
|
1102
|
+
}, Wn = ({ className: e, textareaRef: t, onTranscriptionChange: n, ...r }) => {
|
|
1079
1103
|
let [i, a] = d(!1), [s, l] = d(null), f = u(null);
|
|
1080
1104
|
c(() => {
|
|
1081
1105
|
if (typeof window < "u" && ("SpeechRecognition" in window || "webkitSpeechRecognition" in window)) {
|
|
@@ -1105,80 +1129,80 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1105
1129
|
let p = o(() => {
|
|
1106
1130
|
s && (i ? s.stop() : s.start());
|
|
1107
1131
|
}, [s, i]);
|
|
1108
|
-
return /* @__PURE__ */
|
|
1109
|
-
className:
|
|
1132
|
+
return /* @__PURE__ */ q(Rn, {
|
|
1133
|
+
className: U("relative transition-all duration-200", i && "animate-pulse bg-accent text-accent-foreground", e),
|
|
1110
1134
|
disabled: !s,
|
|
1111
1135
|
onClick: p,
|
|
1112
1136
|
...r,
|
|
1113
|
-
children: /* @__PURE__ */
|
|
1137
|
+
children: /* @__PURE__ */ q(rt, { className: "size-4" })
|
|
1114
1138
|
});
|
|
1115
|
-
},
|
|
1116
|
-
className:
|
|
1139
|
+
}, Gn = (e) => /* @__PURE__ */ q(le, { ...e }), Kn = ({ className: e, ...t }) => /* @__PURE__ */ q(fe, {
|
|
1140
|
+
className: U("border-none bg-transparent font-medium text-muted-foreground shadow-none transition-colors", "hover:bg-accent hover:text-foreground aria-expanded:bg-accent aria-expanded:text-foreground", e),
|
|
1117
1141
|
...t
|
|
1118
|
-
}),
|
|
1119
|
-
className:
|
|
1142
|
+
}), qn = ({ className: e, ...t }) => /* @__PURE__ */ q(ue, {
|
|
1143
|
+
className: U(e),
|
|
1120
1144
|
...t
|
|
1121
|
-
}),
|
|
1122
|
-
className:
|
|
1145
|
+
}), Jn = ({ className: e, ...t }) => /* @__PURE__ */ q(de, {
|
|
1146
|
+
className: U(e),
|
|
1123
1147
|
...t
|
|
1124
|
-
}),
|
|
1125
|
-
className:
|
|
1148
|
+
}), Yn = ({ className: e, ...t }) => /* @__PURE__ */ q(pe, {
|
|
1149
|
+
className: U(e),
|
|
1126
1150
|
...t
|
|
1127
|
-
}),
|
|
1151
|
+
}), Xn = ({ openDelay: e = 0, closeDelay: t = 0, ...n }) => /* @__PURE__ */ q(R, {
|
|
1128
1152
|
closeDelay: t,
|
|
1129
1153
|
openDelay: e,
|
|
1130
1154
|
...n
|
|
1131
|
-
}),
|
|
1155
|
+
}), Zn = (e) => /* @__PURE__ */ q(z, { ...e }), Qn = ({ align: e = "start", ...t }) => /* @__PURE__ */ q(ae, {
|
|
1132
1156
|
align: e,
|
|
1133
1157
|
...t
|
|
1134
|
-
}),
|
|
1135
|
-
className:
|
|
1158
|
+
}), $n = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1159
|
+
className: U(e),
|
|
1136
1160
|
...t
|
|
1137
|
-
}),
|
|
1138
|
-
className:
|
|
1161
|
+
}), er = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1162
|
+
className: U(e),
|
|
1139
1163
|
...t
|
|
1140
|
-
}),
|
|
1141
|
-
className:
|
|
1164
|
+
}), tr = ({ className: e, ...t }) => /* @__PURE__ */ q("h3", {
|
|
1165
|
+
className: U("mb-2 px-3 font-medium text-muted-foreground text-xs", e),
|
|
1142
1166
|
...t
|
|
1143
|
-
}),
|
|
1144
|
-
className:
|
|
1167
|
+
}), nr = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1168
|
+
className: U("space-y-1", e),
|
|
1145
1169
|
...t
|
|
1146
|
-
}),
|
|
1147
|
-
className:
|
|
1170
|
+
}), rr = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1171
|
+
className: U("flex items-center gap-2 px-3 py-2 text-xs hover:bg-accent", e),
|
|
1148
1172
|
...t
|
|
1149
|
-
}),
|
|
1150
|
-
className:
|
|
1173
|
+
}), ir = ({ className: e, ...t }) => /* @__PURE__ */ q(D, {
|
|
1174
|
+
className: U(e),
|
|
1151
1175
|
...t
|
|
1152
|
-
}),
|
|
1153
|
-
className:
|
|
1176
|
+
}), ar = ({ className: e, ...t }) => /* @__PURE__ */ q(A, {
|
|
1177
|
+
className: U(e),
|
|
1154
1178
|
...t
|
|
1155
|
-
}),
|
|
1156
|
-
className:
|
|
1179
|
+
}), or = ({ className: e, ...t }) => /* @__PURE__ */ q(M, {
|
|
1180
|
+
className: U(e),
|
|
1157
1181
|
...t
|
|
1158
|
-
}),
|
|
1159
|
-
className:
|
|
1182
|
+
}), sr = ({ className: e, ...t }) => /* @__PURE__ */ q(O, {
|
|
1183
|
+
className: U(e),
|
|
1160
1184
|
...t
|
|
1161
|
-
}),
|
|
1162
|
-
className:
|
|
1185
|
+
}), cr = ({ className: e, ...t }) => /* @__PURE__ */ q(k, {
|
|
1186
|
+
className: U(e),
|
|
1163
1187
|
...t
|
|
1164
|
-
}),
|
|
1165
|
-
className:
|
|
1188
|
+
}), lr = ({ className: e, ...t }) => /* @__PURE__ */ q(j, {
|
|
1189
|
+
className: U(e),
|
|
1166
1190
|
...t
|
|
1167
|
-
}),
|
|
1168
|
-
className:
|
|
1191
|
+
}), ur = ({ className: e, ...t }) => /* @__PURE__ */ q(N, {
|
|
1192
|
+
className: U(e),
|
|
1169
1193
|
...t
|
|
1170
|
-
}),
|
|
1194
|
+
}), dr = ({ className: e, children: t, ...n }) => /* @__PURE__ */ J(se, {
|
|
1171
1195
|
className: "w-full overflow-x-auto whitespace-nowrap",
|
|
1172
1196
|
...n,
|
|
1173
|
-
children: [/* @__PURE__ */
|
|
1174
|
-
className:
|
|
1197
|
+
children: [/* @__PURE__ */ q("div", {
|
|
1198
|
+
className: U("flex w-max flex-nowrap items-center gap-2", e),
|
|
1175
1199
|
children: t
|
|
1176
|
-
}), /* @__PURE__ */
|
|
1200
|
+
}), /* @__PURE__ */ q(ce, {
|
|
1177
1201
|
className: "hidden",
|
|
1178
1202
|
orientation: "horizontal"
|
|
1179
1203
|
})]
|
|
1180
|
-
}),
|
|
1181
|
-
className:
|
|
1204
|
+
}), fr = ({ suggestion: e, onClick: t, className: n, variant: r = "outline", size: i = "sm", children: a, ...o }) => /* @__PURE__ */ q(v, {
|
|
1205
|
+
className: U("cursor-pointer rounded-full px-4", n),
|
|
1182
1206
|
onClick: () => {
|
|
1183
1207
|
t?.(e);
|
|
1184
1208
|
},
|
|
@@ -1187,7 +1211,7 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1187
1211
|
variant: r,
|
|
1188
1212
|
...o,
|
|
1189
1213
|
children: a || e
|
|
1190
|
-
}),
|
|
1214
|
+
}), pr = r({ code: "" }), mr = {
|
|
1191
1215
|
name: "line-numbers",
|
|
1192
1216
|
line(e, t) {
|
|
1193
1217
|
e.children.unshift({
|
|
@@ -1208,13 +1232,13 @@ var Jt = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1208
1232
|
});
|
|
1209
1233
|
}
|
|
1210
1234
|
};
|
|
1211
|
-
async function
|
|
1212
|
-
let r = n ? [
|
|
1213
|
-
return await Promise.all([
|
|
1235
|
+
async function hr(e, t, n = !1) {
|
|
1236
|
+
let r = n ? [mr] : [];
|
|
1237
|
+
return await Promise.all([Ct(e, {
|
|
1214
1238
|
lang: t,
|
|
1215
1239
|
theme: "one-light",
|
|
1216
1240
|
transformers: r
|
|
1217
|
-
}),
|
|
1241
|
+
}), Ct(e, {
|
|
1218
1242
|
lang: t,
|
|
1219
1243
|
theme: "one-dark-pro",
|
|
1220
1244
|
transformers: r
|
|
@@ -1222,7 +1246,7 @@ async function Nn(e, t, n = !1) {
|
|
|
1222
1246
|
}
|
|
1223
1247
|
var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children: i, ...a }) => {
|
|
1224
1248
|
let [o, s] = d(""), [l, f] = d(""), p = u(!1);
|
|
1225
|
-
return c(() => (
|
|
1249
|
+
return c(() => (hr(e, t, n).then(([e, t]) => {
|
|
1226
1250
|
p.current ||= (s(e), f(t), !0);
|
|
1227
1251
|
}), () => {
|
|
1228
1252
|
p.current = !1;
|
|
@@ -1230,23 +1254,23 @@ var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1230
1254
|
e,
|
|
1231
1255
|
t,
|
|
1232
1256
|
n
|
|
1233
|
-
]), /* @__PURE__ */
|
|
1257
|
+
]), /* @__PURE__ */ q(pr.Provider, {
|
|
1234
1258
|
value: { code: e },
|
|
1235
|
-
children: /* @__PURE__ */
|
|
1236
|
-
className:
|
|
1259
|
+
children: /* @__PURE__ */ q("div", {
|
|
1260
|
+
className: U("group relative w-full overflow-hidden rounded-md border bg-background text-foreground", r),
|
|
1237
1261
|
...a,
|
|
1238
|
-
children: /* @__PURE__ */
|
|
1262
|
+
children: /* @__PURE__ */ J("div", {
|
|
1239
1263
|
className: "relative",
|
|
1240
1264
|
children: [
|
|
1241
|
-
/* @__PURE__ */
|
|
1265
|
+
/* @__PURE__ */ q("div", {
|
|
1242
1266
|
className: "overflow-auto dark:hidden [&>pre]:m-0 [&>pre]:bg-background! [&>pre]:p-4 [&>pre]:text-foreground! [&>pre]:text-sm [&_code]:font-mono [&_code]:text-sm",
|
|
1243
1267
|
dangerouslySetInnerHTML: { __html: o }
|
|
1244
1268
|
}),
|
|
1245
|
-
/* @__PURE__ */
|
|
1269
|
+
/* @__PURE__ */ q("div", {
|
|
1246
1270
|
className: "hidden overflow-auto dark:block [&>pre]:m-0 [&>pre]:bg-background! [&>pre]:p-4 [&>pre]:text-foreground! [&>pre]:text-sm [&_code]:font-mono [&_code]:text-sm",
|
|
1247
1271
|
dangerouslySetInnerHTML: { __html: l }
|
|
1248
1272
|
}),
|
|
1249
|
-
i && /* @__PURE__ */
|
|
1273
|
+
i && /* @__PURE__ */ q("div", {
|
|
1250
1274
|
className: "absolute top-2 right-2 flex items-center gap-2",
|
|
1251
1275
|
children: i
|
|
1252
1276
|
})
|
|
@@ -1254,8 +1278,8 @@ var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1254
1278
|
})
|
|
1255
1279
|
})
|
|
1256
1280
|
});
|
|
1257
|
-
},
|
|
1258
|
-
let [o, c] = d(!1), { code: l } = s(
|
|
1281
|
+
}, gr = ({ onCopy: e, onError: t, timeout: n = 2e3, children: r, className: i, ...a }) => {
|
|
1282
|
+
let [o, c] = d(!1), { code: l } = s(pr), u = async () => {
|
|
1259
1283
|
if (typeof window > "u" || !navigator?.clipboard?.writeText) {
|
|
1260
1284
|
t?.(/* @__PURE__ */ Error("Clipboard API not available"));
|
|
1261
1285
|
return;
|
|
@@ -1265,29 +1289,29 @@ var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1265
1289
|
} catch (e) {
|
|
1266
1290
|
t?.(e);
|
|
1267
1291
|
}
|
|
1268
|
-
}, f = o ?
|
|
1269
|
-
return /* @__PURE__ */
|
|
1270
|
-
className:
|
|
1292
|
+
}, f = o ? Ve : Ye;
|
|
1293
|
+
return /* @__PURE__ */ q(v, {
|
|
1294
|
+
className: U("shrink-0", i),
|
|
1271
1295
|
onClick: u,
|
|
1272
1296
|
size: "icon",
|
|
1273
1297
|
variant: "ghost",
|
|
1274
1298
|
...a,
|
|
1275
|
-
children: r ?? /* @__PURE__ */
|
|
1299
|
+
children: r ?? /* @__PURE__ */ q(f, { size: 14 })
|
|
1276
1300
|
});
|
|
1277
|
-
},
|
|
1278
|
-
className:
|
|
1301
|
+
}, _r = ({ className: e, ...t }) => /* @__PURE__ */ q(w, {
|
|
1302
|
+
className: U("not-prose mb-4 w-full rounded-md border", e),
|
|
1279
1303
|
...t
|
|
1280
|
-
}),
|
|
1304
|
+
}), vr = (e) => /* @__PURE__ */ J(_, {
|
|
1281
1305
|
className: "gap-1.5 rounded-full text-xs",
|
|
1282
1306
|
variant: "secondary",
|
|
1283
1307
|
children: [{
|
|
1284
|
-
"input-streaming": /* @__PURE__ */
|
|
1285
|
-
"input-available": /* @__PURE__ */
|
|
1286
|
-
"approval-requested": /* @__PURE__ */
|
|
1287
|
-
"approval-responded": /* @__PURE__ */
|
|
1288
|
-
"output-available": /* @__PURE__ */
|
|
1289
|
-
"output-error": /* @__PURE__ */
|
|
1290
|
-
"output-denied": /* @__PURE__ */
|
|
1308
|
+
"input-streaming": /* @__PURE__ */ q(Ge, { className: "size-4" }),
|
|
1309
|
+
"input-available": /* @__PURE__ */ q(qe, { className: "size-4 animate-pulse" }),
|
|
1310
|
+
"approval-requested": /* @__PURE__ */ q(qe, { className: "size-4 text-yellow-600" }),
|
|
1311
|
+
"approval-responded": /* @__PURE__ */ q(Be, { className: "size-4 text-blue-600" }),
|
|
1312
|
+
"output-available": /* @__PURE__ */ q(Be, { className: "size-4 text-green-600" }),
|
|
1313
|
+
"output-error": /* @__PURE__ */ q(ft, { className: "size-4 text-red-600" }),
|
|
1314
|
+
"output-denied": /* @__PURE__ */ q(ft, { className: "size-4 text-orange-600" })
|
|
1291
1315
|
}[e], {
|
|
1292
1316
|
"input-streaming": "Pending",
|
|
1293
1317
|
"input-available": "Running",
|
|
@@ -1297,61 +1321,61 @@ var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1297
1321
|
"output-error": "Error",
|
|
1298
1322
|
"output-denied": "Denied"
|
|
1299
1323
|
}[e]]
|
|
1300
|
-
}),
|
|
1301
|
-
className:
|
|
1324
|
+
}), yr = ({ className: e, title: t, type: n, state: r, ...i }) => /* @__PURE__ */ J(E, {
|
|
1325
|
+
className: U("flex w-full items-center justify-between gap-4 p-3", e),
|
|
1302
1326
|
...i,
|
|
1303
|
-
children: [/* @__PURE__ */
|
|
1327
|
+
children: [/* @__PURE__ */ J("div", {
|
|
1304
1328
|
className: "flex items-center gap-2",
|
|
1305
1329
|
children: [
|
|
1306
|
-
/* @__PURE__ */
|
|
1307
|
-
/* @__PURE__ */
|
|
1330
|
+
/* @__PURE__ */ q(ut, { className: "size-4 text-muted-foreground" }),
|
|
1331
|
+
/* @__PURE__ */ q("span", {
|
|
1308
1332
|
className: "font-medium text-sm",
|
|
1309
1333
|
children: t ?? n.split("-").slice(1).join("-")
|
|
1310
1334
|
}),
|
|
1311
|
-
|
|
1335
|
+
vr(r)
|
|
1312
1336
|
]
|
|
1313
|
-
}), /* @__PURE__ */
|
|
1314
|
-
}),
|
|
1315
|
-
className:
|
|
1337
|
+
}), /* @__PURE__ */ q(He, { className: "size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" })]
|
|
1338
|
+
}), br = ({ className: e, ...t }) => /* @__PURE__ */ q(T, {
|
|
1339
|
+
className: U("data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-popover-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in", e),
|
|
1316
1340
|
...t
|
|
1317
|
-
}),
|
|
1318
|
-
className:
|
|
1341
|
+
}), xr = ({ className: e, input: t, ...n }) => /* @__PURE__ */ J("div", {
|
|
1342
|
+
className: U("space-y-2 overflow-hidden p-4", e),
|
|
1319
1343
|
...n,
|
|
1320
|
-
children: [/* @__PURE__ */
|
|
1344
|
+
children: [/* @__PURE__ */ q("h4", {
|
|
1321
1345
|
className: "font-medium text-muted-foreground text-xs uppercase tracking-wide",
|
|
1322
1346
|
children: "Parameters"
|
|
1323
|
-
}), /* @__PURE__ */
|
|
1347
|
+
}), /* @__PURE__ */ q("div", {
|
|
1324
1348
|
className: "rounded-md bg-muted/50",
|
|
1325
|
-
children: /* @__PURE__ */
|
|
1349
|
+
children: /* @__PURE__ */ q(Q, {
|
|
1326
1350
|
code: JSON.stringify(t, null, 2),
|
|
1327
1351
|
language: "json"
|
|
1328
1352
|
})
|
|
1329
1353
|
})]
|
|
1330
|
-
}),
|
|
1354
|
+
}), Sr = ({ className: e, output: t, errorText: n, ...r }) => {
|
|
1331
1355
|
if (!(t || n)) return null;
|
|
1332
|
-
let a = /* @__PURE__ */
|
|
1333
|
-
return typeof t == "object" && !i(t) ? a = /* @__PURE__ */
|
|
1356
|
+
let a = /* @__PURE__ */ q("div", { children: t });
|
|
1357
|
+
return typeof t == "object" && !i(t) ? a = /* @__PURE__ */ q(Q, {
|
|
1334
1358
|
code: JSON.stringify(t, null, 2),
|
|
1335
1359
|
language: "json"
|
|
1336
|
-
}) : typeof t == "string" && (a = /* @__PURE__ */
|
|
1360
|
+
}) : typeof t == "string" && (a = /* @__PURE__ */ q(Q, {
|
|
1337
1361
|
code: t,
|
|
1338
1362
|
language: "json"
|
|
1339
|
-
})), /* @__PURE__ */
|
|
1340
|
-
className:
|
|
1363
|
+
})), /* @__PURE__ */ J("div", {
|
|
1364
|
+
className: U("space-y-2 p-4", e),
|
|
1341
1365
|
...r,
|
|
1342
|
-
children: [/* @__PURE__ */
|
|
1366
|
+
children: [/* @__PURE__ */ q("h4", {
|
|
1343
1367
|
className: "font-medium text-muted-foreground text-xs uppercase tracking-wide",
|
|
1344
1368
|
children: n ? "Error" : "Result"
|
|
1345
|
-
}), /* @__PURE__ */
|
|
1346
|
-
className:
|
|
1347
|
-
children: [n && /* @__PURE__ */
|
|
1369
|
+
}), /* @__PURE__ */ J("div", {
|
|
1370
|
+
className: U("overflow-x-auto rounded-md text-xs [&_table]:w-full", n ? "bg-destructive/10 text-destructive" : "bg-muted/50 text-foreground"),
|
|
1371
|
+
children: [n && /* @__PURE__ */ q("div", { children: n }), a]
|
|
1348
1372
|
})]
|
|
1349
1373
|
});
|
|
1350
|
-
},
|
|
1351
|
-
let a =
|
|
1352
|
-
return /* @__PURE__ */
|
|
1374
|
+
}, Cr = a(({ children: e, as: t = "p", className: n, duration: r = 2, spread: i = 2 }) => {
|
|
1375
|
+
let a = Tt.create(t), o = l(() => (e?.length ?? 0) * i, [e, i]);
|
|
1376
|
+
return /* @__PURE__ */ q(a, {
|
|
1353
1377
|
animate: { backgroundPosition: "0% center" },
|
|
1354
|
-
className:
|
|
1378
|
+
className: U("relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent", "[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]", n),
|
|
1355
1379
|
initial: { backgroundPosition: "100% center" },
|
|
1356
1380
|
style: {
|
|
1357
1381
|
"--spread": `${o}px`,
|
|
@@ -1364,21 +1388,21 @@ var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1364
1388
|
},
|
|
1365
1389
|
children: e
|
|
1366
1390
|
});
|
|
1367
|
-
}),
|
|
1368
|
-
let e = s(
|
|
1391
|
+
}), wr = r(null), Tr = () => {
|
|
1392
|
+
let e = s(wr);
|
|
1369
1393
|
if (!e) throw Error("Reasoning components must be used within Reasoning");
|
|
1370
1394
|
return e;
|
|
1371
|
-
},
|
|
1372
|
-
let [l, u] =
|
|
1395
|
+
}, Er = 1e3, Dr = 1e3, Or = a(({ className: e, isStreaming: t = !1, open: n, defaultOpen: r = !0, onOpenChange: i, duration: a, children: o, ...s }) => {
|
|
1396
|
+
let [l, u] = wt({
|
|
1373
1397
|
prop: n,
|
|
1374
1398
|
defaultProp: r,
|
|
1375
1399
|
onChange: i
|
|
1376
|
-
}), [f, p] =
|
|
1400
|
+
}), [f, p] = wt({
|
|
1377
1401
|
prop: a,
|
|
1378
1402
|
defaultProp: void 0
|
|
1379
|
-
}), [m, h] = d(!1), [g,
|
|
1403
|
+
}), [m, h] = d(!1), [g, _] = d(null);
|
|
1380
1404
|
return c(() => {
|
|
1381
|
-
t ? g === null &&
|
|
1405
|
+
t ? g === null && _(Date.now()) : g !== null && (p(Math.ceil((Date.now() - g) / Dr)), _(null));
|
|
1382
1406
|
}, [
|
|
1383
1407
|
t,
|
|
1384
1408
|
g,
|
|
@@ -1387,7 +1411,7 @@ var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1387
1411
|
if (r && !t && l && !m) {
|
|
1388
1412
|
let e = setTimeout(() => {
|
|
1389
1413
|
u(!1), h(!0);
|
|
1390
|
-
},
|
|
1414
|
+
}, Er);
|
|
1391
1415
|
return () => clearTimeout(e);
|
|
1392
1416
|
}
|
|
1393
1417
|
}, [
|
|
@@ -1396,15 +1420,15 @@ var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1396
1420
|
r,
|
|
1397
1421
|
u,
|
|
1398
1422
|
m
|
|
1399
|
-
]), /* @__PURE__ */
|
|
1423
|
+
]), /* @__PURE__ */ q(wr.Provider, {
|
|
1400
1424
|
value: {
|
|
1401
1425
|
isStreaming: t,
|
|
1402
1426
|
isOpen: l,
|
|
1403
1427
|
setIsOpen: u,
|
|
1404
1428
|
duration: f
|
|
1405
1429
|
},
|
|
1406
|
-
children: /* @__PURE__ */
|
|
1407
|
-
className:
|
|
1430
|
+
children: /* @__PURE__ */ q(w, {
|
|
1431
|
+
className: U("not-prose mb-4", e),
|
|
1408
1432
|
onOpenChange: (e) => {
|
|
1409
1433
|
u(e);
|
|
1410
1434
|
},
|
|
@@ -1413,152 +1437,159 @@ var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1413
1437
|
children: o
|
|
1414
1438
|
})
|
|
1415
1439
|
});
|
|
1416
|
-
}),
|
|
1440
|
+
}), kr = (e, t) => e || t === 0 ? /* @__PURE__ */ q(Cr, {
|
|
1417
1441
|
duration: 1,
|
|
1418
1442
|
children: "Thinking..."
|
|
1419
|
-
}) : t === void 0 ? /* @__PURE__ */
|
|
1443
|
+
}) : t === void 0 ? /* @__PURE__ */ q("p", { children: "Thought for a few seconds" }) : /* @__PURE__ */ J("p", { children: [
|
|
1420
1444
|
"Thought for ",
|
|
1421
1445
|
t,
|
|
1422
1446
|
" seconds"
|
|
1423
|
-
] }),
|
|
1424
|
-
let { isStreaming: i, isOpen: a, duration: o } =
|
|
1425
|
-
return /* @__PURE__ */
|
|
1426
|
-
className:
|
|
1447
|
+
] }), Ar = a(({ className: e, children: t, getThinkingMessage: n = kr, ...r }) => {
|
|
1448
|
+
let { isStreaming: i, isOpen: a, duration: o } = Tr();
|
|
1449
|
+
return /* @__PURE__ */ q(E, {
|
|
1450
|
+
className: U("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground", e),
|
|
1427
1451
|
...r,
|
|
1428
|
-
children: t ?? /* @__PURE__ */
|
|
1429
|
-
/* @__PURE__ */
|
|
1452
|
+
children: t ?? /* @__PURE__ */ J(K, { children: [
|
|
1453
|
+
/* @__PURE__ */ q(Le, { className: "size-4" }),
|
|
1430
1454
|
n(i, o),
|
|
1431
|
-
/* @__PURE__ */
|
|
1455
|
+
/* @__PURE__ */ q(He, { className: U("size-4 transition-transform", a ? "rotate-180" : "rotate-0") })
|
|
1432
1456
|
] })
|
|
1433
1457
|
});
|
|
1434
|
-
}),
|
|
1435
|
-
className:
|
|
1458
|
+
}), jr = a(({ className: e, children: t, ...n }) => /* @__PURE__ */ q(T, {
|
|
1459
|
+
className: U("mt-4 text-sm", "data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in", e),
|
|
1436
1460
|
...n,
|
|
1437
|
-
children: /* @__PURE__ */
|
|
1461
|
+
children: /* @__PURE__ */ q(xt, {
|
|
1438
1462
|
...n,
|
|
1439
1463
|
children: t
|
|
1440
1464
|
})
|
|
1441
1465
|
}));
|
|
1442
|
-
|
|
1466
|
+
Or.displayName = "Reasoning", Ar.displayName = "ReasoningTrigger", jr.displayName = "ReasoningContent";
|
|
1443
1467
|
//#endregion
|
|
1444
1468
|
//#region src/elements/sources.tsx
|
|
1445
|
-
var
|
|
1446
|
-
className:
|
|
1469
|
+
var Mr = ({ className: e, ...t }) => /* @__PURE__ */ q(w, {
|
|
1470
|
+
className: U("not-prose mb-4 text-primary text-xs", e),
|
|
1447
1471
|
...t
|
|
1448
|
-
}),
|
|
1449
|
-
className:
|
|
1472
|
+
}), Nr = ({ className: e, count: t, children: n, ...r }) => /* @__PURE__ */ q(E, {
|
|
1473
|
+
className: U("flex items-center gap-2", e),
|
|
1450
1474
|
...r,
|
|
1451
|
-
children: n ?? /* @__PURE__ */
|
|
1475
|
+
children: n ?? /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ J("p", {
|
|
1452
1476
|
className: "font-medium",
|
|
1453
1477
|
children: [
|
|
1454
1478
|
"Used ",
|
|
1455
1479
|
t,
|
|
1456
1480
|
" sources"
|
|
1457
1481
|
]
|
|
1458
|
-
}), /* @__PURE__ */
|
|
1459
|
-
}),
|
|
1460
|
-
className:
|
|
1482
|
+
}), /* @__PURE__ */ q(He, { className: "h-4 w-4" })] })
|
|
1483
|
+
}), Pr = ({ className: e, ...t }) => /* @__PURE__ */ q(T, {
|
|
1484
|
+
className: U("mt-3 flex w-fit flex-col gap-2", "data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 outline-none data-[state=closed]:animate-out data-[state=open]:animate-in", e),
|
|
1461
1485
|
...t
|
|
1462
|
-
}),
|
|
1486
|
+
}), Fr = ({ href: e, title: t, children: n, ...r }) => /* @__PURE__ */ q("a", {
|
|
1463
1487
|
className: "flex items-center gap-2",
|
|
1464
1488
|
href: e,
|
|
1465
1489
|
rel: "noreferrer",
|
|
1466
1490
|
target: "_blank",
|
|
1467
1491
|
...r,
|
|
1468
|
-
children: n ?? /* @__PURE__ */
|
|
1492
|
+
children: n ?? /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ q(Fe, { className: "h-4 w-4" }), /* @__PURE__ */ q("span", {
|
|
1469
1493
|
className: "block font-medium",
|
|
1470
1494
|
children: t
|
|
1471
1495
|
})] })
|
|
1472
1496
|
});
|
|
1473
1497
|
//#endregion
|
|
1474
1498
|
//#region src/ChatbotEnhanced.tsx
|
|
1475
|
-
function
|
|
1499
|
+
function Ir(e, t) {
|
|
1476
1500
|
return t ? "error" : e ? "streaming" : "ready";
|
|
1477
1501
|
}
|
|
1478
|
-
function
|
|
1502
|
+
function Lr(e) {
|
|
1479
1503
|
return e === "user" ? "user" : "assistant";
|
|
1480
1504
|
}
|
|
1481
|
-
var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type your message...", onSendMessage: i, onClear: a, onStop: o, onReload: s, disabled: c = !1, isLoading: l = !1, error: u, showTimestamp: d = !1, userAvatarUrl: f, userAvatarFallback: p = "You", assistantAvatarUrl: m, assistantAvatarFallback: h = "AI", maxHeight: g = "500px", enableMarkdown: _ = !0, enableFileUpload: v = !1, acceptedFileTypes: y = "image/*,.pdf,.doc,.docx,.txt", maxFileSize: b = 10 * 1024 * 1024, suggestions: x, models: S, selectedModelId: C, onModelChange: w, headerSlot: T, promptOverlaySlot: E, onInputChange: D, onToolApprove: O, toolApproveLabel: k = "Approve", toolDenyLabel: A = "Deny", toolDenyReason: j = "User denied the operation",
|
|
1482
|
-
let
|
|
1505
|
+
var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type your message...", onSendMessage: i, onClear: a, onStop: o, onReload: s, disabled: c = !1, isLoading: l = !1, error: u, showTimestamp: d = !1, userAvatarUrl: f, userAvatarFallback: p = "You", assistantAvatarUrl: m, assistantAvatarFallback: h = "AI", maxHeight: g = "500px", enableMarkdown: _ = !0, enableFileUpload: v = !1, acceptedFileTypes: y = "image/*,.pdf,.doc,.docx,.txt", maxFileSize: b = 10 * 1024 * 1024, suggestions: x, models: S, selectedModelId: C, onModelChange: w, headerSlot: T, promptOverlaySlot: E, onInputChange: D, onToolApprove: O, toolApproveLabel: k = "Approve", toolDenyLabel: A = "Deny", toolDenyReason: j = "User denied the operation", toolDecisions: M, ...N }, P) => {
|
|
1506
|
+
let F = Ir(l, u), [I, L] = e.useState(null), ee = e.useCallback((e) => {
|
|
1483
1507
|
let t = !!e.text?.trim(), n = e.files?.map((e) => e.file).filter(Boolean), r = !!(n && n.length > 0);
|
|
1484
1508
|
(t || r) && i?.(e.text?.trim() ?? "", n);
|
|
1485
1509
|
}, [i]), te = e.useCallback((e) => {
|
|
1486
1510
|
i?.(e);
|
|
1487
1511
|
}, [i]), ne = e.useCallback((e) => {
|
|
1488
|
-
navigator.clipboard?.writeText(e.content),
|
|
1512
|
+
navigator.clipboard?.writeText(e.content), L(e.id), window.setTimeout(() => L((t) => t === e.id ? null : t), 1500);
|
|
1489
1513
|
}, []);
|
|
1490
|
-
return /* @__PURE__ */
|
|
1491
|
-
ref:
|
|
1492
|
-
className:
|
|
1514
|
+
return /* @__PURE__ */ J("div", {
|
|
1515
|
+
ref: P,
|
|
1516
|
+
className: U("flex flex-col border rounded-lg bg-background overflow-hidden", t),
|
|
1493
1517
|
style: { maxHeight: g },
|
|
1494
|
-
...
|
|
1518
|
+
...N,
|
|
1495
1519
|
children: [
|
|
1496
|
-
a && n.length > 0 && /* @__PURE__ */
|
|
1520
|
+
a && n.length > 0 && /* @__PURE__ */ J("div", {
|
|
1497
1521
|
className: "flex items-center justify-between px-4 py-2 border-b bg-muted/30",
|
|
1498
|
-
children: [/* @__PURE__ */
|
|
1522
|
+
children: [/* @__PURE__ */ J("span", {
|
|
1499
1523
|
className: "text-sm text-muted-foreground",
|
|
1500
1524
|
children: [
|
|
1501
1525
|
n.length,
|
|
1502
1526
|
" message",
|
|
1503
1527
|
n.length === 1 ? "" : "s"
|
|
1504
1528
|
]
|
|
1505
|
-
}), /* @__PURE__ */
|
|
1529
|
+
}), /* @__PURE__ */ q("button", {
|
|
1506
1530
|
type: "button",
|
|
1507
1531
|
onClick: a,
|
|
1508
1532
|
className: "text-xs text-muted-foreground hover:text-foreground transition-colors",
|
|
1509
1533
|
children: "Clear"
|
|
1510
1534
|
})]
|
|
1511
1535
|
}),
|
|
1512
|
-
T ? /* @__PURE__ */
|
|
1536
|
+
T ? /* @__PURE__ */ q("div", {
|
|
1513
1537
|
className: "shrink-0 border-b bg-background/50",
|
|
1514
1538
|
children: T
|
|
1515
1539
|
}) : null,
|
|
1516
|
-
/* @__PURE__ */
|
|
1540
|
+
/* @__PURE__ */ J(Kt, {
|
|
1517
1541
|
className: "flex-1 min-h-0",
|
|
1518
|
-
children: [/* @__PURE__ */
|
|
1542
|
+
children: [/* @__PURE__ */ q(qt, {
|
|
1519
1543
|
className: "space-y-4 px-4 py-3",
|
|
1520
|
-
children: n.length === 0 ? /* @__PURE__ */
|
|
1544
|
+
children: n.length === 0 ? /* @__PURE__ */ q(Jt, {
|
|
1521
1545
|
title: "Start a conversation",
|
|
1522
1546
|
description: "Ask anything — the assistant has access to your current app context.",
|
|
1523
|
-
children: x && x.length > 0 ? /* @__PURE__ */
|
|
1547
|
+
children: x && x.length > 0 ? /* @__PURE__ */ q(dr, {
|
|
1524
1548
|
className: "justify-center pt-2",
|
|
1525
|
-
children: x.map((e) => /* @__PURE__ */
|
|
1549
|
+
children: x.map((e) => /* @__PURE__ */ q(fr, {
|
|
1526
1550
|
suggestion: e,
|
|
1527
1551
|
onClick: te
|
|
1528
1552
|
}, e))
|
|
1529
1553
|
}) : null
|
|
1530
1554
|
}) : n.map((e) => {
|
|
1531
1555
|
let t = e.role === "user", n = e.toolInvocations ?? [], r = e.reasoning?.trim(), i = e.sources ?? [];
|
|
1532
|
-
return /* @__PURE__ */
|
|
1533
|
-
from:
|
|
1534
|
-
children: [/* @__PURE__ */
|
|
1535
|
-
!t && r ? /* @__PURE__ */
|
|
1556
|
+
return /* @__PURE__ */ J($t, {
|
|
1557
|
+
from: Lr(e.role),
|
|
1558
|
+
children: [/* @__PURE__ */ J(en, { children: [
|
|
1559
|
+
!t && r ? /* @__PURE__ */ J(Or, {
|
|
1536
1560
|
isStreaming: !!e.streaming && !e.content,
|
|
1537
1561
|
className: "mb-2",
|
|
1538
|
-
children: [/* @__PURE__ */
|
|
1562
|
+
children: [/* @__PURE__ */ q(Ar, {}), /* @__PURE__ */ q(jr, { children: r })]
|
|
1539
1563
|
}) : null,
|
|
1540
1564
|
!t && n.length > 0 ? n.map((e) => {
|
|
1541
|
-
let t = e.state ?? (e.errorText ? "output-error" : e.result === void 0 ? "input-available" : "output-available"), n = `tool-${e.toolName}`, r = t === "approval-requested" && !!O;
|
|
1542
|
-
return /* @__PURE__ */
|
|
1565
|
+
let t = e.state ?? (e.errorText ? "output-error" : e.result === void 0 ? "input-available" : "output-available"), n = `tool-${e.toolName}`, r = M?.[e.toolCallId], i = t === "approval-requested" && !!O && !r, a = t === "approval-requested" && !!e.pendingActionId;
|
|
1566
|
+
return /* @__PURE__ */ J(_r, {
|
|
1543
1567
|
defaultOpen: t !== "output-available",
|
|
1544
|
-
children: [/* @__PURE__ */
|
|
1568
|
+
children: [/* @__PURE__ */ q(yr, {
|
|
1545
1569
|
type: n,
|
|
1546
1570
|
state: t,
|
|
1547
1571
|
title: e.toolName
|
|
1548
|
-
}), /* @__PURE__ */
|
|
1549
|
-
e.args === void 0 ? null : /* @__PURE__ */
|
|
1550
|
-
/* @__PURE__ */
|
|
1572
|
+
}), /* @__PURE__ */ J(br, { children: [
|
|
1573
|
+
e.args === void 0 ? null : /* @__PURE__ */ q(xr, { input: e.args }),
|
|
1574
|
+
a ? null : /* @__PURE__ */ q(Sr, {
|
|
1551
1575
|
output: e.result,
|
|
1552
1576
|
errorText: e.errorText
|
|
1553
1577
|
}),
|
|
1554
|
-
r ? /* @__PURE__ */
|
|
1578
|
+
r ? /* @__PURE__ */ J("div", {
|
|
1579
|
+
className: "flex items-center gap-2 p-3 border-t text-xs " + (r.state === "error" ? "bg-destructive/10 text-destructive" : r.state === "success" ? "bg-emerald-500/10 text-emerald-700 dark:text-emerald-400" : "bg-muted/30 text-muted-foreground"),
|
|
1580
|
+
children: [/* @__PURE__ */ q("span", {
|
|
1581
|
+
"aria-hidden": "true",
|
|
1582
|
+
children: r.state === "pending" ? "⏳" : r.state === "success" ? "✓" : "✗"
|
|
1583
|
+
}), /* @__PURE__ */ q("span", { children: r.message ?? (r.state === "pending" ? "Submitting decision…" : r.state === "success" ? "Action approved and executed." : "Decision failed.") })]
|
|
1584
|
+
}) : null,
|
|
1585
|
+
i ? /* @__PURE__ */ J("div", {
|
|
1555
1586
|
className: "flex gap-2 p-3 border-t bg-muted/30",
|
|
1556
|
-
children: [/* @__PURE__ */
|
|
1587
|
+
children: [/* @__PURE__ */ q("button", {
|
|
1557
1588
|
type: "button",
|
|
1558
1589
|
onClick: () => O?.(e.toolCallId, !0),
|
|
1559
1590
|
className: "inline-flex h-7 items-center rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground hover:bg-primary/90",
|
|
1560
1591
|
children: k
|
|
1561
|
-
}), /* @__PURE__ */
|
|
1592
|
+
}), /* @__PURE__ */ q("button", {
|
|
1562
1593
|
type: "button",
|
|
1563
1594
|
onClick: () => O?.(e.toolCallId, !1, j),
|
|
1564
1595
|
className: "inline-flex h-7 items-center rounded-md border bg-background px-3 text-xs font-medium hover:bg-accent",
|
|
@@ -1569,32 +1600,32 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
|
|
|
1569
1600
|
}, e.toolCallId);
|
|
1570
1601
|
}) : null,
|
|
1571
1602
|
e.content,
|
|
1572
|
-
e.streaming ? /* @__PURE__ */
|
|
1603
|
+
e.streaming ? /* @__PURE__ */ q("span", {
|
|
1573
1604
|
"aria-hidden": !0,
|
|
1574
1605
|
className: "ml-0.5 inline-block w-[2px] h-4 align-middle bg-current animate-pulse"
|
|
1575
1606
|
}) : null,
|
|
1576
|
-
!t && i.length > 0 ? /* @__PURE__ */
|
|
1607
|
+
!t && i.length > 0 ? /* @__PURE__ */ J(Mr, { children: [/* @__PURE__ */ q(Nr, { count: i.length }), /* @__PURE__ */ q(Pr, { children: i.map((e, t) => /* @__PURE__ */ q(Fr, {
|
|
1577
1608
|
href: e.url,
|
|
1578
1609
|
title: e.title ?? e.url
|
|
1579
1610
|
}, e.id ?? e.url ?? t)) })] }) : null,
|
|
1580
|
-
d && e.timestamp ? /* @__PURE__ */
|
|
1611
|
+
d && e.timestamp ? /* @__PURE__ */ q("div", {
|
|
1581
1612
|
className: "text-[10px] opacity-70 mt-1",
|
|
1582
1613
|
children: e.timestamp
|
|
1583
1614
|
}) : null
|
|
1584
|
-
] }), t ? null : /* @__PURE__ */
|
|
1585
|
-
/* @__PURE__ */
|
|
1615
|
+
] }), t ? null : /* @__PURE__ */ J(tn, { children: [
|
|
1616
|
+
/* @__PURE__ */ q(nn, {
|
|
1586
1617
|
label: "Copy",
|
|
1587
1618
|
tooltip: "Copy",
|
|
1588
1619
|
onClick: () => ne(e),
|
|
1589
|
-
children:
|
|
1620
|
+
children: I === e.id ? /* @__PURE__ */ q(Re, { className: "size-3.5" }) : /* @__PURE__ */ q(Je, { className: "size-3.5" })
|
|
1590
1621
|
}),
|
|
1591
|
-
s ? /* @__PURE__ */
|
|
1622
|
+
s ? /* @__PURE__ */ q(nn, {
|
|
1592
1623
|
label: "Regenerate",
|
|
1593
1624
|
tooltip: "Regenerate",
|
|
1594
1625
|
onClick: s,
|
|
1595
|
-
children: /* @__PURE__ */
|
|
1626
|
+
children: /* @__PURE__ */ q(st, { className: "size-3.5" })
|
|
1596
1627
|
}) : null,
|
|
1597
|
-
e.traceId ? /* @__PURE__ */
|
|
1628
|
+
e.traceId ? /* @__PURE__ */ q("a", {
|
|
1598
1629
|
href: `#trace/${e.traceId}`,
|
|
1599
1630
|
"data-trace-id": e.traceId,
|
|
1600
1631
|
className: "text-[10px] text-muted-foreground hover:text-foreground ml-1 underline",
|
|
@@ -1604,18 +1635,18 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
|
|
|
1604
1635
|
] })]
|
|
1605
1636
|
}, e.id);
|
|
1606
1637
|
})
|
|
1607
|
-
}), /* @__PURE__ */
|
|
1638
|
+
}), /* @__PURE__ */ q(Yt, {})]
|
|
1608
1639
|
}),
|
|
1609
|
-
u ? /* @__PURE__ */
|
|
1640
|
+
u ? /* @__PURE__ */ J("div", {
|
|
1610
1641
|
className: "flex items-center gap-2 px-4 py-2 border-t bg-destructive/10 text-destructive text-sm",
|
|
1611
1642
|
role: "alert",
|
|
1612
1643
|
children: [
|
|
1613
|
-
/* @__PURE__ */
|
|
1614
|
-
/* @__PURE__ */
|
|
1644
|
+
/* @__PURE__ */ q(Ne, { className: "h-4 w-4 shrink-0" }),
|
|
1645
|
+
/* @__PURE__ */ q("span", {
|
|
1615
1646
|
className: "flex-1 truncate",
|
|
1616
1647
|
children: u.message || "An error occurred"
|
|
1617
1648
|
}),
|
|
1618
|
-
s ? /* @__PURE__ */
|
|
1649
|
+
s ? /* @__PURE__ */ q("button", {
|
|
1619
1650
|
type: "button",
|
|
1620
1651
|
onClick: s,
|
|
1621
1652
|
className: "text-xs underline hover:no-underline",
|
|
@@ -1623,12 +1654,12 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
|
|
|
1623
1654
|
}) : null
|
|
1624
1655
|
]
|
|
1625
1656
|
}) : null,
|
|
1626
|
-
/* @__PURE__ */
|
|
1657
|
+
/* @__PURE__ */ J("div", {
|
|
1627
1658
|
className: "relative",
|
|
1628
|
-
children: [E ? /* @__PURE__ */
|
|
1659
|
+
children: [E ? /* @__PURE__ */ q("div", {
|
|
1629
1660
|
className: "absolute bottom-full left-0 right-0 z-10 px-3 pb-1",
|
|
1630
1661
|
children: E
|
|
1631
|
-
}) : null, /* @__PURE__ */
|
|
1662
|
+
}) : null, /* @__PURE__ */ J(Mn, {
|
|
1632
1663
|
accept: y,
|
|
1633
1664
|
maxFileSize: b,
|
|
1634
1665
|
onSubmit: ee,
|
|
@@ -1636,30 +1667,30 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
|
|
|
1636
1667
|
console.warn("[plugin-chatbot] prompt-input error", e);
|
|
1637
1668
|
},
|
|
1638
1669
|
children: [
|
|
1639
|
-
v ? /* @__PURE__ */
|
|
1640
|
-
/* @__PURE__ */
|
|
1670
|
+
v ? /* @__PURE__ */ q(Nn, { children: /* @__PURE__ */ q(An, { children: (e) => /* @__PURE__ */ q(kn, { data: e }) }) }) : null,
|
|
1671
|
+
/* @__PURE__ */ q(Pn, {
|
|
1641
1672
|
placeholder: r,
|
|
1642
|
-
disabled: c ||
|
|
1673
|
+
disabled: c || F === "streaming",
|
|
1643
1674
|
onChange: D ? (e) => D(e.currentTarget.value) : void 0
|
|
1644
1675
|
}),
|
|
1645
|
-
/* @__PURE__ */
|
|
1676
|
+
/* @__PURE__ */ J(In, { children: [/* @__PURE__ */ J(Ln, { children: [v ? /* @__PURE__ */ J(zn, { children: [/* @__PURE__ */ q(Bn, {}), /* @__PURE__ */ q(Vn, { children: /* @__PURE__ */ q(jn, {}) })] }) : null, S && S.length > 0 ? /* @__PURE__ */ q("select", {
|
|
1646
1677
|
"aria-label": "Model",
|
|
1647
1678
|
value: C ?? S[0].id,
|
|
1648
1679
|
onChange: (e) => w?.(e.target.value),
|
|
1649
1680
|
className: "h-7 rounded-md border bg-background px-2 text-xs text-muted-foreground hover:text-foreground focus:outline-none focus:ring-1 focus:ring-ring",
|
|
1650
|
-
children: S.map((e) => /* @__PURE__ */
|
|
1681
|
+
children: S.map((e) => /* @__PURE__ */ J("option", {
|
|
1651
1682
|
value: e.id,
|
|
1652
1683
|
children: [e.label ?? e.id, e.provider ? ` · ${e.provider}` : ""]
|
|
1653
1684
|
}, e.id))
|
|
1654
|
-
}) : null] }), /* @__PURE__ */
|
|
1655
|
-
status:
|
|
1685
|
+
}) : null] }), /* @__PURE__ */ q(Un, {
|
|
1686
|
+
status: F,
|
|
1656
1687
|
disabled: c,
|
|
1657
|
-
onClick:
|
|
1688
|
+
onClick: F === "streaming" ? o : void 0
|
|
1658
1689
|
})] })
|
|
1659
1690
|
]
|
|
1660
1691
|
})]
|
|
1661
1692
|
}),
|
|
1662
|
-
/* @__PURE__ */
|
|
1693
|
+
/* @__PURE__ */ q("span", {
|
|
1663
1694
|
hidden: !0,
|
|
1664
1695
|
"data-avatar-user": f ?? p,
|
|
1665
1696
|
"data-avatar-assistant": m ?? h
|
|
@@ -1670,7 +1701,7 @@ var $ = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type y
|
|
|
1670
1701
|
$.displayName = "ChatbotEnhanced";
|
|
1671
1702
|
//#endregion
|
|
1672
1703
|
//#region src/FloatingChatbot.tsx
|
|
1673
|
-
function
|
|
1704
|
+
function Rr({ floatingConfig: t, headerExtra: n, ...r }) {
|
|
1674
1705
|
let { position: i = "bottom-right", defaultOpen: a = !1, panelWidth: o = 400, panelHeight: s = 520, title: c = "Chat", triggerSize: l = 56 } = t ?? {}, [u, d] = e.useState(null);
|
|
1675
1706
|
e.useEffect(() => {
|
|
1676
1707
|
let e = document.getElementById("floating-chatbot-portal");
|
|
@@ -1678,28 +1709,28 @@ function nr({ floatingConfig: t, headerExtra: n, ...r }) {
|
|
|
1678
1709
|
e && e.parentNode && !e.hasChildNodes() && e.parentNode.removeChild(e);
|
|
1679
1710
|
};
|
|
1680
1711
|
}, []);
|
|
1681
|
-
let f = /* @__PURE__ */
|
|
1712
|
+
let f = /* @__PURE__ */ J(Vt, {
|
|
1682
1713
|
defaultOpen: a,
|
|
1683
|
-
children: [/* @__PURE__ */
|
|
1714
|
+
children: [/* @__PURE__ */ q(Wt, {
|
|
1684
1715
|
position: i,
|
|
1685
1716
|
size: l
|
|
1686
|
-
}), /* @__PURE__ */
|
|
1717
|
+
}), /* @__PURE__ */ q(Gt, {
|
|
1687
1718
|
title: c,
|
|
1688
1719
|
position: i,
|
|
1689
1720
|
width: o,
|
|
1690
1721
|
height: s,
|
|
1691
1722
|
headerExtra: n,
|
|
1692
|
-
children: /* @__PURE__ */
|
|
1723
|
+
children: /* @__PURE__ */ q($, {
|
|
1693
1724
|
...r,
|
|
1694
1725
|
maxHeight: "100%",
|
|
1695
1726
|
className: "h-full border-0 rounded-none"
|
|
1696
1727
|
})
|
|
1697
1728
|
})]
|
|
1698
1729
|
});
|
|
1699
|
-
return u ?
|
|
1730
|
+
return u ? ht.createPortal(f, u) : f;
|
|
1700
1731
|
}
|
|
1701
|
-
|
|
1702
|
-
let { messages: r, isLoading: i, sendMessage: a } =
|
|
1732
|
+
Et.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
1733
|
+
let { messages: r, isLoading: i, sendMessage: a } = Y({
|
|
1703
1734
|
api: e.api,
|
|
1704
1735
|
initialMessages: e.messages,
|
|
1705
1736
|
conversationId: e.conversationId,
|
|
@@ -1716,7 +1747,7 @@ W.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
1716
1747
|
autoResponseDelay: e.autoResponseDelay,
|
|
1717
1748
|
onSend: e.onSend
|
|
1718
1749
|
});
|
|
1719
|
-
return /* @__PURE__ */
|
|
1750
|
+
return /* @__PURE__ */ q(ai, {
|
|
1720
1751
|
messages: r,
|
|
1721
1752
|
placeholder: e.placeholder,
|
|
1722
1753
|
onSendMessage: (e) => {
|
|
@@ -1864,8 +1895,8 @@ W.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
1864
1895
|
autoResponseDelay: 1e3,
|
|
1865
1896
|
className: "w-full max-w-2xl"
|
|
1866
1897
|
}
|
|
1867
|
-
}),
|
|
1868
|
-
let { messages: r, isLoading: i, error: a, sendMessage: o, stop: s, reload: c, clear: l, isApiMode: u } =
|
|
1898
|
+
}), Et.register("chatbot-enhanced", ({ schema: e, className: t, ...n }) => {
|
|
1899
|
+
let { messages: r, isLoading: i, error: a, sendMessage: o, stop: s, reload: c, clear: l, isApiMode: u } = Y({
|
|
1869
1900
|
api: e.api,
|
|
1870
1901
|
initialMessages: e.messages,
|
|
1871
1902
|
conversationId: e.conversationId,
|
|
@@ -1882,7 +1913,7 @@ W.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
1882
1913
|
autoResponseDelay: e.autoResponseDelay,
|
|
1883
1914
|
onSend: e.onSend
|
|
1884
1915
|
});
|
|
1885
|
-
return /* @__PURE__ */
|
|
1916
|
+
return /* @__PURE__ */ q($, {
|
|
1886
1917
|
messages: r,
|
|
1887
1918
|
placeholder: e.placeholder,
|
|
1888
1919
|
onSendMessage: (e, t) => {
|
|
@@ -2044,8 +2075,8 @@ W.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
2044
2075
|
autoResponseDelay: 1e3,
|
|
2045
2076
|
className: "w-full max-w-2xl"
|
|
2046
2077
|
}
|
|
2047
|
-
}),
|
|
2048
|
-
let { messages: r, isLoading: i, error: a, sendMessage: o, stop: s, reload: c, clear: l, isApiMode: u } =
|
|
2078
|
+
}), Et.register("chatbot-floating", ({ schema: e, className: t, ...n }) => {
|
|
2079
|
+
let { messages: r, isLoading: i, error: a, sendMessage: o, stop: s, reload: c, clear: l, isApiMode: u } = Y({
|
|
2049
2080
|
api: e.api,
|
|
2050
2081
|
initialMessages: e.messages,
|
|
2051
2082
|
conversationId: e.conversationId,
|
|
@@ -2062,7 +2093,7 @@ W.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
2062
2093
|
autoResponseDelay: e.autoResponseDelay,
|
|
2063
2094
|
onSend: e.onSend
|
|
2064
2095
|
});
|
|
2065
|
-
return /* @__PURE__ */
|
|
2096
|
+
return /* @__PURE__ */ q(Rr, {
|
|
2066
2097
|
floatingConfig: e.floatingConfig,
|
|
2067
2098
|
messages: r,
|
|
2068
2099
|
placeholder: e.placeholder,
|
|
@@ -2234,71 +2265,71 @@ W.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
2234
2265
|
});
|
|
2235
2266
|
//#endregion
|
|
2236
2267
|
//#region src/elements/loader.tsx
|
|
2237
|
-
var
|
|
2268
|
+
var zr = ({ size: e = 16 }) => /* @__PURE__ */ J("svg", {
|
|
2238
2269
|
height: e,
|
|
2239
2270
|
strokeLinejoin: "round",
|
|
2240
2271
|
style: { color: "currentcolor" },
|
|
2241
2272
|
viewBox: "0 0 16 16",
|
|
2242
2273
|
width: e,
|
|
2243
2274
|
children: [
|
|
2244
|
-
/* @__PURE__ */
|
|
2245
|
-
/* @__PURE__ */
|
|
2275
|
+
/* @__PURE__ */ q("title", { children: "Loader" }),
|
|
2276
|
+
/* @__PURE__ */ J("g", {
|
|
2246
2277
|
clipPath: "url(#clip0_2393_1490)",
|
|
2247
2278
|
children: [
|
|
2248
|
-
/* @__PURE__ */
|
|
2279
|
+
/* @__PURE__ */ q("path", {
|
|
2249
2280
|
d: "M8 0V4",
|
|
2250
2281
|
stroke: "currentColor",
|
|
2251
2282
|
strokeWidth: "1.5"
|
|
2252
2283
|
}),
|
|
2253
|
-
/* @__PURE__ */
|
|
2284
|
+
/* @__PURE__ */ q("path", {
|
|
2254
2285
|
d: "M8 16V12",
|
|
2255
2286
|
opacity: "0.5",
|
|
2256
2287
|
stroke: "currentColor",
|
|
2257
2288
|
strokeWidth: "1.5"
|
|
2258
2289
|
}),
|
|
2259
|
-
/* @__PURE__ */
|
|
2290
|
+
/* @__PURE__ */ q("path", {
|
|
2260
2291
|
d: "M3.29773 1.52783L5.64887 4.7639",
|
|
2261
2292
|
opacity: "0.9",
|
|
2262
2293
|
stroke: "currentColor",
|
|
2263
2294
|
strokeWidth: "1.5"
|
|
2264
2295
|
}),
|
|
2265
|
-
/* @__PURE__ */
|
|
2296
|
+
/* @__PURE__ */ q("path", {
|
|
2266
2297
|
d: "M12.7023 1.52783L10.3511 4.7639",
|
|
2267
2298
|
opacity: "0.1",
|
|
2268
2299
|
stroke: "currentColor",
|
|
2269
2300
|
strokeWidth: "1.5"
|
|
2270
2301
|
}),
|
|
2271
|
-
/* @__PURE__ */
|
|
2302
|
+
/* @__PURE__ */ q("path", {
|
|
2272
2303
|
d: "M12.7023 14.472L10.3511 11.236",
|
|
2273
2304
|
opacity: "0.4",
|
|
2274
2305
|
stroke: "currentColor",
|
|
2275
2306
|
strokeWidth: "1.5"
|
|
2276
2307
|
}),
|
|
2277
|
-
/* @__PURE__ */
|
|
2308
|
+
/* @__PURE__ */ q("path", {
|
|
2278
2309
|
d: "M3.29773 14.472L5.64887 11.236",
|
|
2279
2310
|
opacity: "0.6",
|
|
2280
2311
|
stroke: "currentColor",
|
|
2281
2312
|
strokeWidth: "1.5"
|
|
2282
2313
|
}),
|
|
2283
|
-
/* @__PURE__ */
|
|
2314
|
+
/* @__PURE__ */ q("path", {
|
|
2284
2315
|
d: "M15.6085 5.52783L11.8043 6.7639",
|
|
2285
2316
|
opacity: "0.2",
|
|
2286
2317
|
stroke: "currentColor",
|
|
2287
2318
|
strokeWidth: "1.5"
|
|
2288
2319
|
}),
|
|
2289
|
-
/* @__PURE__ */
|
|
2320
|
+
/* @__PURE__ */ q("path", {
|
|
2290
2321
|
d: "M0.391602 10.472L4.19583 9.23598",
|
|
2291
2322
|
opacity: "0.7",
|
|
2292
2323
|
stroke: "currentColor",
|
|
2293
2324
|
strokeWidth: "1.5"
|
|
2294
2325
|
}),
|
|
2295
|
-
/* @__PURE__ */
|
|
2326
|
+
/* @__PURE__ */ q("path", {
|
|
2296
2327
|
d: "M15.6085 10.4722L11.8043 9.2361",
|
|
2297
2328
|
opacity: "0.3",
|
|
2298
2329
|
stroke: "currentColor",
|
|
2299
2330
|
strokeWidth: "1.5"
|
|
2300
2331
|
}),
|
|
2301
|
-
/* @__PURE__ */
|
|
2332
|
+
/* @__PURE__ */ q("path", {
|
|
2302
2333
|
d: "M0.391602 5.52783L4.19583 6.7639",
|
|
2303
2334
|
opacity: "0.8",
|
|
2304
2335
|
stroke: "currentColor",
|
|
@@ -2306,125 +2337,824 @@ var rr = ({ size: e = 16 }) => /* @__PURE__ */ H("svg", {
|
|
|
2306
2337
|
})
|
|
2307
2338
|
]
|
|
2308
2339
|
}),
|
|
2309
|
-
/* @__PURE__ */
|
|
2340
|
+
/* @__PURE__ */ q("defs", { children: /* @__PURE__ */ q("clipPath", {
|
|
2310
2341
|
id: "clip0_2393_1490",
|
|
2311
|
-
children: /* @__PURE__ */
|
|
2342
|
+
children: /* @__PURE__ */ q("rect", {
|
|
2312
2343
|
fill: "white",
|
|
2313
2344
|
height: "16",
|
|
2314
2345
|
width: "16"
|
|
2315
2346
|
})
|
|
2316
2347
|
}) })
|
|
2317
2348
|
]
|
|
2318
|
-
}),
|
|
2319
|
-
className:
|
|
2349
|
+
}), Br = ({ className: e, size: t = 16, ...n }) => /* @__PURE__ */ q("div", {
|
|
2350
|
+
className: U("inline-flex animate-spin items-center justify-center", e),
|
|
2320
2351
|
...n,
|
|
2321
|
-
children: /* @__PURE__ */
|
|
2322
|
-
}),
|
|
2352
|
+
children: /* @__PURE__ */ q(zr, { size: t })
|
|
2353
|
+
}), Vr = /* @__PURE__ */ Ot({
|
|
2323
2354
|
CodeBlock: () => Q,
|
|
2324
|
-
CodeBlockCopyButton: () =>
|
|
2325
|
-
Conversation: () =>
|
|
2326
|
-
ConversationContent: () =>
|
|
2327
|
-
ConversationEmptyState: () =>
|
|
2328
|
-
ConversationScrollButton: () =>
|
|
2329
|
-
Loader: () =>
|
|
2330
|
-
Message: () =>
|
|
2331
|
-
MessageAction: () =>
|
|
2332
|
-
MessageActions: () =>
|
|
2333
|
-
MessageAttachment: () =>
|
|
2334
|
-
MessageAttachments: () =>
|
|
2335
|
-
MessageBranch: () =>
|
|
2336
|
-
MessageBranchContent: () =>
|
|
2337
|
-
MessageBranchNext: () =>
|
|
2338
|
-
MessageBranchPage: () =>
|
|
2339
|
-
MessageBranchPrevious: () =>
|
|
2340
|
-
MessageBranchSelector: () =>
|
|
2341
|
-
MessageContent: () =>
|
|
2342
|
-
MessageResponse: () =>
|
|
2343
|
-
MessageToolbar: () =>
|
|
2344
|
-
PromptInput: () =>
|
|
2345
|
-
PromptInputActionAddAttachments: () =>
|
|
2346
|
-
PromptInputActionMenu: () =>
|
|
2347
|
-
PromptInputActionMenuContent: () =>
|
|
2348
|
-
PromptInputActionMenuItem: () =>
|
|
2349
|
-
PromptInputActionMenuTrigger: () =>
|
|
2350
|
-
PromptInputAttachment: () =>
|
|
2351
|
-
PromptInputAttachments: () =>
|
|
2352
|
-
PromptInputBody: () =>
|
|
2353
|
-
PromptInputButton: () =>
|
|
2354
|
-
PromptInputCommand: () =>
|
|
2355
|
-
PromptInputCommandEmpty: () =>
|
|
2356
|
-
PromptInputCommandGroup: () =>
|
|
2357
|
-
PromptInputCommandInput: () =>
|
|
2358
|
-
PromptInputCommandItem: () =>
|
|
2359
|
-
PromptInputCommandList: () =>
|
|
2360
|
-
PromptInputCommandSeparator: () =>
|
|
2361
|
-
PromptInputFooter: () =>
|
|
2362
|
-
PromptInputHeader: () =>
|
|
2363
|
-
PromptInputHoverCard: () =>
|
|
2364
|
-
PromptInputHoverCardContent: () =>
|
|
2365
|
-
PromptInputHoverCardTrigger: () =>
|
|
2366
|
-
PromptInputProvider: () =>
|
|
2367
|
-
PromptInputSelect: () =>
|
|
2368
|
-
PromptInputSelectContent: () =>
|
|
2369
|
-
PromptInputSelectItem: () =>
|
|
2370
|
-
PromptInputSelectTrigger: () =>
|
|
2371
|
-
PromptInputSelectValue: () =>
|
|
2372
|
-
PromptInputSpeechButton: () =>
|
|
2373
|
-
PromptInputSubmit: () =>
|
|
2374
|
-
PromptInputTab: () =>
|
|
2375
|
-
PromptInputTabBody: () =>
|
|
2376
|
-
PromptInputTabItem: () =>
|
|
2377
|
-
PromptInputTabLabel: () =>
|
|
2378
|
-
PromptInputTabsList: () =>
|
|
2379
|
-
PromptInputTextarea: () =>
|
|
2380
|
-
PromptInputTools: () =>
|
|
2381
|
-
Reasoning: () =>
|
|
2382
|
-
ReasoningContent: () =>
|
|
2383
|
-
ReasoningTrigger: () =>
|
|
2384
|
-
Shimmer: () =>
|
|
2385
|
-
Source: () =>
|
|
2386
|
-
Sources: () =>
|
|
2387
|
-
SourcesContent: () =>
|
|
2388
|
-
SourcesTrigger: () =>
|
|
2389
|
-
Suggestion: () =>
|
|
2390
|
-
Suggestions: () =>
|
|
2391
|
-
Tool: () =>
|
|
2392
|
-
ToolContent: () =>
|
|
2393
|
-
ToolHeader: () =>
|
|
2394
|
-
ToolInput: () =>
|
|
2395
|
-
ToolOutput: () =>
|
|
2396
|
-
highlightCode: () =>
|
|
2355
|
+
CodeBlockCopyButton: () => gr,
|
|
2356
|
+
Conversation: () => Kt,
|
|
2357
|
+
ConversationContent: () => qt,
|
|
2358
|
+
ConversationEmptyState: () => Jt,
|
|
2359
|
+
ConversationScrollButton: () => Yt,
|
|
2360
|
+
Loader: () => Br,
|
|
2361
|
+
Message: () => $t,
|
|
2362
|
+
MessageAction: () => nn,
|
|
2363
|
+
MessageActions: () => tn,
|
|
2364
|
+
MessageAttachment: () => fn,
|
|
2365
|
+
MessageAttachments: () => pn,
|
|
2366
|
+
MessageBranch: () => an,
|
|
2367
|
+
MessageBranchContent: () => on,
|
|
2368
|
+
MessageBranchNext: () => ln,
|
|
2369
|
+
MessageBranchPage: () => un,
|
|
2370
|
+
MessageBranchPrevious: () => cn,
|
|
2371
|
+
MessageBranchSelector: () => sn,
|
|
2372
|
+
MessageContent: () => en,
|
|
2373
|
+
MessageResponse: () => dn,
|
|
2374
|
+
MessageToolbar: () => mn,
|
|
2375
|
+
PromptInput: () => Mn,
|
|
2376
|
+
PromptInputActionAddAttachments: () => jn,
|
|
2377
|
+
PromptInputActionMenu: () => zn,
|
|
2378
|
+
PromptInputActionMenuContent: () => Vn,
|
|
2379
|
+
PromptInputActionMenuItem: () => Hn,
|
|
2380
|
+
PromptInputActionMenuTrigger: () => Bn,
|
|
2381
|
+
PromptInputAttachment: () => kn,
|
|
2382
|
+
PromptInputAttachments: () => An,
|
|
2383
|
+
PromptInputBody: () => Nn,
|
|
2384
|
+
PromptInputButton: () => Rn,
|
|
2385
|
+
PromptInputCommand: () => ir,
|
|
2386
|
+
PromptInputCommandEmpty: () => sr,
|
|
2387
|
+
PromptInputCommandGroup: () => cr,
|
|
2388
|
+
PromptInputCommandInput: () => ar,
|
|
2389
|
+
PromptInputCommandItem: () => lr,
|
|
2390
|
+
PromptInputCommandList: () => or,
|
|
2391
|
+
PromptInputCommandSeparator: () => ur,
|
|
2392
|
+
PromptInputFooter: () => In,
|
|
2393
|
+
PromptInputHeader: () => Fn,
|
|
2394
|
+
PromptInputHoverCard: () => Xn,
|
|
2395
|
+
PromptInputHoverCardContent: () => Qn,
|
|
2396
|
+
PromptInputHoverCardTrigger: () => Zn,
|
|
2397
|
+
PromptInputProvider: () => Dn,
|
|
2398
|
+
PromptInputSelect: () => Gn,
|
|
2399
|
+
PromptInputSelectContent: () => qn,
|
|
2400
|
+
PromptInputSelectItem: () => Jn,
|
|
2401
|
+
PromptInputSelectTrigger: () => Kn,
|
|
2402
|
+
PromptInputSelectValue: () => Yn,
|
|
2403
|
+
PromptInputSpeechButton: () => Wn,
|
|
2404
|
+
PromptInputSubmit: () => Un,
|
|
2405
|
+
PromptInputTab: () => er,
|
|
2406
|
+
PromptInputTabBody: () => nr,
|
|
2407
|
+
PromptInputTabItem: () => rr,
|
|
2408
|
+
PromptInputTabLabel: () => tr,
|
|
2409
|
+
PromptInputTabsList: () => $n,
|
|
2410
|
+
PromptInputTextarea: () => Pn,
|
|
2411
|
+
PromptInputTools: () => Ln,
|
|
2412
|
+
Reasoning: () => Or,
|
|
2413
|
+
ReasoningContent: () => jr,
|
|
2414
|
+
ReasoningTrigger: () => Ar,
|
|
2415
|
+
Shimmer: () => Cr,
|
|
2416
|
+
Source: () => Fr,
|
|
2417
|
+
Sources: () => Mr,
|
|
2418
|
+
SourcesContent: () => Pr,
|
|
2419
|
+
SourcesTrigger: () => Nr,
|
|
2420
|
+
Suggestion: () => fr,
|
|
2421
|
+
Suggestions: () => dr,
|
|
2422
|
+
Tool: () => _r,
|
|
2423
|
+
ToolContent: () => br,
|
|
2424
|
+
ToolHeader: () => yr,
|
|
2425
|
+
ToolInput: () => xr,
|
|
2426
|
+
ToolOutput: () => Sr,
|
|
2427
|
+
highlightCode: () => hr,
|
|
2397
2428
|
usePromptInputAttachments: () => Z,
|
|
2398
|
-
usePromptInputController: () =>
|
|
2399
|
-
useProviderAttachments: () =>
|
|
2400
|
-
useReasoning: () =>
|
|
2401
|
-
}),
|
|
2402
|
-
|
|
2429
|
+
usePromptInputController: () => Cn,
|
|
2430
|
+
useProviderAttachments: () => Tn,
|
|
2431
|
+
useReasoning: () => Tr
|
|
2432
|
+
}), Hr = "/api/v1/ai";
|
|
2433
|
+
function Ur(e, t, n) {
|
|
2434
|
+
let r = e.replace(/\/$/, ""), i = new URLSearchParams();
|
|
2435
|
+
if (n) for (let [e, t] of Object.entries(n)) t == null || t === "" || i.set(e, String(t));
|
|
2436
|
+
let a = i.toString();
|
|
2437
|
+
return `${r}${t}${a ? `?${a}` : ""}`;
|
|
2438
|
+
}
|
|
2439
|
+
async function Wr(e, t, n) {
|
|
2440
|
+
let r = await fetch(e, {
|
|
2441
|
+
credentials: "include",
|
|
2442
|
+
...t,
|
|
2443
|
+
headers: {
|
|
2444
|
+
Accept: "application/json",
|
|
2445
|
+
"Content-Type": "application/json",
|
|
2446
|
+
...n ?? {},
|
|
2447
|
+
...t.headers ?? {}
|
|
2448
|
+
}
|
|
2449
|
+
}), i = null;
|
|
2450
|
+
try {
|
|
2451
|
+
i = await r.json();
|
|
2452
|
+
} catch {}
|
|
2453
|
+
if (!r.ok) {
|
|
2454
|
+
let e = i?.error?.message ?? i?.message ?? i?.error ?? `${r.status} ${r.statusText}`, t = Error(typeof e == "string" ? e : JSON.stringify(e));
|
|
2455
|
+
throw t.status = r.status, t.body = i, t;
|
|
2456
|
+
}
|
|
2457
|
+
return i;
|
|
2458
|
+
}
|
|
2459
|
+
function Gr(t = {}) {
|
|
2460
|
+
let { apiBase: n = Hr, status: r = "pending", conversationId: i, limit: a, headers: o, pollInterval: s = 5e3, enabled: c = !0 } = t, [l, u] = e.useState([]), [d, f] = e.useState(0), [p, m] = e.useState(!1), [h, g] = e.useState(void 0), _ = e.useRef({
|
|
2461
|
+
apiBase: n,
|
|
2462
|
+
status: r,
|
|
2463
|
+
conversationId: i,
|
|
2464
|
+
limit: a,
|
|
2465
|
+
headers: o
|
|
2466
|
+
});
|
|
2467
|
+
_.current = {
|
|
2468
|
+
apiBase: n,
|
|
2469
|
+
status: r,
|
|
2470
|
+
conversationId: i,
|
|
2471
|
+
limit: a,
|
|
2472
|
+
headers: o
|
|
2473
|
+
};
|
|
2474
|
+
let v = e.useCallback(async () => {
|
|
2475
|
+
let { apiBase: e, status: t, conversationId: n, limit: r, headers: i } = _.current;
|
|
2476
|
+
m(!0), g(void 0);
|
|
2477
|
+
try {
|
|
2478
|
+
let a = await Wr(Ur(e, "/pending-actions", {
|
|
2479
|
+
status: t && t !== "all" ? t : void 0,
|
|
2480
|
+
conversationId: n,
|
|
2481
|
+
limit: r
|
|
2482
|
+
}), { method: "GET" }, i);
|
|
2483
|
+
u(Array.isArray(a.items) ? a.items : []), f(typeof a.total == "number" ? a.total : a.items?.length ?? 0);
|
|
2484
|
+
} catch (e) {
|
|
2485
|
+
g(e instanceof Error ? e : Error(String(e)));
|
|
2486
|
+
} finally {
|
|
2487
|
+
m(!1);
|
|
2488
|
+
}
|
|
2489
|
+
}, []), y = e.useCallback(async (e) => {
|
|
2490
|
+
let { apiBase: t, headers: n } = _.current, r = Ur(t, `/pending-actions/${encodeURIComponent(e)}/approve`);
|
|
2491
|
+
try {
|
|
2492
|
+
return await Wr(r, {
|
|
2493
|
+
method: "POST",
|
|
2494
|
+
body: "{}"
|
|
2495
|
+
}, n);
|
|
2496
|
+
} finally {
|
|
2497
|
+
v();
|
|
2498
|
+
}
|
|
2499
|
+
}, [v]), b = e.useCallback(async (e, t) => {
|
|
2500
|
+
let { apiBase: n, headers: r } = _.current, i = Ur(n, `/pending-actions/${encodeURIComponent(e)}/reject`);
|
|
2501
|
+
try {
|
|
2502
|
+
return await Wr(i, {
|
|
2503
|
+
method: "POST",
|
|
2504
|
+
body: JSON.stringify(t ? { reason: t } : {})
|
|
2505
|
+
}, r);
|
|
2506
|
+
} finally {
|
|
2507
|
+
v();
|
|
2508
|
+
}
|
|
2509
|
+
}, [v]);
|
|
2510
|
+
return e.useEffect(() => {
|
|
2511
|
+
if (!c || (v(), !s || s <= 0)) return;
|
|
2512
|
+
let e = setInterval(() => {
|
|
2513
|
+
v();
|
|
2514
|
+
}, s);
|
|
2515
|
+
return () => clearInterval(e);
|
|
2516
|
+
}, [
|
|
2517
|
+
c,
|
|
2518
|
+
s,
|
|
2519
|
+
v,
|
|
2520
|
+
n,
|
|
2521
|
+
r,
|
|
2522
|
+
i,
|
|
2523
|
+
a
|
|
2524
|
+
]), {
|
|
2525
|
+
items: l,
|
|
2526
|
+
total: d,
|
|
2527
|
+
isLoading: p,
|
|
2528
|
+
error: h,
|
|
2529
|
+
refresh: v,
|
|
2530
|
+
approve: y,
|
|
2531
|
+
reject: b
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
//#endregion
|
|
2535
|
+
//#region src/AiPendingActionsInbox.tsx
|
|
2536
|
+
var Kr = {
|
|
2537
|
+
pending: {
|
|
2538
|
+
variant: "secondary",
|
|
2539
|
+
label: "Pending"
|
|
2540
|
+
},
|
|
2541
|
+
approved: {
|
|
2542
|
+
variant: "default",
|
|
2543
|
+
label: "Approved"
|
|
2544
|
+
},
|
|
2545
|
+
executed: {
|
|
2546
|
+
variant: "default",
|
|
2547
|
+
label: "Executed"
|
|
2548
|
+
},
|
|
2549
|
+
failed: {
|
|
2550
|
+
variant: "destructive",
|
|
2551
|
+
label: "Failed"
|
|
2552
|
+
},
|
|
2553
|
+
rejected: {
|
|
2554
|
+
variant: "outline",
|
|
2555
|
+
label: "Rejected"
|
|
2556
|
+
}
|
|
2557
|
+
};
|
|
2558
|
+
function qr({ status: e }) {
|
|
2559
|
+
let t = Kr[e] ?? {
|
|
2560
|
+
variant: "outline",
|
|
2561
|
+
label: e
|
|
2562
|
+
};
|
|
2563
|
+
return /* @__PURE__ */ q(_, {
|
|
2564
|
+
variant: t.variant,
|
|
2565
|
+
children: t.label
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
function Jr(e) {
|
|
2569
|
+
if (!e) return "—";
|
|
2570
|
+
let t = Date.parse(e);
|
|
2571
|
+
if (Number.isNaN(t)) return e;
|
|
2572
|
+
let n = Date.now() - t, r = Math.round(n / 1e3);
|
|
2573
|
+
if (r < 45) return "just now";
|
|
2574
|
+
let i = Math.round(r / 60);
|
|
2575
|
+
if (i < 60) return `${i}m ago`;
|
|
2576
|
+
let a = Math.round(i / 60);
|
|
2577
|
+
if (a < 24) return `${a}h ago`;
|
|
2578
|
+
let o = Math.round(a / 24);
|
|
2579
|
+
if (o < 30) return `${o}d ago`;
|
|
2580
|
+
try {
|
|
2581
|
+
return new Date(e).toLocaleDateString();
|
|
2582
|
+
} catch {
|
|
2583
|
+
return e;
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
function Yr(e) {
|
|
2587
|
+
if (!e) return null;
|
|
2588
|
+
try {
|
|
2589
|
+
return JSON.parse(e);
|
|
2590
|
+
} catch {
|
|
2591
|
+
return e;
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
function Xr({ value: e, max: t = 320 }) {
|
|
2595
|
+
let n = typeof e == "string" ? e : JSON.stringify(e, null, 2);
|
|
2596
|
+
return n == null || n === "" ? /* @__PURE__ */ q("span", {
|
|
2597
|
+
className: "text-muted-foreground text-xs",
|
|
2598
|
+
children: "—"
|
|
2599
|
+
}) : /* @__PURE__ */ q("pre", {
|
|
2600
|
+
className: "bg-muted/40 rounded text-xs p-2 overflow-auto whitespace-pre-wrap break-all",
|
|
2601
|
+
style: { maxHeight: t },
|
|
2602
|
+
children: n
|
|
2603
|
+
});
|
|
2604
|
+
}
|
|
2605
|
+
function Zr(e) {
|
|
2606
|
+
switch (e) {
|
|
2607
|
+
case "pending": return "pending";
|
|
2608
|
+
case "all": return "all";
|
|
2609
|
+
case "decided": return "all";
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
function Qr({ apiBase: t, headers: n, pollInterval: r = 5e3, conversationId: i, variant: a = "card", title: o = "AI Approvals", description: s = "Actions an AI agent proposed that need a human review before execution.", className: c }) {
|
|
2613
|
+
let [l, u] = e.useState("pending"), [d, m] = e.useState(null), [h, g] = e.useState(null), [_, w] = e.useState(""), [T, E] = e.useState(null), [D, O] = e.useState(null), [k, A] = e.useState(null), { items: j, isLoading: M, error: N, refresh: P, approve: F, reject: I } = Gr({
|
|
2614
|
+
apiBase: t,
|
|
2615
|
+
headers: n,
|
|
2616
|
+
pollInterval: r,
|
|
2617
|
+
conversationId: i,
|
|
2618
|
+
status: Zr(l)
|
|
2619
|
+
}), L = e.useMemo(() => l === "decided" ? j.filter((e) => e.status !== "pending") : j, [j, l]), R = e.useMemo(() => d ? j.find((e) => e.id === d) ?? null : null, [d, j]), ae = e.useCallback(async (e) => {
|
|
2620
|
+
E(e), O(null);
|
|
2621
|
+
try {
|
|
2622
|
+
let t = await F(e), n = t.status === "executed";
|
|
2623
|
+
A({
|
|
2624
|
+
id: e,
|
|
2625
|
+
kind: "approve",
|
|
2626
|
+
ok: n,
|
|
2627
|
+
message: n ? "Executed" : t.error ?? "Action failed during execution"
|
|
2628
|
+
});
|
|
2629
|
+
} catch (t) {
|
|
2630
|
+
let n = t instanceof Error ? t.message : String(t);
|
|
2631
|
+
O(n), A({
|
|
2632
|
+
id: e,
|
|
2633
|
+
kind: "approve",
|
|
2634
|
+
ok: !1,
|
|
2635
|
+
message: n
|
|
2636
|
+
});
|
|
2637
|
+
} finally {
|
|
2638
|
+
E(null);
|
|
2639
|
+
}
|
|
2640
|
+
}, [F]), z = e.useCallback(async (e, t) => {
|
|
2641
|
+
E(e), O(null);
|
|
2642
|
+
try {
|
|
2643
|
+
await I(e, t.trim() || void 0), A({
|
|
2644
|
+
id: e,
|
|
2645
|
+
kind: "reject",
|
|
2646
|
+
ok: !0,
|
|
2647
|
+
message: "Rejected"
|
|
2648
|
+
}), g(null), w("");
|
|
2649
|
+
} catch (t) {
|
|
2650
|
+
let n = t instanceof Error ? t.message : String(t);
|
|
2651
|
+
O(n), A({
|
|
2652
|
+
id: e,
|
|
2653
|
+
kind: "reject",
|
|
2654
|
+
ok: !1,
|
|
2655
|
+
message: n
|
|
2656
|
+
});
|
|
2657
|
+
} finally {
|
|
2658
|
+
E(null);
|
|
2659
|
+
}
|
|
2660
|
+
}, [I]), oe = /* @__PURE__ */ J("div", {
|
|
2661
|
+
className: "space-y-3",
|
|
2662
|
+
children: [
|
|
2663
|
+
/* @__PURE__ */ J("div", {
|
|
2664
|
+
className: "flex items-center justify-between gap-2",
|
|
2665
|
+
children: [/* @__PURE__ */ q(Te, {
|
|
2666
|
+
value: l,
|
|
2667
|
+
onValueChange: (e) => u(e),
|
|
2668
|
+
children: /* @__PURE__ */ J(Ee, { children: [
|
|
2669
|
+
/* @__PURE__ */ q(De, {
|
|
2670
|
+
value: "pending",
|
|
2671
|
+
children: "Pending"
|
|
2672
|
+
}),
|
|
2673
|
+
/* @__PURE__ */ q(De, {
|
|
2674
|
+
value: "decided",
|
|
2675
|
+
children: "Decided"
|
|
2676
|
+
}),
|
|
2677
|
+
/* @__PURE__ */ q(De, {
|
|
2678
|
+
value: "all",
|
|
2679
|
+
children: "All"
|
|
2680
|
+
})
|
|
2681
|
+
] })
|
|
2682
|
+
}), /* @__PURE__ */ J(v, {
|
|
2683
|
+
variant: "outline",
|
|
2684
|
+
size: "sm",
|
|
2685
|
+
onClick: () => void P(),
|
|
2686
|
+
disabled: M,
|
|
2687
|
+
"data-testid": "ai-inbox-refresh",
|
|
2688
|
+
children: [/* @__PURE__ */ q(st, { className: `h-3.5 w-3.5 mr-1.5 ${M ? "animate-spin" : ""}` }), "Refresh"]
|
|
2689
|
+
})]
|
|
2690
|
+
}),
|
|
2691
|
+
N ? /* @__PURE__ */ J(f, {
|
|
2692
|
+
variant: "destructive",
|
|
2693
|
+
children: [/* @__PURE__ */ q(Ne, { className: "h-4 w-4" }), /* @__PURE__ */ q(p, { children: N.message })]
|
|
2694
|
+
}) : null,
|
|
2695
|
+
D ? /* @__PURE__ */ J(f, {
|
|
2696
|
+
variant: "destructive",
|
|
2697
|
+
children: [/* @__PURE__ */ q(Ne, { className: "h-4 w-4" }), /* @__PURE__ */ q(p, { children: D })]
|
|
2698
|
+
}) : null,
|
|
2699
|
+
k && !D ? /* @__PURE__ */ J(f, {
|
|
2700
|
+
variant: k.ok ? "default" : "destructive",
|
|
2701
|
+
children: [k.ok ? /* @__PURE__ */ q(ze, { className: "h-4 w-4" }) : /* @__PURE__ */ q(W, { className: "h-4 w-4" }), /* @__PURE__ */ J(p, { children: [
|
|
2702
|
+
k.kind === "approve" ? "Approve" : "Reject",
|
|
2703
|
+
" for",
|
|
2704
|
+
" ",
|
|
2705
|
+
/* @__PURE__ */ J("code", {
|
|
2706
|
+
className: "text-xs",
|
|
2707
|
+
children: [k.id.slice(0, 8), "…"]
|
|
2708
|
+
}),
|
|
2709
|
+
":",
|
|
2710
|
+
" ",
|
|
2711
|
+
k.message ?? (k.ok ? "OK" : "Failed")
|
|
2712
|
+
] })]
|
|
2713
|
+
}) : null,
|
|
2714
|
+
M && L.length === 0 ? /* @__PURE__ */ J("div", {
|
|
2715
|
+
className: "space-y-2",
|
|
2716
|
+
children: [
|
|
2717
|
+
/* @__PURE__ */ q(be, { className: "h-10 w-full" }),
|
|
2718
|
+
/* @__PURE__ */ q(be, { className: "h-10 w-full" }),
|
|
2719
|
+
/* @__PURE__ */ q(be, { className: "h-10 w-full" })
|
|
2720
|
+
]
|
|
2721
|
+
}) : L.length === 0 ? /* @__PURE__ */ q(ee, { children: /* @__PURE__ */ J(ne, { children: [
|
|
2722
|
+
/* @__PURE__ */ q(re, { children: /* @__PURE__ */ q($e, { className: "h-8 w-8 text-muted-foreground" }) }),
|
|
2723
|
+
/* @__PURE__ */ q(ie, { children: "No actions waiting" }),
|
|
2724
|
+
/* @__PURE__ */ q(te, { children: "When the AI proposes a sensitive action it will appear here for review." })
|
|
2725
|
+
] }) }) : /* @__PURE__ */ q("div", {
|
|
2726
|
+
className: "rounded-md border",
|
|
2727
|
+
children: /* @__PURE__ */ J(xe, { children: [/* @__PURE__ */ q(Ce, { children: /* @__PURE__ */ J(we, { children: [
|
|
2728
|
+
/* @__PURE__ */ q(H, {
|
|
2729
|
+
className: "w-[140px]",
|
|
2730
|
+
children: "Tool"
|
|
2731
|
+
}),
|
|
2732
|
+
/* @__PURE__ */ q(H, {
|
|
2733
|
+
className: "w-[140px]",
|
|
2734
|
+
children: "Action"
|
|
2735
|
+
}),
|
|
2736
|
+
/* @__PURE__ */ q(H, {
|
|
2737
|
+
className: "w-[120px]",
|
|
2738
|
+
children: "Object"
|
|
2739
|
+
}),
|
|
2740
|
+
/* @__PURE__ */ q(H, {
|
|
2741
|
+
className: "w-[110px]",
|
|
2742
|
+
children: "Status"
|
|
2743
|
+
}),
|
|
2744
|
+
/* @__PURE__ */ q(H, {
|
|
2745
|
+
className: "w-[110px]",
|
|
2746
|
+
children: "Proposed"
|
|
2747
|
+
}),
|
|
2748
|
+
/* @__PURE__ */ q(H, {
|
|
2749
|
+
className: "w-[260px] text-right",
|
|
2750
|
+
children: "Decision"
|
|
2751
|
+
})
|
|
2752
|
+
] }) }), /* @__PURE__ */ q(Se, { children: L.map((e) => {
|
|
2753
|
+
let t = e.status === "pending", n = T === e.id;
|
|
2754
|
+
return /* @__PURE__ */ J(we, { children: [
|
|
2755
|
+
/* @__PURE__ */ q(V, {
|
|
2756
|
+
className: "font-mono text-xs",
|
|
2757
|
+
children: e.tool_name
|
|
2758
|
+
}),
|
|
2759
|
+
/* @__PURE__ */ q(V, {
|
|
2760
|
+
className: "text-sm",
|
|
2761
|
+
children: e.action_name
|
|
2762
|
+
}),
|
|
2763
|
+
/* @__PURE__ */ q(V, {
|
|
2764
|
+
className: "text-sm",
|
|
2765
|
+
children: e.object_name
|
|
2766
|
+
}),
|
|
2767
|
+
/* @__PURE__ */ q(V, { children: /* @__PURE__ */ q(qr, { status: e.status }) }),
|
|
2768
|
+
/* @__PURE__ */ q(V, {
|
|
2769
|
+
className: "text-xs text-muted-foreground",
|
|
2770
|
+
children: /* @__PURE__ */ J("span", {
|
|
2771
|
+
className: "inline-flex items-center gap-1",
|
|
2772
|
+
children: [
|
|
2773
|
+
/* @__PURE__ */ q(Ke, { className: "h-3 w-3" }),
|
|
2774
|
+
" ",
|
|
2775
|
+
Jr(e.proposed_at)
|
|
2776
|
+
]
|
|
2777
|
+
})
|
|
2778
|
+
}),
|
|
2779
|
+
/* @__PURE__ */ q(V, {
|
|
2780
|
+
className: "text-right",
|
|
2781
|
+
children: /* @__PURE__ */ J("div", {
|
|
2782
|
+
className: "inline-flex gap-1.5",
|
|
2783
|
+
children: [/* @__PURE__ */ J(v, {
|
|
2784
|
+
size: "sm",
|
|
2785
|
+
variant: "ghost",
|
|
2786
|
+
onClick: () => m(e.id),
|
|
2787
|
+
"data-testid": `ai-inbox-view-${e.id}`,
|
|
2788
|
+
children: [/* @__PURE__ */ q(Ze, { className: "h-3.5 w-3.5 mr-1" }), " View"]
|
|
2789
|
+
}), t ? /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ J(v, {
|
|
2790
|
+
size: "sm",
|
|
2791
|
+
variant: "default",
|
|
2792
|
+
disabled: n,
|
|
2793
|
+
onClick: () => void ae(e.id),
|
|
2794
|
+
"data-testid": `ai-inbox-approve-${e.id}`,
|
|
2795
|
+
children: [/* @__PURE__ */ q(ze, { className: "h-3.5 w-3.5 mr-1" }), n ? "Working…" : "Approve"]
|
|
2796
|
+
}), /* @__PURE__ */ J(v, {
|
|
2797
|
+
size: "sm",
|
|
2798
|
+
variant: "destructive",
|
|
2799
|
+
disabled: n,
|
|
2800
|
+
onClick: () => {
|
|
2801
|
+
g(e.id), w("");
|
|
2802
|
+
},
|
|
2803
|
+
"data-testid": `ai-inbox-reject-${e.id}`,
|
|
2804
|
+
children: [/* @__PURE__ */ q(W, { className: "h-3.5 w-3.5 mr-1" }), "Reject"]
|
|
2805
|
+
})] }) : null]
|
|
2806
|
+
})
|
|
2807
|
+
})
|
|
2808
|
+
] }, e.id);
|
|
2809
|
+
}) })] })
|
|
2810
|
+
})
|
|
2811
|
+
]
|
|
2812
|
+
});
|
|
2813
|
+
return /* @__PURE__ */ J(K, { children: [
|
|
2814
|
+
a === "card" ? /* @__PURE__ */ J(y, {
|
|
2815
|
+
className: c,
|
|
2816
|
+
children: [/* @__PURE__ */ J(S, {
|
|
2817
|
+
className: "pb-3",
|
|
2818
|
+
children: [/* @__PURE__ */ J(C, {
|
|
2819
|
+
className: "flex items-center gap-2",
|
|
2820
|
+
children: [
|
|
2821
|
+
/* @__PURE__ */ q(Ie, { className: "h-4 w-4" }),
|
|
2822
|
+
" ",
|
|
2823
|
+
o
|
|
2824
|
+
]
|
|
2825
|
+
}), s ? /* @__PURE__ */ q(x, { children: s }) : null]
|
|
2826
|
+
}), /* @__PURE__ */ q(b, { children: oe })]
|
|
2827
|
+
}) : /* @__PURE__ */ q("div", {
|
|
2828
|
+
className: c,
|
|
2829
|
+
children: oe
|
|
2830
|
+
}),
|
|
2831
|
+
/* @__PURE__ */ q(he, {
|
|
2832
|
+
open: !!d,
|
|
2833
|
+
onOpenChange: (e) => {
|
|
2834
|
+
e || m(null);
|
|
2835
|
+
},
|
|
2836
|
+
children: /* @__PURE__ */ J(ge, {
|
|
2837
|
+
className: "sm:max-w-[560px] overflow-y-auto",
|
|
2838
|
+
children: [/* @__PURE__ */ J(ve, { children: [/* @__PURE__ */ J(ye, {
|
|
2839
|
+
className: "flex items-center gap-2",
|
|
2840
|
+
children: [/* @__PURE__ */ q(Ie, { className: "h-4 w-4" }), R ? R.action_name : "Pending action"]
|
|
2841
|
+
}), /* @__PURE__ */ q(_e, { children: R ? /* @__PURE__ */ J(K, { children: [
|
|
2842
|
+
"Tool ",
|
|
2843
|
+
/* @__PURE__ */ q("code", {
|
|
2844
|
+
className: "text-xs",
|
|
2845
|
+
children: R.tool_name
|
|
2846
|
+
}),
|
|
2847
|
+
" on",
|
|
2848
|
+
" ",
|
|
2849
|
+
/* @__PURE__ */ q("code", {
|
|
2850
|
+
className: "text-xs",
|
|
2851
|
+
children: R.object_name
|
|
2852
|
+
})
|
|
2853
|
+
] }) : "Loading…" })] }), R ? /* @__PURE__ */ J("div", {
|
|
2854
|
+
className: "px-4 space-y-4 mt-4",
|
|
2855
|
+
children: [
|
|
2856
|
+
/* @__PURE__ */ J("div", {
|
|
2857
|
+
className: "grid grid-cols-2 gap-3 text-sm",
|
|
2858
|
+
children: [
|
|
2859
|
+
/* @__PURE__ */ J("div", { children: [/* @__PURE__ */ q(B, {
|
|
2860
|
+
className: "text-xs text-muted-foreground",
|
|
2861
|
+
children: "Status"
|
|
2862
|
+
}), /* @__PURE__ */ q("div", {
|
|
2863
|
+
className: "mt-1",
|
|
2864
|
+
children: /* @__PURE__ */ q(qr, { status: R.status })
|
|
2865
|
+
})] }),
|
|
2866
|
+
/* @__PURE__ */ J("div", { children: [/* @__PURE__ */ q(B, {
|
|
2867
|
+
className: "text-xs text-muted-foreground",
|
|
2868
|
+
children: "Proposed"
|
|
2869
|
+
}), /* @__PURE__ */ q("div", {
|
|
2870
|
+
className: "mt-1 text-xs",
|
|
2871
|
+
children: Jr(R.proposed_at)
|
|
2872
|
+
})] }),
|
|
2873
|
+
/* @__PURE__ */ J("div", { children: [/* @__PURE__ */ q(B, {
|
|
2874
|
+
className: "text-xs text-muted-foreground",
|
|
2875
|
+
children: "Proposed by"
|
|
2876
|
+
}), /* @__PURE__ */ q("div", {
|
|
2877
|
+
className: "mt-1 text-xs font-mono break-all",
|
|
2878
|
+
children: R.proposed_by ?? "—"
|
|
2879
|
+
})] }),
|
|
2880
|
+
/* @__PURE__ */ J("div", { children: [/* @__PURE__ */ q(B, {
|
|
2881
|
+
className: "text-xs text-muted-foreground",
|
|
2882
|
+
children: "Decided by"
|
|
2883
|
+
}), /* @__PURE__ */ q("div", {
|
|
2884
|
+
className: "mt-1 text-xs font-mono break-all",
|
|
2885
|
+
children: R.decided_by ?? "—"
|
|
2886
|
+
})] }),
|
|
2887
|
+
R.conversation_id ? /* @__PURE__ */ J("div", {
|
|
2888
|
+
className: "col-span-2",
|
|
2889
|
+
children: [/* @__PURE__ */ q(B, {
|
|
2890
|
+
className: "text-xs text-muted-foreground",
|
|
2891
|
+
children: "Conversation"
|
|
2892
|
+
}), /* @__PURE__ */ q("div", {
|
|
2893
|
+
className: "mt-1 text-xs font-mono break-all",
|
|
2894
|
+
children: R.conversation_id
|
|
2895
|
+
})]
|
|
2896
|
+
}) : null
|
|
2897
|
+
]
|
|
2898
|
+
}),
|
|
2899
|
+
/* @__PURE__ */ q(me, {}),
|
|
2900
|
+
/* @__PURE__ */ J("div", { children: [/* @__PURE__ */ q(B, {
|
|
2901
|
+
className: "text-xs",
|
|
2902
|
+
children: "Tool input"
|
|
2903
|
+
}), /* @__PURE__ */ q("div", {
|
|
2904
|
+
className: "mt-1.5",
|
|
2905
|
+
children: /* @__PURE__ */ q(Xr, { value: Yr(R.tool_input) })
|
|
2906
|
+
})] }),
|
|
2907
|
+
R.result ? /* @__PURE__ */ J("div", { children: [/* @__PURE__ */ q(B, {
|
|
2908
|
+
className: "text-xs",
|
|
2909
|
+
children: "Result"
|
|
2910
|
+
}), /* @__PURE__ */ q("div", {
|
|
2911
|
+
className: "mt-1.5",
|
|
2912
|
+
children: /* @__PURE__ */ q(Xr, { value: Yr(R.result) })
|
|
2913
|
+
})] }) : null,
|
|
2914
|
+
R.error ? /* @__PURE__ */ J("div", { children: [/* @__PURE__ */ q(B, {
|
|
2915
|
+
className: "text-xs text-destructive",
|
|
2916
|
+
children: "Error"
|
|
2917
|
+
}), /* @__PURE__ */ q("div", {
|
|
2918
|
+
className: "mt-1.5",
|
|
2919
|
+
children: /* @__PURE__ */ q(Xr, { value: R.error })
|
|
2920
|
+
})] }) : null,
|
|
2921
|
+
R.rejection_reason ? /* @__PURE__ */ J("div", { children: [/* @__PURE__ */ q(B, {
|
|
2922
|
+
className: "text-xs",
|
|
2923
|
+
children: "Rejection reason"
|
|
2924
|
+
}), /* @__PURE__ */ q("div", {
|
|
2925
|
+
className: "mt-1.5 text-sm",
|
|
2926
|
+
children: R.rejection_reason
|
|
2927
|
+
})] }) : null,
|
|
2928
|
+
R.status === "pending" ? /* @__PURE__ */ J("div", {
|
|
2929
|
+
className: "pt-2 flex gap-2",
|
|
2930
|
+
children: [/* @__PURE__ */ J(v, {
|
|
2931
|
+
size: "sm",
|
|
2932
|
+
onClick: () => void ae(R.id),
|
|
2933
|
+
disabled: T === R.id,
|
|
2934
|
+
children: [/* @__PURE__ */ q(ze, { className: "h-3.5 w-3.5 mr-1" }), "Approve & Execute"]
|
|
2935
|
+
}), /* @__PURE__ */ J(v, {
|
|
2936
|
+
size: "sm",
|
|
2937
|
+
variant: "destructive",
|
|
2938
|
+
onClick: () => {
|
|
2939
|
+
g(R.id), w("");
|
|
2940
|
+
},
|
|
2941
|
+
disabled: T === R.id,
|
|
2942
|
+
children: [/* @__PURE__ */ q(W, { className: "h-3.5 w-3.5 mr-1" }), "Reject"]
|
|
2943
|
+
})]
|
|
2944
|
+
}) : null
|
|
2945
|
+
]
|
|
2946
|
+
}) : null]
|
|
2947
|
+
})
|
|
2948
|
+
}),
|
|
2949
|
+
/* @__PURE__ */ q(he, {
|
|
2950
|
+
open: !!h,
|
|
2951
|
+
onOpenChange: (e) => {
|
|
2952
|
+
e || (g(null), w(""));
|
|
2953
|
+
},
|
|
2954
|
+
children: /* @__PURE__ */ J(ge, {
|
|
2955
|
+
side: "bottom",
|
|
2956
|
+
className: "max-h-[40vh]",
|
|
2957
|
+
children: [/* @__PURE__ */ J(ve, { children: [/* @__PURE__ */ q(ye, { children: "Reject this action?" }), /* @__PURE__ */ q(_e, { children: "The reason is shown back to the AI so it can adjust its next response." })] }), /* @__PURE__ */ J("div", {
|
|
2958
|
+
className: "px-4 mt-3 space-y-3",
|
|
2959
|
+
children: [/* @__PURE__ */ q(Oe, {
|
|
2960
|
+
value: _,
|
|
2961
|
+
onChange: (e) => w(e.target.value),
|
|
2962
|
+
placeholder: "Optional reason (e.g. 'Wrong record id — please confirm with the user first.')",
|
|
2963
|
+
rows: 4,
|
|
2964
|
+
"data-testid": "ai-inbox-reject-reason"
|
|
2965
|
+
}), /* @__PURE__ */ J("div", {
|
|
2966
|
+
className: "flex justify-end gap-2",
|
|
2967
|
+
children: [/* @__PURE__ */ q(v, {
|
|
2968
|
+
variant: "outline",
|
|
2969
|
+
size: "sm",
|
|
2970
|
+
onClick: () => {
|
|
2971
|
+
g(null), w("");
|
|
2972
|
+
},
|
|
2973
|
+
children: "Cancel"
|
|
2974
|
+
}), /* @__PURE__ */ J(v, {
|
|
2975
|
+
variant: "destructive",
|
|
2976
|
+
size: "sm",
|
|
2977
|
+
onClick: () => h && void z(h, _),
|
|
2978
|
+
disabled: !h || T === h,
|
|
2979
|
+
"data-testid": "ai-inbox-reject-confirm",
|
|
2980
|
+
children: [/* @__PURE__ */ q(W, { className: "h-3.5 w-3.5 mr-1" }), "Reject"]
|
|
2981
|
+
})]
|
|
2982
|
+
})]
|
|
2983
|
+
})]
|
|
2984
|
+
})
|
|
2985
|
+
})
|
|
2986
|
+
] });
|
|
2987
|
+
}
|
|
2988
|
+
//#endregion
|
|
2989
|
+
//#region src/useHitlInChat.ts
|
|
2990
|
+
function $r(e) {
|
|
2991
|
+
return !e || e.length === 0 ? "/api/v1/ai" : e.endsWith("/") ? e.slice(0, -1) : e;
|
|
2992
|
+
}
|
|
2993
|
+
function ei(e, t) {
|
|
2994
|
+
let n = { ...e ?? {} };
|
|
2995
|
+
return t && (n["Content-Type"] = "application/json"), n;
|
|
2996
|
+
}
|
|
2997
|
+
async function ti(e) {
|
|
2998
|
+
let t = await e.text();
|
|
2999
|
+
if (!t) return null;
|
|
3000
|
+
try {
|
|
3001
|
+
return JSON.parse(t);
|
|
3002
|
+
} catch {
|
|
3003
|
+
return { raw: t };
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
function ni(t) {
|
|
3007
|
+
let { messages: n, apiBase: r, headers: i, onDecided: a, continueConversation: o } = t, s = $r(r), c = e.useMemo(() => {
|
|
3008
|
+
let e = /* @__PURE__ */ new Map();
|
|
3009
|
+
for (let t of n) {
|
|
3010
|
+
let n = t.toolInvocations ?? [];
|
|
3011
|
+
for (let t of n) t.pendingActionId && t.toolCallId && e.set(t.toolCallId, {
|
|
3012
|
+
pendingActionId: t.pendingActionId,
|
|
3013
|
+
toolName: t.toolName
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
return e;
|
|
3017
|
+
}, [n]), [l, u] = e.useState({}), d = e.useRef(0), [f, p] = e.useState(!1), m = e.useCallback((e, t) => {
|
|
3018
|
+
u((n) => {
|
|
3019
|
+
if (!t) {
|
|
3020
|
+
if (!(e in n)) return n;
|
|
3021
|
+
let { [e]: t, ...r } = n;
|
|
3022
|
+
return r;
|
|
3023
|
+
}
|
|
3024
|
+
return {
|
|
3025
|
+
...n,
|
|
3026
|
+
[e]: t
|
|
3027
|
+
};
|
|
3028
|
+
});
|
|
3029
|
+
}, []);
|
|
3030
|
+
return {
|
|
3031
|
+
decisions: l,
|
|
3032
|
+
decide: e.useCallback(async (e, t, n) => {
|
|
3033
|
+
let r = c.get(e);
|
|
3034
|
+
if (!r) {
|
|
3035
|
+
m(e, {
|
|
3036
|
+
state: "error",
|
|
3037
|
+
message: "No pending-action id found for this tool call. The tool result may not be a HITL proposal."
|
|
3038
|
+
});
|
|
3039
|
+
return;
|
|
3040
|
+
}
|
|
3041
|
+
let { pendingActionId: l, toolName: u } = r;
|
|
3042
|
+
m(e, {
|
|
3043
|
+
state: "pending",
|
|
3044
|
+
message: t ? "Approving…" : "Rejecting…"
|
|
3045
|
+
}), d.current += 1, p(!0);
|
|
3046
|
+
try {
|
|
3047
|
+
let r = `${s}/pending-actions/${encodeURIComponent(l)}/${t ? "approve" : "reject"}`, c = t ? "{}" : JSON.stringify({ reason: n ?? "" }), d = await fetch(r, {
|
|
3048
|
+
method: "POST",
|
|
3049
|
+
credentials: "include",
|
|
3050
|
+
headers: ei(i, !0),
|
|
3051
|
+
body: c
|
|
3052
|
+
}), f = await ti(d) ?? {};
|
|
3053
|
+
if (!d.ok) {
|
|
3054
|
+
let t = typeof f.error == "string" ? f.error : `Approval failed: HTTP ${d.status}`;
|
|
3055
|
+
m(e, {
|
|
3056
|
+
state: "error",
|
|
3057
|
+
message: t
|
|
3058
|
+
}), a?.(e, {
|
|
3059
|
+
id: l,
|
|
3060
|
+
status: "failed",
|
|
3061
|
+
error: t
|
|
3062
|
+
});
|
|
3063
|
+
return;
|
|
3064
|
+
}
|
|
3065
|
+
let p = f.status ?? (t ? "executed" : "rejected"), h = !1;
|
|
3066
|
+
if (p === "executed" ? (m(e, {
|
|
3067
|
+
state: "success",
|
|
3068
|
+
message: "Approved — action executed."
|
|
3069
|
+
}), h = !0) : p === "rejected" ? (m(e, {
|
|
3070
|
+
state: "success",
|
|
3071
|
+
message: n ? `Rejected: ${n}` : "Rejected."
|
|
3072
|
+
}), h = !0) : p === "failed" ? m(e, {
|
|
3073
|
+
state: "error",
|
|
3074
|
+
message: f.error ?? "Action approved but execution failed."
|
|
3075
|
+
}) : (m(e, {
|
|
3076
|
+
state: "success",
|
|
3077
|
+
message: `Status: ${p}`
|
|
3078
|
+
}), h = !0), a?.(e, f), h && o) {
|
|
3079
|
+
let r = ri({
|
|
3080
|
+
approved: t,
|
|
3081
|
+
status: p,
|
|
3082
|
+
toolName: u,
|
|
3083
|
+
pendingActionId: l,
|
|
3084
|
+
outcome: f,
|
|
3085
|
+
reason: n
|
|
3086
|
+
});
|
|
3087
|
+
r && o(r, {
|
|
3088
|
+
toolCallId: e,
|
|
3089
|
+
pendingActionId: l,
|
|
3090
|
+
decision: t ? "approved" : "rejected",
|
|
3091
|
+
outcome: f,
|
|
3092
|
+
toolName: u
|
|
3093
|
+
});
|
|
3094
|
+
}
|
|
3095
|
+
} catch (t) {
|
|
3096
|
+
m(e, {
|
|
3097
|
+
state: "error",
|
|
3098
|
+
message: t instanceof Error ? t.message : String(t)
|
|
3099
|
+
});
|
|
3100
|
+
} finally {
|
|
3101
|
+
--d.current, d.current <= 0 && (d.current = 0, p(!1));
|
|
3102
|
+
}
|
|
3103
|
+
}, [
|
|
3104
|
+
s,
|
|
3105
|
+
i,
|
|
3106
|
+
c,
|
|
3107
|
+
a,
|
|
3108
|
+
o,
|
|
3109
|
+
m
|
|
3110
|
+
]),
|
|
3111
|
+
isDeciding: f
|
|
3112
|
+
};
|
|
3113
|
+
}
|
|
3114
|
+
function ri(e) {
|
|
3115
|
+
let { approved: t, status: n, toolName: r, pendingActionId: i, outcome: a, reason: o } = e, s = `[HITL ${i}]`;
|
|
3116
|
+
if (t && n === "executed") {
|
|
3117
|
+
let e = a.result;
|
|
3118
|
+
return `${s} The operator approved the \`${r}\` call. It executed successfully with result: ${e == null ? "(no payload)" : typeof e == "string" ? e : ii(JSON.stringify(e), 800)}. Acknowledge the outcome concisely and continue the user's task.`;
|
|
3119
|
+
}
|
|
3120
|
+
if (!t && n === "rejected") return `${s} The operator rejected the \`${r}\` call.${o && o.trim().length > 0 ? ` Reason: ${o}.` : ""} Acknowledge the rejection and ask whether to try a different approach.`;
|
|
3121
|
+
if (n === "failed") {
|
|
3122
|
+
let e = a.error;
|
|
3123
|
+
return `${s} The \`${r}\` call was approved but execution failed: ${typeof e == "string" ? e : ii(JSON.stringify(e ?? {}), 400)}. Apologize concisely and offer alternatives.`;
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
function ii(e, t) {
|
|
3127
|
+
return e.length <= t ? e : `${e.slice(0, t - 1)}…`;
|
|
3128
|
+
}
|
|
3129
|
+
//#endregion
|
|
3130
|
+
//#region src/index.tsx
|
|
3131
|
+
var ai = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type your message...", onSendMessage: i, disabled: a = !1, showTimestamp: o = !1, userAvatarUrl: s, userAvatarFallback: c = "You", assistantAvatarUrl: l, assistantAvatarFallback: u = "AI", maxHeight: d = "500px", ...f }, p) => {
|
|
3132
|
+
let [m, h] = e.useState(""), g = e.useRef(null), _ = e.useRef(null);
|
|
2403
3133
|
e.useEffect(() => {
|
|
2404
|
-
if (
|
|
2405
|
-
let e =
|
|
3134
|
+
if (g.current) {
|
|
3135
|
+
let e = g.current.querySelector("[data-radix-scroll-area-viewport]");
|
|
2406
3136
|
e && (e.scrollTop = e.scrollHeight);
|
|
2407
3137
|
}
|
|
2408
3138
|
}, [n]);
|
|
2409
3139
|
let y = () => {
|
|
2410
|
-
m.trim() && i && (i(m.trim()), h(""),
|
|
3140
|
+
m.trim() && i && (i(m.trim()), h(""), _.current?.focus());
|
|
2411
3141
|
}, b = (e) => {
|
|
2412
3142
|
e.key === "Enter" && !e.shiftKey && (e.preventDefault(), y());
|
|
2413
3143
|
};
|
|
2414
|
-
return /* @__PURE__ */
|
|
3144
|
+
return /* @__PURE__ */ J("div", {
|
|
2415
3145
|
ref: p,
|
|
2416
|
-
className:
|
|
3146
|
+
className: U("flex flex-col border rounded-lg bg-background overflow-hidden", t),
|
|
2417
3147
|
style: { maxHeight: d },
|
|
2418
3148
|
...f,
|
|
2419
|
-
children: [/* @__PURE__ */
|
|
2420
|
-
ref:
|
|
3149
|
+
children: [/* @__PURE__ */ q(se, {
|
|
3150
|
+
ref: g,
|
|
2421
3151
|
className: "flex-1 p-4",
|
|
2422
|
-
children: /* @__PURE__ */
|
|
3152
|
+
children: /* @__PURE__ */ q("div", {
|
|
2423
3153
|
className: "space-y-4",
|
|
2424
|
-
children: n.length === 0 ? /* @__PURE__ */
|
|
3154
|
+
children: n.length === 0 ? /* @__PURE__ */ q("div", {
|
|
2425
3155
|
className: "flex items-center justify-center h-32 text-muted-foreground text-sm",
|
|
2426
3156
|
children: "No messages yet. Start a conversation!"
|
|
2427
|
-
}) : n.map((e) => /* @__PURE__ */
|
|
3157
|
+
}) : n.map((e) => /* @__PURE__ */ q(oi, {
|
|
2428
3158
|
message: e,
|
|
2429
3159
|
showTimestamp: o,
|
|
2430
3160
|
userAvatarUrl: s,
|
|
@@ -2433,83 +3163,83 @@ var rr = ({ size: e = 16 }) => /* @__PURE__ */ H("svg", {
|
|
|
2433
3163
|
assistantAvatarFallback: u
|
|
2434
3164
|
}, e.id))
|
|
2435
3165
|
})
|
|
2436
|
-
}), /* @__PURE__ */
|
|
3166
|
+
}), /* @__PURE__ */ q("div", {
|
|
2437
3167
|
className: "border-t p-4",
|
|
2438
|
-
children: /* @__PURE__ */
|
|
3168
|
+
children: /* @__PURE__ */ J("div", {
|
|
2439
3169
|
className: "flex gap-2",
|
|
2440
|
-
children: [/* @__PURE__ */
|
|
2441
|
-
ref:
|
|
3170
|
+
children: [/* @__PURE__ */ q(oe, {
|
|
3171
|
+
ref: _,
|
|
2442
3172
|
value: m,
|
|
2443
3173
|
onChange: (e) => h(e.target.value),
|
|
2444
3174
|
onKeyDown: b,
|
|
2445
3175
|
placeholder: r,
|
|
2446
3176
|
disabled: a,
|
|
2447
3177
|
className: "flex-1"
|
|
2448
|
-
}), /* @__PURE__ */
|
|
3178
|
+
}), /* @__PURE__ */ q(v, {
|
|
2449
3179
|
onClick: y,
|
|
2450
3180
|
disabled: a || !m.trim(),
|
|
2451
3181
|
size: "icon",
|
|
2452
|
-
children: /* @__PURE__ */
|
|
3182
|
+
children: /* @__PURE__ */ q(ct, { className: "h-4 w-4" })
|
|
2453
3183
|
})]
|
|
2454
3184
|
})
|
|
2455
3185
|
})]
|
|
2456
3186
|
});
|
|
2457
3187
|
});
|
|
2458
|
-
|
|
2459
|
-
var
|
|
3188
|
+
ai.displayName = "Chatbot";
|
|
3189
|
+
var oi = ({ message: e, showTimestamp: t, userAvatarUrl: n, userAvatarFallback: r, assistantAvatarUrl: i, assistantAvatarFallback: a }) => {
|
|
2460
3190
|
let o = e.role === "user";
|
|
2461
|
-
if (e.role === "system") return /* @__PURE__ */
|
|
3191
|
+
if (e.role === "system") return /* @__PURE__ */ q("div", {
|
|
2462
3192
|
className: "flex justify-center",
|
|
2463
|
-
children: /* @__PURE__ */
|
|
3193
|
+
children: /* @__PURE__ */ q("div", {
|
|
2464
3194
|
className: "text-xs text-muted-foreground bg-muted px-3 py-1 rounded-full",
|
|
2465
3195
|
children: e.content
|
|
2466
3196
|
})
|
|
2467
3197
|
});
|
|
2468
3198
|
let s = o ? e.avatar || n : e.avatar || i, c = o ? e.avatarFallback || r : e.avatarFallback || a;
|
|
2469
|
-
return /* @__PURE__ */
|
|
2470
|
-
className:
|
|
2471
|
-
children: [/* @__PURE__ */
|
|
3199
|
+
return /* @__PURE__ */ J("div", {
|
|
3200
|
+
className: U("flex gap-3", o ? "flex-row-reverse" : "flex-row"),
|
|
3201
|
+
children: [/* @__PURE__ */ J(m, {
|
|
2472
3202
|
className: "h-8 w-8",
|
|
2473
|
-
children: [/* @__PURE__ */
|
|
3203
|
+
children: [/* @__PURE__ */ q(g, { src: s }), /* @__PURE__ */ q(h, {
|
|
2474
3204
|
className: "text-xs",
|
|
2475
3205
|
children: c
|
|
2476
3206
|
})]
|
|
2477
|
-
}), /* @__PURE__ */
|
|
2478
|
-
className:
|
|
2479
|
-
children: [/* @__PURE__ */
|
|
2480
|
-
className:
|
|
2481
|
-
children: /* @__PURE__ */
|
|
3207
|
+
}), /* @__PURE__ */ J("div", {
|
|
3208
|
+
className: U("flex flex-col gap-1", o ? "items-end" : "items-start"),
|
|
3209
|
+
children: [/* @__PURE__ */ q("div", {
|
|
3210
|
+
className: U("rounded-lg px-4 py-2 max-w-[70%] break-words", o ? "bg-primary text-primary-foreground" : "bg-muted"),
|
|
3211
|
+
children: /* @__PURE__ */ q("p", {
|
|
2482
3212
|
className: "text-sm whitespace-pre-wrap",
|
|
2483
3213
|
children: e.content
|
|
2484
3214
|
})
|
|
2485
|
-
}), t && e.timestamp && /* @__PURE__ */
|
|
3215
|
+
}), t && e.timestamp && /* @__PURE__ */ q("span", {
|
|
2486
3216
|
className: "text-xs text-muted-foreground",
|
|
2487
3217
|
children: e.timestamp
|
|
2488
3218
|
})]
|
|
2489
3219
|
})]
|
|
2490
3220
|
});
|
|
2491
|
-
},
|
|
3221
|
+
}, si = e.forwardRef(({ className: e, avatarSrc: t, avatarFallback: n = "AI", ...r }, i) => /* @__PURE__ */ J("div", {
|
|
2492
3222
|
ref: i,
|
|
2493
|
-
className:
|
|
3223
|
+
className: U("flex gap-3", e),
|
|
2494
3224
|
...r,
|
|
2495
|
-
children: [/* @__PURE__ */
|
|
3225
|
+
children: [/* @__PURE__ */ J(m, {
|
|
2496
3226
|
className: "h-8 w-8",
|
|
2497
|
-
children: [/* @__PURE__ */
|
|
3227
|
+
children: [/* @__PURE__ */ q(g, { src: t }), /* @__PURE__ */ q(h, {
|
|
2498
3228
|
className: "text-xs",
|
|
2499
3229
|
children: n
|
|
2500
3230
|
})]
|
|
2501
|
-
}), /* @__PURE__ */
|
|
3231
|
+
}), /* @__PURE__ */ q("div", {
|
|
2502
3232
|
className: "flex items-center bg-muted rounded-lg px-4 py-2",
|
|
2503
|
-
children: /* @__PURE__ */
|
|
3233
|
+
children: /* @__PURE__ */ J("div", {
|
|
2504
3234
|
className: "flex gap-1",
|
|
2505
3235
|
children: [
|
|
2506
|
-
/* @__PURE__ */
|
|
2507
|
-
/* @__PURE__ */
|
|
2508
|
-
/* @__PURE__ */
|
|
3236
|
+
/* @__PURE__ */ q("span", { className: "w-2 h-2 bg-muted-foreground rounded-full animate-bounce [animation-delay:-0.3s]" }),
|
|
3237
|
+
/* @__PURE__ */ q("span", { className: "w-2 h-2 bg-muted-foreground rounded-full animate-bounce [animation-delay:-0.15s]" }),
|
|
3238
|
+
/* @__PURE__ */ q("span", { className: "w-2 h-2 bg-muted-foreground rounded-full animate-bounce" })
|
|
2509
3239
|
]
|
|
2510
3240
|
})
|
|
2511
3241
|
})]
|
|
2512
3242
|
}));
|
|
2513
|
-
|
|
3243
|
+
si.displayName = "TypingIndicator";
|
|
2514
3244
|
//#endregion
|
|
2515
|
-
export {
|
|
3245
|
+
export { Vr as AIElements, Qr as AiPendingActionsInbox, ai as Chatbot, $ as ChatbotEnhanced, Rr as FloatingChatbot, Gt as FloatingChatbotPanel, Vt as FloatingChatbotProvider, Wt as FloatingChatbotTrigger, si as TypingIndicator, Ft as uiMessageToChatMessage, It as uiMessagesToChatMessages, zt as useAgents, Ht as useFloatingChatbot, ni as useHitlInChat, Y as useObjectChat, Gr as usePendingActions };
|