andy-stack_vaultkeeper-ai/Services/DependencyService.ts
Andrew Beal cefc408b2e Add context passing between execution steps and enhance orchestration
- Add context_for_next_step parameter to CompleteStep for passing execution history
- Add context parameter to CompleteTask for preserving task completion state
- Update OrchestrationResult to handle context propagation between steps
- Add debug color differentiation for agent types (Main, Execution, Orchestration, Planning)
- Reorganize SearchTypes from Helpers to Types directory
- Add justification requirement for execution deviations
- Support reasonable deviations in orchestration plan validation
- Refactor dependency service with TryResolve utility
- Add whitespace cleanup to Semaphore class
2026-01-28 21:23:47 +00:00

43 lines
No EOL
1.1 KiB
TypeScript

import { Exception } from "Helpers/Exception";
import type { Component } from "obsidian";
const services = new Map<symbol, unknown>();
export function RegisterSingleton<T>(type: symbol, instance: T) {
services.set(type, instance);
}
export function RegisterTransient<T>(type: symbol, factory: () => T) {
services.set(type, factory);
}
export function Resolve<T>(type: symbol): T {
const service = services.get(type);
if (!service) {
Exception.throw(`Service not found for type: ${type.description}`);
}
if (typeof service === "function") {
// It"s a transient factory, return a new instance
return (service as () => T)();
}
// It"s a singleton, return the existing instance
return service as T;
}
export function TryResolve<T>(type: symbol): T | undefined {
if (services.has(type)) {
return Resolve<T>(type);
}
}
export function DeregisterAllServices() {
services.forEach((service) => {
if (service && typeof service === "object" && "unload" in service) {
(service as Component).unload();
}
});
services.clear();
}