Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions components/ai-chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,38 @@ export function AIChatPanel({ canvasDimensions }: AIChatPanelProps) {
}, [])

const getMessagesFingerprint = useCallback((msgs: UIMessage[]) => {
return JSON.stringify(
msgs.map((msg) => ({
id: msg.id,
...chatService.convertToDbMessage(msg),
})),
)
if (msgs.length === 0) return "empty"

const last = msgs[msgs.length - 1]
const lastWithMeta = last as UIMessage & { content?: string; createdAt?: Date | string }

let textPartLength = 0
let filePartCount = 0
let reasoningPartCount = 0
for (const part of last.parts || []) {
if (part.type === "text") {
textPartLength += part.text.length
} else if (part.type === "file") {
filePartCount += 1
} else if (part.type === "reasoning") {
Comment on lines +448 to +452
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include tool invocation state in message fingerprint

This fingerprint only tracks message count plus coarse metadata from the last message (text length and part counts), so updates to tool-invocation parts are not detected when their count stays the same. In this component, addToolResult(...) mutates existing tool-call parts in place; if the tool state/output changes but lengths/counts do not, usePersistMessagesOnChange treats the chat as unchanged and skips cloud/local persistence, which can leave restored sessions with stale or incomplete tool-call state.

Useful? React with 👍 / 👎.

reasoningPartCount += 1
}
}

const createdAt =
lastWithMeta.createdAt instanceof Date ? lastWithMeta.createdAt.toISOString() : (lastWithMeta.createdAt ?? "")

return [
msgs.length,
last.id,
last.role,
createdAt,
lastWithMeta.content?.length ?? 0,
last.parts?.length ?? 0,
textPartLength,
filePartCount,
reasoningPartCount,
].join("|")
}, [])

useLoadChatHistory({
Expand Down
Loading