create get/set for private funcs

This commit is contained in:
perf3ct 2025-03-30 19:56:09 +00:00
parent 997edd8de8
commit 229a29d1cb
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
2 changed files with 58 additions and 25 deletions

View File

@ -99,6 +99,39 @@ export default class LlmChatPanel extends BasicWidget {
private onGetData: (() => Promise<any>) | null = null; private onGetData: (() => Promise<any>) | null = null;
private messages: Array<{role: string; content: string; timestamp?: Date}> = []; 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() { doRender() {
this.$widget = $(TPL); this.$widget = $(TPL);

View File

@ -13,7 +13,7 @@ export default class AiChatTypeWidget extends TypeWidget {
constructor() { constructor() {
super(); super();
this.llmChatPanel = new LlmChatPanel(); this.llmChatPanel = new LlmChatPanel();
// Connect the data callbacks // Connect the data callbacks
this.llmChatPanel.setDataCallbacks( this.llmChatPanel.setDataCallbacks(
(data) => this.saveData(data), (data) => this.saveData(data),
@ -35,19 +35,19 @@ export default class AiChatTypeWidget extends TypeWidget {
// Override the refreshWithNote method to ensure we get note changes // Override the refreshWithNote method to ensure we get note changes
async refreshWithNote(note: FNote | null | undefined) { async refreshWithNote(note: FNote | null | undefined) {
console.log("refreshWithNote called for note:", note?.noteId); console.log("refreshWithNote called for note:", note?.noteId);
// Always force a refresh when the note changes // Always force a refresh when the note changes
if (this.note?.noteId !== note?.noteId) { if (this.note?.noteId !== note?.noteId) {
console.log(`Note ID changed from ${this.note?.noteId} to ${note?.noteId}, forcing reset`); console.log(`Note ID changed from ${this.note?.noteId} to ${note?.noteId}, forcing reset`);
this.isInitialized = false; this.isInitialized = false;
this.initPromise = null; this.initPromise = null;
// Force refresh the chat panel with the new note // Force refresh the chat panel with the new note
if (note) { if (note) {
this.llmChatPanel.currentNoteId = note.noteId; this.llmChatPanel.setCurrentNoteId(note.noteId);
} }
} }
// Continue with regular doRefresh // Continue with regular doRefresh
await this.doRefresh(note); await this.doRefresh(note);
} }
@ -55,7 +55,7 @@ export default class AiChatTypeWidget extends TypeWidget {
async doRefresh(note: FNote | null | undefined) { async doRefresh(note: FNote | null | undefined) {
try { try {
console.log("doRefresh called for note:", note?.noteId); console.log("doRefresh called for note:", note?.noteId);
// If we're already initializing, wait for that to complete // If we're already initializing, wait for that to complete
if (this.initPromise) { if (this.initPromise) {
await this.initPromise; await this.initPromise;
@ -91,9 +91,9 @@ export default class AiChatTypeWidget extends TypeWidget {
this.initPromise = (async () => { this.initPromise = (async () => {
try { try {
// Reset the UI before refreshing // Reset the UI before refreshing
this.llmChatPanel.noteContextChatMessages.innerHTML = ''; this.llmChatPanel.clearNoteContextChatMessages();
this.llmChatPanel.messages = []; this.llmChatPanel.setMessages([]);
// This will load saved data via the getData callback // This will load saved data via the getData callback
await this.llmChatPanel.refresh(); await this.llmChatPanel.refresh();
this.isInitialized = true; this.isInitialized = true;
@ -118,21 +118,21 @@ export default class AiChatTypeWidget extends TypeWidget {
async noteSwitched() { async noteSwitched() {
console.log("Note switched to:", this.noteId); console.log("Note switched to:", this.noteId);
// Force a full reset when switching notes // Force a full reset when switching notes
this.isInitialized = false; this.isInitialized = false;
this.initPromise = null; this.initPromise = null;
if (this.note) { if (this.note) {
// Update the chat panel with the new note ID before refreshing // 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 // Reset the chat panel UI
this.llmChatPanel.noteContextChatMessages.innerHTML = ''; this.llmChatPanel.clearNoteContextChatMessages();
this.llmChatPanel.messages = []; this.llmChatPanel.setMessages([]);
this.llmChatPanel.sessionId = null; this.llmChatPanel.setSessionId(null);
} }
// Call the parent method to refresh // Call the parent method to refresh
await super.noteSwitched(); await super.noteSwitched();
} }
@ -141,25 +141,25 @@ export default class AiChatTypeWidget extends TypeWidget {
if (!this.isActive()) { if (!this.isActive()) {
return; return;
} }
console.log("Active context changed, refreshing AI Chat Panel"); console.log("Active context changed, refreshing AI Chat Panel");
// Always refresh when we become active - this ensures we load the correct note data // Always refresh when we become active - this ensures we load the correct note data
try { try {
// Reset initialization flag to force a refresh // Reset initialization flag to force a refresh
this.isInitialized = false; this.isInitialized = false;
// Make sure the chat panel has the current note ID // Make sure the chat panel has the current note ID
if (this.note) { if (this.note) {
this.llmChatPanel.currentNoteId = this.note.noteId; this.llmChatPanel.setCurrentNoteId(this.note.noteId);
} }
this.initPromise = (async () => { this.initPromise = (async () => {
try { try {
// Reset the UI before refreshing // Reset the UI before refreshing
this.llmChatPanel.noteContextChatMessages.innerHTML = ''; this.llmChatPanel.clearNoteContextChatMessages();
this.llmChatPanel.messages = []; this.llmChatPanel.setMessages([]);
await this.llmChatPanel.refresh(); await this.llmChatPanel.refresh();
this.isInitialized = true; this.isInitialized = true;
} catch (e) { } catch (e) {