File tree Expand file tree Collapse file tree
app/workspace/[workspaceId]/home/hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import type {
1111 PersistedFileAttachment ,
1212 PersistedMessage ,
1313} from '@/lib/copilot/chat/persisted-message'
14- import { normalizeMessage } from '@/lib/copilot/chat/persisted-message'
14+ import { normalizeMessage , withBlockTiming } from '@/lib/copilot/chat/persisted-message'
1515import { resolveStreamToolOutcome } from '@/lib/copilot/chat/stream-tool-outcome'
1616import { MOTHERSHIP_CHAT_API_PATH , STREAM_STORAGE_KEY } from '@/lib/copilot/constants'
1717import type {
@@ -699,15 +699,6 @@ function parseStreamBatchResponse(value: unknown): StreamBatchResponse {
699699 }
700700}
701701
702- function withBlockTiming (
703- persisted : Record < string , unknown > ,
704- src : ContentBlock
705- ) : Record < string , unknown > {
706- if ( typeof src . timestamp === 'number' ) persisted . timestamp = src . timestamp
707- if ( typeof src . endedAt === 'number' ) persisted . endedAt = src . endedAt
708- return persisted
709- }
710-
711702function toRawPersistedContentBlock ( block : ContentBlock ) : Record < string , unknown > | null {
712703 const persisted = toRawPersistedContentBlockBody ( block )
713704 return persisted ? withBlockTiming ( persisted , block ) : null
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616 ToolCallStatus ,
1717} from '@/app/workspace/[workspaceId]/home/types'
1818import type { PersistedContentBlock , PersistedMessage } from './persisted-message'
19+ import { withBlockTiming } from './persisted-message'
1920
2021const STATE_TO_STATUS : Record < string , ToolCallStatus > = {
2122 [ MothershipStreamV1ToolOutcome . success ] : ToolCallStatus . success ,
@@ -43,12 +44,6 @@ function toToolCallInfo(block: PersistedContentBlock): ToolCallInfo | undefined
4344 }
4445}
4546
46- function withBlockTiming ( block : ContentBlock , src : PersistedContentBlock ) : ContentBlock {
47- if ( typeof src . timestamp === 'number' ) block . timestamp = src . timestamp
48- if ( typeof src . endedAt === 'number' ) block . endedAt = src . endedAt
49- return block
50- }
51-
5247function toDisplayBlock ( block : PersistedContentBlock ) : ContentBlock | undefined {
5348 const displayed = toDisplayBlockBody ( block )
5449 return displayed ? withBlockTiming ( displayed , block ) : undefined
Original file line number Diff line number Diff line change @@ -87,13 +87,20 @@ function resolveToolState(block: ContentBlock): PersistedToolState {
8787 return tc . status as PersistedToolState
8888}
8989
90- function withBlockTiming < T extends PersistedContentBlock > (
91- persisted : T ,
90+ /**
91+ * Copy `timestamp` / `endedAt` from a source object onto a target object.
92+ * Shared by every block mapper (persist, display, snapshot) so the timing
93+ * metadata that drives the `Thought for Ns` chip survives the full
94+ * persist → normalize → display round-trip — and one rule lives in one place.
95+ */
96+ export function withBlockTiming < T > (
97+ target : T ,
9298 src : { timestamp ?: number ; endedAt ?: number }
9399) : T {
94- if ( typeof src . timestamp === 'number' ) persisted . timestamp = src . timestamp
95- if ( typeof src . endedAt === 'number' ) persisted . endedAt = src . endedAt
96- return persisted
100+ const writable = target as { timestamp ?: number ; endedAt ?: number }
101+ if ( typeof src . timestamp === 'number' ) writable . timestamp = src . timestamp
102+ if ( typeof src . endedAt === 'number' ) writable . endedAt = src . endedAt
103+ return target
97104}
98105
99106function mapContentBlock ( block : ContentBlock ) : PersistedContentBlock {
You can’t perform that action at this time.
0 commit comments