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.
42 lines
No EOL
1.5 KiB
TypeScript
42 lines
No EOL
1.5 KiB
TypeScript
import type VaultkeeperAIPlugin from "main";
|
|
import { Resolve } from "./DependencyService";
|
|
import { Services } from "./Services";
|
|
import { Notice, TFile, type WorkspaceLeaf } from "obsidian";
|
|
import type { VaultService } from "./VaultService";
|
|
|
|
export class WorkSpaceService {
|
|
private readonly plugin: VaultkeeperAIPlugin = Resolve<VaultkeeperAIPlugin>(Services.VaultkeeperAIPlugin);
|
|
private readonly vaultService: VaultService = Resolve<VaultService>(Services.VaultService);
|
|
|
|
public async openNote(noteName: string) {
|
|
const file: TFile | null = this.plugin.app.metadataCache.getFirstLinkpathDest(noteName, "");
|
|
const leaf: WorkspaceLeaf = this.plugin.app.workspace.getLeaf(false);
|
|
|
|
if (file) {
|
|
await leaf.openFile(file);
|
|
} else {
|
|
new Notice(`Failed to open note: "${noteName}"`);
|
|
}
|
|
}
|
|
|
|
public async openNoteByPath(path: string) {
|
|
const file = this.plugin.app.vault.getAbstractFileByPath(path);
|
|
|
|
if (file instanceof TFile) {
|
|
const leaf: WorkspaceLeaf = this.plugin.app.workspace.getLeaf(false);
|
|
await leaf.openFile(file);
|
|
} else {
|
|
new Notice(`Failed to open note: "${path}"`);
|
|
}
|
|
}
|
|
|
|
public getActiveFile(allowAccessToPluginRoot: boolean = false): TFile | null {
|
|
const activeFile = this.plugin.app.workspace.getActiveFile();
|
|
|
|
if (!activeFile || this.vaultService.isExclusion(activeFile.path, allowAccessToPluginRoot)) {
|
|
return null;
|
|
}
|
|
|
|
return activeFile;
|
|
}
|
|
} |