@devries-cameron20 / t3code-1 / commits / 7bafc40c17
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(mobile): play audio inline and open shared files in the viewer (#21353)

maria committed Oct 25, 2026 at 19:12 UTC 7bafc40c17ab2a1cb8f0eb675cde4d6d3153f119
33 files changed +3034 -220
apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift
+11 -4
@@ -10,6 +10,7 @@ public final class T3NativeControlsModule: Module {
10 private var filePresentation: T3NativeFilePresentation?
11
12 public func definition() -> ModuleDefinition {
13 + Events("videoPlaybackChange")
14 Constants {
15 if #available(iOS 26.0, *) {
16 return [
@@ -247,10 +248,16 @@ public final class T3NativeControlsModule: Module {
248 userInfo: [NSLocalizedDescriptionKey: "The video preview is no longer available."]
249 )
250 }
250 - let presentation = T3NativeVideoPresentation(identifier: identifier, url: url, title: title) { [weak self] error in
251 - self?.videoPresentation = nil
252 - if let error { promise.reject(error) } else { promise.resolve(nil) }
253 - }
251 + let presentation = T3NativeVideoPresentation(
252 + identifier: identifier, url: url, title: title,
253 + onPlaybackChange: { [weak self] isPlaying in
254 + self?.sendEvent("videoPlaybackChange", ["identifier": identifier, "isPlaying": isPlaying])
255 + },
256 + completion: { [weak self] error in
257 + self?.videoPresentation = nil
258 + if let error { promise.reject(error) } else { promise.resolve(nil) }
259 + }
260 + )
261 videoPresentation = presentation
262 presentation.present(from: presenter, sources: presentationSources, sourceIdentifier: sourceIdentifier)
263 }
apps/mobile/modules/t3-native-controls/ios/T3NativeVideoPresentation.swift
+10 -1
@@ -7,6 +7,7 @@ final class T3NativeVideoPresentation: NSObject, AVPlayerViewControllerDelegate,
7 private let controller = AVPlayerViewController()
8 private let completion: (Error?) -> Void
9 private var itemObservation: NSKeyValueObservation?
10 + private var playbackObservation: NSKeyValueObservation?
11 private var backgroundObserver: NSObjectProtocol?
12 private var playbackError: Error?
13 private var presented = false
@@ -27,7 +28,8 @@ final class T3NativeVideoPresentation: NSObject, AVPlayerViewControllerDelegate,
28 private weak var fullScreenController: UIViewController?
29 private var embedded = false
30
30 - init(identifier: String, url: URL, title: String, completion: @escaping (Error?) -> Void) {
31 + init(identifier: String, url: URL, title: String,
32 + onPlaybackChange: @escaping (Bool) -> Void, completion: @escaping (Error?) -> Void) {
33 self.identifier = identifier
34 self.completion = completion
35 super.init()
@@ -38,6 +40,12 @@ final class T3NativeVideoPresentation: NSObject, AVPlayerViewControllerDelegate,
40 metadata.value = title as NSString
41 item.externalMetadata = [metadata]
42 controller.player = AVPlayer(playerItem: item)
43 + playbackObservation = controller.player?.observe(\.timeControlStatus, options: [.new]) { player, _ in
44 + // Waiting keeps the playback request alive through buffering and seeks.
45 + if player.timeControlStatus != .waitingToPlayAtSpecifiedRate {
46 + onPlaybackChange(player.timeControlStatus == .playing)
47 + }
48 + }
49 controller.delegate = self
50 controller.overrideUserInterfaceStyle = .dark
51 controller.allowsPictureInPicturePlayback = false
@@ -148,6 +156,7 @@ final class T3NativeVideoPresentation: NSObject, AVPlayerViewControllerDelegate,
156 controller.removeFromParent()
157 }
158 itemObservation = nil
159 + playbackObservation = nil
160 controller.player = nil
161 if let backgroundObserver { NotificationCenter.default.removeObserver(backgroundObserver) }
162 backgroundObserver = nil
apps/mobile/package.json
+2 -1
@@ -119,7 +119,7 @@
119 "expo-sqlite": "~58.0.13",
120 "expo-symbols": "~58.0.4",
121 "expo-updates": "~58.0.17",
122 - "expo-video": "~58.0.11",
122 + "expo-video": "58.0.11",
123 "expo-web-browser": "~58.0.6",
124 "expo-widgets": "58.0.20",
125 "react": "catalog:",
@@ -179,6 +179,7 @@
179 "react-native-reanimated",
180 "@react-native-menu/menu",
181 "expo-audio",
182 + "expo-video",
183 "expo-network"
184 ]
185 }
apps/mobile/src/components/FilePreviewModal.tsx
+32 -1
@@ -12,6 +12,11 @@ import {
12 import { Keyboard } from "react-native";
13
14 import { loadLocalAttachmentPreview } from "../lib/localAttachmentPreview";
15 +import {
16 + downloadAndShareAttachment,
17 + nativeViewerErrorMessage,
18 + shareLocalAttachment,
19 +} from "../lib/attachmentDownload";
20 import { useRefreshAssetUrl } from "../state/assets";
21 import { filePreviewGallery, filePreviewKey, filePreviewName } from "../lib/filePreviewGallery";
22 import { FilePreviewGallery } from "./FilePreviewGallery";
@@ -122,6 +127,32 @@ function ResolvedFilePreview(props: {
127 [items, resolved],
128 );
129 const ready = selected && gallery.length === items.length;
130 + const onOpenError = (error: unknown) => {
131 + if (props.onOpenError) return props.onOpenError(error);
132 + Dialog.alert("Could not open preview", nativeViewerErrorMessage(error), [
133 + { text: "Cancel", style: "cancel" },
134 + ...(selected?.kind === "document"
135 + ? [
136 + {
137 + text: "Save or share",
138 + onPress: () => {
139 + const input = {
140 + attachment: {
141 + name: filePreviewName(selected),
142 + mimeType: selected.mimeType ?? "application/octet-stream",
143 + },
144 + signal: new AbortController().signal,
145 + };
146 + const sharing = /^(file|content):/.test(selected.uri)
147 + ? shareLocalAttachment({ ...input, uri: selected.uri })
148 + : downloadAndShareAttachment({ ...input, url: selected.uri });
149 + void sharing.catch(() => Dialog.alert("Could not share file", "Please try again."));
150 + },
151 + },
152 + ]
153 + : []),
154 + ]);
155 + };
156 return (
157 <>
158 {items.map((item) => (
@@ -137,7 +168,7 @@ function ResolvedFilePreview(props: {
168 <FilePreview
169 source={{ ...selected, gallery }}
170 onRequestClose={props.onRequestClose}
140 - onOpenError={props.onOpenError}
171 + onOpenError={onOpenError}
172 />
173 ) : null}
174 </>
apps/mobile/src/components/MediaVideoPlayer.tsx
+47 -7
@@ -1,7 +1,7 @@
1 import { useIsFocused } from "@react-navigation/native";
2 import { useEvent } from "expo";
3 import { useVideoPlayer, VideoView } from "expo-video";
4 -import { useEffect, useEffectEvent, useRef, useState } from "react";
4 +import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
5 import { AppState, Pressable, View } from "react-native";
6
7 import { AppActivityIndicator } from "./ui/AppActivityIndicator";
@@ -12,12 +12,14 @@ import { useMediaActions } from "../state/mediaActions";
12 import { type MediaActionsSource } from "../lib/mediaActionsSource";
13 import { useFullscreenVideoOpen, useMediaAudioSessionHold } from "../lib/videoAudioSession";
14 import { MediaActionsMenu } from "./MediaActionsMenu";
15 +import { createAudioPlaybackSession } from "../lib/audioSession";
16
17 function LoadedMediaVideo(props: {
18 readonly uri: string;
19 readonly resolvePlaybackUri?: () => Promise<string | null>;
20 readonly playRequested: boolean;
21 readonly paused: boolean;
22 + readonly onPlaybackStart?: () => void;
23 }) {
24 const focused = useIsFocused();
25 const fullscreenVideoOpen = useFullscreenVideoOpen();
@@ -31,6 +33,38 @@ function LoadedMediaVideo(props: {
33 player.staysActiveInBackground = false;
34 player.bufferOptions = { preferredForwardBufferDuration: 5 };
35 });
36 + const playback = useMemo(() => createAudioPlaybackSession(player, true), [player]);
37 + const previousPlaybackRequested = useRef(false);
38 + const onPlaybackStart = useEffectEvent(() => props.onPlaybackStart?.());
39 + useEffect(() => {
40 + const subscription = player.addListener("playingChange", ({ isPlaying }) => {
41 + if (isPlaying && !active.current && !fullscreen.current) playback.pause();
42 + else playback.playingChanged(isPlaying);
43 + });
44 + const requested = player.addListener("playbackRequestedChange", ({ isPlaybackRequested }) => {
45 + const wasPlaybackRequested = previousPlaybackRequested.current;
46 + previousPlaybackRequested.current = isPlaybackRequested;
47 + if (!isPlaybackRequested) {
48 + if (playback.requested) playback.pause();
49 + } else if (!active.current && !fullscreen.current) playback.pause();
50 + else {
51 + if (!wasPlaybackRequested) onPlaybackStart();
52 + playback.playingChanged(true);
53 + }
54 + });
55 + const ended = player.addListener("playToEnd", () => playback.pause());
56 + const failed = player.addListener("statusChange", ({ status }) => {
57 + if (status === "error") playback.pause();
58 + });
59 + return () => {
60 + subscription.remove();
61 + requested.remove();
62 + ended.remove();
63 + failed.remove();
64 + playback.pause();
65 + previousPlaybackRequested.current = false;
66 + };
67 + }, [player, playback]);
68 const { status } = useEvent(player, "statusChange", { status: player.status });
69 const { isPlaying } = useEvent(player, "playingChange", { isPlaying: player.playing });
70 useMediaAudioSessionHold(isPlaying);
@@ -38,21 +72,22 @@ function LoadedMediaVideo(props: {
72 const uri = props.resolvePlaybackUri ? await props.resolvePlaybackUri() : props.uri;
73 if (signal.aborted) return;
74 if (uri === null) throw new Error("Video unavailable");
41 - player.pause();
75 + playback.pause();
76 + previousPlaybackRequested.current = false;
77 await player.replaceAsync({ uri, contentType: "progressive" });
43 - if (!signal.aborted && props.playRequested && active.current) player.play();
78 + if (!signal.aborted && props.playRequested && active.current) await playback.play();
79 });
80
81 useEffect(() => {
82 active.current = focused && !paused && AppState.currentState === "active";
48 - if (!focused || paused || (!active.current && !fullscreen.current)) player.pause();
83 + if (!focused || paused || (!active.current && !fullscreen.current)) playback.pause();
84 // RN reports both leaving the app and Android fullscreen as background; native handling distinguishes them.
85 const subscription = AppState.addEventListener("change", (state) => {
86 active.current = focused && !paused && state === "active";
52 - if (state === "inactive" || (state === "background" && !fullscreen.current)) player.pause();
87 + if (state === "inactive" || (state === "background" && !fullscreen.current)) playback.pause();
88 });
89 return () => subscription.remove();
55 - }, [focused, player, paused]);
90 + }, [focused, playback, paused]);
91
92 useEffect(() => {
93 const controller = new AbortController();
@@ -117,6 +152,7 @@ interface MediaVideoPlayerProps {
152 readonly expanded?: boolean;
153 readonly autoPlay?: boolean;
154 readonly paused?: boolean;
155 + readonly onPlaybackStart?: () => void;
156 readonly actionsSource?: MediaActionsSource;
157 }
158
@@ -138,6 +174,7 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
174 resolvePlaybackUri={props.resolvePlaybackUri}
175 playRequested={!props.expanded || props.autoPlay === true}
176 paused={(props.paused ?? false) || mediaActions.sharing}
177 + onPlaybackStart={props.onPlaybackStart}
178 />
179 ) : (
180 <MediaActionsMenu media={mediaActions} inModal={props.expanded} style={{ flex: 1 }}>
@@ -150,7 +187,10 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
187 accessibilityState={{ disabled: props.uri === null || props.unavailable === true }}
188 // Stays pressable so the long-press menu still opens on a failed or unsigned tile.
189 onPress={() => {
153 - if (props.uri !== null && !props.unavailable) setPlaybackUri(props.uri);
190 + if (props.uri !== null && !props.unavailable) {
191 + props.onPlaybackStart?.();
192 + setPlaybackUri(props.uri);
193 + }
194 }}
195 className="flex-1 items-center justify-center px-4"
196 >
apps/mobile/src/components/VideoPreviewModal.ios.tsx
+44
@@ -11,6 +11,12 @@ import { fullscreenVideoClosed, fullscreenVideoOpened } from "../lib/videoAudioS
11 import { mediaVideoPreviewUri, type VideoPreviewSource } from "../lib/videoPreviewSource";
12 import { useAssetUrlState, useRefreshAssetUrl } from "../state/assets";
13 import { usePreparedConnection } from "../state/session";
14 +import {
15 + acquireAudioSession,
16 + activateAudioSession,
17 + isAudioSessionOwner,
18 + releaseAudioSession,
19 +} from "../lib/audioSession";
20
21 export type { VideoPreviewSource } from "../lib/videoPreviewSource";
22
@@ -22,6 +28,10 @@ const NativeControls = requireNativeModule<{
28 identifier: string,
29 ): Promise<void>;
30 dismissVideo(identifier: string): Promise<void>;
31 + addListener(
32 + event: "videoPlaybackChange",
33 + listener: (event: { identifier: string; isPlaying: boolean }) => void,
34 + ): { remove(): void };
35 }>("T3NativeControls");
36
37 function NativeVideoPreview(props: {
@@ -71,6 +81,29 @@ function NativeVideoPreview(props: {
81 useEffect(() => {
82 if (localAttachment === null && playbackUrl === null) return;
83 const controller = new AbortController();
84 + let token: ReturnType<typeof acquireAudioSession> | null = null;
85 + const release = () => {
86 + if (token) void releaseAudioSession(token).catch(() => {});
87 + token = null;
88 + };
89 + const acquire = () => {
90 + const next = acquireAudioSession("playback", () => {
91 + release();
92 + void NativeControls.dismissVideo(identifier).catch(() => {});
93 + });
94 + if (!isAudioSessionOwner(next)) {
95 + void NativeControls.dismissVideo(identifier).catch(() => {});
96 + return null;
97 + }
98 + token = next;
99 + return next;
100 + };
101 + const subscription = NativeControls.addListener("videoPlaybackChange", (event) => {
102 + if (event.identifier !== identifier || controller.signal.aborted) return;
103 + if (event.isPlaying) {
104 + if (!token) acquire();
105 + } else release();
106 + });
107 let ready = false;
108 void (async () => {
109 const file =
@@ -82,6 +115,13 @@ function NativeVideoPreview(props: {
115 file?.dispose();
116 return;
117 }
118 + const current = acquire();
119 + if (!current || !(await activateAudioSession(current, true)) || controller.signal.aborted) {
120 + release();
121 + file?.dispose();
122 + if (!controller.signal.aborted) onRequestClose();
123 + return;
124 + }
125 ready = true;
126 const presented = await settlePromise(() =>
127 NativeControls.presentVideo(
@@ -93,9 +133,11 @@ function NativeVideoPreview(props: {
133 );
134 // Native completion follows dismissal, so local playback keeps its file lease.
135 file?.dispose();
136 + release();
137 if (AsyncResult.isFailure(presented)) throw squashAtomCommandFailure(presented);
138 if (!controller.signal.aborted) onRequestClose();
139 })().catch((error: unknown) => {
140 + release();
141 if (controller.signal.aborted) return;
142 // AVKit gives no retry, so re-mint now; the cached URL may simply have expired.
143 if (ready) void refreshAssetUrl();
@@ -111,6 +153,8 @@ function NativeVideoPreview(props: {
153 });
154 return () => {
155 controller.abort();
156 + subscription.remove();
157 + release();
158 void NativeControls.dismissVideo(identifier).catch(() => undefined);
159 };
160 }, [localAttachment, name, source.sourceIdentifier, playbackUrl, identifier]);
apps/mobile/src/components/ui/AppSymbol.tsx
+2
@@ -99,6 +99,7 @@ import IconPlug from "@tabler/icons-react-native/IconPlug";
99 import IconPhoto from "@tabler/icons-react-native/IconPhoto";
100 import IconPin from "@tabler/icons-react-native/IconPin";
101 import IconPinnedOff from "@tabler/icons-react-native/IconPinnedOff";
102 +import IconPlayerPause from "@tabler/icons-react-native/IconPlayerPause";
103 import IconPlayerPlay from "@tabler/icons-react-native/IconPlayerPlay";
104 import IconPlayerStopFilled from "@tabler/icons-react-native/IconPlayerStopFilled";
105 import IconPlus from "@tabler/icons-react-native/IconPlus";
@@ -240,6 +241,7 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
241 pin: IconPin,
242 "pin.slash": IconPinnedOff,
243 play: IconPlayerPlay,
244 + pause: IconPlayerPause,
245 plus: IconPlus,
246 minus: IconMinus,
247 "slash.circle": IconBan,
apps/mobile/src/features/files/AttachmentFileScreen.tsx
+3 -38
@@ -1,19 +1,18 @@
1 import { Toolbar } from "../../components/ui/Toolbar";
2 import * as Dialog from "../../components/ui/Dialog";
3 -/* oxlint-disable react/no-array-index-key -- Captured table rows and columns have stable positions and may contain identical values. */
3 import { NativeStackScreenOptions } from "../../native/StackHeader";
4 import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
5 import type { MenuAction } from "@react-native-menu/menu";
6 import { EnvironmentId } from "@t3tools/contracts";
7 import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
8 import { useEffect, useRef, useState } from "react";
10 -import { Platform, ScrollView, View } from "react-native";
9 +import { Platform, View } from "react-native";
10
11 import {
12 AndroidHeaderIconButton,
13 AndroidScreenHeader,
14 } from "../../components/ui/AndroidScreenHeader";
16 -import { AppText as Text } from "../../components/ui/AppText";
15 +import { DelimitedFilePreview } from "./DelimitedFilePreview";
16 import { AudioFilePreview } from "./AudioFilePreview";
17 import { Menu } from "../../components/ui/Menu";
18 import { EmptyState } from "../../components/ui/EmptyState";
@@ -89,41 +88,7 @@ function AttachmentDocumentBody(props: {
88 </FilePreviewNotice>
89 ) : null}
90 {table && document.activeMode === "table" ? (
92 - <ScrollView className="flex-1">
93 - {table.truncated ? (
94 - <FilePreviewNotice>
95 - Table limited to the first 100 rows and 30 columns. Source shows the rest.
96 - </FilePreviewNotice>
97 - ) : null}
98 - <ScrollView horizontal>
99 - <View>
100 - {table.rows.map((row, rowIndex) => (
101 - <View
102 - key={rowIndex}
103 - className={rowIndex === 0 ? "flex-row bg-subtle" : "flex-row"}
104 - >
105 - {row.map((cell, columnIndex) => (
106 - <View
107 - key={columnIndex}
108 - className="w-48 border-r border-b border-border px-3 py-2"
109 - >
110 - <Text
111 - selectable
112 - className={
113 - rowIndex === 0
114 - ? "text-sm font-t3-semibold text-foreground"
115 - : "text-sm text-foreground"
116 - }
117 - >
118 - {cell}
119 - </Text>
120 - </View>
121 - ))}
122 - </View>
123 - ))}
124 - </View>
125 - </ScrollView>
126 - </ScrollView>
91 + <DelimitedFilePreview table={table} />
92 ) : document.activeMode === "markdown" && props.environmentId ? (
93 <FileMarkdownPreview
94 cwd=""
apps/mobile/src/features/files/AudioFilePreview.tsx
+40 -18
@@ -1,9 +1,11 @@
1 import { Button } from "../../components/ui/Button";
2 -import { useAudioPlayer, useAudioPlayerStatus } from "expo-audio";
3 -import { useEffect, useState } from "react";
4 -import { View } from "react-native";
2 +import { useAudioPlayerStatus } from "expo-audio";
3 +import { useEffect, useMemo, useState } from "react";
4 +import { AppState, View } from "react-native";
5 import { AppText as Text } from "../../components/ui/AppText";
6 import { useFullscreenVideoOpen, useMediaAudioSessionHold } from "../../lib/videoAudioSession";
7 +import { createAudioPlaybackSession } from "../../lib/audioSession";
8 +import { usePlaybackAudioPlayer } from "../voice-input/usePlaybackAudioPlayer";
9
10 function timestamp(seconds: number) {
11 const value = Number.isFinite(seconds) ? Math.max(0, Math.floor(seconds)) : 0;
@@ -11,23 +13,33 @@ function timestamp(seconds: number) {
13 }
14
15 export function AudioFilePreview(props: { uri: string; onRetry: () => void }) {
14 - const player = useAudioPlayer({ uri: props.uri }, { updateInterval: 500 });
16 + const player = usePlaybackAudioPlayer(props.uri);
17 const status = useAudioPlayerStatus(player);
18 + const [playbackRequested, setPlaybackRequested] = useState(false);
19 + const playback = useMemo(
20 + () => createAudioPlaybackSession(player, false, setPlaybackRequested),
21 + [player],
22 + );
23 const [seekError, setSeekError] = useState(false);
24 // Video teardown deactivates the shared iOS session, which would stop this player.
25 useMediaAudioSessionHold(status.playing);
26 const fullscreenVideoOpen = useFullscreenVideoOpen();
27 useEffect(() => {
21 - if (fullscreenVideoOpen) player.pause();
22 - }, [fullscreenVideoOpen, player]);
23 - const seek = (seconds: number, play = false) => {
28 + if (fullscreenVideoOpen || status.didJustFinish || status.error) playback.pause();
29 + else playback.playingChanged(status.playing);
30 + }, [fullscreenVideoOpen, status.didJustFinish, status.error, status.playing, playback]);
31 + useEffect(() => {
32 + const subscription = AppState.addEventListener("change", (state) => {
33 + if (state !== "active") playback.pause();
34 + });
35 + return () => {
36 + subscription.remove();
37 + playback.pause();
38 + };
39 + }, [playback]);
40 + const seek = (seconds: number) => {
41 setSeekError(false);
25 - void player
26 - .seekTo(seconds)
27 - .then(() => {
28 - if (play) player.play();
29 - })
30 - .catch(() => setSeekError(true));
42 + void player.seekTo(seconds).catch(() => setSeekError(true));
43 };
44 return (
45 <View className="flex-1 items-center justify-center gap-5 p-6">
@@ -43,13 +55,23 @@ export function AudioFilePreview(props: { uri: string; onRetry: () => void }) {
55 onPress={() => seek(Math.max(0, status.currentTime - 15))}
56 />
57 <Button
46 - label={!status.isLoaded ? "Loading…" : status.playing ? "Pause" : "Play"}
58 + label={
59 + playbackRequested || status.playing ? "Pause" : !status.isLoaded ? "Loading…" : "Play"
60 + }
61 tone="secondary"
48 - disabled={!status.isLoaded}
62 + disabled={!status.isLoaded && !playbackRequested}
63 onPress={() => {
50 - if (status.playing) player.pause();
51 - else if (status.didJustFinish || status.currentTime >= status.duration) seek(0, true);
52 - else player.play();
64 + if (status.playing || playback.requested) playback.pause();
65 + else {
66 + setSeekError(false);
67 + void playback
68 + .play(
69 + status.didJustFinish || status.currentTime >= status.duration
70 + ? () => player.seekTo(0)
71 + : undefined,
72 + )
73 + .catch(() => setSeekError(true));
74 + }
75 }}
76 />
77 <Button
apps/mobile/src/features/files/DelimitedFilePreview.tsx new
+41
@@ -0,0 +1,41 @@
1 +/* oxlint-disable react/no-array-index-key -- Captured table cells have stable positions and may contain identical values. */
2 +import { ScrollView, View } from "react-native";
3 +import type { parseDelimitedPreview } from "@t3tools/shared/delimitedPreview";
4 +import { AppText as Text } from "../../components/ui/AppText";
5 +import { FilePreviewNotice } from "./FilePreviewFeedback";
6 +
7 +export function DelimitedFilePreview(props: {
8 + readonly table: ReturnType<typeof parseDelimitedPreview>;
9 +}) {
10 + return (
11 + <ScrollView className="flex-1">
12 + {props.table.truncated ? (
13 + <FilePreviewNotice>
14 + Table limited to the first 100 rows and 30 columns. Source shows the rest.
15 + </FilePreviewNotice>
16 + ) : null}
17 + <ScrollView horizontal>
18 + <View>
19 + {props.table.rows.map((row, rowIndex) => (
20 + <View key={rowIndex} className={rowIndex === 0 ? "flex-row bg-subtle" : "flex-row"}>
21 + {row.map((cell, columnIndex) => (
22 + <View key={columnIndex} className="w-48 border-r border-b border-border px-3 py-2">
23 + <Text
24 + selectable
25 + className={
26 + rowIndex === 0
27 + ? "text-sm font-t3-semibold text-foreground"
28 + : "text-sm text-foreground"
29 + }
30 + >
31 + {cell}
32 + </Text>
33 + </View>
34 + ))}
35 + </View>
36 + ))}
37 + </View>
38 + </ScrollView>
39 + </ScrollView>
40 + );
41 +}
apps/mobile/src/features/files/FileMarkdownPreview.tsx
+54 -4
@@ -3,6 +3,7 @@ import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
3 import { resolveMobileMarkdownMediaSource } from "../../lib/markdownMediaSource";
4 import { getBrowseDirectoryPath } from "@t3tools/client-runtime/state/projects";
5 import { useState } from "react";
6 +import { StackActions, useNavigation } from "@react-navigation/native";
7 import { RefreshControl, ScrollView, View } from "react-native";
8
9 import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
@@ -15,8 +16,12 @@ import {
16 ThreadMarkdownImageUnavailable,
17 } from "../threads/ThreadMarkdownImage";
18 import { ThreadMarkdownVideo } from "../threads/ThreadMarkdownVideo";
18 -import { resolveMarkdownMediaPreview } from "../../lib/markdownMedia";
19 -import { normalizeNativeMarkdownUrl } from "../../lib/markdownLinks";
19 +import { markdownFileEmbedLabel, resolveMarkdownMediaPreview } from "../../lib/markdownMedia";
20 +import {
21 + normalizeNativeMarkdownUrl,
22 + resolveMarkdownLinkPresentation,
23 +} from "../../lib/markdownLinks";
24 +import { AppText as Text } from "../../components/ui/AppText";
25 import { VideoPreviewModal, type VideoPreviewSource } from "../../components/VideoPreviewModal";
26 import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
27 import { useMarkdownImageSource } from "../../native/useMarkdownImageSource";
@@ -26,7 +31,7 @@ import {
31 type MarkdownImageRenderer,
32 type NativeMarkdownTextStyle,
33 } from "../../native/SelectableMarkdownText";
29 -import { resolveWorkspaceFilePath } from "./filePath";
34 +import { fileRoutePathSegments, resolveWorkspaceFilePath } from "./filePath";
35
36 interface MarkdownPreviewStyles {
37 readonly nativeTextStyle: NativeMarkdownTextStyle;
@@ -78,6 +83,7 @@ export function FileMarkdownPreview(props: {
83 readonly threadId: ThreadId | null;
84 readonly onRefresh?: () => Promise<void> | void;
85 }) {
86 + const navigation = useNavigation();
87 const [isPullRefreshing, setIsPullRefreshing] = useState(false);
88 const [expandedFile, setExpandedFile] = useState<FilePreviewSource | null>(null);
89 const [expandedVideo, setExpandedVideo] = useState<VideoPreviewSource | null>(null);
@@ -106,6 +112,24 @@ export function FileMarkdownPreview(props: {
112 captured: props.captured,
113 imageEmbed: true,
114 });
115 + const fileLink = resolveMarkdownLinkPresentation(image.href);
116 + if (
117 + (preview && preview.kind !== "image" && preview.kind !== "video") ||
118 + (!props.captured && fileLink.kind === "file" && fileLink.line !== undefined)
119 + ) {
120 + const name =
121 + preview?.source.name ?? (fileLink.kind === "file" ? fileLink.label : "Open file");
122 + return (
123 + <Text
124 + accessibilityRole="link"
125 + accessibilityLabel={`Open ${name}`}
126 + onPress={() => openMedia(image.href, true)}
127 + style={{ color: styles.nativeTextStyle.linkColor }}
128 + >
129 + {name}
130 + </Text>
131 + );
132 + }
133 if (media?.access === "direct") {
134 if (media.kind === "video") {
135 return (
@@ -169,7 +193,21 @@ export function FileMarkdownPreview(props: {
193 captured: props.captured,
194 imageEmbed,
195 });
172 - if (!media) return false;
196 + if (!media || media.kind === "file") {
197 + const fileLink = resolveMarkdownLinkPresentation(href);
198 + if (props.captured || fileLink.kind !== "file") return false;
199 + const params = {
200 + environmentId: String(props.environmentId),
201 + path: fileRoutePathSegments(resolveWorkspaceFilePath(markdownDirectory, fileLink.path)),
202 + ...(fileLink.line ? { line: String(fileLink.line) } : {}),
203 + };
204 + if (props.threadId) {
205 + navigation.navigate("ThreadFile", { ...params, threadId: String(props.threadId) });
206 + } else {
207 + navigation.dispatch(StackActions.push("NewTaskFile", { ...params, cwd: props.cwd }));
208 + }
209 + return true;
210 + }
211 if (media.kind === "video") setExpandedVideo(media.source);
212 else setExpandedFile(media.source);
213 return true;
@@ -198,6 +236,18 @@ export function FileMarkdownPreview(props: {
236 <View className="mx-auto w-full max-w-[760px]">
237 <SelectableMarkdownText
238 markdown={props.markdown}
239 + fileEmbedLabel={(href) =>
240 + markdownFileEmbedLabel(
241 + href,
242 + {
243 + environmentId: props.environmentId,
244 + threadId: props.threadId ?? undefined,
245 + workspaceRoot: markdownDirectory,
246 + captured: props.captured,
247 + },
248 + false,
249 + )
250 + }
251 onLinkPress={onLinkPress}
252 renderImage={renderImage}
253 resolveImageSource={resolveImageSource}
apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
+18 -7
@@ -18,6 +18,8 @@ import {
18 import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
19
20 import { ScreenContent } from "../../components/ui/ScreenContent";
21 +import { filePreviewDelimiter, parseDelimitedPreview } from "@t3tools/shared/delimitedPreview";
22 +import { DelimitedFilePreview } from "./DelimitedFilePreview";
23 import { AudioFilePreview } from "./AudioFilePreview";
24 import { EmptyState } from "../../components/ui/EmptyState";
25 import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
@@ -207,7 +209,8 @@ function defaultViewMode(path: string | null): FileViewMode {
209 (isWorkspaceBrowserPreviewPath(path) ||
210 isWorkspaceImagePreviewPath(path) ||
211 isVideoPreviewFile(path) ||
210 - isAudioPreviewFile(path))
212 + isAudioPreviewFile(path) ||
213 + filePreviewDelimiter({ name: path }) !== null)
214 ? "preview"
215 : "source";
216 }
@@ -237,6 +240,7 @@ function FileContent(props: {
240 const reservedHeaderInset =
241 Platform.OS === "ios" && props.truncated ? (columnMetrics?.safeArea.top ?? insets.top) : 0;
242 const isMarkdown = isMarkdownPreviewFile(props.relativePath);
243 + const delimiter = filePreviewDelimiter({ name: props.relativePath });
244 const isBrowserFile = isWorkspaceBrowserPreviewPath(props.relativePath);
245 const isImageFile = isWorkspaceImagePreviewPath(props.relativePath);
246 const isVideoFile = isVideoPreviewFile(props.relativePath);
@@ -312,7 +316,9 @@ function FileContent(props: {
316 Preview limited to the first 1 MB of a truncated file.
317 </FilePreviewNotice>
318 ) : null}
315 - {props.activeMode === "preview" && isMarkdown ? (
319 + {props.activeMode === "preview" && delimiter ? (
320 + <DelimitedFilePreview table={parseDelimitedPreview(props.fileContents, delimiter)} />
321 + ) : props.activeMode === "preview" && isMarkdown ? (
322 <FileMarkdownPreview
323 cwd={props.cwd}
324 environmentId={props.environmentId}
@@ -638,11 +644,14 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
644 isBrowserFile ||
645 isImageFile ||
646 isVideoFile ||
641 - isAudioFile);
647 + isAudioFile ||
648 + filePreviewDelimiter({ name: relativePath }) !== null);
649 const activeMode =
650 relativePath !== null && modeOverride?.path === relativePath
651 ? modeOverride.mode
645 - : defaultViewMode(relativePath);
652 + : targetLine !== null && filePreviewDelimiter({ name: relativePath ?? "" }) !== null
653 + ? "source"
654 + : defaultViewMode(relativePath);
655 const resolvedActiveMode =
656 isVideoFile || isAudioFile ? "preview" : canPreview ? activeMode : "source";
657 const assetPreviewPath =
@@ -706,7 +715,9 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
715 relativePath !== null &&
716 !isVideoFile &&
717 !isAudioFile &&
709 - (resolvedActiveMode === "source" || isMarkdownPreviewFile(relativePath));
718 + (resolvedActiveMode === "source" ||
719 + isMarkdownPreviewFile(relativePath) ||
720 + filePreviewDelimiter({ name: relativePath }) !== null);
721 const fileQuery = useEnvironmentQuery(
722 canReadFiles &&
723 environmentId !== null &&
@@ -777,8 +788,8 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
788 canToggleMode
789 ? ({
790 id: "preview",
780 - title: "Preview",
781 - icon: "eye",
791 + title: filePreviewDelimiter({ name: relativePath }) ? "Table" : "Preview",
792 + icon: filePreviewDelimiter({ name: relativePath }) ? "tablecells" : "eye",
793 inline: true,
794 onPress: () => setModeOverride({ path: relativePath, mode: "preview" }),
795 } as const)
apps/mobile/src/features/threads/ThreadFeed.tsx
+115 -67
@@ -132,7 +132,8 @@ import { assetImageSource } from "../../lib/assetImageSource";
132 import { composerImageGallery } from "../../lib/composerImageGallery";
133 import { messageImageGallery } from "./messageImageGallery";
134 import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
135 -import { isPdfFile } from "../../lib/filePreview";
135 +import { inlineFilePreviewKind, isPdfFile } from "../../lib/filePreview";
136 +import { ThreadInlineFilePreview } from "./ThreadInlineFilePreview";
137 import { flattenThemeColor } from "../../lib/mobileTheme";
138 import { PresentationSource } from "../../components/ui/NativePresentation";
139 import { NativeScrollViewMarker } from "../../native/NativeScrollViewMarker";
@@ -159,9 +160,8 @@ import {
160
161 import { AppText as Text } from "../../components/ui/AppText";
162 import { VideoPreviewModal, type VideoPreviewSource } from "../../components/VideoPreviewModal";
162 -import { VideoAttachmentTile } from "../../components/VideoAttachmentTile";
163 import { MediaVideoPlayer } from "../../components/MediaVideoPlayer";
164 -import { resolveMarkdownMediaPreview } from "../../lib/markdownMedia";
164 +import { markdownFileEmbedLabel, resolveMarkdownMediaPreview } from "../../lib/markdownMedia";
165 import {
166 attachmentVideoPreviewSource,
167 mediaVideoPreviewUri,
@@ -584,7 +584,7 @@ function MessageAttachmentFile(props: {
584 readonly environmentId: EnvironmentId;
585 readonly attachment: ChatFileAttachment;
586 readonly onPressPreview: (source: FilePreviewSource) => void;
587 - readonly onPressVideo: (attachment: ChatFileAttachment, sourceIdentifier: string) => void;
587 + readonly onPlaybackStart: () => void;
588 }) {
589 const sourceIdentifier = useId();
590 const navigation = useNavigation();
@@ -601,17 +601,6 @@ function MessageAttachmentFile(props: {
601 ? "PDF"
602 : (attachment.name.match(/\.([a-z0-9]{1,8})$/i)?.[1]?.toUpperCase() ?? "File");
603 const sizeLabel = formatAttachmentSize(attachment.sizeBytes);
604 - const thumbnailUrl = useAssetUrl(
605 - props.environmentId,
606 - videoType === null
607 - ? null
608 - : {
609 - _tag: "attachment",
610 - attachmentId: attachment.id,
611 - fileName: attachment.name,
612 - mimeType: videoType,
613 - },
614 - );
604 const httpBaseUrl = Option.isSome(preparedConnection)
605 ? preparedConnection.value.httpBaseUrl
606 : null;
@@ -677,22 +666,64 @@ function MessageAttachmentFile(props: {
666 })();
667 };
668
669 + const openAttachment = () =>
670 + isPdf
671 + ? props.onPressPreview({
672 + kind: "pdf",
673 + name: attachment.name,
674 + environmentId: props.environmentId,
675 + resource: {
676 + _tag: "attachment",
677 + attachmentId: attachment.id,
678 + fileName: attachment.name,
679 + mimeType: "application/pdf",
680 + },
681 + sourceIdentifier,
682 + })
683 + : navigation.navigate("ThreadAttachment", {
684 + environmentId: String(props.environmentId),
685 + ...(selectedThread ? { threadId: String(selectedThread.id) } : {}),
686 + attachmentId: attachment.id,
687 + name: attachment.name,
688 + mimeType: attachment.mimeType,
689 + sizeBytes: String(attachment.sizeBytes),
690 + });
691 + const inlineKind = inlineFilePreviewKind(attachment);
692 + if (inlineKind) {
693 + return (
694 + <PresentationSource identifier={sourceIdentifier}>
695 + <ThreadInlineFilePreview
696 + key={attachment.id}
697 + source={{
698 + kind: "document",
699 + name: attachment.name,
700 + mimeType: attachment.mimeType,
701 + environmentId: props.environmentId,
702 + resource: {
703 + _tag: "attachment",
704 + attachmentId: attachment.id,
705 + fileName: attachment.name,
706 + mimeType: attachment.mimeType,
707 + disposition: "inline",
708 + },
709 + }}
710 + sizeBytes={attachment.sizeBytes}
711 + onOpen={openAttachment}
712 + onPlaybackStart={props.onPlaybackStart}
713 + onLongPress={() => shareFile(sourceIdentifier)}
714 + />
715 + </PresentationSource>
716 + );
717 + }
718 +
719 if (videoType !== null) {
681 - const sourceIdentifier = `attachment:${props.environmentId}:${attachment.id}`;
720 return (
683 - <VideoAttachmentTile
684 - name={attachment.name}
685 - sourceIdentifier={sourceIdentifier}
686 - thumbnailSource={thumbnailUrl}
687 - actionsSource={
688 - attachmentVideoPreviewSource(props.environmentId, attachment, sourceIdentifier)
689 - .actionsSource
690 - }
691 - disabled={opening || httpBaseUrl === null}
692 - onPress={(sourceIdentifier) => props.onPressVideo(attachment, sourceIdentifier)}
693 - className="my-1 rounded-2xl"
694 - style={{ width: 224, maxWidth: "100%", aspectRatio: 16 / 9 }}
695 - />
721 + <View className="my-1" style={{ width: 224, maxWidth: "100%" }}>
722 + <ThreadMarkdownVideo
723 + source={attachmentVideoPreviewSource(props.environmentId, attachment, sourceIdentifier)}
724 + onPlaybackStart={props.onPlaybackStart}
725 + />
726 + </View>
727 );
728 }
729
@@ -711,29 +742,7 @@ function MessageAttachmentFile(props: {
742 disabled={opening || httpBaseUrl === null}
743 className="min-w-0 flex-row items-center gap-3 rounded-xl border border-border bg-card p-3 active:bg-subtle"
744 onLongPress={() => shareFile(sourceIdentifier)}
714 - onPress={() =>
715 - isPdf
716 - ? props.onPressPreview({
717 - kind: "pdf",
718 - name: attachment.name,
719 - environmentId: props.environmentId,
720 - resource: {
721 - _tag: "attachment",
722 - attachmentId: attachment.id,
723 - fileName: attachment.name,
724 - mimeType: "application/pdf",
725 - },
726 - sourceIdentifier,
727 - })
728 - : navigation.navigate("ThreadAttachment", {
729 - environmentId: String(props.environmentId),
730 - ...(selectedThread ? { threadId: String(selectedThread.id) } : {}),
731 - attachmentId: attachment.id,
732 - name: attachment.name,
733 - mimeType: attachment.mimeType,
734 - sizeBytes: String(attachment.sizeBytes),
735 - })
736 - }
745 + onPress={openAttachment}
746 >
747 <View className="h-12 w-10 shrink-0 items-center justify-center rounded-lg bg-subtle">
748 {opening ? (
@@ -767,7 +776,7 @@ function MessageAttachmentList(props: {
776 readonly attachments: ReadonlyArray<ChatAttachment>;
777 readonly environmentId: EnvironmentId;
778 readonly onPressPreview: (source: FilePreviewSource) => void;
770 - readonly onPressVideo: (attachment: ChatFileAttachment, sourceIdentifier: string) => void;
779 + readonly onPlaybackStart: () => void;
780 }) {
781 return props.attachments.map((attachment) =>
782 isImageAttachment(attachment) ? (
@@ -786,7 +795,7 @@ function MessageAttachmentList(props: {
795 environmentId={props.environmentId}
796 attachment={attachment}
797 onPressPreview={props.onPressPreview}
789 - onPressVideo={props.onPressVideo}
798 + onPlaybackStart={props.onPlaybackStart}
799 />
800 ) : (
801 <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
@@ -832,6 +841,7 @@ interface MarkdownLinkHandlers {
841 readonly onFileContextMenuAction: (href: string, actionId: string) => void;
842 readonly onImagePress?: (href: string) => void;
843 readonly resolveImageSource?: MarkdownImageSourceResolver;
844 + readonly fileEmbedLabel?: (href: string, standalone: boolean) => string | null;
845 readonly linkCustomization?: (href: string) => MarkdownLinkCustomization | undefined;
846 }
847
@@ -1262,7 +1272,7 @@ function renderFeedEntry(
1272 readonly onToggleTurnFold: (runId: RunId) => void;
1273 readonly onOpenTurnDiff: (checkpoint: ThreadCheckpointSummary) => void;
1274 readonly onPressPreview: (source: FilePreviewSource) => void;
1265 - readonly onPressVideo: (attachment: ChatFileAttachment, sourceIdentifier: string) => void;
1275 + readonly onPlaybackStart: () => void;
1276 readonly markdownLinkHandlers: MarkdownLinkHandlers;
1277 readonly renderMarkdownImage: MarkdownImageRenderer;
1278 readonly renderViewedImage: MarkdownImageRenderer;
@@ -1297,7 +1307,7 @@ function renderFeedEntry(
1307 attachments={attachments}
1308 environmentId={props.environmentId}
1309 onPressPreview={props.onPressPreview}
1300 - onPressVideo={props.onPressVideo}
1310 + onPlaybackStart={props.onPlaybackStart}
1311 />
1312 )}
1313 />
@@ -1646,7 +1656,7 @@ function renderFeedEntry(
1656 environmentId={props.environmentId}
1657 attachment={attachment}
1658 onPressPreview={props.onPressPreview}
1649 - onPressVideo={props.onPressVideo}
1659 + onPlaybackStart={props.onPlaybackStart}
1660 />
1661 ) : (
1662 <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
@@ -1779,7 +1789,7 @@ function renderFeedEntry(
1789 attachments={attachments}
1790 environmentId={props.environmentId}
1791 onPressPreview={props.onPressPreview}
1782 - onPressVideo={props.onPressVideo}
1792 + onPlaybackStart={props.onPlaybackStart}
1793 />
1794 {showAssistantMeta && message.checkpointSummary ? (
1795 <TurnDiffStat
@@ -2201,6 +2211,9 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2211 const [expandedFile, setExpandedFile] = useState<FilePreviewSource | null>(null);
2212 const [expandedVideo, setExpandedVideo] = useState<VideoPreviewSource | null>(null);
2213 const markdownLinkRequest = useRef<AbortController | null>(null);
2214 + const onInlinePlaybackStart = () => {
2215 + markdownLinkRequest.current?.abort();
2216 + };
2217 useFocusEffect(useCallback(() => () => markdownLinkRequest.current?.abort(), []));
2218 const markdownLinkScope = JSON.stringify([
2219 props.environmentId,
@@ -2297,7 +2310,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2310 workspaceRoot: props.workspaceRoot,
2311 imageEmbed,
2312 });
2300 - if (media) {
2313 + if (media && media.kind !== "file") {
2314 void Haptics.selectionAsync();
2315 const openPreview = () => {
2316 if (request.signal.aborted) return;
@@ -2419,6 +2432,16 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2432 workspaceRoot: props.workspaceRoot ?? null,
2433 });
2434 const markdownLinkHandlers: MarkdownLinkHandlers = {
2435 + fileEmbedLabel: (href, standalone) =>
2436 + markdownFileEmbedLabel(
2437 + href,
2438 + {
2439 + environmentId: props.environmentId,
2440 + threadId: props.threadId,
2441 + workspaceRoot: props.workspaceRoot,
2442 + },
2443 + standalone,
2444 + ),
2445 onLinkPress: onMarkdownLinkPress,
2446 linkCustomization: enrichedThreadLinkCustomization,
2447 onImagePress: (href) => onMarkdownLinkPress(href, true),
@@ -2495,9 +2518,41 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2518 <ThreadMarkdownVideo
2519 key={image.href}
2520 source={{ ...media.source, name: image.alt ?? media.source.name }}
2521 + onPlaybackStart={onInlinePlaybackStart}
2522 + />
2523 + );
2524 + }
2525 + if (media?.kind === "audio") {
2526 + return (
2527 + <ThreadInlineFilePreview
2528 + key={image.href}
2529 + source={media.source}
2530 + onOpen={() => onMarkdownLinkPress(image.href, true)}
2531 + onPlaybackStart={onInlinePlaybackStart}
2532 />
2533 );
2534 }
2535 + const fileLink = resolveMarkdownLinkPresentation(image.href);
2536 + if (
2537 + (media && (media.kind === "pdf" || media.kind === "document" || media.kind === "file")) ||
2538 + (fileLink.kind === "file" && fileLink.line !== undefined)
2539 + ) {
2540 + const name = media?.source.name ?? (fileLink.kind === "file" ? fileLink.label : "Open file");
2541 + return (
2542 + <Text
2543 + accessibilityRole="link"
2544 + accessibilityLabel={`Open ${name}`}
2545 + onPress={() => onMarkdownLinkPress(image.href, true)}
2546 + style={{
2547 + color: markdownStyles.assistant.nativeTextStyle.linkColor,
2548 + fontSize: markdownStyles.assistant.nativeTextStyle.fontSize,
2549 + lineHeight: markdownStyles.assistant.nativeTextStyle.lineHeight,
2550 + }}
2551 + >
2552 + {name}
2553 + </Text>
2554 + );
2555 + }
2556 const imageSource = classifyMarkdownImageSource(image.href, props.workspaceRoot ?? null);
2557 if (imageSource._tag === "Direct") {
2558 return (
@@ -2971,13 +3026,6 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3026 markdownLinkRequest.current?.abort();
3027 setExpandedFile((current) => current ?? source);
3028 };
2974 - const onPressVideo = (attachment: ChatFileAttachment, sourceIdentifier: string) => {
2975 - markdownLinkRequest.current?.abort();
2976 - setExpandedVideo(
2977 - (current) =>
2978 - current ?? attachmentVideoPreviewSource(props.environmentId, attachment, sourceIdentifier),
2979 - );
2980 - };
3029
3030 // Without this, every row above the viewport is assumed to be
3031 // estimatedItemSize tall, and scrolling up through unmeasured content
@@ -3061,7 +3109,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3109 onToggleTurnFold,
3110 onOpenTurnDiff,
3111 onPressPreview,
3064 - onPressVideo,
3112 + onPlaybackStart: onInlinePlaybackStart,
3113 markdownLinkHandlers,
3114 renderMarkdownImage,
3115 renderViewedImage,
apps/mobile/src/features/threads/ThreadInlineFilePreview.tsx new
+254
@@ -0,0 +1,254 @@
1 +import { useIsFocused } from "@react-navigation/native";
2 +import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
3 +import { useAudioPlayerStatus } from "expo-audio";
4 +import { useCallback, useContext, useEffect, useRef, useState } from "react";
5 +import { AppState, Pressable, View } from "react-native";
6 +import type { FilePreviewSource } from "../../components/FilePreviewModal";
7 +import { filePreviewKey } from "../../lib/filePreviewGallery";
8 +import { PierreEntryIcon } from "../../components/PierreEntryIcon";
9 +import { AppText as Text } from "../../components/ui/AppText";
10 +import { SymbolView } from "../../components/ui/AppSymbol";
11 +import { useFullscreenVideoOpen, useMediaAudioSessionHold } from "../../lib/videoAudioSession";
12 +import { useRefreshAssetUrl } from "../../state/assets";
13 +import { ThreadMediaVisibleContext } from "./ThreadMarkdownVideo";
14 +import {
15 + acquireAudioSession,
16 + activateAudioSession,
17 + isAudioSessionOwner,
18 + pauseAudioPlayer,
19 + releaseAudioSession,
20 +} from "../../lib/audioSession";
21 +import { usePlaybackAudioPlayer } from "../voice-input/usePlaybackAudioPlayer";
22 +
23 +type PreviewProps = {
24 + readonly source: FilePreviewSource;
25 + readonly sizeBytes?: number;
26 + readonly onOpen: () => void;
27 + readonly onPlaybackStart?: () => void;
28 + readonly onLongPress?: () => void;
29 +};
30 +
31 +function FileCardHeader(props: PreviewProps) {
32 + return (
33 + <Pressable
34 + accessibilityRole="button"
35 + accessibilityLabel={`Open ${props.source.name}`}
36 + onPress={props.onOpen}
37 + onLongPress={props.onLongPress}
38 + className="h-[72px] flex-row items-center gap-3 p-3 active:bg-subtle"
39 + >
40 + <View className="h-12 w-10 shrink-0 items-center justify-center rounded-lg bg-subtle">
41 + <PierreEntryIcon path={props.source.name ?? "file"} kind="file" size={26} />
42 + </View>
43 + <View className="min-w-0 flex-1 gap-1">
44 + <Text className="text-sm font-t3-medium text-foreground" numberOfLines={1}>
45 + {props.source.name}
46 + </Text>
47 + <Text className="text-xs text-foreground-muted" numberOfLines={1}>
48 + Audio
49 + {props.sizeBytes !== undefined ? ` · ${formatAttachmentSize(props.sizeBytes)}` : ""}
50 + </Text>
51 + </View>
52 + <SymbolView name="chevron.right" size={12} tintColorClassName="accent-foreground-muted" />
53 + </Pressable>
54 + );
55 +}
56 +
57 +function timestamp(seconds: number) {
58 + const value = Number.isFinite(seconds) ? Math.max(0, Math.floor(seconds)) : 0;
59 + return `${Math.floor(value / 60)}:${String(value % 60).padStart(2, "0")}`;
60 +}
61 +
62 +function InlineAudio(props: PreviewProps & { readonly resolveUri: () => Promise<string | null> }) {
63 + // An empty source keeps native buffering off until the user explicitly plays.
64 + const player = usePlaybackAudioPlayer(null);
65 + const status = useAudioPlayerStatus(player);
66 + const [loading, setLoading] = useState(false);
67 + const [error, setError] = useState(false);
68 + const active = useRef(true);
69 + const requestGeneration = useRef(0);
70 + const playRequested = useRef(false);
71 + const audioToken = useRef<ReturnType<typeof acquireAudioSession> | null>(null);
72 + const [playbackRequested, setPlaybackRequested] = useState(false);
73 + const requestPlayback = useCallback((requested: boolean) => {
74 + playRequested.current = requested;
75 + setPlaybackRequested(requested);
76 + if (!requested) {
77 + requestGeneration.current += 1;
78 + setLoading(false);
79 + if (audioToken.current) {
80 + void releaseAudioSession(audioToken.current).catch(() => {});
81 + audioToken.current = null;
82 + }
83 + }
84 + }, []);
85 + useMediaAudioSessionHold(status.playing);
86 + const fullscreenVideoOpen = useFullscreenVideoOpen();
87 + useEffect(() => {
88 + if (fullscreenVideoOpen || status.didJustFinish || status.error) {
89 + // oxlint-disable-next-line react/set-state-in-effect -- Native completion and fullscreen takeover invalidate the pending playback request.
90 + requestPlayback(false);
91 + }
92 + if (fullscreenVideoOpen) pauseAudioPlayer(player);
93 + }, [fullscreenVideoOpen, status.didJustFinish, status.error, player, requestPlayback]);
94 + useEffect(() => {
95 + active.current = true;
96 + const subscription = AppState.addEventListener("change", (state) => {
97 + if (state !== "active") {
98 + requestPlayback(false);
99 + pauseAudioPlayer(player);
100 + }
101 + });
102 + return () => {
103 + active.current = false;
104 + playRequested.current = false;
105 + requestGeneration.current += 1;
106 + if (audioToken.current) {
107 + void releaseAudioSession(audioToken.current).catch(() => {});
108 + audioToken.current = null;
109 + }
110 + subscription.remove();
111 + };
112 + }, [player, requestPlayback]);
113 + const toggle = () => {
114 + if (status.playing || playRequested.current) {
115 + requestPlayback(false);
116 + return pauseAudioPlayer(player);
117 + }
118 + const token = acquireAudioSession(
119 + "playback",
120 + () => {
121 + requestPlayback(false);
122 + pauseAudioPlayer(player);
123 + },
124 + () => {
125 + try {
126 + pauseAudioPlayer(player);
127 + } catch {}
128 + },
129 + );
130 + if (!isAudioSessionOwner(token)) return;
131 + props.onPlaybackStart?.();
132 + audioToken.current = token;
133 + requestPlayback(true);
134 + const generation = ++requestGeneration.current;
135 + const isCurrentRequest = () =>
136 + active.current &&
137 + playRequested.current &&
138 + requestGeneration.current === generation &&
139 + isAudioSessionOwner(token);
140 + setLoading(true);
141 + setError(false);
142 + void Promise.resolve()
143 + .then(async () => {
144 + if (!isCurrentRequest()) return;
145 + if (!status.isLoaded || status.error) {
146 + const uri = await props.resolveUri();
147 + if (!isCurrentRequest() || AppState.currentState !== "active") return;
148 + if (!uri) {
149 + requestPlayback(false);
150 + setError(true);
151 + return;
152 + }
153 + player.replace({ uri });
154 + } else if (status.didJustFinish || status.currentTime >= status.duration) {
155 + await player.seekTo(0);
156 + }
157 + if (!isCurrentRequest() || AppState.currentState !== "active") return;
158 + await activateAudioSession(token);
159 + if (isCurrentRequest() && AppState.currentState === "active") player.play();
160 + })
161 + .catch(() => {
162 + if (isCurrentRequest()) {
163 + requestPlayback(false);
164 + setError(true);
165 + }
166 + })
167 + .finally(() => {
168 + if (isCurrentRequest()) setLoading(false);
169 + });
170 + };
171 + const progress =
172 + status.duration > 0 ? Math.min(1, Math.max(0, status.currentTime / status.duration)) : 0;
173 + const playing = playbackRequested || status.playing;
174 + const busy = loading || (playbackRequested && status.isBuffering);
175 + return (
176 + <>
177 + <FileCardHeader
178 + {...props}
179 + onOpen={() => {
180 + requestPlayback(false);
181 + pauseAudioPlayer(player);
182 + props.onOpen();
183 + }}
184 + />
185 + <View className="h-14 flex-row items-center gap-3 px-3 pb-2">
186 + <Pressable
187 + accessibilityRole="button"
188 + accessibilityLabel={
189 + playing ? "Pause audio" : error || status.error ? "Retry audio" : "Play audio"
190 + }
191 + accessibilityState={{ busy }}
192 + onPress={toggle}
193 + className="h-11 w-11 items-center justify-center rounded-lg bg-subtle"
194 + >
195 + <SymbolView
196 + name={playing ? "pause" : "play"}
197 + size={18}
198 + tintColorClassName="accent-foreground"
199 + />
200 + </Pressable>
201 + <View className="min-w-0 flex-1 gap-2">
202 + <View
203 + accessibilityRole="progressbar"
204 + accessibilityValue={{ min: 0, max: status.duration || 0, now: status.currentTime }}
205 + className="h-1 overflow-hidden rounded-full bg-subtle"
206 + >
207 + <View className="h-1 bg-foreground-muted" style={{ width: `${progress * 100}%` }} />
208 + </View>
209 + <Text className="text-xs text-foreground-muted" numberOfLines={1}>
210 + {error || status.error
211 + ? "Unavailable · tap play to retry"
212 + : busy
213 + ? "Loading…"
214 + : `${timestamp(status.currentTime)} / ${status.isLoaded ? timestamp(status.duration) : "--:--"}`}
215 + </Text>
216 + </View>
217 + </View>
218 + </>
219 + );
220 +}
221 +
222 +function VisibleFilePreview(props: PreviewProps) {
223 + // Each mounted preview owns its source; feed streaming must not restart a fetch or player.
224 + const [source] = useState(props.source);
225 + const refresh = useRefreshAssetUrl(
226 + "environmentId" in source ? source.environmentId : null,
227 + "resource" in source ? source.resource : null,
228 + );
229 + const resolveUri = useCallback(
230 + () => ("uri" in source ? Promise.resolve(source.uri) : refresh()),
231 + [source, refresh],
232 + );
233 + return <InlineAudio {...props} resolveUri={resolveUri} />;
234 +}
235 +
236 +export function ThreadInlineFilePreview(props: PreviewProps) {
237 + const visible = useContext(ThreadMediaVisibleContext);
238 + const focused = useIsFocused();
239 + return (
240 + <View
241 + className="my-1 overflow-hidden rounded-xl border border-border bg-card"
242 + style={{ width: 280, maxWidth: "100%" }}
243 + >
244 + {visible && focused ? (
245 + <VisibleFilePreview key={filePreviewKey(props.source)} {...props} />
246 + ) : (
247 + <>
248 + <FileCardHeader {...props} />
249 + <View className="h-14" />
250 + </>
251 + )}
252 + </View>
253 + );
254 +}
apps/mobile/src/features/threads/ThreadMarkdownVideo.tsx
+3
@@ -12,6 +12,7 @@ export const ThreadMediaVisibleContext = createContext(false);
12 export function ThreadMarkdownVideo(props: {
13 readonly source: MediaVideoPreviewSource;
14 readonly thumbnailVisible?: boolean;
15 + readonly onPlaybackStart?: () => void;
16 }) {
17 const { source } = props;
18 const feedVisible = useContext(ThreadMediaVisibleContext);
@@ -38,6 +39,8 @@ export function ThreadMarkdownVideo(props: {
39 name={source.name}
40 thumbnailKey={thumbnailKey}
41 thumbnailVisible={visible}
42 + paused={!visible}
43 + onPlaybackStart={props.onPlaybackStart}
44 unavailable={"resource" in source && asset._tag === "Failure"}
45 actionsSource={source.actionsSource}
46 />
apps/mobile/src/features/voice-input/VoiceInputProvider.tsx
+20 -30
@@ -3,8 +3,6 @@ import {
3 AudioModule,
4 RecordingPresets,
5 requestRecordingPermissionsAsync,
6 - setAudioModeAsync,
7 - setIsAudioActiveAsync,
6 type RecorderState,
7 type RecordingStatus,
8 } from "expo-audio";
@@ -40,6 +38,11 @@ import {
38 import { createLazyVoiceRecorder, type LazyVoiceRecorder } from "./lazyVoiceRecorder";
39 import { normalizeVoiceInputDecibels, VOICE_WAVEFORM_SAMPLE_COUNT } from "./voiceInputMetering";
40 import { VoiceInputSession } from "./voiceInputSession";
41 +import {
42 + acquireAudioSession,
43 + activateAudioSession,
44 + releaseAudioSession,
45 +} from "../../lib/audioSession";
46
47 const INITIAL_STATE: VoiceInputState = { phase: "idle", error: null, errorAction: null };
48 const VOICE_METERING_INTERVAL_MS = 80;
@@ -55,32 +58,6 @@ const VOICE_RECORDING_OPTIONS = {
58 ...(Platform.OS === "ios" ? IOS_RECORDING_OPTIONS : ANDROID_RECORDING_OPTIONS),
59 };
60
58 -async function releaseVoiceRecordingAudio(): Promise<void> {
59 - try {
60 - await setAudioModeAsync({ allowsRecording: false });
61 - } finally {
62 - // Expo never deactivates AVAudioSession after recording; do so to resume interrupted audio.
63 - await setIsAudioActiveAsync(false);
64 - }
65 -}
66 -
67 -async function configureVoiceRecordingAudio(): Promise<void> {
68 - try {
69 - await setAudioModeAsync({
70 - allowsRecording: true,
71 - interruptionMode: "doNotMix",
72 - playsInSilentMode: true,
73 - shouldPlayInBackground: false,
74 - });
75 - await setIsAudioActiveAsync(true);
76 - } catch (error) {
77 - try {
78 - await releaseVoiceRecordingAudio();
79 - } catch {}
80 - throw error;
81 - }
82 -}
83 -
61 const VoiceInputContext = createContext<ReturnType<typeof useVoiceInputRuntime> | null>(null);
62
63 export function VoiceInputProvider({ children }: { readonly children: ReactNode }) {
@@ -120,6 +97,7 @@ function useVoiceInputRuntime() {
97 const audioLevels = useSharedValue(audioLevelsRef.current);
98 const sessionRef = useRef<VoiceInputSession | null>(null);
99 const recorderRef = useRef<LazyVoiceRecorder<RecorderState> | null>(null);
100 + const audioToken = useRef<ReturnType<typeof acquireAudioSession> | null>(null);
101
102 if (!sessionRef.current || !recorderRef.current) {
103 const recorder = createLazyVoiceRecorder({
@@ -156,8 +134,20 @@ function useVoiceInputRuntime() {
134 const permission = await requestRecordingPermissionsAsync();
135 return { granted: permission.granted, canAskAgain: permission.canAskAgain };
136 },
159 - configureRecording: configureVoiceRecordingAudio,
160 - releaseRecording: releaseVoiceRecordingAudio,
137 + configureRecording: async () => {
138 + const token = acquireAudioSession("recording");
139 + audioToken.current = token;
140 + try {
141 + await activateAudioSession(token);
142 + } catch (error) {
143 + await releaseAudioSession(token).catch(() => {});
144 + throw error;
145 + }
146 + },
147 + releaseRecording: async () => {
148 + if (audioToken.current) await releaseAudioSession(audioToken.current);
149 + audioToken.current = null;
150 + },
151 deleteRecording: (uri) => new File(uri).delete(),
152 onStateChange: (nextState) =>
153 setState({
apps/mobile/src/features/voice-input/usePlaybackAudioPlayer.ts new
+14
@@ -0,0 +1,14 @@
1 +import { useReleasingSharedObjectWithLifecycle } from "expo";
2 +import { createAudioPlayer } from "expo-audio";
3 +import { disposeAudioPlayer } from "../../lib/audioSession";
4 +
5 +export function usePlaybackAudioPlayer(uri: string | null) {
6 + // Keep the native ref alive until any pending activation and release finish.
7 + return useReleasingSharedObjectWithLifecycle(
8 + {
9 + factory: () => createAudioPlayer(uri, { updateInterval: 500 }),
10 + release: disposeAudioPlayer,
11 + },
12 + [uri],
13 + );
14 +}
apps/mobile/src/features/voice-input/voiceInputSession.test.ts
+92 -1
@@ -2,6 +2,22 @@ import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2 import type { PreparedVoiceTranscription } from "@t3tools/client-runtime/voice-input";
3 import { Atom, AtomRegistry } from "effect/reactivity";
4 import { resetVoiceInputGlobalsForTests } from "../../../../../packages/client-runtime/src/voice-input/controller";
5 +import {
6 + acquireAudioSession,
7 + activateAudioSession,
8 + isAudioSessionOwner,
9 + releaseAudioSession,
10 +} from "../../lib/audioSession";
11 +
12 +const audio = vi.hoisted(() => ({
13 + setMode: vi.fn(async (_mode: unknown) => {}),
14 + setActive: vi.fn(async (_active: boolean) => {}),
15 +}));
16 +vi.mock("expo-audio", () => ({
17 + AudioModule: {},
18 + setAudioModeAsync: audio.setMode,
19 + setIsAudioActiveAsync: audio.setActive,
20 +}));
21
22 import {
23 createVoiceInputTarget,
@@ -18,7 +34,10 @@ function createTarget(
34 return createVoiceInputTarget(ownerKey, readText, commit, selection, () => () => {});
35 }
36
21 -function createSession() {
37 +function createSession(recordingAudio?: {
38 + configureRecording: () => Promise<void>;
39 + releaseRecording: () => Promise<void>;
40 +}) {
41 const recorder = {
42 uri: "file:///voice.m4a",
43 prepareToRecordAsync: vi.fn(async () => {}),
@@ -35,6 +54,7 @@ function createSession() {
54 requestPermission: async () => ({ granted: true, canAskAgain: true }),
55 configureRecording: async () => {},
56 releaseRecording: vi.fn(async () => {}),
57 + ...recordingAudio,
58 deleteRecording: vi.fn(),
59 onStateChange: vi.fn(),
60 });
@@ -44,6 +64,77 @@ function createSession() {
64 describe("global voice input", () => {
65 beforeEach(() => resetVoiceInputGlobalsForTests());
66
67 + it.each(["retry", "takeover"])(
68 + "handles failed deactivation with %s without notifying a released owner",
69 + async (action) => {
70 + const pause = vi.fn();
71 + const playback = acquireAudioSession("recording", pause);
72 + await activateAudioSession(playback);
73 + audio.setActive.mockRejectedValueOnce(new Error("Deactivation failed"));
74 + await expect(releaseAudioSession(playback)).rejects.toThrow("Deactivation failed");
75 + if (action === "retry") {
76 + await releaseAudioSession(playback);
77 + expect(audio.setActive).toHaveBeenLastCalledWith(false);
78 + }
79 + const recording = acquireAudioSession("recording");
80 + expect(pause).not.toHaveBeenCalled();
81 + await releaseAudioSession(recording);
82 + vi.clearAllMocks();
83 + },
84 + );
85 +
86 + it.each(["complete", "activation failure"])(
87 + "protects recording from inline playback and releases its session after %s",
88 + async (outcome) => {
89 + const pause = vi.fn();
90 + const playback = acquireAudioSession("playback", pause);
91 + await activateAudioSession(playback);
92 + let recording!: ReturnType<typeof acquireAudioSession>;
93 + const { session, recorder } = createSession({
94 + configureRecording: async () => {
95 + recording = acquireAudioSession("recording");
96 + try {
97 + await activateAudioSession(recording);
98 + } catch (error) {
99 + await releaseAudioSession(recording);
100 + throw error;
101 + }
102 + },
103 + releaseRecording: () => releaseAudioSession(recording),
104 + });
105 + if (outcome === "activation failure") {
106 + audio.setActive.mockRejectedValueOnce(new Error("Audio activation failed"));
107 + }
108 + await session.start(createTarget("first", () => "", vi.fn(), { start: 0, end: 0 }));
109 + expect(pause).toHaveBeenCalledOnce();
110 + expect(isAudioSessionOwner(playback)).toBe(false);
111 + if (outcome === "complete") {
112 + expect(recorder.record).toHaveBeenCalledOnce();
113 + expect(session.controller.currentState.phase).toBe("recording");
114 + audio.setMode.mockClear();
115 + audio.setActive.mockClear();
116 + await releaseAudioSession(playback);
117 + const blockedPlayback = acquireAudioSession("playback");
118 + expect(await activateAudioSession(blockedPlayback)).toBe(false);
119 + await releaseAudioSession(blockedPlayback);
120 + expect(audio.setMode).not.toHaveBeenCalled();
121 + expect(audio.setActive).not.toHaveBeenCalled();
122 + expect(isAudioSessionOwner(recording)).toBe(true);
123 + await session.controller.stop();
124 + } else {
125 + expect(recorder.record).not.toHaveBeenCalled();
126 + expect(session.controller.currentState.phase).toBe("error");
127 + }
128 + expect(audio.setActive).toHaveBeenLastCalledWith(false);
129 + expect(isAudioSessionOwner(recording)).toBe(false);
130 + const replay = acquireAudioSession("playback");
131 + expect(await activateAudioSession(replay)).toBe(true);
132 + expect(audio.setActive).toHaveBeenLastCalledWith(true);
133 + await releaseAudioSession(replay);
134 + vi.clearAllMocks();
135 + },
136 + );
137 +
138 it.each([
139 { selection: { start: 6, end: 11 }, expected: "hello spoken text", cursor: 17 },
140 { selection: { start: 6, end: 6 }, expected: "hello spoken text world", cursor: 18 },
apps/mobile/src/lib/audioSession.ts new
+158
@@ -0,0 +1,158 @@
1 +import { AudioModule, setAudioModeAsync, setIsAudioActiveAsync } from "expo-audio";
2 +
3 +type AudioSessionToken = {
4 + readonly kind: "playback" | "recording";
5 + readonly onCancel?: () => void;
6 + readonly onRelease?: () => void;
7 + released: boolean;
8 +};
9 +
10 +let owner: AudioSessionToken | null = null;
11 +let pending = Promise.resolve();
12 +
13 +// Native session calls are async. Finish an old activation before releasing it
14 +// or configuring its successor, so it cannot reactivate a released session.
15 +function enqueue<T>(operation: () => Promise<T>): Promise<T> {
16 + const result = pending.then(operation);
17 + pending = result.then(
18 + () => {},
19 + () => {},
20 + );
21 + return result;
22 +}
23 +
24 +export function pauseAudioPlayer(player: { pause(deactivateSession?: boolean): void }): void {
25 + // Expo Audio otherwise deactivates iOS's shared session 100 ms after pause,
26 + // even when a video or recorder has already taken ownership.
27 + if (owner && !owner.released) player.pause(false);
28 + else player.pause();
29 +}
30 +
31 +export function disposeAudioPlayer(player: {
32 + pause(deactivateSession?: boolean): void;
33 + release(): void;
34 +}): void {
35 + void enqueue(async () => {
36 + try {
37 + pauseAudioPlayer(player);
38 + } finally {
39 + player.release();
40 + }
41 + }).catch(() => {});
42 +}
43 +
44 +export function acquireAudioSession(
45 + kind: AudioSessionToken["kind"],
46 + onCancel?: () => void,
47 + onRelease?: () => void,
48 +) {
49 + const token: AudioSessionToken = { kind, onCancel, onRelease, released: false };
50 + if (kind === "playback" && owner?.kind === "recording" && !owner.released) return token;
51 + const previous = owner;
52 + // Publish before cancelling the old player, including callbacks already queued by Expo.
53 + AudioModule.setAudioSessionOwner?.(true);
54 + owner = token;
55 + if (previous && !previous.released) previous.onCancel?.();
56 + return token;
57 +}
58 +
59 +export function isAudioSessionOwner(token: AudioSessionToken): boolean {
60 + return owner === token && !token.released;
61 +}
62 +
63 +export function activateAudioSession(
64 + token: AudioSessionToken,
65 + nativePlayback = false,
66 +): Promise<boolean> {
67 + return enqueue(async () => {
68 + if (!isAudioSessionOwner(token)) return false;
69 + // Video configures and activates its own native session, including moviePlayback on iOS.
70 + if (nativePlayback) return true;
71 + await setAudioModeAsync({
72 + allowsRecording: token.kind === "recording",
73 + interruptionMode: "doNotMix",
74 + playsInSilentMode: true,
75 + shouldPlayInBackground: false,
76 + });
77 + if (!isAudioSessionOwner(token)) return false;
78 + await setIsAudioActiveAsync(true);
79 + return isAudioSessionOwner(token);
80 + });
81 +}
82 +
83 +export function releaseAudioSession(token: AudioSessionToken): Promise<void> {
84 + token.released = true;
85 + return enqueue(async () => {
86 + if (owner !== token) return;
87 + try {
88 + if (token.kind === "recording") await setAudioModeAsync({ allowsRecording: false });
89 + } finally {
90 + if (owner === token) {
91 + if (token.kind === "recording") await setIsAudioActiveAsync(false);
92 + // Expo pause releases the native session without disabling its global playback gate.
93 + // Repeat it after any pending activation, even if playback never started.
94 + token.onRelease?.();
95 + if (owner === token) {
96 + AudioModule.setAudioSessionOwner?.(false);
97 + owner = null;
98 + }
99 + }
100 + }
101 + });
102 +}
103 +
104 +export function createAudioPlaybackSession(
105 + player: { play(): void; pause(deactivateSession?: boolean): void },
106 + nativePlayback = false,
107 + onRequestedChange?: (requested: boolean) => void,
108 +) {
109 + let token: AudioSessionToken | null = null;
110 + const stopPlayer = () => {
111 + // useAudioPlayer/useVideoPlayer may have disposed the native ref during unmount.
112 + try {
113 + if (nativePlayback) player.pause();
114 + else pauseAudioPlayer(player);
115 + } catch {}
116 + };
117 + const pause = () => {
118 + const previous = token;
119 + token = null;
120 + onRequestedChange?.(false);
121 + stopPlayer();
122 + if (previous) void releaseAudioSession(previous).catch(() => {});
123 + };
124 + const acquire = () => {
125 + const next = acquireAudioSession("playback", pause, stopPlayer);
126 + if (!isAudioSessionOwner(next)) {
127 + stopPlayer();
128 + return null;
129 + }
130 + token = next;
131 + onRequestedChange?.(true);
132 + return next;
133 + };
134 + return {
135 + pause,
136 + get requested() {
137 + return token !== null;
138 + },
139 + async play(prepare?: () => Promise<void>) {
140 + const current = token ?? acquire();
141 + if (!current) return;
142 + try {
143 + await prepare?.();
144 + if (!(await activateAudioSession(current, nativePlayback))) return;
145 + if (token !== current || !isAudioSessionOwner(current)) return;
146 + player.play();
147 + } catch (error) {
148 + if (token === current) pause();
149 + throw error;
150 + }
151 + },
152 + // A stopped clock is also reported during buffering and seeks. Native
153 + // pause intent must call pause() separately from playingChange.
154 + playingChanged(playing: boolean) {
155 + if (playing && token === null) acquire();
156 + },
157 + };
158 +}
apps/mobile/src/lib/filePreview.test.ts
+1293 -2
@@ -1,6 +1,1275 @@
1 -import { describe, expect, it } from "vite-plus/test";
1 +import { act, createElement, useEffect, useMemo, type ReactNode } from "react";
2 +import { createRoot } from "react-dom/client";
3 +import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
4
3 -import { isPdfFile } from "./filePreview";
5 +import { inlineFilePreviewKind, isPdfFile } from "./filePreview";
6 +import { ThreadInlineFilePreview } from "../features/threads/ThreadInlineFilePreview";
7 +import { AudioFilePreview } from "../features/files/AudioFilePreview";
8 +import { MediaVideoPlayer } from "../components/MediaVideoPlayer";
9 +import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
10 +import { acquireAudioSession, activateAudioSession, releaseAudioSession } from "./audioSession";
11 +import { ThreadFeed } from "../features/threads/ThreadFeed";
12 +import type { ThreadFeedEntry } from "./threadActivity";
13 +import type { MarkdownImageRenderer } from "../native/SelectableMarkdownText";
14 +
15 +const audio = vi.hoisted(() => ({
16 + status: {
17 + playing: false,
18 + isLoaded: false,
19 + error: null,
20 + didJustFinish: false,
21 + currentTime: 0,
22 + duration: 10,
23 + isBuffering: false,
24 + },
25 + player: {
26 + play: vi.fn(),
27 + pause: vi.fn((_deactivateSession?: boolean) => {}),
28 + release: vi.fn(),
29 + replace: vi.fn(),
30 + seekTo: vi.fn(async () => {}),
31 + },
32 + refresh: vi.fn<() => Promise<string | null>>(),
33 + setAudioMode: vi.fn(async (_mode: unknown) => {}),
34 + setActive: vi.fn(async (_active: boolean) => {}),
35 + setSessionOwner: vi.fn((_owned: boolean) => {}),
36 + sessionOwned: false,
37 + enabled: true,
38 + played: vi.fn(),
39 + video: {
40 + playing: false,
41 + playbackRequested: false,
42 + status: "readyToPlay",
43 + play: vi.fn(),
44 + pause: vi.fn(),
45 + replaceAsync: vi.fn(async (_source: unknown) => {}),
46 + addListener: vi.fn(),
47 + },
48 + videoListeners: new Set<(event: { isPlaying: boolean }) => void>(),
49 + videoStatusListeners: new Set<(event: { status: string }) => void>(),
50 + videoEndListeners: new Set<() => void>(),
51 + videoRequestListeners: new Set<(event: { isPlaybackRequested: boolean }) => void>(),
52 + navigate: vi.fn(),
53 + query: vi.fn(),
54 +}));
55 +vi.mock("expo-audio", () => ({
56 + AudioModule: { setAudioSessionOwner: audio.setSessionOwner },
57 + useAudioPlayer: () => audio.player,
58 + createAudioPlayer: () => audio.player,
59 + useAudioPlayerStatus: () => audio.status,
60 + setAudioModeAsync: audio.setAudioMode,
61 + setIsAudioActiveAsync: audio.setActive,
62 +}));
63 +vi.mock("@react-navigation/native", () => ({
64 + useIsFocused: () => true,
65 + useNavigation: () => ({ navigate: audio.navigate }),
66 + useFocusEffect: (callback: () => (() => void) | undefined) => useEffect(callback, [callback]),
67 +}));
68 +vi.mock("react-native", () => ({
69 + Platform: { OS: "android", select: (values: { android?: unknown }) => values.android },
70 + StyleSheet: { create: (styles: unknown) => styles },
71 + useWindowDimensions: () => ({ width: 390, height: 844, fontScale: 1 }),
72 + Text: ({ children }: { children?: ReactNode }) => createElement("span", null, children),
73 + AppState: { currentState: "active", addEventListener: () => ({ remove() {} }) },
74 + View: ({ children }: { children?: ReactNode }) => createElement("div", null, children),
75 + Pressable: (props: {
76 + children?: ReactNode;
77 + onPress: () => void;
78 + disabled?: boolean;
79 + accessibilityLabel?: string;
80 + accessibilityState?: { busy: boolean };
81 + }) =>
82 + createElement(
83 + "button",
84 + {
85 + onClick: props.onPress,
86 + disabled: props.disabled,
87 + "aria-label": props.accessibilityLabel,
88 + "aria-busy": props.accessibilityState?.busy,
89 + },
90 + props.children,
91 + ),
92 +}));
93 +vi.mock("../components/PierreEntryIcon", () => ({ PierreEntryIcon: () => null }));
94 +vi.mock("../components/ui/AppText", () => ({
95 + AppText: ({ children }: { children?: ReactNode }) => createElement("span", null, children),
96 +}));
97 +vi.mock("../components/ui/AppSymbol", () => ({ SymbolView: () => null }));
98 +vi.mock("../components/ui/Button", () => ({
99 + Button: (props: { label: string; onPress(): void; disabled?: boolean }) =>
100 + createElement("button", { onClick: props.onPress, disabled: props.disabled }, props.label),
101 +}));
102 +vi.mock("expo", () => ({
103 + useEvent: (_player: unknown, _event: unknown, initial: unknown) => initial,
104 + useReleasingSharedObjectWithLifecycle: (
105 + lifecycle: {
106 + factory: () => typeof audio.player;
107 + release: (player: typeof audio.player) => void;
108 + },
109 + dependencies: ReadonlyArray<unknown>,
110 + ) => {
111 + const player = useMemo(lifecycle.factory, dependencies);
112 + useEffect(() => () => lifecycle.release(player), [player]);
113 + return player;
114 + },
115 +}));
116 +vi.mock("expo-video", () => ({
117 + useVideoPlayer: () => audio.video,
118 + VideoView: () => null,
119 +}));
120 +vi.mock("../components/VideoThumbnailImage", () => ({ VideoThumbnailImage: () => null }));
121 +vi.mock("../components/ui/AppActivityIndicator", () => ({ AppActivityIndicator: () => null }));
122 +vi.mock("../components/MediaActionsMenu", () => ({
123 + MediaActionsMenu: ({ children }: { children?: ReactNode }) => children,
124 +}));
125 +vi.mock("../state/mediaActions", () => ({
126 + useMediaActions: () => ({ sharing: false, actions: [] }),
127 +}));
128 +vi.mock("./videoAudioSession", () => ({
129 + useMediaAudioSessionHold() {},
130 + useFullscreenVideoOpen: () => false,
131 +}));
132 +vi.mock("../state/assets", () => ({
133 + useRefreshAssetUrl: () => audio.refresh,
134 + useAssetUrlState: () => ({ _tag: "Success", url: "https://example.com/clip.mp4" }),
135 + assetEnvironment: {},
136 +}));
137 +vi.mock("../features/threads/ThreadMarkdownVideo", async (importOriginal) => {
138 + const { createContext } = await import("react");
139 + const actual = await importOriginal<typeof import("../features/threads/ThreadMarkdownVideo")>();
140 + return {
141 + ...actual,
142 + ThreadMediaVisibleContext: createContext(true),
143 + ThreadMarkdownVideo: (props: Parameters<typeof actual.ThreadMarkdownVideo>[0]) =>
144 + createElement(actual.ThreadMarkdownVideo, { ...props, thumbnailVisible: true }),
145 + };
146 +});
147 +
148 +vi.mock("@t3tools/client-runtime/state/runtime", async (importOriginal) => ({
149 + ...(await importOriginal<typeof import("@t3tools/client-runtime/state/runtime")>()),
150 + executeAtomQuery: (...args: unknown[]) => audio.query(...args),
151 +}));
152 +vi.mock("../state/projects", () => ({
153 + projectEnvironment: {
154 + searchEntries: (input: unknown) => input,
155 + fileMetadata: (input: unknown) => input,
156 + },
157 +}));
158 +vi.mock("../state/server", () => ({ serverEnvironment: {} }));
159 +vi.mock("../state/session", () => ({
160 + readEnvironmentScope: () => true,
161 + usePreparedConnection: () => ({ _tag: "Some", value: { httpBaseUrl: "https://example.com" } }),
162 +}));
163 +vi.mock("../state/atom-registry", () => ({ appAtomRegistry: {} }));
164 +vi.mock("../state/threads", () => ({ environmentThreadShells: {}, threadEnvironment: {} }));
165 +vi.mock("../state/entities", () => ({
166 + useLiveThreadLinkLabels: (text: string) => text,
167 + useThreadChipIcons: () => new Map(),
168 +}));
169 +vi.mock("../state/use-thread-selection", () => ({
170 + useThreadSelection: () => ({ selectedThread: null }),
171 +}));
172 +vi.mock("../state/use-atom-query-runner", () => ({ useAtomQueryRunner: () => vi.fn() }));
173 +vi.mock("../state/use-atom-command", () => ({}));
174 +vi.mock("../state/v2-item-support", () => ({}));
175 +vi.mock("../native/SelectableMarkdownText", () => ({
176 + SelectableMarkdownText: (props: {
177 + markdown: string;
178 + onLinkPress(href: string): void;
179 + renderImage?: MarkdownImageRenderer;
180 + }) => {
181 + const embed = props.markdown.match(/!\[([^\]]*)\]\(([^)]+)\)/);
182 + return createElement(
183 + "div",
184 + null,
185 + createElement("button", { onClick: () => props.onLinkPress("target.ts") }, props.markdown),
186 + embed && props.renderImage?.({ href: embed[2]!, alt: embed[1]!, title: null }),
187 + );
188 + },
189 +}));
190 +vi.mock("@legendapp/list/keyboard", () => ({
191 + KeyboardAwareLegendList: (props: {
192 + data: ThreadFeedEntry[];
193 + renderItem(info: { item: ThreadFeedEntry; index: number }): ReactNode;
194 + }) =>
195 + props.data.map((item, index) =>
196 + createElement("div", { key: item.id }, props.renderItem({ item, index })),
197 + ),
198 +}));
199 +vi.mock("@legendapp/list/react-native", () => ({
200 + useViewabilityAmount: (callback: (token: { sizeVisible: number }) => void) =>
201 + useEffect(() => callback({ sizeVisible: 1 }), [callback]),
202 +}));
203 +vi.mock("react-native-reanimated", () => {
204 + const transition = { delay: () => transition, duration: () => transition };
205 + return {
206 + default: { View: ({ children }: { children?: ReactNode }) => children },
207 + FadeIn: transition,
208 + FadeInUp: transition,
209 + };
210 +});
211 +vi.mock("react-native-safe-area-context", () => ({
212 + useSafeAreaInsets: () => ({ top: 0, bottom: 0 }),
213 +}));
214 +vi.mock("expo-haptics", () => ({ selectionAsync: async () => {} }));
215 +vi.mock("expo-image", () => ({}));
216 +vi.mock("uniwind", () => ({}));
217 +vi.mock("../components/ui/Dialog", () => ({}));
218 +vi.mock("../components/ui/NativePresentation", () => ({
219 + PresentationSource: ({ children }: { children?: ReactNode }) => children,
220 +}));
221 +vi.mock("../components/ui/Menu", () => ({
222 + Menu: ({ children }: { children?: ReactNode }) => children,
223 +}));
224 +vi.mock("../components/FilePreviewGallery", () => ({
225 + FilePreviewGallery: ({ children }: { children?: ReactNode }) => children,
226 +}));
227 +vi.mock("../components/FilePreviewModal", () => ({ FilePreviewModal: () => null }));
228 +vi.mock("../components/VideoPreviewModal", () => ({ VideoPreviewModal: () => null }));
229 +vi.mock("../components/ComposerContextSheet", () => ({}));
230 +vi.mock("../native/useOpenPullRequest", () => ({ useOpenPullRequest: () => vi.fn() }));
231 +vi.mock("../native/useMarkdownImageSource", () => ({ useMarkdownImageSource: () => vi.fn() }));
232 +vi.mock("../native/useEnrichedLinkVariants", () => ({
233 + enrichedThreadLinkCustomization: () => undefined,
234 + enrichedContextLinkCustomization: () => undefined,
235 + withChipIcon: (value: unknown) => value,
236 +}));
237 +vi.mock("../native/NativeScrollViewMarker", () => ({
238 + NativeScrollViewMarker: ({ children }: { children?: ReactNode }) => children,
239 +}));
240 +vi.mock("../native/NativeWorkspaceColumns", () => ({
241 + useNativeWorkspaceColumnsSupported: () => false,
242 +}));
243 +vi.mock("../native/native-layout-metrics", () => ({ useDeviceType: () => "phone" }));
244 +vi.mock("../features/layout/workspace-content-width", () => ({
245 + useWorkspaceSettledContentWidth: () => null,
246 +}));
247 +vi.mock("../features/settings/appearance/AppearancePreferencesProvider", () => ({
248 + useAppearancePreferences: () => ({ appearance: { baseFontSize: 14 }, themeAppearance: "dark" }),
249 +}));
250 +vi.mock("./useUniwindTheme", () => ({
251 + useUniwindTheme: () => new Proxy({}, { get: () => "#000000" }),
252 +}));
253 +vi.mock("./composerContextClipboard", () => ({}));
254 +vi.mock("./copyTextWithHaptic", () => ({}));
255 +vi.mock("./openExternalUrl", () => ({}));
256 +vi.mock("./attachmentDownload", () => ({}));
257 +vi.mock("./uuid", () => ({}));
258 +vi.mock("../features/threads/thread-context-divider", () => ({}));
259 +vi.mock("../features/threads/thread-handoff-row", () => ({}));
260 +vi.mock("../features/threads/ThreadGuestShareBar", () => ({ useThreadGuestShare: () => null }));
261 +vi.mock("../features/threads/SecretRequestCard", () => ({}));
262 +vi.mock("../features/threads/worktree-setup-card", () => ({}));
263 +vi.mock("../features/threads/CopyTextButton", () => ({ CopyTextButton: () => null }));
264 +vi.mock("../features/threads/thread-work-log", () => ({ THREAD_DISCLOSURE_TRANSITION_MS: 100 }));
265 +vi.mock("../features/threads/HtmlRenderWebView", () => ({}));
266 +vi.mock("../features/threads/McpAppWebView", () => ({}));
267 +vi.mock("../features/threads/thread-workflow-opening", () => ({ useWorkflowOpening: () => null }));
268 +vi.mock("../features/threads/useFileChipShare", () => ({ useFileChipShare: () => vi.fn() }));
269 +vi.mock("../features/threads/ThreadMarkdownImage", async () => {
270 + const { createContext } = await import("react");
271 + return { MarkdownImageAvailableWidthContext: createContext(390) };
272 +});
273 +vi.mock("../features/review/ReviewCommentCard", () => ({ useReviewCommentColors: () => ({}) }));
274 +vi.mock("../features/prompt-links/prompt-link-actions", () => ({}));
275 +vi.mock("@react-navigation/elements", async () => {
276 + const { createContext } = await import("react");
277 + return { HeaderHeightContext: createContext(0) };
278 +});
279 +
280 +describe("ThreadInlineFilePreview playback", () => {
281 + let root: ReturnType<typeof createRoot> | undefined;
282 + beforeEach(() => {
283 + audio.sessionOwned = false;
284 + audio.setSessionOwner.mockImplementation((owned) => {
285 + audio.sessionOwned = owned;
286 + });
287 + audio.player.pause.mockReset();
288 + audio.enabled = true;
289 + audio.setActive.mockImplementation(async (enabled) => {
290 + audio.enabled = enabled;
291 + });
292 + // Expo's play() silently does nothing while its global gate is disabled.
293 + audio.player.play.mockImplementation(() => {
294 + if (audio.enabled) audio.played();
295 + });
296 + audio.video.addListener.mockImplementation(
297 + (event: string, listener: (event: { isPlaying: boolean }) => void) => {
298 + if (event === "playbackRequestedChange") {
299 + const requestListener = listener as unknown as (event: {
300 + isPlaybackRequested: boolean;
301 + }) => void;
302 + audio.videoRequestListeners.add(requestListener);
303 + return { remove: () => audio.videoRequestListeners.delete(requestListener) };
304 + }
305 + if (event === "statusChange") {
306 + const statusListener = listener as unknown as (event: { status: string }) => void;
307 + audio.videoStatusListeners.add(statusListener);
308 + return { remove: () => audio.videoStatusListeners.delete(statusListener) };
309 + }
310 + if (event === "playToEnd") {
311 + const endListener = listener as unknown as () => void;
312 + audio.videoEndListeners.add(endListener);
313 + return { remove: () => audio.videoEndListeners.delete(endListener) };
314 + }
315 + audio.videoListeners.add(listener);
316 + return { remove: () => audio.videoListeners.delete(listener) };
317 + },
318 + );
319 + audio.video.play.mockImplementation(() => {
320 + audio.video.playing = true;
321 + audio.video.playbackRequested = true;
322 + for (const listener of audio.videoRequestListeners) listener({ isPlaybackRequested: true });
323 + for (const listener of audio.videoListeners) listener({ isPlaying: audio.video.playing });
324 + });
325 + audio.video.pause.mockImplementation(() => {
326 + const wasRequested = audio.video.playbackRequested;
327 + const wasPlaying = audio.video.playing;
328 + audio.video.playbackRequested = false;
329 + audio.video.playing = false;
330 + if (wasRequested) {
331 + for (const listener of audio.videoRequestListeners)
332 + listener({ isPlaybackRequested: false });
333 + }
334 + if (wasPlaying) {
335 + for (const listener of audio.videoListeners) listener({ isPlaying: false });
336 + }
337 + });
338 + });
339 + afterEach(async () => {
340 + await act(async () => root?.unmount());
341 + root = undefined;
342 + vi.clearAllMocks();
343 + audio.refresh.mockReset();
344 + audio.setAudioMode.mockReset();
345 + audio.setActive.mockReset();
346 + audio.video.status = "readyToPlay";
347 + audio.status = {
348 + playing: false,
349 + isLoaded: false,
350 + error: null,
351 + didJustFinish: false,
352 + currentTime: 0,
353 + duration: 10,
354 + isBuffering: false,
355 + };
356 + });
357 +
358 + it.each(
359 + (["user", "assistant"] as const).flatMap((role) =>
360 + (["attachment", "markdown"] as const).flatMap((origin) =>
361 + (["audio", "video"] as const).flatMap((kind) =>
362 + (kind === "video"
363 + ? ["initial play", "native resume", "continued playback"]
364 + : ["initial play"]
365 + ).map((playback) => ({
366 + role,
367 + origin,
368 + kind,
369 + playback,
370 + outcome: playback === "continued playback" ? "preserves" : "cancels",
371 + })),
372 + ),
373 + ),
374 + ),
375 + )(
376 + "$outcome a pending file lookup on $role $origin $kind $playback",
377 + async ({ role, origin, kind, playback }) => {
378 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
379 + const environmentId = EnvironmentId.make("environment-1");
380 + const threadId = ThreadId.make("thread-1");
381 + const messageId = MessageId.make("message-1");
382 + const timestamp = "2026-10-20T00:00:00.000Z";
383 + const name = kind === "audio" ? "clip.mp3" : "clip.mp4";
384 + const mimeType = kind === "audio" ? "audio/mpeg" : "video/mp4";
385 + const uri = `https://example.com/${name}`;
386 + const feed: ThreadFeedEntry[] = [
387 + {
388 + type: "message",
389 + id: messageId,
390 + createdAt: timestamp,
391 + message: {
392 + id: messageId,
393 + role,
394 + text: `open target.ts${origin === "markdown" ? `\n\n![${name}](${uri})` : ""}`,
395 + attachments:
396 + origin === "attachment"
397 + ? [{ type: "file", id: "clip", name, mimeType, sizeBytes: 12 }]
398 + : [],
399 + createdAt: timestamp,
400 + updatedAt: timestamp,
401 + runId: null,
402 + streaming: false,
403 + visibility: "local",
404 + sourceThreadId: threadId,
405 + },
406 + },
407 + ];
408 + let finishLookup!: (value: unknown) => void;
409 + const lookup = new Promise((resolve) => {
410 + finishLookup = resolve;
411 + });
412 + audio.query
413 + .mockResolvedValue({ _tag: "Success", value: { kind: "file" } })
414 + .mockReturnValueOnce(lookup);
415 + audio.refresh.mockResolvedValue(uri);
416 + const container = document.createElement("div");
417 + root = createRoot(container);
418 + await act(async () =>
419 + root!.render(
420 + createElement(ThreadFeed, {
421 + environmentId,
422 + threadId,
423 + threadTitle: "preview",
424 + workspaceRoot: "/repo",
425 + feed,
426 + queuedMessages: [],
427 + dispatchingMessageId: null,
428 + onEditPendingMessage: null,
429 + contentPresentation: { kind: "ready" },
430 + agentLabel: "agent",
431 + latestRun: null,
432 + activeWorkStartedAt: null,
433 + listRef: { current: null },
434 + freeze: { value: false } as Parameters<typeof ThreadFeed>[0]["freeze"],
435 + contentInsetEndAdjustment: { value: 0 } as Parameters<
436 + typeof ThreadFeed
437 + >[0]["contentInsetEndAdjustment"],
438 + anchorMessageId: null,
439 + submittedMessageId: null,
440 + keyboardOffset: 0,
441 + }),
442 + ),
443 + );
444 + const link = Array.from(container.querySelectorAll("button")).find((button) =>
445 + button.textContent?.startsWith("open target.ts"),
446 + )!;
447 + const playLabel = kind === "audio" ? "Play audio" : `Play ${name}`;
448 + const play = () =>
449 + container.querySelector<HTMLButtonElement>(`[aria-label="${playLabel}"]`)!.click();
450 + if (playback !== "initial play") {
451 + await act(async () => play());
452 + expect(audio.video.playing).toBe(true);
453 + if (playback === "native resume") {
454 + await act(async () => audio.video.pause());
455 + expect(audio.video.playing).toBe(false);
456 + } else {
457 + await act(async () => {
458 + for (const listener of audio.videoRequestListeners)
459 + listener({ isPlaybackRequested: true });
460 + });
461 + }
462 + }
463 + await act(async () => link.click());
464 + const signal: AbortSignal = audio.query.mock.calls[0]![2].signal;
465 + expect(signal.aborted).toBe(false);
466 + expect(audio.navigate).not.toHaveBeenCalled();
467 + await act(async () => {
468 + if (playback === "native resume") {
469 + // Native resume requests playback before buffering advances the clock.
470 + audio.video.playbackRequested = true;
471 + for (const listener of audio.videoRequestListeners)
472 + listener({ isPlaybackRequested: true });
473 + expect(audio.video.playing).toBe(false);
474 + } else if (playback === "continued playback") {
475 + for (const isPlaying of [false, true, false, true]) {
476 + audio.video.playing = isPlaying;
477 + for (const listener of audio.videoListeners) listener({ isPlaying });
478 + for (const listener of audio.videoRequestListeners)
479 + listener({ isPlaybackRequested: true });
480 + }
481 + expect(signal.aborted).toBe(false);
482 + } else play();
483 + });
484 + expect(kind === "audio" ? audio.played : audio.video.play).toHaveBeenCalled();
485 + expect(audio.sessionOwned).toBe(true);
486 + await act(async () =>
487 + finishLookup({
488 + _tag: "Success",
489 + value: { entries: [{ path: "src/target.ts", kind: "file" }] },
490 + }),
491 + );
492 + if (playback === "continued playback") {
493 + expect(audio.navigate).toHaveBeenCalledExactlyOnceWith("ThreadFile", {
494 + environmentId,
495 + threadId,
496 + path: ["src", "target.ts"],
497 + });
498 + expect(signal.aborted).toBe(false);
499 + } else {
500 + expect(audio.navigate).not.toHaveBeenCalled();
501 + expect(signal.aborted).toBe(true);
502 + }
503 + expect(container.querySelector(`[aria-label="${playLabel}"]`)).toBeNull();
504 + if (kind === "audio")
505 + expect(container.querySelector('[aria-label="Pause audio"]')).not.toBeNull();
506 + else {
507 + if (playback === "native resume") {
508 + audio.video.playing = true;
509 + for (const listener of audio.videoListeners) listener({ isPlaying: true });
510 + }
511 + expect(audio.video.playing).toBe(true);
512 + }
513 + },
514 + );
515 +
516 + it.each(
517 + ["takeover", "pause", "finish"].flatMap((release) => [
518 + ["inline", "video", release],
519 + ["viewer", "video", release],
520 + ["inline", "native video controls", release],
521 + ["viewer", "native video controls", release],
522 + ["inline", "recording", release],
523 + ["viewer", "recording", release],
524 + ]),
525 + )(
526 + "keeps the shared session active when %s audio yields to %s after %s",
527 + async (source, successor, release) => {
528 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
529 + audio.status = { ...audio.status, isLoaded: true };
530 + const container = document.createElement("div");
531 + root = createRoot(container);
532 + const render = (playVideo = false, showAudio = true) =>
533 + root!.render(
534 + createElement(
535 + "div",
536 + null,
537 + showAudio
538 + ? source === "inline"
539 + ? createElement(ThreadInlineFilePreview, {
540 + source: {
541 + kind: "document",
542 + name: "sound.mp3",
543 + uri: "https://example.com/sound.mp3",
544 + },
545 + onOpen() {},
546 + })
547 + : createElement(AudioFilePreview, {
548 + uri: "https://example.com/sound.mp3",
549 + onRetry() {},
550 + })
551 + : null,
552 + createElement(MediaVideoPlayer, {
553 + uri: "https://example.com/clip.mp4",
554 + name: "clip.mp4",
555 + thumbnailKey: "clip",
556 + expanded: true,
557 + autoPlay: playVideo,
558 + }),
559 + ),
560 + );
561 + await act(async () => render());
562 + await act(async () =>
563 + [...container.querySelectorAll("button")]
564 + .find(
565 + (button) =>
566 + button.getAttribute("aria-label") === "Play audio" || button.textContent === "Play",
567 + )!
568 + .click(),
569 + );
570 + expect(audio.played).toHaveBeenCalledOnce();
571 + let sessionActive = true;
572 + const deactivated = vi.fn();
573 + // Match expo-audio iOS: the queued callback checks ownership at execution time.
574 + const queueDeactivation = () =>
575 + setTimeout(() => {
576 + if (audio.sessionOwned) return;
577 + sessionActive = false;
578 + audio.video.playing = false;
579 + deactivated();
580 + }, 100);
581 + audio.setSessionOwner.mockImplementation((owned) => {
582 + audio.sessionOwned = owned;
583 + if (!owned) queueDeactivation();
584 + });
585 + audio.player.pause.mockImplementation((deactivateSession) => {
586 + if (deactivateSession !== false) queueDeactivation();
587 + });
588 + vi.useFakeTimers();
589 + let recording: ReturnType<typeof acquireAudioSession> | undefined;
590 + try {
591 + if (release === "pause") {
592 + await act(async () =>
593 + [...container.querySelectorAll("button")]
594 + .find(
595 + (button) =>
596 + button.getAttribute("aria-label") === "Pause audio" ||
597 + button.textContent === "Pause",
598 + )!
599 + .click(),
600 + );
601 + } else if (release === "finish") {
602 + // Native completion queues deactivation before JS receives didJustFinish.
603 + queueDeactivation();
604 + audio.status = { ...audio.status, playing: false, didJustFinish: true };
605 + await act(async () => render());
606 + }
607 + if (release !== "takeover") {
608 + expect(vi.getTimerCount()).toBeGreaterThan(0);
609 + await vi.advanceTimersByTimeAsync(50);
610 + }
611 + await act(async () => {
612 + if (successor === "recording") {
613 + recording = acquireAudioSession("recording");
614 + await activateAudioSession(recording);
615 + } else if (successor === "native video controls") audio.video.play();
616 + else render(true);
617 + });
618 + if (successor !== "recording") expect(audio.video.playing).toBe(true);
619 + expect(audio.player.pause).toHaveBeenCalled();
620 + // Cleanup of the old native ref must not interrupt the successor either.
621 + await act(async () => render(successor === "video", false));
622 + await vi.advanceTimersByTimeAsync(200);
623 + expect(sessionActive).toBe(true);
624 + expect(deactivated).not.toHaveBeenCalled();
625 + expect(audio.setActive).not.toHaveBeenCalledWith(false);
626 + if (successor !== "recording") expect(audio.video.playing).toBe(true);
627 + else
628 + expect(audio.setAudioMode).toHaveBeenLastCalledWith(
629 + expect.objectContaining({ allowsRecording: true }),
630 + );
631 + await act(async () => root!.unmount());
632 + root = undefined;
633 + if (recording) await releaseAudioSession(recording);
634 + recording = undefined;
635 + await vi.advanceTimersByTimeAsync(200);
636 + expect(sessionActive).toBe(false);
637 + } finally {
638 + if (recording) await releaseAudioSession(recording);
639 + vi.clearAllTimers();
640 + vi.useRealTimers();
641 + audio.player.pause.mockReset();
642 + }
643 + },
644 + );
645 +
646 + it.each(["inline", "viewer"])("stops video before starting %s audio", async (source) => {
647 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
648 + audio.status = { ...audio.status, isLoaded: true };
649 + const container = document.createElement("div");
650 + root = createRoot(container);
651 + await act(async () =>
652 + root!.render(
653 + createElement(
654 + "div",
655 + null,
656 + createElement(MediaVideoPlayer, {
657 + uri: "https://example.com/clip.mp4",
658 + name: "clip.mp4",
659 + thumbnailKey: "clip",
660 + expanded: true,
661 + autoPlay: true,
662 + }),
663 + source === "inline"
664 + ? createElement(ThreadInlineFilePreview, {
665 + source: {
666 + kind: "document",
667 + name: "sound.mp3",
668 + uri: "https://example.com/sound.mp3",
669 + },
670 + onOpen() {},
671 + })
672 + : createElement(AudioFilePreview, {
673 + uri: "https://example.com/sound.mp3",
674 + onRetry() {},
675 + }),
676 + ),
677 + ),
678 + );
679 + expect(audio.video.playing).toBe(true);
680 + audio.video.pause.mockClear();
681 + await act(async () =>
682 + [...container.querySelectorAll("button")]
683 + .find(
684 + (button) =>
685 + button.getAttribute("aria-label") === "Play audio" || button.textContent === "Play",
686 + )!
687 + .click(),
688 + );
689 + expect(audio.video.playing).toBe(false);
690 + expect(audio.video.pause.mock.invocationCallOrder[0]).toBeLessThan(
691 + audio.player.play.mock.invocationCallOrder[0]!,
692 + );
693 + expect(audio.played).toHaveBeenCalledOnce();
694 + expect(audio.setActive).toHaveBeenLastCalledWith(true);
695 + });
696 +
697 + it("plays inline, opens the file viewer, and yields viewer playback to recording", async () => {
698 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
699 + audio.status = { ...audio.status, isLoaded: true };
700 + const container = document.createElement("div");
701 + root = createRoot(container);
702 + const openViewer = () =>
703 + root!.render(
704 + createElement(AudioFilePreview, { uri: "https://example.com/sound.mp3", onRetry() {} }),
705 + );
706 + await act(async () =>
707 + root!.render(
708 + createElement(ThreadInlineFilePreview, {
709 + source: { kind: "document", name: "sound.mp3", uri: "https://example.com/sound.mp3" },
710 + onOpen: openViewer,
711 + }),
712 + ),
713 + );
714 + await act(async () =>
715 + container.querySelector<HTMLButtonElement>('button[aria-label="Play audio"]')!.click(),
716 + );
717 + expect(audio.played).toHaveBeenCalledOnce();
718 + await act(async () =>
719 + container.querySelector<HTMLButtonElement>('button[aria-label="Open sound.mp3"]')!.click(),
720 + );
721 + expect(audio.enabled).toBe(true);
722 + const play = [...container.querySelectorAll("button")].find(
723 + (button) => button.textContent === "Play",
724 + )!;
725 + await act(async () => play.click());
726 + expect(audio.played).toHaveBeenCalledTimes(2);
727 + audio.player.pause.mockClear();
728 + let recording!: ReturnType<typeof acquireAudioSession>;
729 + await act(async () => {
730 + recording = acquireAudioSession("recording");
731 + });
732 + expect(audio.player.pause).toHaveBeenCalledOnce();
733 + await activateAudioSession(recording);
734 + await act(async () => play.click());
735 + expect(audio.played).toHaveBeenCalledTimes(2);
736 + await releaseAudioSession(recording);
737 + await act(async () => play.click());
738 + expect(audio.played).toHaveBeenCalledTimes(3);
739 + expect(audio.enabled).toBe(true);
740 + });
741 +
742 + it.each(["pause", "unmount", "recording"])(
743 + "does not restart the file viewer after %s during replay seeking",
744 + async (action) => {
745 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
746 + audio.status = { ...audio.status, isLoaded: true, didJustFinish: true, currentTime: 10 };
747 + const seek = Promise.withResolvers<void>();
748 + audio.player.seekTo.mockReturnValueOnce(seek.promise);
749 + const container = document.createElement("div");
750 + root = createRoot(container);
751 + await act(async () =>
752 + root!.render(
753 + createElement(AudioFilePreview, { uri: "https://example.com/sound.mp3", onRetry() {} }),
754 + ),
755 + );
756 + const play = [...container.querySelectorAll("button")].find(
757 + (button) => button.textContent === "Play",
758 + )!;
759 + await act(async () => play.click());
760 + expect(play.textContent).toBe("Pause");
761 + let recording: ReturnType<typeof acquireAudioSession> | undefined;
762 + if (action === "pause") await act(async () => play.click());
763 + else if (action === "recording") {
764 + await act(async () => {
765 + recording = acquireAudioSession("recording");
766 + });
767 + expect(play.textContent).toBe("Play");
768 + await activateAudioSession(recording!);
769 + } else {
770 + await act(async () => root!.unmount());
771 + root = undefined;
772 + }
773 + await act(async () => seek.resolve());
774 + expect(audio.played).not.toHaveBeenCalled();
775 + if (recording) await releaseAudioSession(recording);
776 + },
777 + );
778 +
779 + it.each(["buffering", "seek"])(
780 + "keeps file viewer ownership through %s and native resume",
781 + async (transition) => {
782 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
783 + audio.status = { ...audio.status, isLoaded: true };
784 + const container = document.createElement("div");
785 + root = createRoot(container);
786 + const render = () =>
787 + root!.render(
788 + createElement(AudioFilePreview, {
789 + uri: "https://example.com/sound.mp3",
790 + onRetry() {},
791 + }),
792 + );
793 + await act(async () => render());
794 + await act(async () =>
795 + [...container.querySelectorAll("button")]
796 + .find((button) => button.textContent === "Play")!
797 + .click(),
798 + );
799 + audio.status = { ...audio.status, playing: true };
800 + await act(async () => render());
801 + audio.player.pause.mockClear();
802 + if (transition === "seek") {
803 + await act(async () =>
804 + [...container.querySelectorAll("button")]
805 + .find((button) => button.textContent === "+15s")!
806 + .click(),
807 + );
808 + expect(audio.player.seekTo).toHaveBeenCalledWith(10);
809 + }
810 + audio.status = { ...audio.status, playing: false, isBuffering: transition === "buffering" };
811 + await act(async () => render());
812 + expect(audio.player.pause).not.toHaveBeenCalled();
813 + expect(
814 + [...container.querySelectorAll("button")].map((button) => button.textContent),
815 + ).toContain("Pause");
816 + audio.status = { ...audio.status, playing: true, isBuffering: false };
817 + await act(async () => render());
818 + expect(audio.played).toHaveBeenCalledOnce();
819 + let recording!: ReturnType<typeof acquireAudioSession>;
820 + await act(async () => {
821 + recording = acquireAudioSession("recording");
822 + });
823 + expect(audio.player.pause).toHaveBeenCalledOnce();
824 + await releaseAudioSession(recording);
825 + },
826 + );
827 +
828 + it.each(["pause", "pause while buffering", "pause while loading", "end", "error"])(
829 + "releases file viewer ownership on %s",
830 + async (action) => {
831 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
832 + audio.status = { ...audio.status, isLoaded: true };
833 + const container = document.createElement("div");
834 + root = createRoot(container);
835 + const render = () =>
836 + root!.render(
837 + createElement(AudioFilePreview, {
838 + uri: "https://example.com/sound.mp3",
839 + onRetry() {},
840 + }),
841 + );
842 + await act(async () => render());
843 + await act(async () =>
844 + [...container.querySelectorAll("button")]
845 + .find((button) => button.textContent === "Play")!
846 + .click(),
847 + );
848 + audio.status = { ...audio.status, playing: true };
849 + await act(async () => render());
850 + if (action.startsWith("pause")) {
851 + if (action !== "pause") {
852 + audio.status = {
853 + ...audio.status,
854 + playing: false,
855 + isBuffering: true,
856 + isLoaded: action !== "pause while loading",
857 + };
858 + await act(async () => render());
859 + }
860 + await act(async () =>
861 + [...container.querySelectorAll("button")]
862 + .find((button) => button.textContent === "Pause")!
863 + .click(),
864 + );
865 + } else {
866 + audio.status = { ...audio.status, playing: false, didJustFinish: action === "end" };
867 + if (action === "error") Object.assign(audio.status, { error: "Playback failed" });
868 + await act(async () => render());
869 + }
870 + expect(audio.player.pause).toHaveBeenLastCalledWith();
871 + audio.status = { ...audio.status, playing: false, isBuffering: false, isLoaded: true };
872 + await act(async () => render());
873 + expect(
874 + [...container.querySelectorAll("button")].map((button) => button.textContent),
875 + ).toContain("Play");
876 + audio.player.pause.mockClear();
877 + const recording = acquireAudioSession("recording");
878 + expect(audio.player.pause).not.toHaveBeenCalled();
879 + expect(audio.setActive).not.toHaveBeenCalledWith(false);
880 + await releaseAudioSession(recording);
881 + },
882 + );
883 +
884 + it.each(["buffering", "seek"])(
885 + "keeps video ownership through %s and resume, including recording takeover during the next wait",
886 + async (transition) => {
887 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
888 + root = createRoot(document.createElement("div"));
889 + await act(async () =>
890 + root!.render(
891 + createElement(MediaVideoPlayer, {
892 + uri: "https://example.com/clip.mp4",
893 + name: "clip.mp4",
894 + thumbnailKey: "clip",
895 + expanded: true,
896 + autoPlay: true,
897 + }),
898 + ),
899 + );
900 + audio.video.pause.mockClear();
901 + // iOS can keep readyToPlay during a seek's evaluatingBufferingRate wait.
902 + if (transition === "buffering") {
903 + audio.video.status = "loading";
904 + for (const listener of audio.videoStatusListeners) listener({ status: "loading" });
905 + }
906 + audio.video.playing = false;
907 + for (const listener of audio.videoListeners) listener({ isPlaying: false });
908 + expect(audio.video.pause).not.toHaveBeenCalled();
909 + // Buffer readiness can precede the native playing=true event.
910 + audio.video.status = "readyToPlay";
911 + for (const listener of audio.videoStatusListeners) listener({ status: "readyToPlay" });
912 + expect(audio.video.pause).not.toHaveBeenCalled();
913 + audio.video.playing = true;
914 + for (const listener of audio.videoListeners) listener({ isPlaying: true });
915 + expect(audio.video.play).toHaveBeenCalledOnce();
916 + audio.video.playing = false;
917 + for (const listener of audio.videoListeners) listener({ isPlaying: false });
918 + const recording = acquireAudioSession("recording");
919 + expect(audio.video.pause).toHaveBeenCalledOnce();
920 + audio.video.play();
921 + expect(audio.video.playing).toBe(false);
922 + await releaseAudioSession(recording);
923 + audio.video.play();
924 + expect(audio.video.playing).toBe(true);
925 + },
926 + );
927 +
928 + it.each(["pause", "pause while buffering", "end", "error"])(
929 + "releases video ownership on %s",
930 + async (action) => {
931 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
932 + root = createRoot(document.createElement("div"));
933 + await act(async () =>
934 + root!.render(
935 + createElement(MediaVideoPlayer, {
936 + uri: "https://example.com/clip.mp4",
937 + name: "clip.mp4",
938 + thumbnailKey: "clip",
939 + expanded: true,
940 + autoPlay: true,
941 + }),
942 + ),
943 + );
944 + await act(async () => {
945 + if (action.startsWith("pause")) {
946 + if (action === "pause while buffering") {
947 + audio.video.status = "loading";
948 + audio.video.playing = false;
949 + for (const listener of audio.videoListeners) listener({ isPlaying: false });
950 + }
951 + audio.video.pause();
952 + } else if (action === "end") {
953 + for (const listener of audio.videoEndListeners) listener();
954 + } else {
955 + audio.video.status = "error";
956 + for (const listener of audio.videoStatusListeners) listener({ status: "error" });
957 + }
958 + });
959 + audio.video.pause.mockClear();
960 + const recording = acquireAudioSession("recording");
961 + expect(audio.video.pause).not.toHaveBeenCalled();
962 + await releaseAudioSession(recording);
963 + },
964 + );
965 +
966 + it("keeps thread video playback and native controls working after audio releases", async () => {
967 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
968 + const recording = acquireAudioSession("recording");
969 + await activateAudioSession(recording);
970 + await releaseAudioSession(recording);
971 + const modes = audio.setAudioMode.mock.calls.length;
972 + const activations = audio.setActive.mock.calls.length;
973 + const container = document.createElement("div");
974 + root = createRoot(container);
975 + await act(async () =>
976 + root!.render(
977 + createElement(MediaVideoPlayer, {
978 + uri: "https://example.com/clip.mp4",
979 + name: "clip.mp4",
980 + thumbnailKey: "clip",
981 + expanded: true,
982 + autoPlay: true,
983 + }),
984 + ),
985 + );
986 + expect(audio.video.playing).toBe(true);
987 + expect(audio.setAudioMode).toHaveBeenCalledTimes(modes);
988 + expect(audio.setActive).toHaveBeenCalledTimes(activations);
989 + audio.video.pause();
990 + audio.video.play();
991 + expect(audio.video.playing).toBe(true);
992 + const takeover = acquireAudioSession("recording");
993 + expect(audio.video.playing).toBe(false);
994 + await activateAudioSession(takeover);
995 + audio.video.play();
996 + expect(audio.video.playing).toBe(false);
997 + await releaseAudioSession(takeover);
998 + audio.video.play();
999 + expect(audio.video.playing).toBe(true);
1000 + await act(async () => root!.unmount());
1001 + root = undefined;
1002 + expect(audio.video.playing).toBe(false);
1003 + });
1004 +
1005 + it.each(["play", "cancel", "unmount", "mode failure", "activation failure"])(
1006 + "reactivates audio after voice release and honors %s during activation",
1007 + async (intent) => {
1008 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
1009 + const recording = acquireAudioSession("recording");
1010 + await activateAudioSession(recording);
1011 + await releaseAudioSession(recording);
1012 + vi.clearAllMocks();
1013 + let activate: () => void = () => {};
1014 + if (intent === "mode failure") {
1015 + audio.setAudioMode.mockRejectedValueOnce(new Error("Playback mode unavailable"));
1016 + } else if (intent === "activation failure") {
1017 + audio.setActive.mockRejectedValueOnce(new Error("Audio session unavailable"));
1018 + } else {
1019 + audio.setActive.mockImplementationOnce(
1020 + () => new Promise((resolve) => (activate = resolve)),
1021 + );
1022 + }
1023 + audio.status = { ...audio.status, isLoaded: true };
1024 + const container = document.createElement("div");
1025 + root = createRoot(container);
1026 + act(() =>
1027 + root!.render(
1028 + createElement(ThreadInlineFilePreview, {
1029 + source: { kind: "document", name: "sound.mp3", uri: "https://example.com/sound.mp3" },
1030 + onOpen() {},
1031 + }),
1032 + ),
1033 + );
1034 + const button = container.querySelector<HTMLButtonElement>('button[aria-label="Play audio"]')!;
1035 + await act(async () => button.click());
1036 + expect(audio.setAudioMode).toHaveBeenLastCalledWith({
1037 + allowsRecording: false,
1038 + playsInSilentMode: true,
1039 + interruptionMode: "doNotMix",
1040 + shouldPlayInBackground: false,
1041 + });
1042 + expect(audio.player.play).not.toHaveBeenCalled();
1043 + if (intent.endsWith("failure")) {
1044 + expect(container.textContent).toContain("Unavailable · tap play to retry");
1045 + expect(button.getAttribute("aria-label")).toBe("Retry audio");
1046 + expect(audio.setActive).not.toHaveBeenCalledWith(false);
1047 + return;
1048 + }
1049 + expect(audio.setActive).toHaveBeenLastCalledWith(true);
1050 + expect(audio.setAudioMode.mock.invocationCallOrder[0]).toBeLessThan(
1051 + audio.setActive.mock.invocationCallOrder[0]!,
1052 + );
1053 + if (intent === "cancel") await act(async () => button.click());
1054 + else if (intent === "unmount") {
1055 + act(() => root!.unmount());
1056 + root = undefined;
1057 + expect(audio.player.release).not.toHaveBeenCalled();
1058 + }
1059 + await act(async () => activate());
1060 + if (intent === "play") {
1061 + expect(audio.player.play).toHaveBeenCalledOnce();
1062 + expect(button.getAttribute("aria-label")).toBe("Pause audio");
1063 + } else {
1064 + expect(audio.player.play).not.toHaveBeenCalled();
1065 + expect(audio.setActive).toHaveBeenLastCalledWith(true);
1066 + expect(audio.player.pause).toHaveBeenCalled();
1067 + if (intent === "unmount") {
1068 + expect(audio.player.release).toHaveBeenCalledOnce();
1069 + expect(audio.player.pause.mock.invocationCallOrder[0]).toBeLessThan(
1070 + audio.player.release.mock.invocationCallOrder[0]!,
1071 + );
1072 + }
1073 + if (intent === "cancel") expect(button.getAttribute("aria-label")).toBe("Play audio");
1074 + }
1075 + },
1076 + );
1077 +
1078 + it.each(["playing", "URL pending", "mode pending", "activation pending"])(
1079 + "yields to recording while %s and plays again after recording stops",
1080 + async (phase) => {
1081 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
1082 + const url = Promise.withResolvers<string>();
1083 + const native = Promise.withResolvers<void>();
1084 + audio.refresh.mockReturnValueOnce(url.promise);
1085 + audio.status = { ...audio.status, isLoaded: phase !== "URL pending" };
1086 + if (phase === "mode pending") audio.setAudioMode.mockReturnValueOnce(native.promise);
1087 + if (phase === "activation pending") audio.setActive.mockReturnValueOnce(native.promise);
1088 + const container = document.createElement("div");
1089 + root = createRoot(container);
1090 + act(() =>
1091 + root!.render(
1092 + createElement(ThreadInlineFilePreview, {
1093 + source: {
1094 + kind: "document",
1095 + name: "sound.mp3",
1096 + environmentId: EnvironmentId.make("environment-1"),
1097 + resource: {
1098 + _tag: "workspace-file",
1099 + threadId: ThreadId.make("thread-1"),
1100 + path: "/repo/sound.mp3",
1101 + },
1102 + },
1103 + onOpen() {},
1104 + }),
1105 + ),
1106 + );
1107 + const button = container.querySelector<HTMLButtonElement>('button[aria-label="Play audio"]')!;
1108 + await act(async () => button.click());
1109 + expect(audio.player.play).toHaveBeenCalledTimes(phase === "playing" ? 1 : 0);
1110 + expect(audio.refresh).toHaveBeenCalledTimes(phase === "URL pending" ? 1 : 0);
1111 + let recording!: ReturnType<typeof acquireAudioSession>;
1112 + await act(async () => {
1113 + recording = acquireAudioSession("recording");
1114 + });
1115 + expect(audio.player.pause).toHaveBeenCalled();
1116 + expect(button.getAttribute("aria-label")).toBe("Play audio");
1117 + native.resolve();
1118 + await activateAudioSession(recording);
1119 + expect(audio.setAudioMode).toHaveBeenLastCalledWith({
1120 + allowsRecording: true,
1121 + interruptionMode: "doNotMix",
1122 + playsInSilentMode: true,
1123 + shouldPlayInBackground: false,
1124 + });
1125 + const modeCalls = audio.setAudioMode.mock.calls.length;
1126 + const activationCalls = audio.setActive.mock.calls.length;
1127 + await act(async () => url.resolve("https://example.com/sound.mp3"));
1128 + await act(async () => button.click());
1129 + expect(audio.setAudioMode).toHaveBeenCalledTimes(modeCalls);
1130 + expect(audio.setActive).toHaveBeenCalledTimes(activationCalls);
1131 + expect(audio.setActive).not.toHaveBeenCalledWith(false);
1132 + expect(audio.player.play).toHaveBeenCalledTimes(phase === "playing" ? 1 : 0);
1133 + await releaseAudioSession(recording);
1134 + audio.status = { ...audio.status, isLoaded: true };
1135 + // Refresh the native status before the next tap.
1136 + await act(async () =>
1137 + root!.render(
1138 + createElement(ThreadInlineFilePreview, {
1139 + source: { kind: "document", name: "sound.mp3", uri: "https://example.com/sound.mp3" },
1140 + onOpen() {},
1141 + }),
1142 + ),
1143 + );
1144 + const replay = container.querySelector<HTMLButtonElement>('button[aria-label="Play audio"]')!;
1145 + await act(async () => replay.click());
1146 + expect(audio.player.play).toHaveBeenCalledTimes(phase === "playing" ? 2 : 1);
1147 + expect(audio.setAudioMode).toHaveBeenLastCalledWith({
1148 + allowsRecording: false,
1149 + interruptionMode: "doNotMix",
1150 + playsInSilentMode: true,
1151 + shouldPlayInBackground: false,
1152 + });
1153 + expect(audio.setActive).toHaveBeenLastCalledWith(true);
1154 + },
1155 + );
1156 +
1157 + it.each(["cancel", "unmount", "replay, stale first", "replay, latest first"])(
1158 + "honors the latest audio intent after %s during URL resolution",
1159 + async (intent) => {
1160 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
1161 + const container = document.createElement("div");
1162 + root = createRoot(container);
1163 + const resolutions: Array<(uri: string) => void> = [];
1164 + audio.refresh.mockImplementation(() => new Promise((resolve) => resolutions.push(resolve)));
1165 + act(() =>
1166 + root!.render(
1167 + createElement(ThreadInlineFilePreview, {
1168 + source: {
1169 + kind: "document",
1170 + name: "sound.mp3",
1171 + environmentId: EnvironmentId.make("environment-1"),
1172 + resource: {
1173 + _tag: "workspace-file",
1174 + threadId: ThreadId.make("thread-1"),
1175 + path: "/repo/sound.mp3",
1176 + },
1177 + },
1178 + onOpen() {},
1179 + }),
1180 + ),
1181 + );
1182 + const button = container.querySelector<HTMLButtonElement>('button[aria-label="Play audio"]')!;
1183 + await act(async () => button.click());
1184 + if (intent !== "unmount") {
1185 + await act(async () => button.click());
1186 + expect(button.getAttribute("aria-label")).toBe("Play audio");
1187 + }
1188 + const replay = intent.startsWith("replay");
1189 + if (replay) {
1190 + await act(async () => button.click());
1191 + expect(button.getAttribute("aria-label")).toBe("Pause audio");
1192 + expect(audio.refresh).toHaveBeenCalledTimes(2);
1193 + } else if (intent === "unmount") {
1194 + act(() => root!.unmount());
1195 + root = undefined;
1196 + }
1197 + const latestFirst = intent === "replay, latest first";
1198 + if (latestFirst) await act(async () => resolutions[1]!("https://example.com/latest.mp3"));
1199 + await act(async () => resolutions[0]!("https://example.com/stale.mp3"));
1200 + expect(audio.player.play).toHaveBeenCalledTimes(latestFirst ? 1 : 0);
1201 + expect(audio.player.replace).toHaveBeenCalledTimes(latestFirst ? 1 : 0);
1202 + if (replay) {
1203 + expect(button.getAttribute("aria-label")).toBe("Pause audio");
1204 + if (!latestFirst) {
1205 + expect(container.textContent).toContain("Loading…");
1206 + await act(async () => resolutions[1]!("https://example.com/latest.mp3"));
1207 + }
1208 + expect(audio.player.replace).toHaveBeenCalledExactlyOnceWith({
1209 + uri: "https://example.com/latest.mp3",
1210 + });
1211 + expect(audio.player.play).toHaveBeenCalledOnce();
1212 + }
1213 + },
1214 + );
1215 +
1216 + it.each([false, true])(
1217 + "cancels a second tap while buffering with isLoaded=%s",
1218 + async (isLoaded) => {
1219 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
1220 + const container = document.createElement("div");
1221 + root = createRoot(container);
1222 + audio.status = { ...audio.status, isLoaded, isBuffering: isLoaded };
1223 + let resolve: (uri: string) => void = () => {};
1224 + audio.refresh.mockImplementation(
1225 + () =>
1226 + new Promise((done) => {
1227 + resolve = done;
1228 + }),
1229 + );
1230 + const preview = createElement(ThreadInlineFilePreview, {
1231 + source: {
1232 + kind: "document",
1233 + name: "sound.mp3",
1234 + environmentId: EnvironmentId.make("environment-1"),
1235 + resource: {
1236 + _tag: "workspace-file",
1237 + threadId: ThreadId.make("thread-1"),
1238 + path: "/repo/sound.mp3",
1239 + },
1240 + },
1241 + onOpen() {},
1242 + });
1243 + act(() => root!.render(preview));
1244 + const button = container.querySelector<HTMLButtonElement>('button[aria-label="Play audio"]')!;
1245 + await act(async () => button.click());
1246 + expect(audio.player.play).toHaveBeenCalledTimes(isLoaded ? 1 : 0);
1247 + expect(button.disabled).toBe(false);
1248 + expect(button.getAttribute("aria-label")).toBe("Pause audio");
1249 + expect(button.getAttribute("aria-busy")).toBe("true");
1250 + await act(async () => button.click());
1251 + expect(audio.player.pause).toHaveBeenCalled();
1252 + expect(button.getAttribute("aria-label")).toBe("Play audio");
1253 + expect(button.getAttribute("aria-busy")).toBe("false");
1254 + if (!isLoaded) await act(async () => resolve("https://example.com/sound.mp3"));
1255 + expect(audio.player.play).toHaveBeenCalledTimes(isLoaded ? 1 : 0);
1256 + if (!isLoaded) {
1257 + expect(audio.player.replace).not.toHaveBeenCalled();
1258 + audio.refresh.mockResolvedValue("https://example.com/sound.mp3");
1259 + }
1260 + await act(async () => button.click());
1261 + expect(audio.player.play).toHaveBeenCalledTimes(isLoaded ? 2 : 1);
1262 + audio.status = { ...audio.status, isLoaded: true, didJustFinish: true, currentTime: 10 };
1263 + await act(async () =>
1264 + root!.render(createElement(ThreadInlineFilePreview, { ...preview.props })),
1265 + );
1266 + expect(button.getAttribute("aria-label")).toBe("Play audio");
1267 + await act(async () => button.click());
1268 + expect(audio.player.seekTo).toHaveBeenCalledWith(0);
1269 + expect(audio.player.play).toHaveBeenCalledTimes(isLoaded ? 3 : 2);
1270 + },
1271 + );
1272 +});
1273
1274 describe("PDF preview detection", () => {
1275 it.each([
@@ -12,3 +1281,25 @@ describe("PDF preview detection", () => {
1281 expect(isPdfFile(file)).toBe(expected);
1282 });
1283 });
1284 +
1285 +describe("inline file previews", () => {
1286 + it.each([
1287 + [{ name: "sound.MP3" }, "audio"],
1288 + [{ name: "sound", mimeType: "audio/wav" }, "audio"],
1289 + [{ name: "report.PDF", mimeType: "text/plain" }, null],
1290 + [{ name: "report.csv" }, null],
1291 + [{ name: "report.tsv" }, null],
1292 + [{ name: "report", mimeType: "text/csv; charset=utf-8" }, null],
1293 + [{ name: "report.csv", mimeType: "image/png" }, null],
1294 + [{ name: "image.png" }, null],
1295 + [{ name: "clip.mp4" }, null],
1296 + [{ name: "file.zip" }, null],
1297 + [{ name: "report.docx" }, null],
1298 + [{ name: "report.xlsx" }, null],
1299 + [{ name: "report.pptx" }, null],
1300 + [{ name: "download", mimeType: "application/pdf" }, null],
1301 + [{ name: "sound.mp3", mimeType: "application/pdf" }, null],
1302 + ])("classifies %j as %s", (file, expected) => {
1303 + expect(inlineFilePreviewKind(file)).toBe(expected);
1304 + });
1305 +});
apps/mobile/src/lib/filePreview.ts
+6
@@ -1,3 +1,9 @@
1 +import { filePreviewKind } from "@t3tools/shared/filePreview";
2 +
3 +export function inlineFilePreviewKind(file: { readonly name: string; readonly mimeType?: string }) {
4 + return filePreviewKind(file) === "audio" ? "audio" : null;
5 +}
6 +
7 export function isPdfFile(file: { readonly name: string; readonly mimeType?: string }): boolean {
8 const mimeType = file.mimeType?.split(";", 1)[0]?.trim().toLowerCase();
9 if (mimeType && mimeType !== "application/octet-stream") return mimeType === "application/pdf";
apps/mobile/src/lib/markdownDocument.ts
+53
@@ -351,3 +351,56 @@ export function markdownWithTableBreaks(markdown: string): string {
351 export function parseMarkdownDocument(markdown: string): Root {
352 return parser.parse(markdownWithHtml(markdown));
353 }
354 +
355 +/** Native media slots only cover standalone images; nested file embeds must become links. */
356 +export function markdownWithFileEmbeds(
357 + markdown: string,
358 + label: (href: string, standalone: boolean) => string | null,
359 +): { markdown: string; fileHrefs: ReadonlySet<string> } {
360 + const fileHrefs = new Set<string>();
361 + if (!markdown.includes("![")) return { markdown, fileHrefs };
362 + const root = parser.parse(markdown);
363 + const topLevelBlocks = new Set<MarkdownNode>(root.children);
364 + const definitions = new Map<string, string>();
365 + const collect = (node: MarkdownNode) => {
366 + if (node.type === "definition") {
367 + const identifier = node.identifier.toUpperCase();
368 + if (!definitions.has(identifier)) definitions.set(identifier, node.url);
369 + }
370 + if ("children" in node) node.children.forEach(collect);
371 + };
372 + collect(root);
373 + const edits: Array<{ start: number; end: number; content: string }> = [];
374 + const visit = (node: MarkdownNode, standalone = false, insideLink = false) => {
375 + if (node.type === "image" || node.type === "imageReference") {
376 + const href =
377 + node.type === "image" ? node.url : definitions.get(node.identifier.toUpperCase());
378 + const name = href === undefined ? null : label(href, standalone);
379 + const start = node.position?.start.offset;
380 + const end = node.position?.end.offset;
381 + if (href !== undefined && name !== null && start !== undefined && end !== undefined) {
382 + const text = name.replace(/[\\[\]`*_~|&<>]/g, "\\$&");
383 + const url = href.replace(/[\\&]/g, "\\$&").replace(/</g, "%3C").replace(/>/g, "%3E");
384 + edits.push({ start, end, content: insideLink ? text : `[${text}](<${url}>)` });
385 + fileHrefs.add(href);
386 + }
387 + }
388 + if ("children" in node)
389 + node.children.forEach((child) =>
390 + visit(
391 + child,
392 + node.type === "paragraph" && node.children.length === 1 && topLevelBlocks.has(node),
393 + insideLink || node.type === "link" || node.type === "linkReference",
394 + ),
395 + );
396 + };
397 + visit(root);
398 + const parts: string[] = [];
399 + let offset = 0;
400 + for (const edit of edits) {
401 + parts.push(markdown.slice(offset, edit.start), edit.content);
402 + offset = edit.end;
403 + }
404 + parts.push(markdown.slice(offset));
405 + return { markdown: parts.join(""), fileHrefs };
406 +}
apps/mobile/src/lib/markdownHtml.test.ts
+202 -1
@@ -1,6 +1,16 @@
1 import { describe, expect, it } from "vite-plus/test";
2 -import { markdownHtmlContent, markdownWithHtml, parseMarkdownDocument } from "./markdownDocument";
2 +import {
3 + markdownHtmlContent,
4 + markdownWithHtml,
5 + markdownWithFileEmbeds,
6 + parseMarkdownDocument,
7 + type MarkdownNode,
8 +} from "./markdownDocument";
9 import { markdownImageSources } from "./markdownImageSources";
10 +import { markdownFileEmbedLabel, resolveMarkdownMediaPreview } from "./markdownMedia";
11 +import { resolveMarkdownLinkPresentation } from "./markdownLinks";
12 +import { EnvironmentId, ThreadId } from "@t3tools/contracts";
13 +import { parseMarkdown } from "react-native-enriched-markdown/src/web/parseMarkdown";
14
15 describe("HTML in native Markdown", () => {
16 it("preserves screenshot URLs and captions from GitHub HTML image embeds", () => {
@@ -95,3 +105,194 @@ describe("HTML in native Markdown", () => {
105 expect(markdownWithHtml('Run <a href="javascript:alert(1)">this</a> now')).toBe("Run this now");
106 });
107 });
108 +
109 +describe("file embeds in native thread and file Markdown", () => {
110 + const input = {
111 + environmentId: EnvironmentId.make("environment-1"),
112 + threadId: ThreadId.make("thread-1"),
113 + workspaceRoot: "/repo",
114 + };
115 + const assets = (markdown: string) => {
116 + const result: MarkdownNode[] = [];
117 + const visit = (node: MarkdownNode) => {
118 + if (node.type === "link" || node.type === "image") result.push(node);
119 + if ("children" in node) node.children.forEach(visit);
120 + };
121 + visit(parseMarkdownDocument(markdown));
122 + return result;
123 + };
124 +
125 + it.each([
126 + [
127 + "[![sheet](./report.csv)](https://example.com/download)",
128 + "report.csv",
129 + "https://example.com/download",
130 + ],
131 + ["[![report](./report.pdf)](./report.pdf)", "report.pdf", "./report.pdf"],
132 + [
133 + "[![sheet][f]][download]\n\n[f]: ./report.csv\n[download]: https://example.com/download",
134 + "report.csv",
135 + "https://example.com/download",
136 + ],
137 + ])("keeps the enclosing link for %s", async (source, filename, target) => {
138 + const converted = markdownWithFileEmbeds(source, (href, standalone) =>
139 + markdownFileEmbedLabel(href, input, standalone),
140 + );
141 + expect((await parseMarkdown(converted.markdown)).children).toMatchObject([
142 + {
143 + type: "Paragraph",
144 + children: [
145 + {
146 + type: "Link",
147 + attributes: { url: target },
148 + children: [{ type: "Text", content: filename }],
149 + },
150 + ],
151 + },
152 + ]);
153 + });
154 +
155 + it.each(["f", "F", "File Label", "file label"])(
156 + "uses the first reference definition for %s",
157 + async (identifier) => {
158 + const source = `![sheet][${identifier}]\n\n[${identifier.toLowerCase()}]: ./report.csv\n[${identifier.toUpperCase()}]: ./report.xlsx`;
159 + const converted = markdownWithFileEmbeds(source, (href, standalone) =>
160 + markdownFileEmbedLabel(href, input, standalone),
161 + );
162 + expect(converted.fileHrefs).toEqual(new Set(["./report.csv"]));
163 + expect((await parseMarkdown(converted.markdown)).children).toMatchObject([
164 + {
165 + type: "Paragraph",
166 + children: [
167 + {
168 + type: "Link",
169 + attributes: { url: "./report.csv" },
170 + children: [{ type: "Text", content: "report.csv" }],
171 + },
172 + ],
173 + },
174 + ]);
175 + expect((await parseMarkdown(source)).children).toMatchObject([
176 + { type: "Paragraph", children: [{ type: "Image", attributes: { url: "./report.csv" } }] },
177 + ]);
178 + },
179 + );
180 +
181 + it.each([
182 + "report.csv",
183 + "report.tsv",
184 + "report.pdf",
185 + "report.docx",
186 + "report.xlsx",
187 + "report.pptx",
188 + "report.unknown",
189 + "main.tf",
190 + "schema.prisma",
191 + "index.astro",
192 + "main.zig",
193 + "Containerfile",
194 + "sound.mp3",
195 + "clip.mp4",
196 + ])("uses filename links throughout prose, lists, and tables for %s", (name) => {
197 + for (const href of [
198 + `./${name}`,
199 + `/tmp/${name}`,
200 + `file:///tmp/${name}`,
201 + `https://cdn.example.com/${name}?signature=a%2fb`,
202 + ]) {
203 + if (name === "Containerfile" && href.startsWith("https:")) continue;
204 + for (const source of [
205 + `download: ![sheet](<${href}>)`,
206 + `- ![sheet](<${href}>)`,
207 + `| file |\n| --- |\n| ![sheet](<${href}>) |`,
208 + `download: ![sheet][file]\n\n[file]: <${href}>`,
209 + `download: <img src="${href}" alt="sheet">`,
210 + ]) {
211 + const converted = markdownWithFileEmbeds(markdownWithHtml(source), (url, standalone) =>
212 + markdownFileEmbedLabel(url, input, standalone),
213 + );
214 + const image = href.startsWith("https:") && /\.(unknown|tf|prisma|astro|zig)$/.test(name);
215 + if (image) expect(converted.markdown).toBe(markdownWithHtml(source));
216 + else
217 + expect(assets(converted.markdown)).toMatchObject([
218 + { type: "link", url: href, children: [{ type: "text", value: name }] },
219 + ]);
220 + expect(converted.fileHrefs.has(href)).toBe(!image);
221 + const preview = resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true });
222 + if (
223 + !href.startsWith("https:") &&
224 + !name.endsWith(".pdf") &&
225 + !name.endsWith(".mp3") &&
226 + !name.endsWith(".mp4")
227 + ) {
228 + expect(preview?.kind).toBe("file");
229 + expect(resolveMarkdownLinkPresentation(href)).toMatchObject({ kind: "file" });
230 + }
231 + }
232 + }
233 + });
234 +
235 + it("retains standalone audio players and image/video embeds in threads", () => {
236 + const source =
237 + "![sound](./sound.mp3)\n\n![image](./image.png)\n\n![clip](./clip.mp4)\n\ninline ![photo](./photo.png)";
238 + const converted = markdownWithFileEmbeds(source, (href, standalone) =>
239 + markdownFileEmbedLabel(href, input, standalone),
240 + );
241 + expect(converted.markdown).toBe(source);
242 + expect(converted.fileHrefs.size).toBe(0);
243 + expect(resolveMarkdownMediaPreview("./sound.mp3", input)?.kind).toBe("audio");
244 + });
245 +
246 + it("uses audio filenames in file previews and draft workspaces", () => {
247 + const draft = { ...input, threadId: undefined, workspaceRoot: "/repo/docs" };
248 + const converted = markdownWithFileEmbeds("![sound](./sound.mp3)", (href) =>
249 + markdownFileEmbedLabel(href, draft, false),
250 + );
251 + expect(assets(converted.markdown)).toMatchObject([
252 + { type: "link", url: "./sound.mp3", children: [{ value: "sound.mp3" }] },
253 + ]);
254 + expect(resolveMarkdownMediaPreview("./sound.mp3", draft)?.source).toMatchObject({
255 + resource: { _tag: "draft-workspace-file", cwd: "/repo/docs", path: "/repo/docs/./sound.mp3" },
256 + });
257 + });
258 +
259 + it("keeps captured images on the image path and documents on filename links", () => {
260 + const captured = { ...input, captured: true };
261 + const converted = markdownWithFileEmbeds(
262 + "![photo](./photo.png)\n\n![clip](./clip.mp4)\n\n![sheet](./report.csv)",
263 + (href, standalone) => markdownFileEmbedLabel(href, captured, standalone),
264 + );
265 + expect(assets(converted.markdown)).toMatchObject([
266 + { type: "image", url: "./photo.png" },
267 + { type: "image", url: "./clip.mp4" },
268 + { type: "link", url: "./report.csv", children: [{ value: "report.csv" }] },
269 + ]);
270 + expect(resolveMarkdownMediaPreview("./report.csv", captured)).toBeNull();
271 + });
272 +
273 + it("preserves table structure and filename punctuation", () => {
274 + const source = "| file |\n| --- |\n| ![sheet](./report%5B1%5D%26%7C.csv) |";
275 + const converted = markdownWithFileEmbeds(source, (href, standalone) =>
276 + markdownFileEmbedLabel(href, input, standalone),
277 + );
278 + expect(parseMarkdownDocument(converted.markdown).children[0]?.type).toBe("table");
279 + expect(assets(converted.markdown)).toMatchObject([
280 + { type: "link", url: "./report%5B1%5D%26%7C.csv", children: [{ value: "report[1]&|.csv" }] },
281 + ]);
282 + });
283 +
284 + it("keeps authored positions, signed URLs, and code examples literal", () => {
285 + const href = "https://cdn.example.com/report%23one%2520.csv?name=&lt;&signature=a%2fb";
286 + const source = `![report](<${href.replaceAll("&", "\\&")}>)\n\n![source](./main.tf#L42C3)\n\n\`![sheet](./literal.csv)\`\n\n\`\`\`md\n![sheet](./fenced.csv)\n\`\`\``;
287 + const converted = markdownWithFileEmbeds(source, (url, standalone) =>
288 + markdownFileEmbedLabel(url, input, standalone),
289 + );
290 + expect(assets(converted.markdown)).toMatchObject([
291 + { type: "link", url: href, children: [{ value: "report#one%20.csv" }] },
292 + { type: "link", url: "./main.tf#L42C3", children: [{ value: "main.tf · L42:C3" }] },
293 + ]);
294 + expect(converted.markdown).toContain("`![sheet](./literal.csv)`");
295 + expect(converted.markdown).toContain("```md\n![sheet](./fenced.csv)\n```");
296 + expect(converted.fileHrefs.has(href)).toBe(true);
297 + });
298 +});
apps/mobile/src/lib/markdownMedia.test.ts
+203 -5
@@ -2,6 +2,7 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 import { describe, expect, it } from "vite-plus/test";
3
4 import { resolveMarkdownMediaPreview } from "./markdownMedia";
5 +import { resolveMarkdownLinkPresentation } from "./markdownLinks";
6
7 const input = {
8 environmentId: EnvironmentId.make("environment-1"),
@@ -35,9 +36,9 @@ describe("resolveMarkdownMediaPreview", () => {
36 });
37
38 it.each([
38 - ["/tmp/frame%23one.png:12", "/tmp/frame#one.png"],
39 - ["/tmp/frame%3Fone.png:12:3", "/tmp/frame?one.png"],
40 - ["/tmp/frame%2523one.png:12", "/tmp/frame%23one.png"],
39 + ["/tmp/frame%23one.png", "/tmp/frame#one.png"],
40 + ["/tmp/frame%3Fone.png", "/tmp/frame?one.png"],
41 + ["/tmp/frame%2523one.png", "/tmp/frame%23one.png"],
42 ["file://server/share/frame.png", "\\\\server\\share\\frame.png", "\\\\server\\share"],
43 ["\\\\server\\share\\frame.png", "\\\\server\\share\\frame.png", "\\\\server\\share"],
44 ])("keeps encoded filename and UNC semantics for %s", (href, path, workspaceRoot = "/repo") => {
@@ -69,7 +70,7 @@ describe("resolveMarkdownMediaPreview", () => {
70 });
71 });
72
72 - it.each(["./image.png", "./report.pdf"])(
73 + it.each(["./image.png", "./report.pdf", "./sound.mp3"])(
74 "uses the draft workspace when no thread exists: %s",
75 (href) => {
76 expect(
@@ -82,11 +83,208 @@ describe("resolveMarkdownMediaPreview", () => {
83
84 it("keeps captured host media unavailable while allowing direct media", () => {
85 const captured = { ...input, captured: true };
85 - for (const href of ["./image.png", "./clip.mp4", "./report.pdf"]) {
86 + for (const href of ["./image.png", "./clip.mp4", "./report.pdf", "./sound.mp3"]) {
87 expect(resolveMarkdownMediaPreview(href, captured)).toBeNull();
88 }
89 expect(resolveMarkdownMediaPreview("https://cdn.example.com/report.pdf", captured)?.kind).toBe(
90 "pdf",
91 );
92 });
93 +
94 + it.each([["/tmp/sound%23one.mp3", "audio", "audio/mpeg", "/tmp/sound#one.mp3"]])(
95 + "opens an authored embed through the host: %s",
96 + (href, kind, mimeType, path) => {
97 + expect(resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true })).toMatchObject({
98 + kind,
99 + source: {
100 + kind: "document",
101 + name: path.split("/").at(-1),
102 + mimeType,
103 + environmentId: input.environmentId,
104 + resource: { _tag: "media-file", threadId: input.threadId, path },
105 + },
106 + });
107 + },
108 + );
109 +
110 + it.each([
111 + ["sound%20one.mp3", "audio"],
112 + ["report%20one.csv", "document"],
113 + ["report.tsv", "document"],
114 + ["report.docx", "document"],
115 + ["report.xlsx", "document"],
116 + ["report.pptx", "document"],
117 + ["report.unknown", "image"],
118 + ])("preserves direct signed embeds: %s", (name, kind) => {
119 + const href = `https://cdn.example.com/${name}?signature=a%2fb`;
120 + expect(resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true })).toMatchObject({
121 + kind,
122 + source: { uri: href, name: decodeURIComponent(name) },
123 + });
124 + });
125 +
126 + it.each([
127 + "https://docs.example.com/guide.html",
128 + "https://example.com/index.php?topic=files",
129 + "https://example.com/report.unknown",
130 + "https://example.com/main.tf",
131 + "https://example.com/schema.prisma",
132 + "https://example.com/chart.php?id=1",
133 + "http://example.com/chart.php?id=1",
134 + "//example.com/chart.php?id=1",
135 + "https://example.com/chart?format=png",
136 + "http://example.com/chart?format=png",
137 + "//example.com/chart?format=png",
138 + ])("keeps ordinary remote links in the browser: %s", (href) => {
139 + expect(resolveMarkdownMediaPreview(href, input)).toBeNull();
140 + expect(resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true })).toMatchObject({
141 + kind: "image",
142 + source: { uri: href.startsWith("//") ? `https:${href}` : href },
143 + });
144 + });
145 +
146 + it.each([
147 + "javascript:report.csv",
148 + "data:text/csv,a,b",
149 + "ftp://server/report.csv",
150 + "~/report.csv",
151 + ])("rejects blocked document links and embeds: %s", (href) => {
152 + expect(resolveMarkdownMediaPreview(href, input)).toBeNull();
153 + expect(resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true })).toBeNull();
154 + });
155 +
156 + it.each([
157 + "src/main.ts",
158 + "src/main.tsx",
159 + "report.txt",
160 + "report.md",
161 + "report.html",
162 + "package.json",
163 + "report.csv",
164 + "report.tsv",
165 + "LICENSE",
166 + "Dockerfile",
167 + "main.tf",
168 + "schema.prisma",
169 + "index.astro",
170 + "main.zig",
171 + "Containerfile",
172 + ])("routes text and table links and embeds to the file screen: %s", (name) => {
173 + for (const href of [name, "./" + name, "/tmp/" + name, "file:///tmp/" + name]) {
174 + for (const imageEmbed of [false, true]) {
175 + expect(resolveMarkdownMediaPreview(href, { ...input, imageEmbed })).toMatchObject({
176 + kind: "file",
177 + source: { name: name.split("/").at(-1) },
178 + });
179 + }
180 + expect(resolveMarkdownLinkPresentation(href)).toMatchObject({ kind: "file" });
181 + }
182 + });
183 +
184 + it.each(["doc", "docx", "xls", "xlsx", "ppt", "pptx", "unknown", "zip"])(
185 + "keeps main's source reader for host %s links and embeds",
186 + (extension) => {
187 + const name = `report.${extension}`;
188 + for (const href of [name, `./${name}`, `/tmp/${name}`, `file:///tmp/${name}`]) {
189 + for (const imageEmbed of [false, true]) {
190 + expect(resolveMarkdownMediaPreview(href, { ...input, imageEmbed })).toMatchObject({
191 + kind: "file",
192 + source: {
193 + name,
194 + mimeType: "text/plain",
195 + },
196 + });
197 + expect(
198 + resolveMarkdownMediaPreview(href, {
199 + ...input,
200 + threadId: undefined,
201 + imageEmbed,
202 + })?.kind,
203 + ).toBe("file");
204 + expect(resolveMarkdownLinkPresentation(href)).toMatchObject({ kind: "file" });
205 + }
206 + }
207 + },
208 + );
209 +
210 + it.each(["report.csv", "report.tsv", "report.docx", "report.xlsx", "report.unknown"])(
211 + "preserves draft, captured, and encoded document paths: %s",
212 + (name) => {
213 + const href = `/tmp/one%23two%2520.${name.split(".").at(-1)}`;
214 + const preview = resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true });
215 + expect(preview?.source).toMatchObject({
216 + name: `one#two%20.${name.split(".").at(-1)}`,
217 + resource: { path: decodeURIComponent(href) },
218 + });
219 + expect(
220 + resolveMarkdownMediaPreview(href, { ...input, threadId: undefined })?.source,
221 + ).toMatchObject({ resource: { _tag: "draft-workspace-file", cwd: "/repo" } });
222 + expect(resolveMarkdownMediaPreview(href, { ...input, captured: true })).toBeNull();
223 + expect(
224 + resolveMarkdownMediaPreview(href, { ...input, threadId: undefined, workspaceRoot: null }),
225 + ).toBeNull();
226 + },
227 + );
228 +
229 + it.each([
230 + ["src/main.ts:42", "/repo/src/main.ts", 42],
231 + ["src/main.ts#L42C3", "/repo/src/main.ts", 42],
232 + ["report.csv:142:3", "/repo/report.csv", 142],
233 + ["/tmp/report.pdf:12#page=2", "/tmp/report.pdf", 12],
234 + ["file:///tmp/sound.mp3#L12", "/tmp/sound.mp3", 12],
235 + ["/tmp/frame%23one.png:12", "/tmp/frame#one.png", 12],
236 + ["/tmp/frame%3Fone.png:12:3", "/tmp/frame?one.png", 12],
237 + ["/tmp/frame%2523one.png:12", "/tmp/frame%23one.png", 12],
238 + ["./clip.mp4#L12C3", "/repo/./clip.mp4", 12],
239 + ["src/main.ts%3A42%3A3", "/repo/src/main.ts", 42],
240 + ])("keeps positioned links on the file route: %s", (href, path, line) => {
241 + expect(resolveMarkdownMediaPreview(href, input)).toBeNull();
242 + const presentation = resolveMarkdownLinkPresentation(href);
243 + expect(presentation).toMatchObject({ kind: "file", line });
244 + if (presentation.kind === "file") {
245 + expect(
246 + presentation.path.startsWith("/") ? presentation.path : "/repo/" + presentation.path,
247 + ).toBe(path);
248 + }
249 + });
250 +
251 + it.each(["mp3", "wav", "m4a", "ogg", "oga", "aac", "aiff", "flac", "opus"])(
252 + "resolves audio embeds as audio rather than images: %s",
253 + (extension) => {
254 + expect(
255 + resolveMarkdownMediaPreview("/tmp/sound." + extension, { ...input, imageEmbed: true }),
256 + ).toMatchObject({
257 + kind: "audio",
258 + source: { kind: "document", resource: { _tag: "media-file" } },
259 + });
260 + },
261 + );
262 +
263 + it("does not authorize local files without thread or draft context", () => {
264 + expect(
265 + resolveMarkdownMediaPreview("/tmp/report.pdf", {
266 + ...input,
267 + threadId: undefined,
268 + workspaceRoot: null,
269 + }),
270 + ).toBeNull();
271 + expect(resolveMarkdownMediaPreview("report.pdf", { ...input, workspaceRoot: null })).toBeNull();
272 + });
273 +
274 + it("decodes document filenames once and preserves image and video embeds", () => {
275 + expect(resolveMarkdownMediaPreview("/tmp/report%23one%2520.pdf", input)).toMatchObject({
276 + kind: "pdf",
277 + source: {
278 + name: "report#one%20.pdf",
279 + mimeType: "application/pdf",
280 + resource: { path: "/tmp/report#one%20.pdf" },
281 + },
282 + });
283 + expect(
284 + resolveMarkdownMediaPreview("/tmp/image.png", { ...input, imageEmbed: true })?.kind,
285 + ).toBe("image");
286 + expect(resolveMarkdownMediaPreview("/tmp/clip.mp4", { ...input, imageEmbed: true })?.kind).toBe(
287 + "video",
288 + );
289 + });
290 });
apps/mobile/src/lib/markdownMedia.ts
+73 -6
@@ -2,20 +2,37 @@ import {
2 classifyMarkdownImageSource,
3 markdownImageSourceFragment,
4 } from "@t3tools/client-runtime/markdown-images";
5 +import {
6 + audioMimeTypeFromExtension,
7 + mediaMimeTypeFromExtension,
8 +} from "@t3tools/shared/filePreview";
9 import { splitFilePathPosition } from "@t3tools/shared/fileLinks";
10 +import { parseMarkdownFileLink } from "@t3tools/shared/markdownLinks";
11 import {
12 mediaFileReference,
13 mediaUrlReference,
14 mediaReferenceFileName,
15 } from "@t3tools/client-runtime/media-reference";
16 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
12 -import { normalizeNativeMarkdownUrl } from "./markdownLinks";
17 +import { normalizeNativeMarkdownUrl, resolveMarkdownLinkPresentation } from "./markdownLinks";
18 import { resolveMobileMarkdownMediaSource } from "./markdownMediaSource";
19
20 import type { FilePreviewSource } from "../components/FilePreviewModal";
21 import type { MediaVideoPreviewSource } from "./videoPreviewSource";
22 import type { MediaActionsSource } from "./mediaActionsSource";
23
24 +const DOCUMENT_MIME_TYPES: Readonly<Record<string, string>> = {
25 + ".pdf": "application/pdf",
26 + ".csv": "text/csv",
27 + ".tsv": "text/tab-separated-values",
28 + ".doc": "application/msword",
29 + ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
30 + ".xls": "application/vnd.ms-excel",
31 + ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
32 + ".ppt": "application/vnd.ms-powerpoint",
33 + ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
34 +};
35 +
36 export function resolveMarkdownMediaPreview(
37 href: string,
38 input: {
@@ -27,10 +44,13 @@ export function resolveMarkdownMediaPreview(
44 },
45 ):
46 | { readonly kind: "image"; readonly source: FilePreviewSource }
30 - | { readonly kind: "pdf"; readonly source: FilePreviewSource }
47 + | { readonly kind: "pdf" | "audio" | "document" | "file"; readonly source: FilePreviewSource }
48 | { readonly kind: "video"; readonly source: MediaVideoPreviewSource }
49 | null {
50 + if (parseMarkdownFileLink(href)?.line !== undefined) return null;
51 const classified = classifyMarkdownImageSource(href, input.workspaceRoot);
52 + if (classified._tag === "Direct" && /^data:(?!image\/|video\/)/i.test(classified.uri))
53 + return null;
54 if (classified._tag !== "Blocked") {
55 const path =
56 classified._tag === "Direct" ? classified.uri : splitFilePathPosition(classified.path).path;
@@ -39,12 +59,37 @@ export function resolveMarkdownMediaPreview(
59 ? mediaUrlReference(path)
60 : mediaFileReference(path, input.workspaceRoot);
61 const name = reference && mediaReferenceFileName(reference);
42 - if (name && /\.pdf$/i.test(name)) {
43 - const common = { kind: "pdf" as const, name, mimeType: "application/pdf" };
62 + const extension = name?.slice(name.lastIndexOf(".")).toLowerCase() ?? "";
63 + const isFile = classified._tag === "WorkspaceFile" || /^\.[a-z0-9]+$/i.test(extension);
64 + if (
65 + name &&
66 + isFile &&
67 + mediaMimeTypeFromExtension(extension) === null &&
68 + (classified._tag !== "Direct" ||
69 + Object.hasOwn(DOCUMENT_MIME_TYPES, extension) ||
70 + audioMimeTypeFromExtension(extension) !== null)
71 + ) {
72 + const audioMimeType = audioMimeTypeFromExtension(extension);
73 + const kind = audioMimeType
74 + ? "audio"
75 + : extension === ".pdf"
76 + ? "pdf"
77 + : classified._tag === "WorkspaceFile"
78 + ? "file"
79 + : "document";
80 + const mimeType =
81 + audioMimeType ??
82 + (kind === "file" ? "text/plain" : DOCUMENT_MIME_TYPES[extension]) ??
83 + "application/octet-stream";
84 + const common = {
85 + kind: kind === "pdf" ? ("pdf" as const) : ("document" as const),
86 + name,
87 + mimeType,
88 + };
89 if (classified._tag === "Direct") {
90 const uri = normalizeNativeMarkdownUrl(path);
91 return {
47 - kind: "pdf",
92 + kind,
93 source: {
94 ...common,
95 uri,
@@ -65,7 +110,7 @@ export function resolveMarkdownMediaPreview(
110 : null;
111 if (!resource) return null;
112 return {
68 - kind: "pdf",
113 + kind,
114 source: {
115 ...common,
116 environmentId: input.environmentId,
@@ -111,3 +156,25 @@ export function resolveMarkdownMediaPreview(
156 ? { kind, source: { type: "media", name, mimeType, ...target, actionsSource } }
157 : { kind, source: { kind, name, ...target, actionsSource } };
158 }
159 +
160 +export function markdownFileEmbedLabel(
161 + href: string,
162 + input: Parameters<typeof resolveMarkdownMediaPreview>[1],
163 + standalone: boolean,
164 +): string | null {
165 + const media = resolveMarkdownMediaPreview(href, { ...input, imageEmbed: true });
166 + if (media) {
167 + if (
168 + media.kind === "image" ||
169 + ((media.kind === "video" || media.kind === "audio") && standalone)
170 + )
171 + return null;
172 + return media.source.name ?? null;
173 + }
174 + const file = resolveMarkdownLinkPresentation(href);
175 + if (file.kind === "file" && file.line === undefined) {
176 + if (mediaMimeTypeFromExtension(file.path.slice(file.path.lastIndexOf("."))) !== null)
177 + return null;
178 + }
179 + return file.kind === "file" ? file.label : null;
180 +}
apps/mobile/src/native/EnrichedMarkdownText.tsx
+25 -17
@@ -5,6 +5,7 @@ import {
5 formatComposerContextReference,
6 } from "@t3tools/shared/composerContextReferences";
7 import {
8 + markdownWithFileEmbeds,
9 markdownWithHtml,
10 markdownWithInlineFileLinks,
11 markdownWithTableBreaks,
@@ -153,18 +154,18 @@ function enrichedStyle(
154 }
155
156 export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
156 - const { renderImage, resolveImageSource } = props;
157 + const { renderImage, resolveImageSource, fileEmbedLabel } = props;
158 const { themeAppearance, mathRenderingEnabled } = useAppearancePreferences();
158 - const markdown = useMemo(
159 - () =>
160 - markdownWithTableBreaks(
161 - markdownWithInlineFileLinks(
162 - markdownWithHtml(props.markdown),
163 - ENRICHED_INLINE_FILE_LINK_REGEX,
164 - ),
165 - ),
166 - [props.markdown],
167 - );
159 + const { markdown, fileHrefs } = useMemo(() => {
160 + const content = markdownWithInlineFileLinks(
161 + markdownWithHtml(props.markdown),
162 + ENRICHED_INLINE_FILE_LINK_REGEX,
163 + );
164 + const files = fileEmbedLabel
165 + ? markdownWithFileEmbeds(content, fileEmbedLabel)
166 + : { markdown: content, fileHrefs: new Set<string>() };
167 + return { ...files, markdown: markdownWithTableBreaks(files.markdown) };
168 + }, [props.markdown, fileEmbedLabel]);
169 const [parsedLinkUrls, setParsedLinkUrls] = useState<ReadonlyArray<string>>([]);
170 const onLinksChange = useCallback((links: MarkdownLinkOccurrence[]) => {
171 const urls = [...new Set(links.map((link) => link.url))];
@@ -191,16 +192,21 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
192 : parsedLinkUrls,
193 [parsedLinkUrls, skillLinkKey],
194 );
194 - const { linkVariants, linkPillContent } = useEnrichedLinkVariants(linkUrls, props);
195 + const { linkVariants, linkPillContent } = useEnrichedLinkVariants(linkUrls, props, fileHrefs);
196 const linkRecognition = useMemo(() => ({ text: skillRegex ?? undefined }), [skillRegex]);
197 const [activeMenu, setActiveMenu] = useState<{
198 url: string;
199 menu: NonNullable<ReturnType<NonNullable<typeof props.fileContextMenu>>>;
200 } | null>(null);
200 - const { fileContextMenu, onLinkPress, onFileContextMenuAction } = props;
201 + const { fileContextMenu, onFileContextMenuAction } = props;
202 + const onLinkPress = useCallback(
203 + (url: string) =>
204 + (fileHrefs.has(url) ? (props.onImagePress ?? props.onLinkPress) : props.onLinkPress)?.(url),
205 + [fileHrefs, props.onImagePress, props.onLinkPress],
206 + );
207 const performMenuAction = useCallback(
208 (url: string, actionId: string) => {
203 - if (actionId === "enriched-open-link") onLinkPress?.(url);
209 + if (actionId === "enriched-open-link") onLinkPress(url);
210 else if (actionId === "enriched-copy-link") copyTextWithHaptic(url);
211 else if (actionId === "enriched-share-link") void Share.share({ message: url });
212 else onFileContextMenuAction?.(url, actionId);
@@ -209,7 +215,7 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
215 );
216 const linkContextMenuItems = useMemo(
217 () =>
212 - Platform.OS === "ios" && (fileContextMenu || onLinkPress)
218 + Platform.OS === "ios" && (fileContextMenu || props.onLinkPress || props.onImagePress)
219 ? Object.fromEntries(
220 linkUrls.map((url) => {
221 const menu = fileContextMenu?.(url) ?? {
@@ -231,7 +237,7 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
237 }),
238 )
239 : undefined,
234 - [linkUrls, fileContextMenu, onLinkPress, performMenuAction],
240 + [linkUrls, fileContextMenu, props.onLinkPress, props.onImagePress, performMenuAction],
241 );
242 const selectionClipboard = useMemo(() => {
243 const fragment = decodeComposerContextFragment(props.contextClipboardFragment);
@@ -330,7 +336,9 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
336 enableTaskListItemToggle={false}
337 enableCodeBlockWrapToggle
338 spoilerOverlay="solid"
333 - onLinkPress={props.onLinkPress ? ({ url }) => props.onLinkPress?.(url) : undefined}
339 + onLinkPress={
340 + props.onLinkPress || props.onImagePress ? ({ url }) => onLinkPress(url) : undefined
341 + }
342 onLinkLongPress={onLinkLongPress}
343 linkContextMenuItems={linkContextMenuItems}
344 linkPillContent={linkPillContent}
apps/mobile/src/native/SelectableMarkdownText.types.ts
+1
@@ -73,6 +73,7 @@ export interface SelectableMarkdownTextProps {
73 readonly linkCustomization?: (href: string) => MarkdownLinkCustomization | undefined;
74 readonly contextClipboardFragment?: string;
75 readonly renderImage?: MarkdownImageRenderer;
76 + readonly fileEmbedLabel?: (href: string, standalone: boolean) => string | null;
77 readonly resolveImageSource?: MarkdownImageSourceResolver;
78 readonly onImagePress?: (href: string) => void;
79 readonly marginTop?: number;
apps/mobile/src/native/useEnrichedLinkVariants.ts
+12 -4
@@ -9,7 +9,7 @@ import { contextChipIconSource } from "../lib/contextChipIconSource";
9 import { markdownFileIconSource } from "../lib/markdownFileIcons";
10 import { markdownLinkIcon } from "../lib/markdownLinkIcons";
11 import { useUniwindTheme } from "../lib/useUniwindTheme";
12 -import { resolveMarkdownLinkPresentation } from "../lib/markdownLinks";
12 +import { resolveMarkdownFileIcon, resolveMarkdownLinkPresentation } from "../lib/markdownLinks";
13 import type {
14 MarkdownLinkCustomization,
15 SelectableMarkdownTextProps,
@@ -92,18 +92,26 @@ function presentation(
92 export function useEnrichedLinkVariants(
93 urls: ReadonlyArray<string>,
94 props: SelectableMarkdownTextProps,
95 + fileHrefs: ReadonlySet<string>,
96 ) {
96 - const { linkCustomization, skills, textStyle } = props;
97 + const { linkCustomization, skills, textStyle, fileEmbedLabel } = props;
98 const theme = useUniwindTheme();
99 const links = useMemo(() => {
100 const byUrl = new Map<string, MarkdownLinkCustomization>();
101 for (const url of urls) {
102 if (byUrl.has(url)) continue;
102 - const value = presentation(url, { linkCustomization, skills, textStyle });
103 + const label = fileHrefs.has(url) ? fileEmbedLabel?.(url, false) : null;
104 + const value = label
105 + ? {
106 + label,
107 + color: textStyle.fileTextColor,
108 + icon: markdownFileIconSource(resolveMarkdownFileIcon(label)),
109 + }
110 + : presentation(url, { linkCustomization, skills, textStyle });
111 if (value) byUrl.set(url, value);
112 }
113 return byUrl;
106 - }, [urls, linkCustomization, skills, textStyle]);
114 + }, [urls, linkCustomization, skills, textStyle, fileHrefs, fileEmbedLabel]);
115 const chipForegrounds = useMemo(
116 () =>
117 new Map(
apps/mobile/vite.config.ts
+1
@@ -2,6 +2,7 @@ import { defineConfig } from "vite-plus";
2 import "vite-plus/test/config";
3
4 const reactTests = [
5 + "src/lib/filePreview.test.ts",
6 "src/features/diffs/nativeReviewDiffSurface.test.tsx",
7 "src/features/pull-requests/usePullRequestDiff.test.tsx",
8 "src/components/ui/Dialog.android.test.tsx",
patches/expo-audio@58.0.9.patch
+104
@@ -23,3 +23,107 @@ index 198fe6d..5b39611 100644
23 "url": recorder.url.absoluteString
24 ])
25 }
26 +diff --git a/ios/AudioModule.swift b/ios/AudioModule.swift
27 +--- a/ios/AudioModule.swift
28 ++++ b/ios/AudioModule.swift
29 +@@ -6,6 +6,7 @@
30 +
31 + private let sessionQueue = DispatchQueue(label: "expo.modules.audio.session", qos: .userInitiated)
32 + private var sessionIsActive = false
33 ++ private var hasAudioSessionOwner = false
34 + private var audioSessionActivityKeepers = Set<String>()
35 + private let audioEnabled = OSAllocatedUnfairLock(initialState: true)
36 +
37 +@@ -41,6 +42,16 @@
38 + try setIsAudioActive(isActive)
39 + }
40 +
41 ++ // Video shares AVAudioSession but is absent from this module's registry.
42 ++ Function("setAudioSessionOwner") { (owned: Bool) in
43 ++ self.sessionQueue.sync {
44 ++ self.hasAudioSessionOwner = owned
45 ++ if !owned {
46 ++ self.deactivateSession()
47 ++ }
48 ++ }
49 ++ }
50 ++
51 + AsyncFunction("requestRecordingPermissionsAsync") { (promise: Promise) in
52 + #if os(iOS)
53 + appContext?.permissions?.askForPermission(
54 +@@ -259,9 +259,9 @@
55 + }
56 + }
57 +
58 +- Function("pause") { player in
59 ++ Function("pause") { (player: AudioPlayer, deactivateSession: Bool?) in
60 + player.ref.pause()
61 +- if !player.keepAudioSessionActive {
62 ++ if deactivateSession != false && !player.keepAudioSessionActive {
63 + self.deactivateSession()
64 + }
65 + }
66 +@@ -957,6 +967,7 @@
67 + sessionQueue.asyncAfter(deadline: .now() + .milliseconds(100)) { [weak self] in
68 + guard let self,
69 + self.sessionIsActive,
70 ++ !self.hasAudioSessionOwner,
71 + self.audioSessionActivityKeepers.isEmpty,
72 + !self.isSessionInUse else {
73 + return
74 +diff --git a/src/AudioModule.types.ts b/src/AudioModule.types.ts
75 +--- a/src/AudioModule.types.ts
76 ++++ b/src/AudioModule.types.ts
77 +@@ -27,6 +27,8 @@
78 + */
79 + export declare class NativeAudioModule extends NativeModule {
80 + setIsAudioActiveAsync(active: boolean): Promise<void>;
81 ++ /** iOS only: protect the shared session from delayed expo-audio deactivation. */
82 ++ setAudioSessionOwner?(owned: boolean): void;
83 + setAudioModeAsync(category: Partial<AudioMode>): Promise<void>;
84 + requestRecordingPermissionsAsync(): Promise<PermissionResponse>;
85 + requestNotificationPermissionsAsync(): Promise<PermissionResponse>;
86 +@@ -175,8 +175,9 @@
87 +
88 + /**
89 + * Pauses the player.
90 ++ * @param deactivateSession On iOS, pass false when handing the shared session to another player.
91 + */
92 +- pause(): void;
93 ++ pause(deactivateSession?: boolean): void;
94 +
95 + /**
96 + * Replaces the current audio source with a new one.
97 +diff --git a/build/AudioModule.types.d.ts b/build/AudioModule.types.d.ts
98 +--- a/build/AudioModule.types.d.ts
99 ++++ b/build/AudioModule.types.d.ts
100 +@@ -6,6 +6,8 @@
101 + */
102 + export declare class NativeAudioModule extends NativeModule {
103 + setIsAudioActiveAsync(active: boolean): Promise<void>;
104 ++ /** iOS only: protect the shared session from delayed expo-audio deactivation. */
105 ++ setAudioSessionOwner?(owned: boolean): void;
106 + setAudioModeAsync(category: Partial<AudioMode>): Promise<void>;
107 + requestRecordingPermissionsAsync(): Promise<PermissionResponse>;
108 + requestNotificationPermissionsAsync(): Promise<PermissionResponse>;
109 +@@ -135,8 +135,9 @@
110 + play(): void;
111 + /**
112 + * Pauses the player.
113 ++ * @param deactivateSession On iOS, pass false when handing the shared session to another player.
114 + */
115 +- pause(): void;
116 ++ pause(deactivateSession?: boolean): void;
117 + /**
118 + * Replaces the current audio source with a new one.
119 + */
120 +diff --git a/android/src/main/java/expo/modules/audio/AudioModule.kt b/android/src/main/java/expo/modules/audio/AudioModule.kt
121 +--- a/android/src/main/java/expo/modules/audio/AudioModule.kt
122 ++++ b/android/src/main/java/expo/modules/audio/AudioModule.kt
123 +@@ -678,5 +678,5 @@
124 + }
125 +
126 +- Function("pause") { player: AudioPlayer ->
127 ++ Function("pause") { player: AudioPlayer, /* deactivateSession - iOS only */ _: Boolean? ->
128 + runOnMain {
129 + player.isPaused = false
patches/expo-video@58.0.11.patch new
+93
@@ -0,0 +1,93 @@
1 +diff --git a/android/src/main/java/expo/modules/video/player/VideoPlayer.kt b/android/src/main/java/expo/modules/video/player/VideoPlayer.kt
2 +index 7ccce96..b6f30df 100644
3 +--- a/android/src/main/java/expo/modules/video/player/VideoPlayer.kt
4 ++++ b/android/src/main/java/expo/modules/video/player/VideoPlayer.kt
5 +@@ -265,6 +265,10 @@ class VideoPlayer(val context: Context, appContext: AppContext, source: VideoSou
6 + var keepScreenOnWhilePlaying by VideoPlayerKeepAwake(this, appContext)
7 +
8 + private val playerListener = object : Player.Listener {
9 ++ override fun onPlayWhenReadyChanged(playWhenReady: Boolean, reason: Int) {
10 ++ emit("playbackRequestedChange", mapOf("isPlaybackRequested" to playWhenReady))
11 ++ }
12 ++
13 + override fun onIsPlayingChanged(isPlaying: Boolean) {
14 + this@VideoPlayer.playing = isPlaying
15 + }
16 +diff --git a/ios/VideoPlayerObserver.swift b/ios/VideoPlayerObserver.swift
17 +index adf5820..ce69210 100644
18 +--- a/ios/VideoPlayerObserver.swift
19 ++++ b/ios/VideoPlayerObserver.swift
20 +@@ -46,6 +46,7 @@ private actor ObserverTaskManager {
21 + protocol VideoPlayerObserverDelegate: AnyObject {
22 + func onStatusChanged(player: AVPlayer, oldStatus: PlayerStatus?, newStatus: PlayerStatus, error: Exception?)
23 + func onIsPlayingChanged(player: AVPlayer, oldIsPlaying: Bool?, newIsPlaying: Bool)
24 ++ func onPlaybackRequestedChanged(player: AVPlayer, requested: Bool)
25 + func onRateChanged(player: AVPlayer, oldRate: Float?, newRate: Float)
26 + func onVolumeChanged(player: AVPlayer, oldVolume: Float?, newVolume: Float)
27 + func onPlayedToEnd(player: AVPlayer)
28 +@@ -66,6 +67,7 @@ protocol VideoPlayerObserverDelegate: AnyObject {
29 + extension VideoPlayerObserverDelegate {
30 + func onStatusChanged(player: AVPlayer, oldStatus: PlayerStatus?, newStatus: PlayerStatus, error: Exception?) {}
31 + func onIsPlayingChanged(player: AVPlayer, oldIsPlaying: Bool?, newIsPlaying: Bool) {}
32 ++ func onPlaybackRequestedChanged(player: AVPlayer, requested: Bool) {}
33 + func onRateChanged(player: AVPlayer, oldRate: Float?, newRate: Float) {}
34 + func onVolumeChanged(player: AVPlayer, oldVolume: Float?, newVolume: Float) {}
35 + func onPlayedToEnd(player: AVPlayer) {}
36 +@@ -497,6 +499,12 @@ class VideoPlayerObserver: VideoSourceLoaderListener {
37 + }
38 +
39 + private func onTimeControlStatusChanged(_ player: AVPlayer, _ change: NSKeyValueObservedChange<AVPlayer.TimeControlStatus>) {
40 ++ // Waiting (including evaluatingBufferingRate) preserves the native play request.
41 ++ let requested = player.timeControlStatus != .paused && player.status != .failed && player.currentItem?.status != .failed
42 ++ delegates.forEach { delegate in
43 ++ delegate.value?.onPlaybackRequestedChanged(player: player, requested: requested)
44 ++ }
45 ++
46 + // iOS changes timeControlStatus after an error, so we need to check for errors.
47 + if player.status == .failed || player.currentItem?.status == .failed {
48 + isPlaying = false
49 +diff --git a/ios/VideoPlayer.swift b/ios/VideoPlayer.swift
50 +index 3c2fde4..ef43248 100644
51 +--- a/ios/VideoPlayer.swift
52 ++++ b/ios/VideoPlayer.swift
53 +@@ -396,6 +396,12 @@ internal final class VideoPlayer: SharedRef<AVPlayer>, Hashable, VideoPlayerObse
54 + VideoManager.shared.setAppropriateAudioSessionOrWarn()
55 + }
56 +
57 ++ func onPlaybackRequestedChanged(player: AVPlayer, requested: Bool) {
58 ++ if self.appContext != nil {
59 ++ self.emit(event: "playbackRequestedChange", payload: ["isPlaybackRequested": requested])
60 ++ }
61 ++ }
62 ++
63 + func onRateChanged(player: AVPlayer, oldRate: Float?, newRate: Float) {
64 + if #available(iOS 16.0, tvOS 16.0, *) {
65 + if player.defaultRate != playbackRate {
66 +diff --git a/src/VideoPlayerEvents.types.ts b/src/VideoPlayerEvents.types.ts
67 +index c53b082..2d5fbcb 100644
68 +--- a/src/VideoPlayerEvents.types.ts
69 ++++ b/src/VideoPlayerEvents.types.ts
70 +@@ -11,6 +11,9 @@ import type {
71 + * Handlers for events which can be emitted by the player.
72 + */
73 + export type VideoPlayerEvents = {
74 ++ /** Native play/pause intent, preserved while buffering or seeking. */
75 ++ playbackRequestedChange(payload: { isPlaybackRequested: boolean }): void;
76 ++
77 + /**
78 + * Handler for an event emitted when the status of the player changes.
79 + */
80 +diff --git a/build/VideoPlayerEvents.types.d.ts b/build/VideoPlayerEvents.types.d.ts
81 +index 9c7eaea..25b8799 100644
82 +--- a/build/VideoPlayerEvents.types.d.ts
83 ++++ b/build/VideoPlayerEvents.types.d.ts
84 +@@ -3,6 +3,9 @@ import type { PlayerError, SubtitleTrack, VideoPlayerStatus, VideoSource, VideoT
85 + * Handlers for events which can be emitted by the player.
86 + */
87 + export type VideoPlayerEvents = {
88 ++ /** Native play/pause intent, preserved while buffering or seeking. */
89 ++ playbackRequestedChange(payload: { isPlaybackRequested: boolean }): void;
90 ++
91 + /**
92 + * Handler for an event emitted when the status of the player changes.
93 + */
pnpm-lock.yaml
+7 -6
@@ -361,10 +361,11 @@ patchedDependencies:
361 alchemy@2.0.0-beta.80: bea1b6c0c0b23157fd5f439a1d7feff430f28ac1621ba135d8a13eeec60ccacd
362 app-builder-lib@26.16.1: a28c2dfcfc2b90d6c6247e199e6537391db9ecd941854c650910d607442512d3
363 dbus-next@0.10.2: cfff57561b0ee59b5addb3b2e6c6f20906e967507a530ab67e8db8108e520ba4
364 - expo-audio@58.0.9: 2c2f8c73a23d48804c8b537b8cd73c25eb331aa47d82eaa481c6766cb81e5add
364 + expo-audio@58.0.9: 530af071088a809fe1a97ce2b2269c78335fbb5dcd3893d6937ff5c304c85a0a
365 expo-modules-core@58.0.22: f0b0fd100550ed76e5c25b4d13eb7c9ff62825f8f197c53edf7bf447c50c9fb7
366 expo-network@58.0.3: cd09b6d1744dde4efa081b5619ebcff38877d98f7502a51cab121629dece8237
367 expo-sharing@58.0.19: 61a9741dc6166fdbb5baa2e489275a65dd21aa11d2c915f490a1b337a4468e76
368 + expo-video@58.0.11: e80ec3ef8c4af50a607beea1c0917e71ba679844efdb702b45d17a5f03cf466c
369 expo-widgets@58.0.20: 8bf49067f93742855e15f29559ac75c8b50230b47069060993c9ea01dac11171
370 mdast-util-math@3.0.0: afe6b2c89e1eaddfd3c90cf2723f12c9a17d513e65beff51653781486013251c
371 micromark-extension-gfm-table@2.1.1: 9ad23a530e45d9f83cba1da8654fe16d5af8b59d5c73d5c7a7c91fd25b9be1d8
@@ -625,7 +626,7 @@ importers:
626 version: 58.0.16(@tsc-rs/typescript@0.8.0)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1)
627 expo-audio:
628 specifier: 58.0.9
628 - version: 58.0.9(patch_hash=2c2f8c73a23d48804c8b537b8cd73c25eb331aa47d82eaa481c6766cb81e5add)(expo-asset@58.0.16(@tsc-rs/typescript@0.8.0)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1))(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
629 + version: 58.0.9(patch_hash=530af071088a809fe1a97ce2b2269c78335fbb5dcd3893d6937ff5c304c85a0a)(expo-asset@58.0.16(@tsc-rs/typescript@0.8.0)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1))(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
630 expo-auth-session:
631 specifier: ~58.0.13
632 version: 58.0.13(@tsc-rs/typescript@0.8.0)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1)
@@ -717,8 +718,8 @@ importers:
718 specifier: ~58.0.17
719 version: 58.0.17(expo-dev-client@58.0.14(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6)))(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1)
720 expo-video:
720 - specifier: ~58.0.11
721 - version: 58.0.11(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
721 + specifier: 58.0.11
722 + version: 58.0.11(patch_hash=e80ec3ef8c4af50a607beea1c0917e71ba679844efdb702b45d17a5f03cf466c)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
723 expo-web-browser:
724 specifier: ~58.0.6
725 version: 58.0.6(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))
@@ -18404,7 +18405,7 @@ snapshots:
18405 - supports-color
18406 - typescript
18407
18407 - expo-audio@58.0.9(patch_hash=2c2f8c73a23d48804c8b537b8cd73c25eb331aa47d82eaa481c6766cb81e5add)(expo-asset@58.0.16(@tsc-rs/typescript@0.8.0)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1))(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0):
18408 + expo-audio@58.0.9(patch_hash=530af071088a809fe1a97ce2b2269c78335fbb5dcd3893d6937ff5c304c85a0a)(expo-asset@58.0.16(@tsc-rs/typescript@0.8.0)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1))(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0):
18409 dependencies:
18410 expo: 58.0.14(277a83826bb26ba15256633fefeb0bc2)
18411 expo-asset: 58.0.16(@tsc-rs/typescript@0.8.0)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1)
@@ -18723,7 +18724,7 @@ snapshots:
18724 transitivePeerDependencies:
18725 - supports-color
18726
18726 - expo-video@58.0.11(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0):
18727 + expo-video@58.0.11(patch_hash=e80ec3ef8c4af50a607beea1c0917e71ba679844efdb702b45d17a5f03cf466c)(expo@58.0.14)(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0):
18728 dependencies:
18729 expo: 58.0.14(277a83826bb26ba15256633fefeb0bc2)
18730 react: 19.3.0
pnpm-workspace.yaml
+1
@@ -359,6 +359,7 @@ patchedDependencies:
359 micromark-extension-gfm-table@2.1.1: patches/micromark-extension-gfm-table@2.1.1.patch
360 alchemy@2.0.0-beta.80: patches/alchemy@2.0.0-beta.80.patch
361 expo-audio@58.0.9: patches/expo-audio@58.0.9.patch
362 + expo-video@58.0.11: patches/expo-video@58.0.11.patch
363 expo-network@58.0.3: patches/expo-network@58.0.3.patch
364 "@clerk/expo-native-components@0.4.0": patches/@clerk__expo-native-components@0.4.0.patch
365 "@effect/vitest@4.0.5": patches/@effect__vitest@4.0.5.patch