mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 09:39:53 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The Plugins page is where a person connects tools to agents and approves the actions that those tools request > - #22869 turned Connectors into a Plugins marketplace. Three review findings stayed open after the merge > - The page also did not show clearly which account needs attention, and the Reviews page was a plain queue > - A person must see what waits for a decision and must be able to leave a setup step > - This pull request fixes the three findings, adds a review chip and a Reviews page with decision cards, marks the account rows that need attention, and adds a Close button to the chat connection purpose step > - The benefit is a Plugins page that shows pending work, and permission controls that do not accept changes on stale data ## Linked Issues or Issue Description Refs #22869 **What existing behavior does this improve?** The Plugins marketplace pages under `ui/src/pages/apps`: the plugin page, the header, the Reviews page, and the chat connection setup. **Subsystem affected** UI, Plugins (Apps catalog) pages. **Current behavior** - After a failed refresh of the permissions, the menus stay enabled and work on stale data. - The plugin page shows a different category from Browse for Composio and Arcade apps. - Browse classifies each plugin one time for each category on each render. - A chat connection that needs attention shows only text in its row. - The header shows a count only. The Reviews page shows a plain queue. - The "Choose how to connect" step has no control to leave the flow. **Proposed behavior** - After a failed refresh, the actions stay visible, the menus are disabled, and a status line offers "Try again". - The plugin page uses the same category as Browse. - Browse classifies each plugin one time for each render. - A chat connection row that needs attention shows a small warning glyph with a text alternative. - The header shows the logos of the plugins with pending requests (maximum four), an "N to review" chip, and a chevron. It opens the Reviews page. - The Reviews page shows a back button, a title, a count sentence, and one decision card for each request with "Decline" and "Allow once". - The "Choose how to connect" step has a Close button that returns to Plugins. **Reason and benefit** A person sees what waits for a decision and where. Permission changes do not run on stale data. The render cost of Browse does not grow with the number of categories. **Breaking changes** None. The default layout of the review queue on the app detail page does not change. ## What Changed - `plugin-categories.ts`: add `groupPluginsByCategory`, a single pass that classifies each row one time. `Browse.tsx` uses it. - `Browse.tsx`: the plugin page reads its category label from the same function as Browse. Chat connection rows show a warning glyph when `chatEndpointAttention` returns a reason. - `PluginPermissions.tsx`: `staleReads` finds the reads with an error. The menus are disabled while a read is stale, and a status line with "Try again" refetches the stale queries. - `useReviewCount.ts`: add `useReviewQueue`, which returns the count and the application names from the same query. - `PluginsHeader.tsx`: the review button shows stacked plugin logos, the count chip, and a chevron. - `AppsReview.tsx` and `ReviewQueueCard.tsx`: the Reviews page has a header and a `decisions` layout that reuses the coordinator decision card parts. - `ChatEndpointSetup.tsx`: `ChatConnectionPurpose` accepts `onClose` and shows a Close button. - `Browse.tsx`, `PluginMarketplace.tsx`, `AssistantConnection.tsx`: the Installed tab shows the same tiles as the rest of the page. The account rows stay on the plugin page. Assistant Connection (MCP) has a tile of its own. - `ReviewQueueCard.tsx` (review fixes): linked requests use the compact decision presentation of the interaction card, the fallback card is masked as a whole, and the agents list is indexed by id one time. - Specs: `connection-reviews` reads the "Deny" label. `agentmail`, `ai-connections-app`, and `runner-e2e/connection-flow` open the plugin page from an Installed tile. ## Verification These checks ran on the change before the rebase onto current master. The rebase did not touch `ui/src/pages/apps`. - `cd ui && pnpm typecheck`: pass. - `cd ui && npx vitest run src/pages/apps src/features/connections src/lib/analytics`: 539 tests pass. - `pnpm run check:token-gates`: pass. - `node scripts/check-query-error-rendering.mjs`: 0 findings. - Playwright specs `connection-reviews`, `plugins-browse`, and `one-click-connect`: 7 tests pass. - Manual check in a browser with four sample requests: the header chip and the Reviews page render the logos, the count, and the cards. - After the Installed tiles change: 478 unit tests in `src/pages/apps`, `src/lib/analytics`, and the deep-link routing test pass. The `agentmail`, `plugins-browse`, and `one-click-connect` Playwright specs pass. A manual check in a browser shows the tiles on the Installed tab. Not run or not seen: - The full UI Vitest suite and the Storybook build did not run locally. CI supplies that coverage. - The Close button and the row warning glyph were not seen in a browser. Unit tests cover them. - The decision card layout has no unit test of its own. - The stale-permissions state is tested through the `staleReads` helper only. - The edits to `tests/ai-connections-app/app.spec.ts` and `tests/runner-e2e/connection-flow.ts` did not run locally. ## Risks Low risk. The change is UI only, with no schema or API change. - The decision cards say "Decline", and the "Always allow" action is in a menu. This differs from the design exploration, because the product has no snooze and requests carry no written summary. - The review chip counts pending requests only. It does not count accounts that need attention. - The Installed tab no longer lists account rows. A person opens the plugin page to manage an account or to set a default model account. The "Manage connectors" link on an agent opens the Installed tab. - On an instance without the assistant connection route, the Assistant Connection tile shows the attention mark. ## Model Used Claude Fable 5.2 (`claude-fable-5-2`) in Claude Code, with tool use, code execution, and extended thinking. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [ ] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
270 lines
13 KiB
TypeScript
270 lines
13 KiB
TypeScript
import { useId, useMemo, useState } from "react";
|
||
import { useQuery } from "@tanstack/react-query";
|
||
import { ChevronDown, ChevronRight } from "lucide-react";
|
||
import type { ToolCatalogEntry, ToolConnection } from "@paperclipai/shared";
|
||
import { toolsApi } from "@/api/tools";
|
||
import { describeError } from "@/api/errors";
|
||
import { QueryErrorState } from "@/components/QueryView";
|
||
import { Button } from "@/components/ui/button";
|
||
import {
|
||
DropdownMenu,
|
||
DropdownMenuContent,
|
||
DropdownMenuRadioGroup,
|
||
DropdownMenuRadioItem,
|
||
DropdownMenuTrigger,
|
||
} from "@/components/ui/dropdown-menu";
|
||
import { installStateFrom } from "@/lib/tool-installs";
|
||
import { queryKeys } from "@/lib/queryKeys";
|
||
import { ANALYTICS_MASK_CLASS } from "@/lib/analytics/privacy";
|
||
import { cn } from "@/lib/utils";
|
||
import { actionLabel, actionPermissionMutation } from "./app-detail/action-permissions";
|
||
import { accessFrom, askFirstCatalogIds, enabledCatalogIds } from "./app-detail/saved-permissions";
|
||
import { useConnectionPermissionSave } from "./app-detail/useConnectionPermissionSave";
|
||
|
||
export type ActionPolicy = "allowed" | "ask" | "off";
|
||
|
||
const POLICY_ORDER: ActionPolicy[] = ["allowed", "ask", "off"];
|
||
const POLICY_LABEL: Record<ActionPolicy, string> = { allowed: "Allowed", ask: "Ask first", off: "Off" };
|
||
const TONE: Record<ActionPolicy | "custom", string> = {
|
||
allowed: "text-foreground",
|
||
ask: "text-(--status-task-icon-todo)",
|
||
off: "text-muted-foreground",
|
||
custom: "text-foreground",
|
||
};
|
||
|
||
/** The policy an action has today: off unless enabled, and Ask first only while enabled. */
|
||
export function actionPolicy(id: string, enabledIds: ReadonlySet<string>, askFirstIds: ReadonlySet<string>): ActionPolicy {
|
||
if (!enabledIds.has(id)) return "off";
|
||
return askFirstIds.has(id) ? "ask" : "allowed";
|
||
}
|
||
|
||
/** One policy when every action in the group shares it, otherwise "custom". */
|
||
export function groupPolicy(ids: readonly string[], enabledIds: ReadonlySet<string>, askFirstIds: ReadonlySet<string>): ActionPolicy | "custom" {
|
||
const first = actionPolicy(ids[0], enabledIds, askFirstIds);
|
||
return ids.every((id) => actionPolicy(id, enabledIds, askFirstIds) === first) ? first : "custom";
|
||
}
|
||
|
||
function PolicyMenu({ value, label, disabled, onChange }: { value: ActionPolicy | "custom"; label: string; disabled: boolean; onChange: (next: ActionPolicy) => void }) {
|
||
const text = value === "custom" ? "Custom" : POLICY_LABEL[value];
|
||
if (disabled) return <span className={cn("shrink-0 text-sm", TONE[value])}>{text}</span>;
|
||
return (
|
||
<DropdownMenu>
|
||
<DropdownMenuTrigger asChild>
|
||
<Button type="button" variant="ghost" size="sm" className={cn("-mr-2 h-8 shrink-0", TONE[value])} aria-label={`${label}: ${text}`}>
|
||
{text}
|
||
<ChevronDown className="text-muted-foreground" aria-hidden />
|
||
</Button>
|
||
</DropdownMenuTrigger>
|
||
<DropdownMenuContent align="end" className={cn("w-40", ANALYTICS_MASK_CLASS)}>
|
||
<DropdownMenuRadioGroup value={value} onValueChange={(next) => onChange(next as ActionPolicy)}>
|
||
{POLICY_ORDER.map((policy) => (
|
||
<DropdownMenuRadioItem key={policy} value={policy}>
|
||
{POLICY_LABEL[policy]}
|
||
</DropdownMenuRadioItem>
|
||
))}
|
||
</DropdownMenuRadioGroup>
|
||
</DropdownMenuContent>
|
||
</DropdownMenu>
|
||
);
|
||
}
|
||
|
||
function ActionBlock({
|
||
title,
|
||
entries,
|
||
enabledIds,
|
||
askFirstIds,
|
||
disabled,
|
||
onChange,
|
||
}: {
|
||
title: string;
|
||
entries: ToolCatalogEntry[];
|
||
enabledIds: ReadonlySet<string>;
|
||
askFirstIds: ReadonlySet<string>;
|
||
disabled: boolean;
|
||
onChange: (ids: string[], next: ActionPolicy) => void;
|
||
}) {
|
||
const [open, setOpen] = useState(false);
|
||
const region = useId();
|
||
const ids = entries.map((entry) => entry.id);
|
||
const Chevron = open ? ChevronDown : ChevronRight;
|
||
return (
|
||
<div className="flex flex-col rounded-2xl bg-muted/50">
|
||
<div className="flex h-12 items-center justify-between gap-4 px-4">
|
||
<button
|
||
type="button"
|
||
aria-expanded={open}
|
||
aria-controls={region}
|
||
onClick={() => setOpen((current) => !current)}
|
||
className="-ml-1 flex h-8 items-center gap-2 rounded-md pr-2 pl-1 text-sm font-semibold text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||
>
|
||
<Chevron className="size-4 text-muted-foreground" aria-hidden />
|
||
{title}
|
||
<span className="font-normal text-muted-foreground tabular-nums">{entries.length}</span>
|
||
</button>
|
||
<PolicyMenu value={groupPolicy(ids, enabledIds, askFirstIds)} label={`All ${title.toLowerCase()}`} disabled={disabled} onChange={(next) => onChange(ids, next)} />
|
||
</div>
|
||
<ul id={region} hidden={!open} className="flex flex-col pb-2">
|
||
{entries.map((entry) => {
|
||
const label = actionLabel(entry);
|
||
return (
|
||
<li key={entry.id} className="flex min-h-10 items-center justify-between gap-4 pr-4 pl-11">
|
||
<span className="flex min-w-0 items-baseline gap-2.5">
|
||
<span className="truncate text-sm text-foreground">{label}</span>
|
||
{label === entry.toolName ? null : <span className="truncate font-mono text-xs text-muted-foreground">{entry.toolName}</span>}
|
||
</span>
|
||
<PolicyMenu value={actionPolicy(entry.id, enabledIds, askFirstIds)} label={label} disabled={disabled} onChange={(next) => onChange([entry.id], next)} />
|
||
</li>
|
||
);
|
||
})}
|
||
</ul>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const NOTE = "rounded-2xl bg-muted/50 px-4 py-3 text-sm text-muted-foreground";
|
||
|
||
function ConnectionPermissions({ companyId, connection }: { companyId: string; connection: ToolConnection }) {
|
||
const connectionId = connection.id;
|
||
const [saveError, setSaveError] = useState<string | null>(null);
|
||
const catalogQuery = useQuery({ queryKey: queryKeys.tools.catalog(connectionId), queryFn: () => toolsApi.listCatalog(connectionId) });
|
||
const profilesQuery = useQuery({
|
||
queryKey: queryKeys.tools.connectionProfileConfiguration(companyId, connectionId),
|
||
queryFn: ({ signal }) => toolsApi.listConnectionProfileConfiguration(connectionId, { signal, fresh: true }),
|
||
});
|
||
const policiesQuery = useQuery({
|
||
queryKey: queryKeys.tools.policies(companyId),
|
||
queryFn: ({ signal }) => toolsApi.listPolicies(companyId, { signal, fresh: true }),
|
||
});
|
||
const installsQuery = useQuery({
|
||
queryKey: queryKeys.tools.connectionInstalls(connectionId),
|
||
queryFn: ({ signal }) => toolsApi.getConnectionInstalls(connectionId, { signal, fresh: true }),
|
||
});
|
||
const grantsQuery = useQuery({
|
||
queryKey: queryKeys.tools.connectionGrants(connectionId),
|
||
queryFn: ({ signal }) => toolsApi.listConnectionGrants(connectionId, { signal }),
|
||
});
|
||
const { draft, pending, save } = useConnectionPermissionSave({
|
||
companyId,
|
||
connectionId,
|
||
connection,
|
||
catalog: catalogQuery.data?.catalog ?? [],
|
||
onError: (error) => setSaveError(describeError(error).body),
|
||
});
|
||
|
||
const { reads, writes } = useMemo(() => {
|
||
const byName = (left: ToolCatalogEntry, right: ToolCatalogEntry) => actionLabel(left).localeCompare(actionLabel(right));
|
||
const active = (catalogQuery.data?.catalog ?? []).filter((entry) => entry.status === "active");
|
||
return { reads: active.filter((entry) => entry.isReadOnly).sort(byName), writes: active.filter((entry) => !entry.isReadOnly).sort(byName) };
|
||
}, [catalogQuery.data]);
|
||
const profile = useMemo(() => (profilesQuery.data?.profiles ?? []).find((entry) => entry.profileKey === `app:${connectionId}`), [profilesQuery.data, connectionId]);
|
||
const savedEnabled = useMemo(() => enabledCatalogIds(profile), [profile]);
|
||
const savedAskFirst = useMemo(() => askFirstCatalogIds(policiesQuery.data?.policies ?? [], connectionId), [policiesQuery.data, connectionId]);
|
||
const savedAccess = useMemo(() => accessFrom(profile, installStateFrom(installsQuery.data?.installs ?? connection.installs)), [profile, installsQuery.data, connection.installs]);
|
||
const enabledIds = draft?.enabled ?? savedEnabled;
|
||
const askFirstIds = draft?.askFirst ?? savedAskFirst;
|
||
|
||
// A failed read only blocks the section while it has nothing to show; a failed
|
||
// background refresh keeps the loaded actions on screen.
|
||
const queries = [catalogQuery, profilesQuery, policiesQuery, installsQuery, grantsQuery];
|
||
const unloaded = queries.filter((query) => query.error != null && query.data === undefined);
|
||
if (unloaded.length > 0) {
|
||
return (
|
||
<QueryErrorState
|
||
error={unloaded[0].error}
|
||
action="load this account’s actions"
|
||
onRetry={() => unloaded.forEach((query) => void query.refetch())}
|
||
retrying={unloaded.some((query) => query.isFetching)}
|
||
/>
|
||
);
|
||
}
|
||
const loaded = queries.every((query) => query.data !== undefined);
|
||
if (!loaded) return <p className={NOTE}>Loading actions…</p>;
|
||
if (reads.length + writes.length === 0) return <p className={NOTE}>This account hasn’t listed any actions yet.</p>;
|
||
|
||
// After a failed refresh the values on screen may be out of date, and a save replaces what is stored,
|
||
// so changes wait until every read succeeds again.
|
||
const stale = staleReads(queries);
|
||
const canConfigure = grantsQuery.data?.capabilities?.canConfigure === true && stale.length === 0;
|
||
const change = (ids: string[], next: ActionPolicy) => {
|
||
setSaveError(null);
|
||
save({ ...actionPermissionMutation(ids, next, enabledIds, askFirstIds), access: savedAccess });
|
||
};
|
||
return (
|
||
<>
|
||
{reads.length > 0 ? <ActionBlock title="Reads" entries={reads} enabledIds={enabledIds} askFirstIds={askFirstIds} disabled={!canConfigure || pending} onChange={change} /> : null}
|
||
{writes.length > 0 ? <ActionBlock title="Writes" entries={writes} enabledIds={enabledIds} askFirstIds={askFirstIds} disabled={!canConfigure || pending} onChange={change} /> : null}
|
||
{stale.length > 0 ? (
|
||
<p role="status" className="flex flex-wrap items-center gap-x-2 px-4 text-sm text-muted-foreground">
|
||
Couldn’t refresh these permissions, so changes are paused.
|
||
<Button type="button" variant="link" size="sm" className="h-auto p-0" disabled={stale.some((query) => query.isFetching)} onClick={() => stale.forEach((query) => void query.refetch())}>
|
||
Try again
|
||
</Button>
|
||
</p>
|
||
) : null}
|
||
{saveError ? (
|
||
<p role="alert" className="px-4 text-sm text-destructive">
|
||
Couldn’t save that. {saveError}
|
||
</p>
|
||
) : null}
|
||
</>
|
||
);
|
||
}
|
||
|
||
/** The reads whose last attempt failed: what they loaded earlier may no longer match what is saved. */
|
||
export function staleReads<T extends { error: unknown }>(reads: readonly T[]): T[] {
|
||
return reads.filter((read) => read.error != null);
|
||
}
|
||
|
||
/** Tool permissions for a connected plugin: one block for what it reads and one for what it changes, per account. */
|
||
export function PluginPermissions({
|
||
companyId,
|
||
connections,
|
||
accountName,
|
||
onNavigate,
|
||
}: {
|
||
companyId: string;
|
||
connections: readonly ToolConnection[];
|
||
accountName: (connection: ToolConnection) => string;
|
||
onNavigate: (href: string) => void;
|
||
}) {
|
||
const tools = connections.filter((connection) => connection.connectionPurpose !== "ai");
|
||
const [selectedId, setSelectedId] = useState<string | null>(null);
|
||
const selected = tools.find((connection) => connection.id === selectedId) ?? tools[0];
|
||
if (!selected) return null;
|
||
return (
|
||
<section aria-labelledby="plugin-permissions-title" className="flex flex-col gap-2">
|
||
<div className="flex min-h-8 items-center justify-between gap-4 px-4">
|
||
<h2 id="plugin-permissions-title" className="text-sm text-muted-foreground">
|
||
Tool permissions
|
||
</h2>
|
||
{tools.length > 1 ? (
|
||
<DropdownMenu>
|
||
<DropdownMenuTrigger asChild>
|
||
<Button type="button" variant="ghost" size="sm" className="-mr-2 h-8 max-w-64 text-muted-foreground" aria-label={`Account: ${accountName(selected)}`}>
|
||
<span className="truncate">{accountName(selected)}</span>
|
||
<ChevronDown aria-hidden />
|
||
</Button>
|
||
</DropdownMenuTrigger>
|
||
<DropdownMenuContent align="end" className={ANALYTICS_MASK_CLASS}>
|
||
<DropdownMenuRadioGroup value={selected.id} onValueChange={setSelectedId}>
|
||
{tools.map((connection) => (
|
||
<DropdownMenuRadioItem key={connection.id} value={connection.id}>
|
||
{accountName(connection)}
|
||
</DropdownMenuRadioItem>
|
||
))}
|
||
</DropdownMenuRadioGroup>
|
||
</DropdownMenuContent>
|
||
</DropdownMenu>
|
||
) : null}
|
||
</div>
|
||
<ConnectionPermissions key={selected.id} companyId={companyId} connection={selected} />
|
||
<p className="px-4 text-xs text-muted-foreground">
|
||
Ask first sends the action to Review before it runs.{" "}
|
||
<button type="button" className="underline underline-offset-2 hover:text-foreground" onClick={() => onNavigate(`/apps/${selected.id}/permissions`)}>
|
||
Agent access and more settings
|
||
</button>
|
||
</p>
|
||
</section>
|
||
);
|
||
}
|