Make message blocks reactive to session signals

This commit is contained in:
Shantur Rathore
2025-11-30 20:52:54 +00:00
parent 66c270151a
commit c5011e4ece

View File

@@ -645,11 +645,11 @@ export default function MessageStreamV2(props: MessageStreamV2Props) {
instanceId={props.instanceId} instanceId={props.instanceId}
sessionId={props.sessionId} sessionId={props.sessionId}
store={store} store={store}
messageIndexMap={messageIndexMap()} messageIndexMap={messageIndexMap}
lastAssistantIndex={lastAssistantIndex()} lastAssistantIndex={lastAssistantIndex}
showThinking={preferences().showThinkingBlocks} showThinking={() => preferences().showThinkingBlocks}
thinkingDefaultExpanded={(preferences().thinkingBlocksExpansion ?? "expanded") === "expanded"} thinkingDefaultExpanded={() => (preferences().thinkingBlocksExpansion ?? "expanded") === "expanded"}
showUsageMetrics={showUsagePreference()} showUsageMetrics={showUsagePreference}
onRevert={props.onRevert} onRevert={props.onRevert}
onFork={props.onFork} onFork={props.onFork}
/> />
@@ -694,11 +694,11 @@ interface MessageBlockProps {
instanceId: string instanceId: string
sessionId: string sessionId: string
store: () => InstanceMessageStore store: () => InstanceMessageStore
messageIndexMap: Map<string, number> messageIndexMap: () => Map<string, number>
lastAssistantIndex: number lastAssistantIndex: () => number
showThinking: boolean showThinking: () => boolean
thinkingDefaultExpanded: boolean thinkingDefaultExpanded: () => boolean
showUsageMetrics: boolean showUsageMetrics: () => boolean
onRevert?: (messageId: string) => void onRevert?: (messageId: string) => void
onFork?: (messageId?: string) => void onFork?: (messageId?: string) => void
} }
@@ -712,8 +712,9 @@ function MessageBlock(props: MessageBlockProps) {
const current = record() const current = record()
if (!current) return null if (!current) return null
const index = props.messageIndexMap.get(current.id) ?? 0 const index = props.messageIndexMap().get(current.id) ?? 0
const isQueued = current.role === "user" && (props.lastAssistantIndex === -1 || index > props.lastAssistantIndex) const lastAssistantIdx = props.lastAssistantIndex()
const isQueued = current.role === "user" && (lastAssistantIdx === -1 || index > lastAssistantIdx)
const info = messageInfo() const info = messageInfo()
const infoTime = (info?.time ?? {}) as { created?: number; updated?: number; completed?: number } const infoTime = (info?.time ?? {}) as { created?: number; updated?: number; completed?: number }
const infoTimestamp = typeof infoTime.completed === "number" const infoTimestamp = typeof infoTime.completed === "number"
@@ -727,9 +728,9 @@ function MessageBlock(props: MessageBlockProps) {
current.id, current.id,
current.revision, current.revision,
isQueued ? 1 : 0, isQueued ? 1 : 0,
props.showThinking ? 1 : 0, props.showThinking() ? 1 : 0,
props.thinkingDefaultExpanded ? 1 : 0, props.thinkingDefaultExpanded() ? 1 : 0,
props.showUsageMetrics ? 1 : 0, props.showUsageMetrics() ? 1 : 0,
infoTimestamp, infoTimestamp,
infoErrorName, infoErrorName,
].join("|") ].join("|")
@@ -824,7 +825,7 @@ function MessageBlock(props: MessageBlockProps) {
if (part.type === "step-finish") { if (part.type === "step-finish") {
flushContent() flushContent()
if (props.showUsageMetrics) { if (props.showUsageMetrics()) {
const key = `${current.id}:${part.id ?? partIndex}:${part.type}` const key = `${current.id}:${part.id ?? partIndex}:${part.type}`
const accentColor = lastAccentColor || defaultAccentColor const accentColor = lastAccentColor || defaultAccentColor
items.push({ type: part.type, key, part, messageInfo: info, accentColor }) items.push({ type: part.type, key, part, messageInfo: info, accentColor })
@@ -835,7 +836,7 @@ function MessageBlock(props: MessageBlockProps) {
if (part.type === "reasoning") { if (part.type === "reasoning") {
flushContent() flushContent()
if (props.showThinking && reasoningHasRenderableContent(part)) { if (props.showThinking() && reasoningHasRenderableContent(part)) {
const key = `${current.id}:${part.id ?? partIndex}:reasoning` const key = `${current.id}:${part.id ?? partIndex}:reasoning`
const showAgentMeta = current.role === "assistant" && !agentMetaAttached const showAgentMeta = current.role === "assistant" && !agentMetaAttached
if (showAgentMeta) { if (showAgentMeta) {
@@ -847,7 +848,7 @@ function MessageBlock(props: MessageBlockProps) {
part, part,
messageInfo: info, messageInfo: info,
showAgentMeta, showAgentMeta,
defaultExpanded: props.thinkingDefaultExpanded, defaultExpanded: props.thinkingDefaultExpanded(),
}) })
lastAccentColor = ASSISTANT_BORDER_COLOR lastAccentColor = ASSISTANT_BORDER_COLOR
} }
@@ -965,7 +966,7 @@ function MessageBlock(props: MessageBlockProps) {
kind="finish" kind="finish"
part={(item as StepDisplayItem).part} part={(item as StepDisplayItem).part}
messageInfo={(item as StepDisplayItem).messageInfo} messageInfo={(item as StepDisplayItem).messageInfo}
showUsage={props.showUsageMetrics} showUsage={props.showUsageMetrics()}
borderColor={(item as StepDisplayItem).accentColor} borderColor={(item as StepDisplayItem).accentColor}
/> />
</Match> </Match>