import { openLix } from "../../lix/open-lix.js";
import { InMemoryEnvironment } from "../../environment/in-memory.js";
export const engineBoundarySimulation = {
    name: "engine boundary",
    setup: async (lix) => {
        // Re-seed into an isomorphic boundary environment that hides engine
        const blob = await lix.toBlob();
        // Preserve plugin instances from the original session if available
        const providePlugins = await (async () => {
            try {
                return await lix.plugin?.getAll?.();
            }
            catch {
                return undefined;
            }
        })();
        await lix.close();
        const boundaryLix = await openLix({
            blob,
            environment: new EngineBoundaryEnvironment(),
            providePlugins,
        });
        return boundaryLix;
    },
};
// Inline, isomorphic environment wrapper that hides the engine from openLix()
class EngineBoundaryEnvironment {
    inner;
    constructor() {
        this.inner = new InMemoryEnvironment();
    }
    async open(initOpts) {
        await this.inner.open(initOpts);
        return {};
    }
    async create(createOpts) {
        await this.inner.create(createOpts);
    }
    async export() {
        return this.inner.export();
    }
    async exists() {
        return this.inner.exists();
    }
    async call(name, args) {
        return this.inner.call(name, args);
    }
    async close() {
        await this.inner.close();
    }
}
//# sourceMappingURL=engine-boundary-simulation.js.map