andy-stack_vaultkeeper-ai/Services/MemoriesService.ts
Andrew Beal 28c8ccb44b feat: add quick actions system with provider-aware model settings
Introduce QuickActionsService and QuickAgent for lightweight, single-shot AI
operations. Add a dedicated quickActionModel setting alongside a new top-level
provider setting, with validation ensuring all models match the selected provider
and provider-specific defaults. Refactor FileSystemService to offer both TFile
and path-based overloads (readFile/readFilePath, writeToFile/writeToFilePath,
patchFile/patchFileAtPath). Replace window/document globals with activeWindow/
activeDocument throughout InputService and VaultkeeperAISettingTab for Obsidian
mobile compatibility.
Update linting packages to latest.
2026-04-20 20:20:22 +01:00

54 lines
No EOL
2 KiB
TypeScript

import { Copy, replaceCopy } 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.readFilePath(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 replaceCopy(Copy.MemoriesMaxLengthError,
[this.maxMemoriesLength.toString(), this.maxMemoriesLineLength.toString()]);
}
const result = await this.fileSystemService.writeToFilePath(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);
}
}