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.
Say the skills could not be read instead of saying there are none (#665)
kevinafe623366945
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0dfdac9c..33f72121 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,6 +24,14 @@ terminal, chose its interactive build display, and could not draw it. The scriptfor quiet progress through `COMPOSE_PROGRESS`, which older Compose versions ignore, so nothingchanges where it already worked.+### The skills pages say when the skills could not be read++When `GET /api/plugins` failed, **Agent Skills** said "You don't have any skills yet.", **Admin →+Skills** said "No skills yet.", and opening a skill to edit said "That skill no longer exists, or it+is not yours to edit.", to people who may have written a dozen. They now say the skills could not+be loaded. A list that arrived empty still reads as before, and a failed refetch over a list already+on screen keeps that list.+### A coworker can be pinned to the top of the Agents screenA coworker's Manage tab has a **Pin** switch beside Hide, and pinned coworkers move into adiff --git a/app/src/components/skills/edit-skill.tsx b/app/src/components/skills/edit-skill.tsxindex 6e2cdf44..254a382f 100644--- a/app/src/components/skills/edit-skill.tsx+++ b/app/src/components/skills/edit-skill.tsx@@ -30,6 +30,20 @@ export function EditSkill({ slug }: { slug: string }) {/* Nothing while it loads. "Missing" and "not yet arrived" must not read the same. */if (isPending) return null;+ /*+ * No list is not a missing skill. `isPending` goes false on a failed read too, and the sentence+ * below tells somebody their skill is gone, or was never theirs, on no evidence at all.+ */+ if (!data) {+ return (+ <div className="mx-auto flex w-full max-w-xl flex-col gap-6 p-8">+ <p className="text-destructive text-sm" role="alert">+ This skill could not be loaded.+ </p>+ </div>+ );+ }+if (!skill) {return (<div className="mx-auto flex w-full max-w-xl flex-col gap-6 p-8">diff --git a/app/src/routes/_authed/_app/skills.tsx b/app/src/routes/_authed/_app/skills.tsxindex bb9dd1aa..97268d0a 100644--- a/app/src/routes/_authed/_app/skills.tsx+++ b/app/src/routes/_authed/_app/skills.tsx@@ -140,8 +140,16 @@ function SkillsPage() {* 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.+ *+ * And not after a read that failed, for the same reason: `isPending` goes false on a+ * failed fetch too, and no list is no evidence of no skills. A list already held stays on+ * screen through a failed refetch, because `data` is still there.*/}- {loading ? null : mine.length === 0 ? (+ {loading ? null : !data ? (+ <p className="mt-4 text-destructive text-sm" role="alert">+ Your skills could not be loaded.+ </p>+ ) : mine.length === 0 ? (<Empty className="mt-4 h-[180px] border border-dashed"><EmptyHeader><EmptyTitle className="text-muted-foreground">diff --git a/app/src/routes/_authed/admin/skills.tsx b/app/src/routes/_authed/admin/skills.tsxindex 9f4d2a6d..b02cf55a 100644--- a/app/src/routes/_authed/admin/skills.tsx+++ b/app/src/routes/_authed/admin/skills.tsx@@ -107,7 +107,12 @@ function RouteComponent() {description="Written for the whole deployment. People write their own on their Skills page."title="Installed">- {plugins.isPending ? null : skills.length === 0 ? (+ {/* A read that failed says so; `isPending` goes false on it too, and it is not "none". */}+ {plugins.isPending ? null : !plugins.data ? (+ <p className="mt-4 text-destructive text-sm" role="alert">+ Skills could not be loaded.+ </p>+ ) : skills.length === 0 ? (<PageEmpty>No skills yet.</PageEmpty>) : (<PageRows>diff --git a/app/tests/skills-read-failure.test.tsx b/app/tests/skills-read-failure.test.tsxnew file mode 100644index 00000000..4ea13347--- /dev/null+++ b/app/tests/skills-read-failure.test.tsx@@ -0,0 +1,232 @@+import {+ afterAll,+ afterEach,+ beforeAll,+ beforeEach,+ expect,+ test,+} from "bun:test";+import { GlobalRegistrator } from "@happy-dom/global-registrator";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import {+ createMemoryHistory,+ createRootRoute,+ createRoute,+ createRouter,+ Outlet,+ RouterProvider,+} from "@tanstack/react-router";+import { cleanup, render, waitFor } from "@testing-library/react";+import type { ComponentType } from "react";+import { EditSkill } from "@/components/skills/edit-skill";+import { type PluginsPage, pluginKeys } from "@/lib/plugins/queries";+import { Route as SkillsRoute } from "@/routes/_authed/_app/skills";+import { Route as AdminSkillsRoute } from "@/routes/_authed/admin/skills";++/**+ * The three places skills are listed or opened, when `GET /api/plugins` fails.+ *+ * Each read `data?.skills ?? []` once `isPending` was false, and `isPending` goes false on a failed+ * fetch exactly as it does on a successful one: a request that never came back was drawn as "You+ * don't have any skills yet.", "No skills yet." and "That skill no longer exists", to people who+ * may have written a dozen. `agent-roster-error.test.tsx` is the same mistake on the agent screens.+ *+ * Only the plugins read fails here; who is signed in and the roster answer.+ *+ * THE HARNESS IS THIS REPOSITORY'S, as in `agent-roster-error.test.tsx` and+ * `boundaries-read-failure.test.tsx`: `GlobalRegistrator` in `beforeAll`/`afterAll`, `cleanup` in+ * `afterEach`, queries off `render()`'s own return, a `QueryClient` with `retry: false`, and the+ * exported `Route` singleton captured and restored around its `.update()`.+ */++beforeAll(() => GlobalRegistrator.register());+afterEach(cleanup);+afterAll(() => GlobalRegistrator.unregister());++const originalFetch = global.fetch;++beforeEach(() => {+ global.fetch = Object.assign(+ async (input: Parameters<typeof fetch>[0]) => {+ const path = String(input).split("?")[0];+ const json = (body: unknown) =>+ new Response(JSON.stringify(body), {+ headers: { "content-type": "application/json" },+ });+ if (path === "/api/me") {+ return json({+ user: {+ id: "user-1",+ email: "[email protected]",+ role: "admin",+ onboarding: null,+ },+ });+ }+ if (path === "/api/agents") return json({ agents: [] });+ // The one read under test: a 500 with no body, the shape a broken server sends.+ return new Response(null, { status: 500 });+ },+ { preconnect: originalFetch.preconnect },+ );+});++afterEach(() => {+ global.fetch = originalFetch;+});++/** A client the failing query settles on in one attempt, so no test waits on a retry. */+function failingQueryClient() {+ return new QueryClient({ defaultOptions: { queries: { retry: false } } });+}++/** A client already holding a plugins page with no skills in it: the honest empty answer. */+function answeredEmpty() {+ const client = failingQueryClient();+ const page: PluginsPage = {+ catalogue: [],+ servers: [],+ skills: [],+ botsMayCallBack: true,+ redirectUri: null,+ composioConfigured: false,+ };+ client.setQueryData(pluginKeys.page(), page);+ return client;+}++async function waitForFailedRead(client: QueryClient) {+ await waitFor(() => {+ expect(client.getQueryState(pluginKeys.page())?.status).toBe("error");+ });+}++function captureRouteState(route: object): Record<string, unknown> {+ return { ...route, options: { ...(route as { options: object }).options } };+}++function restoreRouteState(+ route: object,+ snapshot: Record<string, unknown>,+): void {+ for (const key of Object.keys(route)) {+ if (!(key in snapshot)) {+ delete (route as Record<string, unknown>)[key];+ }+ }+ Object.assign(route, snapshot);+}++const pristineSkillsRouteState = captureRouteState(SkillsRoute);+let skillsRouteSnapshot: Record<string, unknown>;++beforeEach(() => {+ skillsRouteSnapshot = captureRouteState(pristineSkillsRouteState);+});++afterEach(() => {+ restoreRouteState(SkillsRoute, skillsRouteSnapshot);+});++/** `/skills`, at the id its `Route.useSearch()` reads: `/_authed/_app/skills`. */+function renderSkills(client: QueryClient) {+ const rootRoute = createRootRoute({ component: Outlet });+ const authedRoute = createRoute({+ id: "/_authed",+ getParentRoute: () => rootRoute,+ component: Outlet,+ });+ const appRoute = createRoute({+ id: "/_app",+ getParentRoute: () => authedRoute,+ component: Outlet,+ });+ const skills = (+ SkillsRoute as unknown as { update: (options: unknown) => unknown }+ ).update({+ path: "/skills",+ getParentRoute: () => appRoute,+ });+ const tree = rootRoute.addChildren([+ authedRoute.addChildren([appRoute.addChildren([skills as never])]),+ ]);+ const router = createRouter({+ routeTree: tree,+ history: createMemoryHistory({ initialEntries: ["/skills"] }),+ });+ return render(+ <QueryClientProvider client={client}>+ <RouterProvider router={router as never} />+ </QueryClientProvider>,+ );+}++/** A component that reads no route of its own, drawn under a root route for `Link`/`useNavigate`. */+function renderAlone(client: QueryClient, Component: ComponentType) {+ const router = createRouter({+ history: createMemoryHistory({ initialEntries: ["/"] }),+ routeTree: createRootRoute({ component: () => <Component /> }),+ });+ return render(+ <QueryClientProvider client={client}>+ <RouterProvider router={router as never} />+ </QueryClientProvider>,+ );+}++test("a person's skills page says the skills failed to load, not that they have none", async () => {+ const client = failingQueryClient();+ const view = renderSkills(client);+ await waitForFailedRead(client);++ expect(+ await view.findByText("Your skills could not be loaded."),+ ).toBeTruthy();+ expect(view.queryByText("You don't have any skills yet.")).toBeNull();+});++test("a person with genuinely no skills is still told so", async () => {+ const client = answeredEmpty();+ const view = renderSkills(client);+ await waitForFailedRead(client);++ expect(await view.findByText("You don't have any skills yet.")).toBeTruthy();+ expect(view.queryByText("Your skills could not be loaded.")).toBeNull();+});++test("the admin skills page says the skills failed to load, not that there are none", async () => {+ const client = failingQueryClient();+ const view = renderAlone(+ client,+ AdminSkillsRoute.options.component as ComponentType,+ );+ await waitForFailedRead(client);++ expect(await view.findByText("Skills could not be loaded.")).toBeTruthy();+ expect(view.queryByText("No skills yet.")).toBeNull();+});++test("a deployment with genuinely no skills still says so on the admin page", async () => {+ const client = answeredEmpty();+ const view = renderAlone(+ client,+ AdminSkillsRoute.options.component as ComponentType,+ );+ await waitForFailedRead(client);++ expect(await view.findByText("No skills yet.")).toBeTruthy();+ expect(view.queryByText("Skills could not be loaded.")).toBeNull();+});++test("opening a skill to edit says it failed to load, not that it no longer exists", async () => {+ const client = failingQueryClient();+ const view = renderAlone(client, () => <EditSkill slug="triage" />);+ await waitForFailedRead(client);++ expect(await view.findByText("This skill could not be loaded.")).toBeTruthy();+ expect(+ view.queryByText(+ "That skill no longer exists, or it is not yours to edit.",+ ),+ ).toBeNull();+});