@@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from "react"
22import { useNavigate , useLocation } from "react-router-dom"
33import { useQuery , useQueryClient } from "@tanstack/react-query"
44import { getRepo } from "@/api/repos"
5+ import { OpenCodeClient } from "@/api/opencode"
56import { setCachedAssistantSessionId , useAssistantSessionLauncher } from "@/hooks/useAssistantSessionLauncher"
67import { useCreateSession } from "@/hooks/useOpenCode"
78import { useDialogParam } from "@/hooks/useDialogParam"
@@ -16,7 +17,7 @@ import { RepoSkillsDialog } from "@/components/repo/RepoSkillsDialog"
1617import { SourceControlPanel } from "@/components/source-control"
1718import { ResetPermissionsDialog } from "@/components/repo/ResetPermissionsDialog"
1819import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup"
19- import { invalidateConfigCaches } from "@/lib/queryInvalidation"
20+ import { invalidateConfigCaches , messagesQueryKey } from "@/lib/queryInvalidation"
2021import { getSessionListPath , getAssistantPath , getAssistantSessionListPath } from "@/lib/navigation"
2122import { SwitchConfigDialog } from "@/components/repo/SwitchConfigDialog"
2223import { Loader2 , Plus } from "lucide-react"
@@ -45,13 +46,17 @@ export function AssistantRedirect() {
4546 const handleNavigate = useCallback ( ( sessionId : string ) => {
4647 if ( repo ?. fullPath ) {
4748 setCachedAssistantSessionId ( repoId , repo . fullPath , sessionId )
49+ void queryClient . prefetchQuery ( {
50+ queryKey : messagesQueryKey ( opcodeUrl , sessionId , repo . fullPath ) ,
51+ queryFn : ( ) => new OpenCodeClient ( opcodeUrl , repo . fullPath ) . listMessages ( sessionId ) ,
52+ } )
4853 }
4954 setStatus ( "opening" )
5055 if ( ! showSessionList ) {
5156 window . history . replaceState ( window . history . state , "" , getSessionListPath ( repoId , true ) )
5257 }
53- navigate ( `/repos/${ repoId } /sessions/${ sessionId } ?assistant=1` )
54- } , [ navigate , repo ?. fullPath , repoId , showSessionList ] )
58+ navigate ( `/repos/${ repoId } /sessions/${ sessionId } ?assistant=1` , { state : { directory : repo ?. fullPath } } )
59+ } , [ navigate , opcodeUrl , queryClient , repo ?. fullPath , repoId , showSessionList ] )
5560
5661 const handleMissingCachedSession = useCallback ( ( ) => {
5762 navigate ( getAssistantSessionListPath ( ) , { replace : true } )
@@ -74,14 +79,15 @@ export function AssistantRedirect() {
7479 if ( assistantDirectory ) {
7580 setCachedAssistantSessionId ( repoId , assistantDirectory , session . id )
7681 }
77- navigate ( `/repos/${ repoId } /sessions/${ session . id } ?assistant=1` )
82+ navigate ( `/repos/${ repoId } /sessions/${ session . id } ?assistant=1` , { state : { directory : assistantDirectory } } )
7883 } )
7984
80- const handleSelectSession = useCallback ( ( sessionId : string ) => {
81- if ( assistantDirectory ) {
82- setCachedAssistantSessionId ( repoId , assistantDirectory , sessionId )
85+ const handleSelectSession = useCallback ( ( sessionId : string , directory ?: string ) => {
86+ const selectedDirectory = directory ?? assistantDirectory
87+ if ( selectedDirectory ) {
88+ setCachedAssistantSessionId ( repoId , selectedDirectory , sessionId )
8389 }
84- navigate ( `/repos/${ repoId } /sessions/${ sessionId } ?assistant=1` )
90+ navigate ( `/repos/${ repoId } /sessions/${ sessionId } ?assistant=1` , { state : { directory : selectedDirectory } } )
8591 } , [ assistantDirectory , navigate , repoId ] )
8692
8793 const handleCreateSession = async ( ) => {
0 commit comments