export async function getDesktopBridgeStatus(options = {}) {
    const endpoint = options.url
        || process.env.VIGTHORIA_DESKTOP_BRIDGE_URL
        || `http://${process.env.VIGTHORIA_DESKTOP_HOST || '127.0.0.1'}:${process.env.VIGTHORIA_DESKTOP_PORT || '49160'}`;
    const timeoutMs = options.timeoutMs ?? 5000;
    try {
        const controller = new AbortController();
        const timer = setTimeout(() => controller.abort(), timeoutMs);
        const response = await fetch(`${endpoint.replace(/\/$/, '')}/health`, {
            signal: controller.signal,
            headers: { Accept: 'application/json' },
        });
        clearTimeout(timer);
        if (!response.ok) {
            return { ok: false, endpoint, error: `HTTP ${response.status}` };
        }
        const data = await response.json();
        return {
            ok: true,
            endpoint,
            service: typeof data.service === 'string' ? data.service : undefined,
            version: typeof data.version === 'string' ? data.version : undefined,
            controlEnabled: data.controlEnabled === true || data.control_enabled === true,
        };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return { ok: false, endpoint, error: message };
    }
}
