@dbx-tools/ui-mastra 0.9.182 → 0.9.185
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 -3
- package/index.support.ts +1 -1
- package/index.ts +1 -1
- package/package.json +7 -8
- 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-thread-layout.tsx +0 -2
- package/src/react/chat-transcript.tsx +37 -60
- package/src/react/feedback-controls.tsx +1 -4
- package/src/react/markdown.tsx +18 -22
- package/src/react/mastra-chat.tsx +70 -15
- package/src/react/tool-pill.tsx +76 -59
- package/src/react/types.ts +1 -0
- package/src/styles.css +0 -15
- package/src/support/genie-client.ts +24 -12
- package/src/support/mastra-client.ts +3 -4
- package/src/support/tool-events.ts +35 -7
- package/src/react/use-composer-viewport-lock.ts +0 -209
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";
|
|
@@ -60,4 +60,3 @@ export type { ToolInputPresentation, WebSearchProgressGroup } from "./src/react/
|
|
|
60
60
|
export { isActiveChatStatus, isRespondingChatStatus } from "./src/react/types.ts";
|
|
61
61
|
export type { ChatStatus, ToolEvent, ToolProgress, ChatModelOption, ChatInputMessage, QueuedSteer, FeedbackValue, FeedbackSubmission, MessageFeedback, ThreadSummary, ThreadPlacement, ChatViewProps, ApprovalDecision, PendingApproval } from "./src/react/types.ts";
|
|
62
62
|
export { useChatThreadQuery } from "./src/react/use-chat-thread-query.ts";
|
|
63
|
-
export { CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT, useComposerViewportLock } from "./src/react/use-composer-viewport-lock.ts";
|
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.185",
|
|
36
|
+
"@dbx-tools/shared-core": "^0.9.185",
|
|
37
|
+
"@dbx-tools/shared-genie": "^0.9.185",
|
|
38
|
+
"@dbx-tools/shared-mastra": "^0.9.185",
|
|
39
|
+
"@dbx-tools/shared-model": "^0.9.185",
|
|
40
|
+
"@dbx-tools/ui": "^0.9.185",
|
|
41
41
|
"@mastra/client-js": "1.50.0",
|
|
42
42
|
"@mastra/core": "1.71.0",
|
|
43
43
|
"@tanstack/react-table": "^8.21.3",
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"echarts-for-react": "^3.0.2",
|
|
47
47
|
"lucide-react": "^0.554.0",
|
|
48
48
|
"marked": "^18.0.5",
|
|
49
|
-
"scrollbooster": "4.0.0",
|
|
50
49
|
"sql-formatter": "^15.6.9",
|
|
51
50
|
"streamdown": "^2.5.0",
|
|
52
51
|
"zod": "4.3.6"
|
|
@@ -56,7 +55,7 @@
|
|
|
56
55
|
"publishConfig": {
|
|
57
56
|
"access": "public"
|
|
58
57
|
},
|
|
59
|
-
"version": "0.9.
|
|
58
|
+
"version": "0.9.185",
|
|
60
59
|
"types": "index.ts",
|
|
61
60
|
"dbxToolsConfig": {
|
|
62
61
|
"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;
|
|
@@ -11,7 +11,6 @@ import React, { useEffect, useRef, useState } from "react";
|
|
|
11
11
|
import { ThreadSidebar, type ThreadSidebarProps } from "./thread-sidebar.tsx";
|
|
12
12
|
import { ThreadTabs } from "./thread-tabs.tsx";
|
|
13
13
|
import type { ChatViewProps } from "./types.ts";
|
|
14
|
-
import { useComposerViewportLock } from "./use-composer-viewport-lock.ts";
|
|
15
14
|
import { closeThreadTab, nextActiveThreadTab, syncThreadTabs } from "../support/thread-tabs.ts";
|
|
16
15
|
|
|
17
16
|
const SIDE_PANEL_MIN_WIDTH_PX = 768;
|
|
@@ -112,7 +111,6 @@ export const ChatThreadLayout = ({
|
|
|
112
111
|
onToggleSidebar,
|
|
113
112
|
}: ChatThreadLayoutProps) => {
|
|
114
113
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
115
|
-
useComposerViewportLock(rootRef);
|
|
116
114
|
const isNarrow = useIsNarrow(rootRef);
|
|
117
115
|
const showThreads = Boolean(threads && onSelectThread) && threadPlacement !== "disabled";
|
|
118
116
|
const placement = threadPlacement === "auto" ? (isNarrow ? "top" : "left") : threadPlacement;
|
|
@@ -14,11 +14,11 @@ import { errorMessage } from "@dbx-tools/shared-core";
|
|
|
14
14
|
import { isToolUIPart } from "ai";
|
|
15
15
|
import { ArrowDownIcon, MessageSquareIcon, RefreshCwIcon, TriangleAlertIcon } from "lucide-react";
|
|
16
16
|
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
17
|
+
import { flushSync } from "react-dom";
|
|
17
18
|
import { AssistantBubble, UserBubble } from "./bubbles.tsx";
|
|
18
19
|
import { messageFeedbackDestination, mlflowTraceUrl } from "./chat-feedback.ts";
|
|
19
20
|
import { SuggestionPills } from "./suggestion-pills.tsx";
|
|
20
21
|
import { isActiveChatStatus, type ChatViewProps, type ToolEvent } from "./types.ts";
|
|
21
|
-
import { CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT } from "./use-composer-viewport-lock.ts";
|
|
22
22
|
import { messageText } from "../support/export.ts";
|
|
23
23
|
|
|
24
24
|
const BOTTOM_THRESHOLD_PX = 24;
|
|
@@ -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
|
}, []);
|
|
@@ -227,7 +233,9 @@ export const useChatTranscriptController = ({
|
|
|
227
233
|
|
|
228
234
|
const scrollToBottomNow = useCallback(() => {
|
|
229
235
|
pinnedRef.current = true;
|
|
230
|
-
|
|
236
|
+
// Native Mobile Safari touch listeners run outside React's delegated event path. Commit the
|
|
237
|
+
// hidden state before mutating scrollTop so the control disappears before the transcript jumps.
|
|
238
|
+
flushSync(() => setIsAtBottom(true));
|
|
231
239
|
pinToBottomNow();
|
|
232
240
|
}, [pinToBottomNow]);
|
|
233
241
|
|
|
@@ -299,45 +307,7 @@ export const ChatTranscript = ({
|
|
|
299
307
|
const visibleSuggestions = messages.length === 0 ? suggestions : followUpQuestions;
|
|
300
308
|
const scrollToBottomButtonRef = useRef<HTMLButtonElement>(null);
|
|
301
309
|
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]);
|
|
310
|
+
const scrollToBottomOverflowRef = useRef<string | null>(null);
|
|
341
311
|
|
|
342
312
|
const activateScrollToBottomFromTouch = useCallback(() => {
|
|
343
313
|
const transcript = controller.scrollRef.current;
|
|
@@ -346,15 +316,20 @@ export const ChatTranscript = ({
|
|
|
346
316
|
return;
|
|
347
317
|
}
|
|
348
318
|
|
|
349
|
-
|
|
350
|
-
|
|
319
|
+
if (scrollToBottomOverflowRef.current === null) {
|
|
320
|
+
scrollToBottomOverflowRef.current = transcript.style.overflowY;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// WebKit has no public API for stopping an overflow scroller's momentum. Briefly removing
|
|
324
|
+
// overflow terminates that momentum; restoring it one frame later keeps normal scrolling native.
|
|
351
325
|
transcript.style.overflowY = "hidden";
|
|
352
326
|
controller.scrollToBottomNow();
|
|
353
327
|
if (scrollToBottomFrameRef.current !== null) {
|
|
354
328
|
window.cancelAnimationFrame(scrollToBottomFrameRef.current);
|
|
355
329
|
}
|
|
356
330
|
scrollToBottomFrameRef.current = window.requestAnimationFrame(() => {
|
|
357
|
-
transcript.style.overflowY =
|
|
331
|
+
transcript.style.overflowY = scrollToBottomOverflowRef.current ?? "";
|
|
332
|
+
scrollToBottomOverflowRef.current = null;
|
|
358
333
|
controller.scrollToBottomNow();
|
|
359
334
|
scrollToBottomFrameRef.current = null;
|
|
360
335
|
});
|
|
@@ -364,6 +339,8 @@ export const ChatTranscript = ({
|
|
|
364
339
|
const button = scrollToBottomButtonRef.current;
|
|
365
340
|
if (!button) return;
|
|
366
341
|
|
|
342
|
+
// React's delegated touch listener may be passive in Mobile Safari. These button-local,
|
|
343
|
+
// non-passive listeners prevent focus transfer without changing transcript gesture handling.
|
|
367
344
|
const handlePointerDown = (event: PointerEvent) => {
|
|
368
345
|
event.preventDefault();
|
|
369
346
|
};
|
|
@@ -381,12 +358,18 @@ 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);
|
|
387
370
|
button.removeEventListener("touchend", handleTouchEnd);
|
|
388
371
|
};
|
|
389
|
-
}, [activateScrollToBottomFromTouch]);
|
|
372
|
+
}, [activateScrollToBottomFromTouch, controller.scrollRef]);
|
|
390
373
|
|
|
391
374
|
return (
|
|
392
375
|
<div className="relative flex min-w-0 max-w-full flex-1 flex-col overflow-hidden">
|
|
@@ -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}
|
|
@@ -521,14 +505,7 @@ export const ChatTranscript = ({
|
|
|
521
505
|
)}
|
|
522
506
|
</div>
|
|
523
507
|
</div>
|
|
524
|
-
<div
|
|
525
|
-
ref={scrollIndicatorRef}
|
|
526
|
-
data-slot="aui_thread-scroll-indicator"
|
|
527
|
-
className="pointer-events-none absolute right-0.5 top-0 z-20 w-0.5 rounded-full bg-foreground/50"
|
|
528
|
-
hidden
|
|
529
|
-
aria-hidden="true"
|
|
530
|
-
/>
|
|
531
|
-
<div className="pointer-events-none absolute inset-x-0 bottom-4 z-20 mx-auto flex w-full max-w-4xl justify-end px-4 md:px-6">
|
|
508
|
+
<div className="pointer-events-none absolute inset-x-0 bottom-4 z-20 mx-auto flex w-full max-w-4xl justify-center px-4 md:px-6">
|
|
532
509
|
<Button
|
|
533
510
|
ref={scrollToBottomButtonRef}
|
|
534
511
|
type="button"
|
|
@@ -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
|
>
|