Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(tasks): rebuild the artifacts tab in quill with versions and full page (#109860)

Shy Alterc8ef65ba2f96
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx
index 52f0fda89b4a..890d6cf016b3 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx
@@ -54,7 +54,21 @@ The release on Tuesday changed the plan picker layout. The start trial button no
![](https://example.com/markdown-pixel.png)
`
-const CHART_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 360" font-family="Inter, sans-serif">
+const REPORT_DRAFT_MARKDOWN = `# Trial starts dropped
+
+Trial starts fell week over week. I am still checking which step lost the most people.
+`
+
+const REPORT_SECOND_DRAFT_MARKDOWN = `# Trial starts dropped at the plan picker
+
+Trial starts fell **18%** week over week. The loss sits almost entirely at the plan picker step.
+
+## Why
+
+- Recordings show people scroll the plan table, then leave without a click.
+`
+
+const CHART_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="1280" height="720" viewBox="0 0 640 360" font-family="Inter, sans-serif">
<rect width="640" height="360" fill="#ffffff"/>
<text x="32" y="40" font-size="16" font-weight="600" fill="#151515">Conversion by funnel step</text>
<rect x="400" y="28" width="10" height="10" rx="2" fill="#1d4aff" fill-opacity="0.3"/><text x="416" y="37" font-size="11" fill="#5f5f5f">Week of Sep 14</text>
@@ -150,8 +164,38 @@ const ARTIFACTS: TaskRunArtifactResponseApi[] = [
},
]
+// Earlier uploads of the report. The file list groups them with `artifact-report` by name.
+const REPORT_OLDER_VERSIONS: TaskRunArtifactResponseApi[] = [
+ {
+ id: 'artifact-report-v2',
+ name: 'trial-drop-report.md',
+ type: 'output',
+ source: 'agent_output',
+ size: 4096,
+ content_type: 'text/markdown',
+ storage_path: 'tasks/artifacts/artifact-report-v2',
+ uploaded_at: '2026-09-28T18:02:00Z',
+ uploaded_by: 'agent',
+ },
+ {
+ id: 'artifact-report-v1',
+ name: 'trial-drop-report.md',
+ type: 'output',
+ source: 'agent_output',
+ size: 1024,
+ content_type: 'text/markdown',
+ storage_path: 'tasks/artifacts/artifact-report-v1',
+ uploaded_at: '2026-09-28T17:51:00Z',
+ uploaded_by: 'agent',
+ },
+]
+
+const REPORT_FILE_NAME = 'trial-drop-report.md'
+
const CONTENT_BY_PATH: Record<string, string> = {
'tasks/artifacts/artifact-report': REPORT_MARKDOWN,
+ 'tasks/artifacts/artifact-report-v2': REPORT_SECOND_DRAFT_MARKDOWN,
+ 'tasks/artifacts/artifact-report-v1': REPORT_DRAFT_MARKDOWN,
'tasks/artifacts/artifact-summary': SUMMARY_HTML,
'tasks/artifacts/artifact-csv': WEEKS_CSV,
}
@@ -313,14 +357,25 @@ function TodayWebLayout({ children }: { children: ReactNode }): JSX.Element {
)
}
-function StoryPage({ tab = 'artifacts', artifactId }: { tab?: TaskRunTab; artifactId?: string }): JSX.Element {
- const { setActiveTab, selectArtifact } = useActions(taskRunArtifactsLogic({ taskId: TASK_ID }))
+function StoryPage({
+ tab = 'artifacts',
+ fileName,
+ versionId,
+}: {
+ tab?: TaskRunTab
+ fileName?: string
+ versionId?: string
+}): JSX.Element {
+ const { setActiveTab, selectArtifact, selectVersion } = useActions(taskRunArtifactsLogic({ taskId: TASK_ID }))
useEffect(() => {
- if (artifactId) {
- selectArtifact(artifactId)
+ if (fileName) {
+ selectArtifact(fileName)
+ }
+ if (versionId) {
+ selectVersion(versionId)
}
setActiveTab(tab)
- }, [tab, artifactId, setActiveTab, selectArtifact])
+ }, [tab, fileName, versionId, setActiveTab, selectArtifact, selectVersion])
return (
<TodayWebLayout>
<TaskDetailPage taskId={TASK_ID} isMobile={false} />
@@ -332,8 +387,10 @@ const meta: Meta = {
title: 'Scenes-App/Tasks/Artifacts',
// No snapshots while the today-rail-nav layout is still changing quickly, the same as the Today stories.
tags: ['test-skip'],
- decorators: [mswDecorator(taskMocks(ARTIFACTS))],
+ // Mocks go through parameters, not story decorators: a story decorator's mocks register before the meta's and lose.
+ decorators: [mswDecorator({})],
parameters: {
+ msw: { mocks: taskMocks(ARTIFACTS) },
layout: 'fullscreen',
viewMode: 'story',
mockDate: '2026-09-28 18:30:00',
@@ -345,18 +402,28 @@ export default meta
type Story = StoryObj<{}>
-export const MarkdownReport: Story = { render: () => <StoryPage artifactId="artifact-report" /> }
+export const MarkdownReport: Story = { render: () => <StoryPage fileName={REPORT_FILE_NAME} /> }
-export const SandboxedHtml: Story = { render: () => <StoryPage artifactId="artifact-summary" /> }
+export const SandboxedHtml: Story = { render: () => <StoryPage fileName="trial-funnel-summary.html" /> }
-export const Image: Story = { render: () => <StoryPage artifactId="artifact-chart" /> }
+export const Image: Story = { render: () => <StoryPage fileName="trial-starts-by-step.svg" /> }
-export const Csv: Story = { render: () => <StoryPage artifactId="artifact-csv" /> }
+export const Csv: Story = { render: () => <StoryPage fileName="trial-starts-by-week.csv" /> }
+
+export const Versions: Story = {
+ parameters: { msw: { mocks: taskMocks([...ARTIFACTS, ...REPORT_OLDER_VERSIONS]) } },
+ render: () => <StoryPage fileName={REPORT_FILE_NAME} />,
+}
+
+export const OlderVersion: Story = {
+ parameters: { msw: { mocks: taskMocks([...ARTIFACTS, ...REPORT_OLDER_VERSIONS]) } },
+ render: () => <StoryPage fileName={REPORT_FILE_NAME} versionId="artifact-report-v1" />,
+}
export const ConversationTab: Story = { render: () => <StoryPage tab="conversation" /> }
export const NoArtifacts: Story = {
- decorators: [mswDecorator(taskMocks([]))],
+ parameters: { msw: { mocks: taskMocks([]) } },
render: () => <StoryPage />,
}
@@ -366,6 +433,6 @@ export const FlagOff: Story = {
}
export const ResumedTask: Story = {
- decorators: [mswDecorator(taskMocks(ARTIFACTS, { resumed: true }))],
- render: () => <StoryPage artifactId="artifact-report" />,
+ parameters: { msw: { mocks: taskMocks(ARTIFACTS, { resumed: true }) } },
+ render: () => <StoryPage fileName={REPORT_FILE_NAME} />,
}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
index a856dac705fc..b68f80cc8281 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
@@ -1,29 +1,76 @@
import { useActions, useValues } from 'kea'
-import { useEffect, useMemo } from 'react'
+import { useEffect, useMemo, useState } from 'react'
import {
+ IconCheck,
IconChevronLeft,
IconChevronRight,
IconCode,
+ IconCollapse45,
+ IconCopy,
IconDatabase,
IconDocument,
IconDownload,
+ IconExpand45,
IconImage,
IconLock,
} from '@posthog/icons'
-import { LemonButton, LemonTable, LemonTabs, LemonTag, Spinner, Tooltip } from '@posthog/lemon-ui'
+import {
+ Badge,
+ Button,
+ Dialog,
+ DialogContent,
+ DialogTitle,
+ Empty,
+ EmptyContent,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyMedia,
+ EmptyTitle,
+ Item,
+ ItemContent,
+ ItemDescription,
+ ItemMedia,
+ ItemTitle,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+ SkeletonText,
+ Spinner,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ Text,
+ ToggleGroup,
+ ToggleGroupItem,
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+ cn,
+} from '@posthog/quill-primitives'
import { dayjs } from 'lib/dayjs'
import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
-import { cn } from 'lib/utils/css-classes'
import { withStrictCsp } from '../artifactHtml'
import {
+ ArtifactFile,
ArtifactPreviewKind,
RunArtifact,
TaskRunTab,
artifactPreviewKind,
formatArtifactSize,
+ isTextPreview,
parseCsv,
} from '../taskRunArtifacts'
import { artifactDownloadUrl, taskRunArtifactsLogic } from '../taskRunArtifactsLogic'
@@ -31,17 +78,50 @@ import { ArtifactImageViewer } from './ArtifactImageViewer'
const MAX_CSV_ROWS = 500
-function KindIcon({ kind }: { kind: ArtifactPreviewKind }): JSX.Element {
- if (kind === 'html') {
- return <IconCode />
- }
- if (kind === 'image') {
- return <IconImage />
- }
- if (kind === 'csv') {
- return <IconDatabase />
- }
- return <IconDocument />
+type PreviewMode = 'rendered' | 'source'
+
+function KindIcon({ kind, className }: { kind: ArtifactPreviewKind; className?: string }): JSX.Element {
+ const Icon =
+ kind === 'html' ? IconCode : kind === 'image' ? IconImage : kind === 'csv' ? IconDatabase : IconDocument
+ return <Icon className={className} />
+}
+
+function IconAction({
+ label,
+ onClick,
+ href,
+ disabledReason,
+ children,
+ dataAttr,
+}: {
+ label: string
+ onClick?: () => void
+ href?: string
+ disabledReason?: string
+ children: JSX.Element
+ dataAttr: string
+}): JSX.Element {
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ delay={0}
+ render={
+ <Button
+ size="icon"
+ aria-label={label}
+ disabled={!!disabledReason}
+ onClick={onClick}
+ data-attr={dataAttr}
+ // eslint-disable-next-line react/forbid-elements
+ render={href && !disabledReason ? <a href={href} download /> : undefined}
+ />
+ }
+ >
+ {children}
+ </TooltipTrigger>
+ <TooltipContent>{disabledReason ?? label}</TooltipContent>
+ </Tooltip>
+ )
}
/**
@@ -67,24 +147,57 @@ function CsvPreview({ text }: { text: string }): JSX.Element {
}, [text])
return (
<div className="flex flex-col gap-2 p-6">
- <LemonTable
- dataSource={rows.map((cells, index) => ({ index, cells }))}
- rowKey="index"
- size="small"
- columns={header.map((title, column) => ({
- title,
- key: String(column),
- render: (_, row) => <span className="font-mono">{row.cells[column]}</span>,
- }))}
- />
+ <div className="overflow-hidden rounded-md border border-border bg-card text-card-foreground">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ {header.map((title, column) => (
+ <TableHead key={column}>{title}</TableHead>
+ ))}
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {rows.map((cells, index) => (
+ <TableRow key={index}>
+ {header.map((_, column) => (
+ <TableCell key={column} className="font-mono tabular-nums">
+ {cells[column]}
+ </TableCell>
+ ))}
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </div>
{truncated && (
- <span className="text-xs text-secondary">{`Showing the first ${MAX_CSV_ROWS} rows. Download the file to see all of them.`}</span>
+ <Text size="xs" variant="muted">
+ {`Showing the first ${MAX_CSV_ROWS} rows. Download the file to see all of them.`}
+ </Text>
)}
</div>
)
}
-function ArtifactPreview({ taskId }: { taskId: string }): JSX.Element | null {
+function SourceView({ text }: { text: string }): JSX.Element {
+ return (
+ <pre className="m-0 min-h-full p-6 font-mono text-xs leading-relaxed whitespace-pre-wrap break-words text-foreground">
+ {text}
+ </pre>
+ )
+}
+
+function TextLoading(): JSX.Element {
+ return (
+ <div className="px-6 py-8">
+ <div className="mx-auto flex max-w-3xl flex-col gap-4 rounded-lg border border-border bg-card px-10 py-8">
+ <SkeletonText lines={1} />
+ <SkeletonText lines={5} />
+ </div>
+ </div>
+ )
+}
+
+function ArtifactPreview({ taskId, mode }: { taskId: string; mode: PreviewMode }): JSX.Element | null {
const { selectedArtifact, selectedKind, selectedText, selectedRun, currentProjectId, artifactTextLoading } =
useValues(taskRunArtifactsLogic({ taskId }))
const { ensureSelectedText, loadArtifactText } = useActions(taskRunArtifactsLogic({ taskId }))
@@ -96,38 +209,50 @@ function ArtifactPreview({ taskId }: { taskId: string }): JSX.Element | null {
}
if (selectedKind === 'image') {
const src = artifactDownloadUrl(currentProjectId, taskId, selectedArtifact)
- return src ? <ArtifactImageViewer src={src} alt={selectedArtifact.name} /> : null
+ return src ? <ArtifactImageViewer key={selectedArtifact.id} src={src} alt={selectedArtifact.name} /> : null
}
if (selectedKind === 'none') {
return (
- <div className="flex min-h-full items-center justify-center p-8 text-sm text-secondary">
- This file type has no preview. Download it to open it.
- </div>
+ <Empty className="h-full">
+ <EmptyHeader>
+ <EmptyTitle>No preview for this file</EmptyTitle>
+ <EmptyDescription>Download it to open it on your computer.</EmptyDescription>
+ </EmptyHeader>
+ </Empty>
)
}
if (!selectedText) {
- return (
- <div className="flex min-h-full items-center justify-center p-8">
- <Spinner className="text-2xl" />
+ return selectedKind === 'html' ? (
+ <div className="flex h-full items-center justify-center">
+ <Spinner />
</div>
+ ) : (
+ <TextLoading />
)
}
if (selectedText.text === null) {
return (
- <div className="flex min-h-full flex-col items-center justify-center gap-2 p-8 text-sm text-secondary">
- <span>{selectedText.error ?? 'This file did not load.'}</span>
- <LemonButton
- type="secondary"
- size="small"
- loading={artifactTextLoading}
- onClick={() => loadArtifactText(selectedArtifact)}
- data-attr="task-artifact-retry"
- >
- Try again
- </LemonButton>
- </div>
+ <Empty className="h-full">
+ <EmptyHeader>
+ <EmptyTitle>This file didn't load</EmptyTitle>
+ <EmptyDescription>{selectedText.error ?? 'Check your connection and try again.'}</EmptyDescription>
+ </EmptyHeader>
+ <EmptyContent>
+ <Button
+ variant="outline"
+ loading={artifactTextLoading}
+ onClick={() => loadArtifactText(selectedArtifact)}
+ data-attr="task-artifact-retry"
+ >
+ Try again
+ </Button>
+ </EmptyContent>
+ </Empty>
)
}
+ if (mode === 'source') {
+ return <SourceView text={selectedText.text} />
+ }
if (selectedKind === 'html') {
return <SandboxedHtmlFrame html={selectedText.text} name={selectedArtifact.name} />
}
@@ -137,147 +262,361 @@ function ArtifactPreview({ taskId }: { taskId: string }): JSX.Element | null {
if (selectedKind === 'markdown') {
return (
<div className="px-6 py-8">
- <article className="mx-auto max-w-3xl rounded-lg border border-primary bg-surface-primary px-10 py-8">
+ <article className="mx-auto max-w-3xl rounded-lg border border-border bg-card px-10 py-8 text-card-foreground">
<LemonMarkdown disableImages="all">{selectedText.text}</LemonMarkdown>
</article>
</div>
)
}
- return <pre className="m-0 p-6 font-mono text-xs whitespace-pre-wrap break-words">{selectedText.text}</pre>
+ return <SourceView text={selectedText.text} />
+}
+
+function fileMeta(file: ArtifactFile): string {
+ const age = dayjs(file.latest.uploaded_at).fromNow()
+ return file.versions.length > 1
+ ? `${file.versions.length} versions · ${age}`
+ : `${formatArtifactSize(file.latest.size)} · ${age}`
}
function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {
const { files, selectedFile } = useValues(taskRunArtifactsLogic({ taskId }))
const { selectArtifact } = useActions(taskRunArtifactsLogic({ taskId }))
return (
- <nav
- className="hidden w-64 shrink-0 flex-col border-r border-primary @[52rem]/main-content:flex"
- aria-label="Artifacts"
- >
- <div className="flex h-10 shrink-0 items-center gap-1.5 border-b border-primary px-3 text-xs font-semibold text-secondary">
- <span>Files</span>
- <span className="font-normal tabular-nums">{files.length}</span>
+ <aside className="hidden w-64 shrink-0 flex-col border-r border-border @[52rem]/main-content:flex">
+ <div className="flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-3">
+ <Text size="xs" weight="medium" variant="muted" render={<span />}>
+ Files
+ </Text>
+ <Text size="xs" variant="muted" render={<span />} className="tabular-nums">
+ {files.length}
+ </Text>
</div>
- <div className="flex min-h-0 flex-1 flex-col gap-px overflow-y-auto p-1.5">
+ <div
+ role="listbox"
+ aria-label="Files"
+ className="flex min-h-0 flex-1 flex-col gap-px overflow-y-auto p-1.5"
+ >
{files.map((file) => {
- const artifact = file.latest
- const kind = artifactPreviewKind(artifact)
+ const selected = file.name === selectedFile?.name
return (
- <LemonButton
+ <Item
key={file.name}
- fullWidth
- size="small"
- active={file.name === selectedFile?.name}
- icon={<KindIcon kind={kind} />}
+ size="xs"
+ role="option"
+ aria-selected={selected}
+ className={cn(
+ 'w-full cursor-pointer rounded-md border-transparent text-left hover:bg-fill-hover',
+ selected && 'bg-fill-selected hover:bg-fill-selected'
+ )}
+ // eslint-disable-next-line react/forbid-elements
+ render={<button type="button" />}
onClick={() => selectArtifact(file.name)}
data-attr="task-artifact-nav-item"
>
- <span className="flex min-w-0 flex-col py-0.5">
- <span className="truncate">{artifact.name}</span>
- <span className="text-xs font-normal text-secondary">
- {`${formatArtifactSize(artifact.size)} · ${dayjs(artifact.uploaded_at).fromNow()}`}
- </span>
- </span>
- </LemonButton>
+ <ItemMedia>
+ <KindIcon
+ kind={artifactPreviewKind(file.latest)}
+ className="size-4 text-muted-foreground"
+ />
+ </ItemMedia>
+ <ItemContent className="min-w-0">
+ <ItemTitle className="w-full truncate">{file.name}</ItemTitle>
+ <ItemDescription className="truncate">{fileMeta(file)}</ItemDescription>
+ </ItemContent>
+ </Item>
)
})}
</div>
- </nav>
+ </aside>
)
}
-function ArtifactToolbar({ taskId, artifact }: { taskId: string; artifact: RunArtifact }): JSX.Element {
- const { files, selectedIndex, currentProjectId } = useValues(taskRunArtifactsLogic({ taskId }))
+function VersionSelect({ taskId, file }: { taskId: string; file: ArtifactFile }): JSX.Element {
+ const { selectedVersion } = useValues(taskRunArtifactsLogic({ taskId }))
+ const { selectVersion } = useActions(taskRunArtifactsLogic({ taskId }))
+ const total = file.versions.length
+ const items = file.versions.map((version, index) => ({
+ value: version.id ?? '',
+ label: `Version ${total - index}`,
+ }))
+ return (
+ <Select
+ items={items}
+ value={selectedVersion?.id ?? ''}
+ // Picking the newest follows the latest, so the next upload shows without another pick.
+ onValueChange={(id: string | null) => selectVersion(!id || id === file.latest.id ? null : id)}
+ >
+ <SelectTrigger aria-label="Version" data-attr="task-artifact-version-select" className="shrink-0">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {file.versions.map((version, index) => (
+ <SelectItem key={version.id} value={version.id ?? ''}>
+ <span className="flex w-52 items-center gap-2">
+ <span>{`Version ${total - index}`}</span>
+ {index === 0 && <Badge variant="success">Latest</Badge>}
+ <Text
+ size="xs"
+ variant="muted"
+ render={<span />}
+ className="ml-auto tabular-nums"
+ title={dayjs(version.uploaded_at).format('MMM D, YYYY HH:mm')}
+ >
+ {dayjs(version.uploaded_at).fromNow()}
+ </Text>
+ </span>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ )
+}
+
+function OlderVersionNotice({ taskId }: { taskId: string }): JSX.Element | null {
+ const { selectedFile, selectedVersion, selectedVersionIndex } = useValues(taskRunArtifactsLogic({ taskId }))
+ const { selectVersion } = useActions(taskRunArtifactsLogic({ taskId }))
+ if (!selectedFile || !selectedVersion || selectedVersionIndex === 0) {
+ return null
+ }
+ const total = selectedFile.versions.length
+ return (
+ <div className="flex h-9 shrink-0 items-center gap-2 border-b border-border bg-info px-3 text-info-foreground">
+ <Text size="xs" render={<span />} className="min-w-0 truncate text-info-foreground">
+ {`You're viewing version ${total - selectedVersionIndex} of ${total}, from ${dayjs(
+ selectedVersion.uploaded_at
+ ).fromNow()}.`}
+ </Text>
+ <Button
+ size="xs"
+ variant="outline"
+ className="ml-auto shrink-0"
+ onClick={() => selectVersion(null)}
+ data-attr="task-artifact-view-latest"
+ >
+ View latest
+ </Button>
+ </div>
+ )
+}
+
+function CopySourceAction({ text }: { text: string | null }): JSX.Element {
+ const [copied, setCopied] = useState(false)
+ useEffect(() => {
+ if (!copied) {
+ return
+ }
+ const timeout = window.setTimeout(() => setCopied(false), 2000)
+ return () => window.clearTimeout(timeout)
+ }, [copied])
+ return (
+ <IconAction
+ label={copied ? 'Copied' : 'Copy source'}
+ disabledReason={text === null ? 'The file has not loaded yet' : undefined}
+ onClick={() => {
+ if (text !== null) {
+ void navigator.clipboard.writeText(text).then(() => setCopied(true))
+ }
+ }}
+ dataAttr="task-artifact-copy"
+ >
+ {copied ? <IconCheck className="size-4" /> : <IconCopy className="size-4" />}
+ </IconAction>
+ )
+}
+
+function ArtifactToolbar({
+ taskId,
+ artifact,
+ mode,
+ onModeChange,
+ expanded,
+ onExpandedChange,
+}: {
+ taskId: string
+ artifact: RunArtifact
+ mode: PreviewMode
+ onModeChange: (mode: PreviewMode) => void
+ expanded: boolean
+ onExpandedChange: (expanded: boolean) => void
+}): JSX.Element {
+ const { files, selectedFile, selectedIndex, selectedText, currentProjectId } = useValues(
+ taskRunArtifactsLogic({ taskId })
+ )
const { stepArtifact, downloadArtifact } = useActions(taskRunArtifactsLogic({ taskId }))
const kind = artifactPreviewKind(artifact)
const downloadUrl = artifactDownloadUrl(currentProjectId, taskId, artifact)
const single = files.length < 2
+ const versioned = !!selectedFile && selectedFile.versions.length > 1
+ // Plain text already shows its source, so only these kinds get a view switch.
+ const hasRenderedForm = kind === 'markdown' || kind === 'html' || kind === 'csv'
return (
- <div className="flex h-10 shrink-0 items-center gap-2 border-b border-primary px-3">
- <span className="flex size-4 shrink-0 items-center text-secondary">
- <KindIcon kind={kind} />
- </span>
- <span className="min-w-0 truncate font-semibold">{artifact.name}</span>
- <Tooltip title={dayjs(artifact.uploaded_at).format('MMM D, YYYY HH:mm')}>
- <span className="hidden shrink-0 text-xs text-secondary @[40rem]/main-content:inline">
- {`${formatArtifactSize(artifact.size)} · ${dayjs(artifact.uploaded_at).fromNow()}`}
- </span>
+ <div className="flex h-10 shrink-0 items-center gap-2 border-b border-border bg-background px-3">
+ <KindIcon kind={kind} className="size-4 shrink-0 text-muted-foreground" />
+ {/* The name truncates and the meta hides on narrow panes, so the tooltip carries both in full. */}
+ <Tooltip>
+ <TooltipTrigger render={<span className="flex min-w-0 items-baseline gap-2" />}>
+ <Text size="sm" weight="medium" render={<span />} className="min-w-0 truncate">
+ {artifact.name}
+ </Text>
+ <Text
+ size="xs"
+ variant="muted"
+ render={<span />}
+ className="hidden shrink-0 tabular-nums @[40rem]/main-content:inline"
+ >
+ {`${formatArtifactSize(artifact.size)} · ${dayjs(artifact.uploaded_at).fromNow()}`}
+ </Text>
+ </TooltipTrigger>
+ <TooltipContent>
+ {`${artifact.name} · ${formatArtifactSize(artifact.size)} · ${dayjs(artifact.uploaded_at).format('MMM D, YYYY HH:mm')}`}
+ </TooltipContent>
</Tooltip>
+ {versioned && selectedFile && <VersionSelect taskId={taskId} file={selectedFile} />}
{kind === 'html' && (
- <Tooltip title="This page runs in a sandbox with scripts off. It cannot read your PostHog data, cookies or session.">
- <LemonTag type="muted" icon={<IconLock />}>
+ <Tooltip>
+ <TooltipTrigger render={<Badge className="shrink-0" />}>
+ <IconLock />
Sandboxed
- </LemonTag>
+ </TooltipTrigger>
+ <TooltipContent>
+ This page runs with scripts off and no network. It can't read your PostHog data, cookies or
+ session.
+ </TooltipContent>
</Tooltip>
)}
<div className="ml-auto flex shrink-0 items-center gap-1">
+ {hasRenderedForm && (
+ <ToggleGroup
+ variant="outline"
+ value={[mode]}
+ onValueChange={(value: string[]) => value[0] && onModeChange(value[0] as PreviewMode)}
+ aria-label="View"
+ className="mr-1"
+ >
+ <ToggleGroupItem value="rendered" data-attr="task-artifact-view-rendered">
+ Preview
+ </ToggleGroupItem>
+ <ToggleGroupItem value="source" data-attr="task-artifact-view-source">
+ Source
+ </ToggleGroupItem>
+ </ToggleGroup>
+ )}
+ {isTextPreview(kind) && <CopySourceAction text={selectedText?.text ?? null} />}
{/* The file list replaces these once there is room for it. */}
- <span className="flex items-center gap-1 @[52rem]/main-content:hidden">
- <span className="px-1 text-xs text-secondary tabular-nums">{`${selectedIndex + 1} of ${files.length}`}</span>
- <LemonButton
- size="small"
- icon={<IconChevronLeft />}
- tooltip="Previous file"
+ <div className="flex items-center gap-1 @[52rem]/main-content:hidden">
+ <Text size="xs" variant="muted" render={<span />} className="px-1 tabular-nums">
+ {`${selectedIndex + 1} of ${files.length}`}
+ </Text>
+ <IconAction
+ label="Previous file"
disabledReason={single ? 'This is the only file' : undefined}
onClick={() => stepArtifact(-1)}
- />
- <LemonButton
- size="small"
- icon={<IconChevronRight />}
- tooltip="Next file"
+ dataAttr="task-artifact-previous"
+ >
+ <IconChevronLeft className="size-4" />
+ </IconAction>
+ <IconAction
+ label="Next file"
disabledReason={single ? 'This is the only file' : undefined}
onClick={() => stepArtifact(1)}
- />
- </span>
- <LemonButton
- size="small"
- icon={<IconDownload />}
- tooltip="Download"
- to={downloadUrl ?? undefined}
- disableClientSideRouting
+ dataAttr="task-artifact-next"
+ >
+ <IconChevronRight className="size-4" />
+ </IconAction>
+ </div>
+ <IconAction
+ label={versioned ? 'Download this version' : 'Download'}
+ href={downloadUrl ?? undefined}
disabledReason={downloadUrl ? undefined : 'The file is not ready yet'}
onClick={() => downloadArtifact(artifact)}
- data-attr="task-artifact-download"
- />
+ dataAttr="task-artifact-download"
+ >
+ <IconDownload className="size-4" />
+ </IconAction>
+ <IconAction
+ label={expanded ? 'Exit full page' : 'Open full page'}
+ onClick={() => onExpandedChange(!expanded)}
+ dataAttr={expanded ? 'task-artifact-collapse' : 'task-artifact-expand'}
+ >
+ {expanded ? <IconCollapse45 className="size-4" /> : <IconExpand45 className="size-4" />}
+ </IconAction>
</div>
</div>
)
}
+function PreviewSurface({ taskId, mode }: { taskId: string; mode: PreviewMode }): JSX.Element {
+ const { selectedKind } = useValues(taskRunArtifactsLogic({ taskId }))
+ const fills = mode === 'rendered' && (selectedKind === 'html' || selectedKind === 'image')
+ return (
+ <div className={cn('min-h-0 flex-1 bg-surface-tertiary', fills ? 'flex flex-col' : 'overflow-y-auto')}>
+ <ArtifactPreview taskId={taskId} mode={mode} />
+ </div>
+ )
+}
+
function ArtifactsWorkspace({ taskId }: { taskId: string }): JSX.Element {
- const { artifacts, selectedArtifact, selectedKind } = useValues(taskRunArtifactsLogic({ taskId }))
+ const { files, selectedArtifact } = useValues(taskRunArtifactsLogic({ taskId }))
const { setActiveTab } = useActions(taskRunArtifactsLogic({ taskId }))
- if (artifacts.length === 0 || !selectedArtifact) {
+ const [mode, setMode] = useState<PreviewMode>('rendered')
+ const [expanded, setExpanded] = useState(false)
+ // A new file opens in its rendered form, whatever the last file showed.
+ useEffect(() => setMode('rendered'), [selectedArtifact?.id])
+
+ if (files.length === 0 || !selectedArtifact) {
return (
- <div className="flex flex-1 flex-col items-center justify-center gap-2 px-6 py-16 text-center">
- <span className="flex size-10 items-center justify-center rounded-full bg-surface-secondary text-xl text-secondary">
- <IconDocument />
- </span>
- <h3 className="mb-0 text-base font-semibold">No artifacts yet</h3>
- <p className="mb-2 max-w-sm text-sm text-secondary">
- Files that the agent writes in this task show here. Ask it for a report, a chart, a CSV or an HTML
- page.
- </p>
- <LemonButton type="secondary" size="small" onClick={() => setActiveTab('conversation')}>
- Go to the conversation
- </LemonButton>
- </div>
+ <Empty className="flex-1">
+ <EmptyHeader>
+ <EmptyMedia variant="icon">
+ <IconDocument />
+ </EmptyMedia>
+ <EmptyTitle>No artifacts yet</EmptyTitle>
+ <EmptyDescription>
+ Files that the agent writes in this task show here. Ask it for a report, a chart, a CSV or an
+ HTML page.
+ </EmptyDescription>
+ </EmptyHeader>
+ <EmptyContent>
+ <Button variant="outline" onClick={() => setActiveTab('conversation')}>
+ Go to the conversation
+ </Button>
+ </EmptyContent>
+ </Empty>
)
}
+ const toolbar = (
+ <ArtifactToolbar
+ taskId={taskId}
+ artifact={selectedArtifact}
+ mode={mode}
+ onModeChange={setMode}
+ expanded={expanded}
+ onExpandedChange={setExpanded}
+ />
+ )
return (
<div className="flex min-h-0 flex-1">
<ArtifactNav taskId={taskId} />
<section className="flex min-w-0 flex-1 flex-col">
- <ArtifactToolbar taskId={taskId} artifact={selectedArtifact} />
- <div
- className={cn(
- 'min-h-0 flex-1 bg-surface-secondary',
- selectedKind === 'html' || selectedKind === 'image' ? 'flex flex-col' : 'overflow-y-auto'
- )}
- >
- <ArtifactPreview taskId={taskId} />
- </div>
+ {toolbar}
+ {!expanded && (
+ <>
+ <OlderVersionNotice taskId={taskId} />
+ <PreviewSurface taskId={taskId} mode={mode} />
+ </>
+ )}
</section>
+ <Dialog open={expanded} onOpenChange={setExpanded}>
+ <DialogContent size="full" showCloseButton={false} className="flex h-full flex-col gap-0 p-0">
+ <DialogTitle className="sr-only">{selectedArtifact.name}</DialogTitle>
+ {/* The toolbar hides parts by container width, so the dialog gets its own container. */}
+ <div className="@container/main-content flex min-h-0 flex-1 flex-col">
+ {toolbar}
+ <OlderVersionNotice taskId={taskId} />
+ <PreviewSurface taskId={taskId} mode={mode} />
+ </div>
+ </DialogContent>
+ </Dialog>
</div>
)
}
@@ -287,29 +626,35 @@ export function TaskRunTabs({ taskId, conversation }: { taskId: string; conversa
const { activeTab, files } = useValues(taskRunArtifactsLogic({ taskId }))
const { setActiveTab } = useActions(taskRunArtifactsLogic({ taskId }))
return (
- <>
- <LemonTabs<TaskRunTab>
- activeKey={activeTab}
- onChange={setActiveTab}
- barClassName="mb-0 px-4"
- tabs={[
- { key: 'conversation', label: 'Conversation', 'data-attr': 'task-run-tab-conversation' },
- {
- key: 'artifacts',
- label: (
- <span className="flex items-center gap-1.5">
- <span>Artifacts</span>
- {files.length > 0 && (
- // The active tab colors its whole label, and a count is not a call to action.
- <span className="font-normal text-secondary! tabular-nums">{files.length}</span>
- )}
- </span>
- ),
- 'data-attr': 'task-run-tab-artifacts',
- },
- ]}
- />
- {activeTab === 'conversation' ? conversation : <ArtifactsWorkspace taskId={taskId} />}
- </>
+ <TooltipProvider>
+ <Tabs
+ value={activeTab}
+ onValueChange={(tab: TaskRunTab) => setActiveTab(tab)}
+ className="flex min-h-0 flex-1 flex-col gap-0"
+ data-quill
+ >
+ <div className="shrink-0 border-b border-border px-4">
+ <TabsList variant="line" aria-label="Task views">
+ <TabsTrigger value="conversation" data-attr="task-run-tab-conversation">
+ Conversation
+ </TabsTrigger>
+ <TabsTrigger value="artifacts" data-attr="task-run-tab-artifacts">
+ Artifacts
+ {files.length > 0 && (
+ <Text size="xs" variant="muted" render={<span />} className="tabular-nums">
+ {files.length}
+ </Text>
+ )}
+ </TabsTrigger>
+ </TabsList>
+ </div>
+ <TabsContent value="conversation" className="flex min-h-0 flex-1 flex-col">
+ {conversation}
+ </TabsContent>
+ <TabsContent value="artifacts" className="flex min-h-0 flex-1 flex-col">
+ <ArtifactsWorkspace taskId={taskId} />
+ </TabsContent>
+ </Tabs>
+ </TooltipProvider>
)
}