Skip to content

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

feat(automations): filter list and calendar by department

Renato Ramos725fdc9e98a8
diff --git a/src/components/TriggersPage.tsx b/src/components/TriggersPage.tsx
index 2ac5eb376e..e5ad4c4bdf 100644
--- a/src/components/TriggersPage.tsx
+++ b/src/components/TriggersPage.tsx
@@ -7,6 +7,7 @@ import { cn } from "@/lib/cn";
import { t } from "@/lib/i18n";
import { isRoutineProblemRun } from "@/lib/routines";
import { saveWebhookCredential, webhookCredentialStore } from "@/lib/webhook-credentials";
+import { botInDepartment, filterableDepartments, GENERAL_DEPARTMENT } from "@/lib/department-filter";
import { useStore } from "@/state/store";
import { useAppTriggers } from "@/lib/app-triggers";
import { AppEventEditor } from "./automations/AppEventEditor";
@@ -35,6 +36,7 @@ export function TriggersPage({ onBack, onOpenRoom }: { onBack: () => void; onOpe
const view = focus?.view === "calendar" ? "calendar" : "list";
const [openId, setOpenId] = useState<string | null>(focus?.section !== "logs" ? focus?.routineId ?? null : null);
const [botFilter, setBotFilter] = useState(focus?.botId ?? "all");
+ const [department, setDepartment] = useState("all");
const [newText, setNewText] = useState<string | null>(null);
const [editing, setEditing] = useState<{ kind: SetUpKind; id?: string; botId?: string } | null>(null);
const routinesOnly = window.ogb?.remoteClient?.active === true;
@@ -50,8 +52,13 @@ export function TriggersPage({ onBack, onOpenRoom }: { onBack: () => void; onOpe
const all = useMemo(() => automationsFrom({ routines: state.routines, webhooks: routinesOnly ? [] : state.webhooks, appTriggers: appTriggers.triggers, runs: state.routineRuns, bots: state.bots }),
[state.routines, state.webhooks, appTriggers.triggers, state.routineRuns, state.bots, routinesOnly]);
+ const departments = filterableDepartments(state.bots, [...new Set([...(state.sections ?? []), ...state.bots.flatMap((bot) => bot.section ? [bot.section] : [])])]);
+ const showDepartments = departments.names.length > 0;
+ const activeDepartment = department === "all" || (department === GENERAL_DEPARTMENT ? departments.hasGeneral : departments.names.includes(department)) ? department : "all";
+ const inDepartment = (botId: string) => botInDepartment(state.bots.find((bot) => bot.id === botId), activeDepartment);
+ const departmentBots = visibleBots.filter((bot) => botInDepartment(bot, activeDepartment));
const showFilter = all.length >= FILTER_FROM && new Set(all.map((automation) => automation.botId)).size > 1;
- const listed = orderAutomations(all.filter((automation) => !showFilter || botFilter === "all" || automation.botId === botFilter));
+ const listed = orderAutomations(all.filter((automation) => inDepartment(automation.botId) && (!showFilter || botFilter === "all" || automation.botId === botFilter)));
const open = all.find((automation) => automation.id === openId) ?? null;
const sentenceOf = (automation: Automation) => automationSentence(automation, botName(automation.botId));
@@ -74,10 +81,17 @@ export function TriggersPage({ onBack, onOpenRoom }: { onBack: () => void; onOpe
<button type="button" ref={backButtonRef} onClick={onBack} aria-label={t("automations.back")} title={t("automations.back")} className="flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink" style={windowNoDragStyle}><ArrowLeft size={18} /></button>
<h1 data-tour="automations-page" className="mr-1 text-[18px] font-semibold tracking-tight text-ink">{t("automations.title")}</h1>
<div className="ml-auto flex items-center gap-3" style={windowNoDragStyle}>
+ {showDepartments && (
+ <Select size="sm" aria-label={t("automations.allDepartments")} value={activeDepartment} onChange={(event) => { setDepartment(event.target.value); setBotFilter("all"); }} className="max-w-[180px]">
+ <option value="all">{t("automations.allDepartments")}</option>
+ {departments.names.map((name) => <option key={name} value={name}>{name}</option>)}
+ {departments.hasGeneral && <option value={GENERAL_DEPARTMENT}>{t("automations.generalDepartment")}</option>}
+ </Select>
+ )}
{showFilter && view === "list" && (
<Select size="sm" aria-label={t("automations.allBots")} value={botFilter} onChange={(event) => setBotFilter(event.target.value)} className="max-w-[180px]">
<option value="all">{t("automations.allBots")}</option>
- {visibleBots.map((bot) => <option key={bot.id} value={bot.id}>{bot.name}</option>)}
+ {departmentBots.map((bot) => <option key={bot.id} value={bot.id}>{bot.name}</option>)}
</Select>
)}
<div role="group" aria-label={t("automations.view")} className="flex items-center rounded-lg border border-hairline/50 bg-panel p-0.5">
@@ -94,7 +108,7 @@ export function TriggersPage({ onBack, onOpenRoom }: { onBack: () => void; onOpe
</header>
<div className="relative flex min-h-0 flex-1">
- {view === "calendar" ? <AutomationsCalendar botFilter={botFilter} selectedAutomationId={openId} onOpenAutomation={setOpenId} onOpenRoom={onOpenRoom} /> : (
+ {view === "calendar" ? <AutomationsCalendar botFilter={botFilter} department={activeDepartment} selectedAutomationId={openId} onOpenAutomation={setOpenId} onOpenRoom={onOpenRoom} /> : (
<div className="min-h-0 flex-1 overflow-y-auto">
<div className="mx-auto w-full max-w-3xl p-4 sm:p-6">
<LimitWarnings botFilter={showFilter ? botFilter : "all"} />
diff --git a/src/components/automations/AutomationsCalendar.tsx b/src/components/automations/AutomationsCalendar.tsx
index b45c7a45c6..adb4080091 100644
--- a/src/components/automations/AutomationsCalendar.tsx
+++ b/src/components/automations/AutomationsCalendar.tsx
@@ -4,6 +4,7 @@ import { ChevronLeft, ChevronRight } from "lucide-react";
import { CalendarSidebar } from "@/components/routines/CalendarSidebar";
import type { CalendarCall } from "@/lib/calendar-calls";
import { cn } from "@/lib/cn";
+import { botInDepartment } from "@/lib/department-filter";
import { t } from "@/lib/i18n";
import { addDays, calendarRangeLabel, projectCalls, projectedRoutineItems, scheduleAt, startOfDay, startOfWeek } from "@/lib/routine-calendar";
import { resetMarkers, useEngineLimits, type ResetMarker } from "@/lib/limit-resets";
@@ -16,8 +17,9 @@ import type { ResetDrop } from "../routines/LimitResetMarkers";
/** The schedules (and scheduled calls) on a week or day grid. An automation opens the same panel as the list; a call
* keeps its own details. */
-export function AutomationsCalendar({ botFilter, selectedAutomationId, onOpenAutomation, onOpenRoom }: {
+export function AutomationsCalendar({ botFilter, department = "all", selectedAutomationId, onOpenAutomation, onOpenRoom }: {
botFilter: string;
+ department?: string;
selectedAutomationId?: string | null;
onOpenAutomation: (id: string) => void;
onOpenRoom: (id: string) => void;
@@ -50,10 +52,14 @@ export function AutomationsCalendar({ botFilter, selectedAutomationId, onOpenAut
const routineItems = projectedRoutineItems(routines, state.routineRuns.filter((run) => botIds.has(run.botId)), rangeStart, rangeEnd)
.map((item) => ({ ...item, kind: "routine" as const, needsYou: Boolean(item.routine && !item.run && needsYou.has(item.routine.id)) }));
const callItems = projectCalls(calls, rangeStart, rangeEnd).map((item) => ({ ...item, kind: "call" as const }));
+ const botOf = (id: string | undefined) => state.bots.find((bot) => bot.id === id);
return [...routineItems, ...callItems]
+ .filter((item) => item.kind === "call"
+ ? item.call.botIds.some((id) => botInDepartment(botOf(id), department))
+ : botInDepartment(botOf(item.routine?.botId ?? item.run?.botId), department))
.filter((item) => botFilter === "all" || (item.kind === "call" ? item.call.botIds.includes(botFilter) : (item.routine?.botId ?? item.run?.botId) === botFilter))
.sort((left, right) => left.at - right.at);
- }, [state.routines, state.routineRuns, state.bots, calls, rangeStart, rangeEnd, botFilter]);
+ }, [state.routines, state.routineRuns, state.bots, calls, rangeStart, rangeEnd, botFilter, department]);
const liveSelected = selected?.kind === "call"
? (() => { const call = calls.find((candidate) => candidate.id === selected.call.id); return call ? { ...selected, call } : null; })()
diff --git a/src/components/automations/automations.test.ts b/src/components/automations/automations.test.ts
index cf45fb2706..f87de6f914 100644
--- a/src/components/automations/automations.test.ts
+++ b/src/components/automations/automations.test.ts
@@ -244,6 +244,73 @@ describe("the Automations list switch", () => {
expect(container.querySelector('[data-automation="orphan"]')).toBeNull();
expect(container.querySelector('[data-automation="orphan-hook"]')).toBeNull();
});
+
+ describe("by department", () => {
+ const sectioned = [{ ...botA, section: "Social" }, { ...botB, section: "Dev" }, { ...botB, id: "bot-c", name: "Atlas", threadId: "thread-c" }] as unknown as Bot[];
+ const department = () => container.querySelector<HTMLSelectElement>('select[aria-label="All departments"]');
+ const pick = (value: string) => { department()!.value = value; department()!.dispatchEvent(new Event("change", { bubbles: true })); };
+
+ it("offers no department question when no bot sits in a department", () => {
+ fixture.state.routines = [routine];
+ mountPage();
+ expect(department()).toBeNull();
+ });
+
+ it("lists only the chosen department's automations, and the General ones for bots outside any", () => {
+ fixture.state.bots = sectioned;
+ fixture.state.sections = ["Dev", "Social"];
+ fixture.state.routines = [routine, { ...routine, id: "dev-routine", name: "Dev check", botId: "bot-b" }, { ...routine, id: "general-routine", name: "General check", botId: "bot-c" }];
+ fixture.state.webhooks = [];
+ mountPage();
+ expect([...department()!.options].map((option) => option.textContent)).toEqual(["All departments", "Dev", "Social", "General"]);
+ expect(["routine-1", "dev-routine", "general-routine"].every((id) => row(id))).toBe(true);
+ flushSync(() => pick("Dev"));
+ expect(row("dev-routine")).not.toBeNull();
+ expect(container.querySelector('[data-automation="routine-1"]')).toBeNull();
+ expect(container.querySelector('[data-automation="general-routine"]')).toBeNull();
+ flushSync(() => pick([...department()!.options].find((option) => option.textContent === "General")!.value));
+ expect(row("general-routine")).not.toBeNull();
+ expect(container.querySelector('[data-automation="dev-routine"]')).toBeNull();
+ });
+
+ it("falls back to everyone when the chosen department no longer holds a bot", () => {
+ fixture.state.bots = sectioned;
+ fixture.state.sections = ["Dev", "Social"];
+ fixture.state.routines = [routine, { ...routine, id: "dev-routine", name: "Dev check", botId: "bot-b" }, { ...routine, id: "general-routine", name: "General check", botId: "bot-c" }];
+ fixture.state.webhooks = [];
+ mountPage();
+ const rerender = () => flushSync(() => root!.render(createElement(TriggersPage, { onBack: vi.fn(), onOpenRoom: vi.fn() })));
+ flushSync(() => pick("Dev"));
+ expect(container.querySelector('[data-automation="routine-1"]')).toBeNull();
+ fixture.state.bots = sectioned.map((bot) => bot.id === "bot-b" ? { ...bot, section: "Social" } : bot);
+ rerender();
+ expect(department()!.value).toBe("all");
+ expect([...department()!.options].map((option) => option.textContent)).toEqual(["All departments", "Social", "General"]);
+ expect(["routine-1", "dev-routine", "general-routine"].every((id) => row(id))).toBe(true);
+ flushSync(() => pick([...department()!.options].find((option) => option.textContent === "General")!.value));
+ fixture.state.bots = sectioned.map((bot) => ({ ...bot, section: "Social" }));
+ rerender();
+ expect(department()!.value).toBe("all");
+ expect(row("general-routine")).not.toBeNull();
+ });
+
+ it("narrows the bot question to that department's bots and clears a bot picked before", () => {
+ fixture.state.bots = sectioned;
+ fixture.state.sections = ["Dev", "Social"];
+ fixture.state.webhooks = [];
+ fixture.state.routines = Array.from({ length: 9 }, (_, index) => ({ ...routine, id: `r-${index}`, name: `Check ${index}`, botId: index < 5 ? "bot-a" : "bot-b" }));
+ mountPage();
+ const bots = () => container.querySelector<HTMLSelectElement>('select[aria-label="All bots"]')!;
+ const change = (select: HTMLSelectElement, value: string) => { select.value = value; select.dispatchEvent(new Event("change", { bubbles: true })); };
+ expect([...bots().options].map((option) => option.textContent)).toEqual(["All bots", "Scout", "Ledger", "Atlas"]);
+ flushSync(() => change(bots(), "bot-a"));
+ expect(container.querySelectorAll("[data-automation]")).toHaveLength(5);
+ flushSync(() => pick("Dev"));
+ expect(bots().value).toBe("all");
+ expect([...bots().options].map((option) => option.textContent)).toEqual(["All bots", "Ledger"]);
+ expect(container.querySelectorAll("[data-automation]")).toHaveLength(4);
+ });
+ });
});
describe("More, for another app's automation", () => {
@@ -299,6 +366,46 @@ describe("the calendar", () => {
expect(dots("Morning summary").every((status) => status === "working")).toBe(true);
expect(container.querySelector('[data-event-card][aria-label^="Orphan check"]')).toBeNull();
});
+
+ it("shows only the chosen department's events", () => {
+ vi.useFakeTimers({ toFake: ["Date"] });
+ vi.setSystemTime(new Date(2026, 9, 14, 8, 0));
+ const at = new Date(2026, 9, 14, 17, 0).getTime();
+ const daily = (id: string, name: string, botId: string) => ({ id, name, prompt: `${name}.`, target: "bot", botId, runOn: "maus", enabled: true,
+ schedule: { type: "daily", time: "17:00", weekdays: [0, 1, 2, 3, 4, 5, 6] }, durationMinutes: 30, nextRunAt: at, createdAt: 0, updatedAt: 0 });
+ fixture.state.bots = [{ ...botA, section: "Social" }, { ...botB, section: "Dev" }] as unknown as Bot[];
+ fixture.state.routines = [daily("social", "Social post", "bot-a"), daily("dev", "Dev check", "bot-b")];
+ fixture.state.groups = [];
+ const cards = (department: string) => {
+ const container = mount(createElement(AutomationsCalendar, { botFilter: "all", department, onOpenAutomation: vi.fn(), onOpenRoom: vi.fn() }));
+ const count = (name: string) => container.querySelectorAll(`[data-event-card][aria-label^="${name}"]`).length;
+ const counts = { social: count("Social post"), dev: count("Dev check") };
+ root!.unmount();
+ container.remove();
+ return counts;
+ };
+ const everyone = cards("all");
+ expect(everyone.social).toBeGreaterThan(0);
+ expect(everyone.dev).toBeGreaterThan(0);
+ expect(cards("Dev")).toEqual({ social: 0, dev: everyone.dev });
+ expect(cards("Social")).toEqual({ social: everyone.social, dev: 0 });
+ });
+
+ it("keeps a call when any of its bots is in the chosen department", async () => {
+ vi.useFakeTimers({ toFake: ["Date"] });
+ vi.setSystemTime(new Date(2026, 9, 14, 8, 0));
+ const at = new Date(2026, 9, 14, 17, 0).getTime();
+ const call = (id: string, name: string, botIds: string[]) => ({ id, name, description: "", botIds, schedule: { type: "once", at }, durationMinutes: 30, attachments: [], nextRunAt: at, createdAt: 0, updatedAt: 0 });
+ fixture.state.bots = [{ ...botA, section: "Social" }, { ...botB, section: "Dev" }] as unknown as Bot[];
+ fixture.state.routines = [];
+ fixture.state.groups = [];
+ fixture.api.mockImplementation(async (path: unknown) => path === "/api/calendar-calls" ? { calls: [call("social", "Social sync", ["bot-a"]), call("dev", "Dev sync", ["bot-b"]), call("both", "All hands", ["bot-a", "bot-b"])] } : {});
+ const container = mount(createElement(AutomationsCalendar, { botFilter: "all", department: "Dev", onOpenAutomation: vi.fn(), onOpenRoom: vi.fn() }));
+ const shown = (name: string) => container.querySelectorAll(`[data-event-card][aria-label^="${name}"]`).length;
+ await vi.waitFor(() => expect(shown("Dev sync")).toBeGreaterThan(0));
+ expect(shown("All hands")).toBeGreaterThan(0);
+ expect(shown("Social sync")).toBe(0);
+ });
});
describe("the secret, under More", () => {
diff --git a/src/lib/department-filter.test.ts b/src/lib/department-filter.test.ts
new file mode 100644
index 0000000000..53597dedb2
--- /dev/null
+++ b/src/lib/department-filter.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from "vitest";
+import { botInDepartment, filterableDepartments, GENERAL_DEPARTMENT } from "./department-filter";
+import type { Bot } from "@/state/store";
+
+const bot = (id: string, section?: string, hidden?: boolean) => ({ id, section, hidden }) as unknown as Bot;
+
+describe("department filter", () => {
+ it("lists used departments in workspace order and flags General", () => {
+ const bots = [bot("a", "Social"), bot("b"), bot("c", "Dev"), bot("d", "Ghost", true)];
+ expect(filterableDepartments(bots, ["Dev", "Ghost", "Social", "Empty"])).toEqual({ names: ["Dev", "Social"], hasGeneral: true });
+ expect(filterableDepartments([bot("a", "Dev")], ["Dev"]).hasGeneral).toBe(false);
+ });
+ it("matches bots to a department", () => {
+ expect(botInDepartment(bot("a", "Dev"), "all")).toBe(true);
+ expect(botInDepartment(undefined, "all")).toBe(true);
+ expect(botInDepartment(bot("a", "Dev"), "Dev")).toBe(true);
+ expect(botInDepartment(bot("a", "Dev"), "Social")).toBe(false);
+ expect(botInDepartment(bot("a"), GENERAL_DEPARTMENT)).toBe(true);
+ expect(botInDepartment(bot("a", "Dev"), GENERAL_DEPARTMENT)).toBe(false);
+ expect(botInDepartment(undefined, "Dev")).toBe(false);
+ });
+});
diff --git a/src/lib/department-filter.ts b/src/lib/department-filter.ts
new file mode 100644
index 0000000000..3f21601d69
--- /dev/null
+++ b/src/lib/department-filter.ts
@@ -0,0 +1,15 @@
+import type { Bot } from "@/state/store";
+
+export const GENERAL_DEPARTMENT = "\u0000general";
+
+export function filterableDepartments(bots: readonly Bot[], order: readonly string[]): { names: string[]; hasGeneral: boolean } {
+ const visible = bots.filter((bot) => !bot.hidden);
+ const used = new Set(visible.map((bot) => bot.section).filter((name): name is string => Boolean(name)));
+ return { names: order.filter((name) => used.has(name)), hasGeneral: visible.some((bot) => !bot.section) };
+}
+
+export function botInDepartment(bot: Pick<Bot, "section"> | undefined, department: string): boolean {
+ if (department === "all") return true;
+ if (!bot) return false;
+ return department === GENERAL_DEPARTMENT ? !bot.section : bot.section === department;
+}
diff --git a/src/locales/en.json b/src/locales/en.json
index bbc98e518c..070c5c57e3 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -5045,6 +5045,8 @@
"automations.wake": "Keep this computer awake for scheduled automations",
"automations.wakeBattery": "Plug in to hold it awake.",
"automations.allBots": "All bots",
+ "automations.allDepartments": "All departments",
+ "automations.generalDepartment": "General",
"automations.status.working": "On",
"automations.status.paused": "Paused",
"automations.status.needsYou": "Needs you",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index e027d26b21..944f536453 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -4785,6 +4785,8 @@
"automations.wake": "Manter este computador acordado para automações agendadas",
"automations.wakeBattery": "Ligue na tomada para mantê-lo acordado.",
"automations.allBots": "Todos os bots",
+ "automations.allDepartments": "Todas as equipes",
+ "automations.generalDepartment": "Geral",
"automations.status.working": "Ligada",
"automations.status.paused": "Pausada",
"automations.status.needsYou": "Aguardando você",