import { ForkedInteractiveMode } from "./forked/interactive-mode.js";
import { createRemoteInteractiveController, } from "./interactive/remote-interactive-controller.js";
export class PeerInteractiveMode {
    runtime;
    controller;
    mode;
    constructor(runtime, options = {}) {
        this.runtime = runtime;
        this.controller = createRemoteInteractiveController(this.runtime, options.capabilities);
        this.mode = new ForkedInteractiveMode({
            peerId: this.runtime.hello.peerId,
            cwd: this.runtime.hello.cwd ?? process.cwd(),
            getView: () => this.controller.getView(),
            actions: this.controller.actions,
            capabilities: this.controller.capabilities,
            getDraft: () => this.runtime.uiState.getSnapshot().draft,
            setDraft: (draft) => this.runtime.uiState.setDraft(draft),
            subscribe: (listener) => {
                const unsubscribers = [
                    this.runtime.appState.subscribe(() => listener()),
                    this.runtime.uiState.subscribe(() => listener()),
                ];
                return () => {
                    for (const unsubscribe of unsubscribers) {
                        unsubscribe();
                    }
                };
            },
        }, options);
    }
    async run() {
        await this.runtime.start();
        try {
            return await this.mode.run();
        }
        finally {
            await this.runtime.stop();
        }
    }
    async stop() {
        await this.mode.stop();
    }
}
//# sourceMappingURL=peer-interactive-mode.js.map