@@ -198,6 +198,7 @@ import {
198198} from "../../state/assets" ;
199199import { useAtomQueryRunner } from "../../state/use-atom-query-runner" ;
200200import { usePreparedConnection } from "../../state/session" ;
201+ import { useLiveThreadLinkLabels } from "../../state/entities" ;
201202import { useThreadSelection } from "../../state/use-thread-selection" ;
202203import { composerDocumentAttachmentRecord } from "../../lib/composerContext" ;
203204import * as Option from "effect/Option" ;
@@ -906,16 +907,15 @@ interface MarkdownLinkHandlers {
906907
907908const AssistantMarkdownContent = memo ( function AssistantMarkdownContent ( props : {
908909 readonly markdown : string ;
910+ readonly environmentId : EnvironmentId ;
909911 readonly markdownStyles : MarkdownStyleSet ;
910912 readonly linkHandlers : MarkdownLinkHandlers ;
911913 readonly onUseArtifactTemplate ?: ( ( template : CodexArtifactTemplate ) => void ) | undefined ;
912914 readonly renderImage : MarkdownImageRenderer ;
913915 readonly skills ?: ReadonlyArray < SelectableMarkdownSkill > | undefined ;
914916} ) {
915- const segments = useMemo (
916- ( ) => splitCodexArtifactTemplateMarkdown ( props . markdown ) ,
917- [ props . markdown ] ,
918- ) ;
917+ const liveMarkdown = useLiveThreadLinkLabels ( props . markdown , props . environmentId ) ;
918+ const segments = useMemo ( ( ) => splitCodexArtifactTemplateMarkdown ( liveMarkdown ) , [ liveMarkdown ] ) ;
919919
920920 return segments . map ( ( segment ) => {
921921 if ( segment . kind === "artifact-template" ) {
@@ -1905,6 +1905,7 @@ function renderFeedEntry(
19051905 < MarkdownImageAvailableWidthContext value = { props . markdownContentWidth } >
19061906 < AssistantMarkdownContent
19071907 markdown = { renderedText }
1908+ environmentId = { props . environmentId }
19081909 markdownStyles = { styles }
19091910 linkHandlers = { props . markdownLinkHandlers }
19101911 onUseArtifactTemplate = { props . onUseArtifactTemplate }
@@ -2002,7 +2003,8 @@ function UserMessageContent(props: UserMessageContentProps) {
20022003 const [ selected , setSelected ] = useState < { contextId : string ; label : string } | null > ( null ) ;
20032004 const navigation = useNavigation ( ) ;
20042005 const { selectedThread } = useThreadSelection ( ) ;
2005- const text = replaceComposerContextReferences ( props . text , ( ref ) => {
2006+ const liveText = useLiveThreadLinkLabels ( props . text , props . environmentId ) ;
2007+ const text = replaceComposerContextReferences ( liveText , ( ref ) => {
20062008 const available = props . context ?. records . some ( ( record ) => record . contextId === ref . contextId ) ;
20072009 return `[${ ref . label } ${ available ? "" : " (unavailable)" } ](t3-context://v1/${ ref . kind } /${ ref . contextId } )` ;
20082010 } ) ;
@@ -2292,11 +2294,12 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
22922294 const userBubbleColor = theme [ "--color-user-bubble" ] ;
22932295 const onMarkdownLinkPress = useCallback (
22942296 ( href : string ) => {
2295- const threadLink = parseThreadLinkHref ( href ) ;
2296- if ( threadLink ) {
2297+ // A thread link names a thread in this feed's environment.
2298+ const linkedThreadId = parseThreadLinkHref ( href ) ;
2299+ if ( linkedThreadId ) {
22972300 navigation . navigate ( "Thread" , {
2298- environmentId : String ( threadLink . environmentId ) ,
2299- threadId : String ( threadLink . threadId ) ,
2301+ environmentId : String ( props . environmentId ) ,
2302+ threadId : String ( linkedThreadId ) ,
23002303 } ) ;
23012304 return ;
23022305 }
@@ -2504,13 +2507,20 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
25042507 ( text : string ) => (
25052508 < AssistantMarkdownContent
25062509 markdown = { text }
2510+ environmentId = { props . environmentId }
25072511 markdownStyles = { markdownStyles . assistant }
25082512 linkHandlers = { markdownLinkHandlers }
25092513 renderImage = { renderMarkdownImage }
25102514 skills = { props . skills }
25112515 />
25122516 ) ,
2513- [ markdownStyles . assistant , markdownLinkHandlers , renderMarkdownImage , props . skills ] ,
2517+ [
2518+ markdownStyles . assistant ,
2519+ markdownLinkHandlers ,
2520+ renderMarkdownImage ,
2521+ props . skills ,
2522+ props . environmentId ,
2523+ ] ,
25142524 ) ;
25152525 const reviewCommentColors = useReviewCommentColors ( ) ;
25162526 const unsettledTurnId = threadFeedRunIsUnsettled ( props . latestRun ) ? props . latestRun . runId : null ;
0 commit comments