@dbx-tools/ui-mastra 0.9.214 → 0.11.3
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/README.md +46 -16
- package/index.react.ts +5 -5
- package/index.support.ts +4 -4
- package/index.ts +1 -1
- package/package.json +17 -17
- package/src/react/_external-link-dialog.tsx +46 -64
- package/src/react/_genie-launcher-icon.tsx +20 -0
- package/src/react/_model-selector.tsx +16 -94
- package/src/react/bubbles.tsx +27 -96
- package/src/react/chat-composer.tsx +65 -105
- package/src/react/chat-thread-layout.tsx +14 -42
- package/src/react/chat-transcript.tsx +19 -13
- package/src/react/chat-view.tsx +2 -0
- package/src/react/data-grid.tsx +2 -2
- package/src/react/embed-slots.tsx +9 -2
- package/src/react/feedback-controls.tsx +17 -32
- package/src/react/markdown.tsx +15 -57
- package/src/react/mastra-assistant.tsx +50 -56
- package/src/react/mastra-chat.tsx +9 -22
- package/src/react/selected-model-pill.tsx +32 -19
- package/src/react/suggestion-pills.tsx +5 -3
- package/src/react/thread-sidebar.tsx +39 -78
- package/src/react/thread-tabs.tsx +11 -31
- package/src/react/tool-pill.tsx +4 -5
- package/src/react/types.ts +6 -0
- package/src/styles.css +80 -0
- package/src/support/active-runs.ts +12 -17
- package/src/support/browser-transcript.ts +14 -21
- package/src/support/chart-option.ts +42 -16
- package/src/support/mastra-client.ts +48 -35
- package/src/support/model-selection.ts +5 -31
- package/src/support/thread-tabs.ts +1 -1
package/src/react/markdown.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Button,
|
|
3
2
|
Table,
|
|
4
3
|
TableBody,
|
|
5
4
|
TableCell,
|
|
@@ -8,19 +7,16 @@ import {
|
|
|
8
7
|
TableHeader,
|
|
9
8
|
TableRow,
|
|
10
9
|
Spinner,
|
|
11
|
-
Tooltip,
|
|
12
|
-
TooltipContent,
|
|
13
|
-
TooltipTrigger,
|
|
14
10
|
cn,
|
|
15
11
|
} from "@databricks/appkit-ui/react";
|
|
16
12
|
import {
|
|
17
|
-
|
|
13
|
+
CopyButton,
|
|
14
|
+
HighlightedCodeBlock,
|
|
18
15
|
createShikiPlugin,
|
|
19
16
|
highlightToHtml,
|
|
20
17
|
useHighlightedHtml,
|
|
21
18
|
} from "@dbx-tools/ui/react";
|
|
22
|
-
import {
|
|
23
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
19
|
+
import React, { useEffect, useState } from "react";
|
|
24
20
|
import { Streamdown, type LinkSafetyConfig } from "streamdown";
|
|
25
21
|
import { ExternalLinkDialog, isSameOriginLink } from "./_external-link-dialog.tsx";
|
|
26
22
|
import { DataGrid, TABLE_WRAPPER_CLASSES, colorizeDelta, type DataRow } from "./data-grid.tsx";
|
|
@@ -100,7 +96,7 @@ function markdownTableData(
|
|
|
100
96
|
* toolbar would dwarf the tiny inline pills it renders in).
|
|
101
97
|
*/
|
|
102
98
|
const plainMarkdownTable = ({ children, ...rest }: React.HTMLAttributes<HTMLTableElement>) => (
|
|
103
|
-
<div className={TABLE_WRAPPER_CLASSES}>
|
|
99
|
+
<div data-slot="aui_chat-table" className={TABLE_WRAPPER_CLASSES}>
|
|
104
100
|
<Table {...rest}>{children}</Table>
|
|
105
101
|
</div>
|
|
106
102
|
);
|
|
@@ -168,12 +164,11 @@ const MarkdownSpan = ({
|
|
|
168
164
|
|
|
169
165
|
/** Chat links keep Streamdown's safety behavior while using a higher-contrast blue. */
|
|
170
166
|
const MARKDOWN_LINK_CLASSES = cn(
|
|
171
|
-
"[&_[data-streamdown=link]]:font-normal [&_[data-streamdown=link]]:text-
|
|
172
|
-
"[&_[data-streamdown=link]]:decoration-
|
|
173
|
-
"[&_[data-streamdown=link]]:transition-colors [&_[data-streamdown=link]]:hover:text-
|
|
167
|
+
"[&_[data-streamdown=link]]:font-normal [&_[data-streamdown=link]]:text-primary",
|
|
168
|
+
"[&_[data-streamdown=link]]:decoration-primary/40 [&_[data-streamdown=link]]:decoration-1 [&_[data-streamdown=link]]:underline-offset-2",
|
|
169
|
+
"[&_[data-streamdown=link]]:transition-colors [&_[data-streamdown=link]]:hover:text-primary/80 [&_[data-streamdown=link]]:hover:decoration-current",
|
|
174
170
|
"[&_[data-streamdown=link]]:focus-visible:rounded-sm [&_[data-streamdown=link]]:focus-visible:outline-none",
|
|
175
171
|
"[&_[data-streamdown=link]]:focus-visible:ring-2 [&_[data-streamdown=link]]:focus-visible:ring-ring [&_[data-streamdown=link]]:focus-visible:ring-offset-2",
|
|
176
|
-
"dark:[&_[data-streamdown=link]]:text-blue-300 dark:[&_[data-streamdown=link]]:decoration-blue-300/40 dark:[&_[data-streamdown=link]]:hover:text-blue-200",
|
|
177
172
|
);
|
|
178
173
|
|
|
179
174
|
/**
|
|
@@ -298,6 +293,7 @@ export const AssistantMarkdown = ({
|
|
|
298
293
|
animate?: boolean;
|
|
299
294
|
}) => (
|
|
300
295
|
<Streamdown
|
|
296
|
+
data-slot="aui_assistant-markdown"
|
|
301
297
|
components={animate ? STREAMING_MARKDOWN_COMPONENTS : MARKDOWN_COMPONENTS}
|
|
302
298
|
plugins={SHIKI_PLUGIN}
|
|
303
299
|
controls={false}
|
|
@@ -334,6 +330,7 @@ export const AssistantMarkdown = ({
|
|
|
334
330
|
*/
|
|
335
331
|
export const ToolMarkdown = ({ children, className }: { children: string; className?: string }) => (
|
|
336
332
|
<Streamdown
|
|
333
|
+
data-slot="aui_tool-markdown"
|
|
337
334
|
components={TOOL_MARKDOWN_COMPONENTS}
|
|
338
335
|
plugins={SHIKI_PLUGIN}
|
|
339
336
|
controls={false}
|
|
@@ -372,42 +369,6 @@ async function _prettySql(sql: string): Promise<string> {
|
|
|
372
369
|
}
|
|
373
370
|
}
|
|
374
371
|
|
|
375
|
-
/**
|
|
376
|
-
* Copy-to-clipboard button with a transient confirmation state: the
|
|
377
|
-
* icon flips to a check for ~1.5s after a successful copy. Shared by
|
|
378
|
-
* the SQL preview (and available to any block that needs a compact
|
|
379
|
-
* copy affordance).
|
|
380
|
-
*/
|
|
381
|
-
const CopyButton = ({ value, className }: { value: string; className?: string }) => {
|
|
382
|
-
const [copied, setCopied] = useState(false);
|
|
383
|
-
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
384
|
-
useEffect(() => () => clearTimeout(timer.current ?? undefined), []);
|
|
385
|
-
const onCopy = () => {
|
|
386
|
-
void copyText(value).then((ok) => {
|
|
387
|
-
if (!ok) return;
|
|
388
|
-
setCopied(true);
|
|
389
|
-
clearTimeout(timer.current ?? undefined);
|
|
390
|
-
timer.current = setTimeout(() => setCopied(false), 1500);
|
|
391
|
-
});
|
|
392
|
-
};
|
|
393
|
-
return (
|
|
394
|
-
<Tooltip>
|
|
395
|
-
<TooltipTrigger asChild>
|
|
396
|
-
<Button
|
|
397
|
-
type="button"
|
|
398
|
-
size="icon"
|
|
399
|
-
variant="ghost"
|
|
400
|
-
className={cn("size-6", className)}
|
|
401
|
-
onClick={onCopy}
|
|
402
|
-
>
|
|
403
|
-
{copied ? <CheckIcon className="size-3" /> : <CopyIcon className="size-3" />}
|
|
404
|
-
</Button>
|
|
405
|
-
</TooltipTrigger>
|
|
406
|
-
<TooltipContent>{copied ? "Copied" : "Copy"}</TooltipContent>
|
|
407
|
-
</Tooltip>
|
|
408
|
-
);
|
|
409
|
-
};
|
|
410
|
-
|
|
411
372
|
/**
|
|
412
373
|
* Render a SQL string as a syntax-highlighted code block. The query is
|
|
413
374
|
* first run through {@link _prettySql} so one-line Genie output reads as
|
|
@@ -415,13 +376,12 @@ const CopyButton = ({ value, className }: { value: string; className?: string })
|
|
|
415
376
|
* {@link highlightToHtml} (shiki). Unlike Streamdown's code renderer,
|
|
416
377
|
* this emits a plain `<pre><code>` with only per-token color spans - no
|
|
417
378
|
* line-number gutter or per-line wrappers - so the SQL selects and
|
|
418
|
-
* copies cleanly. A
|
|
379
|
+
* copies cleanly. A shared copy button copies the formatted source. The
|
|
419
380
|
* highlighter loads asynchronously, so we render uncolored text until
|
|
420
381
|
* the tokens are ready to avoid a flash of empty space.
|
|
421
382
|
*/
|
|
422
383
|
export const SqlBlock = ({ sql }: { sql: string }) => {
|
|
423
384
|
const [formatted, setFormatted] = useState(sql);
|
|
424
|
-
const html = useHighlightedHtml(formatted, "sql");
|
|
425
385
|
useEffect(() => {
|
|
426
386
|
let active = true;
|
|
427
387
|
setFormatted(sql);
|
|
@@ -438,13 +398,11 @@ export const SqlBlock = ({ sql }: { sql: string }) => {
|
|
|
438
398
|
value={formatted}
|
|
439
399
|
className="absolute right-1.5 top-1.5 z-10 bg-background/70 opacity-0 backdrop-blur transition-opacity group-hover:opacity-100 focus-visible:opacity-100"
|
|
440
400
|
/>
|
|
441
|
-
<
|
|
442
|
-
{
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
)}
|
|
447
|
-
</pre>
|
|
401
|
+
<HighlightedCodeBlock
|
|
402
|
+
source={formatted}
|
|
403
|
+
language="sql"
|
|
404
|
+
className="whitespace-pre rounded-md border border-border bg-background p-3 pr-10 leading-tight sm:leading-relaxed"
|
|
405
|
+
/>
|
|
448
406
|
</div>
|
|
449
407
|
);
|
|
450
408
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { Button, TooltipProvider, cn } from "@databricks/appkit-ui/react";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "@databricks/appkit-ui/react";
|
|
9
|
-
import { BotIcon, MessageCircleIcon, XIcon } from "lucide-react";
|
|
3
|
+
IconTooltipButton,
|
|
4
|
+
readStoredItem,
|
|
5
|
+
useElementSize,
|
|
6
|
+
writeStoredItem,
|
|
7
|
+
} from "@dbx-tools/ui/react";
|
|
8
|
+
import { BotIcon, XIcon } from "lucide-react";
|
|
10
9
|
import {
|
|
11
10
|
createContext,
|
|
12
11
|
type CSSProperties,
|
|
@@ -20,11 +19,14 @@ import {
|
|
|
20
19
|
useRef,
|
|
21
20
|
useState,
|
|
22
21
|
} from "react";
|
|
22
|
+
import { GenieLauncherIcon } from "./_genie-launcher-icon.tsx";
|
|
23
23
|
import { ChatView } from "./chat-view.tsx";
|
|
24
24
|
import { useMastraChat, type UseMastraChatOptions } from "./mastra-chat.tsx";
|
|
25
25
|
import { ThreadActions } from "./thread-tabs.tsx";
|
|
26
26
|
import type { MastraRequestContextInput } from "../support/request-context.ts";
|
|
27
27
|
|
|
28
|
+
export { GenieLauncherIcon };
|
|
29
|
+
|
|
28
30
|
/** Outer assistant placement behavior. */
|
|
29
31
|
export type MastraAssistantMode = "dock" | "overlay";
|
|
30
32
|
/** Edge from which the assistant opens. */
|
|
@@ -79,8 +81,11 @@ export interface MastraAssistantProps<TValues extends Record<string, unknown>> e
|
|
|
79
81
|
launcher?: false | MastraAssistantLauncherOptions;
|
|
80
82
|
title?: ReactNode;
|
|
81
83
|
description?: ReactNode;
|
|
82
|
-
icon
|
|
84
|
+
/** Header icon, or `false` for a compact title-and-actions header. */
|
|
85
|
+
icon?: ReactNode | false;
|
|
83
86
|
header?: boolean;
|
|
87
|
+
/** Optional shared toolbar height for aligning the assistant with its host app. */
|
|
88
|
+
toolbarHeight?: CSSProperties["minHeight"];
|
|
84
89
|
closeIcon?: ReactNode;
|
|
85
90
|
newConversationIcon?: ReactNode;
|
|
86
91
|
historyIcon?: ReactNode;
|
|
@@ -137,13 +142,9 @@ const panelSizeBounds = (
|
|
|
137
142
|
};
|
|
138
143
|
|
|
139
144
|
const readStoredSize = (key: string | undefined): number | undefined => {
|
|
140
|
-
if (!key
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return Number.isFinite(value) && value > 0 ? value : undefined;
|
|
144
|
-
} catch {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
145
|
+
if (!key) return undefined;
|
|
146
|
+
const value = Number(readStoredItem(key));
|
|
147
|
+
return Number.isFinite(value) && value > 0 ? value : undefined;
|
|
147
148
|
};
|
|
148
149
|
|
|
149
150
|
const panelPositionClasses: Record<MastraAssistantSide, string> = {
|
|
@@ -191,7 +192,7 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
191
192
|
children,
|
|
192
193
|
chat = {},
|
|
193
194
|
requestContext: requestContextProp,
|
|
194
|
-
mode = "
|
|
195
|
+
mode = "dock",
|
|
195
196
|
side = "right",
|
|
196
197
|
open: openProp,
|
|
197
198
|
defaultOpen = false,
|
|
@@ -204,6 +205,7 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
204
205
|
description,
|
|
205
206
|
icon,
|
|
206
207
|
header = true,
|
|
208
|
+
toolbarHeight,
|
|
207
209
|
closeIcon,
|
|
208
210
|
newConversationIcon,
|
|
209
211
|
historyIcon,
|
|
@@ -232,8 +234,9 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
232
234
|
: undefined;
|
|
233
235
|
const defaultSize = resizeOptions.defaultSize ?? (vertical ? 360 : 432);
|
|
234
236
|
const [panelSize, setPanelSize] = useState(() => readStoredSize(sizeStorageKey) ?? defaultSize);
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
+
const rootSize = useElementSize(rootRef);
|
|
238
|
+
const availableSize = vertical ? rootSize.height : rootSize.width;
|
|
239
|
+
const isNarrow = rootSize.width > 0 && rootSize.width < mobileBreakpoint;
|
|
237
240
|
const resizeState = useRef<ResizeState>(null);
|
|
238
241
|
const sizeConfigRef = useRef(sizeStorageKey);
|
|
239
242
|
const skipSizePersistenceRef = useRef(false);
|
|
@@ -252,7 +255,13 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
252
255
|
},
|
|
253
256
|
[setOpen],
|
|
254
257
|
);
|
|
255
|
-
const close = useCallback(() =>
|
|
258
|
+
const close = useCallback(() => {
|
|
259
|
+
const activeElement = document.activeElement;
|
|
260
|
+
if (activeElement instanceof HTMLElement && panelRef.current?.contains(activeElement)) {
|
|
261
|
+
activeElement.blur();
|
|
262
|
+
}
|
|
263
|
+
setOpen(false);
|
|
264
|
+
}, [setOpen]);
|
|
256
265
|
const toggle = useCallback(() => setOpen(!requestedOpen), [requestedOpen, setOpen]);
|
|
257
266
|
|
|
258
267
|
const controller = useMemo<MastraAssistantController<TValues>>(
|
|
@@ -273,21 +282,6 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
273
282
|
requestContext,
|
|
274
283
|
});
|
|
275
284
|
|
|
276
|
-
useEffect(() => {
|
|
277
|
-
const root = rootRef.current;
|
|
278
|
-
if (!root || typeof ResizeObserver === "undefined") return;
|
|
279
|
-
const observer = new ResizeObserver((entries) => {
|
|
280
|
-
const bounds = entries[0]?.contentRect;
|
|
281
|
-
const width = bounds?.width ?? root.clientWidth;
|
|
282
|
-
const height = bounds?.height ?? root.clientHeight;
|
|
283
|
-
if (width <= 0 || height <= 0) return;
|
|
284
|
-
setAvailableSize(vertical ? height : width);
|
|
285
|
-
setIsNarrow(width < mobileBreakpoint);
|
|
286
|
-
});
|
|
287
|
-
observer.observe(root);
|
|
288
|
-
return () => observer.disconnect();
|
|
289
|
-
}, [mobileBreakpoint, vertical]);
|
|
290
|
-
|
|
291
285
|
useEffect(() => {
|
|
292
286
|
if (!isNarrow || !isOpen) return;
|
|
293
287
|
const panel = panelRef.current;
|
|
@@ -348,16 +342,12 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
348
342
|
}, [defaultSize, sizeStorageKey]);
|
|
349
343
|
|
|
350
344
|
useEffect(() => {
|
|
351
|
-
if (!sizeStorageKey
|
|
345
|
+
if (!sizeStorageKey) return;
|
|
352
346
|
if (skipSizePersistenceRef.current) {
|
|
353
347
|
skipSizePersistenceRef.current = false;
|
|
354
348
|
return;
|
|
355
349
|
}
|
|
356
|
-
|
|
357
|
-
window.localStorage.setItem(sizeStorageKey, String(panelSize));
|
|
358
|
-
} catch {
|
|
359
|
-
// Size persistence is best-effort; the panel remains usable without storage.
|
|
360
|
-
}
|
|
350
|
+
writeStoredItem(sizeStorageKey, String(panelSize));
|
|
361
351
|
}, [panelSize, sizeStorageKey]);
|
|
362
352
|
|
|
363
353
|
useEffect(() => {
|
|
@@ -471,15 +461,9 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
471
461
|
) : null;
|
|
472
462
|
|
|
473
463
|
const closeAction = (
|
|
474
|
-
<
|
|
475
|
-
<
|
|
476
|
-
|
|
477
|
-
{closeIcon ?? <XIcon className="size-4" />}
|
|
478
|
-
<span className="sr-only">Close assistant</span>
|
|
479
|
-
</Button>
|
|
480
|
-
</TooltipTrigger>
|
|
481
|
-
<TooltipContent>Close assistant</TooltipContent>
|
|
482
|
-
</Tooltip>
|
|
464
|
+
<IconTooltipButton tooltip="Close assistant" onClick={close}>
|
|
465
|
+
{closeIcon ?? <XIcon className="size-4" />}
|
|
466
|
+
</IconTooltipButton>
|
|
483
467
|
);
|
|
484
468
|
|
|
485
469
|
const headerActions =
|
|
@@ -531,18 +515,28 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
531
515
|
{resizeHandle}
|
|
532
516
|
{header ? (
|
|
533
517
|
<div
|
|
518
|
+
style={toolbarHeight === undefined ? undefined : { minHeight: toolbarHeight }}
|
|
534
519
|
className={cn(
|
|
535
520
|
"flex min-h-14 shrink-0 items-center gap-3 border-b border-border px-4 py-2",
|
|
536
521
|
headerClassName,
|
|
537
522
|
)}
|
|
538
523
|
>
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
524
|
+
{icon === false ? null : (
|
|
525
|
+
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted">
|
|
526
|
+
{icon ?? <BotIcon className="size-4" />}
|
|
527
|
+
</span>
|
|
528
|
+
)}
|
|
542
529
|
<div className="min-w-0 flex-1">
|
|
543
|
-
<div className="truncate text-sm font-semibold">
|
|
530
|
+
<div data-slot="aui_assistant-title" className="truncate text-sm font-semibold">
|
|
531
|
+
{title}
|
|
532
|
+
</div>
|
|
544
533
|
{description ? (
|
|
545
|
-
<div
|
|
534
|
+
<div
|
|
535
|
+
data-slot="aui_assistant-caption"
|
|
536
|
+
className="truncate text-xs text-muted-foreground"
|
|
537
|
+
>
|
|
538
|
+
{description}
|
|
539
|
+
</div>
|
|
546
540
|
) : null}
|
|
547
541
|
</div>
|
|
548
542
|
<div className="flex shrink-0 items-center gap-1">{headerActions}</div>
|
|
@@ -581,7 +575,7 @@ export function MastraAssistant<TValues extends Record<string, unknown> = Record
|
|
|
581
575
|
launcherOptions.className,
|
|
582
576
|
)}
|
|
583
577
|
>
|
|
584
|
-
{launcherOptions.icon ?? <
|
|
578
|
+
{launcherOptions.icon ?? <GenieLauncherIcon />}
|
|
585
579
|
</Button>
|
|
586
580
|
) : null;
|
|
587
581
|
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import type { ReasoningEffort } from "@dbx-tools/shared-model";
|
|
10
10
|
import type { AiDecideStrategy } from "@dbx-tools/shared-model-gateway";
|
|
11
11
|
import { useBrand } from "@dbx-tools/ui/branding/react";
|
|
12
|
+
import { readStoredItem, writeStoredItem } from "@dbx-tools/ui/react";
|
|
12
13
|
import type { RequestContext } from "@mastra/client-js";
|
|
13
14
|
import type { FileUIPart, UIMessage } from "ai";
|
|
14
15
|
import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -137,21 +138,12 @@ const deriveThreadTitle = (text: string): string => {
|
|
|
137
138
|
|
|
138
139
|
/** Read the persisted active thread id, tolerating storage being unavailable. */
|
|
139
140
|
const readStoredThreadId = (key: string): string | undefined => {
|
|
140
|
-
|
|
141
|
-
return window.localStorage.getItem(key) ?? undefined;
|
|
142
|
-
} catch {
|
|
143
|
-
return undefined;
|
|
144
|
-
}
|
|
141
|
+
return readStoredItem(key);
|
|
145
142
|
};
|
|
146
143
|
|
|
147
144
|
/** Persist the active thread id, silently ignoring storage failures. */
|
|
148
145
|
const storeStoredThreadId = (key: string, id: string): void => {
|
|
149
|
-
|
|
150
|
-
window.localStorage.setItem(key, id);
|
|
151
|
-
} catch {
|
|
152
|
-
// Private-mode / disabled storage: persistence is best-effort, the
|
|
153
|
-
// in-memory selection still works for the session.
|
|
154
|
-
}
|
|
146
|
+
writeStoredItem(key, id);
|
|
155
147
|
};
|
|
156
148
|
|
|
157
149
|
/**
|
|
@@ -164,21 +156,13 @@ const sidebarStorageKey = (basePath: string, agentId: string): string =>
|
|
|
164
156
|
|
|
165
157
|
/** Read the persisted sidebar open flag, falling back when unset / unavailable. */
|
|
166
158
|
const readStoredSidebarOpen = (key: string, fallback: boolean): boolean => {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return value === null ? fallback : value === "1";
|
|
170
|
-
} catch {
|
|
171
|
-
return fallback;
|
|
172
|
-
}
|
|
159
|
+
const value = readStoredItem(key);
|
|
160
|
+
return value === undefined ? fallback : value === "1";
|
|
173
161
|
};
|
|
174
162
|
|
|
175
163
|
/** Persist the sidebar open flag, silently ignoring storage failures. */
|
|
176
164
|
const storeStoredSidebarOpen = (key: string, open: boolean): void => {
|
|
177
|
-
|
|
178
|
-
window.localStorage.setItem(key, open ? "1" : "0");
|
|
179
|
-
} catch {
|
|
180
|
-
// Best-effort; the in-session toggle still works without persistence.
|
|
181
|
-
}
|
|
165
|
+
writeStoredItem(key, open ? "1" : "0");
|
|
182
166
|
};
|
|
183
167
|
|
|
184
168
|
/** Options for {@link useMastraChat}. */
|
|
@@ -260,6 +244,8 @@ export interface UseMastraChatOptions<
|
|
|
260
244
|
* `[]` to force no suggestions.
|
|
261
245
|
*/
|
|
262
246
|
suggestions?: string[];
|
|
247
|
+
/** Replace or omit the built-in empty transcript welcome block. */
|
|
248
|
+
emptyState?: ChatViewProps["emptyState"];
|
|
263
249
|
/**
|
|
264
250
|
* Enable built-in conversation (thread) management: the chat tracks a
|
|
265
251
|
* client-selected thread id, persists it across reloads, lists the
|
|
@@ -1750,6 +1736,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
1750
1736
|
regenerate: options.enableRetry === false ? undefined : regenerate,
|
|
1751
1737
|
onStop: stop,
|
|
1752
1738
|
suggestions,
|
|
1739
|
+
emptyState: options.emptyState,
|
|
1753
1740
|
followUpSuggestions: mastraClient.followUpSuggestions,
|
|
1754
1741
|
followUpSuggestionLimit: mastraClient.followUpSuggestionLimit,
|
|
1755
1742
|
showSelectedModel: options.showSelectedModel ?? false,
|
|
@@ -89,24 +89,37 @@ function elapsedMs(
|
|
|
89
89
|
return Math.max(0, completedAt - startedAt);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return `${(value / 1_000).toFixed(value < 10_000 ? 1 : 0)}k`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function formatDbu(value: number | undefined): string {
|
|
104
|
-
if (value === undefined) return "—";
|
|
105
|
-
return `${value < 0.001 ? value.toFixed(6) : value.toFixed(4)} DBU`;
|
|
92
|
+
/** Presentation controls for a chat metric value. */
|
|
93
|
+
export interface ChatMetricFormatOptions {
|
|
94
|
+
/** Abbreviate token counts at one thousand and above. Defaults to true. */
|
|
95
|
+
readonly compactTokens?: boolean;
|
|
96
|
+
/** Include the DBU suffix. Defaults to true. */
|
|
97
|
+
readonly includeUnit?: boolean;
|
|
98
|
+
/** Put a space before duration units. Defaults to false. */
|
|
99
|
+
readonly spacedDuration?: boolean;
|
|
106
100
|
}
|
|
107
101
|
|
|
108
|
-
|
|
102
|
+
/** Format one chat metric consistently across per-turn and aggregate displays. */
|
|
103
|
+
export function formatChatMetricValue(
|
|
104
|
+
metric: ChatMetric,
|
|
105
|
+
value: number | undefined,
|
|
106
|
+
options: ChatMetricFormatOptions = {},
|
|
107
|
+
): string {
|
|
109
108
|
if (value === undefined) return "—";
|
|
109
|
+
if (metric === "tokens") {
|
|
110
|
+
if (options.compactTokens === false || value < 1_000) return Math.round(value).toLocaleString();
|
|
111
|
+
return `${(value / 1_000).toFixed(value < 10_000 ? 1 : 0)}k`;
|
|
112
|
+
}
|
|
113
|
+
if (metric === "time") {
|
|
114
|
+
const space = options.spacedDuration ? " " : "";
|
|
115
|
+
return value < 1_000
|
|
116
|
+
? `${Math.round(value)}${space}ms`
|
|
117
|
+
: `${(value / 1_000).toFixed(1)}${space}s`;
|
|
118
|
+
}
|
|
119
|
+
if (metric === "dbu") {
|
|
120
|
+
const formatted = value < 0.001 ? value.toFixed(6) : value.toFixed(4);
|
|
121
|
+
return options.includeUnit === false ? formatted : `${formatted} DBU`;
|
|
122
|
+
}
|
|
110
123
|
return `$${value < 0.01 ? value.toFixed(6) : value.toFixed(4)}`;
|
|
111
124
|
}
|
|
112
125
|
|
|
@@ -146,10 +159,10 @@ function metricValues(
|
|
|
146
159
|
): MetricValues {
|
|
147
160
|
const values = activityTurnMetrics(activity, message, active, now, fallbackStartedAt);
|
|
148
161
|
return {
|
|
149
|
-
tokens:
|
|
150
|
-
time:
|
|
151
|
-
dbu:
|
|
152
|
-
usd:
|
|
162
|
+
tokens: formatChatMetricValue("tokens", values.tokens),
|
|
163
|
+
time: formatChatMetricValue("time", values.timeMs),
|
|
164
|
+
dbu: formatChatMetricValue("dbu", values.dbu),
|
|
165
|
+
usd: formatChatMetricValue("usd", values.usd),
|
|
153
166
|
};
|
|
154
167
|
}
|
|
155
168
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Button, cn } from "@databricks/appkit-ui/react";
|
|
2
|
+
import { CornerDownRightIcon } from "lucide-react";
|
|
2
3
|
import { CHAT_PROMPT_TEXT_CLASS } from "./_chat-prompt-style.ts";
|
|
3
4
|
|
|
4
5
|
// Shared rendering for suggested questions. Both the initial starter
|
|
@@ -50,9 +51,9 @@ export const SuggestionPills = ({
|
|
|
50
51
|
key={q}
|
|
51
52
|
type="button"
|
|
52
53
|
size="sm"
|
|
53
|
-
variant="
|
|
54
|
+
variant="ghost"
|
|
54
55
|
className={cn(
|
|
55
|
-
"h-auto shrink-0 whitespace-normal rounded-
|
|
56
|
+
"h-auto shrink-0 items-start justify-start gap-2 whitespace-normal rounded-lg border-0 bg-muted px-3 py-2 text-left font-normal shadow-none hover:bg-muted/80",
|
|
56
57
|
CHAT_PROMPT_TEXT_CLASS,
|
|
57
58
|
orientation === "horizontal"
|
|
58
59
|
? "max-w-[min(20rem,85vw)] md:max-w-full"
|
|
@@ -61,7 +62,8 @@ export const SuggestionPills = ({
|
|
|
61
62
|
onClick={() => onSelect?.(q)}
|
|
62
63
|
disabled={disabled || !onSelect}
|
|
63
64
|
>
|
|
64
|
-
|
|
65
|
+
<CornerDownRightIcon className="mt-0.5 size-4 shrink-0 text-primary" aria-hidden />
|
|
66
|
+
<span>{q}</span>
|
|
65
67
|
</Button>
|
|
66
68
|
))}
|
|
67
69
|
</div>
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Input,
|
|
4
|
-
Spinner,
|
|
5
|
-
Tooltip,
|
|
6
|
-
TooltipContent,
|
|
7
|
-
TooltipTrigger,
|
|
8
|
-
cn,
|
|
9
|
-
} from "@databricks/appkit-ui/react";
|
|
1
|
+
import { Button, Input, Spinner, cn } from "@databricks/appkit-ui/react";
|
|
2
|
+
import { IconTooltipButton } from "@dbx-tools/ui/react";
|
|
10
3
|
import {
|
|
11
4
|
Loader2Icon,
|
|
12
5
|
MessageSquarePlusIcon,
|
|
@@ -156,21 +149,13 @@ export const ThreadSidebar = ({
|
|
|
156
149
|
<div className={cn("shrink-0", !onNew && "ml-auto")}>{headerActions}</div>
|
|
157
150
|
) : null}
|
|
158
151
|
{onHide && (
|
|
159
|
-
<
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
aria-label="Hide conversations"
|
|
167
|
-
className={cn("size-8 shrink-0", !onNew && !headerActions && "ml-auto")}
|
|
168
|
-
>
|
|
169
|
-
<HideIcon className="size-4" />
|
|
170
|
-
</Button>
|
|
171
|
-
</TooltipTrigger>
|
|
172
|
-
<TooltipContent>Hide conversations</TooltipContent>
|
|
173
|
-
</Tooltip>
|
|
152
|
+
<IconTooltipButton
|
|
153
|
+
tooltip="Hide conversations"
|
|
154
|
+
onClick={onHide}
|
|
155
|
+
className={cn("size-8 shrink-0", !onNew && !headerActions && "ml-auto")}
|
|
156
|
+
>
|
|
157
|
+
<HideIcon className="size-4" />
|
|
158
|
+
</IconTooltipButton>
|
|
174
159
|
)}
|
|
175
160
|
</div>
|
|
176
161
|
)}
|
|
@@ -274,65 +259,41 @@ export const ThreadSidebar = ({
|
|
|
274
259
|
)}
|
|
275
260
|
>
|
|
276
261
|
{isStreaming && onCancel ? (
|
|
277
|
-
<
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
className="size-6 text-primary"
|
|
286
|
-
>
|
|
287
|
-
<Loader2Icon className="size-3 animate-spin group-hover:hidden" />
|
|
288
|
-
<SquareIcon className="hidden size-3 fill-current group-hover:block" />
|
|
289
|
-
</Button>
|
|
290
|
-
</TooltipTrigger>
|
|
291
|
-
<TooltipContent>Stop generating</TooltipContent>
|
|
292
|
-
</Tooltip>
|
|
262
|
+
<IconTooltipButton
|
|
263
|
+
tooltip="Stop generating"
|
|
264
|
+
onClick={() => onCancel(thread.id)}
|
|
265
|
+
className="size-6 text-primary"
|
|
266
|
+
>
|
|
267
|
+
<Loader2Icon className="size-3 animate-spin group-hover:hidden" />
|
|
268
|
+
<SquareIcon className="hidden size-3 fill-current group-hover:block" />
|
|
269
|
+
</IconTooltipButton>
|
|
293
270
|
) : null}
|
|
294
271
|
{onRename && (
|
|
295
|
-
<
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
aria-label="Rename conversation"
|
|
303
|
-
className="size-6"
|
|
304
|
-
>
|
|
305
|
-
<PencilIcon className="size-3.5" />
|
|
306
|
-
</Button>
|
|
307
|
-
</TooltipTrigger>
|
|
308
|
-
<TooltipContent>Rename conversation</TooltipContent>
|
|
309
|
-
</Tooltip>
|
|
272
|
+
<IconTooltipButton
|
|
273
|
+
tooltip="Rename conversation"
|
|
274
|
+
onClick={(event) => startEdit(event, thread)}
|
|
275
|
+
className="size-6"
|
|
276
|
+
>
|
|
277
|
+
<PencilIcon className="size-3.5" />
|
|
278
|
+
</IconTooltipButton>
|
|
310
279
|
)}
|
|
311
280
|
{onDelete && (
|
|
312
|
-
<
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
type="button"
|
|
316
|
-
variant={isConfirming ? "destructive" : "ghost"}
|
|
317
|
-
size="icon"
|
|
318
|
-
onMouseDown={(e) => e.preventDefault()}
|
|
319
|
-
onClick={(e) => handleDeleteClick(e, thread.id)}
|
|
320
|
-
aria-label={
|
|
321
|
-
isConfirming
|
|
322
|
-
? "Confirm delete conversation"
|
|
323
|
-
: "Delete conversation"
|
|
324
|
-
}
|
|
325
|
-
className="size-6"
|
|
326
|
-
>
|
|
327
|
-
<Trash2Icon className="size-3.5" />
|
|
328
|
-
</Button>
|
|
329
|
-
</TooltipTrigger>
|
|
330
|
-
<TooltipContent>
|
|
331
|
-
{isConfirming
|
|
281
|
+
<IconTooltipButton
|
|
282
|
+
tooltip={
|
|
283
|
+
isConfirming
|
|
332
284
|
? "Click again to delete this conversation"
|
|
333
|
-
: "Delete conversation"
|
|
334
|
-
|
|
335
|
-
|
|
285
|
+
: "Delete conversation"
|
|
286
|
+
}
|
|
287
|
+
variant={isConfirming ? "destructive" : "ghost"}
|
|
288
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
289
|
+
onClick={(event) => handleDeleteClick(event, thread.id)}
|
|
290
|
+
aria-label={
|
|
291
|
+
isConfirming ? "Confirm delete conversation" : "Delete conversation"
|
|
292
|
+
}
|
|
293
|
+
className="size-6"
|
|
294
|
+
>
|
|
295
|
+
<Trash2Icon className="size-3.5" />
|
|
296
|
+
</IconTooltipButton>
|
|
336
297
|
)}
|
|
337
298
|
</div>
|
|
338
299
|
)}
|