/**
 * Optional Kylin trial user id to persist into `config.toml` via WebSocket `set_model.api_key`.
 *
 * Resolution order:
 * 1. `VITE_KYLIN_USER_ID` (build-time embed for OEM images)
 * 2. `localStorage.kylinbot_kylin_user_id` (user can set once in devtools or a future settings UI)
 */
export function optionalKylinUserIdForPersist(): string | undefined {
  try {
    const fromEnv = import.meta.env.VITE_KYLIN_USER_ID as string | undefined;
    if (fromEnv?.trim()) {
      return fromEnv.trim();
    }
    const fromLs = localStorage.getItem('kylinbot_kylin_user_id');
    if (fromLs?.trim()) {
      return fromLs.trim();
    }
  } catch {
    // ignore
  }
  return undefined;
}
