mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
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.
88 lines
No EOL
3 KiB
TypeScript
88 lines
No EOL
3 KiB
TypeScript
import { Resolve } from "Services/DependencyService";
|
|
import { Services } from "Services/Services";
|
|
import { SystemInstruction } from "./SystemPrompt";
|
|
import type { FileSystemService } from "Services/FileSystemService";
|
|
import type { SettingsService } from "Services/SettingsService";
|
|
import { PlanningPrompt } from "AIPrompts/PlanningPrompt";
|
|
import { ExecutionPrompt } from "./ExecutionPrompt";
|
|
import { OrchestrationPrompt } from "./OrchestrationPrompt";
|
|
import type { MemoriesService } from "Services/MemoriesService";
|
|
import { Copy, replaceCopy } from "Enums/Copy";
|
|
|
|
export interface IPrompt {
|
|
systemInstruction(): Promise<string>;
|
|
orchestrationInstruction(): Promise<string>;
|
|
planningInstruction(): Promise<string>;
|
|
executionInstruction(): string;
|
|
userInstruction(): Promise<string>;
|
|
}
|
|
|
|
export class AIPrompt implements IPrompt {
|
|
|
|
private readonly settingsService: SettingsService;
|
|
private readonly memoriesService: MemoriesService;
|
|
private readonly fileSystemService: FileSystemService;
|
|
|
|
public constructor() {
|
|
this.settingsService = Resolve<SettingsService>(Services.SettingsService);
|
|
this.memoriesService = Resolve<MemoriesService>(Services.MemoriesService);
|
|
this.fileSystemService = Resolve<FileSystemService>(Services.FileSystemService);
|
|
}
|
|
|
|
public async systemInstruction(): Promise<string> {
|
|
return this.buildPrompt(SystemInstruction);
|
|
}
|
|
|
|
public async orchestrationInstruction(): Promise<string> {
|
|
return this.buildPrompt(OrchestrationPrompt);
|
|
}
|
|
|
|
public async planningInstruction(): Promise<string> {
|
|
return this.buildPrompt(PlanningPrompt);
|
|
}
|
|
|
|
public executionInstruction(): string {
|
|
return ExecutionPrompt;
|
|
}
|
|
|
|
private async buildPrompt(basePrompt: string): Promise<string> {
|
|
let prompt = basePrompt;
|
|
|
|
if (this.settingsService.settings.enableMemories) {
|
|
const memories = await this.memoriesService.readMemories();
|
|
if (memories !== "") {
|
|
prompt = prompt + replaceCopy(Copy.MemoriesInjectionHeader, [memories]);
|
|
}
|
|
}
|
|
|
|
prompt = prompt + this.buildActiveDirectives();
|
|
|
|
return prompt;
|
|
}
|
|
|
|
private buildActiveDirectives(): string {
|
|
const s = this.settingsService.settings;
|
|
|
|
const memoriesDirective = !s.enableMemories
|
|
? Copy.DirectiveMemoriesDisabled
|
|
: s.allowUpdatingMemories
|
|
? Copy.DirectiveMemoriesEnabled
|
|
: Copy.DirectiveMemoriesReadOnly;
|
|
|
|
const webSearchDirective = s.enableWebSearch
|
|
? Copy.DirectiveWebSearchEnabled
|
|
: Copy.DirectiveWebSearchDisabled;
|
|
|
|
const webViewerDirective = s.enableWebViewer
|
|
? Copy.DirectiveWebViewerEnabled
|
|
: Copy.DirectiveWebViewerDisabled;
|
|
|
|
const directives = [memoriesDirective, webSearchDirective, webViewerDirective].join("\n");
|
|
return replaceCopy(Copy.ActiveCapabilitiesHeader, [directives]);
|
|
}
|
|
|
|
public async userInstruction(): Promise<string> {
|
|
const result = await this.fileSystemService.readFilePath(this.settingsService.settings.userInstruction, true);
|
|
return result instanceof Error ? "" : result;
|
|
}
|
|
} |