Skip to content

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

1.3 KB
Raw Blame
import { useRef, type ComponentProps } from "react";
import { useAdvancedMode } from "@/lib/interface-mode";
import { useOnScreen } from "@/lib/on-screen";
import { currentTaskBot, type Bot, type InstanceInfo } from "@/state/store";
import { useSidebarRecentMessages } from "./bot-panel/Conversations";
import { lastLine } from "./sidebar-preview";
import { SidebarThreadRow } from "./SidebarThreadRow";

type Props = ComponentProps<typeof SidebarThreadRow> & { bot: Bot; instances: InstanceInfo[]; generation: number };

/** Advanced mode: a thread row with a line of its latest message, read once the row is on screen. Simple mode keeps the
 * plain row and reads nothing. */
export function SidebarConversationRow({ bot, instances, generation, ...props }: Props) {
  return useAdvancedMode() ? <PreviewedThreadRow bot={bot} instances={instances} generation={generation} {...props} /> : <SidebarThreadRow {...props} />;
}

function PreviewedThreadRow({ bot, instances, generation, ...props }: Props) {
  const ref = useRef<HTMLDivElement>(null);
  const onScreen = useOnScreen(ref);
  const messages = useSidebarRecentMessages(bot, props.task, onScreen, generation);
  const preview = messages ? lastLine(currentTaskBot(bot, props.task.threadId), messages, instances, false) : undefined;
  return <div ref={ref}><SidebarThreadRow {...props} preview={preview} /></div>;
}