Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
import { GitFork } from "lucide-react";
import { useMemo, type Dispatch } from "react";
import { ACTION_ICON, type MessageMenuItem } from "./MessageActions";
import { t } from "@/lib/i18n";
import type { Action, AppState } from "@/state/store";
import { sameItems, useStoreDispatch, useStoreSelector } from "@/state/store-select";
type Owner = { kind: "bot" | "group"; ownerId: string; threadId: string; messageId: string };
export function forkMessageItem(owner: Owner, dispatch: Dispatch<Action>, disabled: boolean): MessageMenuItem {
return {
key: "fork-conversation",
icon: <GitFork {...ACTION_ICON} />,
label: t("chat.forkConversation"),
disabled,
onSelect: () => dispatch({ type: "forkMessage", ...owner }),
};
}
const NO_FORKS: never[] = [];
/** A null message: forks from any message of the thread. */
function forksOf(state: AppState, owner: Omit<Owner, "messageId"> & { messageId: string | null }) {
const tasks = owner.kind === "bot"
? state.bots?.find((bot) => bot.id === owner.ownerId)?.tasks
: state.groups?.find((group) => group.id === owner.ownerId)?.tasks;
return tasks?.filter((task) => task.origin?.threadId === owner.threadId && (owner.messageId === null || task.origin.messageId === owner.messageId)) ?? NO_FORKS;
}
/** The messages of a thread that conversations were forked from: one read for the whole transcript. */
export function useForkedMessages(kind: Owner["kind"], ownerId: string, threadId: string): ReadonlySet<string> {
const ids = useStoreSelector((state) => forksOf(state, { kind, ownerId, threadId, messageId: null }).map((task) => task.origin!.messageId), sameItems);
return useMemo(() => new Set(ids), [ids]);
}
export function ForkLinks(owner: Owner & { phone: boolean }) {
const dispatch = useStoreDispatch();
const forks = useStoreSelector((state) => forksOf(state, owner), sameItems);
if (owner.phone || !forks.length) return null;
return (
<div className="mt-1 flex flex-wrap gap-1" data-testid="fork-links">
{forks.map((fork) => (
<button key={fork.threadId} type="button"
className="rounded-full border border-hairline px-2 py-0.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink"
onClick={() => dispatch({ type: "openForkPanel", kind: owner.kind, ownerId: owner.ownerId, threadId: fork.threadId })}>
<GitFork size={12} className="mr-1 inline" />{t("chat.openFork", { title: fork.title })}
</button>
))}
</div>
);
}