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
This commit is contained in:
Andrew Beal 2025-10-18 14:33:17 +01:00
parent fc892c43be
commit cce2cf9132
3 changed files with 8 additions and 4 deletions

View file

@ -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;

View file

@ -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() {

View file

@ -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 };