mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-28 12:04:41 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Much of the work means moving an opaque value somewhere else: an
agent id, a callback URL, a webhook secret, an error payload for a bug
report
> - Copy buttons all over the app do that, and most already say whether
it worked — an icon that flips to a check, a label that reads "Copied"
> - Eleven did not. They passed the promise to `.catch(() => {})` and
showed nothing at all
> - A copy that says nothing looks exactly like a copy the browser
refused, and the only way to tell is to paste somewhere and look
> - The clipboard really does refuse: over plain HTTP on a non-secure
host the async Clipboard API is unavailable, and the fallback can still
fail
> - This pull request gives every copy action an affordance, through two
shared hooks
> - The benefit is that a person can tell a copy from a failure without
leaving the page
## Linked Issues or Issue Description
**What happened?**
Eleven copy buttons gave no feedback. They called `copyTextToClipboard`
and discarded the result:
```
onClick={() => void copyTextToClipboard(robotEmail).catch(() => {})}
```
Nothing changes on screen, whether the write succeeded or failed. This
is the same surface where most other copy buttons do show a check or a
"Copied" label, so the silent ones read as broken.
**Expected behavior**
Every copy action says whether the clipboard took the value. A rejected
write says so rather than staying silent or claiming success.
**Steps to reproduce**
1. Open the connector setup flow for an app that shows a sharing email
or a callback URL.
2. Press **Copy** next to that value.
3. Before this change nothing on screen changes. Compare with the copy
button on a login panel, which flips to a check.
4. To see the failure case, open Paperclip over plain HTTP on a
non-localhost host, where the async Clipboard API is not available.
**Paperclip version or commit**
`45586170e` on `master`.
**Deployment mode**
Local.
**Agent adapter(s) involved**
Not adapter-specific (core bug).
**Additional context**
Commit `1fa36be35` moved every copy through `lib/clipboard.ts`, so the
call sites are findable. Of 62 call sites, 51 already showed feedback
and 11 did not.
## What Changed
- New `ui/src/lib/use-copy-action.ts` with two hooks:
- `useCopyAction` for a control that stays on screen. It returns
`copied` and `failed` for the inline swap the rest of the app already
uses, and resets itself.
- `useCopyToast` for a menu item, which unmounts with its menu before an
inline state could be read, so its confirmation goes to the toast
viewport.
- Both wait for the write to resolve before reporting success, and both
report a rejection as a failure. `AdapterLoginChrome.test.tsx` already
held that line for one button; the helper now makes it the default.
- The eleven silent sites now use one of the two: the connector setup
flow's sharing-email and callback-URL buttons, the runner inspector's
copy-value and copy-path buttons, the agent bubble and skill studio menu
items, annotation "Copy link" on both its hosts, both secret-error
detail buttons, the chat webhook secret, and the motion tweak panel's
export box.
- The chat webhook secret follows its own file's convention: a label
that reads "Webhook secret copied", matching the manifest buttons beside
it.
- The 51 sites that already had feedback are untouched. Converting them
would be a large diff with no visible change.
- `clipboard-usage.test.ts` gains a static check, sibling to the one
that already keeps copies on the shared helper. It fails if a new copy
site ships with no affordance.
## Verification
- `npx vitest run ui/src/lib/use-copy-action.test.tsx
ui/src/lib/clipboard-usage.test.ts ui/src/lib/clipboard.test.ts
ui/src/components/AdapterLoginChrome.test.tsx` — 18 tests pass.
- The new hook tests cover the three cases that matter: no confirmation
while the write is still in flight, a failure state on a rejected write,
and a return to rest after the reset delay. The toast hook is covered
for both tones.
- `npx vitest run ui/src/pages/apps/AppsConnect.test.tsx
ui/src/components/task-chat ui/src/components/RunnerInspector.test.tsx
ui/src/components/DocumentAnnotation` — the suites over the touched
components pass.
- `npx tsc -b ui` — clean.
## Risks
Low. Each change is additive at its own call site and the copy path
itself is unchanged. The static check is the only part that touches
future contributors: it is one assertion, and its pattern list is easy
to extend or drop.
## Model Used
Claude Opus 5 (`claude-opus-5`), 1M context, extended thinking, with
tool use and code execution.
## 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)
- [x] 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
- [x] 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
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
394 lines
13 KiB
TypeScript
394 lines
13 KiB
TypeScript
import { useEffect, useState, type ReactNode } from "react";
|
||
import type {
|
||
FeedbackDataSharingPreference,
|
||
FeedbackVoteValue,
|
||
} from "@paperclipai/shared";
|
||
import { cn, formatShortDate } from "../lib/utils";
|
||
import { timeAgo } from "../lib/timeAgo";
|
||
import { useCopyAction, useCopyToast } from "../lib/use-copy-action";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||
import { Textarea } from "@/components/ui/textarea";
|
||
import {
|
||
Dialog,
|
||
DialogContent,
|
||
DialogDescription,
|
||
DialogFooter,
|
||
DialogHeader,
|
||
DialogTitle,
|
||
} from "@/components/ui/dialog";
|
||
import {
|
||
DropdownMenu,
|
||
DropdownMenuContent,
|
||
DropdownMenuItem,
|
||
DropdownMenuTrigger,
|
||
} from "@/components/ui/dropdown-menu";
|
||
import { Check, Copy, MoreHorizontal, ThumbsDown, ThumbsUp, X } from "lucide-react";
|
||
|
||
const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
|
||
|
||
/**
|
||
* Short relative timestamp for an agent bubble — "2h ago" within a week, then
|
||
* an absolute short date. Mirrors the task thread's `commentDateLabel` so both
|
||
* surfaces read identically.
|
||
*/
|
||
export function agentBubbleDateLabel(date: Date | string | undefined): string {
|
||
if (!date) return "";
|
||
const then = new Date(date).getTime();
|
||
if (Date.now() - then < WEEK_MS) return timeAgo(date);
|
||
return formatShortDate(date);
|
||
}
|
||
|
||
/**
|
||
* Copy-to-clipboard icon button shared by every agent-bubble footer — the
|
||
* conference-room {@link AgentBubbleActionRow} and the redesigned task thread's
|
||
* {@link TaskChatBubbleActions} (PAP-413). Single-sourced so both footers keep
|
||
* identical sizing, radius, and the "copied ✓" feedback affordance rather than
|
||
* re-declaring the same button markup on each surface.
|
||
*/
|
||
export function BubbleCopyButton({ copyText }: { copyText: string }) {
|
||
const { copied, failed, copy } = useCopyAction(2000);
|
||
const label = failed ? "Couldn’t copy message" : "Copy message";
|
||
|
||
return (
|
||
<button
|
||
type="button"
|
||
className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||
title={label}
|
||
aria-label={label}
|
||
onClick={() => {
|
||
void copy(copyText);
|
||
}}
|
||
>
|
||
{copied ? (
|
||
<Check className="h-3.5 w-3.5" />
|
||
) : failed ? (
|
||
<X className="h-3.5 w-3.5 text-destructive" />
|
||
) : (
|
||
<Copy className="h-3.5 w-3.5" />
|
||
)}
|
||
</button>
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Shared agent-bubble action row — copy · 👍 · 👎 · timestamp · ⋯ menu.
|
||
*
|
||
* Rendered below every agent bubble so the task thread (`IssueChatThread`) and
|
||
* the conference room (`BoardChat`) speak the same bubble language (PAP-95 /
|
||
* PAP-105). Each surface supplies its own copy text, timestamp label, optional
|
||
* feedback-vote wiring, and any extra overflow-menu items (e.g. stop-run /
|
||
* view-run on the task side).
|
||
*/
|
||
export function AgentBubbleActionRow({
|
||
copyText,
|
||
dateLabel,
|
||
dateTitle,
|
||
anchorHref,
|
||
feedback,
|
||
menuItems,
|
||
className,
|
||
}: {
|
||
copyText: string;
|
||
/** Short relative label shown inline (e.g. "2h ago"). */
|
||
dateLabel?: string;
|
||
/** Full datetime shown in the hover tooltip. */
|
||
dateTitle?: string;
|
||
/** Anchor href for the timestamp link (deep-link to the comment). */
|
||
anchorHref?: string;
|
||
/** When provided, renders the 👍/👎 feedback buttons wired to this vote API. */
|
||
feedback?: {
|
||
activeVote: FeedbackVoteValue | null;
|
||
sharingPreference: FeedbackDataSharingPreference;
|
||
termsUrl: string | null;
|
||
onVote: (
|
||
vote: FeedbackVoteValue,
|
||
options?: { allowSharing?: boolean; reason?: string },
|
||
) => Promise<void>;
|
||
} | null;
|
||
/** Extra DropdownMenuItem nodes appended after the default "Copy message". */
|
||
menuItems?: ReactNode;
|
||
className?: string;
|
||
}) {
|
||
// The menu closes on click, so its copy confirmation has to outlive it.
|
||
const copyWithToast = useCopyToast();
|
||
return (
|
||
<div className={cn("mt-2 flex items-center gap-1", className)}>
|
||
<BubbleCopyButton copyText={copyText} />
|
||
{feedback ? (
|
||
<IssueChatFeedbackButtons
|
||
activeVote={feedback.activeVote}
|
||
sharingPreference={feedback.sharingPreference}
|
||
termsUrl={feedback.termsUrl}
|
||
onVote={feedback.onVote}
|
||
/>
|
||
) : null}
|
||
{dateLabel ? (
|
||
<Tooltip>
|
||
<TooltipTrigger asChild>
|
||
<a
|
||
href={anchorHref}
|
||
className="text-(length:--text-micro) text-muted-foreground hover:text-foreground hover:underline"
|
||
>
|
||
{dateLabel}
|
||
</a>
|
||
</TooltipTrigger>
|
||
<TooltipContent side="bottom" className="text-xs">
|
||
{dateTitle}
|
||
</TooltipContent>
|
||
</Tooltip>
|
||
) : null}
|
||
<DropdownMenu>
|
||
<DropdownMenuTrigger asChild>
|
||
<Button
|
||
variant="ghost"
|
||
size="icon-xs"
|
||
className="text-muted-foreground hover:text-foreground"
|
||
title="More actions"
|
||
aria-label="More actions"
|
||
>
|
||
<MoreHorizontal className="h-3.5 w-3.5" />
|
||
</Button>
|
||
</DropdownMenuTrigger>
|
||
<DropdownMenuContent align="end">
|
||
<DropdownMenuItem
|
||
onClick={() => {
|
||
void copyWithToast(copyText, "Message copied");
|
||
}}
|
||
>
|
||
<Copy className="mr-2 h-3.5 w-3.5" />
|
||
Copy message
|
||
</DropdownMenuItem>
|
||
{menuItems}
|
||
</DropdownMenuContent>
|
||
</DropdownMenu>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/**
|
||
* 👍/👎 feedback buttons with downvote-reason popover and a sharing-preference
|
||
* prompt. Self-contained (no IssueChatCtx) so it is reused by both the task
|
||
* thread and the conference room via {@link AgentBubbleActionRow}.
|
||
*/
|
||
export function IssueChatFeedbackButtons({
|
||
activeVote,
|
||
sharingPreference = "prompt",
|
||
termsUrl,
|
||
onVote,
|
||
}: {
|
||
activeVote: FeedbackVoteValue | null;
|
||
sharingPreference: FeedbackDataSharingPreference;
|
||
termsUrl: string | null;
|
||
onVote: (vote: FeedbackVoteValue, options?: { allowSharing?: boolean; reason?: string }) => Promise<void>;
|
||
}) {
|
||
const [isSaving, setIsSaving] = useState(false);
|
||
const [optimisticVote, setOptimisticVote] = useState<FeedbackVoteValue | null>(null);
|
||
const [reasonOpen, setReasonOpen] = useState(false);
|
||
const [downvoteReason, setDownvoteReason] = useState("");
|
||
const [pendingSharingDialog, setPendingSharingDialog] = useState<{
|
||
vote: FeedbackVoteValue;
|
||
reason?: string;
|
||
} | null>(null);
|
||
const visibleVote = optimisticVote ?? activeVote ?? null;
|
||
|
||
useEffect(() => {
|
||
if (optimisticVote && activeVote === optimisticVote) setOptimisticVote(null);
|
||
}, [activeVote, optimisticVote]);
|
||
|
||
async function doVote(
|
||
vote: FeedbackVoteValue,
|
||
options?: { allowSharing?: boolean; reason?: string },
|
||
) {
|
||
setIsSaving(true);
|
||
try {
|
||
await onVote(vote, options);
|
||
} catch {
|
||
setOptimisticVote(null);
|
||
} finally {
|
||
setIsSaving(false);
|
||
}
|
||
}
|
||
|
||
function handleVote(vote: FeedbackVoteValue, reason?: string) {
|
||
setOptimisticVote(vote);
|
||
if (sharingPreference === "prompt") {
|
||
setPendingSharingDialog({ vote, ...(reason ? { reason } : {}) });
|
||
return;
|
||
}
|
||
const allowSharing = sharingPreference === "allowed";
|
||
void doVote(vote, {
|
||
...(allowSharing ? { allowSharing: true } : {}),
|
||
...(reason ? { reason } : {}),
|
||
});
|
||
}
|
||
|
||
function handleThumbsUp() {
|
||
handleVote("up");
|
||
}
|
||
|
||
function handleThumbsDown() {
|
||
setOptimisticVote("down");
|
||
setReasonOpen(true);
|
||
// Submit the initial down vote right away
|
||
handleVote("down");
|
||
}
|
||
|
||
function handleSubmitReason() {
|
||
if (!downvoteReason.trim()) return;
|
||
// Re-submit with reason attached
|
||
if (sharingPreference === "prompt") {
|
||
setPendingSharingDialog({ vote: "down", reason: downvoteReason });
|
||
} else {
|
||
const allowSharing = sharingPreference === "allowed";
|
||
void doVote("down", {
|
||
...(allowSharing ? { allowSharing: true } : {}),
|
||
reason: downvoteReason,
|
||
});
|
||
}
|
||
setReasonOpen(false);
|
||
setDownvoteReason("");
|
||
}
|
||
|
||
return (
|
||
<>
|
||
<button
|
||
type="button"
|
||
disabled={isSaving}
|
||
className={cn(
|
||
"inline-flex h-7 w-7 items-center justify-center rounded-md transition-colors",
|
||
visibleVote === "up"
|
||
? "text-green-600 dark:text-green-400"
|
||
: "text-muted-foreground hover:bg-accent hover:text-foreground",
|
||
)}
|
||
title="Helpful"
|
||
aria-label="Helpful"
|
||
onClick={handleThumbsUp}
|
||
>
|
||
<ThumbsUp className="h-3.5 w-3.5" />
|
||
</button>
|
||
<Popover open={reasonOpen} onOpenChange={setReasonOpen}>
|
||
<PopoverTrigger asChild>
|
||
<button
|
||
type="button"
|
||
disabled={isSaving}
|
||
className={cn(
|
||
"inline-flex h-7 w-7 items-center justify-center rounded-md transition-colors",
|
||
visibleVote === "down"
|
||
? "text-amber-600 dark:text-amber-400"
|
||
: "text-muted-foreground hover:bg-accent hover:text-foreground",
|
||
)}
|
||
title="Needs work"
|
||
aria-label="Needs work"
|
||
onClick={handleThumbsDown}
|
||
>
|
||
<ThumbsDown className="h-3.5 w-3.5" />
|
||
</button>
|
||
</PopoverTrigger>
|
||
<PopoverContent side="top" align="start" className="w-80 p-3">
|
||
<div className="mb-2 text-sm font-medium">What could have been better?</div>
|
||
<Textarea
|
||
value={downvoteReason}
|
||
onChange={(event) => setDownvoteReason(event.target.value)}
|
||
placeholder="Add a short note"
|
||
className="min-h-20 resize-y bg-background text-sm"
|
||
disabled={isSaving}
|
||
/>
|
||
<div className="mt-2 flex items-center justify-end gap-2">
|
||
<Button
|
||
type="button"
|
||
size="sm"
|
||
variant="outline"
|
||
disabled={isSaving}
|
||
onClick={() => {
|
||
setReasonOpen(false);
|
||
setDownvoteReason("");
|
||
}}
|
||
>
|
||
Dismiss
|
||
</Button>
|
||
<Button
|
||
type="button"
|
||
size="sm"
|
||
disabled={isSaving || !downvoteReason.trim()}
|
||
onClick={handleSubmitReason}
|
||
>
|
||
{isSaving ? "Saving..." : "Save note"}
|
||
</Button>
|
||
</div>
|
||
</PopoverContent>
|
||
</Popover>
|
||
|
||
<Dialog
|
||
open={Boolean(pendingSharingDialog)}
|
||
onOpenChange={(open) => {
|
||
if (!open && !isSaving) {
|
||
setPendingSharingDialog(null);
|
||
setOptimisticVote(null);
|
||
}
|
||
}}
|
||
>
|
||
<DialogContent>
|
||
<DialogHeader>
|
||
<DialogTitle>Save your feedback sharing preference</DialogTitle>
|
||
<DialogDescription>
|
||
Choose whether voted AI outputs can be shared with Paperclip Labs. This
|
||
answer becomes the default for future thumbs up and thumbs down votes.
|
||
</DialogDescription>
|
||
</DialogHeader>
|
||
<div className="space-y-3 text-sm text-muted-foreground">
|
||
<p>This vote is always saved locally.</p>
|
||
<p>
|
||
Choose <span className="font-medium text-foreground">Always allow</span> to share
|
||
this vote and future voted AI outputs. Choose{" "}
|
||
<span className="font-medium text-foreground">Don't allow</span> to keep this vote
|
||
and future votes local.
|
||
</p>
|
||
<p>You can change this later in Settings > General.</p>
|
||
{termsUrl ? (
|
||
<a
|
||
href={termsUrl}
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
className="inline-flex text-sm text-foreground underline underline-offset-4"
|
||
>
|
||
Read our terms of service
|
||
</a>
|
||
) : null}
|
||
</div>
|
||
<DialogFooter>
|
||
<Button
|
||
type="button"
|
||
variant="outline"
|
||
disabled={!pendingSharingDialog || isSaving}
|
||
onClick={() => {
|
||
if (!pendingSharingDialog) return;
|
||
void doVote(
|
||
pendingSharingDialog.vote,
|
||
pendingSharingDialog.reason ? { reason: pendingSharingDialog.reason } : undefined,
|
||
).then(() => setPendingSharingDialog(null));
|
||
}}
|
||
>
|
||
{isSaving ? "Saving..." : "Don't allow"}
|
||
</Button>
|
||
<Button
|
||
type="button"
|
||
disabled={!pendingSharingDialog || isSaving}
|
||
onClick={() => {
|
||
if (!pendingSharingDialog) return;
|
||
void doVote(pendingSharingDialog.vote, {
|
||
allowSharing: true,
|
||
...(pendingSharingDialog.reason ? { reason: pendingSharingDialog.reason } : {}),
|
||
}).then(() => setPendingSharingDialog(null));
|
||
}}
|
||
>
|
||
{isSaving ? "Saving..." : "Always allow"}
|
||
</Button>
|
||
</DialogFooter>
|
||
</DialogContent>
|
||
</Dialog>
|
||
</>
|
||
);
|
||
}
|