{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "review-10",
  "title": "Computer use viewer",
  "description": "An agent drives a drawn booking site with a named pointer that glides and ripples, a log and a scrubber to replay its steps, Pause, Take over and an approval before it pays.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/call-status.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/media-clock.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/slider.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/review/review-10.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, useInView } from 'motion/react';\nimport { useId, useRef, useState } from 'react';\n\nimport {\n  useRunScript,\n  type RunScriptStep,\n} from '@/registry/ndeko/hooks/use-agent-run';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  emptyRun,\n  pendingApprovalsOf,\n  seriesColorOf,\n  type RunEvent,\n  type RunSnapshot,\n  type ToolCall,\n} from '@/registry/ndeko/lib/agent-run';\nimport {\n  CircleCheckIcon,\n  GlobeIcon,\n  HandIcon,\n  LockIcon,\n  MousePointerClickIcon,\n  MousePointerIcon,\n  PauseIcon,\n  PlayIcon,\n  TriangleAlertIcon,\n  TypeIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\nimport { formatClock, spokenClockOf } from '@/registry/ndeko/lib/media-clock';\nimport {\n  EASE_OUT_STRONG,\n  risePresenceOf,\n} from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { CallStatusMark } from '@/registry/ndeko/ui/call-status';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\nimport { Slider } from '@/registry/ndeko/ui/slider';\n\nexport type Screen =\n  'search' | 'results' | 'details' | 'checkout' | 'confirmed';\n\nexport type Page = {\n  screen: Screen;\n  destination: string;\n  dates: string;\n};\n\nexport type ActionKind = 'navigate' | 'click' | 'type';\n\nexport type BrowserAction = {\n  id: string;\n  kind: ActionKind;\n  label: string;\n  /** The element the pointer goes to; the address bar when it only loads a page. */\n  target: string;\n  pageAfter: Page;\n  isRisky?: boolean;\n};\n\nconst AGENT_NAME = 'Researcher';\n\nconst AGENT_SERIES = 2;\n\nconst KIND_ICON: Record<ActionKind, Icon> = {\n  navigate: GlobeIcon,\n  click: MousePointerClickIcon,\n  type: TypeIcon,\n};\n\nconst ADDRESS: Record<Screen, string> = {\n  search: 'lakeline-stays.example/search',\n  results: 'lakeline-stays.example/lisbon',\n  details: 'lakeline-stays.example/stay/casa-alfama',\n  checkout: 'lakeline-stays.example/checkout',\n  confirmed: 'lakeline-stays.example/booked',\n};\n\nconst BLANK_PAGE: Page = { screen: 'search', destination: '', dates: '' };\n\nconst SCREEN_TARGETS: Record<Screen, string[]> = {\n  search: ['search-title', 'destination', 'dates', 'search'],\n  results: ['results-title', 'alfama', 'tejo', 'miradouro'],\n  details: ['details-title', 'book'],\n  checkout: ['checkout-title', 'pay'],\n  confirmed: ['confirmed-title', 'reference'],\n};\n\n/** Once a click has opened the next page, its element is gone: the pointer rests on the new page's title. */\nfunction pointerTargetOf(action: BrowserAction | undefined, page: Page) {\n  const targets = SCREEN_TARGETS[page.screen];\n  const target = action?.target ?? 'address';\n  const isAddress = target === 'address';\n  const isOnPage = targets.includes(target);\n  const isPresent = isAddress || isOnPage;\n  if (isPresent) {\n    return target;\n  }\n  return targets[0];\n}\n\ntype FrameContextValue = {\n  pointerTarget: string | null;\n  pointerId: string;\n  rippleTarget: string | null;\n  rippleKey: string;\n  isPointerShown: boolean;\n  riskyTarget: string | null;\n};\n\nfunction NamedPointer({\n  pointerId,\n  isShown,\n}: {\n  pointerId: string;\n  isShown: boolean;\n}) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const color = seriesColorOf(AGENT_SERIES);\n  const pointerStyle = { color } as React.CSSProperties;\n\n  return (\n    <motion.span\n      layoutId={pointerId}\n      aria-hidden='true'\n      className='pointer-events-none absolute top-1/2 left-1/2 z-20 flex items-start gap-0.5'\n      initial={false}\n      animate={{ opacity: pointerOpacityOf(isShown) }}\n      transition={pointerTransitionOf(shouldReduceMotion)}\n    >\n      <MousePointerIcon\n        className='size-4 drop-shadow-[0_1px_1px_rgb(0_0_0/0.25)]'\n        strokeWidth={2.25}\n        style={pointerStyle}\n      />\n      <Chip color={color} className='mt-3 h-4 px-1 text-[10px]'>\n        {AGENT_NAME}\n      </Chip>\n    </motion.span>\n  );\n}\n\nfunction pointerOpacityOf(isShown: boolean) {\n  if (isShown) {\n    return 1;\n  }\n  return 0;\n}\n\nfunction pointerTransitionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return { duration: 0 };\n  }\n  return {\n    layout: { type: 'spring' as const, bounce: 0.15, duration: 0.6 },\n    opacity: { duration: 0.2 },\n  };\n}\n\nfunction Ripple({ rippleKey }: { rippleKey: string }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const ripple = rippleMotionOf(shouldReduceMotion);\n\n  return (\n    <motion.span\n      key={rippleKey}\n      aria-hidden='true'\n      className='bg-primary/35 pointer-events-none absolute top-1/2 left-1/2 z-10 -ms-3 -mt-3 size-6 rounded-full'\n      {...ripple}\n    />\n  );\n}\n\nconst RIPPLE = {\n  initial: { scale: 0.4, opacity: 0.6 },\n  animate: { scale: 2.6, opacity: 0 },\n  transition: { duration: 0.6, ease: EASE_OUT_STRONG },\n} as const;\n\nconst RIPPLE_FADE = {\n  initial: { opacity: 0.5 },\n  animate: { opacity: 0 },\n  transition: { duration: 0.5 },\n} as const;\n\nfunction rippleMotionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return RIPPLE_FADE;\n  }\n  return RIPPLE;\n}\n\ntype TargetProps = {\n  id: string;\n  frame: FrameContextValue;\n  className?: string;\n  children: React.ReactNode;\n};\n\n/** An element the agent can point at: the pointer lives inside its current target and glides to the next. */\nfunction Target({ id, frame, className, children }: TargetProps) {\n  const isPointed = frame.pointerTarget === id;\n  const isRippling = frame.rippleTarget === id;\n  const isRisky = frame.riskyTarget === id;\n\n  return (\n    <span\n      className={cn(\n        'relative inline-flex rounded-md transition-shadow duration-200',\n        isRisky && 'ring-warning/60 ring-offset-card ring-2 ring-offset-2',\n        className\n      )}\n    >\n      {children}\n      {isRippling && <Ripple rippleKey={frame.rippleKey} />}\n      {isPointed && (\n        <NamedPointer\n          pointerId={frame.pointerId}\n          isShown={frame.isPointerShown}\n        />\n      )}\n    </span>\n  );\n}\n\nconst SITE_FIELD =\n  'bg-card hairline-ring ring-foreground/12 flex h-7 w-full items-center rounded-md px-2 text-[11px]';\n\nconst SITE_BUTTON =\n  'bg-primary text-primary-foreground flex h-7 items-center justify-center rounded-full px-3 text-[11px] font-medium';\n\nfunction FieldValue({\n  value,\n  placeholder,\n}: {\n  value: string;\n  placeholder: string;\n}) {\n  if (value === '') {\n    return <span className='text-muted-foreground'>{placeholder}</span>;\n  }\n  return (\n    <span className='transition-opacity duration-300 starting:opacity-0'>\n      {value}\n    </span>\n  );\n}\n\nfunction SearchScreen({\n  page,\n  frame,\n}: {\n  page: Page;\n  frame: FrameContextValue;\n}) {\n  return (\n    <div className='flex flex-col gap-2.5'>\n      <Target id='search-title' frame={frame} className='self-start'>\n        <p className='text-[13px] font-semibold'>Find a stay</p>\n      </Target>\n      <Target id='destination' frame={frame} className='w-full'>\n        <span className={SITE_FIELD}>\n          <FieldValue value={page.destination} placeholder='Where to?' />\n        </span>\n      </Target>\n      <div className='grid grid-cols-2 gap-2'>\n        <Target id='dates' frame={frame} className='w-full'>\n          <span className={SITE_FIELD}>\n            <FieldValue value={page.dates} placeholder='Dates' />\n          </span>\n        </Target>\n        <span className={SITE_FIELD}>2 guests</span>\n      </div>\n      <Target id='search' frame={frame} className='self-start'>\n        <span className={SITE_BUTTON}>Search</span>\n      </Target>\n    </div>\n  );\n}\n\nconst STAYS = [\n  { id: 'alfama', name: 'Casa Alfama', note: 'Old town, 4.8', price: '156' },\n  { id: 'tejo', name: 'Rio Tejo Rooms', note: 'Riverside, 4.5', price: '132' },\n  {\n    id: 'miradouro',\n    name: 'Miradouro House',\n    note: 'Viewpoint, 4.7',\n    price: '171',\n  },\n];\n\nfunction ResultsScreen({ frame }: { frame: FrameContextValue }) {\n  return (\n    <div className='flex flex-col gap-2'>\n      <Target id='results-title' frame={frame} className='self-start'>\n        <p className='text-[13px] font-semibold'>3 stays in Lisbon</p>\n      </Target>\n      <ul className='flex flex-col gap-1.5'>\n        {STAYS.map((stay) => (\n          <li\n            key={stay.id}\n            className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex items-center gap-2 rounded-md p-2 text-[11px]'\n          >\n            <span className='bg-foreground/10 size-8 shrink-0 rounded-[5px]' />\n            <span className='flex min-w-0 flex-1 flex-col'>\n              <span className='truncate font-medium'>{stay.name}</span>\n              <span className='text-muted-foreground truncate'>\n                {stay.note}\n              </span>\n            </span>\n            <span className='shrink-0 tabular-nums'>{stay.price} EUR</span>\n            <Target id={stay.id} frame={frame}>\n              <span className='hairline-ring ring-foreground/15 bg-card flex h-6 items-center rounded-full px-2 text-[11px]'>\n                View\n              </span>\n            </Target>\n          </li>\n        ))}\n      </ul>\n    </div>\n  );\n}\n\nfunction DetailsScreen({ frame }: { frame: FrameContextValue }) {\n  return (\n    <div className='flex flex-col gap-2.5'>\n      <span className='bg-foreground/10 h-16 w-full rounded-md' />\n      <div className='flex items-baseline justify-between gap-2'>\n        <Target id='details-title' frame={frame}>\n          <p className='text-[13px] font-semibold'>Casa Alfama</p>\n        </Target>\n        <span className='text-muted-foreground text-[11px]'>Old town, 4.8</span>\n      </div>\n      <dl className='grid grid-cols-[1fr_auto] gap-y-1 text-[11px] tabular-nums'>\n        <dt className='text-muted-foreground'>12 to 14 Dec, 2 nights</dt>\n        <dd>2 × 156.00 EUR</dd>\n        <dt className='font-medium'>Total</dt>\n        <dd className='font-medium'>312.00 EUR</dd>\n      </dl>\n      <Target id='book' frame={frame} className='self-start'>\n        <span className={SITE_BUTTON}>Book 2 nights</span>\n      </Target>\n    </div>\n  );\n}\n\nfunction CheckoutScreen({ frame }: { frame: FrameContextValue }) {\n  return (\n    <div className='flex flex-col gap-2.5'>\n      <Target id='checkout-title' frame={frame} className='self-start'>\n        <p className='text-[13px] font-semibold'>Confirm and pay</p>\n      </Target>\n      <dl className='grid grid-cols-[1fr_auto] gap-y-1 text-[11px] tabular-nums'>\n        <dt className='text-muted-foreground'>Guest</dt>\n        <dd>Dana Reyes</dd>\n        <dt className='text-muted-foreground'>Card</dt>\n        <dd>ending 4417</dd>\n        <dt className='font-medium'>Total</dt>\n        <dd className='font-medium'>312.00 EUR</dd>\n      </dl>\n      <Target id='pay' frame={frame} className='self-start'>\n        <span className={SITE_BUTTON}>Pay 312.00 EUR</span>\n      </Target>\n    </div>\n  );\n}\n\nfunction ConfirmedScreen({ frame }: { frame: FrameContextValue }) {\n  return (\n    <div className='flex flex-col items-center gap-2 py-3 text-center'>\n      <CircleCheckIcon className='text-success-foreground size-6' />\n      <Target id='confirmed-title' frame={frame}>\n        <p className='text-[13px] font-semibold'>Booked</p>\n      </Target>\n      <p className='text-muted-foreground text-[11px]'>\n        Casa Alfama, 12 to 14 Dec, 312.00 EUR\n      </p>\n      <Target id='reference' frame={frame}>\n        <span className='bg-foreground/[0.05] rounded-md px-2 py-1 font-mono text-[11px]'>\n          LKL-48213\n        </span>\n      </Target>\n    </div>\n  );\n}\n\nfunction PageView({ page, frame }: { page: Page; frame: FrameContextValue }) {\n  if (page.screen === 'results') {\n    return <ResultsScreen frame={frame} />;\n  }\n  if (page.screen === 'details') {\n    return <DetailsScreen frame={frame} />;\n  }\n  if (page.screen === 'checkout') {\n    return <CheckoutScreen frame={frame} />;\n  }\n  if (page.screen === 'confirmed') {\n    return <ConfirmedScreen frame={frame} />;\n  }\n  return <SearchScreen page={page} frame={frame} />;\n}\n\nconst SCREEN_SWAP = {\n  initial: { opacity: 0, filter: 'blur(2px)' },\n  animate: { opacity: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, filter: 'blur(2px)' },\n  transition: { duration: 0.2, ease: EASE_OUT_STRONG },\n} as const;\n\nconst SCREEN_FADE = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0 },\n  transition: { duration: 0.15 },\n} as const;\n\nfunction screenMotionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return SCREEN_FADE;\n  }\n  return SCREEN_SWAP;\n}\n\ntype BrowserFrameProps = {\n  page: Page;\n  frame: FrameContextValue;\n  isPaused: boolean;\n  banner: React.ReactNode;\n  overlay: React.ReactNode;\n};\n\nfunction BrowserFrame({\n  page,\n  frame,\n  isPaused,\n  banner,\n  overlay,\n}: BrowserFrameProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const screenMotion = screenMotionOf(shouldReduceMotion);\n\n  return (\n    <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] relative flex flex-col overflow-hidden rounded-lg'>\n      <div className='flex h-9 items-center gap-2 px-2.5'>\n        <Target id='address' frame={frame} className='min-w-0 flex-1'>\n          <span className='bg-card hairline-ring ring-foreground/10 flex h-6 w-full min-w-0 items-center gap-1.5 rounded-full px-2 text-[11px]'>\n            <LockIcon className='text-muted-foreground size-3 shrink-0' />\n            <CompanyMark\n              seed='Lakeline Stays'\n              size='sm'\n              className='rounded-full'\n            />\n            <span className='text-muted-foreground min-w-0 truncate'>\n              {ADDRESS[page.screen]}\n            </span>\n          </span>\n        </Target>\n        <AnimatePresence initial={false}>\n          {isPaused && (\n            <motion.span\n              key='paused'\n              className='flex shrink-0'\n              initial={{ opacity: 0, scale: 0.95 }}\n              animate={{ opacity: 1, scale: 1 }}\n              exit={{ opacity: 0, scale: 0.95 }}\n              transition={{ duration: 0.15 }}\n            >\n              <Chip color='var(--muted-foreground)'>\n                <PauseIcon />\n                Paused\n              </Chip>\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </div>\n      {banner}\n      <div className='bg-card relative m-1.5 mt-0 min-h-56 rounded-md p-3'>\n        <AnimatePresence initial={false} mode='popLayout'>\n          <motion.div key={page.screen} {...screenMotion}>\n            <PageView page={page} frame={frame} />\n          </motion.div>\n        </AnimatePresence>\n        {overlay}\n      </div>\n    </div>\n  );\n}\n\ntype ApprovalCardProps = {\n  onAllow: () => void;\n  onDeny: () => void;\n};\n\nfunction ApprovalCard({ onAllow, onDeny }: ApprovalCardProps) {\n  return (\n    <div\n      role='alertdialog'\n      aria-label='Approve the payment'\n      className='surface-raised absolute inset-x-2 bottom-2 z-30 flex flex-col gap-2.5 rounded-xl p-3'\n    >\n      <p className='flex items-start gap-2 text-xs leading-5'>\n        <TriangleAlertIcon className='text-warning-foreground mt-0.5 size-3.5 shrink-0' />\n        <span>\n          <span className='font-medium'>{AGENT_NAME}</span> wants to pay 312.00\n          EUR to Lakeline Stays with the card ending 4417.\n        </span>\n      </p>\n      <span className='flex items-center gap-2'>\n        <Button type='button' size='sm' onClick={onAllow}>\n          Allow payment\n        </Button>\n        <Button type='button' size='sm' variant='outline' onClick={onDeny}>\n          Deny\n        </Button>\n      </span>\n    </div>\n  );\n}\n\nconst ACTIONS: BrowserAction[] = [\n  {\n    id: 'open',\n    kind: 'navigate',\n    label: 'Open lakeline-stays.example',\n    target: 'address',\n    pageAfter: BLANK_PAGE,\n  },\n  {\n    id: 'destination',\n    kind: 'type',\n    label: 'Type “Lisbon” as the destination',\n    target: 'destination',\n    pageAfter: { screen: 'search', destination: 'Lisbon', dates: '' },\n  },\n  {\n    id: 'dates',\n    kind: 'click',\n    label: 'Pick 12 to 14 December',\n    target: 'dates',\n    pageAfter: {\n      screen: 'search',\n      destination: 'Lisbon',\n      dates: '12 to 14 Dec',\n    },\n  },\n  {\n    id: 'search',\n    kind: 'click',\n    label: 'Click Search',\n    target: 'search',\n    pageAfter: {\n      screen: 'results',\n      destination: 'Lisbon',\n      dates: '12 to 14 Dec',\n    },\n  },\n  {\n    id: 'alfama',\n    kind: 'click',\n    label: 'Open Casa Alfama',\n    target: 'alfama',\n    pageAfter: {\n      screen: 'details',\n      destination: 'Lisbon',\n      dates: '12 to 14 Dec',\n    },\n  },\n  {\n    id: 'book',\n    kind: 'click',\n    label: 'Click Book 2 nights',\n    target: 'book',\n    pageAfter: {\n      screen: 'checkout',\n      destination: 'Lisbon',\n      dates: '12 to 14 Dec',\n    },\n  },\n  {\n    id: 'pay',\n    kind: 'click',\n    label: 'Pay 312.00 EUR',\n    target: 'pay',\n    pageAfter: {\n      screen: 'confirmed',\n      destination: 'Lisbon',\n      dates: '12 to 14 Dec',\n    },\n    isRisky: true,\n  },\n  {\n    id: 'reference',\n    kind: 'navigate',\n    label: 'Read the booking reference',\n    target: 'reference',\n    pageAfter: {\n      screen: 'confirmed',\n      destination: 'Lisbon',\n      dates: '12 to 14 Dec',\n    },\n  },\n];\n\nconst APPROVAL_ID = 'pay-approval';\n\nconst MOVE_MS = 650;\n\nconst SETTLE_MS = 550;\n\n/** A click lands first; the page it opens follows, so the ripple shows on the page where it happened. */\nconst LOAD_MS = 380;\n\ntype ActionOutput = { isLoaded: boolean };\n\nfunction actionOf(id: string) {\n  return ACTIONS.find((action) => action.id === id);\n}\n\nfunction startEvent(action: BrowserAction, status: 'running' | 'waiting') {\n  const event: RunEvent = {\n    type: 'call.started',\n    call: {\n      id: action.id,\n      tool: action.kind,\n      label: action.label,\n      status,\n      input: { target: action.target },\n      output: { isLoaded: false },\n    },\n  };\n  return event;\n}\n\nfunction doneEvent(action: BrowserAction): RunEvent {\n  return { type: 'call.updated', id: action.id, patch: { status: 'done' } };\n}\n\nfunction loadedEvent(action: BrowserAction): RunEvent {\n  return {\n    type: 'call.updated',\n    id: action.id,\n    patch: { output: { isLoaded: true } },\n  };\n}\n\nfunction approvalEvent(): RunEvent {\n  return {\n    type: 'approval.requested',\n    approval: {\n      id: APPROVAL_ID,\n      title: 'Pay 312.00 EUR to Lakeline Stays',\n      risk: 'high',\n      status: 'pending',\n    },\n  };\n}\n\n/** The risky step waits: the script holds on the pending approval until a person answers it. */\nfunction scriptOf(actions: BrowserAction[]): RunScriptStep[] {\n  const steps: RunScriptStep[] = [\n    { after: 500, event: { type: 'run.started' } },\n  ];\n  for (const action of actions) {\n    if (action.isRisky) {\n      steps.push({ after: SETTLE_MS, event: startEvent(action, 'waiting') });\n      steps.push({ after: MOVE_MS, event: approvalEvent() });\n      steps.push({\n        after: 200,\n        event: {\n          type: 'call.updated',\n          id: action.id,\n          patch: { status: 'running' },\n        },\n      });\n    }\n    if (!action.isRisky) {\n      steps.push({ after: SETTLE_MS, event: startEvent(action, 'running') });\n    }\n    steps.push({ after: MOVE_MS, event: doneEvent(action) });\n    steps.push({ after: LOAD_MS, event: loadedEvent(action) });\n  }\n  steps.push({ after: 0, event: { type: 'run.finished', status: 'done' } });\n  return steps;\n}\n\nconst SCRIPT = scriptOf(ACTIONS);\n\nconst INITIAL_RUN = emptyRun({ id: 'browser', title: 'Book a stay in Lisbon' });\n\nfunction isActionOutput(value: unknown): value is ActionOutput {\n  if (typeof value !== 'object' || value === null) {\n    return false;\n  }\n  return typeof (value as ActionOutput).isLoaded === 'boolean';\n}\n\nfunction isLoaded(call: ToolCall) {\n  if (!isActionOutput(call.output)) {\n    return false;\n  }\n  return call.output.isLoaded;\n}\n\nfunction pageBefore(index: number) {\n  const previous = ACTIONS[index - 1];\n  return previous?.pageAfter ?? BLANK_PAGE;\n}\n\nfunction livePageOf(calls: ToolCall[]) {\n  const loaded = calls.filter(isLoaded);\n  const last = loaded.at(-1);\n  if (!last) {\n    return BLANK_PAGE;\n  }\n  const action = actionOf(last.id);\n  return action?.pageAfter ?? BLANK_PAGE;\n}\n\nfunction lastClickOf(calls: ToolCall[]) {\n  const clicks = calls.filter((call) => {\n    const isDone = call.status === 'done';\n    const isClick = call.tool === 'click';\n    return isDone && isClick;\n  });\n  return clicks.at(-1);\n}\n\nfunction offsetOf(run: RunSnapshot, call: ToolCall) {\n  const runStart = run.startedAt ?? 0;\n  const callStart = call.startedAt ?? runStart;\n  return callStart - runStart;\n}\n\nfunction rowToneOf(isViewed: boolean) {\n  if (isViewed) {\n    return 'bg-primary/[0.07]';\n  }\n  return 'hover:bg-foreground/[0.03]';\n}\n\ntype ActionLogProps = {\n  run: RunSnapshot;\n  viewedIndex: number;\n  onView: (index: number) => void;\n};\n\nfunction ActionLog({ run, viewedIndex, onView }: ActionLogProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = risePresenceOf(shouldReduceMotion);\n\n  return (\n    <ol aria-label='Actions' className='flex flex-col'>\n      <AnimatePresence initial={false}>\n        {run.calls.map((call, index) => {\n          const action = actionOf(call.id);\n          const KindIcon = KIND_ICON[action?.kind ?? 'click'];\n          const offset = offsetOf(run, call);\n          const isViewed = index === viewedIndex;\n          return (\n            <motion.li key={call.id} {...rowPresence}>\n              <button\n                type='button'\n                aria-current={currentOf(isViewed)}\n                onClick={() => onView(index)}\n                className={cn(\n                  'focus-visible:ring-ring/25 flex min-h-9 w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-start text-xs transition-colors duration-150 outline-none focus-visible:ring-[3px]',\n                  rowToneOf(isViewed)\n                )}\n              >\n                <span className='text-muted-foreground w-8 shrink-0 tabular-nums'>\n                  <span aria-hidden='true'>{formatClock(offset)}</span>\n                  <span className='sr-only'>{spokenClockOf(offset)}</span>\n                </span>\n                <KindIcon className='text-muted-foreground size-3.5 shrink-0' />\n                <span className='min-w-0 flex-1 truncate'>{call.label}</span>\n                <CallStatusMark status={call.status} />\n              </button>\n            </motion.li>\n          );\n        })}\n      </AnimatePresence>\n    </ol>\n  );\n}\n\nfunction currentOf(isViewed: boolean) {\n  if (isViewed) {\n    return 'step' as const;\n  }\n  return undefined;\n}\n\ntype Control = 'agent' | 'paused' | 'you';\n\nfunction bannerOf(control: Control, isDenied: boolean, onHandBack: () => void) {\n  if (isDenied) {\n    return (\n      <p className='bg-destructive/10 text-destructive-ink mx-1.5 mb-1.5 rounded-md px-2.5 py-1.5 text-xs'>\n        Payment denied. {AGENT_NAME} stopped before paying.\n      </p>\n    );\n  }\n  if (control !== 'you') {\n    return null;\n  }\n  return (\n    <div className='bg-primary/10 text-primary-ink mx-1.5 mb-1.5 flex items-center gap-2 rounded-md py-1 ps-2.5 pe-1 text-xs'>\n      <HandIcon className='size-3.5 shrink-0' />\n      <span className='min-w-0 flex-1'>\n        You have control. {AGENT_NAME} waits until you hand back.\n      </span>\n      <Button\n        type='button'\n        size='sm'\n        variant='ghost'\n        onClick={onHandBack}\n        className='h-6 px-2'\n      >\n        Hand back\n      </Button>\n    </div>\n  );\n}\n\nfunction stepTextOf(index: number, total: number) {\n  const position = index + 1;\n  return `Step ${position} of ${total}`;\n}\n\nfunction announcementOf(run: RunSnapshot, control: Control, isDenied: boolean) {\n  if (isDenied) {\n    return 'Payment denied. The agent stopped';\n  }\n  if (control === 'you') {\n    return 'You have control of the browser';\n  }\n  if (control === 'paused') {\n    return 'The agent is paused';\n  }\n  const pending = pendingApprovalsOf(run);\n  if (pending.length > 0) {\n    return 'The agent waits for your approval to pay 312.00 EUR';\n  }\n  const last = run.calls.at(-1);\n  if (!last) {\n    return '';\n  }\n  if (run.status === 'done') {\n    return 'Booking done';\n  }\n  return `${AGENT_NAME}: ${last.label}`;\n}\n\nexport default function Review10() {\n  const [control, setControl] = useState<Control>('agent');\n  const [isDenied, setIsDenied] = useState(false);\n  const [isHeld, setIsHeld] = useState(false);\n  const [viewIndex, setViewIndex] = useState<number | null>(null);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const pointerId = useId();\n  const isInView = useInView(rootRef, { amount: 0.3 });\n  const isAgentInControl = control === 'agent';\n  const isFree = !isHeld && !isDenied;\n  const isActive = isInView && isAgentInControl && isFree;\n  const { snapshot, store, restart } = useRunScript(SCRIPT, {\n    initial: INITIAL_RUN,\n    isActive,\n  });\n  const pending = pendingApprovalsOf(snapshot);\n  const shouldHold = pending.length > 0;\n  if (shouldHold !== isHeld) {\n    setIsHeld(shouldHold);\n  }\n  const calls = snapshot.calls;\n  const liveIndex = calls.length - 1;\n  const isViewingPast = viewIndex !== null;\n  const shownIndex = viewIndex ?? liveIndex;\n  const shownCall = calls[shownIndex];\n  const shownAction = actionOf(shownCall?.id ?? '');\n  const page = shownPageOf(isViewingPast, shownIndex, calls);\n  const lastClick = lastClickOf(calls);\n  const isWaiting = shouldHold && !isViewingPast;\n  const isYours = control === 'you';\n  const isPaused = control === 'paused';\n  const frame: FrameContextValue = {\n    pointerTarget: pointerTargetOf(shownAction, page),\n    pointerId,\n    rippleTarget: rippleTargetOf(isViewingPast, lastClick),\n    rippleKey: lastClick?.id ?? '',\n    isPointerShown: !isYours,\n    riskyTarget: riskyTargetOf(isWaiting),\n  };\n  const isFinished = snapshot.status === 'done';\n  const hasActions = calls.length > 0;\n  const announcement = announcementOf(snapshot, control, isDenied);\n  const stepText = stepTextOf(shownIndex, ACTIONS.length);\n  const canControl = !isFinished && !isDenied;\n\n  function allow() {\n    store.dispatch({\n      type: 'approval.resolved',\n      id: APPROVAL_ID,\n      decision: 'approved',\n    });\n  }\n\n  function deny() {\n    store.dispatch({\n      type: 'approval.resolved',\n      id: APPROVAL_ID,\n      decision: 'denied',\n    });\n    store.dispatch({\n      type: 'call.updated',\n      id: 'pay',\n      patch: { status: 'failed', error: 'Denied by you' },\n    });\n    store.dispatch({ type: 'run.finished', status: 'cancelled' });\n    setIsDenied(true);\n  }\n\n  function togglePause() {\n    if (control === 'paused') {\n      setControl('agent');\n      return;\n    }\n    setControl('paused');\n  }\n\n  function toggleTakeOver() {\n    if (control === 'you') {\n      setControl('agent');\n      return;\n    }\n    setControl('you');\n  }\n\n  function view(index: number) {\n    if (index === liveIndex) {\n      setViewIndex(null);\n      return;\n    }\n    setViewIndex(index);\n  }\n\n  function scrub(value: number | readonly number[]) {\n    const next = sliderValueOf(value);\n    view(next);\n  }\n\n  function replay() {\n    setControl('agent');\n    setIsDenied(false);\n    setViewIndex(null);\n    restart();\n  }\n\n  const banner = bannerOf(control, isDenied, toggleTakeOver);\n  const showsApproval = isWaiting && !isYours;\n\n  useKeptHeight(rootRef);\n\n  return (\n    <div\n      ref={rootRef}\n      className='bg-card hairline-ring ring-border @container w-full max-w-[56rem] rounded-xl p-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n    >\n      <div className='grid grid-cols-1 gap-3 @2xl:grid-cols-[minmax(0,1fr)_17rem]'>\n        <div className='flex min-w-0 flex-col gap-2.5'>\n          <BrowserFrame\n            page={page}\n            frame={frame}\n            isPaused={isPaused}\n            banner={banner}\n            overlay={\n              <AnimatePresence initial={false}>\n                {showsApproval && (\n                  <motion.div\n                    key='approval'\n                    initial={{ opacity: 0 }}\n                    animate={{ opacity: 1 }}\n                    exit={{ opacity: 0 }}\n                  >\n                    <ApprovalCard onAllow={allow} onDeny={deny} />\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            }\n          />\n          <div className='flex items-center gap-3 px-1'>\n            <Slider\n              value={Math.max(0, shownIndex)}\n              min={0}\n              max={Math.max(1, liveIndex)}\n              step={1}\n              disabled={!hasActions}\n              onValueChange={scrub}\n              thumbLabels={['Frame']}\n              getAriaValueText={(_formatted, value) =>\n                stepTextOf(value, ACTIONS.length)\n              }\n              className='min-w-0 flex-1'\n            />\n            <span className='text-muted-foreground w-24 shrink-0 text-end text-xs tabular-nums'>\n              {stepText}\n            </span>\n          </div>\n          <div className='flex flex-wrap items-center gap-2 px-1'>\n            <Button\n              type='button'\n              variant='outline'\n              size='sm'\n              disabled={!canControl}\n              onClick={togglePause}\n            >\n              <Swap swapKey={pauseLabelOf(control)}>\n                {isPaused && <PlayIcon />}\n                {!isPaused && <PauseIcon />}\n              </Swap>\n              {pauseLabelOf(control)}\n            </Button>\n            <Button\n              type='button'\n              variant='outline'\n              size='sm'\n              disabled={!canControl}\n              onClick={toggleTakeOver}\n            >\n              <HandIcon />\n              {takeOverLabelOf(control)}\n            </Button>\n            <AnimatePresence initial={false}>\n              {isViewingPast && (\n                <motion.span\n                  key='live'\n                  className='flex'\n                  initial={{ opacity: 0, scale: 0.95 }}\n                  animate={{ opacity: 1, scale: 1 }}\n                  exit={{ opacity: 0, scale: 0.95 }}\n                  transition={{ duration: 0.15 }}\n                >\n                  <Button\n                    type='button'\n                    variant='ghost'\n                    size='sm'\n                    onClick={() => setViewIndex(null)}\n                  >\n                    Back to live\n                  </Button>\n                </motion.span>\n              )}\n            </AnimatePresence>\n            {isFinished && (\n              <Button\n                type='button'\n                variant='ghost'\n                size='sm'\n                onClick={replay}\n                className='ms-auto'\n              >\n                Watch again\n              </Button>\n            )}\n            {isDenied && (\n              <Button\n                type='button'\n                variant='ghost'\n                size='sm'\n                onClick={replay}\n                className='ms-auto'\n              >\n                Start over\n              </Button>\n            )}\n          </div>\n        </div>\n        <section\n          aria-label='Action log'\n          className='bg-foreground/[0.02] dark:bg-foreground/[0.035] flex min-w-0 flex-col gap-1 rounded-lg p-1.5'\n        >\n          <header className='flex items-center gap-2 px-2 pt-1 pb-1.5'>\n            <MeshTile seed={AGENT_NAME} color={seriesColorOf(AGENT_SERIES)} />\n            <span className='min-w-0 flex-1 truncate text-[13px] font-medium'>\n              {AGENT_NAME}\n            </span>\n            <BrandTile brand='claude' size='sm' />\n            <span className='text-muted-foreground text-xs'>Claude Sonnet</span>\n          </header>\n          <ActionLog run={snapshot} viewedIndex={shownIndex} onView={view} />\n          {!hasActions && (\n            <p className='text-muted-foreground px-2 py-3 text-xs'>\n              Actions show here as the agent works\n            </p>\n          )}\n        </section>\n      </div>\n      <LiveRegion message={announcement} />\n    </div>\n  );\n}\n\nfunction shownPageOf(\n  isViewingPast: boolean,\n  shownIndex: number,\n  calls: ToolCall[]\n) {\n  if (isViewingPast) {\n    return pageBefore(shownIndex);\n  }\n  return livePageOf(calls);\n}\n\nfunction rippleTargetOf(\n  isViewingPast: boolean,\n  lastClick: ToolCall | undefined\n) {\n  if (isViewingPast) {\n    return null;\n  }\n  if (!lastClick) {\n    return null;\n  }\n  const action = actionOf(lastClick.id);\n  return action?.target ?? null;\n}\n\nfunction riskyTargetOf(isWaiting: boolean) {\n  if (isWaiting) {\n    return 'pay';\n  }\n  return null;\n}\n\nfunction sliderValueOf(value: number | readonly number[]) {\n  if (typeof value === 'number') {\n    return value;\n  }\n  return value[0] ?? 0;\n}\n\nfunction pauseLabelOf(control: Control) {\n  if (control === 'paused') {\n    return 'Resume';\n  }\n  return 'Pause';\n}\n\nfunction takeOverLabelOf(control: Control) {\n  if (control === 'you') {\n    return 'Hand back';\n  }\n  return 'Take over';\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "review"
  ],
  "type": "registry:component"
}