修复重构后新会话未显示底部token用量

This commit is contained in:
xintaofei
2026-03-12 21:23:58 +08:00
parent 8989f0fffb
commit 6c26d067fd
2 changed files with 13 additions and 3 deletions

View File

@@ -141,6 +141,7 @@ const ConversationTabView = memo(function ConversationTabView({
const { const {
appendOptimisticTurn, appendOptimisticTurn,
completeTurn, completeTurn,
getSession,
refetchDetail, refetchDetail,
syncTurnMetadata, syncTurnMetadata,
removeConversation, removeConversation,
@@ -208,10 +209,13 @@ const ConversationTabView = memo(function ConversationTabView({
error: detailError, error: detailError,
} = useConversationDetail(effectiveConversationId) } = useConversationDetail(effectiveConversationId)
const runtimeSession = getSession(effectiveConversationId)
const effectiveSessionStats = runtimeSession?.sessionStats ?? null
useEffect(() => { useEffect(() => {
if (!isActive) return if (!isActive) return
setSessionStats(detail?.session_stats ?? null) setSessionStats(effectiveSessionStats)
}, [detail?.session_stats, isActive, setSessionStats]) }, [effectiveSessionStats, isActive, setSessionStats])
const externalId = detail?.summary.external_id ?? undefined const externalId = detail?.summary.external_id ?? undefined
const draftStorageKey = useMemo(() => { const draftStorageKey = useMemo(() => {
@@ -621,7 +625,7 @@ const ConversationTabView = memo(function ConversationTabView({
connStatus={connStatus} connStatus={connStatus}
isActive={isActive} isActive={isActive}
sendSignal={sendSignal} sendSignal={sendSignal}
sessionStats={detail?.session_stats ?? null} sessionStats={effectiveSessionStats}
detailLoading={detailLoading} detailLoading={detailLoading}
detailError={detailError} detailError={detailError}
hideEmptyState={!hasPersistedConversation || hasSentMessage} hideEmptyState={!hasPersistedConversation || hasSentMessage}

View File

@@ -49,6 +49,9 @@ export interface ConversationRuntimeSession {
syncState: ConversationSyncState syncState: ConversationSyncState
activeTurnToken: string | null activeTurnToken: string | null
// Session-level stats (token usage, context window, etc.)
sessionStats: SessionStats | null
// Cleanup // Cleanup
pendingCleanup: boolean pendingCleanup: boolean
} }
@@ -141,6 +144,7 @@ function createEmptySession(
liveMessage: null, liveMessage: null,
syncState: "idle", syncState: "idle",
activeTurnToken: null, activeTurnToken: null,
sessionStats: null,
pendingCleanup: false, pendingCleanup: false,
} }
} }
@@ -279,6 +283,7 @@ function reducer(
detailError: null, detailError: null,
externalId: nextExternalId ?? current.externalId, externalId: nextExternalId ?? current.externalId,
localTurns: [], localTurns: [],
sessionStats: action.detail.session_stats ?? current.sessionStats,
...(isActivelyInteracting ...(isActivelyInteracting
? {} ? {}
: { optimisticTurns: [], liveMessage: null }), : { optimisticTurns: [], liveMessage: null }),
@@ -483,6 +488,7 @@ function reducer(
...current, ...current,
localTurns: changed ? patchedTurns : current.localTurns, localTurns: changed ? patchedTurns : current.localTurns,
detail: patchedDetail, detail: patchedDetail,
sessionStats: action.sessionStats ?? current.sessionStats,
})) }))
} }