@constructive-io/ui 0.6.1 → 0.9.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/dist/ai-CiaH2sfF.js +2840 -0
- package/dist/ai-CiaH2sfF.js.map +1 -0
- package/dist/ai-lAkichk8.cjs +3182 -0
- package/dist/ai-lAkichk8.cjs.map +1 -0
- package/dist/alert-BXuP0ayz.d.cts +19 -0
- package/dist/alert-BXuP0ayz.d.ts +19 -0
- package/dist/components/ai/index.cjs +61 -0
- package/dist/components/ai/index.d.cts +2 -0
- package/dist/components/ai/index.d.ts +2 -0
- package/dist/components/ai/index.js +4 -0
- package/dist/components/alert.d.cts +2 -19
- package/dist/components/alert.d.ts +2 -19
- package/dist/components/app-bar.cjs +1 -1
- package/dist/components/app-bar.js +1 -1
- package/dist/components/app-shell.cjs +1 -1
- package/dist/components/app-shell.js +1 -1
- package/dist/components/badge.d.cts +2 -2
- package/dist/components/badge.d.ts +2 -2
- package/dist/components/command.cjs +1 -1
- package/dist/components/command.cjs.map +1 -1
- package/dist/components/command.js +1 -1
- package/dist/components/command.js.map +1 -1
- package/dist/components/field.d.cts +1 -1
- package/dist/components/field.d.ts +1 -1
- package/dist/components/sheet.d.cts +1 -1
- package/dist/components/sheet.d.ts +1 -1
- package/dist/components/sidebar.cjs +1 -1
- package/dist/components/sidebar.d.cts +1 -1
- package/dist/components/sidebar.d.ts +1 -1
- package/dist/components/sidebar.js +1 -1
- package/dist/index-B0wXxIAb.d.ts +737 -0
- package/dist/index-CyaFaZe2.d.cts +737 -0
- package/dist/index.cjs +59 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/{sidebar-CPy_fibW.cjs → sidebar-BavjjJp0.cjs} +29 -12
- package/dist/sidebar-BavjjJp0.cjs.map +1 -0
- package/dist/{sidebar-Cfax0g0_.js → sidebar-DeoL2ttp.js} +30 -12
- package/dist/sidebar-DeoL2ttp.js.map +1 -0
- package/package.json +13 -2
- package/src/styles/globals.css +92 -0
- package/dist/sidebar-CPy_fibW.cjs.map +0 -1
- package/dist/sidebar-Cfax0g0_.js.map +0 -1
|
@@ -0,0 +1,2840 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { t as cn } from "./utils-BkMLyah9.js";
|
|
3
|
+
import { Button } from "./components/button.js";
|
|
4
|
+
import { Badge } from "./components/badge.js";
|
|
5
|
+
import { Alert, AlertDescription, AlertTitle } from "./components/alert.js";
|
|
6
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./components/tooltip.js";
|
|
7
|
+
import { Collapsible, CollapsibleContent as CollapsiblePanel, CollapsibleTrigger } from "./components/collapsible.js";
|
|
8
|
+
import { Avatar, AvatarFallback, AvatarImage } from "./components/avatar.js";
|
|
9
|
+
import * as React$1 from "react";
|
|
10
|
+
import { useEffect, useRef, useState } from "react";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { ArrowDown, ArrowUp, Brain, Check, CheckCircle2, ChevronDown, Circle, CircleDashed, CircleX, Copy, ExternalLink, FileCode2, FileText, Globe, ListChecks, Loader2, Paperclip, RefreshCw, RotateCcw, Settings2, Sparkles, Terminal, ThumbsDown, ThumbsUp, Upload, Wrench, X } from "lucide-react";
|
|
13
|
+
import { highlight } from "sugar-high";
|
|
14
|
+
import { c, css, diff, go, java, python, rust } from "sugar-high/presets";
|
|
15
|
+
|
|
16
|
+
//#region src/components/ai/text-shimmer.tsx
|
|
17
|
+
/**
|
|
18
|
+
* Sweeping-gradient status text for in-flight agent states.
|
|
19
|
+
* CSS-only animation so it does not re-render on a timer.
|
|
20
|
+
*/
|
|
21
|
+
function TextShimmer({ className, active = true, children, ...props }) {
|
|
22
|
+
return /* @__PURE__ */ jsx("span", {
|
|
23
|
+
"data-slot": "text-shimmer",
|
|
24
|
+
"data-active": active ? "true" : "false",
|
|
25
|
+
className: cn("inline-block font-medium", active ? [
|
|
26
|
+
"bg-[linear-gradient(90deg,var(--muted-foreground)_35%,var(--foreground)_50%,var(--muted-foreground)_65%)]",
|
|
27
|
+
"bg-size-[200%_100%] bg-clip-text text-transparent",
|
|
28
|
+
"animate-[ai-shimmer-text_1.4s_linear_infinite]",
|
|
29
|
+
"motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-muted-foreground"
|
|
30
|
+
] : "text-muted-foreground", className),
|
|
31
|
+
...props,
|
|
32
|
+
children
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/components/ai/agent-loader.tsx
|
|
38
|
+
const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
39
|
+
function subscribeToReducedMotion(onStoreChange) {
|
|
40
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return () => void 0;
|
|
41
|
+
const mediaQuery = window.matchMedia(REDUCED_MOTION_QUERY);
|
|
42
|
+
mediaQuery.addEventListener("change", onStoreChange);
|
|
43
|
+
return () => mediaQuery.removeEventListener("change", onStoreChange);
|
|
44
|
+
}
|
|
45
|
+
function getReducedMotionSnapshot() {
|
|
46
|
+
return typeof window === "undefined" || typeof window.matchMedia !== "function" ? true : window.matchMedia(REDUCED_MOTION_QUERY).matches;
|
|
47
|
+
}
|
|
48
|
+
/** Chevron wavefront across a 3×3 grid (Drive / Dots). */
|
|
49
|
+
const chevronDelays = Array.from({ length: 9 }, (_, i) => {
|
|
50
|
+
const r = Math.floor(i / 3);
|
|
51
|
+
return (i % 3 + Math.abs(r - 1)) * 90;
|
|
52
|
+
});
|
|
53
|
+
const ORBIT_ORDER = [
|
|
54
|
+
0,
|
|
55
|
+
1,
|
|
56
|
+
2,
|
|
57
|
+
5,
|
|
58
|
+
8,
|
|
59
|
+
7,
|
|
60
|
+
6,
|
|
61
|
+
3
|
|
62
|
+
];
|
|
63
|
+
const orbitDelays = Array.from({ length: 9 }, (_, i) => {
|
|
64
|
+
const k = ORBIT_ORDER.indexOf(i);
|
|
65
|
+
return k === -1 ? null : k * 110;
|
|
66
|
+
});
|
|
67
|
+
const PIXEL_PATTERNS = {
|
|
68
|
+
drive: {
|
|
69
|
+
delays: chevronDelays,
|
|
70
|
+
durationMs: 650,
|
|
71
|
+
round: false
|
|
72
|
+
},
|
|
73
|
+
dots: {
|
|
74
|
+
delays: chevronDelays,
|
|
75
|
+
durationMs: 650,
|
|
76
|
+
round: true
|
|
77
|
+
},
|
|
78
|
+
orbit: {
|
|
79
|
+
delays: orbitDelays,
|
|
80
|
+
durationMs: 950,
|
|
81
|
+
round: false
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function formatElapsed(totalSeconds) {
|
|
85
|
+
if (totalSeconds < 60) return `${totalSeconds.toFixed(1)}s`;
|
|
86
|
+
return `${Math.floor(totalSeconds / 60)}m ${(totalSeconds % 60).toFixed(1)}s`;
|
|
87
|
+
}
|
|
88
|
+
function useElapsedSeconds(enabled, controlledMs) {
|
|
89
|
+
const [ticks, setTicks] = React$1.useState(0);
|
|
90
|
+
React$1.useEffect(() => {
|
|
91
|
+
if (!enabled || controlledMs !== void 0) return;
|
|
92
|
+
const id = window.setInterval(() => setTicks((value) => value + 1), 100);
|
|
93
|
+
return () => window.clearInterval(id);
|
|
94
|
+
}, [enabled, controlledMs]);
|
|
95
|
+
if (controlledMs !== void 0) return controlledMs / 1e3;
|
|
96
|
+
return ticks / 10;
|
|
97
|
+
}
|
|
98
|
+
function PixelGrid({ variant, reducedMotion }) {
|
|
99
|
+
const { delays, durationMs, round } = PIXEL_PATTERNS[variant];
|
|
100
|
+
return /* @__PURE__ */ jsx("span", {
|
|
101
|
+
"aria-hidden": true,
|
|
102
|
+
className: "grid grid-cols-[repeat(3,4px)] gap-[1.5px]",
|
|
103
|
+
children: delays.map((delay, index) => /* @__PURE__ */ jsx("span", {
|
|
104
|
+
className: cn("size-1 bg-foreground", round ? "rounded-full" : "rounded-[1px]"),
|
|
105
|
+
style: {
|
|
106
|
+
opacity: delay === null ? .07 : .15,
|
|
107
|
+
animation: reducedMotion || delay === null ? "none" : `ai-pixel-on ${durationMs}ms ease-in-out ${delay}ms infinite`
|
|
108
|
+
}
|
|
109
|
+
}, index))
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function sizeClass(size) {
|
|
113
|
+
return {
|
|
114
|
+
sm: "size-4",
|
|
115
|
+
md: "size-5",
|
|
116
|
+
lg: "size-6"
|
|
117
|
+
}[size];
|
|
118
|
+
}
|
|
119
|
+
function CircularLoader({ size, className }) {
|
|
120
|
+
return /* @__PURE__ */ jsx("span", {
|
|
121
|
+
className: cn("inline-block animate-spin rounded-full border-2 border-primary border-t-transparent motion-reduce:animate-none", sizeClass(size), className),
|
|
122
|
+
"aria-hidden": true
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function DotsBounce({ size, className }) {
|
|
126
|
+
const dot = {
|
|
127
|
+
sm: "size-1.5",
|
|
128
|
+
md: "size-2",
|
|
129
|
+
lg: "size-2.5"
|
|
130
|
+
}[size];
|
|
131
|
+
return /* @__PURE__ */ jsx("span", {
|
|
132
|
+
className: cn("inline-flex items-center gap-1", className),
|
|
133
|
+
"aria-hidden": true,
|
|
134
|
+
children: [
|
|
135
|
+
0,
|
|
136
|
+
1,
|
|
137
|
+
2
|
|
138
|
+
].map((i) => /* @__PURE__ */ jsx("span", {
|
|
139
|
+
className: cn("rounded-full bg-primary animate-[ai-bounce-dots_1.4s_ease-in-out_infinite] motion-reduce:animate-none", dot),
|
|
140
|
+
style: { animationDelay: `${i * 160}ms` }
|
|
141
|
+
}, i))
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function TypingLoader({ size, className }) {
|
|
145
|
+
const dot = {
|
|
146
|
+
sm: "size-1",
|
|
147
|
+
md: "size-1.5",
|
|
148
|
+
lg: "size-2"
|
|
149
|
+
}[size];
|
|
150
|
+
return /* @__PURE__ */ jsx("span", {
|
|
151
|
+
className: cn("inline-flex items-center gap-1", className),
|
|
152
|
+
"aria-hidden": true,
|
|
153
|
+
children: [
|
|
154
|
+
0,
|
|
155
|
+
1,
|
|
156
|
+
2
|
|
157
|
+
].map((i) => /* @__PURE__ */ jsx("span", {
|
|
158
|
+
className: cn("rounded-full bg-primary animate-[ai-typing_1s_infinite] motion-reduce:animate-none", dot),
|
|
159
|
+
style: { animationDelay: `${i * 250}ms` }
|
|
160
|
+
}, i))
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function WaveLoader({ size, className }) {
|
|
164
|
+
const heights = {
|
|
165
|
+
sm: [
|
|
166
|
+
"6px",
|
|
167
|
+
"9px",
|
|
168
|
+
"12px",
|
|
169
|
+
"9px",
|
|
170
|
+
"6px"
|
|
171
|
+
],
|
|
172
|
+
md: [
|
|
173
|
+
"8px",
|
|
174
|
+
"12px",
|
|
175
|
+
"16px",
|
|
176
|
+
"12px",
|
|
177
|
+
"8px"
|
|
178
|
+
],
|
|
179
|
+
lg: [
|
|
180
|
+
"10px",
|
|
181
|
+
"15px",
|
|
182
|
+
"20px",
|
|
183
|
+
"15px",
|
|
184
|
+
"10px"
|
|
185
|
+
]
|
|
186
|
+
}[size];
|
|
187
|
+
return /* @__PURE__ */ jsx("span", {
|
|
188
|
+
className: cn("inline-flex items-center gap-0.5", sizeClass(size), className),
|
|
189
|
+
"aria-hidden": true,
|
|
190
|
+
children: heights.map((height, i) => /* @__PURE__ */ jsx("span", {
|
|
191
|
+
className: "w-0.5 rounded-full bg-primary animate-[ai-wave_1s_ease-in-out_infinite] motion-reduce:animate-none",
|
|
192
|
+
style: {
|
|
193
|
+
height,
|
|
194
|
+
animationDelay: `${i * 100}ms`
|
|
195
|
+
}
|
|
196
|
+
}, i))
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function PulseDot({ size, className }) {
|
|
200
|
+
const dot = {
|
|
201
|
+
sm: "size-1",
|
|
202
|
+
md: "size-2",
|
|
203
|
+
lg: "size-3"
|
|
204
|
+
}[size];
|
|
205
|
+
return /* @__PURE__ */ jsx("span", {
|
|
206
|
+
className: cn("inline-block rounded-full bg-primary animate-[ai-pulse-dot_1.2s_ease-in-out_infinite] motion-reduce:animate-none", dot, className),
|
|
207
|
+
"aria-hidden": true
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Agent loading indicator. Pixel variants (drive / dots / orbit) match the
|
|
212
|
+
* Beautiful UI craft; simple variants cover common chat spinners.
|
|
213
|
+
*/
|
|
214
|
+
function AgentLoader({ variant = "drive", label = "Working", showElapsed = true, elapsedMs, size = "md", className, text }) {
|
|
215
|
+
const reducedMotion = React$1.useSyncExternalStore(subscribeToReducedMotion, getReducedMotionSnapshot, () => true);
|
|
216
|
+
const isPixel = variant === "drive" || variant === "dots" || variant === "orbit";
|
|
217
|
+
const elapsed = useElapsedSeconds(isPixel && showElapsed, elapsedMs);
|
|
218
|
+
const statusText = text ?? label;
|
|
219
|
+
if (isPixel) return /* @__PURE__ */ jsxs("span", {
|
|
220
|
+
"data-slot": "agent-loader",
|
|
221
|
+
"data-variant": variant,
|
|
222
|
+
role: "status",
|
|
223
|
+
"aria-live": "polite",
|
|
224
|
+
className: cn("inline-flex w-fit items-center gap-2.5", className),
|
|
225
|
+
children: [
|
|
226
|
+
/* @__PURE__ */ jsx(PixelGrid, {
|
|
227
|
+
variant,
|
|
228
|
+
reducedMotion
|
|
229
|
+
}),
|
|
230
|
+
/* @__PURE__ */ jsx(TextShimmer, {
|
|
231
|
+
className: "text-[13px]",
|
|
232
|
+
children: statusText
|
|
233
|
+
}),
|
|
234
|
+
showElapsed ? /* @__PURE__ */ jsx("span", {
|
|
235
|
+
className: "font-mono text-xs tabular-nums text-muted-foreground",
|
|
236
|
+
children: formatElapsed(elapsed)
|
|
237
|
+
}) : null,
|
|
238
|
+
/* @__PURE__ */ jsxs("span", {
|
|
239
|
+
className: "sr-only",
|
|
240
|
+
children: [statusText, showElapsed ? `, ${formatElapsed(elapsed)}` : ""]
|
|
241
|
+
})
|
|
242
|
+
]
|
|
243
|
+
});
|
|
244
|
+
if (variant === "text-shimmer") return /* @__PURE__ */ jsx("span", {
|
|
245
|
+
"data-slot": "agent-loader",
|
|
246
|
+
role: "status",
|
|
247
|
+
className: cn("inline-flex", className),
|
|
248
|
+
children: /* @__PURE__ */ jsx(TextShimmer, {
|
|
249
|
+
className: cn(size === "sm" && "text-xs", size === "lg" && "text-base"),
|
|
250
|
+
children: statusText
|
|
251
|
+
})
|
|
252
|
+
});
|
|
253
|
+
if (variant === "loading-dots") return /* @__PURE__ */ jsxs("span", {
|
|
254
|
+
"data-slot": "agent-loader",
|
|
255
|
+
role: "status",
|
|
256
|
+
className: cn("inline-flex items-center gap-0.5 font-medium text-primary", className),
|
|
257
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
258
|
+
className: cn(size === "sm" && "text-xs", size === "md" && "text-sm", size === "lg" && "text-base"),
|
|
259
|
+
children: statusText
|
|
260
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
261
|
+
"aria-hidden": true,
|
|
262
|
+
className: "inline-flex",
|
|
263
|
+
children: [
|
|
264
|
+
0,
|
|
265
|
+
1,
|
|
266
|
+
2
|
|
267
|
+
].map((i) => /* @__PURE__ */ jsx("span", {
|
|
268
|
+
className: "animate-[ai-loading-dots_1.4s_infinite] motion-reduce:animate-none",
|
|
269
|
+
style: { animationDelay: `${(i + 1) * .2}s` },
|
|
270
|
+
children: "."
|
|
271
|
+
}, i))
|
|
272
|
+
})]
|
|
273
|
+
});
|
|
274
|
+
const indicator = variant === "circular" ? /* @__PURE__ */ jsx(CircularLoader, { size }) : variant === "bounce-dots" ? /* @__PURE__ */ jsx(DotsBounce, { size }) : variant === "typing" ? /* @__PURE__ */ jsx(TypingLoader, { size }) : variant === "wave" ? /* @__PURE__ */ jsx(WaveLoader, { size }) : /* @__PURE__ */ jsx(PulseDot, { size });
|
|
275
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
276
|
+
"data-slot": "agent-loader",
|
|
277
|
+
"data-variant": variant,
|
|
278
|
+
role: "status",
|
|
279
|
+
"aria-live": "polite",
|
|
280
|
+
className: cn("inline-flex items-center gap-2", className),
|
|
281
|
+
children: [indicator, statusText ? /* @__PURE__ */ jsx("span", {
|
|
282
|
+
className: "sr-only",
|
|
283
|
+
children: statusText
|
|
284
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
285
|
+
className: "sr-only",
|
|
286
|
+
children: "Loading"
|
|
287
|
+
})]
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/** @deprecated Prefer AgentLoader — alias kept for prompt-kit familiarity. */
|
|
291
|
+
const Loader = AgentLoader;
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/components/ai/prompt-input.tsx
|
|
295
|
+
const PromptInputContext = React$1.createContext(null);
|
|
296
|
+
function usePromptInput() {
|
|
297
|
+
const context = React$1.useContext(PromptInputContext);
|
|
298
|
+
if (!context) throw new Error("PromptInput compound parts must be used within <PromptInput>.");
|
|
299
|
+
return context;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Compound chat composer shell. Host owns submit/streaming; this owns layout,
|
|
303
|
+
* autosize context, and action slots.
|
|
304
|
+
*/
|
|
305
|
+
function PromptInput({ className, isLoading = false, maxHeight = 240, value, onValueChange, onSubmit, children, disabled = false, shape = "default", onClick, ...props }) {
|
|
306
|
+
const [internalValue, setInternalValue] = React$1.useState(value ?? "");
|
|
307
|
+
const textareaRef = React$1.useRef(null);
|
|
308
|
+
React$1.useEffect(() => {
|
|
309
|
+
if (value !== void 0) setInternalValue(value);
|
|
310
|
+
}, [value]);
|
|
311
|
+
const handleChange = React$1.useCallback((next) => {
|
|
312
|
+
setInternalValue(next);
|
|
313
|
+
onValueChange?.(next);
|
|
314
|
+
}, [onValueChange]);
|
|
315
|
+
const handleClick = (event) => {
|
|
316
|
+
if (!disabled) textareaRef.current?.focus();
|
|
317
|
+
onClick?.(event);
|
|
318
|
+
};
|
|
319
|
+
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(PromptInputContext.Provider, {
|
|
320
|
+
value: {
|
|
321
|
+
isLoading,
|
|
322
|
+
value: value ?? internalValue,
|
|
323
|
+
setValue: onValueChange ?? handleChange,
|
|
324
|
+
maxHeight,
|
|
325
|
+
onSubmit,
|
|
326
|
+
disabled: disabled || isLoading,
|
|
327
|
+
textareaRef
|
|
328
|
+
},
|
|
329
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
330
|
+
"data-slot": "prompt-input",
|
|
331
|
+
"data-shape": shape,
|
|
332
|
+
"data-loading": isLoading ? "true" : "false",
|
|
333
|
+
onClick: handleClick,
|
|
334
|
+
className: cn("cursor-text border border-input bg-background p-2 shadow-xs", "transition-shadow focus-within:border-primary/60 focus-within:ring-[3px] focus-within:ring-primary/35", shape === "pill" ? "rounded-3xl" : "rounded-xl", disabled && "cursor-not-allowed opacity-60", className),
|
|
335
|
+
...props,
|
|
336
|
+
children
|
|
337
|
+
})
|
|
338
|
+
}) });
|
|
339
|
+
}
|
|
340
|
+
function PromptInputTextarea({ className, onKeyDown, disableAutosize = false, ...props }) {
|
|
341
|
+
const { value, setValue, maxHeight, onSubmit, disabled, textareaRef } = usePromptInput();
|
|
342
|
+
const adjustHeight = React$1.useCallback((element) => {
|
|
343
|
+
if (!element || disableAutosize) return;
|
|
344
|
+
element.style.height = "auto";
|
|
345
|
+
if (typeof maxHeight === "number") element.style.height = `${Math.min(element.scrollHeight, maxHeight)}px`;
|
|
346
|
+
else element.style.height = `min(${element.scrollHeight}px, ${maxHeight})`;
|
|
347
|
+
}, [disableAutosize, maxHeight]);
|
|
348
|
+
const setRefs = React$1.useCallback((element) => {
|
|
349
|
+
textareaRef.current = element;
|
|
350
|
+
adjustHeight(element);
|
|
351
|
+
}, [adjustHeight, textareaRef]);
|
|
352
|
+
React$1.useLayoutEffect(() => {
|
|
353
|
+
adjustHeight(textareaRef.current);
|
|
354
|
+
}, [
|
|
355
|
+
adjustHeight,
|
|
356
|
+
textareaRef,
|
|
357
|
+
value
|
|
358
|
+
]);
|
|
359
|
+
const handleKeyDown = (event) => {
|
|
360
|
+
if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
|
|
361
|
+
event.preventDefault();
|
|
362
|
+
onSubmit?.();
|
|
363
|
+
}
|
|
364
|
+
onKeyDown?.(event);
|
|
365
|
+
};
|
|
366
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
367
|
+
ref: setRefs,
|
|
368
|
+
"data-slot": "prompt-input-textarea",
|
|
369
|
+
value,
|
|
370
|
+
onChange: (event) => {
|
|
371
|
+
adjustHeight(event.target);
|
|
372
|
+
setValue(event.target.value);
|
|
373
|
+
},
|
|
374
|
+
onKeyDown: handleKeyDown,
|
|
375
|
+
disabled,
|
|
376
|
+
rows: 1,
|
|
377
|
+
className: cn("min-h-11 w-full resize-none border-none bg-transparent px-2 py-1.5 text-sm outline-none", "placeholder:text-muted-foreground disabled:cursor-not-allowed", className),
|
|
378
|
+
...props
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
function PromptInputActions({ className, ...props }) {
|
|
382
|
+
return /* @__PURE__ */ jsx("div", {
|
|
383
|
+
"data-slot": "prompt-input-actions",
|
|
384
|
+
className: cn("flex items-center gap-1.5 px-1", className),
|
|
385
|
+
...props
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
function PromptInputAction({ tooltip, children, className, side = "top", ...props }) {
|
|
389
|
+
const { disabled } = usePromptInput();
|
|
390
|
+
return /* @__PURE__ */ jsxs(Tooltip, {
|
|
391
|
+
...props,
|
|
392
|
+
children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
393
|
+
asChild: true,
|
|
394
|
+
onClick: (event) => event.stopPropagation(),
|
|
395
|
+
disabled,
|
|
396
|
+
children
|
|
397
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
398
|
+
side,
|
|
399
|
+
className,
|
|
400
|
+
children: tooltip
|
|
401
|
+
})]
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function PromptInputBody({ className, ...props }) {
|
|
405
|
+
return /* @__PURE__ */ jsx("div", {
|
|
406
|
+
"data-slot": "prompt-input-body",
|
|
407
|
+
className: cn("flex min-w-0 flex-col gap-1", className),
|
|
408
|
+
...props
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/components/ai/use-throttled-text.ts
|
|
414
|
+
/** Default stream throttle (~15fps) — bounds markdown re-parse cost. */
|
|
415
|
+
const STREAM_THROTTLE_MS = 66;
|
|
416
|
+
/**
|
|
417
|
+
* Throttle `text` updates while `streaming` is true; flush immediately when
|
|
418
|
+
* streaming ends so settled content is never delayed.
|
|
419
|
+
*/
|
|
420
|
+
function useThrottledText(text, streaming, intervalMs = 66) {
|
|
421
|
+
const [throttled, setThrottled] = useState(text);
|
|
422
|
+
const latest = useRef(text);
|
|
423
|
+
latest.current = text;
|
|
424
|
+
const lastFlush = useRef(0);
|
|
425
|
+
const timer = useRef(null);
|
|
426
|
+
useEffect(() => {
|
|
427
|
+
if (!streaming) {
|
|
428
|
+
if (timer.current) {
|
|
429
|
+
clearTimeout(timer.current);
|
|
430
|
+
timer.current = null;
|
|
431
|
+
}
|
|
432
|
+
setThrottled((prev) => prev === text ? prev : text);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const now = Date.now();
|
|
436
|
+
const elapsed = now - lastFlush.current;
|
|
437
|
+
if (elapsed >= intervalMs) {
|
|
438
|
+
lastFlush.current = now;
|
|
439
|
+
setThrottled(text);
|
|
440
|
+
} else if (timer.current == null) timer.current = setTimeout(() => {
|
|
441
|
+
timer.current = null;
|
|
442
|
+
lastFlush.current = Date.now();
|
|
443
|
+
setThrottled(latest.current);
|
|
444
|
+
}, intervalMs - elapsed);
|
|
445
|
+
}, [
|
|
446
|
+
text,
|
|
447
|
+
streaming,
|
|
448
|
+
intervalMs
|
|
449
|
+
]);
|
|
450
|
+
useEffect(() => () => {
|
|
451
|
+
if (timer.current) clearTimeout(timer.current);
|
|
452
|
+
}, []);
|
|
453
|
+
return throttled;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/components/ai/markdown.tsx
|
|
458
|
+
function escapeHtml(value) {
|
|
459
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Lightweight markdown → HTML without hard deps.
|
|
463
|
+
* Handles paragraphs, bold, italic, inline code, fenced code, links, lists.
|
|
464
|
+
* Hosts that need full GFM can pass pre-rendered HTML via a future `html` prop
|
|
465
|
+
* or wrap with their own marked+DOMPurify pipeline.
|
|
466
|
+
*/
|
|
467
|
+
function renderBasicMarkdown(source) {
|
|
468
|
+
const fences = [];
|
|
469
|
+
let text = source.replace(/```([\w-]*)\n?([\s\S]*?)```/g, (_match, lang, code) => {
|
|
470
|
+
const index = fences.length;
|
|
471
|
+
const language = lang ? ` data-language="${escapeHtml(lang)}"` : "";
|
|
472
|
+
fences.push(`<pre class="ai-md-pre" data-slot="markdown-pre"${language}><code>${escapeHtml(code.replace(/\n$/, ""))}</code></pre>`);
|
|
473
|
+
return `\u0000FENCE${index}\u0000`;
|
|
474
|
+
});
|
|
475
|
+
text = escapeHtml(text);
|
|
476
|
+
text = text.replace(/`([^`\n]+)`/g, "<code class=\"ai-md-code\">$1</code>");
|
|
477
|
+
text = text.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
|
|
478
|
+
text = text.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g, "<em>$1</em>");
|
|
479
|
+
text = text.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, "<a href=\"$2\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ai-md-link\">$1</a>");
|
|
480
|
+
const lines = text.split("\n");
|
|
481
|
+
const html = [];
|
|
482
|
+
let listOpen = null;
|
|
483
|
+
const closeList = () => {
|
|
484
|
+
if (listOpen) {
|
|
485
|
+
html.push(`</${listOpen}>`);
|
|
486
|
+
listOpen = null;
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
for (const line of lines) {
|
|
490
|
+
const unordered = line.match(/^[-*]\s+(.+)$/);
|
|
491
|
+
const ordered = line.match(/^\d+\.\s+(.+)$/);
|
|
492
|
+
const heading = line.match(/^(#{1,3})\s+(.+)$/);
|
|
493
|
+
if (unordered) {
|
|
494
|
+
if (listOpen !== "ul") {
|
|
495
|
+
closeList();
|
|
496
|
+
html.push("<ul class=\"ai-md-list\">");
|
|
497
|
+
listOpen = "ul";
|
|
498
|
+
}
|
|
499
|
+
html.push(`<li>${unordered[1]}</li>`);
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
if (ordered) {
|
|
503
|
+
if (listOpen !== "ol") {
|
|
504
|
+
closeList();
|
|
505
|
+
html.push("<ol class=\"ai-md-list\">");
|
|
506
|
+
listOpen = "ol";
|
|
507
|
+
}
|
|
508
|
+
html.push(`<li>${ordered[1]}</li>`);
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
closeList();
|
|
512
|
+
if (heading) {
|
|
513
|
+
const level = heading[1].length;
|
|
514
|
+
html.push(`<h${level} class="ai-md-h">${heading[2]}</h${level}>`);
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (line.trim() === "") {
|
|
518
|
+
html.push("");
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (line.includes("\0FENCE")) {
|
|
522
|
+
html.push(line.replace(/\u0000FENCE(\d+)\u0000/g, (_m, i) => fences[Number(i)] ?? ""));
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
html.push(`<p class="ai-md-p">${line}</p>`);
|
|
526
|
+
}
|
|
527
|
+
closeList();
|
|
528
|
+
return html.join("\n").replace(/\u0000FENCE(\d+)\u0000/g, (_m, i) => fences[Number(i)] ?? "");
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Markdown renderer for assistant messages. Throttles while streaming.
|
|
532
|
+
* Uses a zero-dependency subset suitable for most agent replies; swap for a
|
|
533
|
+
* host-level marked pipeline when you need tables/footnotes.
|
|
534
|
+
*/
|
|
535
|
+
function Markdown({ className, children, streaming = false, ...props }) {
|
|
536
|
+
const text = useThrottledText(children, streaming);
|
|
537
|
+
const html = React$1.useMemo(() => renderBasicMarkdown(text), [text]);
|
|
538
|
+
return /* @__PURE__ */ jsx("div", {
|
|
539
|
+
"data-slot": "markdown",
|
|
540
|
+
"data-streaming": streaming ? "true" : "false",
|
|
541
|
+
className: cn("ai-markdown max-w-none space-y-3 break-words text-sm leading-relaxed text-foreground", "[&_.ai-md-p]:my-0", "[&_.ai-md-h]:font-semibold", "[&_h1.ai-md-h]:text-lg [&_h2.ai-md-h]:text-base [&_h3.ai-md-h]:text-sm", "[&_.ai-md-list]:my-1 [&_.ai-md-list]:list-disc [&_.ai-md-list]:space-y-1 [&_.ai-md-list]:pl-5", "[&_ol.ai-md-list]:list-decimal", "[&_.ai-md-code]:rounded-md [&_.ai-md-code]:bg-muted [&_.ai-md-code]:px-1 [&_.ai-md-code]:py-0.5 [&_.ai-md-code]:font-mono [&_.ai-md-code]:text-[0.85em]", "[&_.ai-md-pre]:overflow-x-auto [&_.ai-md-pre]:rounded-lg [&_.ai-md-pre]:border [&_.ai-md-pre]:border-border [&_.ai-md-pre]:bg-muted/50 [&_.ai-md-pre]:p-3 [&_.ai-md-pre]:font-mono [&_.ai-md-pre]:text-xs", "[&_.ai-md-link]:text-primary [&_.ai-md-link]:underline-offset-2 hover:[&_.ai-md-link]:underline", className),
|
|
542
|
+
dangerouslySetInnerHTML: { __html: html },
|
|
543
|
+
...props
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/components/ai/message.tsx
|
|
549
|
+
function Message({ className, from, ...props }) {
|
|
550
|
+
return /* @__PURE__ */ jsx("div", {
|
|
551
|
+
"data-slot": "message",
|
|
552
|
+
"data-from": from,
|
|
553
|
+
className: cn("flex w-full gap-3", from === "user" && "justify-end [&_[data-slot=message-content]]:rounded-2xl [&_[data-slot=message-content]]:bg-secondary [&_[data-slot=message-content]]:px-3 [&_[data-slot=message-content]]:py-2", from === "assistant" && "justify-start", className),
|
|
554
|
+
...props
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
function MessageAvatar({ src, alt = "", fallback, className, delay }) {
|
|
558
|
+
return /* @__PURE__ */ jsxs(Avatar, {
|
|
559
|
+
className: cn("size-8 shrink-0", className),
|
|
560
|
+
"data-slot": "message-avatar",
|
|
561
|
+
children: [src ? /* @__PURE__ */ jsx(AvatarImage, {
|
|
562
|
+
src,
|
|
563
|
+
alt
|
|
564
|
+
}) : null, fallback ? /* @__PURE__ */ jsx(AvatarFallback, {
|
|
565
|
+
delay,
|
|
566
|
+
children: fallback
|
|
567
|
+
}) : null]
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
function MessageContent({ className, markdown = false, streaming = false, children, ...props }) {
|
|
571
|
+
const contentClassName = cn("min-w-0 max-w-[min(100%,42rem)] text-sm leading-relaxed text-foreground", className);
|
|
572
|
+
if (markdown && typeof children === "string") return /* @__PURE__ */ jsx(Markdown, {
|
|
573
|
+
"data-slot": "message-content",
|
|
574
|
+
streaming,
|
|
575
|
+
className: contentClassName,
|
|
576
|
+
...props,
|
|
577
|
+
children
|
|
578
|
+
});
|
|
579
|
+
return /* @__PURE__ */ jsx("div", {
|
|
580
|
+
"data-slot": "message-content",
|
|
581
|
+
className: contentClassName,
|
|
582
|
+
...props,
|
|
583
|
+
children
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
function MessageActions({ className, ...props }) {
|
|
587
|
+
return /* @__PURE__ */ jsx("div", {
|
|
588
|
+
"data-slot": "message-actions",
|
|
589
|
+
className: cn("flex items-center gap-1 text-muted-foreground", className),
|
|
590
|
+
...props
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
function MessageAction({ tooltip, children, className, side = "top", ...props }) {
|
|
594
|
+
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Tooltip, {
|
|
595
|
+
...props,
|
|
596
|
+
children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
597
|
+
asChild: true,
|
|
598
|
+
children
|
|
599
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
600
|
+
side,
|
|
601
|
+
className,
|
|
602
|
+
children: tooltip
|
|
603
|
+
})]
|
|
604
|
+
}) });
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/components/ai/code-block.tsx
|
|
609
|
+
/** Default visible lines before the expand control appears. */
|
|
610
|
+
const DEFAULT_COLLAPSED_LINES = 12;
|
|
611
|
+
/** Approx. line box for text-xs + leading-relaxed (+ padding slack). */
|
|
612
|
+
const LINE_BOX_PX = 20;
|
|
613
|
+
/** Vertical padding inside the pre (p-3 = 12px × 2). */
|
|
614
|
+
const PRE_PAD_Y = 24;
|
|
615
|
+
/** Map common language labels to sugar-high presets (JS/TS/JSX is the default). */
|
|
616
|
+
function optionsForLanguage(language) {
|
|
617
|
+
if (!language) return void 0;
|
|
618
|
+
switch (language.toLowerCase().trim()) {
|
|
619
|
+
case "ts":
|
|
620
|
+
case "tsx":
|
|
621
|
+
case "typescript":
|
|
622
|
+
case "js":
|
|
623
|
+
case "jsx":
|
|
624
|
+
case "javascript":
|
|
625
|
+
case "mjs":
|
|
626
|
+
case "cjs": return;
|
|
627
|
+
case "py":
|
|
628
|
+
case "python": return python;
|
|
629
|
+
case "rs":
|
|
630
|
+
case "rust": return rust;
|
|
631
|
+
case "go":
|
|
632
|
+
case "golang": return go;
|
|
633
|
+
case "java": return java;
|
|
634
|
+
case "c":
|
|
635
|
+
case "h":
|
|
636
|
+
case "cpp":
|
|
637
|
+
case "c++":
|
|
638
|
+
case "cxx":
|
|
639
|
+
case "cc": return c;
|
|
640
|
+
case "css":
|
|
641
|
+
case "scss":
|
|
642
|
+
case "less": return css;
|
|
643
|
+
case "diff":
|
|
644
|
+
case "patch": return diff;
|
|
645
|
+
default: return;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Agent code surface with lightweight sugar-high highlighting, elegant header,
|
|
650
|
+
* copy action, and collapse/expand for long sources.
|
|
651
|
+
*/
|
|
652
|
+
function CodeBlock({ code, language, filename, showCopy = true, highlight: highlightEnabled = true, maxCollapsedLines = DEFAULT_COLLAPSED_LINES, maxExpandedHeight = "min(28rem, 70vh)", expanded: expandedProp, defaultExpanded = false, onExpandedChange, streamingLines = false, lineIntervalMs = 240, className, ...props }) {
|
|
653
|
+
const [copied, setCopied] = React$1.useState(false);
|
|
654
|
+
const [uncontrolledExpanded, setUncontrolledExpanded] = React$1.useState(defaultExpanded);
|
|
655
|
+
const expanded = expandedProp ?? uncontrolledExpanded;
|
|
656
|
+
const setExpanded = React$1.useCallback((next) => {
|
|
657
|
+
if (expandedProp === void 0) setUncontrolledExpanded(next);
|
|
658
|
+
onExpandedChange?.(next);
|
|
659
|
+
}, [expandedProp, onExpandedChange]);
|
|
660
|
+
const lines = React$1.useMemo(() => code.replace(/\n$/, "").split("\n"), [code]);
|
|
661
|
+
const lineCount = lines.length === 1 && lines[0] === "" ? 0 : lines.length;
|
|
662
|
+
const [visibleCount, setVisibleCount] = React$1.useState(streamingLines ? 0 : lines.length);
|
|
663
|
+
React$1.useEffect(() => {
|
|
664
|
+
if (!streamingLines) {
|
|
665
|
+
setVisibleCount(lines.length);
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
setVisibleCount(0);
|
|
669
|
+
if (lines.length === 0) return;
|
|
670
|
+
const id = window.setInterval(() => {
|
|
671
|
+
setVisibleCount((count) => {
|
|
672
|
+
if (count >= lines.length) {
|
|
673
|
+
window.clearInterval(id);
|
|
674
|
+
return count;
|
|
675
|
+
}
|
|
676
|
+
return count + 1;
|
|
677
|
+
});
|
|
678
|
+
}, lineIntervalMs);
|
|
679
|
+
return () => window.clearInterval(id);
|
|
680
|
+
}, [
|
|
681
|
+
streamingLines,
|
|
682
|
+
lines,
|
|
683
|
+
lineIntervalMs,
|
|
684
|
+
code
|
|
685
|
+
]);
|
|
686
|
+
const visible = streamingLines ? lines.slice(0, visibleCount).join("\n") : code;
|
|
687
|
+
const highlightedHtml = React$1.useMemo(() => {
|
|
688
|
+
if (!highlightEnabled || !visible) return null;
|
|
689
|
+
try {
|
|
690
|
+
return highlight(visible, optionsForLanguage(language));
|
|
691
|
+
} catch {
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
}, [
|
|
695
|
+
visible,
|
|
696
|
+
language,
|
|
697
|
+
highlightEnabled
|
|
698
|
+
]);
|
|
699
|
+
const handleCopy = React$1.useCallback(async () => {
|
|
700
|
+
try {
|
|
701
|
+
await navigator.clipboard.writeText(code);
|
|
702
|
+
setCopied(true);
|
|
703
|
+
window.setTimeout(() => setCopied(false), 1500);
|
|
704
|
+
} catch {}
|
|
705
|
+
}, [code]);
|
|
706
|
+
const collapsible = maxCollapsedLines !== false && lineCount > maxCollapsedLines && !streamingLines;
|
|
707
|
+
const isCollapsed = collapsible && !expanded;
|
|
708
|
+
const hiddenLineCount = collapsible ? Math.max(0, lineCount - maxCollapsedLines) : 0;
|
|
709
|
+
const collapsedMaxHeight = maxCollapsedLines === false ? void 0 : PRE_PAD_Y + maxCollapsedLines * LINE_BOX_PX;
|
|
710
|
+
const hasHeader = Boolean(filename || language || showCopy);
|
|
711
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
712
|
+
"data-slot": "code-block",
|
|
713
|
+
"data-language": language || void 0,
|
|
714
|
+
"data-expanded": collapsible ? expanded : void 0,
|
|
715
|
+
className: cn("overflow-hidden rounded-lg border border-border bg-muted/40 text-sm", "[--sh-class:oklch(0.48_0.12_250)] [--sh-identifier:var(--foreground)] [--sh-sign:var(--muted-foreground)]", "[--sh-property:oklch(0.48_0.11_230)] [--sh-entity:oklch(0.48_0.1_175)] [--sh-jsxliterals:oklch(0.5_0.14_290)]", "[--sh-string:oklch(0.48_0.1_160)] [--sh-keyword:oklch(0.52_0.16_25)] [--sh-comment:var(--muted-foreground)]", "[--sh-space:transparent] [--sh-break:transparent]", "dark:[--sh-class:oklch(0.78_0.1_250)] dark:[--sh-identifier:oklch(0.93_0_0)]", "dark:[--sh-sign:oklch(0.68_0.02_286)] dark:[--sh-property:oklch(0.78_0.1_230)]", "dark:[--sh-entity:oklch(0.78_0.1_175)] dark:[--sh-jsxliterals:oklch(0.8_0.12_290)]", "dark:[--sh-string:oklch(0.78_0.1_160)] dark:[--sh-keyword:oklch(0.78_0.14_25)]", "dark:[--sh-comment:oklch(0.62_0.02_286)]", className),
|
|
716
|
+
...props,
|
|
717
|
+
children: [
|
|
718
|
+
hasHeader ? /* @__PURE__ */ jsxs("div", {
|
|
719
|
+
"data-slot": "code-block-header",
|
|
720
|
+
className: "flex items-center gap-2 border-b border-border/70 bg-muted/50 px-2.5 py-1.5",
|
|
721
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
722
|
+
className: "flex min-w-0 flex-1 items-center gap-2",
|
|
723
|
+
children: [
|
|
724
|
+
filename ? /* @__PURE__ */ jsx("span", {
|
|
725
|
+
"data-slot": "code-block-filename",
|
|
726
|
+
className: "min-w-0 truncate font-mono text-[12px] text-foreground/80",
|
|
727
|
+
title: filename,
|
|
728
|
+
children: filename
|
|
729
|
+
}) : language ? /* @__PURE__ */ jsx("span", {
|
|
730
|
+
"data-slot": "code-block-language",
|
|
731
|
+
className: "min-w-0 truncate font-mono text-[12px] text-foreground/80",
|
|
732
|
+
children: language
|
|
733
|
+
}) : null,
|
|
734
|
+
filename && language ? /* @__PURE__ */ jsx("span", {
|
|
735
|
+
"data-slot": "code-block-language",
|
|
736
|
+
className: cn("inline-flex shrink-0 items-center rounded-md px-1.5 py-0.5", "border border-border/60 bg-background/50", "font-sans text-[10px] font-medium tracking-wide text-muted-foreground uppercase"),
|
|
737
|
+
children: language
|
|
738
|
+
}) : null,
|
|
739
|
+
collapsible ? /* @__PURE__ */ jsxs("span", {
|
|
740
|
+
"data-slot": "code-block-meta",
|
|
741
|
+
className: "hidden shrink-0 font-sans text-[11px] tabular-nums text-muted-foreground/70 sm:inline",
|
|
742
|
+
children: [lineCount, " lines"]
|
|
743
|
+
}) : null
|
|
744
|
+
]
|
|
745
|
+
}), showCopy ? /* @__PURE__ */ jsx(Button, {
|
|
746
|
+
type: "button",
|
|
747
|
+
variant: "ghost",
|
|
748
|
+
size: "icon-xs",
|
|
749
|
+
className: "shrink-0 text-muted-foreground hover:text-foreground",
|
|
750
|
+
"aria-label": copied ? "Copied" : "Copy code",
|
|
751
|
+
onClick: handleCopy,
|
|
752
|
+
children: copied ? /* @__PURE__ */ jsx(Check, { className: "size-3.5" }) : /* @__PURE__ */ jsx(Copy, { className: "size-3.5" })
|
|
753
|
+
}) : null]
|
|
754
|
+
}) : null,
|
|
755
|
+
/* @__PURE__ */ jsxs("div", {
|
|
756
|
+
"data-slot": "code-block-body",
|
|
757
|
+
className: "relative",
|
|
758
|
+
children: [/* @__PURE__ */ jsx("pre", {
|
|
759
|
+
className: cn("overflow-x-auto p-3 font-mono text-xs leading-relaxed text-foreground", "[&_.sh__line]:block", "transition-[max-height] duration-300 ease-[cubic-bezier(0.2,0,0,1)] motion-reduce:transition-none", isCollapsed && "overflow-y-hidden", !isCollapsed && maxExpandedHeight !== false && collapsible && "overflow-y-auto"),
|
|
760
|
+
style: isCollapsed ? { maxHeight: collapsedMaxHeight } : collapsible && maxExpandedHeight !== false ? { maxHeight: maxExpandedHeight } : void 0,
|
|
761
|
+
children: highlightedHtml ? /* @__PURE__ */ jsx("code", { dangerouslySetInnerHTML: { __html: highlightedHtml } }) : /* @__PURE__ */ jsx("code", { children: visible })
|
|
762
|
+
}), isCollapsed ? /* @__PURE__ */ jsx("div", {
|
|
763
|
+
"aria-hidden": true,
|
|
764
|
+
"data-slot": "code-block-fade",
|
|
765
|
+
className: cn("pointer-events-none absolute inset-x-0 bottom-0 h-16", "bg-linear-to-t from-muted/95 via-muted/55 to-transparent", "dark:from-muted/90 dark:via-muted/50")
|
|
766
|
+
}) : null]
|
|
767
|
+
}),
|
|
768
|
+
collapsible ? /* @__PURE__ */ jsx("div", {
|
|
769
|
+
"data-slot": "code-block-footer",
|
|
770
|
+
className: "border-t border-border/70 bg-muted/40",
|
|
771
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
772
|
+
type: "button",
|
|
773
|
+
"data-slot": "code-block-expand",
|
|
774
|
+
"aria-expanded": expanded,
|
|
775
|
+
onClick: () => setExpanded(!expanded),
|
|
776
|
+
className: cn("flex w-full items-center justify-center gap-1.5 px-3 py-2", "text-[12px] font-medium text-muted-foreground", "outline-none transition-colors duration-150", "hover:bg-muted/70 hover:text-foreground", "focus-visible:bg-muted/70 focus-visible:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"),
|
|
777
|
+
children: [/* @__PURE__ */ jsx("span", { children: expanded ? "Show less" : hiddenLineCount === 1 ? "Show 1 more line" : `Show ${hiddenLineCount} more lines` }), /* @__PURE__ */ jsx(ChevronDown, {
|
|
778
|
+
className: cn("size-3.5 opacity-70 transition-transform duration-200 ease-[cubic-bezier(0.2,0,0,1)] motion-reduce:transition-none", expanded && "rotate-180"),
|
|
779
|
+
"aria-hidden": true
|
|
780
|
+
})]
|
|
781
|
+
})
|
|
782
|
+
}) : null
|
|
783
|
+
]
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region src/components/ai/response-stream.tsx
|
|
789
|
+
/**
|
|
790
|
+
* Progressive text reveal for demos and offline fixtures.
|
|
791
|
+
* Production streaming should feed tokens into Markdown/MessageContent instead.
|
|
792
|
+
*/
|
|
793
|
+
function ResponseStream({ text, mode = "typewriter", speed = 2, className, markdown = false, onComplete }) {
|
|
794
|
+
const [cursor, setCursor] = React$1.useState(0);
|
|
795
|
+
const completeRef = React$1.useRef(onComplete);
|
|
796
|
+
completeRef.current = onComplete;
|
|
797
|
+
React$1.useEffect(() => {
|
|
798
|
+
setCursor(0);
|
|
799
|
+
}, [text]);
|
|
800
|
+
React$1.useEffect(() => {
|
|
801
|
+
if (cursor >= text.length) {
|
|
802
|
+
completeRef.current?.();
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
const id = window.setTimeout(() => {
|
|
806
|
+
setCursor((value) => Math.min(text.length, value + Math.max(1, speed)));
|
|
807
|
+
}, mode === "fade" ? 16 : 18);
|
|
808
|
+
return () => window.clearTimeout(id);
|
|
809
|
+
}, [
|
|
810
|
+
cursor,
|
|
811
|
+
text,
|
|
812
|
+
speed,
|
|
813
|
+
mode
|
|
814
|
+
]);
|
|
815
|
+
const visible = text.slice(0, cursor);
|
|
816
|
+
const streaming = cursor < text.length;
|
|
817
|
+
if (markdown) return /* @__PURE__ */ jsx(Markdown, {
|
|
818
|
+
streaming,
|
|
819
|
+
className,
|
|
820
|
+
children: visible
|
|
821
|
+
});
|
|
822
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
823
|
+
"data-slot": "response-stream",
|
|
824
|
+
"data-streaming": streaming ? "true" : "false",
|
|
825
|
+
className: cn("whitespace-pre-wrap text-sm leading-relaxed text-foreground", mode === "fade" && streaming && "animate-[fade-in_200ms_ease-out]", className),
|
|
826
|
+
children: [visible, streaming ? /* @__PURE__ */ jsx("span", {
|
|
827
|
+
"aria-hidden": true,
|
|
828
|
+
className: "ml-0.5 inline-block h-3.5 w-px translate-y-0.5 bg-foreground/70 animate-pulse motion-reduce:animate-none"
|
|
829
|
+
}) : null]
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region src/components/ai/chat-container.tsx
|
|
835
|
+
const ChatContainerContext = React$1.createContext(null);
|
|
836
|
+
function useChatContainer() {
|
|
837
|
+
const context = React$1.useContext(ChatContainerContext);
|
|
838
|
+
if (!context) throw new Error("useChatContainer must be used within ChatContainer.");
|
|
839
|
+
return context;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Scroll region for chat transcripts with stick-to-bottom tracking.
|
|
843
|
+
* Pair with ScrollButton for jump-to-latest.
|
|
844
|
+
*/
|
|
845
|
+
function ChatContainer({ className, children, bottomThreshold = 48, autoScroll = true, ...props }) {
|
|
846
|
+
const scrollRef = React$1.useRef(null);
|
|
847
|
+
const [isAtBottom, setIsAtBottom] = React$1.useState(true);
|
|
848
|
+
const isAtBottomRef = React$1.useRef(true);
|
|
849
|
+
const scrollToBottom = React$1.useCallback((behavior = "smooth") => {
|
|
850
|
+
const node = scrollRef.current;
|
|
851
|
+
if (!node) return;
|
|
852
|
+
node.scrollTo({
|
|
853
|
+
top: node.scrollHeight,
|
|
854
|
+
behavior
|
|
855
|
+
});
|
|
856
|
+
}, []);
|
|
857
|
+
const updatePinned = React$1.useCallback(() => {
|
|
858
|
+
const node = scrollRef.current;
|
|
859
|
+
if (!node) return;
|
|
860
|
+
const pinned = node.scrollHeight - node.scrollTop - node.clientHeight <= bottomThreshold;
|
|
861
|
+
isAtBottomRef.current = pinned;
|
|
862
|
+
setIsAtBottom(pinned);
|
|
863
|
+
}, [bottomThreshold]);
|
|
864
|
+
React$1.useEffect(() => {
|
|
865
|
+
const node = scrollRef.current;
|
|
866
|
+
if (!node) return;
|
|
867
|
+
updatePinned();
|
|
868
|
+
node.addEventListener("scroll", updatePinned, { passive: true });
|
|
869
|
+
const observer = new ResizeObserver(() => {
|
|
870
|
+
if (autoScroll && isAtBottomRef.current) node.scrollTop = node.scrollHeight;
|
|
871
|
+
updatePinned();
|
|
872
|
+
});
|
|
873
|
+
observer.observe(node);
|
|
874
|
+
if (node.firstElementChild) observer.observe(node.firstElementChild);
|
|
875
|
+
return () => {
|
|
876
|
+
node.removeEventListener("scroll", updatePinned);
|
|
877
|
+
observer.disconnect();
|
|
878
|
+
};
|
|
879
|
+
}, [autoScroll, updatePinned]);
|
|
880
|
+
React$1.useLayoutEffect(() => {
|
|
881
|
+
if (!autoScroll || !isAtBottomRef.current) return;
|
|
882
|
+
const node = scrollRef.current;
|
|
883
|
+
if (!node) return;
|
|
884
|
+
node.scrollTop = node.scrollHeight;
|
|
885
|
+
});
|
|
886
|
+
return /* @__PURE__ */ jsx(ChatContainerContext.Provider, {
|
|
887
|
+
value: {
|
|
888
|
+
scrollRef,
|
|
889
|
+
isAtBottom,
|
|
890
|
+
scrollToBottom
|
|
891
|
+
},
|
|
892
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
893
|
+
ref: scrollRef,
|
|
894
|
+
"data-slot": "chat-container",
|
|
895
|
+
"data-at-bottom": isAtBottom ? "true" : "false",
|
|
896
|
+
className: cn("relative min-h-0 flex-1 overflow-y-auto overscroll-contain", className),
|
|
897
|
+
...props,
|
|
898
|
+
children
|
|
899
|
+
})
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
function ChatContainerContent({ className, ...props }) {
|
|
903
|
+
return /* @__PURE__ */ jsx("div", {
|
|
904
|
+
"data-slot": "chat-container-content",
|
|
905
|
+
className: cn("mx-auto flex w-full max-w-2xl flex-col gap-4 px-4 py-6", className),
|
|
906
|
+
...props
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
//#endregion
|
|
911
|
+
//#region src/components/ai/scroll-button.tsx
|
|
912
|
+
/**
|
|
913
|
+
* Floating jump-to-latest control. Appears when the transcript is scrolled up.
|
|
914
|
+
* Must render inside ChatContainer (reads pin state via context).
|
|
915
|
+
*
|
|
916
|
+
* Visual: single soft ring + ambient shadow — not the outline Button chrome
|
|
917
|
+
* (which stacks border + inset pseudo and reads as a double border).
|
|
918
|
+
*/
|
|
919
|
+
function ScrollButton({ className, visible, label = "Scroll to latest", onClick, type = "button", ...props }) {
|
|
920
|
+
const { isAtBottom, scrollToBottom } = useChatContainer();
|
|
921
|
+
if (!(visible ?? !isAtBottom)) return null;
|
|
922
|
+
return /* @__PURE__ */ jsx("button", {
|
|
923
|
+
type,
|
|
924
|
+
"aria-label": label,
|
|
925
|
+
"data-slot": "scroll-button",
|
|
926
|
+
className: cn("absolute bottom-4 left-1/2 z-10 flex size-9 -translate-x-1/2 items-center justify-center", "rounded-full border border-border/80 bg-background/95 text-muted-foreground", "shadow-md shadow-black/10 backdrop-blur-md", "dark:border-border dark:bg-card/90 dark:shadow-black/40", "outline-none transition-[transform,background-color,color,box-shadow,border-color] duration-150 ease-out", "hover:border-border hover:bg-accent hover:text-foreground hover:shadow-lg", "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background", "motion-safe:active:scale-[0.96]", "animate-[fade-in_150ms_ease-out] motion-reduce:animate-none", className),
|
|
927
|
+
onClick: (event) => {
|
|
928
|
+
scrollToBottom("smooth");
|
|
929
|
+
onClick?.(event);
|
|
930
|
+
},
|
|
931
|
+
...props,
|
|
932
|
+
children: /* @__PURE__ */ jsx(ArrowDown, {
|
|
933
|
+
className: "size-4 opacity-90",
|
|
934
|
+
"aria-hidden": true
|
|
935
|
+
})
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
//#endregion
|
|
940
|
+
//#region src/components/ai/system-message.tsx
|
|
941
|
+
/**
|
|
942
|
+
* Banner-style notice for app-injected transcript messages (errors, hints).
|
|
943
|
+
* Not an assistant reply — keep it visually distinct via Alert variants.
|
|
944
|
+
*/
|
|
945
|
+
function SystemMessage({ className, title, variant = "info", children, ...props }) {
|
|
946
|
+
return /* @__PURE__ */ jsxs(Alert, {
|
|
947
|
+
"data-slot": "system-message",
|
|
948
|
+
variant,
|
|
949
|
+
className: cn("text-left", className),
|
|
950
|
+
...props,
|
|
951
|
+
children: [title ? /* @__PURE__ */ jsx(AlertTitle, { children: title }) : null, children ? /* @__PURE__ */ jsx(AlertDescription, { children }) : null]
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
//#endregion
|
|
956
|
+
//#region src/components/ai/format-duration.ts
|
|
957
|
+
/** Format elapsed ms for "Thought for …" / "Worked for …" labels. */
|
|
958
|
+
function formatDuration(ms) {
|
|
959
|
+
if (ms < 1e3) return `${Math.max(1, Math.round(ms))}ms`;
|
|
960
|
+
const seconds = ms / 1e3;
|
|
961
|
+
if (seconds < 10) return `${seconds.toFixed(1)}s`;
|
|
962
|
+
if (seconds < 60) return `${Math.round(seconds)}s`;
|
|
963
|
+
const minutes = Math.floor(seconds / 60);
|
|
964
|
+
const rem = Math.round(seconds % 60);
|
|
965
|
+
return rem === 0 ? `${minutes}m` : `${minutes}m ${rem}s`;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
//#endregion
|
|
969
|
+
//#region src/components/ai/reasoning.tsx
|
|
970
|
+
/**
|
|
971
|
+
* Collapsible model reasoning / thinking block.
|
|
972
|
+
* Auto-opens while streaming; auto-collapses when settled unless the user toggled.
|
|
973
|
+
*/
|
|
974
|
+
function Reasoning({ children, content, isStreaming = false, durationMs = null, open: openProp, onOpenChange, markdown = false, className, streamingLabel = "Thinking…", doneLabel = "Thought" }) {
|
|
975
|
+
const [internalOpen, setInternalOpen] = React$1.useState(isStreaming);
|
|
976
|
+
const userToggled = React$1.useRef(false);
|
|
977
|
+
const prevStreaming = React$1.useRef(isStreaming);
|
|
978
|
+
const controlled = openProp !== void 0;
|
|
979
|
+
const open = controlled ? openProp : internalOpen;
|
|
980
|
+
const setOpen = React$1.useCallback((next) => {
|
|
981
|
+
if (!controlled) setInternalOpen(next);
|
|
982
|
+
onOpenChange?.(next);
|
|
983
|
+
}, [controlled, onOpenChange]);
|
|
984
|
+
React$1.useEffect(() => {
|
|
985
|
+
const was = prevStreaming.current;
|
|
986
|
+
prevStreaming.current = isStreaming;
|
|
987
|
+
if (!was && isStreaming) {
|
|
988
|
+
userToggled.current = false;
|
|
989
|
+
if (!controlled) setInternalOpen(true);
|
|
990
|
+
onOpenChange?.(true);
|
|
991
|
+
} else if (was && !isStreaming && !userToggled.current) {
|
|
992
|
+
if (!controlled) setInternalOpen(false);
|
|
993
|
+
onOpenChange?.(false);
|
|
994
|
+
}
|
|
995
|
+
}, [
|
|
996
|
+
isStreaming,
|
|
997
|
+
controlled,
|
|
998
|
+
onOpenChange
|
|
999
|
+
]);
|
|
1000
|
+
const body = children ?? content ?? "";
|
|
1001
|
+
if ((typeof body === "string" ? body.trim().length === 0 : !body) && !isStreaming) return null;
|
|
1002
|
+
const duration = durationMs != null && durationMs > 0 ? formatDuration(durationMs) : null;
|
|
1003
|
+
const label = isStreaming ? streamingLabel : duration ? `Thought for ${duration}` : doneLabel;
|
|
1004
|
+
return /* @__PURE__ */ jsxs(Collapsible, {
|
|
1005
|
+
open,
|
|
1006
|
+
onOpenChange: (next) => {
|
|
1007
|
+
if (isStreaming) userToggled.current = true;
|
|
1008
|
+
setOpen(next);
|
|
1009
|
+
},
|
|
1010
|
+
className: cn("w-full", className),
|
|
1011
|
+
"data-slot": "reasoning",
|
|
1012
|
+
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
1013
|
+
className: cn("group flex w-fit max-w-full items-center gap-1.5 rounded-md px-1.5 py-1 text-left text-[13px]", "text-muted-foreground transition-colors duration-150 hover:bg-accent hover:text-foreground", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),
|
|
1014
|
+
children: [
|
|
1015
|
+
/* @__PURE__ */ jsx(Brain, { className: "size-3.5 shrink-0 opacity-80" }),
|
|
1016
|
+
isStreaming ? /* @__PURE__ */ jsx(TextShimmer, {
|
|
1017
|
+
className: "text-[13px] font-medium",
|
|
1018
|
+
children: label
|
|
1019
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
1020
|
+
className: "font-medium",
|
|
1021
|
+
children: label
|
|
1022
|
+
}),
|
|
1023
|
+
/* @__PURE__ */ jsx(ChevronDown, {
|
|
1024
|
+
"data-slot": "collapsible-icon",
|
|
1025
|
+
className: "size-3.5 shrink-0 opacity-60 transition-transform duration-200"
|
|
1026
|
+
})
|
|
1027
|
+
]
|
|
1028
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
1029
|
+
innerClassName: "py-0",
|
|
1030
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1031
|
+
className: "my-1 ml-1.5 border-l border-border/70 py-1 pl-3",
|
|
1032
|
+
children: markdown && typeof body === "string" ? /* @__PURE__ */ jsx(Markdown, {
|
|
1033
|
+
streaming: isStreaming,
|
|
1034
|
+
className: "text-[13px] text-muted-foreground",
|
|
1035
|
+
children: body
|
|
1036
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
1037
|
+
className: "whitespace-pre-wrap text-[13px] leading-relaxed text-muted-foreground",
|
|
1038
|
+
children: body
|
|
1039
|
+
})
|
|
1040
|
+
})
|
|
1041
|
+
})]
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
/** Compact “Thinking…” line with optional stop action (prompt-kit style). */
|
|
1045
|
+
function ThinkingBar({ className, text = "Thinking", onStop, stopLabel = "Answer now", onClick }) {
|
|
1046
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1047
|
+
"data-slot": "thinking-bar",
|
|
1048
|
+
className: cn("flex w-full items-center justify-between gap-3", className),
|
|
1049
|
+
children: [onClick ? /* @__PURE__ */ jsxs("button", {
|
|
1050
|
+
type: "button",
|
|
1051
|
+
onClick,
|
|
1052
|
+
className: "flex items-center gap-1 text-sm transition-opacity duration-150 hover:opacity-80",
|
|
1053
|
+
children: [/* @__PURE__ */ jsx(TextShimmer, {
|
|
1054
|
+
className: "font-medium",
|
|
1055
|
+
children: text
|
|
1056
|
+
}), /* @__PURE__ */ jsx(ChevronDown, { className: "size-4 -rotate-90 text-muted-foreground" })]
|
|
1057
|
+
}) : /* @__PURE__ */ jsx(TextShimmer, {
|
|
1058
|
+
className: "cursor-default font-medium",
|
|
1059
|
+
children: text
|
|
1060
|
+
}), onStop ? /* @__PURE__ */ jsx("button", {
|
|
1061
|
+
type: "button",
|
|
1062
|
+
onClick: onStop,
|
|
1063
|
+
className: "border-b border-dotted border-muted-foreground/50 text-sm text-muted-foreground transition-colors duration-150 hover:border-foreground hover:text-foreground",
|
|
1064
|
+
children: stopLabel
|
|
1065
|
+
}) : null]
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region src/components/ai/thinking-trace.tsx
|
|
1071
|
+
/**
|
|
1072
|
+
* Beautiful UI–style expandable agent trace with mode variants.
|
|
1073
|
+
* Production hosts pass rows + streaming; demos can drive visibleCount.
|
|
1074
|
+
*/
|
|
1075
|
+
function ThinkingTrace({ mode = "steps", activeLabel, doneLabel, durationMs = null, isStreaming = false, rows, query, open: openProp, onOpenChange, className, visibleCount }) {
|
|
1076
|
+
const defaults = MODE_DEFAULTS[mode];
|
|
1077
|
+
const [internalOpen, setInternalOpen] = React$1.useState(isStreaming);
|
|
1078
|
+
const userToggled = React$1.useRef(false);
|
|
1079
|
+
const prevStreaming = React$1.useRef(isStreaming);
|
|
1080
|
+
const controlled = openProp !== void 0;
|
|
1081
|
+
const open = controlled ? openProp : internalOpen;
|
|
1082
|
+
React$1.useEffect(() => {
|
|
1083
|
+
const was = prevStreaming.current;
|
|
1084
|
+
prevStreaming.current = isStreaming;
|
|
1085
|
+
if (!was && isStreaming) {
|
|
1086
|
+
userToggled.current = false;
|
|
1087
|
+
if (!controlled) setInternalOpen(true);
|
|
1088
|
+
} else if (was && !isStreaming && !userToggled.current) {
|
|
1089
|
+
if (!controlled) setInternalOpen(false);
|
|
1090
|
+
}
|
|
1091
|
+
}, [isStreaming, controlled]);
|
|
1092
|
+
const setOpen = (next) => {
|
|
1093
|
+
if (isStreaming) userToggled.current = true;
|
|
1094
|
+
if (!controlled) setInternalOpen(next);
|
|
1095
|
+
onOpenChange?.(next);
|
|
1096
|
+
};
|
|
1097
|
+
const count = visibleCount ?? rows.length;
|
|
1098
|
+
const shown = rows.slice(0, Math.max(0, count));
|
|
1099
|
+
const duration = durationMs != null && durationMs > 0 ? formatDuration(durationMs) : null;
|
|
1100
|
+
const workingLabel = activeLabel ?? defaults.active;
|
|
1101
|
+
const settledLabel = doneLabel ?? (duration ? `${defaults.donePrefix} ${duration}` : defaults.done);
|
|
1102
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1103
|
+
"data-slot": "thinking-trace",
|
|
1104
|
+
"data-mode": mode,
|
|
1105
|
+
className: cn("flex w-full flex-col", className),
|
|
1106
|
+
children: /* @__PURE__ */ jsxs(Collapsible, {
|
|
1107
|
+
open,
|
|
1108
|
+
onOpenChange: setOpen,
|
|
1109
|
+
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
1110
|
+
className: cn("group -mx-1.5 flex w-fit items-center gap-2 rounded-md px-1.5 py-1 text-left", "transition-colors duration-150 hover:bg-accent"),
|
|
1111
|
+
children: [
|
|
1112
|
+
/* @__PURE__ */ jsx(Sparkles, { className: cn("size-3.5 shrink-0", isStreaming ? "text-muted-foreground" : "text-muted-foreground/70") }),
|
|
1113
|
+
isStreaming ? /* @__PURE__ */ jsx(TextShimmer, {
|
|
1114
|
+
className: "text-[13px] font-medium whitespace-nowrap",
|
|
1115
|
+
children: workingLabel
|
|
1116
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
1117
|
+
className: "text-[13px] font-medium whitespace-nowrap text-muted-foreground animate-[fade-in_350ms_ease-out_both] motion-reduce:animate-none",
|
|
1118
|
+
children: settledLabel
|
|
1119
|
+
}),
|
|
1120
|
+
/* @__PURE__ */ jsx(ChevronDown, {
|
|
1121
|
+
"data-slot": "collapsible-icon",
|
|
1122
|
+
className: "size-3.5 text-muted-foreground/60"
|
|
1123
|
+
})
|
|
1124
|
+
]
|
|
1125
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
1126
|
+
innerClassName: "py-0",
|
|
1127
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1128
|
+
className: "relative mt-1 ml-1.5 border-l border-border/70 pl-3",
|
|
1129
|
+
children: [mode === "search" && query ? /* @__PURE__ */ jsxs("div", {
|
|
1130
|
+
className: "mb-2 flex items-center gap-1.5 text-[12px] text-muted-foreground",
|
|
1131
|
+
children: [/* @__PURE__ */ jsx(Globe, { className: "size-3 shrink-0" }), /* @__PURE__ */ jsx("span", {
|
|
1132
|
+
className: "truncate font-mono",
|
|
1133
|
+
children: query
|
|
1134
|
+
})]
|
|
1135
|
+
}) : null, /* @__PURE__ */ jsx("ul", {
|
|
1136
|
+
className: "flex flex-col gap-1.5",
|
|
1137
|
+
children: shown.map((row, index) => {
|
|
1138
|
+
const settled = !isStreaming || index < shown.length - 1 || count >= rows.length;
|
|
1139
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
1140
|
+
className: "flex min-w-0 items-start gap-2 text-[13px] animate-[ai-fade-up_300ms_cubic-bezier(0.23,1,0.32,1)_both] motion-reduce:animate-none",
|
|
1141
|
+
style: { animationDelay: `${Math.min(index, 6) * 40}ms` },
|
|
1142
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1143
|
+
className: "mt-0.5 shrink-0",
|
|
1144
|
+
children: settled ? mode === "coding" ? /* @__PURE__ */ jsx(RowIcon, {
|
|
1145
|
+
mono: row.mono,
|
|
1146
|
+
primary: row.primary
|
|
1147
|
+
}) : /* @__PURE__ */ jsx(Check, { className: "size-3 text-muted-foreground/70" }) : /* @__PURE__ */ jsx(Loader2, { className: "size-3 animate-spin text-muted-foreground motion-reduce:animate-none" })
|
|
1148
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1149
|
+
className: "min-w-0 flex-1",
|
|
1150
|
+
children: [
|
|
1151
|
+
row.href ? /* @__PURE__ */ jsx("a", {
|
|
1152
|
+
href: row.href,
|
|
1153
|
+
target: "_blank",
|
|
1154
|
+
rel: "noreferrer noopener",
|
|
1155
|
+
className: "font-medium text-foreground underline-offset-2 hover:underline",
|
|
1156
|
+
children: row.primary
|
|
1157
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
1158
|
+
className: cn("text-foreground", row.mono && "font-mono text-[12px]", mode === "reasoning" && "text-muted-foreground"),
|
|
1159
|
+
children: row.primary
|
|
1160
|
+
}),
|
|
1161
|
+
row.secondary ? /* @__PURE__ */ jsx("span", {
|
|
1162
|
+
className: cn("ml-1.5 text-muted-foreground", row.mono && "font-mono text-[12px]"),
|
|
1163
|
+
children: row.secondary
|
|
1164
|
+
}) : null,
|
|
1165
|
+
(row.add != null || row.del != null) && /* @__PURE__ */ jsxs("span", {
|
|
1166
|
+
className: "ml-1.5 font-mono text-[11px] tabular-nums",
|
|
1167
|
+
children: [row.add != null ? /* @__PURE__ */ jsxs("span", {
|
|
1168
|
+
className: "text-success",
|
|
1169
|
+
children: ["+", row.add]
|
|
1170
|
+
}) : null, row.del != null ? /* @__PURE__ */ jsxs("span", {
|
|
1171
|
+
className: "ml-1 text-destructive",
|
|
1172
|
+
children: ["-", row.del]
|
|
1173
|
+
}) : null]
|
|
1174
|
+
})
|
|
1175
|
+
]
|
|
1176
|
+
})]
|
|
1177
|
+
}, `${row.primary}-${index}`);
|
|
1178
|
+
})
|
|
1179
|
+
})]
|
|
1180
|
+
})
|
|
1181
|
+
})]
|
|
1182
|
+
})
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
function RowIcon({ mono, primary }) {
|
|
1186
|
+
const p = primary.toLowerCase();
|
|
1187
|
+
if (p.startsWith("run") || p.startsWith("bash")) return /* @__PURE__ */ jsx(Terminal, { className: "size-3 text-muted-foreground" });
|
|
1188
|
+
if (p.startsWith("read") || p.startsWith("edit") || p.startsWith("write") || mono) return /* @__PURE__ */ jsx(FileCode2, { className: "size-3 text-muted-foreground" });
|
|
1189
|
+
return /* @__PURE__ */ jsx(Check, { className: "size-3 text-muted-foreground/70" });
|
|
1190
|
+
}
|
|
1191
|
+
const MODE_DEFAULTS = {
|
|
1192
|
+
steps: {
|
|
1193
|
+
active: "Thinking",
|
|
1194
|
+
done: "Thought",
|
|
1195
|
+
donePrefix: "Thought for"
|
|
1196
|
+
},
|
|
1197
|
+
reasoning: {
|
|
1198
|
+
active: "Thinking",
|
|
1199
|
+
done: "Thought",
|
|
1200
|
+
donePrefix: "Thought for"
|
|
1201
|
+
},
|
|
1202
|
+
search: {
|
|
1203
|
+
active: "Searching the web",
|
|
1204
|
+
done: "Searched the web",
|
|
1205
|
+
donePrefix: "Searched for"
|
|
1206
|
+
},
|
|
1207
|
+
coding: {
|
|
1208
|
+
active: "Running tools",
|
|
1209
|
+
done: "Ran tools",
|
|
1210
|
+
donePrefix: "Ran tools for"
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
//#endregion
|
|
1215
|
+
//#region src/components/ai/steps.tsx
|
|
1216
|
+
/**
|
|
1217
|
+
* Marker box (px). Icons are size-3.5 (14px); the box is slightly larger.
|
|
1218
|
+
* Odd rail keeps the 1px connector on an integer left: (RAIL - 1) / 2.
|
|
1219
|
+
*/
|
|
1220
|
+
const RAIL = 15;
|
|
1221
|
+
/** Air between icon edge and the vertical segment (px). */
|
|
1222
|
+
const GAP = 6;
|
|
1223
|
+
const STATUS_LABEL = {
|
|
1224
|
+
pending: "Pending",
|
|
1225
|
+
running: "In progress",
|
|
1226
|
+
done: "Completed",
|
|
1227
|
+
error: "Failed"
|
|
1228
|
+
};
|
|
1229
|
+
/**
|
|
1230
|
+
* Quiet timeline with gapped segments (not a continuous spine through icons):
|
|
1231
|
+
*
|
|
1232
|
+
* ```
|
|
1233
|
+
* ✓
|
|
1234
|
+
* ↕ GAP
|
|
1235
|
+
* │ ≥ MIN_SEGMENT
|
|
1236
|
+
* ↕ GAP
|
|
1237
|
+
* ◌
|
|
1238
|
+
* ```
|
|
1239
|
+
*
|
|
1240
|
+
* Each step (except last) draws its own connector. The rail enforces a minimum
|
|
1241
|
+
* height so short title-only steps still show a readable segment.
|
|
1242
|
+
*/
|
|
1243
|
+
function Steps({ children, className, open, onOpenChange, defaultOpen = true, title = "Steps" }) {
|
|
1244
|
+
return /* @__PURE__ */ jsxs(Collapsible, {
|
|
1245
|
+
open,
|
|
1246
|
+
defaultOpen,
|
|
1247
|
+
onOpenChange,
|
|
1248
|
+
className: cn("w-full min-w-0", className),
|
|
1249
|
+
"data-slot": "steps",
|
|
1250
|
+
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
1251
|
+
className: cn("group flex w-fit max-w-full items-center gap-1.5 rounded-md px-1.5 py-1 text-[13px]", "text-muted-foreground transition-colors duration-150 hover:bg-accent hover:text-foreground"),
|
|
1252
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1253
|
+
className: "min-w-0 truncate font-medium",
|
|
1254
|
+
children: title
|
|
1255
|
+
}), /* @__PURE__ */ jsx(ChevronDown, {
|
|
1256
|
+
"data-slot": "collapsible-icon",
|
|
1257
|
+
className: "size-3.5 shrink-0 opacity-60"
|
|
1258
|
+
})]
|
|
1259
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
1260
|
+
innerClassName: "py-1.5",
|
|
1261
|
+
children: /* @__PURE__ */ jsx("ol", {
|
|
1262
|
+
className: "flex min-w-0 flex-col",
|
|
1263
|
+
"data-slot": "steps-list",
|
|
1264
|
+
children
|
|
1265
|
+
})
|
|
1266
|
+
})]
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Status as stroke icons only — no filled disks, no translucent glow.
|
|
1271
|
+
* Matches PlanTracker: Check / CircleDashed / Circle / X.
|
|
1272
|
+
*/
|
|
1273
|
+
function StepMarker({ status }) {
|
|
1274
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1275
|
+
"data-slot": "step-marker",
|
|
1276
|
+
className: "relative z-10 flex shrink-0 items-center justify-center rounded-full bg-background",
|
|
1277
|
+
style: {
|
|
1278
|
+
width: RAIL,
|
|
1279
|
+
height: RAIL
|
|
1280
|
+
},
|
|
1281
|
+
"aria-hidden": true,
|
|
1282
|
+
children: status === "done" ? /* @__PURE__ */ jsx(Check, {
|
|
1283
|
+
className: "size-3.5 text-success",
|
|
1284
|
+
strokeWidth: 2.5
|
|
1285
|
+
}) : status === "running" ? /* @__PURE__ */ jsx(CircleDashed, {
|
|
1286
|
+
className: "size-3.5 animate-spin text-primary motion-reduce:animate-none",
|
|
1287
|
+
strokeWidth: 2
|
|
1288
|
+
}) : status === "error" ? /* @__PURE__ */ jsx(X, {
|
|
1289
|
+
className: "size-3.5 text-destructive",
|
|
1290
|
+
strokeWidth: 2.5
|
|
1291
|
+
}) : /* @__PURE__ */ jsx(Circle, {
|
|
1292
|
+
className: "size-3.5 text-muted-foreground/40",
|
|
1293
|
+
strokeWidth: 1.75
|
|
1294
|
+
})
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
function Step({ children, title, description, status = "pending", className }) {
|
|
1298
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
1299
|
+
"data-slot": "step",
|
|
1300
|
+
"data-status": status,
|
|
1301
|
+
"aria-current": status === "running" ? "step" : void 0,
|
|
1302
|
+
className: cn("group/step relative flex min-w-0 items-stretch gap-2.5", className),
|
|
1303
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1304
|
+
"data-slot": "step-rail",
|
|
1305
|
+
className: "relative flex min-h-[39px] shrink-0 flex-col items-center group-last/step:min-h-[15px]",
|
|
1306
|
+
style: { width: RAIL },
|
|
1307
|
+
children: [/* @__PURE__ */ jsx(StepMarker, { status }), /* @__PURE__ */ jsx("span", {
|
|
1308
|
+
"aria-hidden": true,
|
|
1309
|
+
"data-slot": "step-connector",
|
|
1310
|
+
className: "pointer-events-none absolute w-px bg-border group-last/step:hidden",
|
|
1311
|
+
style: {
|
|
1312
|
+
left: (RAIL - 1) / 2,
|
|
1313
|
+
top: 21,
|
|
1314
|
+
bottom: GAP
|
|
1315
|
+
}
|
|
1316
|
+
})]
|
|
1317
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1318
|
+
className: cn("min-w-0 flex-1 text-[13px]", "pb-3.5 group-last/step:pb-0"),
|
|
1319
|
+
children: [
|
|
1320
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1321
|
+
className: cn("break-words font-medium", status === "running" && "text-foreground", status === "done" && "text-muted-foreground", status === "pending" && "text-muted-foreground/80", status === "error" && "text-destructive"),
|
|
1322
|
+
style: {
|
|
1323
|
+
minHeight: RAIL,
|
|
1324
|
+
lineHeight: `${RAIL}px`
|
|
1325
|
+
},
|
|
1326
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1327
|
+
className: "sr-only",
|
|
1328
|
+
children: [STATUS_LABEL[status], ": "]
|
|
1329
|
+
}), title]
|
|
1330
|
+
}),
|
|
1331
|
+
description ? /* @__PURE__ */ jsx("div", {
|
|
1332
|
+
className: "mt-1 break-words text-[12px] leading-snug text-muted-foreground",
|
|
1333
|
+
children: description
|
|
1334
|
+
}) : null,
|
|
1335
|
+
children ? /* @__PURE__ */ jsx("div", {
|
|
1336
|
+
"data-slot": "step-body",
|
|
1337
|
+
className: cn("mt-1.5 min-w-0 break-words text-[12px] leading-snug text-muted-foreground", "[&_pre]:mt-1.5 [&_pre]:max-w-full [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:border [&_pre]:border-border [&_pre]:bg-muted/40 [&_pre]:p-2 [&_pre]:font-mono [&_pre]:text-[11px] [&_pre]:leading-relaxed", "[&_code]:rounded-sm [&_code]:bg-muted/50 [&_code]:px-1 [&_code]:py-px [&_code]:font-mono [&_code]:text-[11.5px]"),
|
|
1338
|
+
children
|
|
1339
|
+
}) : null
|
|
1340
|
+
]
|
|
1341
|
+
})]
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
/** Alias for prompt-kit chain-of-thought naming. */
|
|
1345
|
+
const ChainOfThought = Steps;
|
|
1346
|
+
const ChainOfThoughtStep = Step;
|
|
1347
|
+
|
|
1348
|
+
//#endregion
|
|
1349
|
+
//#region src/components/ai/types.ts
|
|
1350
|
+
function normalizeToolStatus(status) {
|
|
1351
|
+
switch (status) {
|
|
1352
|
+
case "input-streaming":
|
|
1353
|
+
case "pending": return "pending";
|
|
1354
|
+
case "input-available":
|
|
1355
|
+
case "running": return "running";
|
|
1356
|
+
case "output-available":
|
|
1357
|
+
case "success": return "success";
|
|
1358
|
+
case "output-error":
|
|
1359
|
+
case "error": return "error";
|
|
1360
|
+
case "aborted": return "aborted";
|
|
1361
|
+
default: return "pending";
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
//#endregion
|
|
1366
|
+
//#region src/components/ai/tool.tsx
|
|
1367
|
+
function formatValue(value) {
|
|
1368
|
+
if (value === null) return "null";
|
|
1369
|
+
if (value === void 0) return "undefined";
|
|
1370
|
+
if (typeof value === "string") return value;
|
|
1371
|
+
try {
|
|
1372
|
+
return JSON.stringify(value, null, 2);
|
|
1373
|
+
} catch {
|
|
1374
|
+
return String(value);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
function StatusIcon({ status }) {
|
|
1378
|
+
switch (status) {
|
|
1379
|
+
case "pending": return /* @__PURE__ */ jsx(Loader2, { className: "size-3.5 animate-spin text-info motion-reduce:animate-none" });
|
|
1380
|
+
case "running": return /* @__PURE__ */ jsx(Settings2, { className: "size-3.5 text-warning" });
|
|
1381
|
+
case "success": return /* @__PURE__ */ jsx(CheckCircle2, { className: "size-3.5 text-success" });
|
|
1382
|
+
case "error": return /* @__PURE__ */ jsx(CircleX, { className: "size-3.5 text-destructive" });
|
|
1383
|
+
case "aborted": return /* @__PURE__ */ jsx(Wrench, { className: "size-3.5 text-muted-foreground" });
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
function statusBadge(status) {
|
|
1387
|
+
return {
|
|
1388
|
+
pending: {
|
|
1389
|
+
label: "Queued",
|
|
1390
|
+
className: "bg-info/10 text-info border-info/20"
|
|
1391
|
+
},
|
|
1392
|
+
running: {
|
|
1393
|
+
label: "Running",
|
|
1394
|
+
className: "bg-warning/10 text-warning border-warning/25"
|
|
1395
|
+
},
|
|
1396
|
+
success: {
|
|
1397
|
+
label: "Done",
|
|
1398
|
+
className: "bg-success/10 text-success border-success/20"
|
|
1399
|
+
},
|
|
1400
|
+
error: {
|
|
1401
|
+
label: "Error",
|
|
1402
|
+
className: "bg-destructive/10 text-destructive border-destructive/20"
|
|
1403
|
+
},
|
|
1404
|
+
aborted: {
|
|
1405
|
+
label: "Stopped",
|
|
1406
|
+
className: "bg-muted text-muted-foreground border-border"
|
|
1407
|
+
}
|
|
1408
|
+
}[status];
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Tool call presentation in card, chip, or compact row density.
|
|
1412
|
+
*/
|
|
1413
|
+
function Tool({ name, status: statusProp = "pending", summary, input, output, errorText, detail, diff, variant = "row", defaultOpen = false, open, onOpenChange, className, children }) {
|
|
1414
|
+
const status = normalizeToolStatus(statusProp);
|
|
1415
|
+
const diffs = diff ? Array.isArray(diff) ? diff : [diff] : [];
|
|
1416
|
+
const hasBody = Boolean(children) || Boolean(detail?.length) || input !== void 0 || output !== void 0 || Boolean(errorText) || diffs.length > 0;
|
|
1417
|
+
if (variant === "chip") return /* @__PURE__ */ jsxs("div", {
|
|
1418
|
+
"data-slot": "tool",
|
|
1419
|
+
"data-variant": "chip",
|
|
1420
|
+
"data-status": status,
|
|
1421
|
+
className: cn("inline-flex max-w-full items-center gap-1.5 rounded-md border border-border/80 bg-muted/40 px-2 py-1 text-[12px]", className),
|
|
1422
|
+
children: [
|
|
1423
|
+
/* @__PURE__ */ jsx(StatusIcon, { status }),
|
|
1424
|
+
/* @__PURE__ */ jsx("span", {
|
|
1425
|
+
className: "shrink-0 font-medium text-foreground",
|
|
1426
|
+
children: name
|
|
1427
|
+
}),
|
|
1428
|
+
summary ? /* @__PURE__ */ jsx("span", {
|
|
1429
|
+
className: "min-w-0 truncate font-mono text-muted-foreground",
|
|
1430
|
+
children: summary
|
|
1431
|
+
}) : null
|
|
1432
|
+
]
|
|
1433
|
+
});
|
|
1434
|
+
const trigger = /* @__PURE__ */ jsxs("span", {
|
|
1435
|
+
className: cn("flex min-w-0 max-w-full items-center gap-1.5 text-[13px] text-muted-foreground", variant === "card" && "w-full justify-between font-normal"),
|
|
1436
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1437
|
+
className: "flex min-w-0 items-center gap-1.5",
|
|
1438
|
+
children: [
|
|
1439
|
+
/* @__PURE__ */ jsx(StatusIcon, { status }),
|
|
1440
|
+
/* @__PURE__ */ jsx("span", {
|
|
1441
|
+
className: "shrink-0 font-medium text-foreground/90",
|
|
1442
|
+
children: name
|
|
1443
|
+
}),
|
|
1444
|
+
summary ? /* @__PURE__ */ jsx("span", {
|
|
1445
|
+
className: cn("min-w-0 truncate rounded-md bg-muted px-1.5 py-0.5 font-mono text-[11.5px] text-muted-foreground"),
|
|
1446
|
+
children: summary
|
|
1447
|
+
}) : null,
|
|
1448
|
+
variant === "card" ? /* @__PURE__ */ jsx("span", {
|
|
1449
|
+
className: cn("rounded-full border px-2 py-0.5 text-[11px] font-medium", statusBadge(status).className),
|
|
1450
|
+
children: statusBadge(status).label
|
|
1451
|
+
}) : null
|
|
1452
|
+
]
|
|
1453
|
+
}), hasBody ? /* @__PURE__ */ jsx(ChevronDown, {
|
|
1454
|
+
"data-slot": "collapsible-icon",
|
|
1455
|
+
className: "size-3.5 shrink-0 opacity-0 transition-[opacity,transform] duration-150 group-hover/tool:opacity-100 group-data-[panel-open]/collapsible:opacity-100"
|
|
1456
|
+
}) : null]
|
|
1457
|
+
});
|
|
1458
|
+
if (!hasBody) return /* @__PURE__ */ jsx("div", {
|
|
1459
|
+
"data-slot": "tool",
|
|
1460
|
+
"data-variant": variant,
|
|
1461
|
+
"data-status": status,
|
|
1462
|
+
className: cn("flex w-full items-center py-0.5 text-left", className),
|
|
1463
|
+
children: trigger
|
|
1464
|
+
});
|
|
1465
|
+
const body = /* @__PURE__ */ jsxs("div", {
|
|
1466
|
+
className: "space-y-2 text-[12.5px]",
|
|
1467
|
+
children: [
|
|
1468
|
+
children,
|
|
1469
|
+
detail?.map((line, i) => /* @__PURE__ */ jsx("div", {
|
|
1470
|
+
className: cn("font-mono leading-relaxed text-muted-foreground", line.tone === "add" && "text-success"),
|
|
1471
|
+
children: line.text
|
|
1472
|
+
}, i)),
|
|
1473
|
+
input !== void 0 ? /* @__PURE__ */ jsxs("section", { children: [/* @__PURE__ */ jsx("h4", {
|
|
1474
|
+
className: "mb-1 text-xs font-medium text-muted-foreground",
|
|
1475
|
+
children: "Input"
|
|
1476
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1477
|
+
className: "max-h-40 overflow-auto rounded-md border border-border bg-background p-2 font-mono text-[11.5px] leading-relaxed",
|
|
1478
|
+
children: formatValue(input)
|
|
1479
|
+
})] }) : null,
|
|
1480
|
+
output !== void 0 ? /* @__PURE__ */ jsxs("section", { children: [/* @__PURE__ */ jsx("h4", {
|
|
1481
|
+
className: "mb-1 text-xs font-medium text-muted-foreground",
|
|
1482
|
+
children: "Output"
|
|
1483
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1484
|
+
className: "max-h-48 overflow-auto rounded-md border border-border bg-background p-2 font-mono text-[11.5px] leading-relaxed",
|
|
1485
|
+
children: formatValue(output)
|
|
1486
|
+
})] }) : null,
|
|
1487
|
+
errorText ? /* @__PURE__ */ jsx("section", {
|
|
1488
|
+
className: "rounded-md border border-destructive/30 bg-destructive/8 p-2 text-destructive",
|
|
1489
|
+
children: errorText
|
|
1490
|
+
}) : null,
|
|
1491
|
+
diffs.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
1492
|
+
className: "flex flex-wrap gap-1.5 pt-0.5",
|
|
1493
|
+
children: diffs.map((d) => /* @__PURE__ */ jsxs("span", {
|
|
1494
|
+
className: "inline-flex items-center gap-1.5 rounded-md border border-border bg-muted/50 px-1.5 py-0.5 font-mono text-[11px]",
|
|
1495
|
+
children: [
|
|
1496
|
+
/* @__PURE__ */ jsx("span", {
|
|
1497
|
+
className: "text-foreground",
|
|
1498
|
+
children: d.file
|
|
1499
|
+
}),
|
|
1500
|
+
d.add != null ? /* @__PURE__ */ jsxs("span", {
|
|
1501
|
+
className: "text-success",
|
|
1502
|
+
children: ["+", d.add]
|
|
1503
|
+
}) : null,
|
|
1504
|
+
d.del != null ? /* @__PURE__ */ jsxs("span", {
|
|
1505
|
+
className: "text-destructive",
|
|
1506
|
+
children: ["-", d.del]
|
|
1507
|
+
}) : null
|
|
1508
|
+
]
|
|
1509
|
+
}, d.file))
|
|
1510
|
+
}) : null
|
|
1511
|
+
]
|
|
1512
|
+
});
|
|
1513
|
+
if (variant === "card") return /* @__PURE__ */ jsx("div", {
|
|
1514
|
+
"data-slot": "tool",
|
|
1515
|
+
"data-variant": "card",
|
|
1516
|
+
"data-status": status,
|
|
1517
|
+
className: cn("overflow-hidden rounded-lg border border-border", className),
|
|
1518
|
+
children: /* @__PURE__ */ jsxs(Collapsible, {
|
|
1519
|
+
open,
|
|
1520
|
+
defaultOpen,
|
|
1521
|
+
onOpenChange,
|
|
1522
|
+
className: "group/tool group/collapsible",
|
|
1523
|
+
children: [/* @__PURE__ */ jsx(CollapsibleTrigger, {
|
|
1524
|
+
className: "w-full bg-background px-3 py-2 hover:bg-accent/40",
|
|
1525
|
+
children: trigger
|
|
1526
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
1527
|
+
className: "border-t border-border",
|
|
1528
|
+
innerClassName: "px-3 py-2",
|
|
1529
|
+
children: body
|
|
1530
|
+
})]
|
|
1531
|
+
})
|
|
1532
|
+
});
|
|
1533
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1534
|
+
"data-slot": "tool",
|
|
1535
|
+
"data-variant": "row",
|
|
1536
|
+
"data-status": status,
|
|
1537
|
+
className: cn("flex flex-col", className),
|
|
1538
|
+
children: /* @__PURE__ */ jsxs(Collapsible, {
|
|
1539
|
+
open,
|
|
1540
|
+
defaultOpen,
|
|
1541
|
+
onOpenChange,
|
|
1542
|
+
className: "group/tool group/collapsible",
|
|
1543
|
+
children: [/* @__PURE__ */ jsx(CollapsibleTrigger, {
|
|
1544
|
+
className: cn("group/row -mx-1 flex min-h-8 w-[calc(100%+0.5rem)] min-w-0 items-center gap-2 rounded-md px-1 py-1 text-left", "transition-colors duration-150 hover:bg-accent", "pointer-coarse:min-h-11"),
|
|
1545
|
+
children: trigger
|
|
1546
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
1547
|
+
innerClassName: "py-1 pl-5",
|
|
1548
|
+
children: body
|
|
1549
|
+
})]
|
|
1550
|
+
})
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
function ToolGroup({ label, children, defaultOpen = true, className }) {
|
|
1554
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1555
|
+
"data-slot": "tool-group",
|
|
1556
|
+
className: cn("w-full max-w-md", className),
|
|
1557
|
+
children: /* @__PURE__ */ jsxs(Collapsible, {
|
|
1558
|
+
defaultOpen,
|
|
1559
|
+
className: "group/collapsible",
|
|
1560
|
+
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
1561
|
+
className: cn("-mx-1.5 flex w-fit items-center gap-1.5 rounded-md px-1.5 py-1 text-[12.5px]", "text-muted-foreground transition-colors duration-150 hover:bg-accent hover:text-foreground"),
|
|
1562
|
+
children: [/* @__PURE__ */ jsx(ChevronDown, {
|
|
1563
|
+
"data-slot": "collapsible-icon",
|
|
1564
|
+
className: "size-3"
|
|
1565
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1566
|
+
className: "tabular-nums",
|
|
1567
|
+
children: label
|
|
1568
|
+
})]
|
|
1569
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
1570
|
+
innerClassName: "py-1",
|
|
1571
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1572
|
+
className: "mt-0.5 flex flex-col gap-1",
|
|
1573
|
+
children
|
|
1574
|
+
})
|
|
1575
|
+
})]
|
|
1576
|
+
})
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
//#endregion
|
|
1581
|
+
//#region src/components/ai/approval-card.tsx
|
|
1582
|
+
/**
|
|
1583
|
+
* Human-in-the-loop approval: simple confirm/skip or multi-question flow.
|
|
1584
|
+
*/
|
|
1585
|
+
function ApprovalCard({ title, description, questions, confirmLabel = "Confirm", skipLabel = "Skip", destructive = false, preview, onConfirm, onSkip, onDismiss, className, defaultSent = false }) {
|
|
1586
|
+
const multi = Boolean(questions?.length);
|
|
1587
|
+
const [qi, setQi] = React$1.useState(0);
|
|
1588
|
+
const [answers, setAnswers] = React$1.useState({});
|
|
1589
|
+
const [sent, setSent] = React$1.useState(defaultSent);
|
|
1590
|
+
const question = multi ? questions[qi] : null;
|
|
1591
|
+
const selected = question ? answers[question.id] ?? [] : [];
|
|
1592
|
+
const last = multi ? qi === questions.length - 1 : true;
|
|
1593
|
+
const toggleOption = (optionId) => {
|
|
1594
|
+
if (!question) return;
|
|
1595
|
+
const type = question.type ?? "single";
|
|
1596
|
+
setAnswers((prev) => {
|
|
1597
|
+
const current = prev[question.id] ?? [];
|
|
1598
|
+
const next = type === "single" ? [optionId] : current.includes(optionId) ? current.filter((id) => id !== optionId) : [...current, optionId];
|
|
1599
|
+
return {
|
|
1600
|
+
...prev,
|
|
1601
|
+
[question.id]: next
|
|
1602
|
+
};
|
|
1603
|
+
});
|
|
1604
|
+
if ((question.type ?? "single") === "single") window.setTimeout(() => {
|
|
1605
|
+
if (last) {
|
|
1606
|
+
setSent(true);
|
|
1607
|
+
onConfirm?.({ answers: {
|
|
1608
|
+
...answers,
|
|
1609
|
+
[question.id]: [optionId]
|
|
1610
|
+
} });
|
|
1611
|
+
} else setQi((i) => i + 1);
|
|
1612
|
+
}, 280);
|
|
1613
|
+
};
|
|
1614
|
+
const submitMulti = () => {
|
|
1615
|
+
if (!question) return;
|
|
1616
|
+
if (last) {
|
|
1617
|
+
setSent(true);
|
|
1618
|
+
onConfirm?.({ answers });
|
|
1619
|
+
} else setQi((i) => i + 1);
|
|
1620
|
+
};
|
|
1621
|
+
if (sent) return /* @__PURE__ */ jsxs("div", {
|
|
1622
|
+
"data-slot": "approval-card",
|
|
1623
|
+
className: cn("flex min-h-28 w-full max-w-sm flex-col items-center justify-center gap-2 rounded-xl border border-border bg-card p-4 shadow-xs", className),
|
|
1624
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1625
|
+
className: "flex size-6 items-center justify-center rounded-full bg-success text-white animate-[ai-fade-up_300ms_cubic-bezier(0.23,1,0.32,1)_both]",
|
|
1626
|
+
children: /* @__PURE__ */ jsx(Check, {
|
|
1627
|
+
className: "size-3.5",
|
|
1628
|
+
strokeWidth: 3
|
|
1629
|
+
})
|
|
1630
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1631
|
+
className: "text-[13px] font-medium text-foreground",
|
|
1632
|
+
children: "Approved"
|
|
1633
|
+
})]
|
|
1634
|
+
});
|
|
1635
|
+
if (!multi) return /* @__PURE__ */ jsxs("div", {
|
|
1636
|
+
"data-slot": "approval-card",
|
|
1637
|
+
"data-destructive": destructive ? "true" : "false",
|
|
1638
|
+
className: cn("w-full max-w-md overflow-hidden rounded-xl border bg-card shadow-xs", destructive ? "border-destructive/35" : "border-border", className),
|
|
1639
|
+
children: [
|
|
1640
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1641
|
+
className: "flex items-start justify-between gap-2 px-3 pt-3",
|
|
1642
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1643
|
+
className: "min-w-0 space-y-1",
|
|
1644
|
+
children: [title ? /* @__PURE__ */ jsx("div", {
|
|
1645
|
+
className: "text-[13px] font-medium text-pretty text-foreground",
|
|
1646
|
+
children: title
|
|
1647
|
+
}) : null, description ? /* @__PURE__ */ jsx("div", {
|
|
1648
|
+
className: "text-xs text-pretty text-muted-foreground",
|
|
1649
|
+
children: description
|
|
1650
|
+
}) : null]
|
|
1651
|
+
}), onDismiss ? /* @__PURE__ */ jsx(Button, {
|
|
1652
|
+
type: "button",
|
|
1653
|
+
variant: "ghost",
|
|
1654
|
+
size: "icon-xs",
|
|
1655
|
+
"aria-label": "Dismiss",
|
|
1656
|
+
onClick: onDismiss,
|
|
1657
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
|
|
1658
|
+
}) : null]
|
|
1659
|
+
}),
|
|
1660
|
+
preview ? /* @__PURE__ */ jsx("div", {
|
|
1661
|
+
className: "px-3 pt-2",
|
|
1662
|
+
children: preview
|
|
1663
|
+
}) : null,
|
|
1664
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1665
|
+
className: "flex items-center justify-end gap-1.5 px-3 py-2.5",
|
|
1666
|
+
children: [onSkip ? /* @__PURE__ */ jsx(Button, {
|
|
1667
|
+
type: "button",
|
|
1668
|
+
variant: "ghost",
|
|
1669
|
+
size: "sm",
|
|
1670
|
+
onClick: onSkip,
|
|
1671
|
+
children: skipLabel
|
|
1672
|
+
}) : null, /* @__PURE__ */ jsx(Button, {
|
|
1673
|
+
type: "button",
|
|
1674
|
+
size: "sm",
|
|
1675
|
+
variant: destructive ? "destructive" : "default",
|
|
1676
|
+
onClick: () => {
|
|
1677
|
+
setSent(true);
|
|
1678
|
+
onConfirm?.({});
|
|
1679
|
+
},
|
|
1680
|
+
children: confirmLabel
|
|
1681
|
+
})]
|
|
1682
|
+
})
|
|
1683
|
+
]
|
|
1684
|
+
});
|
|
1685
|
+
const progress = questions.map((_, i) => i <= qi);
|
|
1686
|
+
const canAdvance = selected.length > 0;
|
|
1687
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1688
|
+
"data-slot": "approval-card",
|
|
1689
|
+
className: cn("w-full max-w-sm overflow-hidden rounded-xl border border-border bg-card shadow-xs", className),
|
|
1690
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1691
|
+
className: "p-3 animate-[ai-fade-up_300ms_cubic-bezier(0.23,1,0.32,1)_both] motion-reduce:animate-none",
|
|
1692
|
+
children: [
|
|
1693
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1694
|
+
className: "flex items-start justify-between gap-2",
|
|
1695
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1696
|
+
className: "text-[13px] font-medium text-pretty text-foreground",
|
|
1697
|
+
children: question.prompt
|
|
1698
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1699
|
+
className: "flex items-center gap-1",
|
|
1700
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1701
|
+
className: "flex items-center gap-0.5",
|
|
1702
|
+
"aria-hidden": true,
|
|
1703
|
+
children: progress.map((on, i) => /* @__PURE__ */ jsx("span", { className: cn("h-1 rounded-full transition-[width,background-color] duration-200", on ? "w-3 bg-primary" : "w-1.5 bg-border") }, i))
|
|
1704
|
+
}), onDismiss ? /* @__PURE__ */ jsx(Button, {
|
|
1705
|
+
type: "button",
|
|
1706
|
+
variant: "ghost",
|
|
1707
|
+
size: "icon-xs",
|
|
1708
|
+
"aria-label": "Dismiss",
|
|
1709
|
+
onClick: onDismiss,
|
|
1710
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
|
|
1711
|
+
}) : null]
|
|
1712
|
+
})]
|
|
1713
|
+
}),
|
|
1714
|
+
/* @__PURE__ */ jsx("div", {
|
|
1715
|
+
className: "mt-2 flex flex-col gap-0.5",
|
|
1716
|
+
children: question.options.map((option) => {
|
|
1717
|
+
const on = selected.includes(option.id);
|
|
1718
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
1719
|
+
type: "button",
|
|
1720
|
+
"aria-pressed": on,
|
|
1721
|
+
onClick: () => toggleOption(option.id),
|
|
1722
|
+
className: cn("-mx-1.5 flex min-h-10 items-start gap-2 rounded-md px-1.5 py-1.5 text-left text-[13px]", "transition-colors duration-150 hover:bg-accent", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", on && "bg-accent"),
|
|
1723
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1724
|
+
className: cn("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border", on ? "border-primary bg-primary text-primary-foreground" : "border-border"),
|
|
1725
|
+
children: on ? /* @__PURE__ */ jsx(Check, {
|
|
1726
|
+
className: "size-2.5",
|
|
1727
|
+
strokeWidth: 3
|
|
1728
|
+
}) : null
|
|
1729
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
1730
|
+
className: "min-w-0",
|
|
1731
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1732
|
+
className: "font-medium text-foreground",
|
|
1733
|
+
children: option.label
|
|
1734
|
+
}), option.description ? /* @__PURE__ */ jsx("span", {
|
|
1735
|
+
className: "mt-0.5 block text-xs text-muted-foreground",
|
|
1736
|
+
children: option.description
|
|
1737
|
+
}) : null]
|
|
1738
|
+
})]
|
|
1739
|
+
}, option.id);
|
|
1740
|
+
})
|
|
1741
|
+
}),
|
|
1742
|
+
(question.type === "multiple" || !last) && /* @__PURE__ */ jsx("div", {
|
|
1743
|
+
className: "mt-2 flex justify-end",
|
|
1744
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
1745
|
+
type: "button",
|
|
1746
|
+
size: "icon-sm",
|
|
1747
|
+
"aria-label": last ? confirmLabel : "Next",
|
|
1748
|
+
disabled: !canAdvance,
|
|
1749
|
+
onClick: submitMulti,
|
|
1750
|
+
children: /* @__PURE__ */ jsx(ArrowUp, { className: "size-4" })
|
|
1751
|
+
})
|
|
1752
|
+
})
|
|
1753
|
+
]
|
|
1754
|
+
}, question.id)
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
//#endregion
|
|
1759
|
+
//#region src/components/ai/source.tsx
|
|
1760
|
+
function Source({ href, title, description, favicon, domain, className }) {
|
|
1761
|
+
const host = domain ?? (href ? safeHost(href) : void 0);
|
|
1762
|
+
const content = /* @__PURE__ */ jsxs("span", {
|
|
1763
|
+
"data-slot": "source",
|
|
1764
|
+
className: cn("inline-flex max-w-full items-center gap-1.5 rounded-full border border-border bg-muted/50 px-2 py-0.5 text-[12px]", "text-muted-foreground transition-colors duration-150 hover:bg-accent hover:text-foreground", className),
|
|
1765
|
+
children: [
|
|
1766
|
+
favicon ? /* @__PURE__ */ jsx("img", {
|
|
1767
|
+
src: favicon,
|
|
1768
|
+
alt: "",
|
|
1769
|
+
className: "size-3.5 rounded-sm outline outline-1 outline-black/10 dark:outline-white/10"
|
|
1770
|
+
}) : /* @__PURE__ */ jsx(FileText, { className: "size-3 shrink-0 opacity-70" }),
|
|
1771
|
+
/* @__PURE__ */ jsx("span", {
|
|
1772
|
+
className: "min-w-0 truncate font-medium",
|
|
1773
|
+
children: host ?? title
|
|
1774
|
+
}),
|
|
1775
|
+
href ? /* @__PURE__ */ jsx(ExternalLink, { className: "size-3 shrink-0 opacity-50" }) : null
|
|
1776
|
+
]
|
|
1777
|
+
});
|
|
1778
|
+
const chip = href ? /* @__PURE__ */ jsx("a", {
|
|
1779
|
+
href,
|
|
1780
|
+
target: "_blank",
|
|
1781
|
+
rel: "noreferrer noopener",
|
|
1782
|
+
className: "inline-flex max-w-full",
|
|
1783
|
+
children: content
|
|
1784
|
+
}) : content;
|
|
1785
|
+
if (!description && title === host) return chip;
|
|
1786
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
1787
|
+
asChild: true,
|
|
1788
|
+
children: chip
|
|
1789
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
1790
|
+
side: "top",
|
|
1791
|
+
className: "max-w-xs",
|
|
1792
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1793
|
+
className: "space-y-0.5",
|
|
1794
|
+
children: [
|
|
1795
|
+
/* @__PURE__ */ jsx("div", {
|
|
1796
|
+
className: "font-medium",
|
|
1797
|
+
children: title
|
|
1798
|
+
}),
|
|
1799
|
+
description ? /* @__PURE__ */ jsx("div", {
|
|
1800
|
+
className: "text-xs opacity-90",
|
|
1801
|
+
children: description
|
|
1802
|
+
}) : null,
|
|
1803
|
+
href ? /* @__PURE__ */ jsx("div", {
|
|
1804
|
+
className: "truncate font-mono text-[10px] opacity-70",
|
|
1805
|
+
children: href
|
|
1806
|
+
}) : null
|
|
1807
|
+
]
|
|
1808
|
+
})
|
|
1809
|
+
})] });
|
|
1810
|
+
}
|
|
1811
|
+
function Sources({ children, className, label }) {
|
|
1812
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1813
|
+
"data-slot": "sources",
|
|
1814
|
+
className: cn("flex flex-col gap-1.5", className),
|
|
1815
|
+
children: [label ? /* @__PURE__ */ jsx("div", {
|
|
1816
|
+
className: "text-[11px] font-medium text-muted-foreground",
|
|
1817
|
+
children: label
|
|
1818
|
+
}) : null, /* @__PURE__ */ jsx("div", {
|
|
1819
|
+
className: "flex flex-wrap gap-1.5",
|
|
1820
|
+
children
|
|
1821
|
+
})]
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
function safeHost(url) {
|
|
1825
|
+
try {
|
|
1826
|
+
return new URL(url).hostname.replace(/^www\./, "");
|
|
1827
|
+
} catch {
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
//#endregion
|
|
1833
|
+
//#region src/components/ai/inline-diff.tsx
|
|
1834
|
+
/** Naive line diff for presentation (not a full Myers algorithm). */
|
|
1835
|
+
function lineDiff(before, after) {
|
|
1836
|
+
const a = before.split("\n");
|
|
1837
|
+
const b = after.split("\n");
|
|
1838
|
+
const aSet = new Set(a);
|
|
1839
|
+
const bSet = new Set(b);
|
|
1840
|
+
const lines = [];
|
|
1841
|
+
for (const line of a) if (!bSet.has(line)) lines.push({
|
|
1842
|
+
type: "del",
|
|
1843
|
+
text: line
|
|
1844
|
+
});
|
|
1845
|
+
for (const line of b) if (!aSet.has(line)) lines.push({
|
|
1846
|
+
type: "add",
|
|
1847
|
+
text: line
|
|
1848
|
+
});
|
|
1849
|
+
else if (!lines.some((l) => l.type === "context" && l.text === line)) {}
|
|
1850
|
+
if (lines.length === 0 && before !== after) return [...a.map((text) => ({
|
|
1851
|
+
type: "del",
|
|
1852
|
+
text
|
|
1853
|
+
})), ...b.map((text) => ({
|
|
1854
|
+
type: "add",
|
|
1855
|
+
text
|
|
1856
|
+
}))];
|
|
1857
|
+
const dels = a.filter((line) => !bSet.has(line)).map((text) => ({
|
|
1858
|
+
type: "del",
|
|
1859
|
+
text
|
|
1860
|
+
}));
|
|
1861
|
+
const adds = b.filter((line) => !aSet.has(line)).map((text) => ({
|
|
1862
|
+
type: "add",
|
|
1863
|
+
text
|
|
1864
|
+
}));
|
|
1865
|
+
const shared = b.filter((line) => aSet.has(line)).map((text) => ({
|
|
1866
|
+
type: "context",
|
|
1867
|
+
text
|
|
1868
|
+
}));
|
|
1869
|
+
if (shared.length > 6) return [...dels, ...adds];
|
|
1870
|
+
return [
|
|
1871
|
+
...shared.slice(0, 2),
|
|
1872
|
+
...dels,
|
|
1873
|
+
...adds,
|
|
1874
|
+
...shared.slice(2)
|
|
1875
|
+
];
|
|
1876
|
+
}
|
|
1877
|
+
function InlineDiff({ source, className, maxLines = 40 }) {
|
|
1878
|
+
const lines = React$1.useMemo(() => lineDiff(source.before, source.after), [source.before, source.after]);
|
|
1879
|
+
const visible = lines.slice(0, maxLines);
|
|
1880
|
+
const hidden = lines.length - visible.length;
|
|
1881
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1882
|
+
"data-slot": "inline-diff",
|
|
1883
|
+
className: cn("overflow-hidden rounded-lg border border-border bg-muted/30 font-mono text-[11.5px] leading-relaxed", className),
|
|
1884
|
+
children: [
|
|
1885
|
+
source.fileName ? /* @__PURE__ */ jsx("div", {
|
|
1886
|
+
className: "border-b border-border/80 bg-muted/50 px-2.5 py-1 text-xs text-muted-foreground",
|
|
1887
|
+
children: source.fileName
|
|
1888
|
+
}) : null,
|
|
1889
|
+
/* @__PURE__ */ jsx("pre", {
|
|
1890
|
+
className: "overflow-x-auto p-0",
|
|
1891
|
+
children: visible.map((line, i) => /* @__PURE__ */ jsxs("div", {
|
|
1892
|
+
className: cn("flex gap-2 px-2.5 py-0.5", line.type === "add" && "bg-success/10 text-success", line.type === "del" && "bg-destructive/10 text-destructive", line.type === "context" && "text-muted-foreground"),
|
|
1893
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1894
|
+
className: "w-3 shrink-0 select-none opacity-70",
|
|
1895
|
+
children: line.type === "add" ? "+" : line.type === "del" ? "-" : " "
|
|
1896
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1897
|
+
className: "min-w-0 whitespace-pre-wrap break-all",
|
|
1898
|
+
children: line.text || " "
|
|
1899
|
+
})]
|
|
1900
|
+
}, i))
|
|
1901
|
+
}),
|
|
1902
|
+
hidden > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
1903
|
+
className: "border-t border-border/60 px-2.5 py-1 text-[11px] text-muted-foreground",
|
|
1904
|
+
children: [
|
|
1905
|
+
"+",
|
|
1906
|
+
hidden,
|
|
1907
|
+
" more lines"
|
|
1908
|
+
]
|
|
1909
|
+
}) : null
|
|
1910
|
+
]
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
//#endregion
|
|
1915
|
+
//#region src/components/ai/feedback-bar.tsx
|
|
1916
|
+
/**
|
|
1917
|
+
* Message action row: copy, regenerate, thumbs.
|
|
1918
|
+
*/
|
|
1919
|
+
function FeedbackBar({ className, onCopy, onRegenerate, onFeedback, copyText, showCopy = true, showRegenerate = true, showFeedback = true }) {
|
|
1920
|
+
const [copied, setCopied] = React$1.useState(false);
|
|
1921
|
+
const [feedback, setFeedback] = React$1.useState(null);
|
|
1922
|
+
const handleCopy = async () => {
|
|
1923
|
+
try {
|
|
1924
|
+
if (copyText) await navigator.clipboard.writeText(copyText);
|
|
1925
|
+
await onCopy?.();
|
|
1926
|
+
setCopied(true);
|
|
1927
|
+
window.setTimeout(() => setCopied(false), 1500);
|
|
1928
|
+
} catch {}
|
|
1929
|
+
};
|
|
1930
|
+
const setFb = (value) => {
|
|
1931
|
+
const next = feedback === value ? null : value;
|
|
1932
|
+
setFeedback(next);
|
|
1933
|
+
onFeedback?.(next);
|
|
1934
|
+
};
|
|
1935
|
+
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs("div", {
|
|
1936
|
+
"data-slot": "feedback-bar",
|
|
1937
|
+
className: cn("flex items-center gap-0.5 text-muted-foreground", className),
|
|
1938
|
+
children: [
|
|
1939
|
+
showCopy ? /* @__PURE__ */ jsx(Action, {
|
|
1940
|
+
tip: copied ? "Copied" : "Copy",
|
|
1941
|
+
onClick: handleCopy,
|
|
1942
|
+
label: copied ? "Copied" : "Copy",
|
|
1943
|
+
children: copied ? /* @__PURE__ */ jsx(Check, { className: "size-3.5" }) : /* @__PURE__ */ jsx(Copy, { className: "size-3.5" })
|
|
1944
|
+
}) : null,
|
|
1945
|
+
showRegenerate && onRegenerate ? /* @__PURE__ */ jsx(Action, {
|
|
1946
|
+
tip: "Regenerate",
|
|
1947
|
+
onClick: onRegenerate,
|
|
1948
|
+
label: "Regenerate",
|
|
1949
|
+
children: /* @__PURE__ */ jsx(RefreshCw, { className: "size-3.5" })
|
|
1950
|
+
}) : null,
|
|
1951
|
+
showFeedback ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Action, {
|
|
1952
|
+
tip: "Good response",
|
|
1953
|
+
onClick: () => setFb("up"),
|
|
1954
|
+
label: "Good response",
|
|
1955
|
+
active: feedback === "up",
|
|
1956
|
+
children: /* @__PURE__ */ jsx(ThumbsUp, { className: "size-3.5" })
|
|
1957
|
+
}), /* @__PURE__ */ jsx(Action, {
|
|
1958
|
+
tip: "Bad response",
|
|
1959
|
+
onClick: () => setFb("down"),
|
|
1960
|
+
label: "Bad response",
|
|
1961
|
+
active: feedback === "down",
|
|
1962
|
+
children: /* @__PURE__ */ jsx(ThumbsDown, { className: "size-3.5" })
|
|
1963
|
+
})] }) : null
|
|
1964
|
+
]
|
|
1965
|
+
}) });
|
|
1966
|
+
}
|
|
1967
|
+
function Action({ tip, children, onClick, label, active }) {
|
|
1968
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
1969
|
+
asChild: true,
|
|
1970
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
1971
|
+
type: "button",
|
|
1972
|
+
variant: "ghost",
|
|
1973
|
+
size: "icon-xs",
|
|
1974
|
+
"aria-label": label,
|
|
1975
|
+
"aria-pressed": active,
|
|
1976
|
+
onClick,
|
|
1977
|
+
className: cn(active && "bg-accent text-foreground"),
|
|
1978
|
+
children
|
|
1979
|
+
})
|
|
1980
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
1981
|
+
side: "bottom",
|
|
1982
|
+
children: tip
|
|
1983
|
+
})] });
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
//#endregion
|
|
1987
|
+
//#region src/components/ai/prompt-suggestion.tsx
|
|
1988
|
+
function PromptSuggestion({ children, onClick, className }) {
|
|
1989
|
+
return /* @__PURE__ */ jsx("button", {
|
|
1990
|
+
type: "button",
|
|
1991
|
+
"data-slot": "prompt-suggestion",
|
|
1992
|
+
onClick,
|
|
1993
|
+
className: cn("inline-flex max-w-full items-center rounded-full border border-border bg-background px-3 py-1.5", "text-left text-[13px] text-foreground shadow-xs", "transition-[background-color,box-shadow,transform] duration-150 ease-out", "hover:bg-accent hover:shadow-sm", "motion-safe:active:scale-[0.98]", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", className),
|
|
1994
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
1995
|
+
className: "min-w-0 truncate",
|
|
1996
|
+
children
|
|
1997
|
+
})
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
function PromptSuggestions({ children, className, label = "Follow-ups" }) {
|
|
2001
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2002
|
+
"data-slot": "prompt-suggestions",
|
|
2003
|
+
className: cn("flex flex-col gap-2", className),
|
|
2004
|
+
children: [label ? /* @__PURE__ */ jsx("div", {
|
|
2005
|
+
className: "text-[12px] font-medium text-muted-foreground",
|
|
2006
|
+
children: label
|
|
2007
|
+
}) : null, /* @__PURE__ */ jsx("div", {
|
|
2008
|
+
className: "flex flex-wrap gap-1.5",
|
|
2009
|
+
children
|
|
2010
|
+
})]
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
//#endregion
|
|
2015
|
+
//#region src/components/ai/streaming-text.tsx
|
|
2016
|
+
/**
|
|
2017
|
+
* Streamed answer with blur-resolve words, citation chips, actions, follow-ups.
|
|
2018
|
+
* For production, drive `streaming` + full `text` from the host; the interval
|
|
2019
|
+
* path is for demos when tokens arrive as a finished string.
|
|
2020
|
+
*/
|
|
2021
|
+
function StreamingText({ text = "", tokens, sources = [], followUps = [], onFollowUp, streaming = true, wordIntervalMs = 48, showActions = true, onCopy, className }) {
|
|
2022
|
+
const words = React$1.useMemo(() => {
|
|
2023
|
+
if (tokens) return null;
|
|
2024
|
+
return text.split(/(\s+)/).filter(Boolean);
|
|
2025
|
+
}, [text, tokens]);
|
|
2026
|
+
const total = tokens?.length ?? words?.length ?? 0;
|
|
2027
|
+
const [visible, setVisible] = React$1.useState(streaming ? 0 : Number.MAX_SAFE_INTEGER);
|
|
2028
|
+
React$1.useEffect(() => {
|
|
2029
|
+
if (!streaming) {
|
|
2030
|
+
setVisible(Number.MAX_SAFE_INTEGER);
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
setVisible(0);
|
|
2034
|
+
if (total === 0) return;
|
|
2035
|
+
const id = window.setInterval(() => {
|
|
2036
|
+
setVisible((v) => {
|
|
2037
|
+
if (v >= total) {
|
|
2038
|
+
window.clearInterval(id);
|
|
2039
|
+
return v;
|
|
2040
|
+
}
|
|
2041
|
+
return v + 1;
|
|
2042
|
+
});
|
|
2043
|
+
}, wordIntervalMs);
|
|
2044
|
+
return () => window.clearInterval(id);
|
|
2045
|
+
}, [
|
|
2046
|
+
streaming,
|
|
2047
|
+
tokens,
|
|
2048
|
+
words,
|
|
2049
|
+
wordIntervalMs,
|
|
2050
|
+
text,
|
|
2051
|
+
total
|
|
2052
|
+
]);
|
|
2053
|
+
const done = !streaming || visible >= total;
|
|
2054
|
+
/** Blur only the newest token while still revealing — not after the run settles. */
|
|
2055
|
+
const revealing = streaming && visible < total;
|
|
2056
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2057
|
+
"data-slot": "streaming-text",
|
|
2058
|
+
className: cn("flex w-full flex-col gap-3", className),
|
|
2059
|
+
children: [
|
|
2060
|
+
/* @__PURE__ */ jsx("div", {
|
|
2061
|
+
className: "text-[13px] leading-relaxed text-pretty text-foreground",
|
|
2062
|
+
children: tokens ? tokens.slice(0, visible).map((tok, i) => {
|
|
2063
|
+
if (tok.type === "cite") {
|
|
2064
|
+
const src = sources.find((s) => s.id === tok.id);
|
|
2065
|
+
return /* @__PURE__ */ jsx("sup", {
|
|
2066
|
+
className: "mx-0.5",
|
|
2067
|
+
children: /* @__PURE__ */ jsx(Source, {
|
|
2068
|
+
title: src?.title ?? tok.id,
|
|
2069
|
+
href: src?.href,
|
|
2070
|
+
description: src?.description,
|
|
2071
|
+
className: "align-super text-[10px]"
|
|
2072
|
+
})
|
|
2073
|
+
}, i);
|
|
2074
|
+
}
|
|
2075
|
+
return /* @__PURE__ */ jsx("span", {
|
|
2076
|
+
className: cn("transition-[filter,opacity] duration-200 ease-out motion-reduce:transition-none", i === visible - 1 && revealing ? "opacity-90 blur-[2px] motion-reduce:blur-0" : "opacity-100 blur-0"),
|
|
2077
|
+
children: tok.text
|
|
2078
|
+
}, i);
|
|
2079
|
+
}) : words?.slice(0, visible).map((w, i) => /* @__PURE__ */ jsx("span", {
|
|
2080
|
+
className: cn("transition-[filter,opacity] duration-200 ease-out motion-reduce:transition-none", i === visible - 1 && revealing && !/^\s+$/.test(w) ? "opacity-90 blur-[2px] motion-reduce:blur-0" : "opacity-100 blur-0"),
|
|
2081
|
+
children: w
|
|
2082
|
+
}, i))
|
|
2083
|
+
}),
|
|
2084
|
+
sources.length > 0 && done ? /* @__PURE__ */ jsx(Sources, {
|
|
2085
|
+
label: `${sources.length} sources`,
|
|
2086
|
+
children: sources.map((s) => /* @__PURE__ */ jsx(Source, {
|
|
2087
|
+
title: s.title,
|
|
2088
|
+
href: s.href,
|
|
2089
|
+
description: s.description
|
|
2090
|
+
}, s.id))
|
|
2091
|
+
}) : null,
|
|
2092
|
+
showActions && done ? /* @__PURE__ */ jsx(FeedbackBar, {
|
|
2093
|
+
copyText: text,
|
|
2094
|
+
onCopy,
|
|
2095
|
+
showRegenerate: false
|
|
2096
|
+
}) : null,
|
|
2097
|
+
followUps.length > 0 && done ? /* @__PURE__ */ jsx(PromptSuggestions, { children: followUps.map((f) => /* @__PURE__ */ jsx(PromptSuggestion, {
|
|
2098
|
+
onClick: () => onFollowUp?.(f),
|
|
2099
|
+
children: f
|
|
2100
|
+
}, f)) }) : null
|
|
2101
|
+
]
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
//#endregion
|
|
2106
|
+
//#region src/components/ai/diff-table.tsx
|
|
2107
|
+
/**
|
|
2108
|
+
* Table of proposed AI edits: removed rows tint destructive, added rows tint success.
|
|
2109
|
+
*/
|
|
2110
|
+
function DiffTable({ title = "Proposed changes", columns, rows, addedRows = [], animate = false, className }) {
|
|
2111
|
+
const [stage, setStage] = React$1.useState(animate ? 0 : 2);
|
|
2112
|
+
React$1.useEffect(() => {
|
|
2113
|
+
if (!animate) {
|
|
2114
|
+
setStage(2);
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
setStage(0);
|
|
2118
|
+
const t1 = window.setTimeout(() => setStage(1), 500);
|
|
2119
|
+
const t2 = window.setTimeout(() => setStage(2), 1100);
|
|
2120
|
+
return () => {
|
|
2121
|
+
window.clearTimeout(t1);
|
|
2122
|
+
window.clearTimeout(t2);
|
|
2123
|
+
};
|
|
2124
|
+
}, [
|
|
2125
|
+
animate,
|
|
2126
|
+
rows,
|
|
2127
|
+
addedRows
|
|
2128
|
+
]);
|
|
2129
|
+
const showRemovedTint = stage >= 1;
|
|
2130
|
+
const showAdded = stage >= 2 && addedRows.length > 0;
|
|
2131
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2132
|
+
"data-slot": "diff-table",
|
|
2133
|
+
className: cn("w-full overflow-hidden rounded-xl border border-border bg-card shadow-xs", className),
|
|
2134
|
+
children: [title ? /* @__PURE__ */ jsx("div", {
|
|
2135
|
+
className: "flex items-center justify-between border-b border-border px-3 py-2",
|
|
2136
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
2137
|
+
className: "text-[12.5px] font-medium text-foreground",
|
|
2138
|
+
children: title
|
|
2139
|
+
})
|
|
2140
|
+
}) : null, /* @__PURE__ */ jsx("div", {
|
|
2141
|
+
className: "overflow-x-auto",
|
|
2142
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
2143
|
+
className: "w-full border-collapse text-left text-[13px]",
|
|
2144
|
+
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", {
|
|
2145
|
+
className: "border-b border-border",
|
|
2146
|
+
children: columns.map((col) => /* @__PURE__ */ jsx("th", {
|
|
2147
|
+
scope: "col",
|
|
2148
|
+
className: cn("px-3 py-2 text-[12px] font-medium text-muted-foreground", col.className),
|
|
2149
|
+
children: col.header
|
|
2150
|
+
}, col.id))
|
|
2151
|
+
}) }), /* @__PURE__ */ jsxs("tbody", { children: [rows.map((row) => {
|
|
2152
|
+
const out = Boolean(row.removed && showRemovedTint);
|
|
2153
|
+
return /* @__PURE__ */ jsx("tr", {
|
|
2154
|
+
"data-removed": out ? "true" : void 0,
|
|
2155
|
+
className: cn("border-b border-border last:border-0", "transition-colors duration-200 ease-out motion-reduce:transition-none", out && "bg-destructive/8"),
|
|
2156
|
+
children: columns.map((col, colIndex) => /* @__PURE__ */ jsx("td", {
|
|
2157
|
+
className: cn("px-3 py-2 align-middle transition-colors duration-200 motion-reduce:transition-none", out && "text-destructive", out && colIndex > 0 && "line-through decoration-destructive/50", !out && colIndex === 0 && "font-medium text-foreground", !out && colIndex > 0 && "text-muted-foreground", col.className),
|
|
2158
|
+
children: col.cell(row)
|
|
2159
|
+
}, col.id))
|
|
2160
|
+
}, row.id);
|
|
2161
|
+
}), addedRows.map((row) => /* @__PURE__ */ jsx("tr", {
|
|
2162
|
+
className: "border-0",
|
|
2163
|
+
children: /* @__PURE__ */ jsx("td", {
|
|
2164
|
+
colSpan: columns.length,
|
|
2165
|
+
className: "p-0",
|
|
2166
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2167
|
+
className: cn("grid transition-[grid-template-rows,opacity] duration-300 ease-out motion-reduce:transition-none", showAdded ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0"),
|
|
2168
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2169
|
+
className: "overflow-hidden bg-success/8",
|
|
2170
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2171
|
+
className: "grid items-center border-t border-border",
|
|
2172
|
+
style: { gridTemplateColumns: `repeat(${columns.length}, minmax(0, 1fr))` },
|
|
2173
|
+
children: row.cells.map((cell, i) => /* @__PURE__ */ jsx("div", {
|
|
2174
|
+
className: cn("px-3 py-2 text-success", i === 0 && "font-medium"),
|
|
2175
|
+
children: cell
|
|
2176
|
+
}, i))
|
|
2177
|
+
})
|
|
2178
|
+
})
|
|
2179
|
+
})
|
|
2180
|
+
})
|
|
2181
|
+
}, row.id))] })]
|
|
2182
|
+
})
|
|
2183
|
+
})]
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
//#endregion
|
|
2188
|
+
//#region src/components/ai/plan-tracker.tsx
|
|
2189
|
+
/**
|
|
2190
|
+
* Live agent plan checklist, typically pinned above the composer.
|
|
2191
|
+
*/
|
|
2192
|
+
function PlanTracker({ plan, streaming = false, className, flushBottom = true, defaultOpen = false, open, onOpenChange }) {
|
|
2193
|
+
if (!plan || plan.steps.length === 0) return null;
|
|
2194
|
+
const total = plan.steps.length;
|
|
2195
|
+
const done = plan.steps.filter((s) => s.status === "done").length;
|
|
2196
|
+
const complete = done === total;
|
|
2197
|
+
const activeIndex = plan.steps.findIndex((s) => s.status === "in_progress");
|
|
2198
|
+
const focusIndex = activeIndex >= 0 ? activeIndex : streaming ? plan.steps.findIndex((s) => s.status === "pending") : -1;
|
|
2199
|
+
const focusStep = focusIndex >= 0 ? plan.steps[focusIndex] : null;
|
|
2200
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2201
|
+
"data-slot": "plan-tracker",
|
|
2202
|
+
className: cn("w-full", className),
|
|
2203
|
+
children: /* @__PURE__ */ jsx(Collapsible, {
|
|
2204
|
+
open,
|
|
2205
|
+
defaultOpen,
|
|
2206
|
+
onOpenChange,
|
|
2207
|
+
className: "group/collapsible",
|
|
2208
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
2209
|
+
className: cn("border border-input bg-muted/40", flushBottom ? "rounded-t-xl border-b-0" : "rounded-xl"),
|
|
2210
|
+
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
2211
|
+
className: cn("group flex w-full items-center gap-1.5 px-3 py-2 text-left text-[13px]", "text-muted-foreground transition-colors duration-150 hover:text-foreground"),
|
|
2212
|
+
children: [
|
|
2213
|
+
/* @__PURE__ */ jsx(ListChecks, { className: "size-3.5 shrink-0" }),
|
|
2214
|
+
complete ? /* @__PURE__ */ jsx("span", {
|
|
2215
|
+
className: "min-w-0 flex-1 truncate font-medium",
|
|
2216
|
+
children: `${total}/${total} done`
|
|
2217
|
+
}) : focusStep ? /* @__PURE__ */ jsxs("span", {
|
|
2218
|
+
className: "min-w-0 flex-1 truncate font-medium",
|
|
2219
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
2220
|
+
className: "mr-1.5 font-mono text-[12px] font-normal tabular-nums text-muted-foreground/60",
|
|
2221
|
+
children: [
|
|
2222
|
+
focusIndex + 1,
|
|
2223
|
+
"/",
|
|
2224
|
+
total
|
|
2225
|
+
]
|
|
2226
|
+
}), focusStep.label]
|
|
2227
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
2228
|
+
className: "min-w-0 flex-1 truncate font-medium",
|
|
2229
|
+
children: `${done}/${total} steps`
|
|
2230
|
+
}),
|
|
2231
|
+
/* @__PURE__ */ jsx(ChevronDown, {
|
|
2232
|
+
"data-slot": "collapsible-icon",
|
|
2233
|
+
className: "size-3.5 shrink-0 text-muted-foreground/60"
|
|
2234
|
+
})
|
|
2235
|
+
]
|
|
2236
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
2237
|
+
innerClassName: "py-0",
|
|
2238
|
+
children: /* @__PURE__ */ jsx("ul", {
|
|
2239
|
+
className: "max-h-48 overflow-y-auto px-2 pb-1",
|
|
2240
|
+
children: plan.steps.map((step, i) => /* @__PURE__ */ jsx(PlanRow, { step }, `${step.label}-${i}`))
|
|
2241
|
+
})
|
|
2242
|
+
})]
|
|
2243
|
+
})
|
|
2244
|
+
})
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
function PlanRow({ step }) {
|
|
2248
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
2249
|
+
className: "flex items-center gap-2 rounded-md px-1.5 py-1 text-[13px]",
|
|
2250
|
+
children: [/* @__PURE__ */ jsx(StepIcon, { status: step.status }), /* @__PURE__ */ jsx("span", {
|
|
2251
|
+
className: cn("min-w-0 flex-1 truncate", step.status === "done" ? "text-muted-foreground line-through" : "text-foreground"),
|
|
2252
|
+
children: step.label
|
|
2253
|
+
})]
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
function StepIcon({ status }) {
|
|
2257
|
+
if (status === "done") return /* @__PURE__ */ jsx(Check, { className: "size-3.5 shrink-0 text-success" });
|
|
2258
|
+
if (status === "in_progress") return /* @__PURE__ */ jsx(CircleDashed, { className: "size-3.5 shrink-0 text-foreground/70" });
|
|
2259
|
+
return /* @__PURE__ */ jsx(Circle, { className: "size-3.5 shrink-0 text-muted-foreground/40" });
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
//#endregion
|
|
2263
|
+
//#region src/components/ai/context-ring.tsx
|
|
2264
|
+
function formatCompact(n) {
|
|
2265
|
+
if (n >= 1e6) {
|
|
2266
|
+
const m = n / 1e6;
|
|
2267
|
+
return `${Number.isInteger(m) ? m : m.toFixed(m < 10 ? 2 : 1)}M`;
|
|
2268
|
+
}
|
|
2269
|
+
if (n >= 1e3) {
|
|
2270
|
+
const k = n / 1e3;
|
|
2271
|
+
return `${Number.isInteger(k) ? k : k.toFixed(k < 10 ? 1 : 0)}K`;
|
|
2272
|
+
}
|
|
2273
|
+
return String(n);
|
|
2274
|
+
}
|
|
2275
|
+
function meterTone(pct, recomputing, hasUsage) {
|
|
2276
|
+
if (!hasUsage) return "idle";
|
|
2277
|
+
if (recomputing) return "recomputing";
|
|
2278
|
+
if (pct >= 95) return "critical";
|
|
2279
|
+
if (pct >= 80) return "warn";
|
|
2280
|
+
return "ok";
|
|
2281
|
+
}
|
|
2282
|
+
function toneStroke(tone) {
|
|
2283
|
+
switch (tone) {
|
|
2284
|
+
case "critical": return "var(--destructive)";
|
|
2285
|
+
case "warn": return "var(--warning)";
|
|
2286
|
+
case "recomputing": return "var(--muted-foreground)";
|
|
2287
|
+
case "ok": return "var(--primary)";
|
|
2288
|
+
default: return "var(--border)";
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
* Snap to fixed decimals so SVG attrs match across SSR and client.
|
|
2293
|
+
* Raw Math.cos/sin floats can differ by a ULP between Node and the browser,
|
|
2294
|
+
* which React reports as a hydration mismatch on line/circle coordinates.
|
|
2295
|
+
*/
|
|
2296
|
+
function snap(n, digits = 3) {
|
|
2297
|
+
const f = 10 ** digits;
|
|
2298
|
+
return Math.round(n * f) / f;
|
|
2299
|
+
}
|
|
2300
|
+
/** Polar point; 0% is 12 o'clock, clockwise. */
|
|
2301
|
+
function polar(cx, cy, r, pct) {
|
|
2302
|
+
const rad = pct / 100 * Math.PI * 2 - Math.PI / 2;
|
|
2303
|
+
return {
|
|
2304
|
+
x: snap(cx + r * Math.cos(rad)),
|
|
2305
|
+
y: snap(cy + r * Math.sin(rad))
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* Compact context-window meter: linear segmented bar, bent into a ring.
|
|
2310
|
+
* Filled ticks glow; remaining ticks stay quiet.
|
|
2311
|
+
*/
|
|
2312
|
+
function ContextRing({ usage, size = 24, stroke = 2, className }) {
|
|
2313
|
+
const uid = React$1.useId().replace(/:/g, "");
|
|
2314
|
+
const center = size / 2;
|
|
2315
|
+
const glowPad = snap(Math.max(4, size * .18));
|
|
2316
|
+
const recomputing = !!usage && usage.tokens === null;
|
|
2317
|
+
const pct = usage && usage.percent != null ? Math.max(0, Math.min(100, usage.percent)) : 0;
|
|
2318
|
+
const tone = meterTone(pct, recomputing, !!usage);
|
|
2319
|
+
const color = toneStroke(tone);
|
|
2320
|
+
const hit = Math.max(size, 32);
|
|
2321
|
+
const tickCount = size >= 36 ? 40 : size >= 28 ? 32 : 28;
|
|
2322
|
+
const barLen = snap(Math.max(3.2, size * .18));
|
|
2323
|
+
const barWidth = snap(Math.max(1.15, Math.min(1.75, stroke * .72)));
|
|
2324
|
+
const rOuter = snap(size / 2 - glowPad * .15);
|
|
2325
|
+
const rInner = snap(rOuter - barLen);
|
|
2326
|
+
const filledCount = usage ? Math.round(pct / 100 * tickCount) : 0;
|
|
2327
|
+
const blurStd = snap(Math.max(1.4, size * .06));
|
|
2328
|
+
const glowId = `ctx-bar-glow-${uid}`;
|
|
2329
|
+
let tooltip;
|
|
2330
|
+
if (!usage) tooltip = "No usage yet";
|
|
2331
|
+
else if (usage.tokens === null) tooltip = "Recomputing after compaction…";
|
|
2332
|
+
else tooltip = `${Math.round(usage.percent ?? 0)}% used · ${formatCompact(usage.tokens)} / ${formatCompact(usage.contextWindow)}`;
|
|
2333
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
2334
|
+
asChild: true,
|
|
2335
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
2336
|
+
"data-slot": "context-ring",
|
|
2337
|
+
"data-tone": tone,
|
|
2338
|
+
"aria-label": tooltip,
|
|
2339
|
+
className: cn("inline-flex items-center justify-center", className),
|
|
2340
|
+
style: {
|
|
2341
|
+
width: hit,
|
|
2342
|
+
height: hit
|
|
2343
|
+
},
|
|
2344
|
+
children: /* @__PURE__ */ jsxs("svg", {
|
|
2345
|
+
width: size,
|
|
2346
|
+
height: size,
|
|
2347
|
+
viewBox: `${-glowPad} ${-glowPad} ${size + glowPad * 2} ${size + glowPad * 2}`,
|
|
2348
|
+
className: cn(recomputing && "motion-safe:animate-pulse"),
|
|
2349
|
+
"aria-hidden": true,
|
|
2350
|
+
children: [/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("filter", {
|
|
2351
|
+
id: glowId,
|
|
2352
|
+
x: "-120%",
|
|
2353
|
+
y: "-120%",
|
|
2354
|
+
width: "340%",
|
|
2355
|
+
height: "340%",
|
|
2356
|
+
colorInterpolationFilters: "sRGB",
|
|
2357
|
+
children: [
|
|
2358
|
+
/* @__PURE__ */ jsx("feGaussianBlur", {
|
|
2359
|
+
stdDeviation: blurStd,
|
|
2360
|
+
result: "blur"
|
|
2361
|
+
}),
|
|
2362
|
+
/* @__PURE__ */ jsx("feColorMatrix", {
|
|
2363
|
+
in: "blur",
|
|
2364
|
+
type: "matrix",
|
|
2365
|
+
values: "1 0 0 0 0\n 0 1 0 0 0\n 0 0 1 0 0\n 0 0 0 0.75 0",
|
|
2366
|
+
result: "glow"
|
|
2367
|
+
}),
|
|
2368
|
+
/* @__PURE__ */ jsxs("feMerge", { children: [/* @__PURE__ */ jsx("feMergeNode", { in: "glow" }), /* @__PURE__ */ jsx("feMergeNode", { in: "SourceGraphic" })] })
|
|
2369
|
+
]
|
|
2370
|
+
}) }), Array.from({ length: tickCount }, (_, i) => {
|
|
2371
|
+
const t = (i + .5) / tickCount * 100;
|
|
2372
|
+
const filled = i < filledCount;
|
|
2373
|
+
const isFrontier = filled && i === filledCount - 1;
|
|
2374
|
+
const outer = polar(center, center, rOuter, t);
|
|
2375
|
+
const inner = polar(center, center, rInner, t);
|
|
2376
|
+
return /* @__PURE__ */ jsx("line", {
|
|
2377
|
+
x1: inner.x,
|
|
2378
|
+
y1: inner.y,
|
|
2379
|
+
x2: outer.x,
|
|
2380
|
+
y2: outer.y,
|
|
2381
|
+
stroke: filled ? color : "var(--border)",
|
|
2382
|
+
strokeWidth: barWidth,
|
|
2383
|
+
strokeLinecap: "round",
|
|
2384
|
+
opacity: filled ? recomputing ? .55 : isFrontier ? 1 : .92 : usage ? .38 : .28,
|
|
2385
|
+
filter: filled ? `url(#${glowId})` : void 0,
|
|
2386
|
+
className: "transition-[stroke,opacity] duration-200 ease-out"
|
|
2387
|
+
}, i);
|
|
2388
|
+
})]
|
|
2389
|
+
})
|
|
2390
|
+
})
|
|
2391
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
2392
|
+
side: "top",
|
|
2393
|
+
children: tooltip
|
|
2394
|
+
})] });
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
//#endregion
|
|
2398
|
+
//#region src/components/ai/task-row.tsx
|
|
2399
|
+
function TaskRow({ label, meta, status, progress, details, onRetry, className, defaultOpen = false, index = 0 }) {
|
|
2400
|
+
const hasDetails = Boolean(details?.length);
|
|
2401
|
+
const header = /* @__PURE__ */ jsxs("div", {
|
|
2402
|
+
className: "flex min-w-0 flex-1 items-center gap-2.5",
|
|
2403
|
+
children: [
|
|
2404
|
+
/* @__PURE__ */ jsx("span", {
|
|
2405
|
+
className: "relative flex size-6 shrink-0 items-center justify-center",
|
|
2406
|
+
children: status === "running" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("svg", {
|
|
2407
|
+
width: "24",
|
|
2408
|
+
height: "24",
|
|
2409
|
+
className: "absolute inset-0 animate-spin motion-reduce:animate-none",
|
|
2410
|
+
style: { animationDuration: "1.1s" },
|
|
2411
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
2412
|
+
cx: "12",
|
|
2413
|
+
cy: "12",
|
|
2414
|
+
r: "10",
|
|
2415
|
+
fill: "none",
|
|
2416
|
+
stroke: "var(--border)",
|
|
2417
|
+
strokeWidth: "2"
|
|
2418
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
2419
|
+
cx: "12",
|
|
2420
|
+
cy: "12",
|
|
2421
|
+
r: "10",
|
|
2422
|
+
fill: "none",
|
|
2423
|
+
stroke: "var(--muted-foreground)",
|
|
2424
|
+
strokeWidth: "2",
|
|
2425
|
+
strokeLinecap: "round",
|
|
2426
|
+
strokeDasharray: `${2 * Math.PI * 10 * .28} ${2 * Math.PI * 10 * .72}`
|
|
2427
|
+
})]
|
|
2428
|
+
}), progress != null ? /* @__PURE__ */ jsx("span", {
|
|
2429
|
+
className: "relative text-[10px] font-semibold tabular-nums text-foreground",
|
|
2430
|
+
children: Math.round(progress)
|
|
2431
|
+
}) : /* @__PURE__ */ jsx(Loader2, { className: "relative size-3 animate-spin text-muted-foreground motion-reduce:animate-none" })] }) : status === "completed" ? /* @__PURE__ */ jsx("span", {
|
|
2432
|
+
className: "flex size-5 items-center justify-center rounded-full bg-success text-white",
|
|
2433
|
+
children: /* @__PURE__ */ jsx(Check, {
|
|
2434
|
+
className: "size-3",
|
|
2435
|
+
strokeWidth: 3
|
|
2436
|
+
})
|
|
2437
|
+
}) : status === "failed" ? /* @__PURE__ */ jsx("span", {
|
|
2438
|
+
className: "flex size-5 items-center justify-center rounded-full bg-destructive text-white",
|
|
2439
|
+
children: /* @__PURE__ */ jsx(X, {
|
|
2440
|
+
className: "size-3",
|
|
2441
|
+
strokeWidth: 3
|
|
2442
|
+
})
|
|
2443
|
+
}) : /* @__PURE__ */ jsx("span", { className: "size-5 rounded-full border border-border" })
|
|
2444
|
+
}),
|
|
2445
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2446
|
+
className: "min-w-0 flex-1",
|
|
2447
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2448
|
+
className: "truncate text-[13px] font-medium text-foreground",
|
|
2449
|
+
children: label
|
|
2450
|
+
}), meta ? /* @__PURE__ */ jsx("div", {
|
|
2451
|
+
className: "truncate text-[12px] text-muted-foreground",
|
|
2452
|
+
children: meta
|
|
2453
|
+
}) : null]
|
|
2454
|
+
}),
|
|
2455
|
+
status === "completed" ? /* @__PURE__ */ jsx("span", {
|
|
2456
|
+
className: "inline-flex h-5 items-center rounded-full bg-success/10 px-2 text-[11.5px] font-medium text-success",
|
|
2457
|
+
children: "Completed"
|
|
2458
|
+
}) : status === "failed" ? /* @__PURE__ */ jsxs("span", {
|
|
2459
|
+
className: "inline-flex items-center gap-1",
|
|
2460
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2461
|
+
className: "inline-flex h-5 items-center rounded-full bg-destructive/10 px-2 text-[11.5px] font-medium text-destructive",
|
|
2462
|
+
children: "Failed"
|
|
2463
|
+
}), onRetry ? /* @__PURE__ */ jsx(Button, {
|
|
2464
|
+
type: "button",
|
|
2465
|
+
variant: "ghost",
|
|
2466
|
+
size: "icon-xs",
|
|
2467
|
+
"aria-label": "Retry",
|
|
2468
|
+
onClick: onRetry,
|
|
2469
|
+
children: /* @__PURE__ */ jsx(RotateCcw, { className: "size-3" })
|
|
2470
|
+
}) : null]
|
|
2471
|
+
}) : null,
|
|
2472
|
+
hasDetails ? /* @__PURE__ */ jsx(ChevronDown, {
|
|
2473
|
+
"data-slot": "collapsible-icon",
|
|
2474
|
+
className: "size-3.5 shrink-0 text-muted-foreground/60"
|
|
2475
|
+
}) : null
|
|
2476
|
+
]
|
|
2477
|
+
});
|
|
2478
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2479
|
+
"data-slot": "task-row",
|
|
2480
|
+
"data-status": status,
|
|
2481
|
+
className: cn("rounded-lg border border-border/80 bg-card px-2.5 py-2 shadow-xs", "animate-[ai-fade-up_300ms_cubic-bezier(0.23,1,0.32,1)_both] motion-reduce:animate-none", className),
|
|
2482
|
+
style: { animationDelay: `${index * 80}ms` },
|
|
2483
|
+
children: hasDetails ? /* @__PURE__ */ jsxs(Collapsible, {
|
|
2484
|
+
defaultOpen,
|
|
2485
|
+
className: "group/collapsible",
|
|
2486
|
+
children: [/* @__PURE__ */ jsx(CollapsibleTrigger, {
|
|
2487
|
+
className: "w-full text-left",
|
|
2488
|
+
children: header
|
|
2489
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
2490
|
+
innerClassName: "py-1.5 pl-8",
|
|
2491
|
+
children: /* @__PURE__ */ jsx("ul", {
|
|
2492
|
+
className: "space-y-1",
|
|
2493
|
+
children: details.map((d, i) => /* @__PURE__ */ jsxs("li", {
|
|
2494
|
+
className: "flex items-center justify-between gap-2 text-[12px]",
|
|
2495
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2496
|
+
className: "text-muted-foreground",
|
|
2497
|
+
children: d.label
|
|
2498
|
+
}), d.meta ? /* @__PURE__ */ jsx("span", {
|
|
2499
|
+
className: "font-mono tabular-nums text-muted-foreground/80",
|
|
2500
|
+
children: d.meta
|
|
2501
|
+
}) : null]
|
|
2502
|
+
}, i))
|
|
2503
|
+
})
|
|
2504
|
+
})]
|
|
2505
|
+
}) : header
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
2508
|
+
function TaskList({ children, className }) {
|
|
2509
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2510
|
+
"data-slot": "task-list",
|
|
2511
|
+
className: cn("flex flex-col gap-2", className),
|
|
2512
|
+
children
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
//#endregion
|
|
2517
|
+
//#region src/components/ai/context-card.tsx
|
|
2518
|
+
function ContextCard({ title, body, meta, sourceType, sourceName, className, index = 0 }) {
|
|
2519
|
+
return /* @__PURE__ */ jsxs("article", {
|
|
2520
|
+
"data-slot": "context-card",
|
|
2521
|
+
className: cn("rounded-xl border border-border bg-card p-3 shadow-xs", "animate-[ai-fade-up_300ms_cubic-bezier(0.23,1,0.32,1)_both] motion-reduce:animate-none", className),
|
|
2522
|
+
style: { animationDelay: `${index * 60}ms` },
|
|
2523
|
+
children: [
|
|
2524
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2525
|
+
className: "flex items-start justify-between gap-2",
|
|
2526
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
2527
|
+
className: "text-[13px] font-medium text-balance text-foreground",
|
|
2528
|
+
children: title
|
|
2529
|
+
}), meta ? /* @__PURE__ */ jsx("span", {
|
|
2530
|
+
className: "shrink-0 text-[11px] tabular-nums text-muted-foreground",
|
|
2531
|
+
children: meta
|
|
2532
|
+
}) : null]
|
|
2533
|
+
}),
|
|
2534
|
+
/* @__PURE__ */ jsx("p", {
|
|
2535
|
+
className: "mt-1.5 text-[13px] text-pretty leading-relaxed text-muted-foreground",
|
|
2536
|
+
children: body
|
|
2537
|
+
}),
|
|
2538
|
+
(sourceType || sourceName) && /* @__PURE__ */ jsxs("div", {
|
|
2539
|
+
className: "mt-2.5 flex items-center gap-1.5 text-[12px] text-muted-foreground",
|
|
2540
|
+
children: [
|
|
2541
|
+
/* @__PURE__ */ jsx(FileText, { className: "size-3 shrink-0 opacity-70" }),
|
|
2542
|
+
sourceType ? /* @__PURE__ */ jsx(Badge, {
|
|
2543
|
+
variant: "secondary",
|
|
2544
|
+
className: "h-5 px-1.5 text-[10px] font-medium",
|
|
2545
|
+
children: sourceType
|
|
2546
|
+
}) : null,
|
|
2547
|
+
sourceName ? /* @__PURE__ */ jsx("span", {
|
|
2548
|
+
className: "min-w-0 truncate",
|
|
2549
|
+
children: sourceName
|
|
2550
|
+
}) : null
|
|
2551
|
+
]
|
|
2552
|
+
})
|
|
2553
|
+
]
|
|
2554
|
+
});
|
|
2555
|
+
}
|
|
2556
|
+
function ContextCards({ children, className, label = "Chunks", count }) {
|
|
2557
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2558
|
+
"data-slot": "context-cards",
|
|
2559
|
+
className: cn("flex flex-col gap-2", className),
|
|
2560
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
2561
|
+
className: "flex items-center gap-2 text-[12px] text-muted-foreground",
|
|
2562
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2563
|
+
className: "font-medium",
|
|
2564
|
+
children: label
|
|
2565
|
+
}), count != null ? /* @__PURE__ */ jsx("span", {
|
|
2566
|
+
className: "tabular-nums text-muted-foreground/70",
|
|
2567
|
+
children: count
|
|
2568
|
+
}) : null]
|
|
2569
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
2570
|
+
className: "flex flex-col gap-2",
|
|
2571
|
+
children
|
|
2572
|
+
})]
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
//#endregion
|
|
2577
|
+
//#region src/components/ai/recommendation-card.tsx
|
|
2578
|
+
/**
|
|
2579
|
+
* Agent suggestion with confidence meter and optional alternatives drawer.
|
|
2580
|
+
*/
|
|
2581
|
+
function RecommendationCard({ title = "Recommendation", body, confidence, confidenceLabel, alternatives = [], acceptLabel = "Accept", onAccept, className, selectedId: selectedProp, defaultSelectedId }) {
|
|
2582
|
+
const [internalId, setInternalId] = React$1.useState(defaultSelectedId ?? alternatives[0]?.id ?? "primary");
|
|
2583
|
+
const selectedId = selectedProp ?? internalId;
|
|
2584
|
+
const displayBody = alternatives.find((a) => a.id === selectedId)?.description ?? body;
|
|
2585
|
+
const pct = confidence != null ? Math.round(Math.max(0, Math.min(1, confidence)) * 100) : null;
|
|
2586
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2587
|
+
"data-slot": "recommendation-card",
|
|
2588
|
+
className: cn("w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-xs", className),
|
|
2589
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
2590
|
+
className: "space-y-3 p-3",
|
|
2591
|
+
children: [
|
|
2592
|
+
/* @__PURE__ */ jsx("div", {
|
|
2593
|
+
className: "text-[12px] font-medium text-muted-foreground",
|
|
2594
|
+
children: title
|
|
2595
|
+
}),
|
|
2596
|
+
/* @__PURE__ */ jsx("div", {
|
|
2597
|
+
className: "text-[13px] text-pretty leading-relaxed text-foreground",
|
|
2598
|
+
children: displayBody
|
|
2599
|
+
}),
|
|
2600
|
+
pct != null ? /* @__PURE__ */ jsxs("div", {
|
|
2601
|
+
className: "space-y-1",
|
|
2602
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
2603
|
+
className: "flex items-center justify-between text-[11px] text-muted-foreground",
|
|
2604
|
+
children: [/* @__PURE__ */ jsx("span", { children: confidenceLabel ?? "Confidence" }), /* @__PURE__ */ jsxs("span", {
|
|
2605
|
+
className: "tabular-nums font-medium text-foreground",
|
|
2606
|
+
children: [pct, "%"]
|
|
2607
|
+
})]
|
|
2608
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
2609
|
+
className: "h-1.5 overflow-hidden rounded-full bg-muted",
|
|
2610
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2611
|
+
className: "h-full origin-left rounded-full bg-primary transition-transform duration-200 ease-out motion-reduce:transition-none",
|
|
2612
|
+
style: { transform: `scaleX(${pct / 100})` }
|
|
2613
|
+
})
|
|
2614
|
+
})]
|
|
2615
|
+
}) : null,
|
|
2616
|
+
alternatives.length > 0 ? /* @__PURE__ */ jsxs(Collapsible, {
|
|
2617
|
+
className: "group/collapsible",
|
|
2618
|
+
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
2619
|
+
className: cn("flex w-full items-center justify-between rounded-md border border-border/80 px-2.5 py-1.5 text-[12.5px]", "text-muted-foreground transition-colors duration-150 hover:bg-accent hover:text-foreground"),
|
|
2620
|
+
children: [/* @__PURE__ */ jsx("span", { children: "Other options" }), /* @__PURE__ */ jsx(ChevronDown, {
|
|
2621
|
+
"data-slot": "collapsible-icon",
|
|
2622
|
+
className: "size-3.5"
|
|
2623
|
+
})]
|
|
2624
|
+
}), /* @__PURE__ */ jsx(CollapsiblePanel, {
|
|
2625
|
+
innerClassName: "py-1.5",
|
|
2626
|
+
children: /* @__PURE__ */ jsx("ul", {
|
|
2627
|
+
className: "flex flex-col gap-0.5",
|
|
2628
|
+
children: alternatives.map((opt) => {
|
|
2629
|
+
const on = opt.id === selectedId;
|
|
2630
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("button", {
|
|
2631
|
+
type: "button",
|
|
2632
|
+
"aria-pressed": on,
|
|
2633
|
+
onClick: () => {
|
|
2634
|
+
setInternalId(opt.id);
|
|
2635
|
+
},
|
|
2636
|
+
className: cn("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-[13px]", "transition-colors duration-150 hover:bg-accent", on && "bg-accent"),
|
|
2637
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2638
|
+
className: cn("mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border", on ? "border-primary bg-primary text-primary-foreground" : "border-border"),
|
|
2639
|
+
children: on ? /* @__PURE__ */ jsx(Check, {
|
|
2640
|
+
className: "size-2.5",
|
|
2641
|
+
strokeWidth: 3
|
|
2642
|
+
}) : null
|
|
2643
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
2644
|
+
className: "min-w-0 flex-1",
|
|
2645
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2646
|
+
className: "font-medium text-foreground",
|
|
2647
|
+
children: opt.label
|
|
2648
|
+
}), opt.badge ? /* @__PURE__ */ jsx("span", {
|
|
2649
|
+
className: "ml-1.5 text-[11px] text-muted-foreground",
|
|
2650
|
+
children: opt.badge
|
|
2651
|
+
}) : null]
|
|
2652
|
+
})]
|
|
2653
|
+
}) }, opt.id);
|
|
2654
|
+
})
|
|
2655
|
+
})
|
|
2656
|
+
})]
|
|
2657
|
+
}) : null,
|
|
2658
|
+
/* @__PURE__ */ jsx("div", {
|
|
2659
|
+
className: "flex justify-end",
|
|
2660
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
2661
|
+
type: "button",
|
|
2662
|
+
size: "sm",
|
|
2663
|
+
onClick: () => onAccept?.(selectedId),
|
|
2664
|
+
children: acceptLabel
|
|
2665
|
+
})
|
|
2666
|
+
})
|
|
2667
|
+
]
|
|
2668
|
+
})
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
//#endregion
|
|
2673
|
+
//#region src/components/ai/file-upload.tsx
|
|
2674
|
+
/**
|
|
2675
|
+
* Drag-and-drop / file picker for chat attachments.
|
|
2676
|
+
*/
|
|
2677
|
+
function FileUpload({ files: filesProp, onFilesChange, multiple = true, accept, disabled, className, variant = "dropzone", children }) {
|
|
2678
|
+
const [internal, setInternal] = React$1.useState([]);
|
|
2679
|
+
const [dragging, setDragging] = React$1.useState(false);
|
|
2680
|
+
const inputRef = React$1.useRef(null);
|
|
2681
|
+
const files = filesProp ?? internal;
|
|
2682
|
+
const setFiles = (next) => {
|
|
2683
|
+
setInternal(next);
|
|
2684
|
+
onFilesChange?.(next);
|
|
2685
|
+
};
|
|
2686
|
+
const addFiles = (list) => {
|
|
2687
|
+
const incoming = Array.from(list);
|
|
2688
|
+
setFiles(multiple ? [...files, ...incoming] : incoming.slice(0, 1));
|
|
2689
|
+
};
|
|
2690
|
+
const removeAt = (index) => {
|
|
2691
|
+
setFiles(files.filter((_, i) => i !== index));
|
|
2692
|
+
};
|
|
2693
|
+
const onDrop = (event) => {
|
|
2694
|
+
event.preventDefault();
|
|
2695
|
+
setDragging(false);
|
|
2696
|
+
if (disabled || !event.dataTransfer.files?.length) return;
|
|
2697
|
+
addFiles(event.dataTransfer.files);
|
|
2698
|
+
};
|
|
2699
|
+
if (variant === "button") return /* @__PURE__ */ jsxs("div", {
|
|
2700
|
+
"data-slot": "file-upload",
|
|
2701
|
+
className: cn("inline-flex", className),
|
|
2702
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
2703
|
+
ref: inputRef,
|
|
2704
|
+
type: "file",
|
|
2705
|
+
className: "sr-only",
|
|
2706
|
+
multiple,
|
|
2707
|
+
accept,
|
|
2708
|
+
disabled,
|
|
2709
|
+
onChange: (e) => {
|
|
2710
|
+
if (e.target.files) addFiles(e.target.files);
|
|
2711
|
+
e.target.value = "";
|
|
2712
|
+
}
|
|
2713
|
+
}), children ?? /* @__PURE__ */ jsx(Button, {
|
|
2714
|
+
type: "button",
|
|
2715
|
+
variant: "ghost",
|
|
2716
|
+
size: "icon-sm",
|
|
2717
|
+
"aria-label": "Attach files",
|
|
2718
|
+
disabled,
|
|
2719
|
+
onClick: () => inputRef.current?.click(),
|
|
2720
|
+
children: /* @__PURE__ */ jsx(Paperclip, { className: "size-4" })
|
|
2721
|
+
})]
|
|
2722
|
+
});
|
|
2723
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2724
|
+
"data-slot": "file-upload",
|
|
2725
|
+
className: cn("w-full space-y-2", className),
|
|
2726
|
+
children: [
|
|
2727
|
+
/* @__PURE__ */ jsx("input", {
|
|
2728
|
+
ref: inputRef,
|
|
2729
|
+
type: "file",
|
|
2730
|
+
className: "sr-only",
|
|
2731
|
+
multiple,
|
|
2732
|
+
accept,
|
|
2733
|
+
disabled,
|
|
2734
|
+
onChange: (e) => {
|
|
2735
|
+
if (e.target.files) addFiles(e.target.files);
|
|
2736
|
+
e.target.value = "";
|
|
2737
|
+
}
|
|
2738
|
+
}),
|
|
2739
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2740
|
+
role: "button",
|
|
2741
|
+
tabIndex: disabled ? -1 : 0,
|
|
2742
|
+
onKeyDown: (e) => {
|
|
2743
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2744
|
+
e.preventDefault();
|
|
2745
|
+
inputRef.current?.click();
|
|
2746
|
+
}
|
|
2747
|
+
},
|
|
2748
|
+
onClick: () => !disabled && inputRef.current?.click(),
|
|
2749
|
+
onDragEnter: (e) => {
|
|
2750
|
+
e.preventDefault();
|
|
2751
|
+
setDragging(true);
|
|
2752
|
+
},
|
|
2753
|
+
onDragOver: (e) => e.preventDefault(),
|
|
2754
|
+
onDragLeave: () => setDragging(false),
|
|
2755
|
+
onDrop,
|
|
2756
|
+
className: cn("flex cursor-pointer flex-col items-center justify-center gap-2 rounded-xl border border-dashed px-4 py-6 text-center", "transition-colors duration-150", dragging ? "border-primary bg-primary/5" : "border-border bg-muted/30 hover:bg-muted/50", disabled && "pointer-events-none opacity-60"),
|
|
2757
|
+
children: [
|
|
2758
|
+
/* @__PURE__ */ jsx(Upload, { className: "size-5 text-muted-foreground" }),
|
|
2759
|
+
/* @__PURE__ */ jsx("div", {
|
|
2760
|
+
className: "text-[13px] font-medium text-foreground",
|
|
2761
|
+
children: "Drop files or click to upload"
|
|
2762
|
+
}),
|
|
2763
|
+
/* @__PURE__ */ jsx("div", {
|
|
2764
|
+
className: "text-xs text-muted-foreground",
|
|
2765
|
+
children: multiple ? "Multiple files supported" : "Single file"
|
|
2766
|
+
})
|
|
2767
|
+
]
|
|
2768
|
+
}),
|
|
2769
|
+
files.length > 0 ? /* @__PURE__ */ jsx("ul", {
|
|
2770
|
+
className: "flex flex-col gap-1",
|
|
2771
|
+
children: files.map((file, i) => /* @__PURE__ */ jsxs("li", {
|
|
2772
|
+
className: "flex items-center gap-2 rounded-md border border-border bg-card px-2 py-1.5 text-[12.5px]",
|
|
2773
|
+
children: [
|
|
2774
|
+
/* @__PURE__ */ jsx(Paperclip, { className: "size-3.5 shrink-0 text-muted-foreground" }),
|
|
2775
|
+
/* @__PURE__ */ jsx("span", {
|
|
2776
|
+
className: "min-w-0 flex-1 truncate font-medium",
|
|
2777
|
+
children: file.name
|
|
2778
|
+
}),
|
|
2779
|
+
/* @__PURE__ */ jsx("span", {
|
|
2780
|
+
className: "shrink-0 tabular-nums text-muted-foreground",
|
|
2781
|
+
children: formatBytes(file.size)
|
|
2782
|
+
}),
|
|
2783
|
+
/* @__PURE__ */ jsx(Button, {
|
|
2784
|
+
type: "button",
|
|
2785
|
+
variant: "ghost",
|
|
2786
|
+
size: "icon-xs",
|
|
2787
|
+
"aria-label": `Remove ${file.name}`,
|
|
2788
|
+
onClick: () => removeAt(i),
|
|
2789
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
|
|
2790
|
+
})
|
|
2791
|
+
]
|
|
2792
|
+
}, `${file.name}-${i}`))
|
|
2793
|
+
}) : null
|
|
2794
|
+
]
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
function formatBytes(n) {
|
|
2798
|
+
if (n < 1024) return `${n} B`;
|
|
2799
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
|
2800
|
+
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
2801
|
+
}
|
|
2802
|
+
|
|
2803
|
+
//#endregion
|
|
2804
|
+
//#region src/components/ai/image.tsx
|
|
2805
|
+
/**
|
|
2806
|
+
* Display AI-generated or user-uploaded images from base64 / bytes / URL.
|
|
2807
|
+
*/
|
|
2808
|
+
function AiImage({ data, mimeType = "image/png", src, bytes, alt = "", className, ...props }) {
|
|
2809
|
+
const resolved = React$1.useMemo(() => {
|
|
2810
|
+
if (src) return src;
|
|
2811
|
+
if (data) {
|
|
2812
|
+
if (data.startsWith("data:")) return data;
|
|
2813
|
+
return `data:${mimeType};base64,${data}`;
|
|
2814
|
+
}
|
|
2815
|
+
if (bytes) {
|
|
2816
|
+
let binary = "";
|
|
2817
|
+
bytes.forEach((b) => {
|
|
2818
|
+
binary += String.fromCharCode(b);
|
|
2819
|
+
});
|
|
2820
|
+
return `data:${mimeType};base64,${btoa(binary)}`;
|
|
2821
|
+
}
|
|
2822
|
+
}, [
|
|
2823
|
+
src,
|
|
2824
|
+
data,
|
|
2825
|
+
bytes,
|
|
2826
|
+
mimeType
|
|
2827
|
+
]);
|
|
2828
|
+
if (!resolved) return null;
|
|
2829
|
+
return /* @__PURE__ */ jsx("img", {
|
|
2830
|
+
"data-slot": "ai-image",
|
|
2831
|
+
src: resolved,
|
|
2832
|
+
alt,
|
|
2833
|
+
className: cn("max-h-80 max-w-full rounded-lg object-contain", "outline outline-1 outline-black/10 dark:outline-white/10", className),
|
|
2834
|
+
...props
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
//#endregion
|
|
2839
|
+
export { PromptInputTextarea as $, Reasoning as A, Message as B, ToolGroup as C, Step as D, ChainOfThoughtStep as E, ChatContainer as F, Markdown as G, MessageActions as H, ChatContainerContent as I, useThrottledText as J, renderBasicMarkdown as K, useChatContainer as L, formatDuration as M, SystemMessage as N, Steps as O, ScrollButton as P, PromptInputBody as Q, ResponseStream as R, Tool as S, ChainOfThought as T, MessageAvatar as U, MessageAction as V, MessageContent as W, PromptInputAction as X, PromptInput as Y, PromptInputActions as Z, lineDiff as _, ContextCards as a, ApprovalCard as b, ContextRing as c, DiffTable as d, usePromptInput as et, StreamingText as f, InlineDiff as g, FeedbackBar as h, ContextCard as i, ThinkingBar as j, ThinkingTrace as k, formatCompact as l, PromptSuggestions as m, FileUpload as n, Loader as nt, TaskList as o, PromptSuggestion as p, STREAM_THROTTLE_MS as q, RecommendationCard as r, TextShimmer as rt, TaskRow as s, AiImage as t, AgentLoader as tt, PlanTracker as u, Source as v, normalizeToolStatus as w, StatusIcon as x, Sources as y, CodeBlock as z };
|
|
2840
|
+
//# sourceMappingURL=ai-CiaH2sfF.js.map
|