11import { useCallback , useEffect , useRef , useState } from 'react' ;
22import { useLocation , useNavigate , useParams } from 'react-router-dom' ;
3- import { useRecoilState , useRecoilValue } from 'recoil' ;
3+ import { useRecoilState , useRecoilValue , useSetRecoilState } from 'recoil' ;
44import { NotificationSeverity } from '~/common' ;
5- import type { AppConversation , ConversationGroup } from '~/@types/app' ;
6- import { getAppConversationsApi } from '~/api/apps' ;
5+ import type { AppConversation , AppItem , ConversationGroup } from '~/@types/app' ;
6+ import { getAppConversationsApi , getAssistantDetailApi , getFlowApi } from '~/api/apps' ;
77import { groupConversationsByTime , getAppShareUrl } from '~/pages/apps/appUtils' ;
88import { copyText } from '~/utils' ;
99import { useToastContext } from '~/Providers' ;
@@ -15,6 +15,9 @@ import {
1515import { generateUUID } from '~/utils' ;
1616import { useLocalize } from '~/hooks' ;
1717
18+ // flow_type 5 === assistant; anything else (1 = skill, 10 = workflow) goes through getFlowApi.
19+ const FLOW_TYPE_ASSISTANT = 5 ;
20+
1821/**
1922 * Hook for the app chat sidebar.
2023 * Handles: loading conversations, time grouping, new/switch conversation, sidebar toggle.
@@ -29,6 +32,7 @@ export function useAppSidebar() {
2932 showToastRef . current = showToast ;
3033
3134 const currentApp = useRecoilValue ( currentAppInfoState ) ;
35+ const setCurrentApp = useSetRecoilState ( currentAppInfoState ) ;
3236 const [ conversations , setConversations ] = useRecoilState ( appConversationsState ) ;
3337 const [ sidebarVisible , setSidebarVisible ] = useRecoilState ( sidebarVisibleState ) ;
3438
@@ -128,6 +132,34 @@ export function useAppSidebar() {
128132 // This prevents re-triggering when the user creates a new chat or switches conversations.
129133 const hasAutoSelectedRef = useRef < string | null > ( null ) ;
130134
135+ // Fetch flow-level info (name / logo / description) into currentAppInfoState so
136+ // the sidebar card stays populated even when no chat is active — e.g. right after
137+ // deleting the active conversation, chatsState briefly loses the flow reference.
138+ useEffect ( ( ) => {
139+ if ( ! flowId || ! flowType ) return ;
140+ const numericType = Number ( flowType ) ;
141+ ( async ( ) => {
142+ try {
143+ const res = numericType === FLOW_TYPE_ASSISTANT
144+ ? await getAssistantDetailApi ( flowId , undefined , true )
145+ : await getFlowApi ( flowId , 'v1' , undefined , true ) ;
146+ if ( res ?. status_code !== 200 ) return ;
147+ const data = res . data ;
148+ if ( ! data ) return ;
149+ setCurrentApp ( {
150+ id : data . id ?? flowId ,
151+ name : data . name ?? '' ,
152+ description : data . description ?? '' ,
153+ logo : data . logo ?? '' ,
154+ flow_type : Number ( data . flow_type ?? numericType ) ,
155+ user_id : data . user_id ?? '' ,
156+ } as AppItem ) ;
157+ } catch {
158+ // silent — sidebar falls back to placeholder text
159+ }
160+ } ) ( ) ;
161+ } , [ flowId , flowType , setCurrentApp ] ) ;
162+
131163 // Auto-fetch on mount or flowId change, with one-time auto-select
132164 useEffect ( ( ) => {
133165 fetchConversations ( ) . then ( ( list ) => {
0 commit comments