Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
import {
IconChecklist,
IconEyeCheck,
IconHandStop,
IconTerminal2,
} from "@tabler/icons-react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { Link } from "@tanstack/react-router";
import { Fragment } from "react";
import {
PageEmpty,
PageRows,
PageSection,
} from "@/components/layout/page-shell";
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemMedia,
ItemTitle,
} from "@/components/ui/item";
import { Separator } from "@/components/ui/separator";
import { Switch } from "@/components/ui/switch";
import { agentListQueryOptions } from "@/lib/agents/queries";
import {
approvalInboxOptions,
approvalPreferencesMutationOptions,
createApprovalRuleMutationOptions,
revokeApprovalRuleMutationOptions,
ruleCoversBot,
updateApprovalRuleMutationOptions,
} from "@/lib/approvals";
import { currentUserQueryOptions } from "@/lib/auth/queries";
import { queryClient } from "@/query-client";
import { HOST_LABELS, LabelSelect, RuleForm, RuleRow } from "./rules";
/**
* The person's own approval settings: whether their Bots ask before changing things, and the rules
* that apply to every one of their Bots. Team rules are listed so the person can see them, locked;
* administrators change them in Admin → Approvals. Rules for a single Bot are on that Bot's page.
*/
export function ApprovalSettings() {
const inbox = useQuery(approvalInboxOptions());
const me = useQuery(currentUserQueryOptions()).data;
const agents = useQuery(agentListQueryOptions());
const hiddenAgents = useQuery(agentListQueryOptions(true));
const preferences = useMutation(
approvalPreferencesMutationOptions(queryClient),
);
const addRule = useMutation(createApprovalRuleMutationOptions(queryClient));
const changeRule = useMutation(
updateApprovalRuleMutationOptions(queryClient),
);
const revoke = useMutation(revokeApprovalRuleMutationOptions(queryClient));
const error =
inbox.error ?? preferences.error ?? changeRule.error ?? revoke.error;
if (inbox.isPending && !error) return null;
const enforced = inbox.data?.team?.enforceAutoReview ?? false;
const rulesOff = inbox.data?.team?.customRulesEnabled === false;
const everyBot = (inbox.data?.rules ?? []).filter(
(rule) => rule.botId === "*",
);
/*
* Rules that name no Bot this person can open — a Bot since deleted, or a name typed where an id
* belonged. They are still enforced, so they are listed here where they can be removed.
*/
const reachable = [...(agents.data ?? []), ...(hiddenAgents.data ?? [])];
const otherBots = (inbox.data?.rules ?? []).filter(
(rule) =>
rule.botId !== "*" &&
(agents.data === undefined ||
!reachable.some((agent) => ruleCoversBot(rule.botId, agent.id))),
);
const teamRules = inbox.data?.teamRules ?? [];
const canAdd = Boolean(inbox.data?.preferences) && !rulesOff;
const saved = teamRules.length + everyBot.length;
return (
<>
{error ? (
<p className="mt-6 text-destructive text-sm" role="alert">
{error.message}
</p>
) : null}
{me?.role === "admin" ? (
<p className="mt-6 text-muted-foreground text-sm">
Team settings and shared account requests are in{" "}
<Link className="underline underline-offset-4" to="/admin/approvals">
Admin → Approvals
</Link>
.
</p>
) : null}
<PageSection title="Before a Bot acts">
<PageRows>
<Item size="sm">
<ItemMedia variant="icon">
<IconHandStop />
</ItemMedia>
<ItemContent>
<ItemTitle>Ask before making changes</ItemTitle>
<ItemDescription>
Review a Bot's changes to websites, connected apps, and files.
</ItemDescription>
</ItemContent>
<ItemActions>
<Switch
aria-label="Ask before making changes"
checked={inbox.data?.enabled ?? false}
disabled={inbox.isLoading || preferences.isPending}
onCheckedChange={(enabled) => preferences.mutate({ enabled })}
/>
</ItemActions>
</Item>
{inbox.data?.preferences ? (
<>
<Separator />
<Item size="sm">
<ItemMedia variant="icon">
<IconEyeCheck />
</ItemMedia>
<ItemContent>
<ItemTitle id="auto-review-title">Auto-review</ItemTitle>
<ItemDescription
className="line-clamp-none"
id="auto-review-description"
>
{enforced ? "An admin requires this. " : ""}
Before a Bot does something that could affect your accounts
or share information, OpenBot checks it against your request
and your rules. If it can't tell, it asks you.
</ItemDescription>
</ItemContent>
<ItemActions>
<Switch
// Named by its title alone and described by the sentence beside it, so the name
// stays short however long the description grows.
aria-describedby="auto-review-description"
aria-labelledby="auto-review-title"
checked={enforced || inbox.data.preferences.autoReview}
disabled={enforced || preferences.isPending}
onCheckedChange={(autoReview) =>
preferences.mutate({ autoReview })
}
/>
</ItemActions>
</Item>
<Separator />
<Item size="sm">
<ItemMedia variant="icon">
<IconTerminal2 />
</ItemMedia>
<ItemContent>
<ItemTitle>Commands on your computer</ItemTitle>
<ItemDescription className="line-clamp-none">
{inbox.data.hostCommands &&
inbox.data.hostCommands !==
inbox.data.preferences.hostCommands
? `An admin limits this to "${HOST_LABELS[inbox.data.hostCommands]}". `
: ""}
The OpenBot desktop app still shows you each command before
it runs.
</ItemDescription>
</ItemContent>
<ItemActions>
<LabelSelect
disabled={preferences.isPending}
label="Commands on your computer"
labels={HOST_LABELS}
onChange={(hostCommands) =>
preferences.mutate({ hostCommands })
}
value={inbox.data.preferences.hostCommands}
/>
</ItemActions>
</Item>
</>
) : null}
</PageRows>
</PageSection>
<PageSection
description={
<>
The strictest matching rule wins. An "ask" rule beats an "allow"
rule. Team rules are locked. Passwords, security settings and
payments are always handed to you. Rules for one Bot are on{" "}
<Link className="underline underline-offset-4" to="/bots">
that Bot's page
</Link>
.
{rulesOff
? " An admin has turned off personal rules. Yours are kept but don't apply."
: ""}
</>
}
title="Rules for every Bot"
>
{saved === 0 ? (
<PageEmpty icon={IconChecklist} title="No rules yet" />
) : null}
{saved > 0 || canAdd ? (
<PageRows>
{teamRules.map((rule, index) => (
<Fragment key={rule.id}>
{index > 0 ? <Separator /> : null}
<RuleRow
disabled
locked
onChange={() => {}}
onRevoke={() => {}}
rule={rule}
team
/>
</Fragment>
))}
{everyBot.map((rule, index) => (
<Fragment key={rule.id}>
{teamRules.length + index > 0 ? <Separator /> : null}
<RuleRow
disabled={revoke.isPending || changeRule.isPending}
locked={rulesOff}
onChange={(behaviour) =>
changeRule.mutate({ id: rule.id, behaviour })
}
onRevoke={() => revoke.mutate(rule.id)}
rule={rule}
/>
</Fragment>
))}
{canAdd ? (
<>
{saved > 0 ? <Separator /> : null}
<RuleForm botField={false} label="Add a rule" save={addRule} />
</>
) : null}
</PageRows>
) : null}
</PageSection>
{agents.data !== undefined && otherBots.length > 0 ? (
<PageSection
description="These don't match a Bot you can open. They still apply to any Bot they match. Remove the ones you don't want."
title="Rules for other Bots"
>
<PageRows>
{otherBots.map((rule, index) => (
<Fragment key={rule.id}>
{index > 0 ? <Separator /> : null}
<RuleRow
disabled={revoke.isPending || changeRule.isPending}
locked={rulesOff}
onChange={(behaviour) =>
changeRule.mutate({ id: rule.id, behaviour })
}
onRevoke={() => revoke.mutate(rule.id)}
rule={rule}
/>
</Fragment>
))}
</PageRows>
</PageSection>
) : null}
</>
);
}