Skip to content

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

Add separate switches for routine and tool activity

Locksley Lennoxecf78b94cabf
diff --git a/src/components/ChatView.automation.test.ts b/src/components/ChatView.automation.test.ts
index bbfbb5a567..4a28b3a1be 100644
--- a/src/components/ChatView.automation.test.ts
+++ b/src/components/ChatView.automation.test.ts
@@ -80,23 +80,36 @@ describe("an automation's line in the chat", () => {
try {
await draw(transcript([
{ id: "routine", parentId: "m2", role: "bot", kind: "text", text: "No new calls.", at: at(3), automation: line("run-1") },
- { id: "approval", parentId: "routine", role: "bot", kind: "text", text: "Please confirm.", at: at(4), automation: line("run-2", { needsYou: true }) },
+ { id: "resolved-tool", parentId: "routine", role: "bot", kind: "options", at: at(4), automation: line("run-1", { copyOf: "tool-1" }), card: { title: "Tool call", subtitle: "Read fixture", options: ["Allow", "Deny"], requestId: "tool-1", tool: "Bash", answered: "allow" } },
+ { id: "pending-tool", parentId: "resolved-tool", role: "bot", kind: "options", at: at(5), automation: line("run-1", { copyOf: "tool-2", needsYou: true }), card: { title: "Pending tool call", subtitle: "Read fixture", options: ["Allow", "Deny"], requestId: "tool-2", tool: "Bash" } },
+ { id: "approval", parentId: "pending-tool", role: "bot", kind: "text", text: "Please confirm.", at: at(6), automation: line("run-2", { needsYou: true }) },
]));
const button = (name: string) => [...document.querySelectorAll("button")].find((item) => item.textContent?.trim() === name)!;
- flushSync(() => button(t("routines.logs")).click());
- flushSync(() => button(t("chat.automation.showInChat")).click());
+ flushSync(() => button(t("chat.automation.activity")).click());
+ flushSync(() => document.querySelector<HTMLButtonElement>('[role="switch"][aria-label="' + t("chat.automation.showInChat") + '"]')!.click());
expect(document.querySelector('[data-mid="routine"]')).toBeNull();
expect(document.querySelector('[data-mid="approval"]')?.textContent).toContain("Please confirm.");
expect(document.querySelector('[data-mid="m2"]')?.textContent).toContain("Here is the draft.");
expect(localStorage.getItem("omb-advanced-chat-automation")).toBe("hide");
+ const tools = document.querySelector<HTMLButtonElement>('[role="switch"][aria-label="' + t("chat.automation.showTools") + '"]')!;
+ expect(tools.getAttribute("aria-checked")).toBe("true");
+ expect(document.querySelector('[data-mid="resolved-tool"]')).not.toBeNull();
+ flushSync(() => tools.click());
+ expect(tools.getAttribute("aria-checked")).toBe("false");
+ expect(document.querySelector('[data-mid="resolved-tool"]')).toBeNull();
+ expect(document.querySelector('[data-mid="pending-tool"]')).not.toBeNull();
+ expect(document.querySelector('[data-mid="approval"]')?.textContent).toContain("Please confirm.");
+ flushSync(() => tools.click());
+
dispatch.mockClear();
flushSync(() => button(t("chat.automation.openLogs")).click());
expect(dispatch).toHaveBeenCalledWith({ type: "showRoutines", section: "logs", botId: "pepper" });
- flushSync(() => button(t("chat.automation.showInChat")).click());
+ flushSync(() => document.querySelector<HTMLButtonElement>('[role="switch"][aria-label="' + t("chat.automation.showInChat") + '"]')!.click());
expect(document.querySelector('[data-mid="routine"]')?.textContent).toContain("No new calls.");
} finally {
localStorage.removeItem("omb-advanced-mode");
localStorage.removeItem("omb-advanced-chat-automation");
+ localStorage.removeItem("omb-advanced-chat-tools");
}
});
diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx
index 15192a2948..cdbf7c3a38 100644
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@ -1,3 +1,4 @@
+import { Switch } from "./SettingsPrimitives";
import { createContext, memo, use, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type Dispatch, type ReactNode } from "react";
import { useAdvancedMode } from "@/lib/interface-mode";
import { PHONE_LAYOUT, useMediaQuery } from "@/lib/use-media-query";
@@ -795,6 +796,19 @@ const MessagesList = memo(function MessagesList({
const CHATHEAD_PILL = `flex min-w-0 items-center gap-2 rounded-full py-0.5 pl-1.5 text-ink ${ELEVATED_FLOAT}`;
+function useChatActivityVisibility(key: string) {
+ const [visible, setVisible] = useState(() => {
+ try { return localStorage.getItem(key) !== "hide"; }
+ catch { return true; }
+ });
+ const toggle = () => {
+ setVisible(!visible);
+ try { localStorage.setItem(key, visible ? "hide" : "show"); }
+ catch { /* Keep the preference for this visit. */ }
+ };
+ return [visible, toggle] as const;
+}
+
export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = false }: { bot: Bot; inForkPanel?: boolean }) {
const bot = useMemo(() => currentTaskBot(profile), [profile]);
const state = useStoreSelector((s) => ({ computerStart: s.computerStarts[profile.id], mascotMotion: s.mascotMotion?.botId === profile.id ? s.mascotMotion : null, instances: s.instances, config: s.config, focusMessage: s.focusMessage, forkPanelOpen: s.forkPanel !== null, settingsOpen: s.settingsOpen, computerOpen: s.computerOpen, error: s.error, notice: s.notice }), sameFields), dispatch = useStoreDispatch(), store = useStoreRef();
@@ -807,16 +821,8 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
const [pagePane, setPagePane] = useState<HTMLDivElement | null>(null);
const advanced = useAdvancedMode();
const [automationLogsOpen, setAutomationLogsOpen] = useState(false);
- const [showAutomationInChat, setShowAutomationInChat] = useState(() => {
- try { return localStorage.getItem("omb-advanced-chat-automation") !== "hide"; }
- catch { return true; }
- });
- const toggleAutomationInChat = () => {
- const next = !showAutomationInChat;
- setShowAutomationInChat(next);
- try { localStorage.setItem("omb-advanced-chat-automation", next ? "show" : "hide"); }
- catch { /* The preference still works for this visit. */ }
- };
+ const [showAutomationInChat, toggleAutomationInChat] = useChatActivityVisibility("omb-advanced-chat-automation");
+ const [showToolsInChat, toggleToolsInChat] = useChatActivityVisibility("omb-advanced-chat-tools");
useEffect(() => setAutomationLogsOpen(false), [bot.threadId]);
const phone = useMediaQuery(PHONE_LAYOUT);
const phoneMenu = phone && !remoteClient;
@@ -838,13 +844,17 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
const { messages: allMessages, activeLeafId } = bot;
const messages = useMemo(() => visibleMessages({ messages: allMessages, activeLeafId }), [allMessages, activeLeafId]);
const chatMessages = useMemo(() => {
- if (!advanced || showAutomationInChat) return messages;
+ if (!advanced || (showAutomationInChat && showToolsInChat)) return messages;
return messages.filter((message) => {
if (message.role !== "bot" || message.id === bot.pinnedMessageId) return true;
+ const approval = message.kind === "options" && message.card?.requestId && message.card.tool ? message.card : undefined;
+ if (approval && !approval.answered && !approval.dismissed && !approval.expired) return true;
+ if (approval && !showToolsInChat) return false;
+ if (showAutomationInChat) return true;
if (message.kind === "routine.run") return message.routineRun?.status === "waiting" || message.routineRun?.status === "failed";
return !message.automation || Boolean(message.automation.needsYou || message.automation.failed || message.automation.partial || message.automation.copyOf);
});
- }, [advanced, showAutomationInChat, messages, bot.pinnedMessageId]);
+ }, [advanced, showAutomationInChat, showToolsInChat, messages, bot.pinnedMessageId]);
const lookups = useMemo(() => transcriptLookups(allMessages, messages), [allMessages, messages]);
const liveTools = useLiveToolIds(messages, bot);
const recordedRun = useMemo(() => runSteps(messages, liveTools), [messages, liveTools]);
@@ -888,7 +898,7 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
const bots = useStoreSelector((s) => s.bots, sameDrawnBots);
const teammates = useTeammates(); const mentionPeers = useMemo(() => [...bots.filter((peer) => peer.id !== bot.id), ...teammates.peers], [bots, bot.id, teammates]);
const focus = state.focusMessage?.threadId === bot.threadId ? state.focusMessage : null;
- const showToolCalls = showToolCallsEnabled(state.config);
+ const showToolCalls = showToolCallsEnabled(state.config) && (!advanced || showToolsInChat);
const tts = state.config?.tts;
const localVoice = localSystemVoiceActive();
const locale = activeLocale();
@@ -1015,18 +1025,23 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
>
<div data-chathead-row className={cn("flex items-center justify-between", phone ? "gap-2" : "@max-[30rem]/chathead:flex-wrap @max-[30rem]/chathead:gap-y-1 @min-[30rem]/chathead:grid @min-[30rem]/chathead:grid-cols-[minmax(0,1fr)_minmax(0,auto)_minmax(max-content,1fr)]")}>
{advanced && !inForkPanel && (
- <section aria-label={t("routines.logs")} className="flex min-w-0 flex-wrap items-center gap-1.5" style={headerNoDragStyle}>
+ <section aria-label={t("chat.automation.activity")} className="flex min-w-0 flex-wrap items-center gap-1.5" style={headerNoDragStyle}>
<button
type="button"
aria-expanded={automationLogsOpen}
onClick={() => setAutomationLogsOpen((open) => !open)}
className="ui-pill shrink-0"
- ><List size={14} aria-hidden="true" />{t("routines.logs")}</button>
+ ><List size={14} aria-hidden="true" />{t("chat.automation.activity")}</button>
{automationLogsOpen && (
<section className="chat-run-log-actions flex min-w-0 flex-wrap items-center gap-1.5">
- <button type="button" className="ui-pill" aria-pressed={showAutomationInChat} onClick={toggleAutomationInChat}>
+ <label className="flex items-center gap-2 rounded-full px-2 py-1 text-xs text-ink-secondary">
{t("chat.automation.showInChat")}
- </button>
+ <Switch aria-label={t("chat.automation.showInChat")} checked={showAutomationInChat} onClick={toggleAutomationInChat} />
+ </label>
+ <label className="flex items-center gap-2 rounded-full px-2 py-1 text-xs text-ink-secondary">
+ {t("chat.automation.showTools")}
+ <Switch aria-label={t("chat.automation.showTools")} checked={showToolsInChat} onClick={toggleToolsInChat} />
+ </label>
<button type="button" className="ui-pill" onClick={() => dispatch({ type: "showRoutines", section: "logs", botId: bot.id })}>
{t("chat.automation.openLogs")}
</button>
diff --git a/src/locales/en.json b/src/locales/en.json
index d907a2fd80..9b0fc2ca8f 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2631,7 +2631,9 @@
"chat.peer.requested": "sent a request",
"chat.peer.viewExchange": "View exchange",
"chat.peer.exchangeTitle": "{peer} and {bot}",
- "chat.automation.showInChat": "Show routine updates in chat",
+ "chat.automation.activity": "Chat activity",
+ "chat.automation.showInChat": "Routine updates",
+ "chat.automation.showTools": "Tool activity",
"chat.automation.openLogs": "Open run history",
"chat.automation.openRun": "See run",
"chat.automation.openRunFor": "See the run behind this {name} message",