export function resolveServerHttpOrigin(): string { if (typeof window === "undefined") return ""; const bridgeWsUrl = window.desktopBridge?.getWsUrl?.(); const envWsUrl = import.meta.env.VITE_WS_URL as string | undefined; const wsUrl = typeof bridgeWsUrl === "string" && bridgeWsUrl.length > 0 ? bridgeWsUrl : typeof envWsUrl === "string" && envWsUrl.length > 0 ? envWsUrl : `ws://${window.location.hostname}:${window.location.port}`; const httpUrl = wsUrl.replace(/^wss:/, "https:").replace(/^ws:/, "http:"); try { return new URL(httpUrl).origin; } catch { return httpUrl; } }