@@ -2,6 +2,7 @@ import * as Haptics from "expo-haptics";
22import { KeyboardAwareLegendList } from "@legendapp/list/keyboard" ;
33import { type LegendListRef } from "@legendapp/list/react-native" ;
44import type {
5+ AssetResource ,
56 ChatAttachment ,
67 ChatFileAttachment ,
78 ChatImageAttachment ,
@@ -17,7 +18,11 @@ import {
1718import { resolveAssetUrl } from "@t3tools/client-runtime/state/assets" ;
1819import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments" ;
1920import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime" ;
20- import { classifyMarkdownImageSource } from "@t3tools/client-runtime/markdown-images" ;
21+ import {
22+ classifyMarkdownImageSource ,
23+ markdownImageSourceFragment ,
24+ } from "@t3tools/client-runtime/markdown-images" ;
25+ import { resolveViewedImageAsset } from "@t3tools/client-runtime/work-log/presentation" ;
2126import {
2227 renderCodexFileCitationsAsMarkdown ,
2328 splitCodexArtifactTemplateMarkdown ,
@@ -565,24 +570,24 @@ function ThreadMarkdownImageRequest(props: {
565570 ) ;
566571}
567572
568- /** Markdown image whose src is a workspace file — loads through a signed asset URL. */
573+ /** Environment-hosted image that loads through a signed asset URL. */
569574function ThreadMarkdownImage ( props : {
570575 readonly environmentId : EnvironmentId ;
571- readonly threadId : ThreadId ;
572- readonly path : string ;
576+ readonly resource : Extract < AssetResource , { readonly _tag : "attachment" | "workspace-file" } > ;
573577 readonly alt : string | null ;
578+ readonly srcFragment ?: string ;
574579 readonly onPressPreview : ( source : FilePreviewSource ) => void ;
575580} ) {
576- const assetUrl = useAssetUrlState ( props . environmentId , {
577- _tag : "workspace-file" ,
578- threadId : props . threadId ,
579- path : props . path ,
580- } ) ;
581+ const assetUrl = useAssetUrlState ( props . environmentId , props . resource ) ;
581582
582583 return (
583584 < ThreadMarkdownImageView
584- uri = { assetUrl . _tag === "Success" ? assetUrl . url : null }
585- sourceKey = { props . path }
585+ uri = { assetUrl . _tag === "Success" ? assetUrl . url + ( props . srcFragment ?? "" ) : null }
586+ sourceKey = {
587+ props . resource . _tag === "attachment"
588+ ? `attachment:${ props . resource . attachmentId } `
589+ : `workspace:${ props . resource . path } `
590+ }
586591 unavailable = { assetUrl . _tag === "Failure" }
587592 alt = { props . alt }
588593 onPressPreview = { props . onPressPreview }
@@ -1333,6 +1338,7 @@ function renderFeedEntry(
13331338 readonly onPressVideo : ( attachment : ChatFileAttachment , sourceIdentifier : string ) => void ;
13341339 readonly onMarkdownLinkPress : ( href : string ) => void ;
13351340 readonly renderMarkdownImage : MarkdownImageRenderer ;
1341+ readonly renderViewedImage : MarkdownImageRenderer ;
13361342 readonly iconSubtleColor : string | import ( "react-native" ) . ColorValue ;
13371343 readonly userBubbleColor : string | import ( "react-native" ) . ColorValue ;
13381344 readonly markdownStyles : MarkdownStyleSets ;
@@ -1545,7 +1551,7 @@ function renderFeedEntry(
15451551 iconSubtleColor = { iconSubtleColor }
15461552 onCopyRow = { props . onCopyWorkRow }
15471553 onToggleRow = { props . onToggleWorkRow }
1548- renderImage = { props . renderMarkdownImage }
1554+ renderImage = { props . renderViewedImage }
15491555 />
15501556 ) ;
15511557}
@@ -1984,15 +1990,37 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
19841990 return (
19851991 < ThreadMarkdownImage
19861992 environmentId = { props . environmentId }
1987- threadId = { props . threadId }
1988- path = { imageSource . path }
1993+ resource = { {
1994+ _tag : "workspace-file" ,
1995+ threadId : props . threadId ,
1996+ path : imageSource . path ,
1997+ } }
19891998 alt = { image . alt }
1999+ srcFragment = { markdownImageSourceFragment ( image . href ) }
19902000 onPressPreview = { ( source ) => setExpandedFile ( ( current ) => current ?? source ) }
19912001 />
19922002 ) ;
19932003 } ,
19942004 [ props . environmentId , props . threadId , props . workspaceRoot ] ,
19952005 ) ;
2006+ const renderViewedImage = useCallback < MarkdownImageRenderer > (
2007+ ( image ) => {
2008+ const viewedImage = resolveViewedImageAsset ( image . href , {
2009+ threadId : props . threadId ,
2010+ workspaceRoot : props . workspaceRoot ,
2011+ } ) ;
2012+ return viewedImage ? (
2013+ < ThreadMarkdownImage
2014+ environmentId = { props . environmentId }
2015+ resource = { viewedImage . resource }
2016+ alt = { viewedImage . alt }
2017+ srcFragment = { viewedImage . srcFragment }
2018+ onPressPreview = { ( source ) => setExpandedFile ( ( current ) => current ?? source ) }
2019+ />
2020+ ) : null ;
2021+ } ,
2022+ [ props . environmentId , props . threadId , props . workspaceRoot ] ,
2023+ ) ;
19962024 const markdownStyles = useMarkdownStyles ( onMarkdownLinkPress , renderMarkdownImage ) ;
19972025 const reviewCommentColors = useReviewCommentColors ( ) ;
19982026 // LegendList does not invalidate visible rows when only the renderItem closure changes.
@@ -2444,6 +2472,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
24442472 onPressVideo,
24452473 onMarkdownLinkPress,
24462474 renderMarkdownImage,
2475+ renderViewedImage,
24472476 iconSubtleColor,
24482477 userBubbleColor,
24492478 markdownStyles,
@@ -2478,6 +2507,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
24782507 props . onUseArtifactTemplate ,
24792508 props . skills ,
24802509 renderMarkdownImage ,
2510+ renderViewedImage ,
24812511 ] ,
24822512 ) ;
24832513
0 commit comments