refactor(media): unify file and media previews across clients #9253
Mergedjuliusmarmingemerged 8 commits into
main fromt3code/mobile-media-viewersmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change
- apps/web/src/components/media/MediaActions.tsx lines 116 to 116OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -96,15 +110,7 @@96110 try {97- const items: ContextMenuItem<MediaAction>[] = [];98- if (reference?.kind === "file") {99- items.push({ id: "copy-full", label: "Copy full path" });100- if (reference.relativePath)101- items.push({ id: "copy-relative", label: "Copy relative path" });102- } else if (reference?.kind === "url") {103- items.push({ id: "copy-url", label: "Copy URL" });104- }105- if (source.kind === "image") {106- const unavailable = source.src === null && source.asset === undefined;107- items.push({ id: "save", label: "Save image", disabled: unavailable });108- items.push({ id: "copy-image", label: "Copy image", disabled: unavailable });109- }110- if (source.onOpenFile) items.push({ id: "open-file", label: "Open in file viewer" });111+ const items: ContextMenuItem<MediaActionId>[] = availableMediaActions({112+ kind: source.kind,113+ reference,114+ canOpenFile: source.onOpenFile !== undefined,115+ canFetchBytes: source.src !== null || source.asset !== undefined,116+ canCopyImage: true,@@ -158,0 +372,21 @@372+ const trimmed = path.replace(/[/\\]+$/, "");373+ if (trimmed.length === 0) return path;374+ const separatorIndex = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));375+ return separatorIndex >= 0 ? trimmed.slice(separatorIndex + 1) : trimmed;376+}377+378+/**379+ * The path relative to a workspace root, or null when it lies outside. Drive380+ * letters and separators are normalized; the comparison ignores case because381+ * both Windows and macOS default to case-insensitive filesystems.382+ */383+export function workspaceRelativeFilePath(384+ path: string,385+ workspaceRoot: string | null | undefined,386+): string | null {387+ if (!workspaceRoot) return null;388+ const normalizedPath = stripSlashPrefixedWindowsDrive(path.replaceAll("\\", "/"));389+ const normalizedRoot = stripSlashPrefixedWindowsDrive(390+ workspaceRoot.replaceAll("\\", "/"),391+ ).replace(/\/+$/, "");392+ if (!normalizedPath.toLowerCase().startsWith(`${normalizedRoot.toLowerCase()}/`)) return null;apps/mobile/modules/t3-markdown-text/src/SelectableMarkdownText.ios.tsx lines 88 to 88OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -83,3 +85,4 @@8385 runs={chunk.runs}8486 textStyle={textStyle}8587 onLinkPress={onLinkPress}88+ fileContextMenu={fileContextMenu}apps/mobile/src/components/VideoPreviewModal.ios.tsx line 76Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -61,17 +64,17 @@6164 onRequestClose();6265 }, [loadError]);63666467 useEffect(() => {65- if (source.type === "remote" && playbackUrl === null) return;68+ if (localAttachment === null && playbackUrl === null) return;6669 const controller = new AbortController();6770 let ready = false;6871 void (async () => {6972 const file =70- source.type === "local"71- ? await loadLocalAttachmentPreview(source.attachment, controller.signal)73+ localAttachment !== null74+ ? await loadLocalAttachmentPreview(localAttachment, controller.signal)7275 : null;73- if (source.type === "local" && !file) return;76+ if (localAttachment !== null && !file) return;7477 try {7578 if (controller.signal.aborted) return;7679 ready = true;7780 await NativeControls.presentVideo(packages/client-runtime/src/markdownLinks.ts line 345Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -158,0 +372,21 @@372+ const trimmed = path.replace(/[/\\]+$/, "");373+ if (trimmed.length === 0) return path;374+ const separatorIndex = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));375+ return separatorIndex >= 0 ? trimmed.slice(separatorIndex + 1) : trimmed;376+}377+378+/**379+ * The path relative to a workspace root, or null when it lies outside. Drive380+ * letters and separators are normalized; the comparison ignores case because381+ * both Windows and macOS default to case-insensitive filesystems.382+ */383+export function workspaceRelativeFilePath(384+ path: string,385+ workspaceRoot: string | null | undefined,386+): string | null {387+ if (!workspaceRoot) return null;388+ const normalizedPath = stripSlashPrefixedWindowsDrive(path.replaceAll("\\", "/"));389+ const normalizedRoot = stripSlashPrefixedWindowsDrive(390+ workspaceRoot.replaceAll("\\", "/"),391+ ).replace(/\/+$/, "");392+ if (!normalizedPath.toLowerCase().startsWith(`${normalizedRoot.toLowerCase()}/`)) return null;packages/client-runtime/src/markdownLinks.ts line 366OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -158,0 +346,21 @@346+export function parseMarkdownFileLink(347+ href: string,348+ options?: MarkdownFileLinkOptions,349+): FilePathPosition | null {350+ const normalized = normalizeMarkdownLinkDestination(href);351+ if (normalized.length === 0 || normalized.startsWith("#") || normalized.startsWith("//")) {352+ return null;353+ }354+355+ const fileUrl = normalized.toLowerCase().startsWith("file:")356+ ? parseFileUrlHref(normalized, { decodePath: true })357+ : null;358+ const source = fileUrl ?? splitMarkdownLinkSearchAndHash(normalized);359+ const path = stripSlashPrefixedWindowsDrive(360+ fileUrl ? source.path.trim() : safeDecodeURIComponent(source.path.trim()),361+ );362+ const hash = safeDecodeURIComponent(source.hash.trim());363+ if (path.length === 0 || hasExternalScheme(path)) return null;364+365+ const position = splitFilePathPosition(path, hash);366+ return looksLikeFilePath(position.path, path, options) ? position : null;@@ -156,3 +189,7 @@156189 }157190 return candidate;158191 }192+193+export function safeDecodeURIComponent(value: string): string {194+ try {195+ return decodeURIComponent(value);
- apps/web/src/components/chat/ExpandedImageDialog.tsx lines 43 to 42OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -25,3 +26,17 @@2526 );2627 }272829+/** Asset-backed videos mint on open and re-mint on retry; URL-only items play what they were given. */30+function ExpandedVideo({ item }: { readonly item: ExpandedImageItem }) {31+ const asset = item.actionsSource?.asset;32+ const assetUrl = useAssetUrlState(asset?.environmentId ?? null, asset?.resource ?? null);33+ const refreshAssetUrl = useAssetUrlRefresh(asset?.environmentId ?? null, asset?.resource ?? null);34+ const src = asset35+ ? assetUrl._tag === "Success"36+ ? assetUrl.url + (item.srcFragment ?? "")37+ : null38+ : item.src;39+ return (40+ <MediaVideoPlayer41+ src={src}42+ label={item.name}apps/web/src/components/chat/ExpandedImageDialog.tsx lines 47 to 48OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -27 +28,21 @@272829+/** Asset-backed videos mint on open and re-mint on retry; URL-only items play what they were given. */30+function ExpandedVideo({ item }: { readonly item: ExpandedImageItem }) {31+ const asset = item.actionsSource?.asset;32+ const assetUrl = useAssetUrlState(asset?.environmentId ?? null, asset?.resource ?? null);33+ const refreshAssetUrl = useAssetUrlRefresh(asset?.environmentId ?? null, asset?.resource ?? null);34+ const src = asset35+ ? assetUrl._tag === "Success"36+ ? assetUrl.url + (item.srcFragment ?? "")37+ : null38+ : item.src;39+ return (40+ <MediaVideoPlayer41+ src={src}42+ label={item.name}43+ sourceFailed={assetUrl._tag === "Failure"}44+ originalUrl={item.originalUrl}45+ preload="metadata"46+ autoPlay={item.autoPlay ?? true}47+ className="block max-h-[86vh] max-w-[92vw]"48+ videoClassName="max-h-[86vh] max-w-[92vw] rounded-lg border border-border/70 shadow-2xl"
- apps/mobile/modules/t3-markdown-text/ios/T3MarkdownText.mm line 512OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -484,3 +509,4 @@484509 return YES;485510 }486511512+- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizerapps/mobile/src/components/VideoPreviewModal.ios.tsx line 56Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -53,5 +56,5 @@53565457 useEffect(() => Keyboard.dismiss(), []);5558 useEffect(() => {56- if (playbackUrl === null && assetUrl._tag === "Success") setPlaybackUrl(assetUrl.url);57- }, [playbackUrl, assetUrl]);59+ if (playbackUrl === null && resolvedUrl !== null) setPlaybackUrl(resolvedUrl);60+ }, [playbackUrl, resolvedUrl]);
- @@ -158,0 +277,21 @@277+ );278+}279+280+function looksLikePosixFilesystemPath(path: string): boolean {281+ if (!path.startsWith("/")) return false;282+ if (POSIX_FILE_ROOT_PREFIXES.some((prefix) => path.startsWith(prefix))) return true;283+ if (POSITION_SUFFIX_PATTERN.test(path)) return true;284+ const basename = path.slice(path.lastIndexOf("/") + 1);285+ return FILE_EXTENSION_PATTERN.test(basename);286+}287+288+/**289+ * Decides whether a decoded link destination is a file path rather than a route290+ * or prose. Only a `:line` suffix the author wrote counts as evidence; a `#L`291+ * anchor never turns `/chat/settings` into a file.292+ */293+function looksLikeFilePath(path: string, authoredPath: string): boolean {294+ if (isWindowsAbsolutePath(path) || RELATIVE_PATH_PREFIX_PATTERN.test(path)) return true;295+ if (path.startsWith("/")) return looksLikePosixFilesystemPath(authoredPath);296+ if (EXTENSIONLESS_FILE_NAMES.has(path)) return true;297+ return RELATIVE_FILE_PATH_PATTERN.test(authoredPath) || RELATIVE_FILE_NAME_PATTERN.test(path);packages/client-runtime/src/markdownLinks.ts lines 285 to 285OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -158,0 +265,21 @@265+ };266+}267+268+export function formatFilePathPosition(position: FilePathPosition): string {269+ if (!position.line) return position.path;270+ return `${position.path}:${position.line}${position.column ? `:${position.column}` : ""}`;271+}272+273+export function isRelativeFilePath(path: string): boolean {274+ return (275+ RELATIVE_PATH_PREFIX_PATTERN.test(path) ||276+ (!path.startsWith("/") && !isWindowsAbsolutePath(path))277+ );278+}279+280+function looksLikePosixFilesystemPath(path: string): boolean {281+ if (!path.startsWith("/")) return false;282+ if (POSIX_FILE_ROOT_PREFIXES.some((prefix) => path.startsWith(prefix))) return true;283+ if (POSITION_SUFFIX_PATTERN.test(path)) return true;284+ const basename = path.slice(path.lastIndexOf("/") + 1);285+ return FILE_EXTENSION_PATTERN.test(basename);docs/internals/mobile-navigation.md lines 104 to 105OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -91,11 +89,17 @@91-presentation. The URL is captured once per preview so credential refresh does not92-restart playback. Saving or sharing still downloads the original file.89+Every video on iOS opens in AVKit directly from its signed asset URL: sent attachments,90+markdown and workspace videos, and composer drafts. AVKit handles buffering; the client91+does not download the entire file or show a separate opening overlay before presentation.92+The URL is captured once per preview so credential refresh does not restart playback.93+Media actions (copy path, open in file viewer, save or share) belong to the surface that94+opened the video, a long-press on the thumbnail, so the player carries no95+menu. AVKit has no retry; a failed mint alerts and closes, and the next open mints again.93969497 The native presentation promise completes after dismissal. Local draft previews9598 hold their file lease until that promise settles. The iOS preview component requests9699 native dismissal when its source screen unmounts. Playback pauses in the background.97100 AVPlayer activates audio as playback starts. The presenter pauses and releases98101 its own player on close, then restores the previous audio-session configuration99102 if no other component changed it during playback. It does not deactivate the100-shared session, which may still serve another player or recorder. Android retains101-its React Native modal and Expo Video player.103+shared session, which may still serve another player or recorder. Android plays every104+video, attachments included, in its React Native modal with the Expo Video player,105+streaming from the signed URL and downloading only for save or share.apps/mobile/src/components/ComposerAttachmentStrip.tsx line 195Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -207,20 +187,8 @@207- );208- }209- })210- .finally(() => {211- if (shareRef.current === controller) {212- shareRef.current = null;213- setSharing(false);214- }215- });216- };217-218187 return (219188 <VideoAttachmentTile220189 name={attachment.name}221190 sourceIdentifier={sourceIdentifier}222191 thumbnailSource={attachment}223192 compact={props.compact}224193 onPress={() => props.onPressVideo(attachment, sourceIdentifier)}225- onShare={onShare}226- disabled={sharing}194+ actionsSource={actionsSource}apps/web/src/components/chat/ExpandedImageDialog.tsx lines 153 to 153OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -127,19 +151,3 @@127151 </Button>128- {item.type === "video" && failedVideoSrc === item.src ? (129- <ExpandedMediaFailure>130- <p>This video could not be loaded or played.</p>131- <OpenMediaLink originalUrl={item.originalUrl} src={item.src} fileName={item.name} />132- </ExpandedMediaFailure>133- ) : item.type === "video" ? (134- <video135- src={item.src}136- aria-label={item.name}137- autoPlay={item.autoPlay ?? true}138- preload="metadata"139- controls140- playsInline141- onLoadedMetadata={(event) => prepareVideoFirstFrame(event.currentTarget)}142- onError={() => setFailedVideoSrc(item.src)}143- className="max-h-[86vh] max-w-[92vw] rounded-lg border border-border/70 bg-black object-contain shadow-2xl"144- />145- ) : failedImageSrc === item.src ? (152+ {item.type === "video" ? (153+ <ExpandedVideo item={item} />
- apps/mobile/src/features/threads/ThreadFeed.tsx line 691Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -688,4 +702,3 @@688702 thumbnailVisible={visible}689703 unavailable={"resource" in source && asset._tag === "Failure"}690704 actionsSource={source.actionsSource}691- onExpand={() => props.onExpand(source)}apps/mobile/src/lib/mediaActions.ts line 57Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -39,3 +43,13 @@3943 controller.current = request;4044 setSharing(true);4145 void (async () => {46+ if ("attachment" in source) {47+ const preview = await loadLocalAttachmentPreview(source.attachment, request.signal);48+ if (!preview) return;49+ try {50+ await preview.share(request.signal);51+ } finally {52+ preview.dispose();53+ }54+ return;55+ }
- apps/web/src/components/chat/ExpandedImageDialog.tsx lines 45 to 46OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -25,3 +26,21 @@2526 );2627 }272829+function ExpandedVideo({ item }: { readonly item: ExpandedImageItem }) {30+ const asset = item.actionsSource?.asset;31+ const assetUrl = useAssetUrlState(asset?.environmentId ?? null, asset?.resource ?? null);32+ const refreshAssetUrl = useAssetUrlRefresh(asset?.environmentId ?? null, asset?.resource ?? null);33+ const src = asset34+ ? assetUrl._tag === "Success"35+ ? assetUrl.url + (item.srcFragment ?? "")36+ : null37+ : item.src;38+ if (assetUrl._tag === "Failure") {39+ return (40+ <ExpandedMediaFailure>41+ <p>This video could not be loaded or played.</p>42+ <OpenMediaLink originalUrl={item.originalUrl} src={src} fileName={item.name} />43+ </ExpandedMediaFailure>44+ );45+ }46+ return (
- apps/web/src/components/chat/ExpandedImageDialog.tsx line 45OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -25,3 +26,20 @@2526 );2627 }272829+function ExpandedVideo({ item }: { readonly item: ExpandedImageItem }) {30+ const asset = item.actionsSource?.asset;31+ const assetUrl = useAssetUrlState(asset?.environmentId ?? null, asset?.resource ?? null);32+ const refreshAssetUrl = useAssetUrlRefresh(asset?.environmentId ?? null, asset?.resource ?? null);33+ const src = asset34+ ? assetUrl._tag === "Success"35+ ? assetUrl.url + (item.srcFragment ?? "")36+ : null37+ : item.src;38+ if (assetUrl._tag === "Failure") {39+ return (40+ <ExpandedMediaFailure>41+ <p>This video could not be loaded or played.</p>42+ <OpenMediaLink originalUrl={item.originalUrl} src={src} fileName={item.name} />43+ </ExpandedMediaFailure>44+ );45+ }
- apps/web/src/components/chat/ExpandedImageDialog.tsx lines 53 to 53OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -27,0 +33,21 @@33+ const src = asset34+ ? assetUrl._tag === "Success"35+ ? assetUrl.url + (item.srcFragment ?? "")36+ : null37+ : item.src;38+ if (assetUrl._tag === "Failure") {39+ return (40+ <ExpandedMediaFailure>41+ <p>This video could not be loaded or played.</p>42+ <OpenMediaLink originalUrl={item.originalUrl} src={src} fileName={item.name} />43+ </ExpandedMediaFailure>44+ );45+ }46+ return (47+ <MediaVideoPlayer48+ src={src}49+ label={item.name}50+ originalUrl={item.originalUrl}51+ preload="metadata"52+ autoPlay={item.autoPlay ?? true}53+ className="block max-h-[86vh] max-w-[92vw]"
- apps/web/src/rightPanelStore.ts line 425OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -418,3 +431,12 @@418431 };419432 }),420433 })),434+ openAttachment: (ref, attachment) =>435+ set((state) => ({436+ byThreadKey: updateThread(state.byThreadKey, scopedThreadKey(ref), (current) => {437+ const withoutStandaloneExplorer = current.surfaces.filter(438+ (surface) => surface.kind !== "files",439+ );440+ return upsertSurface(441+ { ...current, surfaces: withoutStandaloneExplorer },442+ attachmentSurface(attachment),apps/web/src/rightPanelStore.ts line 166OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -157,3 +161,6 @@157161 revealRequestId,158162 });159163164+const attachmentSurface = (attachment: ChatFileAttachment): RightPanelSurface => ({165+ id: `file:attachment:${attachment.id}`,166+ kind: "file",
- apps/web/src/components/ChatView.tsx line 7149OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -7171,3 +7146,4 @@71717146 relativePath={71727147 activeRightPanelSurface.kind === "file" ? activeRightPanelSurface.relativePath : null71737148 }7149+ {...(activeFileSurface?.attachment ? { attachment: activeFileSurface.attachment } : {})}
- apps/web/src/components/chat/MessagesTimeline.tsx line 1170OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1125,0 +1150,21 @@1150+ file.previewUrl === undefined && resource !== null && assetUrl._tag === "Failure"1151+ }1152+ label={file.name}1153+ preload="visible"1154+ className="block w-full"1155+ videoClassName="border-border/80 max-h-[220px] rounded-lg border"1156+ stateClassName="border-border/80 min-h-[72px] rounded-lg border bg-black text-white"1157+ onRetry={asset ? refreshAssetUrl : undefined}1158+ onExpand={asset ? () => ctx.onFileOpen(file) : undefined}1159+ actionsSource={1160+ asset1161+ ? {1162+ kind: "video",1163+ name: file.name,1164+ src,1165+ asset,1166+ }1167+ : undefined1168+ }1169+ />1170+ );
- apps/web/src/components/chat/MessagesTimeline.tsx lines 1144 to 1146OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1123,3 +1129,18 @@11231129 );11241130 });112511311132+function UserVideoAttachment({ file }: { readonly file: ChatFileAttachment }) {1133+ const ctx = use(TimelineRowCtx);1134+ const asset = useMemo(1135+ () =>1136+ file.downloadable === false1137+ ? null1138+ : buildAttachmentVideoAsset(ctx.activeThreadEnvironmentId, file),1139+ [ctx.activeThreadEnvironmentId, file.downloadable, file.id, file.mimeType, file.name],1140+ );1141+ const resource = asset?.resource ?? null;1142+ const assetUrl = useAssetUrlState(ctx.activeThreadEnvironmentId, resource);1143+ const refreshAssetUrl = useAssetUrlRefresh(ctx.activeThreadEnvironmentId, resource);1144+ const src = file.previewUrl ?? (assetUrl._tag === "Success" ? assetUrl.url : null);1145+1146+ return (
- apps/web/src/components/chat/MessagesTimeline.tsx line 1227OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1177,4 +1224,4 @@11771224 <img11781225 src={image.previewUrl}11791226 alt={image.name}1180- className="block h-auto max-h-[220px] w-full object-cover"1227+ className="block size-full object-cover"
- apps/web/src/components/chat/MessagesTimeline.tsx line 1156OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1125,0 +1136,21 @@1136+ file.downloadable === false1137+ ? null1138+ : buildAttachmentVideoAsset(ctx.activeThreadEnvironmentId, file),1139+ [ctx.activeThreadEnvironmentId, file.downloadable, file.id, file.mimeType, file.name],1140+ );1141+ const resource = asset?.resource ?? null;1142+ const assetUrl = useAssetUrlState(ctx.activeThreadEnvironmentId, resource);1143+ const refreshAssetUrl = useAssetUrlRefresh(ctx.activeThreadEnvironmentId, resource);1144+ const src = file.previewUrl ?? (assetUrl._tag === "Success" ? assetUrl.url : null);1145+1146+ return (1147+ <MediaVideoPlayer1148+ src={src}1149+ sourceFailed={1150+ file.previewUrl === undefined && resource !== null && assetUrl._tag === "Failure"1151+ }1152+ label={file.name}1153+ preload="visible"1154+ className="block aspect-[4/3] w-full"1155+ videoClassName="border-border/80 aspect-auto size-full rounded-lg border"1156+ stateClassName="border-border/80 aspect-auto h-full min-h-[72px] rounded-lg border bg-black text-white"
- apps/web/src/components/chat/MessagesTimeline.tsx lines 1144 to 1144OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1123,3 +1129,16 @@11231129 );11241130 });112511311132+function UserVideoAttachment({ file }: { readonly file: ChatFileAttachment }) {1133+ const ctx = use(TimelineRowCtx);1134+ const asset = useMemo(1135+ () =>1136+ file.downloadable === false1137+ ? null1138+ : buildAttachmentVideoAsset(ctx.activeThreadEnvironmentId, file),1139+ [ctx.activeThreadEnvironmentId, file.downloadable, file.id, file.mimeType, file.name],1140+ );1141+ const resource = asset?.resource ?? null;1142+ const assetUrl = useAssetUrlState(ctx.activeThreadEnvironmentId, resource);1143+ const refreshAssetUrl = useAssetUrlRefresh(ctx.activeThreadEnvironmentId, resource);1144+ const src = file.previewUrl ?? (assetUrl._tag === "Success" ? assetUrl.url : null);
- @@ -47,4 +46,3 @@4746 readonly source: ResolvedFilePreviewSource;4847 readonly onRequestClose: () => void;4948 }) {50- return props.source.kind === "image" && props.source.actionsSource ? (
- apps/mobile/src/features/files/WorkspaceFileImagePreview.tsx line 64Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -58,7 +46,19 @@46+ <PresentationSource identifier={sourceIdentifier} style={{ flex: 1 }}>47+ <Image48+ accessible={false}49+ source={imageSource}50+ className="h-full w-full"51+ resizeMode="contain"52+ onLoadStart={() => setLoadError(null)}53+ onError={(event) => {54+ setLoadError(event.nativeEvent.error || "The image could not be rendered.");55+ }}56+ />57+ </PresentationSource>58+ </Pressable>59+ </MediaActionsMenu>5860 {loadError !== null ? (5961 <View className="absolute inset-0 items-center justify-center bg-card px-6">6062 <EmptyState title="Image unavailable" detail={loadError} />6163 </View>6264 ) : null}63-64- <View className="absolute right-2 top-2">apps/mobile/src/components/MediaVideoPlayer.tsx line 138OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -139,11 +129,10 @@139- cacheKey={props.thumbnailKey}140- source={props.thumbnailVisible === false ? null : props.uri}141- contentFit="contain"142- />143- ) : null}144- {props.unavailable ? (145- <AppText className="text-sm text-white/80">Video unavailable</AppText>146- ) : props.uri === null ? (147- <ActivityIndicator color="#ffffff" accessibilityLabel="Loading video" />148- ) : (149- <>129+ <MediaActionsMenu media={mediaActions} inModal={props.expanded} style={{ flex: 1 }}>130+ <Pressable131+ accessibilityRole="button"132+ accessibilityLabel={`Play ${props.name}`}133+ accessibilityHint={134+ mediaActions.actions.length > 0 ? "Touch and hold for media actions" : undefined135+ }136+ accessibilityState={{ disabled: props.uri === null || props.unavailable === true }}137+ disabled={props.uri === null || props.unavailable === true}138+ onPress={() => setPlaybackUri(props.uri)}
- apps/mobile/modules/t3-native-controls/ios/T3NativeFilePresentation.swift line 148Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -144,3 +144,5 @@144144 type = detectedType145145 } else if CGPDFDocument(download as CFURL) != nil {146146 type = .pdf147+ } else if URL(fileURLWithPath: title).pathExtension.lowercased() == "svg" {148+ type = .svgapps/mobile/src/components/VideoPreviewModal.tsx line 81OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -165,12 +65,17 @@65+ if (controller.signal.aborted) file.dispose();66+ else setUri(file.uri);16567 },166- (error: unknown) => {68+ (cause: unknown) => {16769 if (!controller.signal.aborted) {168- setFailure(error instanceof Error ? error.message : "Could not load this video.");70+ setError(cause instanceof Error ? cause.message : "Could not load this video.");16971 }17072 },17173 );17274 return () => {17375 controller.abort();174- preview?.dispose();76+ void loading.then(77+ (file) => file?.dispose(),78+ () => undefined,79+ );17580 };176- }, [source.type, environmentId, attachment.id, attachment.name, mimeType, fileUri, downloadUrl]);81+ }, [attachment]);
Sign in to join this conversation.




Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
7751299· PR result:452f18a· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.