Skip to content

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

Bot panel: Routines is a row under Working folder on Details

luishron12370aae81384fb
diff --git a/src/components/BotSettingsDialog.simple.test.ts b/src/components/BotSettingsDialog.simple.test.ts
index fedd84f0ad..785cbc7220 100644
--- a/src/components/BotSettingsDialog.simple.test.ts
+++ b/src/components/BotSettingsDialog.simple.test.ts
@@ -208,7 +208,7 @@ const botTab = (bot: Bot) => capture(() => DetailsTab({ bot, derived: derived(),
const settingsPage = (bot: Bot, editingInstructions = false) =>
capture(() => SettingsPage({ bot, derived: derived(), onOpen, editingInstructions, onEditInstructions }));
const library = (bot: Bot) => capture(() => LibraryTab({ bot }));
-const keeps = (bot: Bot) => capture(() => BotKeeps({ bot, onOpen }));
+const keeps = (bot: Bot) => capture(() => BotKeeps({ bot, routines: fixture.derived.botRoutines as Routine[], onOpen }));
const computer = (bot: Bot) => capture(() => ComputerTab({ bot, derived: derived(), onOpen }));
const find = (rendered: { nodes: Node[] }, attr: string, value: unknown = true) => {
const found = rendered.nodes.find((node) => node.props[attr] === value);
@@ -666,11 +666,11 @@ describe("the avatar editor", () => {
describe("the Details tab", () => {
- it("holds the model, what the bot keeps, the conversations, this conversation's rows and routines, in that order, with no switch or Thinking row", () => {
+ it("holds the model, what the bot keeps with its routines, the conversations and this conversation's rows, in that order, with no switch or Thinking row", () => {
const rendered = botTab(makeBot());
expect(ofType(rendered, ModelPicker)!.props).toMatchObject({ bot: expect.objectContaining({ id: "scout" }), threadId: "thread-scout", contained: true });
expect(ofType(rendered, BotConversations)!.props.bot).toMatchObject({ id: "scout" });
- const order = ['data-panel-row="model"', 'data-panel-page="memory"', 'data-panel-page="skills"', 'data-panel-page="folder"', 'data-panel-card="conversations"', 'data-panel-item="find"', 'data-panel-item="activity"', 'data-panel-empty="routines"']
+ const order = ['data-panel-row="model"', 'data-panel-page="memory"', 'data-panel-page="skills"', 'data-panel-page="folder"', 'data-panel-page="routines"', 'data-panel-card="conversations"', 'data-panel-item="find"', 'data-panel-item="activity"']
.map((marker) => rendered.html.indexOf(marker));
expect(order.every((index) => index > -1)).toBe(true);
expect([...order].sort((a, b) => a - b)).toEqual(order);
@@ -786,30 +786,26 @@ describe("the Details tab", () => {
});
});
- it("offers Add a routine, which says what routines are, and Automations while the bot has none, and lists them once it has some", () => {
- const empty = botTab(makeBot());
- expect(empty.html).toContain('data-panel-empty="routines"');
- expect(empty.html).toContain('title="Jobs this bot runs on a schedule, like a news roundup every morning."');
- expect(empty.html).toMatch(/data-panel-automations=""[^>]*>Automations<svg/);
+ it("keeps Routines a row under Working folder while the bot has none, which says what routines are and opens the page to add one", () => {
+ const empty = keeps(makeBot());
expect(empty.html.match(/data-panel-page="routines"/g)).toHaveLength(1);
- const add = find(empty, "data-panel-page", "routines");
- expect(empty.html).toMatch(/data-panel-page="routines"[^>]*>.*<span class="truncate">Add a routine<\/span><\/button>/);
- click(add);
+ for (const gone of ['data-panel-empty="routines"', "data-panel-automations", "Add a routine"]) expect(empty.html, gone).not.toContain(gone);
+ expect(empty.html).toMatch(/data-panel-page="routines" title="Jobs this bot runs on a schedule, like a news roundup every morning."/);
+ expect(rowValue(empty, "routines")).toBe("None");
+ click(find(empty, "data-panel-page", "routines"));
expect(onOpen).toHaveBeenLastCalledWith("routines");
fixture.derived.botRoutines = [routine()];
- const some = botTab(makeBot());
- expect(some.html).not.toContain('data-panel-empty="routines"');
- expect(some.html.indexOf('data-panel-card="conversations"')).toBeLessThan(some.html.indexOf('data-panel-page="routines"'));
+ expect(keeps(makeBot()).html).not.toContain('title="Jobs this bot runs');
});
it("values Routines by how many are on, and opens the routines page", () => {
fixture.derived.botRoutines = [routine(), routine({ id: "r2", enabled: false }), routine({ id: "r3" })];
- const rendered = botTab(makeBot());
+ const rendered = keeps(makeBot());
expect(rowValue(rendered, "routines")).toBe("2 on");
click(find(rendered, "data-panel-page", "routines"));
expect(onOpen).toHaveBeenLastCalledWith("routines");
fixture.derived.botRoutines = [routine({ enabled: false })];
- expect(rowValue(botTab(makeBot()), "routines")).toBe("None");
+ expect(rowValue(keeps(makeBot()), "routines")).toBe("None");
});
it("lists Find, Activity and the Inspector for this conversation as rows that run them, leaving Copy and Download to Share", () => {
diff --git a/src/components/bot-panel/DetailsTab.tsx b/src/components/bot-panel/DetailsTab.tsx
index 65af02411f..8cc47d39ae 100644
--- a/src/components/bot-panel/DetailsTab.tsx
+++ b/src/components/bot-panel/DetailsTab.tsx
@@ -1,4 +1,4 @@
-import { Calendar, CalendarPlus, ChevronRight, Sparkles } from "lucide-react";
+import { ChevronRight, Sparkles } from "lucide-react";
import { cn } from "@/lib/cn";
import { t } from "@/lib/i18n";
@@ -10,8 +10,8 @@ import type { useBotSettingsDerived } from "../bot-settings/useBotSettingsDerive
import { BotConversations } from "./Conversations";
import { BotKeeps } from "./Keeps";
import type { SimplePageId } from "./page-registry";
-import { Card, CardLabel, LabelAction, panelActionCls, NavRow, RowIcon, rowCls, RowText } from "./rows";
-import { useStoreDispatch, useStoreSelector } from "@/state/store-select";
+import { CardLabel, RowIcon, rowCls, RowText } from "./rows";
+import { useStoreSelector } from "@/state/store-select";
import { newChatBot } from "@/state/new-chat";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { approvalModeFor, modelSwitchNeedsAsk } from "../../../shared/approval-mode";
@@ -50,7 +50,6 @@ export function DetailsTab({ bot, derived, onOpen }: {
onOpen: (page: SimplePageId) => void;
}) {
const { items } = useChatMoreItems(bot);
- const dispatch = useStoreDispatch();
// While a blank chat is open the chat shows it, not the conversation it covers: the Model and Reasoning rows show and
// set the blank chat's choices, which the first send applies to the conversation it makes.
const newChat = useStoreSelector((state) => state.newChat);
@@ -63,7 +62,6 @@ export function DetailsTab({ bot, derived, onOpen }: {
const driverOf = (instanceId: string) => instances.find((instance) => instance.instanceId === instanceId)?.driverKind;
const reasoningSetsDefault = ownerOrAdmin === true
&& !modelSwitchNeedsAsk(approvalModeFor(bot), driverOf(bot.modelSelection.instanceId), driverOf(thread.modelSelection.instanceId));
- const routinesOn = derived.botRoutines.filter((routine) => routine.enabled).length;
const conversationItems = CONVERSATION_ITEMS.flatMap((key) => items.filter((item) => item.key === key));
return (
@@ -90,7 +88,7 @@ export function DetailsTab({ bot, derived, onOpen }: {
/>
</section>
- <BotKeeps bot={bot} onOpen={onOpen} />
+ <BotKeeps bot={bot} routines={derived.botRoutines} onOpen={onOpen} />
<BotConversations bot={bot} />
@@ -100,34 +98,6 @@ export function DetailsTab({ bot, derived, onOpen }: {
{conversationItems.map((item) => <ItemRow key={item.key} item={item} />)}
</section>
)}
-
- {derived.botRoutines.length === 0 ? (
- <section data-panel-empty="routines">
- <CardLabel action={<LabelAction data-panel-automations="" onClick={() => dispatch({ type: "showRoutines", view: "list" })}>{t("sidebar.nav.automations")}</LabelAction>}>
- {t("botSettings.simple.routines")}
- </CardLabel>
- <button
- type="button"
- data-panel-page="routines"
- title={t("botPanel.routines.emptyHint")}
- onClick={() => onOpen("routines")}
- className={cn(panelActionCls, "w-full")}
- >
- <CalendarPlus size={15} aria-hidden="true" className="shrink-0 text-ink-secondary" />
- <span className="truncate">{t("botPanel.routines.add")}</span>
- </button>
- </section>
- ) : (
- <Card label={t("botSettings.simple.routines")} anchor="routines">
- <NavRow
- data-panel-page="routines"
- icon={Calendar}
- title={t("botSettings.simple.routines")}
- value={routinesOn > 0 ? t("botPanel.routinesOn", { count: routinesOn }) : t("botPanel.none")}
- onClick={() => onOpen("routines")}
- />
- </Card>
- )}
</div>
);
}
diff --git a/src/components/bot-panel/Keeps.dom.test.ts b/src/components/bot-panel/Keeps.dom.test.ts
index 62aaf61325..e5f82553de 100644
--- a/src/components/bot-panel/Keeps.dom.test.ts
+++ b/src/components/bot-panel/Keeps.dom.test.ts
@@ -3,6 +3,7 @@ import { act, createElement } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
+import type { Routine } from "@/lib/routines";
import type { Bot } from "@/state/store";
const fixture = vi.hoisted(() => ({ skills: [] as unknown[], skillBurger: true }));
@@ -33,17 +34,25 @@ afterEach(() => {
host.remove();
});
-const render = async (onOpen: (page: string) => void = () => {}) => {
- await act(async () => root.render(createElement(BotKeeps, { bot, onOpen })));
+const render = async (onOpen: (page: string) => void = () => {}, routines: Routine[] = []) => {
+ await act(async () => root.render(createElement(BotKeeps, { bot, routines, onOpen })));
};
-it("lists what it remembers, its skills and its folder, and each opens its page", async () => {
+it("lists what it remembers, its skills, its folder and its routines, and each opens its page", async () => {
const opened: string[] = [];
await render((page) => opened.push(page));
const rows = [...host.querySelectorAll<HTMLButtonElement>("[data-panel-page]")];
- expect(rows.map((row) => row.dataset.panelPage)).toEqual(["memory", "skills", "folder"]);
+ expect(rows.map((row) => row.dataset.panelPage)).toEqual(["memory", "skills", "folder", "routines"]);
for (const row of rows) await act(async () => row.click());
- expect(opened).toEqual(["memory", "skills", "folder"]);
+ expect(opened).toEqual(["memory", "skills", "folder", "routines"]);
+});
+
+it("values Routines by how many are on", async () => {
+ const routine = (id: string, enabled: boolean) => ({ id, botId: "scout", enabled }) as Routine;
+ await render(undefined, [routine("a", true), routine("b", false), routine("c", true)]);
+ expect(host.querySelector('[data-panel-page="routines"]')!.textContent).toContain("2 on");
+ await render(undefined, [routine("b", false)]);
+ expect(host.querySelector('[data-panel-page="routines"]')!.textContent).toContain("None");
});
it("counts a saved Skill Burger among the bot's skills only while Skill Burger is on", async () => {
diff --git a/src/components/bot-panel/Keeps.tsx b/src/components/bot-panel/Keeps.tsx
index e677d51390..06d295333e 100644
--- a/src/components/bot-panel/Keeps.tsx
+++ b/src/components/bot-panel/Keeps.tsx
@@ -1,7 +1,8 @@
-import { Brain, Folder, Zap } from "lucide-react";
+import { Brain, Calendar, Folder, Zap } from "lucide-react";
import { t } from "@/lib/i18n";
import { useFeature } from "@/lib/use-feature";
+import type { Routine } from "@/lib/routines";
import { shortPath } from "@/lib/short-path";
import type { Bot } from "@/state/store";
import { isBurgerSource } from "../../../shared/skill-burger/saved";
@@ -12,13 +13,14 @@ import type { SimplePageId } from "./page-registry";
import { NavRow } from "./rows";
import { useMemoryDoc } from "./use-memory-doc";
-/** What the bot keeps: its memory, its skills and its working folder, each a row that opens its page. */
-export function BotKeeps({ bot, onOpen }: { bot: Bot; onOpen: (page: SimplePageId) => void }) {
+/** What the bot keeps: its memory, its skills, its working folder and its routines, each a row that opens its page. */
+export function BotKeeps({ bot, routines, onOpen }: { bot: Bot; routines: readonly Routine[]; onOpen: (page: SimplePageId) => void }) {
const { capabilities } = useDesktopCapabilities();
const skills = useManagedSkills(bot), skillBurger = useFeature("skillBurger");
const memory = useMemoryDoc(bot);
const skillsOn = skills.skills.filter((skill) => skillSwitchOn(skill) && (skillBurger || !isBurgerSource(skill.source))).length;
const remembers = memory.docs ? panelMemoryNotes(memory.docs).length > 0 || Boolean(memory.thread?.text.trim()) : null;
+ const routinesOn = routines.filter((routine) => routine.enabled).length;
const memoryValue = bot.memoryEnabled === false ? t("botPanel.memory.off")
: remembers === false || (remembers === null && memory.error) ? t("botPanel.memory.nothingYet") : undefined;
return (
@@ -38,6 +40,14 @@ export function BotKeeps({ bot, onOpen }: { bot: Bot; onOpen: (page: SimplePageI
value={bot.cwd ? shortPath(bot.cwd, capabilities.host?.homeDir) : t("botPanel.folder.private")}
onClick={() => onOpen("folder")}
/>
+ <NavRow
+ data-panel-page="routines"
+ icon={Calendar}
+ title={t("botSettings.simple.routines")}
+ tooltip={routines.length === 0 ? t("botPanel.routines.emptyHint") : undefined}
+ value={routinesOn > 0 ? t("botPanel.routinesOn", { count: routinesOn }) : t("botPanel.none")}
+ onClick={() => onOpen("routines")}
+ />
</section>
);
}
diff --git a/src/components/bot-panel/MemoryPage.team.test.ts b/src/components/bot-panel/MemoryPage.team.test.ts
index 82289047c7..1b2f0ecec1 100644
--- a/src/components/bot-panel/MemoryPage.team.test.ts
+++ b/src/components/bot-panel/MemoryPage.team.test.ts
@@ -85,12 +85,12 @@ it("on a Team Cloud shows the person's own notes, topics included, as text they
});
it("shows no count on the Details tab, only whether it remembers anything", async () => {
- await act(async () => root.render(createElement(BotKeeps, { bot, onOpen: () => {} })));
+ await act(async () => root.render(createElement(BotKeeps, { bot, routines: [], onOpen: () => {} })));
await settle();
expect(host.querySelector('[data-panel-page="memory"]')?.textContent).toBe("What it remembers");
files["memory/food.md"] = "";
files["MEMORY.md"] = "";
- await act(async () => root.render(createElement(BotKeeps, { bot: { ...bot, threadId: "t2" }, onOpen: () => {} })));
+ await act(async () => root.render(createElement(BotKeeps, { bot: { ...bot, threadId: "t2" }, routines: [], onOpen: () => {} })));
await settle();
expect(host.querySelector('[data-panel-page="memory"]')?.textContent).toContain("Nothing yet");
});
diff --git a/src/components/bot-panel/rows.tsx b/src/components/bot-panel/rows.tsx
index a39bca5e05..7416f8cec4 100644
--- a/src/components/bot-panel/rows.tsx
+++ b/src/components/bot-panel/rows.tsx
@@ -13,7 +13,7 @@ const titleCls = "text-[14px] font-medium text-ink";
const hintCls = "mt-px text-[13px] leading-[1.35] text-ink-secondary";
export const buttonCls =
"inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-[8px] bg-control px-3.5 text-[13px] font-medium text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50";
-/** The panel's action rows, New conversation and Add a routine: flat like every other row, so the only fill in the
+/** The panel's action row, New conversation: flat like every other row, so the only fill in the
* tab is the conversation you are in. */
export const panelActionCls = "flex h-9 min-w-0 items-center gap-2.5 rounded-[8px] [&>svg]:size-4 px-3.5 text-[14px] font-medium text-ink transition-colors hover:bg-ink/[0.04]";
export const chipCls = (on: boolean) =>
@@ -31,7 +31,7 @@ export function CardLabel({ children, action }: { children: ReactNode; action?:
);
}
-export function LabelAction({ children, onClick, ...rest }: { children: ReactNode; onClick: () => void; "aria-label"?: string; "data-panel-action"?: string; "data-panel-automations"?: string }) {
+export function LabelAction({ children, onClick, ...rest }: { children: ReactNode; onClick: () => void; "aria-label"?: string; "data-panel-action"?: string }) {
return (
<button type="button" {...rest} onClick={onClick} className="inline-flex shrink-0 items-center gap-0.5 rounded-[6px] px-1 py-px text-[13px] font-normal text-ink-secondary hover:bg-ink/[0.04] hover:text-ink">
{children}