/**
 * A simple Dependency Injection container to manage late-binding dependencies
 * and resolve circular references.
 */
export class Container {
    constructor(parent) {
        this.services = new Map();
        this.factories = new Map();
        this.parent = parent;
    }
    /**
     * Create a child container that inherits from this container
     */
    createChild() {
        return new Container(this);
    }
    /**
     * Register a singleton instance
     */
    register(token, instance) {
        this.services.set(token, instance);
    }
    /**
     * Register a factory function for lazy resolution
     */
    provide(token, factory) {
        this.factories.set(token, factory);
    }
    /**
     * Resolve a service by token
     */
    get(token) {
        if (this.services.has(token)) {
            return this.services.get(token);
        }
        const factory = this.factories.get(token);
        if (factory) {
            const instance = factory();
            this.services.set(token, instance);
            return instance;
        }
        if (this.parent) {
            return this.parent.get(token);
        }
        return undefined;
    }
    /**
     * Check if a service exists
     */
    has(token) {
        return (this.services.has(token) ||
            this.factories.has(token) ||
            (this.parent ? this.parent.has(token) : false));
    }
}
// Example usage for ToolManager:
/*
const container = new Container();

// 1. Provide managers lazily
container.provide('SubagentManager', () => new SubagentManager(...));
container.provide('SkillManager', () => new SkillManager(...));

// 2. ToolManager can now resolve them only when needed (e.g., in execute)
class ToolManager {
  constructor(private container: Container) {}

  async execute(name: string, args: any, context: any) {
    const enhancedContext = {
      ...context,
      subagentManager: this.container.has('SubagentManager')
        ? this.container.get('SubagentManager')
        : undefined,
      // ...
    };
    // ...
  }
}
*/
