@@ -3,7 +3,7 @@ import { useNavigate, useLocation } from "react-router-dom"
33import { useQuery , useQueryClient } from "@tanstack/react-query"
44import { getRepo } from "@/api/repos"
55import { OpenCodeClient } from "@/api/opencode"
6- import { setCachedAssistantSessionId , useAssistantSessionLauncher } from "@/hooks/useAssistantSessionLauncher"
6+ import { getCachedAssistantDirectory , setCachedAssistantSessionId , useAssistantSessionLauncher } from "@/hooks/useAssistantSessionLauncher"
77import { useCreateSession } from "@/hooks/useOpenCode"
88import { useDialogParam } from "@/hooks/useDialogParam"
99import { useSSE } from "@/hooks/useSSE"
@@ -36,6 +36,7 @@ export function AssistantRedirect() {
3636 const [ switchConfigOpen , setSwitchConfigOpen ] = useState ( false )
3737 const [ status , setStatus ] = useState < "preparing" | "opening" | "creating" | "error" > ( "preparing" )
3838 const [ errorMessage , setErrorMessage ] = useState < string | null > ( null )
39+ const cachedAssistantDirectory = getCachedAssistantDirectory ( repoId )
3940
4041 const opcodeUrl = OPENCODE_API_ENDPOINT
4142 const { data : repo , isLoading : repoLoading , error : repoError } = useQuery ( {
@@ -44,19 +45,20 @@ export function AssistantRedirect() {
4445 } )
4546
4647 const handleNavigate = useCallback ( ( sessionId : string ) => {
47- if ( repo ?. fullPath ) {
48- setCachedAssistantSessionId ( repoId , repo . fullPath , sessionId )
48+ const directory = repo ?. fullPath ?? cachedAssistantDirectory
49+ if ( directory ) {
50+ setCachedAssistantSessionId ( repoId , directory , sessionId )
4951 void queryClient . prefetchQuery ( {
50- queryKey : messagesQueryKey ( opcodeUrl , sessionId , repo . fullPath ) ,
51- queryFn : ( ) => new OpenCodeClient ( opcodeUrl , repo . fullPath ) . listMessages ( sessionId ) ,
52+ queryKey : messagesQueryKey ( opcodeUrl , sessionId , directory ) ,
53+ queryFn : ( ) => new OpenCodeClient ( opcodeUrl , directory ) . listMessages ( sessionId ) ,
5254 } )
5355 }
5456 setStatus ( "opening" )
5557 if ( ! showSessionList ) {
5658 window . history . replaceState ( window . history . state , "" , getSessionListPath ( repoId , true ) )
5759 }
58- navigate ( `/repos/${ repoId } /sessions/${ sessionId } ?assistant=1` , { state : { directory : repo ?. fullPath } } )
59- } , [ navigate , opcodeUrl , queryClient , repo ?. fullPath , repoId , showSessionList ] )
60+ navigate ( `/repos/${ repoId } /sessions/${ sessionId } ?assistant=1` , { state : { directory } } )
61+ } , [ cachedAssistantDirectory , navigate , opcodeUrl , queryClient , repo ?. fullPath , repoId , showSessionList ] )
6062
6163 const handleMissingCachedSession = useCallback ( ( ) => {
6264 navigate ( getAssistantSessionListPath ( ) , { replace : true } )
@@ -70,7 +72,7 @@ export function AssistantRedirect() {
7072 onMissingCachedSession : handleMissingCachedSession ,
7173 } )
7274
73- const assistantDirectory = repo ?. fullPath
75+ const assistantDirectory = repo ?. fullPath ?? cachedAssistantDirectory
7476 const assistantFileBasePath = assistantDirectory ?. split ( '/' ) . filter ( Boolean ) . at ( - 1 )
7577
7678 useSSE ( opcodeUrl , assistantDirectory )
@@ -101,8 +103,8 @@ export function AssistantRedirect() {
101103 try {
102104 if ( showSessionList ) return
103105 setStatus ( "preparing" )
104- if ( repoLoading ) return
105- if ( repoError || ! repo ?. fullPath ) throw new Error ( "Failed to load Assistant workspace" )
106+ if ( repoLoading && ! assistantDirectory ) return
107+ if ( ( repoError && ! assistantDirectory ) || ! assistantDirectory ) throw new Error ( "Failed to load Assistant workspace" )
106108 if ( cancelled ) return
107109 setStatus ( "creating" )
108110 await openAssistant ( )
@@ -118,7 +120,7 @@ export function AssistantRedirect() {
118120 return ( ) => {
119121 cancelled = true
120122 }
121- } , [ repo ?. fullPath , repoError , repoLoading , openAssistant , showSessionList ] )
123+ } , [ assistantDirectory , repoError , repoLoading , openAssistant , showSessionList ] )
122124
123125 if ( showSessionList ) {
124126 return (
@@ -140,9 +142,9 @@ export function AssistantRedirect() {
140142 </ Header . Actions >
141143 </ Header >
142144 < div className = "flex-1 flex flex-col min-h-0" >
143- { repoError ? (
145+ { repoError && ! assistantDirectory ? (
144146 < div className = "p-4 text-sm text-muted-foreground" > Failed to load Assistant sessions</ div >
145- ) : repoLoading || ! repo ?. fullPath ? (
147+ ) : repoLoading && ! assistantDirectory ? (
146148 < div className = "p-4 text-sm text-muted-foreground" > Loading Assistant sessions...</ div >
147149 ) : (
148150 < SessionList
0 commit comments