From c9ef192ef22b84126e5c76029d83a53927923d93 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Sat, 8 Nov 2025 23:11:45 +0000 Subject: [PATCH] improve message autoscroll and metadata --- src/components/message-stream.tsx | 10 ++++++++++ src/stores/sessions.ts | 17 +++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/components/message-stream.tsx b/src/components/message-stream.tsx index 536d5d6b..ba728e0b 100644 --- a/src/components/message-stream.tsx +++ b/src/components/message-stream.tsx @@ -270,6 +270,8 @@ export default function MessageStream(props: MessageStreamProps) { ) }) + const currentSession = createMemo(() => sessions().get(props.instanceId)?.get(props.sessionId)) + const formattedSessionInfo = createMemo(() => { const sessionInfo = getSessionInfo(props.instanceId, props.sessionId) || { tokens: 0, @@ -287,6 +289,7 @@ export default function MessageStream(props: MessageStreamProps) { ) }) + function isNearBottom(element: HTMLDivElement, offset = SCROLL_OFFSET) { const { scrollTop, scrollHeight, clientHeight } = element const distance = scrollHeight - (scrollTop + clientHeight) @@ -388,7 +391,14 @@ export default function MessageStream(props: MessageStreamProps) { tokenSegments.push(`${message.id}:${message.version ?? 0}:${message.status}:${message.parts.length}`) + for (const part of message.parts) { + const partId = typeof part.id === "string" ? part.id : part.type ?? "part" + const partVersion = typeof (part as any).version === "number" ? (part as any).version : 0 + tokenSegments.push(`${message.id}:${partId}:${partVersion}`) + } + const baseDisplayParts = message.displayParts + const displayParts: MessageDisplayParts = baseDisplayParts && baseDisplayParts.showThinking === showThinking ? baseDisplayParts diff --git a/src/stores/sessions.ts b/src/stores/sessions.ts index 03fc9963..3b733e36 100644 --- a/src/stores/sessions.ts +++ b/src/stores/sessions.ts @@ -1409,19 +1409,20 @@ function handleMessageUpdate(instanceId: string, event: any): void { message.status = "complete" as const message.version += 1 message.displayParts = computeDisplayParts(message, preferences().showThinkingBlocks) - - session.messagesInfo.set(info.id, info) - - withSession(instanceId, info.sessionID, (session) => { - // Session already mutated in place - }) - - updateSessionInfo(instanceId, info.sessionID) } + + session.messagesInfo.set(info.id, info) + + withSession(instanceId, info.sessionID, (session) => { + // Session already mutated in place + }) + + updateSessionInfo(instanceId, info.sessionID) } } function handleSessionUpdate(instanceId: string, event: any): void { + const info = event.properties?.info if (!info) return