import { ClaudeBridge } from './claude-bridge.js';
import { OpenCodeBridge } from './opencode-bridge.js';
import { getEngine, setEngine } from '../config/engine-config.js';
export class EngineManager {
    _engine;
    _engineType;
    constructor() {
        this._engineType = getEngine();
        this._engine = this.createBridge(this._engineType);
        console.log(`[engine-manager] Initialized with ${this._engineType}`);
    }
    createBridge(type) {
        if (type === 'claude-code') {
            console.log('[engine-manager] Creating Claude Code bridge');
            return new ClaudeBridge({
                timeoutMs: parseInt(process.env.BRIDGE_TIMEOUT_MS ?? '300000', 10),
            });
        }
        console.log('[engine-manager] Creating OpenCode bridge');
        return new OpenCodeBridge({
            baseUrl: process.env.OPENCODE_BASE_URL,
            timeoutMs: parseInt(process.env.BRIDGE_TIMEOUT_MS ?? '300000', 10),
        });
    }
    get engine() {
        return this._engine;
    }
    get engineType() {
        return this._engineType;
    }
    switchEngine(newType) {
        if (this._engineType === newType)
            return;
        console.log(`[engine-manager] Switching engine from "${this._engineType}" to "${newType}"`);
        // Abort all active sessions from old engine
        console.log('[engine-manager] Killing active sessions...');
        this._engine.kill('__all__');
        // Create new bridge
        this._engineType = newType;
        this._engine = this.createBridge(newType);
        setEngine(newType);
    }
    getActiveSquads() {
        const engine = this._engine;
        if (engine.activeSessions) {
            return Array.from(engine.activeSessions.keys());
        }
        if (engine.activeProcesses) {
            return Array.from(engine.activeProcesses.keys());
        }
        return [];
    }
}
//# sourceMappingURL=engine-manager.js.map