diff --git a/src/components/conversations/conversation-detail-panel.tsx b/src/components/conversations/conversation-detail-panel.tsx index cea7a4f..1d2286d 100644 --- a/src/components/conversations/conversation-detail-panel.tsx +++ b/src/components/conversations/conversation-detail-panel.tsx @@ -137,7 +137,7 @@ const ConversationTabView = memo(function ConversationTabView({ const tWelcome = useTranslations("Folder.chat.welcomeInputPanel") const sharedT = useTranslations("Folder.chat.shared") const { folder, folderId, refreshConversations } = useFolderContext() - const { bindConversationTab } = useTabContext() + const { bindConversationTab, setTabRuntimeConversationId } = useTabContext() const { setSessionStats } = useSessionStats() const { appendOptimisticTurn, @@ -177,6 +177,19 @@ const ConversationTabView = memo(function ConversationTabView({ const canAutoConnect = hasPersistedConversation || (agentsLoaded && usableAgentCount > 0) + // Expose the runtime session key to the tab so the aux panel (Diff sidebar) + // can look up live turns even before the DB conversation is created. + useEffect(() => { + if (effectiveConversationId !== conversationId) { + setTabRuntimeConversationId(tabId, effectiveConversationId) + } + }, [ + tabId, + effectiveConversationId, + conversationId, + setTabRuntimeConversationId, + ]) + // Clear pendingCleanup when tab is (re)opened useEffect(() => { setPendingCleanup(effectiveConversationId, false) @@ -544,7 +557,13 @@ const ConversationTabView = memo(function ConversationTabView({ } setCreatedConversationId(newConversationId) - bindConversationTab(tabId, newConversationId, selectedAgent, title) + bindConversationTab( + tabId, + newConversationId, + selectedAgent, + title, + effectiveConversationId + ) moveMessageInputDraft( buildNewConversationDraftStorageKey({ folderId }), buildConversationDraftStorageKey(selectedAgent, newConversationId) diff --git a/src/components/layout/aux-panel-session-files-tab.tsx b/src/components/layout/aux-panel-session-files-tab.tsx index 1515faf..938160b 100644 --- a/src/components/layout/aux-panel-session-files-tab.tsx +++ b/src/components/layout/aux-panel-session-files-tab.tsx @@ -265,7 +265,8 @@ export function SessionFilesTab() { const { tabs, activeTabId } = useTabContext() const activeTab = tabs.find((t) => t.id === activeTabId) - const conversationId = activeTab?.conversationId + const conversationId = + activeTab?.runtimeConversationId ?? activeTab?.conversationId if (!activeTab) { return ( diff --git a/src/contexts/tab-context.tsx b/src/contexts/tab-context.tsx index d9e2265..c68bef3 100644 --- a/src/contexts/tab-context.tsx +++ b/src/contexts/tab-context.tsx @@ -24,6 +24,10 @@ interface TabItemInternal { id: string kind: "conversation" conversationId: number | null + /** The runtime session key used by ConversationRuntimeContext. + * For new conversations this is a virtual (negative) ID that differs + * from the persisted `conversationId`. */ + runtimeConversationId?: number agentType: AgentType title: string isPinned: boolean @@ -55,7 +59,12 @@ interface TabContextValue { tabId: string, conversationId: number, agentType: AgentType, - title: string + title: string, + runtimeConversationId?: number + ) => void + setTabRuntimeConversationId: ( + tabId: string, + runtimeConversationId: number ) => void reorderTabs: (reorderedTabs: TabItem[]) => void } @@ -558,13 +567,20 @@ export function TabProvider({ children }: TabProviderProps) { tabId: string, conversationId: number, agentType: AgentType, - title: string + title: string, + runtimeConversationId?: number ) => { let nextActiveTabId: string | null = null setTabs((prev) => prev.flatMap((tab) => { if (tab.id === tabId) { - const nextTab = { ...tab, conversationId, agentType, title } + const nextTab = { + ...tab, + conversationId, + agentType, + title, + runtimeConversationId, + } return [nextTab] } @@ -594,6 +610,17 @@ export function TabProvider({ children }: TabProviderProps) { [syncFolderContext] ) + const setTabRuntimeConversationId = useCallback( + (tabId: string, runtimeConversationId: number) => { + setTabs((prev) => + prev.map((tab) => + tab.id === tabId ? { ...tab, runtimeConversationId } : tab + ) + ) + }, + [] + ) + const value = useMemo( () => ({ tabs, @@ -609,6 +636,7 @@ export function TabProvider({ children }: TabProviderProps) { toggleTileMode, openNewConversationTab, bindConversationTab, + setTabRuntimeConversationId, reorderTabs, }), [ @@ -625,6 +653,7 @@ export function TabProvider({ children }: TabProviderProps) { toggleTileMode, openNewConversationTab, bindConversationTab, + setTabRuntimeConversationId, reorderTabs, ] )