@dbx-tools/ui-mastra 0.9.181 → 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.
@@ -17,12 +17,52 @@ import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from
17
17
  import { AssistantBubble, UserBubble } from "./bubbles.tsx";
18
18
  import { messageFeedbackDestination, mlflowTraceUrl } from "./chat-feedback.ts";
19
19
  import { SuggestionPills } from "./suggestion-pills.tsx";
20
- import { isRespondingChatStatus, type ChatViewProps } from "./types.ts";
20
+ import { isActiveChatStatus, type ChatViewProps, type ToolEvent } from "./types.ts";
21
+ import { CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT } from "./use-composer-viewport-lock.ts";
21
22
  import { messageText } from "../support/export.ts";
22
23
 
23
24
  const BOTTOM_THRESHOLD_PX = 24;
25
+ const FOCUS_RESIZE_BOTTOM_THRESHOLD_PX = 2;
26
+ const FOCUS_RESIZE_SETTLE_MS = 650;
24
27
  const TOP_LOAD_MORE_THRESHOLD_PX = 120;
25
28
 
29
+ /** Gestures that indicate the user is intentionally navigating transcript history. */
30
+ export const TRANSCRIPT_FOLLOW_CANCEL_EVENTS = ["touchmove", "wheel"] as const;
31
+
32
+ const assistantMessageHasVisibleContent = (
33
+ message: ChatViewProps["messages"][number],
34
+ events: ToolEvent[] | undefined,
35
+ ): boolean =>
36
+ message.role === "assistant" &&
37
+ (message.parts.some(
38
+ (part) =>
39
+ ((part.type === "text" || part.type === "reasoning") &&
40
+ Boolean((part as { text?: string }).text)) ||
41
+ isToolUIPart(part) ||
42
+ part.type === "data-tool-call-approval",
43
+ ) ||
44
+ Boolean(events?.length));
45
+
46
+ /** Find the visible assistant response that owns the current turn footer. */
47
+ export const latestVisibleAssistantIndexInTurn = (
48
+ messages: ChatViewProps["messages"],
49
+ toolEventsByMessage: NonNullable<ChatViewProps["toolEventsByMessage"]>,
50
+ ): number => {
51
+ let lastUserIndex = -1;
52
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
53
+ if (messages[index]?.role !== "user") continue;
54
+ lastUserIndex = index;
55
+ break;
56
+ }
57
+ for (let index = messages.length - 1; index > lastUserIndex; index -= 1) {
58
+ const message = messages[index];
59
+ if (message && assistantMessageHasVisibleContent(message, toolEventsByMessage[message.id])) {
60
+ return index;
61
+ }
62
+ }
63
+ return -1;
64
+ };
65
+
26
66
  type ChatTranscriptControllerOptions = {
27
67
  messages: ChatViewProps["messages"];
28
68
  toolEventsByMessage: NonNullable<ChatViewProps["toolEventsByMessage"]>;
@@ -38,7 +78,7 @@ export type ChatTranscriptController = {
38
78
  contentRef: React.RefObject<HTMLDivElement | null>;
39
79
  isAtBottom: boolean;
40
80
  handleScroll: React.UIEventHandler<HTMLDivElement>;
41
- scrollToBottom: () => void;
81
+ scrollToBottomNow: () => void;
42
82
  resumeFollow: () => void;
43
83
  };
44
84
 
@@ -80,6 +120,81 @@ export const useChatTranscriptController = ({
80
120
  return () => observer.disconnect();
81
121
  }, [messages.length, isLoadingHistory]);
82
122
 
123
+ useLayoutEffect(() => {
124
+ const element = scrollRef.current;
125
+ const frame = element?.closest<HTMLElement>('[data-slot="aui_thread-frame"]');
126
+ if (!element || !frame || typeof ResizeObserver === "undefined") return;
127
+
128
+ let focusResizeActive = false;
129
+ let focusPinnedToBottom = false;
130
+ let focusScrollTop = 0;
131
+ let focusResizeTimer = 0;
132
+
133
+ const finishFocusResize = () => {
134
+ focusResizeActive = false;
135
+ focusPinnedToBottom = false;
136
+ window.clearTimeout(focusResizeTimer);
137
+ };
138
+ const scheduleFocusResizeFinish = () => {
139
+ window.clearTimeout(focusResizeTimer);
140
+ focusResizeTimer = window.setTimeout(finishFocusResize, FOCUS_RESIZE_SETTLE_MS);
141
+ };
142
+ const restoreFocusPosition = () => {
143
+ if (!focusResizeActive) return;
144
+ programmaticScrollRef.current = true;
145
+ if (focusPinnedToBottom) {
146
+ element.scrollTop = element.scrollHeight;
147
+ setIsAtBottom(true);
148
+ } else {
149
+ element.scrollTop = focusScrollTop;
150
+ }
151
+ };
152
+ const beginFocusResize = () => {
153
+ const distanceFromBottom = element.scrollHeight - element.scrollTop - element.clientHeight;
154
+ focusPinnedToBottom = distanceFromBottom <= FOCUS_RESIZE_BOTTOM_THRESHOLD_PX;
155
+ focusScrollTop = element.scrollTop;
156
+ pinnedRef.current = focusPinnedToBottom;
157
+ focusResizeActive = true;
158
+ restoreFocusPosition();
159
+ scheduleFocusResizeFinish();
160
+ };
161
+ const handleFocusStart = (event: Event) => {
162
+ const target = event.target instanceof Element ? event.target : null;
163
+ if (!target?.closest(".aui-composer-input")) return;
164
+ beginFocusResize();
165
+ };
166
+ const handleReaderGesture = () => {
167
+ finishFocusResize();
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;
172
+ };
173
+ const observer = new ResizeObserver(() => {
174
+ restoreFocusPosition();
175
+ if (focusResizeActive) scheduleFocusResizeFinish();
176
+ });
177
+
178
+ frame.addEventListener("touchstart", handleFocusStart, { passive: true, capture: true });
179
+ frame.addEventListener("focusin", handleFocusStart);
180
+ frame.addEventListener("focusout", finishFocusResize);
181
+ for (const eventName of TRANSCRIPT_FOLLOW_CANCEL_EVENTS) {
182
+ element.addEventListener(eventName, handleReaderGesture, { passive: true });
183
+ }
184
+ observer.observe(element);
185
+
186
+ return () => {
187
+ finishFocusResize();
188
+ frame.removeEventListener("touchstart", handleFocusStart, true);
189
+ frame.removeEventListener("focusin", handleFocusStart);
190
+ frame.removeEventListener("focusout", finishFocusResize);
191
+ for (const eventName of TRANSCRIPT_FOLLOW_CANCEL_EVENTS) {
192
+ element.removeEventListener(eventName, handleReaderGesture);
193
+ }
194
+ observer.disconnect();
195
+ };
196
+ }, []);
197
+
83
198
  useEffect(() => {
84
199
  if (prependAnchorRef.current || !pinnedRef.current) return;
85
200
  pinToBottomNow();
@@ -116,14 +231,11 @@ export const useChatTranscriptController = ({
116
231
  }
117
232
  };
118
233
 
119
- const scrollToBottom = useCallback(() => {
120
- const element = scrollRef.current;
121
- if (!element) return;
234
+ const scrollToBottomNow = useCallback(() => {
122
235
  pinnedRef.current = true;
123
236
  setIsAtBottom(true);
124
- programmaticScrollRef.current = true;
125
- element.scrollTo({ top: element.scrollHeight, behavior: "smooth" });
126
- }, []);
237
+ pinToBottomNow();
238
+ }, [pinToBottomNow]);
127
239
 
128
240
  const resumeFollow = useCallback(() => {
129
241
  pinnedRef.current = true;
@@ -139,7 +251,7 @@ export const useChatTranscriptController = ({
139
251
  contentRef,
140
252
  isAtBottom,
141
253
  handleScroll,
142
- scrollToBottom,
254
+ scrollToBottomNow,
143
255
  resumeFollow,
144
256
  };
145
257
  };
@@ -151,7 +263,7 @@ type ChatTranscriptProps = {
151
263
  error: ChatViewProps["error"];
152
264
  suggestions: NonNullable<ChatViewProps["suggestions"]>;
153
265
  followUpQuestions: string[];
154
- onSelectFollowUp: (question: string) => void;
266
+ onSelectSuggestion: (question: string) => void;
155
267
  toolEventsByMessage: NonNullable<ChatViewProps["toolEventsByMessage"]>;
156
268
  regenerate: ChatViewProps["regenerate"];
157
269
  isLoadingMore: NonNullable<ChatViewProps["isLoadingMore"]>;
@@ -163,6 +275,7 @@ type ChatTranscriptProps = {
163
275
  feedbackModes: NonNullable<ChatViewProps["feedbackModes"]>;
164
276
  onFeedback: ChatViewProps["onFeedback"];
165
277
  mlflowExperimentUrl: ChatViewProps["mlflowExperimentUrl"];
278
+ mlflowTracePrefix: ChatViewProps["mlflowTracePrefix"];
166
279
  };
167
280
 
168
281
  /** Internal transcript renderer with loading, error, approval, and feedback states. */
@@ -173,7 +286,7 @@ export const ChatTranscript = ({
173
286
  error,
174
287
  suggestions,
175
288
  followUpQuestions,
176
- onSelectFollowUp,
289
+ onSelectSuggestion,
177
290
  toolEventsByMessage,
178
291
  regenerate,
179
292
  isLoadingMore,
@@ -185,155 +298,238 @@ export const ChatTranscript = ({
185
298
  feedbackModes,
186
299
  onFeedback,
187
300
  mlflowExperimentUrl,
301
+ mlflowTracePrefix,
188
302
  }: ChatTranscriptProps) => {
189
- const isRunning = isRespondingChatStatus(status);
190
- const lastMessage = messages.at(-1);
191
- const lastEvents = lastMessage ? toolEventsByMessage[lastMessage.id] : undefined;
192
- const lastAssistantParts = lastMessage?.role === "assistant" ? lastMessage.parts : [];
193
- const lastAssistantHasContent =
194
- lastAssistantParts.some(
195
- (part) =>
196
- ((part.type === "text" || part.type === "reasoning") &&
197
- Boolean((part as { text?: string }).text)) ||
198
- isToolUIPart(part) ||
199
- part.type === "data-tool-call-approval",
200
- ) || (lastEvents?.length ?? 0) > 0;
201
- const showWaitingIndicator = status === "finishing" || (isRunning && !lastAssistantHasContent);
303
+ const activeAssistantIndex = latestVisibleAssistantIndexInTurn(messages, toolEventsByMessage);
304
+ const showWaitingIndicator = isActiveChatStatus(status) && activeAssistantIndex === -1;
305
+ const visibleSuggestions = messages.length === 0 ? suggestions : followUpQuestions;
306
+ const scrollToBottomButtonRef = useRef<HTMLButtonElement>(null);
307
+ const scrollToBottomFrameRef = useRef<number | null>(null);
308
+ const scrollToBottomOverflowRef = useRef<string | null>(null);
309
+
310
+ const activateScrollToBottomFromTouch = useCallback(() => {
311
+ const transcript = controller.scrollRef.current;
312
+ if (!transcript) {
313
+ controller.scrollToBottomNow();
314
+ return;
315
+ }
316
+
317
+ if (scrollToBottomOverflowRef.current === null) {
318
+ scrollToBottomOverflowRef.current = transcript.style.overflowY;
319
+ }
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.
324
+ transcript.style.overflowY = "hidden";
325
+ controller.scrollToBottomNow();
326
+ if (scrollToBottomFrameRef.current !== null) {
327
+ window.cancelAnimationFrame(scrollToBottomFrameRef.current);
328
+ }
329
+ scrollToBottomFrameRef.current = window.requestAnimationFrame(() => {
330
+ transcript.style.overflowY = scrollToBottomOverflowRef.current ?? "";
331
+ scrollToBottomOverflowRef.current = null;
332
+ controller.scrollToBottomNow();
333
+ scrollToBottomFrameRef.current = null;
334
+ });
335
+ }, [controller.scrollRef, controller.scrollToBottomNow]);
336
+
337
+ useLayoutEffect(() => {
338
+ const button = scrollToBottomButtonRef.current;
339
+ if (!button) return;
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.
344
+ const handlePointerDown = (event: PointerEvent) => {
345
+ event.preventDefault();
346
+ };
347
+ const handleTouchStart = (event: TouchEvent) => {
348
+ event.preventDefault();
349
+ activateScrollToBottomFromTouch();
350
+ };
351
+ const handleTouchEnd = (event: TouchEvent) => {
352
+ event.preventDefault();
353
+ };
354
+
355
+ button.addEventListener("pointerdown", handlePointerDown);
356
+ button.addEventListener("touchstart", handleTouchStart, { passive: false });
357
+ button.addEventListener("touchend", handleTouchEnd, { passive: false });
358
+ return () => {
359
+ if (scrollToBottomFrameRef.current !== null) {
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;
367
+ }
368
+ button.removeEventListener("pointerdown", handlePointerDown);
369
+ button.removeEventListener("touchstart", handleTouchStart);
370
+ button.removeEventListener("touchend", handleTouchEnd);
371
+ };
372
+ }, [activateScrollToBottomFromTouch]);
202
373
 
203
374
  return (
204
375
  <div className="relative flex min-w-0 max-w-full flex-1 flex-col overflow-hidden">
205
376
  <div
206
377
  ref={controller.scrollRef}
378
+ data-slot="aui_thread-viewport"
207
379
  onScroll={controller.handleScroll}
208
- className="min-w-0 max-w-full flex-1 overflow-y-auto overflow-x-clip overscroll-contain [overflow-anchor:none] [scrollbar-gutter:stable]"
380
+ className="min-h-0 min-w-0 max-w-full flex-1 touch-pan-y overflow-x-hidden overflow-y-scroll overscroll-contain [overflow-anchor:none] [scrollbar-gutter:stable]"
209
381
  >
210
- {messages.length === 0 && !isLoadingHistory ? (
211
- <Empty className="mx-auto h-full w-full max-w-4xl px-4 md:px-6">
212
- <EmptyHeader>
213
- <EmptyMedia variant="icon">
214
- <MessageSquareIcon className="size-5" />
215
- </EmptyMedia>
216
- <EmptyTitle>Start a conversation</EmptyTitle>
217
- <EmptyDescription>
218
- {suggestions.length > 0
219
- ? "Ask anything, or pick a suggestion below."
220
- : "Ask anything to get started."}
221
- </EmptyDescription>
222
- </EmptyHeader>
223
- </Empty>
224
- ) : (
225
- <div
226
- ref={controller.contentRef}
227
- className="mx-auto flex min-w-0 w-full max-w-4xl flex-col gap-3 overflow-x-clip px-4 py-3 md:px-6"
228
- >
229
- {(isLoadingMore || isLoadingHistory) && (
230
- <div className="flex items-center justify-center gap-2 py-1 text-xs text-muted-foreground">
231
- <Spinner className="size-3" />
232
- <span>{isLoadingHistory ? "Loading history..." : "Loading older messages..."}</span>
233
- </div>
234
- )}
235
- {messages.map((message, index) => {
236
- const isLast = index === messages.length - 1;
237
- if (message.role === "assistant") {
238
- const messageFeedback = feedbackByMessage[message.id];
239
- const feedbackDestination = messageFeedbackDestination(
240
- message,
241
- feedbackModes,
242
- messageFeedback?.traceId,
243
- );
244
- const traceUrl = mlflowExperimentUrl
245
- ? mlflowTraceUrl(mlflowExperimentUrl, messageFeedback?.traceId)
246
- : undefined;
247
- const requestMessage = [...messages.slice(0, index)]
248
- .reverse()
249
- .find((candidate) => candidate.role === "user");
250
- const feedbackRequest = requestMessage ? messageText(requestMessage) : "";
251
- return (
252
- <AssistantBubble
253
- key={message.id}
254
- message={message}
255
- isLast={isLast}
256
- status={status}
257
- events={toolEventsByMessage[message.id]}
258
- regenerate={regenerate}
259
- onResolveToolApproval={onResolveToolApproval}
260
- externalApprovals={pendingApprovalsByMessage[message.id]}
261
- {...(onExportMessage
262
- ? { onExport: (format) => onExportMessage(message, format) }
263
- : {})}
264
- {...(onFeedback && feedbackDestination
265
- ? {
266
- onFeedback: (submission) => onFeedback(message, submission),
267
- feedbackMode: feedbackDestination.mode,
268
- ...(feedbackRequest ? { feedbackRequest } : {}),
269
- ...(messageFeedback?.value
270
- ? { feedbackValue: messageFeedback.value }
271
- : {}),
272
- }
273
- : {})}
274
- {...(traceUrl ? { mlflowTraceUrl: traceUrl } : {})}
275
- />
276
- );
277
- }
278
- return <UserBubble key={message.id} message={message} />;
279
- })}
382
+ <div
383
+ ref={controller.contentRef}
384
+ data-slot="aui_thread-content"
385
+ className="mx-auto flex min-h-full min-w-0 w-full max-w-4xl flex-col gap-3 overflow-x-clip px-4 py-3 md:px-6"
386
+ >
387
+ {messages.length === 0 && !isLoadingHistory ? (
388
+ <Empty className="h-full flex-1 px-0">
389
+ <EmptyHeader>
390
+ <EmptyMedia variant="icon">
391
+ <MessageSquareIcon className="size-5" />
392
+ </EmptyMedia>
393
+ <EmptyTitle>Start a conversation</EmptyTitle>
394
+ <EmptyDescription>
395
+ {suggestions.length > 0
396
+ ? "Ask anything, or pick a suggestion below."
397
+ : "Ask anything to get started."}
398
+ </EmptyDescription>
399
+ </EmptyHeader>
400
+ </Empty>
401
+ ) : (
402
+ <>
403
+ {(isLoadingMore || isLoadingHistory) && (
404
+ <div className="flex items-center justify-center gap-2 py-1 text-xs text-muted-foreground">
405
+ <Spinner className="size-3" />
406
+ <span>
407
+ {isLoadingHistory ? "Loading history..." : "Loading older messages..."}
408
+ </span>
409
+ </div>
410
+ )}
411
+ {messages.map((message, index) => {
412
+ const isLast = index === activeAssistantIndex;
413
+ if (message.role === "assistant") {
414
+ const messageFeedback = feedbackByMessage[message.id];
415
+ const feedbackDestination = messageFeedbackDestination(
416
+ message,
417
+ feedbackModes,
418
+ messageFeedback?.traceId,
419
+ );
420
+ const traceUrl = mlflowExperimentUrl
421
+ ? mlflowTraceUrl(
422
+ mlflowExperimentUrl,
423
+ messageFeedback?.traceId,
424
+ mlflowTracePrefix,
425
+ )
426
+ : undefined;
427
+ const requestMessage = [...messages.slice(0, index)]
428
+ .reverse()
429
+ .find((candidate) => candidate.role === "user");
430
+ const feedbackRequest = requestMessage ? messageText(requestMessage) : "";
431
+ return (
432
+ <AssistantBubble
433
+ key={message.id}
434
+ message={message}
435
+ isLast={isLast}
436
+ status={status}
437
+ continuation={messages[index - 1]?.role === "assistant"}
438
+ events={toolEventsByMessage[message.id]}
439
+ regenerate={regenerate}
440
+ onResolveToolApproval={onResolveToolApproval}
441
+ externalApprovals={pendingApprovalsByMessage[message.id]}
442
+ {...(onExportMessage
443
+ ? { onExport: (format) => onExportMessage(message, format) }
444
+ : {})}
445
+ {...(onFeedback && feedbackDestination
446
+ ? {
447
+ onFeedback: (submission) => onFeedback(message, submission),
448
+ feedbackMode: feedbackDestination.mode,
449
+ ...(feedbackRequest ? { feedbackRequest } : {}),
450
+ ...(messageFeedback?.value
451
+ ? { feedbackValue: messageFeedback.value }
452
+ : {}),
453
+ }
454
+ : {})}
455
+ {...(traceUrl ? { mlflowTraceUrl: traceUrl } : {})}
456
+ />
457
+ );
458
+ }
459
+ return <UserBubble key={message.id} message={message} />;
460
+ })}
461
+ {showWaitingIndicator && (
462
+ <div
463
+ role="status"
464
+ aria-live="polite"
465
+ className="flex h-7 items-center px-3 text-muted-foreground"
466
+ >
467
+ <Spinner className="size-3" />
468
+ <span className="sr-only">Response in progress</span>
469
+ </div>
470
+ )}
471
+ {status === "error" && (
472
+ <div className="flex flex-col items-start gap-2">
473
+ <Alert variant="destructive">
474
+ <TriangleAlertIcon className="size-4" />
475
+ <AlertTitle>Something went wrong</AlertTitle>
476
+ <AlertDescription>
477
+ {error
478
+ ? errorMessage(error)
479
+ : "The assistant ran into an error. Please try again."}
480
+ </AlertDescription>
481
+ </Alert>
482
+ {regenerate && (
483
+ <Button
484
+ type="button"
485
+ variant="outline"
486
+ size="sm"
487
+ onClick={regenerate}
488
+ className="gap-1.5"
489
+ >
490
+ <RefreshCwIcon className="size-3" />
491
+ Retry
492
+ </Button>
493
+ )}
494
+ </div>
495
+ )}
496
+ </>
497
+ )}
498
+ {!isLoadingHistory && visibleSuggestions.length > 0 && (
280
499
  <SuggestionPills
281
- questions={followUpQuestions}
282
- onSelect={onSelectFollowUp}
283
- className="pb-2 pt-1"
500
+ questions={visibleSuggestions}
501
+ onSelect={onSelectSuggestion}
502
+ orientation="horizontal"
503
+ className="mt-auto pt-3"
284
504
  />
285
- {showWaitingIndicator && (
286
- <div
287
- role="status"
288
- aria-live="polite"
289
- className="flex h-7 items-center px-3 text-muted-foreground"
290
- >
291
- <Spinner className="size-3" />
292
- <span className="sr-only">Response in progress</span>
293
- </div>
294
- )}
295
- {status === "error" && (
296
- <div className="flex flex-col items-start gap-2">
297
- <Alert variant="destructive">
298
- <TriangleAlertIcon className="size-4" />
299
- <AlertTitle>Something went wrong</AlertTitle>
300
- <AlertDescription>
301
- {error
302
- ? errorMessage(error)
303
- : "The assistant ran into an error. Please try again."}
304
- </AlertDescription>
305
- </Alert>
306
- {regenerate && (
307
- <Button
308
- type="button"
309
- variant="outline"
310
- size="sm"
311
- onClick={regenerate}
312
- className="gap-1.5"
313
- >
314
- <RefreshCwIcon className="size-3" />
315
- Retry
316
- </Button>
317
- )}
318
- </div>
319
- )}
320
- </div>
321
- )}
322
- </div>
323
- {!controller.isAtBottom && (
324
- <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">
325
- <Button
326
- type="button"
327
- variant="outline"
328
- size="icon"
329
- onClick={controller.scrollToBottom}
330
- aria-label="Jump to latest message"
331
- className="pointer-events-auto rounded-full shadow"
332
- >
333
- <ArrowDownIcon className="size-4" />
334
- </Button>
505
+ )}
335
506
  </div>
336
- )}
507
+ </div>
508
+ <div
509
+ data-slot="aui_thread-scroll-indicator"
510
+ className="pointer-events-none absolute right-0.5 top-0 z-20 w-0.5 rounded-full bg-foreground/50"
511
+ hidden
512
+ aria-hidden="true"
513
+ />
514
+ <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">
515
+ <Button
516
+ ref={scrollToBottomButtonRef}
517
+ type="button"
518
+ variant="outline"
519
+ size="icon"
520
+ onClick={controller.scrollToBottomNow}
521
+ aria-label="Jump to latest message"
522
+ aria-hidden={controller.isAtBottom}
523
+ tabIndex={controller.isAtBottom ? -1 : undefined}
524
+ className={
525
+ controller.isAtBottom
526
+ ? "pointer-events-none invisible rounded-full shadow"
527
+ : "pointer-events-auto rounded-full shadow"
528
+ }
529
+ >
530
+ <ArrowDownIcon className="size-4" />
531
+ </Button>
532
+ </div>
337
533
  </div>
338
534
  );
339
535
  };
@@ -1,3 +1,4 @@
1
+ import { useState } from "react";
1
2
  import { ChatComposer } from "./chat-composer.tsx";
2
3
  import { ChatThreadLayout } from "./chat-thread-layout.tsx";
3
4
  import { ChatTranscript, useChatTranscriptController } from "./chat-transcript.tsx";
@@ -70,7 +71,9 @@ export const ChatView = ({
70
71
  feedbackModes = [],
71
72
  onFeedback,
72
73
  mlflowExperimentUrl,
74
+ mlflowTracePrefix,
73
75
  }: ChatViewProps) => {
76
+ const [composerFocusRequest, setComposerFocusRequest] = useState(0);
74
77
  const transcript = useChatTranscriptController({
75
78
  messages,
76
79
  toolEventsByMessage,
@@ -91,6 +94,12 @@ export const ChatView = ({
91
94
  followUpSuggestionLimit,
92
95
  )
93
96
  : [];
97
+ const startNewThread = onNewThread
98
+ ? () => {
99
+ onNewThread();
100
+ setComposerFocusRequest((request) => request + 1);
101
+ }
102
+ : undefined;
94
103
 
95
104
  return (
96
105
  <ChatThreadLayout
@@ -107,7 +116,7 @@ export const ChatView = ({
107
116
  streamingThreadIds={streamingThreadIds}
108
117
  isLoadingThreads={isLoadingThreads}
109
118
  onSelectThread={onSelectThread}
110
- onNewThread={onNewThread}
119
+ onNewThread={startNewThread}
111
120
  onDeleteThread={onDeleteThread}
112
121
  onRenameThread={onRenameThread}
113
122
  onCancelThread={onCancelThread}
@@ -121,7 +130,7 @@ export const ChatView = ({
121
130
  error={error}
122
131
  suggestions={suggestions}
123
132
  followUpQuestions={followUpQuestions}
124
- onSelectFollowUp={(text) => sendMessage({ text })}
133
+ onSelectSuggestion={(text) => sendMessage({ text })}
125
134
  toolEventsByMessage={toolEventsByMessage}
126
135
  regenerate={regenerate}
127
136
  isLoadingMore={isLoadingMore}
@@ -133,9 +142,10 @@ export const ChatView = ({
133
142
  feedbackModes={feedbackModes}
134
143
  onFeedback={onFeedback}
135
144
  mlflowExperimentUrl={mlflowExperimentUrl}
145
+ mlflowTracePrefix={mlflowTracePrefix}
136
146
  />
137
147
  <ChatComposer
138
- isEmpty={messages.length === 0}
148
+ focusRequest={composerFocusRequest}
139
149
  status={status}
140
150
  sendMessage={sendMessage}
141
151
  queuedSteers={queuedSteers}
@@ -143,7 +153,6 @@ export const ChatView = ({
143
153
  onRemoveSteer={onRemoveSteer}
144
154
  onReorderSteers={onReorderSteers}
145
155
  onStop={onStop}
146
- suggestions={suggestions}
147
156
  models={models}
148
157
  model={model}
149
158
  onModelChange={onModelChange}