mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-30 17:14:54 +01:00
feat(ui): add task artifact media gallery and full-row links (#13825)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Tasks collect the files and work products that agents create. > - The Artifacts tab shows these outputs in rows, which makes videos hard to compare. > - Small text links also make artifact rows harder to open. > - This pull request adds image and video tiles with previews and makes the full artifact row clickable. > - Users can compare outputs and open the existing media viewer with one click. ## Linked Issues or Issue Description **What existing behavior does this improve?** The task Artifacts tab and media previews in task chat. **Current behavior** Video outputs appear as file rows or icons. Users must click a small link to open a work product. A task with eight video outputs gives little visual context. **Proposed behavior** Show images and videos in a responsive gallery. Show a paused video frame as the thumbnail. Keep documents, links, and other files in rows whose entire area opens the item. **Reason and benefit** Users can compare generated media without opening each item. Larger click targets also make the sidebar easier to use. **Breaking changes** None. This uses the existing artifact URLs, media viewer, run grouping, and attachment filters. No API or database changes. Related work: #11226 added the task sidebar output surface, and #7361 added rich attachment previews. #3524 concerns a separate reviewed-assets panel. This PR improves the existing task artifact components. The duplicate search found no active PR for this change. This is polish for the shipped Artifacts & Work Products roadmap item. ## What Changed - Add a shared media tile for work products and agent attachments. - Reuse video and image previews in task artifacts and chat. Seek up to one second into videos and reset preview state when the source changes. - Use the existing task gallery for playback and downloads. Preserve grouping and attachment deduplication. - Extend native links and buttons across work-product rows, including keyboard focus indicators. - Add eight offline Storybook examples for video outputs, mixed media, clickable rows, narrow and wide panels, missing previews, empty state, and light mode. - Register the component in the design guide and document its use. ## Verification - 108 focused component tests pass, including thumbnail seeking, source changes, gallery activation, and attachment deduplication. - `pnpm build`, `pnpm -r typecheck`, Storybook build, token gates, and `git diff --check` pass locally. - Reviewed the production components in the embedded browser. Checked all eight video thumbnails, mixed media, narrow layout, light mode, blank-area row clicks, keyboard gallery activation for generic-MIME images, and playback from chat video thumbnails. - Storybook: open **Tasks / Artifact Gallery** and select **Eight Video Outputs**, **Mixed Media And Files**, or **Whole Row Clickable**. The small local clips are synthetic fixtures. - All build, typecheck, unit, runner, and end-to-end CI jobs pass for `b8ace289b5e07df5b9f2c319b159f3923ce427b4`. Greptile gives 5/5 with both review findings resolved. All 54 PR checks pass, including the external security scan. The full test suite passed in CI. The duplicate serial local test run was stopped after CI finished; the 108 focused tests, full build, and recursive typecheck passed locally. ## Risks - Video thumbnails require the browser to load metadata and a frame. A slow server or unsupported codec can leave the fallback visible; opening and downloading still use the existing viewer. - Full-row click targets change pointer interaction with work-product cards. Native link and button semantics remain in place. ## Model Used OpenAI GPT-6 in Codex, with code execution and browser tools. The exact deployment ID and context window are not exposed in this session. ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
92d4868e79
commit
1ccae464c5
27 files changed
+351
-45
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import { useContext, useState, type CSSProperties } from "react";
|
||||
import { IssueGalleryContext } from "@/context/IssueGalleryContext";
|
||||
import { ArtifactPreview } from "@/components/artifacts/ArtifactCard";
|
||||
import { MediaArtifactCard } from "@/components/artifacts/MediaArtifactCard";
|
||||
import { ImageGalleryModal } from "@/components/ImageGalleryModal";
|
||||
import { isImageContentType, isVideoLikeOutput } from "@/lib/issue-output";
|
||||
import { isImageLikeOutput, isVideoLikeOutput } from "@/lib/issue-output";
|
||||
import { attachmentDownloadPath } from "@/lib/issue-attachments";
|
||||
import type { IssueWorkProduct } from "@paperclipai/shared";
|
||||
import {
|
||||
@@ -124,7 +126,7 @@ function Chip({ chip }: { chip: StateChip }) {
|
||||
export interface RichWorkProductCardProps {
|
||||
workProduct: IssueWorkProduct;
|
||||
href: string | null;
|
||||
variant?: "card" | "compact";
|
||||
variant?: "card" | "compact" | "gallery";
|
||||
}
|
||||
|
||||
export function RichWorkProductCard({ workProduct, href, variant = "card" }: RichWorkProductCardProps) {
|
||||
@@ -132,8 +134,8 @@ export function RichWorkProductCard({ workProduct, href, variant = "card" }: Ric
|
||||
const [galleryOpen, setGalleryOpen] = useState(false);
|
||||
const metadata = workProduct.metadata;
|
||||
const contentType = stringMeta(metadata, "contentType") ?? "";
|
||||
const isImage = isImageContentType(contentType);
|
||||
const isVideo = isVideoLikeOutput(contentType, stringMeta(metadata, "originalFilename"));
|
||||
const isImage = isImageLikeOutput(contentType, stringMeta(metadata, "originalFilename") ?? workProduct.title);
|
||||
const isVideo = isVideoLikeOutput(contentType, stringMeta(metadata, "originalFilename") ?? workProduct.title);
|
||||
let Icon: LucideIcon = File;
|
||||
let meta: Array<string | null> = [];
|
||||
let action = "Open preview";
|
||||
@@ -214,10 +216,6 @@ export function RichWorkProductCard({ workProduct, href, variant = "card" }: Ric
|
||||
const fileCount = files === null ? null : `${files} ${files === 1 ? "file" : "files"}`;
|
||||
const statsLabel = [changeCounts || null, fileCount].filter(Boolean).join(" · ");
|
||||
const compact = variant === "compact";
|
||||
const imagePath = isImage
|
||||
? stringMeta(metadata, "openPath", "contentPath") ?? href
|
||||
: null;
|
||||
|
||||
const mediaPath = workProduct.type === "artifact" && (isImage || isVideo)
|
||||
? stringMeta(metadata, "contentPath", "openPath") ?? href
|
||||
: null;
|
||||
@@ -232,10 +230,26 @@ export function RichWorkProductCard({ workProduct, href, variant = "card" }: Ric
|
||||
if (mediaPath && !openIssueGallery?.(mediaPath)) setGalleryOpen(true);
|
||||
};
|
||||
|
||||
if (variant === "gallery" && mediaPath) {
|
||||
return (
|
||||
<MediaArtifactCard
|
||||
id={workProduct.id}
|
||||
title={workProduct.title}
|
||||
contentPath={mediaPath}
|
||||
contentType={contentType}
|
||||
originalFilename={stringMeta(metadata, "originalFilename") ?? workProduct.title}
|
||||
downloadPath={stringMeta(metadata, "downloadPath") ?? undefined}
|
||||
detail={visibleMeta.join(" · ")}
|
||||
badge={chip ? <Chip chip={chip} /> : null}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<article
|
||||
className={cn(
|
||||
"@container flex min-w-0 rounded-md border border-border bg-card/60",
|
||||
"@container relative flex min-w-0 rounded-md border border-border bg-card/60",
|
||||
(mediaPath || actionHref) && "hover:bg-accent/50",
|
||||
compact ? "items-center gap-2 px-2.5 py-1.5" : "items-start gap-3 px-3 py-2.5",
|
||||
)}
|
||||
data-testid={`task-chat-rich-work-product-${workProduct.type}`}
|
||||
@@ -243,10 +257,10 @@ export function RichWorkProductCard({ workProduct, href, variant = "card" }: Ric
|
||||
>
|
||||
<div className={cn(
|
||||
"flex shrink-0 items-center justify-center overflow-hidden rounded-sm bg-muted/60 text-muted-foreground",
|
||||
compact ? "h-8 w-8" : "h-10 w-10",
|
||||
mediaPath ? "w-20" : compact ? "h-8 w-8" : "h-10 w-10",
|
||||
)}>
|
||||
{imagePath ? (
|
||||
<img src={imagePath} alt="" className="h-full w-full object-cover" />
|
||||
{mediaPath ? (
|
||||
<ArtifactPreview artifact={{ contentPath: mediaPath, title: workProduct.title, mediaKind: isVideo ? "video" : "image" }} />
|
||||
) : (
|
||||
<Icon aria-hidden className={compact ? "h-4 w-4" : "h-5 w-5"} />
|
||||
)}
|
||||
@@ -259,11 +273,11 @@ export function RichWorkProductCard({ workProduct, href, variant = "card" }: Ric
|
||||
<div className={cn("flex shrink-0 items-center", compact ? "gap-1.5" : "gap-2")}>
|
||||
{chip ? <Chip chip={chip} /> : null}
|
||||
{mediaPath ? (
|
||||
<button type="button" onClick={openGallery} aria-label={`${action}: ${workProduct.title}`} className="inline-flex items-center gap-1 text-xs font-medium text-foreground hover:underline">
|
||||
<button type="button" onClick={openGallery} aria-label={`${action}: ${workProduct.title}`} className="inline-flex items-center gap-1 text-xs font-medium text-foreground after:absolute after:inset-0 after:rounded-md focus-visible:outline-none focus-visible:after:ring-2 focus-visible:after:ring-ring">
|
||||
{compact ? null : <span className="hidden @sm:inline">{action}</span>}<Maximize2 aria-hidden className="h-3 w-3" />
|
||||
</button>
|
||||
) : actionHref ? (
|
||||
<a href={actionHref} aria-label={`${action}: ${workProduct.title}`} className="inline-flex items-center gap-1 text-xs font-medium text-foreground hover:underline" target={actionHref.startsWith("http") ? "_blank" : undefined} rel={actionHref.startsWith("http") ? "noreferrer" : undefined}>
|
||||
<a href={actionHref} aria-label={`${action}: ${workProduct.title}`} className="inline-flex items-center gap-1 text-xs font-medium text-foreground after:absolute after:inset-0 after:rounded-md focus-visible:outline-none focus-visible:after:ring-2 focus-visible:after:ring-ring" target={actionHref.startsWith("http") ? "_blank" : undefined} rel={actionHref.startsWith("http") ? "noreferrer" : undefined}>
|
||||
{compact ? null : <span className="hidden @sm:inline">{action}</span>}<ExternalLink aria-hidden className="h-3 w-3" />
|
||||
</a>
|
||||
) : null}
|
||||
|
||||
@@ -94,6 +94,33 @@ describe("TaskChatBubble attachment chips", () => {
|
||||
expect(container.textContent).toContain("PDF");
|
||||
});
|
||||
|
||||
it("opens video thumbnails in a local gallery when no task gallery is available", () => {
|
||||
renderMessage("[clip.mp4](/api/attachments/clip/content)", "agent", [
|
||||
attachment({ id: "clip", originalFilename: "clip.mp4", contentType: "video/mp4" }),
|
||||
]);
|
||||
const group = container.querySelector('[data-testid="task-chat-bubble-attachments"]');
|
||||
expect(group?.querySelector("video")?.getAttribute("src")).toBe("/api/attachments/clip/content");
|
||||
expect(group?.querySelector("video")?.autoplay).toBe(false);
|
||||
flushSync(() => group!.querySelector<HTMLButtonElement>('button[aria-label="Open clip.mp4"]')!.click());
|
||||
expect(document.querySelector('[role="dialog"] video')?.getAttribute("src")).toBe("/api/attachments/clip/content");
|
||||
expect(document.querySelector('[role="dialog"] a[download]')?.getAttribute("href")).toBe("/api/attachments/clip/content?download=1");
|
||||
});
|
||||
|
||||
it.each(["video/mp4", "application/octet-stream"])("opens %s video attachments in the shared task gallery", (contentType) => {
|
||||
const openGallery = vi.fn(() => true);
|
||||
const clip = attachment({ id: "clip", originalFilename: "clip.mp4", contentType });
|
||||
flushSync(() => root!.render(
|
||||
<ThemeProvider>
|
||||
<IssueGalleryContext.Provider value={openGallery}>
|
||||
<TaskChatBubble item={{ id: "m1", kind: "message", author: "agent", text: `[clip.mp4](${clip.contentPath})` }} attachments={[clip]} />
|
||||
</IssueGalleryContext.Provider>
|
||||
</ThemeProvider>,
|
||||
));
|
||||
flushSync(() => container.querySelector<HTMLButtonElement>('button[aria-label="Open clip.mp4"]')!.click());
|
||||
expect(openGallery).toHaveBeenCalledWith(clip.contentPath);
|
||||
expect(document.querySelector('[role="dialog"]')).toBeNull();
|
||||
});
|
||||
|
||||
it("leaves messages without file references untouched", () => {
|
||||
renderMessage("Just words and a [normal link](https://example.com).");
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { ArtifactPreview } from "@/components/artifacts/ArtifactCard";
|
||||
import { isVideoLikeOutput } from "@/lib/issue-output";
|
||||
import { AgentAvatar, type AvatarAgent } from "../AgentAvatar";
|
||||
import { useCallback, useContext, useState, type ReactNode } from "react";
|
||||
import { useEmailComment } from "@/components/EmailMessageCard";
|
||||
@@ -96,7 +98,7 @@ export function TaskChatAgentIdentity({
|
||||
* surface with an avatar author header (the agent's assigned icon + name);
|
||||
* system notices are centered and recede.
|
||||
*/
|
||||
function galleryItemForImage(
|
||||
function galleryItemForMedia(
|
||||
src: string,
|
||||
name?: string,
|
||||
attachment?: ReturnType<typeof hydrateAttachmentRefs>[number],
|
||||
@@ -198,16 +200,17 @@ function TaskChatBubbleContent({
|
||||
...hydratedLinkedRefs.filter((ref) => !isImageAttachment(ref)),
|
||||
...boundAttachmentRefs.filter((ref) => !isImageAttachment(ref)),
|
||||
]);
|
||||
const mediaRefs = [...imageRefs, ...attachmentRefs.filter((ref) => isVideoLikeOutput(ref.contentType, ref.name))];
|
||||
const galleryItems: GalleryMediaItem[] =
|
||||
lightboxSrc !== null && !imageRefs.some((ref) => ref.url === lightboxSrc)
|
||||
lightboxSrc !== null && !mediaRefs.some((ref) => ref.url === lightboxSrc)
|
||||
? // A clicked image the extractor missed (e.g. inline HTML) still gets a
|
||||
// single-item lightbox rather than nothing.
|
||||
[galleryItemForImage(lightboxSrc)]
|
||||
: imageRefs.map((ref) => galleryItemForImage(ref.url, ref.name, ref));
|
||||
[galleryItemForMedia(lightboxSrc)]
|
||||
: mediaRefs.map((ref) => galleryItemForMedia(ref.url, ref.name, ref));
|
||||
const lightboxIndex =
|
||||
lightboxSrc === null
|
||||
? -1
|
||||
: Math.max(0, imageRefs.findIndex((ref) => ref.url === lightboxSrc));
|
||||
: Math.max(0, mediaRefs.findIndex((ref) => ref.url === lightboxSrc));
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -308,10 +311,11 @@ function TaskChatBubbleContent({
|
||||
const kind = fileKindForAttachment(ref);
|
||||
const KindIcon = kind.icon;
|
||||
const size = formatFileSize(ref.byteSize);
|
||||
const video = isVideoLikeOutput(ref.contentType, ref.name);
|
||||
return (
|
||||
<Attachment key={ref.url} size="sm">
|
||||
<AttachmentMedia>
|
||||
<KindIcon aria-hidden />
|
||||
<AttachmentMedia className={video ? "aspect-video group-data-[size=sm]/attachment:w-20" : undefined}>
|
||||
{video ? <ArtifactPreview artifact={{ title: ref.name, contentPath: ref.openPath ?? ref.url, mediaKind: "video" }} /> : <KindIcon aria-hidden />}
|
||||
</AttachmentMedia>
|
||||
<AttachmentContent>
|
||||
<AttachmentTitle className="max-w-48">
|
||||
@@ -323,7 +327,8 @@ function TaskChatBubbleContent({
|
||||
</AttachmentContent>
|
||||
<AttachmentTrigger
|
||||
aria-label={`Open ${ref.name}`}
|
||||
render={
|
||||
onClick={video ? () => openImage(ref.url) : undefined}
|
||||
render={video ? <button type="button" /> :
|
||||
<a
|
||||
href={ref.openPath ?? ref.url}
|
||||
target="_blank"
|
||||
|
||||
@@ -181,7 +181,10 @@ describe("TaskChatProtocolCard", () => {
|
||||
expect(container.textContent).toContain("Open gallery");
|
||||
});
|
||||
|
||||
it.each(["image/png", "video/webm"])("opens %s artifacts in the task gallery", (contentType) => {
|
||||
it.each([
|
||||
["image/png", "compact"], ["video/webm", "compact"],
|
||||
["image/png", "gallery"], ["video/webm", "gallery"],
|
||||
] as const)("opens %s artifacts from the %s presentation in the task gallery", (contentType, variant) => {
|
||||
const openGallery = vi.fn(() => true);
|
||||
const contentPath = "/api/attachments/media/content";
|
||||
flushSync(() => root.render(
|
||||
@@ -189,7 +192,7 @@ describe("TaskChatProtocolCard", () => {
|
||||
<RichWorkProductCard
|
||||
workProduct={workProduct({ type: "artifact", metadata: { contentType, contentPath } })}
|
||||
href={contentPath}
|
||||
variant="compact"
|
||||
variant={variant}
|
||||
/>
|
||||
</IssueGalleryContext.Provider>,
|
||||
));
|
||||
|
||||
Reference in new issue
Block a user