@dbx-tools/ui-mastra 0.9.179 → 0.9.182
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 -1
- package/index.ts +1 -1
- package/package.json +8 -7
- package/src/react/_assistant-response-status.tsx +2 -2
- package/src/react/bubbles.tsx +2 -2
- package/src/react/chat-composer.tsx +11 -16
- package/src/react/chat-feedback.ts +20 -3
- package/src/react/chat-thread-layout.tsx +16 -2
- package/src/react/chat-transcript.tsx +362 -149
- package/src/react/chat-view.tsx +13 -4
- package/src/react/feedback-controls.tsx +41 -6
- package/src/react/mastra-chat.tsx +3 -3
- package/src/react/suggestion-pills.tsx +20 -8
- package/src/react/thread-tabs.tsx +2 -2
- package/src/react/types.ts +3 -1
- package/src/react/use-composer-viewport-lock.ts +209 -0
- package/src/styles.css +15 -0
- package/src/support/mastra-client.ts +12 -4
|
@@ -17,12 +17,49 @@ 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
|
+
const assistantMessageHasVisibleContent = (
|
|
30
|
+
message: ChatViewProps["messages"][number],
|
|
31
|
+
events: ToolEvent[] | undefined,
|
|
32
|
+
): boolean =>
|
|
33
|
+
message.role === "assistant" &&
|
|
34
|
+
(message.parts.some(
|
|
35
|
+
(part) =>
|
|
36
|
+
((part.type === "text" || part.type === "reasoning") &&
|
|
37
|
+
Boolean((part as { text?: string }).text)) ||
|
|
38
|
+
isToolUIPart(part) ||
|
|
39
|
+
part.type === "data-tool-call-approval",
|
|
40
|
+
) ||
|
|
41
|
+
Boolean(events?.length));
|
|
42
|
+
|
|
43
|
+
/** Find the visible assistant response that owns the current turn footer. */
|
|
44
|
+
export const latestVisibleAssistantIndexInTurn = (
|
|
45
|
+
messages: ChatViewProps["messages"],
|
|
46
|
+
toolEventsByMessage: NonNullable<ChatViewProps["toolEventsByMessage"]>,
|
|
47
|
+
): number => {
|
|
48
|
+
let lastUserIndex = -1;
|
|
49
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
50
|
+
if (messages[index]?.role !== "user") continue;
|
|
51
|
+
lastUserIndex = index;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
for (let index = messages.length - 1; index > lastUserIndex; index -= 1) {
|
|
55
|
+
const message = messages[index];
|
|
56
|
+
if (message && assistantMessageHasVisibleContent(message, toolEventsByMessage[message.id])) {
|
|
57
|
+
return index;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return -1;
|
|
61
|
+
};
|
|
62
|
+
|
|
26
63
|
type ChatTranscriptControllerOptions = {
|
|
27
64
|
messages: ChatViewProps["messages"];
|
|
28
65
|
toolEventsByMessage: NonNullable<ChatViewProps["toolEventsByMessage"]>;
|
|
@@ -38,7 +75,7 @@ export type ChatTranscriptController = {
|
|
|
38
75
|
contentRef: React.RefObject<HTMLDivElement | null>;
|
|
39
76
|
isAtBottom: boolean;
|
|
40
77
|
handleScroll: React.UIEventHandler<HTMLDivElement>;
|
|
41
|
-
|
|
78
|
+
scrollToBottomNow: () => void;
|
|
42
79
|
resumeFollow: () => void;
|
|
43
80
|
};
|
|
44
81
|
|
|
@@ -80,6 +117,78 @@ export const useChatTranscriptController = ({
|
|
|
80
117
|
return () => observer.disconnect();
|
|
81
118
|
}, [messages.length, isLoadingHistory]);
|
|
82
119
|
|
|
120
|
+
useLayoutEffect(() => {
|
|
121
|
+
const element = scrollRef.current;
|
|
122
|
+
const frame = element?.closest<HTMLElement>('[data-slot="aui_thread-frame"]');
|
|
123
|
+
if (!element || !frame || typeof ResizeObserver === "undefined") return;
|
|
124
|
+
|
|
125
|
+
let focusResizeActive = false;
|
|
126
|
+
let focusPinnedToBottom = false;
|
|
127
|
+
let focusScrollTop = 0;
|
|
128
|
+
let focusResizeTimer = 0;
|
|
129
|
+
|
|
130
|
+
const finishFocusResize = () => {
|
|
131
|
+
focusResizeActive = false;
|
|
132
|
+
focusPinnedToBottom = false;
|
|
133
|
+
window.clearTimeout(focusResizeTimer);
|
|
134
|
+
};
|
|
135
|
+
const scheduleFocusResizeFinish = () => {
|
|
136
|
+
window.clearTimeout(focusResizeTimer);
|
|
137
|
+
focusResizeTimer = window.setTimeout(finishFocusResize, FOCUS_RESIZE_SETTLE_MS);
|
|
138
|
+
};
|
|
139
|
+
const restoreFocusPosition = () => {
|
|
140
|
+
if (!focusResizeActive) return;
|
|
141
|
+
programmaticScrollRef.current = true;
|
|
142
|
+
if (focusPinnedToBottom) {
|
|
143
|
+
element.scrollTop = element.scrollHeight;
|
|
144
|
+
setIsAtBottom(true);
|
|
145
|
+
} else {
|
|
146
|
+
element.scrollTop = focusScrollTop;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const beginFocusResize = () => {
|
|
150
|
+
const distanceFromBottom = element.scrollHeight - element.scrollTop - element.clientHeight;
|
|
151
|
+
focusPinnedToBottom = distanceFromBottom <= FOCUS_RESIZE_BOTTOM_THRESHOLD_PX;
|
|
152
|
+
focusScrollTop = element.scrollTop;
|
|
153
|
+
pinnedRef.current = focusPinnedToBottom;
|
|
154
|
+
focusResizeActive = true;
|
|
155
|
+
restoreFocusPosition();
|
|
156
|
+
scheduleFocusResizeFinish();
|
|
157
|
+
};
|
|
158
|
+
const handleFocusStart = (event: Event) => {
|
|
159
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
160
|
+
if (!target?.closest(".aui-composer-input")) return;
|
|
161
|
+
beginFocusResize();
|
|
162
|
+
};
|
|
163
|
+
const handleReaderGesture = () => {
|
|
164
|
+
finishFocusResize();
|
|
165
|
+
pinnedRef.current = false;
|
|
166
|
+
};
|
|
167
|
+
const observer = new ResizeObserver(() => {
|
|
168
|
+
restoreFocusPosition();
|
|
169
|
+
if (focusResizeActive) scheduleFocusResizeFinish();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
frame.addEventListener("touchstart", handleFocusStart, { passive: true, capture: true });
|
|
173
|
+
frame.addEventListener("focusin", handleFocusStart);
|
|
174
|
+
frame.addEventListener("focusout", finishFocusResize);
|
|
175
|
+
element.addEventListener("touchmove", handleReaderGesture, { passive: true });
|
|
176
|
+
element.addEventListener("pointermove", handleReaderGesture, { passive: true });
|
|
177
|
+
element.addEventListener("wheel", handleReaderGesture, { passive: true });
|
|
178
|
+
observer.observe(element);
|
|
179
|
+
|
|
180
|
+
return () => {
|
|
181
|
+
finishFocusResize();
|
|
182
|
+
frame.removeEventListener("touchstart", handleFocusStart, true);
|
|
183
|
+
frame.removeEventListener("focusin", handleFocusStart);
|
|
184
|
+
frame.removeEventListener("focusout", finishFocusResize);
|
|
185
|
+
element.removeEventListener("touchmove", handleReaderGesture);
|
|
186
|
+
element.removeEventListener("pointermove", handleReaderGesture);
|
|
187
|
+
element.removeEventListener("wheel", handleReaderGesture);
|
|
188
|
+
observer.disconnect();
|
|
189
|
+
};
|
|
190
|
+
}, []);
|
|
191
|
+
|
|
83
192
|
useEffect(() => {
|
|
84
193
|
if (prependAnchorRef.current || !pinnedRef.current) return;
|
|
85
194
|
pinToBottomNow();
|
|
@@ -116,14 +225,11 @@ export const useChatTranscriptController = ({
|
|
|
116
225
|
}
|
|
117
226
|
};
|
|
118
227
|
|
|
119
|
-
const
|
|
120
|
-
const element = scrollRef.current;
|
|
121
|
-
if (!element) return;
|
|
228
|
+
const scrollToBottomNow = useCallback(() => {
|
|
122
229
|
pinnedRef.current = true;
|
|
123
230
|
setIsAtBottom(true);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}, []);
|
|
231
|
+
pinToBottomNow();
|
|
232
|
+
}, [pinToBottomNow]);
|
|
127
233
|
|
|
128
234
|
const resumeFollow = useCallback(() => {
|
|
129
235
|
pinnedRef.current = true;
|
|
@@ -139,7 +245,7 @@ export const useChatTranscriptController = ({
|
|
|
139
245
|
contentRef,
|
|
140
246
|
isAtBottom,
|
|
141
247
|
handleScroll,
|
|
142
|
-
|
|
248
|
+
scrollToBottomNow,
|
|
143
249
|
resumeFollow,
|
|
144
250
|
};
|
|
145
251
|
};
|
|
@@ -151,7 +257,7 @@ type ChatTranscriptProps = {
|
|
|
151
257
|
error: ChatViewProps["error"];
|
|
152
258
|
suggestions: NonNullable<ChatViewProps["suggestions"]>;
|
|
153
259
|
followUpQuestions: string[];
|
|
154
|
-
|
|
260
|
+
onSelectSuggestion: (question: string) => void;
|
|
155
261
|
toolEventsByMessage: NonNullable<ChatViewProps["toolEventsByMessage"]>;
|
|
156
262
|
regenerate: ChatViewProps["regenerate"];
|
|
157
263
|
isLoadingMore: NonNullable<ChatViewProps["isLoadingMore"]>;
|
|
@@ -163,6 +269,7 @@ type ChatTranscriptProps = {
|
|
|
163
269
|
feedbackModes: NonNullable<ChatViewProps["feedbackModes"]>;
|
|
164
270
|
onFeedback: ChatViewProps["onFeedback"];
|
|
165
271
|
mlflowExperimentUrl: ChatViewProps["mlflowExperimentUrl"];
|
|
272
|
+
mlflowTracePrefix: ChatViewProps["mlflowTracePrefix"];
|
|
166
273
|
};
|
|
167
274
|
|
|
168
275
|
/** Internal transcript renderer with loading, error, approval, and feedback states. */
|
|
@@ -173,7 +280,7 @@ export const ChatTranscript = ({
|
|
|
173
280
|
error,
|
|
174
281
|
suggestions,
|
|
175
282
|
followUpQuestions,
|
|
176
|
-
|
|
283
|
+
onSelectSuggestion,
|
|
177
284
|
toolEventsByMessage,
|
|
178
285
|
regenerate,
|
|
179
286
|
isLoadingMore,
|
|
@@ -185,155 +292,261 @@ export const ChatTranscript = ({
|
|
|
185
292
|
feedbackModes,
|
|
186
293
|
onFeedback,
|
|
187
294
|
mlflowExperimentUrl,
|
|
295
|
+
mlflowTracePrefix,
|
|
188
296
|
}: ChatTranscriptProps) => {
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
297
|
+
const activeAssistantIndex = latestVisibleAssistantIndexInTurn(messages, toolEventsByMessage);
|
|
298
|
+
const showWaitingIndicator = isActiveChatStatus(status) && activeAssistantIndex === -1;
|
|
299
|
+
const visibleSuggestions = messages.length === 0 ? suggestions : followUpQuestions;
|
|
300
|
+
const scrollToBottomButtonRef = useRef<HTMLButtonElement>(null);
|
|
301
|
+
const scrollToBottomFrameRef = useRef<number | null>(null);
|
|
302
|
+
const scrollIndicatorRef = useRef<HTMLDivElement>(null);
|
|
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]);
|
|
341
|
+
|
|
342
|
+
const activateScrollToBottomFromTouch = useCallback(() => {
|
|
343
|
+
const transcript = controller.scrollRef.current;
|
|
344
|
+
if (!transcript) {
|
|
345
|
+
controller.scrollToBottomNow();
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const previousOverflowY = transcript.style.overflowY;
|
|
350
|
+
transcript.dispatchEvent(new Event(CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT));
|
|
351
|
+
transcript.style.overflowY = "hidden";
|
|
352
|
+
controller.scrollToBottomNow();
|
|
353
|
+
if (scrollToBottomFrameRef.current !== null) {
|
|
354
|
+
window.cancelAnimationFrame(scrollToBottomFrameRef.current);
|
|
355
|
+
}
|
|
356
|
+
scrollToBottomFrameRef.current = window.requestAnimationFrame(() => {
|
|
357
|
+
transcript.style.overflowY = previousOverflowY;
|
|
358
|
+
controller.scrollToBottomNow();
|
|
359
|
+
scrollToBottomFrameRef.current = null;
|
|
360
|
+
});
|
|
361
|
+
}, [controller.scrollRef, controller.scrollToBottomNow]);
|
|
362
|
+
|
|
363
|
+
useLayoutEffect(() => {
|
|
364
|
+
const button = scrollToBottomButtonRef.current;
|
|
365
|
+
if (!button) return;
|
|
366
|
+
|
|
367
|
+
const handlePointerDown = (event: PointerEvent) => {
|
|
368
|
+
event.preventDefault();
|
|
369
|
+
};
|
|
370
|
+
const handleTouchStart = (event: TouchEvent) => {
|
|
371
|
+
event.preventDefault();
|
|
372
|
+
activateScrollToBottomFromTouch();
|
|
373
|
+
};
|
|
374
|
+
const handleTouchEnd = (event: TouchEvent) => {
|
|
375
|
+
event.preventDefault();
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
button.addEventListener("pointerdown", handlePointerDown);
|
|
379
|
+
button.addEventListener("touchstart", handleTouchStart, { passive: false });
|
|
380
|
+
button.addEventListener("touchend", handleTouchEnd, { passive: false });
|
|
381
|
+
return () => {
|
|
382
|
+
if (scrollToBottomFrameRef.current !== null) {
|
|
383
|
+
window.cancelAnimationFrame(scrollToBottomFrameRef.current);
|
|
384
|
+
}
|
|
385
|
+
button.removeEventListener("pointerdown", handlePointerDown);
|
|
386
|
+
button.removeEventListener("touchstart", handleTouchStart);
|
|
387
|
+
button.removeEventListener("touchend", handleTouchEnd);
|
|
388
|
+
};
|
|
389
|
+
}, [activateScrollToBottomFromTouch]);
|
|
202
390
|
|
|
203
391
|
return (
|
|
204
392
|
<div className="relative flex min-w-0 max-w-full flex-1 flex-col overflow-hidden">
|
|
205
393
|
<div
|
|
206
394
|
ref={controller.scrollRef}
|
|
395
|
+
data-slot="aui_thread-viewport"
|
|
207
396
|
onScroll={controller.handleScroll}
|
|
208
|
-
className="min-w-0 max-w-full flex-1
|
|
397
|
+
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
398
|
>
|
|
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
|
-
|
|
399
|
+
<div
|
|
400
|
+
ref={controller.contentRef}
|
|
401
|
+
data-slot="aui_thread-content"
|
|
402
|
+
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"
|
|
403
|
+
>
|
|
404
|
+
{messages.length === 0 && !isLoadingHistory ? (
|
|
405
|
+
<Empty className="h-full flex-1 px-0">
|
|
406
|
+
<EmptyHeader>
|
|
407
|
+
<EmptyMedia variant="icon">
|
|
408
|
+
<MessageSquareIcon className="size-5" />
|
|
409
|
+
</EmptyMedia>
|
|
410
|
+
<EmptyTitle>Start a conversation</EmptyTitle>
|
|
411
|
+
<EmptyDescription>
|
|
412
|
+
{suggestions.length > 0
|
|
413
|
+
? "Ask anything, or pick a suggestion below."
|
|
414
|
+
: "Ask anything to get started."}
|
|
415
|
+
</EmptyDescription>
|
|
416
|
+
</EmptyHeader>
|
|
417
|
+
</Empty>
|
|
418
|
+
) : (
|
|
419
|
+
<>
|
|
420
|
+
{(isLoadingMore || isLoadingHistory) && (
|
|
421
|
+
<div className="flex items-center justify-center gap-2 py-1 text-xs text-muted-foreground">
|
|
422
|
+
<Spinner className="size-3" />
|
|
423
|
+
<span>
|
|
424
|
+
{isLoadingHistory ? "Loading history..." : "Loading older messages..."}
|
|
425
|
+
</span>
|
|
426
|
+
</div>
|
|
427
|
+
)}
|
|
428
|
+
{messages.map((message, index) => {
|
|
429
|
+
const isLast = index === activeAssistantIndex;
|
|
430
|
+
if (message.role === "assistant") {
|
|
431
|
+
const messageFeedback = feedbackByMessage[message.id];
|
|
432
|
+
const feedbackDestination = messageFeedbackDestination(
|
|
433
|
+
message,
|
|
434
|
+
feedbackModes,
|
|
435
|
+
messageFeedback?.traceId,
|
|
436
|
+
);
|
|
437
|
+
const traceUrl = mlflowExperimentUrl
|
|
438
|
+
? mlflowTraceUrl(
|
|
439
|
+
mlflowExperimentUrl,
|
|
440
|
+
messageFeedback?.traceId,
|
|
441
|
+
mlflowTracePrefix,
|
|
442
|
+
)
|
|
443
|
+
: undefined;
|
|
444
|
+
const requestMessage = [...messages.slice(0, index)]
|
|
445
|
+
.reverse()
|
|
446
|
+
.find((candidate) => candidate.role === "user");
|
|
447
|
+
const feedbackRequest = requestMessage ? messageText(requestMessage) : "";
|
|
448
|
+
return (
|
|
449
|
+
<AssistantBubble
|
|
450
|
+
key={message.id}
|
|
451
|
+
message={message}
|
|
452
|
+
isLast={isLast}
|
|
453
|
+
status={status}
|
|
454
|
+
events={toolEventsByMessage[message.id]}
|
|
455
|
+
regenerate={regenerate}
|
|
456
|
+
onResolveToolApproval={onResolveToolApproval}
|
|
457
|
+
externalApprovals={pendingApprovalsByMessage[message.id]}
|
|
458
|
+
{...(onExportMessage
|
|
459
|
+
? { onExport: (format) => onExportMessage(message, format) }
|
|
460
|
+
: {})}
|
|
461
|
+
{...(onFeedback && feedbackDestination
|
|
462
|
+
? {
|
|
463
|
+
onFeedback: (submission) => onFeedback(message, submission),
|
|
464
|
+
feedbackMode: feedbackDestination.mode,
|
|
465
|
+
...(feedbackRequest ? { feedbackRequest } : {}),
|
|
466
|
+
...(messageFeedback?.value
|
|
467
|
+
? { feedbackValue: messageFeedback.value }
|
|
468
|
+
: {}),
|
|
469
|
+
}
|
|
470
|
+
: {})}
|
|
471
|
+
{...(traceUrl ? { mlflowTraceUrl: traceUrl } : {})}
|
|
472
|
+
/>
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
return <UserBubble key={message.id} message={message} />;
|
|
476
|
+
})}
|
|
477
|
+
{showWaitingIndicator && (
|
|
478
|
+
<div
|
|
479
|
+
role="status"
|
|
480
|
+
aria-live="polite"
|
|
481
|
+
className="flex h-7 items-center px-3 text-muted-foreground"
|
|
482
|
+
>
|
|
483
|
+
<Spinner className="size-3" />
|
|
484
|
+
<span className="sr-only">Response in progress</span>
|
|
485
|
+
</div>
|
|
486
|
+
)}
|
|
487
|
+
{status === "error" && (
|
|
488
|
+
<div className="flex flex-col items-start gap-2">
|
|
489
|
+
<Alert variant="destructive">
|
|
490
|
+
<TriangleAlertIcon className="size-4" />
|
|
491
|
+
<AlertTitle>Something went wrong</AlertTitle>
|
|
492
|
+
<AlertDescription>
|
|
493
|
+
{error
|
|
494
|
+
? errorMessage(error)
|
|
495
|
+
: "The assistant ran into an error. Please try again."}
|
|
496
|
+
</AlertDescription>
|
|
497
|
+
</Alert>
|
|
498
|
+
{regenerate && (
|
|
499
|
+
<Button
|
|
500
|
+
type="button"
|
|
501
|
+
variant="outline"
|
|
502
|
+
size="sm"
|
|
503
|
+
onClick={regenerate}
|
|
504
|
+
className="gap-1.5"
|
|
505
|
+
>
|
|
506
|
+
<RefreshCwIcon className="size-3" />
|
|
507
|
+
Retry
|
|
508
|
+
</Button>
|
|
509
|
+
)}
|
|
510
|
+
</div>
|
|
511
|
+
)}
|
|
512
|
+
</>
|
|
513
|
+
)}
|
|
514
|
+
{!isLoadingHistory && visibleSuggestions.length > 0 && (
|
|
280
515
|
<SuggestionPills
|
|
281
|
-
questions={
|
|
282
|
-
onSelect={
|
|
283
|
-
|
|
516
|
+
questions={visibleSuggestions}
|
|
517
|
+
onSelect={onSelectSuggestion}
|
|
518
|
+
orientation="horizontal"
|
|
519
|
+
className="mt-auto pt-3"
|
|
284
520
|
/>
|
|
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>
|
|
521
|
+
)}
|
|
335
522
|
</div>
|
|
336
|
-
|
|
523
|
+
</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">
|
|
532
|
+
<Button
|
|
533
|
+
ref={scrollToBottomButtonRef}
|
|
534
|
+
type="button"
|
|
535
|
+
variant="outline"
|
|
536
|
+
size="icon"
|
|
537
|
+
onClick={controller.scrollToBottomNow}
|
|
538
|
+
aria-label="Jump to latest message"
|
|
539
|
+
aria-hidden={controller.isAtBottom}
|
|
540
|
+
tabIndex={controller.isAtBottom ? -1 : undefined}
|
|
541
|
+
className={
|
|
542
|
+
controller.isAtBottom
|
|
543
|
+
? "pointer-events-none invisible rounded-full shadow"
|
|
544
|
+
: "pointer-events-auto rounded-full shadow"
|
|
545
|
+
}
|
|
546
|
+
>
|
|
547
|
+
<ArrowDownIcon className="size-4" />
|
|
548
|
+
</Button>
|
|
549
|
+
</div>
|
|
337
550
|
</div>
|
|
338
551
|
);
|
|
339
552
|
};
|
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}
|