Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): usage not reset when opening an empty chat

Elian Doran1a02be7c9136
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
index a6931299e6..b3088db20b 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
@@ -170,9 +170,7 @@ export function useLlmChat(
}
// Restore last prompt tokens from the most recent message with usage
const lastUsage = [...(content.messages || [])].reverse().find(m => m.usage)?.usage;
- if (lastUsage) {
- setLastPromptTokens(lastUsage.promptTokens);
- }
+ setLastPromptTokens(lastUsage?.promptTokens ?? 0);
}, [supportsExtendedThinking]);
// Get current state as content object (uses refs to avoid stale closures)