Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.6 KB
Raw Blame
import { useCallback, useState } from 'react';
import { useCopyToClipboard } from 'react-use';
import { Button } from '@signozhq/ui/button';
import { Tooltip } from '@signozhq/ui/tooltip';
import { Check, Copy } from '@signozhq/icons';

import logEvent from 'api/common/logEvent';

import { AIAssistantEvents } from '../../events';
import { Message } from '../../types';

import styles from './UserMessageActions.module.scss';

interface UserMessageActionsProps {
	message: Message;
}

/**
 * Action row rendered under user message bubbles. Mirrors the assistant
 * feedback strip's hover-reveal treatment via the bubble's
 * `--feedback-opacity` CSS variable; intentionally minimal for now —
 * additional actions (edit, share, …) can slot in alongside the copy chip.
 */
export default function UserMessageActions({
	message,
}: UserMessageActionsProps): JSX.Element {
	const [copied, setCopied] = useState(false);
	const [, copyToClipboard] = useCopyToClipboard();

	const handleCopy = useCallback((): void => {
		void logEvent(AIAssistantEvents.MessageCopied, {
			role: message.role,
			messageId: message.id,
			hadToolCalls: false,
		});
		copyToClipboard(message.content);
		setCopied(true);
		setTimeout(() => setCopied(false), 1500);
	}, [copyToClipboard, message.content, message.id, message.role]);

	return (
		<div className={styles.actions}>
			<Tooltip title={copied ? 'Copied!' : 'Copy'}>
				<Button
					size="sm"
					icon
					variant="ghost"
					color="secondary"
					onClick={handleCopy}
					aria-label={copied ? 'Copied' : 'Copy message'}
				>
					{copied ? <Check size={12} /> : <Copy size={12} />}
				</Button>
			</Tooltip>
		</div>
	);
}