From cce2cf9132c93078f6ca0f5276c1947aa410570f Mon Sep 17 00:00:00 2001 From: Andrew Beal Date: Sat, 18 Oct 2025 14:33:17 +0100 Subject: [PATCH] fix: update token display timing and remove unused imports - Add 500ms timeout to chat padding recalculation to prevent race conditions - Replace svelte tick() with setTimeout for conversation title updates - Update token display after each conversation save and streaming response - Remove unused svelte/transition and tick imports --- Components/ChatArea.svelte | 5 +++-- Components/TopBar.svelte | 3 +-- Services/ChatService.ts | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Components/ChatArea.svelte b/Components/ChatArea.svelte index 67d1509..f33eac5 100644 --- a/Components/ChatArea.svelte +++ b/Components/ChatArea.svelte @@ -11,7 +11,6 @@ import type AIAgentPlugin from "main"; import { Copy } from "Enums/Copy"; import { Selector } from "Enums/Selector"; - import { fade } from "svelte/transition"; export let messages: ConversationContent[] = []; export let currentThought: string | null = null; @@ -21,7 +20,8 @@ export let editModeActive: boolean = false; export function onFinishedSubmitting() { - if (lastAssistantMessageElement && lastAssistantMessageElement.offsetHeight < + setTimeout(() => { + if (lastAssistantMessageElement && lastAssistantMessageElement.offsetHeight < chatContainer.offsetHeight - parseFloat(getComputedStyle(chatContainer).padding) * 2) { // Recalculate padding when streaming ends to fix race condition with streaming indicator removal tick().then(() => { @@ -43,6 +43,7 @@ } }, 1000); } + }, 500); } let thoughtElement: HTMLElement | undefined; diff --git a/Components/TopBar.svelte b/Components/TopBar.svelte index 4e103fd..3587ee3 100644 --- a/Components/TopBar.svelte +++ b/Components/TopBar.svelte @@ -8,7 +8,6 @@ import type { ConversationHistoryModal } from 'Modals/ConversationHistoryModal'; import { openPluginSettings } from 'Helpers/Helpers'; import type { ChatService } from 'Services/ChatService'; - import { tick } from 'svelte'; import { fade } from 'svelte/transition'; export let leaf: WorkspaceLeaf; @@ -22,7 +21,7 @@ chatService.onNameChanged = (name: string) => { conversationTitle = ""; - tick().then(() => conversationTitle = name); + setTimeout(() => conversationTitle = name, 500); }; function startNewConversation() { diff --git a/Services/ChatService.ts b/Services/ChatService.ts index b41ca73..a71ed60 100644 --- a/Services/ChatService.ts +++ b/Services/ChatService.ts @@ -70,6 +70,7 @@ export class ChatService { this.onNameChanged?.(conversation.title); // on change for initial conversation name this.namingService.requestName(conversation, userRequest, this.onNameChanged, this.abortController); } + this.updateTokenDisplay(conversation); // Process AI responses and function calls let response = await this.streamRequestResponse(conversation, allowDestructiveActions, callbacks); @@ -90,6 +91,8 @@ export class ChatService { await this.conversationService.saveConversation(conversation); } + this.updateTokenDisplay(conversation); + response = await this.streamRequestResponse(conversation, allowDestructiveActions, callbacks); } @@ -212,6 +215,7 @@ export class ChatService { } await this.conversationService.saveConversation(conversation); } + this.updateTokenDisplay(conversation); } return { functionCall: capturedFunctionCall, shouldContinue: capturedShouldContinue };