Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.2 KB
Raw Blame
import { isOfficialCloudServer, OFFICIAL_CLOUD_URL } from '@lobechat/const';

import { type ElectronState } from '../initialState';

const isSyncActive = (s: ElectronState) => s.dataSyncConfig.active ?? false;

const storageMode = (s: ElectronState) => s.dataSyncConfig.storageMode;

/**
 * Returns the effective remote server URL based on storage mode:
 * - Cloud mode: returns OFFICIAL_CLOUD_URL, the gateway entrypoint the main process
 *   also uses as `OFFICIAL_CLOUD_SERVER`
 * - SelfHost mode: returns the configured remoteServerUrl
 */
const remoteServerUrl = (s: ElectronState) =>
  s.dataSyncConfig.storageMode === 'cloud'
    ? OFFICIAL_CLOUD_URL
    : s.dataSyncConfig.remoteServerUrl || '';

/**
 * Returns the raw remoteServerUrl from config without transformation.
 * Use this when you need the original configured value (e.g., for editing forms).
 */
const rawRemoteServerUrl = (s: ElectronState) => s.dataSyncConfig.remoteServerUrl || '';

const isOfficialServer = (s: ElectronState) => isOfficialCloudServer(remoteServerUrl(s));

export const electronSyncSelectors = {
  isOfficialServer,
  isSyncActive,
  rawRemoteServerUrl,
  remoteServerUrl,
  storageMode,
};