Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
import { SettingsFoldRow, SettingsRows } from "../SettingsPrimitives";
import { useEffect, useId, useRef, useState, type ReactNode } from "react";
import { ChevronRight, Search } from "lucide-react";
import { type ConfigStatus } from "@/state/store";
import { cn } from "@/lib/cn";
import { scrollParent, scrollWithin } from "@/lib/scroll-within";
import { t } from "@/lib/i18n";
import { LiveProviderSettings } from "../LiveProviderSettings";
import { VoiceEveryReplySetting } from "../VoiceEveryReplySetting";
import { VoicePlaybackRateSetting } from "../VoicePlaybackRateSetting";
import { VoiceHearingSetting } from "../VoiceHearingSetting";
import { BuiltInCustomHeaders } from "../OpenAiCompatCustomHeaders";
import { BuiltInReplyWait, LmStudioServer, OtherOpenAiCompatServers } from "../OpenAiCompatServers";
import { OllamaServer } from "../OllamaServer";
import { KEY_CATALOG, KEY_SECTIONS, keyHidden, keyMatches, savedState, type KeyEntry, type KeyId, type KeySectionId } from "./key-catalog";
import { finishKeyFocus, useKeyFocus, type KeyFocusRequest } from "./key-focus";
import { AnthropicEveryClaudeBot, OpenAiCompatUrl, OpenCodeProviderKeys, VoiceServerUrl } from "./KeyPanels";
import { VpsConnection } from "./VpsServersPanel";
import { KEY_CONTENT, KEY_ROW, KeyRow, MaskedKey, RowHeading, type KeyStatus } from "./KeyRow";
import { sameFields, useStoreDispatch, useStoreSelector } from "@/state/store-select";
const CARD = "rounded-xl bg-card in-data-[settings-look=simple]:rounded-[12px] in-data-[settings-look=simple]:border-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge) in-data-[settings-look=simple]:bg-menu";
const HIGHLIGHT_MS = 1600;
const PANELS: Partial<Record<KeyId, (visible: boolean) => ReactNode>> = {
opencodeProviders: () => <OpenCodeProviderKeys />,
ollama: (visible) => <OllamaServer visible={visible} />,
lmStudio: () => <LmStudioServer heading={false} />,
chatterbox: () => <VoiceServerUrl />,
vps: () => <VpsConnection />,
};
const EXTRAS: Partial<Record<KeyId, () => ReactNode>> = {
anthropic: () => <AnthropicEveryClaudeBot />,
openaiCompat: () => <><OpenAiCompatUrl /><BuiltInReplyWait /><BuiltInCustomHeaders /><OtherOpenAiCompatServers /></>,
liveKey: () => <LiveProviderSettings />,
};
function connected(entry: KeyEntry, config: ConfigStatus | null | undefined): boolean {
if (entry.kind === "uses") return false;
const saved = savedState(entry, config);
return saved.configured || saved.included === true;
}
function PanelRow({ entry, visible }: { entry: KeyEntry; visible: boolean }) {
const state = useStoreSelector((s) => ({ config: s.config }), sameFields);
const titleId = useId();
const saved = savedState(entry, state.config);
const status: KeyStatus = saved.configured ? { tone: "ok", text: t("keys.connected") } : null;
return (
<div data-key-row={entry.id} role="group" aria-labelledby={titleId} className={KEY_ROW}>
<RowHeading entry={entry} status={status} titleId={titleId} />
<div className={cn("flex flex-col gap-2", KEY_CONTENT)}>{PANELS[entry.id]?.(visible)}</div>
</div>
);
}
function ElsewhereRow({ entry }: { entry: KeyEntry }) {
const state = useStoreSelector((s) => ({ config: s.config }), sameFields), dispatch = useStoreDispatch();
const titleId = useId();
const opens = entry.opens;
const saved = savedState(entry, state.config);
const status: KeyStatus = saved.configured ? { tone: "ok", text: t("keys.connected") } : null;
return (
<div data-key-row={entry.id} role="group" aria-labelledby={titleId} className={KEY_ROW}>
<RowHeading entry={entry} status={status} titleId={titleId} />
<div className={cn("flex flex-col gap-2", KEY_CONTENT)}>
{saved.configured && <div className="flex"><MaskedKey saved={saved} label={t(entry.labelKey)} /></div>}
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
{entry.whereKey && <span className="min-w-0 flex-1 text-[12px] leading-4 text-ink-secondary">{t(entry.whereKey)}</span>}
{opens && (
<button type="button" data-key-open className="ui-button shrink-0" onClick={() => dispatch({ type: "toggleAppSettings", open: true, section: opens })}>
{t("keys.row.open")}
</button>
)}
</div>
</div>
</div>
);
}
export function KeyCatalogRow({ entry, visible }: { entry: KeyEntry; visible: boolean }) {
if (entry.kind === "uses" && entry.uses) return <KeyRow id={entry.uses} row={entry.id} />;
if (entry.kind === "panel") return <PanelRow entry={entry} visible={visible} />;
if (entry.kind === "elsewhere") return <ElsewhereRow entry={entry} />;
return <KeyRow id={entry.id}>{EXTRAS[entry.id]?.()}</KeyRow>;
}
function KeySection({ id, rows, open, onToggle }: { id: KeySectionId; rows: KeyEntry[]; open: boolean; onToggle: () => void }) {
const state = useStoreSelector((s) => ({ config: s.config }), sameFields);
const section = KEY_SECTIONS.find((candidate) => candidate.id === id)!;
const headId = useId();
const bodyId = useId();
const count = rows.filter((entry) => connected(entry, state.config)).length;
return (
<section data-keys-section={id} aria-labelledby={headId} className={CARD}>
<button
type="button"
aria-expanded={open}
aria-controls={bodyId}
onClick={onToggle}
className="flex w-full cursor-pointer items-center gap-3 rounded-[inherit] px-4 py-2.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus/60"
>
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
<span id={headId} className="text-[14px] font-medium leading-5 text-ink">{t(section.titleKey)}</span>
<span className="text-[13px] leading-[18px] text-ink-secondary">{t(section.purposeKey)}</span>
</span>
{count > 0 && <span className="shrink-0 text-[12px] leading-4 text-ink-secondary">{t("keys.section.connected", { count })}</span>}
<ChevronRight size={14} aria-hidden="true" className={cn("shrink-0 text-ink-secondary transition-transform motion-reduce:transition-none", open && "rotate-90")} />
</button>
<div id={bodyId} hidden={!open} className="flex flex-col gap-0.5 border-t border-hairline/40 px-1 py-1.5 in-data-[settings-look=simple]:border-t-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge)">
{rows.map((entry) => <KeyCatalogRow key={entry.id} entry={entry} visible={open} />)}
{id === "voice" && <VoicePlaybackRateSetting />}
{id === "voice" && <VoiceEveryReplySetting />}
{id === "voice" && <VoiceHearingSetting />}
</div>
</section>
);
}
function landOn(page: HTMLElement | null, request: KeyFocusRequest, section: KeySectionId): boolean {
const row = request.row ? page?.querySelector<HTMLElement>(`[data-key-row="${request.row}"]`) : page?.querySelector<HTMLElement>(`[data-keys-section="${section}"]`);
if (!row || row.closest("[hidden]")) return false;
const scroller = scrollParent(row);
if (scroller) scrollWithin(scroller, row, request.row ? "center" : "start", 16);
if (!request.row) return true;
row.querySelector<HTMLElement>("[data-key-input], [data-key-replace], [data-key-own], [data-key-open], input, button")?.focus({ preventScroll: true });
row.setAttribute("data-key-highlight", "");
window.setTimeout(() => row.removeAttribute("data-key-highlight"), HIGHLIGHT_MS);
return true;
}
/** `bare`: inside AI's Other services, every section is a fold row in one card; `exclude`: sections listed elsewhere
* (AI providers are AI's own Providers list), unless a search or a link asks for a key in one. */
export function KeysPage({ bare = false, exclude = [] }: { bare?: boolean; exclude?: KeySectionId[] } = {}) {
const state = useStoreSelector((s) => ({ config: s.config }), sameFields);
const [query, setQuery] = useState("");
const [open, setOpen] = useState<ReadonlySet<KeySectionId>>(() => new Set(
KEY_SECTIONS.filter((section) => section.id === "ai" || KEY_CATALOG.some((entry) => entry.section === section.id && connected(entry, state.config)))
.map((section) => section.id),
));
const pageRef = useRef<HTMLDivElement>(null);
const focus = useKeyFocus();
const q = query.trim().toLowerCase();
useEffect(() => {
if (!focus) return;
const section = KEY_CATALOG.find((entry) => entry.id === focus.row)?.section ?? "ai";
setQuery("");
setOpen((current) => current.has(section) ? current : new Set([...current, section]));
let frame = 0;
let tries = 0;
const attempt = () => {
if (landOn(pageRef.current, focus, section) || ++tries > 60) finishKeyFocus(focus);
else frame = window.requestAnimationFrame(attempt);
};
frame = window.requestAnimationFrame(attempt);
return () => window.cancelAnimationFrame(frame);
}, [focus]);
const rows = KEY_CATALOG.filter((entry) => keyMatches(entry, q, state.config) && !keyHidden(entry.id, state.config));
const asked = focus ? KEY_CATALOG.find((entry) => entry.id === focus.row)?.section : undefined;
const sections = KEY_SECTIONS.filter((section) => !exclude.includes(section.id) || section.id === asked).flatMap((section) => {
const own = rows.filter((entry) => entry.section === section.id);
return own.length > 0 ? [{ id: section.id, rows: own }] : [];
});
const toggle = (id: KeySectionId) => setOpen((current) => {
const next = new Set(current);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
if (bare) {
return (
<div ref={pageRef} data-keys-page="">
{/* The key rows inside lead with their provider's mark, so every row of this card keeps the 32 px slot column
(empty on the fold rows), and the card has one text edge and one divider inset (§6.5). */}
<SettingsRows icons>
{sections.map(({ id, rows: sectionRows }) => {
const section = KEY_SECTIONS.find((candidate) => candidate.id === id)!;
const count = sectionRows.filter((entry) => connected(entry, state.config)).length;
return (
<SettingsFoldRow key={id} id={`keys-${id}`} title={t(section.titleKey)} subtitle={t(section.purposeKey)} leading={<span aria-hidden="true" />}
value={count > 0 ? t("keys.section.connected", { count }) : undefined} open={open.has(id)} onToggle={() => toggle(id)}>
<div data-keys-section={id} className="flex flex-col gap-0.5 py-1.5">
{sectionRows.map((entry) => <KeyCatalogRow key={entry.id} entry={entry} visible={open.has(id)} />)}
{id === "voice" && <VoicePlaybackRateSetting />}
{id === "voice" && <VoiceEveryReplySetting />}
{id === "voice" && <VoiceHearingSetting />}
</div>
</SettingsFoldRow>
);
})}
</SettingsRows>
</div>
);
}
return (
<div ref={pageRef} data-keys-page className="flex flex-col gap-4">
<p className="text-[13px] leading-[18px] text-ink-secondary">{t("settings.connections.subtitle")}</p>
<div className="flex h-8 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] focus-within:ring-2 focus-within:ring-focus/60">
<Search size={15} aria-hidden="true" className="shrink-0 text-ink-secondary" />
<input
data-keys-search
type="text"
value={query}
onChange={(event) => setQuery(event.target.value)}
onKeyDown={(event) => {
if (event.key !== "Escape" || !query) return;
event.preventDefault();
event.stopPropagation();
setQuery("");
}}
placeholder={t("keys.search.placeholder")}
aria-label={t("keys.search.aria")}
autoComplete="off"
spellCheck={false}
className="w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"
/>
</div>
{sections.length === 0 ? (
<p data-keys-empty className="px-1 text-[13px] leading-[18px] text-ink-secondary">{t("keys.search.none", { query: query.trim() })}</p>
) : sections.map(({ id, rows: sectionRows }) => (
<KeySection
key={id}
id={id}
rows={sectionRows}
open={q !== "" || open.has(id)}
onToggle={() => setOpen((current) => {
const next = new Set(current);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
})}
/>
))}
</div>
);
}