Optimize streaming updates and clear optimistic parts

This commit is contained in:
Shantur Rathore
2025-10-28 11:19:19 +00:00
parent 7a91f4fd26
commit 3a15ba7f76
4 changed files with 358 additions and 100 deletions

View File

@@ -180,15 +180,16 @@ export default function MessageStream(props: MessageStreamProps) {
const displayItems = createMemo(() => {
const items: DisplayItem[] = []
let lastAssistantMessageId = ""
let lastAssistantIndex = -1
for (let i = props.messages.length - 1; i >= 0; i--) {
if (props.messages[i].type === "assistant") {
lastAssistantMessageId = props.messages[i].id
lastAssistantIndex = i
break
}
}
for (const message of props.messages) {
for (let index = 0; index < props.messages.length; index++) {
const message = props.messages[index]
const messageInfo = props.messagesInfo?.get(message.id)
// If we hit the revert point, stop rendering messages
@@ -200,7 +201,7 @@ export default function MessageStream(props: MessageStreamProps) {
const toolParts = message.parts.filter((p) => p.type === "tool")
const reasoningParts = preferences().showThinkingBlocks ? message.parts.filter((p) => p.type === "reasoning") : []
const isQueued = message.type === "user" && message.id > lastAssistantMessageId
const isQueued = message.type === "user" && (lastAssistantIndex === -1 || index > lastAssistantIndex)
if (textParts.length > 0 || reasoningParts.length > 0 || messageInfo?.error) {
items.push({

View File

@@ -67,7 +67,7 @@ const OpenCodeBinarySelector: Component<OpenCodeBinarySelectorProps> = (props) =
onCleanup(() => {
document.removeEventListener("click", handleClickOutside)
// Clean up validating state on unmount
setValidatingPaths(new Set())
setValidatingPaths(new Set<string>())
setValidating(false)
})
})