andy-stack_vaultkeeper-ai/Services/ServiceRegistration.ts

153 lines
8.8 KiB
TypeScript
Raw Permalink Normal View History

// Core and Enums
2026-07-04 11:16:08 +00:00
import { AIProvider } from "Enums/ApiProvider";
import { Environment } from "Enums/Environment";
2025-11-10 08:03:27 +00:00
import type VaultkeeperAIPlugin from "main";
import { AssetsService } from "./AssetsService";
// Services
import { RegisterSingleton, RegisterTransient, Resolve } from "./DependencyService";
2025-09-08 14:50:06 +00:00
import { Services } from "./Services";
import { AbortService } from "./AbortService";
import { AIToolService } from "./AIServices/AIToolService";
import { ChatService } from "./ChatService";
import { ConversationFileSystemService } from "./ConversationFileSystemService";
import { ConversationNamingService } from "./ConversationNamingService";
import { DebugService } from "./DebugService";
import { DiffService } from "./DiffService";
import { EventService } from "./EventService";
import { PlanApprovalService } from "./PlanApprovalService";
import { FileSystemService } from "./FileSystemService";
import { HTMLService } from "./HTMLService";
import { InputService } from "./InputService";
import { MainAgent } from "./AIServices/MainAgent";
import { MemoriesService } from "./MemoriesService";
import { SanitiserService } from "./SanitiserService";
import { SettingsService, type IVaultkeeperAISettings } from "./SettingsService";
import { StreamingMarkdownService } from "./StreamingMarkdownService";
import { StreamingService } from "./StreamingService";
import { UserInputService } from "./UserInputService";
import { VaultCacheService } from "./VaultCacheService";
import { VaultService } from "./VaultService";
import { WorkSpaceService } from "./WorkSpaceService";
import { WebViewerService } from "./WebViewerService";
// Stores
import { ExecutionPlanStore } from "Stores/ExecutionPlanStore";
import { SearchStateStore } from "Stores/SearchStateStore";
// Modals
import { ConversationHistoryModal } from "Modals/ConversationHistoryModal";
import { HelpModal } from "Modals/HelpModal";
// AI Classes
import type { IAIClass } from "AIClasses/IAIClass";
2025-12-17 18:06:16 +00:00
import type { IAIFileService } from "AIClasses/IAIFileService";
2026-07-04 11:16:08 +00:00
import type { IConversationNamingAgent } from "AIClasses/IConversationNamingAgent";
import { Claude } from "AIClasses/Claude/Claude";
2026-07-04 11:16:08 +00:00
import { ClaudeConversationNamingAgent } from "AIClasses/Claude/ClaudeConversationNamingAgent";
2025-12-17 18:06:16 +00:00
import { ClaudeFileService } from "AIClasses/Claude/ClaudeFileService";
import { Gemini } from "AIClasses/Gemini/Gemini";
2026-07-04 11:16:08 +00:00
import { GeminiConversationNamingAgent } from "AIClasses/Gemini/GeminiConversationNamingAgent";
2025-12-17 18:06:16 +00:00
import { GeminiFileService } from "AIClasses/Gemini/GeminiFileService";
import { Mistral } from "AIClasses/Mistral/Mistral";
2026-07-04 11:16:08 +00:00
import { MistralConversationNamingAgent } from "AIClasses/Mistral/MistralConversationNamingAgent";
import { MistralFileService } from "AIClasses/Mistral/MistralFileService";
import { OpenAI } from "AIClasses/OpenAI/OpenAI";
2026-07-04 11:16:08 +00:00
import { OpenAIConversationNamingAgent } from "AIClasses/OpenAI/OpenAIConversationNamingAgent";
2025-12-17 18:06:16 +00:00
import { OpenAIFileService } from "AIClasses/OpenAI/OpenAIFileService";
2026-07-04 11:16:08 +00:00
import { Local } from "AIClasses/Local/Local";
import { LocalConversationNamingAgent } from "AIClasses/Local/LocalConversationNamingAgent";
import { LocalFileService } from "AIClasses/Local/LocalFileService";
// Prompts
import { AIPrompt, type IPrompt } from "AIPrompts/IPrompt";
import { QuickAgent } from "./AIServices/QuickAgent";
import { QuickActionsDefinitionsService } from "./QuickActions/QuickActionsDefinitionsService";
import { QuickActionsService } from "./QuickActions/QuickActionsService";
2025-09-08 14:50:06 +00:00
2025-11-10 08:03:27 +00:00
export async function RegisterPlugin(plugin: VaultkeeperAIPlugin) {
RegisterSingleton<VaultkeeperAIPlugin>(Services.VaultkeeperAIPlugin, plugin);
RegisterSingleton<SettingsService>(Services.SettingsService, new SettingsService(await plugin.loadData() as Partial<IVaultkeeperAISettings>));
RegisterSingleton<AssetsService>(Services.AssetsService, new AssetsService());
}
export function RegisterDependencies() {
if (process.env.NODE_ENV === Environment.DEV) {
RegisterTransient<DebugService | undefined>(Services.DebugService, () => new DebugService());
}
RegisterSingleton<EventService>(Services.EventService, new EventService());
RegisterSingleton<AbortService>(Services.AbortService, new AbortService());
RegisterSingleton<HTMLService>(Services.HTMLService, new HTMLService());
RegisterSingleton<SanitiserService>(Services.SanitiserService, new SanitiserService());
RegisterSingleton<DiffService>(Services.DiffService, new DiffService());
RegisterSingleton<PlanApprovalService>(Services.PlanApprovalService, new PlanApprovalService());
RegisterSingleton<VaultService>(Services.VaultService, new VaultService());
RegisterSingleton<VaultCacheService>(Services.VaultCacheService, new VaultCacheService());
RegisterSingleton<FileSystemService>(Services.FileSystemService, new FileSystemService());
RegisterSingleton<SearchStateStore>(Services.SearchStateStore, new SearchStateStore());
RegisterSingleton<ExecutionPlanStore>(Services.ExecutionPlanStore, new ExecutionPlanStore());
RegisterSingleton<UserInputService>(Services.UserInputService, new UserInputService());
RegisterSingleton<WorkSpaceService>(Services.WorkSpaceService, new WorkSpaceService());
RegisterSingleton<MemoriesService>(Services.MemoriesService, new MemoriesService());
RegisterSingleton<ConversationFileSystemService>(Services.ConversationFileSystemService, new ConversationFileSystemService());
RegisterSingleton<ConversationNamingService>(Services.ConversationNamingService, new ConversationNamingService());
RegisterSingleton<QuickActionsDefinitionsService>(Services.QuickActionsDefinitionsService, new QuickActionsDefinitionsService());
RegisterSingleton<QuickActionsService>(Services.QuickActionsService, new QuickActionsService());
RegisterTransient<WebViewerService>(Services.WebViewerService, () => new WebViewerService());
2025-09-08 14:50:06 +00:00
RegisterSingleton<IPrompt>(Services.IPrompt, new AIPrompt());
RegisterSingleton<AIToolService>(Services.AIToolService, new AIToolService());
refactor: implement multi-agent orchestration architecture Restructure the AI workflow from a single-agent model to a specialized multi-agent system with distinct roles: - Add AgentType enum (Main, Orchestration, Planning, Execution) to define agent specializations - Replace AIControllerService and AIFunctionService with modular agent classes in Services/AIServices/: - MainAgent: Handles user interaction and delegates to orchestration - OrchestrationAgent: Coordinates plan execution and step-by-step workflow - PlanningAgent: Creates and revises execution plans - ExecutionAgent: Executes individual plan steps - AIController: Base class providing common agent loop functionality - Create specialized prompts (OrchestrationPrompt, ExecutionPrompt) for agent-specific behavior - Add OrchestrationResult type to communicate workflow control decisions (continue, abort, replan) - Introduce agent-specific function scoping: - ExecuteWorkflow for main agent - CompleteTask for execution agent - CompleteStep/Replan/CancelPlan for orchestration agent - SubmitPlan/AskUserQuestionPlanning for planning agent - Update BaseAIClass to use agentType property instead of isPlanningAgent boolean for model selection - Simplify ExecutionPlan and ExecutionStep types by removing execution state tracking (moved to agent coordination) - Remove PlanningEnabledAppendix and ExecutionStatus enum (superseded by agent architecture) - Add comprehensive integration tests for agent workflows This architecture provides better separation of concerns, clearer agent responsibilities, and more robust plan execution with explicit orchestration control flow.
2026-01-27 20:29:20 +00:00
RegisterSingleton<MainAgent>(Services.MainAgent, new MainAgent());
RegisterSingleton<StreamingService>(Services.StreamingService, new StreamingService());
RegisterSingleton<ChatService>(Services.ChatService, new ChatService());
2025-09-08 14:50:06 +00:00
RegisterTransient<QuickAgent>(Services.QuickAgent, () => new QuickAgent());
RegisterTransient<StreamingMarkdownService>(Services.StreamingMarkdownService, () => new StreamingMarkdownService());
2025-10-29 19:46:20 +00:00
RegisterTransient<InputService>(Services.InputService, () => new InputService());
RegisterModals();
RegisterAiProvider();
2025-09-08 14:50:06 +00:00
}
export function RegisterAiProvider() {
const settingsService = Resolve<SettingsService>(Services.SettingsService);
2026-07-04 11:16:08 +00:00
const provider = settingsService.settings.provider;
if (provider == AIProvider.Claude) {
2025-12-17 18:06:16 +00:00
RegisterSingleton<IAIFileService>(Services.IAIFileService, new ClaudeFileService());
RegisterSingleton<IAIClass>(Services.IAIClass, new Claude());
2026-07-04 11:16:08 +00:00
RegisterSingleton<IConversationNamingAgent>(Services.IConversationNamingService, new ClaudeConversationNamingAgent());
}
else if (provider == AIProvider.Gemini) {
2025-12-17 18:06:16 +00:00
RegisterSingleton<IAIFileService>(Services.IAIFileService, new GeminiFileService());
RegisterSingleton<IAIClass>(Services.IAIClass, new Gemini());
2026-07-04 11:16:08 +00:00
RegisterSingleton<IConversationNamingAgent>(Services.IConversationNamingService, new GeminiConversationNamingAgent());
2025-09-08 14:50:06 +00:00
}
else if (provider == AIProvider.OpenAI) {
2025-12-17 18:06:16 +00:00
RegisterSingleton<IAIFileService>(Services.IAIFileService, new OpenAIFileService());
RegisterSingleton<IAIClass>(Services.IAIClass, new OpenAI());
2026-07-04 11:16:08 +00:00
RegisterSingleton<IConversationNamingAgent>(Services.IConversationNamingService, new OpenAIConversationNamingAgent());
}
else if (provider == AIProvider.Mistral) {
RegisterSingleton<IAIFileService>(Services.IAIFileService, new MistralFileService());
RegisterSingleton<IAIClass>(Services.IAIClass, new Mistral());
2026-07-04 11:16:08 +00:00
RegisterSingleton<IConversationNamingAgent>(Services.IConversationNamingService, new MistralConversationNamingAgent());
}
else if (provider == AIProvider.Local) {
RegisterSingleton<IAIFileService>(Services.IAIFileService, new LocalFileService());
RegisterSingleton<IAIClass>(Services.IAIClass, new Local());
RegisterSingleton<IConversationNamingAgent>(Services.IConversationNamingService, new LocalConversationNamingAgent());
}
refactor: implement multi-agent orchestration architecture Restructure the AI workflow from a single-agent model to a specialized multi-agent system with distinct roles: - Add AgentType enum (Main, Orchestration, Planning, Execution) to define agent specializations - Replace AIControllerService and AIFunctionService with modular agent classes in Services/AIServices/: - MainAgent: Handles user interaction and delegates to orchestration - OrchestrationAgent: Coordinates plan execution and step-by-step workflow - PlanningAgent: Creates and revises execution plans - ExecutionAgent: Executes individual plan steps - AIController: Base class providing common agent loop functionality - Create specialized prompts (OrchestrationPrompt, ExecutionPrompt) for agent-specific behavior - Add OrchestrationResult type to communicate workflow control decisions (continue, abort, replan) - Introduce agent-specific function scoping: - ExecuteWorkflow for main agent - CompleteTask for execution agent - CompleteStep/Replan/CancelPlan for orchestration agent - SubmitPlan/AskUserQuestionPlanning for planning agent - Update BaseAIClass to use agentType property instead of isPlanningAgent boolean for model selection - Simplify ExecutionPlan and ExecutionStep types by removing execution state tracking (moved to agent coordination) - Remove PlanningEnabledAppendix and ExecutionStatus enum (superseded by agent architecture) - Add comprehensive integration tests for agent workflows This architecture provides better separation of concerns, clearer agent responsibilities, and more robust plan execution with explicit orchestration control flow.
2026-01-27 20:29:20 +00:00
Resolve<MainAgent>(Services.MainAgent).resolveAIProvider();
Resolve<ConversationNamingService>(Services.ConversationNamingService).resolveNamingProvider();
Resolve<ConversationFileSystemService>(Services.ConversationFileSystemService).resolveAIFileService();
}
function RegisterModals() {
RegisterTransient<ConversationHistoryModal>(Services.ConversationHistoryModal, () => new ConversationHistoryModal());
RegisterTransient<HelpModal>(Services.HelpModal, () => new HelpModal())
2025-09-08 14:50:06 +00:00
}