Files
PaperClipAI/ui/src/pages/apps/ReviewQueueCard.tsx
T
TonioandClaude Fable 5.2 5ea8c99717 fix(ui): close the Plugins review follow-ups and add the Reviews page (#23005)
## 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>
2026-11-26 02:23:18 +00:00

374 lines
16 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useMemo, useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { ArrowUpRight, Check, Loader2, MoreHorizontal, ShieldQuestion, X } from "lucide-react";
import type { Agent, ToolActionRequestListItem } from "@paperclipai/shared";
import { googleWorkspaceToolTitle, humanizeConnectionDisplayName } from "@paperclipai/shared";
import { useCompany } from "@/context/CompanyContext";
import { useToast } from "@/context/ToastContext";
import { queryKeys } from "@/lib/queryKeys";
import { timeAgo } from "@/lib/timeAgo";
import { issuesApi } from "@/api/issues";
import { IssueThreadInteractionCard } from "@/components/IssueThreadInteractionCard";
import { QueryErrorState, useQueryView } from "@/components/QueryView";
import { toolsApi } from "@/api/tools";
import { Button } from "@/components/ui/button";
import { MarkdownBody } from "@/components/MarkdownBody";
import { describeError } from "@/api/errors";
import { agentsApi } from "@/api/agents";
import { Link } from "@/lib/router";
import { cn } from "@/lib/utils";
import { ANALYTICS_MASK_CLASS } from "@/lib/analytics/privacy";
import { AgentAvatar } from "@/components/AgentAvatar";
import { DecisionCardFooter } from "@/components/DecisionCardFooter";
import { NeedsYouPanel, NeedsYouPanelNote, NeedsYouPanelRow } from "@/components/coordinator/NeedsYouCardKit";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { AppLogo } from "./AppLogo";
/**
* "Ask first" review queue (M1b float / M9 card, PAP-10859).
*
* Renders pending `tool_action_requests` as prosumer cards with three choices:
* • Allow once → approve this single request
* • Always allow → approve + create a trust rule (won't ask again)
* • Decline → reject this request
*
* Pass `connectionId` to scope the queue to a single app (App detail); omit it
* to show every pending request (Needs attention page).
*
* `layout="decisions"` draws each request as a decision card with no section
* heading, for the Reviews page, which carries its own title and count.
*/
export function ReviewQueueCard({
connectionId,
emptyState = "hidden",
heading = "Waiting for your OK",
plain = false,
layout = "queue",
}: {
connectionId?: string;
emptyState?: "hidden" | "reassure";
heading?: string;
plain?: boolean;
layout?: "queue" | "decisions";
}) {
const { selectedCompanyId } = useCompany();
const query = useQuery({
queryKey: queryKeys.tools.actionRequests(selectedCompanyId ?? "__none__", "pending"),
queryFn: () => toolsApi.listActionRequests(selectedCompanyId!, "pending"),
enabled: !!selectedCompanyId,
refetchInterval: 20_000,
});
const view = useQueryView(query);
const items = useMemo(() => {
const all = query.data?.actionRequests ?? [];
return connectionId ? all.filter((item) => item.connectionId === connectionId) : all;
}, [query.data, connectionId]);
const decisions = layout === "decisions";
const agentsQuery = useQuery({
queryKey: queryKeys.agents.list(selectedCompanyId ?? "__none__"),
queryFn: () => agentsApi.list(selectedCompanyId!),
enabled: decisions && !!selectedCompanyId && items.some((item) => item.requestedByAgentId),
});
const agents = useMemo(() => indexAgentsById(agentsQuery.data ?? []), [agentsQuery.data]);
if (!selectedCompanyId) return null;
if (query.isLoading || view.kind === "reconnecting") return null;
if (view.kind === "error") return <QueryErrorState error={query.error} action="load connection reviews" onRetry={view.retry} retrying={view.isFetching} />;
if (items.length === 0) {
if (emptyState === "hidden") return null;
return (
<div className={plain ? "py-5 text-sm text-muted-foreground" : "rounded-xl border border-border bg-card p-5 text-sm text-muted-foreground"}>
Nothing is waiting for your OK right now.
</div>
);
}
if (decisions) {
return (
<ul aria-label="Requests to review" className="flex flex-col gap-3">
{items.map((item) => (
<li key={item.request.id}>
<ReviewRow companyId={selectedCompanyId} item={item} plain={false} decision agent={item.requestedByAgentId ? agents.get(item.requestedByAgentId) ?? null : null} />
</li>
))}
</ul>
);
}
return (
<section className="space-y-3">
<div className="flex items-center gap-2">
<ShieldQuestion className="h-4 w-4 text-muted-foreground" />
<h2 className="text-sm font-bold text-foreground">{heading}</h2>
<span className="inline-flex items-center rounded-full bg-muted px-2 py-0.5 text-xs font-semibold text-muted-foreground">
{items.length}
</span>
</div>
<div className="space-y-3">
{items.map((item) => (
<ReviewRow key={item.request.id} companyId={selectedCompanyId} item={item} plain={plain} />
))}
</div>
</section>
);
}
function ReviewRow({
companyId,
item,
plain,
decision = false,
agent = null,
}: {
companyId: string;
item: ToolActionRequestListItem;
plain: boolean;
decision?: boolean;
agent?: Agent | null;
}) {
const queryClient = useQueryClient();
const { pushToast } = useToast();
const [resolving, setResolving] = useState<null | "allow" | "always" | "decline">(null);
const interactionQuery = useQuery({
queryKey: queryKeys.issues.interactions(item.request.issueId ?? "__none__"),
queryFn: () => issuesApi.listInteractions(item.request.issueId!),
enabled: Boolean(item.request.issueId && item.request.interactionId),
});
const linkedInteraction = interactionQuery.data?.find(row => row.id === item.request.interactionId);
const invalidate = () => {
queryClient.invalidateQueries({ queryKey: queryKeys.tools.actionRequests(companyId, "pending") });
queryClient.invalidateQueries({ queryKey: queryKeys.apps.attention(companyId) });
queryClient.invalidateQueries({ queryKey: queryKeys.tools.trustRules(companyId) });
if (item.request.issueId) queryClient.invalidateQueries({ queryKey: queryKeys.issues.interactions(item.request.issueId) });
};
const allowOnce = useMutation({
mutationFn: () => toolsApi.approveActionRequest(companyId, item.request.id),
onMutate: () => setResolving("allow"),
onSuccess: () => {
pushToast({ title: "Allowed once", body: `${actionLabel(item)} can run this time.`, tone: "success" });
invalidate();
},
onError: (error) => {
invalidate();
failToast(pushToast, error);
},
onSettled: () => setResolving(null),
});
const alwaysAllow = useMutation({
mutationFn: async () => {
return toolsApi.approveActionRequest(companyId, item.request.id, true);
},
onMutate: () => setResolving("always"),
onSuccess: () => {
pushToast({
title: "Always allowed",
body: `${actionLabel(item)} won’t ask again.`,
tone: "success",
});
invalidate();
queryClient.invalidateQueries({ queryKey: queryKeys.tools.trustRules(companyId) });
},
onError: (error) => {
invalidate();
failToast(pushToast, error);
},
onSettled: () => setResolving(null),
});
const decline = useMutation({
mutationFn: () => toolsApi.declineActionRequest(companyId, item.request.id),
onMutate: () => setResolving("decline"),
onSuccess: () => {
pushToast({ title: "Declined", body: `${actionLabel(item)} won’t run.`, tone: "info" });
invalidate();
},
onError: (error) => {
invalidate();
failToast(pushToast, error);
},
onSettled: () => setResolving(null),
});
if (decision && interactionQuery.isLoading) {
return (
<article className="coordinator-decision-card" aria-busy="true">
<p className="text-sm text-muted-foreground">Loading request…</p>
</article>
);
}
if (linkedInteraction) {
const card = <IssueThreadInteractionCard
interaction={linkedInteraction}
presentationVariant={decision ? "coordinator-decision" : "default"}
primaryActionOnRight={decision}
onAcceptInteraction={async (_interaction, _keys, _options, rememberAction) => {
try { await toolsApi.approveActionRequest(companyId, item.request.id, rememberAction); }
finally { invalidate(); }
}}
onRejectInteraction={async (_interaction, reason) => {
try { await toolsApi.declineActionRequest(companyId, item.request.id, reason); }
finally { invalidate(); }
}}
/>;
return decision ? <article className="coordinator-decision-card space-y-3">{card}</article> : card;
}
const busy = resolving !== null;
const preview = item.request.previewMarkdown?.trim();
const canAlwaysAllow = Boolean(item.requestedByAgentId && item.connectionId && !item.request.approvalId);
if (decision) {
const action = actionLabel(item);
const app = item.applicationName ? humanizeConnectionDisplayName(item.applicationName) : null;
const risk = item.riskLevel ? RISK_LABELS[item.riskLevel] : null;
return (
<article className={cn("coordinator-decision-card space-y-3", ANALYTICS_MASK_CLASS)} aria-label={app ? `${action} in ${app}` : action}>
<div className="flex items-center justify-between gap-4">
<span className="min-w-0 truncate text-xs leading-4.5 text-muted-foreground">Approve tool access</span>
<div className="flex shrink-0 items-center gap-3" data-attention-context>
{agent ? (
<span className="inline-flex min-w-0 items-center gap-2 text-xs leading-4.5 text-muted-foreground">
<AgentAvatar agent={agent} size={20} />
<span className="truncate">from {agent.name}</span>
</span>
) : null}
<time className="shrink-0 text-xs leading-4.5 text-muted-foreground" dateTime={new Date(item.request.createdAt).toISOString()}>
{timeAgo(item.request.createdAt)}
</time>
{canAlwaysAllow ? (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button type="button" variant="ghost" size="icon-sm" className="-mr-1.5 size-7 text-muted-foreground" aria-label={`More for ${action}`} disabled={busy}>
<MoreHorizontal aria-hidden />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className={`w-72 ${ANALYTICS_MASK_CLASS}`}>
<DropdownMenuItem className="flex flex-col items-start gap-0.5 py-2" onSelect={() => alwaysAllow.mutate()}>
<span className="text-sm text-foreground">Always allow</span>
<span className="text-xs text-muted-foreground">This agent can run this action on this connection without asking again.</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
) : null}
</div>
</div>
<div className="space-y-1.5">
<h2>{app ? `${action} in ${app}` : action}</h2>
<p className="text-sm text-muted-foreground">
{app ? `${action} is set to Ask first in ${app}, so it waits for your OK.` : "This action is set to Ask first, so it waits for your OK."} Allow once runs it now.
</p>
</div>
<NeedsYouPanel>
{app ? (
<NeedsYouPanelRow
icon={<AppLogo name={app} size={20} compact className="bg-transparent" />}
title={app}
meta={<>{action}{risk ? <> · <span className={cn(risk.danger && "text-destructive")}>{risk.label}</span></> : null}</>}
/>
) : null}
{preview ? <div className="text-sm"><MarkdownBody>{preview}</MarkdownBody></div> : null}
{agent ? <NeedsYouPanelNote>Requested by {agent.name}.</NeedsYouPanelNote> : null}
</NeedsYouPanel>
<DecisionCardFooter
leading={item.request.issueId ? (
<Link to={`/issues/${item.request.issueId}`} className="flex max-w-full min-w-0 items-center gap-1.5 text-(length:--text-compact) leading-5 text-muted-foreground hover:text-foreground">
<span className="min-w-0 truncate">{agent ? `Open task · Chat with ${agent.name}` : "Open task"}</span>
<ArrowUpRight className="size-4 shrink-0" aria-hidden />
</Link>
) : undefined}
>
<Button type="button" variant="ghost" onClick={() => decline.mutate()} disabled={busy}>
{resolving === "decline" ? <Loader2 className="animate-spin" aria-hidden /> : null}
Decline
</Button>
<Button type="button" onClick={() => allowOnce.mutate()} disabled={busy}>
{resolving === "allow" || resolving === "always" ? <Loader2 className="animate-spin" aria-hidden /> : null}
Allow once
</Button>
</DecisionCardFooter>
</article>
);
}
return (
<div className={plain ? "py-3" : "rounded-xl border border-border bg-card p-4"}>
<div className="flex flex-wrap items-baseline gap-x-2 gap-y-1 text-sm">
<span className="font-bold text-foreground">{actionLabel(item)}</span>
{item.applicationName && (
<span className="text-muted-foreground">
in {humanizeConnectionDisplayName(item.applicationName)}
</span>
)}
<span className="text-xs text-muted-foreground">· asked {timeAgo(item.request.createdAt)}</span>
</div>
{preview ? (
<div className="mt-2 rounded-lg border border-border bg-background px-3 py-2 text-sm">
<MarkdownBody>{preview}</MarkdownBody>
</div>
) : (
<p className="mt-1 text-sm text-muted-foreground">
An agent wants to run this action. Your connection policy requires approval first.
</p>
)}
{item.requestedByAgentId && item.connectionId && !item.request.approvalId ? <p className="mt-2 text-xs text-muted-foreground">Always allow lets this agent use this action with different arguments on this connection, within the current project when present.</p> : null}
<div className="mt-3 flex flex-wrap items-center gap-2">
<Button size="sm" onClick={() => allowOnce.mutate()} disabled={busy}>
{resolving === "allow" ? <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" /> : <Check className="mr-1.5 h-3.5 w-3.5" />}
Allow once
</Button>
{item.requestedByAgentId && item.connectionId && !item.request.approvalId ? <Button size="sm" variant="outline" onClick={() => alwaysAllow.mutate()} disabled={busy}>
{resolving === "always" ? <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" /> : null}
Always allow
</Button> : null}
<Button size="sm" variant="ghost" onClick={() => decline.mutate()} disabled={busy}>
{resolving === "decline" ? <Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" /> : <X className="mr-1.5 h-3.5 w-3.5" />}
Decline
</Button>
</div>
</div>
);
}
const RISK_LABELS: Record<NonNullable<ToolActionRequestListItem["riskLevel"]>, { label: string; danger: boolean }> = {
low: { label: "Low risk", danger: false },
medium: { label: "Medium risk", danger: false },
high: { label: "High risk", danger: true },
critical: { label: "Critical risk", danger: true },
read: { label: "Reads data", danger: false },
write: { label: "Changes data", danger: false },
destructive: { label: "Destructive", danger: true },
};
export function indexAgentsById<T extends { id: string }>(agents: readonly T[]): Map<string, T> {
const byId = new Map<string, T>();
for (const agent of agents) byId.set(agent.id, agent);
return byId;
}
function actionLabel(item: ToolActionRequestListItem): string {
if (!item.toolTitle && !item.toolName) return "This action";
return humanizeConnectionDisplayName(item.toolName ?? "", { title: googleWorkspaceToolTitle(item.toolName ?? "", item.toolTitle) });
}
function failToast(
pushToast: ReturnType<typeof useToast>["pushToast"],
error: unknown,
) {
pushToast({
title: "Couldn’t save that",
body: describeError(error).body,
tone: "error",
});
}