Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(agent): add copy button to assistant messages in AI agent chat (closes #371) (#374)

Maqbool Ahmed5625386898da
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/agent/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/agent/page.tsx
index dc6419505..3d47f5eac 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/agent/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/agent/page.tsx
@@ -18,7 +18,10 @@ import { Link } from '@/i18n/navigation';
import { Button, buttonVariants } from '@/components/ui/button';
import { Markdown } from '@/components/ui/markdown';
import { cn } from '@/lib/utils';
+import { toast } from 'sonner';
import {
+ Check,
+ Copy,
Plus,
Send,
Sparkles,
@@ -390,8 +393,22 @@ function AgentChat(props: {
function MessageBubble({ message }: { message: UIMessage }) {
const isUser = message.role === 'user';
+ const [copied, setCopied] = useState(false);
+
+ const rawText = (message.parts ?? [])
+ .filter((p) => p.type === 'text')
+ .map((p) => (p as { type: 'text'; text: string }).text)
+ .join('\n\n');
+
+ async function handleCopy() {
+ await navigator.clipboard.writeText(rawText).catch(() => {});
+ setCopied(true);
+ toast.success('Copied');
+ setTimeout(() => setCopied(false), 2000);
+ }
+
return (
- <div className={cn('flex gap-3', isUser ? 'justify-end' : 'justify-start')}>
+ <div className={cn('group flex gap-3', isUser ? 'justify-end' : 'justify-start')}>
{!isUser && (
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary">
<Sparkles className="h-4 w-4" />
@@ -399,7 +416,7 @@ function MessageBubble({ message }: { message: UIMessage }) {
)}
<div
className={cn(
- 'max-w-[80%] rounded-2xl px-4 py-3 text-sm',
+ 'relative max-w-[80%] rounded-2xl px-4 py-3 text-sm',
isUser ? 'bg-primary text-primary-foreground' : 'bg-card border',
)}
>
@@ -434,6 +451,16 @@ function MessageBubble({ message }: { message: UIMessage }) {
}
return null;
})}
+ {!isUser && rawText && (
+ <button
+ type="button"
+ onClick={() => void handleCopy()}
+ aria-label={copied ? 'Copied' : 'Copy message'}
+ className="absolute bottom-2 right-2 p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-foreground transition-opacity"
+ >
+ {copied ? <Check className="h-3.5 w-3.5" /> : <Copy className="h-3.5 w-3.5" />}
+ </button>
+ )}
</div>
</div>
);