: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(tasks): add an artifacts tab to the web task page (#109356)
Shy Alter7395dc336551
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsxnew file mode 100644index 000000000000..154b8c835167--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx@@ -0,0 +1,352 @@+import type { Meta, StoryObj } from '@storybook/react'+import { useActions, useValues } from 'kea'+import { HttpResponse } from 'msw'+import { ReactNode, useEffect } from 'react'++import { FEATURE_FLAGS } from 'lib/constants'+import { urls } from 'scenes/urls'+import { userLogic } from 'scenes/userLogic'++import { SceneLayout } from '~/layout/scenes/SceneLayout'+import { TodayShell } from '~/layout/today/TodayShell'+import { todayShellLogic } from '~/layout/today/todayShellLogic'+import { mswDecorator } from '~/mocks/browser'+import type { MockSignature } from '~/mocks/utils'++import type { TaskRunArtifactResponseApi } from 'products/tasks/frontend/generated/api.schemas'+import { TaskRuntimeEnumApi } from 'products/tasks/frontend/generated/api.schemas'++import { OriginProduct, Task, TaskRun, TaskRunEnvironment, TaskRunStatus } from '../../types/taskTypes'+import { TaskDetailPage } from './components/TaskDetailPage'+import { TaskRunTab } from './taskRunArtifacts'+import { taskRunArtifactsLogic } from './taskRunArtifactsLogic'++const TASK_ID = 'task-trials'+const RUN_ID = 'run-trials'++const REPORT_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. Other steps did not change.++| Step | Week of Sep 14 | Week of Sep 21 |+| --- | --- | --- |+| Pricing | 100% | 100% |+| Plan picker | 62% | 44% |+| Details | 48% | 35% |+| Trial started | 41% | 30% |++## What happened++The release on Tuesday changed the plan picker layout. The start trial button now sits below the fold at 1366 × 768, the most common laptop size in this funnel. Wide screens do not show the drop.++## Why++- Recordings show people scroll the plan table, then leave without a click.+- The drop starts on the day of the release and holds all week.+- Mobile uses a different layout and did not change.++## Next steps++1. Pin the start trial button to the top of the plan table.+2. Run an A/B test on the change for one week.+++`++const CHART_SVG = `<svg xmlns="http://www.w3.org/2000/svg" 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>+<rect x="516" y="28" width="10" height="10" rx="2" fill="#1d4aff"/><text x="532" y="37" font-size="11" fill="#5f5f5f">Week of Sep 21</text>+<g stroke="#e5e5e2"><line x1="64" y1="80" x2="608" y2="80"/><line x1="64" y1="140" x2="608" y2="140"/><line x1="64" y1="200" x2="608" y2="200"/><line x1="64" y1="260" x2="608" y2="260"/><line x1="64" y1="320" x2="608" y2="320"/></g>+<g font-size="10" fill="#8a8a8a" text-anchor="end"><text x="56" y="84">100%</text><text x="56" y="144">75%</text><text x="56" y="204">50%</text><text x="56" y="264">25%</text><text x="56" y="324">0%</text></g>+<g fill="#1d4aff" fill-opacity="0.3"><rect x="96" y="80" width="40" height="240" rx="3"/><rect x="232" y="171" width="40" height="149" rx="3"/><rect x="368" y="205" width="40" height="115" rx="3"/><rect x="504" y="222" width="40" height="98" rx="3"/></g>+<g fill="#1d4aff"><rect x="140" y="80" width="40" height="240" rx="3"/><rect x="276" y="214" width="40" height="106" rx="3"/><rect x="412" y="236" width="40" height="84" rx="3"/><rect x="548" y="248" width="40" height="72" rx="3"/></g>+<g font-size="11" fill="#5f5f5f" text-anchor="middle"><text x="138" y="342">Pricing</text><text x="274" y="342">Plan picker</text><text x="410" y="342">Details</text><text x="546" y="342">Trial started</text></g>+</svg>`++const WEEKS_CSV = `week,trial_starts,conversion+2026-08-31,1204,41%+2026-09-07,1188,40%+2026-09-14,1231,41%+2026-09-21,1009,30%+`++const SUMMARY_HTML = `<!doctype html>+<html>+<head>+<meta charset="utf-8" />+<style>+ body { margin: 0; font-family: Inter, system-ui, sans-serif; color: #151515; background: #fafaf9; }+ main { max-width: 760px; margin: 0 auto; padding: 32px 28px; }+ h1 { font-size: 20px; margin: 0 0 4px; }+ p { color: #5f5f5f; font-size: 13px; margin: 0 0 20px; }+ .step { display: grid; grid-template-columns: 120px 1fr 48px; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 13px; }+ .track { height: 28px; border-radius: 6px; background: #eeeeea; overflow: hidden; }+ .bar { height: 100%; background: #1d4aff; border-radius: 6px; }+ .value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }+ .note { margin-top: 24px; padding: 12px 14px; border-radius: 8px; background: #fff4e5; color: #7a4a00; font-size: 12px; }+</style>+</head>+<body>+<main>+ <h1>Trial funnel, week of Sep 21</h1>+ <p>Share of visitors who reach each step.</p>+ <div class="step"><span>Pricing</span><div class="track"><div class="bar" style="width: 100%"></div></div><span class="value">100%</span></div>+ <div class="step"><span>Plan picker</span><div class="track"><div class="bar" style="width: 44%"></div></div><span class="value">44%</span></div>+ <div class="step"><span>Details</span><div class="track"><div class="bar" style="width: 35%"></div></div><span class="value">35%</span></div>+ <div class="step"><span>Trial started</span><div class="track"><div class="bar" style="width: 30%"></div></div><span class="value">30%</span></div>+ <div class="note">The plan picker step drops from 62% to 44% against the week before.</div>+ <img src="https://example.com/html-pixel.png" alt="" width="1" height="1" />+</main>+</body>+</html>`++const ARTIFACTS: TaskRunArtifactResponseApi[] = [+ {+ id: 'artifact-report',+ name: 'trial-drop-report.md',+ type: 'output',+ source: 'agent_output',+ size: 6144,+ content_type: 'text/markdown',+ storage_path: 'tasks/artifacts/artifact-report',+ uploaded_at: '2026-09-28T18:18:00Z',+ uploaded_by: 'agent',+ },+ {+ id: 'artifact-summary',+ name: 'trial-funnel-summary.html',+ type: 'output',+ source: 'agent_output',+ size: 4096,+ content_type: 'text/html',+ storage_path: 'tasks/artifacts/artifact-summary',+ uploaded_at: '2026-09-28T18:16:00Z',+ uploaded_by: 'agent',+ },+ {+ id: 'artifact-chart',+ name: 'trial-starts-by-step.svg',+ type: 'output',+ source: 'agent_output',+ size: 8192,+ content_type: 'image/svg+xml',+ storage_path: 'tasks/artifacts/artifact-chart',+ uploaded_at: '2026-09-28T18:14:00Z',+ uploaded_by: 'agent',+ },+ {+ id: 'artifact-csv',+ name: 'trial-starts-by-week.csv',+ type: 'output',+ source: 'agent_output',+ size: 3072,+ content_type: 'text/csv',+ storage_path: 'tasks/artifacts/artifact-csv',+ uploaded_at: '2026-09-28T18:13:00Z',+ uploaded_by: 'agent',+ },+]++const CONTENT_BY_PATH: Record<string, string> = {+ 'tasks/artifacts/artifact-report': REPORT_MARKDOWN,+ 'tasks/artifacts/artifact-summary': SUMMARY_HTML,+ 'tasks/artifacts/artifact-csv': WEEKS_CSV,+}++function mockRun(artifacts: TaskRunArtifactResponseApi[]): TaskRun {+ return {+ id: RUN_ID,+ task: TASK_ID,+ stage: null,+ branch: null,+ status: TaskRunStatus.COMPLETED,+ environment: TaskRunEnvironment.CLOUD,+ runtime_adapter: null,+ model: 'claude-opus-5-5',+ reasoning_effort: 'high',+ log_url: null,+ error_message: null,+ output: null,+ task_summary: null,+ task_tags: [],+ state: {},+ artifacts,+ created_at: '2026-09-28T17:42:00Z',+ updated_at: '2026-09-28T18:19:00Z',+ completed_at: '2026-09-28T18:19:00Z',+ } as TaskRun+}++function mockTask(run: TaskRun): Task {+ return {+ id: TASK_ID,+ task_number: 12,+ slug: 'TASK-12',+ title: 'Investigate the drop in trial starts',+ description: 'Trial starts dropped last week. Find the step where people leave and write it up for the team.',+ origin_product: OriginProduct.USER_CREATED,+ runtime: TaskRuntimeEnumApi.Acp,+ repository: null,+ github_integration: null,+ signal_report: null,+ json_schema: null,+ internal: false,+ latest_run: run,+ created_at: '2026-09-28T17:42:00Z',+ updated_at: '2026-09-28T18:19:00Z',+ created_by: { id: 1, uuid: 'user-uuid', distinct_id: 'user-1', first_name: 'Ada', email: '[email protected]' },+ } as Task+}++function logLine(update: Record<string, unknown>, timestamp: string): string {+ return JSON.stringify({+ type: 'notification',+ timestamp,+ notification: { method: 'session/update', params: { update } },+ })+}++const RUN_LOGS = [+ logLine(+ {+ sessionUpdate: 'user_message_chunk',+ content: {+ type: 'text',+ text: 'Trial starts dropped last week. Find the step where people leave and write it up for the team.',+ },+ },+ '2026-09-28T17:42:00Z'+ ),+ logLine(+ {+ sessionUpdate: 'tool_call',+ toolCallId: 'call-query',+ title: 'Run SQL query',+ status: 'completed',+ rawInput: { query: 'SELECT step, count() FROM trial_funnel GROUP BY step' },+ },+ '2026-09-28T17:50:00Z'+ ),+ logLine(+ {+ sessionUpdate: 'agent_message',+ content: {+ type: 'text',+ text: 'Trial starts fell 18% week over week. Almost all of the loss is at the plan picker step, which changed in the release on Tuesday. The new layout pushes the start trial button below the fold on laptop screens.\n\nI wrote a short report, an interactive funnel explorer, a chart of each step, and the weekly numbers as a CSV. Open the **Artifacts** tab to see them.',+ },+ },+ '2026-09-28T18:19:00Z'+ ),+].join('\n')++function taskMocks(artifacts: TaskRunArtifactResponseApi[]): {+ get: Record<string, MockSignature>+ post: Record<string, MockSignature>+} {+ const run = mockRun(artifacts)+ const task = mockTask(run)+ return {+ get: {+ '/api/code/invites/check-access/': { has_access: true, has_loops_access: false },+ '/api/projects/:team_id/tasks/': ({ request }: { request: Request }) => {+ const results = new URL(request.url).searchParams.get('pinned') ? [] : [task]+ return [200, { results, count: results.length, next: null, previous: null }]+ },+ [`/api/projects/:team_id/tasks/${TASK_ID}/`]: task,+ [`/api/projects/:team_id/tasks/${TASK_ID}/runs/`]: { count: 1, next: null, previous: null, results: [run] },+ [`/api/projects/:team_id/tasks/${TASK_ID}/runs/${RUN_ID}/`]: run,+ [`/api/projects/:team_id/tasks/${TASK_ID}/runs/${RUN_ID}/logs`]: () => new HttpResponse(RUN_LOGS),+ [`/api/projects/:team_id/tasks/${TASK_ID}/runs/${RUN_ID}/artifacts/artifact-chart/download/`]: () =>+ new HttpResponse(CHART_SVG, { headers: { 'Content-Type': 'image/svg+xml' } }),+ '/api/projects/:team_id/task_channels/': [],+ '/api/projects/:team_id/integrations/': { results: [] },+ '/api/environments/:team_id/conversations/': { results: [], next: null },+ },+ post: {+ [`/api/projects/:team_id/tasks/${TASK_ID}/runs/${RUN_ID}/artifacts/download/`]: async ({+ request,+ }: {+ request: Request+ }) => {+ const { storage_path } = (await request.json()) as { storage_path: string }+ return new HttpResponse(CONTENT_BY_PATH[storage_path] ?? '', {+ headers: { 'Content-Type': 'text/plain' },+ })+ },+ },+ }+}++function TodayWebLayout({ children }: { children: ReactNode }): JSX.Element {+ const { pickPane } = useActions(todayShellLogic)+ const { user } = useValues(userLogic)+ useEffect(() => {+ pickPane('spaces')+ }, [pickPane])+ return (+ <div className="TodayAppLayout Today flex h-screen w-full overflow-hidden bg-surface-tertiary">+ {user ? <TodayShell className="left-nav" /> : null}+ <div className="@container/main-content-container main-content-container relative m-1 ml-0 flex min-w-0 flex-1 overflow-hidden rounded border border-primary">+ <main className="@container/main-content flex h-full flex-1 flex-col overflow-x-hidden overflow-y-auto rounded-t bg-[var(--color-bg-primary)] p-0">+ <SceneLayout sceneConfig={{ layout: 'app-raw-no-header', name: 'Max', projectBased: true }}>+ <div className="flex h-full grow flex-col overflow-hidden">{children}</div>+ </SceneLayout>+ </main>+ </div>+ </div>+ )+}++function StoryPage({ tab = 'artifacts', artifactId }: { tab?: TaskRunTab; artifactId?: string }): JSX.Element {+ const { setActiveTab, selectArtifact } = useActions(taskRunArtifactsLogic({ taskId: TASK_ID }))+ useEffect(() => {+ if (artifactId) {+ selectArtifact(artifactId)+ }+ setActiveTab(tab)+ }, [tab, artifactId, setActiveTab, selectArtifact])+ return (+ <TodayWebLayout>+ <TaskDetailPage taskId={TASK_ID} isMobile={false} />+ </TodayWebLayout>+ )+}++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))],+ parameters: {+ layout: 'fullscreen',+ viewMode: 'story',+ mockDate: '2026-09-28 18:30:00',+ pageUrl: urls.aiTask(TASK_ID),+ featureFlags: [FEATURE_FLAGS.TODAY_RAIL_NAV, FEATURE_FLAGS.TASKS],+ },+}+export default meta++type Story = StoryObj<{}>++export const MarkdownReport: Story = { render: () => <StoryPage artifactId="artifact-report" /> }++export const SandboxedHtml: Story = { render: () => <StoryPage artifactId="artifact-summary" /> }++export const Image: Story = { render: () => <StoryPage artifactId="artifact-chart" /> }++export const Csv: Story = { render: () => <StoryPage artifactId="artifact-csv" /> }++export const ConversationTab: Story = { render: () => <StoryPage tab="conversation" /> }++export const NoArtifacts: Story = {+ decorators: [mswDecorator(taskMocks([]))],+ render: () => <StoryPage />,+}++export const FlagOff: Story = {+ parameters: { featureFlags: [FEATURE_FLAGS.TASKS] },+ render: () => <StoryPage tab="conversation" />,+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/artifactHtml.test.ts b/products/posthog_ai/frontend/scenes/TaskTracker/artifactHtml.test.tsnew file mode 100644index 000000000000..237ae0c7d598--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/artifactHtml.test.ts@@ -0,0 +1,19 @@+import { ARTIFACT_HTML_CSP, withStrictCsp } from './artifactHtml'++describe('withStrictCsp', () => {+ test.each([+ [+ 'a full document',+ '<!doctype html><html><head><title>x</title></head><body><img src="https://example.com/a.png"></body></html>',+ ],+ ['a head tag inside a comment', '<!-- <head> --><img src="https://example.com/a.png">'],+ ['a head tag inside a title', '<title><head></title><img src="https://example.com/a.png">'],+ ['a head tag inside a script', '<script>"<head>"</script><img src="https://example.com/a.png">'],+ ['a fragment', '<p>Hello</p><img src="https://example.com/a.png">'],+ ])('the policy is the first element of the parsed head for %s', (_, html) => {+ const doc = new DOMParser().parseFromString(withStrictCsp(html), 'text/html')+ const first = doc.head.firstElementChild+ expect(first?.getAttribute('http-equiv')).toBe('Content-Security-Policy')+ expect(first?.getAttribute('content')).toBe(ARTIFACT_HTML_CSP)+ })+})diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/artifactHtml.ts b/products/posthog_ai/frontend/scenes/TaskTracker/artifactHtml.tsnew file mode 100644index 000000000000..140b461a5363--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/artifactHtml.ts@@ -0,0 +1,12 @@+// A sandbox stops scripts but not subresources, so the policy keeps the page from fetching anything.+export const ARTIFACT_HTML_CSP =+ "default-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; form-action 'none'"++/**+ * Wraps untrusted HTML so the policy is the first thing the parser reads. The policy never goes inside the+ * untrusted text: a `<head>` in a comment, a title or a script would put it where the browser ignores it.+ * A second doctype, `html` or `head` later in the text is dropped by the parser, so the trusted head stays.+ */+export function withStrictCsp(html: string): string {+ return `<!doctype html><html><head><meta http-equiv="Content-Security-Policy" content="${ARTIFACT_HTML_CSP}"></head><body>${html}</body></html>`+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsxindex 898327e21d50..be1ba46fb722 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx@@ -4,6 +4,7 @@ import { IconExternal, IconGithub, IconPlay } from '@posthog/icons'import { LemonButton } from '@posthog/lemon-ui'import { NotFound } from 'lib/components/NotFound'+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { urls } from 'scenes/urls'import { nextTaskTitle } from '../../../lib/task-title'@@ -11,6 +12,7 @@ import { isPiTaskRuntime } from '../../../types/taskTypes'import { taskDetailSceneLogic } from '../taskDetailSceneLogic'import { taskTrackerSceneLogic } from '../taskTrackerSceneLogic'import { TaskHeaderActionsSkeleton } from './taskDetailSkeletons'+import { TaskRunTabs } from './TaskRunArtifacts'import { TaskRunLog } from './TaskRunLog'import { TaskRunSceneShell } from './TaskRunSceneShell'@@ -27,6 +29,7 @@ export function TaskDetailPage({ taskId, isMobile, titleActions }: TaskDetailPagconst { runTask, deleteTask, loadTask, updateTask } = useActions(sceneLogic)const { activeCreation, hasDesktopAccess } = useValues(taskTrackerSceneLogic)const isActiveCreation = activeCreation?.taskId === taskId+ const artifactsTabEnabled = useFeatureFlag('TODAY_RAIL_NAV')if (taskNotFound && !task) {return <NotFound object="task" />@@ -97,6 +100,16 @@ export function TaskDetailPage({ taskId, isMobile, titleActions }: TaskDetailPagconst optimisticStreamKey = isActiveCreation ? activeCreation?.streamKey : undefinedconst optimisticRunId = isActiveCreation ? activeCreation?.runId : undefined+ const runLog = (+ <TaskRunLog+ taskId={taskId}+ optimisticStreamKey={optimisticStreamKey}+ optimisticRunId={optimisticRunId}+ interactionKey={isActiveCreation ? activeCreation?.interactionKey : undefined}+ autoFocus={isActiveCreation && activeCreation?.composerWasFocused}+ />+ )+return (<TaskRunSceneShelltask={task}@@ -114,13 +127,7 @@ export function TaskDetailPage({ taskId, isMobile, titleActions }: TaskDetailPagonRetry={loadTask}isMobile={isMobile}>- <TaskRunLog- taskId={taskId}- optimisticStreamKey={optimisticStreamKey}- optimisticRunId={optimisticRunId}- interactionKey={isActiveCreation ? activeCreation?.interactionKey : undefined}- autoFocus={isActiveCreation && activeCreation?.composerWasFocused}- />+ {artifactsTabEnabled ? <TaskRunTabs taskId={taskId} conversation={runLog} /> : runLog}</TaskRunSceneShell>)}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsxnew file mode 100644index 000000000000..48be70a63924--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx@@ -0,0 +1,312 @@+import { useActions, useValues } from 'kea'+import { useEffect, useMemo } from 'react'++import {+ IconChevronLeft,+ IconChevronRight,+ IconCode,+ IconDatabase,+ IconDocument,+ IconDownload,+ IconImage,+ IconLock,+} from '@posthog/icons'+import { LemonButton, LemonTable, LemonTabs, LemonTag, Spinner, Tooltip } from '@posthog/lemon-ui'++import { dayjs } from 'lib/dayjs'+import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'+import { cn } from 'lib/utils/css-classes'++import type { TaskRunArtifactResponseApi } from 'products/tasks/frontend/generated/api.schemas'++import { withStrictCsp } from '../artifactHtml'+import {+ ARTIFACT_KIND_LABEL,+ ArtifactPreviewKind,+ TaskRunTab,+ artifactPreviewKind,+ formatArtifactSize,+ parseCsv,+} from '../taskRunArtifacts'+import { artifactDownloadUrl, taskRunArtifactsLogic } from '../taskRunArtifactsLogic'++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 />+}++/**+ * Agent-written HTML is untrusted. An empty `sandbox` gives the document an opaque origin with scripts,+ * forms, popups and top navigation all off, so it cannot reach the app's cookies, storage or DOM.+ */+function SandboxedHtmlFrame({ html, name }: { html: string; name: string }): JSX.Element {+ return (+ <iframe+ className="size-full border-0 bg-white"+ sandbox=""+ referrerPolicy="no-referrer"+ srcDoc={withStrictCsp(html)}+ title={`Preview of ${name}`}+ />+ )+}++function CsvPreview({ text }: { text: string }): JSX.Element {+ const { header, rows, truncated } = useMemo(() => {+ const [first = [], ...rest] = parseCsv(text)+ return { header: first, rows: rest.slice(0, MAX_CSV_ROWS), truncated: rest.length > MAX_CSV_ROWS }+ }, [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>,+ }))}+ />+ {truncated && (+ <span className="text-xs text-secondary">{`Showing the first ${MAX_CSV_ROWS} rows. Download the file to see all of them.`}</span>+ )}+ </div>+ )+}++function ArtifactPreview({ taskId }: { taskId: string }): JSX.Element | null {+ const { selectedArtifact, selectedKind, selectedText, selectedRun, currentProjectId, artifactTextLoading } =+ useValues(taskRunArtifactsLogic({ taskId }))+ const { ensureSelectedText, loadArtifactText } = useActions(taskRunArtifactsLogic({ taskId }))+ useEffect(() => {+ ensureSelectedText()+ }, [selectedArtifact?.id, selectedRun?.id, currentProjectId, ensureSelectedText])+ if (!selectedArtifact || !selectedKind) {+ return null+ }+ if (selectedKind === 'image') {+ const src = artifactDownloadUrl(currentProjectId, selectedRun, selectedArtifact)+ return (+ <div className="flex min-h-full items-center justify-center p-8">+ {src && (+ <img+ src={src}+ alt={selectedArtifact.name}+ className="max-w-full rounded border border-primary bg-white"+ />+ )}+ </div>+ )+ }+ 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>+ )+ }+ if (!selectedText) {+ return (+ <div className="flex min-h-full items-center justify-center p-8">+ <Spinner className="text-2xl" />+ </div>+ )+ }+ 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>+ )+ }+ if (selectedKind === 'html') {+ return <SandboxedHtmlFrame html={selectedText.text} name={selectedArtifact.name} />+ }+ if (selectedKind === 'csv') {+ return <CsvPreview text={selectedText.text} />+ }+ 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">+ <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>+}++function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {+ const { artifacts, selectedArtifact } = useValues(taskRunArtifactsLogic({ taskId }))+ const { selectArtifact } = useActions(taskRunArtifactsLogic({ taskId }))+ return (+ <nav+ className="hidden w-64 shrink-0 flex-col gap-px overflow-y-auto border-r border-primary p-2 @[52rem]/main-content:flex"+ aria-label="Artifacts"+ >+ <span className="py-1 pl-2 text-xs font-semibold text-secondary">{`Files ${artifacts.length}`}</span>+ {artifacts.map((artifact) => {+ const kind = artifactPreviewKind(artifact)+ return (+ <LemonButton+ key={artifact.id}+ fullWidth+ size="small"+ active={artifact.id === selectedArtifact?.id}+ icon={<KindIcon kind={kind} />}+ onClick={() => artifact.id && selectArtifact(artifact.id)}+ 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">+ {`${ARTIFACT_KIND_LABEL[kind]} · ${formatArtifactSize(artifact.size)}`}+ </span>+ </span>+ </LemonButton>+ )+ })}+ </nav>+ )+}++function ArtifactToolbar({ taskId, artifact }: { taskId: string; artifact: TaskRunArtifactResponseApi }): JSX.Element {+ const { artifacts, selectedIndex, selectedRun, currentProjectId } = useValues(taskRunArtifactsLogic({ taskId }))+ const { stepArtifact, downloadArtifact } = useActions(taskRunArtifactsLogic({ taskId }))+ const kind = artifactPreviewKind(artifact)+ const downloadUrl = artifactDownloadUrl(currentProjectId, selectedRun, artifact)+ const single = artifacts.length < 2+ return (+ <div className="flex shrink-0 flex-wrap items-center gap-2 border-b border-primary px-3 py-1.5">+ <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>+ <span className="text-xs text-secondary">+ {`${formatArtifactSize(artifact.size)} · ${dayjs(artifact.uploaded_at).fromNow()}`}+ </span>+ {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 />}>+ Sandboxed+ </LemonTag>+ </Tooltip>+ )}+ <div className="ml-auto flex items-center gap-1">+ <span className="px-1 text-xs text-secondary tabular-nums">{`${selectedIndex + 1} of ${artifacts.length}`}</span>+ <LemonButton+ size="small"+ icon={<IconChevronLeft />}+ tooltip="Previous file"+ disabledReason={single ? 'This is the only file' : undefined}+ onClick={() => stepArtifact(-1)}+ />+ <LemonButton+ size="small"+ icon={<IconChevronRight />}+ tooltip="Next file"+ disabledReason={single ? 'This is the only file' : undefined}+ onClick={() => stepArtifact(1)}+ />+ <LemonButton+ size="small"+ icon={<IconDownload />}+ tooltip="Download"+ to={downloadUrl ?? undefined}+ disableClientSideRouting+ disabledReason={downloadUrl ? undefined : 'The file is not ready yet'}+ onClick={() => downloadArtifact(artifact)}+ data-attr="task-artifact-download"+ />+ </div>+ </div>+ )+}++function ArtifactsWorkspace({ taskId }: { taskId: string }): JSX.Element {+ const { artifacts, selectedArtifact, selectedKind } = useValues(taskRunArtifactsLogic({ taskId }))+ const { setActiveTab } = useActions(taskRunArtifactsLogic({ taskId }))+ if (artifacts.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>+ )+ }+ 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' ? 'flex flex-col' : 'overflow-y-auto'+ )}+ >+ <ArtifactPreview taskId={taskId} />+ </div>+ </section>+ </div>+ )+}++/** Conversation and Artifacts tabs for a task run. The caller renders the thread as `conversation`. */+export function TaskRunTabs({ taskId, conversation }: { taskId: string; conversation: JSX.Element }): JSX.Element {+ const { activeTab, artifacts } = 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>+ {artifacts.length > 0 && <span className="text-secondary">{artifacts.length}</span>}+ </span>+ ),+ 'data-attr': 'task-run-tab-artifacts',+ },+ ]}+ />+ {activeTab === 'conversation' ? conversation : <ArtifactsWorkspace taskId={taskId} />}+ </>+ )+}