@dbx-tools/ui-mastra 0.9.182 → 0.9.184
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/index.react.ts +2 -2
- package/index.support.ts +1 -1
- package/index.ts +1 -1
- package/package.json +7 -7
- package/src/react/_assistant-activity.ts +2 -6
- package/src/react/_external-link-dialog.tsx +11 -14
- package/src/react/bubbles.tsx +19 -7
- package/src/react/chat-composer.tsx +3 -3
- package/src/react/chat-feedback.ts +1 -2
- package/src/react/chat-stream.ts +3 -5
- package/src/react/chat-transcript.tsx +32 -49
- package/src/react/feedback-controls.tsx +1 -4
- package/src/react/markdown.tsx +18 -22
- package/src/react/mastra-chat.tsx +25 -13
- package/src/react/tool-pill.tsx +76 -59
- package/src/react/types.ts +1 -0
- package/src/react/use-composer-viewport-lock.ts +161 -71
- package/src/styles.css +2 -5
- package/src/support/mastra-client.ts +3 -4
- package/src/support/tool-events.ts +35 -7
package/index.react.ts
CHANGED
|
@@ -35,7 +35,7 @@ export { useChatSessions } from "./src/react/chat-sessions.ts";
|
|
|
35
35
|
export type { ThreadSessionReader, ThreadSessionUpdater, ThreadMessageWriter } from "./src/react/chat-sessions.ts";
|
|
36
36
|
export { readMlflowTracePart, readThreadTitlePart, chatStatusForChunk, closeOnTerminalChunk, waitForTerminalChunk, useChatStream } from "./src/react/chat-stream.ts";
|
|
37
37
|
export { ChatThreadLayout } from "./src/react/chat-thread-layout.tsx";
|
|
38
|
-
export { latestVisibleAssistantIndexInTurn, useChatTranscriptController, ChatTranscript } from "./src/react/chat-transcript.tsx";
|
|
38
|
+
export { TRANSCRIPT_FOLLOW_CANCEL_EVENTS, latestVisibleAssistantIndexInTurn, useChatTranscriptController, ChatTranscript } from "./src/react/chat-transcript.tsx";
|
|
39
39
|
export type { ChatTranscriptController } from "./src/react/chat-transcript.tsx";
|
|
40
40
|
export { ChatView } from "./src/react/chat-view.tsx";
|
|
41
41
|
export { colorizeDelta, renderDataCell, humanizeLabel, TABLE_WRAPPER_CLASSES, DataGrid } from "./src/react/data-grid.tsx";
|
|
@@ -43,7 +43,7 @@ export type { DataRow } from "./src/react/data-grid.tsx";
|
|
|
43
43
|
export { MarkdownWithEmbeds } from "./src/react/embed-slots.tsx";
|
|
44
44
|
export { ExportMenu } from "./src/react/export-menu.tsx";
|
|
45
45
|
export { FeedbackControls } from "./src/react/feedback-controls.tsx";
|
|
46
|
-
export { AssistantMarkdown, ToolMarkdown, SqlBlock, SourceBlock } from "./src/react/markdown.tsx";
|
|
46
|
+
export { CHAT_LINK_SAFETY, AssistantMarkdown, ToolMarkdown, SqlBlock, SourceBlock } from "./src/react/markdown.tsx";
|
|
47
47
|
export { useMastraAssistant, MastraAssistant } from "./src/react/mastra-assistant.tsx";
|
|
48
48
|
export type { MastraAssistantMode, MastraAssistantSide, MastraAssistantLauncherPosition, MastraAssistantResizeOptions, MastraAssistantLauncherOptions, MastraAssistantController, MastraAssistantProps } from "./src/react/mastra-assistant.tsx";
|
|
49
49
|
export { useMastraChat, MastraChat } from "./src/react/mastra-chat.tsx";
|
package/index.support.ts
CHANGED
|
@@ -37,4 +37,4 @@ export { threadStorageKey } from "./src/support/thread-persistence.ts";
|
|
|
37
37
|
export { DEFAULT_THREAD_SESSION_KEY, createThreadSession, isSessionRunning, lastUserMessage, interruptedTurnMessages, enqueueSteer, removeSteer, reorderSteers, sessionKey } from "./src/support/thread-sessions.ts";
|
|
38
38
|
export type { SessionQueuedSteer, SessionRun, ThreadSession } from "./src/support/thread-sessions.ts";
|
|
39
39
|
export { THREAD_TAB_SEED_MAX, syncThreadTabs, closeThreadTab, nextActiveThreadTab } from "./src/support/thread-tabs.ts";
|
|
40
|
-
export { compactReasoningText, genieReasoningText, toolEventsFromParts, mergeToolEvents } from "./src/support/tool-events.ts";
|
|
40
|
+
export { compactReasoningText, genieOutputReasoningSections, toolReasoningSections, genieReasoningText, toolEventsFromParts, mergeToolEvents } from "./src/support/tool-events.ts";
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@databricks/appkit-ui": "0.81.0",
|
|
35
|
-
"@dbx-tools/shared-auth": "^0.9.
|
|
36
|
-
"@dbx-tools/shared-core": "^0.9.
|
|
37
|
-
"@dbx-tools/shared-genie": "^0.9.
|
|
38
|
-
"@dbx-tools/shared-mastra": "^0.9.
|
|
39
|
-
"@dbx-tools/shared-model": "^0.9.
|
|
40
|
-
"@dbx-tools/ui": "^0.9.
|
|
35
|
+
"@dbx-tools/shared-auth": "^0.9.184",
|
|
36
|
+
"@dbx-tools/shared-core": "^0.9.184",
|
|
37
|
+
"@dbx-tools/shared-genie": "^0.9.184",
|
|
38
|
+
"@dbx-tools/shared-mastra": "^0.9.184",
|
|
39
|
+
"@dbx-tools/shared-model": "^0.9.184",
|
|
40
|
+
"@dbx-tools/ui": "^0.9.184",
|
|
41
41
|
"@mastra/client-js": "1.50.0",
|
|
42
42
|
"@mastra/core": "1.71.0",
|
|
43
43
|
"@tanstack/react-table": "^8.21.3",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"version": "0.9.
|
|
59
|
+
"version": "0.9.184",
|
|
60
60
|
"types": "index.ts",
|
|
61
61
|
"dbxToolsConfig": {
|
|
62
62
|
"tags": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isToolUIPart, type UIMessage } from "ai";
|
|
2
2
|
|
|
3
3
|
import type { ToolEvent } from "./types.ts";
|
|
4
|
-
import { compactReasoningText } from "../support/tool-events.ts";
|
|
4
|
+
import { compactReasoningText, toolReasoningSections } from "../support/tool-events.ts";
|
|
5
5
|
|
|
6
6
|
/** One ordered activity entry rendered before an assistant's answer text. */
|
|
7
7
|
export type AssistantActivityItem =
|
|
@@ -20,11 +20,7 @@ export const assistantActivityItems = (
|
|
|
20
20
|
if (renderedEventIds.has(event.id)) return;
|
|
21
21
|
renderedEventIds.add(event.id);
|
|
22
22
|
items.push({ type: "tool", key: `tool-${event.id}`, event });
|
|
23
|
-
const thoughts = (event
|
|
24
|
-
if (progress.type !== "thinking") return [];
|
|
25
|
-
const text = compactReasoningText(progress.text);
|
|
26
|
-
return text ? [text] : [];
|
|
27
|
-
});
|
|
23
|
+
const thoughts = toolReasoningSections(event);
|
|
28
24
|
if (thoughts.length > 0) {
|
|
29
25
|
items.push({ type: "thought", key: `thought-${event.id}`, text: thoughts.join("\n\n") });
|
|
30
26
|
}
|
|
@@ -20,17 +20,14 @@ export interface LinkPresentation {
|
|
|
20
20
|
absoluteUrl: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
/** Return whether a chat URL
|
|
24
|
-
export function
|
|
23
|
+
/** Return whether a chat URL resolves within the current app origin. */
|
|
24
|
+
export function isSameOriginLink(url: string, baseUrl?: string): boolean {
|
|
25
25
|
const base = baseUrl ?? (typeof window === "undefined" ? undefined : window.location.href);
|
|
26
26
|
if (!base) return false;
|
|
27
27
|
try {
|
|
28
28
|
const resolved = new URL(url, base);
|
|
29
29
|
const current = new URL(base);
|
|
30
|
-
return
|
|
31
|
-
resolved.origin === current.origin &&
|
|
32
|
-
(resolved.pathname === "/sandbox" || resolved.pathname.startsWith("/sandbox/"))
|
|
33
|
-
);
|
|
30
|
+
return resolved.origin === current.origin;
|
|
34
31
|
} catch {
|
|
35
32
|
return false;
|
|
36
33
|
}
|
|
@@ -85,10 +82,10 @@ export const ExternalLinkDialog = ({ isOpen, onClose, onConfirm, url }: LinkSafe
|
|
|
85
82
|
|
|
86
83
|
return (
|
|
87
84
|
<AlertDialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
|
88
|
-
<AlertDialogContent className="border-border/60 p-5 shadow-2xl dark:border-white/10 sm:
|
|
89
|
-
<AlertDialogHeader>
|
|
90
|
-
<AlertDialogTitle className="flex items-center gap-2">
|
|
91
|
-
<ExternalLinkIcon className="size-
|
|
85
|
+
<AlertDialogContent className="max-h-[calc(100dvh-1rem)] w-[calc(100vw-1rem)] max-w-lg gap-5 overflow-y-auto border-border/60 p-5 shadow-2xl dark:border-white/10 sm:w-full sm:p-6">
|
|
86
|
+
<AlertDialogHeader className="text-left">
|
|
87
|
+
<AlertDialogTitle className="flex items-center gap-2.5">
|
|
88
|
+
<ExternalLinkIcon className="size-5 shrink-0" aria-hidden="true" />
|
|
92
89
|
Open external link?
|
|
93
90
|
</AlertDialogTitle>
|
|
94
91
|
<AlertDialogDescription>
|
|
@@ -96,14 +93,14 @@ export const ExternalLinkDialog = ({ isOpen, onClose, onConfirm, url }: LinkSafe
|
|
|
96
93
|
</AlertDialogDescription>
|
|
97
94
|
</AlertDialogHeader>
|
|
98
95
|
<div
|
|
99
|
-
className="max-h-32 overflow-y-auto break-all rounded-md bg-muted px-3 py-2 font-mono text-sm"
|
|
96
|
+
className="max-h-32 overflow-y-auto break-all rounded-md border border-border/50 bg-muted/70 px-3 py-2.5 font-mono text-sm leading-5"
|
|
100
97
|
title={link.absoluteUrl}
|
|
101
98
|
>
|
|
102
99
|
{link.displayUrl}
|
|
103
100
|
</div>
|
|
104
101
|
<AlertDialogFooter>
|
|
105
|
-
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
106
|
-
<Button type="button" variant="outline" onClick={copyLink}>
|
|
102
|
+
<AlertDialogCancel className="w-full sm:w-auto">Cancel</AlertDialogCancel>
|
|
103
|
+
<Button className="w-full sm:w-auto" type="button" variant="outline" onClick={copyLink}>
|
|
107
104
|
{copied ? (
|
|
108
105
|
<CheckIcon className="size-4" aria-hidden="true" />
|
|
109
106
|
) : (
|
|
@@ -111,7 +108,7 @@ export const ExternalLinkDialog = ({ isOpen, onClose, onConfirm, url }: LinkSafe
|
|
|
111
108
|
)}
|
|
112
109
|
{copied ? "Copied" : "Copy link"}
|
|
113
110
|
</Button>
|
|
114
|
-
<AlertDialogAction onClick={onConfirm}>
|
|
111
|
+
<AlertDialogAction className="w-full sm:w-auto" onClick={onConfirm}>
|
|
115
112
|
<ExternalLinkIcon className="size-4" aria-hidden="true" />
|
|
116
113
|
Open link
|
|
117
114
|
</AlertDialogAction>
|
package/src/react/bubbles.tsx
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
import { MarkdownWithEmbeds } from "./embed-slots.tsx";
|
|
35
35
|
import { ExportMenu } from "./export-menu.tsx";
|
|
36
36
|
import { FeedbackControls } from "./feedback-controls.tsx";
|
|
37
|
-
import { ToolMarkdown } from "./markdown.tsx";
|
|
37
|
+
import { CHAT_LINK_SAFETY, ToolMarkdown } from "./markdown.tsx";
|
|
38
38
|
import { ToolSessionPill, humanizeToolName } from "./tool-pill.tsx";
|
|
39
39
|
import {
|
|
40
40
|
isRespondingChatStatus,
|
|
@@ -62,13 +62,13 @@ const UserAvatar = () => (
|
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
const ThoughtsDisclosure = ({ text }: { text: string }) => (
|
|
65
|
-
<Collapsible>
|
|
66
|
-
<CollapsibleTrigger className="group flex w-
|
|
65
|
+
<Collapsible className="min-w-0 max-w-full overflow-hidden rounded-md border border-border/40 bg-background/30 px-2 py-1 transition-colors">
|
|
66
|
+
<CollapsibleTrigger className="group flex w-full cursor-pointer items-center gap-2 text-left text-xs text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
|
67
67
|
<ChevronDownIcon className="size-3 shrink-0 transition-transform group-data-[state=closed]:-rotate-90" />
|
|
68
68
|
Thoughts
|
|
69
69
|
</CollapsibleTrigger>
|
|
70
|
-
<CollapsibleContent>
|
|
71
|
-
<div className="mt-1
|
|
70
|
+
<CollapsibleContent className="min-w-0 max-w-full overflow-hidden">
|
|
71
|
+
<div className="mt-1.5 min-w-0 max-w-full overflow-hidden text-xs text-muted-foreground">
|
|
72
72
|
<ToolMarkdown className="prose-p:my-0 [&_p]:!my-0">{text}</ToolMarkdown>
|
|
73
73
|
</div>
|
|
74
74
|
</CollapsibleContent>
|
|
@@ -198,7 +198,11 @@ const ToolApprovalCard = ({
|
|
|
198
198
|
{asEmailInput(input) ? (
|
|
199
199
|
<EmailApprovalPreview email={asEmailInput(input)!} />
|
|
200
200
|
) : (
|
|
201
|
-
<RecordPreview
|
|
201
|
+
<RecordPreview
|
|
202
|
+
value={input}
|
|
203
|
+
linkSafety={CHAT_LINK_SAFETY}
|
|
204
|
+
className="rounded bg-background/40"
|
|
205
|
+
/>
|
|
202
206
|
)}
|
|
203
207
|
{expired ? (
|
|
204
208
|
<div className="mt-3 flex items-center gap-1.5 text-xs font-medium text-muted-foreground">
|
|
@@ -313,6 +317,8 @@ type AssistantBubbleProps = {
|
|
|
313
317
|
message: UIMessage;
|
|
314
318
|
isLast: boolean;
|
|
315
319
|
status: ChatStatus;
|
|
320
|
+
/** Tighten the transcript gap when this is another segment of the same assistant turn. */
|
|
321
|
+
continuation?: boolean;
|
|
316
322
|
events?: ToolEvent[];
|
|
317
323
|
regenerate?: () => void;
|
|
318
324
|
/** Approve / deny handler for inline {@link ToolApprovalCard}s. */
|
|
@@ -348,6 +354,7 @@ export const AssistantBubble = ({
|
|
|
348
354
|
message,
|
|
349
355
|
isLast,
|
|
350
356
|
status,
|
|
357
|
+
continuation = false,
|
|
351
358
|
events,
|
|
352
359
|
regenerate,
|
|
353
360
|
onResolveToolApproval,
|
|
@@ -410,7 +417,12 @@ export const AssistantBubble = ({
|
|
|
410
417
|
// nothing so the prose flows unaffected. Suggested questions
|
|
411
418
|
// stay gated on settle to avoid pop-in mid-stream.
|
|
412
419
|
return (
|
|
413
|
-
<Item
|
|
420
|
+
<Item
|
|
421
|
+
className={cn(
|
|
422
|
+
"min-w-0 max-w-full items-start gap-0 overflow-hidden border-none bg-transparent p-0",
|
|
423
|
+
continuation && "-mt-1.5",
|
|
424
|
+
)}
|
|
425
|
+
>
|
|
414
426
|
{/*
|
|
415
427
|
* `min-w-0` is required so wide content (markdown tables, long
|
|
416
428
|
* code blocks) can shrink to fit instead of pushing the whole
|
|
@@ -33,7 +33,7 @@ import { autosizeComposerTextarea, observeComposerWidth } from "./_composer-auto
|
|
|
33
33
|
import { imageFileToUIPart, MAX_COMPOSER_IMAGES } from "./_image-attachments.ts";
|
|
34
34
|
import { ModelSelector } from "./_model-selector.tsx";
|
|
35
35
|
import { ExportMenu } from "./export-menu.tsx";
|
|
36
|
-
import { isActiveChatStatus,
|
|
36
|
+
import { isActiveChatStatus, type ChatViewProps } from "./types.ts";
|
|
37
37
|
|
|
38
38
|
type QueuedSteerListProps = {
|
|
39
39
|
queuedSteers: NonNullable<ChatViewProps["queuedSteers"]>;
|
|
@@ -319,7 +319,7 @@ export const ChatComposer = ({
|
|
|
319
319
|
}, [focusRequest, isLoadingHistory]);
|
|
320
320
|
|
|
321
321
|
const isRunning = isActiveChatStatus(status);
|
|
322
|
-
const canStop =
|
|
322
|
+
const canStop = isRunning;
|
|
323
323
|
const hasDraft = Boolean(input.trim() || files.length > 0);
|
|
324
324
|
const submit = () => {
|
|
325
325
|
const text = input.trim();
|
|
@@ -468,7 +468,7 @@ export const ChatComposer = ({
|
|
|
468
468
|
}}
|
|
469
469
|
placeholder="Send a message..."
|
|
470
470
|
rows={1}
|
|
471
|
-
className="aui-composer-input field-sizing-fixed min-h-10 max-h-
|
|
471
|
+
className="aui-composer-input field-sizing-fixed min-h-10 max-h-[min(12rem,35dvh)] w-full flex-none overflow-y-auto px-4 pb-2 pt-4 text-base sm:text-sm"
|
|
472
472
|
/>
|
|
473
473
|
{allowAttachments && fileError && (
|
|
474
474
|
<div className="px-4 text-xs text-destructive" role="alert">
|
|
@@ -27,8 +27,7 @@ export interface GenieFeedbackTarget {
|
|
|
27
27
|
|
|
28
28
|
/** Per-message feedback destination and optional Genie identity. */
|
|
29
29
|
export type MessageFeedbackDestination =
|
|
30
|
-
|
|
31
|
-
| ({ mode: "genie" } & GenieFeedbackTarget);
|
|
30
|
+
{ mode: "mlflow"; traceId: string } | ({ mode: "genie" } & GenieFeedbackTarget);
|
|
32
31
|
|
|
33
32
|
/** Read the latest Genie target from an assistant message's tool results. */
|
|
34
33
|
export function genieFeedbackTarget(message: UIMessage): GenieFeedbackTarget | undefined {
|
package/src/react/chat-stream.ts
CHANGED
|
@@ -42,6 +42,7 @@ export const readThreadTitlePart = (chunk: UIMessageChunk): string | undefined =
|
|
|
42
42
|
|
|
43
43
|
/** Map lifecycle-only chunks onto the UI's active-turn state. */
|
|
44
44
|
export const chatStatusForChunk = (chunk: UIMessageChunk): ChatStatus | undefined => {
|
|
45
|
+
if (chunk.type === "error") return "error";
|
|
45
46
|
if ((chunk as { type?: string }).type === RESPONSE_COMPLETE_PART_TYPE) return "finishing";
|
|
46
47
|
if (chunk.type === "finish" || chunk.type === "abort") return "finishing";
|
|
47
48
|
return undefined;
|
|
@@ -69,7 +70,7 @@ export function closeOnTerminalChunk(
|
|
|
69
70
|
}
|
|
70
71
|
onChunk?.(value);
|
|
71
72
|
controller.enqueue(value);
|
|
72
|
-
if (value.type === "finish" || value.type === "abort") {
|
|
73
|
+
if (value.type === "finish" || value.type === "abort" || value.type === "error") {
|
|
73
74
|
onTerminal?.();
|
|
74
75
|
controller.close();
|
|
75
76
|
await reader.cancel("terminal AI SDK chunk received").catch(() => undefined);
|
|
@@ -178,10 +179,7 @@ export function useChatStream({ getSession, updateSession, writeMessages }: UseC
|
|
|
178
179
|
updateSession(threadId, (current) => ({
|
|
179
180
|
...current,
|
|
180
181
|
runId: runIdRef.current,
|
|
181
|
-
status:
|
|
182
|
-
terminalReceived || current.status === "finishing"
|
|
183
|
-
? "finishing"
|
|
184
|
-
: "streaming",
|
|
182
|
+
status: terminalReceived || current.status === "finishing" ? "finishing" : "streaming",
|
|
185
183
|
}));
|
|
186
184
|
}
|
|
187
185
|
return threadTitle;
|
|
@@ -26,6 +26,9 @@ const FOCUS_RESIZE_BOTTOM_THRESHOLD_PX = 2;
|
|
|
26
26
|
const FOCUS_RESIZE_SETTLE_MS = 650;
|
|
27
27
|
const TOP_LOAD_MORE_THRESHOLD_PX = 120;
|
|
28
28
|
|
|
29
|
+
/** Gestures that indicate the user is intentionally navigating transcript history. */
|
|
30
|
+
export const TRANSCRIPT_FOLLOW_CANCEL_EVENTS = ["touchmove", "wheel"] as const;
|
|
31
|
+
|
|
29
32
|
const assistantMessageHasVisibleContent = (
|
|
30
33
|
message: ChatViewProps["messages"][number],
|
|
31
34
|
events: ToolEvent[] | undefined,
|
|
@@ -162,7 +165,10 @@ export const useChatTranscriptController = ({
|
|
|
162
165
|
};
|
|
163
166
|
const handleReaderGesture = () => {
|
|
164
167
|
finishFocusResize();
|
|
165
|
-
|
|
168
|
+
// A wheel/touch gesture at the bottom may not move the viewport. Let the
|
|
169
|
+
// ensuing scroll event decide whether follow mode should stop so inert
|
|
170
|
+
// or downward gestures cannot detach desktop chat from new content.
|
|
171
|
+
programmaticScrollRef.current = false;
|
|
166
172
|
};
|
|
167
173
|
const observer = new ResizeObserver(() => {
|
|
168
174
|
restoreFocusPosition();
|
|
@@ -172,9 +178,9 @@ export const useChatTranscriptController = ({
|
|
|
172
178
|
frame.addEventListener("touchstart", handleFocusStart, { passive: true, capture: true });
|
|
173
179
|
frame.addEventListener("focusin", handleFocusStart);
|
|
174
180
|
frame.addEventListener("focusout", finishFocusResize);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
for (const eventName of TRANSCRIPT_FOLLOW_CANCEL_EVENTS) {
|
|
182
|
+
element.addEventListener(eventName, handleReaderGesture, { passive: true });
|
|
183
|
+
}
|
|
178
184
|
observer.observe(element);
|
|
179
185
|
|
|
180
186
|
return () => {
|
|
@@ -182,9 +188,9 @@ export const useChatTranscriptController = ({
|
|
|
182
188
|
frame.removeEventListener("touchstart", handleFocusStart, true);
|
|
183
189
|
frame.removeEventListener("focusin", handleFocusStart);
|
|
184
190
|
frame.removeEventListener("focusout", finishFocusResize);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
191
|
+
for (const eventName of TRANSCRIPT_FOLLOW_CANCEL_EVENTS) {
|
|
192
|
+
element.removeEventListener(eventName, handleReaderGesture);
|
|
193
|
+
}
|
|
188
194
|
observer.disconnect();
|
|
189
195
|
};
|
|
190
196
|
}, []);
|
|
@@ -299,45 +305,7 @@ export const ChatTranscript = ({
|
|
|
299
305
|
const visibleSuggestions = messages.length === 0 ? suggestions : followUpQuestions;
|
|
300
306
|
const scrollToBottomButtonRef = useRef<HTMLButtonElement>(null);
|
|
301
307
|
const scrollToBottomFrameRef = useRef<number | null>(null);
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
useLayoutEffect(() => {
|
|
305
|
-
const transcript = controller.scrollRef.current;
|
|
306
|
-
const content = controller.contentRef.current;
|
|
307
|
-
const indicator = scrollIndicatorRef.current;
|
|
308
|
-
if (!transcript || !content || !indicator) return;
|
|
309
|
-
|
|
310
|
-
const syncScrollIndicator = () => {
|
|
311
|
-
const maxScrollTop = transcript.scrollHeight - transcript.clientHeight;
|
|
312
|
-
const keyboardScroller = transcript.hasAttribute("data-keyboard-touch-scroller");
|
|
313
|
-
indicator.hidden = !keyboardScroller || maxScrollTop <= 0;
|
|
314
|
-
if (indicator.hidden) return;
|
|
315
|
-
|
|
316
|
-
const height = Math.max(
|
|
317
|
-
28,
|
|
318
|
-
Math.round((transcript.clientHeight / transcript.scrollHeight) * transcript.clientHeight),
|
|
319
|
-
);
|
|
320
|
-
const top = Math.round((transcript.scrollTop / maxScrollTop) * (transcript.clientHeight - height));
|
|
321
|
-
indicator.style.height = `${height}px`;
|
|
322
|
-
indicator.style.transform = `translateY(${top}px)`;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
const resizeObserver = new ResizeObserver(syncScrollIndicator);
|
|
326
|
-
const attributeObserver = new MutationObserver(syncScrollIndicator);
|
|
327
|
-
resizeObserver.observe(transcript);
|
|
328
|
-
resizeObserver.observe(content);
|
|
329
|
-
attributeObserver.observe(transcript, {
|
|
330
|
-
attributeFilter: ["data-keyboard-touch-scroller"],
|
|
331
|
-
});
|
|
332
|
-
transcript.addEventListener("scroll", syncScrollIndicator, { passive: true });
|
|
333
|
-
syncScrollIndicator();
|
|
334
|
-
|
|
335
|
-
return () => {
|
|
336
|
-
resizeObserver.disconnect();
|
|
337
|
-
attributeObserver.disconnect();
|
|
338
|
-
transcript.removeEventListener("scroll", syncScrollIndicator);
|
|
339
|
-
};
|
|
340
|
-
}, [controller.contentRef, controller.scrollRef]);
|
|
308
|
+
const scrollToBottomOverflowRef = useRef<string | null>(null);
|
|
341
309
|
|
|
342
310
|
const activateScrollToBottomFromTouch = useCallback(() => {
|
|
343
311
|
const transcript = controller.scrollRef.current;
|
|
@@ -346,15 +314,21 @@ export const ChatTranscript = ({
|
|
|
346
314
|
return;
|
|
347
315
|
}
|
|
348
316
|
|
|
349
|
-
|
|
317
|
+
if (scrollToBottomOverflowRef.current === null) {
|
|
318
|
+
scrollToBottomOverflowRef.current = transcript.style.overflowY;
|
|
319
|
+
}
|
|
350
320
|
transcript.dispatchEvent(new Event(CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT));
|
|
321
|
+
|
|
322
|
+
// Hiding overflow cancels WebKit's native momentum immediately. The second assignment on the
|
|
323
|
+
// next frame keeps the transcript pinned after its normal scroll range has been restored.
|
|
351
324
|
transcript.style.overflowY = "hidden";
|
|
352
325
|
controller.scrollToBottomNow();
|
|
353
326
|
if (scrollToBottomFrameRef.current !== null) {
|
|
354
327
|
window.cancelAnimationFrame(scrollToBottomFrameRef.current);
|
|
355
328
|
}
|
|
356
329
|
scrollToBottomFrameRef.current = window.requestAnimationFrame(() => {
|
|
357
|
-
transcript.style.overflowY =
|
|
330
|
+
transcript.style.overflowY = scrollToBottomOverflowRef.current ?? "";
|
|
331
|
+
scrollToBottomOverflowRef.current = null;
|
|
358
332
|
controller.scrollToBottomNow();
|
|
359
333
|
scrollToBottomFrameRef.current = null;
|
|
360
334
|
});
|
|
@@ -364,6 +338,9 @@ export const ChatTranscript = ({
|
|
|
364
338
|
const button = scrollToBottomButtonRef.current;
|
|
365
339
|
if (!button) return;
|
|
366
340
|
|
|
341
|
+
// React delegates touch events through a passive document listener in Mobile Safari. Native
|
|
342
|
+
// non-passive listeners are required here so the button can scroll without transferring focus
|
|
343
|
+
// away from the composer and closing the keyboard.
|
|
367
344
|
const handlePointerDown = (event: PointerEvent) => {
|
|
368
345
|
event.preventDefault();
|
|
369
346
|
};
|
|
@@ -381,6 +358,12 @@ export const ChatTranscript = ({
|
|
|
381
358
|
return () => {
|
|
382
359
|
if (scrollToBottomFrameRef.current !== null) {
|
|
383
360
|
window.cancelAnimationFrame(scrollToBottomFrameRef.current);
|
|
361
|
+
scrollToBottomFrameRef.current = null;
|
|
362
|
+
}
|
|
363
|
+
const transcript = controller.scrollRef.current;
|
|
364
|
+
if (transcript && scrollToBottomOverflowRef.current !== null) {
|
|
365
|
+
transcript.style.overflowY = scrollToBottomOverflowRef.current;
|
|
366
|
+
scrollToBottomOverflowRef.current = null;
|
|
384
367
|
}
|
|
385
368
|
button.removeEventListener("pointerdown", handlePointerDown);
|
|
386
369
|
button.removeEventListener("touchstart", handleTouchStart);
|
|
@@ -451,6 +434,7 @@ export const ChatTranscript = ({
|
|
|
451
434
|
message={message}
|
|
452
435
|
isLast={isLast}
|
|
453
436
|
status={status}
|
|
437
|
+
continuation={messages[index - 1]?.role === "assistant"}
|
|
454
438
|
events={toolEventsByMessage[message.id]}
|
|
455
439
|
regenerate={regenerate}
|
|
456
440
|
onResolveToolApproval={onResolveToolApproval}
|
|
@@ -522,7 +506,6 @@ export const ChatTranscript = ({
|
|
|
522
506
|
</div>
|
|
523
507
|
</div>
|
|
524
508
|
<div
|
|
525
|
-
ref={scrollIndicatorRef}
|
|
526
509
|
data-slot="aui_thread-scroll-indicator"
|
|
527
510
|
className="pointer-events-none absolute right-0.5 top-0 z-20 w-0.5 rounded-full bg-foreground/50"
|
|
528
511
|
hidden
|
|
@@ -99,10 +99,7 @@ export const FeedbackControls = ({
|
|
|
99
99
|
</TooltipTrigger>
|
|
100
100
|
<TooltipContent>Bad response</TooltipContent>
|
|
101
101
|
</Tooltip>
|
|
102
|
-
<Dialog
|
|
103
|
-
open={open}
|
|
104
|
-
onOpenChange={setOpen}
|
|
105
|
-
>
|
|
102
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
106
103
|
<Tooltip>
|
|
107
104
|
<TooltipTrigger asChild>
|
|
108
105
|
<DialogTrigger asChild disabled={!canComment}>
|
package/src/react/markdown.tsx
CHANGED
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
import { createShikiPlugin, highlightToHtml, useHighlightedHtml } from "@dbx-tools/ui/react";
|
|
17
17
|
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
18
18
|
import React, { useEffect, useRef, useState } from "react";
|
|
19
|
-
import { Streamdown } from "streamdown";
|
|
20
|
-
import { ExternalLinkDialog,
|
|
19
|
+
import { Streamdown, type LinkSafetyConfig } from "streamdown";
|
|
20
|
+
import { ExternalLinkDialog, isSameOriginLink } from "./_external-link-dialog.tsx";
|
|
21
21
|
import { DataGrid, TABLE_WRAPPER_CLASSES, colorizeDelta, type DataRow } from "./data-grid.tsx";
|
|
22
22
|
import { copyText } from "../support/clipboard.ts";
|
|
23
23
|
|
|
@@ -135,18 +135,14 @@ const MARKDOWN_TABLE_PARTS = {
|
|
|
135
135
|
},
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
-
/** Chat links
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
"visited:text-blue-800 dark:text-blue-300 dark:decoration-blue-300/40 dark:visited:text-blue-300 dark:hover:text-blue-200",
|
|
147
|
-
className,
|
|
148
|
-
)}
|
|
149
|
-
/>
|
|
138
|
+
/** Chat links keep Streamdown's safety behavior while using a higher-contrast blue. */
|
|
139
|
+
const MARKDOWN_LINK_CLASSES = cn(
|
|
140
|
+
"[&_[data-streamdown=link]]:font-normal [&_[data-streamdown=link]]:text-blue-700",
|
|
141
|
+
"[&_[data-streamdown=link]]:decoration-blue-700/40 [&_[data-streamdown=link]]:decoration-1 [&_[data-streamdown=link]]:underline-offset-2",
|
|
142
|
+
"[&_[data-streamdown=link]]:transition-colors [&_[data-streamdown=link]]:hover:text-blue-800 [&_[data-streamdown=link]]:hover:decoration-current",
|
|
143
|
+
"[&_[data-streamdown=link]]:focus-visible:rounded-sm [&_[data-streamdown=link]]:focus-visible:outline-none",
|
|
144
|
+
"[&_[data-streamdown=link]]:focus-visible:ring-2 [&_[data-streamdown=link]]:focus-visible:ring-ring [&_[data-streamdown=link]]:focus-visible:ring-offset-2",
|
|
145
|
+
"dark:[&_[data-streamdown=link]]:text-blue-300 dark:[&_[data-streamdown=link]]:decoration-blue-300/40 dark:[&_[data-streamdown=link]]:hover:text-blue-200",
|
|
150
146
|
);
|
|
151
147
|
|
|
152
148
|
/**
|
|
@@ -158,7 +154,6 @@ const MarkdownLink = ({ className, ...props }: React.AnchorHTMLAttributes<HTMLAn
|
|
|
158
154
|
*/
|
|
159
155
|
const MARKDOWN_COMPONENTS = {
|
|
160
156
|
...MARKDOWN_TABLE_PARTS,
|
|
161
|
-
a: MarkdownLink,
|
|
162
157
|
table: ({
|
|
163
158
|
node,
|
|
164
159
|
children,
|
|
@@ -201,7 +196,6 @@ const STREAMING_MARKDOWN_COMPONENTS = {
|
|
|
201
196
|
*/
|
|
202
197
|
const TOOL_MARKDOWN_COMPONENTS = {
|
|
203
198
|
...MARKDOWN_TABLE_PARTS,
|
|
204
|
-
a: MarkdownLink,
|
|
205
199
|
table: plainMarkdownTable,
|
|
206
200
|
};
|
|
207
201
|
|
|
@@ -214,13 +208,13 @@ const TOOL_MARKDOWN_COMPONENTS = {
|
|
|
214
208
|
const SHIKI_PLUGIN = { code: createShikiPlugin() };
|
|
215
209
|
|
|
216
210
|
/** Keep Streamdown's link confirmation while matching the chat's AppKit UI. */
|
|
217
|
-
const
|
|
211
|
+
export const CHAT_LINK_SAFETY = {
|
|
218
212
|
enabled: true,
|
|
219
|
-
onLinkCheck:
|
|
213
|
+
onLinkCheck: isSameOriginLink,
|
|
220
214
|
renderModal: (props: React.ComponentProps<typeof ExternalLinkDialog>) => (
|
|
221
215
|
<ExternalLinkDialog {...props} />
|
|
222
216
|
),
|
|
223
|
-
};
|
|
217
|
+
} satisfies LinkSafetyConfig;
|
|
224
218
|
|
|
225
219
|
/**
|
|
226
220
|
* Per-word fade-in applied while a reply is still streaming. Streamdown
|
|
@@ -274,7 +268,7 @@ export const AssistantMarkdown = ({
|
|
|
274
268
|
components={animate ? STREAMING_MARKDOWN_COMPONENTS : MARKDOWN_COMPONENTS}
|
|
275
269
|
plugins={SHIKI_PLUGIN}
|
|
276
270
|
controls={false}
|
|
277
|
-
linkSafety={
|
|
271
|
+
linkSafety={CHAT_LINK_SAFETY}
|
|
278
272
|
animated={animate ? ANIMATE_OPTIONS : false}
|
|
279
273
|
isAnimating={animate}
|
|
280
274
|
className={cn(
|
|
@@ -285,6 +279,7 @@ export const AssistantMarkdown = ({
|
|
|
285
279
|
"prose-h1:text-lg prose-h1:mt-4 prose-h1:mb-2",
|
|
286
280
|
"prose-h2:text-base prose-h2:mt-4 prose-h2:mb-2",
|
|
287
281
|
"prose-h3:text-sm prose-h3:mt-3 prose-h3:mb-1.5 prose-h3:text-muted-foreground prose-h3:uppercase prose-h3:tracking-wider",
|
|
282
|
+
MARKDOWN_LINK_CLASSES,
|
|
288
283
|
)}
|
|
289
284
|
>
|
|
290
285
|
{children}
|
|
@@ -309,7 +304,7 @@ export const ToolMarkdown = ({ children, className }: { children: string; classN
|
|
|
309
304
|
components={TOOL_MARKDOWN_COMPONENTS}
|
|
310
305
|
plugins={SHIKI_PLUGIN}
|
|
311
306
|
controls={false}
|
|
312
|
-
linkSafety={
|
|
307
|
+
linkSafety={CHAT_LINK_SAFETY}
|
|
313
308
|
className={cn(
|
|
314
309
|
"prose prose-sm dark:prose-invert min-w-0 max-w-full overflow-x-hidden break-words",
|
|
315
310
|
"!text-xs leading-tight text-muted-foreground sm:leading-snug",
|
|
@@ -318,7 +313,8 @@ export const ToolMarkdown = ({ children, className }: { children: string; classN
|
|
|
318
313
|
"prose-li:my-0 prose-li:leading-tight prose-li:marker:text-muted-foreground/60 [&_li]:!text-xs sm:prose-li:leading-snug",
|
|
319
314
|
"prose-headings:my-1 prose-headings:text-xs prose-headings:font-semibold",
|
|
320
315
|
"prose-strong:text-foreground/90 prose-strong:font-medium [&_strong]:!text-xs",
|
|
321
|
-
"prose-code:font-medium [&_code]:!text-xs [&
|
|
316
|
+
"prose-code:font-medium [&_code]:!text-xs [&_[data-streamdown=link]]:!text-xs",
|
|
317
|
+
MARKDOWN_LINK_CLASSES,
|
|
322
318
|
className,
|
|
323
319
|
)}
|
|
324
320
|
>
|
|
@@ -81,6 +81,7 @@ export type ThreadIdChangeReason = "hydrate" | "select" | "new" | "delete" | "mi
|
|
|
81
81
|
// preserving the visual scroll position across the prepend.
|
|
82
82
|
|
|
83
83
|
const logger = log.logger("ui-mastra/chat");
|
|
84
|
+
const STEER_INTERRUPT_SETTLEMENT_TIMEOUT_MS = 2_000;
|
|
84
85
|
|
|
85
86
|
const makeUserMessage = (text: string, files: FileUIPart[] = []): UIMessage => ({
|
|
86
87
|
id: hash.id(),
|
|
@@ -326,8 +327,9 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
326
327
|
const enableFeedback = options.enableFeedback !== false;
|
|
327
328
|
const feedbackModes = enableFeedback ? mastraClient.feedbackModes : [];
|
|
328
329
|
const feedbackAvailable = feedbackModes.length > 0;
|
|
329
|
-
const { url: mlflowExperimentUrl, tracePrefix: mlflowTracePrefix } =
|
|
330
|
-
|
|
330
|
+
const { url: mlflowExperimentUrl, tracePrefix: mlflowTracePrefix } = useMastraMlflowExperiment(
|
|
331
|
+
feedbackModes.includes("mlflow"),
|
|
332
|
+
);
|
|
331
333
|
const [resourceScope, setResourceScope] = useState<string | null>(null);
|
|
332
334
|
useEffect(() => {
|
|
333
335
|
let cancelled = false;
|
|
@@ -661,6 +663,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
661
663
|
if (
|
|
662
664
|
controller.signal.aborted ||
|
|
663
665
|
getSession(threadId).runToken !== token ||
|
|
666
|
+
getSession(threadId).status === "error" ||
|
|
664
667
|
initialError instanceof MastraChatRequestError ||
|
|
665
668
|
!mastraClient.backgroundTurns ||
|
|
666
669
|
!runId
|
|
@@ -994,12 +997,24 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
994
997
|
if (!isSessionRunning(current)) return;
|
|
995
998
|
const streamThreadId = threadId === DEFAULT_THREAD_SESSION_KEY ? undefined : threadId;
|
|
996
999
|
const runId = current.runId;
|
|
1000
|
+
const settlementSignal = AbortSignal.timeout(STEER_INTERRUPT_SETTLEMENT_TIMEOUT_MS);
|
|
997
1001
|
const settlement =
|
|
998
1002
|
mastraClient.backgroundTurns && runId
|
|
999
1003
|
? mastraClient
|
|
1000
|
-
.observeAgentStream({
|
|
1004
|
+
.observeAgentStream({
|
|
1005
|
+
agentId,
|
|
1006
|
+
runId,
|
|
1007
|
+
threadId: streamThreadId,
|
|
1008
|
+
signal: settlementSignal,
|
|
1009
|
+
})
|
|
1001
1010
|
.then((stream) => waitForTerminalChunk(stream.stream))
|
|
1002
1011
|
.catch((error: unknown) => {
|
|
1012
|
+
if (settlementSignal.aborted) {
|
|
1013
|
+
logger.warn("interrupted background run did not settle before replacement", {
|
|
1014
|
+
runId,
|
|
1015
|
+
});
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1003
1018
|
logger.warn("failed to observe interrupted background run", {
|
|
1004
1019
|
runId,
|
|
1005
1020
|
error: toError(error),
|
|
@@ -1100,10 +1115,10 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
1100
1115
|
[appendUserMessage, runStream, activeKey, getSession, updateSession],
|
|
1101
1116
|
);
|
|
1102
1117
|
|
|
1103
|
-
// Fire a queued steer immediately, out of order: remove it from the queue
|
|
1104
|
-
// append it
|
|
1105
|
-
// in-flight run (abort
|
|
1106
|
-
//
|
|
1118
|
+
// Fire a queued steer immediately, out of order: remove it from the queue
|
|
1119
|
+
// and append it first so acceptance is visible while the prior durable run
|
|
1120
|
+
// settles. `runStream`/`driveStream` then supersede the in-flight run (abort
|
|
1121
|
+
// + runToken bump + settle running pills) and send the chosen steer.
|
|
1107
1122
|
const sendSteerNow = useCallback(
|
|
1108
1123
|
(steerId: string) => {
|
|
1109
1124
|
const threadId = activeKey;
|
|
@@ -1115,14 +1130,11 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
|
|
|
1115
1130
|
queuedSteers: removeSteerFromQueue(session.queuedSteers, steerId),
|
|
1116
1131
|
}));
|
|
1117
1132
|
logger.info("steer:send-now", { threadId });
|
|
1133
|
+
const { message } = appendUserMessage(threadId, steer.text ?? "", steer.files);
|
|
1134
|
+
const replacementMessages = interruptedTurnMessages(current.messages, message);
|
|
1118
1135
|
void (async () => {
|
|
1119
1136
|
await interruptActiveRun(threadId);
|
|
1120
|
-
|
|
1121
|
-
void runStream(
|
|
1122
|
-
threadId,
|
|
1123
|
-
interruptedTurnMessages(current.messages, message),
|
|
1124
|
-
steer.requestContext,
|
|
1125
|
-
);
|
|
1137
|
+
void runStream(threadId, replacementMessages, steer.requestContext);
|
|
1126
1138
|
})();
|
|
1127
1139
|
},
|
|
1128
1140
|
[activeKey, appendUserMessage, getSession, interruptActiveRun, runStream, updateSession],
|