mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Implement conversation reset functionality and file deletion in ConversationFileSystemService
This commit is contained in:
parent
ea54a1e6e3
commit
adbe6045cf
6 changed files with 57 additions and 4 deletions
|
|
@ -6,7 +6,6 @@ import type { GeminiActionDefinitions } from "Actioner/Gemini/GeminiActionDefini
|
|||
import { create_file } from "Actioner/Actions";
|
||||
import type { IAIClass } from "AIClasses/IAIClass";
|
||||
import type { IPrompt } from "AIClasses/IPrompt";
|
||||
import type { Part } from "@google/genai";
|
||||
import { StreamingService, type StreamChunk } from "Services/StreamingService";
|
||||
|
||||
export class Gemini implements IAIClass {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
import { tick } from "svelte";
|
||||
import { ConversationFileSystemService } from "Services/ConversationFileSystemService";
|
||||
import { setIcon } from "obsidian";
|
||||
import { conversationStore } from "../Stores/conversationStore";
|
||||
|
||||
let ai: IAIClass = Resolve(Services.IAIClass);
|
||||
let actioner: IActioner = Resolve(Services.IActioner);
|
||||
|
|
@ -139,6 +140,11 @@
|
|||
$: if (submitButton) {
|
||||
setIcon(submitButton, 'send-horizontal');
|
||||
}
|
||||
|
||||
$: if ($conversationStore.shouldReset) {
|
||||
messages = [];
|
||||
conversationStore.clearResetFlag();
|
||||
}
|
||||
</script>
|
||||
|
||||
<main class="container">
|
||||
|
|
|
|||
|
|
@ -3,17 +3,22 @@
|
|||
import { Services } from '../Services/Services';
|
||||
import type AIAgentPlugin from '../main';
|
||||
import { setIcon, type WorkspaceLeaf } from 'obsidian';
|
||||
import { ConversationFileSystemService } from '../Services/ConversationFileSystemService';
|
||||
import { conversationStore } from '../Stores/conversationStore';
|
||||
|
||||
export let leaf: WorkspaceLeaf;
|
||||
|
||||
const plugin = Resolve<AIAgentPlugin>(Services.AIAgentPlugin);
|
||||
const conversationService = Resolve<ConversationFileSystemService>(Services.ConversationFileSystemService);
|
||||
|
||||
function startNewConversation() {
|
||||
|
||||
conversationService.resetCurrentConversation();
|
||||
conversationStore.reset();
|
||||
}
|
||||
|
||||
function deleteCurrentConversation() {
|
||||
|
||||
async function deleteCurrentConversation() {
|
||||
await conversationService.deleteCurrentConversation();
|
||||
conversationStore.reset();
|
||||
}
|
||||
|
||||
function openConversationHistory() {
|
||||
|
|
|
|||
|
|
@ -47,4 +47,18 @@ export class ConversationFileSystemService {
|
|||
this.currentConversationPath = null;
|
||||
}
|
||||
|
||||
public async deleteCurrentConversation(): Promise<boolean> {
|
||||
if (!this.currentConversationPath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const deleted = await this.fileSystemService.deleteFile(this.currentConversationPath);
|
||||
|
||||
if (deleted) {
|
||||
this.resetCurrentConversation();
|
||||
}
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,22 @@ export class FileSystemService {
|
|||
}
|
||||
}
|
||||
|
||||
public async deleteFile(filePath: string): Promise<boolean> {
|
||||
try {
|
||||
const file: TAbstractFile | null = this.vault.getAbstractFileByPath(filePath);
|
||||
|
||||
if (file && file instanceof TFile) {
|
||||
await this.vault.delete(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error("Error deleting file:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async createDirectories(vault: Vault, filePath: string) {
|
||||
const dirPath: string = filePath.substring(0, filePath.lastIndexOf('/'));
|
||||
|
||||
|
|
|
|||
13
Stores/conversationStore.ts
Normal file
13
Stores/conversationStore.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { writable } from 'svelte/store';
|
||||
|
||||
function createConversationStore() {
|
||||
const { subscribe, set, update } = writable({ shouldReset: false });
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
reset: () => set({ shouldReset: true }),
|
||||
clearResetFlag: () => set({ shouldReset: false })
|
||||
};
|
||||
}
|
||||
|
||||
export const conversationStore = createConversationStore();
|
||||
Loading…
Reference in a new issue