修复右侧边栏diff区不实时显示修改文件

This commit is contained in:
xintaofei
2026-03-12 23:45:03 +08:00
parent a1d5a237e5
commit 0c54900396
3 changed files with 55 additions and 6 deletions

View File

@@ -137,7 +137,7 @@ const ConversationTabView = memo(function ConversationTabView({
const tWelcome = useTranslations("Folder.chat.welcomeInputPanel") const tWelcome = useTranslations("Folder.chat.welcomeInputPanel")
const sharedT = useTranslations("Folder.chat.shared") const sharedT = useTranslations("Folder.chat.shared")
const { folder, folderId, refreshConversations } = useFolderContext() const { folder, folderId, refreshConversations } = useFolderContext()
const { bindConversationTab } = useTabContext() const { bindConversationTab, setTabRuntimeConversationId } = useTabContext()
const { setSessionStats } = useSessionStats() const { setSessionStats } = useSessionStats()
const { const {
appendOptimisticTurn, appendOptimisticTurn,
@@ -177,6 +177,19 @@ const ConversationTabView = memo(function ConversationTabView({
const canAutoConnect = const canAutoConnect =
hasPersistedConversation || (agentsLoaded && usableAgentCount > 0) 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 // Clear pendingCleanup when tab is (re)opened
useEffect(() => { useEffect(() => {
setPendingCleanup(effectiveConversationId, false) setPendingCleanup(effectiveConversationId, false)
@@ -544,7 +557,13 @@ const ConversationTabView = memo(function ConversationTabView({
} }
setCreatedConversationId(newConversationId) setCreatedConversationId(newConversationId)
bindConversationTab(tabId, newConversationId, selectedAgent, title) bindConversationTab(
tabId,
newConversationId,
selectedAgent,
title,
effectiveConversationId
)
moveMessageInputDraft( moveMessageInputDraft(
buildNewConversationDraftStorageKey({ folderId }), buildNewConversationDraftStorageKey({ folderId }),
buildConversationDraftStorageKey(selectedAgent, newConversationId) buildConversationDraftStorageKey(selectedAgent, newConversationId)

View File

@@ -265,7 +265,8 @@ export function SessionFilesTab() {
const { tabs, activeTabId } = useTabContext() const { tabs, activeTabId } = useTabContext()
const activeTab = tabs.find((t) => t.id === activeTabId) const activeTab = tabs.find((t) => t.id === activeTabId)
const conversationId = activeTab?.conversationId const conversationId =
activeTab?.runtimeConversationId ?? activeTab?.conversationId
if (!activeTab) { if (!activeTab) {
return ( return (

View File

@@ -24,6 +24,10 @@ interface TabItemInternal {
id: string id: string
kind: "conversation" kind: "conversation"
conversationId: number | null 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 agentType: AgentType
title: string title: string
isPinned: boolean isPinned: boolean
@@ -55,7 +59,12 @@ interface TabContextValue {
tabId: string, tabId: string,
conversationId: number, conversationId: number,
agentType: AgentType, agentType: AgentType,
title: string title: string,
runtimeConversationId?: number
) => void
setTabRuntimeConversationId: (
tabId: string,
runtimeConversationId: number
) => void ) => void
reorderTabs: (reorderedTabs: TabItem[]) => void reorderTabs: (reorderedTabs: TabItem[]) => void
} }
@@ -558,13 +567,20 @@ export function TabProvider({ children }: TabProviderProps) {
tabId: string, tabId: string,
conversationId: number, conversationId: number,
agentType: AgentType, agentType: AgentType,
title: string title: string,
runtimeConversationId?: number
) => { ) => {
let nextActiveTabId: string | null = null let nextActiveTabId: string | null = null
setTabs((prev) => setTabs((prev) =>
prev.flatMap((tab) => { prev.flatMap((tab) => {
if (tab.id === tabId) { if (tab.id === tabId) {
const nextTab = { ...tab, conversationId, agentType, title } const nextTab = {
...tab,
conversationId,
agentType,
title,
runtimeConversationId,
}
return [nextTab] return [nextTab]
} }
@@ -594,6 +610,17 @@ export function TabProvider({ children }: TabProviderProps) {
[syncFolderContext] [syncFolderContext]
) )
const setTabRuntimeConversationId = useCallback(
(tabId: string, runtimeConversationId: number) => {
setTabs((prev) =>
prev.map((tab) =>
tab.id === tabId ? { ...tab, runtimeConversationId } : tab
)
)
},
[]
)
const value = useMemo( const value = useMemo(
() => ({ () => ({
tabs, tabs,
@@ -609,6 +636,7 @@ export function TabProvider({ children }: TabProviderProps) {
toggleTileMode, toggleTileMode,
openNewConversationTab, openNewConversationTab,
bindConversationTab, bindConversationTab,
setTabRuntimeConversationId,
reorderTabs, reorderTabs,
}), }),
[ [
@@ -625,6 +653,7 @@ export function TabProvider({ children }: TabProviderProps) {
toggleTileMode, toggleTileMode,
openNewConversationTab, openNewConversationTab,
bindConversationTab, bindConversationTab,
setTabRuntimeConversationId,
reorderTabs, reorderTabs,
] ]
) )