@dbx-tools/ui-mastra 0.9.182 → 0.9.185
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 -3
- package/index.support.ts +1 -1
- package/index.ts +1 -1
- package/package.json +7 -8
- package/src/react/_assistant-activity.ts +2 -6
- package/src/react/_external-link-dialog.tsx +11 -14
- package/src/react/bubbles.tsx +19 -7
- package/src/react/chat-composer.tsx +3 -3
- package/src/react/chat-feedback.ts +1 -2
- package/src/react/chat-stream.ts +3 -5
- package/src/react/chat-thread-layout.tsx +0 -2
- package/src/react/chat-transcript.tsx +37 -60
- package/src/react/feedback-controls.tsx +1 -4
- package/src/react/markdown.tsx +18 -22
- package/src/react/mastra-chat.tsx +70 -15
- package/src/react/tool-pill.tsx +76 -59
- package/src/react/types.ts +1 -0
- package/src/styles.css +0 -15
- package/src/support/genie-client.ts +24 -12
- package/src/support/mastra-client.ts +3 -4
- package/src/support/tool-events.ts +35 -7
- package/src/react/use-composer-viewport-lock.ts +0 -209
|
@@ -1,209 +0,0 @@
|
|
|
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
|
-
};
|