Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Open a folded earlier answer on any jump to it, and let Show less fold it
AdityaUmale31578735d17f
diff --git a/src/components/ChatView.check-rounds.test.ts b/src/components/ChatView.check-rounds.test.tsindex 881a4d41f6..d103ebfe2d 100644--- a/src/components/ChatView.check-rounds.test.ts+++ b/src/components/ChatView.check-rounds.test.ts@@ -72,4 +72,30 @@ describe("Check before done rounds in the chat", () => {vi.unstubAllGlobals();}});++ it.each([+ ["a citation jump", undefined],+ ["a search hit", "dusk"],+ ])("opens a folded answer for %s, and Show less folds it again", (_name, matchText) => {+ vi.stubGlobal("fetch", () => new Promise(() => {}));+ const container = document.createElement("div");+ document.body.append(container);+ const root = createRoot(container);+ const focused: AppState = { ...state, focusMessage: { threadId: "pepper-thread", messageId: "first", ...(matchText ? { matchText } : {}), nonce: 1, consumed: false } };+ const value = { state: focused, dispatch: vi.fn(), flushBotPatches: async () => null, refreshInstances: async () => {}, refreshModels: async () => {} };+ try {+ flushSync(() => root.render(createElement(BotEditorStore, { value, children: createElement(ChatView, { bot }) })));+ const folded = () => container.querySelector<HTMLButtonElement>("[data-testid=earlier-answer]");+ expect(folded()).toBeNull();+ const opened = container.querySelector(`[data-citation-source="first"]`)?.closest("[data-look=message-bot]");+ expect(opened?.textContent).toContain("First summary, it says dusk.");+ const less = [...opened!.querySelectorAll("button")].find((button) => button.textContent === t("chat.showLess"));+ flushSync(() => less!.click());+ expect(folded()).not.toBeNull();+ } finally {+ root.unmount();+ container.remove();+ vi.unstubAllGlobals();+ }+ });});diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsxindex 94ba15385b..1d09c3545e 100644--- a/src/components/ChatView.tsx+++ b/src/components/ChatView.tsx@@ -307,7 +307,7 @@ const Bubble = memo(function Bubble({const speaker = user ? otherSpeaker(message, speakerViewer ?? null) : null;const ownBubbleStyle = speaker ? undefined : bubbleStyle;const [expanded, setExpanded] = useState(false), [folded, setFolded] = useState(false);- const focusedSearch = focus?.messageId === message.id && Boolean(focus.matchText);+ const focusedHere = focus?.messageId === message.id, focusedSearch = focusedHere && Boolean(focus.matchText);const [viewRaw, setViewRaw] = useState(false);const speech = useSpeech();const speaking = speech.messageId === message.id && speech.status !== "idle";@@ -361,8 +361,8 @@ const Bubble = memo(function Bubble({user && !webhookView && !expanded && (visibleText.length > USER_COLLAPSE_CHARS || visibleText.split("\n").length > USER_COLLAPSE_LINES);useEffect(() => {setFolded(false);- if (focusedSearch && (collapsible || peer)) setExpanded(true);- }, [focusedSearch, collapsible, Boolean(peer), focus?.nonce]);+ if ((focusedSearch && (collapsible || peer)) || (focusedHere && earlierRound !== undefined)) setExpanded(true);+ }, [focusedSearch, focusedHere, collapsible, Boolean(peer), earlierRound, focus?.nonce]);if (user && editing && !webhookView && !hasAttachments) {return (@@ -374,7 +374,7 @@ const Bubble = memo(function Bubble({// A long request from another bot is one line until opened.const peerLong = peer ? peerPreview(text) : null;- if (peer && peerLong && !expanded && (!focusedSearch || folded)) return <div {...{ [MESSAGE_ROW]: "" }} className="group flex w-full flex-col items-start"><PeerLabel peer={peer} bots={bots} /><PeerCompactRow preview={peerLong} onOpen={() => setExpanded(true)} /></div>; if (earlierRound && !expanded && !focusedSearch) return <div {...{ [MESSAGE_ROW]: "" }} className="group flex w-full flex-col items-start"><PeerCompactRow label={t("chat.checkWork.earlierAnswer", { round: earlierRound })} preview={flatPreview(text)} testId="earlier-answer" onOpen={() => setExpanded(true)} /></div>;+ if (peer && peerLong && !expanded && (!focusedSearch || folded)) return <div {...{ [MESSAGE_ROW]: "" }} className="group flex w-full flex-col items-start"><PeerLabel peer={peer} bots={bots} /><PeerCompactRow preview={peerLong} onOpen={() => setExpanded(true)} /></div>; if (earlierRound && !expanded) return <div {...{ [MESSAGE_ROW]: "" }} className="group flex w-full flex-col items-start"><PeerCompactRow label={t("chat.checkWork.earlierAnswer", { round: earlierRound })} preview={flatPreview(text)} testId="earlier-answer" onOpen={() => setExpanded(true)} /></div>;const forks = user && versions ? versions : [message];const versionIndex = forks.findIndex((v) => v.id === message.id);const switchTo = (v: Message | undefined) => {