mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 16:30:27 +00:00
- 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
43 lines
No EOL
1.1 KiB
TypeScript
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();
|
|
} |