mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
Manage Connect account access with agent profile chips (#23598)
## Thinking Path > - Paperclip connects provider accounts to agents. > - The account dialog summarizes agent access. > - Initials alone make selected agents hard to identify. > - Agent Overview already shows agent names and avatars together. > - Reuse those chips and let people edit the selection in place. ## Linked Issues or Issue Description Related PR #23576. **What happened?** The credential summary showed overlapping badges and required opening Change to edit the selected agents. **Expected behavior** Show each selected agent by name. Offer a searchable add control and a remove control on each editable agent chip. **Steps to reproduce** Open Connect account, choose Antigravity under Other Models, and inspect credential access. ## What Changed Reuse profile chips and the agent picker. Keep the draft selection in sync with the expanded access editor. ## Verification All 36 focused credential selection and provider sign-in tests passed. ## Risks A large explicit selection wraps across multiple rows. Organization-wide agent access uses one summary chip. ## Model Used OpenAI GPT-6, via Codex. ## Checklist - [ ] I have included a thinking path that traces from project context to this change - [ ] 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 - [ ] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [ ] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [ ] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [ ] I have run tests locally and they pass - [ ] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [ ] 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
This commit is contained in:
1 parent
3b380c6b15
commit
432ca25efa
6 files changed
+111
-45
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { AgentAvatar, type AvatarAgent } from "@/components/AgentAvatar";
|
||||
import { useEffect, useMemo, useState, type ComponentProps, type ReactNode } from "react";
|
||||
import { ChevronRight } from "lucide-react";
|
||||
import { ChevronRight, Plus } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -23,6 +23,7 @@ export function AgentSelect({
|
||||
emptyMessage = "No agents yet.",
|
||||
disabled = false,
|
||||
triggerClassName,
|
||||
addChip = false,
|
||||
id,
|
||||
}: {
|
||||
agents: AgentMultiSelectOption[];
|
||||
@@ -32,6 +33,7 @@ export function AgentSelect({
|
||||
emptyMessage?: string;
|
||||
disabled?: boolean;
|
||||
triggerClassName?: string;
|
||||
addChip?: boolean;
|
||||
id?: string;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -61,16 +63,20 @@ export function AgentSelect({
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className={cn("w-full justify-between", triggerClassName)}
|
||||
aria-label={addChip ? "Add agent" : undefined}
|
||||
title={addChip ? "Add agent" : undefined}
|
||||
disabled={disabled}
|
||||
>
|
||||
{addChip ? <Plus className="size-3.5" aria-hidden /> : <>
|
||||
<span className={cn("flex min-w-0 items-center gap-2", !selectedAgent && "text-muted-foreground")}>
|
||||
{selectedAgent && <AgentAvatar agent={selectedAgent} size={20} />}
|
||||
<span className="truncate">{selectedAgent?.name ?? placeholder}</span>
|
||||
</span>
|
||||
<ChevronRight className="h-4 w-4 shrink-0 text-muted-foreground" />
|
||||
</>}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-(--radix-popover-trigger-width) p-0" align="start">
|
||||
<PopoverContent className={cn(addChip ? "w-64" : "w-(--radix-popover-trigger-width)", "p-0")} align="start">
|
||||
<div className="border-b border-border p-3">
|
||||
<Input
|
||||
value={filter}
|
||||
@@ -92,6 +98,7 @@ export function AgentSelect({
|
||||
aria-label={`Select ${agent.name}`}
|
||||
onClick={() => {
|
||||
onChange(agent.id);
|
||||
setFilter("");
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { Agent } from "@paperclipai/shared";
|
||||
import { AgentAvatar } from "@/components/AgentAvatar";
|
||||
import { AgentAvatar, type AvatarAgent } from "@/components/AgentAvatar";
|
||||
|
||||
export const agentIdentityChipClass = "agent-identity-chip inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-md px-2 py-1 text-xs";
|
||||
|
||||
export function AgentIdentityChipContent({ agent }: { agent: Agent }) {
|
||||
export function AgentIdentityChipContent({ agent }: { agent: AvatarAgent & { name: string } }) {
|
||||
return <><AgentAvatar agent={agent} size={20} /><span className="truncate">{agent.name}</span></>;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// @vitest-environment jsdom
|
||||
import { useState } from "react";
|
||||
import { flushSync } from "react-dom";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { ConnectionAccessDefaults } from "./ConnectionSetupFlow";
|
||||
|
||||
const agents = ["Alpha", "Beta", "Gamma"].map(name => ({ id: name, name }));
|
||||
const host = document.createElement("div");
|
||||
let root: ReturnType<typeof createRoot>;
|
||||
|
||||
function Access({ disabled = false }) {
|
||||
const [ids, setIds] = useState(new Set(["Alpha"]));
|
||||
return <ConnectionAccessDefaults flat companyId="test" agents={agents} disabled={disabled}
|
||||
sentence="Connects as you" authKind="api_key" grantKind="user" setGrantKind={() => {}}
|
||||
installChoice="specific" setInstallChoice={() => {}} installAgentIds={ids} setInstallAgentIds={setIds} />;
|
||||
}
|
||||
|
||||
function render(disabled = false) {
|
||||
document.body.append(host);
|
||||
root = createRoot(host);
|
||||
flushSync(() => root.render(<Access disabled={disabled} />));
|
||||
}
|
||||
|
||||
function button(label: string) {
|
||||
const result = [...document.querySelectorAll("button")].find(el =>
|
||||
(el.getAttribute("aria-label") ?? el.textContent?.trim()) === label);
|
||||
if (!result) throw new Error(`Missing button: ${label}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
function click(label: string) {
|
||||
flushSync(() => button(label).click());
|
||||
}
|
||||
|
||||
afterEach(() => { flushSync(() => root.unmount()); host.remove(); });
|
||||
|
||||
it("clears the search after adding and shares chip edits with the expanded picker", () => {
|
||||
render();
|
||||
click("Add agent");
|
||||
const search = document.querySelector<HTMLInputElement>('input[placeholder="Filter agents"]')!;
|
||||
flushSync(() => {
|
||||
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(search, "Beta");
|
||||
search.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
});
|
||||
click("Select Beta");
|
||||
click("Add agent");
|
||||
expect(document.querySelector<HTMLInputElement>('input[placeholder="Filter agents"]')?.value).toBe("");
|
||||
click("Select Gamma");
|
||||
click("Remove Alpha");
|
||||
click("Change");
|
||||
expect(button("2 agents selected")).toBeTruthy();
|
||||
click("Remove Beta");
|
||||
expect(button("1 agent selected")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("disables adding and hides removal when editing is disabled", () => {
|
||||
render(true);
|
||||
expect(host.querySelector('[aria-label="Add agent"]')).toBeNull();
|
||||
expect(host.querySelector('[aria-label="Remove Alpha"]')).toBeNull();
|
||||
});
|
||||
@@ -46,6 +46,7 @@ import {
|
||||
Search,
|
||||
UserRound,
|
||||
UsersRound,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import type {
|
||||
AppDefinition,
|
||||
@@ -93,9 +94,9 @@ import { toolsApi } from "@/api/tools";
|
||||
import { agentsApi } from "@/api/agents";
|
||||
import { appCopyFor, credentialFieldLabel } from "@/lib/app-gallery-copy";
|
||||
import { JsonSchemaForm, validateJsonSchemaForm, type JsonSchemaNode } from "@/components/JsonSchemaForm";
|
||||
import { credentialAccessBadges } from "./credential-access-badges";
|
||||
import { Avatar, AvatarFallback, AvatarGroup, AvatarGroupCount } from "@/components/ui/avatar";
|
||||
import { AgentMultiSelect, type AgentMultiSelectOption } from "@/components/AgentMultiSelect";
|
||||
import { partitionCredentialAgents } from "./credential-access-badges";
|
||||
import { AgentIdentityChipContent, agentIdentityChipClass } from "@/components/agents/AgentIdentityChip";
|
||||
import { AgentMultiSelect, AgentSelect, type AgentMultiSelectOption } from "@/components/AgentMultiSelect";
|
||||
import { describeError, errorStatus } from "@/api/errors";
|
||||
import { InlineBanner } from "@/components/InlineBanner";
|
||||
import { useQueryView } from "@/components/QueryView";
|
||||
@@ -4687,10 +4688,11 @@ export function ConnectionAccessDefaults({
|
||||
const [open, setOpen] = useState(false);
|
||||
const expanded = open || forceOpen;
|
||||
const { installChoice, installAgentIds } = accessProps;
|
||||
const { visible, remaining } = useMemo(
|
||||
() => credentialAccessBadges(flat ? agents ?? [] : [], installAgentIds, installChoice === "all"),
|
||||
const { selected, available } = useMemo(
|
||||
() => partitionCredentialAgents(flat && installChoice === "specific" ? agents ?? [] : [], installAgentIds),
|
||||
[flat, agents, installAgentIds, installChoice],
|
||||
);
|
||||
const editable = !disabled && !accessProps.lockedAgentId && !accessProps.preserveAgentAccess && accessProps.grantKind !== "agent";
|
||||
const ownerLabel = accessProps.grantKind === "organization" ? "Organization" : "You";
|
||||
|
||||
return (
|
||||
@@ -4698,21 +4700,24 @@ export function ConnectionAccessDefaults({
|
||||
<div className={cn("flex flex-wrap justify-between gap-x-3 gap-y-1", flat ? "items-center" : "items-baseline")}>
|
||||
<div className="grid gap-2">
|
||||
<p className={cn("text-muted-foreground", flat ? "text-xs" : "text-sm")}>{sentence}</p>
|
||||
{flat && <AvatarGroup aria-label="Credential access">
|
||||
<Avatar title={ownerLabel} aria-label={ownerLabel} role="img">
|
||||
<AvatarFallback className="bg-linear-to-b from-accent to-secondary text-foreground">
|
||||
{accessProps.grantKind === "organization" ? <UsersRound className="size-4" /> : <UserRound className="size-4" />}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
{visible.map((agent, index) => (
|
||||
<Avatar key={agent.id} title={agent.name} aria-label={agent.name} role="img">
|
||||
<AvatarFallback className={cn("bg-linear-to-b from-background/60 text-foreground", [
|
||||
"bg-(--status-task-icon-done)/50", "bg-(--status-task-icon-todo)/50", "bg-(--status-task-icon-in_review)/50", "bg-(--status-task-icon-in_progress)/50",
|
||||
][index])}>{Array.from(agent.name.trim())[0]?.toLocaleUpperCase()}</AvatarFallback>
|
||||
</Avatar>
|
||||
))}
|
||||
{remaining > 0 && <AvatarGroupCount aria-label={`${remaining} more agents`}>+{remaining}</AvatarGroupCount>}
|
||||
</AvatarGroup>}
|
||||
{flat && <div className="flex flex-wrap items-center gap-1.5" role="group" aria-label="Credential access">
|
||||
<span className={agentIdentityChipClass}>
|
||||
{accessProps.grantKind === "organization" ? <UsersRound className="size-4" /> : <UserRound className="size-4" />}
|
||||
{ownerLabel}
|
||||
</span>
|
||||
{installChoice === "all" && <span className={agentIdentityChipClass}><Bot className="size-4" />Any agent</span>}
|
||||
{selected.map(agent => <span key={agent.id} className={agentIdentityChipClass}>
|
||||
<AgentIdentityChipContent agent={agent} />
|
||||
{editable && <button type="button" aria-label={`Remove ${agent.name}`} className="shrink-0 rounded-sm p-0.5 text-muted-foreground hover:text-foreground" onClick={() => {
|
||||
const next = new Set(installAgentIds);
|
||||
next.delete(agent.id);
|
||||
accessProps.setInstallAgentIds(next);
|
||||
}}><X className="size-3" /></button>}
|
||||
</span>)}
|
||||
{editable && installChoice === "specific" && <AgentSelect addChip agents={available} value="" disabled={!available.length}
|
||||
triggerClassName="size-7 justify-center rounded-md border-dashed bg-transparent p-0 text-muted-foreground"
|
||||
onChange={id => accessProps.setInstallAgentIds(new Set(installAgentIds).add(id))} />}
|
||||
</div>}
|
||||
</div>
|
||||
<CollapsibleTrigger asChild><Button
|
||||
type="button"
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { credentialAccessBadges } from "./credential-access-badges";
|
||||
import { partitionCredentialAgents } from "./credential-access-badges";
|
||||
|
||||
it("limits the visible badges and stops scanning once the first four matches are found", () => {
|
||||
it("shows every selected agent and offers only unselected agents in one pass", () => {
|
||||
const agents = Array.from({ length: 500 }, (_, i) => ({ id: String(i) }));
|
||||
const selected = new Set(["4", "10", "100", "200", "400"]);
|
||||
const lookups = vi.spyOn(selected, "has");
|
||||
expect(credentialAccessBadges(agents, selected, true)).toEqual({ visible: agents.slice(0, 4), remaining: 496 });
|
||||
expect(lookups).not.toHaveBeenCalled();
|
||||
expect(credentialAccessBadges(agents, selected, false)).toEqual({
|
||||
visible: [agents[4], agents[10], agents[100], agents[200]], remaining: 1,
|
||||
});
|
||||
expect(lookups).toHaveBeenCalledTimes(201);
|
||||
const ids = new Set(["4", "10", "100", "200", "400"]);
|
||||
const lookups = vi.spyOn(ids, "has");
|
||||
const { selected, available } = partitionCredentialAgents(agents, ids);
|
||||
expect(lookups).toHaveBeenCalledTimes(agents.length);
|
||||
expect(selected.map(agent => agent.id)).toEqual([...ids]);
|
||||
expect(available).toEqual(agents.filter(agent => !ids.has(agent.id)));
|
||||
});
|
||||
@@ -1,13 +1,9 @@
|
||||
export function credentialAccessBadges<T extends { id: string }>(
|
||||
agents: readonly T[],
|
||||
selected: ReadonlySet<string>,
|
||||
allAgents: boolean,
|
||||
) {
|
||||
const count = allAgents ? agents.length : selected.size;
|
||||
const visible: T[] = [];
|
||||
export function partitionCredentialAgents<T extends { id: string }>(agents: readonly T[], selectedIds: ReadonlySet<string>) {
|
||||
const selected: T[] = [];
|
||||
const available: T[] = [];
|
||||
for (const agent of agents) {
|
||||
if (visible.length === Math.min(4, count)) break;
|
||||
if (allAgents || selected.has(agent.id)) visible.push(agent);
|
||||
if (selectedIds.has(agent.id)) selected.push(agent);
|
||||
else available.push(agent);
|
||||
}
|
||||
return { visible, remaining: count - visible.length };
|
||||
return { selected, available };
|
||||
}
|
||||
Reference in new issue
Block a user