mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Add memories feature allowing AI to retain vault conventions, user preferences, and established workflows across conversation sessions. Include read-only mode option, validation requiring read-before-write, and settings UI with toggle controls. Adjusted default search and snippet size values in plugin settings.
53 lines
No EOL
1.9 KiB
TypeScript
53 lines
No EOL
1.9 KiB
TypeScript
import { Copy } from "Enums/Copy";
|
|
import { Path } from "Enums/Path";
|
|
import { Resolve } from "./DependencyService";
|
|
import type { FileSystemService } from "./FileSystemService";
|
|
import { Services } from "./Services";
|
|
import type { WorkSpaceService } from "./WorkSpaceService";
|
|
|
|
export class MemoriesService {
|
|
|
|
private readonly maxMemoriesLength: number = 10;
|
|
private readonly maxMemoriesLineLength: number = 200;
|
|
|
|
private readonly fileSystemService: FileSystemService;
|
|
private readonly workSpaceService: WorkSpaceService;
|
|
|
|
constructor() {
|
|
this.fileSystemService = Resolve<FileSystemService>(Services.FileSystemService);
|
|
this.workSpaceService = Resolve<WorkSpaceService>(Services.WorkSpaceService);
|
|
}
|
|
|
|
public async openMemories() {
|
|
if (!await this.fileSystemService.exists(Path.Memories, true)) {
|
|
await this.updateMemories(""); // Create memories file if one doesn't exist
|
|
}
|
|
await this.workSpaceService.openNoteByPath(Path.Memories);
|
|
}
|
|
|
|
public async readMemories(): Promise<string> {
|
|
const result = await this.fileSystemService.readFile(Path.Memories, true);
|
|
|
|
if (result instanceof Error) {
|
|
return Copy.MemoriesEmpty;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async updateMemories(newMemories: string): Promise<string|Error> {
|
|
if (!this.isValidMemoryLength(newMemories)) {
|
|
return Copy.MemoriesMaxLengthError;
|
|
}
|
|
|
|
const result = await this.fileSystemService.writeFile(Path.Memories, newMemories, true, false);
|
|
return result instanceof Error ? result : Copy.MemoriesUpdatedSuccess;
|
|
}
|
|
|
|
private isValidMemoryLength(memories: string): boolean {
|
|
const lines = memories.split(/\r?\n/);
|
|
return lines.length <= this.maxMemoriesLength &&
|
|
lines.every(line => line.length <= this.maxMemoriesLineLength);
|
|
}
|
|
|
|
} |