diff --git a/app/src/components/manage/skill-page.tsx b/app/src/components/manage/skill-page.tsx index 49f6ae6fc5..74fd309e67 100644 --- a/app/src/components/manage/skill-page.tsx +++ b/app/src/components/manage/skill-page.tsx @@ -2,10 +2,11 @@ import { IconBolt, IconChevronRight, IconFileOff, + IconPencil, IconTrash, } from "@/components/icons"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { useNavigate } from "@tanstack/react-router"; +import { Link, linkOptions, useNavigate } from "@tanstack/react-router"; import { useState } from "react"; import { PageEmpty, @@ -13,7 +14,9 @@ import { PageSection, PageShell, } from "@/components/layout/page-shell"; +import { SkillAgents } from "@/components/skills/skill-agents"; import { SkillFields } from "@/components/skills/skill-fields"; +import { SkillOverview, skillByline } from "@/components/skills/skill-overview"; import { SkillTeamGrantsRow } from "@/components/team-grants/team-grants-row"; import { Button } from "@/components/ui/button"; import { @@ -38,6 +41,7 @@ import { toast } from "@/components/ui/toast"; import { grantRoster } from "@/lib/agents/grant-roster"; import { useBotListScope } from "@/lib/agents/list-scope"; import { agentListQueryOptions } from "@/lib/agents/queries"; +import { currentUserQueryOptions } from "@/lib/auth/queries"; import { type Failure, failureSaid, loadFailure } from "@/lib/load-failure"; import { useManagePaths } from "@/lib/manage-paths"; import { setPluginGrantMutationOptions } from "@/lib/plugins/mutations"; @@ -48,17 +52,35 @@ import { import { skillListQueryOptions } from "@/lib/skills/queries"; /** - * One of the deployment's skills: which Bots offer it, what it says, and removing it. + * One skill, on a screen of its own: the one way to open a skill someone wrote. Skills in the main + * menu opens it at `/skills/$slug` (`place="you"`), and Admin at `/admin/skills/$slug`. * - * Bots first, because a skill no Bot offers does nothing, and that is the decision made most often - * here. Each Bot is one row with one switch, as on a tool's page (`plugin-tool-page.tsx`), where the - * list used to draw a chip per Bot inside every skill's row. + * Read first, as a person reads a skill more often than they change it: who wrote it, its + * one-liner, the tools it needs and its instructions (`SkillOverview`). Edit opens the form on the + * same address (`?edit=true`); Cancel and Save come back to the overview, replacing the form in the + * history so Back doesn't reopen it. + * + * Under the overview, which Bots offer it. Where the person manages every Bot's skills (Admin, and + * the personal edition, where there is one person), each Bot is one row with one switch, as on a + * tool's page (`plugin-tool-page.tsx`), then Delete. In the team edition's Skills a person puts + * their own skill on their own Bots only (`SkillAgents`), and a workspace skill is read-only. * * Editing saves the same way creating does: `replaceSkill` writes under the slug and leaves the * owner alone, so the command is fixed here (`slugLocked`). */ -export function SkillPage({ slug }: { slug: string }) { +export function SkillPage({ + slug, + place, + editing = false, +}: { + slug: string; + /** Admin's page, or the main menu's Skills. */ + place: "admin" | "you"; + /** The form, rather than the overview. */ + editing?: boolean; +}) { const paths = useManagePaths(); + const me = useQuery(currentUserQueryOptions()).data; const navigate = useNavigate(); const queryClient = useQueryClient(); const skillList = useQuery(skillListQueryOptions()); @@ -79,7 +101,17 @@ export function SkillPage({ slug }: { slug: string }) { const saveSkill = useMutation(saveSkillMutationOptions(queryClient)); const removeSkill = useMutation(removeSkillMutationOptions(queryClient)); - const back = { label: "Skills", linkProps: paths.skills() }; + const here = + place === "admin" + ? linkOptions({ to: "/admin/skills/$slug", params: { slug } }) + : linkOptions({ to: "/skills/$slug", params: { slug } }); + const back = { + label: "Skills", + linkProps: + place === "admin" + ? linkOptions({ to: "/admin/skills" }) + : linkOptions({ to: "/skills" }), + }; const skill = skillList.data?.find((candidate) => candidate.slug === slug); /* Nothing rather than a placeholder, so no sentence asserts anything while the fetch is open. */ @@ -120,183 +152,242 @@ export function SkillPage({ slug }: { slug: string }) { hidden: hiddenAgents ?? [], holders: skill.grantedTo, }); + /* Every Bot's switch and Delete: Admin, or the personal edition's one person. */ + const manages = place === "admin" || paths.edition === "personal"; + const yours = !!me && skill.ownerUserId === me.id; + const canEdit = manages || yours; + + if (editing && canEdit) { + return ( + + { + await saveSkill.mutateAsync({ + ...values, + global: skill.ownerUserId === null, + }); + toast.add({ title: "Skill saved", type: "success" }); + // Replaced, so Back from the overview doesn't open the form again. + await navigate({ ...here, replace: true }); + }} + sections={{ + cancel: ( + + ), + flush: true, + }} + slugLocked + submitLabel="Save changes" + /> + + ); + } return ( ( + + )} + size="sm" + variant="outline" + > + + Edit + + ) : undefined + } backButton={back} - {...(skill.summary ? { description: skill.summary } : {})} + description={skillByline(skill, me?.id, paths.edition)} title={skill.title} > +
+ {skill.summary ?

{skill.summary}

: null} + +
+ {error ? ( -

+

{failureSaid(error)}

) : null} - - Bots with their switch on offer {skill.title} when someone types{" "} - /. It takes effect at once. - - } - title="Bots" - > - {/* A roster that couldn't be read is not a roster of none. */} - {agents === undefined && roster.error ? ( -

- {loadFailure( - roster.error, - "Couldn't load your Bots. Try again in a moment.", - )} -

- ) : null} - {bots.length === 0 ? ( - agents === undefined ? null : ( - - Create a Bot to offer this skill. - - ) - ) : ( - - {bots.map((bot, index) => { - const held = skill.grantedTo.includes(bot.id); - return ( -
- - - {bot.name} - - {bot.hidden ? "Hidden from your roster. " : ""} - {held - ? "Offers this skill." - : "Doesn't offer this skill."} - - - - {/* - * Binary and immediate: it takes effect when switched and there is no save. - * Disabled only while its own write is in flight, so switching one Bot does - * not freeze the rest of the list. - */} - { - setError(null); - setGrant.mutate({ - agentId: bot.id, - granted: next, - kind: "skill", - ref: skill.slug, - }); - }} - /> - - - {index !== bots.length - 1 && } -
- ); - })} -
- )} -
- - { - await saveSkill.mutateAsync({ ...values, global: true }); - toast.add({ title: "Skill saved", type: "success" }); - }} - slugLocked - submitLabel="Save changes" - /> + {/* Their own skill on their own Bots: what a person may grant in the team edition. */} + {!manages && yours ? ( + + + + ) : null} - {/* A row that opens the confirmation, as deleting a Bot is on its own page. */} - - - {/* Teams are the team edition's: with one person there is nobody to grant a skill to. */} - {paths.edition === "team" ? ( - - ) : null} - setRemoving(true)} type="button" />} - size="sm" + {manages ? ( + <> + + Bots with their switch on offer {skill.title} when someone types{" "} + /. It takes effect at once. + + } + title="Bots" > - - - - - Delete - - People can't run it any more, and no Bot offers it. You can't - undo this. - - - - - - - - + {/* A roster that couldn't be read is not a roster of none. */} + {agents === undefined && roster.error ? ( +

+ {loadFailure( + roster.error, + "Couldn't load your Bots. Try again in a moment.", + )} +

+ ) : null} + {bots.length === 0 ? ( + agents === undefined ? null : ( + + Create a Bot to offer this skill. + + ) + ) : ( + + {bots.map((bot, index) => { + const held = skill.grantedTo.includes(bot.id); + return ( +
+ + + {bot.name} + + {bot.hidden ? "Hidden from your roster. " : ""} + {held + ? "Offers this skill." + : "Doesn't offer this skill."} + + + + {/* + * Binary and immediate: it takes effect when switched and there is no save. + * Disabled only while its own write is in flight, so switching one Bot does + * not freeze the rest of the list. + */} + { + setError(null); + setGrant.mutate({ + agentId: bot.id, + granted: next, + kind: "skill", + ref: skill.slug, + }); + }} + /> + + + {index !== bots.length - 1 && } +
+ ); + })} +
+ )} + - - - - Delete {skill.title}? - - People can't run it any more, and no Bot offers it. You can't undo - this. - - - {removeSkill.error ? ( -

- {failureSaid(removeSkill.error)} -

- ) : null} - - - - -
-
+ {/* A row that opens the confirmation, as deleting a Bot is on its own page. */} + + + {/* Teams are the team edition's: with one person there is nobody to grant a skill to. */} + {paths.edition === "team" ? ( + + ) : null} + setRemoving(true)} type="button" /> + } + size="sm" + > + + + + + Delete + + People can't run it any more, and no Bot offers it. You + can't undo this. + + + + + + + + + + + + + Delete {skill.title}? + + People can't run it any more, and no Bot offers it. You can't + undo this. + + + {removeSkill.error ? ( +

+ {failureSaid(removeSkill.error)} +

+ ) : null} + + + + +
+
+ + ) : null}
); } diff --git a/app/src/components/settings/learning-sharing.tsx b/app/src/components/settings/learning-sharing.tsx index cc159451d1..752dcdde23 100644 --- a/app/src/components/settings/learning-sharing.tsx +++ b/app/src/components/settings/learning-sharing.tsx @@ -124,7 +124,7 @@ export function SkillMark({ children }: { children: React.ReactNode }) { * the Skills learned from their recordings and conversations, each marked Learned. * * Every recording a person makes goes into their own Learning space, and the Skills learned there - * reach every Bot they use. In the team edition they also choose, below the list, who else's Bots may + * reach every Bot they use. In the team edition they also choose, below the lists, who else's Bots may * draw on them: none (the default), all, or the Skills they open one by one. Each change takes effect * when it is made; there is no save. Sharing waits for an administrator (Admin, Automatic learning, * Skill sharing): until then nothing can be opened, and what was opened can still be closed. @@ -134,6 +134,7 @@ export function LearningSharing({ writtenKnown = true, heldAbove = false, action, + afterSkills = null, }: { /** * The page above has already said OpenBot is holding off (a move, or the database out of reach): @@ -146,6 +147,11 @@ export function LearningSharing({ writtenKnown?: boolean; /** The section's one verb: New skill. */ action?: React.ReactNode; + /** + * The page's other lists of skills (Workspace skills), drawn right after Your skills and before + * the sharing choice, so every list is read before the setting about them. + */ + afterSkills?: React.ReactNode; } = {}) { const sharing = useQuery(personalLearningQueryOptions()); const setMode = useMutation( @@ -165,9 +171,9 @@ export function LearningSharing({ )); // Which edition decides the layout, so nothing draws until it is known. A failed read counts as the team edition. - if (capabilities.isPending) return null; + if (capabilities.isPending) return afterSkills; // Nothing to list yet from either read. - if (sharing.isPending && !writtenKnown) return null; + if (sharing.isPending && !writtenKnown) return afterSkills; const personal = capabilities.data?.edition === "personal"; /* * The skills a person wrote don't come from Learning, so they and New skill are drawn whether or @@ -175,14 +181,17 @@ export function LearningSharing({ */ if (sharing.isPending || sharing.error) { return ( - - {sharing.error && !(heldAbove && isHeld(sharing.error)) ? ( -

- {failureSaid(sharing.error)} -

- ) : null} - {written.length > 0 ? {writtenRows} : null} -
+ <> + + {sharing.error && !(heldAbove && isHeld(sharing.error)) ? ( +

+ {failureSaid(sharing.error)} +

+ ) : null} + {written.length > 0 ? {writtenRows} : null} +
+ {afterSkills} + ); } const data = sharing.data; @@ -200,68 +209,71 @@ export function LearningSharing({ const learned = data.skills ?? []; const none = learned.length === 0 && written.length === 0; return ( - - {none ? ( - writtenKnown ? ( - - {data.skills === null - ? emptySentence(data, mode, true) - : "No skills yet. Write one with New skill, or teach a Bot a task."} - - ) : null - ) : ( - - {writtenRows} - {learned.map((skill, index) => ( - - {index > 0 || written.length > 0 ? : null} - setReading(skill.name)} - type="button" - /> - } - > - - - - - - {skillTitle(skill.name, skill.description)} - Learned - - {skill.description} - - - - - - - ))} - - )} - setReading(null)} - source={{ kind: "personal" }} - /> - + <> + + {none ? ( + writtenKnown ? ( + + {data.skills === null + ? emptySentence(data, mode, true) + : "No skills yet. Write one with New skill, or teach a Bot a task."} + + ) : null + ) : ( + + {writtenRows} + {learned.map((skill, index) => ( + + {index > 0 || written.length > 0 ? : null} + setReading(skill.name)} + type="button" + /> + } + > + + + + + + {skillTitle(skill.name, skill.description)} + Learned + + {skill.description} + + + + + + + ))} + + )} + setReading(null)} + source={{ kind: "personal" }} + /> + + {afterSkills} + ); } - // Below the list: it is a choice about the learned skills in it. + // Below the lists: it is a choice about the learned skills in them. const choiceSection = ( + {afterSkills} {choiceSection} {failure ? (

diff --git a/app/src/components/skills/edit-skill.tsx b/app/src/components/skills/edit-skill.tsx deleted file mode 100644 index a52b510902..0000000000 --- a/app/src/components/skills/edit-skill.tsx +++ /dev/null @@ -1,102 +0,0 @@ -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 { loadFailure } from "@/lib/load-failure"; -import { saveSkillMutationOptions } from "@/lib/skills/mutations"; -import { skillListQueryOptions } from "@/lib/skills/queries"; - -/** - * Editing a skill, in the same panel that writes one. - * - * THERE IS NO SEPARATE EDIT, AND NONE IS NEEDED. `replaceSkill` writes under the slug and keeps - * whose the skill is, so a re-save changes the words and never quietly changes its owner. The server - * has already refused anyone editing a skill that is not theirs before it gets that far. - */ -export function EditSkill({ slug }: { slug: string }) { - const queryClient = useQueryClient(); - const navigate = useNavigate(); - const { data, error, isPending } = useQuery(skillListQueryOptions()); - - /* - * Read from the list already on screen rather than fetched again. It is the same request the page - * behind this panel just made, so react-query serves it from cache and the form is filled on the - * first frame instead of flashing empty fields at somebody who came here to change one word. - */ - const skill = data?.find((candidate) => candidate.slug === slug); - - const saveSkill = useMutation(saveSkillMutationOptions(queryClient)); - - /* 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 ( -

-

- {loadFailure( - error, - "Couldn't load this skill. Try again in a moment.", - )} -

-
- ); - } - - if (!skill) { - return ( -
- {/* - * 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. - */} -

- This skill was deleted, or it isn't yours to edit. -

-
- ); - } - - return ( -
-
-

Edit skill

-

- Changes apply the next time someone uses {skill.title}. Bots that have - it keep it. -

-
- - } - onSubmit={async (values) => { - await saveSkill.mutateAsync(values); - await navigate({ search: {}, to: "/skills" }); - }} - slugLocked - submitLabel="Save changes" - /> -
- ); -} diff --git a/app/src/components/skills/proposed-skill.tsx b/app/src/components/skills/proposed-skill.tsx index b5322af394..d85ce43f9f 100644 --- a/app/src/components/skills/proposed-skill.tsx +++ b/app/src/components/skills/proposed-skill.tsx @@ -199,8 +199,8 @@ function PutItOnABot({ slug }: { slug: string }) { return ( Put it on a Bot diff --git a/app/src/components/skills/skill-overview.tsx b/app/src/components/skills/skill-overview.tsx new file mode 100644 index 0000000000..1f7f89bc18 --- /dev/null +++ b/app/src/components/skills/skill-overview.tsx @@ -0,0 +1,137 @@ +import { RESEARCH_ROLES } from "@openbot/shared/research"; +import { useQuery } from "@tanstack/react-query"; +import { PageCard } from "@/components/layout/page-shell"; +import { toolTitle } from "@/components/skills/skill-tools"; +import { appsQueryOptions } from "@/lib/apps/queries"; +import type { Skill } from "@/lib/skills/queries"; + +/** + * The grey line under a skill's name: who made it, and the command that runs it. Only what the API + * gives: a skill has an owner and a slug, and no date it was last changed. + */ +export function skillByline( + skill: Pick, + me: string | undefined, + edition: "team" | "personal", +): string { + const who = + skill.ownerUserId === null + ? edition === "personal" + ? "Written for every Bot" + : "Written by an admin for everyone" + : skill.ownerUserId === me + ? "Written by you" + : "Written by someone in your organization"; + return `${who} · /${skill.slug}`; +} + +type ToolGroup = { title: string; tools: string[] }; + +/** + * The tools a skill names, one entry per app, in the names the tool picker shows. A ref no app here + * offers is named from the ref itself (`acme-wiki/search_pages` is Acme wiki, Search pages) and kept + * apart: it does nothing until that app is connected. + */ +function toolGroups( + refs: string[], + apps: { title: string; tools: { ref: string; name: string }[] }[] | undefined, +): { connected: ToolGroup[]; missing: ToolGroup[] } { + const connected = new Map(); + const missing = new Map(); + const add = (groups: Map, title: string, tool: string) => + groups.set(title, [...(groups.get(title) ?? []), tool]); + for (const ref of refs) { + const research = RESEARCH_ROLES.find((role) => role.ref === ref); + if (research) { + add(connected, "Web research", research.label); + continue; + } + const app = apps?.find((each) => + each.tools.some((tool) => tool.ref === ref), + ); + const tool = app?.tools.find((each) => each.ref === ref); + if (app && tool) { + add(connected, app.title, toolTitle(tool.name)); + continue; + } + const split = ref.indexOf("/"); + add( + missing, + toolTitle(split === -1 ? ref : ref.slice(0, split)), + split === -1 ? "" : toolTitle(ref.slice(split + 1)), + ); + } + const list = (groups: Map) => + [...groups].map(([title, tools]) => ({ + title, + tools: tools.filter(Boolean), + })); + return { connected: list(connected), missing: list(missing) }; +} + +function ToolGroups({ groups }: { groups: ToolGroup[] }) { + return ( +
    + {groups.map((group) => ( +
  • +
    {group.title}
    + {group.tools.length > 0 ? ( +
    + {group.tools.join(", ")} +
    + ) : null} +
  • + ))} +
+ ); +} + +function SkillToolList({ refs }: { refs: string[] }) { + const apps = useQuery({ ...appsQueryOptions(), enabled: refs.length > 0 }); + if (refs.length === 0) { + return

None

; + } + // Until the apps arrive, nothing: an app would flash as not connected and then move. + if (apps.isPending) return null; + const { connected, missing } = toolGroups(refs, apps.data); + return ( + <> + {connected.length > 0 ? : null} + {/* Last: the part that does nothing yet. */} + {missing.length > 0 ? ( + <> +

+ Apps not connected +

+ + + ) : null} + + ); +} + +/** + * A skill read, not edited: the tools it needs, then its instructions as text. The form is one click + * away, behind the host's Edit button. + * + * The tools come first in the markup, so on a narrow window they sit right under the heading. + * From `@2xl` they move into a small box beside the instructions, which keep most of the width. + */ +export function SkillOverview({ skill }: { skill: Skill }) { + return ( +
+
+ +

Tools it needs

+ +
+
+

Instructions

+

+ {skill.instructions} +

+
+
+
+ ); +} diff --git a/app/src/components/skills/skill-tools.tsx b/app/src/components/skills/skill-tools.tsx index f8bc7d32f4..388add610b 100644 --- a/app/src/components/skills/skill-tools.tsx +++ b/app/src/components/skills/skill-tools.tsx @@ -70,7 +70,7 @@ type ToolGroup = { }; /** `create_routine` → "Create routine". The raw name stays on the row's tooltip. */ -function toolTitle(name: string): string { +export function toolTitle(name: string): string { const words = name.replace(/[_-]+/g, " ").trim(); return words ? words[0]?.toUpperCase() + words.slice(1) : name; } diff --git a/app/src/components/skills/skills-settings-page.tsx b/app/src/components/skills/skills-settings-page.tsx index f1db62552a..bc054810ec 100644 --- a/app/src/components/skills/skills-settings-page.tsx +++ b/app/src/components/skills/skills-settings-page.tsx @@ -53,32 +53,25 @@ import { useManagePaths } from "@/lib/manage-paths"; import { removeSkillMutationOptions } from "@/lib/skills/mutations"; import { type Skill, skillListQueryOptions } from "@/lib/skills/queries"; import { queryClient } from "@/query-client"; -import { EditSkill } from "./edit-skill"; import { NewSkill } from "./new-skill"; /** * Skills: the one page, for every Bot, that answers "what does it know how to do?", in the main * menu. It was Capabilities → Skills, Settings → Skills, and Settings → Learning. * - * 1. Your skills: one list of the skills that are yours, each marked with how it was made. Skills - * you wrote open the side panel; in the personal edition the skills written for every Bot open - * their own page with a switch per Bot (`/skills/$slug`); learned ones open their dialog - * and keep the team edition's sharing switches (`LearningSharing`). - * 2. Workspace skills, team edition only: the admin's, read-only. - * 3. Waiting for your review: what OpenBot proposes, with Learn now and automatic approval. - * 4. Teach a Bot: one row to the recording page, where OpenBot can run a browser for you. + * 1. Your skills: one list of the skills that are yours, each marked with how it was made. Every + * skill someone wrote opens its own screen, read first, with Edit for the form + * (`/skills/$slug`); learned ones open their dialog and keep the team edition's sharing switches + * (`LearningSharing`). + * 2. Workspace skills, team edition only: the admin's. Each opens the same screen, with no Edit. + * 3. Who else's Bots use your skills, team edition only: after the lists, so both are read first. + * 4. Waiting for your review: what OpenBot proposes, with Learn now and automatic approval. + * 5. Teach a Bot: one row to the recording page, where OpenBot can run a browser for you. * - * Writing and editing a skill you own is a search parameter, as it was on Capabilities, so the list - * stays behind the panel and the form is linkable and closed by Back. + * Writing a new skill in the team edition is a search parameter, as it was on Capabilities, so the + * list stays behind the panel and the panel is linkable and closed by Back. */ -export function SkillsSettingsPage({ - creating, - editing, -}: { - creating: boolean; - /** The slug being edited, or undefined. */ - editing?: string; -}) { +export function SkillsSettingsPage({ creating }: { creating: boolean }) { const navigate = useNavigate(); const paths = useManagePaths(); const personal = paths.edition === "personal"; @@ -95,9 +88,6 @@ export function SkillsSettingsPage({ onSuccess: () => setError(null), }); - // Creating wins if both are somehow set: it is the more recent intent. - const showCreate = creating; - const showEdit = !showCreate && editing !== undefined; const loaded = !skillList.isPending && !me.isPending; /** Both reads answered, so `written` is the whole truth and an empty list means none. */ const writtenKnown = skillList.data !== undefined && me.data !== undefined; @@ -118,19 +108,26 @@ export function SkillsSettingsPage({ const writtenRow = (skill: Skill) => ( - - - - - - {skill.title} - Written - - {/* What it is for, not its command: the `/` menu finds a skill by its name. */} - {skill.summary ? ( - {skill.summary} - ) : null} - + {/* The row opens the skill's screen; the menu sits beside that link, not inside it. */} + + + + + + + {skill.title} + Written + + {/* What it is for, not its command: the `/` menu finds a skill by its name. */} + {skill.summary ? ( + {skill.summary} + ) : null} + + navigate({ - to: "/skills", - search: { edit: skill.slug }, + to: "/skills/$slug", + params: { slug: skill.slug }, + search: { edit: true }, }) } > @@ -169,6 +167,7 @@ export function SkillsSettingsPage({ + ); @@ -210,17 +209,51 @@ export function SkillsSettingsPage({ ? [...mine.map(writtenRow), ...(personal ? everyBot.map(everyBotRow) : [])] : []; + /* + * No menu on these rows: a workspace skill is the admin's, and the person reading this can't + * edit it, delete it or choose which Bots carry it. Each opens its screen to be read. Hidden + * when there are none. + */ + const workspace = + !personal && everyBot.length > 0 ? ( + + + {everyBot.map((skill, index) => ( + + + } + size="sm" + > + + + + + {skill.title} + {skill.summary ? ( + {skill.summary} + ) : null} + + + + + + {index !== everyBot.length - 1 && } + + ))} + + + ) : null; + return ( - ) : editing ? ( - - ) : null - } + detail={creating ? : null} onClose={() => navigate({ to: "/skills", search: {} })} - open={showCreate || showEdit} + open={creating} > } + afterSkills={workspace} heldAbove={heldAbove} written={written} writtenKnown={writtenKnown} /> - {/* - * No menu on these rows: a workspace skill is the admin's, and the person reading this can't - * edit it, delete it or choose which Bots carry it. Hidden when there are none. - */} - {!personal && everyBot.length > 0 ? ( - - - {everyBot.map((skill, index) => ( - - - - - - - {skill.title} - {skill.summary ? ( - {skill.summary} - ) : null} - - - {index !== everyBot.length - 1 && } - - ))} - - - ) : null} - {/* Only where OpenBot can run a browser for this person. */} diff --git a/app/src/components/vault/vault-page.tsx b/app/src/components/vault/vault-page.tsx index 7a6f5f1f7d..b88bbab9db 100644 --- a/app/src/components/vault/vault-page.tsx +++ b/app/src/components/vault/vault-page.tsx @@ -1,9 +1,11 @@ import { IconPlus } from "@/components/icons"; +import { useQuery } from "@tanstack/react-query"; import { Link } from "@tanstack/react-router"; import { PageSection, PageShell } from "@/components/layout/page-shell"; import { CredentialsList } from "@/components/manage/credentials-page"; import { Button } from "@/components/ui/button"; import { useManagePaths } from "@/lib/manage-paths"; +import { savedLoginsQueryOptions } from "@/lib/passwords/queries"; import { SavedLogins } from "./saved-logins"; /** @@ -17,6 +19,9 @@ import { SavedLogins } from "./saved-logins"; export function VaultPage() { const paths = useManagePaths(); const personal = paths.edition === "personal"; + // The same read the list makes, so the heading counts what the rows show. + const count = useQuery(savedLoginsQueryOptions()).data?.logins.length ?? 0; + const loginsTitle = count > 0 ? `Saved logins (${count})` : "Saved logins"; return ( {/* * The team edition's Vault is its logins alone, one section, so it carries no heading: the - * page title already names it. + * page title already names it. The personal edition's has keys too, so each part is named. */} {personal ? ( diff --git a/app/src/routes/_authed/_app/skills.tsx b/app/src/routes/_authed/_app/skills.tsx index 961b3158df..9f2c6800c1 100644 --- a/app/src/routes/_authed/_app/skills.tsx +++ b/app/src/routes/_authed/_app/skills.tsx @@ -1,4 +1,4 @@ -import { createFileRoute } from "@tanstack/react-router"; +import { createFileRoute, redirect } from "@tanstack/react-router"; import { z } from "zod"; import { SkillsSettingsPage } from "@/components/skills/skills-settings-page"; import { agentListQueryOptions } from "@/lib/agents/queries"; @@ -12,18 +12,31 @@ import { skillListQueryOptions } from "@/lib/skills/queries"; * `SkillsSettingsPage`. A skill proposed in a conversation links here, and so do the old addresses * (`/settings/skills`, `/capabilities/skills`). * - * Writing a skill is a search parameter rather than a route, so the list stays on screen behind the - * panel and the form is linkable, reloadable, and closed by Back. `/skills/new` and `/skills/$slug` - * are the personal edition's pages for a skill written for every Bot. + * Writing a skill in the team edition is a search parameter, so the list stays on screen behind the + * panel and the form is linkable, reloadable, and closed by Back. A skill someone wrote opens on + * its own screen, `/skills/$slug`, in both editions. */ const skillsSearchSchema = z.object({ new: z.boolean().optional(), - /** The slug being edited. Absent means nothing is. */ + /** + * An older address for editing a skill in the panel. It opens the skill's own screen, on its + * form, so links already sent keep working. + */ edit: z.string().optional(), }); export const Route = createFileRoute("/_authed/_app/skills")({ validateSearch: skillsSearchSchema, + beforeLoad: ({ search }) => { + if (search.edit !== undefined) { + throw redirect({ + to: "/skills/$slug", + params: { slug: search.edit }, + search: { edit: true }, + replace: true, + }); + } + }, loader: ({ context }) => loadFirstScreen(context.queryClient, [ skillListQueryOptions(), @@ -36,6 +49,6 @@ export const Route = createFileRoute("/_authed/_app/skills")({ }); function SkillsRoute() { - const { new: creating, edit } = Route.useSearch(); - return ; + const { new: creating } = Route.useSearch(); + return ; } diff --git a/app/src/routes/_authed/_app/skills_.$slug.tsx b/app/src/routes/_authed/_app/skills_.$slug.tsx index 397f305fd0..69c0318251 100644 --- a/app/src/routes/_authed/_app/skills_.$slug.tsx +++ b/app/src/routes/_authed/_app/skills_.$slug.tsx @@ -1,12 +1,16 @@ import { createFileRoute } from "@tanstack/react-router"; +import { z } from "zod"; import { SkillPage } from "@/components/manage/skill-page"; -import { personalOnly } from "@/lib/edition-guard"; -/** The personal edition's page for a skill written for every Bot, with a switch per Bot. */ +/** + * One skill, in both editions: read first, with Edit for the form (`?edit=true`). Skills in the + * main menu opens every skill someone wrote here. + */ export const Route = createFileRoute("/_authed/_app/skills_/$slug")({ - beforeLoad: personalOnly("/skills"), + validateSearch: z.object({ edit: z.boolean().optional() }), component: function SkillRoute() { const { slug } = Route.useParams(); - return ; + const { edit } = Route.useSearch(); + return ; }, }); diff --git a/app/src/routes/_authed/admin/skills_.$slug.tsx b/app/src/routes/_authed/admin/skills_.$slug.tsx index a3a8882c3b..393d396470 100644 --- a/app/src/routes/_authed/admin/skills_.$slug.tsx +++ b/app/src/routes/_authed/admin/skills_.$slug.tsx @@ -1,9 +1,12 @@ import { createFileRoute } from "@tanstack/react-router"; +import { z } from "zod"; import { SkillPage } from "@/components/manage/skill-page"; export const Route = createFileRoute("/_authed/admin/skills_/$slug")({ + validateSearch: z.object({ edit: z.boolean().optional() }), component: function SkillRoute() { const { slug } = Route.useParams(); - return ; + const { edit } = Route.useSearch(); + return ; }, }); diff --git a/app/tests/admin-skills-pages.test.tsx b/app/tests/admin-skills-pages.test.tsx index fc06751d96..b08f25042c 100644 --- a/app/tests/admin-skills-pages.test.tsx +++ b/app/tests/admin-skills-pages.test.tsx @@ -165,7 +165,7 @@ function renderAt(path: string) { path: "/admin/skills/$slug", component: function One() { const { slug } = one.useParams(); - return ; + return ; }, }); const router = createRouter({ diff --git a/app/tests/skill-page-overview.test.tsx b/app/tests/skill-page-overview.test.tsx new file mode 100644 index 0000000000..d57a1714eb --- /dev/null +++ b/app/tests/skill-page-overview.test.tsx @@ -0,0 +1,202 @@ +import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"; +import { GlobalRegistrator } from "@happy-dom/global-registrator"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { + createMemoryHistory, + createRootRoute, + createRoute, + createRouter, + RouterProvider, +} from "@tanstack/react-router"; +import { cleanup, render, waitFor } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { z } from "zod"; +import { SkillPage } from "@/components/manage/skill-page"; +import { appKeys } from "@/lib/apps/queries"; +import { authKeys } from "@/lib/auth/queries"; +import { deploymentKeys } from "@/lib/deployment/queries"; +import { type Skill, skillKeys } from "@/lib/skills/queries"; +import { settleReactWork } from "./settle-react-work"; + +/** + * A skill's own screen, `/skills/$slug`: read first (who wrote it, its one-liner, the tools it + * needs, its instructions as text), with Edit for the form on the same address. + */ + +beforeAll(() => GlobalRegistrator.register()); +afterEach(cleanup); +afterAll(async () => { + await settleReactWork(); + GlobalRegistrator.unregister(); +}); + +const originalFetch = global.fetch; +afterEach(() => { + global.fetch = originalFetch; +}); + +const standup: Skill = { + id: "standup", + slug: "standup", + ownerUserId: "me", + title: "Standup", + summary: "Write today's standup.", + instructions: "Read my calendar.\n\nWrite three short lines.", + grantedTo: [], + tools: ["wiki/search_pages", "acme-crm/find_contact"], + usableOnYourBots: true, +}; + +const workspace: Skill = { + ...standup, + id: "onboarding", + slug: "onboarding", + ownerUserId: null, + title: "Onboarding", + tools: [], +}; + +function draw(path: string, { edition = "team" as "team" | "personal" } = {}) { + /** What the server answers: a save of the skill, and its list again after. */ + const sent: string[] = []; + global.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { + const url = String(input instanceof Request ? input.url : input); + const method = init?.method ?? "GET"; + sent.push(`${method} ${url}`); + if (method === "PUT") { + return Response.json({ + slug: "standup", + title: "Standup", + summary: "Write today's standup.", + instructions: "Read my calendar.", + tools: [], + ownerId: "me", + botIds: [], + usableOnYourBots: true, + }); + } + return Response.json({}, { status: 404 }); + }) as unknown as typeof fetch; + const client = new QueryClient({ + defaultOptions: { queries: { retry: false, staleTime: Infinity } }, + }); + client.setQueryData(deploymentKeys.capabilities(), { + generativeUi: true, + selfHostBanner: false, + localEvaluation: edition === "personal", + edition, + }); + client.setQueryData(authKeys.currentUser(), { + id: "me", + name: "Maya", + email: "maya@example.test", + role: "user", + }); + client.setQueryData(skillKeys.list(), [standup, workspace]); + client.setQueryData(appKeys.list(), [ + { + id: "wiki", + title: "Acme wiki", + tools: [ + { + ref: "wiki/search_pages", + name: "search_pages", + description: "Search the wiki.", + effect: "read", + }, + ], + }, + ]); + const root = createRootRoute(); + const list = createRoute({ + path: "/skills", + getParentRoute: () => root, + component: () => null, + }); + const one = createRoute({ + path: "/skills/$slug", + getParentRoute: () => root, + validateSearch: z.object({ edit: z.boolean().optional() }), + component: function One() { + const { slug } = one.useParams(); + const { edit } = one.useSearch(); + return ; + }, + }); + const history = createMemoryHistory({ initialEntries: ["/skills", path] }); + const router = createRouter({ + routeTree: root.addChildren([list, one]), + history, + }); + const view = render( + + + , + ); + return { view, router, history, sent }; +} + +test("a skill opens read first: its name, who wrote it, its one-liner, tools and instructions", async () => { + const { view } = draw("/skills/standup"); + expect( + await view.findByRole("heading", { level: 1, name: "Standup" }), + ).toBeTruthy(); + expect(view.getByText("Written by you · /standup")).toBeTruthy(); + expect(view.getByText("Write today's standup.")).toBeTruthy(); + expect(view.getByRole("heading", { name: "Tools it needs" })).toBeTruthy(); + // The instructions as text, not in a field. + expect(view.queryByRole("textbox")).toBeNull(); + expect(view.getByText(/Read my calendar\./).textContent).toBe( + "Read my calendar.\n\nWrite three short lines.", + ); + expect(view.getByText("Skills").closest("a")?.getAttribute("href")).toBe( + "/skills", + ); + expect(view.getByText("Edit").closest("a")?.getAttribute("href")).toBe( + "/skills/standup?edit=true", + ); +}); + +test("tools are named by app, and an app not connected is named from the ref, never shown raw", async () => { + const { view } = draw("/skills/standup"); + await view.findByRole("heading", { level: 1, name: "Standup" }); + expect(view.getByText("Acme wiki")).toBeTruthy(); + expect(view.getByText("Search pages")).toBeTruthy(); + expect(view.getByText("Apps not connected")).toBeTruthy(); + expect(view.getByText("Acme crm")).toBeTruthy(); + expect(view.getByText("Find contact")).toBeTruthy(); + expect(view.queryByText(/acme-crm\/find_contact/)).toBeNull(); +}); + +test("a workspace skill is read-only in the team edition: an admin wrote it, so there is no Edit", async () => { + const { view } = draw("/skills/onboarding"); + await view.findByRole("heading", { level: 1, name: "Onboarding" }); + expect( + view.getByText("Written by an admin for everyone · /onboarding"), + ).toBeTruthy(); + expect(view.getByText("None")).toBeTruthy(); + expect(view.queryByText("Edit")).toBeNull(); +}); + +test("Edit opens the form on the same address, and Cancel goes back to the skill", async () => { + const { view } = draw("/skills/standup?edit=true"); + expect( + await view.findByRole("heading", { level: 1, name: "Edit skill" }), + ).toBeTruthy(); + expect(view.getAllByRole("textbox").length).toBeGreaterThan(0); + expect(view.getByText("Cancel").closest("a")?.getAttribute("href")).toBe( + "/skills/standup", + ); +}); + +test("saving goes back to the skill and replaces the form, so Back doesn't open it again", async () => { + const { view, router, history, sent } = draw("/skills/standup?edit=true"); + await view.findByRole("heading", { level: 1, name: "Edit skill" }); + const before = history.length; + await userEvent.click(view.getByText("Save changes")); + await waitFor(() => + expect(router.state.location.href).toBe("/skills/standup"), + ); + expect(sent.some((line) => line.startsWith("PUT "))).toBe(true); + expect(history.length).toBe(before); +}); diff --git a/app/tests/skills-read-failure.test.tsx b/app/tests/skills-read-failure.test.tsx index 72d716c34d..d5dabfbc97 100644 --- a/app/tests/skills-read-failure.test.tsx +++ b/app/tests/skills-read-failure.test.tsx @@ -16,7 +16,7 @@ import { } 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 { SkillPage } from "@/components/manage/skill-page"; import { SkillsSettingsPage } from "@/components/skills/skills-settings-page"; import { learningKeys } from "@/lib/learning/queries"; import { skillKeys } from "@/lib/skills/queries"; @@ -186,13 +186,13 @@ test("a deployment with genuinely no skills still says so on the admin page", as 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, () => ); + const view = renderAlone(client, () => ( + + )); await waitForFailedRead(client); expect( await view.findByText("Couldn't load this skill. Try again in a moment."), ).toBeTruthy(); - expect( - view.queryByText("This skill was deleted, or it isn't yours to edit."), - ).toBeNull(); + expect(view.queryByText("Skill not found")).toBeNull(); }); diff --git a/app/tests/skills-settings-page.test.tsx b/app/tests/skills-settings-page.test.tsx index 7e8681be2a..ed7862acb5 100644 --- a/app/tests/skills-settings-page.test.tsx +++ b/app/tests/skills-settings-page.test.tsx @@ -69,6 +69,7 @@ function draw( learning = true, written = true, learned = [refundOrder] as unknown[], + skills = undefined as Skill[] | undefined, } = {}, ) { global.fetch = (async () => @@ -89,10 +90,13 @@ function draw( role: "user", }); if (written) { - client.setQueryData(skillKeys.list(), [ - skill("weekly-report", "Weekly report", "me"), - skill("onboarding", "Onboarding", null), - ]); + client.setQueryData( + skillKeys.list(), + skills ?? [ + skill("weekly-report", "Weekly report", "me"), + skill("onboarding", "Onboarding", null), + ], + ); } if (learning) { client.setQueryData(learningKeys.personal, { @@ -114,8 +118,13 @@ function draw( getParentRoute: () => root, component: () => , }); + const one = createRoute({ + path: "/skills/$slug", + getParentRoute: () => root, + component: () => null, + }); const router = createRouter({ - routeTree: root.addChildren([page]), + routeTree: root.addChildren([page, one]), history: createMemoryHistory({ initialEntries: ["/skills"] }), }); return render( @@ -250,3 +259,36 @@ test("Capabilities and Learning open Skills and Memory", () => { search: { edit: "weekly-report" }, }); }); + +test("both lists come before the setting about who else's Bots use them", async () => { + const view = draw("team"); + await view.findByRole("heading", { name: "Workspace skills" }); + const headings = view + .getAllByRole("heading", { level: 2 }) + .map((heading) => heading.textContent); + expect(headings.indexOf("Your skills")).toBeLessThan( + headings.indexOf("Workspace skills"), + ); + expect(headings.indexOf("Workspace skills")).toBeLessThan( + headings.indexOf("Who else's Bots use your skills"), + ); +}); + +test("a skill you wrote opens its own screen, and a workspace skill too", async () => { + const view = draw("team"); + await view.findByRole("heading", { name: "Workspace skills" }); + const yours = section(view, "Your skills"); + const written = within(yours).getByText("Weekly report").closest("a"); + expect(written?.getAttribute("href")).toBe("/skills/weekly-report"); + // A chevron, as the learned and workspace rows have. + expect( + written?.parentElement?.querySelector("[data-slot=item-actions] > svg"), + ).toBeTruthy(); + const workspace = section(view, "Workspace skills"); + expect( + within(workspace) + .getByText("Onboarding") + .closest("a") + ?.getAttribute("href"), + ).toBe("/skills/onboarding"); +}); diff --git a/app/tests/team-grants-skill-row.test.tsx b/app/tests/team-grants-skill-row.test.tsx index d18d8e0649..7435cbcdd1 100644 --- a/app/tests/team-grants-skill-row.test.tsx +++ b/app/tests/team-grants-skill-row.test.tsx @@ -131,7 +131,7 @@ function open(edition: "team" | "personal" = "team") { const router = createRouter({ history: createMemoryHistory({ initialEntries: ["/"] }), routeTree: createRootRoute({ - component: () => , + component: () => , }), }); const view = render( diff --git a/app/tests/teams-screens.fixture.tsx b/app/tests/teams-screens.fixture.tsx index 1ba8439bc6..89e2b31a60 100644 --- a/app/tests/teams-screens.fixture.tsx +++ b/app/tests/teams-screens.fixture.tsx @@ -115,9 +115,7 @@ const router = createRouter({ app("/teams", TeamsPage), app("/teams/new", NewTeamPage), app("/teams/$teamId", TeamDetail), - app("/skills", () => ( - - )), + app("/skills", () => ), ]), // A Bot's page is in the app's frame, whose sidebar is not this test's business. createRoute({ diff --git a/app/tests/vault.test.tsx b/app/tests/vault.test.tsx index 63aa4e0012..2cf09cd4b5 100644 --- a/app/tests/vault.test.tsx +++ b/app/tests/vault.test.tsx @@ -32,7 +32,19 @@ afterAll(async () => { GlobalRegistrator.unregister(); }); -function draw(edition: "team" | "personal") { +const LOGIN = { + id: "l1", + origin: "https://example.com", + username: "me@example.com", + createdAt: "2026-11-01T00:00:00Z", + updatedAt: "2026-11-01T00:00:00Z", + lastUsedAt: null, +}; + +function draw( + edition: "team" | "personal", + logins: (typeof LOGIN)[] = [LOGIN], +) { const client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity } }, }); @@ -44,16 +56,7 @@ function draw(edition: "team" | "personal") { }); client.setQueryData(passwordKeys.logins(), { passwordManager: true, - logins: [ - { - id: "l1", - origin: "https://example.com", - username: "me@example.com", - createdAt: "2026-11-01T00:00:00Z", - updatedAt: "2026-11-01T00:00:00Z", - lastUsedAt: null, - }, - ], + logins, }); client.setQueryData(credentialKeys.list(), [ { @@ -85,7 +88,9 @@ describe("the Vault", () => { test("holds saved logins and keys in the personal edition", async () => { const view = draw("personal"); expect(await view.findByRole("heading", { name: "Vault" })).toBeTruthy(); - expect(view.getByRole("heading", { name: "Logins" })).toBeTruthy(); + expect( + view.getByRole("heading", { name: "Saved logins (1)" }), + ).toBeTruthy(); expect(view.getByText("https://example.com")).toBeTruthy(); expect(view.getByRole("heading", { name: "Keys" })).toBeTruthy(); expect(view.getByText("openai")).toBeTruthy(); @@ -112,12 +117,22 @@ describe("the Vault", () => { ).toBeTruthy(); expect(view.queryByText(/logins and keys/)).toBeNull(); // One section: the page title already names it. - expect(view.queryByRole("heading", { name: "Logins" })).toBeNull(); expect(view.getAllByRole("heading").map((h) => h.textContent)).toEqual([ "Vault", ]); }); + test("in the personal edition, the logins heading counts every saved login", async () => { + const view = draw("personal", [ + LOGIN, + { ...LOGIN, id: "l2", origin: "https://github.com" }, + { ...LOGIN, id: "l3", origin: "https://acme.test" }, + ]); + expect( + await view.findByRole("heading", { name: "Saved logins (3)" }), + ).toBeTruthy(); + }); + test("in the personal edition says it keeps logins and keys", async () => { const view = draw("personal"); expect(