@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.
- package/index.react.ts +3 -2
- package/index.support.ts +1 -1
- package/index.ts +1 -1
- package/package.json +8 -7
- package/src/react/_assistant-activity.ts +2 -6
- package/src/react/_assistant-response-status.tsx +2 -2
- package/src/react/_external-link-dialog.tsx +11 -14
- package/src/react/bubbles.tsx +21 -9
- package/src/react/chat-composer.tsx +13 -18
- package/src/react/chat-feedback.ts +21 -5
- package/src/react/chat-stream.ts +3 -5
- package/src/react/chat-thread-layout.tsx +4 -1
- package/src/react/chat-transcript.tsx +345 -149
- package/src/react/chat-view.tsx +13 -4
- package/src/react/feedback-controls.tsx +32 -2
- package/src/react/markdown.tsx +18 -22
- package/src/react/mastra-chat.tsx +24 -12
- package/src/react/suggestion-pills.tsx +20 -8
- package/src/react/tool-pill.tsx +76 -59
- package/src/react/types.ts +4 -1
- package/src/react/use-composer-viewport-lock.ts +299 -0
- package/src/styles.css +12 -0
- package/src/support/mastra-client.ts +15 -8
- package/src/support/tool-events.ts +35 -7
|
@@ -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 {
|
|
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
|
-
|
|
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
|
|
120
|
-
const element = scrollRef.current;
|
|
121
|
-
if (!element) return;
|
|
234
|
+
const scrollToBottomNow = useCallback(() => {
|
|
122
235
|
pinnedRef.current = true;
|
|
123
236
|
setIsAtBottom(true);
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
<
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
messageFeedback
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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={
|
|
282
|
-
onSelect={
|
|
283
|
-
|
|
500
|
+
questions={visibleSuggestions}
|
|
501
|
+
onSelect={onSelectSuggestion}
|
|
502
|
+
orientation="horizontal"
|
|
503
|
+
className="mt-auto pt-3"
|
|
284
504
|
/>
|
|
285
|
-
|
|
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
|
};
|
package/src/react/chat-view.tsx
CHANGED
|
@@ -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={
|
|
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
|
-
|
|
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
|
-
|
|
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}
|