@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.
@@ -13,7 +13,7 @@ import {
13
13
  cn,
14
14
  } from "@databricks/appkit-ui/react";
15
15
  import { MessageSquareTextIcon, ThumbsDownIcon, ThumbsUpIcon } from "lucide-react";
16
- import { useState } from "react";
16
+ import { useRef, useState } from "react";
17
17
  import type { FeedbackSubmission, FeedbackValue } from "./types.ts";
18
18
 
19
19
  /** Render per-message rating controls and a dedicated written-feedback modal. */
@@ -34,6 +34,8 @@ export const FeedbackControls = ({
34
34
  const [open, setOpen] = useState(false);
35
35
  const [comment, setComment] = useState("");
36
36
  const [sending, setSending] = useState(false);
37
+ const commentTriggerRef = useRef<HTMLButtonElement>(null);
38
+ const restoreTriggerFocusRef = useRef(false);
37
39
  const genieRequest = request?.trim();
38
40
  const canComment = mode === "mlflow" || Boolean(value && genieRequest);
39
41
 
@@ -97,27 +99,60 @@ export const FeedbackControls = ({
97
99
  </TooltipTrigger>
98
100
  <TooltipContent>Bad response</TooltipContent>
99
101
  </Tooltip>
100
- <Dialog open={open} onOpenChange={setOpen}>
102
+ <Dialog
103
+ open={open}
104
+ onOpenChange={setOpen}
105
+ >
101
106
  <Tooltip>
102
107
  <TooltipTrigger asChild>
103
108
  <DialogTrigger asChild disabled={!canComment}>
104
109
  <Button
110
+ ref={commentTriggerRef}
105
111
  type="button"
106
112
  size="icon"
107
113
  variant="ghost"
108
114
  className="size-7"
109
115
  aria-label={canComment ? "Leave written feedback" : "Rate the response first"}
110
116
  disabled={!canComment}
117
+ onPointerDown={() => {
118
+ restoreTriggerFocusRef.current = false;
119
+ }}
120
+ onKeyDown={(event) => {
121
+ if (event.key === "Enter" || event.key === " ") {
122
+ restoreTriggerFocusRef.current = true;
123
+ }
124
+ }}
111
125
  >
112
126
  <MessageSquareTextIcon className="size-3" />
113
127
  </Button>
114
128
  </DialogTrigger>
115
129
  </TooltipTrigger>
116
- <TooltipContent>
117
- {canComment ? "Leave written feedback" : "Rate the response first"}
118
- </TooltipContent>
130
+ {!open && (
131
+ <TooltipContent>
132
+ {canComment ? "Leave written feedback" : "Rate the response first"}
133
+ </TooltipContent>
134
+ )}
119
135
  </Tooltip>
120
- <DialogContent className="sm:max-w-md">
136
+ <DialogContent
137
+ className="max-h-[calc(100dvh-1rem)] w-[calc(100vw-1rem)] overflow-y-auto sm:max-w-md"
138
+ onPointerDownCapture={() => {
139
+ restoreTriggerFocusRef.current = false;
140
+ }}
141
+ onPointerDownOutside={() => {
142
+ restoreTriggerFocusRef.current = false;
143
+ }}
144
+ onKeyDownCapture={(event) => {
145
+ if (event.key === "Escape") restoreTriggerFocusRef.current = true;
146
+ }}
147
+ onCloseAutoFocus={(event) => {
148
+ event.preventDefault();
149
+ requestAnimationFrame(() => {
150
+ if (restoreTriggerFocusRef.current) commentTriggerRef.current?.focus();
151
+ else commentTriggerRef.current?.blur();
152
+ restoreTriggerFocusRef.current = false;
153
+ });
154
+ }}
155
+ >
121
156
  <DialogHeader>
122
157
  <DialogTitle>Share feedback</DialogTitle>
123
158
  </DialogHeader>
@@ -326,9 +326,8 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
326
326
  const enableFeedback = options.enableFeedback !== false;
327
327
  const feedbackModes = enableFeedback ? mastraClient.feedbackModes : [];
328
328
  const feedbackAvailable = feedbackModes.length > 0;
329
- const { url: mlflowExperimentUrl } = useMastraMlflowExperiment(
330
- feedbackModes.includes("mlflow"),
331
- );
329
+ const { url: mlflowExperimentUrl, tracePrefix: mlflowTracePrefix } =
330
+ useMastraMlflowExperiment(feedbackModes.includes("mlflow"));
332
331
  const [resourceScope, setResourceScope] = useState<string | null>(null);
333
332
  useEffect(() => {
334
333
  let cancelled = false;
@@ -1555,6 +1554,7 @@ export const useMastraChat = <TValues extends Record<string, unknown> = Record<s
1555
1554
  feedbackByMessage: activeSession.feedbackByMessage,
1556
1555
  onFeedback: submitFeedback,
1557
1556
  ...(mlflowExperimentUrl ? { mlflowExperimentUrl } : {}),
1557
+ ...(mlflowTracePrefix ? { mlflowTracePrefix } : {}),
1558
1558
  }
1559
1559
  : {}),
1560
1560
  };
@@ -17,32 +17,44 @@ export interface SuggestionPillsProps {
17
17
  * arrived yet.
18
18
  */
19
19
  disabled?: boolean;
20
+ /** Arrange suggestions in a horizontal row or vertical list. */
21
+ orientation?: "horizontal" | "vertical";
20
22
  /** Extra classes for the wrapping flex row (layout / spacing). */
21
23
  className?: string;
22
24
  }
23
25
 
24
- /**
25
- * Render a flex-wrapped row of suggestion pills. Pills grow vertically
26
- * for long questions (`h-auto` + `whitespace-normal`) and keep a
27
- * capsule shape that scales cleanly when text wraps to multiple lines.
28
- * Disabled when no `onSelect` is provided, or when `disabled` is set.
29
- */
26
+ /** Render suggestion actions in the requested layout. */
30
27
  export const SuggestionPills = ({
31
28
  questions,
32
29
  onSelect,
33
30
  disabled = false,
31
+ orientation = "horizontal",
34
32
  className,
35
33
  }: SuggestionPillsProps) => {
36
34
  if (questions.length === 0) return null;
37
35
  return (
38
- <div className={cn("flex flex-wrap gap-1.5", className)}>
36
+ <div
37
+ aria-label="Suggested questions"
38
+ className={cn(
39
+ "flex gap-1.5",
40
+ orientation === "horizontal"
41
+ ? "touch-pan-x flex-nowrap overflow-x-auto overscroll-x-contain [scrollbar-width:none] md:flex-wrap md:overflow-x-visible [&::-webkit-scrollbar]:hidden"
42
+ : "flex-col",
43
+ className,
44
+ )}
45
+ >
39
46
  {questions.map((q) => (
40
47
  <Button
41
48
  key={q}
42
49
  type="button"
43
50
  size="sm"
44
51
  variant="outline"
45
- className="h-auto max-w-full whitespace-normal rounded-2xl px-3 py-1.5 text-left text-xs font-normal leading-snug"
52
+ className={cn(
53
+ "h-auto shrink-0 whitespace-normal rounded-2xl px-3 py-1.5 text-left text-xs font-normal leading-snug",
54
+ orientation === "horizontal"
55
+ ? "max-w-[min(20rem,85vw)] md:max-w-full"
56
+ : "w-full max-w-full justify-start",
57
+ )}
46
58
  onClick={() => onSelect?.(q)}
47
59
  disabled={disabled || !onSelect}
48
60
  >
@@ -109,7 +109,7 @@ export const ThreadActions = ({
109
109
  <PopoverContent
110
110
  align="end"
111
111
  aria-label="Conversation history"
112
- className="w-72 p-0"
112
+ className="max-h-[calc(100dvh-1rem)] w-72 max-w-[calc(100vw-1rem)] overflow-hidden p-0"
113
113
  onOpenAutoFocus={(event) => event.preventDefault()}
114
114
  onCloseAutoFocus={(event) => event.preventDefault()}
115
115
  onFocusOutside={(event) => event.preventDefault()}
@@ -137,7 +137,7 @@ export const ThreadActions = ({
137
137
  },
138
138
  }
139
139
  : {})}
140
- className="h-96 w-full border-none"
140
+ className="h-96 max-h-[calc(100dvh-1rem)] w-full border-none"
141
141
  />
142
142
  </PopoverContent>
143
143
  </Popover>
@@ -390,9 +390,11 @@ export type ChatViewProps = {
390
390
  onFeedback?: (message: UIMessage, submission: FeedbackSubmission) => void | Promise<void>;
391
391
  /**
392
392
  * Configured MLflow experiment URL for viewers with effective
393
- * `CAN_MANAGE`. When present, assistant action rows show a debug link.
393
+ * `CAN_READ`. When present, assistant action rows show a debug link.
394
394
  */
395
395
  mlflowExperimentUrl?: string;
396
+ /** Unity Catalog trace prefix used to open the exact trace in MLflow. */
397
+ mlflowTracePrefix?: string;
396
398
  };
397
399
 
398
400
  /** Payload {@link ChatViewProps.onResolveToolApproval} receives. */
@@ -0,0 +1,209 @@
1
+ import { ScrollBooster } from "scrollbooster";
2
+ import { useLayoutEffect, type RefObject } from "react";
3
+
4
+ const SCROLL_BOUNDARY_EPSILON = 1;
5
+ const KEYBOARD_TRANSITION_THRESHOLD = 80;
6
+ const FOCUS_GUARD_FALLBACK_MS = 600;
7
+ const FOCUS_GUARD_SETTLE_MS = 120;
8
+
9
+ export const CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT = "dbx-tools:cancel-transcript-kinetic-scroll";
10
+
11
+ const isIOSWebKit = () => {
12
+ const userAgent = window.navigator.userAgent;
13
+ return (
14
+ /iPad|iPhone|iPod/.test(userAgent) ||
15
+ (userAgent.includes("Macintosh") && window.navigator.maxTouchPoints > 1)
16
+ );
17
+ };
18
+
19
+ /** Prevent Mobile Safari focus and touch gestures from panning the document. */
20
+ export const useComposerViewportLock = (frameRef: RefObject<HTMLElement | null>) => {
21
+ useLayoutEffect(() => {
22
+ const frame = frameRef.current;
23
+ const dock = frame?.querySelector<HTMLElement>('[data-slot="aui_composer-dock"]');
24
+ const transcript = frame?.querySelector<HTMLElement>('[data-slot="aui_thread-viewport"]');
25
+ const transcriptContent = frame?.querySelector<HTMLElement>('[data-slot="aui_thread-content"]');
26
+ if (!frame || !dock || !transcript || !transcriptContent) return;
27
+
28
+ const iosWebKit = isIOSWebKit();
29
+ const createTranscriptScroller = () =>
30
+ iosWebKit
31
+ ? new ScrollBooster({
32
+ viewport: transcript,
33
+ content: transcriptContent,
34
+ direction: "vertical",
35
+ pointerMode: "mouse",
36
+ scrollMode: "native",
37
+ bounce: false,
38
+ textSelection: true,
39
+ wheel: false,
40
+ keyboard: false,
41
+ })
42
+ : null;
43
+ let transcriptScroller = createTranscriptScroller();
44
+ let transcriptScrollerRestartFrame: number | null = null;
45
+ let transcriptTouchRoutingEnabled = false;
46
+ let lastTouchY: number | null = null;
47
+ let focusRevealTimer: number | null = null;
48
+ let guardedInput: HTMLTextAreaElement | null = null;
49
+ let guardedOpacity = "";
50
+ let guardViewportHeight = 0;
51
+ let guardViewportTop = 0;
52
+
53
+ const syncTranscriptTouchRouting = () => {
54
+ const viewport = window.visualViewport;
55
+ const keyboardVisible =
56
+ viewport !== null &&
57
+ viewport !== undefined &&
58
+ window.innerHeight - viewport.height > KEYBOARD_TRANSITION_THRESHOLD;
59
+ if (iosWebKit) {
60
+ frame.toggleAttribute("data-ios-keyboard-open", keyboardVisible);
61
+ transcript.toggleAttribute("data-keyboard-touch-scroller", keyboardVisible);
62
+ }
63
+ if (!transcriptScroller) return;
64
+ if (keyboardVisible === transcriptTouchRoutingEnabled) return;
65
+ transcriptTouchRoutingEnabled = keyboardVisible;
66
+ transcriptScroller.updateOptions({ pointerMode: keyboardVisible ? "touch" : "mouse" });
67
+ };
68
+
69
+ const revealGuardedInput = () => {
70
+ if (!guardedInput) return;
71
+ guardedInput.style.opacity = guardedOpacity;
72
+ delete guardedInput.dataset.iosFocusGuard;
73
+ guardedInput = null;
74
+ focusRevealTimer = null;
75
+ guardViewportHeight = 0;
76
+ guardViewportTop = 0;
77
+ };
78
+
79
+ const scheduleGuardReveal = (delay: number) => {
80
+ if (focusRevealTimer !== null) window.clearTimeout(focusRevealTimer);
81
+ focusRevealTimer = window.setTimeout(revealGuardedInput, delay);
82
+ };
83
+
84
+ const guardInput = (input: HTMLTextAreaElement) => {
85
+ if (guardedInput === input) return;
86
+ if (focusRevealTimer !== null) window.clearTimeout(focusRevealTimer);
87
+ revealGuardedInput();
88
+ guardedInput = input;
89
+ guardedOpacity = input.style.opacity;
90
+ guardViewportHeight = window.visualViewport?.height ?? window.innerHeight;
91
+ guardViewportTop = window.visualViewport?.offsetTop ?? 0;
92
+ input.dataset.iosFocusGuard = "true";
93
+ input.style.opacity = "0";
94
+ };
95
+
96
+ const handleInputFocus = (event: FocusEvent) => {
97
+ if (!isIOSWebKit()) return;
98
+ const input = event.target instanceof HTMLTextAreaElement ? event.target : null;
99
+ if (!input?.classList.contains("aui-composer-input")) return;
100
+ guardInput(input);
101
+ scheduleGuardReveal(FOCUS_GUARD_FALLBACK_MS);
102
+ };
103
+
104
+ const handleInputBlur = (event: FocusEvent) => {
105
+ if (event.target === guardedInput) revealGuardedInput();
106
+ };
107
+
108
+ const handleVisualViewportChange = () => {
109
+ syncTranscriptTouchRouting();
110
+ const viewport = window.visualViewport;
111
+ if (!guardedInput || !viewport) return;
112
+ const heightChanged = guardViewportHeight - viewport.height > KEYBOARD_TRANSITION_THRESHOLD;
113
+ const topChanged =
114
+ Math.abs(viewport.offsetTop - guardViewportTop) > KEYBOARD_TRANSITION_THRESHOLD;
115
+ if (!heightChanged && !topChanged) return;
116
+ scheduleGuardReveal(FOCUS_GUARD_SETTLE_MS);
117
+ };
118
+
119
+ const handleTouchStart = (event: TouchEvent) => {
120
+ const target = event.target instanceof Element ? event.target : null;
121
+ const input = target?.closest<HTMLTextAreaElement>(".aui-composer-input");
122
+ if (input && isIOSWebKit()) {
123
+ guardInput(input);
124
+ scheduleGuardReveal(FOCUS_GUARD_FALLBACK_MS);
125
+ }
126
+ lastTouchY = event.touches[0]?.clientY ?? null;
127
+ };
128
+
129
+ const handleTouchMove = (event: TouchEvent) => {
130
+ const touchY = event.touches[0]?.clientY;
131
+ if (touchY === undefined) return;
132
+
133
+ const target = event.target instanceof Element ? event.target : null;
134
+ const input = target?.closest<HTMLTextAreaElement>(".aui-composer-input");
135
+ const deltaY = lastTouchY === null ? 0 : touchY - lastTouchY;
136
+ lastTouchY = touchY;
137
+
138
+ if (input && input.scrollHeight > input.clientHeight + SCROLL_BOUNDARY_EPSILON) {
139
+ const canScrollTowardStart = deltaY > 0 && input.scrollTop > SCROLL_BOUNDARY_EPSILON;
140
+ const canScrollTowardEnd =
141
+ deltaY < 0 &&
142
+ input.scrollTop + input.clientHeight < input.scrollHeight - SCROLL_BOUNDARY_EPSILON;
143
+ if (canScrollTowardStart || canScrollTowardEnd) return;
144
+ }
145
+
146
+ if (event.cancelable) event.preventDefault();
147
+ };
148
+
149
+ const handleTouchEnd = () => {
150
+ lastTouchY = null;
151
+ };
152
+
153
+ const handleCancelTranscriptKineticScroll = () => {
154
+ transcriptScroller?.destroy();
155
+ transcriptScroller = null;
156
+ if (transcriptScrollerRestartFrame !== null) {
157
+ window.cancelAnimationFrame(transcriptScrollerRestartFrame);
158
+ }
159
+ transcriptScrollerRestartFrame = window.requestAnimationFrame(() => {
160
+ transcriptScrollerRestartFrame = window.requestAnimationFrame(() => {
161
+ transcriptScroller = createTranscriptScroller();
162
+ transcriptScroller?.updateOptions({
163
+ pointerMode: transcriptTouchRoutingEnabled ? "touch" : "mouse",
164
+ });
165
+ transcriptScrollerRestartFrame = null;
166
+ });
167
+ });
168
+ };
169
+
170
+ dock.addEventListener("touchstart", handleTouchStart, { passive: true });
171
+ dock.addEventListener("touchmove", handleTouchMove, { passive: false });
172
+ dock.addEventListener("touchend", handleTouchEnd, { passive: true });
173
+ dock.addEventListener("touchcancel", handleTouchEnd, { passive: true });
174
+ dock.addEventListener("focus", handleInputFocus, true);
175
+ dock.addEventListener("blur", handleInputBlur, true);
176
+ transcript.addEventListener(
177
+ CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT,
178
+ handleCancelTranscriptKineticScroll,
179
+ );
180
+ window.visualViewport?.addEventListener("resize", handleVisualViewportChange);
181
+ window.visualViewport?.addEventListener("scroll", handleVisualViewportChange);
182
+ window.visualViewport?.addEventListener("scrollend", handleVisualViewportChange);
183
+ syncTranscriptTouchRouting();
184
+
185
+ return () => {
186
+ if (focusRevealTimer !== null) window.clearTimeout(focusRevealTimer);
187
+ if (transcriptScrollerRestartFrame !== null) {
188
+ window.cancelAnimationFrame(transcriptScrollerRestartFrame);
189
+ }
190
+ revealGuardedInput();
191
+ transcriptScroller?.destroy();
192
+ frame.removeAttribute("data-ios-keyboard-open");
193
+ transcript.removeAttribute("data-keyboard-touch-scroller");
194
+ dock.removeEventListener("touchstart", handleTouchStart);
195
+ dock.removeEventListener("touchmove", handleTouchMove);
196
+ dock.removeEventListener("touchend", handleTouchEnd);
197
+ dock.removeEventListener("touchcancel", handleTouchEnd);
198
+ dock.removeEventListener("focus", handleInputFocus, true);
199
+ dock.removeEventListener("blur", handleInputBlur, true);
200
+ transcript.removeEventListener(
201
+ CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT,
202
+ handleCancelTranscriptKineticScroll,
203
+ );
204
+ window.visualViewport?.removeEventListener("resize", handleVisualViewportChange);
205
+ window.visualViewport?.removeEventListener("scroll", handleVisualViewportChange);
206
+ window.visualViewport?.removeEventListener("scrollend", handleVisualViewportChange);
207
+ };
208
+ }, [frameRef]);
209
+ };
package/src/styles.css CHANGED
@@ -20,3 +20,18 @@
20
20
  @import "@dbx-tools/ui/styles.css";
21
21
 
22
22
  @source "./react";
23
+
24
+ [data-slot="aui_thread-viewport"][data-keyboard-touch-scroller] {
25
+ scrollbar-width: none;
26
+ }
27
+
28
+ [data-slot="aui_thread-viewport"][data-keyboard-touch-scroller]::-webkit-scrollbar {
29
+ display: none;
30
+ width: 0;
31
+ height: 0;
32
+ }
33
+
34
+ [data-slot="aui_thread-frame"][data-ios-keyboard-open] {
35
+ overscroll-behavior: none;
36
+ touch-action: none;
37
+ }
@@ -724,14 +724,16 @@ export const useMastraClient = (): MastraPluginClient => {
724
724
  */
725
725
  export const useMastraMlflowExperiment = (
726
726
  enabled = true,
727
- ): { url: string | null; loading: boolean } => {
727
+ ): { url: string | null; tracePrefix: string | null; loading: boolean } => {
728
728
  const client = useMastraClient();
729
729
  const [url, setUrl] = useState<string | null>(null);
730
+ const [tracePrefix, setTracePrefix] = useState<string | null>(null);
730
731
  const [loading, setLoading] = useState(enabled);
731
732
 
732
733
  useEffect(() => {
733
734
  if (!enabled) {
734
735
  setUrl(null);
736
+ setTracePrefix(null);
735
737
  setLoading(false);
736
738
  return;
737
739
  }
@@ -740,10 +742,16 @@ export const useMastraMlflowExperiment = (
740
742
  client
741
743
  .mlflowExperiment(controller.signal)
742
744
  .then((result) => {
743
- if (!controller.signal.aborted) setUrl(result.url);
745
+ if (!controller.signal.aborted) {
746
+ setUrl(result.url);
747
+ setTracePrefix(result.tracePrefix);
748
+ }
744
749
  })
745
750
  .catch(() => {
746
- if (!controller.signal.aborted) setUrl(null);
751
+ if (!controller.signal.aborted) {
752
+ setUrl(null);
753
+ setTracePrefix(null);
754
+ }
747
755
  })
748
756
  .finally(() => {
749
757
  if (!controller.signal.aborted) setLoading(false);
@@ -751,7 +759,7 @@ export const useMastraMlflowExperiment = (
751
759
  return () => controller.abort();
752
760
  }, [client, enabled]);
753
761
 
754
- return { url, loading };
762
+ return { url, tracePrefix, loading };
755
763
  };
756
764
 
757
765
  /**