diff --git a/.claude/skills/openbot-screen-layout/SKILL.md b/.claude/skills/openbot-screen-layout/SKILL.md
index 25b0fe22bf..47ee952305 100644
--- a/.claude/skills/openbot-screen-layout/SKILL.md
+++ b/.claude/skills/openbot-screen-layout/SKILL.md
@@ -130,10 +130,14 @@ button.
3. `ItemActions` holds the control, or the value when the row is read-only.
4. `ItemHeader` and `ItemFooter` are `basis-full`, so they wrap onto a line of their own inside the
row. That is where a **set** goes — chips, toggles, anything that would otherwise fight the label
- for horizontal space. A set does not belong in `ItemActions`.
-5. `ItemDescription` is `line-clamp-2`. Where the text is the point rather than a hint, pass
+ for horizontal space. A set of chips or toggles does not belong in `ItemActions`.
+5. A row's **buttons** go in `ItemActions`, on the right, as on every other row, even when there are
+ several (a task's Open, Stop and Mark done). Give it `className="flex-wrap justify-end"` so they
+ wrap under each other on a narrow window. Never under the row's text on the left: that is where
+ a task's Open sat on a Bot's Activity, the one row whose action was not on the right.
+6. `ItemDescription` is `line-clamp-2`. Where the text is the point rather than a hint, pass
`className="line-clamp-none"`.
-6. To make the whole row navigate or open something, pass `render`:
+7. To make the whole row navigate or open something, pass `render`:
`render={}` or `render={}`. A real element, so
the keyboard reaches it and a link can be opened in a new tab.
@@ -154,6 +158,15 @@ starts to feel wrong.
`ItemDescription` plus `` in
`ItemActions`, and the row is a `Link` to a screen of its own (Screens, Not Dialogs). Editing
more than one value in place turns a settings screen back into a form.
+ **The one exception: a few short text fields that are edited together.** A Bot's Name, Title,
+ What it does and Instructions are fields on its Setup itself, in one `PageCard` inside a
+ `
);
}
+
+/**
+ * Who a Bot is, as fields you edit in place, with one Save: Name, Title, What it does, and
+ * Instructions where the Bot carries them. For whoever manages the Bot; anybody else reads the rows.
+ *
+ * Before, each was a row that opened a screen of its own, so renaming a Bot and giving it a title
+ * took two trips. Each field keeps its screen (`BotSetupFieldPage`) for an address that links to it.
+ *
+ * Checked against the same limits the server enforces, every field before anything is sent. What is
+ * wrong shows under its field, and a refused save under the form. Only what changed is sent, in one
+ * update. Enter in a one-line field saves, but not the Enter that confirms a composed character.
+ */
+export function IdentityForm({ agent }: { agent: AgentProfile }) {
+ const fields = identityFieldsOf(agent);
+ const update = useMutation(updateAgentMutationOptions(queryClient));
+ const shown = Object.fromEntries(
+ fields.map((entry) => [entry.slug, shownValue(agent, entry)]),
+ );
+ const [drafts, setDrafts] = useState>(shown);
+ /*
+ * What each field held when its draft was last in step with the Bot. When the Bot changes from
+ * elsewhere while the page is open (another tab, the Bot itself, a teammate), a field nobody has
+ * typed in takes the new value, so Save never sends back the old one. A field being edited keeps
+ * what is typed in it.
+ */
+ const [base, setBase] = useState>(shown);
+ if (fields.some((entry) => shown[entry.slug] !== base[entry.slug])) {
+ setDrafts((current) =>
+ Object.fromEntries(
+ fields.map((entry) => [
+ entry.slug,
+ current[entry.slug] === base[entry.slug]
+ ? (shown[entry.slug] ?? "")
+ : (current[entry.slug] ?? ""),
+ ]),
+ ),
+ );
+ setBase(shown);
+ }
+ const [errors, setErrors] = useState>({});
+ // A refused save is kept whole, not as its words, so a hold is drawn calmly (`failureSaid`).
+ const [refused, setRefused] = useState(null);
+ const [saved, setSaved] = useState(false);
+ const baseId = useId();
+ const draftOf = (entry: SetupField) =>
+ drafts[entry.slug] ?? shownValue(agent, entry);
+ const changed = fields.filter(
+ (entry) => draftOf(entry) !== shownValue(agent, entry),
+ );
+ const submit = async () => {
+ setRefused(null);
+ const found: Record = {};
+ let patch: Partial = {};
+ for (const entry of changed) {
+ const parsed = entry.schema.safeParse(draftOf(entry));
+ if (!parsed.success) {
+ found[entry.slug] =
+ parsed.error.issues[0]?.message ?? "Check this field and try again.";
+ continue;
+ }
+ patch = { ...patch, ...savedPatch(agent, entry, parsed.data) };
+ }
+ setErrors(found);
+ const first = fields.find((entry) => found[entry.slug]);
+ if (first) {
+ document.getElementById(`${baseId}-${first.slug}`)?.focus();
+ return;
+ }
+ if (changed.length === 0) return;
+ try {
+ await update.mutateAsync({
+ agentId: agent.id,
+ input: profileUpdateInput(agent, patch),
+ });
+ setSaved(true);
+ } catch (failure) {
+ setRefused(failureOf(failure, "Couldn't save. Try again."));
+ }
+ };
+ return (
+
+ );
+}
diff --git a/app/src/components/bot-profile/setup.tsx b/app/src/components/bot-profile/setup.tsx
index e4ec2064db..3888619954 100644
--- a/app/src/components/bot-profile/setup.tsx
+++ b/app/src/components/bot-profile/setup.tsx
@@ -7,6 +7,7 @@ import { keySummary } from "@/components/bot-profile/key-page";
import {
AGENT_URL_FIELD,
hasConnection,
+ IdentityForm,
identityFieldsOf,
type SetupField,
setupFieldLink,
@@ -61,8 +62,9 @@ import { queryClient } from "@/query-client";
/**
* Who a Bot is and where it runs. Editable by whoever may manage it; read-only for everyone else.
*
- * A row that edits text (Name, Title, What it does, Instructions, Agent URL) or the key is a summary
- * and a chevron, and a link to a screen of its own under the Bot's Setup (`setup-fields.tsx`,
+ * Name, Title, What it does and Instructions are fields edited in place, with one Save
+ * (`IdentityForm`), for whoever manages the Bot; anybody else reads them as rows. The Agent URL and
+ * the key are a summary and a chevron, and a link to a screen of their own (`setup-fields.tsx`,
* `key-page.tsx`). Visibility and Isolated write when picked or switched, so they stay in the row.
*/
export function SetupSections({ agent }: { agent: AgentProfile }) {
@@ -79,25 +81,33 @@ export function SetupSections({ agent }: { agent: AgentProfile }) {
return (
<>
+ {agent.canManage ? (
+
+ ) : (
+
+ {identityFieldsOf(agent).map((entry, index) => (
+
+ {index > 0 ? : null}
+
+
+ ))}
+
+ )}
+
+ {/*
+ * Who can find it and where it runs: switches and picks that write at once, so a section of
+ * their own under the fields, not a second card stacked in Identity.
+ */}
+
- {identityFieldsOf(agent).map((entry, index) => (
-
- {index > 0 ? : null}
-
-
- ))}
{personal ? (
- <>
-
-
-
-
-
-
- >
+
+
+
+
+
) : (
<>
- save({ visibility })}
diff --git a/app/src/components/layout/page-parts.tsx b/app/src/components/layout/page-parts.tsx
index 07606938d5..17fd22a005 100644
--- a/app/src/components/layout/page-parts.tsx
+++ b/app/src/components/layout/page-parts.tsx
@@ -119,6 +119,7 @@ export function PageSection({
action,
children,
className,
+ count,
description,
id,
title,
@@ -126,6 +127,8 @@ export function PageSection({
action?: React.ReactNode;
children?: React.ReactNode;
className?: string;
+ /** How many things the section lists, said beside its title ("Skills 22"). */
+ count?: number;
description?: React.ReactNode;
/** For an address that opens the page at this section, as its hash. */
id?: string;
@@ -139,7 +142,14 @@ export function PageSection({
* Close to body size and lighter than the page title, so the sections read as parts of
* the page rather than as a second row of titles competing with it.
*/}
-
{action}
) : null}
diff --git a/app/src/components/tasks/task-row.tsx b/app/src/components/tasks/task-row.tsx
index 8966e61386..6b974ed98d 100644
--- a/app/src/components/tasks/task-row.tsx
+++ b/app/src/components/tasks/task-row.tsx
@@ -15,9 +15,9 @@ import { Button } from "@/components/ui/button";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import {
Item,
+ ItemActions,
ItemContent,
ItemDescription,
- ItemFooter,
ItemMedia,
ItemTitle,
} from "@/components/ui/item";
@@ -158,8 +158,9 @@ function canMarkDone(listed: ListedTask, settled = false): boolean {
* and what it needs next, with Open to read it and reply there, Mark done or Reopen, and Try again
* once it couldn't finish.
*
- * The buttons sit on a line of their own rather than the row being a link, so no button is nested
- * inside one. Open is the primary action while the task has something to read or answer.
+ * The buttons sit on the right, as on every other row, and the row is not a link, so no button is
+ * nested inside one. Open is the primary action while the task has something to read or answer.
+ * Under the text, Open sat on the left of a finished task's row, where no other row puts an action.
*/
export function TaskRow({
listed,
@@ -238,69 +239,69 @@ export function TaskRow({
) : null}
-
- {canTryAgain({ ...task, status }) ? (
-
- ) : null}
-
- }
- size="sm"
- variant={openFirst ? "default" : "outline"}
- >
- Open
-
- {canStop ? (
-
- ) : null}
- {status === "resolved" ? (
-
- ) : canMarkDone(listed, settled) ? (
-
- ) : null}
-
{error ? (
{failureSaid(error)}
) : null}
+
+ {canTryAgain({ ...task, status }) ? (
+
+ ) : null}
+
+ }
+ size="sm"
+ variant={openFirst ? "default" : "outline"}
+ >
+ Open
+
+ {canStop ? (
+
+ ) : null}
+ {status === "resolved" ? (
+
+ ) : canMarkDone(listed, settled) ? (
+
+ ) : null}
+
);
}
diff --git a/app/src/lib/routines/by-bot.ts b/app/src/lib/routines/by-bot.ts
index 1fe6c69805..733120c505 100644
--- a/app/src/lib/routines/by-bot.ts
+++ b/app/src/lib/routines/by-bot.ts
@@ -152,7 +152,8 @@ function band(row: MergedRoutine): number {
return nextStart(row) === null ? 3 : 2;
}
-function sortedRows(rows: readonly MergedRoutine[]): MergedRoutine[] {
+/** The rows in the Routines page's order: the five bands of `band`, ties kept in their order. */
+export function sortedRows(rows: readonly MergedRoutine[]): MergedRoutine[] {
return rows
.map((row, index) => ({
row,
diff --git a/app/src/routes/_authed/_app/bots.$agentId.computer.tsx b/app/src/routes/_authed/_app/bots.$agentId.computer.tsx
index ccb8ebc230..2bab5e8efb 100644
--- a/app/src/routes/_authed/_app/bots.$agentId.computer.tsx
+++ b/app/src/routes/_authed/_app/bots.$agentId.computer.tsx
@@ -1,5 +1,6 @@
import { createFileRoute } from "@tanstack/react-router";
import { BotSubpage } from "@/components/bot-profile/bot-subpage";
+import { BotComputerState } from "@/components/bot-profile/computer-state";
import { ComputersPage } from "@/components/manage/computers-page";
import { WindowsComputerChoice } from "@/components/windows-computer/windows-computer-choice";
@@ -22,6 +23,7 @@ function ComputerPage() {
>
{(agent) => (
<>
+
>
diff --git a/app/tests/bot-activity-groups.test.tsx b/app/tests/bot-activity-groups.test.tsx
index 46f80e0ae2..6d5995a184 100644
--- a/app/tests/bot-activity-groups.test.tsx
+++ b/app/tests/bot-activity-groups.test.tsx
@@ -98,6 +98,7 @@ function draw(
checkIns: readonly unknown[] = [],
/** Drawn under the Needs you board, as OpenFuse's Activity draws it. */
boardAbove = false,
+ routines: readonly unknown[] = [],
) {
global.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
const path = pathOf(input);
@@ -107,7 +108,10 @@ function draw(
if (path === CONVERSATIONS_PATH)
return Response.json(conversationPage([MAIN]));
return (
- answerScheduleLists(input, init, { checkIns }) ??
+ answerScheduleLists(input, init, {
+ checkIns: checkIns as never,
+ routines: routines as never,
+ }) ??
answerBotsList(input, init, { visible: [{ id: BOT, name: "Scout" }] }) ??
Response.json({ error: "unexpected" }, { status: 404 })
);
@@ -473,3 +477,101 @@ test("a working task's row opens its thread and does not offer Mark done", async
(await row(title)).getByRole("button", { name: "Mark done" }),
).toBeTruthy();
});
+
+test("a scheduled routine says when it runs, in words, never how long ago it was due", async () => {
+ const view = draw(
+ {
+ scheduled: [
+ item({
+ id: "routine:r1",
+ kind: "routine",
+ title: "Standup summary",
+ status: "due",
+ // Due two weeks ago: it read "due · 2 weeks ago".
+ at: new Date(Date.now() - 14 * 86_400_000).toISOString(),
+ }),
+ ],
+ },
+ [],
+ [],
+ false,
+ [
+ {
+ id: "r1",
+ botId: BOT,
+ schedule: "Every weekday at 9:00",
+ cron: "0 9 * * 1-5",
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
+ instruction: "Post the standup summary.",
+ title: "Standup summary",
+ conversation: { id: "c1", name: null, title: "Standup", gone: false },
+ enabled: true,
+ nextRunAt: "2999-01-01T09:00:00.000Z",
+ lastRun: null,
+ goalId: null,
+ createdAt: NOW,
+ },
+ ],
+ );
+ expect(
+ await view.findByText("Routine · On · Every weekday at 9:00"),
+ ).toBeTruthy();
+ expect(view.queryByText(/ago/)).toBeNull();
+});
+
+test("a finished task's Open sits on the right with the row's other actions, not under its text", async () => {
+ const view = draw({}, [task("ready", "ready_for_review")]);
+ const done = within(
+ (await view.findByRole("heading", { name: "Done" })).closest(
+ "section",
+ ) as HTMLElement,
+ );
+ const open = done.getByText("Open");
+ expect(open.closest("[data-slot=item-actions]")).not.toBeNull();
+ expect(open.closest("[data-slot=item-content]")).toBeNull();
+});
+
+test("a follow-up says when it is due, or that it was, in one phrase", async () => {
+ const view = draw(
+ {
+ scheduled: [
+ item({
+ id: "wake:soon",
+ kind: "follow_up",
+ title: "Check the invoice",
+ status: "due",
+ at: new Date(Date.now() + 3 * 3_600_000).toISOString(),
+ cancellable: true,
+ }),
+ item({
+ id: "wake:late",
+ kind: "follow_up",
+ title: "Chase the receipt",
+ status: "due",
+ at: new Date(Date.now() - 14 * 86_400_000).toISOString(),
+ cancellable: true,
+ }),
+ ],
+ },
+ [],
+ );
+ expect(await view.findByText("Follow-up · due in 3 hours")).toBeTruthy();
+ expect(view.getByText("Follow-up · was due 2 weeks ago")).toBeTruthy();
+});
+
+test("a routine at work says Running now, in the Routines page's words", async () => {
+ const view = draw(
+ {
+ inProgress: [
+ item({
+ id: "routine:r1",
+ kind: "routine",
+ title: "Morning inbox summary",
+ status: "running",
+ }),
+ ],
+ },
+ [],
+ );
+ expect(await view.findByText("Routine · Running now")).toBeTruthy();
+});
diff --git a/app/tests/bot-computer-state.test.tsx b/app/tests/bot-computer-state.test.tsx
new file mode 100644
index 0000000000..03da8e79cc
--- /dev/null
+++ b/app/tests/bot-computer-state.test.tsx
@@ -0,0 +1,60 @@
+import { afterAll, afterEach, beforeAll, expect, test } from "bun:test";
+import { GlobalRegistrator } from "@happy-dom/global-registrator";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { cleanup, render } from "@testing-library/react";
+import { BotComputerState } from "@/components/bot-profile/computer-state";
+import { computerKeys } from "@/lib/computers/queries";
+import { deploymentKeys } from "@/lib/deployment/queries";
+import { settleReactWork } from "./settle-react-work";
+
+/*
+ * The top of a Bot's Computer page says whether its computer is on, read without waking it.
+ */
+
+beforeAll(() => GlobalRegistrator.register());
+afterEach(cleanup);
+afterAll(async () => {
+ await settleReactWork();
+ GlobalRegistrator.unregister();
+});
+
+function draw(state: string | null, botComputers = true) {
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false, staleTime: Infinity } },
+ });
+ client.setQueryData(deploymentKeys.capabilities(), { botComputers });
+ if (state !== null)
+ client.setQueryData(computerKeys.status("atlas"), {
+ botId: "atlas",
+ state,
+ });
+ return render(
+
+
+ ,
+ );
+}
+
+test("a computer that is off says it is asleep, and when it starts", () => {
+ const view = draw("absent");
+ expect(view.getByText("Asleep")).toBeTruthy();
+ expect(view.getByText("It starts when this Bot next needs it.")).toBeTruthy();
+});
+
+test("each state the server sends has its own word", () => {
+ for (const [state, word] of [
+ ["starting", "Starting"],
+ ["ready", "Awake"],
+ ["unreachable", "Not answering"],
+ ] as const) {
+ const view = draw(state);
+ expect(view.getByText(word)).toBeTruthy();
+ cleanup();
+ }
+});
+
+test("a state this app doesn't know, or no computers for Bots, draws nothing", () => {
+ expect(draw("hibernating").container.textContent).toBe("");
+ cleanup();
+ expect(draw("absent", false).container.textContent).toBe("");
+});
diff --git a/app/tests/bot-key-setting.test.tsx b/app/tests/bot-key-setting.test.tsx
index 61897c0f7a..4e22003c28 100644
--- a/app/tests/bot-key-setting.test.tsx
+++ b/app/tests/bot-key-setting.test.tsx
@@ -284,6 +284,6 @@ test("anyone who can't manage the Bot reads whether a key is set, and is linked
test("a Bot that runs inside OpenBot has no Key row", async () => {
const view = draw({ ...BOT, endpoint: null, builtIn: true });
- expect(await view.findByRole("link", { name: /^Name/ })).toBeTruthy();
+ expect(await view.findByLabelText("Name")).toBeTruthy();
expect(view.queryByRole("heading", { name: "Connection" })).toBeNull();
});
diff --git a/app/tests/bot-long-instructions-layout.fixture.tsx b/app/tests/bot-long-instructions-layout.fixture.tsx
index f82dde7d8d..1e30525b9c 100644
--- a/app/tests/bot-long-instructions-layout.fixture.tsx
+++ b/app/tests/bot-long-instructions-layout.fixture.tsx
@@ -20,7 +20,7 @@ import { queryClient } from "@/query-client";
/**
* A Bot whose instructions run to the most they take, 5000 characters, for
* bot-long-instructions-layout.test.tsx to bundle and load in a browser. `?screen=new-bot` opens
- * the New Bot sheet; anything else, the Bot's Setup page, whose rows open their own screens. The server's answers come from a fetch
+ * the New Bot sheet; anything else, the Bot's Setup page, whose fields are edited in place. The server's answers come from a fetch
* here, as the API gives them, and a change is kept and read back.
*/
setCurrentOrganization("default");
diff --git a/app/tests/bot-long-instructions-layout.test.tsx b/app/tests/bot-long-instructions-layout.test.tsx
index 51e0a72046..6964f7ac3c 100644
--- a/app/tests/bot-long-instructions-layout.test.tsx
+++ b/app/tests/bot-long-instructions-layout.test.tsx
@@ -230,17 +230,17 @@ describe.skipIf(!asked)("a Bot's instructions at 5000 characters", () => {
test(`Setup holds them, and What it does saves all 5000 and refuses a 5001st, in ${engine}, ${theme}, ${window.width}px`, async () => {
const page = await open(engine, theme, window, "setup");
- const row = page.getByRole("link", { name: /^What it does/ });
- await row.waitFor();
+ // What it does is a field on Setup itself, saved with the form's one Save.
+ const field = page.getByRole("textbox", { name: "What it does" });
+ const save = page.getByRole("button", { name: "Save" });
+ await field.waitFor();
await styled(page);
expect((await measure(page)).sideways).toBe(false);
await shoot(page, `setup-${at}.png`);
- await row.click();
- const field = page.getByRole("textbox", { name: "What it does" });
- await field.waitFor();
- await styled(page);
- expect(await field.inputValue()).toHaveLength(5000);
+ const original = await field.inputValue();
+ expect(original).toHaveLength(5000);
+ await save.scrollIntoViewIfNeeded();
const editing = await measure(page);
expect(editing.sideways).toBe(false);
expect(editing.formInside).toBe(true);
@@ -249,22 +249,28 @@ describe.skipIf(!asked)("a Bot's instructions at 5000 characters", () => {
await field.press("ControlOrMeta+End");
await field.pressSequentially("!");
- await page.getByRole("button", { name: "Save" }).click();
- await page.getByRole("alert").waitFor();
+ await save.click();
+ const alert = page.getByRole("alert");
+ await alert.waitFor();
+ await alert.scrollIntoViewIfNeeded();
await styled(page);
const refused = await measure(page);
expect(refused.alert).toBe(
"What it does must be 5000 characters or fewer.",
);
expect(refused.alertSeen).toBe(true);
- expect(refused.saveInside).toBe(true);
expect(refused.sideways).toBe(false);
await shoot(page, `what-it-does-5001-${at}.png`);
- await field.press("Backspace");
- await page.getByRole("button", { name: "Save" }).click();
- // Saved, back on Setup.
- await row.waitFor();
+ // Back to 5000 characters, with the last one changed: Save sends only a change.
+ await field.fill(`${original.slice(0, -1)}?`);
+ expect(await field.inputValue()).toHaveLength(5000);
+ await save.click();
+ // Saved, in place.
+ await page
+ .getByRole("status")
+ .filter({ hasText: "Saved." })
+ .waitFor();
expect((await measure(page)).sideways).toBe(false);
await page.close();
}, 90_000);
diff --git a/app/tests/bot-page-length.test.tsx b/app/tests/bot-page-length.test.tsx
index d145d42b08..438cebc965 100644
--- a/app/tests/bot-page-length.test.tsx
+++ b/app/tests/bot-page-length.test.tsx
@@ -376,6 +376,6 @@ test("a goal's activity row says Goal and opens the Bot's routines", async () =>
const title = await view.findByText("Close the month 1");
const row = title.closest("a");
expect(row?.getAttribute("href")).toBe("/bots/scout/routines");
- expect(row?.textContent).toContain("Goal · running");
+ expect(row?.textContent).toContain("Goal · Running now");
expect(row?.textContent).not.toMatch(/responsibilit/i);
});
diff --git a/app/tests/bot-routines-summary.test.tsx b/app/tests/bot-routines-summary.test.tsx
index 46a926d5c3..0afc2c864e 100644
--- a/app/tests/bot-routines-summary.test.tsx
+++ b/app/tests/bot-routines-summary.test.tsx
@@ -7,7 +7,7 @@ import {
createRouter,
RouterProvider,
} from "@tanstack/react-router";
-import { cleanup, render } from "@testing-library/react";
+import { act, cleanup, fireEvent, render } from "@testing-library/react";
import { BotRoutinesSummary } from "@/components/bot-profile/routines-summary";
import { viewerTimeZone } from "@/components/routines/routine-page";
import type { RoutineRecord } from "@/lib/routines/queries";
@@ -15,8 +15,9 @@ import { answerScheduleLists, pathOf, ROUTINES_PATH } from "./schedules-api";
import { settleReactWork } from "./settle-react-work";
/**
- * A Bot's routines on its own page, under For you: what is running and what is lined up, in the
- * Routines page's words, with See all to the Bot's Routines.
+ * A Bot's routines on its own page, under For you: what is running, what is lined up and what is
+ * paused, each with a switch that turns it on or off right there: at most five, then All routines with
+ * the total, to the Bot's Routines.
*/
beforeAll(() => GlobalRegistrator.register());
@@ -48,10 +49,16 @@ const routine = (overrides: Partial = {}): RoutineRecord => ({
...overrides,
});
+/** Every write the section sent, as "METHOD path". */
+let writes: string[] = [];
+
function draw(routines: unknown[], { fail = false } = {}) {
+ writes = [];
global.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
if (fail && pathOf(input) === ROUTINES_PATH)
return new Response(null, { status: 500 });
+ if (init?.method && init.method !== "GET")
+ writes.push(`${init.method} ${pathOf(input)}`);
return answerScheduleLists(input, init, { routines }) ?? Response.json({});
}) as unknown as typeof fetch;
const router = createRouter({
@@ -73,10 +80,13 @@ function draw(routines: unknown[], { fail = false } = {}) {
const rowNames = (view: ReturnType) =>
[...view.container.querySelectorAll("a[href^='/routines/']")].map(
- (row) => row.textContent,
+ (link) => link.textContent,
);
-test("running first, then what starts soonest, with See all to the Bot's Routines", async () => {
+const heading = (view: ReturnType) =>
+ view.findByRole("heading", { name: "Routines" });
+
+test("running first, then what starts soonest, then what is paused, counted, with All routines to the Bot's Routines", async () => {
const view = draw([
routine({ id: "late", title: "Late", nextRunAt: "2999-01-03T09:00:00Z" }),
routine({
@@ -89,14 +99,15 @@ test("running first, then what starts soonest, with See all to the Bot's Routine
routine({ id: "paused", title: "Paused", enabled: false }),
routine({ id: "other", title: "Someone else's", botId: "scout" }),
]);
- await view.findByRole("heading", { name: "Routines" });
- expect(rowNames(view)).toEqual(["Running", "Soon", "Late"]);
+ await heading(view);
+ expect(view.getByText("4 routines")).toBeTruthy();
+ expect(rowNames(view)).toEqual(["Running", "Soon", "Late", "Paused"]);
expect(view.getByText("Running now")).toBeTruthy();
- const seeAll = view.getByRole("button", { name: "See all" });
+ const seeAll = view.getByRole("button", { name: "All routines (4)" });
expect(seeAll.getAttribute("href")).toBe("/bots/atlas/routines");
});
-test("at most five, the rest behind See all", async () => {
+test("at most five, then All routines with the total", async () => {
const view = draw(
Array.from({ length: 7 }, (_, index) =>
routine({
@@ -106,7 +117,7 @@ test("at most five, the rest behind See all", async () => {
}),
),
);
- await view.findByRole("heading", { name: "Routines" });
+ await heading(view);
expect(rowNames(view)).toEqual([
"Routine 0",
"Routine 1",
@@ -114,13 +125,31 @@ test("at most five, the rest behind See all", async () => {
"Routine 3",
"Routine 4",
]);
+ expect(view.getByRole("button", { name: "All routines (7)" })).toBeTruthy();
});
-test("only paused routines: says nothing is running or scheduled, and still has See all", async () => {
+test("a paused routine is listed with its switch off and when it would run, and switching it on resumes it", async () => {
const view = draw([routine({ enabled: false })]);
- expect(await view.findByText("Nothing running or scheduled.")).toBeTruthy();
- expect(view.getByRole("button", { name: "See all" })).toBeTruthy();
- expect(rowNames(view)).toEqual([]);
+ const toggle = await view.findByRole("switch", { name: "Standup summary" });
+ expect(toggle.getAttribute("aria-checked")).toBe("false");
+ expect(view.getByText("Paused · Every weekday at 9:00")).toBeTruthy();
+ expect(view.getByRole("button", { name: "All routines (1)" })).toBeTruthy();
+ await act(async () => {
+ fireEvent.click(toggle);
+ });
+ await settleReactWork();
+ expect(writes).toEqual([`POST ${ROUTINES_PATH}/r1/resume`]);
+});
+
+test("a routine that is on has its switch on, and switching it off pauses it", async () => {
+ const view = draw([routine()]);
+ const toggle = await view.findByRole("switch", { name: "Standup summary" });
+ expect(toggle.getAttribute("aria-checked")).toBe("true");
+ await act(async () => {
+ fireEvent.click(toggle);
+ });
+ await settleReactWork();
+ expect(writes).toEqual([`POST ${ROUTINES_PATH}/r1/pause`]);
});
test("a Bot with no routines has no Routines section", async () => {
@@ -129,8 +158,8 @@ test("a Bot with no routines has no Routines section", async () => {
expect(view.queryByRole("heading", { name: "Routines" })).toBeNull();
});
-test("a read that fails is said, and See all still goes to the Bot's Routines", async () => {
+test("a read that fails is said, and All routines still goes to the Bot's Routines", async () => {
const view = draw([], { fail: true });
expect(await view.findByRole("alert")).toBeTruthy();
- expect(view.getByRole("button", { name: "See all" })).toBeTruthy();
+ expect(view.getByRole("button", { name: "All routines (0)" })).toBeTruthy();
});
diff --git a/app/tests/bot-setup-agent-url.test.tsx b/app/tests/bot-setup-agent-url.test.tsx
index 6905f3b253..c737a141a3 100644
--- a/app/tests/bot-setup-agent-url.test.tsx
+++ b/app/tests/bot-setup-agent-url.test.tsx
@@ -284,7 +284,7 @@ test("the Agent URL is read-only to anyone who can't manage the Bot, and a Bot t
// Nothing to connect, and what runs it is not the person's concern: no section, no "Built in".
const builtIn = draw({ ...BOT, endpoint: null, builtIn: true });
- expect(await builtIn.findByRole("link", { name: /^Name/ })).toBeTruthy();
+ expect(await builtIn.findByLabelText("Name")).toBeTruthy();
expect(builtIn.queryByRole("heading", { name: "Connection" })).toBeNull();
expect(builtIn.queryByText("Built in")).toBeNull();
});
@@ -293,8 +293,7 @@ test("renaming a Bot whose stored address the rules now refuse does not send tha
// Saved before the deployment closed private addresses: still stored, and refused if sent again.
const local = { ...BOT, endpoint: "http://127.0.0.1:8000/ag-ui" };
const view = draw(local);
- await openRow(await view.findByRole("link", { name: /^Name/ }));
-
+ // Name is a field on Setup itself, saved with the form's one Save.
await replaceAndSave(await view.findByLabelText("Name"), "Sales Desk");
expect(within(view.baseElement).queryByRole("alert")).toBeNull();
diff --git a/app/tests/bot-setup-engine.test.tsx b/app/tests/bot-setup-engine.test.tsx
index 75774517cc..2423d3b0b8 100644
--- a/app/tests/bot-setup-engine.test.tsx
+++ b/app/tests/bot-setup-engine.test.tsx
@@ -89,7 +89,7 @@ function draw(screen: ReactNode) {
test("a Bot that runs inside OpenBot has no Connection section, whichever engine runs it", async () => {
for (const framework of ["LangGraph (TypeScript)", "OpenBot", undefined]) {
const view = draw();
- expect(await view.findByRole("link", { name: /^Name/ })).toBeTruthy();
+ expect(await view.findByLabelText("Name")).toBeTruthy();
expect(view.queryByRole("heading", { name: "Connection" })).toBeNull();
expect(view.queryByText("Built in")).toBeNull();
expect(view.queryByText("Runs on")).toBeNull();
diff --git a/app/tests/bot-setup-instructions-limit.test.tsx b/app/tests/bot-setup-instructions-limit.test.tsx
index 844a9ef573..fac05088f1 100644
--- a/app/tests/bot-setup-instructions-limit.test.tsx
+++ b/app/tests/bot-setup-instructions-limit.test.tsx
@@ -18,7 +18,7 @@ import userEvent from "@testing-library/user-event";
import { HttpResponse, http } from "msw";
import { setupServer } from "msw/node";
import { agentFormSchema } from "@/lib/agents/form";
-import type { AgentProfile } from "@/lib/agents/queries";
+import { type AgentProfile, agentKeys } from "@/lib/agents/queries";
import {
getGetBotMockHandler,
getUpdateBotMockHandler,
@@ -80,6 +80,8 @@ const server = setupServer(
patches.push(body);
stored = {
...stored,
+ name: body.name ?? stored.name,
+ title: body.title ?? stored.title,
roleDescription: body.roleDescription,
...(body.instructions === undefined
? {}
@@ -123,8 +125,8 @@ function draw(bot: AgentProfile) {
}
/**
- * Open a row's own screen from Setup (or stay on it, with `row` null), type `value` in place of what
- * its field holds, and press Save.
+ * Open a row's own screen from Setup (or, with `row` null, use the field on Setup itself), type
+ * `value` in place of what its field holds, and press Save.
*/
async function save(
view: ReturnType,
@@ -168,17 +170,12 @@ test(
const most = `${"Check every receipt. ".repeat(238)}Done.`.slice(0, 5000);
expect(most).toHaveLength(5000);
- const tooLong = await save(
- view,
- /^What it does/,
- "What it does",
- `${most}!`,
- );
+ const tooLong = await save(view, null, "What it does", `${most}!`);
expect(within(tooLong).getByRole("alert").textContent).toBe(
"What it does must be 5000 characters or fewer.",
);
expect(patches).toEqual([]);
- // Still on the field's screen, with what was typed: Save again with fewer.
+ // Still in the field, with what was typed: Save again with fewer.
await save(view, null, "What it does", most);
expect(patches).toHaveLength(1);
@@ -194,17 +191,12 @@ test(
const view = draw({ ...BOT, instructions: "Help with everyday work." });
const most = "i".repeat(5000);
- const tooLong = await save(
- view,
- /^Instructions/,
- "Instructions",
- `${most}i`,
- );
+ const tooLong = await save(view, null, "Instructions", `${most}i`);
expect(within(tooLong).getByRole("alert").textContent).toBe(
"Instructions must be 5000 characters or fewer.",
);
expect(patches).toEqual([]);
- // Still on the field's screen, with what was typed: Save again with fewer.
+ // Still in the field, with what was typed: Save again with fewer.
await save(view, null, "Instructions", most);
expect(patches).toHaveLength(1);
@@ -212,3 +204,73 @@ test(
},
TYPING,
);
+
+test(
+ "Name and Title are edited in place and sent together with one Save",
+ async () => {
+ const view = draw(BOT);
+ const name = await view.findByLabelText("Name");
+ const title = view.getByLabelText("Title");
+ const form = name.closest("form") as HTMLElement;
+ const save = within(form).getByRole("button", { name: "Save" });
+ // Nothing changed yet, so nothing to save.
+ expect(save.hasAttribute("disabled")).toBe(true);
+ // Examples in the empty fields, so a person sees the kind of answer each takes.
+ expect(title.getAttribute("placeholder")).toBe(
+ "Research, marketing, admin",
+ );
+ expect(
+ view.getByLabelText("What it does").getAttribute("placeholder"),
+ ).toBe("What should this Bot help with?");
+
+ const user = userEvent.setup({ document: name.ownerDocument, delay: null });
+ await user.clear(name);
+ await user.type(name, "Sales Desk");
+ await user.clear(title);
+ await user.type(title, "Sales");
+ await act(async () => {
+ fireEvent.click(save);
+ });
+ await settleReactWork();
+
+ expect(patches).toHaveLength(1);
+ expect(patches[0]).toMatchObject({ name: "Sales Desk", title: "Sales" });
+ expect(await view.findByText("Saved.")).toBeTruthy();
+ },
+ TYPING,
+);
+
+test(
+ "a field nobody typed in follows a change made elsewhere, so Save never sends the old value back",
+ async () => {
+ const view = draw(BOT);
+ const name = await view.findByLabelText("Name");
+ const title = view.getByLabelText("Title") as HTMLInputElement;
+
+ // Someone renames the Bot's title in another tab while this page is open.
+ stored = { ...stored, title: "Accounts payable" };
+ await act(async () => {
+ await queryClient.invalidateQueries({ queryKey: agentKeys.all });
+ });
+ expect(await view.findByDisplayValue("Accounts payable")).toBe(title);
+
+ const user = userEvent.setup({ document: name.ownerDocument, delay: null });
+ await user.clear(name);
+ await user.type(name, "Sales Desk");
+ await act(async () => {
+ fireEvent.click(
+ within(name.closest("form") as HTMLElement).getByRole("button", {
+ name: "Save",
+ }),
+ );
+ });
+ await settleReactWork();
+
+ expect(patches).toHaveLength(1);
+ expect(patches[0]).toMatchObject({
+ name: "Sales Desk",
+ title: "Accounts payable",
+ });
+ },
+ TYPING,
+);
diff --git a/app/tests/settings-tool-cards-personal.test.tsx b/app/tests/settings-tool-cards-personal.test.tsx
index e8667a031b..3aa2650bbc 100644
--- a/app/tests/settings-tool-cards-personal.test.tsx
+++ b/app/tests/settings-tool-cards-personal.test.tsx
@@ -521,7 +521,7 @@ describe.skipIf(!asked)("the personal settings cards", () => {
type Pair = {
/** Each row of the card: its label and what it says now. */
rows: { label: string; now: string }[];
- /** The screen's words, and its switches and choices by name. */
+ /** The screen's words and what its fields hold, and its switches and choices by name. */
screen: string;
switches: Record;
side: boolean;
@@ -544,7 +544,17 @@ function pairs(page: Page): Promise> {
now: words(row.querySelector('[data-value="after"]')),
}),
),
- screen: words(screen),
+ // What the screen shows: its words, and what its fields hold (Setup edits text in place).
+ screen: [
+ words(screen),
+ ...[
+ ...(screen?.querySelectorAll<
+ HTMLInputElement | HTMLTextAreaElement
+ >("input, textarea") ?? []),
+ ].map((field) => field.value),
+ ]
+ .join(" ")
+ .trim(),
switches: Object.fromEntries(
[...(screen?.querySelectorAll('[role="switch"]') ?? [])].map(
(control) => [
diff --git a/app/workbench/api/extraHandlers.test.ts b/app/workbench/api/extraHandlers.test.ts
index 9476a2ea0f..a236549199 100644
--- a/app/workbench/api/extraHandlers.test.ts
+++ b/app/workbench/api/extraHandlers.test.ts
@@ -58,4 +58,37 @@ describe("extraHandlers", () => {
);
expect(response).toBeUndefined();
});
+
+ test("a Bot's computer status says what the computer list says", async () => {
+ const handlers = extraHandlers({
+ agents: () => [],
+ computers: () => [
+ { botId: "research-assistant", running: true },
+ { botId: "general-assistant", running: false },
+ ],
+ });
+ const state = async (botId: string) => {
+ const response = await getResponse(
+ handlers,
+ new Request(
+ `${ORIGIN}/api/v2/organizations/default/computers/${botId}`,
+ ),
+ );
+ const body = (await response?.json()) as { state: string } | undefined;
+ return body?.state;
+ };
+ expect(await state("research-assistant")).toBe("ready");
+ expect(await state("general-assistant")).toBe("absent");
+ // No computer listed for it at all: asleep, never awake.
+ expect(await state("someone-else")).toBe("absent");
+ });
+
+ test("without a computer list, the status is left to the spec's handlers", async () => {
+ const handlers = extraHandlers({ agents: () => [] });
+ const response = await getResponse(
+ handlers,
+ new Request(`${ORIGIN}/api/v2/organizations/default/computers/any-bot`),
+ );
+ expect(response).toBeUndefined();
+ });
});
diff --git a/app/workbench/api/extraHandlers.ts b/app/workbench/api/extraHandlers.ts
index 3a689bb09c..d6f2395f95 100644
--- a/app/workbench/api/extraHandlers.ts
+++ b/app/workbench/api/extraHandlers.ts
@@ -62,10 +62,76 @@ const SIGNED_IN = {
},
};
+/** What the computer status answer needs from the computer list: whose it is, and whether it runs. */
+export type ListedComputer = { botId?: string; running: boolean };
+
+/**
+ * The computers the app's computer list answers, so a Bot's computer status says the same thing.
+ * Without an answer of the scene's own, the spec's example list.
+ */
+export function computersForStatus(
+ api: ApiControl,
+ path: string,
+ fallback: readonly ListedComputer[],
+): readonly ListedComputer[] {
+ const answer = api.answerFor({ method: "GET", path })?.answer;
+ if (!answer) return fallback;
+ if (answer.mode !== "value" && answer.mode !== "delay") return [];
+ const body = answer.body;
+ if (
+ typeof body !== "object" ||
+ body === null ||
+ !("computers" in body) ||
+ !Array.isArray(body.computers)
+ )
+ return [];
+ return body.computers.flatMap((computer: unknown) =>
+ typeof computer === "object" &&
+ computer !== null &&
+ "running" in computer &&
+ typeof computer.running === "boolean"
+ ? [
+ {
+ running: computer.running,
+ ...("botId" in computer && typeof computer.botId === "string"
+ ? { botId: computer.botId }
+ : {}),
+ },
+ ]
+ : [],
+ );
+}
+
export function extraHandlers(options: {
agents(): readonly string[];
+ /** The computer list the app reads; absent, the status answer is left to the spec's handlers. */
+ computers?(): readonly ListedComputer[];
}): RequestHandler[] {
+ const { computers } = options;
return [
+ /*
+ * app/src/components/bot-profile/computer-state.tsx: a Bot's computer status, said the way the
+ * computer list says it: awake while the list has a running computer for the Bot, asleep
+ * otherwise. The spec's example answered "ready" for every Bot, so the Bot's Computer page said
+ * Awake at the top and No computers yet under it.
+ */
+ ...(computers
+ ? [
+ http.get<{ organizationId: string; botId: string }>(
+ "*/api/v2/organizations/:organizationId/computers/:botId",
+ ({ params }) =>
+ HttpResponse.json({
+ botId: params.botId,
+ state: computers().some(
+ (computer) =>
+ computer.botId === params.botId && computer.running,
+ )
+ ? "ready"
+ : "absent",
+ }),
+ ),
+ ]
+ : []),
// app/src/lib/copilot/provider.tsx: CopilotKitProvider with runtimeUrl "/api/copilotkit" asks
// the runtime which agents it has. The list is read for each request, so a scene can change it.
http.get("*/api/copilotkit/info", () =>
diff --git a/app/workbench/frameBoot.ts b/app/workbench/frameBoot.ts
index d1cd3fcb5f..6be2f24495 100644
--- a/app/workbench/frameBoot.ts
+++ b/app/workbench/frameBoot.ts
@@ -14,7 +14,13 @@ import {
import { forceTheme, watchTheme } from "../../desktop/workbench/frameTheme";
import { getListBotsResponseMock } from "../src/lib/api/generated/bots/bots.msw";
import { createAgentStreams } from "./api/agentStream";
-import { agentsForBots, BOTS_ROUTE, extraHandlers } from "./api/extraHandlers";
+import { getListComputersResponseMock } from "../src/lib/api/generated/computers/computers.msw";
+import {
+ agentsForBots,
+ BOTS_ROUTE,
+ computersForStatus,
+ extraHandlers,
+} from "./api/extraHandlers";
import { installFakeApi } from "./api/fakeApi";
import { generatedHandlers } from "./api/handlers";
import { pageFallback } from "./pageDefaults";
@@ -136,6 +142,12 @@ function boot(): void {
source: "extra",
handlers: extraHandlers({
agents: () => scene.start.agents ?? agentsForBots(api, botsPath),
+ computers: () =>
+ computersForStatus(
+ api,
+ `/api/v2/organizations/${organization}/computers`,
+ getListComputersResponseMock().computers,
+ ),
}),
},
{ source: "spec", handlers: generatedHandlers() },