import { createHttpTransport } from './daemon-http-client.js';
import { createClientTransport } from './client-transport.js';
import { createWebSocketConnector } from './shared.js';
import { createRemoteUiRuntimeEvents } from './ui-runtime-events.js';
export function createRealtimeTransport(options) {
    const baseTransport = createHttpTransport({
        baseUrl: options.baseUrl,
        authToken: options.authToken,
        fetchImpl: options.fetchImpl,
    });
    const WebSocketImpl = options.webSocketImpl ?? WebSocket;
    const events = createRemoteUiRuntimeEvents(createWebSocketConnector(options.baseUrl, options.authToken, WebSocketImpl));
    const operator = {
        ...baseTransport.operator,
        events,
    };
    const transport = createClientTransport('realtime', operator, baseTransport.peer);
    return Object.freeze({
        ...transport,
        async snapshot() {
            const snapshot = await baseTransport.snapshot();
            return {
                ...snapshot,
                kind: 'realtime',
            };
        },
    });
}
