{
  "schemaVersion": 1,
  "target": "react",
  "name": "agent-screen",
  "version": "0.1.0",
  "category": "ai-elements",
  "title": "Agent Screen",
  "description": "A live thumbnail of a computer-use agent's screen with its status, the current step and the agent's cursor and clicks, which grows into a larger view with Take over and Stop.",
  "tags": [
    "ai",
    "agent",
    "computer use",
    "browser",
    "screen",
    "live",
    "takeover",
    "dialog"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "dot-loader",
      "version": "0.1.0"
    }
  ],
  "docsPath": "/components/agent-screen",
  "props": [
    {
      "name": "frame",
      "type": "ReactNode",
      "description": "What is on the agent's screen: an image of the latest frame, a video, or any element."
    },
    {
      "name": "status",
      "type": "\"connecting\" | \"live\" | \"takeover\" | \"ended\"",
      "description": "Connecting shows a loading frame; takeover outlines the screen in amber; ended dims it."
    },
    {
      "name": "agentName",
      "type": "ReactNode",
      "default": "\"Agent\"",
      "description": "Who is driving."
    },
    {
      "name": "caption",
      "type": "ReactNode",
      "description": "The current step, under the thumbnail and in the larger view."
    },
    {
      "name": "cursor",
      "type": "{ x, y, click? }",
      "description": "The agent's cursor in 0 to 1 coordinates. Change click to play a ripple once the cursor arrives."
    },
    {
      "name": "aspectRatio",
      "type": "number",
      "default": "16 / 10",
      "description": "Width over height of the agent's screen."
    },
    {
      "name": "screenWidth",
      "type": "number",
      "default": "1280",
      "description": "Width the frame is laid out at before it is scaled to fit, so element frames look the same at every size."
    },
    {
      "name": "startedAt",
      "type": "number | Date",
      "description": "Shows the session clock."
    },
    {
      "name": "onTakeOver / onHandBack / onStop",
      "type": "() => void",
      "description": "Buttons in the larger view."
    },
    {
      "name": "expanded / defaultExpanded / onExpandedChange",
      "type": "boolean",
      "default": "false",
      "description": "Whether the larger view is open."
    }
  ],
  "accessibility": [
    "The thumbnail is a button labelled \"Expand screen\" with aria-haspopup=\"dialog\"; the larger view is a Base UI Dialog labelled by the agent's name, with focus trapped inside and returned to the thumbnail on close.",
    "Escape or the Collapse button closes it. Take over, Hand back and Stop are buttons; Stop is disabled once the session has ended.",
    "The current step is a polite live region; the clock and cursor are aria-hidden. Status is written in text (Live, You have control, Session ended), not only shown by color.",
    "Under reduced motion the cursor jumps instead of gliding, the click ripple only fades, and the larger view fades in without growing from the thumbnail."
  ],
  "states": [
    "connecting",
    "live",
    "takeover",
    "ended",
    "expanded"
  ],
  "files": [
    {
      "path": "agent/agent-screen.tsx",
      "content": "\"use client\";\n\nimport { Dialog as BaseDialog } from \"@base-ui/react/dialog\";\nimport {\n  type ComponentProps,\n  type CSSProperties,\n  type ReactNode,\n  useCallback,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport { DotGrid } from \"./dot-loader\";\n\n/*\n * Agent screen: a live thumbnail of a computer-use agent's screen with its status, the current\n * step, and the agent's cursor (which glides between targets and leaves a ripple where it clicks).\n *\n * Expanding moves the screen itself: the dialog is laid out at its full size, then starts scaled\n * down exactly over the thumbnail and grows into place while the dialog chrome fades in around it.\n * Collapsing runs the same path back. The frame is rendered at a fixed virtual resolution and\n * scaled to fit, so it looks identical at both sizes. Under reduced motion the cursor jumps,\n * ripples only fade, and the dialog fades without travel.\n */\n\nexport type AgentScreenStatus = \"connecting\" | \"live\" | \"takeover\" | \"ended\";\n\nexport interface AgentCursor {\n  /** 0 to 1 across the screen. */\n  x: number;\n  /** 0 to 1 down the screen. */\n  y: number;\n  /** Change this value to play a click ripple at the cursor. */\n  click?: number | string;\n}\n\nexport interface AgentScreenProps extends Omit<ComponentProps<\"section\">, \"children\"> {\n  /** What is on the agent's screen: an image of the latest frame, a video, or any element. */\n  frame?: ReactNode;\n  status: AgentScreenStatus;\n  /** Who is driving, for example \"Browser agent\". */\n  agentName?: ReactNode;\n  /** The current step, for example \"Clicking Export CSV\". */\n  caption?: ReactNode;\n  cursor?: AgentCursor;\n  /** Width over height of the agent's screen. */\n  aspectRatio?: number;\n  /**\n   * Width in CSS pixels the frame is laid out at before it is scaled to fit. Set it to the agent's\n   * screen width for element frames; images and video simply fill the box.\n   */\n  screenWidth?: number;\n  /** When the session started, as epoch milliseconds or a Date. */\n  startedAt?: number | Date;\n  onTakeOver?: () => void;\n  onHandBack?: () => void;\n  onStop?: () => void;\n  expanded?: boolean;\n  defaultExpanded?: boolean;\n  onExpandedChange?: (expanded: boolean) => void;\n}\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nconst quint = \"cubic-bezier(0.23, 1, 0.32, 1)\";\n\nconst statusMeta: Record<AgentScreenStatus, { label: string; tone: string }> = {\n  connecting: { label: \"Connecting\", tone: \"text-zinc-500\" },\n  live: { label: \"Live\", tone: \"text-sky-600 dark:text-sky-400\" },\n  takeover: { label: \"You have control\", tone: \"text-amber-600 dark:text-amber-400\" },\n  ended: { label: \"Session ended\", tone: \"text-zinc-500\" },\n};\n\nfunction usePrefersReducedMotion() {\n  const [reduce, setReduce] = useState(false);\n  useEffect(() => {\n    const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const update = () => setReduce(query.matches);\n    update();\n    query.addEventListener(\"change\", update);\n    return () => query.removeEventListener(\"change\", update);\n  }, []);\n  return reduce;\n}\n\nfunction StatusGlyph({ status }: { status: AgentScreenStatus }) {\n  if (status === \"live\" || status === \"connecting\") {\n    return <DotGrid pattern={status === \"live\" ? \"orbit\" : \"scan\"} grid={3} size={14} status=\"running\" tone=\"inherit\" />;\n  }\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" className=\"size-3.5\">\n      <circle cx=\"8\" cy=\"8\" r=\"6.25\" />\n      {status === \"takeover\" ? <path d=\"M6.5 5.75v4.5M9.5 5.75v4.5\" /> : <path d=\"m4 12 8-8\" />}\n    </svg>\n  );\n}\n\nfunction Clock({ startedAt, running }: { startedAt?: number; running: boolean }) {\n  const ref = useRef<HTMLSpanElement>(null);\n  useEffect(() => {\n    const el = ref.current;\n    if (!el || startedAt == null) return;\n    const write = () => {\n      const s = Math.max(0, Math.floor((Date.now() - startedAt) / 1000));\n      el.textContent = `${Math.floor(s / 60)}:${String(s % 60).padStart(2, \"0\")}`;\n    };\n    write();\n    if (!running) return;\n    const id = setInterval(write, 1000);\n    return () => clearInterval(id);\n  }, [startedAt, running]);\n  if (startedAt == null) return null;\n  return <span ref={ref} aria-hidden=\"true\" className=\"font-mono text-xs text-zinc-500 tabular-nums\" />;\n}\n\n// ---------------------------------------------------------------------------\n// The screen: a fixed-resolution frame scaled into its box, with the cursor on top.\n\nfunction Screen({\n  frame,\n  status,\n  cursor,\n  aspectRatio,\n  screenWidth,\n  reduce,\n  large = false,\n  agentName,\n}: {\n  frame: ReactNode;\n  status: AgentScreenStatus;\n  cursor?: AgentCursor;\n  aspectRatio: number;\n  screenWidth: number;\n  reduce: boolean;\n  large?: boolean;\n  agentName?: ReactNode;\n}) {\n  const boxRef = useRef<HTMLDivElement>(null);\n  const [box, setBox] = useState({ w: 0, h: 0 });\n\n  useLayoutEffect(() => {\n    const el = boxRef.current;\n    if (!el) return;\n    const read = () => setBox({ w: el.clientWidth, h: el.clientHeight });\n    read();\n    if (typeof ResizeObserver === \"undefined\") return;\n    const observer = new ResizeObserver(read);\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, []);\n\n  const screenHeight = screenWidth / aspectRatio;\n  const scale = box.w ? box.w / screenWidth : 0;\n  const showCursor = cursor && status === \"live\" && box.w > 0;\n\n  return (\n    <div\n      ref={boxRef}\n      className={cx(\n        \"relative w-full overflow-hidden bg-zinc-950 transition-[outline-color] duration-200 motion-reduce:transition-none\",\n        large ? \"rounded-xl\" : \"rounded-lg\",\n        \"outline-2 -outline-offset-2 outline-solid\",\n        status === \"takeover\" ? \"outline-amber-500\" : \"outline-transparent\",\n      )}\n      style={{ aspectRatio: String(aspectRatio) }}\n    >\n      {status === \"connecting\" ? (\n        <div className=\"absolute inset-0 grid place-content-center justify-items-center gap-3 text-white\">\n          <DotGrid pattern=\"scan\" grid={4} size={large ? 40 : 24} status=\"running\" tone=\"inherit\" />\n          <p className={cx(\"text-white/60\", large ? \"text-sm\" : \"text-xs\")}>Connecting to the agent&apos;s screen</p>\n        </div>\n      ) : (\n        <div\n          className={cx(\"absolute top-0 left-0 origin-top-left transition-[opacity,filter] duration-300 motion-reduce:transition-none\", status === \"ended\" && \"opacity-40 grayscale\")}\n          style={{ width: screenWidth, height: screenHeight, transform: `scale(${scale})`, visibility: scale ? \"visible\" : \"hidden\" }}\n        >\n          {frame}\n        </div>\n      )}\n\n      {showCursor ? <Cursor cursor={cursor} box={box} reduce={reduce} large={large} agentName={agentName} /> : null}\n\n      {status === \"takeover\" ? (\n        <span className=\"absolute top-2 left-2 rounded-md bg-amber-500 px-1.5 py-0.5 text-[11px] font-medium text-black\">You have control</span>\n      ) : null}\n      {status === \"ended\" ? (\n        <span className=\"absolute inset-0 grid place-items-center\">\n          <span className=\"rounded-md bg-black/75 px-2 py-1 text-xs font-medium text-white\">Session ended</span>\n        </span>\n      ) : null}\n    </div>\n  );\n}\n\nfunction Cursor({ cursor, box, reduce, large, agentName }: { cursor: AgentCursor; box: { w: number; h: number }; reduce: boolean; large: boolean; agentName?: ReactNode }) {\n  const rippleRef = useRef<HTMLSpanElement>(null);\n  const arrowRef = useRef<SVGSVGElement>(null);\n  const lastClick = useRef(cursor.click);\n  const x = Math.max(0, Math.min(1, cursor.x)) * box.w;\n  const y = Math.max(0, Math.min(1, cursor.y)) * box.h;\n\n  // A click plays once the cursor has arrived: the arrow dips and a ring spreads from its tip.\n  useEffect(() => {\n    if (cursor.click === undefined || cursor.click === lastClick.current) return;\n    lastClick.current = cursor.click;\n    const ring = rippleRef.current;\n    const arrow = arrowRef.current;\n    if (!ring || typeof ring.animate !== \"function\") return;\n    const travel = reduce ? 0 : 520;\n    if (reduce) {\n      ring.animate([{ opacity: 0.6, transform: \"translate(-50%, -50%) scale(1)\" }, { opacity: 0, transform: \"translate(-50%, -50%) scale(1)\" }], { duration: 360, easing: \"ease-out\" });\n      return;\n    }\n    ring.animate(\n      [\n        { opacity: 0.7, transform: \"translate(-50%, -50%) scale(0.3)\" },\n        { opacity: 0, transform: \"translate(-50%, -50%) scale(1.5)\" },\n      ],\n      { duration: 520, delay: travel, easing: quint, fill: \"backwards\" },\n    );\n    arrow?.animate([{ transform: \"scale(1)\" }, { transform: \"scale(0.86)\" }, { transform: \"scale(1)\" }], { duration: 220, delay: travel, easing: \"ease-out\" });\n  }, [cursor.click, reduce]);\n\n  const size = large ? 22 : 15;\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"pointer-events-none absolute top-0 left-0\"\n      style={{\n        transform: `translate(${x}px, ${y}px)`,\n        transition: reduce ? \"none\" : \"transform 520ms cubic-bezier(0.65, 0, 0.35, 1)\",\n      }}\n    >\n      <span ref={rippleRef} className={cx(\"absolute top-0 left-0 rounded-full border-2 border-sky-400 opacity-0\", large ? \"size-11\" : \"size-7\")} style={{ transform: \"translate(-50%, -50%)\" }} />\n      <svg ref={arrowRef} viewBox=\"0 0 16 16\" className=\"absolute -top-px -left-px origin-top-left drop-shadow-[0_1px_2px_rgb(0_0_0/0.45)]\" style={{ width: size, height: size }}>\n        <path d=\"M2 1.5 13.5 7.6l-5 1.2-2.4 4.7z\" fill=\"#0ea5e9\" stroke=\"#fff\" strokeWidth=\"1.25\" strokeLinejoin=\"round\" />\n      </svg>\n      {large && agentName ? (\n        <span className=\"absolute top-5 left-4 rounded-md bg-sky-500 px-1.5 py-0.5 text-[11px] font-medium whitespace-nowrap text-white\">{agentName}</span>\n      ) : null}\n    </span>\n  );\n}\n\n// ---------------------------------------------------------------------------\n\nconst iconButton = cx(\n  \"inline-flex size-8 items-center justify-center rounded-lg text-zinc-500\",\n  \"transition-[background-color,color,scale] duration-150 ease-out motion-safe:active:scale-[0.94] motion-reduce:transition-none\",\n  \"hover:bg-zinc-950/[0.05] hover:text-zinc-950 dark:hover:bg-white/[0.08] dark:hover:text-white\",\n  \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n);\n\nconst button = {\n  base: \"inline-flex h-8 items-center justify-center rounded-lg px-3 text-sm font-medium whitespace-nowrap select-none transition-[background-color,border-color,scale] duration-150 ease-out motion-safe:active:scale-[0.97] motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n  secondary: \"border border-zinc-950/12 bg-white text-zinc-950 hover:border-zinc-950/20 hover:bg-zinc-950/[0.03] dark:border-white/15 dark:bg-black dark:text-white dark:hover:border-white/25 dark:hover:bg-white/[0.06]\",\n  danger: \"bg-red-600 text-white hover:bg-red-700\",\n};\n\nfunction ExpandIcon() {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-3.5\">\n      <path d=\"M9.5 2.5h4v4M6.5 13.5h-4v-4M13.5 2.5 9 7M2.5 13.5 7 9\" />\n    </svg>\n  );\n}\n\nfunction CollapseIcon() {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-4\">\n      <path d=\"M13.5 6.5h-4v-4M2.5 9.5h4v4M9.5 6.5l4-4M6.5 9.5l-4 4\" />\n    </svg>\n  );\n}\n\n/**\n * A live thumbnail of a computer-use agent's screen. Expanding grows the screen into a dialog with\n * Take over and Stop; Escape or Collapse sends it back to the thumbnail.\n */\nexport function AgentScreen({\n  frame,\n  status,\n  agentName = \"Agent\",\n  caption,\n  cursor,\n  aspectRatio = 16 / 10,\n  screenWidth = 1280,\n  startedAt,\n  onTakeOver,\n  onHandBack,\n  onStop,\n  expanded: expandedProp,\n  defaultExpanded = false,\n  onExpandedChange,\n  className,\n  ...props\n}: AgentScreenProps) {\n  const reduce = usePrefersReducedMotion();\n  const [uncontrolled, setUncontrolled] = useState(defaultExpanded);\n  const expanded = expandedProp ?? uncontrolled;\n  // `mounted` keeps the dialog open while it animates back to the thumbnail.\n  const [mounted, setMounted] = useState(expanded);\n  const [closing, setClosing] = useState(false);\n  const thumbRef = useRef<HTMLDivElement>(null);\n  const popupRef = useRef<HTMLDivElement>(null);\n  const bigRef = useRef<HTMLDivElement>(null);\n  const expandRef = useRef<HTMLButtonElement>(null);\n  const titleId = useId();\n  const start = startedAt instanceof Date ? startedAt.getTime() : startedAt;\n  const meta = statusMeta[status];\n\n  const setExpanded = useCallback(\n    (next: boolean) => {\n      if (expandedProp === undefined) setUncontrolled(next);\n      onExpandedChange?.(next);\n    },\n    [expandedProp, onExpandedChange],\n  );\n\n  /** The transform that puts the dialog's screen exactly over the thumbnail's screen. */\n  const flipFrom = useCallback(() => {\n    const thumb = thumbRef.current?.getBoundingClientRect();\n    const big = bigRef.current?.getBoundingClientRect();\n    const popup = popupRef.current?.getBoundingClientRect();\n    if (!thumb || !big || !popup || !big.width) return null;\n    const s = thumb.width / big.width;\n    const originX = big.left - popup.left + big.width / 2;\n    const originY = big.top - popup.top + big.height / 2;\n    const dx = thumb.left + thumb.width / 2 - (big.left + big.width / 2);\n    const dy = thumb.top + thumb.height / 2 - (big.top + big.height / 2);\n    return { origin: `${originX}px ${originY}px`, transform: `translate(${dx}px, ${dy}px) scale(${s})` };\n  }, []);\n\n  // Open: mount, then grow from the thumbnail.\n  useEffect(() => {\n    if (expanded) {\n      setClosing(false);\n      setMounted(true);\n    } else if (mounted && !closing) {\n      // Close: travel back, then unmount.\n      const popup = popupRef.current;\n      const from = flipFrom();\n      if (!popup || !from || reduce || typeof popup.animate !== \"function\") {\n        setMounted(false);\n        return;\n      }\n      setClosing(true);\n      popup.style.transformOrigin = from.origin;\n      for (const el of popup.querySelectorAll<HTMLElement>(\"[data-chrome]\")) {\n        el.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 160, easing: \"ease-out\", fill: \"forwards\" });\n      }\n      const animation = popup.animate([{ transform: \"none\" }, { transform: from.transform }], { duration: 300, easing: \"cubic-bezier(0.32, 0.72, 0, 1)\", fill: \"forwards\" });\n      animation.onfinish = () => {\n        setMounted(false);\n        setClosing(false);\n      };\n    }\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [expanded]);\n\n  // Runs once the popup is in the DOM after opening.\n  const onPopupMounted = useCallback(() => {\n    const popup = popupRef.current;\n    if (!popup || typeof popup.animate !== \"function\") return;\n    if (reduce) {\n      popup.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 160, easing: \"ease-out\" });\n      return;\n    }\n    const from = flipFrom();\n    if (!from) return;\n    popup.style.transformOrigin = from.origin;\n    popup.animate([{ transform: from.transform }, { transform: \"none\" }], { duration: 440, easing: quint });\n    // The chrome waits for the screen to get going, then fades in around it.\n    for (const el of popup.querySelectorAll<HTMLElement>(\"[data-chrome]\")) {\n      el.animate([{ opacity: 0 }, { opacity: 0, offset: 0.25 }, { opacity: 1 }], { duration: 400, easing: \"ease-out\" });\n    }\n  }, [flipFrom, reduce]);\n\n  // Base UI renders the portal after this component commits, so the grow starts when the popup attaches.\n  const grown = useRef(false);\n  const attachPopup = useCallback(\n    (el: HTMLDivElement | null) => {\n      popupRef.current = el;\n      // Once per open: a re-attached ref must not restart (or flatten) the grow.\n      if (el && !grown.current) {\n        grown.current = true;\n        onPopupMounted();\n      }\n    },\n    [onPopupMounted],\n  );\n  useEffect(() => {\n    if (!mounted) grown.current = false;\n  }, [mounted]);\n\n  const screenProps = { frame, status, cursor, aspectRatio, screenWidth, reduce, agentName };\n  const live = status === \"live\" || status === \"connecting\";\n\n  return (\n    <section\n      aria-label={typeof agentName === \"string\" ? `${agentName} screen` : \"Agent screen\"}\n      data-status={status}\n      className={cx(\n        \"w-full rounded-xl border border-zinc-950/10 bg-white p-2 text-left text-zinc-950 shadow-[0_1px_2px_rgb(0_0_0/0.04)]\",\n        \"dark:border-white/10 dark:bg-black dark:text-white dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]\",\n        className,\n      )}\n      {...props}\n    >\n      <div ref={thumbRef} className=\"group/thumb relative\">\n        {/* The button stays mounted while the screen is in the dialog, so focus can come back to it. */}\n        <button\n          ref={expandRef}\n          type=\"button\"\n          onClick={() => setExpanded(true)}\n          aria-label=\"Expand screen\"\n          aria-haspopup=\"dialog\"\n          aria-expanded={mounted}\n          className=\"block w-full rounded-lg outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500\"\n        >\n          {mounted ? (\n            // The screen is in the dialog; the thumbnail keeps its place.\n            <span className=\"grid w-full place-items-center rounded-lg border border-dashed border-zinc-950/15 dark:border-white/15\" style={{ aspectRatio: String(aspectRatio) }}>\n              <span className=\"text-xs text-zinc-500\">Open in a larger view</span>\n            </span>\n          ) : (\n            <>\n              <Screen {...screenProps} />\n              <span\n                aria-hidden=\"true\"\n                className={cx(\n                  \"absolute top-2 right-2 inline-flex size-7 items-center justify-center rounded-md bg-zinc-950/80 text-white\",\n                  \"transition-[background-color] duration-150 ease-out group-hover/thumb:bg-zinc-950 motion-reduce:transition-none\",\n                )}\n              >\n                <ExpandIcon />\n              </span>\n            </>\n          )}\n        </button>\n      </div>\n\n      <div className=\"grid gap-0.5 px-1.5 pt-2.5 pb-1\">\n        <div className=\"flex items-center gap-2 text-xs\">\n          <span className={cx(\"flex items-center gap-1.5 font-medium\", meta.tone)}>\n            <StatusGlyph status={status} />\n            {meta.label}\n          </span>\n          <span className=\"truncate text-zinc-500\">{agentName}</span>\n          <span className=\"ml-auto\">\n            <Clock startedAt={start} running={live} />\n          </span>\n        </div>\n        <p role=\"status\" className=\"min-h-5 truncate text-sm text-zinc-600 dark:text-zinc-400\">\n          <span\n            key={typeof caption === \"string\" ? caption : undefined}\n            className=\"inline-block transition-[opacity,translate] duration-300 ease-[cubic-bezier(0.23,1,0.32,1)] starting:translate-y-1 starting:opacity-0 motion-reduce:transition-none\"\n          >\n            {status === \"connecting\" ? \"Waiting for the first frame\" : caption}\n          </span>\n        </p>\n      </div>\n\n      <BaseDialog.Root\n        open={mounted}\n        onOpenChange={(open) => {\n          if (!open) setExpanded(false);\n        }}\n      >\n        <BaseDialog.Portal>\n          <BaseDialog.Backdrop\n            className={cx(\n              \"fixed inset-0 z-50 bg-black/40 transition-opacity duration-200 ease-out motion-reduce:transition-none dark:bg-black/70\",\n              \"data-[starting-style]:opacity-0 data-[ending-style]:opacity-0\",\n              closing && \"opacity-0\",\n            )}\n          />\n          <BaseDialog.Popup\n            ref={attachPopup}\n            aria-labelledby={titleId}\n            finalFocus={expandRef}\n            className={cx(\n              \"fixed inset-0 z-50 m-auto flex h-fit max-h-[calc(100dvh-2rem)] w-[min(960px,calc(100vw-2rem))] flex-col text-zinc-950 dark:text-white\",\n              \"outline-none\",\n            )}\n          >\n            {/* The chrome fades around the screen, which travels on its own. */}\n            <div\n              data-chrome\n              aria-hidden=\"true\"\n              className=\"absolute inset-0 rounded-2xl border border-zinc-950/10 bg-white shadow-[0_24px_64px_-16px_rgb(0_0_0/0.28)] dark:border-white/15 dark:bg-black dark:shadow-[0_24px_64px_-12px_rgb(0_0_0/1),inset_0_1px_0_rgb(255_255_255/0.08)]\"\n            />\n            <div data-chrome className=\"relative flex items-center gap-3 px-4 pt-3 pb-2.5\">\n                <span className={cx(\"flex items-center gap-1.5 text-xs font-medium\", meta.tone)}>\n                  <StatusGlyph status={status} />\n                  {meta.label}\n                </span>\n                <BaseDialog.Title id={titleId} className=\"min-w-0 truncate text-sm font-semibold\">\n                  {agentName}\n                </BaseDialog.Title>\n                <span className=\"ml-auto flex items-center gap-2\">\n                  <Clock startedAt={start} running={live} />\n                  <BaseDialog.Close aria-label=\"Collapse\" className={iconButton}>\n                    <CollapseIcon />\n                  </BaseDialog.Close>\n                </span>\n            </div>\n            <div className=\"relative px-2\">\n              <div ref={bigRef} className=\"mx-auto w-full\" style={{ maxWidth: `calc((100dvh - 9.5rem) * ${aspectRatio})` } as CSSProperties}>\n                {mounted ? <Screen {...screenProps} large /> : null}\n              </div>\n            </div>\n            <div data-chrome className=\"relative flex flex-wrap items-center gap-x-4 gap-y-2 px-4 pt-2.5 pb-3\">\n                <p className=\"min-w-0 flex-1 truncate text-sm text-zinc-600 dark:text-zinc-400\">{status === \"connecting\" ? \"Waiting for the first frame\" : caption}</p>\n                <div className=\"ml-auto flex items-center gap-2\">\n                  {status === \"takeover\" ? (\n                    <button type=\"button\" onClick={onHandBack} className={cx(button.base, button.secondary)}>\n                      Hand back\n                    </button>\n                  ) : (\n                    <button type=\"button\" disabled={status !== \"live\"} onClick={onTakeOver} className={cx(button.base, button.secondary, \"disabled:pointer-events-none disabled:opacity-40\")}>\n                      Take over\n                    </button>\n                  )}\n                  <button type=\"button\" disabled={status === \"ended\"} onClick={onStop} className={cx(button.base, button.danger, \"disabled:pointer-events-none disabled:opacity-40\")}>\n                    Stop\n                  </button>\n                </div>\n            </div>\n          </BaseDialog.Popup>\n        </BaseDialog.Portal>\n      </BaseDialog.Root>\n    </section>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { type AgentCursor, AgentScreen, type AgentScreenStatus } from \"@/components/shaken/agent/agent-screen\";\n\n/*\n * The agent's screen here is a small invoicing app drawn in code at 1280 x 800. In your app,\n * pass the latest frame from your computer-use session instead, for example\n * <img src={frameUrl} alt=\"\" className=\"size-full object-cover\" />.\n */\n\ntype ScreenState = { filter: boolean; selected: string | null; exported: boolean };\n\nconst invoices = [\n  { id: \"INV-2051\", customer: \"Northwind Freight\", amount: \"$12,400.00\", due: \"Nov 30\", status: \"Open\" },\n  { id: \"INV-2049\", customer: \"Halcyon Dental\", amount: \"$3,180.00\", due: \"Nov 2\", status: \"Overdue\" },\n  { id: \"INV-2048\", customer: \"Kestrel Robotics\", amount: \"$28,000.00\", due: \"Dec 4\", status: \"Open\" },\n  { id: \"INV-2047\", customer: \"Bramble & Rye\", amount: \"$6,450.00\", due: \"Oct 28\", status: \"Overdue\" },\n  { id: \"INV-2045\", customer: \"Osprey Health\", amount: \"$2,975.00\", due: \"Oct 30\", status: \"Overdue\" },\n  { id: \"INV-2044\", customer: \"Marlow Studio\", amount: \"$1,240.00\", due: \"Oct 12\", status: \"Paid\" },\n  { id: \"INV-2042\", customer: \"Fennick Labs\", amount: \"$9,800.00\", due: \"Oct 19\", status: \"Overdue\" },\n];\n\nconst nav = [\"Overview\", \"Invoices\", \"Customers\", \"Payouts\", \"Reports\"];\nconst filters = [\"All\", \"Overdue\", \"Drafts\", \"Paid\"];\n\nexport function LedgerScreen({ filter, selected, exported }: ScreenState) {\n  const rows = filter ? invoices.filter((invoice) => invoice.status === \"Overdue\") : invoices;\n  return (\n    <div className=\"flex h-[800px] w-[1280px] flex-col bg-white font-sans text-[14px] text-zinc-900\">\n      <div className=\"flex h-[44px] shrink-0 items-center gap-3 border-b border-zinc-200 bg-zinc-100 px-4\">\n        <span className=\"flex gap-1.5\">\n          <span className=\"size-3 rounded-full bg-zinc-300\" />\n          <span className=\"size-3 rounded-full bg-zinc-300\" />\n          <span className=\"size-3 rounded-full bg-zinc-300\" />\n        </span>\n        <span className=\"ml-24 w-[420px] rounded-md bg-white px-3 py-1 text-[13px] text-zinc-500\">ledgerline.app/invoices{filter ? \"?status=overdue\" : \"\"}</span>\n      </div>\n      <div className=\"flex min-h-0 flex-1\">\n        <aside className=\"w-[232px] shrink-0 border-r border-zinc-200 bg-zinc-50 px-4\">\n          <div className=\"flex h-[76px] items-center gap-2 text-[15px] font-semibold\">\n            <span className=\"size-6 rounded-md bg-emerald-600\" />\n            Ledgerline\n          </div>\n          <ul>\n            {nav.map((item) => (\n              <li key={item} className={`flex h-[36px] items-center rounded-md px-3 ${item === \"Invoices\" ? \"bg-zinc-200/70 font-medium\" : \"text-zinc-600\"}`}>\n                {item}\n              </li>\n            ))}\n          </ul>\n        </aside>\n        <main className=\"relative min-w-0 flex-1 px-8\">\n          <div className=\"flex h-[84px] items-end pb-2\">\n            <h1 className=\"text-[24px] font-semibold\">Invoices</h1>\n          </div>\n          <div className=\"flex h-[36px] items-center gap-2\">\n            {filters.map((item) => {\n              const active = (item === \"Overdue\" && filter) || (item === \"All\" && !filter);\n              return (\n                <span key={item} className={`flex h-[32px] items-center rounded-full border px-4 text-[13px] ${active ? \"border-zinc-900 bg-zinc-900 text-white\" : \"border-zinc-300 text-zinc-600\"}`}>\n                  {item}\n                </span>\n              );\n            })}\n            <span className=\"ml-auto flex h-[36px] w-[124px] items-center justify-center rounded-md bg-emerald-600 text-[13px] font-medium text-white\">Export CSV</span>\n          </div>\n          <div className=\"mt-6\">\n            <div className=\"grid h-[36px] grid-cols-[140px_1fr_160px_120px_110px] items-center border-b border-zinc-200 text-[12px] font-medium text-zinc-500\">\n              <span>Invoice</span>\n              <span>Customer</span>\n              <span className=\"text-right\">Amount</span>\n              <span className=\"pl-8\">Due</span>\n              <span>Status</span>\n            </div>\n            {rows.map((invoice) => (\n              <div\n                key={invoice.id}\n                className={`grid h-[48px] grid-cols-[140px_1fr_160px_120px_110px] items-center border-b border-zinc-100 ${selected === invoice.id ? \"bg-sky-50\" : \"\"}`}\n              >\n                <span className=\"font-mono text-[13px] text-zinc-600\">{invoice.id}</span>\n                <span className=\"font-medium\">{invoice.customer}</span>\n                <span className=\"text-right font-mono text-[13px]\">{invoice.amount}</span>\n                <span className=\"pl-8 text-zinc-600\">{invoice.due}</span>\n                <span className={invoice.status === \"Overdue\" ? \"text-red-600\" : invoice.status === \"Paid\" ? \"text-emerald-700\" : \"text-zinc-600\"}>{invoice.status}</span>\n              </div>\n            ))}\n          </div>\n          {exported ? (\n            <div className=\"absolute right-8 bottom-8 rounded-lg bg-zinc-900 px-4 py-3 text-[13px] text-white shadow-lg\">Exported overdue-invoices.csv (4 rows)</div>\n          ) : null}\n        </main>\n      </div>\n    </div>\n  );\n}\n\n// Positions in the 1280 x 800 screen, as fractions.\nconst script: { caption: string; cursor: { x: number; y: number }; apply: (state: ScreenState) => ScreenState }[] = [\n  { caption: \"Opening Invoices\", cursor: { x: 0.07, y: 0.2175 }, apply: () => ({ filter: false, selected: null, exported: false }) },\n  { caption: \"Filtering to overdue invoices\", cursor: { x: 0.272, y: 0.183 }, apply: (s) => ({ ...s, filter: true }) },\n  { caption: \"Opening INV-2047 for Bramble & Rye\", cursor: { x: 0.36, y: 0.37 }, apply: (s) => ({ ...s, selected: \"INV-2047\" }) },\n  { caption: \"Exporting 4 overdue invoices to CSV\", cursor: { x: 0.928, y: 0.183 }, apply: (s) => ({ ...s, exported: true }) },\n];\n\nexport default function AgentScreenExample() {\n  const [status, setStatus] = useState<AgentScreenStatus>(\"connecting\");\n  const [startedAt] = useState(() => Date.now() - 154_000);\n  const [step, setStep] = useState(0);\n  const [cursor, setCursor] = useState<AgentCursor>({ x: 0.5, y: 0.6 });\n  const [screen, setScreen] = useState<ScreenState>({ filter: false, selected: null, exported: false });\n  const clicks = useRef(0);\n\n  // Connect, then play the script while the agent has control.\n  useEffect(() => {\n    if (status !== \"connecting\") return;\n    const id = setTimeout(() => setStatus(\"live\"), 1600);\n    return () => clearTimeout(id);\n  }, [status]);\n\n  useEffect(() => {\n    if (status !== \"live\") return;\n    const current = script[step % script.length]!;\n    clicks.current += 1;\n    setCursor({ ...current.cursor, click: clicks.current });\n    // The screen reacts once the cursor lands and clicks.\n    const land = setTimeout(() => setScreen((s) => current.apply(s)), 560);\n    const next = setTimeout(() => setStep((n) => n + 1), 2400);\n    return () => {\n      clearTimeout(land);\n      clearTimeout(next);\n    };\n  }, [status, step]);\n\n  return (\n    <AgentScreen\n      className=\"max-w-sm\"\n      agentName=\"Browser agent\"\n      status={status}\n      startedAt={startedAt}\n      caption={script[step % script.length]!.caption}\n      cursor={cursor}\n      frame={<LedgerScreen {...screen} />}\n      onTakeOver={() => setStatus(\"takeover\")}\n      onHandBack={() => setStatus(\"live\")}\n      onStop={() => setStatus(\"ended\")}\n    />\n  );\n}\n"
  }
}
