@dbx-tools/ui-mastra 0.9.182 → 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.
@@ -9,7 +9,7 @@ import { parse, toLabel, capitalize } from "@dbx-tools/shared-core";
9
9
  import { humanizeStatus } from "@dbx-tools/shared-genie";
10
10
  import { detectCodeLanguage, JsonBlock, RecordPreview } from "@dbx-tools/ui/react";
11
11
  import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react";
12
- import { SourceBlock, ToolMarkdown } from "./markdown.tsx";
12
+ import { CHAT_LINK_SAFETY, SourceBlock, ToolMarkdown } from "./markdown.tsx";
13
13
  import type { ToolEvent, ToolProgress } from "./types.ts";
14
14
 
15
15
  // Consolidated tool-session pill and its Genie progress detail view:
@@ -298,7 +298,7 @@ const MessageGroupBody = ({
298
298
  // opens directly to its SQL instead of adding a redundant
299
299
  // second "SQL" pill around the only child.
300
300
  <Collapsible key={bucket.key} className="rounded border border-border/60 bg-background/40">
301
- <CollapsibleTrigger className="group flex w-full items-center gap-1.5 px-2 py-1 text-left text-xs uppercase tracking-wide text-muted-foreground hover:text-foreground">
301
+ <CollapsibleTrigger className="group flex w-full items-center gap-1.5 py-1 pl-0 pr-1 text-left text-xs uppercase tracking-wide text-muted-foreground hover:text-foreground">
302
302
  <ChevronDownIcon className="size-3 shrink-0 transition-transform group-data-[state=closed]:-rotate-90" />
303
303
  <span>{queryBuckets.length > 1 ? `Query ${i + 1}` : "Query"}</span>
304
304
  {bucket.query?.title ? (
@@ -412,13 +412,20 @@ const RawToolPayload = ({
412
412
  <CollapsibleContent className="min-w-0 max-w-full overflow-hidden">
413
413
  <div className="max-h-48 max-w-full overflow-auto overscroll-contain sm:max-h-64">
414
414
  {structured === undefined ? (
415
- <JsonBlock
416
- json={formatRawToolPayload(value)}
417
- className="py-2 leading-tight text-foreground sm:leading-relaxed"
418
- />
415
+ typeof value === "string" ? (
416
+ <div className="px-2 py-1.5">
417
+ <ToolMarkdown>{value}</ToolMarkdown>
418
+ </div>
419
+ ) : (
420
+ <JsonBlock
421
+ json={formatRawToolPayload(value)}
422
+ className="py-2 leading-tight text-foreground sm:leading-relaxed"
423
+ />
424
+ )
419
425
  ) : (
420
426
  <RecordPreview
421
427
  value={structured}
428
+ linkSafety={CHAT_LINK_SAFETY}
422
429
  className="max-w-full bg-transparent text-foreground [&_pre]:rounded-none [&_pre]:bg-transparent"
423
430
  />
424
431
  )}
@@ -591,14 +598,18 @@ const WebSearchProgressDetails = ({ event }: { event: ToolEvent }) => {
591
598
  };
592
599
 
593
600
  /** Latest cumulative detail emitted by a non-search tool. */
594
- const ToolStatusProgressDetails = ({ event }: { event: ToolEvent }) => {
595
- if (event.toolName === "web_search") return null;
596
- const detail = [...(event.progress ?? [])]
601
+ const toolStatusProgressDetail = (event: ToolEvent): string | undefined => {
602
+ if (event.toolName === "web_search") return undefined;
603
+ return [...(event.progress ?? [])]
597
604
  .reverse()
598
605
  .find(
599
606
  (progress): progress is ToolStatusProgress =>
600
607
  progress.type === "tool_status" && Boolean(progress.detail?.trim()),
601
608
  )?.detail;
609
+ };
610
+
611
+ const ToolStatusProgressDetails = ({ event }: { event: ToolEvent }) => {
612
+ const detail = toolStatusProgressDetail(event);
602
613
  if (!detail) return null;
603
614
  return (
604
615
  <SourceBlock
@@ -616,8 +627,10 @@ const ToolStatusProgressDetails = ({ event }: { event: ToolEvent }) => {
616
627
  * a row whose only content is the question stays non-expandable.
617
628
  */
618
629
  const hasExpandableDetails = (event: ToolEvent): boolean => {
619
- if (event.status === "running") return true;
620
- if ("input" in event || "output" in event) return true;
630
+ if (!event.toolName.startsWith("ask_genie") && event.input !== undefined) return true;
631
+ if (event.output !== undefined) return true;
632
+ if (webSearchProgressGroups(event).length > 0) return true;
633
+ if (toolStatusProgressDetail(event)) return true;
621
634
  const summary = summarizeProgress(event.progress ?? []);
622
635
  return summary.groups.some(
623
636
  (g) => g.attachments.some(isAttachmentRenderable) || g.errors.length > 0,
@@ -724,7 +737,7 @@ const ToolCallRow = ({ event }: { event: ToolEvent }) => {
724
737
  return (
725
738
  <Collapsible className="min-w-0 max-w-full overflow-hidden rounded border border-border/40 bg-background/30">
726
739
  <CollapsibleTrigger className="group flex w-full items-start gap-2 px-2 py-1 text-left text-xs text-muted-foreground cursor-pointer hover:text-foreground">
727
- <ChevronDownIcon className="mt-0.5 size-3 shrink-0 transition-transform group-data-[state=open]:rotate-180" />
740
+ <ChevronDownIcon className="mt-0.5 size-3 shrink-0 transition-transform group-data-[state=closed]:-rotate-90" />
728
741
  <span className="mt-0.5 shrink-0">
729
742
  <ToolStatusIcon status={event.status} />
730
743
  </span>
@@ -774,6 +787,32 @@ export const ToolSessionPill = ({ events }: { events: ToolEvent[] }) => {
774
787
  ? `Calling ${latestName}`
775
788
  : `Called ${latestName}`;
776
789
  const countSuffix = events.length > 1 ? ` · ${events.length} calls` : "";
790
+ const expandable =
791
+ events.length > 1 || hasExpandableDetails(latest) || Boolean(askGenieQuestion(latest));
792
+
793
+ const header = (
794
+ <>
795
+ {expandable ? (
796
+ <ChevronDownIcon className="size-3 shrink-0 transition-transform group-data-[state=closed]:-rotate-90" />
797
+ ) : null}
798
+ <ToolStatusIcon status={tone} />
799
+ <span
800
+ className={cn(
801
+ "min-w-0 flex-1 truncate",
802
+ tone === "running" && "animate-pulse text-foreground/90",
803
+ )}
804
+ >
805
+ {verb}
806
+ {countSuffix}
807
+ </span>
808
+ {tone === "running" && (
809
+ <span className="relative ml-1 flex size-2 shrink-0" aria-hidden>
810
+ <span className="absolute inline-flex size-full animate-ping rounded-full bg-primary/60" />
811
+ <span className="relative inline-flex size-2 rounded-full bg-primary" />
812
+ </span>
813
+ )}
814
+ </>
815
+ );
777
816
 
778
817
  return (
779
818
  <div
@@ -790,53 +829,31 @@ export const ToolSessionPill = ({ events }: { events: ToolEvent[] }) => {
790
829
  : "border-border/40",
791
830
  )}
792
831
  >
793
- <Collapsible>
794
- <CollapsibleTrigger className="group flex w-full items-center gap-2 text-left text-xs text-muted-foreground cursor-pointer hover:text-foreground">
795
- <ChevronDownIcon className="size-3 shrink-0 transition-transform group-data-[state=open]:rotate-180" />
796
- <ToolStatusIcon status={tone} />
797
- {/*
798
- * Verb + count share one span so the `·` separator reads
799
- * as a natural inline divider. `min-w-0` lets the truncate
800
- * clip without forcing the row to overflow when the verb
801
- * is long.
802
- */}
803
- <span
804
- className={cn(
805
- "min-w-0 flex-1 truncate",
806
- tone === "running" && "animate-pulse text-foreground/90",
807
- )}
808
- >
809
- {verb}
810
- {countSuffix}
811
- </span>
812
- {/*
813
- * Trailing "live" pip on the right edge while any tool is
814
- * in flight. Two-layer: a static dot under an animated
815
- * ping ring, matching the convention native chat apps use
816
- * for active recording / streaming indicators.
817
- */}
818
- {tone === "running" && (
819
- <span className="relative ml-1 flex size-2 shrink-0" aria-hidden>
820
- <span className="absolute inline-flex size-full animate-ping rounded-full bg-primary/60" />
821
- <span className="relative inline-flex size-2 rounded-full bg-primary" />
822
- </span>
823
- )}
824
- </CollapsibleTrigger>
825
- <CollapsibleContent className="min-w-0 max-w-full overflow-hidden">
826
- <div
827
- className={cn(
828
- "mt-1.5 min-w-0 max-w-full overflow-hidden",
829
- events.length > 1 && "flex flex-col gap-1",
830
- )}
831
- >
832
- {events.length === 1 ? (
833
- <ToolCallDetails event={latest} showQuestion />
834
- ) : (
835
- events.map((event) => <ToolCallRow key={event.id} event={event} />)
836
- )}
837
- </div>
838
- </CollapsibleContent>
839
- </Collapsible>
832
+ {expandable ? (
833
+ <Collapsible>
834
+ <CollapsibleTrigger className="group flex w-full cursor-pointer items-center gap-2 text-left text-xs text-muted-foreground hover:text-foreground">
835
+ {header}
836
+ </CollapsibleTrigger>
837
+ <CollapsibleContent className="min-w-0 max-w-full overflow-hidden">
838
+ <div
839
+ className={cn(
840
+ "mt-1.5 min-w-0 max-w-full overflow-hidden",
841
+ events.length > 1 && "flex flex-col gap-1",
842
+ )}
843
+ >
844
+ {events.length === 1 ? (
845
+ <ToolCallDetails event={latest} showQuestion />
846
+ ) : (
847
+ events.map((event) => <ToolCallRow key={event.id} event={event} />)
848
+ )}
849
+ </div>
850
+ </CollapsibleContent>
851
+ </Collapsible>
852
+ ) : (
853
+ <div className="flex w-full items-center gap-2 text-left text-xs text-muted-foreground">
854
+ {header}
855
+ </div>
856
+ )}
840
857
  </div>
841
858
  );
842
859
  };
@@ -69,6 +69,7 @@ export type ChatModelOption = Pick<
69
69
  */
70
70
  export type ChatInputMessage = { text?: string; files?: FileUIPart[] };
71
71
 
72
+ /** Queued chat input with the stable identifier used for ordering and removal. */
72
73
  export type QueuedSteer = ChatInputMessage & { id: string };
73
74
 
74
75
  /** Thumbs reaction a user can leave on an assistant turn. */
@@ -1,11 +1,19 @@
1
- import { ScrollBooster } from "scrollbooster";
2
1
  import { useLayoutEffect, type RefObject } from "react";
2
+ import { ScrollBooster } from "scrollbooster";
3
3
 
4
- const SCROLL_BOUNDARY_EPSILON = 1;
5
- const KEYBOARD_TRANSITION_THRESHOLD = 80;
4
+ const COMPOSER_DOCK_SELECTOR = '[data-slot="aui_composer-dock"]';
5
+ const COMPOSER_INPUT_SELECTOR = ".aui-composer-input";
6
+ const TRANSCRIPT_SELECTOR = '[data-slot="aui_thread-viewport"]';
7
+ const TRANSCRIPT_CONTENT_SELECTOR = '[data-slot="aui_thread-content"]';
8
+ const TRANSCRIPT_INDICATOR_SELECTOR = '[data-slot="aui_thread-scroll-indicator"]';
9
+
10
+ const SCROLL_BOUNDARY_EPSILON_PX = 1;
11
+ const KEYBOARD_GEOMETRY_THRESHOLD_PX = 80;
6
12
  const FOCUS_GUARD_FALLBACK_MS = 600;
7
13
  const FOCUS_GUARD_SETTLE_MS = 120;
14
+ const MIN_SCROLL_INDICATOR_HEIGHT_PX = 28;
8
15
 
16
+ /** Internal event used by the scroll-to-bottom control to cancel iOS drag momentum first. */
9
17
  export const CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT = "dbx-tools:cancel-transcript-kinetic-scroll";
10
18
 
11
19
  const isIOSWebKit = () => {
@@ -16,33 +24,79 @@ const isIOSWebKit = () => {
16
24
  );
17
25
  };
18
26
 
19
- /** Prevent Mobile Safari focus and touch gestures from panning the document. */
27
+ const isKeyboardVisible = (viewport: VisualViewport | null): boolean =>
28
+ Boolean(viewport && window.innerHeight - viewport.height > KEYBOARD_GEOMETRY_THRESHOLD_PX);
29
+
30
+ const composerInputFromEvent = (event: Event): HTMLTextAreaElement | null => {
31
+ const target = event.target instanceof Element ? event.target : null;
32
+ return target?.closest<HTMLTextAreaElement>(COMPOSER_INPUT_SELECTOR) ?? null;
33
+ };
34
+
35
+ const createTranscriptScroller = (viewport: HTMLElement, content: HTMLElement) =>
36
+ new ScrollBooster({
37
+ viewport,
38
+ content,
39
+ direction: "vertical",
40
+ pointerMode: "mouse",
41
+ scrollMode: "native",
42
+ bounce: false,
43
+ textSelection: true,
44
+ wheel: false,
45
+ keyboard: false,
46
+ });
47
+
48
+ const syncScrollIndicator = (
49
+ transcript: HTMLElement,
50
+ indicator: HTMLElement | null,
51
+ visible: boolean,
52
+ ) => {
53
+ if (!indicator) return;
54
+
55
+ const maxScrollTop = transcript.scrollHeight - transcript.clientHeight;
56
+ indicator.hidden = !visible || maxScrollTop <= 0;
57
+ if (indicator.hidden) return;
58
+
59
+ // Safari paints native overlay scrollbars against stale pre-keyboard geometry. This thumb is
60
+ // positioned inside the resized transcript so it always matches the visible scroll region.
61
+ const proportionalHeight =
62
+ (transcript.clientHeight / transcript.scrollHeight) * transcript.clientHeight;
63
+ const height = Math.min(
64
+ transcript.clientHeight,
65
+ Math.max(MIN_SCROLL_INDICATOR_HEIGHT_PX, Math.round(proportionalHeight)),
66
+ );
67
+ const scrollTop = Math.min(maxScrollTop, Math.max(0, transcript.scrollTop));
68
+ const top = Math.round((scrollTop / maxScrollTop) * (transcript.clientHeight - height));
69
+ indicator.style.height = `${height}px`;
70
+ indicator.style.transform = `translateY(${top}px)`;
71
+ };
72
+
73
+ /**
74
+ * Contains Mobile Safari keyboard and touch behavior inside the chat frame.
75
+ *
76
+ * When the host shell follows `visualViewport`, this hook owns the remaining iOS-specific work:
77
+ * suppressing Safari's input-reveal pan, routing keyboard-open transcript drags through
78
+ * ScrollBooster, stopping existing momentum before composer actions, and drawing the keyboard-safe
79
+ * scrollbar thumb.
80
+ */
20
81
  export const useComposerViewportLock = (frameRef: RefObject<HTMLElement | null>) => {
21
82
  useLayoutEffect(() => {
22
83
  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"]');
84
+ const dock = frame?.querySelector<HTMLElement>(COMPOSER_DOCK_SELECTOR);
85
+ const transcript = frame?.querySelector<HTMLElement>(TRANSCRIPT_SELECTOR);
86
+ const transcriptContent = frame?.querySelector<HTMLElement>(TRANSCRIPT_CONTENT_SELECTOR);
87
+ const scrollIndicator =
88
+ frame?.querySelector<HTMLElement>(TRANSCRIPT_INDICATOR_SELECTOR) ?? null;
26
89
  if (!frame || !dock || !transcript || !transcriptContent) return;
27
90
 
28
91
  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();
92
+ let transcriptScroller = iosWebKit
93
+ ? createTranscriptScroller(transcript, transcriptContent)
94
+ : null;
44
95
  let transcriptScrollerRestartFrame: number | null = null;
45
96
  let transcriptTouchRoutingEnabled = false;
97
+ let momentumRestoreFrame: number | null = null;
98
+ let momentumScrollTop = 0;
99
+ let momentumOverflowY: string | null = null;
46
100
  let lastTouchY: number | null = null;
47
101
  let focusRevealTimer: number | null = null;
48
102
  let guardedInput: HTMLTextAreaElement | null = null;
@@ -50,20 +104,18 @@ export const useComposerViewportLock = (frameRef: RefObject<HTMLElement | null>)
50
104
  let guardViewportHeight = 0;
51
105
  let guardViewportTop = 0;
52
106
 
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);
107
+ const syncIndicator = () =>
108
+ syncScrollIndicator(transcript, scrollIndicator, transcriptTouchRoutingEnabled);
109
+
110
+ const syncKeyboardState = () => {
111
+ const keyboardVisible = iosWebKit && isKeyboardVisible(window.visualViewport);
112
+ transcript.toggleAttribute("data-keyboard-touch-scroller", keyboardVisible);
113
+
114
+ if (keyboardVisible !== transcriptTouchRoutingEnabled) {
115
+ transcriptTouchRoutingEnabled = keyboardVisible;
116
+ transcriptScroller?.updateOptions({ pointerMode: keyboardVisible ? "touch" : "mouse" });
62
117
  }
63
- if (!transcriptScroller) return;
64
- if (keyboardVisible === transcriptTouchRoutingEnabled) return;
65
- transcriptTouchRoutingEnabled = keyboardVisible;
66
- transcriptScroller.updateOptions({ pointerMode: keyboardVisible ? "touch" : "mouse" });
118
+ syncIndicator();
67
119
  };
68
120
 
69
121
  const revealGuardedInput = () => {
@@ -93,10 +145,51 @@ export const useComposerViewportLock = (frameRef: RefObject<HTMLElement | null>)
93
145
  input.style.opacity = "0";
94
146
  };
95
147
 
148
+ const stopNativeTranscriptMomentum = () => {
149
+ if (!iosWebKit) return;
150
+
151
+ transcriptScroller?.setPosition({ y: transcript.scrollTop });
152
+ momentumScrollTop = transcript.scrollTop;
153
+ if (momentumOverflowY === null) momentumOverflowY = transcript.style.overflowY;
154
+ if (momentumRestoreFrame !== null) window.cancelAnimationFrame(momentumRestoreFrame);
155
+
156
+ // WebKit carries an existing inertial transcript gesture through keyboard focus. Removing
157
+ // overflow for one frame ends that gesture while preserving the reader's exact position.
158
+ transcript.style.overflowY = "hidden";
159
+ transcript.scrollTop = momentumScrollTop;
160
+ momentumRestoreFrame = window.requestAnimationFrame(() => {
161
+ transcript.style.overflowY = momentumOverflowY ?? "";
162
+ transcript.scrollTop = momentumScrollTop;
163
+ momentumOverflowY = null;
164
+ momentumRestoreFrame = null;
165
+ });
166
+ };
167
+
168
+ const restartTranscriptScroller = () => {
169
+ if (!iosWebKit) return;
170
+ transcriptScroller?.destroy();
171
+ transcriptScroller = null;
172
+ if (transcriptScrollerRestartFrame !== null) {
173
+ window.cancelAnimationFrame(transcriptScrollerRestartFrame);
174
+ }
175
+
176
+ // Reattach after the current touch sequence and its next paint have completed. Recreating the
177
+ // instance during the same dispatch allows ScrollBooster's old kinetic loop to keep running.
178
+ transcriptScrollerRestartFrame = window.requestAnimationFrame(() => {
179
+ transcriptScrollerRestartFrame = window.requestAnimationFrame(() => {
180
+ transcriptScroller = createTranscriptScroller(transcript, transcriptContent);
181
+ transcriptScroller.updateOptions({
182
+ pointerMode: transcriptTouchRoutingEnabled ? "touch" : "mouse",
183
+ });
184
+ transcriptScrollerRestartFrame = null;
185
+ });
186
+ });
187
+ };
188
+
96
189
  const handleInputFocus = (event: FocusEvent) => {
97
- if (!isIOSWebKit()) return;
190
+ if (!iosWebKit) return;
98
191
  const input = event.target instanceof HTMLTextAreaElement ? event.target : null;
99
- if (!input?.classList.contains("aui-composer-input")) return;
192
+ if (!input?.matches(COMPOSER_INPUT_SELECTOR)) return;
100
193
  guardInput(input);
101
194
  scheduleGuardReveal(FOCUS_GUARD_FALLBACK_MS);
102
195
  };
@@ -106,43 +199,48 @@ export const useComposerViewportLock = (frameRef: RefObject<HTMLElement | null>)
106
199
  };
107
200
 
108
201
  const handleVisualViewportChange = () => {
109
- syncTranscriptTouchRouting();
202
+ syncKeyboardState();
110
203
  const viewport = window.visualViewport;
111
204
  if (!guardedInput || !viewport) return;
112
- const heightChanged = guardViewportHeight - viewport.height > KEYBOARD_TRANSITION_THRESHOLD;
205
+ const heightChanged = guardViewportHeight - viewport.height > KEYBOARD_GEOMETRY_THRESHOLD_PX;
113
206
  const topChanged =
114
- Math.abs(viewport.offsetTop - guardViewportTop) > KEYBOARD_TRANSITION_THRESHOLD;
207
+ Math.abs(viewport.offsetTop - guardViewportTop) > KEYBOARD_GEOMETRY_THRESHOLD_PX;
115
208
  if (!heightChanged && !topChanged) return;
209
+
210
+ // Restore only after WebKit has started the keyboard transition and the host shell has
211
+ // resized. Restoring earlier makes the visible textarea eligible for another reveal pan.
116
212
  scheduleGuardReveal(FOCUS_GUARD_SETTLE_MS);
117
213
  };
118
214
 
119
215
  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()) {
216
+ const input = composerInputFromEvent(event);
217
+ if (input && iosWebKit) {
218
+ // This must run before the native focus default action. Focus events can arrive after Safari
219
+ // has already selected and centered its reveal target.
123
220
  guardInput(input);
124
221
  scheduleGuardReveal(FOCUS_GUARD_FALLBACK_MS);
125
222
  }
126
223
  lastTouchY = event.touches[0]?.clientY ?? null;
224
+ stopNativeTranscriptMomentum();
127
225
  };
128
226
 
129
227
  const handleTouchMove = (event: TouchEvent) => {
130
228
  const touchY = event.touches[0]?.clientY;
131
229
  if (touchY === undefined) return;
132
230
 
133
- const target = event.target instanceof Element ? event.target : null;
134
- const input = target?.closest<HTMLTextAreaElement>(".aui-composer-input");
231
+ const input = composerInputFromEvent(event);
135
232
  const deltaY = lastTouchY === null ? 0 : touchY - lastTouchY;
136
233
  lastTouchY = touchY;
137
234
 
138
- if (input && input.scrollHeight > input.clientHeight + SCROLL_BOUNDARY_EPSILON) {
139
- const canScrollTowardStart = deltaY > 0 && input.scrollTop > SCROLL_BOUNDARY_EPSILON;
235
+ if (input && input.scrollHeight > input.clientHeight + SCROLL_BOUNDARY_EPSILON_PX) {
236
+ const canScrollTowardStart = deltaY > 0 && input.scrollTop > SCROLL_BOUNDARY_EPSILON_PX;
140
237
  const canScrollTowardEnd =
141
238
  deltaY < 0 &&
142
- input.scrollTop + input.clientHeight < input.scrollHeight - SCROLL_BOUNDARY_EPSILON;
239
+ input.scrollTop + input.clientHeight < input.scrollHeight - SCROLL_BOUNDARY_EPSILON_PX;
143
240
  if (canScrollTowardStart || canScrollTowardEnd) return;
144
241
  }
145
242
 
243
+ // Composer drags must not select the document or visual viewport as the gesture scroller.
146
244
  if (event.cancelable) event.preventDefault();
147
245
  };
148
246
 
@@ -150,22 +248,12 @@ export const useComposerViewportLock = (frameRef: RefObject<HTMLElement | null>)
150
248
  lastTouchY = null;
151
249
  };
152
250
 
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
- };
251
+ const resizeObserver =
252
+ iosWebKit && scrollIndicator && typeof ResizeObserver !== "undefined"
253
+ ? new ResizeObserver(syncIndicator)
254
+ : null;
255
+ resizeObserver?.observe(transcript);
256
+ resizeObserver?.observe(transcriptContent);
169
257
 
170
258
  dock.addEventListener("touchstart", handleTouchStart, { passive: true });
171
259
  dock.addEventListener("touchmove", handleTouchMove, { passive: false });
@@ -173,33 +261,35 @@ export const useComposerViewportLock = (frameRef: RefObject<HTMLElement | null>)
173
261
  dock.addEventListener("touchcancel", handleTouchEnd, { passive: true });
174
262
  dock.addEventListener("focus", handleInputFocus, true);
175
263
  dock.addEventListener("blur", handleInputBlur, true);
176
- transcript.addEventListener(
177
- CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT,
178
- handleCancelTranscriptKineticScroll,
179
- );
264
+ transcript.addEventListener("scroll", syncIndicator, { passive: true });
265
+ transcript.addEventListener(CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT, restartTranscriptScroller);
180
266
  window.visualViewport?.addEventListener("resize", handleVisualViewportChange);
181
267
  window.visualViewport?.addEventListener("scroll", handleVisualViewportChange);
182
268
  window.visualViewport?.addEventListener("scrollend", handleVisualViewportChange);
183
- syncTranscriptTouchRouting();
269
+ syncKeyboardState();
184
270
 
185
271
  return () => {
272
+ if (momentumRestoreFrame !== null) window.cancelAnimationFrame(momentumRestoreFrame);
186
273
  if (focusRevealTimer !== null) window.clearTimeout(focusRevealTimer);
187
274
  if (transcriptScrollerRestartFrame !== null) {
188
275
  window.cancelAnimationFrame(transcriptScrollerRestartFrame);
189
276
  }
190
277
  revealGuardedInput();
191
278
  transcriptScroller?.destroy();
192
- frame.removeAttribute("data-ios-keyboard-open");
279
+ resizeObserver?.disconnect();
193
280
  transcript.removeAttribute("data-keyboard-touch-scroller");
281
+ if (scrollIndicator) scrollIndicator.hidden = true;
282
+ if (momentumOverflowY !== null) transcript.style.overflowY = momentumOverflowY;
194
283
  dock.removeEventListener("touchstart", handleTouchStart);
195
284
  dock.removeEventListener("touchmove", handleTouchMove);
196
285
  dock.removeEventListener("touchend", handleTouchEnd);
197
286
  dock.removeEventListener("touchcancel", handleTouchEnd);
198
287
  dock.removeEventListener("focus", handleInputFocus, true);
199
288
  dock.removeEventListener("blur", handleInputBlur, true);
289
+ transcript.removeEventListener("scroll", syncIndicator);
200
290
  transcript.removeEventListener(
201
291
  CANCEL_TRANSCRIPT_KINETIC_SCROLL_EVENT,
202
- handleCancelTranscriptKineticScroll,
292
+ restartTranscriptScroller,
203
293
  );
204
294
  window.visualViewport?.removeEventListener("resize", handleVisualViewportChange);
205
295
  window.visualViewport?.removeEventListener("scroll", handleVisualViewportChange);
package/src/styles.css CHANGED
@@ -22,6 +22,8 @@
22
22
  @source "./react";
23
23
 
24
24
  [data-slot="aui_thread-viewport"][data-keyboard-touch-scroller] {
25
+ /* The adjacent custom thumb uses the transcript's keyboard-resized geometry. */
26
+ scrollbar-gutter: auto;
25
27
  scrollbar-width: none;
26
28
  }
27
29
 
@@ -30,8 +32,3 @@
30
32
  width: 0;
31
33
  height: 0;
32
34
  }
33
-
34
- [data-slot="aui_thread-frame"][data-ios-keyboard-open] {
35
- overscroll-behavior: none;
36
- touch-action: none;
37
- }
@@ -987,10 +987,9 @@ export const useMastraThreads = (
987
987
  }
988
988
  const controller = new AbortController();
989
989
  if (!hasLoadedRef.current) setLoading(true);
990
- void load(controller.signal)
991
- .finally(() => {
992
- if (!controller.signal.aborted) setLoading(false);
993
- });
990
+ void load(controller.signal).finally(() => {
991
+ if (!controller.signal.aborted) setLoading(false);
992
+ });
994
993
  return () => controller.abort();
995
994
  }, [enabled, load, nonce]);
996
995
 
@@ -1,3 +1,4 @@
1
+ import { GenieMessageSchema } from "@dbx-tools/shared-genie";
1
2
  import {
2
3
  GENIE_PROGRESS_PART_TYPE,
3
4
  GenieProgressPartDataSchema,
@@ -16,6 +17,39 @@ export function compactReasoningText(text: string): string {
16
17
  .join(" ");
17
18
  }
18
19
 
20
+ /** Read reasoning persisted in a completed Genie's message attachments. */
21
+ export function genieOutputReasoningSections(output: unknown): string[] {
22
+ if (!output || typeof output !== "object") return [];
23
+ const candidate = "message" in output ? output.message : output;
24
+ const parsed = GenieMessageSchema.safeParse(candidate);
25
+ if (!parsed.success) return [];
26
+
27
+ return (parsed.data.attachments ?? []).flatMap((attachment) =>
28
+ (attachment.query?.thoughts ?? []).flatMap((thought) => {
29
+ const text = compactReasoningText(thought.content);
30
+ return text ? [text] : [];
31
+ }),
32
+ );
33
+ }
34
+
35
+ /** Collect one tool's streamed and persisted reasoning without duplicates. */
36
+ export function toolReasoningSections(event: ToolEvent): string[] {
37
+ const sections: string[] = [];
38
+ const seen = new Set<string>();
39
+ const append = (text: string) => {
40
+ if (!text || seen.has(text)) return;
41
+ seen.add(text);
42
+ sections.push(text);
43
+ };
44
+
45
+ for (const progress of event.progress ?? []) {
46
+ if (progress.type !== "thinking") continue;
47
+ append(compactReasoningText(progress.text));
48
+ }
49
+ for (const text of genieOutputReasoningSections(event.output)) append(text);
50
+ return sections;
51
+ }
52
+
19
53
  /**
20
54
  * Collect Genie `thinking` events for the assistant Thoughts panel.
21
55
  *
@@ -25,13 +59,7 @@ export function compactReasoningText(text: string): string {
25
59
  */
26
60
  export function genieReasoningText(events: ToolEvent[]): string {
27
61
  const sections: string[] = [];
28
- for (const event of events) {
29
- for (const progress of event.progress ?? []) {
30
- if (progress.type !== "thinking") continue;
31
- const text = compactReasoningText(progress.text);
32
- if (text) sections.push(text);
33
- }
34
- }
62
+ for (const event of events) sections.push(...toolReasoningSections(event));
35
63
  return sections.join("\n");
36
64
  }
37
65