mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Move replaceCopy function from Copy enum to Helpers module to improve separation of concerns. Add splitFrontmatter and mergeTagsIntoFrontmatter utilities for YAML frontmatter manipulation. Remove unused Beautify prompt and QuickActionsService. Add timeout support to Semaphore.wait(). Remove unused Event.QuickActionsSettingsChanged. Update all imports across AI classes, prompts, services, and tests.
96 lines
No EOL
3.3 KiB
TypeScript
96 lines
No EOL
3.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 { replaceCopy } from 'Helpers/Helpers';
|
|
import { Copy } from "Enums/Copy";
|
|
import { ChatMode } from "Enums/ChatMode";
|
|
|
|
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 chatModeDirective = s.chatMode === ChatMode.ReadOnly
|
|
? Copy.DirectiveChatModeReadOnly
|
|
: s.chatMode === ChatMode.Edit
|
|
? Copy.DirectiveChatModeEdit
|
|
: Copy.DirectiveChatModePlanning;
|
|
|
|
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 = [chatModeDirective, 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;
|
|
}
|
|
} |