Skip to content

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.

Show what a Bot can draw, and put every request behind one client (#60)

Guido Vizosoa5450a7c0265
diff --git a/.claude/skills/openbot-data-access/SKILL.md b/.claude/skills/openbot-data-access/SKILL.md
new file mode 100644
index 00000000..75ca44bc
--- /dev/null
+++ b/.claude/skills/openbot-data-access/SKILL.md
@@ -0,0 +1,292 @@
+---
+name: openbot-data-access
+description: Governs how the OpenBot browser app reads and writes server data — every request goes through `client` in app/src/lib/client.ts, every read is a queryOptions factory in app/src/lib/<entity>/queries.ts, every write is a mutationOptions factory in app/src/lib/<entity>/mutations.ts, and components consume them through useQuery/useMutation. Use when adding or changing a screen that loads server data, calling a /api/... endpoint from the browser, adding a query key, writing a create/update/delete flow, deciding where a fetch belongs, or reviewing a diff that contains the word fetch under app/src. Don't use for server-side route handlers under server/ (that is not browser code), for form validation schemas (those live in lib/<entity>/form.ts), for page layout and Item rows, or or for the AG-UI stream itself, which the runtime carries rather than the client.
+---
+
+# OpenBot Data Access
+
+## When To Use
+
+This skill applies to any change under `app/src` that moves data between the browser and the API
+server. It fires on new screens, new endpoints, new query keys, and on any diff that introduces
+`fetch` anywhere but `app/src/lib/client.ts`.
+
+It does not cover server handlers under `server/`, zod form schemas (`lib/<entity>/form.ts`), or page
+layout. It does cover `lib/copilot/`: the conversation itself streams over AG-UI, but the tool calls a
+Bot makes during a turn are ordinary authenticated requests and go through the client like everything
+else.
+
+## The Shape
+
+Every entity the browser knows about owns a directory under `app/src/lib/`:
+
+```
+app/src/lib/
+ client.ts # the only fetch in the app
+ <entity>/
+ queries.ts # read types, key factory, queryOptions factories
+ mutations.ts # input type, mutationOptions factories
+ form.ts # zod schema (a different skill's territory)
+```
+
+`client.ts` owns the transport: credentials, the JSON content type, body serialisation, and turning a
+failed status into an `Error` carrying the server's own message. It owns nothing about meaning — the
+envelope key and the sentence a person reads stay at the call site, because those are facts about one
+endpoint rather than about requests in general.
+
+```ts
+client<T>(path, key, options?): Promise<T> // parsed, and `key` unwrapped
+client(path, options?): Promise<Response> // for a caller that only needed it to work
+tryClient(path, options?): Promise<Response> // never throws; the status is the answer
+```
+
+`options` is `{ method?, body?, fallback?, signal? }`. `body` is serialised by the client, which is
+also what sets the content type — so a caller passes an object, never a string. Passing
+`JSON.stringify(x)` sends a JSON string of a JSON string, which no endpoint accepts.
+
+### Three kinds of request
+
+Not everything crossing the wire is cached state, and the shape follows from which kind it is.
+
+1. **A cached read** is a `queryOptions` factory in `queries.ts`. It has a key, and something can
+ invalidate it.
+2. **A write somebody asked for** is a `mutationOptions` factory in `mutations.ts`. It invalidates on
+ success.
+3. **Everything else is a plain exported function**, living beside the factories for its entity.
+ A verdict about this moment (`decideComponent`, `testAgentConnection`), a tool call during a
+ Bot's turn (`callPluginTool`, the computer control surface), a frame of a screen, a step inside
+ another write (`storeMcpToken`). These fail closed and return a value rather than throwing,
+ because a refusal is usually the answer. Giving one a cache key would create a key nothing reads
+ and an invalidation nothing triggers.
+
+The third kind still lives under `lib/`. It is not licence to call the server from a component.
+
+There are thirteen of these today — `agents`, `audit`, `auth`, `channels`, `components`, `computers`,
+`connectors`, `credentials`, `package`, `plugins`, `sandboxed`, `skills`, `copilot`. They all look the
+same on purpose. `lib/agents/queries.ts` and `lib/agents/mutations.ts` are the reference pair; read them
+before writing a new one.
+
+**The one rule that matters:** a React component never calls `fetch`. If a component file contains
+`fetch`, the change is wrong regardless of whether it works.
+
+## Procedures
+
+### Procedure 1: Add a read
+
+1. Create or open `app/src/lib/<entity>/queries.ts`.
+2. Declare the browser-shaped type for the payload — `<Entity>Profile`, `<Entity>Status`,
+ `<Entity>Summary`, or `<Entity>Record`, matching whichever sibling name fits. This type describes
+ what the browser receives, not what the database stores.
+3. Include the server's authorization verdicts as fields on that type (`canManage`, `systemOwned`,
+ `mine`, `hasAuth`) and document them. The browser renders these flags; it never recomputes
+ ownership or permission rules from other fields.
+4. Never put a secret's value in a read type. A credential is `hasAuth: boolean` or a
+ `revokedAt` timestamp. Secrets are write-only in this codebase.
+5. Add or extend the key factory, named `<entity>Keys`:
+
+ ```ts
+ export const agentKeys = {
+ all: ["agents"] as const,
+ list: (hidden = false) => ["agents", "list", { hidden }] as const,
+ detail: (agentId: string) => ["agents", "detail", agentId] as const,
+ };
+ ```
+
+ `all` is always the bare entity name and is the invalidation root. List keys carry their
+ parameters as a trailing object so two filters are two cache entries. Every array is `as const`.
+ A single-key entity still gets a factory: `export const packageKeys = { active: ["tenant-package", "active"] as const };`.
+
+6. Export a factory function returning `queryOptions({ queryKey, queryFn })`, named
+ `<subject>QueryOptions`. Existing spellings: `agentListQueryOptions`, `agentQueryOptions`,
+ `agentComponentsQueryOptions`, `activePackageQueryOptions`.
+7. Inside `queryFn`, call `client` with the path, the envelope key, and a `fallback` sentence. It
+ sends the credentials, checks the status, raises the server's message when there is one, and
+ unwraps the key so the caller receives the payload rather than the wrapper:
+
+ ```ts
+ queryFn: (): Promise<AgentProfile[]> =>
+ client("/api/agents", "agents", { fallback: "Could not load coworkers" }),
+ ```
+
+ Where the whole body is the payload, omit the key and read it: `(await client(path, { fallback
+ })).json()`. Where a failed status is an *answer* rather than an error — a refused component call,
+ a 401 that means "not signed in" — use `tryClient` and read the status.
+
+8. Annotate the `queryFn` return type explicitly (`(): Promise<AgentProfile[]>`). `client` is generic
+ in its payload, so the annotation is what fixes what the key unwraps to.
+
+### Procedure 2: Add a write
+
+1. Create or open `app/src/lib/<entity>/mutations.ts`.
+2. Declare the input type as `<Entity>Input` — the shape the API accepts, which is not the form's
+ shape. Mapping between them is `form.ts`'s job (`agentInputFrom`).
+3. Call `client`. Do **not** write a per-entity request helper — `agentRequest`,
+ `componentRequest` and two others each owned a private copy of the same credentials, headers and
+ error extraction, and one of the four had quietly dropped the extraction. `client` owns it now:
+
+ ```ts
+ mutationFn: (input: AgentInput): Promise<AgentProfile> =>
+ client("/api/agents", "agent", { method: "POST", body: input, fallback: FALLBACK }),
+ ```
+
+ Where the write returns nothing a caller needs, omit the key and `await client(path, { ... })`.
+ Keep one `const FALLBACK` per file rather than repeating the sentence: the reader of the failure
+ cares which entity failed, and within one file that never changes.
+
+4. Export one factory per write, named `<verb><Entity>MutationOptions(queryClient)`, returning
+ `mutationOptions({ mutationFn, onSuccess })`. Existing spellings: `createAgentMutationOptions`,
+ `updateAgentMutationOptions`, `duplicateAgentMutationOptions`, `setAgentHiddenMutationOptions`,
+ `deleteAgentMutationOptions`.
+5. Give `mutationFn` exactly one parameter. For a single value that is the value
+ (`agentId: string`); for more than one it is a named `variables` object
+ (`{ agentId: string; input: AgentInput }`).
+6. Invalidate on success — never patch the cache by hand:
+
+ ```ts
+ onSuccess: () => queryClient.invalidateQueries({ queryKey: agentKeys.all })
+ ```
+
+ With several writes in one file, wrap that in a private `invalidate<Entity>(queryClient)` helper.
+ Server-derived fields are the reason: a hand-patched cache entry is a guess at what the server
+ decided, and it is wrong the first time the server adds a rule.
+7. `queryClient.removeQueries` instead of `invalidateQueries` when the data should stop existing
+ rather than be refetched. Sign-out is the only current case
+ (`lib/auth/mutations.ts`).
+8. A fire-and-forget write takes no `queryClient` and has no `onSuccess`
+ (`recordChannelActivityMutationOptions`). Deliberate, and it carries a comment saying why the
+ failure is acceptable. Do not reach for this to avoid writing error handling.
+
+### Procedure 3: Consume from a component
+
+1. Import the factories, never the endpoint — and import the `queryClient`, never call
+ `useQueryClient()`:
+
+ ```ts
+ import { queryClient } from "@/query-client";
+
+ const credentials = useQuery(credentialListQueryOptions());
+ const createCredential = useMutation(createCredentialMutationOptions(queryClient));
+ ```
+
+2. **`useQueryClient()` is not the convention here.** There is exactly one client: constructed at
+ module scope in `app/src/query-client.ts` and handed to both `QueryClientProvider` and the router
+ context in `main.tsx`. The hook therefore resolves to the same object the import already holds,
+ at the cost of a hook call and a `const` line. The import also works where a hook cannot — a
+ plain event handler, a module with no component around it, a test — which is why mutation
+ factories take a `QueryClient` parameter rather than reaching for the hook themselves.
+3. Import with the `@/` alias — `@/lib/credentials/queries`, not `../../../lib/credentials/queries`.
+ Both spellings exist in the tree today; the alias is the correct one.
+4. Branch on all four states in order, every time — pending, error, empty, rows — and never
+ dereference `data` without having handled the first three:
+
+ ```tsx
+ {credentials.isPending ? null : credentials.error ? (
+ <p className="text-destructive text-sm" role="alert">Could not load credentials.</p>
+ ) : credentials.data?.length === 0 ? (
+ <PageEmpty>No credentials are configured.</PageEmpty>
+ ) : (
+ <PageRows>{/* rows */}</PageRows>
+ )}
+ ```
+
+5. **The pending branch renders nothing.** OpenBot has no loading placeholder — no "Loading…"
+ text, no spinner, no skeleton, no shimmer. The section's heading is already on screen; what
+ arrives underneath it is the answer, and a placeholder that appears and vanishes inside a
+ local round-trip is a flicker rather than information. A few screens still carry
+ `<PageEmpty>Loading …</PageEmpty>` and one carries a `Skeleton` block, both from before this
+ decision. They are not the pattern to copy.
+6. `isPending` is still branched on, and branched on **first**. Deleting the branch instead of
+ returning `null` from it would show the empty-state sentence — "No credentials are
+ configured." — for the whole duration of the fetch, which states something false.
+7. This says nothing about mutations. A button the person just pressed still says `"Saving…"` or
+ `"Deleting…"`, because that is feedback for an action they took rather than a placeholder for
+ data they are waiting on. Derive it from the mutation, not from `useState`:
+ `disabled={... || createCredential.isPending}`.
+8. Read `credentials.tsx` in `app/src/routes/_authed/admin/` for the whole pattern end to end —
+ with the caveat that its pending branch still renders text.
+
+### Procedure 4: Preload in a route
+
+1. When data gates navigation, load it in `beforeLoad` with `ensureQueryData` and the same options
+ factory the component uses:
+
+ ```ts
+ const user = await context.queryClient.ensureQueryData(currentUserQueryOptions());
+ if (!user) throw redirect({ to: "/sign" });
+ ```
+
+2. The factory is shared between the guard and the component on purpose — one key, one fetch, and
+ the component's `useQuery` is already warm.
+3. Authorization decided here, not inside a component (`routes/_authed.tsx`,
+ `routes/_authed/admin/route.tsx`).
+4. Inside `beforeLoad` and `loader`, use `context.queryClient` — the router's typed handle, and the
+ same singleton `main.tsx` put there. No import needed at those two call sites; everywhere else,
+ import it.
+
+## Decision Tree
+
+- Adding a screen that displays server data → Procedure 1, then Procedure 3.
+- Adding a create, update, delete, or toggle → Procedure 2, then Procedure 3.
+- The data decides whether the person is allowed on the page at all → Procedure 4.
+- Changing an existing payload's shape → Procedure 1, step 2, and check every consumer of the type.
+- Filtering or paginating an existing list → Procedure 1, step 5: a new parameter goes in the
+ trailing object of the list key, not into a second key factory.
+- The data is form input rather than server state → not this skill; `lib/<entity>/form.ts`.
+- The data arrives over the CopilotKit runtime → not this skill; `lib/copilot/`.
+
+## Red Flags
+
+| Signal | What it means | Do instead |
+|--------|---------------|------------|
+| `fetch(` anywhere but `lib/client.ts` | Either the read has no key and nothing can invalidate it, or the transport has been rewritten by hand | Move it into `lib/<entity>/` behind a factory, and call `client` |
+| A module-private `<entity>Request` helper | Superseded. Four of these existed and one had lost its `body.error` extraction | Call `client` |
+| `client` on an endpoint whose refusal is an answer | Turns the boundary working into an exception the caller has to catch | `tryClient`, and read the status |
+| `body: JSON.stringify(x)` at a call site | Double-encoded; the client serialises | Pass the object |
+| A one-shot tool call written as a `mutationOptions` factory | Gets a `queryClient` and an invalidation it has no use for | A plain function beside the factories |
+| A `fallback` sentence repeated on every write in a file | The reader cares which entity failed, and that does not change within a file | One `const FALLBACK` per file |
+| `<PageEmpty>Loading …</PageEmpty>`, a spinner, or a `Skeleton` while a query is pending | OpenBot uses no loading placeholder; the flicker costs more than the reassurance buys | Return `null` from the pending branch |
+| The pending branch deleted rather than returning `null` | The empty-state sentence shows for the length of the fetch, asserting something false | Keep the branch, first in the chain, returning `null` |
+| `const queryClient = useQueryClient()` | A hook call and a local binding for an object that is one import away, and unavailable outside a component | `import { queryClient } from "@/query-client"` |
+| `new QueryClient()` anywhere outside `app/src/query-client.ts` | A second cache; queries written by one client are invisible to the other | Import the singleton. A test needing isolation constructs its own and passes it explicitly |
+| `useQuery({ queryKey: ["agents"], ... })` at a call site | An inline key drifts from the factory and silently stops matching invalidations | Call the factory: `useQuery(agentListQueryOptions())` |
+| `queryClient.setQueryData(...)` after a mutation | Guesses at server-derived fields; wrong the moment the server adds a rule | `invalidateQueries({ queryKey: <entity>Keys.all })` |
+| A component computing `user.role === "admin" && thing.ownerId === user.id` | Duplicates an authorization rule that the server already decided | Render the server's flag (`canManage`, `mine`) |
+| A read type carrying a token, key, or `plaintext` | Secrets are write-only in OpenBot | Expose `hasAuth: boolean` or a `revokedAt` timestamp |
+| A hand-written `body.error` extraction | `client` already does it, and did it more consistently than the four copies did | Pass `fallback` and let it raise |
+| `queryFn` returning `{ agents: [...] }` | Leaks the transport envelope into every component | Unwrap in the `queryFn`; components see the array |
+| A second `<entity>Keys` object, or keys defined in `mutations.ts` | Two sources of truth for one cache namespace | One factory per entity, in `queries.ts`; `mutations.ts` imports it |
+
+## Error Handling
+
+- **A 401 in a `queryFn`**: `client` sends the credentials, so a 401 means the session expired — the
+ `_authed` guard handles the redirect on the next navigation. Do not add per-query redirect logic.
+ The one place a 401 is expected is `currentUserQueryOptions`, which uses `tryClient` because not
+ being signed in is an answer there rather than a failure.
+- **The server returns no `error` field**: `client` falls back to the `fallback` option. Name the
+ entity in it ("Could not load coworkers"). Do not print a status code to a person.
+- **A refusal arrives as a thrown `Error` instead of a value**: the call site used `client` where it
+ needed `tryClient`. The gateway declining is the product working, not a fault.
+- **The server rejects a body it should accept, or reads it as a string**: something stringified
+ before handing it over. `client` serialises; a caller passes the object.
+- **An invalidation does not refresh the list**: the key at the call site does not match the key the
+ mutation invalidated. Both must come from the same `<entity>Keys` factory. Check for an inline key
+ array before anything else.
+- **Two filters of the same list overwrite each other's cache**: the parameter is missing from the
+ list key. Add it to the trailing object (`list: (hidden = false) => [..., { hidden }]`).
+- **A mutation succeeds but the screen shows stale server-derived fields**: something patched the
+ cache instead of invalidating it. Remove the patch.
+- **TypeScript cannot infer the `queryFn` return**: the explicit `Promise<T>` annotation is missing
+ from the `queryFn` signature. Add it rather than casting at the call site.
+- **"No X are configured." flashes before the list appears**: the pending branch is missing, or it
+ sits after the empty check. It goes first and returns `null`.
+- **A query is slow enough that the blank feels broken**: the answer is not a placeholder, it is a
+ slow endpoint. Fix the endpoint, or preload the data in the route (Procedure 4) so the screen is
+ not entered until it is there.
+- **A mutation factory is needed where no hook can run** — a bare event handler, a module with no
+ component around it, a `bun test` file: import `queryClient` from `app/src/query-client.ts` and
+ pass it in. This is the reason the singleton is the convention rather than the hook.
+- **An invalidation appears to do nothing and the keys do match**: two clients exist. Search for
+ `new QueryClient(` outside `app/src/query-client.ts`.
+- **Unsure which entity directory a new endpoint belongs to**: name it after the noun the URL is
+ about (`/api/agents/:id/plugins` is `plugins`, keyed by agent). If no existing directory fits,
+ create one with the same three-file shape rather than adding the read to a neighbour.
diff --git a/.claude/skills/openbot-screen-layout/SKILL.md b/.claude/skills/openbot-screen-layout/SKILL.md
new file mode 100644
index 00000000..a8e5f96c
--- /dev/null
+++ b/.claude/skills/openbot-screen-layout/SKILL.md
@@ -0,0 +1,211 @@
+---
+name: openbot-screen-layout
+description: The default layout for every OpenBot configuration screen — PageShell and its prose/wide widths, PageSection and PageRows, Item row composition, the settings-row pattern where a summary and a chevron open a dialog, and the size and variant vocabulary. This is what a new screen looks like unless an instruction says otherwise. Use when adding or changing a screen under app/src/routes, adding a row to an admin or settings page, choosing a Button or Item size, picking between a bordered and a filled row, laying out a dialog, or reviewing a diff that adds max-w-*, a hand-drawn card, or a new spacing scale under app/src. Don't use for where the data comes from (that is openbot-data-access), for the gallery components under components/gallery that a Bot draws, for the chat and channel surfaces, or for editing the primitives under components/ui themselves.
+---
+
+# OpenBot Screen Layout
+
+## When To Use
+
+This skill applies to any change under `app/src/routes` that puts a configuration screen on the
+screen — a new admin page, a new settings section, a new row on an existing page, a detail page
+behind a list. Twelve screens render through `PageShell` today and seven build their rows out of
+`Item`; all of them look the same on purpose.
+
+It does not cover where the data comes from — that is `openbot-data-access`, which owns queries,
+mutations, and the pending/error/empty/rows branching. It does not cover the gallery components
+under `components/gallery`, which a Bot draws inside a conversation rather than a person navigating
+to. It does not cover the primitives under `components/ui`, which are shadcn files with their own
+upstream.
+
+## The Default
+
+**A new screen uses this layout. Deviating from it needs a reason given in the request.**
+
+This is the point of the skill. The decisions here — the width, the spacing, the heading sizes, the
+row anatomy, which control means what — are already made, and they are already made the same way on
+every other screen. Somebody who does not work in the frontend should be able to add a page that
+looks like it belongs without making a single visual decision, by reaching for `PageShell`,
+`PageSection`, `PageRows` and `Item` and filling them in.
+
+The failure this prevents is the one the `PageShell` doc comment describes: Admin was once nine pages
+that shared no layout — four container widths, four heading sizes, four padding schemes, three of
+them drawing their own buttons and inputs. It did not read as a different screen, it read as a
+different application, at exactly the moment an administrator was deciding whether to trust it with
+credentials.
+
+So: no hand-drawn containers, no new widths, no new spacing scale, no second way to draw a row. If
+the screen genuinely does not fit — a table, a canvas, an editor beside a live preview — that is a
+deviation worth stating out loud and worth a comment saying why.
+
+## The Shape
+
+Four components make the frame. They compose in this order and nest no other way.
+
+```
+PageShell the page: header (title, description, action, backButton) then children
+ PageSection a titled group of unrelated decisions, with a deliberately large gap above it
+ PageRows the grouped card: rounded-lg border bg-card
+ Item one row, size="sm", divided from its neighbours by <Separator />
+ PageEmpty what a section says when it has nothing to list
+```
+
+`PageShell` takes a `width`: `prose` (`max-w-2xl`) is the default because configuration is mostly
+reading, and a row of label-and-control has no business being wider than the sentence explaining it.
+`wide` (`max-w-5xl`) exists for one screen — `admin/audit.tsx`, because an audit log is a table to be
+scanned and prose width would wrap every row. It is not a licence for anything else to be wide.
+
+`PageEmpty` is a sentence, not an illustration with a heading. On a configuration screen "nothing
+here yet" is a fact, and the section heading already said what the section is for.
+
+## Procedures
+
+### Procedure 1: Lay out a screen
+
+1. Open with `PageShell`, giving it `title` and `description`. Leave `width` alone.
+2. On a detail screen reached from a list, pass `backButton={{ label, linkProps }}` — it draws a
+ chevron-left bar above the header. Do not put a Back button in `action`; `action` is for the
+ page's one primary verb, on the title's baseline.
+3. Group the page's decisions into `PageSection`s, each with a `title` and, where the grouping is not
+ self-evident, a `description`.
+4. Give each section one `PageRows` card. Rows go inside it as `Item size="sm"`, with `<Separator />`
+ between them and none after the last. `PageRows` is a card with dividers, not a stack of cards —
+ gaps between rows are the wrong shape.
+5. Read `admin/connectors.tsx` for the whole pattern end to end, and
+ `admin/components/$name.tsx` for a screen with two sections and mixed row kinds.
+
+### Procedure 2: Compose a row
+
+1. `ItemMedia variant="icon"` holds a leading icon from `@tabler/icons-react`. It is what makes a
+ card of rows scannable; a row without one reads as a paragraph.
+2. `ItemContent` holds `ItemTitle` and, where the row needs a second line, `ItemDescription`.
+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
+ `className="line-clamp-none"`.
+6. To make the whole row navigate or open something, pass `render`:
+ `render={<button type="button" onClick={…} />}` or `render={<Link to=… />}`. A real element, so
+ the keyboard reaches it and a link can be opened in a new tab.
+
+**The one mistake this makes easy:** the element passed to `render` must have **no children**.
+`useRender` merges props, and children given there replace the row's own — the media, the content
+and the actions all vanish and the row draws empty. The button takes its accessible name from the
+title and description inside it.
+
+### Procedure 3: Choose what a row does
+
+Every row is one of three kinds. Picking the wrong one is the most common way one of these screens
+starts to feel wrong.
+
+1. **Binary, immediate** — a `Switch` in `ItemActions`. It takes effect when switched; there is no
+ save. `ItemDescription` states the consequence in the present tense ("Bots may answer with it." /
+ "No Bot may use it.").
+2. **Anything larger** — a free-text field, a set of grants, more than one input — is a summary in
+ `ItemDescription` plus `<IconChevronRight className="size-4 text-muted-foreground" />` in
+ `ItemActions`, and the row opens a dialog. Editing more than one value in place turns a settings
+ screen back into a form.
+3. **Read-only** — the value in `ItemActions`, no chevron, nothing to click. A chevron on a row that
+ goes nowhere is a promise the row cannot keep.
+
+The summary on a chevron row states the current answer, not the field's name: "All 3 Bots", "2 of 3
+Bots", "Nothing — it draws only what the model hands it". Compute it from the query so it updates
+itself when the dialog changes something.
+
+### Procedure 4: Sizes and variants
+
+1. `Item size="sm"` for rows inside a card. `default` only for a row standing on its own.
+2. `Button size="sm"` for a control inside a row or a dialog footer; `lg` for a page's own actions;
+ `icon-sm` for a control floating over artwork.
+3. `Item variant` — pick **one for the whole screen**. `muted` is a fill with no border; `outline` is
+ a border with no fill; `default` is neither. Mixing two of them on one screen reads as two
+ different kinds of list, and the reader looks for a distinction that is not there.
+4. `bg-card` is invisible inside a dialog. `--card` and `--popover` resolve to the same colour in
+ both themes, so a card-coloured row against a popover is no row at all. Use `muted`.
+
+### Procedure 5: Lay out a dialog
+
+1. `DialogContent` defaults to `max-w-lg` and `max-h-[85svh]` with `p-5`. Header, body and footer go
+ in as `DialogHeader` / `DialogBody className="mt-4"` / `DialogFooter className="mt-4"`.
+2. `DialogBody` must stay a **direct child** of `DialogContent`. Wrapping the three sections in one
+ padded div breaks the `flex-1 min-h-0` chain and the body stops scrolling.
+3. `DialogBody` carries `flex-1 min-h-0` and **no overflow of its own**, despite a comment saying it
+ scrolls. Any dialog tall enough to need it passes `overflow-y-auto` explicitly; without it the
+ body shrinks and paints its content over the footer.
+4. For artwork reaching the dialog's edges: `className="p-0 gap-0 overflow-hidden"` on
+ `DialogContent`, each section carrying its own padding, and `overflow-hidden` handing the popup's
+ rounding to the artwork's corners. Pass `showCloseButton={false}` and supply a close button with
+ its own backing — the built-in one is a ghost button in the foreground colour and disappears over
+ a pale image.
+
+## The rem Trap
+
+`app/src/styles.css` sets `html { font-size: 15px }`. Every rem-based Tailwind token is therefore
+**0.9375×** its documented pixel value:
+
+| Token | Documented | Actual here |
+|-------|-----------|-------------|
+| `max-w-2xl` | 672px | **630px** |
+| `max-w-3xl` | 768px | **720px** |
+| `max-w-5xl` | 1024px | **960px** |
+
+Never hardcode a pixel constant derived from a Tailwind rem token, and never compute a ratio from
+one. Measure the element — `offsetWidth`, `clientWidth`, a `ResizeObserver` — and scale from what is
+actually on screen. A constant taken from the Tailwind docs is wrong by 6.25% here, which is enough
+to sit a centred element visibly off centre or clip a card's corners against its container.
+
+## Decision Tree
+
+- Adding a screen → Procedure 1, then Procedure 2 for each row.
+- Adding a row to an existing screen → Procedure 2, then Procedure 3 to pick its kind.
+- The row toggles one thing → Procedure 3, kind 1: a `Switch`, no save.
+- The row edits text, or a set of grants, or more than one value → Procedure 3, kind 2: a summary, a
+ chevron, and a dialog. Then Procedure 5.
+- The row only states something → Procedure 3, kind 3: a value and no chevron.
+- Unsure which `Item` size, `Button` size, or `variant` → Procedure 4.
+- A width, ratio or scale needs a number in pixels → the rem Trap section. Measure, do not assume.
+- The screen genuinely does not fit this shape → say so in the response and comment the reason in the
+ code. A table is the one accepted precedent (`admin/audit.tsx`, `width="wide"`).
+- The question is which states the screen renders while loading or failing → not this skill;
+ `openbot-data-access`, Procedure 3.
+
+## Red Flags
+
+| Signal | What it means | Do instead |
+|--------|---------------|------------|
+| A hand-written `rounded-lg border border-border bg-card` div wrapping rows | `PageRows` re-implemented, and it will drift from the other seven screens | Use `PageRows` |
+| Rows separated by `gap-*` instead of `<Separator />` | A stack of cards rather than one card of rows | `<Separator />` between rows, none after the last |
+| `width="wide"` on anything that is not a table | Prose width is the default for a reason; wide was for the audit log | Leave `width` alone |
+| A `max-w-*`, `p-*` or text size invented for one screen | A fifth container width, which is what this layout exists to stop | Reach for the existing component |
+| Children on an element passed to `Item`'s `render` | They replace the row's own children; the row draws empty | Pass a childless element |
+| `bg-card` on a row inside a dialog | `--card` equals `--popover`; the row is invisible | `variant="muted"` |
+| `Item variant="outline"` and `variant="muted"` on one screen | Reads as two kinds of list and invites a distinction that is not there | One variant per screen |
+| A pixel constant matching a Tailwind rem token (672, 768, 1024) | Assumes a 16px root; the root here is 15px | Measure the element |
+| A `Switch` on a row that needs two or more values | Half the change happens in place and half in a dialog | A summary, a chevron, and a dialog |
+| A chevron on a row that opens nothing | Announces a destination that does not exist | Value in `ItemActions`, no chevron |
+| A set of chips or toggles crammed into `ItemActions` | It competes with the label for width and wraps badly | `ItemFooter`, which is `basis-full` |
+| A back link in `PageShell`'s `action` | `action` is the page's primary verb, on the title's baseline | `backButton={{ label, linkProps }}` |
+
+## Error Handling
+
+- **A row renders empty — media, title and actions all missing**: children were passed on the
+ element given to `Item`'s `render`. Remove them.
+- **A row's content sits visibly off centre, or a card's corners are clipped by its container**: a
+ pixel constant was taken from the Tailwind docs and the root font size is 15px. Measure the drawn
+ element instead of the box it was given.
+- **A dialog's footer has body content painted over it**: `DialogBody` is missing
+ `overflow-y-auto`. It has `flex-1 min-h-0` and no overflow of its own.
+- **A dialog stops scrolling after a refactor**: `DialogBody` is no longer a direct child of
+ `DialogContent`. Restore it and give each section its own padding instead.
+- **Artwork overflows the box it was placed in**: an inline `<svg>` with a `viewBox` and no width or
+ height resolves to 100% width and a height derived from its own ratio. Give it
+ `className="h-full w-full"`; `overflow-hidden` on the parent clips at the border rather than the
+ padding, so it is no help here.
+- **A row's summary does not change after its dialog edits something**: the summary was captured into
+ state instead of computed from the query. Derive it on every render.
+- **Two screens that should match do not**: one of them drew its own container. Diff the two against
+ `admin/connectors.tsx` and delete whichever hand-drawn wrapper is not `PageRows`.
+- **The layout genuinely cannot express the screen**: stop and say so rather than bending it
+ silently. A deviation with a stated reason and a comment is fine; an undocumented fifth way to draw
+ a card is what this skill exists to prevent.
diff --git a/.gitignore b/.gitignore
index 3ba208a9..f5d48e06 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,9 @@
.worktrees/
.superpowers/
+
+# Claude Code: .claude/skills/ is shared, the rest is local state
+.claude/worktrees/
+.claude/settings.local.json
docs/superpowers/
docs/specs/
diff --git a/app/src/components/admin/admin-sidebar.tsx b/app/src/components/admin/admin-sidebar.tsx
index 1a5559e9..a5730ac0 100644
--- a/app/src/components/admin/admin-sidebar.tsx
+++ b/app/src/components/admin/admin-sidebar.tsx
@@ -75,7 +75,7 @@ const GROUPS: {
linkOptions: { to: "/admin/plugins" },
},
{
- title: "Components",
+ title: "UI Components",
icon: IconLayoutGrid,
linkOptions: { to: "/admin/components" },
},
@@ -103,11 +103,19 @@ export function AdminSidebar({
}: React.ComponentProps<typeof Sidebar>) {
return (
<Sidebar {...props}>
- <SidebarHeader>
+ {/*
+ * Pinned to the same height as the app sidebar's header. Left to itself this one is 60px
+ * against the app's 45px — `p-2` around a `size="lg"` button rather than a fixed height — so
+ * the nav list started lower here and the sidebar appeared to shift on the way into Admin.
+ *
+ * The button takes its default height rather than `h-full`. `h-full` resolves against the
+ * parent, which in the app sidebar is a flex row holding a second control and here is not, so
+ * the same class produces two different heights.
+ */}
+ <SidebarHeader className="h-12 p-2">
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton
- size="lg"
render={(props) => (
<Link {...appLinkOptions} {...props}>
<IconArrowLeft className="mr-2 h-4 w-4" />
@@ -144,7 +152,7 @@ export function AdminSidebar({
{GROUPS.map((group) => (
<SidebarGroup key={group.label}>
<SidebarGroupLabel>{group.label}</SidebarGroupLabel>
- <SidebarMenu>
+ <SidebarMenu className="gap-px">
{group.items.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton
diff --git a/app/src/components/agents/agent-fields.tsx b/app/src/components/agents/agent-fields.tsx
index 752a816c..9035b838 100644
--- a/app/src/components/agents/agent-fields.tsx
+++ b/app/src/components/agents/agent-fields.tsx
@@ -18,11 +18,10 @@ import {
} from "@/components/ui/select";
import { Textarea } from "@/components/ui/textarea";
import { type AgentFormValues, agentFormSchema } from "@/lib/agents/form";
-
-/** What the server said when it tried the endpoint. */
-type ConnectionVerdict =
- | { ok: true; events: string[] }
- | { ok: false; reason: string };
+import {
+ type ConnectionVerdict,
+ testAgentConnection,
+} from "@/lib/agents/queries";
export function AgentFields({
defaultValues,
@@ -56,35 +55,7 @@ export function AgentFields({
setTesting(true);
setConnection(null);
try {
- const response = await fetch("/api/agents/test-connection", {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- // Include the unsaved key so the test matches the pending form state.
- body: JSON.stringify({
- endpoint,
- ...(key.trim() ? { headers: { Authorization: key.trim() } } : {}),
- }),
- });
- const body = (await response.json().catch(() => null)) as
- | ConnectionVerdict
- | { error?: string }
- | null;
- if (body && "ok" in body) {
- setConnection(body);
- } else {
- setConnection({
- ok: false,
- reason:
- (body as { error?: string } | null)?.error ??
- "The connection could not be tested.",
- });
- }
- } catch {
- setConnection({
- ok: false,
- reason: "The connection could not be tested.",
- });
+ setConnection(await testAgentConnection(endpoint, key));
} finally {
setTesting(false);
}
diff --git a/app/src/components/app-sidebar/app-sidebar.tsx b/app/src/components/app-sidebar/app-sidebar.tsx
index eed28233..d06b65ca 100644
--- a/app/src/components/app-sidebar/app-sidebar.tsx
+++ b/app/src/components/app-sidebar/app-sidebar.tsx
@@ -34,6 +34,7 @@ import {
SidebarMenuItem,
SidebarRail,
} from "@/components/ui/sidebar";
+import { EASE_OUT, ENTRANCE_SECONDS } from "@/lib/motion";
import { signOutMutationOptions } from "@/lib/auth/mutations";
import { currentUserQueryOptions } from "@/lib/auth/queries";
import {
@@ -74,9 +75,6 @@ function UserAvatar() {
*/
const MAX_ANIMATED_ROWS = 60;
-const ENTRANCE_SECONDS = 0.2;
-const EASE_OUT = [0.23, 1, 0.32, 1] as const;
-
/**
* The roster, narrowed to what the person typed.
*
diff --git a/app/src/components/channels/channel-chat.tsx b/app/src/components/channels/channel-chat.tsx
index dabb8ba9..f27a7dfb 100644
--- a/app/src/components/channels/channel-chat.tsx
+++ b/app/src/components/channels/channel-chat.tsx
@@ -6,6 +6,7 @@ import {
} from "@copilotkit/react-core/v2";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useCallback, useEffect, useRef, useState } from "react";
+import { readThreadMessages } from "@/lib/copilot/thread-messages";
import { toAgentOptions } from "@/components/channels/composer";
import { ConversationView } from "@/components/channels/conversation-view";
import {
@@ -105,23 +106,14 @@ export function ChannelChat({
}
try {
- const response = await fetch(
- `/api/copilotkit/threads/${encodeURIComponent(channel.threadId)}/messages?agentId=${encodeURIComponent(runtimeAgentId)}`,
- { credentials: "include" },
+ const stored = await readThreadMessages(
+ channel.threadId,
+ runtimeAgentId,
);
- if (response.ok && current) {
- const stored = (await response.json())?.messages;
- // Never overwrite local messages that arrived while history was loading.
- if (
- Array.isArray(stored) &&
- stored.length > 0 &&
- agent.messages.length === 0
- ) {
- agent.setMessages(stored);
- }
+ // Never overwrite local messages that arrived while history was loading.
+ if (current && stored.length > 0 && agent.messages.length === 0) {
+ agent.setMessages(stored);
}
- } catch {
- // An unreadable history is not a reason to block the composer.
} finally {
// Release even on join/restore failure; the gate orders messages, not withholds them.
openJoinGate.current();
diff --git a/app/src/components/component-preview.tsx b/app/src/components/component-preview.tsx
new file mode 100644
index 00000000..ea2999a9
--- /dev/null
+++ b/app/src/components/component-preview.tsx
@@ -0,0 +1,140 @@
+import { useEffect, useRef, useState } from "react";
+import { galleryComponent } from "@/lib/copilot/gallery-registry";
+
+/**
+ * The width a gallery component is given to lay out against, standing in for the conversation
+ * column: previewing at the tile's own width would be a different component.
+ *
+ * Only an upper bound, and deliberately not read as the component's width. `GalleryFrame` caps
+ * itself at `max-w-2xl`, which is 42rem — 630px against this app's 15px root, not the 672px a 16px
+ * root would give. Assuming that number left every preview sitting half the difference off centre,
+ * so the drawn width is measured instead.
+ */
+const PREVIEW_LAYOUT_WIDTH = 672;
+
+/**
+ * How much of the space it could fill a preview actually takes, leaving the rest as margin.
+ *
+ * Padding the tile instead would not do it: the fit is measured against whichever axis runs out
+ * first, so a component that binds on height would still meet the top and bottom edges. Holding it
+ * off every edge means taking a share of the room on both axes at once.
+ */
+export const PREVIEW_FILL = 0.85;
+
+/**
+ * One component, drawn at its real size and scaled to sit inside the tile.
+ *
+ * The scale is measured rather than declared. CSS cannot do it: `scale()` needs a unitless number
+ * and `calc()` will not divide a length by one, so a container query cannot produce the ratio — and
+ * a hard-coded ratio would be wrong as soon as the tile changes shape.
+ *
+ * It is measured against both axes, because a component's height is its own business: a donut chart
+ * and a five-line checklist are the same width and nothing like the same height. Fitting on width
+ * alone left the tall ones running out of the bottom of the tile.
+ *
+ * Never scaled past its natural size, then held to `fill` of what it could fill. A box wider than a
+ * conversation column would otherwise magnify a component beyond the size anybody will actually see
+ * it at.
+ *
+ * Drawn inert and hidden from assistive technology. These are the real components, so a decision
+ * card here has a real note field and real Approve and Decline buttons; nothing in Admin should be
+ * able to reach them, and a screen reader should not find a second set of them on the page.
+ */
+export function ComponentPreview({
+ name,
+ fill = PREVIEW_FILL,
+}: {
+ name: string;
+ fill?: number;
+}) {
+ const entry = galleryComponent(name);
+ const box = useRef<HTMLDivElement>(null);
+ const content = useRef<HTMLDivElement>(null);
+ const [scale, setScale] = useState(0);
+
+ useEffect(() => {
+ const outer = box.current;
+ const inner = content.current;
+ if (!outer || !inner) return;
+
+ const measure = () => {
+ /*
+ * Measured on the component's own root rather than the box it was handed, because the two are
+ * not the same width: the box is the column it lays out against, and the component caps
+ * itself inside that. Scaling by the box would shrink it to fit a width it never occupied.
+ *
+ * `offsetWidth` and `offsetHeight` are laid-out values, which a transform does not touch — so
+ * reading them here cannot feed back into the scale about to be applied to them.
+ */
+ const drawn = inner.firstElementChild;
+ const measured = drawn instanceof HTMLElement ? drawn : inner;
+
+ if (!measured.offsetWidth || !measured.offsetHeight) return;
+ if (!outer.clientWidth || !outer.clientHeight) return;
+
+ setScale(
+ fill *
+ Math.min(
+ 1,
+ outer.clientWidth / measured.offsetWidth,
+ outer.clientHeight / measured.offsetHeight,
+ ),
+ );
+ };
+
+ const observer = new ResizeObserver(measure);
+ observer.observe(outer);
+ observer.observe(inner);
+ return () => observer.disconnect();
+ }, [fill]);
+
+ if (!entry?.preview) {
+ return (
+ <div className="flex h-full w-full items-center justify-center p-4">
+ {/*
+ * A fixed dark grey rather than `text-muted-foreground`. That token lightens in the dark
+ * theme — 0.5 to 0.708 — while the artwork behind this text does not: it is the same pale
+ * gradient either way, with no dark variant. Following the theme therefore moved the text
+ * towards its background exactly when it needed to move away from it.
+ */}
+ <p className="text-center text-neutral-700 text-xs">
+ {entry
+ ? "This one is only drawn in a conversation."
+ : "This build cannot draw this."}
+ </p>
+ </div>
+ );
+ }
+
+ const { Component } = entry;
+
+ return (
+ <div
+ aria-hidden="true"
+ className="flex h-full w-full items-center justify-center overflow-hidden"
+ inert
+ ref={box}
+ >
+ {/*
+ * Centred by the flex parent and scaled about its own middle. The layout box stays full size
+ * and may be larger than the tile, which is what keeps it centred: shrinking happens around
+ * the centre point the parent already placed.
+ *
+ * A flex row itself, so a component narrower than the column it was given is centred in it
+ * rather than left against one edge. Whatever `max-w-2xl` resolves to, the slack is split.
+ */}
+ <div
+ className="flex shrink-0 justify-center transition-opacity"
+ ref={content}
+ style={{
+ // Until the tile has been measured there is no honest scale, so draw nothing.
+ opacity: scale > 0 ? 1 : 0,
+ transform: `scale(${scale})`,
+ width: PREVIEW_LAYOUT_WIDTH,
+ }}
+ >
+ <Component {...entry.preview} />
+ </div>
+ </div>
+ );
+}
diff --git a/app/src/components/computer/computer-view.tsx b/app/src/components/computer/computer-view.tsx
index 77878f27..e6120c59 100644
--- a/app/src/components/computer/computer-view.tsx
+++ b/app/src/components/computer/computer-view.tsx
@@ -3,21 +3,13 @@ import { createPortal } from "react-dom";
import { LiveScreen } from "./live-screen";
import { ComputerPlaceholder } from "./placeholder";
import {
- type ControlState,
readControl,
releaseControl,
supplySecret,
takeControl,
-} from "./take-the-wheel";
-
-type Screenshot = {
- base64: string;
- width: number;
- height: number;
- capturedAt: string;
- /** `about:blank` when the browser has not been sent anywhere yet. Absent on older computers. */
- url?: string;
-};
+ type ControlState,
+} from "@/lib/computers/control";
+import { readScreenshot, type Screenshot } from "@/lib/computers/screen";
/** Explicit blank-browser URLs use placeholder artwork; missing URL fields are treated as real pages. */
function isBlankBrowser(shot: Screenshot): boolean {
@@ -122,33 +114,21 @@ export function ComputerView({
// Always fetch at least one frame; only repeated refreshes are conditional.
const tick = async () => {
try {
- const response = await fetch(
- `/api/computers/${computerId}/screenshot`,
- {
- credentials: "include",
- },
- );
+ const { frame, error } = await readScreenshot(computerId);
if (generation.current !== mine) return;
- if (!response.ok) {
- const body = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- setProblem(body?.error ?? "The screen is not available right now.");
+ if (!frame) {
+ setProblem(error ?? "The screen is not available right now.");
} else {
- const next = (await response.json()) as Screenshot;
// Exact byte comparison is the settling signal.
- unchanged = next.base64 === lastFrame ? unchanged + 1 : 0;
- lastFrame = next.base64;
+ unchanged = frame.base64 === lastFrame ? unchanged + 1 : 0;
+ lastFrame = frame.base64;
// Decode before swapping to avoid blanking the visible image during data URL changes.
- await preloadFrame(next.base64);
+ await preloadFrame(frame.base64);
if (generation.current !== mine) return;
- setShot(next);
+ setShot(frame);
setProblem(null);
}
- } catch {
- if (generation.current !== mine) return;
- setProblem("The screen is not available right now.");
} finally {
if (generation.current === mine && shouldContinue()) {
timer = setTimeout(tick, intervalMs);
diff --git a/app/src/components/computer/needs-you.ts b/app/src/components/computer/needs-you.ts
index cbed6777..51aea52a 100644
--- a/app/src/components/computer/needs-you.ts
+++ b/app/src/components/computer/needs-you.ts
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
-import { readControl } from "./take-the-wheel";
+import { readControl } from "@/lib/computers/control";
/**
* Poll closed screens for control/secret prompts so blocked Bots can surface outside the screen.
diff --git a/app/src/components/computer/take-the-wheel.ts b/app/src/components/computer/take-the-wheel.ts
index 725a443a..3dcf8dc5 100644
--- a/app/src/components/computer/take-the-wheel.ts
+++ b/app/src/components/computer/take-the-wheel.ts
@@ -1,94 +1,10 @@
/**
- * Computer control API helpers and screenshot-to-page coordinate conversion.
+ * Screenshot-to-page coordinate conversion.
+ *
+ * Geometry only. Talking to a computer moved to `lib/computers/control.ts`; this stayed because it is
+ * about the image on screen rather than about the machine behind it.
*/
-export type ControlState = {
- holder: "bot" | "human";
- since: string;
- reason?: string;
- requested: boolean;
- /** What the Bot is waiting for, by name only. Present means show the masked prompt. */
- secretWanted?: string;
-};
-
-async function callControl(
- computerId: string,
- path: string,
- init?: RequestInit,
-): Promise<ControlState | null> {
- const response = await fetch(`/api/computers/${computerId}${path}`, {
- credentials: "include",
- ...init,
- });
- if (!response.ok) return null;
- return (await response.json()) as ControlState;
-}
-
-export function readControl(computerId: string) {
- return callControl(computerId, "/control");
-}
-
-export function takeControl(computerId: string) {
- return callControl(computerId, "/control/take", { method: "POST" });
-}
-
-export function releaseControl(computerId: string) {
- return callControl(computerId, "/control/release", { method: "POST" });
-}
-
-/**
- * Supply a secret synchronously and never echo the value back to the UI.
- */
-export async function supplySecret(
- computerId: string,
- text: string,
-): Promise<{ ok: boolean; error?: string }> {
- try {
- const response = await fetch(`/api/computers/${computerId}/human/secret`, {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ text }),
- });
- if (response.ok) return { ok: true };
- const body = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- return { ok: false, error: body?.error ?? "That could not be entered." };
- } catch {
- return {
- ok: false,
- error: "The assistant's computer could not be reached.",
- };
- }
-}
-
-/**
- * Serializes human input requests without blocking the caller; ordering matters for typed secrets.
- */
-let inputQueue: Promise<unknown> = Promise.resolve();
-
-/**
- * Send one human input event. Returns immediately; delivery is ordered.
- */
-export function sendHumanInput(
- computerId: string,
- kind: "click" | "type" | "key" | "scroll",
- body: Record<string, unknown>,
-): void {
- inputQueue = inputQueue
- .then(() =>
- fetch(`/api/computers/${computerId}/human/${kind}`, {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(body),
- }),
- )
- // Fire-and-forget: the user can see/retry input failures, while the input queue must keep moving.
- .catch(() => undefined);
-}
-
/**
* Convert display coordinates on a scaled screenshot into browser viewport coordinates.
*/
diff --git a/app/src/components/gallery/activity.tsx b/app/src/components/gallery/activity.tsx
index a0c66743..e72d5673 100644
--- a/app/src/components/gallery/activity.tsx
+++ b/app/src/components/gallery/activity.tsx
@@ -267,6 +267,12 @@ function RefusalList({
export const GALLERY: GalleryComponent[] = [
{
+ /*
+ * NO `preview`, DELIBERATELY. This one reads the deployment through `callComponentFunction` as
+ * soon as it mounts, and needs the Bot and conversation it was called in. Drawing it in Admin
+ * would put a real read, attributed to whichever Bot happened to be active, behind a page that
+ * only means to show what the component looks like. Admin draws it as unpreviewable instead.
+ */
name: "showActivityReport",
title: "Activity report",
kind: "card",
diff --git a/app/src/components/gallery/preview.tsx b/app/src/components/gallery/preview.tsx
index 72d260dc..ce613665 100644
--- a/app/src/components/gallery/preview.tsx
+++ b/app/src/components/gallery/preview.tsx
@@ -103,10 +103,10 @@ export function GalleryPreview({
/**
* One component, drawn from its own sample props.
*
- * Separate from the gallery because the two surfaces want different framing: the gallery labels
- * every tile, and an admin page already has the name and the description above it.
+ * Private to this file. Admin and Settings draw components through `ComponentPreview`, which scales
+ * one to fit a tile; this draws at natural size, which is what the per-Bot panel below wants.
*/
-export function PreviewOf({ name }: { name: string }) {
+function PreviewOf({ name }: { name: string }) {
const component = GALLERY_COMPONENTS.find((entry) => entry.name === name);
if (!component) return null;
if (!component.preview) {
diff --git a/app/src/components/layout/detail-panel.tsx b/app/src/components/layout/detail-panel.tsx
index 5328bd4a..38d7ba3a 100644
--- a/app/src/components/layout/detail-panel.tsx
+++ b/app/src/components/layout/detail-panel.tsx
@@ -2,6 +2,7 @@ import { IconX } from "@tabler/icons-react";
import { motion, useReducedMotion } from "motion/react";
import type { ReactNode } from "react";
import { Button } from "@/components/ui/button";
+import { EASE_OUT } from "@/lib/motion";
/**
* A main pane with a detail pane that slides in beside it.
@@ -16,9 +17,6 @@ import { Button } from "@/components/ui/button";
const ANIMATION_DURATION_SECONDS = 0.3;
const DEFAULT_DETAIL_WIDTH = 400;
-/** Strong ease-out. The browser's built-in curve is too weak to read as deliberate. */
-const EASE_OUT = [0.23, 1, 0.32, 1] as const;
-
/**
* The content overlaps the tail of the pane rather than following it.
*
diff --git a/app/src/components/layout/page-shell.tsx b/app/src/components/layout/page-shell.tsx
index d2e5e646..377fa01d 100644
--- a/app/src/components/layout/page-shell.tsx
+++ b/app/src/components/layout/page-shell.tsx
@@ -1,6 +1,9 @@
import type * as React from "react";
import { cn } from "@/lib/utils";
+import { Link, type LinkProps } from "@tanstack/react-router";
+import { Button } from "../ui/button";
+import { IconChevronLeft } from "@tabler/icons-react";
/**
* The frame every configuration screen sits in.
@@ -40,6 +43,7 @@ export function PageShell({
description,
title,
width = "prose",
+ backButton,
}: {
/** Sits on the title's baseline. For the page's one primary verb, if it has one. */
action?: React.ReactNode;
@@ -48,28 +52,46 @@ export function PageShell({
description?: React.ReactNode;
title: string;
width?: ShellWidth;
+ backButton?: {
+ linkProps: LinkProps;
+ label: string;
+ };
}) {
return (
- <div
- className={cn(
- "mx-auto flex w-full flex-col px-4 py-12",
- WIDTHS[width],
- className,
- )}
- >
- <header className="flex flex-col gap-2">
- <div className="flex flex-row items-center justify-between gap-4">
- <h1 className="font-bold text-2xl">{title}</h1>
- {action}
+ <>
+ {!!backButton && (
+ <div className="max-w-7xl w-full h-14 flex items-center px-3">
+ <Button
+ variant="ghost"
+ render={(props) => <Link {...backButton.linkProps} {...props} />}
+ >
+ <IconChevronLeft />
+ {backButton.label}
+ </Button>
</div>
- {description ? (
- <p className="max-w-prose text-pretty text-muted-foreground text-sm leading-relaxed">
- {description}
- </p>
- ) : null}
- </header>
- {children}
- </div>
+ )}
+ <div
+ className={cn(
+ "mx-auto flex w-full flex-col px-4 py-12",
+ { "pt-8": !!backButton },
+ WIDTHS[width],
+ className,
+ )}
+ >
+ <header className="flex flex-col gap-2">
+ <div className="flex flex-row items-center justify-between gap-4">
+ <h1 className="font-bold text-2xl">{title}</h1>
+ {action}
+ </div>
+ {description ? (
+ <p className="max-w-prose text-pretty text-muted-foreground text-sm leading-relaxed">
+ {description}
+ </p>
+ ) : null}
+ </header>
+ {children}
+ </div>
+ </>
);
}
@@ -126,8 +148,17 @@ export function PageRows({
className?: string;
}) {
return (
+ /*
+ * The rows are squared off and the card clips them. `Item` carries `rounded-lg` of its own, which
+ * inside a card of divided rows painted a hover as a floating pill: a middle row has no corners,
+ * and the first and last cannot be concentric with the card while sitting a border inside it.
+ */
<div
- className={cn("mt-4 rounded-lg border border-border bg-card", className)}
+ className={cn(
+ "mt-4 overflow-hidden rounded-lg border border-border bg-card",
+ "[&_[data-slot=item]]:rounded-none",
+ className,
+ )}
>
{children}
</div>
diff --git a/app/src/components/settings/background.tsx b/app/src/components/settings/background.tsx
new file mode 100644
index 00000000..a7c3cf02
--- /dev/null
+++ b/app/src/components/settings/background.tsx
@@ -0,0 +1,162 @@
+import type { SVGProps } from "react";
+
+/**
+ * Decorative waiting artwork for the fixed-size computer frame.
+ */
+export function SettingsItemBackground(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ viewBox="0 0 1200 800"
+ preserveAspectRatio="xMidYMin slice"
+ fill="none"
+ aria-hidden="true"
+ focusable="false"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g clipPath="url(#clip0_2002_10)">
+ <path fill="#fff" d="M0 0H1200V800H0z" />
+ <path fill="url(#paint0_linear_2002_10)" d="M0 0H1200V754H0z" />
+ <g
+ opacity={0.93}
+ filter="url(#filter0_n_2002_10)"
+ style={{
+ mixBlendMode: "lighten",
+ }}
+ >
+ <path
+ transform="rotate(180 1201 754)"
+ fill="url(#paint1_radial_2002_10)"
+ d="M1201 754H2402V1509H1201z"
+ />
+ </g>
+ <g
+ filter="url(#filter1_n_2002_10)"
+ style={{
+ mixBlendMode: "color-burn",
+ }}
+ >
+ <path fill="#F0F0F0" fillOpacity={0.84} d="M0 0H1200V754H0z" />
+ </g>
+ </g>
+ <defs>
+ <filter
+ id="filter0_n_2002_10"
+ x={0}
+ y={-1}
+ width={1201}
+ height={755}
+ filterUnits="userSpaceOnUse"
+ colorInterpolationFilters="sRGB"
+ >
+ <feFlood floodOpacity={0} result="BackgroundImageFix" />
+ <feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape" />
+ <feTurbulence
+ type="fractalNoise"
+ baseFrequency="0.76923078298568726 0.76923078298568726"
+ stitchTiles="stitch"
+ numOctaves={3}
+ result="noise"
+ seed={2673}
+ />
+ <feComponentTransfer in="noise" result="coloredNoise1">
+ <feFuncR type="linear" slope={2} intercept={-0.5} />
+ <feFuncG type="linear" slope={2} intercept={-0.5} />
+ <feFuncB type="linear" slope={2} intercept={-0.5} />
+ <feFuncA
+ type="discrete"
+ tableValues="1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
+ />
+ </feComponentTransfer>
+ <feComposite
+ operator="in"
+ in2="shape"
+ in="coloredNoise1"
+ result="noise1Clipped"
+ />
+ <feComponentTransfer in="noise1Clipped" result="color1">
+ <feFuncA type="table" tableValues="0 0.15" />
+ </feComponentTransfer>
+ <feMerge result="effect1_noise_2002_10">
+ <feMergeNode in="shape" />
+ <feMergeNode in="color1" />
+ </feMerge>
+ </filter>
+ <filter
+ id="filter1_n_2002_10"
+ x={0}
+ y={0}
+ width={1200}
+ height={754}
+ filterUnits="userSpaceOnUse"
+ colorInterpolationFilters="sRGB"
+ >
+ <feFlood floodOpacity={0} result="BackgroundImageFix" />
+ <feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape" />
+ <feTurbulence
+ type="fractalNoise"
+ baseFrequency="2 2"
+ stitchTiles="stitch"
+ numOctaves={3}
+ result="noise"
+ seed={7521}
+ />
+ <feColorMatrix
+ in="noise"
+ type="luminanceToAlpha"
+ result="alphaNoise"
+ />
+ <feComponentTransfer in="alphaNoise" result="coloredNoise1">
+ <feFuncA
+ type="discrete"
+ tableValues="1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
+ />
+ </feComponentTransfer>
+ <feComposite
+ operator="in"
+ in2="shape"
+ in="coloredNoise1"
+ result="noise1Clipped"
+ />
+ <feFlood floodColor="rgba(0, 0, 0, 0.25)" result="color1Flood" />
+ <feComposite
+ operator="in"
+ in2="noise1Clipped"
+ in="color1Flood"
+ result="color1"
+ />
+ <feMerge result="effect1_noise_2002_10">
+ <feMergeNode in="shape" />
+ <feMergeNode in="color1" />
+ </feMerge>
+ </filter>
+ <linearGradient
+ id="paint0_linear_2002_10"
+ x1={1200}
+ y1={-53.8571}
+ x2={-274.518}
+ y2={423.589}
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop stopColor="#FFB8E7" />
+ <stop offset={1} stopColor="#2EE297" />
+ </linearGradient>
+ <radialGradient
+ id="paint1_radial_2002_10"
+ cx={0}
+ cy={0}
+ r={1}
+ gradientTransform="matrix(229.838 -1654.36 2337.29 481.415 2278.37 2408.36)"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop offset={0.420388} stopColor="#9DF200" />
+ <stop offset={0.66} stopColor="#0099A9" />
+ <stop offset={1} stopColor="#fff" />
+ </radialGradient>
+ <clipPath id="clip0_2002_10">
+ <path fill="#fff" d="M0 0H1200V800H0z" />
+ </clipPath>
+ </defs>
+ </svg>
+ );
+}
diff --git a/app/src/components/settings/settings-sidebar.tsx b/app/src/components/settings/settings-sidebar.tsx
index 471e58f5..5a99b398 100644
--- a/app/src/components/settings/settings-sidebar.tsx
+++ b/app/src/components/settings/settings-sidebar.tsx
@@ -1,4 +1,8 @@
-import { IconArrowLeft } from "@tabler/icons-react";
+import {
+ IconArrowLeft,
+ IconLayoutGrid,
+ IconSettings,
+} from "@tabler/icons-react";
import { Link, type LinkOptions } from "@tanstack/react-router";
import type * as React from "react";
import {
@@ -14,11 +18,31 @@ import {
const appLinkOptions = { to: "/" } satisfies LinkOptions;
-const ITEMS = [
+const ITEMS: {
+ /**
+ * Whether this entry lights only on its own route.
+ *
+ * On for an entry whose path is a prefix of another's, which is the only reason to want it. Off
+ * everywhere else, so an entry stays lit on the pages beneath it.
+ */
+ exact?: boolean;
+ icon: React.ComponentType<{ className?: string }>;
+ linkOptions: LinkOptions;
+ title: string;
+}[] = [
{
title: "General",
+ icon: IconSettings,
+ /* `/settings` prefixes every other route here, and would otherwise light up on all of them. */
+ exact: true,
linkOptions: { to: "/settings" },
},
+ {
+ /* The same mark Admin gives UI Components. It is the same subject seen from the other side. */
+ title: "Components gallery",
+ icon: IconLayoutGrid,
+ linkOptions: { to: "/settings/components-gallery" },
+ },
];
export function SettingsSidebar({
@@ -26,11 +50,11 @@ export function SettingsSidebar({
}: React.ComponentProps<typeof Sidebar>) {
return (
<Sidebar {...props}>
- <SidebarHeader>
+ {/* Matched to the app sidebar's header, as Admin's is. See admin-sidebar.tsx. */}
+ <SidebarHeader className="h-12 p-2">
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton
- size="lg"
render={(props) => (
<Link {...appLinkOptions} {...props}>
<IconArrowLeft className="mr-2 h-4 w-4" />
@@ -42,29 +66,31 @@ export function SettingsSidebar({
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
- <SidebarMenu>
- <SidebarGroup>
- {ITEMS.map((option) => {
- return (
- <SidebarMenuItem key={option.title}>
- <SidebarMenuButton
- render={(props) => (
- <Link
- {...option.linkOptions}
- activeProps={{
- className: "bg-foreground/5",
- }}
- {...props}
- >
- {option.title}
- </Link>
- )}
- />
- </SidebarMenuItem>
- );
- })}
- </SidebarGroup>
- </SidebarMenu>
+ {/*
+ * Group outside menu, as Admin has it. The other way round nests a list item inside a div
+ * inside the `ul`, which is not markup a list is allowed to be made of.
+ */}
+ <SidebarGroup>
+ <SidebarMenu className="gap-px">
+ {ITEMS.map((option) => (
+ <SidebarMenuItem key={option.title}>
+ <SidebarMenuButton
+ render={(props) => (
+ <Link
+ {...option.linkOptions}
+ activeOptions={{ exact: option.exact ?? false }}
+ activeProps={{ className: "bg-foreground/5" }}
+ {...props}
+ >
+ <option.icon className="mr-2 h-4 w-4" />
+ {option.title}
+ </Link>
+ )}
+ />
+ </SidebarMenuItem>
+ ))}
+ </SidebarMenu>
+ </SidebarGroup>
</SidebarContent>
<SidebarRail />
</Sidebar>
diff --git a/app/src/components/skills/edit-skill.tsx b/app/src/components/skills/edit-skill.tsx
index fa26cad2..f4b4cd04 100644
--- a/app/src/components/skills/edit-skill.tsx
+++ b/app/src/components/skills/edit-skill.tsx
@@ -2,8 +2,8 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "@tanstack/react-router";
import { SkillAgents } from "@/components/skills/skill-agents";
import { SkillFields } from "@/components/skills/skill-fields";
-import { pluginKeys, pluginsPageQueryOptions } from "@/lib/plugins/queries";
-import type { SkillFormValues } from "@/lib/skills/form";
+import { saveSkillMutationOptions } from "@/lib/plugins/mutations";
+import { pluginsPageQueryOptions } from "@/lib/plugins/queries";
/**
* Editing a skill, in the same panel that writes one.
@@ -25,39 +25,22 @@ export function EditSkill({ slug }: { slug: string }) {
*/
const skill = data?.skills.find((candidate) => candidate.slug === slug);
- const saveSkill = useMutation({
- mutationFn: async (values: SkillFormValues) => {
- const response = await fetch("/api/plugins/skills", {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(values),
- });
- if (!response.ok) {
- const body = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- throw new Error(body?.error ?? "The skill could not be saved.");
- }
- return response.json();
- },
- onSuccess: () =>
- queryClient.invalidateQueries({ queryKey: pluginKeys.all }),
- });
+ const saveSkill = useMutation(saveSkillMutationOptions(queryClient));
+
+ /* Nothing while it loads. "Missing" and "not yet arrived" must not read the same. */
+ if (isPending) return null;
if (!skill) {
return (
<div className="mx-auto flex w-full max-w-xl flex-col gap-6 p-8">
+ {/*
+ * Said plainly rather than shown as an empty form. A skill can be missing because it was
+ * deleted in another tab, or because the link names one that is somebody else's — and an
+ * empty form here would invite them to write it back into existence under a slug they may
+ * not own.
+ */}
<p className="text-muted-foreground text-sm">
- {isPending
- ? "Loading…"
- : /*
- * Said plainly rather than shown as an empty form. A skill can be missing because it
- * was deleted in another tab, or because the link names one that is somebody else's —
- * and an empty form here would invite them to write it back into existence under a
- * slug they may not own.
- */
- "That skill no longer exists, or it is not yours to edit."}
+ That skill no longer exists, or it is not yours to edit.
</p>
</div>
);
diff --git a/app/src/components/skills/new-skill.tsx b/app/src/components/skills/new-skill.tsx
index a81c9cf6..8e7fc42d 100644
--- a/app/src/components/skills/new-skill.tsx
+++ b/app/src/components/skills/new-skill.tsx
@@ -1,8 +1,8 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "@tanstack/react-router";
import { SkillFields } from "@/components/skills/skill-fields";
-import { pluginKeys } from "@/lib/plugins/queries";
-import { emptySkillForm, type SkillFormValues } from "@/lib/skills/form";
+import { saveSkillMutationOptions } from "@/lib/plugins/mutations";
+import { emptySkillForm } from "@/lib/skills/form";
/**
* Writing a skill, in the detail panel beside the list.
@@ -14,30 +14,7 @@ export function NewSkill() {
const queryClient = useQueryClient();
const navigate = useNavigate();
- const createSkill = useMutation({
- mutationFn: async (values: SkillFormValues) => {
- const response = await fetch("/api/plugins/skills", {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(values),
- });
- if (!response.ok) {
- /*
- * The server's sentence, not one invented here. It refuses for reasons this form cannot
- * check — a slug somebody else already owns is the common one — and paraphrasing that into
- * "That did not work" would throw away the only part worth reading.
- */
- const body = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- throw new Error(body?.error ?? "The skill could not be saved.");
- }
- return response.json();
- },
- onSuccess: () =>
- queryClient.invalidateQueries({ queryKey: pluginKeys.all }),
- });
+ const createSkill = useMutation(saveSkillMutationOptions(queryClient));
return (
<div className="mx-auto flex w-full max-w-xl flex-col gap-6 p-8">
diff --git a/app/src/components/skills/skill-agents.tsx b/app/src/components/skills/skill-agents.tsx
index 5c1eb2c8..1603f5d8 100644
--- a/app/src/components/skills/skill-agents.tsx
+++ b/app/src/components/skills/skill-agents.tsx
@@ -1,7 +1,7 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Button } from "@/components/ui/button";
import { agentListQueryOptions } from "@/lib/agents/queries";
-import { pluginKeys } from "@/lib/plugins/queries";
+import { setPluginGrantMutationOptions } from "@/lib/plugins/mutations";
/**
* Which of your Agents carry this skill.
@@ -28,30 +28,11 @@ export function SkillAgents({
const mine = (agents ?? []).filter((agent) => agent.mine);
const held = new Set(grantedTo);
- const toggle = useMutation({
- mutationFn: async ({ agentId, on }: { agentId: string; on: boolean }) => {
- const response = on
- ? await fetch(
- `/api/plugins/grants?kind=skill&ref=${encodeURIComponent(slug)}&agentId=${encodeURIComponent(agentId)}`,
- { method: "DELETE", credentials: "include" },
- )
- : await fetch("/api/plugins/grants", {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ kind: "skill", ref: slug, agentId }),
- });
- if (!response.ok) {
- const body = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- // The server's sentence: it knows why it refused and this component does not.
- throw new Error(body?.error ?? "That Agent could not be changed.");
- }
- },
- onSuccess: () =>
- queryClient.invalidateQueries({ queryKey: pluginKeys.all }),
- });
+ const grant = useMutation(setPluginGrantMutationOptions(queryClient));
+
+ /* `on` is the current state, so a click asks for its opposite. */
+ const toggle = (agentId: string, on: boolean) =>
+ grant.mutate({ agentId, granted: !on, kind: "skill", ref: slug });
return (
<div className="flex flex-col gap-2">
@@ -67,9 +48,9 @@ export function SkillAgents({
const on = held.has(agent.id);
return (
<Button
- disabled={toggle.isPending}
+ disabled={grant.isPending}
key={agent.id}
- onClick={() => toggle.mutate({ agentId: agent.id, on })}
+ onClick={() => toggle(agent.id, on)}
size="sm"
type="button"
/*
@@ -89,9 +70,9 @@ export function SkillAgents({
</p>
</>
)}
- {toggle.error ? (
+ {grant.error ? (
<p className="text-destructive text-xs" role="alert">
- {toggle.error.message}
+ {grant.error.message}
</p>
) : null}
</div>
diff --git a/app/src/components/ui/dialog.tsx b/app/src/components/ui/dialog.tsx
index e9858798..08880c94 100644
--- a/app/src/components/ui/dialog.tsx
+++ b/app/src/components/ui/dialog.tsx
@@ -98,12 +98,21 @@ function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
);
}
-/** Body scrolls, so the header and footer stay put on a short viewport. */
+/**
+ * Body scrolls, so the header and footer stay put on a short viewport.
+ *
+ * `overflow-y-auto` is the half that was missing. `flex-1 min-h-0` lets this shrink, but without an
+ * overflow it shrinks and then paints its content over the footer — which every dialog here was short
+ * enough never to show.
+ */
function DialogBody({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-body"
- className={cn("-mx-1 flex min-h-0 flex-1 flex-col gap-4 px-1", className)}
+ className={cn(
+ "-mx-1 flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-1",
+ className,
+ )}
{...props}
/>
);
diff --git a/app/src/lib/agents/mutations.ts b/app/src/lib/agents/mutations.ts
index fc73e8ae..b0b00436 100644
--- a/app/src/lib/agents/mutations.ts
+++ b/app/src/lib/agents/mutations.ts
@@ -1,4 +1,5 @@
import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client } from "@/lib/client";
import { type AgentProfile, type AgentVisibility, agentKeys } from "./queries";
export type AgentInput = {
@@ -12,30 +13,8 @@ export type AgentInput = {
auth?: { header: string; value: string };
};
-async function agentRequest(
- path: string,
- init: { method: string; body?: AgentInput },
-): Promise<Response> {
- const response = await fetch(path, {
- method: init.method,
- credentials: "include",
- headers: init.body ? { "content-type": "application/json" } : undefined,
- body: init.body ? JSON.stringify(init.body) : undefined,
- });
- if (!response.ok) {
- // The server's message is the useful one: it names the field or the permission that failed.
- const message = await response
- .json()
- .then((body: { error?: string }) => body.error)
- .catch(() => undefined);
- throw new Error(message ?? "Coworker operation failed");
- }
- return response;
-}
-
-async function agentFrom(response: Response): Promise<AgentProfile> {
- return ((await response.json()) as { agent: AgentProfile }).agent;
-}
+/** The sentence for every write here, since they all fail the same way to a reader. */
+const FALLBACK = "Coworker operation failed";
/** Server-derived fields are invalidated instead of patched by hand. */
function invalidateAgents(queryClient: QueryClient) {
@@ -44,35 +23,38 @@ function invalidateAgents(queryClient: QueryClient) {
export function createAgentMutationOptions(queryClient: QueryClient) {
return mutationOptions({
- mutationFn: async (input: AgentInput) =>
- agentFrom(
- await agentRequest("/api/agents", { method: "POST", body: input }),
- ),
+ mutationFn: (input: AgentInput): Promise<AgentProfile> =>
+ client("/api/agents", "agent", {
+ method: "POST",
+ body: input,
+ fallback: FALLBACK,
+ }),
onSuccess: () => invalidateAgents(queryClient),
});
}
export function updateAgentMutationOptions(queryClient: QueryClient) {
return mutationOptions({
- mutationFn: async (variables: { agentId: string; input: AgentInput }) =>
- agentFrom(
- await agentRequest(`/api/agents/${variables.agentId}`, {
- method: "PATCH",
- body: variables.input,
- }),
- ),
+ mutationFn: (variables: {
+ agentId: string;
+ input: AgentInput;
+ }): Promise<AgentProfile> =>
+ client(`/api/agents/${variables.agentId}`, "agent", {
+ method: "PATCH",
+ body: variables.input,
+ fallback: FALLBACK,
+ }),
onSuccess: () => invalidateAgents(queryClient),
});
}
export function duplicateAgentMutationOptions(queryClient: QueryClient) {
return mutationOptions({
- mutationFn: async (agentId: string) =>
- agentFrom(
- await agentRequest(`/api/agents/${agentId}/duplicate`, {
- method: "POST",
- }),
- ),
+ mutationFn: (agentId: string): Promise<AgentProfile> =>
+ client(`/api/agents/${agentId}/duplicate`, "agent", {
+ method: "POST",
+ fallback: FALLBACK,
+ }),
onSuccess: () => invalidateAgents(queryClient),
});
}
@@ -80,9 +62,9 @@ export function duplicateAgentMutationOptions(queryClient: QueryClient) {
export function setAgentHiddenMutationOptions(queryClient: QueryClient) {
return mutationOptions({
mutationFn: async (variables: { agentId: string; hidden: boolean }) => {
- await agentRequest(
+ await client(
`/api/agents/${variables.agentId}/${variables.hidden ? "hide" : "unhide"}`,
- { method: "POST" },
+ { method: "POST", fallback: FALLBACK },
);
},
onSuccess: () => invalidateAgents(queryClient),
@@ -92,7 +74,10 @@ export function setAgentHiddenMutationOptions(queryClient: QueryClient) {
export function deleteAgentMutationOptions(queryClient: QueryClient) {
return mutationOptions({
mutationFn: async (agentId: string) => {
- await agentRequest(`/api/agents/${agentId}`, { method: "DELETE" });
+ await client(`/api/agents/${agentId}`, {
+ method: "DELETE",
+ fallback: FALLBACK,
+ });
},
onSuccess: () => invalidateAgents(queryClient),
});
@@ -107,13 +92,11 @@ export function deleteAgentMutationOptions(queryClient: QueryClient) {
*/
export function issueCallbackTokenMutationOptions(queryClient: QueryClient) {
return mutationOptions({
- mutationFn: async (agentId: string): Promise<string> => {
- const response = await agentRequest(
- `/api/agents/${agentId}/callback-token`,
- { method: "POST" },
- );
- return ((await response.json()) as { token: string }).token;
- },
+ mutationFn: (agentId: string): Promise<string> =>
+ client(`/api/agents/${agentId}/callback-token`, "token", {
+ method: "POST",
+ fallback: FALLBACK,
+ }),
onSuccess: () => invalidateAgents(queryClient),
});
}
@@ -122,8 +105,9 @@ export function issueCallbackTokenMutationOptions(queryClient: QueryClient) {
export function revokeCallbackTokenMutationOptions(queryClient: QueryClient) {
return mutationOptions({
mutationFn: async (agentId: string) => {
- await agentRequest(`/api/agents/${agentId}/callback-token`, {
+ await client(`/api/agents/${agentId}/callback-token`, {
method: "DELETE",
+ fallback: FALLBACK,
});
},
onSuccess: () => invalidateAgents(queryClient),
diff --git a/app/src/lib/agents/queries.ts b/app/src/lib/agents/queries.ts
index bf027b94..ce276d69 100644
--- a/app/src/lib/agents/queries.ts
+++ b/app/src/lib/agents/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client, tryClient } from "@/lib/client";
export type AgentVisibility = "public" | "private";
@@ -47,28 +48,61 @@ export const agentKeys = {
export function agentListQueryOptions(hidden = false) {
return queryOptions({
queryKey: agentKeys.list(hidden),
- queryFn: async (): Promise<AgentProfile[]> => {
- const response = await fetch(
- `/api/agents${hidden ? "?hidden=true" : ""}`,
- {
- credentials: "include",
- },
- );
- if (!response.ok) throw new Error("Could not load coworkers");
- return ((await response.json()) as { agents: AgentProfile[] }).agents;
- },
+ queryFn: (): Promise<AgentProfile[]> =>
+ client(`/api/agents${hidden ? "?hidden=true" : ""}`, "agents", {
+ fallback: "Could not load coworkers",
+ }),
});
}
export function agentQueryOptions(agentId: string) {
return queryOptions({
queryKey: agentKeys.detail(agentId),
- queryFn: async (): Promise<AgentProfile> => {
- const response = await fetch(`/api/agents/${agentId}`, {
- credentials: "include",
- });
- if (!response.ok) throw new Error("Could not load this coworker");
- return ((await response.json()) as { agent: AgentProfile }).agent;
- },
+ queryFn: (): Promise<AgentProfile> =>
+ client(`/api/agents/${agentId}`, "agent", {
+ fallback: "Could not load this coworker",
+ }),
});
}
+
+/** What the server said when it tried the endpoint. */
+export type ConnectionVerdict =
+ | { ok: true; events: string[] }
+ | { ok: false; reason: string };
+
+/**
+ * Ask the server to reach a coworker's endpoint, from where a run will reach it.
+ *
+ * A plain function rather than a factory: the answer is about this moment, nothing caches it, and
+ * there is no key for anything to invalidate. Fails closed, like the other verdicts here — an
+ * endpoint that cannot be tested is reported as unreachable rather than thrown at the form.
+ *
+ * The unsaved key is sent so the test matches the form as it stands, not as it was last saved.
+ */
+export async function testAgentConnection(
+ endpoint: string,
+ key: string,
+): Promise<ConnectionVerdict> {
+ try {
+ const response = await tryClient("/api/agents/test-connection", {
+ method: "POST",
+ body: {
+ endpoint,
+ ...(key.trim() ? { headers: { Authorization: key.trim() } } : {}),
+ },
+ });
+ const body = (await response.json().catch(() => null)) as
+ | ConnectionVerdict
+ | { error?: string }
+ | null;
+ if (body && "ok" in body) return body;
+ return {
+ ok: false,
+ reason:
+ (body as { error?: string } | null)?.error ??
+ "The connection could not be tested.",
+ };
+ } catch {
+ return { ok: false, reason: "The connection could not be tested." };
+ }
+}
diff --git a/app/src/lib/audit/queries.ts b/app/src/lib/audit/queries.ts
index 9f0d0627..fe15f9c8 100644
--- a/app/src/lib/audit/queries.ts
+++ b/app/src/lib/audit/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client } from "@/lib/client";
export const auditKeys = { all: ["audit-events"] as const };
@@ -6,10 +7,9 @@ export function auditEventsQueryOptions(search = "") {
return queryOptions({
queryKey: [...auditKeys.all, search] as const,
queryFn: async () => {
- const response = await fetch(`/api/admin/audit-events${search}`, {
- credentials: "include",
+ const response = await client(`/api/admin/audit-events${search}`, {
+ fallback: "Could not load audit events",
});
- if (!response.ok) throw new Error("Could not load audit events");
return response.json();
},
});
diff --git a/app/src/lib/auth/mutations.ts b/app/src/lib/auth/mutations.ts
index 164a4e75..771ee0df 100644
--- a/app/src/lib/auth/mutations.ts
+++ b/app/src/lib/auth/mutations.ts
@@ -1,14 +1,12 @@
import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client } from "@/lib/client";
import { authKeys } from "./queries";
async function signOut() {
- const response = await fetch("/api/auth/sign-out", {
+ await client("/api/auth/sign-out", {
method: "POST",
- credentials: "include",
+ fallback: "Could not sign out",
});
- if (!response.ok) {
- throw new Error(`Could not sign out (${response.status})`);
- }
}
export function signOutMutationOptions(queryClient: QueryClient) {
diff --git a/app/src/lib/auth/queries.ts b/app/src/lib/auth/queries.ts
index 2b1f2a8d..aee0db55 100644
--- a/app/src/lib/auth/queries.ts
+++ b/app/src/lib/auth/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { tryClient } from "@/lib/client";
export type AuthenticatedUser = {
id: string;
@@ -14,7 +15,11 @@ export const authKeys = {
};
async function currentUser(): Promise<AuthenticatedUser | null> {
- const response = await fetch("/api/me", { credentials: "include" });
+ /*
+ * `tryClient` rather than `client`: not being signed in is an answer here, not a failure, and it
+ * arrives as a 401 that has to be read before anything decides the request went wrong.
+ */
+ const response = await tryClient("/api/me");
if (response.status === 401) {
return null;
}
diff --git a/app/src/lib/channels/mutations.ts b/app/src/lib/channels/mutations.ts
index 776756cf..95f7185d 100644
--- a/app/src/lib/channels/mutations.ts
+++ b/app/src/lib/channels/mutations.ts
@@ -1,4 +1,5 @@
import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client, tryClient } from "@/lib/client";
import { type AgentChannel, channelKeys } from "./queries";
/**
@@ -9,19 +10,11 @@ import { type AgentChannel, channelKeys } from "./queries";
export function createChannelMutationOptions(queryClient: QueryClient) {
return mutationOptions({
mutationFn: async (agentIds: string[]): Promise<AgentChannel> => {
- const response = await fetch("/api/channels", {
+ const response = await client("/api/channels", {
method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ agentIds }),
+ body: { agentIds },
+ fallback: "Could not start a channel",
});
- if (!response.ok) {
- const message = await response
- .json()
- .then((body: { error?: string }) => body.error)
- .catch(() => undefined);
- throw new Error(message ?? "Could not start a channel");
- }
return ((await response.json()) as { channel: AgentChannel }).channel;
},
onSuccess: () =>
@@ -45,15 +38,14 @@ export function recordChannelActivityMutationOptions() {
agentId: string | null;
at: string;
}) => {
- await fetch(`/api/channels/${variables.channelId}/activity`, {
+ /* Still fire-and-forget: `tryClient` does not throw, and the result is not read. */
+ await tryClient(`/api/channels/${variables.channelId}/activity`, {
method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({
+ body: {
agentId: variables.agentId,
at: variables.at,
text: variables.text,
- }),
+ },
});
},
});
diff --git a/app/src/lib/channels/queries.ts b/app/src/lib/channels/queries.ts
index 7a58550b..21124dae 100644
--- a/app/src/lib/channels/queries.ts
+++ b/app/src/lib/channels/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client } from "@/lib/client";
/**
* A channel as the browser sees it.
@@ -35,12 +36,9 @@ export function channelListQueryOptions() {
return queryOptions({
queryKey: channelKeys.list(),
queryFn: async (): Promise<ChannelSummary[]> => {
- const response = await fetch("/api/channels", {
- credentials: "include",
+ return client("/api/channels", "channels", {
+ fallback: "Could not load channels",
});
- if (!response.ok) throw new Error("Could not load channels");
- return ((await response.json()) as { channels: ChannelSummary[] })
- .channels;
},
});
}
@@ -49,11 +47,9 @@ export function channelQueryOptions(channelId: string) {
return queryOptions({
queryKey: channelKeys.detail(channelId),
queryFn: async (): Promise<AgentChannel> => {
- const response = await fetch(`/api/channels/${channelId}`, {
- credentials: "include",
+ return client(`/api/channels/${channelId}`, "channel", {
+ fallback: "Could not load this channel",
});
- if (!response.ok) throw new Error("Could not load this channel");
- return ((await response.json()) as { channel: AgentChannel }).channel;
},
});
}
diff --git a/app/src/lib/client.ts b/app/src/lib/client.ts
new file mode 100644
index 00000000..2abae4c4
--- /dev/null
+++ b/app/src/lib/client.ts
@@ -0,0 +1,102 @@
+/**
+ * The one place the browser talks to the API server.
+ *
+ * WHAT THIS REPLACES. Every read opened with the same four lines — fetch with `credentials`, check
+ * `ok`, throw a sentence, unwrap the envelope — and every entity that wrote more than once grew its
+ * own private copy of the same request helper: `agentRequest`, `componentRequest`, and two others,
+ * identical apart from the fallback sentence. Four copies of one function is four places for the
+ * `body.error` extraction to be forgotten, and it had been, in more than one of them.
+ *
+ * WHAT IT DOES NOT DO. It owns the transport and nothing about meaning. The envelope key and the
+ * sentence a person reads are per-endpoint facts, so they stay at the call site — a client that
+ * guessed the envelope would be a client that had to be argued with.
+ */
+
+export type ClientOptions = {
+ /** Absent means GET. */
+ method?: string;
+ /** Serialised as JSON, which is also what sets the content type. */
+ body?: unknown;
+ /**
+ * What a person reads when the server sent no message of its own.
+ *
+ * Name the entity in it — "Could not load coworkers" rather than "Request failed" — because this
+ * is the sentence that reaches the screen when the server is the one that broke.
+ */
+ fallback?: string;
+ /** For the calls a Bot makes on a person's behalf, which are abandoned when the turn is. */
+ signal?: AbortSignal;
+};
+
+/** Every request in this app is authenticated, and every one of them is JSON or nothing. */
+async function send(path: string, options: ClientOptions): Promise<Response> {
+ return fetch(path, {
+ method: options.method,
+ credentials: "include",
+ headers:
+ options.body === undefined
+ ? undefined
+ : { "content-type": "application/json" },
+ body: options.body === undefined ? undefined : JSON.stringify(options.body),
+ ...(options.signal ? { signal: options.signal } : {}),
+ });
+}
+
+/**
+ * A request whose failure is a value rather than a throw.
+ *
+ * For the endpoints where a refusal is the answer: the gateway declining a component call, or the
+ * catalogue announcement that is allowed to come back empty. Those callers read the status
+ * themselves, and turning a refusal into an exception would make the boundary working look like the
+ * boundary breaking.
+ */
+export function tryClient(
+ path: string,
+ options: ClientOptions = {},
+): Promise<Response> {
+ return send(path, options);
+}
+
+/**
+ * A request that throws when the server says no, carrying the server's own message.
+ *
+ * With a `key`, the JSON body is parsed and that key unwrapped, so a caller receives the payload
+ * rather than the envelope it arrived in. Without one, the `Response` is returned for a caller that
+ * only needed to know it worked.
+ */
+export async function client<T>(
+ path: string,
+ key: string,
+ options?: ClientOptions,
+): Promise<T>;
+export async function client(
+ path: string,
+ options?: ClientOptions,
+): Promise<Response>;
+export async function client<T>(
+ path: string,
+ keyOrOptions?: string | ClientOptions,
+ maybeOptions?: ClientOptions,
+): Promise<T | Response> {
+ const key = typeof keyOrOptions === "string" ? keyOrOptions : undefined;
+ const options =
+ (typeof keyOrOptions === "string" ? maybeOptions : keyOrOptions) ?? {};
+
+ const response = await send(path, options);
+
+ if (!response.ok) {
+ /*
+ * The server's message is the useful one: it names the field or the permission that failed. The
+ * fallback is only for the cases where it sent none, or sent something that is not JSON.
+ */
+ const message = await response
+ .json()
+ .then((body: { error?: string }) => body.error)
+ .catch(() => undefined);
+ throw new Error(message ?? options.fallback ?? "That request failed.");
+ }
+
+ if (key === undefined) return response;
+
+ return ((await response.json()) as Record<string, T>)[key];
+}
diff --git a/app/src/lib/components/mutations.ts b/app/src/lib/components/mutations.ts
new file mode 100644
index 00000000..9de0711a
--- /dev/null
+++ b/app/src/lib/components/mutations.ts
@@ -0,0 +1,106 @@
+import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client } from "@/lib/client";
+import { componentKeys } from "./queries";
+
+/**
+ * Writes against a component's governance: publication, per-Bot grants, per-function grants, and the
+ * draft description.
+ *
+ * Every one of these is a decision the server records and may refuse, so none of them patch the
+ * cache — the list is invalidated and the screen re-reads whatever was actually decided.
+ */
+
+/** The sentence for every write here, for the rare case the server sends none of its own. */
+const FALLBACK = "Component operation failed";
+
+/** Server-derived fields are invalidated instead of patched by hand. */
+function invalidateComponents(queryClient: QueryClient) {
+ return queryClient.invalidateQueries({ queryKey: componentKeys.all });
+}
+
+/** The path segment for one component, which is a tool name rather than an opaque id. */
+function componentPath(name: string): string {
+ return `/api/components/${encodeURIComponent(name)}`;
+}
+
+/**
+ * Whether one Bot may answer with a component.
+ *
+ * Granting posts to the collection; withholding deletes from it. The absence of a grant is what
+ * withholds it, so there is no third state to send.
+ */
+export function setComponentGrantMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (variables: {
+ name: string;
+ agentId: string;
+ granted: boolean;
+ }) => {
+ await (variables.granted
+ ? client(`${componentPath(variables.name)}/grants`, {
+ method: "POST",
+ body: { agentId: variables.agentId },
+ fallback: FALLBACK,
+ })
+ : client(
+ `${componentPath(variables.name)}/grants/${encodeURIComponent(variables.agentId)}`,
+ { method: "DELETE", fallback: FALLBACK },
+ ));
+ },
+ onSuccess: () => invalidateComponents(queryClient),
+ });
+}
+
+/** Whether a component may read one deployment data function. */
+export function setComponentFunctionMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (variables: {
+ name: string;
+ functionName: string;
+ granted: boolean;
+ }) => {
+ await (variables.granted
+ ? client(`${componentPath(variables.name)}/functions`, {
+ method: "POST",
+ body: { function: variables.functionName },
+ fallback: FALLBACK,
+ })
+ : client(
+ `${componentPath(variables.name)}/functions/${encodeURIComponent(variables.functionName)}`,
+ { method: "DELETE", fallback: FALLBACK },
+ ));
+ },
+ onSuccess: () => invalidateComponents(queryClient),
+ });
+}
+
+/** Whether any Bot is told the component exists. */
+export function setComponentPublishedMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (variables: { name: string; published: boolean }) => {
+ await client(`${componentPath(variables.name)}/publication`, {
+ method: "POST",
+ body: { published: variables.published },
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidateComponents(queryClient),
+ });
+}
+
+/**
+ * The description the model will read once it is published. Saving it changes nothing a Bot can see
+ * until publication, which is why it is a separate write.
+ */
+export function saveComponentDraftMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (variables: { name: string; description: string }) => {
+ await client(`${componentPath(variables.name)}/draft`, {
+ method: "PUT",
+ body: { description: variables.description },
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidateComponents(queryClient),
+ });
+}
diff --git a/app/src/lib/components/queries.ts b/app/src/lib/components/queries.ts
index 2170dd32..5a0b75ee 100644
--- a/app/src/lib/components/queries.ts
+++ b/app/src/lib/components/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client, tryClient } from "@/lib/client";
/** A component as the Admin surface sees it: its state, its versions and who is held back from it. */
export type ComponentRecord = {
@@ -34,11 +35,11 @@ export function componentListQueryOptions() {
return queryOptions({
queryKey: componentKeys.list(),
queryFn: async (): Promise<ComponentRecord[]> => {
- const response = await fetch("/api/components", {
- credentials: "include",
- });
- if (!response.ok) throw new Error("The components could not be loaded.");
- return (await response.json()).components ?? [];
+ return (
+ (await client("/api/components", "components", {
+ fallback: "The components could not be loaded.",
+ })) ?? []
+ );
},
});
}
@@ -58,14 +59,13 @@ export function agentComponentsQueryOptions(agentId: string | undefined) {
// out an interval before it shows.
refetchOnWindowFocus: true,
queryFn: async (): Promise<GrantedComponent[]> => {
- const response = await fetch(
- `/api/components/for-agent/${encodeURIComponent(agentId ?? "")}`,
- { credentials: "include" },
+ return (
+ (await client(
+ `/api/components/for-agent/${encodeURIComponent(agentId ?? "")}`,
+ "components",
+ { fallback: "This Bot's components could not be loaded." },
+ )) ?? []
);
- if (!response.ok) {
- throw new Error("This Bot's components could not be loaded.");
- }
- return (await response.json()).components ?? [];
},
});
}
@@ -80,11 +80,9 @@ export async function announceGallery(
}[],
): Promise<string[]> {
try {
- const response = await fetch("/api/components/catalogue", {
+ const response = await tryClient("/api/components/catalogue", {
method: "PUT",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ components }),
+ body: { components },
});
if (!response.ok) return [];
return (await response.json()).added ?? [];
@@ -104,12 +102,11 @@ export function dataFunctionsQueryOptions() {
return queryOptions({
queryKey: ["components", "functions"] as const,
queryFn: async (): Promise<DataFunctionSummary[]> => {
- const response = await fetch("/api/components/functions", {
- credentials: "include",
- });
- if (!response.ok)
- throw new Error("The data functions could not be loaded.");
- return (await response.json()).functions ?? [];
+ return (
+ (await client("/api/components/functions", "functions", {
+ fallback: "The data functions could not be loaded.",
+ })) ?? []
+ );
},
});
}
@@ -132,14 +129,9 @@ export async function callComponentFunction(
error?: string;
}> {
try {
- const response = await fetch(
+ const response = await tryClient(
`/api/components/${encodeURIComponent(component)}/call`,
- {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ agentId, args, function: functionName }),
- },
+ { method: "POST", body: { agentId, args, function: functionName } },
);
const payload = await response.json().catch(() => null);
if (payload && typeof payload === "object") {
@@ -169,14 +161,9 @@ export async function decideComponent(
functions: readonly string[] = [],
): Promise<{ allowed: boolean; reason?: string }> {
try {
- const response = await fetch(
+ const response = await tryClient(
`/api/components/${encodeURIComponent(name)}/decision`,
- {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ agentId, functions }),
- },
+ { method: "POST", body: { agentId, functions } },
);
if (!response.ok) {
return {
diff --git a/app/src/lib/computers/control.ts b/app/src/lib/computers/control.ts
new file mode 100644
index 00000000..eddca096
--- /dev/null
+++ b/app/src/lib/computers/control.ts
@@ -0,0 +1,98 @@
+import { tryClient } from "@/lib/client";
+
+/**
+ * Handing control of a Bot's computer to a person, and back.
+ *
+ * Plain functions rather than factories, and every one of them fails closed. Nothing here is cached:
+ * who holds the wheel is a fact about this second, and a stale copy of it would be worse than no
+ * copy — it would show somebody a screen they cannot drive, or let them think they can.
+ *
+ * The reads answer `null` on failure rather than throwing. A panel that cannot say who is driving
+ * should say nothing, not tear down the screen the person is looking at.
+ */
+
+export type ControlState = {
+ holder: "bot" | "human";
+ since: string;
+ reason?: string;
+ requested: boolean;
+ /** What the Bot is waiting for, by name only. Present means show the masked prompt. */
+ secretWanted?: string;
+};
+
+async function callControl(
+ computerId: string,
+ path: string,
+ method?: string,
+): Promise<ControlState | null> {
+ const response = await tryClient(
+ `/api/computers/${computerId}${path}`,
+ method ? { method } : {},
+ );
+ if (!response.ok) return null;
+ return (await response.json()) as ControlState;
+}
+
+export function readControl(computerId: string) {
+ return callControl(computerId, "/control");
+}
+
+export function takeControl(computerId: string) {
+ return callControl(computerId, "/control/take", "POST");
+}
+
+export function releaseControl(computerId: string) {
+ return callControl(computerId, "/control/release", "POST");
+}
+
+/**
+ * Supply a secret synchronously and never echo the value back to the UI.
+ *
+ * The one call here that reports why it failed, because a person is waiting on the answer and a
+ * silent failure would leave them typing into something that is not listening.
+ */
+export async function supplySecret(
+ computerId: string,
+ text: string,
+): Promise<{ ok: boolean; error?: string }> {
+ try {
+ const response = await tryClient(
+ `/api/computers/${computerId}/human/secret`,
+ { method: "POST", body: { text } },
+ );
+ if (response.ok) return { ok: true };
+ const body = (await response.json().catch(() => null)) as {
+ error?: string;
+ } | null;
+ return { ok: false, error: body?.error ?? "That could not be entered." };
+ } catch {
+ return {
+ ok: false,
+ error: "The assistant's computer could not be reached.",
+ };
+ }
+}
+
+/**
+ * Serializes human input requests without blocking the caller; ordering matters for typed secrets.
+ */
+let inputQueue: Promise<unknown> = Promise.resolve();
+
+/**
+ * Send one human input event. Returns immediately; delivery is ordered.
+ */
+export function sendHumanInput(
+ computerId: string,
+ kind: "click" | "type" | "key" | "scroll",
+ body: Record<string, unknown>,
+): void {
+ inputQueue = inputQueue
+ .then(() =>
+ tryClient(`/api/computers/${computerId}/human/${kind}`, {
+ method: "POST",
+ body,
+ }),
+ )
+ // Fire-and-forget: the user can see/retry input failures, while the input queue must keep moving.
+ .catch(() => undefined);
+}
diff --git a/app/src/lib/computers/mutations.ts b/app/src/lib/computers/mutations.ts
new file mode 100644
index 00000000..8fa014be
--- /dev/null
+++ b/app/src/lib/computers/mutations.ts
@@ -0,0 +1,47 @@
+import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client } from "@/lib/client";
+import { type ActionPolicy, computerKeys } from "./queries";
+
+/** Stopping frees the container; resetting also deletes the browser profile. */
+export type ComputerAction = "stop" | "reset";
+
+function invalidateComputers(queryClient: QueryClient) {
+ return queryClient.invalidateQueries({ queryKey: computerKeys.all });
+}
+
+export function setComputerStateMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (variables: {
+ botId: string;
+ action: ComputerAction;
+ }) => {
+ await client(
+ `/api/computers/${encodeURIComponent(variables.botId)}/computers/${variables.action}`,
+ {
+ method: "POST",
+ fallback: `The computer could not be ${variables.action}.`,
+ },
+ );
+ },
+ onSuccess: () => invalidateComputers(queryClient),
+ });
+}
+
+/**
+ * Replace the whole policy.
+ *
+ * A PUT rather than a patch because the rules are ordered and evaluated as a set: sending a
+ * difference would leave the server deciding where a new rule belongs, and where a deny sits
+ * relative to an allow is most of what a policy means.
+ */
+export function saveActionPolicyMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: (next: ActionPolicy): Promise<ActionPolicy> =>
+ client("/api/computers/policy", "policy", {
+ method: "PUT",
+ body: next,
+ fallback: "The boundary could not be saved.",
+ }),
+ onSuccess: () => invalidateComputers(queryClient),
+ });
+}
diff --git a/app/src/lib/computers/queries.ts b/app/src/lib/computers/queries.ts
new file mode 100644
index 00000000..23873ae3
--- /dev/null
+++ b/app/src/lib/computers/queries.ts
@@ -0,0 +1,69 @@
+import { queryOptions } from "@tanstack/react-query";
+import { client } from "@/lib/client";
+
+/** One Bot's computer, as Admin sees it. */
+export type ComputerProfile = {
+ botId: string;
+ running: boolean;
+ startedAt: string | null;
+ egress: string | null;
+};
+
+/** Whether each Bot has a browser profile of its own, or they share one. */
+export type ComputerIsolation = "per-bot" | "shared";
+
+/** What the list endpoint answers: the computers, and how they are separated. */
+export type ComputerFleet = {
+ computers: ComputerProfile[];
+ isolation?: ComputerIsolation;
+};
+
+/**
+ * Whether the boundary acts on its verdict.
+ *
+ * `dry-run` records what it would have refused without refusing it, which is how a policy is tried
+ * out before it stops a Bot mid-task.
+ */
+export type PolicyMode = "dry-run" | "enforce";
+
+/** The rules a Bot's actions are judged against. */
+export type ActionPolicy = {
+ mode: PolicyMode;
+ deny: string[];
+ allow: string[];
+};
+
+export const computerKeys = {
+ all: ["computers"] as const,
+ fleet: () => ["computers", "fleet"] as const,
+ policy: () => ["computers", "policy"] as const,
+};
+
+/**
+ * A placeholder id in the path. The endpoint answers with every computer regardless, so this is
+ * addressing a collection through a member's route rather than naming one.
+ */
+const FLEET_ID = "openbot-computer";
+
+/** No envelope key: the body carries both the list and the isolation mode. */
+export function computerFleetQueryOptions() {
+ return queryOptions({
+ queryKey: computerKeys.fleet(),
+ queryFn: async (): Promise<ComputerFleet> => {
+ const response = await client(`/api/computers/${FLEET_ID}/computers`, {
+ fallback: "The computers could not be listed.",
+ });
+ return response.json();
+ },
+ });
+}
+
+export function actionPolicyQueryOptions() {
+ return queryOptions({
+ queryKey: computerKeys.policy(),
+ queryFn: (): Promise<ActionPolicy> =>
+ client("/api/computers/policy", "policy", {
+ fallback: "The boundary could not be read.",
+ }),
+ });
+}
diff --git a/app/src/lib/computers/screen.ts b/app/src/lib/computers/screen.ts
new file mode 100644
index 00000000..874a5438
--- /dev/null
+++ b/app/src/lib/computers/screen.ts
@@ -0,0 +1,42 @@
+import { tryClient } from "@/lib/client";
+
+/**
+ * One frame of a Bot's screen.
+ *
+ * Not a cached read. Frames are polled while somebody is watching and are stale the moment after
+ * they arrive, so holding one in a query cache would mean serving a picture of a screen that has
+ * since moved.
+ */
+export type Screenshot = {
+ base64: string;
+ width: number;
+ height: number;
+ capturedAt: string;
+ /** `about:blank` when the browser has not been sent anywhere yet. Absent on older computers. */
+ url?: string;
+};
+
+/**
+ * Read the current frame.
+ *
+ * Fails closed, and says why: the screen going unavailable is something the person watching needs
+ * told, and it is not a reason to tear down the panel they are watching it in. The caller decides
+ * whether to keep polling.
+ */
+export async function readScreenshot(
+ computerId: string,
+): Promise<{ frame?: Screenshot; error?: string }> {
+ const unavailable = "The screen is not available right now.";
+ try {
+ const response = await tryClient(`/api/computers/${computerId}/screenshot`);
+ if (!response.ok) {
+ const body = (await response.json().catch(() => null)) as {
+ error?: string;
+ } | null;
+ return { error: body?.error ?? unavailable };
+ }
+ return { frame: (await response.json()) as Screenshot };
+ } catch {
+ return { error: unavailable };
+ }
+}
diff --git a/app/src/lib/connectors/mutations.ts b/app/src/lib/connectors/mutations.ts
new file mode 100644
index 00000000..0c627f80
--- /dev/null
+++ b/app/src/lib/connectors/mutations.ts
@@ -0,0 +1,30 @@
+import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client } from "@/lib/client";
+import { connectorKeys } from "./queries";
+
+/** What Google Drive needs before it can read anything on a deployment's behalf. */
+export type GoogleDriveSetupInput = {
+ serviceAccountJson: string;
+ impersonationSubject: string;
+};
+
+/**
+ * Configure the Google Drive connector.
+ *
+ * The service account JSON is a credential, so it goes one way only: it is sent here and never read
+ * back. What a later read returns is whether the connector is configured, not what it was configured
+ * with.
+ */
+export function setUpGoogleDriveMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (input: GoogleDriveSetupInput) => {
+ await client("/api/admin/connectors/google-drive/setup", {
+ method: "POST",
+ body: input,
+ fallback: "Could not set up Google Drive",
+ });
+ },
+ onSuccess: () =>
+ queryClient.invalidateQueries({ queryKey: connectorKeys.all }),
+ });
+}
diff --git a/app/src/lib/connectors/queries.ts b/app/src/lib/connectors/queries.ts
index ac0e08f3..6f3d984f 100644
--- a/app/src/lib/connectors/queries.ts
+++ b/app/src/lib/connectors/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client } from "@/lib/client";
export type ConnectorStatus = {
id: string;
@@ -17,12 +18,9 @@ export function connectorListQueryOptions() {
return queryOptions({
queryKey: connectorKeys.list(),
queryFn: async (): Promise<ConnectorStatus[]> => {
- const response = await fetch("/api/admin/connectors", {
- credentials: "include",
+ return client("/api/admin/connectors", "connectors", {
+ fallback: "Could not load connectors",
});
- if (!response.ok) throw new Error("Could not load connectors");
- return ((await response.json()) as { connectors: ConnectorStatus[] })
- .connectors;
},
});
}
diff --git a/app/src/lib/copilot/bot-thread.ts b/app/src/lib/copilot/bot-thread.ts
index 087b852d..82480558 100644
--- a/app/src/lib/copilot/bot-thread.ts
+++ b/app/src/lib/copilot/bot-thread.ts
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
+import { tryClient } from "@/lib/client";
/**
* The thread the direct Bot chat talks in.
@@ -32,10 +33,7 @@ function remember(agentId: string, threadId: string): void {
async function mint(): Promise<string | null> {
try {
- const response = await fetch("/api/threads/mint", {
- method: "POST",
- credentials: "include",
- });
+ const response = await tryClient("/api/threads/mint", { method: "POST" });
if (!response.ok) return null;
const body = (await response.json()) as { threadId?: unknown };
return typeof body.threadId === "string" ? body.threadId : null;
diff --git a/app/src/lib/copilot/computer-tools.tsx b/app/src/lib/copilot/computer-tools.tsx
index ce480b13..a7be0e15 100644
--- a/app/src/lib/copilot/computer-tools.tsx
+++ b/app/src/lib/copilot/computer-tools.tsx
@@ -1,11 +1,9 @@
import { useFrontendTool } from "@copilotkit/react-core/v2";
import { z } from "zod";
+import { tryClient } from "@/lib/client";
import { ToolLine } from "@/components/channels/tool-line";
import { ComputerView } from "@/components/computer/computer-view";
-import {
- type ControlState,
- readControl,
-} from "@/components/computer/take-the-wheel";
+import { readControl, type ControlState } from "@/lib/computers/control";
import { useActiveBotHolder } from "./active-bot";
import { reportComputerActivity } from "./computer-activity";
@@ -45,18 +43,22 @@ async function waitForPerson(
async function callComputer(
botId: string,
path: string,
- init?: RequestInit,
+ /*
+ * A body, not a `RequestInit`. The client serialises it, so a caller that stringified first would
+ * send a JSON string of a JSON string — which is what happened, briefly, when this moved over.
+ */
+ init?: { method?: string; body?: unknown },
signal?: AbortSignal,
): Promise<ToolOutcome> {
// Announce before the call so the screen can open while the action is running.
reportComputerActivity(botId);
let response: Response;
try {
- response = await fetch(`/api/computers/${botId}${path}`, {
- credentials: "include",
+ response = await tryClient(`/api/computers/${botId}${path}`, {
+ method: init?.method,
+ body: init?.body,
// Abort cancels the request and prevents later actions, but cannot undo browser work already executing.
- ...(signal ? { signal } : {}),
- ...init,
+ signal,
});
} catch (error) {
// An abort is a stopped run, not a computer failure.
@@ -194,8 +196,7 @@ export function ComputerTools() {
"/navigate",
{
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ url }),
+ body: { url },
},
signal,
);
@@ -285,8 +286,7 @@ export function ComputerTools() {
"/type",
{
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
+ body: input,
},
signal,
),
@@ -327,8 +327,7 @@ export function ComputerTools() {
"/click",
{
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
+ body: input,
},
signal,
),
@@ -378,8 +377,7 @@ export function ComputerTools() {
"/key",
{
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
+ body: input,
},
signal,
),
@@ -426,8 +424,7 @@ export function ComputerTools() {
"/control/secret",
{
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
+ body: input,
},
signal,
);
@@ -476,15 +473,9 @@ export function ComputerTools() {
{ signal }: { signal?: AbortSignal } = {},
) => {
try {
- const response = await fetch(
+ const response = await tryClient(
`/api/agents/${encodeURIComponent(bot.current)}/declined`,
- {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
- ...(signal ? { signal } : {}),
- },
+ { method: "POST", body: input, signal },
);
return response.ok
? "Recorded. Now tell the person what you decided and why."
@@ -521,8 +512,7 @@ export function ComputerTools() {
"/control/request",
{
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
+ body: input,
},
signal,
);
@@ -563,8 +553,7 @@ export function ComputerTools() {
handler: async (input: { path?: string }) =>
callComputer(bot.current, "/files/list", {
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input ?? {}),
+ body: input ?? {},
}),
render: ({ result, status }) => {
const outcome = outcomeOf(result);
@@ -601,8 +590,7 @@ export function ComputerTools() {
handler: async (input: { path: string }) =>
callComputer(bot.current, "/files/read", {
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
+ body: input,
}),
render: ({ args, result, status }) => {
const outcome = outcomeOf(result);
@@ -649,8 +637,7 @@ export function ComputerTools() {
}) =>
callComputer(bot.current, "/files/write", {
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
+ body: input,
}),
render: ({ args, result, status }) => {
const outcome = outcomeOf(result);
@@ -692,8 +679,7 @@ export function ComputerTools() {
"/scroll",
{
method: "POST",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(input),
+ body: input,
},
signal,
),
diff --git a/app/src/lib/copilot/gallery-registry.ts b/app/src/lib/copilot/gallery-registry.ts
index 152f7744..be999ea3 100644
--- a/app/src/lib/copilot/gallery-registry.ts
+++ b/app/src/lib/copilot/gallery-registry.ts
@@ -38,6 +38,9 @@ export type GalleryComponent = {
* Props rather than tool arguments, because they are not always the same thing: a component that
* suspends the run is handed the whole interaction, `{ status, args, respond }`, and would crash
* on arguments alone.
+ *
+ * Omitted by a component that cannot be drawn away from a conversation, which is then shown as an
+ * unpreviewable tile rather than as a component that failed.
*/
preview?: Record<string, unknown>;
Component: (props: Record<string, unknown>) => ReactElement | null;
@@ -103,3 +106,17 @@ export function galleryManifest(): GalleryManifestEntry[] {
export const RENDERABLE_NAMES: ReadonlySet<string> = new Set(
GALLERY_COMPONENTS.map((component) => component.name),
);
+
+const BY_NAME: ReadonlyMap<string, GalleryComponent> = new Map(
+ GALLERY_COMPONENTS.map((component) => [component.name, component]),
+);
+
+/**
+ * The component behind a catalogue name, or `undefined` where this build has no renderer for it.
+ *
+ * A deployment's component rows are governance state and outlive the build that drew them, so a
+ * name arriving from the server is not a promise that anything here can draw it.
+ */
+export function galleryComponent(name: string): GalleryComponent | undefined {
+ return BY_NAME.get(name);
+}
diff --git a/app/src/lib/copilot/thread-messages.ts b/app/src/lib/copilot/thread-messages.ts
new file mode 100644
index 00000000..fcc2b8aa
--- /dev/null
+++ b/app/src/lib/copilot/thread-messages.ts
@@ -0,0 +1,26 @@
+import type { Message } from "@ag-ui/core";
+import { tryClient } from "@/lib/client";
+
+/**
+ * The messages a thread already holds, for restoring a conversation somebody comes back to.
+ *
+ * A plain fail-closed function rather than a query. Nothing caches it — the transcript this seeds is
+ * then owned by the running agent, so a cached copy would be a second version of the same
+ * conversation — and an unreadable history is not a reason to keep somebody from typing. Every
+ * failure returns nothing and lets the composer open.
+ */
+export async function readThreadMessages(
+ threadId: string,
+ agentId: string,
+): Promise<Message[]> {
+ try {
+ const response = await tryClient(
+ `/api/copilotkit/threads/${encodeURIComponent(threadId)}/messages?agentId=${encodeURIComponent(agentId)}`,
+ );
+ if (!response.ok) return [];
+ const stored = (await response.json())?.messages;
+ return Array.isArray(stored) ? (stored as Message[]) : [];
+ } catch {
+ return [];
+ }
+}
diff --git a/app/src/lib/credentials/mutations.ts b/app/src/lib/credentials/mutations.ts
index 950651a1..5b15e137 100644
--- a/app/src/lib/credentials/mutations.ts
+++ b/app/src/lib/credentials/mutations.ts
@@ -1,4 +1,5 @@
import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client } from "@/lib/client";
import { credentialKeys } from "./queries";
export type CredentialInput = {
@@ -9,20 +10,14 @@ export type CredentialInput = {
plaintext: string;
};
-async function credentialRequest(path: string, body?: CredentialInput) {
- const response = await fetch(path, {
- method: "POST",
- credentials: "include",
- headers: body ? { "content-type": "application/json" } : undefined,
- body: body ? JSON.stringify(body) : undefined,
- });
- if (!response.ok) throw new Error("Credential operation failed");
-}
-
export function createCredentialMutationOptions(queryClient: QueryClient) {
return mutationOptions({
mutationFn: (input: CredentialInput) =>
- credentialRequest("/api/admin/credentials", input),
+ client("/api/admin/credentials", {
+ method: "POST",
+ body: input,
+ fallback: "Credential operation failed",
+ }),
onSuccess: () =>
queryClient.invalidateQueries({ queryKey: credentialKeys.all }),
});
@@ -31,8 +26,44 @@ export function createCredentialMutationOptions(queryClient: QueryClient) {
export function revokeCredentialMutationOptions(queryClient: QueryClient) {
return mutationOptions({
mutationFn: (credentialId: string) =>
- credentialRequest(`/api/admin/credentials/${credentialId}/revoke`),
+ client(`/api/admin/credentials/${credentialId}/revoke`, {
+ method: "POST",
+ fallback: "Credential operation failed",
+ }),
onSuccess: () =>
queryClient.invalidateQueries({ queryKey: credentialKeys.all }),
});
}
+
+/**
+ * Store an MCP server's token and hand back the credential id.
+ *
+ * A plain function rather than a factory, because it is a step inside another write rather than a
+ * write somebody asked for: a plugin server record keeps only the credential id, so the token has to
+ * become a credential before the server can be created. Returns `undefined` for an empty token,
+ * which is how a server with no auth is added.
+ *
+ * The token goes one way. What a later read returns is that a credential exists, never its value.
+ */
+export async function storeMcpToken(
+ serverId: string,
+ token?: string,
+): Promise<string | undefined> {
+ if (!token?.trim()) return undefined;
+ const credential = await client<{ id: string }>(
+ "/api/admin/credentials",
+ "credential",
+ {
+ method: "POST",
+ body: {
+ kind: "mcp",
+ provider: serverId,
+ keyId: `mcp-${serverId}`,
+ plaintext: token.trim(),
+ metadata: { server: serverId },
+ },
+ fallback: "The token could not be stored.",
+ },
+ );
+ return credential?.id;
+}
diff --git a/app/src/lib/credentials/queries.ts b/app/src/lib/credentials/queries.ts
index 4cc2c7eb..fe19bb40 100644
--- a/app/src/lib/credentials/queries.ts
+++ b/app/src/lib/credentials/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client } from "@/lib/client";
export type CredentialStatus = {
id: string;
@@ -18,12 +19,9 @@ export function credentialListQueryOptions() {
return queryOptions({
queryKey: credentialKeys.list(),
queryFn: async (): Promise<CredentialStatus[]> => {
- const response = await fetch("/api/admin/credentials", {
- credentials: "include",
+ return client("/api/admin/credentials", "credentials", {
+ fallback: "Could not load credentials",
});
- if (!response.ok) throw new Error("Could not load credentials");
- return ((await response.json()) as { credentials: CredentialStatus[] })
- .credentials;
},
});
}
diff --git a/app/src/lib/package/queries.ts b/app/src/lib/package/queries.ts
index 630df72a..24505cb8 100644
--- a/app/src/lib/package/queries.ts
+++ b/app/src/lib/package/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client } from "@/lib/client";
export const packageKeys = { active: ["tenant-package", "active"] as const };
@@ -6,10 +7,9 @@ export function activePackageQueryOptions() {
return queryOptions({
queryKey: packageKeys.active,
queryFn: async () => {
- const response = await fetch("/api/admin/package", {
- credentials: "include",
+ const response = await client("/api/admin/package", {
+ fallback: "Could not load the active package",
});
- if (!response.ok) throw new Error("Could not load the active package");
return response.json();
},
});
diff --git a/app/src/lib/plugins/mutations.ts b/app/src/lib/plugins/mutations.ts
new file mode 100644
index 00000000..126fb305
--- /dev/null
+++ b/app/src/lib/plugins/mutations.ts
@@ -0,0 +1,171 @@
+import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client } from "@/lib/client";
+import { pluginKeys } from "./queries";
+
+/**
+ * Writes against what a deployment has installed: MCP servers, skills, and which Bots carry them.
+ *
+ * Servers and skills are two kinds of the same thing here — a plugin the deployment holds and grants
+ * — which is why one grant endpoint serves both and takes the kind as an argument rather than having
+ * two of everything.
+ */
+
+/** A skill as the server accepts it. `global` is an administrator writing for everybody. */
+export type SkillInput = {
+ slug: string;
+ title: string;
+ summary?: string;
+ instructions: string;
+ global?: boolean;
+};
+
+/** A curated server from the catalogue, which supplies the URL. */
+export type CuratedServerInput = {
+ key: string;
+ instanceHost?: string;
+ credentialId?: string;
+};
+
+/**
+ * A server somebody typed the URL of, which therefore has to pass the URL checks.
+ *
+ * `token` is carried through as the previous version did. It is already a credential by the time
+ * this is sent — the id beside it is what the record keeps — so the server has no use for it.
+ */
+export type CustomServerInput = {
+ id: string;
+ title: string;
+ url: string;
+ token?: string;
+ credentialId?: string;
+};
+
+/** Which kinds of plugin a grant can be about. */
+export type PluginKind = "mcp" | "skill";
+
+const FALLBACK = "That did not work.";
+
+function invalidatePlugins(queryClient: QueryClient) {
+ return queryClient.invalidateQueries({ queryKey: pluginKeys.all });
+}
+
+/**
+ * Whether one Bot carries one plugin.
+ *
+ * Granting posts to the collection; withholding deletes from it, and the delete identifies the row
+ * by query string because a grant has no id of its own — it is the three things it joins.
+ */
+export function setPluginGrantMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (variables: {
+ kind: PluginKind;
+ ref: string;
+ agentId: string;
+ granted: boolean;
+ }) => {
+ if (variables.granted) {
+ await client("/api/plugins/grants", {
+ method: "POST",
+ body: {
+ kind: variables.kind,
+ ref: variables.ref,
+ agentId: variables.agentId,
+ },
+ fallback: "That Agent could not be changed.",
+ });
+ return;
+ }
+ await client(
+ `/api/plugins/grants?kind=${variables.kind}&ref=${encodeURIComponent(variables.ref)}&agentId=${encodeURIComponent(variables.agentId)}`,
+ { method: "DELETE", fallback: "That Agent could not be changed." },
+ );
+ },
+ onSuccess: () => invalidatePlugins(queryClient),
+ });
+}
+
+export function addCuratedServerMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (input: CuratedServerInput) => {
+ await client("/api/plugins/servers", {
+ method: "POST",
+ body: input,
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidatePlugins(queryClient),
+ });
+}
+
+export function addCustomServerMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (input: CustomServerInput) => {
+ await client("/api/plugins/servers/custom", {
+ method: "POST",
+ body: input,
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidatePlugins(queryClient),
+ });
+}
+
+/** Re-read a server's tool list, which is what makes a newly-added tool appear. */
+export function refreshPluginServerMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (serverId: string) => {
+ await client(`/api/plugins/servers/${serverId}/refresh`, {
+ method: "POST",
+ body: {},
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidatePlugins(queryClient),
+ });
+}
+
+export function removePluginServerMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (serverId: string) => {
+ await client(`/api/plugins/servers/${encodeURIComponent(serverId)}`, {
+ method: "DELETE",
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidatePlugins(queryClient),
+ });
+}
+
+/**
+ * Write a skill, or rewrite one.
+ *
+ * One endpoint for both: the slug is the identity, so posting an existing one replaces it. The
+ * fallback names saving rather than creating for that reason.
+ */
+export function saveSkillMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: (input: SkillInput): Promise<unknown> =>
+ client("/api/plugins/skills", {
+ method: "POST",
+ body: input,
+ /*
+ * The server refuses for reasons a form cannot check — a slug somebody else already owns is
+ * the common one — and paraphrasing that would throw away the only part worth reading.
+ */
+ fallback: "The skill could not be saved.",
+ }),
+ onSuccess: () => invalidatePlugins(queryClient),
+ });
+}
+
+export function removeSkillMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (slug: string) => {
+ await client(`/api/plugins/skills/${encodeURIComponent(slug)}`, {
+ method: "DELETE",
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidatePlugins(queryClient),
+ });
+}
diff --git a/app/src/lib/plugins/queries.ts b/app/src/lib/plugins/queries.ts
index aad4c73a..14d3a36a 100644
--- a/app/src/lib/plugins/queries.ts
+++ b/app/src/lib/plugins/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client, tryClient } from "@/lib/client";
/** A tool one server offers, as the Plugins page sees it. */
export type PluginTool = {
@@ -85,8 +86,9 @@ export function pluginsPageQueryOptions() {
return queryOptions({
queryKey: pluginKeys.page(),
queryFn: async (): Promise<PluginsPage> => {
- const response = await fetch("/api/plugins", { credentials: "include" });
- if (!response.ok) throw new Error("Plugins could not be loaded.");
+ const response = await client("/api/plugins", {
+ fallback: "Plugins could not be loaded.",
+ });
return response.json();
},
});
@@ -101,12 +103,10 @@ export function agentPluginsQueryOptions(agentId: string) {
enabled: agentId.length > 0,
refetchInterval: 15_000,
queryFn: async (): Promise<GrantedPlugins> => {
- const response = await fetch(
+ const response = await client(
`/api/plugins/for/${encodeURIComponent(agentId)}`,
- { credentials: "include" },
+ { fallback: "This Bot's plugins could not be read." },
);
- if (!response.ok)
- throw new Error("This Bot's plugins could not be read.");
return response.json();
},
});
@@ -128,12 +128,11 @@ export async function callPluginTool(
agentId: string,
signal?: AbortSignal,
): Promise<PluginCallOutcome> {
- const response = await fetch("/api/plugins/call", {
+ /* A refused tool is an outcome this returns, not an error it throws. */
+ const response = await tryClient("/api/plugins/call", {
method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ ref, args, agentId }),
- ...(signal ? { signal } : {}),
+ body: { ref, args, agentId },
+ signal,
});
const body = (await response.json().catch(() => null)) as {
diff --git a/app/src/lib/sandboxed/mutations.ts b/app/src/lib/sandboxed/mutations.ts
new file mode 100644
index 00000000..d56e7ab4
--- /dev/null
+++ b/app/src/lib/sandboxed/mutations.ts
@@ -0,0 +1,82 @@
+import { mutationOptions, type QueryClient } from "@tanstack/react-query";
+import { client } from "@/lib/client";
+import { sandboxedKeys } from "./queries";
+
+/**
+ * A browser-authored component as the server accepts it.
+ *
+ * `argumentSchema` and `sampleArguments` arrive parsed. The playground holds them as text while
+ * somebody is typing, and text that does not parse is not a draft the server should be asked to
+ * store — so parsing is the editor's job and this is what survives it.
+ */
+export type SandboxedDraftInput = {
+ slug: string;
+ title: string;
+ description: string;
+ html: string;
+ css: string;
+ jsFunctions: string;
+ argumentSchema: Record<string, unknown>;
+ sampleArguments: Record<string, unknown>;
+};
+
+const FALLBACK = "That did not work.";
+
+function invalidateSandboxed(queryClient: QueryClient) {
+ return queryClient.invalidateQueries({ queryKey: sandboxedKeys.all });
+}
+
+/** The name the server knows a browser-authored component by. */
+function sandboxedName(slug: string): string {
+ return `custom_${slug}`;
+}
+
+export function saveSandboxedDraftMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (input: SandboxedDraftInput) => {
+ await client("/api/sandboxed", {
+ method: "POST",
+ body: input,
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidateSandboxed(queryClient),
+ });
+}
+
+/**
+ * Publish what is on screen.
+ *
+ * Saves first, in the same mutation, because publishing acts on the stored draft rather than on the
+ * editors. Two calls rather than one endpoint, so a save that fails stops the publish — which is the
+ * behaviour worth keeping: publishing a draft the server never received would put something on
+ * screen that nobody wrote.
+ */
+export function publishSandboxedMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (input: SandboxedDraftInput) => {
+ await client("/api/sandboxed", {
+ method: "POST",
+ body: input,
+ fallback: FALLBACK,
+ });
+ await client(
+ `/api/sandboxed/${encodeURIComponent(sandboxedName(input.slug))}/publish`,
+ { method: "POST", fallback: FALLBACK },
+ );
+ },
+ onSuccess: () => invalidateSandboxed(queryClient),
+ });
+}
+
+export function deleteSandboxedMutationOptions(queryClient: QueryClient) {
+ return mutationOptions({
+ mutationFn: async (name: string) => {
+ await client(`/api/sandboxed/${encodeURIComponent(name)}`, {
+ method: "DELETE",
+ fallback: FALLBACK,
+ });
+ },
+ onSuccess: () => invalidateSandboxed(queryClient),
+ });
+}
diff --git a/app/src/lib/sandboxed/queries.ts b/app/src/lib/sandboxed/queries.ts
index 73a8cc83..97cc071c 100644
--- a/app/src/lib/sandboxed/queries.ts
+++ b/app/src/lib/sandboxed/queries.ts
@@ -1,4 +1,5 @@
import { queryOptions } from "@tanstack/react-query";
+import { client } from "@/lib/client";
/** A component authored in the browser, as the playground edits it. */
export type SandboxedRecord = {
@@ -41,13 +42,11 @@ export function sandboxedListQueryOptions() {
return queryOptions({
queryKey: sandboxedKeys.list(),
queryFn: async (): Promise<SandboxedRecord[]> => {
- const response = await fetch("/api/sandboxed", {
- credentials: "include",
- });
- if (!response.ok) {
- throw new Error("The playground's components could not be loaded.");
- }
- return (await response.json()).components ?? [];
+ return (
+ (await client("/api/sandboxed", "components", {
+ fallback: "The playground's components could not be loaded.",
+ })) ?? []
+ );
},
});
}
@@ -64,13 +63,11 @@ export function publishedSandboxedQueryOptions() {
queryKey: sandboxedKeys.published(),
refetchInterval: 30_000,
queryFn: async (): Promise<PublishedSandboxed[]> => {
- const response = await fetch("/api/sandboxed/published", {
- credentials: "include",
- });
- if (!response.ok) {
- throw new Error("The published components could not be loaded.");
- }
- return (await response.json()).components ?? [];
+ return (
+ (await client("/api/sandboxed/published", "components", {
+ fallback: "The published components could not be loaded.",
+ })) ?? []
+ );
},
});
}
diff --git a/app/src/routeTree.gen.ts b/app/src/routeTree.gen.ts
index 3feb12cc..48a0bf9f 100644
--- a/app/src/routeTree.gen.ts
+++ b/app/src/routeTree.gen.ts
@@ -20,7 +20,6 @@ import { Route as AuthedAppSkillsRouteImport } from './routes/_authed/_app/skill
import { Route as AuthedAdminIndexRouteImport } from './routes/_authed/admin/index'
import { Route as AuthedAdminAuditRouteImport } from './routes/_authed/admin/audit'
import { Route as AuthedAdminBoundariesRouteImport } from './routes/_authed/admin/boundaries'
-import { Route as AuthedAdminComponentsRouteImport } from './routes/_authed/admin/components'
import { Route as AuthedAdminComputersRouteImport } from './routes/_authed/admin/computers'
import { Route as AuthedAdminConnectorsRouteImport } from './routes/_authed/admin/connectors'
import { Route as AuthedAdminCredentialsRouteImport } from './routes/_authed/admin/credentials'
@@ -30,7 +29,11 @@ import { Route as AuthedSettingsIndexRouteImport } from './routes/_authed/settin
import { Route as AuthedAppAgentsIndexRouteImport } from './routes/_authed/_app/agents/index'
import { Route as AuthedAppChannelChannelIdRouteImport } from './routes/_authed/_app/channel/$channelId'
import { Route as AuthedAppChannelNewRouteImport } from './routes/_authed/_app/channel/new'
+import { Route as AuthedAdminComponentsIndexRouteImport } from './routes/_authed/admin/components/index'
+import { Route as AuthedAdminComponentsNameRouteImport } from './routes/_authed/admin/components/$name'
import { Route as AuthedAdminConnectorsGoogleDriveRouteImport } from './routes/_authed/admin/connectors/google-drive'
+import { Route as AuthedSettingsComponentsGalleryIndexRouteImport } from './routes/_authed/settings/components-gallery/index'
+import { Route as AuthedSettingsComponentsGalleryNameRouteImport } from './routes/_authed/settings/components-gallery/$name'
const AuthedRoute = AuthedRouteImport.update({
id: '/_authed',
@@ -85,11 +88,6 @@ const AuthedAdminBoundariesRoute = AuthedAdminBoundariesRouteImport.update({
path: '/boundaries',
getParentRoute: () => AuthedAdminRouteRoute,
} as any)
-const AuthedAdminComponentsRoute = AuthedAdminComponentsRouteImport.update({
- id: '/components',
- path: '/components',
- getParentRoute: () => AuthedAdminRouteRoute,
-} as any)
const AuthedAdminComputersRoute = AuthedAdminComputersRouteImport.update({
id: '/computers',
path: '/computers',
@@ -136,12 +134,36 @@ const AuthedAppChannelNewRoute = AuthedAppChannelNewRouteImport.update({
path: '/channel/new',
getParentRoute: () => AuthedAppRoute,
} as any)
+const AuthedAdminComponentsIndexRoute =
+ AuthedAdminComponentsIndexRouteImport.update({
+ id: '/components/',
+ path: '/components/',
+ getParentRoute: () => AuthedAdminRouteRoute,
+ } as any)
+const AuthedAdminComponentsNameRoute =
+ AuthedAdminComponentsNameRouteImport.update({
+ id: '/components/$name',
+ path: '/components/$name',
+ getParentRoute: () => AuthedAdminRouteRoute,
+ } as any)
const AuthedAdminConnectorsGoogleDriveRoute =
AuthedAdminConnectorsGoogleDriveRouteImport.update({
id: '/google-drive',
path: '/google-drive',
getParentRoute: () => AuthedAdminConnectorsRoute,
} as any)
+const AuthedSettingsComponentsGalleryIndexRoute =
+ AuthedSettingsComponentsGalleryIndexRouteImport.update({
+ id: '/components-gallery/',
+ path: '/components-gallery/',
+ getParentRoute: () => AuthedSettingsRouteRoute,
+ } as any)
+const AuthedSettingsComponentsGalleryNameRoute =
+ AuthedSettingsComponentsGalleryNameRouteImport.update({
+ id: '/components-gallery/$name',
+ path: '/components-gallery/$name',
+ getParentRoute: () => AuthedSettingsRouteRoute,
+ } as any)
export interface FileRoutesByFullPath {
'/': typeof AuthedAppIndexRoute
@@ -152,7 +174,6 @@ export interface FileRoutesByFullPath {
'/skills': typeof AuthedAppSkillsRoute
'/admin/audit': typeof AuthedAdminAuditRoute
'/admin/boundaries': typeof AuthedAdminBoundariesRoute
- '/admin/components': typeof AuthedAdminComponentsRoute
'/admin/computers': typeof AuthedAdminComputersRoute
'/admin/connectors': typeof AuthedAdminConnectorsRouteWithChildren
'/admin/credentials': typeof AuthedAdminCredentialsRoute
@@ -162,8 +183,12 @@ export interface FileRoutesByFullPath {
'/settings/': typeof AuthedSettingsIndexRoute
'/channel/$channelId': typeof AuthedAppChannelChannelIdRoute
'/channel/new': typeof AuthedAppChannelNewRoute
+ '/admin/components/$name': typeof AuthedAdminComponentsNameRoute
'/admin/connectors/google-drive': typeof AuthedAdminConnectorsGoogleDriveRoute
+ '/settings/components-gallery/$name': typeof AuthedSettingsComponentsGalleryNameRoute
'/agents/': typeof AuthedAppAgentsIndexRoute
+ '/admin/components/': typeof AuthedAdminComponentsIndexRoute
+ '/settings/components-gallery/': typeof AuthedSettingsComponentsGalleryIndexRoute
}
export interface FileRoutesByTo {
'/': typeof AuthedAppIndexRoute
@@ -172,7 +197,6 @@ export interface FileRoutesByTo {
'/skills': typeof AuthedAppSkillsRoute
'/admin/audit': typeof AuthedAdminAuditRoute
'/admin/boundaries': typeof AuthedAdminBoundariesRoute
- '/admin/components': typeof AuthedAdminComponentsRoute
'/admin/computers': typeof AuthedAdminComputersRoute
'/admin/connectors': typeof AuthedAdminConnectorsRouteWithChildren
'/admin/credentials': typeof AuthedAdminCredentialsRoute
@@ -182,8 +206,12 @@ export interface FileRoutesByTo {
'/settings': typeof AuthedSettingsIndexRoute
'/channel/$channelId': typeof AuthedAppChannelChannelIdRoute
'/channel/new': typeof AuthedAppChannelNewRoute
+ '/admin/components/$name': typeof AuthedAdminComponentsNameRoute
'/admin/connectors/google-drive': typeof AuthedAdminConnectorsGoogleDriveRoute
+ '/settings/components-gallery/$name': typeof AuthedSettingsComponentsGalleryNameRoute
'/agents': typeof AuthedAppAgentsIndexRoute
+ '/admin/components': typeof AuthedAdminComponentsIndexRoute
+ '/settings/components-gallery': typeof AuthedSettingsComponentsGalleryIndexRoute
}
export interface FileRoutesById {
__root__: typeof rootRouteImport
@@ -196,7 +224,6 @@ export interface FileRoutesById {
'/_authed/_app/skills': typeof AuthedAppSkillsRoute
'/_authed/admin/audit': typeof AuthedAdminAuditRoute
'/_authed/admin/boundaries': typeof AuthedAdminBoundariesRoute
- '/_authed/admin/components': typeof AuthedAdminComponentsRoute
'/_authed/admin/computers': typeof AuthedAdminComputersRoute
'/_authed/admin/connectors': typeof AuthedAdminConnectorsRouteWithChildren
'/_authed/admin/credentials': typeof AuthedAdminCredentialsRoute
@@ -207,8 +234,12 @@ export interface FileRoutesById {
'/_authed/settings/': typeof AuthedSettingsIndexRoute
'/_authed/_app/channel/$channelId': typeof AuthedAppChannelChannelIdRoute
'/_authed/_app/channel/new': typeof AuthedAppChannelNewRoute
+ '/_authed/admin/components/$name': typeof AuthedAdminComponentsNameRoute
'/_authed/admin/connectors/google-drive': typeof AuthedAdminConnectorsGoogleDriveRoute
+ '/_authed/settings/components-gallery/$name': typeof AuthedSettingsComponentsGalleryNameRoute
'/_authed/_app/agents/': typeof AuthedAppAgentsIndexRoute
+ '/_authed/admin/components/': typeof AuthedAdminComponentsIndexRoute
+ '/_authed/settings/components-gallery/': typeof AuthedSettingsComponentsGalleryIndexRoute
}
export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath
@@ -221,7 +252,6 @@ export interface FileRouteTypes {
| '/skills'
| '/admin/audit'
| '/admin/boundaries'
- | '/admin/components'
| '/admin/computers'
| '/admin/connectors'
| '/admin/credentials'
@@ -231,8 +261,12 @@ export interface FileRouteTypes {
| '/settings/'
| '/channel/$channelId'
| '/channel/new'
+ | '/admin/components/$name'
| '/admin/connectors/google-drive'
+ | '/settings/components-gallery/$name'
| '/agents/'
+ | '/admin/components/'
+ | '/settings/components-gallery/'
fileRoutesByTo: FileRoutesByTo
to:
| '/'
@@ -241,7 +275,6 @@ export interface FileRouteTypes {
| '/skills'
| '/admin/audit'
| '/admin/boundaries'
- | '/admin/components'
| '/admin/computers'
| '/admin/connectors'
| '/admin/credentials'
@@ -251,8 +284,12 @@ export interface FileRouteTypes {
| '/settings'
| '/channel/$channelId'
| '/channel/new'
+ | '/admin/components/$name'
| '/admin/connectors/google-drive'
+ | '/settings/components-gallery/$name'
| '/agents'
+ | '/admin/components'
+ | '/settings/components-gallery'
id:
| '__root__'
| '/_authed'
@@ -264,7 +301,6 @@ export interface FileRouteTypes {
| '/_authed/_app/skills'
| '/_authed/admin/audit'
| '/_authed/admin/boundaries'
- | '/_authed/admin/components'
| '/_authed/admin/computers'
| '/_authed/admin/connectors'
| '/_authed/admin/credentials'
@@ -275,8 +311,12 @@ export interface FileRouteTypes {
| '/_authed/settings/'
| '/_authed/_app/channel/$channelId'
| '/_authed/_app/channel/new'
+ | '/_authed/admin/components/$name'
| '/_authed/admin/connectors/google-drive'
+ | '/_authed/settings/components-gallery/$name'
| '/_authed/_app/agents/'
+ | '/_authed/admin/components/'
+ | '/_authed/settings/components-gallery/'
fileRoutesById: FileRoutesById
}
export interface RootRouteChildren {
@@ -363,13 +403,6 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AuthedAdminBoundariesRouteImport
parentRoute: typeof AuthedAdminRouteRoute
}
- '/_authed/admin/components': {
- id: '/_authed/admin/components'
- path: '/components'
- fullPath: '/admin/components'
- preLoaderRoute: typeof AuthedAdminComponentsRouteImport
- parentRoute: typeof AuthedAdminRouteRoute
- }
'/_authed/admin/computers': {
id: '/_authed/admin/computers'
path: '/computers'
@@ -433,6 +466,20 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AuthedAppChannelNewRouteImport
parentRoute: typeof AuthedAppRoute
}
+ '/_authed/admin/components/': {
+ id: '/_authed/admin/components/'
+ path: '/components'
+ fullPath: '/admin/components/'
+ preLoaderRoute: typeof AuthedAdminComponentsIndexRouteImport
+ parentRoute: typeof AuthedAdminRouteRoute
+ }
+ '/_authed/admin/components/$name': {
+ id: '/_authed/admin/components/$name'
+ path: '/components/$name'
+ fullPath: '/admin/components/$name'
+ preLoaderRoute: typeof AuthedAdminComponentsNameRouteImport
+ parentRoute: typeof AuthedAdminRouteRoute
+ }
'/_authed/admin/connectors/google-drive': {
id: '/_authed/admin/connectors/google-drive'
path: '/google-drive'
@@ -440,6 +487,20 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AuthedAdminConnectorsGoogleDriveRouteImport
parentRoute: typeof AuthedAdminConnectorsRoute
}
+ '/_authed/settings/components-gallery/': {
+ id: '/_authed/settings/components-gallery/'
+ path: '/components-gallery'
+ fullPath: '/settings/components-gallery/'
+ preLoaderRoute: typeof AuthedSettingsComponentsGalleryIndexRouteImport
+ parentRoute: typeof AuthedSettingsRouteRoute
+ }
+ '/_authed/settings/components-gallery/$name': {
+ id: '/_authed/settings/components-gallery/$name'
+ path: '/components-gallery/$name'
+ fullPath: '/settings/components-gallery/$name'
+ preLoaderRoute: typeof AuthedSettingsComponentsGalleryNameRouteImport
+ parentRoute: typeof AuthedSettingsRouteRoute
+ }
}
}
@@ -459,25 +520,27 @@ const AuthedAdminConnectorsRouteWithChildren =
interface AuthedAdminRouteRouteChildren {
AuthedAdminAuditRoute: typeof AuthedAdminAuditRoute
AuthedAdminBoundariesRoute: typeof AuthedAdminBoundariesRoute
- AuthedAdminComponentsRoute: typeof AuthedAdminComponentsRoute
AuthedAdminComputersRoute: typeof AuthedAdminComputersRoute
AuthedAdminConnectorsRoute: typeof AuthedAdminConnectorsRouteWithChildren
AuthedAdminCredentialsRoute: typeof AuthedAdminCredentialsRoute
AuthedAdminPlaygroundRoute: typeof AuthedAdminPlaygroundRoute
AuthedAdminPluginsRoute: typeof AuthedAdminPluginsRoute
AuthedAdminIndexRoute: typeof AuthedAdminIndexRoute
+ AuthedAdminComponentsNameRoute: typeof AuthedAdminComponentsNameRoute
+ AuthedAdminComponentsIndexRoute: typeof AuthedAdminComponentsIndexRoute
}
const AuthedAdminRouteRouteChildren: AuthedAdminRouteRouteChildren = {
AuthedAdminAuditRoute: AuthedAdminAuditRoute,
AuthedAdminBoundariesRoute: AuthedAdminBoundariesRoute,
- AuthedAdminComponentsRoute: AuthedAdminComponentsRoute,
AuthedAdminComputersRoute: AuthedAdminComputersRoute,
AuthedAdminConnectorsRoute: AuthedAdminConnectorsRouteWithChildren,
AuthedAdminCredentialsRoute: AuthedAdminCredentialsRoute,
AuthedAdminPlaygroundRoute: AuthedAdminPlaygroundRoute,
AuthedAdminPluginsRoute: AuthedAdminPluginsRoute,
AuthedAdminIndexRoute: AuthedAdminIndexRoute,
+ AuthedAdminComponentsNameRoute: AuthedAdminComponentsNameRoute,
+ AuthedAdminComponentsIndexRoute: AuthedAdminComponentsIndexRoute,
}
const AuthedAdminRouteRouteWithChildren =
@@ -485,10 +548,16 @@ const AuthedAdminRouteRouteWithChildren =
interface AuthedSettingsRouteRouteChildren {
AuthedSettingsIndexRoute: typeof AuthedSettingsIndexRoute
+ AuthedSettingsComponentsGalleryNameRoute: typeof AuthedSettingsComponentsGalleryNameRoute
+ AuthedSettingsComponentsGalleryIndexRoute: typeof AuthedSettingsComponentsGalleryIndexRoute
}
const AuthedSettingsRouteRouteChildren: AuthedSettingsRouteRouteChildren = {
AuthedSettingsIndexRoute: AuthedSettingsIndexRoute,
+ AuthedSettingsComponentsGalleryNameRoute:
+ AuthedSettingsComponentsGalleryNameRoute,
+ AuthedSettingsComponentsGalleryIndexRoute:
+ AuthedSettingsComponentsGalleryIndexRoute,
}
const AuthedSettingsRouteRouteWithChildren =
diff --git a/app/src/routes/_authed/_app/channel/$channelId.tsx b/app/src/routes/_authed/_app/channel/$channelId.tsx
index 5af2dfaa..06541d0f 100644
--- a/app/src/routes/_authed/_app/channel/$channelId.tsx
+++ b/app/src/routes/_authed/_app/channel/$channelId.tsx
@@ -213,11 +213,8 @@ function ChannelBody({
isPending: boolean;
hasError: boolean;
}) {
- if (isPending) {
- return (
- <p className="p-8 text-sm text-muted-foreground">Loading channel…</p>
- );
- }
+ // Nothing while the channel loads: a placeholder inside a local round-trip is a flicker.
+ if (isPending) return null;
if (hasError || !channel) {
return (
<p className="p-8 text-sm text-destructive" role="alert">
diff --git a/app/src/routes/_authed/_app/skills.tsx b/app/src/routes/_authed/_app/skills.tsx
index f53a18cb..410d39ac 100644
--- a/app/src/routes/_authed/_app/skills.tsx
+++ b/app/src/routes/_authed/_app/skills.tsx
@@ -13,8 +13,10 @@ import { StaggerItem } from "@/components/layout/stagger";
import { EditSkill } from "@/components/skills/edit-skill";
import { NewSkill } from "@/components/skills/new-skill";
import { Button } from "@/components/ui/button";
+import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { currentUserQueryOptions } from "@/lib/auth/queries";
-import { pluginKeys, pluginsPageQueryOptions } from "@/lib/plugins/queries";
+import { removeSkillMutationOptions } from "@/lib/plugins/mutations";
+import { pluginsPageQueryOptions } from "@/lib/plugins/queries";
import {
Item,
ItemActions,
@@ -61,25 +63,23 @@ function SkillsPage() {
// roster uses when `new` and `agent` arrive together.
const showCreate = isCreating === true;
const showEdit = !showCreate && editingSlug !== undefined;
- const { data } = useQuery(pluginsPageQueryOptions());
- const { data: me } = useQuery(currentUserQueryOptions());
+ const { data, isPending: skillsPending } = useQuery(
+ pluginsPageQueryOptions(),
+ );
+ const { data: me, isPending: mePending } = useQuery(
+ currentUserQueryOptions(),
+ );
+ /*
+ * Both, because `mine` is the intersection of the two: until the person is known, nothing matches
+ * them and the list is empty for a reason that is not "you have no skills".
+ */
+ const loading = skillsPending || mePending;
const [error, setError] = useState<string | null>(null);
- const mutate = useMutation({
- mutationFn: async (run: () => Promise<Response>) => {
- const response = await run();
- if (!response.ok) {
- const body = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- throw new Error(body?.error ?? "That did not work.");
- }
- },
- onError: (caught: Error) => setError(caught.message),
- onSuccess: () => {
- setError(null);
- void queryClient.invalidateQueries({ queryKey: pluginKeys.all });
- },
+ const removeSkill = useMutation({
+ ...removeSkillMutationOptions(queryClient),
+ onError: (thrown: Error) => setError(thrown.message),
+ onSuccess: () => setError(null),
});
/*
@@ -137,7 +137,20 @@ function SkillsPage() {
}
title="Your skills"
>
- {!!mine?.length && (
+ {/*
+ * Nothing while the two queries are still in flight. The alternative is the empty state
+ * standing there saying this person has written no skills, which is a claim the page has
+ * not yet earned.
+ */}
+ {loading ? null : mine.length === 0 ? (
+ <Empty className="mt-4 h-[180px] border border-dashed">
+ <EmptyHeader>
+ <EmptyTitle className="text-muted-foreground">
+ You don't have any skills yet.
+ </EmptyTitle>
+ </EmptyHeader>
+ </Empty>
+ ) : (
<PageRows>
{mine.map((skill, index) => (
<StaggerItem index={index} key={skill.id}>
@@ -184,17 +197,10 @@ function SkillsPage() {
* opened over the wrong row is the ordinary way this goes wrong.
*/}
<DropdownMenuItem
- onClick={() =>
- mutate.mutate(() =>
- fetch(
- `/api/plugins/skills/${encodeURIComponent(skill.slug)}`,
- {
- method: "DELETE",
- credentials: "include",
- },
- ),
- )
- }
+ onClick={() => {
+ setError(null);
+ removeSkill.mutate(skill.slug);
+ }}
variant="destructive"
>
Delete /{skill.slug}
diff --git a/app/src/routes/_authed/admin/audit.tsx b/app/src/routes/_authed/admin/audit.tsx
index 2a6319b8..6a1fffe1 100644
--- a/app/src/routes/_authed/admin/audit.tsx
+++ b/app/src/routes/_authed/admin/audit.tsx
@@ -87,9 +87,7 @@ function AuditPage() {
))}
</div>
- {events.isPending ? (
- <PageEmpty>Loading the trail…</PageEmpty>
- ) : events.isError ? (
+ {events.isPending ? null : events.isError ? (
<p className="mt-4 text-destructive text-sm" role="alert">
The audit trail could not be loaded.
</p>
diff --git a/app/src/routes/_authed/admin/boundaries.tsx b/app/src/routes/_authed/admin/boundaries.tsx
index 518ea304..2f74ac12 100644
--- a/app/src/routes/_authed/admin/boundaries.tsx
+++ b/app/src/routes/_authed/admin/boundaries.tsx
@@ -1,6 +1,14 @@
+import { useMutation, useQuery } from "@tanstack/react-query";
import { createFileRoute, Link } from "@tanstack/react-router";
-import { useCallback, useEffect, useState } from "react";
+import { useState } from "react";
import { PageSection, PageShell } from "@/components/layout/page-shell";
+import { saveActionPolicyMutationOptions } from "@/lib/computers/mutations";
+import {
+ type ActionPolicy,
+ actionPolicyQueryOptions,
+ type PolicyMode,
+} from "@/lib/computers/queries";
+import { queryClient } from "@/query-client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
@@ -9,14 +17,6 @@ import { Input } from "@/components/ui/input";
* actions are recorded in Audit with the matching rule.
*/
-type PolicyMode = "dry-run" | "enforce";
-
-type ActionPolicy = {
- mode: PolicyMode;
- deny: string[];
- allow: string[];
-};
-
/**
* Presets are concrete CEL rules, not a separate policy language.
*/
@@ -44,61 +44,28 @@ export const Route = createFileRoute("/_authed/admin/boundaries")({
});
function BoundariesPage() {
- const [policy, setPolicy] = useState<ActionPolicy | null>(null);
const [problem, setProblem] = useState<string | null>(null);
- const [saving, setSaving] = useState(false);
const [saved, setSaved] = useState(false);
const [draft, setDraft] = useState("");
- const load = useCallback(async () => {
- try {
- const response = await fetch("/api/computers/policy", {
- credentials: "include",
- });
- if (!response.ok) {
- setProblem("The boundary could not be read.");
- return;
- }
- const body = (await response.json()) as { policy: ActionPolicy };
- setPolicy(body.policy);
- setProblem(null);
- } catch {
- setProblem("The boundary could not be reached.");
- }
- }, []);
+ const stored = useQuery(actionPolicyQueryOptions());
+ const savePolicy = useMutation(saveActionPolicyMutationOptions(queryClient));
- useEffect(() => {
- void load();
- }, [load]);
+ /*
+ * The saved policy wins while a save is in flight and after it lands: the server normalises what
+ * it stores, so what came back is the policy, not what was sent.
+ */
+ const policy = savePolicy.data ?? stored.data ?? null;
+ const saving = savePolicy.isPending;
- const save = useCallback(async (next: ActionPolicy) => {
- setSaving(true);
+ const save = (next: ActionPolicy) => {
setSaved(false);
- try {
- const response = await fetch("/api/computers/policy", {
- method: "PUT",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(next),
- });
- const body = (await response.json().catch(() => null)) as {
- policy?: ActionPolicy;
- error?: string;
- } | null;
- if (!response.ok) {
- setProblem(body?.error ?? "The boundary could not be saved.");
- return;
- }
- // Display the persisted policy in case the server normalized it.
- if (body?.policy) setPolicy(body.policy);
- setProblem(null);
- setSaved(true);
- } catch {
- setProblem("The boundary could not be reached.");
- } finally {
- setSaving(false);
- }
- }, []);
+ setProblem(null);
+ savePolicy.mutate(next, {
+ onError: (thrown: Error) => setProblem(thrown.message),
+ onSuccess: () => setSaved(true),
+ });
+ };
if (problem && !policy) {
return (
@@ -110,14 +77,9 @@ function BoundariesPage() {
);
}
+ /* Nothing until the policy is known: a rule list that guesses is worse than a blank. */
if (!policy) {
- return (
- <PageShell title="Boundaries">
- <p className="mt-4 text-muted-foreground text-sm">
- Loading the boundary…
- </p>
- </PageShell>
- );
+ return <PageShell title="Boundaries">{null}</PageShell>;
}
const addRule = (rule: string) => {
diff --git a/app/src/routes/_authed/admin/components.tsx b/app/src/routes/_authed/admin/components.tsx
deleted file mode 100644
index 2b0c10e8..00000000
--- a/app/src/routes/_authed/admin/components.tsx
+++ /dev/null
@@ -1,429 +0,0 @@
-import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
-import { createFileRoute } from "@tanstack/react-router";
-import { useState } from "react";
-import {
- PageEmpty,
- PageSection,
- PageShell,
-} from "@/components/layout/page-shell";
-import { PreviewOf } from "@/components/gallery/preview";
-import { StaggerItem } from "@/components/layout/stagger";
-import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogBody,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
-} from "@/components/ui/dialog";
-import { Field, FieldLabel } from "@/components/ui/field";
-import { Textarea } from "@/components/ui/textarea";
-import { agentListQueryOptions } from "@/lib/agents/queries";
-import {
- type ComponentRecord,
- componentKeys,
- componentListQueryOptions,
- type DataFunctionSummary,
- dataFunctionsQueryOptions,
-} from "@/lib/components/queries";
-import { RENDERABLE_NAMES } from "@/lib/copilot/gallery-registry";
-
-/**
- * Runtime governance for compiled gallery components: publication, per-Bot grants, model-facing
- * descriptions, and component data-function access.
- */
-export const Route = createFileRoute("/_authed/admin/components")({
- component: RouteComponent,
-});
-
-function RouteComponent() {
- const queryClient = useQueryClient();
- const { data: components, isLoading } = useQuery(componentListQueryOptions());
- const { data: agents } = useQuery(agentListQueryOptions());
- const { data: dataFunctions } = useQuery(dataFunctionsQueryOptions());
-
- const invalidate = () => {
- void queryClient.invalidateQueries({ queryKey: componentKeys.all });
- };
-
- const setGrant = useMutation({
- mutationFn: async ({
- name,
- agentId,
- granted,
- }: {
- name: string;
- agentId: string;
- granted: boolean;
- }) => {
- const response = granted
- ? await fetch(`/api/components/${encodeURIComponent(name)}/grants`, {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ agentId }),
- })
- : await fetch(
- `/api/components/${encodeURIComponent(name)}/grants/${encodeURIComponent(agentId)}`,
- { method: "DELETE", credentials: "include" },
- );
- if (!response.ok) throw new Error("That change could not be saved.");
- },
- onSuccess: invalidate,
- });
-
- const setFunction = useMutation({
- mutationFn: async ({
- name,
- functionName,
- granted,
- }: {
- name: string;
- functionName: string;
- granted: boolean;
- }) => {
- const response = granted
- ? await fetch(`/api/components/${encodeURIComponent(name)}/functions`, {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ function: functionName }),
- })
- : await fetch(
- `/api/components/${encodeURIComponent(name)}/functions/${encodeURIComponent(functionName)}`,
- { method: "DELETE", credentials: "include" },
- );
- if (!response.ok) throw new Error("That change could not be saved.");
- },
- onSuccess: invalidate,
- });
-
- const setPublished = useMutation({
- mutationFn: async ({
- name,
- published,
- }: {
- name: string;
- published: boolean;
- }) => {
- const response = await fetch(
- `/api/components/${encodeURIComponent(name)}/publication`,
- {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ published }),
- },
- );
- if (!response.ok) throw new Error("That change could not be saved.");
- },
- onSuccess: invalidate,
- });
-
- const saveDraft = useMutation({
- mutationFn: async ({
- name,
- description,
- }: {
- name: string;
- description: string;
- }) => {
- const response = await fetch(
- `/api/components/${encodeURIComponent(name)}/draft`,
- {
- method: "PUT",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({ description }),
- },
- );
- if (!response.ok) throw new Error("That draft could not be saved.");
- },
- onSuccess: invalidate,
- });
-
- const bots = agents ?? [];
-
- return (
- <PageShell
- description="What each Bot may answer with. Every published component is available to every Bot; switch one off here and that Bot is never told about it. Each change and each refusal is a row in Audit."
- title="Components"
- >
- {/*
- * ONE CARD EACH, RATHER THAN A ROW EACH. Every other list in admin is `Item` rows, and these
- * started as hand-drawn ones — but a component carries per-Bot grants and per-function grants,
- * which is a set of switches rather than a line of text. Cramming that into a row would mean
- * hiding it behind a menu, and which Bots hold a component is the thing this page exists to
- * answer at a glance.
- */}
- <PageSection title="Published components">
- {isLoading ? <PageEmpty>Loading…</PageEmpty> : null}
-
- {components?.length === 0 && !isLoading ? (
- <PageEmpty>This deployment ships no components.</PageEmpty>
- ) : null}
-
- <div className="mt-4 flex flex-col gap-3">
- {(components ?? []).map((component, index) => (
- <StaggerItem index={index} key={component.name}>
- <ComponentRow
- bots={bots}
- component={component}
- dataFunctions={dataFunctions ?? []}
- key={component.name}
- onSetFunction={(functionName, granted) =>
- setFunction.mutate({
- functionName,
- granted,
- name: component.name,
- })
- }
- onPublish={(published) =>
- setPublished.mutate({ name: component.name, published })
- }
- onSaveDraft={(description) =>
- saveDraft.mutate({ name: component.name, description })
- }
- onSetGrant={(agentId, granted) =>
- setGrant.mutate({ agentId, granted, name: component.name })
- }
- />
- </StaggerItem>
- ))}
- </div>
- </PageSection>
- </PageShell>
- );
-}
-
-function ComponentRow({
- component,
- bots,
- dataFunctions,
- onSetGrant,
- onSetFunction,
- onPublish,
- onSaveDraft,
-}: {
- component: ComponentRecord;
- bots: { id: string; name: string }[];
- dataFunctions: DataFunctionSummary[];
- onSetGrant: (agentId: string, granted: boolean) => void;
- onSetFunction: (functionName: string, granted: boolean) => void;
- onPublish: (published: boolean) => void;
- onSaveDraft: (description: string) => void;
-}) {
- const [editing, setEditing] = useState(false);
- const [draft, setDraft] = useState(component.draftDescription);
- const withheld = new Set(component.withheldFrom);
- const heldFunctions = new Set(component.functions);
-
- return (
- <section
- className="rounded-lg border border-border bg-card"
- data-testid={`component-${component.name}`}
- >
- <div className="flex flex-wrap items-start justify-between gap-4 border-b border-border px-4 py-3">
- <div className="min-w-0">
- <div className="flex items-center gap-2">
- <h3 className="font-medium text-sm">{component.title}</h3>
- <code className="rounded bg-foreground/5 px-1.5 py-0.5 text-xs text-muted-foreground">
- {component.name}
- </code>
- {RENDERABLE_NAMES.has(component.name) ? null : (
- <span className="rounded-md bg-amber-500/10 px-1.5 py-0.5 text-xs font-medium text-amber-700 dark:text-amber-400">
- Not in this build, nothing can draw it
- </span>
- )}
- {component.published ? null : (
- <span className="rounded-md bg-amber-500/10 px-1.5 py-0.5 text-xs font-medium text-amber-700 dark:text-amber-400">
- Unpublished, no Bot may use it
- </span>
- )}
- {component.hasUnpublishedChanges ? (
- <span className="rounded-md bg-foreground/5 px-1.5 py-0.5 text-xs font-medium text-muted-foreground">
- Draft not published
- </span>
- ) : null}
- </div>
- <p className="mt-1 max-w-3xl text-sm text-muted-foreground">
- {component.publishedDescription ??
- "Nothing is published, so no Bot is told about this."}
- </p>
- <p className="mt-1 text-xs text-muted-foreground">
- Last changed {new Date(component.updatedAt).toLocaleString()}
- {component.updatedBy ? ` by ${component.updatedBy}` : null}
- </p>
- {/*
- * What granting this actually puts in front of somebody.
- *
- * Closed by default: this page is a list an administrator scans, and thirteen components
- * drawn at once is a page nobody reads. Open, it is the real component, which is the only
- * thing that answers "should this Bot have it".
- */}
- {RENDERABLE_NAMES.has(component.name) ? (
- <details className="mt-3 max-w-3xl">
- <summary className="cursor-pointer text-muted-foreground text-xs underline underline-offset-4 hover:text-foreground">
- See it
- </summary>
- <div className="mt-3">
- <PreviewOf name={component.name} />
- </div>
- </details>
- ) : null}
- </div>
-
- <div className="flex shrink-0 items-center gap-2">
- <Button
- onClick={() => setEditing((open) => !open)}
- size="sm"
- variant="outline"
- >
- Edit description
- </Button>
- <Button
- data-testid={`publish-${component.name}`}
- onClick={() => onPublish(!component.published)}
- size="sm"
- variant={component.published ? "outline" : "default"}
- >
- {component.published ? "Unpublish" : "Publish"}
- </Button>
- </div>
- </div>
-
- <Dialog onOpenChange={setEditing} open={editing}>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>{component.title}</DialogTitle>
- <DialogDescription>
- The draft description is what the model reads when deciding to
- call this. It changes nothing until it is published.
- </DialogDescription>
- </DialogHeader>
- <DialogBody className="mt-4">
- <Field>
- <FieldLabel htmlFor={`draft-${component.name}`}>
- Draft description
- </FieldLabel>
- <Textarea
- id={`draft-${component.name}`}
- onChange={(event) => setDraft(event.target.value)}
- rows={4}
- value={draft}
- />
- </Field>
- </DialogBody>
- <DialogFooter className="mt-4">
- <Button onClick={() => setEditing(false)} size="sm" variant="ghost">
- Cancel
- </Button>
- <Button
- onClick={() => {
- onSaveDraft(draft);
- setEditing(false);
- }}
- size="sm"
- variant="outline"
- >
- Save draft
- </Button>
- <Button
- onClick={() => {
- onSaveDraft(draft);
- onPublish(true);
- setEditing(false);
- }}
- size="sm"
- >
- Publish
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
-
- <div className="px-4 py-3">
- {/*
- * The row of Bots was unlabelled, so a filled name and a hollow one were a state nobody
- * could read: it was not said anywhere that these are the Bots allowed to answer with this,
- * nor that clicking one takes it away.
- */}
- <p className="font-medium text-muted-foreground text-xs">
- Bots that may answer with it
- </p>
- <p className="mt-1 text-muted-foreground text-xs">
- Filled means yes. Switch one off and that Bot is never told the
- component exists, so it cannot ask for it and does not apologise for
- not having it.
- </p>
- <div className="mt-2 flex flex-wrap gap-2">
- {bots.length === 0 ? (
- <p className="text-muted-foreground text-sm">
- There are no Bots yet.
- </p>
- ) : null}
- {bots.map((bot) => {
- const has = !withheld.has(bot.id);
- return (
- <Button
- data-testid={`grant-${component.name}-${bot.id}`}
- key={bot.id}
- onClick={() => onSetGrant(bot.id, !has)}
- size="sm"
- type="button"
- /* The fill is the state, as on the skills grants: a glance has to answer which are on. */
- variant={has ? "default" : "outline"}
- >
- {bot.name}
- </Button>
- );
- })}
- </div>
- </div>
-
- {/* Data-function grants are separate from Bot component grants. */}
- {dataFunctions.length > 0 ? (
- <div className="border-t border-border px-4 py-3">
- {/*
- * "May read" on its own said nothing. It is a different kind of grant from the row above,
- * and the difference is the whole point: the row above decides who may draw this, and this
- * decides what it is allowed to go and fetch in order to draw it. Somebody who reads the
- * two as one switch will grant a component to every Bot believing that is all they did.
- */}
- <p className="font-medium text-muted-foreground text-xs">
- What it may go and read
- </p>
- <p className="mt-1 text-muted-foreground text-xs">
- A separate grant, and not implied by the one above. This component
- can ask the server for data to fill itself with; until one of these
- is on it draws only what the Bot passes it. Each one names what it
- reads, and every read is a row in Audit.
- </p>
- <div className="mt-2 flex flex-wrap gap-2">
- {dataFunctions.map((fn) => {
- const has = heldFunctions.has(fn.name);
- return (
- <Button
- data-testid={`function-${component.name}-${fn.name}`}
- key={fn.name}
- onClick={() => onSetFunction(fn.name, !has)}
- size="sm"
- title={fn.description}
- type="button"
- variant={has ? "default" : "outline"}
- >
- {fn.name}
- <span className="ml-2 text-muted-foreground text-xs">
- {fn.reads}
- </span>
- </Button>
- );
- })}
- </div>
- </div>
- ) : null}
- </section>
- );
-}
diff --git a/app/src/routes/_authed/admin/components/$name.tsx b/app/src/routes/_authed/admin/components/$name.tsx
new file mode 100644
index 00000000..aa1b3282
--- /dev/null
+++ b/app/src/routes/_authed/admin/components/$name.tsx
@@ -0,0 +1,579 @@
+import {
+ IconAlertTriangle,
+ IconChevronRight,
+ IconClock,
+ IconCode,
+ IconDatabase,
+ IconFileText,
+ IconTag,
+ IconUsers,
+ IconWorld,
+} from "@tabler/icons-react";
+import { useMutation, useQuery } from "@tanstack/react-query";
+import { createFileRoute, Link } from "@tanstack/react-router";
+import { type ReactNode, useState } from "react";
+import { ComponentPreview } from "@/components/component-preview";
+import {
+ PageRows,
+ PageSection,
+ PageShell,
+} from "@/components/layout/page-shell";
+import { SettingsItemBackground } from "@/components/settings/background";
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import {
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
+} from "@/components/ui/empty";
+import {
+ Item,
+ ItemActions,
+ ItemContent,
+ ItemDescription,
+ ItemMedia,
+ ItemTitle,
+} from "@/components/ui/item";
+import { Separator } from "@/components/ui/separator";
+import { Switch } from "@/components/ui/switch";
+import { Textarea } from "@/components/ui/textarea";
+import { agentListQueryOptions } from "@/lib/agents/queries";
+import {
+ saveComponentDraftMutationOptions,
+ setComponentFunctionMutationOptions,
+ setComponentGrantMutationOptions,
+ setComponentPublishedMutationOptions,
+} from "@/lib/components/mutations";
+import {
+ type ComponentRecord,
+ componentListQueryOptions,
+ type DataFunctionSummary,
+ dataFunctionsQueryOptions,
+} from "@/lib/components/queries";
+import { RENDERABLE_NAMES } from "@/lib/copilot/gallery-registry";
+import { queryClient } from "@/query-client";
+
+/**
+ * Governance for one compiled component: publication, per-Bot grants, the model-facing description,
+ * and which data functions it may read.
+ */
+/** The same way back from every state this route can be in. */
+const BACK = {
+ label: "UI Components",
+ linkProps: { to: "/admin/components" },
+} as const;
+
+export const Route = createFileRoute("/_authed/admin/components/$name")({
+ component: RouteComponent,
+});
+
+function RouteComponent() {
+ const { name } = Route.useParams();
+ const components = useQuery(componentListQueryOptions());
+ const agents = useQuery(agentListQueryOptions());
+ const dataFunctions = useQuery(dataFunctionsQueryOptions());
+
+ const setGrant = useMutation(setComponentGrantMutationOptions(queryClient));
+ const setFunction = useMutation(
+ setComponentFunctionMutationOptions(queryClient),
+ );
+ const setPublished = useMutation(
+ setComponentPublishedMutationOptions(queryClient),
+ );
+ const saveDraft = useMutation(saveComponentDraftMutationOptions(queryClient));
+
+ /*
+ * Read out of the list rather than held in state, so a change made here is reflected here.
+ */
+ const component = components.data?.find((entry) => entry.name === name);
+
+ /*
+ * Pending first and drawing nothing: there is no loading placeholder in this app, and the
+ * alternative here is worse than a blank — "no such component" while the list is still in flight
+ * says something false about a component that is about to appear.
+ */
+ if (components.isPending) return null;
+
+ if (components.error) {
+ return (
+ <PageShell backButton={BACK} title="Components">
+ <p className="mt-8 text-destructive text-sm" role="alert">
+ Could not load components.
+ </p>
+ </PageShell>
+ );
+ }
+
+ if (!component) {
+ /*
+ * A name in the URL is a claim, not a promise: it can be stale, mistyped, or a component this
+ * build no longer ships.
+ */
+ return (
+ <PageShell
+ backButton={BACK}
+ description="Nothing here answers to that name."
+ title="No such component"
+ >
+ <Empty className="mt-12 min-h-[30dvh] border border-dashed">
+ <EmptyHeader>
+ <EmptyTitle>{name}</EmptyTitle>
+ <EmptyDescription className="text-pretty">
+ It may have been renamed, or this deployment may no longer ship
+ it.
+ </EmptyDescription>
+ </EmptyHeader>
+ <Button
+ render={<Link to="/admin/components" />}
+ size="sm"
+ variant="outline"
+ >
+ Back to components
+ </Button>
+ </Empty>
+ </PageShell>
+ );
+ }
+
+ return (
+ /*
+ * Keyed on the name so the draft is seeded from the component actually being looked at. The
+ * route component is reused when only the parameter changes, so without it the text held from
+ * the last one opened would be what a save wrote back.
+ */
+ <ComponentDetail
+ bots={agents.data ?? []}
+ component={component}
+ dataFunctions={dataFunctions.data ?? []}
+ key={component.name}
+ onPublish={(published) => setPublished.mutate({ name, published })}
+ onSaveDraft={(description) => saveDraft.mutate({ description, name })}
+ onSetFunction={(functionName, granted) =>
+ setFunction.mutate({ functionName, granted, name })
+ }
+ onSetGrant={(agentId, granted) =>
+ setGrant.mutate({ agentId, granted, name })
+ }
+ />
+ );
+}
+
+/** Which sub-dialog is open, if any. */
+type Sheet = "description" | "grants" | "functions" | null;
+
+/**
+ * A row that states something and cannot be changed. No chevron, because there is nothing behind it.
+ */
+function FactRow({
+ icon,
+ label,
+ children,
+}: {
+ icon: ReactNode;
+ label: string;
+ children: ReactNode;
+}) {
+ return (
+ <Item size="sm">
+ <ItemMedia variant="icon">{icon}</ItemMedia>
+ <ItemContent>
+ <ItemTitle>{label}</ItemTitle>
+ </ItemContent>
+ <ItemActions className="text-muted-foreground text-sm">
+ {children}
+ </ItemActions>
+ </Item>
+ );
+}
+
+/**
+ * A row whose detail is a dialog. The whole row is the button, as it is in the settings screens this
+ * follows — a chevron on the right announces where it goes, but it is not the only thing you can hit.
+ */
+function SheetRow({
+ icon,
+ label,
+ summary,
+ onOpen,
+ testId,
+}: {
+ icon: ReactNode;
+ label: string;
+ summary: string;
+ onOpen: () => void;
+ testId: string;
+}) {
+ return (
+ <Item
+ className="w-full text-left transition-colors hover:bg-muted/50"
+ /*
+ * No children on the render element. `useRender` merges props, and children given here would
+ * replace the row's own — which is how this first drew as three empty rows. The button takes
+ * its accessible name from the title and summary inside instead.
+ */
+ render={<button data-testid={testId} onClick={onOpen} type="button" />}
+ size="sm"
+ >
+ <ItemMedia variant="icon">{icon}</ItemMedia>
+ <ItemContent>
+ <ItemTitle>{label}</ItemTitle>
+ <ItemDescription>{summary}</ItemDescription>
+ </ItemContent>
+ <ItemActions>
+ <IconChevronRight className="size-4 text-muted-foreground" />
+ </ItemActions>
+ </Item>
+ );
+}
+
+/**
+ * One component in full: what it is, what it looks like, what the model is told about it, and who
+ * may use it.
+ *
+ * Settings-screen shape rather than a form. Each row states where something stands and, if it can be
+ * changed, opens a dialog to change it; nothing is saved by a button at the bottom of the page,
+ * because there is no page-level state to save. Publication and the grants take effect as they are
+ * switched, and the description is the one thing held while it is being typed — which is why it is
+ * the only dialog with a Cancel.
+ */
+function ComponentDetail({
+ component,
+ bots,
+ dataFunctions,
+ onSetGrant,
+ onSetFunction,
+ onPublish,
+ onSaveDraft,
+}: {
+ component: ComponentRecord;
+ bots: { id: string; name: string }[];
+ dataFunctions: DataFunctionSummary[];
+ onSetGrant: (agentId: string, granted: boolean) => void;
+ onSetFunction: (functionName: string, granted: boolean) => void;
+ onPublish: (published: boolean) => void;
+ onSaveDraft: (description: string) => void;
+}) {
+ const [sheet, setSheet] = useState<Sheet>(null);
+ const [draft, setDraft] = useState(component.draftDescription);
+ const withheld = new Set(component.withheldFrom);
+ const heldFunctions = new Set(component.functions);
+ const renderable = RENDERABLE_NAMES.has(component.name);
+
+ const granted = bots.filter((bot) => !withheld.has(bot.id));
+ const held = dataFunctions.filter((fn) => heldFunctions.has(fn.name));
+
+ const grantSummary =
+ bots.length === 0
+ ? "There are no Bots yet"
+ : granted.length === bots.length
+ ? `All ${bots.length} Bots`
+ : granted.length === 0
+ ? "No Bots"
+ : `${granted.length} of ${bots.length} Bots`;
+
+ const functionSummary =
+ dataFunctions.length === 0
+ ? "This deployment grants no data functions"
+ : held.length === 0
+ ? "Nothing — it draws only what the model hands it"
+ : held.map((fn) => fn.name).join(", ");
+
+ return (
+ <PageShell
+ backButton={BACK}
+ description={
+ component.publishedDescription ??
+ "Nothing is published, so no Bot is told about this."
+ }
+ title={component.title}
+ >
+ {/*
+ * The render at the top of the page. Bordered and rounded rather than bleeding to the edges:
+ * inside a prose column that is what the tiles do, and a page has no dialog edge to reach for.
+ */}
+ <div className="relative mt-8 aspect-[2/1] overflow-hidden rounded-lg border border-border bg-card">
+ <div className="absolute inset-0">
+ <SettingsItemBackground className="h-full w-full" />
+ </div>
+ <div className="absolute inset-0 z-10">
+ <ComponentPreview name={component.name} />
+ </div>
+ </div>
+
+ <PageSection
+ description="What this component is for, and which Bots are allowed to answer with it."
+ title="Configuration"
+ >
+ <PageRows>
+ {/*
+ * First, and only when it applies: a component this build cannot draw is a fact that
+ * outranks everything under it, because none of it can have any effect.
+ */}
+ {renderable ? null : (
+ <>
+ <Item size="sm">
+ <ItemMedia variant="icon">
+ <IconAlertTriangle className="text-amber-600 dark:text-amber-400" />
+ </ItemMedia>
+ <ItemContent>
+ <ItemTitle>Not in this build</ItemTitle>
+ <ItemDescription>
+ Nothing here can draw it, whatever else is set.
+ </ItemDescription>
+ </ItemContent>
+ </Item>
+ <Separator />
+ </>
+ )}
+
+ <Item size="sm">
+ <ItemMedia variant="icon">
+ <IconWorld />
+ </ItemMedia>
+ <ItemContent>
+ <ItemTitle>Published</ItemTitle>
+ <ItemDescription>
+ {component.published
+ ? "Bots may answer with it."
+ : "No Bot may use it."}
+ {component.hasUnpublishedChanges
+ ? " The description has changes that are not published."
+ : null}
+ </ItemDescription>
+ </ItemContent>
+ <ItemActions>
+ <Switch
+ aria-label="Published"
+ checked={component.published}
+ data-testid={`publish-${component.name}`}
+ onCheckedChange={onPublish}
+ />
+ </ItemActions>
+ </Item>
+
+ <Separator />
+
+ <SheetRow
+ icon={<IconFileText />}
+ label="Description"
+ onOpen={() => setSheet("description")}
+ summary={component.draftDescription || "Nothing yet"}
+ testId={`description-${component.name}`}
+ />
+
+ <Separator />
+
+ <SheetRow
+ icon={<IconUsers />}
+ label="Available to"
+ onOpen={() => setSheet("grants")}
+ summary={grantSummary}
+ testId={`grants-${component.name}`}
+ />
+
+ <Separator />
+
+ <SheetRow
+ icon={<IconDatabase />}
+ label="May read"
+ onOpen={() => setSheet("functions")}
+ summary={functionSummary}
+ testId={`functions-${component.name}`}
+ />
+ </PageRows>
+ </PageSection>
+
+ <PageSection title="Details">
+ <PageRows>
+ <FactRow icon={<IconTag />} label="Kind">
+ {component.kind}
+ </FactRow>
+ <Separator />
+ <FactRow icon={<IconCode />} label="Called as">
+ <code className="rounded bg-foreground/5 px-1.5 py-0.5 text-xs">
+ {component.name}
+ </code>
+ </FactRow>
+ <Separator />
+ <FactRow icon={<IconClock />} label="Last changed">
+ {new Date(component.updatedAt).toLocaleString()}
+ {component.updatedBy ? ` by ${component.updatedBy}` : null}
+ </FactRow>
+ </PageRows>
+ </PageSection>
+
+ {/*
+ * The one dialog holding state of its own, so the one with something to discard. The draft is
+ * reset on close either way, so reopening reads what is actually stored rather than what was
+ * abandoned.
+ */}
+ <Dialog
+ onOpenChange={(open) => {
+ if (!open) {
+ setSheet(null);
+ setDraft(component.draftDescription);
+ }
+ }}
+ open={sheet === "description"}
+ >
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Description</DialogTitle>
+ <DialogDescription>
+ What the model reads when deciding to call this. It changes
+ nothing until the component is published.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogBody className="mt-4">
+ <Textarea
+ aria-label="Description"
+ onChange={(event) => setDraft(event.target.value)}
+ rows={6}
+ value={draft}
+ />
+ </DialogBody>
+ <DialogFooter className="mt-4">
+ <Button
+ onClick={() => {
+ setSheet(null);
+ setDraft(component.draftDescription);
+ }}
+ size="sm"
+ variant="ghost"
+ >
+ Cancel
+ </Button>
+ <Button
+ onClick={() => {
+ onSaveDraft(draft);
+ setSheet(null);
+ }}
+ size="sm"
+ >
+ Save
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+
+ {/* Grants take effect as they are switched, so there is nothing here to save or to discard. */}
+ <Dialog
+ onOpenChange={(open) => !open && setSheet(null)}
+ open={sheet === "grants"}
+ >
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Available to</DialogTitle>
+ <DialogDescription>
+ Switch a Bot off and it is never told this component exists, so it
+ cannot ask for it and does not apologise for not having it. Each
+ change takes effect immediately.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogBody className="mt-4">
+ {bots.length === 0 ? (
+ <p className="text-muted-foreground text-sm">
+ There are no Bots yet.
+ </p>
+ ) : (
+ <div className="flex flex-col">
+ {bots.map((bot, index) => {
+ const has = !withheld.has(bot.id);
+ return (
+ <div key={bot.id}>
+ {index === 0 ? null : <Separator />}
+ <Item size="sm">
+ <ItemContent>
+ <ItemTitle>{bot.name}</ItemTitle>
+ </ItemContent>
+ <ItemActions>
+ <Switch
+ aria-label={bot.name}
+ checked={has}
+ data-testid={`grant-${component.name}-${bot.id}`}
+ onCheckedChange={(next) => onSetGrant(bot.id, next)}
+ />
+ </ItemActions>
+ </Item>
+ </div>
+ );
+ })}
+ </div>
+ )}
+ </DialogBody>
+ <DialogFooter className="mt-4">
+ <Button onClick={() => setSheet(null)} size="sm">
+ Done
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+
+ <Dialog
+ onOpenChange={(open) => !open && setSheet(null)}
+ open={sheet === "functions"}
+ >
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>May read</DialogTitle>
+ <DialogDescription>
+ A separate grant from Available to, and not implied by it: that
+ one decides who may draw this, and this decides what it may go and
+ fetch in order to draw itself. Until one of these is on it shows
+ only what the Bot passes it, and every read it does make is a row
+ in Audit. Each change takes effect immediately.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogBody className="mt-4">
+ {dataFunctions.length === 0 ? (
+ <p className="text-muted-foreground text-sm">
+ This deployment grants no data functions.
+ </p>
+ ) : (
+ <div className="flex flex-col">
+ {dataFunctions.map((fn, index) => {
+ const has = heldFunctions.has(fn.name);
+ return (
+ <div key={fn.name}>
+ {index === 0 ? null : <Separator />}
+ <Item size="sm">
+ <ItemContent>
+ <ItemTitle>{fn.name}</ItemTitle>
+ <ItemDescription>{fn.description}</ItemDescription>
+ </ItemContent>
+ <ItemActions>
+ <Switch
+ aria-label={fn.name}
+ checked={has}
+ data-testid={`function-${component.name}-${fn.name}`}
+ onCheckedChange={(next) =>
+ onSetFunction(fn.name, next)
+ }
+ />
+ </ItemActions>
+ </Item>
+ </div>
+ );
+ })}
+ </div>
+ )}
+ </DialogBody>
+ <DialogFooter className="mt-4">
+ <Button onClick={() => setSheet(null)} size="sm">
+ Done
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </PageShell>
+ );
+}
diff --git a/app/src/routes/_authed/admin/components/index.tsx b/app/src/routes/_authed/admin/components/index.tsx
new file mode 100644
index 00000000..799ff1d1
--- /dev/null
+++ b/app/src/routes/_authed/admin/components/index.tsx
@@ -0,0 +1,102 @@
+import { useQuery } from "@tanstack/react-query";
+import { createFileRoute, Link } from "@tanstack/react-router";
+import { ComponentPreview } from "@/components/component-preview";
+import { PageShell } from "@/components/layout/page-shell";
+import { SettingsItemBackground } from "@/components/settings/background";
+import {
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
+} from "@/components/ui/empty";
+import { componentListQueryOptions } from "@/lib/components/queries";
+import { cn } from "@/lib/utils";
+
+/**
+ * The gallery of compiled components. Governance for any one of them is its own page, because a
+ * component carries per-Bot grants, per-function grants and an editable description — more than a
+ * tile can hold.
+ */
+export const Route = createFileRoute("/_authed/admin/components/")({
+ component: RouteComponent,
+});
+
+function RouteComponent() {
+ const components = useQuery(componentListQueryOptions());
+
+ return (
+ <PageShell
+ description="What each Bot may answer with. Every published component is available to every Bot; switch one off here and that Bot is never told about it. Each change and each refusal is a row in Audit."
+ title="UI Components"
+ >
+ {/*
+ * Pending, error, empty, rows — in that order. Pending draws nothing rather than a
+ * placeholder, and it has to come first: the empty sentence would otherwise stand there
+ * asserting there are no components for as long as the fetch takes.
+ */}
+ {components.isPending ? null : components.error ? (
+ <p className="mt-12 text-destructive text-sm" role="alert">
+ Could not load components.
+ </p>
+ ) : components.data?.length === 0 ? (
+ <Empty className="mt-12 min-h-[30dvh] border border-dashed">
+ <EmptyHeader>
+ <EmptyTitle>No components yet</EmptyTitle>
+ <EmptyDescription className="text-pretty">
+ Components that your Agents can use will be shown here.
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ ) : (
+ <div className="mx-auto mt-12 grid w-full max-w-2xl grid-cols-1 gap-4 md:grid-cols-2">
+ {components.data?.map((component) => (
+ /*
+ * A real link rather than a button, so a component can be opened in a new tab the way
+ * anything else addressable can. Its name comes from the title and description below:
+ * the preview is `aria-hidden`, so nothing inside it reaches the accessible name.
+ */
+ <Link
+ className="flex aspect-square flex-col overflow-hidden rounded-lg border border-border bg-card text-left outline-none transition-colors hover:border-ring focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
+ data-testid={`component-${component.name}`}
+ key={component.name}
+ params={{ name: component.name }}
+ to="/admin/components/$name"
+ >
+ <div className="min-h-28 p-4">
+ <div className="flex flex-row items-center gap-2">
+ <div
+ className={cn("inline-block size-1.5 rounded-full", {
+ "bg-muted-foreground": !component.published,
+ "bg-success": component.published,
+ })}
+ />
+ <h4 className="line-clamp-1 font-medium text-sm">
+ {component.title}
+ </h4>
+ </div>
+ <p className="mt-2 line-clamp-2 text-muted-foreground text-xs">
+ {component.draftDescription}
+ </p>
+ </div>
+ <div className="relative flex-1">
+ {/*
+ * The artwork is sized explicitly. Left to itself it carries a viewBox and no width
+ * or height, which resolves to the full width and a height derived from its 3:2
+ * ratio — taller than this box, and `overflow-hidden` clips at the border rather
+ * than the padding, so it escaped the inset and met the tile's corners square.
+ * `slice` crops it to whatever shape it is given instead.
+ */}
+ <div className="absolute top-0 left-0 h-full w-full p-3">
+ <SettingsItemBackground className="h-full w-full rounded-md" />
+ </div>
+ <div className="absolute top-0 left-0 z-10 h-full w-full p-3">
+ <ComponentPreview name={component.name} />
+ </div>
+ </div>
+ </Link>
+ ))}
+ </div>
+ )}
+ </PageShell>
+ );
+}
diff --git a/app/src/routes/_authed/admin/computers.tsx b/app/src/routes/_authed/admin/computers.tsx
index 3676ea93..2cb48df3 100644
--- a/app/src/routes/_authed/admin/computers.tsx
+++ b/app/src/routes/_authed/admin/computers.tsx
@@ -1,5 +1,6 @@
+import { useMutation, useQuery } from "@tanstack/react-query";
import { createFileRoute, Link } from "@tanstack/react-router";
-import { useCallback, useEffect, useState } from "react";
+import { useState } from "react";
import {
PageEmpty,
PageRows,
@@ -25,86 +26,41 @@ import {
} from "@/components/ui/item";
import { Separator } from "@/components/ui/separator";
import { useBotNames } from "@/lib/agents/bot-names";
-
-type ComputerProfile = {
- botId: string;
- running: boolean;
- startedAt: string | null;
- egress: string | null;
-};
-
-/** API placeholder id; the list endpoint returns all computers. */
-const COMPUTER_ID = "openbot-computer";
+import { setComputerStateMutationOptions } from "@/lib/computers/mutations";
+import { computerFleetQueryOptions } from "@/lib/computers/queries";
+import { queryClient } from "@/query-client";
export const Route = createFileRoute("/_authed/admin/computers")({
component: ComputersPage,
});
function ComputersPage() {
- const [computers, setComputers] = useState<ComputerProfile[] | null>(null);
- /** Whether each Bot has an isolated browser profile. */
- const [isolation, setIsolation] = useState<"per-bot" | "shared" | null>(null);
- const [problem, setProblem] = useState<string | null>(null);
/** Bot id currently running a stop/reset request. */
const [busy, setBusy] = useState<string | null>(null);
/** Reset deletes the browser profile, so it requires confirmation. */
const [confirming, setConfirming] = useState<string | null>(null);
const nameFor = useBotNames();
- const load = useCallback(async () => {
- try {
- const response = await fetch(`/api/computers/${COMPUTER_ID}/computers`, {
- credentials: "include",
- });
- if (!response.ok) {
- const body = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- setProblem(body?.error ?? "The computers could not be listed.");
- return;
- }
- const body = (await response.json()) as {
- computers: ComputerProfile[];
- isolation?: "per-bot" | "shared";
- };
- setComputers(body.computers);
- setIsolation(body.isolation ?? null);
- setProblem(null);
- } catch {
- setProblem("The computers could not be reached.");
- }
- }, []);
+ const fleet = useQuery(computerFleetQueryOptions());
+ const setState = useMutation(setComputerStateMutationOptions(queryClient));
- useEffect(() => {
- void load();
- }, [load]);
+ const computers = fleet.data?.computers ?? null;
+ const isolation = fleet.data?.isolation ?? null;
+ /*
+ * One line for either failure. A list that could not be read and an action that was refused are
+ * both "this did not work", and the page has one place to say so.
+ */
+ const problem = fleet.error
+ ? "The computers could not be listed."
+ : setState.error
+ ? setState.error.message
+ : null;
- const run = useCallback(
- async (botId: string, action: "stop" | "reset") => {
- setBusy(botId);
- setConfirming(null);
- try {
- const response = await fetch(
- `/api/computers/${encodeURIComponent(botId)}/computers/${action}`,
- { method: "POST", credentials: "include" },
- );
- if (!response.ok) {
- const body = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- setProblem(body?.error ?? `The computer could not be ${action}.`);
- } else {
- setProblem(null);
- }
- } catch {
- setProblem("The computer could not be reached.");
- } finally {
- setBusy(null);
- await load();
- }
- },
- [load],
- );
+ const run = (botId: string, action: "stop" | "reset") => {
+ setBusy(botId);
+ setConfirming(null);
+ setState.mutate({ action, botId }, { onSettled: () => setBusy(null) });
+ };
return (
<PageShell
@@ -139,9 +95,7 @@ function ComputersPage() {
<PageSection title="Computers in this deployment">
{computers === null && problem ? (
<PageEmpty>The list could not be loaded.</PageEmpty>
- ) : computers === null ? (
- <PageEmpty>Loading…</PageEmpty>
- ) : computers.length === 0 ? (
+ ) : computers === null ? null : computers.length === 0 ? (
<PageEmpty>
No computers yet. One appears the first time a Bot opens a page.
</PageEmpty>
diff --git a/app/src/routes/_authed/admin/connectors.tsx b/app/src/routes/_authed/admin/connectors.tsx
index dd699db5..53b0eadd 100644
--- a/app/src/routes/_authed/admin/connectors.tsx
+++ b/app/src/routes/_authed/admin/connectors.tsx
@@ -32,9 +32,7 @@ function ConnectorsPage() {
title="Connectors"
>
<PageSection title="Available">
- {connectors.isPending ? (
- <PageEmpty>Loading connectors…</PageEmpty>
- ) : connectors.error ? (
+ {connectors.isPending ? null : connectors.error ? (
<p className="mt-4 text-destructive text-sm" role="alert">
Could not load connectors.
</p>
diff --git a/app/src/routes/_authed/admin/connectors/google-drive.tsx b/app/src/routes/_authed/admin/connectors/google-drive.tsx
index f2d79ebf..4bd8dad6 100644
--- a/app/src/routes/_authed/admin/connectors/google-drive.tsx
+++ b/app/src/routes/_authed/admin/connectors/google-drive.tsx
@@ -1,6 +1,7 @@
import { useForm } from "@tanstack/react-form";
-import { useMutation, useQueryClient } from "@tanstack/react-query";
+import { useMutation } from "@tanstack/react-query";
import { createFileRoute } from "@tanstack/react-router";
+import { queryClient } from "@/query-client";
import { z } from "zod";
import { PageShell } from "@/components/layout/page-shell";
import { Button } from "@/components/ui/button";
@@ -12,30 +13,14 @@ import {
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
-import { connectorKeys } from "@/lib/connectors/queries";
+import { setUpGoogleDriveMutationOptions } from "@/lib/connectors/mutations";
export const Route = createFileRoute("/_authed/admin/connectors/google-drive")({
component: GoogleDriveConnectorPage,
});
function GoogleDriveConnectorPage() {
- const queryClient = useQueryClient();
- const setup = useMutation({
- mutationFn: async (value: {
- serviceAccountJson: string;
- impersonationSubject: string;
- }) => {
- const response = await fetch("/api/admin/connectors/google-drive/setup", {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(value),
- });
- if (!response.ok) throw new Error("Could not set up Google Drive");
- },
- onSuccess: () =>
- queryClient.invalidateQueries({ queryKey: connectorKeys.all }),
- });
+ const setup = useMutation(setUpGoogleDriveMutationOptions(queryClient));
const form = useForm({
defaultValues: { serviceAccountJson: "", impersonationSubject: "" },
validators: {
diff --git a/app/src/routes/_authed/admin/credentials.tsx b/app/src/routes/_authed/admin/credentials.tsx
index a20e262a..956c0fa3 100644
--- a/app/src/routes/_authed/admin/credentials.tsx
+++ b/app/src/routes/_authed/admin/credentials.tsx
@@ -266,9 +266,7 @@ function CredentialsPage() {
</Dialog>
<PageSection title="Configured credentials">
- {credentials.isPending ? (
- <PageEmpty>Loading credentials…</PageEmpty>
- ) : credentials.error ? (
+ {credentials.isPending ? null : credentials.error ? (
<p className="mt-4 text-destructive text-sm" role="alert">
Could not load credentials.
</p>
diff --git a/app/src/routes/_authed/admin/index.tsx b/app/src/routes/_authed/admin/index.tsx
index ed7f4886..d438aef9 100644
--- a/app/src/routes/_authed/admin/index.tsx
+++ b/app/src/routes/_authed/admin/index.tsx
@@ -91,7 +91,7 @@ const SECTIONS: {
linkOptions: { to: "/admin/plugins" },
},
{
- title: "Components",
+ title: "UI Components",
description: "Custom pieces a Bot can draw in a conversation.",
icon: IconLayoutGrid,
linkOptions: { to: "/admin/components" },
diff --git a/app/src/routes/_authed/admin/playground.tsx b/app/src/routes/_authed/admin/playground.tsx
index 4a934734..667b7655 100644
--- a/app/src/routes/_authed/admin/playground.tsx
+++ b/app/src/routes/_authed/admin/playground.tsx
@@ -14,9 +14,14 @@ import {
import { Field, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
+import {
+ deleteSandboxedMutationOptions,
+ publishSandboxedMutationOptions,
+ type SandboxedDraftInput,
+ saveSandboxedDraftMutationOptions,
+} from "@/lib/sandboxed/mutations";
import {
type SandboxedRecord,
- sandboxedKeys,
sandboxedListQueryOptions,
} from "@/lib/sandboxed/queries";
@@ -65,56 +70,41 @@ function PlaygroundPage() {
const sample = parsed(draft.sampleArguments);
const schema = parsed(draft.argumentSchema);
- const mutate = useMutation({
- mutationFn: async (action: () => Promise<Response>) => {
- setError(null);
- const response = await action();
- if (!response.ok) {
- const detail = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- throw new Error(detail?.error ?? "That did not work.");
- }
- return response.json();
- },
- onSuccess: () =>
- queryClient.invalidateQueries({ queryKey: sandboxedKeys.all }),
- onError: (thrown: Error) => setError(thrown.message),
+ /* Every write here reports into the same banner, so they share one failure handler. */
+ const report = { onError: (thrown: Error) => setError(thrown.message) };
+ const saveDraft = useMutation({
+ ...saveSandboxedDraftMutationOptions(queryClient),
+ ...report,
+ });
+ const publishDraft = useMutation({
+ ...publishSandboxedMutationOptions(queryClient),
+ ...report,
+ });
+ const removeComponent = useMutation({
+ ...deleteSandboxedMutationOptions(queryClient),
+ ...report,
+ });
+ /** What the editors currently describe, in the shape the server accepts. */
+ const input = (): SandboxedDraftInput => ({
+ slug: draft.slug,
+ title: draft.title,
+ description: draft.description,
+ html: draft.html,
+ css: draft.css,
+ jsFunctions: draft.jsFunctions,
+ argumentSchema: schema ?? {},
+ sampleArguments: sample ?? {},
});
- const saveDraft = () =>
- fetch("/api/sandboxed", {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({
- slug: draft.slug,
- title: draft.title,
- description: draft.description,
- html: draft.html,
- css: draft.css,
- jsFunctions: draft.jsFunctions,
- argumentSchema: schema ?? {},
- sampleArguments: sample ?? {},
- }),
- });
-
- const save = () => mutate.mutate(saveDraft);
+ const save = () => {
+ setError(null);
+ saveDraft.mutate(input());
+ };
- /**
- * Publish what is on screen.
- *
- * Saved first, because publishing acts on the stored draft rather than on the editors.
- */
- const publish = () =>
- mutate.mutate(async () => {
- const saved = await saveDraft();
- if (!saved.ok) return saved;
- return fetch(
- `/api/sandboxed/${encodeURIComponent(`custom_${draft.slug}`)}/publish`,
- { method: "POST", credentials: "include" },
- );
- });
+ const publish = () => {
+ setError(null);
+ publishDraft.mutate(input());
+ };
const load = (component: SandboxedRecord) =>
setDraft({
@@ -330,12 +320,8 @@ function PlaygroundPage() {
const name = deleting;
setDeleting(null);
if (name) {
- mutate.mutate(() =>
- fetch(`/api/sandboxed/${encodeURIComponent(name)}`, {
- method: "DELETE",
- credentials: "include",
- }),
- );
+ setError(null);
+ removeComponent.mutate(name);
}
}}
size="sm"
diff --git a/app/src/routes/_authed/admin/plugins.tsx b/app/src/routes/_authed/admin/plugins.tsx
index f805b4a1..20402f1b 100644
--- a/app/src/routes/_authed/admin/plugins.tsx
+++ b/app/src/routes/_authed/admin/plugins.tsx
@@ -3,11 +3,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { createFileRoute } from "@tanstack/react-router";
import * as React from "react";
import { useState } from "react";
-import {
- PageEmpty,
- PageSection,
- PageShell,
-} from "@/components/layout/page-shell";
+import { PageSection, PageShell } from "@/components/layout/page-shell";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -24,10 +20,19 @@ import { Separator } from "@/components/ui/separator";
import { Textarea } from "@/components/ui/textarea";
import { useBotNames } from "@/lib/agents/bot-names";
import { agentListQueryOptions } from "@/lib/agents/queries";
+import { storeMcpToken } from "@/lib/credentials/mutations";
+import {
+ addCuratedServerMutationOptions,
+ addCustomServerMutationOptions,
+ refreshPluginServerMutationOptions,
+ removePluginServerMutationOptions,
+ removeSkillMutationOptions,
+ saveSkillMutationOptions,
+ setPluginGrantMutationOptions,
+} from "@/lib/plugins/mutations";
import {
type PluginServer,
type PluginSkill,
- pluginKeys,
pluginsPageQueryOptions,
} from "@/lib/plugins/queries";
@@ -46,58 +51,58 @@ function PluginsPage() {
const [tab, setTab] = useState<"catalogue" | "yours" | "skills">("catalogue");
const [error, setError] = useState<string | null>(null);
- const refresh = () =>
- queryClient.invalidateQueries({ queryKey: pluginKeys.all });
-
- const post = async (path: string, body: unknown) => {
- setError(null);
- const response = await fetch(`/api/plugins${path}`, {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify(body),
- });
- if (!response.ok) {
- const detail = (await response.json().catch(() => null)) as {
- error?: string;
- } | null;
- throw new Error(detail?.error ?? "That did not work.");
- }
- return response.json();
- };
+ /*
+ * Every write on this page reports into the same banner, so they share one failure handler rather
+ * than each growing its own. `refresh` stays because two of them are chains that end in a server
+ * record the catalogue reads back.
+ */
+ const report = { onError: (thrown: Error) => setError(thrown.message) };
+ const setGrant = useMutation({
+ ...setPluginGrantMutationOptions(queryClient),
+ ...report,
+ });
+ const addCurated = useMutation({
+ ...addCuratedServerMutationOptions(queryClient),
+ ...report,
+ });
+ const addCustom = useMutation({
+ ...addCustomServerMutationOptions(queryClient),
+ ...report,
+ });
+ const refreshServer = useMutation({
+ ...refreshPluginServerMutationOptions(queryClient),
+ ...report,
+ });
+ const removeServer = useMutation({
+ ...removePluginServerMutationOptions(queryClient),
+ ...report,
+ });
+ const saveSkill = useMutation({
+ ...saveSkillMutationOptions(queryClient),
+ ...report,
+ });
+ const removeSkill = useMutation({
+ ...removeSkillMutationOptions(queryClient),
+ ...report,
+ });
/**
- * Store the token as a credential first; plugin server records keep only the credential id.
+ * Adding a server is two writes: the token becomes a credential, then the record refers to it.
+ * Chained here rather than in a factory because only this page knows a token was typed.
*/
- const storeToken = async (
+ const addServerWithToken = async (
+ run: (credentialId?: string) => void,
serverId: string,
token?: string,
- ): Promise<string | undefined> => {
- if (!token?.trim()) return undefined;
- const response = await fetch("/api/admin/credentials", {
- method: "POST",
- credentials: "include",
- headers: { "content-type": "application/json" },
- body: JSON.stringify({
- kind: "mcp",
- provider: serverId,
- keyId: `mcp-${serverId}`,
- plaintext: token.trim(),
- metadata: { server: serverId },
- }),
- });
- if (!response.ok) {
- throw new Error("The token could not be stored.");
+ ) => {
+ setError(null);
+ try {
+ run(await storeMcpToken(serverId, token));
+ } catch (thrown) {
+ setError((thrown as Error).message);
}
- return (await response.json())?.credential?.id;
};
- const mutate = useMutation({
- mutationFn: async (action: () => Promise<unknown>) => action(),
- onSuccess: refresh,
- onError: (thrown: Error) => setError(thrown.message),
- });
-
const bots = (agents ?? []).map((agent: { id: string }) => ({
id: agent.id,
name: nameFor(agent.id),
@@ -136,9 +141,7 @@ function PluginsPage() {
) : null}
<div className="mt-6">
- {isPending ? (
- <PageEmpty>Loading plugins…</PageEmpty>
- ) : isError || !data ? (
+ {isPending ? null : isError || !data ? (
<p className="mt-4 text-destructive text-sm" role="alert">
Plugins could not be loaded.
</p>
@@ -147,69 +150,53 @@ function PluginsPage() {
added={new Set(data.servers.map((server) => server.id))}
items={data.catalogue}
onAdd={(key, instanceHost, token) =>
- mutate.mutate(async () => {
- const credentialId = await storeToken(key, token);
- return post("/servers", { key, instanceHost, credentialId });
- })
+ void addServerWithToken(
+ (credentialId) =>
+ addCurated.mutate({ key, instanceHost, credentialId }),
+ key,
+ token,
+ )
}
onAddCustom={(input) =>
- mutate.mutate(async () => {
- const credentialId = await storeToken(input.id, input.token);
- return post("/servers/custom", { ...input, credentialId });
- })
+ void addServerWithToken(
+ (credentialId) =>
+ addCustom.mutate({ ...input, credentialId }),
+ input.id,
+ input.token,
+ )
}
/>
) : tab === "yours" ? (
<Yours
bots={bots}
onGrant={(ref, agentId, held) =>
- mutate.mutate(() =>
- held
- ? fetch(
- `/api/plugins/grants?kind=mcp&ref=${encodeURIComponent(ref)}&agentId=${encodeURIComponent(agentId)}`,
- { method: "DELETE", credentials: "include" },
- )
- : post("/grants", { kind: "mcp", ref, agentId }),
- )
- }
- onRefresh={(id) =>
- mutate.mutate(() => post(`/servers/${id}/refresh`, {}))
- }
- onRemove={(id) =>
- mutate.mutate(() =>
- fetch(`/api/plugins/servers/${encodeURIComponent(id)}`, {
- method: "DELETE",
- credentials: "include",
- }),
- )
+ setGrant.mutate({
+ agentId,
+ granted: !held,
+ kind: "mcp",
+ ref,
+ })
}
+ onRefresh={(id) => refreshServer.mutate(id)}
+ onRemove={(id) => removeServer.mutate(id)}
servers={data.servers}
/>
) : (
<Skills
bots={bots}
onGrant={(slug, agentId, held) =>
- mutate.mutate(() =>
- held
- ? fetch(
- `/api/plugins/grants?kind=skill&ref=${encodeURIComponent(slug)}&agentId=${encodeURIComponent(agentId)}`,
- { method: "DELETE", credentials: "include" },
- )
- : post("/grants", { kind: "skill", ref: slug, agentId }),
- )
+ setGrant.mutate({
+ agentId,
+ granted: !held,
+ kind: "skill",
+ ref: slug,
+ })
}
// Admin-authored skills are deployment-global; personal skills are created elsewhere.
onInstall={(input) =>
- mutate.mutate(() => post("/skills", { ...input, global: true }))
- }
- onUninstall={(slug) =>
- mutate.mutate(() =>
- fetch(`/api/plugins/skills/${encodeURIComponent(slug)}`, {
- method: "DELETE",
- credentials: "include",
- }),
- )
+ saveSkill.mutate({ ...input, global: true })
}
+ onUninstall={(slug) => removeSkill.mutate(slug)}
skills={data.skills}
/>
)}
diff --git a/app/src/routes/_authed/settings/components-gallery/$name.tsx b/app/src/routes/_authed/settings/components-gallery/$name.tsx
new file mode 100644
index 00000000..f1cddc17
--- /dev/null
+++ b/app/src/routes/_authed/settings/components-gallery/$name.tsx
@@ -0,0 +1,152 @@
+import { IconCode, IconTag } from "@tabler/icons-react";
+import { useQuery } from "@tanstack/react-query";
+import { createFileRoute, Link } from "@tanstack/react-router";
+import type { ReactNode } from "react";
+import { ComponentPreview } from "@/components/component-preview";
+import {
+ PageRows,
+ PageSection,
+ PageShell,
+} from "@/components/layout/page-shell";
+import { SettingsItemBackground } from "@/components/settings/background";
+import { Button } from "@/components/ui/button";
+import {
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
+} from "@/components/ui/empty";
+import {
+ Item,
+ ItemActions,
+ ItemContent,
+ ItemMedia,
+ ItemTitle,
+} from "@/components/ui/item";
+import { Separator } from "@/components/ui/separator";
+import { componentListQueryOptions } from "@/lib/components/queries";
+
+/** The same way back from every state this route can be in. */
+const BACK = {
+ label: "Components gallery",
+ linkProps: { to: "/settings/components-gallery" },
+} as const;
+
+/**
+ * One component, drawn as large as this column allows, and nothing to change.
+ *
+ * Deliberately not the Admin detail page with its controls hidden. That page is built out of four
+ * mutations and three kinds of row; threading a read-only flag through all of it would leave every
+ * row carrying a branch for a case it mostly does not have.
+ */
+export const Route = createFileRoute(
+ "/_authed/settings/components-gallery/$name",
+)({
+ component: RouteComponent,
+});
+
+/** A read-only fact: the label on the left, the value against the right. */
+function FactRow({
+ icon,
+ label,
+ children,
+}: {
+ icon: ReactNode;
+ label: string;
+ children: ReactNode;
+}) {
+ return (
+ <Item size="sm">
+ <ItemMedia variant="icon">{icon}</ItemMedia>
+ <ItemContent>
+ <ItemTitle>{label}</ItemTitle>
+ </ItemContent>
+ <ItemActions className="text-muted-foreground text-sm">
+ {children}
+ </ItemActions>
+ </Item>
+ );
+}
+
+function RouteComponent() {
+ const { name } = Route.useParams();
+ const components = useQuery(componentListQueryOptions());
+
+ if (components.isPending) return null;
+
+ if (components.error) {
+ return (
+ <PageShell backButton={BACK} title="Components gallery">
+ <p className="mt-8 text-destructive text-sm" role="alert">
+ Could not load components.
+ </p>
+ </PageShell>
+ );
+ }
+
+ /*
+ * Unpublished is treated as absent rather than as a component with a notice on it. Nothing can
+ * draw one, so from here there is no difference between not published and not there.
+ */
+ const component = components.data?.find(
+ (entry) => entry.name === name && entry.published,
+ );
+
+ if (!component) {
+ return (
+ <PageShell
+ backButton={BACK}
+ description="Nothing here answers to that name."
+ title="No such component"
+ >
+ <Empty className="mt-12 min-h-[30dvh] border border-dashed">
+ <EmptyHeader>
+ <EmptyTitle>{name}</EmptyTitle>
+ <EmptyDescription className="text-pretty">
+ It may have been withdrawn, or this deployment may no longer ship
+ it.
+ </EmptyDescription>
+ </EmptyHeader>
+ <Button
+ render={<Link to="/settings/components-gallery" />}
+ size="sm"
+ variant="outline"
+ >
+ Back to the gallery
+ </Button>
+ </Empty>
+ </PageShell>
+ );
+ }
+
+ return (
+ <PageShell
+ backButton={BACK}
+ description={component.publishedDescription ?? undefined}
+ title={component.title}
+ >
+ <div className="relative mt-8 aspect-[2/1] overflow-hidden rounded-lg border border-border bg-card">
+ <div className="absolute inset-0">
+ <SettingsItemBackground className="h-full w-full" />
+ </div>
+ <div className="absolute inset-0 z-10">
+ <ComponentPreview name={component.name} />
+ </div>
+ </div>
+
+ <PageSection title="Details">
+ <PageRows>
+ <FactRow icon={<IconTag />} label="Kind">
+ {component.kind}
+ </FactRow>
+ <Separator />
+ <FactRow icon={<IconCode />} label="Called as">
+ <code className="rounded bg-foreground/5 px-1.5 py-0.5 text-xs">
+ {component.name}
+ </code>
+ </FactRow>
+ </PageRows>
+ </PageSection>
+ </PageShell>
+ );
+}
diff --git a/app/src/routes/_authed/settings/components-gallery/index.tsx b/app/src/routes/_authed/settings/components-gallery/index.tsx
new file mode 100644
index 00000000..3c74b82b
--- /dev/null
+++ b/app/src/routes/_authed/settings/components-gallery/index.tsx
@@ -0,0 +1,84 @@
+import { useQuery } from "@tanstack/react-query";
+import { createFileRoute, Link } from "@tanstack/react-router";
+import { ComponentPreview } from "@/components/component-preview";
+import { PageShell } from "@/components/layout/page-shell";
+import { SettingsItemBackground } from "@/components/settings/background";
+import {
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
+} from "@/components/ui/empty";
+import { componentListQueryOptions } from "@/lib/components/queries";
+
+/**
+ * What a Bot can draw, for the person it draws for.
+ *
+ * The same gallery an administrator governs, with none of the governing. Published components only:
+ * an unpublished one is not something any Bot can put on screen, so listing it here would describe a
+ * capability nobody has. The description shown is the published one — what the model is actually
+ * told — rather than a draft an administrator may be part-way through rewording.
+ */
+export const Route = createFileRoute("/_authed/settings/components-gallery/")({
+ component: RouteComponent,
+});
+
+function RouteComponent() {
+ const components = useQuery(componentListQueryOptions());
+ const published = components.data?.filter((component) => component.published);
+
+ return (
+ <PageShell
+ description="The pieces a Bot can draw in a conversation instead of describing something in prose. Which of them any one Bot may use is an administrator's decision."
+ title="Components gallery"
+ >
+ {components.isPending ? null : components.error ? (
+ <p className="mt-12 text-destructive text-sm" role="alert">
+ Could not load components.
+ </p>
+ ) : published?.length === 0 ? (
+ <Empty className="mt-12 min-h-[30dvh] border border-dashed">
+ <EmptyHeader>
+ <EmptyTitle>Nothing published yet</EmptyTitle>
+ <EmptyDescription className="text-pretty">
+ When an administrator publishes a component, it will show up here.
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ ) : (
+ <div className="mx-auto mt-12 grid w-full max-w-2xl grid-cols-1 gap-4 md:grid-cols-2">
+ {published?.map((component) => (
+ /*
+ * No status dot, unlike the Admin tiles. Everything listed here is published by
+ * definition, so a dot saying so would be the same mark on every tile.
+ */
+ <Link
+ className="flex aspect-square flex-col overflow-hidden rounded-lg border border-border bg-card text-left outline-none transition-colors hover:border-ring focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
+ data-testid={`gallery-${component.name}`}
+ key={component.name}
+ params={{ name: component.name }}
+ to="/settings/components-gallery/$name"
+ >
+ <div className="min-h-28 p-4">
+ <h4 className="line-clamp-1 font-medium text-sm">
+ {component.title}
+ </h4>
+ <p className="mt-2 line-clamp-2 text-muted-foreground text-xs">
+ {component.publishedDescription}
+ </p>
+ </div>
+ <div className="relative flex-1">
+ <div className="absolute top-0 left-0 h-full w-full p-3">
+ <SettingsItemBackground className="h-full w-full rounded-md" />
+ </div>
+ <div className="absolute top-0 left-0 z-10 h-full w-full p-3">
+ <ComponentPreview name={component.name} />
+ </div>
+ </div>
+ </Link>
+ ))}
+ </div>
+ )}
+ </PageShell>
+ );
+}
diff --git a/app/src/styles.css b/app/src/styles.css
index cbb26797..b202fe53 100644
--- a/app/src/styles.css
+++ b/app/src/styles.css
@@ -34,6 +34,7 @@ html {
--accent: oklch(0.97 0 0);
--accent-foreground: oklch(0.205 0 0);
--destructive: oklch(0.577 0.245 27.325);
+ --success: oklch(0.6 0.118 184.704);
--border: oklch(0.922 0 0);
--input: oklch(0.922 0 0);
--ring: oklch(0.708 0 0);
@@ -69,6 +70,7 @@ html {
--accent: oklch(0.269 0 0);
--accent-foreground: oklch(0.985 0 0);
--destructive: oklch(0.704 0.191 22.216);
+ --success: oklch(0.704 0.14 182.503);
--border: oklch(1 0 0 / 10%);
--input: oklch(1 0 0 / 15%);
--ring: oklch(0.556 0 0);
@@ -135,6 +137,7 @@ body {
--color-input: var(--input);
--color-border: var(--border);
--color-destructive: var(--destructive);
+ --color-success: var(--success);
--color-accent-foreground: var(--accent-foreground);
--color-accent: var(--accent);
--color-muted-foreground: var(--muted-foreground);