import { useState } from 'react';
import { Meta, StoryObj } from '@storybook/react-vite';
import { AgentInbox, AgentTask } from './AgentInbox';
import './agent-inbox-story.css';
const names = (count: number) =>
Array.from({ length: count }, (_, index) => `ACME Site ${index + 1}`);
const TASKS: AgentTask[] = [
// Autopilot
{
agent: 'Opus 5.5',
description:
'The update left drupal/core-recommended pinned to a version that does not exist, so the build failed. A fix is ready in composer.json and composer.lock.',
id: 'ironwood-fix',
sites: ['ACME Ironwood Athletics'],
sourceCount: 14,
status: 'waiting',
steps: [
{ label: 'Read the build log', time: '9m ago' },
{ label: 'Forked a sandbox', time: '8m ago' },
{ label: 'Isolated the root cause', time: '5m ago' },
{ label: 'Verified the fix in the sandbox', time: '2m ago' },
],
subtitle: 'Autopilot',
time: '9m 12s',
title: 'Fix the failed update',
toolCount: 11,
},
{
agent: 'Sonnet 5.5',
description:
'Visual tests flagged 3 pages with layout shifts after the theme update. Comparing before and after to separate real regressions from font loading.',
id: 'campus-vrt',
sites: ['ACME Campus Theme'],
sourceCount: 36,
status: 'running',
steps: [
{ label: 'Pulled the before and after screenshots', time: '4m ago' },
{ label: 'Diffed 36 pages', time: '2m ago' },
],
subtitle: 'Autopilot',
time: '4m 40s',
title: 'Check the visual regression after the theme update',
toolCount: 8,
},
{
agent: 'Opus 5.5',
description:
'The investigation stopped before it could finish, so there is no fix to review.',
id: 'harbor-updates',
sites: ['ACME Harbor Museum'],
status: 'failed',
steps: [
{ label: 'Read the build log', time: '12m ago' },
{ label: 'Forked a sandbox', time: '11m ago' },
{ label: 'The sandbox stopped responding', time: '10m ago' },
],
subtitle: 'Autopilot',
title: 'Find out why updates stopped applying',
toolCount: 3,
},
// Advanced Edge
{
agent: 'Opus 5.5',
description:
'Blocked requests rose from about 200 to 41,000 an hour, mostly from 3 networks. Proposing an ASN blocklist for them.',
id: 'edge-403',
sites: names(3),
sourceCount: 5200,
status: 'waiting',
steps: [
{ label: 'Grouped blocked requests by network', time: '14m ago' },
{
label: 'Checked the 3 networks against known crawlers',
time: '9m ago',
},
{ label: 'Drafted the ASN blocklist rule', time: '3m ago' },
],
subtitle: 'Advanced Edge',
time: '18m 05s',
title: 'Investigate the 403 spike on /wp-login.php',
toolCount: 9,
},
{
agent: 'Sonnet 5.5',
description:
'Cookies set on /events/* vary the cache key. Testing which cookie it is.',
id: 'edge-cache',
sites: names(2),
sourceCount: 2400,
status: 'running',
steps: [
{ label: 'Compared cache keys before and after Tuesday', time: '6m ago' },
{ label: 'Found cookies on /events/*', time: '3m ago' },
],
subtitle: 'Advanced Edge',
time: '7m 30s',
title: 'Find why the cache hit rate fell from 91% to 58%',
toolCount: 14,
},
{
agent: 'Haiku 5.5',
description:
'Could not read the last 24 hours of edge logs, so it cannot confirm real customers are not blocked.',
id: 'edge-geo',
sites: ['ACME Coastal Clinic'],
status: 'failed',
steps: [
{ label: 'Listed the countries on the blocklist', time: '5m ago' },
{ label: 'Edge logs unavailable for the last 24 hours', time: '4m ago' },
],
subtitle: 'Advanced Edge',
title: 'Test the new geo blocklist against checkout traffic',
toolCount: 2,
},
// Insights
{
agent: 'Opus 5.5',
description:
'Visits are down 34% week over week. Comparing referrers, top pages and bot share; one landing page lost its organic search traffic.',
id: 'insights-drop',
sites: ['ACME Harbor Museum'],
sourceCount: 18,
status: 'running',
steps: [
{ label: 'Compared visits by referrer', time: '5m ago' },
{ label: 'Excluded bot traffic', time: '3m ago' },
{ label: 'Found one landing page with a 90% drop', time: '1m ago' },
],
subtitle: 'Insights',
time: '5m 52s',
title: 'Explain the traffic drop',
toolCount: 6,
},
{
agent: 'Sonnet 5.5',
description:
'12 URLs return 404 after the migration, and 7 have an obvious redirect target. Redirects for those 7 are drafted.',
id: 'insights-404',
sites: ['ACME Corporate Site'],
sourceCount: 12,
status: 'waiting',
steps: [
{ label: 'Listed pages returning 404', time: '8m ago' },
{ label: 'Matched them to the new URLs', time: '5m ago' },
{ label: 'Drafted 7 redirects', time: '2m ago' },
],
subtitle: 'Insights',
time: '8m 14s',
title: 'Fix the 404s after the migration',
toolCount: 5,
},
{
agent: 'Sonnet 5.5',
description:
'Summarized traffic, cache and errors across 24 sites. 3 sites are flagged for review.',
id: 'insights-weekly',
sites: names(24),
sourceCount: 24,
status: 'done',
steps: [
{ label: 'Pulled last week for 24 sites', time: '1h ago' },
{ label: 'Flagged 3 sites with unusual error rates', time: '1h ago' },
{ label: 'Wrote the summary', time: '1h ago' },
],
subtitle: 'Insights',
time: '3m 10s',
title: 'Weekly report',
toolCount: 4,
},
// Site dashboard
{
agent: 'Opus 5.5',
description:
'Response time rose from 2.1s to 5.4s after the last deploy. Traced a slow database query to a plugin.',
id: 'dash-slow',
sites: ['ACME Corporate Site'],
sourceCount: 9,
status: 'running',
steps: [
{ label: 'Compared response times around the deploy', time: '7m ago' },
{ label: 'Profiled the slowest requests', time: '4m ago' },
{ label: 'Traced a slow query to a plugin', time: '1m ago' },
],
subtitle: 'Site dashboard',
time: '8m 21s',
title: 'Diagnose the slow Live environment',
toolCount: 13,
},
{
agent: 'Haiku 5.5',
description:
'The certificate expires in 6 days, and a DNS CAA record blocks renewal. You need to change the record.',
id: 'dash-cert',
sites: ['ACME Coastal Clinic'],
status: 'waiting',
steps: [
{ label: 'Checked the certificate expiry', time: '20m ago' },
{ label: 'Found a CAA record that blocks renewal', time: '19m ago' },
],
subtitle: 'Site dashboard',
time: '20m 03s',
title: 'Renew the certificate on acme-coastal-clinic.org',
toolCount: 3,
},
{
agent: 'Sonnet 5.5',
description:
'The files backup exceeded the size limit. Excluded a cache folder and ready to retry.',
id: 'dash-backup',
sites: ['ACME Thistledown Gardens'],
status: 'failed',
steps: [
{ label: 'Read the backup log', time: '30m ago' },
{ label: 'Found a 4 GB cache folder', time: '29m ago' },
{ label: 'Backup failed: size limit exceeded', time: '28m ago' },
],
subtitle: 'Site dashboard',
title: 'Restore the nightly backup',
toolCount: 4,
},
];
const meta: Meta<typeof AgentInbox> = {
tags: ['new-pattern', 'in-progress'],
title: 'Component Proposals/Agent Inbox',
component: AgentInbox,
parameters: {
layout: 'padded',
docs: {
description: {
component:
'**New pattern:** not in PDS v2 today. Every task your agents are working on, grouped by what it needs from you: Needs you, Running and Done. A card opens in place to show the last steps and the decisions you can make. First sketch for ideation, not ready for review.',
},
},
},
argTypes: {
className: { table: { category: 'Base attributes' } },
defaultView: {
control: 'inline-radio',
options: ['board', 'list'],
table: { category: 'Layout' },
},
labelStrings: { control: 'object', table: { category: 'Content' } },
lanes: {
control: 'check',
options: ['needs', 'running', 'done'],
table: { category: 'Layout' },
},
onApprove: { table: { category: 'Events' } },
onOpen: { table: { category: 'Events' } },
onReject: { table: { category: 'Events' } },
onRetry: { table: { category: 'Events' } },
onViewChange: { table: { category: 'Events' } },
tasks: { control: 'object', table: { category: 'Content' } },
},
args: { tasks: TASKS },
};
export default meta;
type Story = StoryObj<typeof AgentInbox>;
// The consumer owns the decisions, so the story keeps the tasks in state and
// moves a task to its new lane when you decide.
const InteractiveInbox = (args: React.ComponentProps<typeof AgentInbox>) => {
const [tasks, setTasks] = useState(args.tasks);
const set = (id: string, status: AgentTask['status'], label: string) =>
setTasks((all) =>
all.map((t) =>
t.id === id
? {
...t,
status,
steps: [...(t.steps ?? []), { label, time: 'now' }],
}
: t,
),
);
return (
<AgentInbox
{...args}
onApprove={(t) => set(t.id, 'running', 'You approved, continuing')}
onOpen={() => undefined}
onReject={(t) => set(t.id, 'failed', 'You rejected the request')}
onRetry={(t) => set(t.id, 'running', 'Retrying')}
tasks={tasks}
/>
);
};
export const Board: Story = {
render: (args) => <InteractiveInbox {...args} />,
};
export const List: Story = {
args: { defaultView: 'list' },
render: (args) => <InteractiveInbox {...args} />,
};
export const NarrowContainer: Story = {
name: 'Narrow container (drawer width)',
render: (args) => (
<div className='agent-inbox-story__narrow'>
<InteractiveInbox {...args} />
</div>
),
};
export const NeedsYouOnly: Story = {
args: { lanes: ['needs'] },
render: (args) => <InteractiveInbox {...args} />,
};
export const EmptyLanes: Story = {
args: { tasks: TASKS.filter((t) => t.status === 'running') },
};
Context: AgentInbox
Net-new componentOpen in Storybook