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={ ) : null} @@ -209,6 +239,30 @@ function useActivityGroups(agentId: string, boardAbove = false) { .filter((routine) => routine.goalId) .map((routine) => routine.id), ); + /* + * When each lined-up routine runs, in words, by the activity's id for it: a routine by its own + * schedule, a goal by the schedules of the routines that run it that are on. + */ + const scheduleOf = (item: ActivityItem): string | null => { + const all = routines.data?.routines ?? []; + const [prefix, id] = [ + item.id.slice(0, item.id.indexOf(":")), + item.id.slice(item.id.indexOf(":") + 1), + ]; + if (item.kind === "routine" && prefix === "routine") { + const routine = all.find((candidate) => candidate.id === id); + return routine ? scheduleWords(routine) : null; + } + if (item.kind === "responsibility" && prefix === "responsibility") { + const runs = all.filter( + (routine) => routine.goalId === id && routine.enabled, + ); + return runs.length + ? runs.map((routine) => scheduleWords(routine)).join(", ") + : null; + } + return null; + }; const ownCheckIns = (checkIns.data ?? []).filter( (checkIn) => checkIn.botId === agentId && checkIn.enabled, ); @@ -232,6 +286,7 @@ function useActivityGroups(agentId: string, boardAbove = false) { goalRoutineIds, ownCheckIns, groups, + scheduleOf, pending: activity.isPending || taskList.isPending, }; } @@ -374,6 +429,7 @@ function EntryRow({ blocked, botName, entry, + scheduleOf, settled, titleOf, }: { @@ -381,6 +437,8 @@ function EntryRow({ blocked: string | null; botName: string; entry: ActivityEntry; + /** When a lined-up routine or goal runs, in words, or null. */ + scheduleOf: (item: ActivityItem) => string | null; /** Under Done: a task there asks for nothing. */ settled: boolean; /** What a conversation is called, or null when the list has not reached it. */ @@ -409,7 +467,14 @@ function EntryRow({ showBot={false} /> ); - return ; + return ( + + ); } /** @@ -438,6 +503,7 @@ export function BotActivitySections({ ownCheckIns, groups, pending, + scheduleOf, } = useActivityGroups(agentId, boardAbove); const bots = useQuery(agentListQueryOptions()); const blocked = useCheckInsBlocked(); @@ -487,6 +553,7 @@ export function BotActivitySections({ "This Bot" } entry={entry} + scheduleOf={scheduleOf} settled={group.id === "done"} titleOf={titleOf} /> diff --git a/app/src/components/bot-profile/computer-state.tsx b/app/src/components/bot-profile/computer-state.tsx new file mode 100644 index 0000000000..a93dcd0a16 --- /dev/null +++ b/app/src/components/bot-profile/computer-state.tsx @@ -0,0 +1,93 @@ +import { useQuery } from "@tanstack/react-query"; +import { IconDeviceDesktop } from "@/components/icons"; +import { PageRows } from "@/components/layout/page-shell"; +import { + Item, + ItemContent, + ItemDescription, + ItemMedia, + ItemTitle, +} from "@/components/ui/item"; +import { + type ComputerState, + computerStatusQueryOptions, +} from "@/lib/computers/queries"; +import { useNoBotComputers } from "@/lib/deployment/queries"; +import { cn } from "@/lib/utils"; + +/** How often a computer on its way up is read again, until it is up. */ +const STARTING_POLL_MS = 5_000; + +/** What the card says for each state, and the dot on its icon. */ +const SAID: Record< + ComputerState, + { title: string; description: string; dot: string } +> = { + absent: { + title: "Asleep", + description: "It starts when this Bot next needs it.", + dot: "bg-muted-foreground", + }, + starting: { + title: "Starting", + description: "It's on its way up. A first start takes about a minute.", + dot: "animate-pulse bg-success motion-reduce:animate-none", + }, + ready: { + title: "Awake", + description: "It's ready for this Bot's work.", + dot: "bg-success", + }, + unreachable: { + title: "Not answering", + description: "OpenBot can't reach this computer right now.", + dot: "bg-destructive", + }, +}; + +function said(state: string | undefined) { + return state !== undefined && Object.hasOwn(SAID, state) + ? SAID[state as ComputerState] + : null; +} + +/** + * The top of a Bot's Computer page: whether its computer is on, as one card. Before, the page began + * with settings and never said whether the computer was asleep or awake. + * + * Read from the status route, which never wakes a computer, so opening this page doesn't start one. + * Nothing is drawn where there are no computers for Bots, while the state is unread, when it can't be + * read, or for a state a newer server sends that this app doesn't know. + */ +export function BotComputerState({ agentId }: { agentId: string }) { + const noComputers = useNoBotComputers(); + const status = useQuery({ + ...computerStatusQueryOptions(agentId), + enabled: noComputers === false, + retry: false, + refetchInterval: (query) => + query.state.data?.state === "starting" ? STARTING_POLL_MS : false, + }); + const shown = said(status.data?.state); + if (noComputers !== false || !shown) return null; + return ( + + + + + + + {shown.title} + {shown.description} + + + + ); +} diff --git a/app/src/components/bot-profile/routines-summary.tsx b/app/src/components/bot-profile/routines-summary.tsx index 137d1f3c02..8618bfb4b4 100644 --- a/app/src/components/bot-profile/routines-summary.tsx +++ b/app/src/components/bot-profile/routines-summary.tsx @@ -1,24 +1,32 @@ import { useQuery } from "@tanstack/react-query"; import { Link } from "@tanstack/react-router"; -import { AnimatePresence } from "motion/react"; +import { Fragment } from "react"; import { PageRows, PageSection } from "@/components/layout/page-shell"; -import { GroupRow } from "@/components/routines/bot-group"; -import { Unfold } from "@/components/routines/unfold"; +import { RoutineRow, routineCount } from "@/components/routines/routine-row"; import { Button } from "@/components/ui/button"; +import { Separator } from "@/components/ui/separator"; import { loadFailure } from "@/lib/load-failure"; import { proactiveSettingsQueryOptions } from "@/lib/proactive"; import { responsibilitiesQueryOptions } from "@/lib/responsibilities"; -import { runningAndScheduled } from "@/lib/routines/by-bot"; -import { mergeRoutines } from "@/lib/routines/merged"; +import { sortedRows } from "@/lib/routines/by-bot"; +import { type MergedRoutine, mergeRoutines } from "@/lib/routines/merged"; import { routinesQueryOptions } from "@/lib/routines/queries"; -/** How many rows the Bot's page shows before See all. */ +/** How many rows the Bot's page shows before All routines. */ const SHOWN = 5; +/** A goal that is completed has nothing to switch back on, so the Bot's page leaves it out. */ +function completed(row: MergedRoutine): boolean { + return row.kind === "goal" && row.goal.status === "completed"; +} + /** - * A Bot's routines on its own page, under For you: what is running now and what is lined up next, - * as the Routines page draws them, with See all to the Bot's Routines. Not drawn for a Bot with no - * routines, which its Routines row under Settings already says. + * A Bot's routines on its own page, under For you, in the Routines page's own rows + * (`RoutineRow`): each says where it stands and has its on/off switch, changed right here. Running + * and lined-up ones first, then the paused ones, as the Routines page orders them. At most five, + * then All routines with the total, to the Bot's Routines. Before, paused routines were left out and + * nothing could be switched here. Not drawn for a Bot with no routines, which its Routines row under + * Settings already says. */ export function BotRoutinesSummary({ agentId }: { agentId: string }) { const routines = useQuery(routinesQueryOptions()); @@ -33,18 +41,15 @@ export function BotRoutinesSummary({ agentId }: { agentId: string }) { }).filter((row) => row.agentId === agentId); const failed = [routines.error, goals.error, checkIns.error].find(Boolean); if (all.length === 0 && !failed) return null; - const shown = runningAndScheduled(all, agentId).slice(0, SHOWN); + const listed = sortedRows(all.filter((row) => !completed(row))); + const shown = listed.slice(0, SHOWN); return ( } - size="sm" - variant="ghost" - > - See all - + + {routineCount(listed.length)} + } title="Routines" > @@ -58,20 +63,27 @@ export function BotRoutinesSummary({ agentId }: { agentId: string }) {

) : null} {shown.length > 0 ? ( - - - {shown.map((row) => ( - - - - ))} - + + {shown.map((row, index) => ( + + {index > 0 ? : null} + + + ))} ) : failed ? null : (

- Nothing running or scheduled. + Every goal this Bot had is completed.

)} +
); } diff --git a/app/src/components/bot-profile/setup-fields.tsx b/app/src/components/bot-profile/setup-fields.tsx index a6b68a12d0..c48da81678 100644 --- a/app/src/components/bot-profile/setup-fields.tsx +++ b/app/src/components/bot-profile/setup-fields.tsx @@ -1,5 +1,6 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import { Link, useNavigate } from "@tanstack/react-router"; +import type * as React from "react"; import { useId, useState } from "react"; import type { ZodType } from "zod"; import { @@ -11,7 +12,12 @@ import { } from "@/components/icons"; import { PageCard, PageShell } from "@/components/layout/page-shell"; import { Button } from "@/components/ui/button"; -import { Field, FieldLabel } from "@/components/ui/field"; +import { + Field, + FieldError, + FieldGroup, + FieldLabel, +} from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { @@ -43,6 +49,8 @@ export type SetupField = { icon: typeof IconId; /** Said under the screen's title, where the label alone doesn't say what the field is for. */ description?: string; + /** An example in the empty field, so a person sees the kind of answer it takes. */ + placeholder?: string; multiline?: boolean; /** A web address: the URL keyboard, monospace like the row it edits, nothing corrected. */ address?: boolean; @@ -57,6 +65,7 @@ export const IDENTITY_FIELDS: readonly SetupField[] = [ field: "name", label: "Name", icon: IconId, + placeholder: "Expense Review", schema: agentFormSchema.shape.name, }, { @@ -64,6 +73,7 @@ export const IDENTITY_FIELDS: readonly SetupField[] = [ field: "title", label: "Title", icon: IconTag, + placeholder: "Research, marketing, admin", schema: agentFormSchema.shape.title, }, { @@ -75,6 +85,7 @@ export const IDENTITY_FIELDS: readonly SetupField[] = [ // told is the row below. label: "What it does", icon: IconTextCaption, + placeholder: "What should this Bot help with?", multiline: true, schema: agentFormSchema.shape.roleDescription, }, @@ -84,6 +95,7 @@ export const IDENTITY_FIELDS: readonly SetupField[] = [ field: "instructions", label: "Instructions", icon: IconNotes, + placeholder: "What should this Bot always keep in mind?", multiline: true, schema: agentFormSchema.shape.instructions.unwrap(), }, @@ -334,3 +346,168 @@ function FieldForm({ ); } + +/** + * 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 ( +
{ + event.preventDefault(); + void submit(); + }} + > + + {saved && changed.length === 0 ? ( + + Saved. + + ) : null} + + + } + > + + {fields.map((entry) => { + const id = `${baseId}-${entry.slug}`; + const error = errors[entry.slug]; + const errorId = `${id}-error`; + const common = { + id, + onChange: ( + event: React.ChangeEvent< + HTMLInputElement | HTMLTextAreaElement + >, + ) => { + const value = event.target.value; + setSaved(false); + setDrafts((current) => ({ ...current, [entry.slug]: value })); + }, + placeholder: entry.placeholder, + value: draftOf(entry), + ...(error + ? { "aria-invalid": true, "aria-describedby": errorId } + : {}), + }; + return ( + + {entry.label} + {entry.multiline ? ( + // Grows with what it holds up to a bound, then scrolls inside. +