Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(share): handle missing share target in message button

Steven Enamakel13fc06a1eb2b
diff --git a/app/src/features/share/ShareMessageButton.test.tsx b/app/src/features/share/ShareMessageButton.test.tsx
new file mode 100644
index 0000000000..3725865d85
--- /dev/null
+++ b/app/src/features/share/ShareMessageButton.test.tsx
@@ -0,0 +1,37 @@
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { describe, expect, test, vi } from 'vitest';
+
+import { ShareMessageButton } from './ShareMessageButton';
+
+vi.mock('./ShareCardModal', () => ({
+ ShareCardModal: ({ onClose }: { onClose: () => void }) => (
+ <div data-testid="share-modal">
+ <button onClick={onClose}>close</button>
+ </div>
+ ),
+}));
+
+describe('ShareMessageButton', () => {
+ test('renders nothing when there is no shareable content', () => {
+ const { container } = render(<ShareMessageButton content=" " agentName="Tiny" />);
+ expect(container.firstChild).toBeNull();
+ });
+
+ test('renders a share trigger for agent content', () => {
+ render(<ShareMessageButton content="Did the thing" agentName="Tiny" />);
+ expect(screen.getByTestId('chat-message-share')).toBeInTheDocument();
+ expect(screen.queryByTestId('share-modal')).not.toBeInTheDocument();
+ });
+
+ test('opens and closes the share modal', async () => {
+ const user = userEvent.setup();
+ render(<ShareMessageButton content="Did the thing" agentName="Tiny" threadId="t1" />);
+
+ await user.click(screen.getByTestId('chat-message-share'));
+ expect(screen.getByTestId('share-modal')).toBeInTheDocument();
+
+ await user.click(screen.getByText('close'));
+ expect(screen.queryByTestId('share-modal')).not.toBeInTheDocument();
+ });
+});
diff --git a/app/src/features/share/ShareMessageButton.tsx b/app/src/features/share/ShareMessageButton.tsx
new file mode 100644
index 0000000000..6dafdd3ab6
--- /dev/null
+++ b/app/src/features/share/ShareMessageButton.tsx
@@ -0,0 +1,68 @@
+import { useState } from 'react';
+
+import { useT } from '../../lib/i18n/I18nContext';
+import { ShareCardModal } from './ShareCardModal';
+
+interface ShareMessageButtonProps {
+ /** Plain-text agent output to turn into a share card. */
+ content: string;
+ /** Display name of the agent/profile that produced the output. */
+ agentName: string;
+ /** Optional thread id, forwarded to inference for log grouping. */
+ threadId?: string;
+ /** Extra classes for positioning within the message row. */
+ className?: string;
+}
+
+/**
+ * Hover-revealed "Share" affordance rendered under a completed agent message
+ * (issue #5006). Opens `ShareCardModal`. Self-contained so the wiring into the
+ * large `Conversations.tsx` message list stays a one-liner. Renders nothing when
+ * there is no shareable text.
+ */
+export function ShareMessageButton({
+ content,
+ agentName,
+ threadId,
+ className = '',
+}: ShareMessageButtonProps) {
+ const { t } = useT();
+ const [open, setOpen] = useState(false);
+
+ if (!content.trim()) return null;
+
+ return (
+ <>
+ <button
+ type="button"
+ data-analytics-id="chat-message-share"
+ data-testid="chat-message-share"
+ onClick={() => setOpen(true)}
+ title={t('share.button')}
+ aria-label={t('share.button')}
+ className={`p-1 rounded-md opacity-0 group-hover/msg:opacity-100 hover:bg-surface-hover dark:bg-surface-muted dark:hover:bg-surface-muted text-content-faint hover:text-content-secondary transition-all ${className}`}>
+ <svg
+ className="w-3.5 h-3.5"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ aria-hidden="true">
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M8.7 10.7l6.6-3.4M8.7 13.3l6.6 3.4M18 8a3 3 0 100-6 3 3 0 000 6zM6 15a3 3 0 100-6 3 3 0 000 6zm12 7a3 3 0 100-6 3 3 0 000 6z"
+ />
+ </svg>
+ </button>
+ {open ? (
+ <ShareCardModal
+ content={content}
+ agentName={agentName}
+ threadId={threadId}
+ onClose={() => setOpen(false)}
+ />
+ ) : null}
+ </>
+ );
+}