Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
create get/set for private funcs
perf3ct229a29d1cba2
diff --git a/src/public/app/widgets/llm_chat_panel.ts b/src/public/app/widgets/llm_chat_panel.tsindex cffb0bedcf..b88abe1ab5 100644--- a/src/public/app/widgets/llm_chat_panel.ts+++ b/src/public/app/widgets/llm_chat_panel.ts@@ -99,6 +99,39 @@ export default class LlmChatPanel extends BasicWidget {private onGetData: (() => Promise<any>) | null = null;private messages: Array<{role: string; content: string; timestamp?: Date}> = [];+ // Public getters and setters for private properties+ public getCurrentNoteId(): string | null {+ return this.currentNoteId;+ }++ public setCurrentNoteId(noteId: string | null): void {+ this.currentNoteId = noteId;+ }++ public getMessages(): Array<{role: string; content: string; timestamp?: Date}> {+ return this.messages;+ }++ public setMessages(messages: Array<{role: string; content: string; timestamp?: Date}>): void {+ this.messages = messages;+ }++ public getSessionId(): string | null {+ return this.sessionId;+ }++ public setSessionId(sessionId: string | null): void {+ this.sessionId = sessionId;+ }++ public getNoteContextChatMessages(): HTMLElement {+ return this.noteContextChatMessages;+ }++ public clearNoteContextChatMessages(): void {+ this.noteContextChatMessages.innerHTML = '';+ }+doRender() {this.$widget = $(TPL);diff --git a/src/public/app/widgets/type_widgets/ai_chat.ts b/src/public/app/widgets/type_widgets/ai_chat.tsindex 113ab4377b..96927f13b6 100644--- a/src/public/app/widgets/type_widgets/ai_chat.ts+++ b/src/public/app/widgets/type_widgets/ai_chat.ts@@ -13,7 +13,7 @@ export default class AiChatTypeWidget extends TypeWidget {constructor() {super();this.llmChatPanel = new LlmChatPanel();-+// Connect the data callbacksthis.llmChatPanel.setDataCallbacks((data) => this.saveData(data),@@ -35,19 +35,19 @@ export default class AiChatTypeWidget extends TypeWidget {// Override the refreshWithNote method to ensure we get note changesasync refreshWithNote(note: FNote | null | undefined) {console.log("refreshWithNote called for note:", note?.noteId);-+// Always force a refresh when the note changesif (this.note?.noteId !== note?.noteId) {console.log(`Note ID changed from ${this.note?.noteId} to ${note?.noteId}, forcing reset`);this.isInitialized = false;this.initPromise = null;-+// Force refresh the chat panel with the new noteif (note) {- this.llmChatPanel.currentNoteId = note.noteId;+ this.llmChatPanel.setCurrentNoteId(note.noteId);}}-+// Continue with regular doRefreshawait this.doRefresh(note);}@@ -55,7 +55,7 @@ export default class AiChatTypeWidget extends TypeWidget {async doRefresh(note: FNote | null | undefined) {try {console.log("doRefresh called for note:", note?.noteId);-+// If we're already initializing, wait for that to completeif (this.initPromise) {await this.initPromise;@@ -91,9 +91,9 @@ export default class AiChatTypeWidget extends TypeWidget {this.initPromise = (async () => {try {// Reset the UI before refreshing- this.llmChatPanel.noteContextChatMessages.innerHTML = '';- this.llmChatPanel.messages = [];-+ this.llmChatPanel.clearNoteContextChatMessages();+ this.llmChatPanel.setMessages([]);+// This will load saved data via the getData callbackawait this.llmChatPanel.refresh();this.isInitialized = true;@@ -118,21 +118,21 @@ export default class AiChatTypeWidget extends TypeWidget {async noteSwitched() {console.log("Note switched to:", this.noteId);-+// Force a full reset when switching notesthis.isInitialized = false;this.initPromise = null;-+if (this.note) {// Update the chat panel with the new note ID before refreshing- this.llmChatPanel.currentNoteId = this.note.noteId;-+ this.llmChatPanel.setCurrentNoteId(this.note.noteId);+// Reset the chat panel UI- this.llmChatPanel.noteContextChatMessages.innerHTML = '';- this.llmChatPanel.messages = [];- this.llmChatPanel.sessionId = null;+ this.llmChatPanel.clearNoteContextChatMessages();+ this.llmChatPanel.setMessages([]);+ this.llmChatPanel.setSessionId(null);}-+// Call the parent method to refreshawait super.noteSwitched();}@@ -141,25 +141,25 @@ export default class AiChatTypeWidget extends TypeWidget {if (!this.isActive()) {return;}-+console.log("Active context changed, refreshing AI Chat Panel");-+// Always refresh when we become active - this ensures we load the correct note datatry {// Reset initialization flag to force a refreshthis.isInitialized = false;-+// Make sure the chat panel has the current note IDif (this.note) {- this.llmChatPanel.currentNoteId = this.note.noteId;+ this.llmChatPanel.setCurrentNoteId(this.note.noteId);}-+this.initPromise = (async () => {try {// Reset the UI before refreshing- this.llmChatPanel.noteContextChatMessages.innerHTML = '';- this.llmChatPanel.messages = [];-+ this.llmChatPanel.clearNoteContextChatMessages();+ this.llmChatPanel.setMessages([]);+await this.llmChatPanel.refresh();this.isInitialized = true;} catch (e) {