Passes EventBus through LifecycleFactory and AgentLifecycleController so that when an account is marked exhausted, an agent:account_switched event is emitted with the previous and new account IDs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
/**
|
|
* Lifecycle Factory — Wire up all lifecycle components with proper dependencies.
|
|
*
|
|
* Creates and configures the complete lifecycle management system with all
|
|
* dependencies properly injected. Provides simple entry point for integration.
|
|
*/
|
|
|
|
import { FileSystemSignalManager } from './signal-manager.js';
|
|
import { DefaultRetryPolicy } from './retry-policy.js';
|
|
import { AgentErrorAnalyzer } from './error-analyzer.js';
|
|
import { DefaultCleanupStrategy } from './cleanup-strategy.js';
|
|
import { AgentLifecycleController } from './controller.js';
|
|
import type { AgentRepository } from '../../db/repositories/agent-repository.js';
|
|
import type { AccountRepository } from '../../db/repositories/account-repository.js';
|
|
import type { ProcessManager } from '../process-manager.js';
|
|
import type { CleanupManager } from '../cleanup-manager.js';
|
|
import type { EventBus } from '../../events/types.js';
|
|
|
|
export interface LifecycleFactoryOptions {
|
|
repository: AgentRepository;
|
|
processManager: ProcessManager;
|
|
cleanupManager: CleanupManager;
|
|
accountRepository?: AccountRepository;
|
|
debug?: boolean;
|
|
eventBus?: EventBus;
|
|
}
|
|
|
|
/**
|
|
* Create a fully configured AgentLifecycleController with all dependencies.
|
|
*/
|
|
export function createLifecycleController(options: LifecycleFactoryOptions): AgentLifecycleController {
|
|
const {
|
|
repository,
|
|
processManager,
|
|
cleanupManager,
|
|
accountRepository,
|
|
debug = false,
|
|
eventBus,
|
|
} = options;
|
|
|
|
// Create core components
|
|
const signalManager = new FileSystemSignalManager();
|
|
const retryPolicy = new DefaultRetryPolicy();
|
|
const errorAnalyzer = new AgentErrorAnalyzer(signalManager);
|
|
const cleanupStrategy = new DefaultCleanupStrategy(cleanupManager);
|
|
|
|
// Wire up the main controller
|
|
const lifecycleController = new AgentLifecycleController(
|
|
signalManager,
|
|
retryPolicy,
|
|
errorAnalyzer,
|
|
processManager,
|
|
repository,
|
|
cleanupManager,
|
|
cleanupStrategy,
|
|
accountRepository,
|
|
debug,
|
|
eventBus,
|
|
);
|
|
|
|
return lifecycleController;
|
|
} |