@object-ui/plugin-chatbot 5.4.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +43 -0
- package/dist/index.js +1401 -616
- package/dist/index.umd.cjs +2 -2
- 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 +56 -0
- package/dist/packages/plugin-chatbot/src/ChatbotEnhanced.d.ts.map +1 -1
- package/dist/packages/plugin-chatbot/src/index.d.ts +9 -0
- package/dist/packages/plugin-chatbot/src/index.d.ts.map +1 -1
- package/dist/packages/plugin-chatbot/src/mapMessages.d.ts +45 -0
- package/dist/packages/plugin-chatbot/src/mapMessages.d.ts.map +1 -0
- 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/useObjectChat.d.ts.map +1 -1
- 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,38 +1,109 @@
|
|
|
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
|
+
//#region src/mapMessages.ts
|
|
35
|
+
function At(e, t) {
|
|
36
|
+
return typeof e.content == "string" ? e.content : t.filter((e) => e.type === "text").map((e) => e.text ?? "").join("");
|
|
37
|
+
}
|
|
38
|
+
function jt(e) {
|
|
39
|
+
let t = e.filter((e) => e.type === "reasoning" || e.type === "reasoning-delta").map((e) => e.text ?? "").join("\n").trim();
|
|
40
|
+
return t.length > 0 ? t : void 0;
|
|
41
|
+
}
|
|
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) {
|
|
66
|
+
return e.filter((e) => e.type === "dynamic-tool" ? !0 : typeof e.type == "string" && e.type.startsWith("tool-")).map((e) => {
|
|
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;
|
|
68
|
+
return {
|
|
69
|
+
toolCallId: e.toolCallId ?? e.id ?? `${e.type ?? "tool"}-${Math.random().toString(36).slice(2, 8)}`,
|
|
70
|
+
toolName: t,
|
|
71
|
+
args: e.input ?? e.args,
|
|
72
|
+
result: n,
|
|
73
|
+
errorText: e.errorText,
|
|
74
|
+
state: a,
|
|
75
|
+
pendingActionId: r?.pendingActionId
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function Pt(e) {
|
|
80
|
+
let t = e.filter((e) => e.type === "source-url" || e.type === "source").map((e) => ({
|
|
81
|
+
id: e.id,
|
|
82
|
+
title: e.title,
|
|
83
|
+
url: e.url ?? e.href
|
|
84
|
+
})).filter((e) => !!e.url);
|
|
85
|
+
return t.length > 0 ? t : void 0;
|
|
86
|
+
}
|
|
87
|
+
function Ft(e, t = {}) {
|
|
88
|
+
let n = Array.isArray(e.parts) ? e.parts : [], r = Nt(n), i = Array.isArray(e.toolInvocations) ? e.toolInvocations : [];
|
|
89
|
+
return {
|
|
90
|
+
id: e.id ?? `msg-${Math.random().toString(36).slice(2, 8)}`,
|
|
91
|
+
role: e.role ?? "assistant",
|
|
92
|
+
content: At(e, n),
|
|
93
|
+
reasoning: jt(n),
|
|
94
|
+
toolInvocations: r.length > 0 ? r : i,
|
|
95
|
+
sources: Pt(n),
|
|
96
|
+
streaming: t.streaming
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function It(e, t = {}) {
|
|
100
|
+
if (!Array.isArray(e) || e.length === 0) return [];
|
|
101
|
+
let n = e.length - 1;
|
|
102
|
+
return e.map((e, r) => Ft(e, { streaming: !!t.isStreaming && r === n && e.role === "assistant" }));
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
34
105
|
//#region src/useObjectChat.ts
|
|
35
|
-
function
|
|
106
|
+
function Lt(e) {
|
|
36
107
|
return (e ?? []).map((e, t) => ({
|
|
37
108
|
id: e.id || `msg-${t}`,
|
|
38
109
|
role: e.role || "user",
|
|
@@ -43,17 +114,17 @@ function $e(e) {
|
|
|
43
114
|
toolInvocations: e.toolInvocations
|
|
44
115
|
}));
|
|
45
116
|
}
|
|
46
|
-
function
|
|
47
|
-
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) => ({
|
|
48
119
|
id: e.id,
|
|
49
120
|
role: e.role,
|
|
50
121
|
parts: [{
|
|
51
122
|
type: "text",
|
|
52
123
|
text: e.content ?? ""
|
|
53
124
|
}]
|
|
54
|
-
})), []), C =
|
|
125
|
+
})), []), C = pt({
|
|
55
126
|
transport: l(() => {
|
|
56
|
-
if (x) return new
|
|
127
|
+
if (x) return new mt({
|
|
57
128
|
api: t,
|
|
58
129
|
headers: { ...f },
|
|
59
130
|
body: {
|
|
@@ -78,34 +149,14 @@ function G(e = {}) {
|
|
|
78
149
|
onError: x ? (e) => {
|
|
79
150
|
h?.(e);
|
|
80
151
|
} : void 0
|
|
81
|
-
}), [w, T] = d(() =>
|
|
152
|
+
}), [w, T] = d(() => Lt(n)), [E, D] = d(!1), [O, k] = d(""), [A, j] = d(""), M = u(null);
|
|
82
153
|
if (c(() => () => {
|
|
83
154
|
M.current &&= (clearTimeout(M.current), null);
|
|
84
155
|
}, []), x) {
|
|
85
|
-
let { messages: e, status: t, error: n, sendMessage: r, regenerate: i, stop: a, setMessages: s } = C, c = t === "submitted" || t === "streaming", l = e.map((t) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
args: e.input ?? e.args,
|
|
90
|
-
result: e.output ?? e.result,
|
|
91
|
-
errorText: e.errorText,
|
|
92
|
-
state: e.state
|
|
93
|
-
})), o = n.filter((e) => e?.type === "source-url" || e?.type === "source").map((e) => ({
|
|
94
|
-
id: e.id,
|
|
95
|
-
title: e.title,
|
|
96
|
-
url: e.url ?? e.href
|
|
97
|
-
})).filter((e) => !!e.url), s = Array.isArray(t.toolInvocations) ? t.toolInvocations : [];
|
|
98
|
-
return {
|
|
99
|
-
id: t.id,
|
|
100
|
-
role: t.role,
|
|
101
|
-
content: r,
|
|
102
|
-
toolInvocations: a.length > 0 ? a : s,
|
|
103
|
-
reasoning: i,
|
|
104
|
-
sources: o.length > 0 ? o : void 0,
|
|
105
|
-
metadata: t.metadata,
|
|
106
|
-
streaming: c && t.id === e[e.length - 1]?.id && t.role === "assistant"
|
|
107
|
-
};
|
|
108
|
-
});
|
|
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) => ({
|
|
157
|
+
...t,
|
|
158
|
+
metadata: e[n]?.metadata
|
|
159
|
+
}));
|
|
109
160
|
return {
|
|
110
161
|
messages: l,
|
|
111
162
|
isLoading: c,
|
|
@@ -114,7 +165,7 @@ function G(e = {}) {
|
|
|
114
165
|
let t = e.trim();
|
|
115
166
|
if (!t) return;
|
|
116
167
|
let n = [...l, {
|
|
117
|
-
id:
|
|
168
|
+
id: kt("msg"),
|
|
118
169
|
role: "user",
|
|
119
170
|
content: t
|
|
120
171
|
}];
|
|
@@ -147,7 +198,7 @@ function G(e = {}) {
|
|
|
147
198
|
sendMessage: o((e) => {
|
|
148
199
|
if (!e.trim()) return;
|
|
149
200
|
let t = {
|
|
150
|
-
id:
|
|
201
|
+
id: kt("msg"),
|
|
151
202
|
role: "user",
|
|
152
203
|
content: e.trim(),
|
|
153
204
|
timestamp: g ? (/* @__PURE__ */ new Date()).toLocaleTimeString() : void 0
|
|
@@ -157,7 +208,7 @@ function G(e = {}) {
|
|
|
157
208
|
return b?.(e.trim(), r), r;
|
|
158
209
|
}), k(""), _ && (D(!0), M.current = setTimeout(() => {
|
|
159
210
|
let e = {
|
|
160
|
-
id:
|
|
211
|
+
id: kt("msg"),
|
|
161
212
|
role: "assistant",
|
|
162
213
|
content: v || "Thank you for your message!",
|
|
163
214
|
timestamp: g ? (/* @__PURE__ */ new Date()).toLocaleTimeString() : void 0
|
|
@@ -186,7 +237,7 @@ function G(e = {}) {
|
|
|
186
237
|
}
|
|
187
238
|
//#endregion
|
|
188
239
|
//#region src/useAgents.ts
|
|
189
|
-
function
|
|
240
|
+
function Rt(e) {
|
|
190
241
|
return e.filter((e) => typeof e?.name == "string" && e.name.length > 0).map((e) => ({
|
|
191
242
|
name: e.name,
|
|
192
243
|
label: e.label || e.name,
|
|
@@ -195,7 +246,7 @@ function et(e) {
|
|
|
195
246
|
active: e.active !== !1
|
|
196
247
|
}));
|
|
197
248
|
}
|
|
198
|
-
function
|
|
249
|
+
function zt(e = {}) {
|
|
199
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);
|
|
200
251
|
return _.current = n, c(() => {
|
|
201
252
|
if (!r || !t) return;
|
|
@@ -215,7 +266,7 @@ function tt(e = {}) {
|
|
|
215
266
|
return e.json();
|
|
216
267
|
}).then((e) => {
|
|
217
268
|
if (n) return;
|
|
218
|
-
let t =
|
|
269
|
+
let t = Rt(Array.isArray(e) ? e : e?.agents ?? []);
|
|
219
270
|
s(t.length > 0 ? t : i);
|
|
220
271
|
}).catch((e) => {
|
|
221
272
|
n || e.name === "AbortError" || (m(e), s(i));
|
|
@@ -237,8 +288,8 @@ function tt(e = {}) {
|
|
|
237
288
|
}
|
|
238
289
|
//#endregion
|
|
239
290
|
//#region src/FloatingChatbotProvider.tsx
|
|
240
|
-
var
|
|
241
|
-
function
|
|
291
|
+
var Bt = e.createContext(null);
|
|
292
|
+
function Vt({ defaultOpen: t = !1, children: n }) {
|
|
242
293
|
let [r, i] = e.useState(t), [a, o] = e.useState(!1), s = e.useMemo(() => ({
|
|
243
294
|
isOpen: r,
|
|
244
295
|
isFullscreen: a,
|
|
@@ -249,21 +300,21 @@ function rt({ defaultOpen: t = !1, children: n }) {
|
|
|
249
300
|
toggle: () => i((e) => !e),
|
|
250
301
|
toggleFullscreen: () => o((e) => !e)
|
|
251
302
|
}), [r, a]);
|
|
252
|
-
return /* @__PURE__ */
|
|
303
|
+
return /* @__PURE__ */ q(Bt.Provider, {
|
|
253
304
|
value: s,
|
|
254
305
|
children: n
|
|
255
306
|
});
|
|
256
307
|
}
|
|
257
|
-
function
|
|
258
|
-
let t = e.useContext(
|
|
308
|
+
function Ht() {
|
|
309
|
+
let t = e.useContext(Bt);
|
|
259
310
|
if (!t) throw Error("useFloatingChatbot must be used within a <FloatingChatbotProvider>");
|
|
260
311
|
return t;
|
|
261
312
|
}
|
|
262
313
|
//#endregion
|
|
263
314
|
//#region src/FloatingChatbotTrigger.tsx
|
|
264
|
-
function
|
|
315
|
+
function Ut() {
|
|
265
316
|
try {
|
|
266
|
-
let { t: e } =
|
|
317
|
+
let { t: e } = gt();
|
|
267
318
|
return (t, n) => {
|
|
268
319
|
let r = e(`common.${t}`);
|
|
269
320
|
return !r || r === `common.${t}` ? n : r;
|
|
@@ -272,11 +323,11 @@ function it() {
|
|
|
272
323
|
return (e, t) => t;
|
|
273
324
|
}
|
|
274
325
|
}
|
|
275
|
-
function
|
|
276
|
-
let { isOpen: r, toggle: i } =
|
|
277
|
-
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, {
|
|
278
329
|
onClick: i,
|
|
279
|
-
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),
|
|
280
331
|
style: {
|
|
281
332
|
width: t,
|
|
282
333
|
height: t
|
|
@@ -284,13 +335,13 @@ function at({ position: e = "bottom-right", size: t = 56, className: n }) {
|
|
|
284
335
|
size: "icon",
|
|
285
336
|
"aria-label": r ? a("closeChat", "Close chat") : a("openChat", "Open chat"),
|
|
286
337
|
"data-testid": "floating-chatbot-trigger",
|
|
287
|
-
children:
|
|
338
|
+
children: q(r ? dt : nt, { className: "h-6 w-6" })
|
|
288
339
|
});
|
|
289
340
|
}
|
|
290
341
|
//#endregion
|
|
291
342
|
//#region src/FloatingChatbotPanel.tsx
|
|
292
|
-
function
|
|
293
|
-
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();
|
|
294
345
|
if (!s) return null;
|
|
295
346
|
let d = c ? {
|
|
296
347
|
inset: 0,
|
|
@@ -301,46 +352,46 @@ function ot({ title: e = "Chat", position: t = "bottom-right", width: n = 400, h
|
|
|
301
352
|
height: r,
|
|
302
353
|
maxHeight: "calc(100vh - 100px)"
|
|
303
354
|
};
|
|
304
|
-
return /* @__PURE__ */
|
|
305
|
-
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),
|
|
306
357
|
style: d,
|
|
307
358
|
role: "dialog",
|
|
308
359
|
"aria-label": e,
|
|
309
360
|
"data-testid": "floating-chatbot-panel",
|
|
310
|
-
children: [/* @__PURE__ */
|
|
361
|
+
children: [/* @__PURE__ */ J("div", {
|
|
311
362
|
className: "flex items-center justify-between gap-2 px-4 py-2 border-b bg-muted/40",
|
|
312
363
|
children: [
|
|
313
|
-
/* @__PURE__ */
|
|
364
|
+
/* @__PURE__ */ q("span", {
|
|
314
365
|
className: "text-sm font-medium truncate shrink-0",
|
|
315
366
|
children: e
|
|
316
367
|
}),
|
|
317
|
-
o ? /* @__PURE__ */
|
|
368
|
+
o ? /* @__PURE__ */ q("div", {
|
|
318
369
|
className: "flex-1 min-w-0 flex items-center justify-end mr-1",
|
|
319
370
|
"data-testid": "floating-chatbot-header-extra",
|
|
320
371
|
children: o
|
|
321
372
|
}) : null,
|
|
322
|
-
/* @__PURE__ */
|
|
373
|
+
/* @__PURE__ */ J("div", {
|
|
323
374
|
className: "flex items-center gap-1 shrink-0",
|
|
324
|
-
children: [/* @__PURE__ */
|
|
375
|
+
children: [/* @__PURE__ */ q(v, {
|
|
325
376
|
variant: "ghost",
|
|
326
377
|
size: "icon",
|
|
327
378
|
className: "h-7 w-7",
|
|
328
379
|
onClick: u,
|
|
329
380
|
"aria-label": c ? "Exit fullscreen" : "Fullscreen",
|
|
330
381
|
"data-testid": "floating-chatbot-fullscreen",
|
|
331
|
-
children:
|
|
332
|
-
}), /* @__PURE__ */
|
|
382
|
+
children: q(c ? it : tt, { className: "h-4 w-4" })
|
|
383
|
+
}), /* @__PURE__ */ q(v, {
|
|
333
384
|
variant: "ghost",
|
|
334
385
|
size: "icon",
|
|
335
386
|
className: "h-7 w-7",
|
|
336
387
|
onClick: l,
|
|
337
388
|
"aria-label": "Close chat",
|
|
338
389
|
"data-testid": "floating-chatbot-close",
|
|
339
|
-
children: /* @__PURE__ */
|
|
390
|
+
children: /* @__PURE__ */ q(dt, { className: "h-4 w-4" })
|
|
340
391
|
})]
|
|
341
392
|
})
|
|
342
393
|
]
|
|
343
|
-
}), /* @__PURE__ */
|
|
394
|
+
}), /* @__PURE__ */ q("div", {
|
|
344
395
|
className: "flex-1 overflow-hidden",
|
|
345
396
|
children: i
|
|
346
397
|
})]
|
|
@@ -348,99 +399,99 @@ function ot({ title: e = "Chat", position: t = "bottom-right", width: n = 400, h
|
|
|
348
399
|
}
|
|
349
400
|
//#endregion
|
|
350
401
|
//#region src/elements/conversation.tsx
|
|
351
|
-
var
|
|
352
|
-
className:
|
|
402
|
+
var Kt = ({ className: e, ...t }) => /* @__PURE__ */ q(_t, {
|
|
403
|
+
className: U("relative flex-1 overflow-y-hidden", e),
|
|
353
404
|
initial: "smooth",
|
|
354
405
|
resize: "smooth",
|
|
355
406
|
role: "log",
|
|
356
407
|
...t
|
|
357
|
-
}),
|
|
358
|
-
className:
|
|
408
|
+
}), qt = ({ className: e, ...t }) => /* @__PURE__ */ q(_t.Content, {
|
|
409
|
+
className: U("flex flex-col gap-8 p-4", e),
|
|
359
410
|
...t
|
|
360
|
-
}),
|
|
361
|
-
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),
|
|
362
413
|
...a,
|
|
363
|
-
children: i ?? /* @__PURE__ */
|
|
414
|
+
children: i ?? /* @__PURE__ */ J(K, { children: [r && /* @__PURE__ */ q("div", {
|
|
364
415
|
className: "text-muted-foreground",
|
|
365
416
|
children: r
|
|
366
|
-
}), /* @__PURE__ */
|
|
417
|
+
}), /* @__PURE__ */ J("div", {
|
|
367
418
|
className: "space-y-1",
|
|
368
|
-
children: [/* @__PURE__ */
|
|
419
|
+
children: [/* @__PURE__ */ q("h3", {
|
|
369
420
|
className: "font-medium text-sm",
|
|
370
421
|
children: t
|
|
371
|
-
}), n && /* @__PURE__ */
|
|
422
|
+
}), n && /* @__PURE__ */ q("p", {
|
|
372
423
|
className: "text-muted-foreground text-sm",
|
|
373
424
|
children: n
|
|
374
425
|
})]
|
|
375
426
|
})] })
|
|
376
|
-
}),
|
|
377
|
-
let { isAtBottom: n, scrollToBottom: r } =
|
|
427
|
+
}), Yt = ({ className: e, ...t }) => {
|
|
428
|
+
let { isAtBottom: n, scrollToBottom: r } = vt(), i = o(() => {
|
|
378
429
|
r();
|
|
379
430
|
}, [r]);
|
|
380
|
-
return !n && /* @__PURE__ */
|
|
381
|
-
className:
|
|
431
|
+
return !n && /* @__PURE__ */ q(v, {
|
|
432
|
+
className: U("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full", e),
|
|
382
433
|
onClick: i,
|
|
383
434
|
size: "icon",
|
|
384
435
|
type: "button",
|
|
385
436
|
variant: "outline",
|
|
386
437
|
...t,
|
|
387
|
-
children: /* @__PURE__ */
|
|
438
|
+
children: /* @__PURE__ */ q(Pe, { className: "size-4" })
|
|
388
439
|
});
|
|
389
|
-
},
|
|
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", {
|
|
390
441
|
variants: { orientation: {
|
|
391
442
|
horizontal: "[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
|
|
392
443
|
vertical: "flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"
|
|
393
444
|
} },
|
|
394
445
|
defaultVariants: { orientation: "horizontal" }
|
|
395
446
|
});
|
|
396
|
-
function
|
|
397
|
-
return /* @__PURE__ */
|
|
447
|
+
function Zt({ className: e, orientation: t, ...n }) {
|
|
448
|
+
return /* @__PURE__ */ q("div", {
|
|
398
449
|
role: "group",
|
|
399
450
|
"data-slot": "button-group",
|
|
400
451
|
"data-orientation": t,
|
|
401
|
-
className:
|
|
452
|
+
className: U(Xt({ orientation: t }), e),
|
|
402
453
|
...n
|
|
403
454
|
});
|
|
404
455
|
}
|
|
405
|
-
function
|
|
406
|
-
return /* @__PURE__ */
|
|
407
|
-
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),
|
|
408
459
|
...n
|
|
409
460
|
});
|
|
410
461
|
}
|
|
411
462
|
//#endregion
|
|
412
463
|
//#region src/elements/message.tsx
|
|
413
|
-
var
|
|
414
|
-
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),
|
|
415
466
|
...n
|
|
416
|
-
}),
|
|
417
|
-
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),
|
|
418
469
|
...n,
|
|
419
470
|
children: e
|
|
420
|
-
}),
|
|
421
|
-
className:
|
|
471
|
+
}), tn = ({ className: e, children: t, ...n }) => /* @__PURE__ */ q("div", {
|
|
472
|
+
className: U("flex items-center gap-1", e),
|
|
422
473
|
...n,
|
|
423
474
|
children: t
|
|
424
|
-
}),
|
|
425
|
-
let o = /* @__PURE__ */
|
|
475
|
+
}), nn = ({ tooltip: e, children: t, label: n, variant: r = "ghost", size: i = "icon", ...a }) => {
|
|
476
|
+
let o = /* @__PURE__ */ J(v, {
|
|
426
477
|
size: i,
|
|
427
478
|
type: "button",
|
|
428
479
|
variant: r,
|
|
429
480
|
...a,
|
|
430
|
-
children: [t, /* @__PURE__ */
|
|
481
|
+
children: [t, /* @__PURE__ */ q("span", {
|
|
431
482
|
className: "sr-only",
|
|
432
483
|
children: n || e
|
|
433
484
|
})]
|
|
434
485
|
});
|
|
435
|
-
return e ? /* @__PURE__ */
|
|
486
|
+
return e ? /* @__PURE__ */ q(je, { children: /* @__PURE__ */ J(ke, { children: [/* @__PURE__ */ q(Me, {
|
|
436
487
|
asChild: !0,
|
|
437
488
|
children: o
|
|
438
|
-
}), /* @__PURE__ */
|
|
439
|
-
},
|
|
440
|
-
let e = s(
|
|
489
|
+
}), /* @__PURE__ */ q(Ae, { children: /* @__PURE__ */ q("p", { children: e }) })] }) }) : o;
|
|
490
|
+
}, rn = r(null), X = () => {
|
|
491
|
+
let e = s(rn);
|
|
441
492
|
if (!e) throw Error("MessageBranch components must be used within MessageBranch");
|
|
442
493
|
return e;
|
|
443
|
-
},
|
|
494
|
+
}, an = ({ defaultBranch: e = 0, onBranchChange: t, className: n, ...r }) => {
|
|
444
495
|
let [i, a] = d(e), [o, s] = d([]), c = (e) => {
|
|
445
496
|
a(e), t?.(e);
|
|
446
497
|
}, l = {
|
|
@@ -455,36 +506,36 @@ var mt = ({ className: e, from: t, ...n }) => /* @__PURE__ */ B("div", {
|
|
|
455
506
|
branches: o,
|
|
456
507
|
setBranches: s
|
|
457
508
|
};
|
|
458
|
-
return /* @__PURE__ */
|
|
509
|
+
return /* @__PURE__ */ q(rn.Provider, {
|
|
459
510
|
value: l,
|
|
460
|
-
children: /* @__PURE__ */
|
|
461
|
-
className:
|
|
511
|
+
children: /* @__PURE__ */ q("div", {
|
|
512
|
+
className: U("grid w-full gap-2 [&>div]:pb-0", n),
|
|
462
513
|
...r
|
|
463
514
|
})
|
|
464
515
|
});
|
|
465
|
-
},
|
|
466
|
-
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];
|
|
467
518
|
return c(() => {
|
|
468
519
|
i.length !== a.length && r(a);
|
|
469
520
|
}, [
|
|
470
521
|
a,
|
|
471
522
|
i,
|
|
472
523
|
r
|
|
473
|
-
]), a.map((e, r) => /* @__PURE__ */
|
|
474
|
-
className:
|
|
524
|
+
]), a.map((e, r) => /* @__PURE__ */ q("div", {
|
|
525
|
+
className: U("grid gap-2 overflow-hidden [&>div]:pb-0", r === n ? "block" : "hidden"),
|
|
475
526
|
...t,
|
|
476
527
|
children: e
|
|
477
528
|
}, e.key));
|
|
478
|
-
},
|
|
479
|
-
let { totalBranches: r } =
|
|
480
|
-
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, {
|
|
481
532
|
className: "[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md",
|
|
482
533
|
orientation: "horizontal",
|
|
483
534
|
...n
|
|
484
535
|
});
|
|
485
|
-
},
|
|
486
|
-
let { goToPrevious: n, totalBranches: r } =
|
|
487
|
-
return /* @__PURE__ */
|
|
536
|
+
}, cn = ({ children: e, ...t }) => {
|
|
537
|
+
let { goToPrevious: n, totalBranches: r } = X();
|
|
538
|
+
return /* @__PURE__ */ q(v, {
|
|
488
539
|
"aria-label": "Previous branch",
|
|
489
540
|
disabled: r <= 1,
|
|
490
541
|
onClick: n,
|
|
@@ -492,11 +543,11 @@ var mt = ({ className: e, from: t, ...n }) => /* @__PURE__ */ B("div", {
|
|
|
492
543
|
type: "button",
|
|
493
544
|
variant: "ghost",
|
|
494
545
|
...t,
|
|
495
|
-
children: e ?? /* @__PURE__ */
|
|
546
|
+
children: e ?? /* @__PURE__ */ q(Ue, { size: 14 })
|
|
496
547
|
});
|
|
497
|
-
},
|
|
498
|
-
let { goToNext: r, totalBranches: i } =
|
|
499
|
-
return /* @__PURE__ */
|
|
548
|
+
}, ln = ({ children: e, className: t, ...n }) => {
|
|
549
|
+
let { goToNext: r, totalBranches: i } = X();
|
|
550
|
+
return /* @__PURE__ */ q(v, {
|
|
500
551
|
"aria-label": "Next branch",
|
|
501
552
|
disabled: i <= 1,
|
|
502
553
|
onClick: r,
|
|
@@ -504,12 +555,12 @@ var mt = ({ className: e, from: t, ...n }) => /* @__PURE__ */ B("div", {
|
|
|
504
555
|
type: "button",
|
|
505
556
|
variant: "ghost",
|
|
506
557
|
...n,
|
|
507
|
-
children: e ?? /* @__PURE__ */
|
|
558
|
+
children: e ?? /* @__PURE__ */ q(We, { size: 14 })
|
|
508
559
|
});
|
|
509
|
-
},
|
|
510
|
-
let { currentBranch: n, totalBranches: r } =
|
|
511
|
-
return /* @__PURE__ */
|
|
512
|
-
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),
|
|
513
564
|
...t,
|
|
514
565
|
children: [
|
|
515
566
|
n + 1,
|
|
@@ -517,23 +568,23 @@ var mt = ({ className: e, from: t, ...n }) => /* @__PURE__ */ B("div", {
|
|
|
517
568
|
r
|
|
518
569
|
]
|
|
519
570
|
});
|
|
520
|
-
},
|
|
521
|
-
className:
|
|
571
|
+
}, dn = a(({ className: e, ...t }) => /* @__PURE__ */ q(xt, {
|
|
572
|
+
className: U("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", e),
|
|
522
573
|
...t
|
|
523
574
|
}), (e, t) => e.children === t.children);
|
|
524
|
-
|
|
525
|
-
function
|
|
575
|
+
dn.displayName = "MessageResponse";
|
|
576
|
+
function fn({ data: e, className: t, onRemove: n, ...r }) {
|
|
526
577
|
let i = e.filename || "", a = (e.mediaType?.startsWith("image/") && e.url ? "image" : "file") == "image", o = i || (a ? "Image" : "Attachment");
|
|
527
|
-
return /* @__PURE__ */
|
|
528
|
-
className:
|
|
578
|
+
return /* @__PURE__ */ q("div", {
|
|
579
|
+
className: U("group relative size-24 overflow-hidden rounded-lg", t),
|
|
529
580
|
...r,
|
|
530
|
-
children: a ? /* @__PURE__ */
|
|
581
|
+
children: a ? /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ q("img", {
|
|
531
582
|
alt: i || "attachment",
|
|
532
583
|
className: "size-full object-cover",
|
|
533
584
|
height: 100,
|
|
534
585
|
src: e.url,
|
|
535
586
|
width: 100
|
|
536
|
-
}), n && /* @__PURE__ */
|
|
587
|
+
}), n && /* @__PURE__ */ J(v, {
|
|
537
588
|
"aria-label": "Remove attachment",
|
|
538
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",
|
|
539
590
|
onClick: (e) => {
|
|
@@ -541,17 +592,17 @@ function Tt({ data: e, className: t, onRemove: n, ...r }) {
|
|
|
541
592
|
},
|
|
542
593
|
type: "button",
|
|
543
594
|
variant: "ghost",
|
|
544
|
-
children: [/* @__PURE__ */
|
|
595
|
+
children: [/* @__PURE__ */ q(G, {}), /* @__PURE__ */ q("span", {
|
|
545
596
|
className: "sr-only",
|
|
546
597
|
children: "Remove"
|
|
547
598
|
})]
|
|
548
|
-
})] }) : /* @__PURE__ */
|
|
599
|
+
})] }) : /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ J(ke, { children: [/* @__PURE__ */ q(Me, {
|
|
549
600
|
asChild: !0,
|
|
550
|
-
children: /* @__PURE__ */
|
|
601
|
+
children: /* @__PURE__ */ q("div", {
|
|
551
602
|
className: "flex size-full shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",
|
|
552
|
-
children: /* @__PURE__ */
|
|
603
|
+
children: /* @__PURE__ */ q(at, { className: "size-4" })
|
|
553
604
|
})
|
|
554
|
-
}), /* @__PURE__ */
|
|
605
|
+
}), /* @__PURE__ */ q(Ae, { children: /* @__PURE__ */ q("p", { children: o }) })] }), n && /* @__PURE__ */ J(v, {
|
|
555
606
|
"aria-label": "Remove attachment",
|
|
556
607
|
className: "size-6 shrink-0 rounded-full p-0 opacity-0 transition-opacity hover:bg-accent group-hover:opacity-100 [&>svg]:size-3",
|
|
557
608
|
onClick: (e) => {
|
|
@@ -559,36 +610,36 @@ function Tt({ data: e, className: t, onRemove: n, ...r }) {
|
|
|
559
610
|
},
|
|
560
611
|
type: "button",
|
|
561
612
|
variant: "ghost",
|
|
562
|
-
children: [/* @__PURE__ */
|
|
613
|
+
children: [/* @__PURE__ */ q(G, {}), /* @__PURE__ */ q("span", {
|
|
563
614
|
className: "sr-only",
|
|
564
615
|
children: "Remove"
|
|
565
616
|
})]
|
|
566
617
|
})] })
|
|
567
618
|
});
|
|
568
619
|
}
|
|
569
|
-
function
|
|
570
|
-
return e ? /* @__PURE__ */
|
|
571
|
-
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),
|
|
572
623
|
...n,
|
|
573
624
|
children: e
|
|
574
625
|
}) : null;
|
|
575
626
|
}
|
|
576
|
-
var
|
|
577
|
-
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),
|
|
578
629
|
...n,
|
|
579
630
|
children: t
|
|
580
631
|
});
|
|
581
632
|
//#endregion
|
|
582
633
|
//#region src/elements/ui/input-group.tsx
|
|
583
|
-
function
|
|
584
|
-
return /* @__PURE__ */
|
|
634
|
+
function hn({ className: e, ...t }) {
|
|
635
|
+
return /* @__PURE__ */ q("div", {
|
|
585
636
|
"data-slot": "input-group",
|
|
586
637
|
role: "group",
|
|
587
|
-
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),
|
|
588
639
|
...t
|
|
589
640
|
});
|
|
590
641
|
}
|
|
591
|
-
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", {
|
|
592
643
|
variants: { align: {
|
|
593
644
|
"inline-start": "order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]",
|
|
594
645
|
"inline-end": "order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]",
|
|
@@ -597,19 +648,19 @@ var kt = H("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 tex
|
|
|
597
648
|
} },
|
|
598
649
|
defaultVariants: { align: "inline-start" }
|
|
599
650
|
});
|
|
600
|
-
function
|
|
601
|
-
return /* @__PURE__ */
|
|
651
|
+
function _n({ className: e, align: t = "inline-start", ...n }) {
|
|
652
|
+
return /* @__PURE__ */ q("div", {
|
|
602
653
|
role: "group",
|
|
603
654
|
"data-slot": "input-group-addon",
|
|
604
655
|
"data-align": t,
|
|
605
|
-
className:
|
|
656
|
+
className: U(gn({ align: t }), e),
|
|
606
657
|
onClick: (e) => {
|
|
607
658
|
e.target.closest("button") || e.currentTarget.parentElement?.querySelector("input")?.focus();
|
|
608
659
|
},
|
|
609
660
|
...n
|
|
610
661
|
});
|
|
611
662
|
}
|
|
612
|
-
var
|
|
663
|
+
var vn = yt("flex items-center gap-2 text-sm shadow-none", {
|
|
613
664
|
variants: { size: {
|
|
614
665
|
xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",
|
|
615
666
|
sm: "h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5",
|
|
@@ -618,38 +669,38 @@ var jt = H("flex items-center gap-2 text-sm shadow-none", {
|
|
|
618
669
|
} },
|
|
619
670
|
defaultVariants: { size: "xs" }
|
|
620
671
|
});
|
|
621
|
-
function
|
|
622
|
-
return /* @__PURE__ */
|
|
672
|
+
function yn({ className: e, type: t = "button", variant: n = "ghost", size: r = "xs", ...i }) {
|
|
673
|
+
return /* @__PURE__ */ q(v, {
|
|
623
674
|
type: t,
|
|
624
675
|
"data-size": r,
|
|
625
676
|
variant: n,
|
|
626
|
-
className:
|
|
677
|
+
className: U(vn({ size: r }), e),
|
|
627
678
|
...i
|
|
628
679
|
});
|
|
629
680
|
}
|
|
630
|
-
function
|
|
631
|
-
return /* @__PURE__ */
|
|
681
|
+
function bn({ className: e, ...t }) {
|
|
682
|
+
return /* @__PURE__ */ q(Oe, {
|
|
632
683
|
"data-slot": "input-group-control",
|
|
633
|
-
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),
|
|
634
685
|
...t
|
|
635
686
|
});
|
|
636
687
|
}
|
|
637
688
|
//#endregion
|
|
638
689
|
//#region src/elements/prompt-input.tsx
|
|
639
|
-
var
|
|
640
|
-
let e = s(
|
|
690
|
+
var xn = r(null), Sn = r(null), Cn = () => {
|
|
691
|
+
let e = s(xn);
|
|
641
692
|
if (!e) throw Error("Wrap your component inside <PromptInputProvider> to use usePromptInputController().");
|
|
642
693
|
return e;
|
|
643
|
-
},
|
|
644
|
-
let e = s(
|
|
694
|
+
}, wn = () => s(xn), Tn = () => {
|
|
695
|
+
let e = s(Sn);
|
|
645
696
|
if (!e) throw Error("Wrap your component inside <PromptInputProvider> to use useProviderAttachments().");
|
|
646
697
|
return e;
|
|
647
|
-
},
|
|
648
|
-
function
|
|
698
|
+
}, En = () => s(Sn);
|
|
699
|
+
function Dn({ initialInput: e = "", children: t }) {
|
|
649
700
|
let [n, r] = d(e), i = o(() => r(""), []), [a, s] = d([]), f = u(null), p = u(() => {}), m = o((e) => {
|
|
650
701
|
let t = Array.from(e);
|
|
651
702
|
t.length !== 0 && s((e) => e.concat(t.map((e) => ({
|
|
652
|
-
id:
|
|
703
|
+
id: St(),
|
|
653
704
|
type: "file",
|
|
654
705
|
url: URL.createObjectURL(e),
|
|
655
706
|
mediaType: e.type,
|
|
@@ -700,41 +751,41 @@ function Rt({ initialInput: e = "", children: t }) {
|
|
|
700
751
|
y,
|
|
701
752
|
b
|
|
702
753
|
]);
|
|
703
|
-
return /* @__PURE__ */
|
|
754
|
+
return /* @__PURE__ */ q(xn.Provider, {
|
|
704
755
|
value: x,
|
|
705
|
-
children: /* @__PURE__ */
|
|
756
|
+
children: /* @__PURE__ */ q(Sn.Provider, {
|
|
706
757
|
value: y,
|
|
707
758
|
children: t
|
|
708
759
|
})
|
|
709
760
|
});
|
|
710
761
|
}
|
|
711
|
-
var
|
|
712
|
-
let e =
|
|
762
|
+
var On = r(null), Z = () => {
|
|
763
|
+
let e = En(), t = s(On), n = e ?? t;
|
|
713
764
|
if (!n) throw Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");
|
|
714
765
|
return n;
|
|
715
766
|
};
|
|
716
|
-
function
|
|
767
|
+
function kn({ data: e, className: t, ...n }) {
|
|
717
768
|
let r = Z(), i = e.filename || "", a = (e.mediaType?.startsWith("image/") && e.url ? "image" : "file") == "image", o = i || (a ? "Image" : "Attachment");
|
|
718
|
-
return /* @__PURE__ */
|
|
769
|
+
return /* @__PURE__ */ J(Xn, { children: [/* @__PURE__ */ q(z, {
|
|
719
770
|
asChild: !0,
|
|
720
|
-
children: /* @__PURE__ */
|
|
721
|
-
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),
|
|
722
773
|
...n,
|
|
723
|
-
children: [/* @__PURE__ */
|
|
774
|
+
children: [/* @__PURE__ */ J("div", {
|
|
724
775
|
className: "relative size-5 shrink-0",
|
|
725
|
-
children: [/* @__PURE__ */
|
|
776
|
+
children: [/* @__PURE__ */ q("div", {
|
|
726
777
|
className: "absolute inset-0 flex size-5 items-center justify-center overflow-hidden rounded bg-background transition-opacity group-hover:opacity-0",
|
|
727
|
-
children: a ? /* @__PURE__ */
|
|
778
|
+
children: a ? /* @__PURE__ */ q("img", {
|
|
728
779
|
alt: i || "attachment",
|
|
729
780
|
className: "size-5 object-cover",
|
|
730
781
|
height: 20,
|
|
731
782
|
src: e.url,
|
|
732
783
|
width: 20
|
|
733
|
-
}) : /* @__PURE__ */
|
|
784
|
+
}) : /* @__PURE__ */ q("div", {
|
|
734
785
|
className: "flex size-5 items-center justify-center text-muted-foreground",
|
|
735
|
-
children: /* @__PURE__ */
|
|
786
|
+
children: /* @__PURE__ */ q(at, { className: "size-3" })
|
|
736
787
|
})
|
|
737
|
-
}), /* @__PURE__ */
|
|
788
|
+
}), /* @__PURE__ */ J(v, {
|
|
738
789
|
"aria-label": "Remove attachment",
|
|
739
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",
|
|
740
791
|
onClick: (t) => {
|
|
@@ -742,37 +793,37 @@ function Bt({ data: e, className: t, ...n }) {
|
|
|
742
793
|
},
|
|
743
794
|
type: "button",
|
|
744
795
|
variant: "ghost",
|
|
745
|
-
children: [/* @__PURE__ */
|
|
796
|
+
children: [/* @__PURE__ */ q(G, {}), /* @__PURE__ */ q("span", {
|
|
746
797
|
className: "sr-only",
|
|
747
798
|
children: "Remove"
|
|
748
799
|
})]
|
|
749
800
|
})]
|
|
750
|
-
}), /* @__PURE__ */
|
|
801
|
+
}), /* @__PURE__ */ q("span", {
|
|
751
802
|
className: "flex-1 truncate",
|
|
752
803
|
children: o
|
|
753
804
|
})]
|
|
754
805
|
}, e.id)
|
|
755
|
-
}), /* @__PURE__ */
|
|
806
|
+
}), /* @__PURE__ */ q(Qn, {
|
|
756
807
|
className: "w-auto p-2",
|
|
757
|
-
children: /* @__PURE__ */
|
|
808
|
+
children: /* @__PURE__ */ J("div", {
|
|
758
809
|
className: "w-auto space-y-3",
|
|
759
|
-
children: [a && /* @__PURE__ */
|
|
810
|
+
children: [a && /* @__PURE__ */ q("div", {
|
|
760
811
|
className: "flex max-h-96 w-96 items-center justify-center overflow-hidden rounded-md border",
|
|
761
|
-
children: /* @__PURE__ */
|
|
812
|
+
children: /* @__PURE__ */ q("img", {
|
|
762
813
|
alt: i || "attachment preview",
|
|
763
814
|
className: "max-h-full max-w-full object-contain",
|
|
764
815
|
height: 384,
|
|
765
816
|
src: e.url,
|
|
766
817
|
width: 448
|
|
767
818
|
})
|
|
768
|
-
}), /* @__PURE__ */
|
|
819
|
+
}), /* @__PURE__ */ q("div", {
|
|
769
820
|
className: "flex items-center gap-2.5",
|
|
770
|
-
children: /* @__PURE__ */
|
|
821
|
+
children: /* @__PURE__ */ J("div", {
|
|
771
822
|
className: "min-w-0 flex-1 space-y-1 px-0.5",
|
|
772
|
-
children: [/* @__PURE__ */
|
|
823
|
+
children: [/* @__PURE__ */ q("h4", {
|
|
773
824
|
className: "truncate font-semibold text-sm leading-none",
|
|
774
825
|
children: i || (a ? "Image" : "Attachment")
|
|
775
|
-
}), e.mediaType && /* @__PURE__ */
|
|
826
|
+
}), e.mediaType && /* @__PURE__ */ q("p", {
|
|
776
827
|
className: "truncate font-mono text-muted-foreground text-xs",
|
|
777
828
|
children: e.mediaType
|
|
778
829
|
})]
|
|
@@ -781,29 +832,29 @@ function Bt({ data: e, className: t, ...n }) {
|
|
|
781
832
|
})
|
|
782
833
|
})] });
|
|
783
834
|
}
|
|
784
|
-
function
|
|
835
|
+
function An({ children: e, className: t, ...r }) {
|
|
785
836
|
let i = Z();
|
|
786
|
-
return i.files.length ? /* @__PURE__ */
|
|
787
|
-
className:
|
|
837
|
+
return i.files.length ? /* @__PURE__ */ q("div", {
|
|
838
|
+
className: U("flex flex-wrap items-center gap-2 p-3 w-full", t),
|
|
788
839
|
...r,
|
|
789
|
-
children: i.files.map((t) => /* @__PURE__ */
|
|
840
|
+
children: i.files.map((t) => /* @__PURE__ */ q(n, { children: e(t) }, t.id))
|
|
790
841
|
}) : null;
|
|
791
842
|
}
|
|
792
|
-
var
|
|
843
|
+
var jn = ({ label: e = "Add photos or files", ...t }) => {
|
|
793
844
|
let n = Z();
|
|
794
|
-
return /* @__PURE__ */
|
|
845
|
+
return /* @__PURE__ */ J(I, {
|
|
795
846
|
...t,
|
|
796
847
|
onSelect: (e) => {
|
|
797
848
|
e.preventDefault(), n.openFileDialog();
|
|
798
849
|
},
|
|
799
850
|
children: [
|
|
800
|
-
/* @__PURE__ */
|
|
851
|
+
/* @__PURE__ */ q(Qe, { className: "mr-2 size-4" }),
|
|
801
852
|
" ",
|
|
802
853
|
e
|
|
803
854
|
]
|
|
804
855
|
});
|
|
805
|
-
},
|
|
806
|
-
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);
|
|
807
858
|
C.current = S;
|
|
808
859
|
let w = o(() => {
|
|
809
860
|
v.current?.click();
|
|
@@ -838,7 +889,7 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
838
889
|
});
|
|
839
890
|
let i = [];
|
|
840
891
|
for (let e of n) i.push({
|
|
841
|
-
id:
|
|
892
|
+
id: St(),
|
|
842
893
|
type: "file",
|
|
843
894
|
url: URL.createObjectURL(e),
|
|
844
895
|
mediaType: e.type,
|
|
@@ -888,7 +939,7 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
888
939
|
}, [_]);
|
|
889
940
|
let N = (e) => {
|
|
890
941
|
e.currentTarget.files && k(e.currentTarget.files), e.currentTarget.value = "";
|
|
891
|
-
},
|
|
942
|
+
}, P = async (e) => {
|
|
892
943
|
try {
|
|
893
944
|
let t = await (await fetch(e)).blob();
|
|
894
945
|
return new Promise((e) => {
|
|
@@ -898,7 +949,7 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
898
949
|
} catch {
|
|
899
950
|
return null;
|
|
900
951
|
}
|
|
901
|
-
},
|
|
952
|
+
}, F = l(() => ({
|
|
902
953
|
files: S.map((e) => ({
|
|
903
954
|
...e,
|
|
904
955
|
id: e.id
|
|
@@ -914,7 +965,7 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
914
965
|
A,
|
|
915
966
|
j,
|
|
916
967
|
M
|
|
917
|
-
]),
|
|
968
|
+
]), I = /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ q("input", {
|
|
918
969
|
accept: t,
|
|
919
970
|
"aria-label": "Upload files",
|
|
920
971
|
className: "hidden",
|
|
@@ -923,14 +974,14 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
923
974
|
ref: v,
|
|
924
975
|
title: "Upload files",
|
|
925
976
|
type: "file"
|
|
926
|
-
}), /* @__PURE__ */
|
|
927
|
-
className:
|
|
977
|
+
}), /* @__PURE__ */ q("form", {
|
|
978
|
+
className: U("w-full", e),
|
|
928
979
|
onSubmit: (e) => {
|
|
929
980
|
e.preventDefault();
|
|
930
981
|
let t = e.currentTarget, n = _ ? g.textInput.value : new FormData(t).get("message") || "";
|
|
931
982
|
_ || t.reset(), Promise.all(S.map(async ({ id: e, ...t }) => {
|
|
932
983
|
if (t.url && t.url.startsWith("blob:")) {
|
|
933
|
-
let e = await
|
|
984
|
+
let e = await P(t.url);
|
|
934
985
|
return {
|
|
935
986
|
...t,
|
|
936
987
|
url: e ?? t.url
|
|
@@ -951,20 +1002,20 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
951
1002
|
},
|
|
952
1003
|
ref: y,
|
|
953
1004
|
...h,
|
|
954
|
-
children: /* @__PURE__ */
|
|
1005
|
+
children: /* @__PURE__ */ q(hn, {
|
|
955
1006
|
className: "overflow-hidden",
|
|
956
1007
|
children: m
|
|
957
1008
|
})
|
|
958
1009
|
})] });
|
|
959
|
-
return _ ?
|
|
960
|
-
value:
|
|
961
|
-
children:
|
|
1010
|
+
return _ ? I : /* @__PURE__ */ q(On.Provider, {
|
|
1011
|
+
value: F,
|
|
1012
|
+
children: I
|
|
962
1013
|
});
|
|
963
|
-
},
|
|
964
|
-
className:
|
|
1014
|
+
}, Nn = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1015
|
+
className: U("contents", e),
|
|
965
1016
|
...t
|
|
966
|
-
}),
|
|
967
|
-
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) => {
|
|
968
1019
|
if (e.key === "Enter") {
|
|
969
1020
|
if (o || e.nativeEvent.isComposing || e.shiftKey) return;
|
|
970
1021
|
e.preventDefault();
|
|
@@ -992,8 +1043,8 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
992
1043
|
i.textInput.setInput(t.currentTarget.value), e?.(t);
|
|
993
1044
|
}
|
|
994
1045
|
} : { onChange: e };
|
|
995
|
-
return /* @__PURE__ */
|
|
996
|
-
className:
|
|
1046
|
+
return /* @__PURE__ */ q(bn, {
|
|
1047
|
+
className: U("field-sizing-content max-h-48 min-h-16", t),
|
|
997
1048
|
name: "message",
|
|
998
1049
|
onCompositionEnd: () => s(!1),
|
|
999
1050
|
onCompositionStart: () => s(!0),
|
|
@@ -1003,52 +1054,52 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1003
1054
|
...r,
|
|
1004
1055
|
...u
|
|
1005
1056
|
});
|
|
1006
|
-
},
|
|
1057
|
+
}, Fn = ({ className: e, ...t }) => /* @__PURE__ */ q(_n, {
|
|
1007
1058
|
align: "block-end",
|
|
1008
|
-
className:
|
|
1059
|
+
className: U("order-first flex-wrap gap-1", e),
|
|
1009
1060
|
...t
|
|
1010
|
-
}),
|
|
1061
|
+
}), In = ({ className: e, ...t }) => /* @__PURE__ */ q(_n, {
|
|
1011
1062
|
align: "block-end",
|
|
1012
|
-
className:
|
|
1063
|
+
className: U("justify-between gap-1", e),
|
|
1013
1064
|
...t
|
|
1014
|
-
}),
|
|
1015
|
-
className:
|
|
1065
|
+
}), Ln = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1066
|
+
className: U("flex items-center gap-1", e),
|
|
1016
1067
|
...t
|
|
1017
|
-
}),
|
|
1068
|
+
}), Rn = ({ variant: e = "ghost", className: n, size: r, ...i }) => {
|
|
1018
1069
|
let a = r ?? (t.count(i.children) > 1 ? "sm" : "icon-sm");
|
|
1019
|
-
return /* @__PURE__ */
|
|
1020
|
-
className:
|
|
1070
|
+
return /* @__PURE__ */ q(yn, {
|
|
1071
|
+
className: U(n),
|
|
1021
1072
|
size: a,
|
|
1022
1073
|
type: "button",
|
|
1023
1074
|
variant: e,
|
|
1024
1075
|
...i
|
|
1025
1076
|
});
|
|
1026
|
-
},
|
|
1077
|
+
}, zn = (e) => /* @__PURE__ */ q(P, { ...e }), Bn = ({ className: e, children: t, ...n }) => /* @__PURE__ */ q(L, {
|
|
1027
1078
|
asChild: !0,
|
|
1028
|
-
children: /* @__PURE__ */
|
|
1079
|
+
children: /* @__PURE__ */ q(Rn, {
|
|
1029
1080
|
className: e,
|
|
1030
1081
|
...n,
|
|
1031
|
-
children: t ?? /* @__PURE__ */
|
|
1082
|
+
children: t ?? /* @__PURE__ */ q(ot, { className: "size-4" })
|
|
1032
1083
|
})
|
|
1033
|
-
}),
|
|
1084
|
+
}), Vn = ({ className: e, ...t }) => /* @__PURE__ */ q(F, {
|
|
1034
1085
|
align: "start",
|
|
1035
|
-
className:
|
|
1086
|
+
className: U(e),
|
|
1036
1087
|
...t
|
|
1037
|
-
}),
|
|
1038
|
-
className:
|
|
1088
|
+
}), Hn = ({ className: e, ...t }) => /* @__PURE__ */ q(I, {
|
|
1089
|
+
className: U(e),
|
|
1039
1090
|
...t
|
|
1040
|
-
}),
|
|
1041
|
-
let o = /* @__PURE__ */
|
|
1042
|
-
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, {
|
|
1043
1094
|
"aria-label": "Submit",
|
|
1044
|
-
className:
|
|
1095
|
+
className: U(e),
|
|
1045
1096
|
size: n,
|
|
1046
1097
|
type: "submit",
|
|
1047
1098
|
variant: t,
|
|
1048
1099
|
...a,
|
|
1049
1100
|
children: i ?? o
|
|
1050
1101
|
});
|
|
1051
|
-
},
|
|
1102
|
+
}, Wn = ({ className: e, textareaRef: t, onTranscriptionChange: n, ...r }) => {
|
|
1052
1103
|
let [i, a] = d(!1), [s, l] = d(null), f = u(null);
|
|
1053
1104
|
c(() => {
|
|
1054
1105
|
if (typeof window < "u" && ("SpeechRecognition" in window || "webkitSpeechRecognition" in window)) {
|
|
@@ -1078,80 +1129,80 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1078
1129
|
let p = o(() => {
|
|
1079
1130
|
s && (i ? s.stop() : s.start());
|
|
1080
1131
|
}, [s, i]);
|
|
1081
|
-
return /* @__PURE__ */
|
|
1082
|
-
className:
|
|
1132
|
+
return /* @__PURE__ */ q(Rn, {
|
|
1133
|
+
className: U("relative transition-all duration-200", i && "animate-pulse bg-accent text-accent-foreground", e),
|
|
1083
1134
|
disabled: !s,
|
|
1084
1135
|
onClick: p,
|
|
1085
1136
|
...r,
|
|
1086
|
-
children: /* @__PURE__ */
|
|
1137
|
+
children: /* @__PURE__ */ q(rt, { className: "size-4" })
|
|
1087
1138
|
});
|
|
1088
|
-
},
|
|
1089
|
-
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),
|
|
1090
1141
|
...t
|
|
1091
|
-
}),
|
|
1092
|
-
className:
|
|
1142
|
+
}), qn = ({ className: e, ...t }) => /* @__PURE__ */ q(ue, {
|
|
1143
|
+
className: U(e),
|
|
1093
1144
|
...t
|
|
1094
|
-
}),
|
|
1095
|
-
className:
|
|
1145
|
+
}), Jn = ({ className: e, ...t }) => /* @__PURE__ */ q(de, {
|
|
1146
|
+
className: U(e),
|
|
1096
1147
|
...t
|
|
1097
|
-
}),
|
|
1098
|
-
className:
|
|
1148
|
+
}), Yn = ({ className: e, ...t }) => /* @__PURE__ */ q(pe, {
|
|
1149
|
+
className: U(e),
|
|
1099
1150
|
...t
|
|
1100
|
-
}),
|
|
1151
|
+
}), Xn = ({ openDelay: e = 0, closeDelay: t = 0, ...n }) => /* @__PURE__ */ q(R, {
|
|
1101
1152
|
closeDelay: t,
|
|
1102
1153
|
openDelay: e,
|
|
1103
1154
|
...n
|
|
1104
|
-
}),
|
|
1155
|
+
}), Zn = (e) => /* @__PURE__ */ q(z, { ...e }), Qn = ({ align: e = "start", ...t }) => /* @__PURE__ */ q(ae, {
|
|
1105
1156
|
align: e,
|
|
1106
1157
|
...t
|
|
1107
|
-
}),
|
|
1108
|
-
className:
|
|
1158
|
+
}), $n = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1159
|
+
className: U(e),
|
|
1109
1160
|
...t
|
|
1110
|
-
}),
|
|
1111
|
-
className:
|
|
1161
|
+
}), er = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1162
|
+
className: U(e),
|
|
1112
1163
|
...t
|
|
1113
|
-
}),
|
|
1114
|
-
className:
|
|
1164
|
+
}), tr = ({ className: e, ...t }) => /* @__PURE__ */ q("h3", {
|
|
1165
|
+
className: U("mb-2 px-3 font-medium text-muted-foreground text-xs", e),
|
|
1115
1166
|
...t
|
|
1116
|
-
}),
|
|
1117
|
-
className:
|
|
1167
|
+
}), nr = ({ className: e, ...t }) => /* @__PURE__ */ q("div", {
|
|
1168
|
+
className: U("space-y-1", e),
|
|
1118
1169
|
...t
|
|
1119
|
-
}),
|
|
1120
|
-
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),
|
|
1121
1172
|
...t
|
|
1122
|
-
}),
|
|
1123
|
-
className:
|
|
1173
|
+
}), ir = ({ className: e, ...t }) => /* @__PURE__ */ q(D, {
|
|
1174
|
+
className: U(e),
|
|
1124
1175
|
...t
|
|
1125
|
-
}),
|
|
1126
|
-
className:
|
|
1176
|
+
}), ar = ({ className: e, ...t }) => /* @__PURE__ */ q(A, {
|
|
1177
|
+
className: U(e),
|
|
1127
1178
|
...t
|
|
1128
|
-
}),
|
|
1129
|
-
className:
|
|
1179
|
+
}), or = ({ className: e, ...t }) => /* @__PURE__ */ q(M, {
|
|
1180
|
+
className: U(e),
|
|
1130
1181
|
...t
|
|
1131
|
-
}),
|
|
1132
|
-
className:
|
|
1182
|
+
}), sr = ({ className: e, ...t }) => /* @__PURE__ */ q(O, {
|
|
1183
|
+
className: U(e),
|
|
1133
1184
|
...t
|
|
1134
|
-
}),
|
|
1135
|
-
className:
|
|
1185
|
+
}), cr = ({ className: e, ...t }) => /* @__PURE__ */ q(k, {
|
|
1186
|
+
className: U(e),
|
|
1136
1187
|
...t
|
|
1137
|
-
}),
|
|
1138
|
-
className:
|
|
1188
|
+
}), lr = ({ className: e, ...t }) => /* @__PURE__ */ q(j, {
|
|
1189
|
+
className: U(e),
|
|
1139
1190
|
...t
|
|
1140
|
-
}),
|
|
1141
|
-
className:
|
|
1191
|
+
}), ur = ({ className: e, ...t }) => /* @__PURE__ */ q(N, {
|
|
1192
|
+
className: U(e),
|
|
1142
1193
|
...t
|
|
1143
|
-
}),
|
|
1194
|
+
}), dr = ({ className: e, children: t, ...n }) => /* @__PURE__ */ J(se, {
|
|
1144
1195
|
className: "w-full overflow-x-auto whitespace-nowrap",
|
|
1145
1196
|
...n,
|
|
1146
|
-
children: [/* @__PURE__ */
|
|
1147
|
-
className:
|
|
1197
|
+
children: [/* @__PURE__ */ q("div", {
|
|
1198
|
+
className: U("flex w-max flex-nowrap items-center gap-2", e),
|
|
1148
1199
|
children: t
|
|
1149
|
-
}), /* @__PURE__ */
|
|
1200
|
+
}), /* @__PURE__ */ q(ce, {
|
|
1150
1201
|
className: "hidden",
|
|
1151
1202
|
orientation: "horizontal"
|
|
1152
1203
|
})]
|
|
1153
|
-
}),
|
|
1154
|
-
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),
|
|
1155
1206
|
onClick: () => {
|
|
1156
1207
|
t?.(e);
|
|
1157
1208
|
},
|
|
@@ -1160,7 +1211,7 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1160
1211
|
variant: r,
|
|
1161
1212
|
...o,
|
|
1162
1213
|
children: a || e
|
|
1163
|
-
}),
|
|
1214
|
+
}), pr = r({ code: "" }), mr = {
|
|
1164
1215
|
name: "line-numbers",
|
|
1165
1216
|
line(e, t) {
|
|
1166
1217
|
e.children.unshift({
|
|
@@ -1181,21 +1232,21 @@ var Ht = ({ label: e = "Add photos or files", ...t }) => {
|
|
|
1181
1232
|
});
|
|
1182
1233
|
}
|
|
1183
1234
|
};
|
|
1184
|
-
async function
|
|
1185
|
-
let r = n ? [
|
|
1186
|
-
return await Promise.all([
|
|
1235
|
+
async function hr(e, t, n = !1) {
|
|
1236
|
+
let r = n ? [mr] : [];
|
|
1237
|
+
return await Promise.all([Ct(e, {
|
|
1187
1238
|
lang: t,
|
|
1188
1239
|
theme: "one-light",
|
|
1189
1240
|
transformers: r
|
|
1190
|
-
}),
|
|
1241
|
+
}), Ct(e, {
|
|
1191
1242
|
lang: t,
|
|
1192
1243
|
theme: "one-dark-pro",
|
|
1193
1244
|
transformers: r
|
|
1194
1245
|
})]);
|
|
1195
1246
|
}
|
|
1196
|
-
var
|
|
1247
|
+
var Q = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children: i, ...a }) => {
|
|
1197
1248
|
let [o, s] = d(""), [l, f] = d(""), p = u(!1);
|
|
1198
|
-
return c(() => (
|
|
1249
|
+
return c(() => (hr(e, t, n).then(([e, t]) => {
|
|
1199
1250
|
p.current ||= (s(e), f(t), !0);
|
|
1200
1251
|
}), () => {
|
|
1201
1252
|
p.current = !1;
|
|
@@ -1203,23 +1254,23 @@ var $ = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1203
1254
|
e,
|
|
1204
1255
|
t,
|
|
1205
1256
|
n
|
|
1206
|
-
]), /* @__PURE__ */
|
|
1257
|
+
]), /* @__PURE__ */ q(pr.Provider, {
|
|
1207
1258
|
value: { code: e },
|
|
1208
|
-
children: /* @__PURE__ */
|
|
1209
|
-
className:
|
|
1259
|
+
children: /* @__PURE__ */ q("div", {
|
|
1260
|
+
className: U("group relative w-full overflow-hidden rounded-md border bg-background text-foreground", r),
|
|
1210
1261
|
...a,
|
|
1211
|
-
children: /* @__PURE__ */
|
|
1262
|
+
children: /* @__PURE__ */ J("div", {
|
|
1212
1263
|
className: "relative",
|
|
1213
1264
|
children: [
|
|
1214
|
-
/* @__PURE__ */
|
|
1265
|
+
/* @__PURE__ */ q("div", {
|
|
1215
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",
|
|
1216
1267
|
dangerouslySetInnerHTML: { __html: o }
|
|
1217
1268
|
}),
|
|
1218
|
-
/* @__PURE__ */
|
|
1269
|
+
/* @__PURE__ */ q("div", {
|
|
1219
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",
|
|
1220
1271
|
dangerouslySetInnerHTML: { __html: l }
|
|
1221
1272
|
}),
|
|
1222
|
-
i && /* @__PURE__ */
|
|
1273
|
+
i && /* @__PURE__ */ q("div", {
|
|
1223
1274
|
className: "absolute top-2 right-2 flex items-center gap-2",
|
|
1224
1275
|
children: i
|
|
1225
1276
|
})
|
|
@@ -1227,8 +1278,8 @@ var $ = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1227
1278
|
})
|
|
1228
1279
|
})
|
|
1229
1280
|
});
|
|
1230
|
-
},
|
|
1231
|
-
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 () => {
|
|
1232
1283
|
if (typeof window > "u" || !navigator?.clipboard?.writeText) {
|
|
1233
1284
|
t?.(/* @__PURE__ */ Error("Clipboard API not available"));
|
|
1234
1285
|
return;
|
|
@@ -1238,29 +1289,29 @@ var $ = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1238
1289
|
} catch (e) {
|
|
1239
1290
|
t?.(e);
|
|
1240
1291
|
}
|
|
1241
|
-
}, f = o ?
|
|
1242
|
-
return /* @__PURE__ */
|
|
1243
|
-
className:
|
|
1292
|
+
}, f = o ? Ve : Ye;
|
|
1293
|
+
return /* @__PURE__ */ q(v, {
|
|
1294
|
+
className: U("shrink-0", i),
|
|
1244
1295
|
onClick: u,
|
|
1245
1296
|
size: "icon",
|
|
1246
1297
|
variant: "ghost",
|
|
1247
1298
|
...a,
|
|
1248
|
-
children: r ?? /* @__PURE__ */
|
|
1299
|
+
children: r ?? /* @__PURE__ */ q(f, { size: 14 })
|
|
1249
1300
|
});
|
|
1250
|
-
},
|
|
1251
|
-
className:
|
|
1301
|
+
}, _r = ({ className: e, ...t }) => /* @__PURE__ */ q(w, {
|
|
1302
|
+
className: U("not-prose mb-4 w-full rounded-md border", e),
|
|
1252
1303
|
...t
|
|
1253
|
-
}),
|
|
1304
|
+
}), vr = (e) => /* @__PURE__ */ J(_, {
|
|
1254
1305
|
className: "gap-1.5 rounded-full text-xs",
|
|
1255
1306
|
variant: "secondary",
|
|
1256
1307
|
children: [{
|
|
1257
|
-
"input-streaming": /* @__PURE__ */
|
|
1258
|
-
"input-available": /* @__PURE__ */
|
|
1259
|
-
"approval-requested": /* @__PURE__ */
|
|
1260
|
-
"approval-responded": /* @__PURE__ */
|
|
1261
|
-
"output-available": /* @__PURE__ */
|
|
1262
|
-
"output-error": /* @__PURE__ */
|
|
1263
|
-
"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" })
|
|
1264
1315
|
}[e], {
|
|
1265
1316
|
"input-streaming": "Pending",
|
|
1266
1317
|
"input-available": "Running",
|
|
@@ -1270,61 +1321,61 @@ var $ = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1270
1321
|
"output-error": "Error",
|
|
1271
1322
|
"output-denied": "Denied"
|
|
1272
1323
|
}[e]]
|
|
1273
|
-
}),
|
|
1274
|
-
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),
|
|
1275
1326
|
...i,
|
|
1276
|
-
children: [/* @__PURE__ */
|
|
1327
|
+
children: [/* @__PURE__ */ J("div", {
|
|
1277
1328
|
className: "flex items-center gap-2",
|
|
1278
1329
|
children: [
|
|
1279
|
-
/* @__PURE__ */
|
|
1280
|
-
/* @__PURE__ */
|
|
1330
|
+
/* @__PURE__ */ q(ut, { className: "size-4 text-muted-foreground" }),
|
|
1331
|
+
/* @__PURE__ */ q("span", {
|
|
1281
1332
|
className: "font-medium text-sm",
|
|
1282
1333
|
children: t ?? n.split("-").slice(1).join("-")
|
|
1283
1334
|
}),
|
|
1284
|
-
|
|
1335
|
+
vr(r)
|
|
1285
1336
|
]
|
|
1286
|
-
}), /* @__PURE__ */
|
|
1287
|
-
}),
|
|
1288
|
-
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),
|
|
1289
1340
|
...t
|
|
1290
|
-
}),
|
|
1291
|
-
className:
|
|
1341
|
+
}), xr = ({ className: e, input: t, ...n }) => /* @__PURE__ */ J("div", {
|
|
1342
|
+
className: U("space-y-2 overflow-hidden p-4", e),
|
|
1292
1343
|
...n,
|
|
1293
|
-
children: [/* @__PURE__ */
|
|
1344
|
+
children: [/* @__PURE__ */ q("h4", {
|
|
1294
1345
|
className: "font-medium text-muted-foreground text-xs uppercase tracking-wide",
|
|
1295
1346
|
children: "Parameters"
|
|
1296
|
-
}), /* @__PURE__ */
|
|
1347
|
+
}), /* @__PURE__ */ q("div", {
|
|
1297
1348
|
className: "rounded-md bg-muted/50",
|
|
1298
|
-
children: /* @__PURE__ */
|
|
1349
|
+
children: /* @__PURE__ */ q(Q, {
|
|
1299
1350
|
code: JSON.stringify(t, null, 2),
|
|
1300
1351
|
language: "json"
|
|
1301
1352
|
})
|
|
1302
1353
|
})]
|
|
1303
|
-
}),
|
|
1354
|
+
}), Sr = ({ className: e, output: t, errorText: n, ...r }) => {
|
|
1304
1355
|
if (!(t || n)) return null;
|
|
1305
|
-
let a = /* @__PURE__ */
|
|
1306
|
-
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, {
|
|
1307
1358
|
code: JSON.stringify(t, null, 2),
|
|
1308
1359
|
language: "json"
|
|
1309
|
-
}) : typeof t == "string" && (a = /* @__PURE__ */
|
|
1360
|
+
}) : typeof t == "string" && (a = /* @__PURE__ */ q(Q, {
|
|
1310
1361
|
code: t,
|
|
1311
1362
|
language: "json"
|
|
1312
|
-
})), /* @__PURE__ */
|
|
1313
|
-
className:
|
|
1363
|
+
})), /* @__PURE__ */ J("div", {
|
|
1364
|
+
className: U("space-y-2 p-4", e),
|
|
1314
1365
|
...r,
|
|
1315
|
-
children: [/* @__PURE__ */
|
|
1366
|
+
children: [/* @__PURE__ */ q("h4", {
|
|
1316
1367
|
className: "font-medium text-muted-foreground text-xs uppercase tracking-wide",
|
|
1317
1368
|
children: n ? "Error" : "Result"
|
|
1318
|
-
}), /* @__PURE__ */
|
|
1319
|
-
className:
|
|
1320
|
-
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]
|
|
1321
1372
|
})]
|
|
1322
1373
|
});
|
|
1323
|
-
},
|
|
1324
|
-
let a =
|
|
1325
|
-
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, {
|
|
1326
1377
|
animate: { backgroundPosition: "0% center" },
|
|
1327
|
-
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),
|
|
1328
1379
|
initial: { backgroundPosition: "100% center" },
|
|
1329
1380
|
style: {
|
|
1330
1381
|
"--spread": `${o}px`,
|
|
@@ -1337,21 +1388,21 @@ var $ = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1337
1388
|
},
|
|
1338
1389
|
children: e
|
|
1339
1390
|
});
|
|
1340
|
-
}),
|
|
1341
|
-
let e = s(
|
|
1391
|
+
}), wr = r(null), Tr = () => {
|
|
1392
|
+
let e = s(wr);
|
|
1342
1393
|
if (!e) throw Error("Reasoning components must be used within Reasoning");
|
|
1343
1394
|
return e;
|
|
1344
|
-
},
|
|
1345
|
-
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({
|
|
1346
1397
|
prop: n,
|
|
1347
1398
|
defaultProp: r,
|
|
1348
1399
|
onChange: i
|
|
1349
|
-
}), [f, p] =
|
|
1400
|
+
}), [f, p] = wt({
|
|
1350
1401
|
prop: a,
|
|
1351
1402
|
defaultProp: void 0
|
|
1352
|
-
}), [m, h] = d(!1), [g,
|
|
1403
|
+
}), [m, h] = d(!1), [g, _] = d(null);
|
|
1353
1404
|
return c(() => {
|
|
1354
|
-
t ? g === null &&
|
|
1405
|
+
t ? g === null && _(Date.now()) : g !== null && (p(Math.ceil((Date.now() - g) / Dr)), _(null));
|
|
1355
1406
|
}, [
|
|
1356
1407
|
t,
|
|
1357
1408
|
g,
|
|
@@ -1360,7 +1411,7 @@ var $ = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1360
1411
|
if (r && !t && l && !m) {
|
|
1361
1412
|
let e = setTimeout(() => {
|
|
1362
1413
|
u(!1), h(!0);
|
|
1363
|
-
},
|
|
1414
|
+
}, Er);
|
|
1364
1415
|
return () => clearTimeout(e);
|
|
1365
1416
|
}
|
|
1366
1417
|
}, [
|
|
@@ -1369,15 +1420,15 @@ var $ = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1369
1420
|
r,
|
|
1370
1421
|
u,
|
|
1371
1422
|
m
|
|
1372
|
-
]), /* @__PURE__ */
|
|
1423
|
+
]), /* @__PURE__ */ q(wr.Provider, {
|
|
1373
1424
|
value: {
|
|
1374
1425
|
isStreaming: t,
|
|
1375
1426
|
isOpen: l,
|
|
1376
1427
|
setIsOpen: u,
|
|
1377
1428
|
duration: f
|
|
1378
1429
|
},
|
|
1379
|
-
children: /* @__PURE__ */
|
|
1380
|
-
className:
|
|
1430
|
+
children: /* @__PURE__ */ q(w, {
|
|
1431
|
+
className: U("not-prose mb-4", e),
|
|
1381
1432
|
onOpenChange: (e) => {
|
|
1382
1433
|
u(e);
|
|
1383
1434
|
},
|
|
@@ -1386,167 +1437,195 @@ var $ = ({ code: e, language: t, showLineNumbers: n = !1, className: r, children
|
|
|
1386
1437
|
children: o
|
|
1387
1438
|
})
|
|
1388
1439
|
});
|
|
1389
|
-
}),
|
|
1440
|
+
}), kr = (e, t) => e || t === 0 ? /* @__PURE__ */ q(Cr, {
|
|
1390
1441
|
duration: 1,
|
|
1391
1442
|
children: "Thinking..."
|
|
1392
|
-
}) : t === void 0 ? /* @__PURE__ */
|
|
1443
|
+
}) : t === void 0 ? /* @__PURE__ */ q("p", { children: "Thought for a few seconds" }) : /* @__PURE__ */ J("p", { children: [
|
|
1393
1444
|
"Thought for ",
|
|
1394
1445
|
t,
|
|
1395
1446
|
" seconds"
|
|
1396
|
-
] }),
|
|
1397
|
-
let { isStreaming: i, isOpen: a, duration: o } =
|
|
1398
|
-
return /* @__PURE__ */
|
|
1399
|
-
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),
|
|
1400
1451
|
...r,
|
|
1401
|
-
children: t ?? /* @__PURE__ */
|
|
1402
|
-
/* @__PURE__ */
|
|
1452
|
+
children: t ?? /* @__PURE__ */ J(K, { children: [
|
|
1453
|
+
/* @__PURE__ */ q(Le, { className: "size-4" }),
|
|
1403
1454
|
n(i, o),
|
|
1404
|
-
/* @__PURE__ */
|
|
1455
|
+
/* @__PURE__ */ q(He, { className: U("size-4 transition-transform", a ? "rotate-180" : "rotate-0") })
|
|
1405
1456
|
] })
|
|
1406
1457
|
});
|
|
1407
|
-
}),
|
|
1408
|
-
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),
|
|
1409
1460
|
...n,
|
|
1410
|
-
children: /* @__PURE__ */
|
|
1461
|
+
children: /* @__PURE__ */ q(xt, {
|
|
1411
1462
|
...n,
|
|
1412
1463
|
children: t
|
|
1413
1464
|
})
|
|
1414
1465
|
}));
|
|
1415
|
-
|
|
1466
|
+
Or.displayName = "Reasoning", Ar.displayName = "ReasoningTrigger", jr.displayName = "ReasoningContent";
|
|
1416
1467
|
//#endregion
|
|
1417
1468
|
//#region src/elements/sources.tsx
|
|
1418
|
-
var
|
|
1419
|
-
className:
|
|
1469
|
+
var Mr = ({ className: e, ...t }) => /* @__PURE__ */ q(w, {
|
|
1470
|
+
className: U("not-prose mb-4 text-primary text-xs", e),
|
|
1420
1471
|
...t
|
|
1421
|
-
}),
|
|
1422
|
-
className:
|
|
1472
|
+
}), Nr = ({ className: e, count: t, children: n, ...r }) => /* @__PURE__ */ q(E, {
|
|
1473
|
+
className: U("flex items-center gap-2", e),
|
|
1423
1474
|
...r,
|
|
1424
|
-
children: n ?? /* @__PURE__ */
|
|
1475
|
+
children: n ?? /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ J("p", {
|
|
1425
1476
|
className: "font-medium",
|
|
1426
1477
|
children: [
|
|
1427
1478
|
"Used ",
|
|
1428
1479
|
t,
|
|
1429
1480
|
" sources"
|
|
1430
1481
|
]
|
|
1431
|
-
}), /* @__PURE__ */
|
|
1432
|
-
}),
|
|
1433
|
-
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),
|
|
1434
1485
|
...t
|
|
1435
|
-
}),
|
|
1486
|
+
}), Fr = ({ href: e, title: t, children: n, ...r }) => /* @__PURE__ */ q("a", {
|
|
1436
1487
|
className: "flex items-center gap-2",
|
|
1437
1488
|
href: e,
|
|
1438
1489
|
rel: "noreferrer",
|
|
1439
1490
|
target: "_blank",
|
|
1440
1491
|
...r,
|
|
1441
|
-
children: n ?? /* @__PURE__ */
|
|
1492
|
+
children: n ?? /* @__PURE__ */ J(K, { children: [/* @__PURE__ */ q(Fe, { className: "h-4 w-4" }), /* @__PURE__ */ q("span", {
|
|
1442
1493
|
className: "block font-medium",
|
|
1443
1494
|
children: t
|
|
1444
1495
|
})] })
|
|
1445
1496
|
});
|
|
1446
1497
|
//#endregion
|
|
1447
1498
|
//#region src/ChatbotEnhanced.tsx
|
|
1448
|
-
function
|
|
1499
|
+
function Ir(e, t) {
|
|
1449
1500
|
return t ? "error" : e ? "streaming" : "ready";
|
|
1450
1501
|
}
|
|
1451
|
-
function
|
|
1502
|
+
function Lr(e) {
|
|
1452
1503
|
return e === "user" ? "user" : "assistant";
|
|
1453
1504
|
}
|
|
1454
|
-
var
|
|
1455
|
-
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) => {
|
|
1456
1507
|
let t = !!e.text?.trim(), n = e.files?.map((e) => e.file).filter(Boolean), r = !!(n && n.length > 0);
|
|
1457
1508
|
(t || r) && i?.(e.text?.trim() ?? "", n);
|
|
1458
|
-
}, [i]),
|
|
1509
|
+
}, [i]), te = e.useCallback((e) => {
|
|
1459
1510
|
i?.(e);
|
|
1460
|
-
}, [i]),
|
|
1461
|
-
navigator.clipboard?.writeText(e.content),
|
|
1511
|
+
}, [i]), ne = e.useCallback((e) => {
|
|
1512
|
+
navigator.clipboard?.writeText(e.content), L(e.id), window.setTimeout(() => L((t) => t === e.id ? null : t), 1500);
|
|
1462
1513
|
}, []);
|
|
1463
|
-
return /* @__PURE__ */
|
|
1464
|
-
ref:
|
|
1465
|
-
className:
|
|
1514
|
+
return /* @__PURE__ */ J("div", {
|
|
1515
|
+
ref: P,
|
|
1516
|
+
className: U("flex flex-col border rounded-lg bg-background overflow-hidden", t),
|
|
1466
1517
|
style: { maxHeight: g },
|
|
1467
|
-
...
|
|
1518
|
+
...N,
|
|
1468
1519
|
children: [
|
|
1469
|
-
a && n.length > 0 && /* @__PURE__ */
|
|
1520
|
+
a && n.length > 0 && /* @__PURE__ */ J("div", {
|
|
1470
1521
|
className: "flex items-center justify-between px-4 py-2 border-b bg-muted/30",
|
|
1471
|
-
children: [/* @__PURE__ */
|
|
1522
|
+
children: [/* @__PURE__ */ J("span", {
|
|
1472
1523
|
className: "text-sm text-muted-foreground",
|
|
1473
1524
|
children: [
|
|
1474
1525
|
n.length,
|
|
1475
1526
|
" message",
|
|
1476
1527
|
n.length === 1 ? "" : "s"
|
|
1477
1528
|
]
|
|
1478
|
-
}), /* @__PURE__ */
|
|
1529
|
+
}), /* @__PURE__ */ q("button", {
|
|
1479
1530
|
type: "button",
|
|
1480
1531
|
onClick: a,
|
|
1481
1532
|
className: "text-xs text-muted-foreground hover:text-foreground transition-colors",
|
|
1482
1533
|
children: "Clear"
|
|
1483
1534
|
})]
|
|
1484
1535
|
}),
|
|
1485
|
-
/* @__PURE__ */
|
|
1536
|
+
T ? /* @__PURE__ */ q("div", {
|
|
1537
|
+
className: "shrink-0 border-b bg-background/50",
|
|
1538
|
+
children: T
|
|
1539
|
+
}) : null,
|
|
1540
|
+
/* @__PURE__ */ J(Kt, {
|
|
1486
1541
|
className: "flex-1 min-h-0",
|
|
1487
|
-
children: [/* @__PURE__ */
|
|
1542
|
+
children: [/* @__PURE__ */ q(qt, {
|
|
1488
1543
|
className: "space-y-4 px-4 py-3",
|
|
1489
|
-
children: n.length === 0 ? /* @__PURE__ */
|
|
1544
|
+
children: n.length === 0 ? /* @__PURE__ */ q(Jt, {
|
|
1490
1545
|
title: "Start a conversation",
|
|
1491
1546
|
description: "Ask anything — the assistant has access to your current app context.",
|
|
1492
|
-
children: x && x.length > 0 ? /* @__PURE__ */
|
|
1547
|
+
children: x && x.length > 0 ? /* @__PURE__ */ q(dr, {
|
|
1493
1548
|
className: "justify-center pt-2",
|
|
1494
|
-
children: x.map((e) => /* @__PURE__ */
|
|
1549
|
+
children: x.map((e) => /* @__PURE__ */ q(fr, {
|
|
1495
1550
|
suggestion: e,
|
|
1496
|
-
onClick:
|
|
1551
|
+
onClick: te
|
|
1497
1552
|
}, e))
|
|
1498
1553
|
}) : null
|
|
1499
1554
|
}) : n.map((e) => {
|
|
1500
1555
|
let t = e.role === "user", n = e.toolInvocations ?? [], r = e.reasoning?.trim(), i = e.sources ?? [];
|
|
1501
|
-
return /* @__PURE__ */
|
|
1502
|
-
from:
|
|
1503
|
-
children: [/* @__PURE__ */
|
|
1504
|
-
!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, {
|
|
1505
1560
|
isStreaming: !!e.streaming && !e.content,
|
|
1506
1561
|
className: "mb-2",
|
|
1507
|
-
children: [/* @__PURE__ */
|
|
1562
|
+
children: [/* @__PURE__ */ q(Ar, {}), /* @__PURE__ */ q(jr, { children: r })]
|
|
1508
1563
|
}) : null,
|
|
1509
1564
|
!t && n.length > 0 ? n.map((e) => {
|
|
1510
|
-
let t = e.state ?? (e.errorText ? "output-error" : e.result === void 0 ? "input-available" : "output-available"), n = `tool-${e.toolName}
|
|
1511
|
-
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, {
|
|
1512
1567
|
defaultOpen: t !== "output-available",
|
|
1513
|
-
children: [/* @__PURE__ */
|
|
1568
|
+
children: [/* @__PURE__ */ q(yr, {
|
|
1514
1569
|
type: n,
|
|
1515
1570
|
state: t,
|
|
1516
1571
|
title: e.toolName
|
|
1517
|
-
}), /* @__PURE__ */
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1572
|
+
}), /* @__PURE__ */ J(br, { children: [
|
|
1573
|
+
e.args === void 0 ? null : /* @__PURE__ */ q(xr, { input: e.args }),
|
|
1574
|
+
a ? null : /* @__PURE__ */ q(Sr, {
|
|
1575
|
+
output: e.result,
|
|
1576
|
+
errorText: e.errorText
|
|
1577
|
+
}),
|
|
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", {
|
|
1586
|
+
className: "flex gap-2 p-3 border-t bg-muted/30",
|
|
1587
|
+
children: [/* @__PURE__ */ q("button", {
|
|
1588
|
+
type: "button",
|
|
1589
|
+
onClick: () => O?.(e.toolCallId, !0),
|
|
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",
|
|
1591
|
+
children: k
|
|
1592
|
+
}), /* @__PURE__ */ q("button", {
|
|
1593
|
+
type: "button",
|
|
1594
|
+
onClick: () => O?.(e.toolCallId, !1, j),
|
|
1595
|
+
className: "inline-flex h-7 items-center rounded-md border bg-background px-3 text-xs font-medium hover:bg-accent",
|
|
1596
|
+
children: A
|
|
1597
|
+
})]
|
|
1598
|
+
}) : null
|
|
1599
|
+
] })]
|
|
1521
1600
|
}, e.toolCallId);
|
|
1522
1601
|
}) : null,
|
|
1523
1602
|
e.content,
|
|
1524
|
-
e.streaming ? /* @__PURE__ */
|
|
1603
|
+
e.streaming ? /* @__PURE__ */ q("span", {
|
|
1525
1604
|
"aria-hidden": !0,
|
|
1526
1605
|
className: "ml-0.5 inline-block w-[2px] h-4 align-middle bg-current animate-pulse"
|
|
1527
1606
|
}) : null,
|
|
1528
|
-
!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, {
|
|
1529
1608
|
href: e.url,
|
|
1530
1609
|
title: e.title ?? e.url
|
|
1531
1610
|
}, e.id ?? e.url ?? t)) })] }) : null,
|
|
1532
|
-
d && e.timestamp ? /* @__PURE__ */
|
|
1611
|
+
d && e.timestamp ? /* @__PURE__ */ q("div", {
|
|
1533
1612
|
className: "text-[10px] opacity-70 mt-1",
|
|
1534
1613
|
children: e.timestamp
|
|
1535
1614
|
}) : null
|
|
1536
|
-
] }), t ? null : /* @__PURE__ */
|
|
1537
|
-
/* @__PURE__ */
|
|
1615
|
+
] }), t ? null : /* @__PURE__ */ J(tn, { children: [
|
|
1616
|
+
/* @__PURE__ */ q(nn, {
|
|
1538
1617
|
label: "Copy",
|
|
1539
1618
|
tooltip: "Copy",
|
|
1540
|
-
onClick: () =>
|
|
1541
|
-
children:
|
|
1619
|
+
onClick: () => ne(e),
|
|
1620
|
+
children: I === e.id ? /* @__PURE__ */ q(Re, { className: "size-3.5" }) : /* @__PURE__ */ q(Je, { className: "size-3.5" })
|
|
1542
1621
|
}),
|
|
1543
|
-
s ? /* @__PURE__ */
|
|
1622
|
+
s ? /* @__PURE__ */ q(nn, {
|
|
1544
1623
|
label: "Regenerate",
|
|
1545
1624
|
tooltip: "Regenerate",
|
|
1546
1625
|
onClick: s,
|
|
1547
|
-
children: /* @__PURE__ */
|
|
1626
|
+
children: /* @__PURE__ */ q(st, { className: "size-3.5" })
|
|
1548
1627
|
}) : null,
|
|
1549
|
-
e.traceId ? /* @__PURE__ */
|
|
1628
|
+
e.traceId ? /* @__PURE__ */ q("a", {
|
|
1550
1629
|
href: `#trace/${e.traceId}`,
|
|
1551
1630
|
"data-trace-id": e.traceId,
|
|
1552
1631
|
className: "text-[10px] text-muted-foreground hover:text-foreground ml-1 underline",
|
|
@@ -1556,18 +1635,18 @@ var Yn = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type
|
|
|
1556
1635
|
] })]
|
|
1557
1636
|
}, e.id);
|
|
1558
1637
|
})
|
|
1559
|
-
}), /* @__PURE__ */
|
|
1638
|
+
}), /* @__PURE__ */ q(Yt, {})]
|
|
1560
1639
|
}),
|
|
1561
|
-
u ? /* @__PURE__ */
|
|
1640
|
+
u ? /* @__PURE__ */ J("div", {
|
|
1562
1641
|
className: "flex items-center gap-2 px-4 py-2 border-t bg-destructive/10 text-destructive text-sm",
|
|
1563
1642
|
role: "alert",
|
|
1564
1643
|
children: [
|
|
1565
|
-
/* @__PURE__ */
|
|
1566
|
-
/* @__PURE__ */
|
|
1644
|
+
/* @__PURE__ */ q(Ne, { className: "h-4 w-4 shrink-0" }),
|
|
1645
|
+
/* @__PURE__ */ q("span", {
|
|
1567
1646
|
className: "flex-1 truncate",
|
|
1568
1647
|
children: u.message || "An error occurred"
|
|
1569
1648
|
}),
|
|
1570
|
-
s ? /* @__PURE__ */
|
|
1649
|
+
s ? /* @__PURE__ */ q("button", {
|
|
1571
1650
|
type: "button",
|
|
1572
1651
|
onClick: s,
|
|
1573
1652
|
className: "text-xs underline hover:no-underline",
|
|
@@ -1575,36 +1654,43 @@ var Yn = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type
|
|
|
1575
1654
|
}) : null
|
|
1576
1655
|
]
|
|
1577
1656
|
}) : null,
|
|
1578
|
-
/* @__PURE__ */
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1657
|
+
/* @__PURE__ */ J("div", {
|
|
1658
|
+
className: "relative",
|
|
1659
|
+
children: [E ? /* @__PURE__ */ q("div", {
|
|
1660
|
+
className: "absolute bottom-full left-0 right-0 z-10 px-3 pb-1",
|
|
1661
|
+
children: E
|
|
1662
|
+
}) : null, /* @__PURE__ */ J(Mn, {
|
|
1663
|
+
accept: y,
|
|
1664
|
+
maxFileSize: b,
|
|
1665
|
+
onSubmit: ee,
|
|
1666
|
+
onError: (e) => {
|
|
1667
|
+
console.warn("[plugin-chatbot] prompt-input error", e);
|
|
1668
|
+
},
|
|
1669
|
+
children: [
|
|
1670
|
+
v ? /* @__PURE__ */ q(Nn, { children: /* @__PURE__ */ q(An, { children: (e) => /* @__PURE__ */ q(kn, { data: e }) }) }) : null,
|
|
1671
|
+
/* @__PURE__ */ q(Pn, {
|
|
1672
|
+
placeholder: r,
|
|
1673
|
+
disabled: c || F === "streaming",
|
|
1674
|
+
onChange: D ? (e) => D(e.currentTarget.value) : void 0
|
|
1675
|
+
}),
|
|
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", {
|
|
1677
|
+
"aria-label": "Model",
|
|
1678
|
+
value: C ?? S[0].id,
|
|
1679
|
+
onChange: (e) => w?.(e.target.value),
|
|
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",
|
|
1681
|
+
children: S.map((e) => /* @__PURE__ */ J("option", {
|
|
1682
|
+
value: e.id,
|
|
1683
|
+
children: [e.label ?? e.id, e.provider ? ` · ${e.provider}` : ""]
|
|
1684
|
+
}, e.id))
|
|
1685
|
+
}) : null] }), /* @__PURE__ */ q(Un, {
|
|
1686
|
+
status: F,
|
|
1687
|
+
disabled: c,
|
|
1688
|
+
onClick: F === "streaming" ? o : void 0
|
|
1689
|
+
})] })
|
|
1690
|
+
]
|
|
1691
|
+
})]
|
|
1606
1692
|
}),
|
|
1607
|
-
/* @__PURE__ */
|
|
1693
|
+
/* @__PURE__ */ q("span", {
|
|
1608
1694
|
hidden: !0,
|
|
1609
1695
|
"data-avatar-user": f ?? p,
|
|
1610
1696
|
"data-avatar-assistant": m ?? h
|
|
@@ -1612,10 +1698,10 @@ var Yn = e.forwardRef(({ className: t, messages: n = [], placeholder: r = "Type
|
|
|
1612
1698
|
]
|
|
1613
1699
|
});
|
|
1614
1700
|
});
|
|
1615
|
-
|
|
1701
|
+
$.displayName = "ChatbotEnhanced";
|
|
1616
1702
|
//#endregion
|
|
1617
1703
|
//#region src/FloatingChatbot.tsx
|
|
1618
|
-
function
|
|
1704
|
+
function Rr({ floatingConfig: t, headerExtra: n, ...r }) {
|
|
1619
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);
|
|
1620
1706
|
e.useEffect(() => {
|
|
1621
1707
|
let e = document.getElementById("floating-chatbot-portal");
|
|
@@ -1623,28 +1709,28 @@ function Xn({ floatingConfig: t, headerExtra: n, ...r }) {
|
|
|
1623
1709
|
e && e.parentNode && !e.hasChildNodes() && e.parentNode.removeChild(e);
|
|
1624
1710
|
};
|
|
1625
1711
|
}, []);
|
|
1626
|
-
let f = /* @__PURE__ */
|
|
1712
|
+
let f = /* @__PURE__ */ J(Vt, {
|
|
1627
1713
|
defaultOpen: a,
|
|
1628
|
-
children: [/* @__PURE__ */
|
|
1714
|
+
children: [/* @__PURE__ */ q(Wt, {
|
|
1629
1715
|
position: i,
|
|
1630
1716
|
size: l
|
|
1631
|
-
}), /* @__PURE__ */
|
|
1717
|
+
}), /* @__PURE__ */ q(Gt, {
|
|
1632
1718
|
title: c,
|
|
1633
1719
|
position: i,
|
|
1634
1720
|
width: o,
|
|
1635
1721
|
height: s,
|
|
1636
1722
|
headerExtra: n,
|
|
1637
|
-
children: /* @__PURE__ */
|
|
1723
|
+
children: /* @__PURE__ */ q($, {
|
|
1638
1724
|
...r,
|
|
1639
1725
|
maxHeight: "100%",
|
|
1640
1726
|
className: "h-full border-0 rounded-none"
|
|
1641
1727
|
})
|
|
1642
1728
|
})]
|
|
1643
1729
|
});
|
|
1644
|
-
return u ?
|
|
1730
|
+
return u ? ht.createPortal(f, u) : f;
|
|
1645
1731
|
}
|
|
1646
|
-
|
|
1647
|
-
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({
|
|
1648
1734
|
api: e.api,
|
|
1649
1735
|
initialMessages: e.messages,
|
|
1650
1736
|
conversationId: e.conversationId,
|
|
@@ -1661,7 +1747,7 @@ U.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
1661
1747
|
autoResponseDelay: e.autoResponseDelay,
|
|
1662
1748
|
onSend: e.onSend
|
|
1663
1749
|
});
|
|
1664
|
-
return /* @__PURE__ */
|
|
1750
|
+
return /* @__PURE__ */ q(ai, {
|
|
1665
1751
|
messages: r,
|
|
1666
1752
|
placeholder: e.placeholder,
|
|
1667
1753
|
onSendMessage: (e) => {
|
|
@@ -1809,8 +1895,8 @@ U.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
1809
1895
|
autoResponseDelay: 1e3,
|
|
1810
1896
|
className: "w-full max-w-2xl"
|
|
1811
1897
|
}
|
|
1812
|
-
}),
|
|
1813
|
-
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({
|
|
1814
1900
|
api: e.api,
|
|
1815
1901
|
initialMessages: e.messages,
|
|
1816
1902
|
conversationId: e.conversationId,
|
|
@@ -1827,7 +1913,7 @@ U.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
1827
1913
|
autoResponseDelay: e.autoResponseDelay,
|
|
1828
1914
|
onSend: e.onSend
|
|
1829
1915
|
});
|
|
1830
|
-
return /* @__PURE__ */
|
|
1916
|
+
return /* @__PURE__ */ q($, {
|
|
1831
1917
|
messages: r,
|
|
1832
1918
|
placeholder: e.placeholder,
|
|
1833
1919
|
onSendMessage: (e, t) => {
|
|
@@ -1989,8 +2075,8 @@ U.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
1989
2075
|
autoResponseDelay: 1e3,
|
|
1990
2076
|
className: "w-full max-w-2xl"
|
|
1991
2077
|
}
|
|
1992
|
-
}),
|
|
1993
|
-
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({
|
|
1994
2080
|
api: e.api,
|
|
1995
2081
|
initialMessages: e.messages,
|
|
1996
2082
|
conversationId: e.conversationId,
|
|
@@ -2007,7 +2093,7 @@ U.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
2007
2093
|
autoResponseDelay: e.autoResponseDelay,
|
|
2008
2094
|
onSend: e.onSend
|
|
2009
2095
|
});
|
|
2010
|
-
return /* @__PURE__ */
|
|
2096
|
+
return /* @__PURE__ */ q(Rr, {
|
|
2011
2097
|
floatingConfig: e.floatingConfig,
|
|
2012
2098
|
messages: r,
|
|
2013
2099
|
placeholder: e.placeholder,
|
|
@@ -2179,71 +2265,71 @@ U.register("chatbot", ({ schema: e, className: t, ...n }) => {
|
|
|
2179
2265
|
});
|
|
2180
2266
|
//#endregion
|
|
2181
2267
|
//#region src/elements/loader.tsx
|
|
2182
|
-
var
|
|
2268
|
+
var zr = ({ size: e = 16 }) => /* @__PURE__ */ J("svg", {
|
|
2183
2269
|
height: e,
|
|
2184
2270
|
strokeLinejoin: "round",
|
|
2185
2271
|
style: { color: "currentcolor" },
|
|
2186
2272
|
viewBox: "0 0 16 16",
|
|
2187
2273
|
width: e,
|
|
2188
2274
|
children: [
|
|
2189
|
-
/* @__PURE__ */
|
|
2190
|
-
/* @__PURE__ */
|
|
2275
|
+
/* @__PURE__ */ q("title", { children: "Loader" }),
|
|
2276
|
+
/* @__PURE__ */ J("g", {
|
|
2191
2277
|
clipPath: "url(#clip0_2393_1490)",
|
|
2192
2278
|
children: [
|
|
2193
|
-
/* @__PURE__ */
|
|
2279
|
+
/* @__PURE__ */ q("path", {
|
|
2194
2280
|
d: "M8 0V4",
|
|
2195
2281
|
stroke: "currentColor",
|
|
2196
2282
|
strokeWidth: "1.5"
|
|
2197
2283
|
}),
|
|
2198
|
-
/* @__PURE__ */
|
|
2284
|
+
/* @__PURE__ */ q("path", {
|
|
2199
2285
|
d: "M8 16V12",
|
|
2200
2286
|
opacity: "0.5",
|
|
2201
2287
|
stroke: "currentColor",
|
|
2202
2288
|
strokeWidth: "1.5"
|
|
2203
2289
|
}),
|
|
2204
|
-
/* @__PURE__ */
|
|
2290
|
+
/* @__PURE__ */ q("path", {
|
|
2205
2291
|
d: "M3.29773 1.52783L5.64887 4.7639",
|
|
2206
2292
|
opacity: "0.9",
|
|
2207
2293
|
stroke: "currentColor",
|
|
2208
2294
|
strokeWidth: "1.5"
|
|
2209
2295
|
}),
|
|
2210
|
-
/* @__PURE__ */
|
|
2296
|
+
/* @__PURE__ */ q("path", {
|
|
2211
2297
|
d: "M12.7023 1.52783L10.3511 4.7639",
|
|
2212
2298
|
opacity: "0.1",
|
|
2213
2299
|
stroke: "currentColor",
|
|
2214
2300
|
strokeWidth: "1.5"
|
|
2215
2301
|
}),
|
|
2216
|
-
/* @__PURE__ */
|
|
2302
|
+
/* @__PURE__ */ q("path", {
|
|
2217
2303
|
d: "M12.7023 14.472L10.3511 11.236",
|
|
2218
2304
|
opacity: "0.4",
|
|
2219
2305
|
stroke: "currentColor",
|
|
2220
2306
|
strokeWidth: "1.5"
|
|
2221
2307
|
}),
|
|
2222
|
-
/* @__PURE__ */
|
|
2308
|
+
/* @__PURE__ */ q("path", {
|
|
2223
2309
|
d: "M3.29773 14.472L5.64887 11.236",
|
|
2224
2310
|
opacity: "0.6",
|
|
2225
2311
|
stroke: "currentColor",
|
|
2226
2312
|
strokeWidth: "1.5"
|
|
2227
2313
|
}),
|
|
2228
|
-
/* @__PURE__ */
|
|
2314
|
+
/* @__PURE__ */ q("path", {
|
|
2229
2315
|
d: "M15.6085 5.52783L11.8043 6.7639",
|
|
2230
2316
|
opacity: "0.2",
|
|
2231
2317
|
stroke: "currentColor",
|
|
2232
2318
|
strokeWidth: "1.5"
|
|
2233
2319
|
}),
|
|
2234
|
-
/* @__PURE__ */
|
|
2320
|
+
/* @__PURE__ */ q("path", {
|
|
2235
2321
|
d: "M0.391602 10.472L4.19583 9.23598",
|
|
2236
2322
|
opacity: "0.7",
|
|
2237
2323
|
stroke: "currentColor",
|
|
2238
2324
|
strokeWidth: "1.5"
|
|
2239
2325
|
}),
|
|
2240
|
-
/* @__PURE__ */
|
|
2326
|
+
/* @__PURE__ */ q("path", {
|
|
2241
2327
|
d: "M15.6085 10.4722L11.8043 9.2361",
|
|
2242
2328
|
opacity: "0.3",
|
|
2243
2329
|
stroke: "currentColor",
|
|
2244
2330
|
strokeWidth: "1.5"
|
|
2245
2331
|
}),
|
|
2246
|
-
/* @__PURE__ */
|
|
2332
|
+
/* @__PURE__ */ q("path", {
|
|
2247
2333
|
d: "M0.391602 5.52783L4.19583 6.7639",
|
|
2248
2334
|
opacity: "0.8",
|
|
2249
2335
|
stroke: "currentColor",
|
|
@@ -2251,125 +2337,824 @@ var Zn = ({ size: e = 16 }) => /* @__PURE__ */ V("svg", {
|
|
|
2251
2337
|
})
|
|
2252
2338
|
]
|
|
2253
2339
|
}),
|
|
2254
|
-
/* @__PURE__ */
|
|
2340
|
+
/* @__PURE__ */ q("defs", { children: /* @__PURE__ */ q("clipPath", {
|
|
2255
2341
|
id: "clip0_2393_1490",
|
|
2256
|
-
children: /* @__PURE__ */
|
|
2342
|
+
children: /* @__PURE__ */ q("rect", {
|
|
2257
2343
|
fill: "white",
|
|
2258
2344
|
height: "16",
|
|
2259
2345
|
width: "16"
|
|
2260
2346
|
})
|
|
2261
2347
|
}) })
|
|
2262
2348
|
]
|
|
2263
|
-
}),
|
|
2264
|
-
className:
|
|
2349
|
+
}), Br = ({ className: e, size: t = 16, ...n }) => /* @__PURE__ */ q("div", {
|
|
2350
|
+
className: U("inline-flex animate-spin items-center justify-center", e),
|
|
2265
2351
|
...n,
|
|
2266
|
-
children: /* @__PURE__ */
|
|
2267
|
-
}),
|
|
2268
|
-
CodeBlock: () =>
|
|
2269
|
-
CodeBlockCopyButton: () =>
|
|
2270
|
-
Conversation: () =>
|
|
2271
|
-
ConversationContent: () =>
|
|
2272
|
-
ConversationEmptyState: () =>
|
|
2273
|
-
ConversationScrollButton: () =>
|
|
2274
|
-
Loader: () =>
|
|
2275
|
-
Message: () =>
|
|
2276
|
-
MessageAction: () =>
|
|
2277
|
-
MessageActions: () =>
|
|
2278
|
-
MessageAttachment: () =>
|
|
2279
|
-
MessageAttachments: () =>
|
|
2280
|
-
MessageBranch: () =>
|
|
2281
|
-
MessageBranchContent: () =>
|
|
2282
|
-
MessageBranchNext: () =>
|
|
2283
|
-
MessageBranchPage: () =>
|
|
2284
|
-
MessageBranchPrevious: () =>
|
|
2285
|
-
MessageBranchSelector: () =>
|
|
2286
|
-
MessageContent: () =>
|
|
2287
|
-
MessageResponse: () =>
|
|
2288
|
-
MessageToolbar: () =>
|
|
2289
|
-
PromptInput: () =>
|
|
2290
|
-
PromptInputActionAddAttachments: () =>
|
|
2291
|
-
PromptInputActionMenu: () =>
|
|
2292
|
-
PromptInputActionMenuContent: () =>
|
|
2293
|
-
PromptInputActionMenuItem: () =>
|
|
2294
|
-
PromptInputActionMenuTrigger: () =>
|
|
2295
|
-
PromptInputAttachment: () =>
|
|
2296
|
-
PromptInputAttachments: () =>
|
|
2297
|
-
PromptInputBody: () =>
|
|
2298
|
-
PromptInputButton: () =>
|
|
2299
|
-
PromptInputCommand: () =>
|
|
2300
|
-
PromptInputCommandEmpty: () =>
|
|
2301
|
-
PromptInputCommandGroup: () =>
|
|
2302
|
-
PromptInputCommandInput: () =>
|
|
2303
|
-
PromptInputCommandItem: () =>
|
|
2304
|
-
PromptInputCommandList: () =>
|
|
2305
|
-
PromptInputCommandSeparator: () =>
|
|
2306
|
-
PromptInputFooter: () =>
|
|
2307
|
-
PromptInputHeader: () =>
|
|
2308
|
-
PromptInputHoverCard: () =>
|
|
2309
|
-
PromptInputHoverCardContent: () =>
|
|
2310
|
-
PromptInputHoverCardTrigger: () =>
|
|
2311
|
-
PromptInputProvider: () =>
|
|
2312
|
-
PromptInputSelect: () =>
|
|
2313
|
-
PromptInputSelectContent: () =>
|
|
2314
|
-
PromptInputSelectItem: () =>
|
|
2315
|
-
PromptInputSelectTrigger: () =>
|
|
2316
|
-
PromptInputSelectValue: () =>
|
|
2317
|
-
PromptInputSpeechButton: () =>
|
|
2318
|
-
PromptInputSubmit: () =>
|
|
2319
|
-
PromptInputTab: () =>
|
|
2320
|
-
PromptInputTabBody: () =>
|
|
2321
|
-
PromptInputTabItem: () =>
|
|
2322
|
-
PromptInputTabLabel: () =>
|
|
2323
|
-
PromptInputTabsList: () =>
|
|
2324
|
-
PromptInputTextarea: () =>
|
|
2325
|
-
PromptInputTools: () =>
|
|
2326
|
-
Reasoning: () =>
|
|
2327
|
-
ReasoningContent: () =>
|
|
2328
|
-
ReasoningTrigger: () =>
|
|
2329
|
-
Shimmer: () =>
|
|
2330
|
-
Source: () =>
|
|
2331
|
-
Sources: () =>
|
|
2332
|
-
SourcesContent: () =>
|
|
2333
|
-
SourcesTrigger: () =>
|
|
2334
|
-
Suggestion: () =>
|
|
2335
|
-
Suggestions: () =>
|
|
2336
|
-
Tool: () =>
|
|
2337
|
-
ToolContent: () =>
|
|
2338
|
-
ToolHeader: () =>
|
|
2339
|
-
ToolInput: () =>
|
|
2340
|
-
ToolOutput: () =>
|
|
2341
|
-
highlightCode: () =>
|
|
2352
|
+
children: /* @__PURE__ */ q(zr, { size: t })
|
|
2353
|
+
}), Vr = /* @__PURE__ */ Ot({
|
|
2354
|
+
CodeBlock: () => Q,
|
|
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,
|
|
2342
2428
|
usePromptInputAttachments: () => Z,
|
|
2343
|
-
usePromptInputController: () =>
|
|
2344
|
-
useProviderAttachments: () =>
|
|
2345
|
-
useReasoning: () =>
|
|
2346
|
-
}),
|
|
2347
|
-
|
|
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);
|
|
2348
3133
|
e.useEffect(() => {
|
|
2349
|
-
if (
|
|
2350
|
-
let e =
|
|
3134
|
+
if (g.current) {
|
|
3135
|
+
let e = g.current.querySelector("[data-radix-scroll-area-viewport]");
|
|
2351
3136
|
e && (e.scrollTop = e.scrollHeight);
|
|
2352
3137
|
}
|
|
2353
3138
|
}, [n]);
|
|
2354
3139
|
let y = () => {
|
|
2355
|
-
m.trim() && i && (i(m.trim()), h(""),
|
|
3140
|
+
m.trim() && i && (i(m.trim()), h(""), _.current?.focus());
|
|
2356
3141
|
}, b = (e) => {
|
|
2357
3142
|
e.key === "Enter" && !e.shiftKey && (e.preventDefault(), y());
|
|
2358
3143
|
};
|
|
2359
|
-
return /* @__PURE__ */
|
|
3144
|
+
return /* @__PURE__ */ J("div", {
|
|
2360
3145
|
ref: p,
|
|
2361
|
-
className:
|
|
3146
|
+
className: U("flex flex-col border rounded-lg bg-background overflow-hidden", t),
|
|
2362
3147
|
style: { maxHeight: d },
|
|
2363
3148
|
...f,
|
|
2364
|
-
children: [/* @__PURE__ */
|
|
2365
|
-
ref:
|
|
3149
|
+
children: [/* @__PURE__ */ q(se, {
|
|
3150
|
+
ref: g,
|
|
2366
3151
|
className: "flex-1 p-4",
|
|
2367
|
-
children: /* @__PURE__ */
|
|
3152
|
+
children: /* @__PURE__ */ q("div", {
|
|
2368
3153
|
className: "space-y-4",
|
|
2369
|
-
children: n.length === 0 ? /* @__PURE__ */
|
|
3154
|
+
children: n.length === 0 ? /* @__PURE__ */ q("div", {
|
|
2370
3155
|
className: "flex items-center justify-center h-32 text-muted-foreground text-sm",
|
|
2371
3156
|
children: "No messages yet. Start a conversation!"
|
|
2372
|
-
}) : n.map((e) => /* @__PURE__ */
|
|
3157
|
+
}) : n.map((e) => /* @__PURE__ */ q(oi, {
|
|
2373
3158
|
message: e,
|
|
2374
3159
|
showTimestamp: o,
|
|
2375
3160
|
userAvatarUrl: s,
|
|
@@ -2378,83 +3163,83 @@ var Zn = ({ size: e = 16 }) => /* @__PURE__ */ V("svg", {
|
|
|
2378
3163
|
assistantAvatarFallback: u
|
|
2379
3164
|
}, e.id))
|
|
2380
3165
|
})
|
|
2381
|
-
}), /* @__PURE__ */
|
|
3166
|
+
}), /* @__PURE__ */ q("div", {
|
|
2382
3167
|
className: "border-t p-4",
|
|
2383
|
-
children: /* @__PURE__ */
|
|
3168
|
+
children: /* @__PURE__ */ J("div", {
|
|
2384
3169
|
className: "flex gap-2",
|
|
2385
|
-
children: [/* @__PURE__ */
|
|
2386
|
-
ref:
|
|
3170
|
+
children: [/* @__PURE__ */ q(oe, {
|
|
3171
|
+
ref: _,
|
|
2387
3172
|
value: m,
|
|
2388
3173
|
onChange: (e) => h(e.target.value),
|
|
2389
3174
|
onKeyDown: b,
|
|
2390
3175
|
placeholder: r,
|
|
2391
3176
|
disabled: a,
|
|
2392
3177
|
className: "flex-1"
|
|
2393
|
-
}), /* @__PURE__ */
|
|
3178
|
+
}), /* @__PURE__ */ q(v, {
|
|
2394
3179
|
onClick: y,
|
|
2395
3180
|
disabled: a || !m.trim(),
|
|
2396
3181
|
size: "icon",
|
|
2397
|
-
children: /* @__PURE__ */
|
|
3182
|
+
children: /* @__PURE__ */ q(ct, { className: "h-4 w-4" })
|
|
2398
3183
|
})]
|
|
2399
3184
|
})
|
|
2400
3185
|
})]
|
|
2401
3186
|
});
|
|
2402
3187
|
});
|
|
2403
|
-
|
|
2404
|
-
var
|
|
3188
|
+
ai.displayName = "Chatbot";
|
|
3189
|
+
var oi = ({ message: e, showTimestamp: t, userAvatarUrl: n, userAvatarFallback: r, assistantAvatarUrl: i, assistantAvatarFallback: a }) => {
|
|
2405
3190
|
let o = e.role === "user";
|
|
2406
|
-
if (e.role === "system") return /* @__PURE__ */
|
|
3191
|
+
if (e.role === "system") return /* @__PURE__ */ q("div", {
|
|
2407
3192
|
className: "flex justify-center",
|
|
2408
|
-
children: /* @__PURE__ */
|
|
3193
|
+
children: /* @__PURE__ */ q("div", {
|
|
2409
3194
|
className: "text-xs text-muted-foreground bg-muted px-3 py-1 rounded-full",
|
|
2410
3195
|
children: e.content
|
|
2411
3196
|
})
|
|
2412
3197
|
});
|
|
2413
3198
|
let s = o ? e.avatar || n : e.avatar || i, c = o ? e.avatarFallback || r : e.avatarFallback || a;
|
|
2414
|
-
return /* @__PURE__ */
|
|
2415
|
-
className:
|
|
2416
|
-
children: [/* @__PURE__ */
|
|
3199
|
+
return /* @__PURE__ */ J("div", {
|
|
3200
|
+
className: U("flex gap-3", o ? "flex-row-reverse" : "flex-row"),
|
|
3201
|
+
children: [/* @__PURE__ */ J(m, {
|
|
2417
3202
|
className: "h-8 w-8",
|
|
2418
|
-
children: [/* @__PURE__ */
|
|
3203
|
+
children: [/* @__PURE__ */ q(g, { src: s }), /* @__PURE__ */ q(h, {
|
|
2419
3204
|
className: "text-xs",
|
|
2420
3205
|
children: c
|
|
2421
3206
|
})]
|
|
2422
|
-
}), /* @__PURE__ */
|
|
2423
|
-
className:
|
|
2424
|
-
children: [/* @__PURE__ */
|
|
2425
|
-
className:
|
|
2426
|
-
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", {
|
|
2427
3212
|
className: "text-sm whitespace-pre-wrap",
|
|
2428
3213
|
children: e.content
|
|
2429
3214
|
})
|
|
2430
|
-
}), t && e.timestamp && /* @__PURE__ */
|
|
3215
|
+
}), t && e.timestamp && /* @__PURE__ */ q("span", {
|
|
2431
3216
|
className: "text-xs text-muted-foreground",
|
|
2432
3217
|
children: e.timestamp
|
|
2433
3218
|
})]
|
|
2434
3219
|
})]
|
|
2435
3220
|
});
|
|
2436
|
-
},
|
|
3221
|
+
}, si = e.forwardRef(({ className: e, avatarSrc: t, avatarFallback: n = "AI", ...r }, i) => /* @__PURE__ */ J("div", {
|
|
2437
3222
|
ref: i,
|
|
2438
|
-
className:
|
|
3223
|
+
className: U("flex gap-3", e),
|
|
2439
3224
|
...r,
|
|
2440
|
-
children: [/* @__PURE__ */
|
|
3225
|
+
children: [/* @__PURE__ */ J(m, {
|
|
2441
3226
|
className: "h-8 w-8",
|
|
2442
|
-
children: [/* @__PURE__ */
|
|
3227
|
+
children: [/* @__PURE__ */ q(g, { src: t }), /* @__PURE__ */ q(h, {
|
|
2443
3228
|
className: "text-xs",
|
|
2444
3229
|
children: n
|
|
2445
3230
|
})]
|
|
2446
|
-
}), /* @__PURE__ */
|
|
3231
|
+
}), /* @__PURE__ */ q("div", {
|
|
2447
3232
|
className: "flex items-center bg-muted rounded-lg px-4 py-2",
|
|
2448
|
-
children: /* @__PURE__ */
|
|
3233
|
+
children: /* @__PURE__ */ J("div", {
|
|
2449
3234
|
className: "flex gap-1",
|
|
2450
3235
|
children: [
|
|
2451
|
-
/* @__PURE__ */
|
|
2452
|
-
/* @__PURE__ */
|
|
2453
|
-
/* @__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" })
|
|
2454
3239
|
]
|
|
2455
3240
|
})
|
|
2456
3241
|
})]
|
|
2457
3242
|
}));
|
|
2458
|
-
|
|
3243
|
+
si.displayName = "TypingIndicator";
|
|
2459
3244
|
//#endregion
|
|
2460
|
-
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 };
|