@@ -498,7 +498,10 @@ import {
498498 hasDismissedResumeCompaction ,
499499 shouldOfferResumeCompaction ,
500500} from "./chat/ContextWindowMeter.logic" ;
501- import { deriveLatestContextWindowSnapshot } from "../lib/contextWindow" ;
501+ import {
502+ deriveLatestContextWindowSnapshot ,
503+ latestProviderTurnTokenUsage ,
504+ } from "../lib/contextWindow" ;
502505import {
503506 DRAFT_HERO_TRANSITION_ANIMATION_ID ,
504507 DRAFT_HERO_TRANSITION_EASING ,
@@ -1719,17 +1722,12 @@ export default function ChatView(props: ChatViewProps) {
17191722 status : threadStatus ,
17201723 } ) ;
17211724 const threadDetailLoading = threadSyncPhase === "loading" ;
1722- // Latest provider-reported context usage (#8144): the newest turn that has
1723- // a report wins; stale turns keep the meter alive between turns.
1724- const activeThreadLiveTokenUsage = useMemo ( ( ) => {
1725- const turns = serverProjection ?. providerTurns ;
1726- if ( ! turns || turns . length === 0 ) return null ;
1727- for ( let index = turns . length - 1 ; index >= 0 ; index -= 1 ) {
1728- const usage = turns [ index ] ?. tokenUsage ;
1729- if ( usage !== undefined ) return usage ;
1730- }
1731- return null ;
1732- } , [ serverProjection ?. providerTurns ] ) ;
1725+ // Latest provider-reported context usage (#8144): the newest report wins;
1726+ // stale turns keep the meter alive between turns.
1727+ const activeThreadLiveTokenUsage = useMemo (
1728+ ( ) => latestProviderTurnTokenUsage ( serverProjection ?. providerTurns ?? [ ] ) ,
1729+ [ serverProjection ?. providerTurns ] ,
1730+ ) ;
17331731 const serverVisibleTurnItems = useThreadVisibleTurnItems ( routeThreadDetailRef ) ;
17341732 const serverThreadHistory = useThreadHistory ( routeThreadDetailRef ) ;
17351733 const threadHistoryControls = useMemo < MessagesTimelineHistoryControls | undefined > ( ( ) => {
@@ -7753,6 +7751,8 @@ export default function ChatView(props: ChatViewProps) {
77537751 provider : selectedProvider ,
77547752 usedTokens : activeContextWindow . usedTokens ,
77557753 updatedAt : activeContextWindow . updatedAt ,
7754+ // Only the live report carries a TTL, and only when it is the window's source.
7755+ promptCacheTtlMs : activeThreadLiveTokenUsage ?. promptCacheTtlMs ,
77567756 now : `${ nowMinute } :00.000Z` ,
77577757 } )
77587758 ? activeContextWindow . usedTokens
0 commit comments