mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
- Change ChatMode enum values from numeric (0,1,2) to string literals ("read_only", "edit", "planning")
- Move chat mode state management from ChatWindow to SettingsService with persistence
- Add chat mode awareness to system prompts and tool validation
- Replace Map with WeakMap for settings subscribers to prevent memory leaks
- Add type-safe event handlers to EventService
- Update esbuild and TypeScript targets from ES2018/ES2020 to ES2022
- Add requiresEditModeEnabled() validation to prevent tool hallucination in read-only mode
- Update all test fixtures to include chatMode in mock settings
95 lines
No EOL
3.3 KiB
TypeScript
95 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 { Copy, replaceCopy } 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;
|
|
}
|
|
} |