@@ -235,6 +235,8 @@ interface ChatMarkdownProps {
235235 /** Directory that anchors relative links and images; defaults to `cwd`. Set
236236 to the file's own directory when rendering a markdown file. */
237237 imageBaseDir ?: string | undefined ;
238+ /** File previews refresh embedded host assets when opened or after workspace edits. */
239+ workspaceMutationId ?: string | null | undefined ;
238240 onImageExpand ?: ( ( preview : ExpandedImagePreview ) => void ) | undefined ;
239241 extraRemarkPlugins ?: NonNullable < ReactMarkdownOptions [ "remarkPlugins" ] > ;
240242 /** Renders a `t3-context://` link as a chip; without it the link shows its label as text. */
@@ -1598,11 +1600,29 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props
15981600 too old to know this resource. Only safe when the client can reach it directly. */
15991601 readonly fallbackSrc ?: string | undefined ;
16001602 readonly workspaceRoot ?: string | undefined ;
1603+ readonly workspaceMutationId ?: string | null | undefined ;
16011604 readonly onImageExpand ?: ( ( preview : ExpandedImagePreview ) => void ) | undefined ;
16021605} ) {
16031606 const assetUrl = useAssetUrlState ( props . environmentId , props . resource ) ;
16041607 const refreshAssetUrl = useAssetUrlRefresh ( props . environmentId , props . resource ) ;
16051608 const resource = props . resource ;
1609+ const refreshToken = JSON . stringify ( [ props . environmentId , resource , props . workspaceMutationId ] ) ;
1610+ const handledRefreshToken = useRef < string | null > ( null ) ;
1611+ useEffect ( ( ) => {
1612+ if (
1613+ props . workspaceMutationId === undefined ||
1614+ ( resource . _tag !== "media-file" && resource . _tag !== "workspace-file" ) ||
1615+ handledRefreshToken . current === refreshToken
1616+ ) {
1617+ return ;
1618+ }
1619+ handledRefreshToken . current = refreshToken ;
1620+ // A first request already reads the current file. Cached URLs and failures
1621+ // need a new signature after a file is created or atomically replaced.
1622+ if ( assetUrl . _tag !== "Loading" ) {
1623+ void refreshAssetUrl ( ) . catch ( ( ) => undefined ) ;
1624+ }
1625+ } , [ assetUrl . _tag , props . workspaceMutationId , refreshAssetUrl , refreshToken , resource . _tag ] ) ;
16061626 const path =
16071627 resource . _tag === "media-file"
16081628 ? resource . path
@@ -2316,6 +2336,7 @@ function useChatMarkdownState({
23162336 onUseArtifactTemplate,
23172337 onRunShellCommand,
23182338 imageBaseDir,
2339+ workspaceMutationId,
23192340 onImageExpand,
23202341 renderContextReference,
23212342 headingLevelOffset = 0 ,
@@ -2730,6 +2751,7 @@ function useChatMarkdownState({
27302751 renderContextReference,
27312752 headingLevelOffset,
27322753 imageBaseDir,
2754+ workspaceMutationId,
27332755 inlineCodeFileLinkMetaByText,
27342756 isStreaming,
27352757 linkTargetPreference,
@@ -2763,6 +2785,7 @@ function useChatMarkdownState({
27632785 renderContextReference ,
27642786 headingLevelOffset ,
27652787 imageBaseDir ,
2788+ workspaceMutationId ,
27662789 inlineCodeFileLinkMetaByText ,
27672790 isStreaming ,
27682791 linkTargetPreference ,
@@ -3219,6 +3242,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
32193242 githubMedia,
32203243 imageBaseDir,
32213244 threadRef,
3245+ workspaceMutationId,
32223246 renderContextReference,
32233247 } = use ( ChatMarkdownRendererContext ) ;
32243248 const imageExpand = use ( MarkdownLinkContext ) ? undefined : expandMedia ;
@@ -3334,6 +3358,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
33343358 standalone = { standalone }
33353359 style = { authoredSizeStyle }
33363360 workspaceRoot = { cwd }
3361+ workspaceMutationId = { workspaceMutationId }
33373362 onImageExpand = { imageExpand }
33383363 />
33393364 ) ;
0 commit comments