diff options
| author | Adam Malczewski <[email protected]> | 2026-03-29 13:44:05 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-03-29 13:44:05 +0900 |
| commit | e8d107e454b3804e089a33ce5fe7c931040d4647 (patch) | |
| tree | 4f8787fae670e86515baed54e00087ce3ef28da6 /src/chat-view.ts | |
| parent | 67d7d50ee2b05f66de3ab6aea38ff5d7d56ce839 (diff) | |
| download | ai-pulse-obsidian-plugin-e8d107e454b3804e089a33ce5fe7c931040d4647.tar.gz ai-pulse-obsidian-plugin-e8d107e454b3804e089a33ce5fe7c931040d4647.zip | |
remove calendar and chat history
Diffstat (limited to 'src/chat-view.ts')
| -rw-r--r-- | src/chat-view.ts | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/src/chat-view.ts b/src/chat-view.ts index dd27c63..55b730d 100644 --- a/src/chat-view.ts +++ b/src/chat-view.ts @@ -7,8 +7,6 @@ import { ToolModal } from "./tool-modal"; import { TOOL_REGISTRY } from "./tools"; import type { OllamaToolDefinition } from "./tools"; import { collectVaultContext, formatVaultContext } from "./vault-context"; -import { toRuntimeMessages, toPersistableMessages } from "./chat-history"; -import type { PersistedMessage } from "./chat-history"; export const VIEW_TYPE_CHAT = "ai-pulse-chat"; @@ -21,7 +19,6 @@ export class ChatView extends ItemView { private toolsButton: HTMLButtonElement | null = null; private abortController: AbortController | null = null; private scrollDebounceTimer: ReturnType<typeof setTimeout> | null = null; - private saveDebounceTimer: ReturnType<typeof setTimeout> | null = null; private bubbleContent: Map<HTMLDivElement, string> = new Map(); private modelBadge: HTMLDivElement | null = null; @@ -116,9 +113,6 @@ export class ChatView extends ItemView { if (this.messageContainer !== null) { this.messageContainer.empty(); } - this.plugin.settings.chatHistory = []; - this.plugin.updateChatSnapshot([]); - void this.plugin.saveSettings(); (document.activeElement as HTMLElement)?.blur(); }); @@ -148,22 +142,12 @@ export class ChatView extends ItemView { // Auto-connect on open void this.plugin.connect(); - - // Restore persisted chat history - void this.restoreChatHistory(); } async onClose(): Promise<void> { if (this.abortController !== null) { this.abortController.abort(); } - if (this.saveDebounceTimer !== null) { - clearTimeout(this.saveDebounceTimer); - this.saveDebounceTimer = null; - } - // Save any pending history before closing - this.plugin.settings.chatHistory = toPersistableMessages(this.messages); - void this.plugin.saveSettings(); this.contentEl.empty(); this.messages = []; this.bubbleContent.clear(); @@ -235,7 +219,6 @@ export class ChatView extends ItemView { // Track in message history this.messages.push({ role: "user", content: text }); - this.saveChatHistoryDebounced(); // Switch to streaming state this.abortController = new AbortController(); @@ -337,7 +320,6 @@ export class ChatView extends ItemView { await this.finalizeBubble(currentBubble); } this.messages.push({ role: "assistant", content: response }); - this.saveChatHistoryDebounced(); this.scrollToBottom(); } catch (err: unknown) { const isAbort = err instanceof DOMException && err.name === "AbortError"; @@ -755,98 +737,6 @@ export class ChatView extends ItemView { } } - /** - * Save chat history with debouncing to avoid excessive writes. - */ - private saveChatHistoryDebounced(): void { - if (this.saveDebounceTimer !== null) { - clearTimeout(this.saveDebounceTimer); - } - this.saveDebounceTimer = setTimeout(() => { - this.saveDebounceTimer = null; - const persistable = toPersistableMessages(this.messages); - this.plugin.settings.chatHistory = persistable; - // Update the plugin's snapshot so the sync checker doesn't treat - // our own save as an external change. - this.plugin.updateChatSnapshot(persistable); - void this.plugin.saveSettings(); - }, 500); - } - - /** - * Restore chat history from the persisted file and render messages. - */ - private async restoreChatHistory(): Promise<void> { - const persisted = this.plugin.settings.chatHistory; - if (persisted.length === 0) return; - - this.messages = toRuntimeMessages(persisted); - this.plugin.updateChatSnapshot(persisted); - await this.renderPersistedMessages(persisted); - this.scrollToBottom(); - } - - /** - * Render persisted messages into the chat container. - * User messages are shown as plain text; assistant messages are rendered as markdown. - */ - private async renderPersistedMessages(messages: PersistedMessage[]): Promise<void> { - if (this.messageContainer === null) return; - - for (const msg of messages) { - if (msg.role === "user") { - this.messageContainer.createDiv({ - cls: "ai-pulse-message user", - text: msg.content, - }); - } else if (msg.role === "assistant") { - const bubble = this.messageContainer.createDiv({ - cls: "ai-pulse-message assistant ai-pulse-markdown", - }); - await MarkdownRenderer.render( - this.plugin.app, - msg.content, - bubble, - "", - this, - ); - - // Wire up internal [[wiki-links]] so they navigate on click - bubble.querySelectorAll("a.internal-link").forEach((link) => { - link.addEventListener("click", (evt) => { - evt.preventDefault(); - const href = link.getAttribute("href"); - if (href !== null) { - void this.plugin.app.workspace.openLinkText(href, "", false); - } - }); - }); - } - } - } - - /** - * Reload chat history from disk (e.g., after an external sync). - * Replaces the current messages and re-renders the UI. - */ - async reloadChatHistory(): Promise<void> { - const persisted = this.plugin.settings.chatHistory; - - // Skip reload if we're currently streaming — avoid disrupting the UI - if (this.abortController !== null) return; - - this.messages = toRuntimeMessages(persisted); - this.bubbleContent.clear(); - if (this.messageContainer !== null) { - this.messageContainer.empty(); - } - - if (persisted.length > 0) { - await this.renderPersistedMessages(persisted); - this.scrollToBottom(); - } - } - private scrollToBottom(): void { if (this.messageContainer === null) return; const lastChild = this.messageContainer.lastElementChild; |
