Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

11.5 KB
Raw Blame
import { useState } from "react";
import { Plus } from "lucide-react";
import { productName } from "@/lib/brand";
import { FEEDBACK_URL, HELP_CENTER_URL, desktopAppVersion, openExternalLink } from "@/lib/app-links";
import { t } from "@/lib/i18n";
import { useStoreDispatch } from "@/state/store-select";
import { AboutDialog } from "../../AboutDialog";
import { AnalyticsRow } from "../../AnalyticsRow";
import { ChatWidthRow, FontRow, SidebarToolsLayoutRow, UsageIndicatorRow } from "../../AppearanceSelectRows";
import {
  ColorUserBubblesRow, FollowUpRow, LanguageRow, PinnedCirclesRow, ReplayTourRow, SendKeyRow, ShowThreadsRow,
  ToolCallsRow, UniversalPinsRow, UpdatesRow,
} from "../../AppSettingsRows";
import { ChromeRailRow } from "../../ChromeRailToggle";
import { ConnectedWorkspacesSettings } from "../../ConnectedWorkspacesSettings";
import { LendComputerSwitch } from "../../LendComputerSwitch";
import { CustomThemesSettings } from "../../CustomThemesSettings";
import { DiagnosticsRow } from "../../DiagnosticsRow";
import { NotificationRows } from "../../NotificationSettingsRows";
import { OpenAtLoginRow } from "../../OpenAtLoginRow";
import { PinnedPanelsSettings } from "../../PinnedPanelsSettings";
import { RemoteComputerSection } from "../../RemoteComputerSection";
import { SettingRow, SettingsGroup, SettingsLinkRow, SettingsRows, Switch } from "../../SettingsPrimitives";
import { SkinPicker } from "../../SkinPicker";
import { TalkShortcutRow } from "../../TalkShortcutRow";
import { useSkinChoice, ThemeRow } from "../../ThemeRow";
import { WindowFrameRow } from "../../WindowFrameRow";
import { resolveSkin, SKINS } from "@/lib/skins";
import { versionLine } from "../settings-context";
import { useSettingsShell } from "../settings-shell";
import { PlaceBadge } from "../SettingsNav";
import { InertRow, useSwitchToComputer } from "../inert";
import { AdvancedPagePart, AdvancedSection } from "../AdvancedSection";
import { useOtherPlaces } from "../settings-context";

/** A row this page can't change because it lives on This computer: not on the app's own home page (main's home:page). */
const elsewhere = (bridge: unknown, ctx: { desktop: boolean; here: boolean; home: boolean; client: boolean }) => ctx.desktop && !ctx.client && !ctx.here && !ctx.home && !bridge;

export function AppPage() {
  const { ctx } = useSettingsShell();
  const dispatch = useStoreDispatch();
  const [about, setAbout] = useState(false);
  const desk = ctx.desktop && !ctx.client;
  const computer = useSwitchToComputer();
  const appVersionLine = versionLine(desktopAppVersion());
  return <>
    {ctx.desktop && (
      <SettingsGroup label={t("settings.updates.title")} block="updates">
        <SettingsRows>
          {window.ogb?.updater ? <UpdatesRow title={appVersionLine} />
            // On the app's own page with no updater (a package or store build), the version is live and says why
            // there is no button; only another place's page names This computer.
            : ctx.home || ctx.client ? <SettingRow title={appVersionLine} subtitle={t("settings.updates.fromPackage")}>{null}</SettingRow>
              : <InertRow title={appVersionLine} reason={t("settings.inert.checkFromHere", { place: computer.name })}
                control={<button type="button" className="ui-button" tabIndex={-1}>{t("settings.updates.check")}</button>} />}
        </SettingsRows>
      </SettingsGroup>
    )}
    {/* Simple keeps language and notifications here, since General is an Advanced page. */}
    {!ctx.advanced && (
      <SettingsGroup label={t("settings.app.languageNotifications")} block="typing">
        <SettingsRows selectWidth={208}>
          <LanguageRow simple />
          <NotificationRows simple />
        </SettingsRows>
      </SettingsGroup>
    )}
    {/* Your computers, in Simple too: where a server is added, and where "Let its bots use this computer" is switched. */}
    {ctx.desktop && (window.ogb?.environments
      ? <ConnectedWorkspacesSettings label={t("settings.app.computers")} description={t("settings.app.computersLine")} />
      : !ctx.client && <PlacesFromHere />)}
    {ctx.desktop && ctx.advanced && <RemoteComputerSection hideWhenUnavailable legacyOnly />}
    <SettingsGroup label={t("sidebar.menu.helpShort")} block="help">
      <SettingsRows>
        <SettingsLinkRow title={t("sidebar.menu.help")} external onClick={() => void openExternalLink(HELP_CENTER_URL)} />
        {/* Simple keeps the Help card short: feedback, shortcuts and the tour are in the outer menu's Help too. */}
        {ctx.advanced && <SettingsLinkRow title={t("sidebar.menu.feedback")} external onClick={() => void openExternalLink(FEEDBACK_URL)} />}
        {ctx.advanced && <SettingsLinkRow title={t("sidebar.menu.shortcuts")} onClick={() => { dispatch({ type: "toggleAppSettings", open: false }); dispatch({ type: "toggleShortcuts", open: true }); }} />}
        {ctx.advanced && !ctx.client && <ReplayTourRow />}
        {desk && ctx.advanced && (window.ogb?.exportDiagnostics ? <DiagnosticsRow simple /> : <InertRow title={t("settings.app.diagnostics")}
          control={<button type="button" className="ui-button" tabIndex={-1}>{t("settings.diagnostics.export")}</button>} />)}
        <div data-settings-block="about" className="contents">
          <SettingsLinkRow title={t("settings.app.about", { app: productName() })} onClick={() => setAbout(true)} />
        </div>
      </SettingsRows>
    </SettingsGroup>
    <AboutDialog open={about} onClose={() => setAbout(false)} />
  </>;
}

/** A Cloud's page in the desktop window: the places list reads the rail through the workspaces bridge, which works on
 * every page; only the environments on this computer need This computer's own page. */
function PlacesFromHere() {
  const { place, ctx } = useSettingsShell();
  const others = useOtherPlaces("app");
  const workspaces = window.ogb?.workspaces;
  const lend = window.ogb?.lendComputer;
  const choose = lend?.choose;
  if (!workspaces) return null;
  return <>
    <SettingsGroup label={t("settings.app.computers")} description={t("settings.app.computersLine")} block="your-computers">
      <SettingsRows icons>
        <SettingRow title={place.name} leading={<PlaceBadge place={place} size={24} />} subtitle={t("servers.managed")}>
          <span className="text-[13px] leading-5 text-ink-secondary">{t("servers.current")}</span>
        </SettingRow>
        {/* On a server's own page: the same switch its row has on This computer's page. */}
        {lend && <LendComputerSwitch id={null} className="mx-4 mb-3 ms-[60px]" onChoose={choose && (() => void choose(null).catch(() => {}))} />}
        {others.map((other) => (
          <SettingRow key={other.key} title={other.name} leading={<PlaceBadge place={{ kind: other.kind === "computer" ? "computer" : "cloud", name: other.name, color: other.color }} size={24} />}
            subtitle={other.kind === "computer" ? t("servers.localHint") : undefined}>
            <button type="button" className="ui-button" data-place-switch={other.key} onClick={other.open}>{t("servers.switch")}</button>
          </SettingRow>
        ))}
        {workspaces.add && <SettingsLinkRow title={t("connect.otherTitle")} leading={<span className="flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary"><Plus size={18} aria-hidden="true" /></span>}
          onClick={() => void workspaces.add?.("address")} data={{ "data-server-connect": "" }} />}
      </SettingsRows>
    </SettingsGroup>
    {ctx.advanced && <SettingsGroup label={t("connectedWorkspaces.localTitle")} block="environments">
      <SettingsRows><InertRow title={t("connectedWorkspaces.newEnvironment")} /></SettingsRows>
    </SettingsGroup>}
  </>;
}

export function GeneralPage() {
  const { ctx, place, go } = useSettingsShell();
  return <>
    <AdvancedPagePart anchor="typing"><SettingsGroup label={t("settings.simple.group.typing")} block="typing">
      <SettingsRows selectWidth={208}>
        <LanguageRow simple />
        <SendKeyRow simple />
        <FollowUpRow simple />
        {window.ogb?.talkShortcut ? <TalkShortcutRow /> : elsewhere(window.ogb?.talkShortcut, ctx) && ctx.cloud ? <InertRow title={t("settings.search.talk")} control={<span className="text-[13px] leading-5 text-ink-secondary">{t("settings.general.talkOff")}</span>} /> : null}
      </SettingsRows>
    </SettingsGroup></AdvancedPagePart>
    <AdvancedPagePart anchor="notifications"><SettingsGroup label={t("notifications.title")} block="notifications"
      footnote={!ctx.client && <>{t("settings.general.awayEmails")}{" "}<button type="button" className="cursor-pointer text-accent-text hover:underline" onClick={() => go("bots", "about-you")}>{`${place.name} › ${t("settings.page.bots")}`}</button></>}>
      <SettingsRows><NotificationRows simple /></SettingsRows>
    </SettingsGroup></AdvancedPagePart>
    {ctx.desktop && !ctx.client && (
      <AdvancedPagePart anchor="startup"><SettingsGroup label={t("settings.general.startup")} block="startup">
        <SettingsRows>{window.ogb?.openAtLogin ? <OpenAtLoginRow simple /> : <InertRow title={t("settings.openAtLogin.title")} control={<Switch checked={false} tabIndex={-1} aria-label={t("settings.openAtLogin.title")} />} />}</SettingsRows>
      </SettingsGroup></AdvancedPagePart>
    )}
    <AdvancedPagePart anchor="privacy"><SettingsGroup label={t("settings.general.privacy")} block="privacy">
      <SettingsRows><AnalyticsRow simple /></SettingsRows>
    </SettingsGroup></AdvancedPagePart>
  </>;
}

function ThemePickerRow({ open, onToggle }: { open: boolean; onToggle: () => void }) {
  const choice = useSkinChoice();
  const current = SKINS.find((skin) => skin.id === resolveSkin(choice))?.name;
  return (
    <SettingRow title={t("settings.theme.title")} subtitle={choice === "system" ? t("settings.simple.themes.followHint") : current}>
      <button type="button" className="ui-button" aria-expanded={open} data-settings-themes="" onClick={onToggle}>{t(open ? "settings.appearance.hideThemes" : "settings.simple.themes.browse")}</button>
    </SettingRow>
  );
}

export function AppearancePage() {
  const { ctx, place, go, anchor } = useSettingsShell();
  const [themes, setThemes] = useState(anchor === "themes");
  return <>
    <SettingsGroup label={t("settings.appearance.look")} block="look">
      <SettingsRows>
        <ThemeRow simple />
        <ThemePickerRow open={themes} onToggle={() => setThemes((open) => !open)} />
        {themes && <div data-settings-block="themes" className="p-4"><SkinPicker /></div>}
        <ColorUserBubblesRow simple />
        {!ctx.client && <SettingsLinkRow title={t("placeLook.sidebarColor")} value={place.name} badge={<PlaceBadge place={place} size={14} />} onClick={() => go("overview", "sidebar")} data={{ "data-settings-door": "sidebar-color" }} />}
      </SettingsRows>
    </SettingsGroup>
    <CustomThemesSettings />
    <SettingsGroup label={t("settings.appearance.chat")} block="chat">
      <SettingsRows>
        {!ctx.client && <ToolCallsRow />}
        {ctx.advanced && <ChatWidthRow />}
        {ctx.advanced && <FontRow />}
        {ctx.advanced && <UsageIndicatorRow />}
      </SettingsRows>
    </SettingsGroup>
    {/* Simple keeps the Look card and Tool calls; the window's layout is Advanced. */}
    <AdvancedSection anchor="appearance"><SettingsGroup label={t("settings.appearance.layout")} block="appearance">
      <SettingsRows>
        <ChromeRailRow />
        <WindowFrameRow />
        <ShowThreadsRow />
        <SidebarToolsLayoutRow />
        <PinnedCirclesRow />
        <UniversalPinsRow />
      </SettingsRows>
    </SettingsGroup></AdvancedSection>
    {ctx.advanced && <PinnedPanelsSettings />}
  </>;
}