Agent Recap
What the agents did while you were away: the night as a small chart with a peak per event, then a board of what needs you, what failed and what's done, acted on right on the card.
"use client"
import * as React from "react"
import { CircleCheck, TriangleAlert, User } from "lucide-react"
import {
AiKitStyles,
AiStyle,
BrandTile,
cx,
Roll,
} from "@/lib/ai-kit"
export type RecapColumn = "ask" | "fail" | "done"
export interface RecapEvent {
id: string
/** Where in the night it happened, 0 (start) to 1 (now). */
at: number
kind: RecapColumn
/** Peak height, 0 to 1. */
size: number
}
export interface RecapCard {
id: string
column: RecapColumn
brand: string
title: string
detail: string
time: string
/** A count chip, e.g. tickets answered. */
count?: number
/** Label of the main action on a card that needs you, e.g. "Approve". */
action?: string
/** Set while the card is being worked on after you acted. */
busy?: boolean
}
export type RecapAct = "primary" | "review" | "retry" | "undo"
export interface AgentRecapProps {
since: string
until: string
away: string
events: readonly RecapEvent[]
cards: readonly RecapCard[]
onAct?: (id: string, act: RecapAct) => void
/** Change it to redraw the chart from the left. */
drawKey?: string | number
className?: string
}
const CSS = `
.aik-rc{--aik-r-shell:26px;--aik-rim:6px;width:min(100%,1000px);container-type:inline-size}
.aik-rc-in{display:grid;gap:18px;padding:22px 22px 18px}
.aik-rc-head{display:flex;align-items:flex-start;gap:16px;flex-wrap:wrap}
.aik-rc-head h3{font-size:20px;line-height:26px;font-weight:600;letter-spacing:-.01em}
.aik-rc-since{display:flex;align-items:center;gap:8px;margin-top:4px;font-size:14px;color:var(--aik-text-3)}
.aik-rc-since b{padding:2px 8px;border-radius:7px;background:var(--aik-raised);font:500 13px var(--aik-mono);color:var(--aik-text-2)}
.aik-rc-sum{margin-left:auto;display:flex;gap:18px;font-size:14px;color:var(--aik-text-3)}
.aik-rc-sum span{display:inline-flex;align-items:center;gap:6px;white-space:nowrap}
.aik-rc-sum b{font-weight:600;color:var(--aik-text);font-variant-numeric:tabular-nums}
.aik-rc-chart{display:block;width:100%;height:auto;overflow:visible}
.aik-rc-grid{stroke:var(--aik-line);stroke-width:1}
.aik-rc-line{fill:none;stroke:var(--aik-text-3);stroke-width:2;stroke-linejoin:round;stroke-dasharray:1;animation:aik-rc-draw 2.2s var(--aik-ease-move) both}
.aik-rc-area{fill:url(#aik-rc-fill);animation:aik-rc-fade 1.6s 600ms var(--aik-ease-out) both}
.aik-rc-dot{transform-box:fill-box;transform-origin:center;animation:aik-rc-pop 420ms var(--aik-ease-soft) both}
.aik-rc-dot circle:first-child{opacity:.25}
.aik-rc-x{display:flex;justify-content:space-between;margin-top:-6px;font:12.5px var(--aik-mono);color:var(--aik-text-3)}
@keyframes aik-rc-draw{from{stroke-dashoffset:1}to{stroke-dashoffset:0}}
@keyframes aik-rc-fade{from{opacity:0}}
@keyframes aik-rc-pop{from{opacity:0;transform:scale(0)}}
.aik-rc-board{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;align-items:start}
.aik-rc-col{display:grid;gap:6px;align-content:start;min-height:280px;padding:6px;border-radius:18px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line)}
.aik-rc-colh{display:flex;align-items:center;gap:8px;height:38px;padding:0 8px 0 10px;font-size:14px;color:var(--aik-text-2)}
.aik-rc-colh .aik-roll{margin-left:auto;min-width:24px;height:24px;place-items:center;border-radius:8px;background:var(--aik-raised);font:600 12px var(--aik-mono)}
.aik-rc-card{display:grid;gap:8px;padding:12px;border-radius:13px;background:var(--aik-card);box-shadow:var(--aik-sh-card);transition:opacity var(--aik-d-panel)}
.aik-rc-card[data-busy]{opacity:.6}
.aik-rc-ct{display:flex;align-items:center;gap:10px;font-size:15px;font-weight:600;line-height:20px;min-width:0}
.aik-rc-ct > span:last-child{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-rc-cd{display:flex;align-items:center;gap:8px;font-size:13.5px;color:var(--aik-text-3);padding-left:38px;min-width:0}
.aik-rc-cd > span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-rc-card[data-c="fail"] .aik-rc-cd > span:first-child{color:var(--aik-red)}
.aik-rc-cd i{font-style:normal;padding:1px 7px;border-radius:6px;background:var(--aik-raised);font:500 12px var(--aik-mono);color:var(--aik-text-2)}
.aik-rc-cd em{font-style:normal;white-space:nowrap;font-variant-numeric:tabular-nums}
.aik-rc-acts{display:flex;align-items:center;justify-content:flex-end;gap:6px}
.aik-rc-acts .aik-btn{height:30px;font-size:13px}
.aik-rc-done{margin-right:auto;padding:3px 9px;border-radius:7px;font-size:12.5px;font-weight:500;color:var(--aik-green);background:color-mix(in oklab,var(--aik-green) 14%,transparent)}
.aik-rc-undo{height:30px;padding:0 8px;border-radius:8px;color:var(--aik-text-3);font-size:13px;transition:color var(--aik-d-state),background var(--aik-d-state)}
.aik-rc-undo:hover{color:var(--aik-text);background:var(--aik-hover)}
@container (max-width:720px){.aik-rc-board{grid-template-columns:minmax(0,1fr)}.aik-rc-col{min-height:0}.aik-rc-sum{margin-left:0;gap:12px;font-size:13px}}
@media (prefers-reduced-motion: reduce){.aik-rc-line,.aik-rc-area,.aik-rc-dot{animation:none}}
`
const COLS: ReadonlyArray<{
key: RecapColumn
title: string
icon: typeof User
}> = [
{ key: "ask", title: "Needs you", icon: User },
{ key: "fail", title: "Failed", icon: TriangleAlert },
{ key: "done", title: "Done", icon: CircleCheck },
]
const DOT: Record<RecapColumn, string> = {
ask: "var(--aik-amber)",
fail: "var(--aik-red)",
done: "var(--aik-text-2)",
}
const W = 1000
const H = 190
function nightPath(events: readonly RecapEvent[]) {
const pts: Array<[number, number]> = []
for (let i = 0; i <= 200; i++) {
const t = i / 200
let v = 0
for (const e of events)
v += e.size * Math.exp(-((t - e.at) ** 2) / (2 * 0.028 ** 2))
pts.push([t * W, H - 8 - Math.min(v, 1) * (H - 26)])
}
return pts
}
/**
* What the agents did while you were away: the night as a small chart with
* a peak per event, then a board of what needs you, what failed and what's
* done, with the actions right on the card.
*/
export function AgentRecap({
since,
until,
away,
events,
cards,
onAct,
drawKey,
className,
}: AgentRecapProps) {
const root = React.useRef<HTMLDivElement>(null)
const els = React.useRef(new Map<string, HTMLElement>())
const last = React.useRef(new Map<string, { x: number; y: number }>())
const layout = cards.map((c) => c.id + c.column).join()
// Cards that change column glide to their new place.
React.useLayoutEffect(() => {
const base = root.current?.getBoundingClientRect()
if (!base) return
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches
const next = new Map<string, { x: number; y: number }>()
els.current.forEach((el, id) => {
const r = el.getBoundingClientRect()
const at = { x: r.left - base.left, y: r.top - base.top }
next.set(id, at)
const was = last.current.get(id)
if (!was || still) return
const dx = was.x - at.x
const dy = was.y - at.y
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) return
el.animate(
[
{ transform: `translate(${dx}px,${dy}px) scale(.98)` },
{ transform: "none" },
],
{ duration: 600, easing: "cubic-bezier(.65,0,.15,1)" }
)
})
last.current = next
}, [layout])
const pts = React.useMemo(() => nightPath(events), [events])
const line = pts
.map(([x, y], i) => `${i ? "L" : "M"}${x.toFixed(1)} ${y.toFixed(1)}`)
.join("")
const count = (k: RecapColumn) => cards.filter((c) => c.column === k).length
return (
<div ref={root} className={cx("aik aik-rc aik-shell", className)}>
<AiKitStyles />
<AiStyle id="agent-recap" css={CSS} />
<div className="aik-surface aik-rc-in">
<div className="aik-rc-head">
<div>
<h3>While you were away</h3>
<p className="aik-rc-since">
Since {since} <b>{away}</b>
</p>
</div>
<div className="aik-rc-sum">
<span>
<CircleCheck size={15} aria-hidden="true" />
<b>
<Roll>{String(count("done"))}</Roll>
</b>{" "}
done
</span>
<span>
<User size={15} aria-hidden="true" />
<b>
<Roll>{String(count("ask"))}</Roll>
</b>{" "}
need you
</span>
<span>
<TriangleAlert size={15} aria-hidden="true" />
<b>
<Roll>{String(count("fail"))}</Roll>
</b>{" "}
failed
</span>
</div>
</div>
<div key={drawKey}>
<svg
className="aik-rc-chart"
viewBox={`0 0 ${W} ${H}`}
aria-hidden="true"
>
<defs>
<linearGradient id="aik-rc-fill" x1="0" x2="0" y1="0" y2="1">
<stop
offset="0"
stopColor="var(--aik-text-3)"
stopOpacity=".22"
/>
<stop
offset="1"
stopColor="var(--aik-text-3)"
stopOpacity="0"
/>
</linearGradient>
</defs>
{Array.from({ length: 13 }, (_, i) => (
<line
key={`v${i}`}
className="aik-rc-grid"
x1={(i * W) / 13 + 24}
x2={(i * W) / 13 + 24}
y1={0}
y2={H}
/>
))}
{[0.25, 0.5, 0.75].map((f) => (
<line
key={f}
className="aik-rc-grid"
x1={0}
x2={W}
y1={H * f}
y2={H * f}
/>
))}
<path className="aik-rc-area" d={`${line}L${W} ${H}L0 ${H}Z`} />
<path className="aik-rc-line" d={line} pathLength={1} />
{events.map((e) => {
const x = e.at * W
const y = pts[Math.round(e.at * 200)][1]
return (
<g
key={e.id}
className="aik-rc-dot"
style={{ animationDelay: `${300 + e.at * 1900}ms` }}
>
<circle cx={x} cy={y} r={9} fill={DOT[e.kind]} />
<circle cx={x} cy={y} r={4.5} fill={DOT[e.kind]} />
</g>
)
})}
</svg>
<div className="aik-rc-x">
<span>{since}</span>
<span>{until}</span>
</div>
</div>
<div className="aik-rc-board">
{COLS.map((col) => {
const Icon = col.icon
const items = cards.filter((c) => c.column === col.key)
return (
<section
key={col.key}
className="aik-rc-col"
aria-label={col.title}
>
<div className="aik-rc-colh">
<Icon size={16} aria-hidden="true" />
{col.title}
<Roll>{String(items.length)}</Roll>
</div>
{items.map((card) => (
<div
key={card.id}
ref={(el) => {
if (el) els.current.set(card.id, el)
else els.current.delete(card.id)
}}
className="aik-rc-card"
data-c={card.column}
data-busy={card.busy ? "" : undefined}
>
<div className="aik-rc-ct">
<BrandTile name={card.brand} size={28} />
<span>{card.title}</span>
</div>
<div className="aik-rc-cd">
<span>{card.detail}</span>
{card.count ? <i>{card.count}</i> : null}
<em>{card.time}</em>
</div>
<div className="aik-rc-acts">
{card.column === "ask" ? (
<>
<button
type="button"
className="aik-rc-undo"
onClick={() => onAct?.(card.id, "review")}
>
Review
</button>
<button
type="button"
className="aik-btn line"
onClick={() => onAct?.(card.id, "primary")}
>
{card.action ?? "Approve"}
</button>
</>
) : card.column === "fail" ? (
<button
type="button"
className="aik-btn line"
onClick={() => onAct?.(card.id, "retry")}
>
{card.busy ? "Retrying…" : "Retry"}
</button>
) : (
<>
<span className="aik-rc-done">Done</span>
<button
type="button"
className="aik-rc-undo"
onClick={() => onAct?.(card.id, "undo")}
>
Undo
</button>
</>
)}
</div>
</div>
))}
</section>
)
})}
</div>
</div>
</div>
)
}
Installation
One command adds agent-recap and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.
$npx shadcn@latest add https://tweenui.dev/r/agent-recap.json