{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-ops-06",
  "title": "Webhooks",
  "description": "Endpoints beside the detail of the one you pick: a failed delivery opens its response, payload and headers, Retry turns into a spinner then Delivered while the delivery rate rolls back up, and a new endpoint shows its signing secret once.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/copy-button.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/json-view.json",
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/morph-button.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/tabs.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/toggle.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-06/index.tsx",
      "content": "'use client';\n\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { EndpointDetail } from './endpoint-detail';\nimport { EndpointList, HEALTH_WORD, shortUrlOf } from './endpoint-list';\nimport {\n  endpointOf,\n  healthOf,\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  RETRY_MS,\n  SCRIPT,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\n/** On a phone one view shows at a time; a wide block always shows both. */\nfunction listVisibilityOf(isDetailOpen: boolean) {\n  if (isDetailOpen) {\n    return 'hidden';\n  }\n  return 'block';\n}\n\nfunction detailVisibilityOf(isDetailOpen: boolean) {\n  if (isDetailOpen) {\n    return 'block';\n  }\n  return 'hidden';\n}\n\nexport default function AgentOps06() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const { schedule } = useTimeouts();\n  const endpoint = endpointOf(state, state.selectedId);\n  const health = healthOf(state, endpoint.id);\n  const announcement = `${shortUrlOf(endpoint.url)}: ${HEALTH_WORD[health]}`;\n  const message = spokenUnless(isAutoplaying, announcement);\n  const canReplay = isFinished && !isAutoplaying;\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const target = ref.current?.querySelector<HTMLElement>(selector);\n      target?.focus();\n    });\n  }\n\n  function select(id: string) {\n    act({ type: 'selected', id });\n    focusLater('[data-back]');\n  }\n\n  function back() {\n    act({ type: 'back' });\n    focusLater(`[data-endpoint=\"${state.selectedId}\"]`);\n  }\n\n  function retry(id: string) {\n    act({ type: 'retry', id });\n    schedule(() => act({ type: 'retried', id }), RETRY_MS);\n  }\n\n  function openForm() {\n    act({ type: 'formOpened' });\n    focusLater('[data-form-first]');\n  }\n\n  function closeForm() {\n    act({ type: 'formClosed' });\n    focusLater('[data-add-endpoint]');\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container min-h-dvh w-full'\n      >\n        <div className='mx-auto flex max-w-6xl flex-col gap-4 p-4 @3xl:p-8 @4xl:flex-row @4xl:items-start @4xl:gap-6'>\n          <div\n            className={cn(\n              'transition-opacity duration-200 @4xl:block @4xl:w-[24rem] @4xl:shrink-0 starting:opacity-0',\n              listVisibilityOf(state.isDetailOpen)\n            )}\n          >\n            <EndpointList\n              state={state}\n              pressed={pressed}\n              onAction={act}\n              onSelect={select}\n              onOpenForm={openForm}\n              onCloseForm={closeForm}\n            />\n            <div className='flex h-9 items-end'>\n              <ReplayButton\n                isShown={canReplay}\n                onReplay={restart}\n                label='Replay the retry'\n              />\n            </div>\n          </div>\n          <div\n            className={cn(\n              'min-w-0 flex-1 @4xl:block',\n              detailVisibilityOf(state.isDetailOpen)\n            )}\n          >\n            <EndpointDetail\n              endpoint={endpoint}\n              state={state}\n              pressed={pressed}\n              onAction={act}\n              onBack={back}\n              onRetry={retry}\n            />\n          </div>\n        </div>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-06/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-06/endpoint-list.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { CheckIcon, PlusIcon } from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { CopyButton } from '@/registry/ndeko/ui/copy-button';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { Toggle } from '@/registry/ndeko/ui/toggle';\n\nimport { EVENT_NAMES, type Endpoint, type EventName } from './data';\nimport {\n  healthOf,\n  hoursOf,\n  totalsOf,\n  type FormState,\n  type Health,\n  type WebhookAction,\n  type WebhookState,\n} from './session';\n\nconst RATE_FORMAT = new Intl.NumberFormat('en-US', {\n  minimumFractionDigits: 1,\n  maximumFractionDigits: 1,\n});\n\nexport const HEALTH_WORD: Record<Health, string> = {\n  healthy: 'Healthy',\n  retrying: 'Retrying',\n  failing: 'Failing',\n};\n\n/** Retrying is the one live state, so it is the one that breathes. */\nexport const HEALTH_DOT: Record<Health, string> = {\n  healthy: 'bg-success',\n  retrying: 'bg-info animate-pulse',\n  failing: 'bg-destructive',\n};\n\nexport function rateTextOf(rate: number) {\n  return `${RATE_FORMAT.format(rate)}%`;\n}\n\nexport function shortUrlOf(url: string) {\n  return url.replace('https://', '');\n}\n\nfunction rowToneOf(isSelected: boolean) {\n  if (isSelected) {\n    return 'bg-foreground/[0.05]';\n  }\n  return 'hover:bg-foreground/[0.03]';\n}\n\nfunction pressedQuietOf(isPressed: boolean) {\n  if (isPressed) {\n    return 'scale-[0.985] bg-foreground/[0.07]';\n  }\n  return undefined;\n}\n\n/** The arrow keys walk the rows of a list. */\nexport function moveBetweenRows(event: React.KeyboardEvent<HTMLElement>) {\n  const isDown = event.key === 'ArrowDown';\n  const isUp = event.key === 'ArrowUp';\n  if (!isDown && !isUp) {\n    return;\n  }\n  const found = event.currentTarget.querySelectorAll<HTMLElement>('[data-row]');\n  const rows = Array.from(found);\n  const current = rows.findIndex((row) => row === document.activeElement);\n  if (current === -1) {\n    return;\n  }\n  let next = current - 1;\n  if (isDown) {\n    next = current + 1;\n  }\n  const target = rows[next];\n  if (target) {\n    event.preventDefault();\n    target.focus();\n  }\n}\n\ntype EndpointRowProps = {\n  endpoint: Endpoint;\n  state: WebhookState;\n  isPressed: boolean;\n  onSelect: (id: string) => void;\n};\n\nfunction EndpointRow({\n  endpoint,\n  state,\n  isPressed,\n  onSelect,\n}: EndpointRowProps) {\n  const health = healthOf(state, endpoint.id);\n  const hours = hoursOf(state, endpoint);\n  const totals = totalsOf(hours);\n  const hasTraffic = totals.ok + totals.failed > 0;\n  const isSelected = state.selectedId === endpoint.id;\n  const shortUrl = shortUrlOf(endpoint.url);\n\n  return (\n    <button\n      type='button'\n      data-row\n      data-endpoint={endpoint.id}\n      aria-pressed={isSelected}\n      onClick={() => onSelect(endpoint.id)}\n      className={cn(\n        'focus-visible:ring-ring/25 flex w-full cursor-pointer flex-col gap-2 rounded-lg px-2.5 py-2.5 text-start transition-[background-color,scale] duration-150 outline-none focus-visible:ring-[3px] focus-visible:ring-inset',\n        rowToneOf(isSelected),\n        pressedQuietOf(isPressed)\n      )}\n    >\n      <span className='flex items-center gap-2'>\n        <span\n          aria-hidden='true'\n          className={cn(\n            'size-2 shrink-0 rounded-full transition-colors duration-300',\n            HEALTH_DOT[health]\n          )}\n        />\n        <code className='min-w-0 flex-1 truncate font-mono text-xs'>\n          {shortUrl}\n        </code>\n        <span className='sr-only'>{HEALTH_WORD[health]}</span>\n        {hasTraffic && (\n          <span className='text-muted-foreground shrink-0 text-xs tabular-nums'>\n            {rateTextOf(totals.rate)}\n          </span>\n        )}\n        {!hasTraffic && (\n          <span className='text-muted-foreground shrink-0 text-xs'>\n            No delivery yet\n          </span>\n        )}\n      </span>\n      <span className='flex flex-wrap gap-1 ps-4'>\n        {endpoint.events.map((event) => (\n          <Badge\n            key={event}\n            variant='secondary'\n            className='font-mono text-[11px]'\n          >\n            {event}\n          </Badge>\n        ))}\n      </span>\n    </button>\n  );\n}\n\ntype EndpointFormProps = {\n  form: FormState;\n  pressed: string | null;\n  onAction: (action: WebhookAction) => void;\n  onClose: () => void;\n};\n\nfunction EndpointForm({ form, pressed, onAction, onClose }: EndpointFormProps) {\n  const urlId = useId();\n  const errorId = useId();\n  const hasError = form.error !== null;\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onAction({ type: 'created' });\n  }\n\n  function toggle(event: EventName) {\n    onAction({ type: 'eventToggled', event });\n  }\n\n  return (\n    <form noValidate onSubmit={submit} className='flex flex-col gap-3'>\n      <div className='flex flex-col gap-1.5'>\n        <Label htmlFor={urlId}>Endpoint URL</Label>\n        <Input\n          id={urlId}\n          data-form-first\n          type='url'\n          inputMode='url'\n          autoComplete='off'\n          autoCapitalize='off'\n          spellCheck={false}\n          placeholder='https://example.com/hooks'\n          value={form.url}\n          aria-invalid={hasError}\n          aria-describedby={errorId}\n          onChange={(event) =>\n            onAction({ type: 'urlTyped', text: event.target.value })\n          }\n          className='font-mono'\n        />\n      </div>\n      <div className='flex flex-col gap-1.5'>\n        <span className='text-[13px] leading-none font-medium'>Events</span>\n        <div role='group' aria-label='Events' className='flex flex-wrap gap-1'>\n          {EVENT_NAMES.map((event) => {\n            const isOn = form.events.includes(event);\n            return (\n              <Toggle\n                key={event}\n                size='sm'\n                variant='outline'\n                pressed={isOn}\n                onPressedChange={() => toggle(event)}\n                className='gap-1 rounded-full px-2.5 font-mono text-xs'\n              >\n                {isOn && <CheckIcon className='size-3' />}\n                {event}\n              </Toggle>\n            );\n          })}\n        </div>\n      </div>\n      <p id={errorId} aria-live='polite' className='empty:hidden'>\n        {hasError && (\n          <span className='text-destructive-ink text-xs'>{form.error}</span>\n        )}\n      </p>\n      <div className='flex items-center justify-end gap-2'>\n        <Button type='button' variant='ghost' size='sm' onClick={onClose}>\n          Cancel\n        </Button>\n        <Button\n          type='submit'\n          size='sm'\n          className={pressedSolidOf(pressed === 'create')}\n        >\n          Create endpoint\n        </Button>\n      </div>\n    </form>\n  );\n}\n\ntype CreatedNoticeProps = {\n  secret: string;\n  onDone: () => void;\n};\n\n/** The one time the secret of a new endpoint is on screen. */\nfunction CreatedNotice({ secret, onDone }: CreatedNoticeProps) {\n  return (\n    <div className='flex flex-col gap-2.5 transition-opacity duration-300 starting:opacity-0'>\n      <p className='flex items-center gap-1.5 text-[13px] font-medium'>\n        <CheckIcon className='text-success-foreground size-4 shrink-0' />\n        Endpoint created\n      </p>\n      <p className='text-muted-foreground text-xs'>\n        Its signing secret is shown once. Copy it before you close this.\n      </p>\n      <div className='bg-card hairline-ring ring-foreground/12 dark:bg-foreground/[0.04] flex h-8 items-center gap-1 rounded-md ps-2.5 pe-1'>\n        <code className='min-w-0 flex-1 truncate font-mono text-xs'>\n          {secret}\n        </code>\n        <CopyButton text={secret} label='Copy the signing secret' />\n      </div>\n      <Button\n        type='button'\n        variant='outline'\n        size='sm'\n        onClick={onDone}\n        className='self-end'\n      >\n        Done\n      </Button>\n    </div>\n  );\n}\n\nexport type EndpointListProps = {\n  state: WebhookState;\n  pressed: string | null;\n  onAction: (action: WebhookAction) => void;\n  onSelect: (id: string) => void;\n  onOpenForm: () => void;\n  onCloseForm: () => void;\n};\n\nexport function EndpointList({\n  state,\n  pressed,\n  onAction,\n  onSelect,\n  onOpenForm,\n  onCloseForm,\n}: EndpointListProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const form = state.form;\n  const isFormOpen = form.phase !== 'closed';\n  let createdSecret: string | null = null;\n  if (form.phase === 'created') {\n    createdSecret = form.secret;\n  }\n\n  return (\n    <section aria-label='Endpoints' className='flex flex-col gap-3'>\n      <header className='flex flex-wrap items-center gap-x-3 gap-y-2'>\n        <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n          <h1 className='text-lg font-semibold text-balance'>Webhooks</h1>\n          <p className='text-muted-foreground text-xs'>\n            Where agent events are sent\n          </p>\n        </div>\n        <Button\n          type='button'\n          size='sm'\n          data-add-endpoint\n          aria-expanded={isFormOpen}\n          disabled={isFormOpen}\n          onClick={onOpenForm}\n          className={pressedSolidOf(pressed === 'add')}\n        >\n          <PlusIcon />\n          Add endpoint\n        </Button>\n      </header>\n\n      <Fold open={isFormOpen}>\n        <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] rounded-xl p-3'>\n          {createdSecret === null && (\n            <EndpointForm\n              form={form}\n              pressed={pressed}\n              onAction={onAction}\n              onClose={onCloseForm}\n            />\n          )}\n          {createdSecret !== null && (\n            <CreatedNotice secret={createdSecret} onDone={onCloseForm} />\n          )}\n        </div>\n      </Fold>\n\n      <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] rounded-xl p-1 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n        <ul className='flex flex-col gap-0.5' onKeyDown={moveBetweenRows}>\n          <AnimatePresence initial={false}>\n            {state.endpoints.map((endpoint) => (\n              <motion.li\n                key={endpoint.id}\n                className='overflow-hidden'\n                {...rowPresence}\n              >\n                <EndpointRow\n                  endpoint={endpoint}\n                  state={state}\n                  isPressed={pressed === `endpoint-${endpoint.id}`}\n                  onSelect={onSelect}\n                />\n              </motion.li>\n            ))}\n          </AnimatePresence>\n        </ul>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-06/endpoint-list.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-06/endpoint-detail.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  ArrowLeftIcon,\n  CheckIcon,\n  CircleCheckIcon,\n  CircleXIcon,\n  EyeIcon,\n  EyeOffIcon,\n  LoaderIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { CopyButton } from '@/registry/ndeko/ui/copy-button';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\n\nimport type { Delivery, DeliveryStatus, Endpoint, HourBucket } from './data';\nimport { HEALTH_DOT, HEALTH_WORD, moveBetweenRows } from './endpoint-list';\nimport { codeVariantOf, codeWordOf, Inspector } from './inspector';\nimport {\n  deliveriesOf,\n  healthOf,\n  hoursOf,\n  totalsOf,\n  type DayTotals,\n  type WebhookAction,\n  type WebhookState,\n} from './session';\n\nconst RATE_FORMAT: Intl.NumberFormatOptions = {\n  minimumFractionDigits: 1,\n  maximumFractionDigits: 1,\n};\n\nconst HEALTH_WORDS = Object.values(HEALTH_WORD);\n\nconst SECRET_PREFIX = 'whsec_';\n\nconst SHOWN_TAIL = 4;\n\nconst RETRY_STATE: Record<DeliveryStatus, MorphState> = {\n  failed: 'idle',\n  pending: 'busy',\n  done: 'done',\n};\n\nconst RETRY_LABELS: Record<MorphState, string> = {\n  idle: 'Retry',\n  busy: 'Retrying',\n  done: 'Delivered',\n};\n\n/** whsec_ and the last four characters stay readable, so two secrets can be told apart. */\nfunction maskedOf(secret: string) {\n  const tail = secret.slice(-SHOWN_TAIL);\n  return `${SECRET_PREFIX}••••••••••••${tail}`;\n}\n\nfunction shownSecretOf(secret: string, isShown: boolean) {\n  if (isShown) {\n    return secret;\n  }\n  return maskedOf(secret);\n}\n\nfunction revealLabelOf(isShown: boolean) {\n  if (isShown) {\n    return 'Hide the signing secret';\n  }\n  return 'Show the signing secret';\n}\n\nfunction deliveredWordOf(totals: DayTotals) {\n  const total = totals.ok + totals.failed;\n  if (total === 0) {\n    return 'No delivery in the last 24 hours';\n  }\n  if (totals.failed === 0) {\n    return `${total} delivered, none failed`;\n  }\n  return `${total} sent, ${totals.failed} failed`;\n}\n\nfunction maxTotalOf(hours: HourBucket[]) {\n  let max = 1;\n  for (const bucket of hours) {\n    max = Math.max(max, bucket.ok + bucket.failed);\n  }\n  return max;\n}\n\nfunction barStyleOf(bucket: HourBucket, max: number) {\n  const total = bucket.ok + bucket.failed;\n  const share = Math.max(0.06, total / max);\n  return { transform: `scaleY(${share})` };\n}\n\nfunction barToneOf(bucket: HourBucket) {\n  if (bucket.failed > 0) {\n    return 'bg-destructive';\n  }\n  return 'bg-foreground/25';\n}\n\nfunction rowToneOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'bg-foreground/[0.05]';\n  }\n  return 'hover:bg-foreground/[0.03]';\n}\n\nfunction pressedQuietOf(isPressed: boolean) {\n  if (isPressed) {\n    return 'scale-[0.985] bg-foreground/[0.07]';\n  }\n  return undefined;\n}\n\nfunction pressedButtonOf(isPressed: boolean) {\n  if (isPressed) {\n    return 'scale-[0.94] bg-foreground/[0.07]';\n  }\n  return undefined;\n}\n\n/** A delivery shows the retry control while it fails or once it has been sent again. */\nfunction showsRetry(delivery: Delivery) {\n  const wasSentAgain = delivery.attempt > 1;\n  const isSettled = delivery.status === 'done';\n  return wasSentAgain || !isSettled;\n}\n\ntype HourStripProps = {\n  hours: HourBucket[];\n  summary: string;\n};\n\n/** One bar per hour, as tall as its traffic; an hour with a failure takes the failure colour. */\nfunction HourStrip({ hours, summary }: HourStripProps) {\n  const max = maxTotalOf(hours);\n\n  return (\n    <div className='flex flex-col gap-1.5'>\n      <div\n        role='img'\n        aria-label={`Deliveries per hour over 24 hours. ${summary}`}\n        className='flex h-10 items-end gap-[3px]'\n      >\n        {hours.map((bucket, hour) => (\n          <span\n            key={hour}\n            style={barStyleOf(bucket, max)}\n            className={cn(\n              'h-full min-w-0 flex-1 origin-bottom rounded-t-[2px] transition-[transform,background-color] duration-300 ease-(--ease-out-strong)',\n              barToneOf(bucket)\n            )}\n          />\n        ))}\n      </div>\n      <div\n        aria-hidden='true'\n        className='text-muted-foreground flex justify-between text-[11px]'\n      >\n        <span>24 h ago</span>\n        <span>Now</span>\n      </div>\n    </div>\n  );\n}\n\nfunction DeliveryMark({ status }: { status: DeliveryStatus }) {\n  return (\n    <Swap swapKey={status} className='size-4 shrink-0'>\n      {status === 'done' && (\n        <CircleCheckIcon className='text-success-foreground size-4' />\n      )}\n      {status === 'failed' && (\n        <CircleXIcon className='text-destructive-ink size-4' />\n      )}\n      {status === 'pending' && (\n        <LoaderIcon className='text-muted-foreground size-4 animate-spin' />\n      )}\n    </Swap>\n  );\n}\n\ntype DeliveryRowProps = {\n  delivery: Delivery;\n  isOpen: boolean;\n  hasRetryColumn: boolean;\n  pressed: string | null;\n  onOpen: (id: string) => void;\n  onRetry: (id: string) => void;\n};\n\nfunction DeliveryRow({\n  delivery,\n  isOpen,\n  hasRetryColumn,\n  pressed,\n  onOpen,\n  onRetry,\n}: DeliveryRowProps) {\n  const codeWord = codeWordOf(delivery);\n\n  return (\n    <div className='flex items-center gap-1.5'>\n      <button\n        type='button'\n        data-row\n        aria-expanded={isOpen}\n        onClick={() => onOpen(delivery.id)}\n        className={cn(\n          'focus-visible:ring-ring/25 flex h-10 min-w-0 flex-1 cursor-pointer items-center gap-2.5 rounded-lg px-2 text-start transition-[background-color,scale] duration-150 outline-none focus-visible:ring-[3px] focus-visible:ring-inset',\n          rowToneOf(isOpen),\n          pressedQuietOf(pressed === `delivery-${delivery.id}`)\n        )}\n      >\n        <DeliveryMark status={delivery.status} />\n        <code className='min-w-0 flex-1 truncate font-mono text-xs'>\n          {delivery.event}\n        </code>\n        <Badge\n          variant={codeVariantOf(delivery.status)}\n          className='tabular-nums transition-colors duration-300'\n        >\n          <Swap swapKey={codeWord}>{codeWord}</Swap>\n        </Badge>\n        <span className='text-muted-foreground hidden w-16 shrink-0 text-end text-xs tabular-nums @sm:block'>\n          {delivery.time}\n        </span>\n      </button>\n      {hasRetryColumn && (\n        <span className='flex w-[5.5rem] shrink-0 justify-end'>\n          {showsRetry(delivery) && (\n            <MorphButton\n              type='button'\n              size='sm'\n              variant='outline'\n              state={RETRY_STATE[delivery.status]}\n              labels={RETRY_LABELS}\n              onClick={() => onRetry(delivery.id)}\n              className={pressedButtonOf(pressed === `retry-${delivery.id}`)}\n            />\n          )}\n        </span>\n      )}\n    </div>\n  );\n}\n\ntype SecretRowProps = {\n  endpoint: Endpoint;\n  state: WebhookState;\n  onAction: (action: WebhookAction) => void;\n};\n\nfunction SecretRow({ endpoint, state, onAction }: SecretRowProps) {\n  const isShown = state.isSecretShown;\n  const isAsking = state.rotate === 'asking';\n  const isRotated = state.rotate === 'rotated';\n  const shownSecret = shownSecretOf(endpoint.secret, isShown);\n\n  return (\n    <div className='flex flex-col gap-2'>\n      <h3 className='text-muted-foreground text-xs'>Signing secret</h3>\n      <div className='flex items-center gap-1'>\n        <code className='bg-foreground/[0.04] dark:bg-foreground/[0.06] h-8 min-w-0 flex-1 truncate rounded-md px-2.5 font-mono text-xs leading-8'>\n          {shownSecret}\n        </code>\n        <Button\n          type='button'\n          variant='ghost'\n          size='icon'\n          aria-pressed={isShown}\n          aria-label={revealLabelOf(isShown)}\n          onClick={() => onAction({ type: 'secretToggled' })}\n          className='text-muted-foreground'\n        >\n          <Swap swapKey={String(isShown)}>\n            {isShown && <EyeOffIcon />}\n            {!isShown && <EyeIcon />}\n          </Swap>\n        </Button>\n        <Button\n          type='button'\n          variant='outline'\n          aria-expanded={isAsking}\n          disabled={isRotated}\n          onClick={() => onAction({ type: 'rotateAsked' })}\n        >\n          Rotate\n        </Button>\n      </div>\n      <Fold open={isAsking}>\n        <div className='bg-destructive/10 flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg p-2.5'>\n          <p className='min-w-48 flex-1 text-xs leading-5'>\n            Rotate the secret? Deliveries signed with the old one are refused\n            from that moment.\n          </p>\n          <div className='flex items-center gap-2'>\n            <Button\n              type='button'\n              size='sm'\n              variant='destructive'\n              onClick={() => onAction({ type: 'rotated' })}\n            >\n              Rotate secret\n            </Button>\n            <Button\n              type='button'\n              size='sm'\n              variant='ghost'\n              onClick={() => onAction({ type: 'rotateCancelled' })}\n            >\n              Keep it\n            </Button>\n          </div>\n        </div>\n      </Fold>\n      <Fold open={isRotated}>\n        <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex flex-col gap-2.5 rounded-lg p-2.5'>\n          <p className='flex items-center gap-1.5 text-xs'>\n            <CheckIcon className='text-success-foreground size-3.5 shrink-0' />\n            New secret, shown once. Copy it before you close this\n          </p>\n          <div className='bg-card hairline-ring ring-foreground/12 dark:bg-foreground/[0.04] flex h-8 items-center gap-1 rounded-md ps-2.5 pe-1'>\n            <code className='min-w-0 flex-1 truncate font-mono text-xs'>\n              {endpoint.secret}\n            </code>\n            <CopyButton\n              text={endpoint.secret}\n              label='Copy the new signing secret'\n            />\n          </div>\n          <Button\n            type='button'\n            variant='outline'\n            size='sm'\n            onClick={() => onAction({ type: 'rotateDone' })}\n            className='self-end'\n          >\n            Done\n          </Button>\n        </div>\n      </Fold>\n    </div>\n  );\n}\n\nexport type EndpointDetailProps = {\n  endpoint: Endpoint;\n  state: WebhookState;\n  pressed: string | null;\n  onAction: (action: WebhookAction) => void;\n  onBack: () => void;\n  onRetry: (id: string) => void;\n};\n\nexport function EndpointDetail({\n  endpoint,\n  state,\n  pressed,\n  onAction,\n  onBack,\n  onRetry,\n}: EndpointDetailProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const health = healthOf(state, endpoint.id);\n  const hours = hoursOf(state, endpoint);\n  const totals = totalsOf(hours);\n  const deliveries = deliveriesOf(state, endpoint.id);\n  const hasDeliveries = deliveries.length > 0;\n  const hasRetryColumn = deliveries.some(showsRetry);\n  const summary = deliveredWordOf(totals);\n  const openDelivery = deliveries.find(\n    (delivery) => delivery.id === state.openDeliveryId\n  );\n\n  return (\n    <section\n      aria-label='Endpoint'\n      className='flex flex-col gap-4 transition-opacity duration-200 starting:opacity-0'\n    >\n      <Button\n        type='button'\n        variant='ghost'\n        size='sm'\n        data-back\n        onClick={onBack}\n        className={cn(\n          'text-muted-foreground -ms-2 self-start @4xl:hidden',\n          pressedButtonOf(pressed === 'back')\n        )}\n      >\n        <ArrowLeftIcon />\n        Endpoints\n      </Button>\n\n      <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] flex flex-col gap-5 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n        <header className='flex flex-col gap-1.5'>\n          <p className='flex items-center gap-2 text-xs'>\n            <span\n              aria-hidden='true'\n              className={cn(\n                'size-2 shrink-0 rounded-full transition-colors duration-300',\n                HEALTH_DOT[health]\n              )}\n            />\n            <WordRoll text={HEALTH_WORD[health]} labels={HEALTH_WORDS} />\n          </p>\n          <h2 className='font-mono text-[13px] font-medium break-all'>\n            {endpoint.url}\n          </h2>\n        </header>\n\n        <div className='flex flex-col gap-3'>\n          <div className='flex flex-wrap items-baseline gap-x-2.5 gap-y-1'>\n            <MotionNumber\n              value={totals.rate}\n              format={RATE_FORMAT}\n              suffix='%'\n              className='text-2xl leading-8 font-semibold'\n            />\n            <span className='text-muted-foreground text-xs'>\n              answered with a success in 24 hours\n            </span>\n            <Badge variant='secondary' className='ms-auto'>\n              Illustrative\n            </Badge>\n          </div>\n          <HourStrip hours={hours} summary={summary} />\n          <p className='text-muted-foreground text-xs tabular-nums'>\n            {summary}\n          </p>\n        </div>\n\n        <SecretRow endpoint={endpoint} state={state} onAction={onAction} />\n\n        <div className='flex flex-col gap-2'>\n          <h3 className='text-muted-foreground text-xs'>Recent deliveries</h3>\n          {!hasDeliveries && (\n            <p className='text-muted-foreground text-[13px]'>\n              Nothing was sent here yet. The first event shows up in this list.\n            </p>\n          )}\n          <ul className='-mx-2 flex flex-col' onKeyDown={moveBetweenRows}>\n            {deliveries.map((delivery) => (\n              <li key={delivery.id}>\n                <DeliveryRow\n                  delivery={delivery}\n                  isOpen={state.openDeliveryId === delivery.id}\n                  hasRetryColumn={hasRetryColumn}\n                  pressed={pressed}\n                  onOpen={(id) => onAction({ type: 'deliveryOpened', id })}\n                  onRetry={onRetry}\n                />\n              </li>\n            ))}\n          </ul>\n          <AnimatePresence initial={false}>\n            {openDelivery && (\n              <motion.div\n                key='inspector'\n                className='overflow-hidden'\n                {...rowPresence}\n              >\n                <Inspector\n                  delivery={openDelivery}\n                  tab={state.tab}\n                  onTabChange={(tab) => onAction({ type: 'tab', tab })}\n                />\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-06/endpoint-detail.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-06/inspector.tsx",
      "content": "'use client';\n\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { JsonView } from '@/registry/ndeko/ui/json-view';\nimport { Tabs, TabsList, TabsPanel, TabsTab } from '@/registry/ndeko/ui/tabs';\n\nimport { headersOf, type Delivery, type DeliveryStatus } from './data';\nimport type { InspectorTab } from './session';\n\nconst TABS: InspectorTab[] = ['payload', 'headers'];\n\nconst CODE_VARIANT: Record<DeliveryStatus, 'success' | 'destructive' | 'info'> =\n  {\n    done: 'success',\n    failed: 'destructive',\n    pending: 'info',\n  };\n\nconst CODE_PHRASE: Record<number, string> = {\n  200: '200 OK',\n  500: '500 Internal Server Error',\n};\n\nexport function codeVariantOf(status: DeliveryStatus) {\n  return CODE_VARIANT[status];\n}\n\n/** 200, 500, or Sending while the endpoint has not answered. */\nexport function codeWordOf(delivery: Delivery) {\n  if (delivery.code === null) {\n    return 'Sending';\n  }\n  return String(delivery.code);\n}\n\nfunction codePhraseOf(delivery: Delivery) {\n  if (delivery.code === null) {\n    return 'Sending';\n  }\n  return CODE_PHRASE[delivery.code] ?? String(delivery.code);\n}\n\nfunction attemptWordOf(attempt: number) {\n  if (attempt === 1) {\n    return 'First attempt';\n  }\n  return `Attempt ${attempt}`;\n}\n\nfunction timingOf(delivery: Delivery) {\n  const attempt = attemptWordOf(delivery.attempt);\n  if (delivery.ms === null) {\n    return attempt;\n  }\n  return `${attempt} · ${delivery.ms} ms`;\n}\n\nfunction responseBodyOf(delivery: Delivery) {\n  if (delivery.status === 'pending') {\n    return 'Waiting for the endpoint to answer';\n  }\n  return delivery.responseBody;\n}\n\nexport type InspectorProps = {\n  delivery: Delivery;\n  tab: InspectorTab;\n  onTabChange: (tab: InspectorTab) => void;\n};\n\nexport function Inspector({ delivery, tab, onTabChange }: InspectorProps) {\n  const codePhrase = codePhraseOf(delivery);\n  const responseBody = responseBodyOf(delivery);\n\n  function changeTab(next: unknown) {\n    const found = TABS.find((candidate) => candidate === next);\n    if (found) {\n      onTabChange(found);\n    }\n  }\n\n  return (\n    <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex flex-col gap-3 rounded-lg p-3'>\n      <div className='flex flex-col gap-2'>\n        <div className='flex flex-wrap items-center gap-x-2.5 gap-y-1'>\n          <h3 className='text-[13px] font-medium'>Response</h3>\n          <Badge\n            variant={codeVariantOf(delivery.status)}\n            className='transition-colors duration-300'\n          >\n            <Swap swapKey={codePhrase}>{codePhrase}</Swap>\n          </Badge>\n          <span className='text-muted-foreground text-xs tabular-nums'>\n            {timingOf(delivery)}\n          </span>\n        </div>\n        <code className='bg-card dark:bg-foreground/[0.04] hairline-ring ring-foreground/10 block rounded-md px-2.5 py-2 font-mono text-xs break-all'>\n          <Swap swapKey={responseBody}>{responseBody}</Swap>\n        </code>\n      </div>\n      <Tabs value={tab} onValueChange={changeTab} className='gap-2'>\n        <TabsList variant='segmented' aria-label='What was sent'>\n          <TabsTab value='payload'>Payload</TabsTab>\n          <TabsTab value='headers'>Headers</TabsTab>\n        </TabsList>\n        <AnimatedSize>\n          <TabsPanel value='payload'>\n            <JsonView\n              value={delivery.payload}\n              className='bg-card dark:bg-foreground/[0.04] max-h-56'\n            />\n          </TabsPanel>\n          <TabsPanel value='headers'>\n            <JsonView\n              value={headersOf(delivery)}\n              className='bg-card dark:bg-foreground/[0.04] max-h-56'\n            />\n          </TabsPanel>\n        </AnimatedSize>\n      </Tabs>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-06/inspector.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-06/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport {\n  DELIVERIES,\n  DEMO_URL,\n  ENDPOINTS,\n  FAILED_DELIVERY_ID,\n  NEW_SECRETS,\n  RETRY_OK,\n  type Delivery,\n  type Endpoint,\n  type EventName,\n  type HourBucket,\n} from './data';\n\nexport type InspectorTab = 'payload' | 'headers';\n\n/** Rotated: the new secret is on screen, for the one time it is shown. */\nexport type RotateStatus = 'idle' | 'asking' | 'rotated';\n\n/** Created: the endpoint exists and its secret is on screen, for the one time it is shown. */\nexport type FormPhase = 'closed' | 'editing' | 'created';\n\nexport type FormState = {\n  phase: FormPhase;\n  url: string;\n  events: EventName[];\n  error: string | null;\n  /** The secret of the endpoint the form just created. */\n  secret: string | null;\n};\n\nexport type WebhookState = {\n  endpoints: Endpoint[];\n  deliveries: Delivery[];\n  selectedId: string;\n  /** On a phone the detail replaces the list; a wide block shows both. */\n  isDetailOpen: boolean;\n  openDeliveryId: string | null;\n  tab: InspectorTab;\n  isSecretShown: boolean;\n  rotate: RotateStatus;\n  form: FormState;\n  secretsIssued: number;\n};\n\nexport type WebhookAction =\n  | { type: 'selected'; id: string }\n  | { type: 'back' }\n  | { type: 'deliveryOpened'; id: string }\n  | { type: 'tab'; tab: InspectorTab }\n  | { type: 'retry'; id: string }\n  | { type: 'retried'; id: string }\n  | { type: 'secretToggled' }\n  | { type: 'rotateAsked' }\n  | { type: 'rotateCancelled' }\n  | { type: 'rotated' }\n  | { type: 'rotateDone' }\n  | { type: 'formOpened' }\n  | { type: 'formClosed' }\n  | { type: 'urlTyped'; text: string }\n  | { type: 'eventToggled'; event: EventName }\n  | { type: 'created' };\n\ntype Step = SessionStep<WebhookState, WebhookAction>;\n\nconst CLOSED_FORM: FormState = {\n  phase: 'closed',\n  url: '',\n  events: ['run.completed'],\n  error: null,\n  secret: null,\n};\n\nexport const INITIAL: WebhookState = {\n  endpoints: ENDPOINTS,\n  deliveries: DELIVERIES,\n  selectedId: 'calder',\n  isDetailOpen: false,\n  openDeliveryId: null,\n  tab: 'payload',\n  isSecretShown: false,\n  rotate: 'idle',\n  form: CLOSED_FORM,\n  secretsIssued: 0,\n};\n\nexport function endpointOf(state: WebhookState, id: string) {\n  const endpoint = state.endpoints.find((candidate) => candidate.id === id);\n  return endpoint ?? state.endpoints[0];\n}\n\nexport function deliveriesOf(state: WebhookState, endpointId: string) {\n  return state.deliveries.filter(\n    (delivery) => delivery.endpointId === endpointId\n  );\n}\n\nexport type Health = 'healthy' | 'retrying' | 'failing';\n\nexport function healthOf(state: WebhookState, endpointId: string): Health {\n  const deliveries = deliveriesOf(state, endpointId);\n  const hasFailed = deliveries.some((delivery) => delivery.status === 'failed');\n  if (hasFailed) {\n    return 'failing';\n  }\n  const hasPending = deliveries.some(\n    (delivery) => delivery.status === 'pending'\n  );\n  if (hasPending) {\n    return 'retrying';\n  }\n  return 'healthy';\n}\n\n/** A delivery that was retried with success leaves the failures of the current hour. */\nfunction recoveredCountOf(state: WebhookState, endpointId: string) {\n  const deliveries = deliveriesOf(state, endpointId);\n  const recovered = deliveries.filter((delivery) => {\n    const wasRetried = delivery.attempt > 1;\n    const isDone = delivery.status === 'done';\n    return wasRetried && isDone;\n  });\n  return recovered.length;\n}\n\nexport function hoursOf(state: WebhookState, endpoint: Endpoint) {\n  const recovered = recoveredCountOf(state, endpoint.id);\n  const lastHour = endpoint.hours.length - 1;\n  return endpoint.hours.map((bucket, hour): HourBucket => {\n    if (hour !== lastHour) {\n      return bucket;\n    }\n    const moved = Math.min(recovered, bucket.failed);\n    return { ok: bucket.ok + moved, failed: bucket.failed - moved };\n  });\n}\n\nexport type DayTotals = {\n  ok: number;\n  failed: number;\n  /** Share of the deliveries that were answered with a success, from 0 to 100. */\n  rate: number;\n};\n\nexport function totalsOf(hours: HourBucket[]): DayTotals {\n  let ok = 0;\n  let failed = 0;\n  for (const bucket of hours) {\n    ok += bucket.ok;\n    failed += bucket.failed;\n  }\n  const total = Math.max(1, ok + failed);\n  const rate = (ok / total) * 100;\n  return { ok, failed, rate };\n}\n\nfunction withDelivery(\n  state: WebhookState,\n  id: string,\n  change: (delivery: Delivery) => Delivery\n): WebhookState {\n  const deliveries = state.deliveries.map((delivery) => {\n    if (delivery.id === id) {\n      return change(delivery);\n    }\n    return delivery;\n  });\n  return { ...state, deliveries };\n}\n\nfunction retry(delivery: Delivery): Delivery {\n  if (delivery.status !== 'failed') {\n    return delivery;\n  }\n  return {\n    ...delivery,\n    status: 'pending',\n    code: null,\n    ms: null,\n    attempt: delivery.attempt + 1,\n  };\n}\n\nfunction retried(delivery: Delivery): Delivery {\n  if (delivery.status !== 'pending') {\n    return delivery;\n  }\n  return { ...delivery, status: 'done', ...RETRY_OK };\n}\n\nfunction selected(state: WebhookState, id: string): WebhookState {\n  const isSame = state.selectedId === id;\n  if (isSame) {\n    return { ...state, isDetailOpen: true };\n  }\n  return {\n    ...state,\n    selectedId: id,\n    isDetailOpen: true,\n    openDeliveryId: null,\n    isSecretShown: false,\n    rotate: 'idle',\n  };\n}\n\nfunction deliveryOpened(state: WebhookState, id: string): WebhookState {\n  if (state.openDeliveryId === id) {\n    return { ...state, openDeliveryId: null };\n  }\n  return { ...state, openDeliveryId: id };\n}\n\nfunction nextSecretOf(state: WebhookState) {\n  return NEW_SECRETS[state.secretsIssued % NEW_SECRETS.length];\n}\n\nfunction rotated(state: WebhookState): WebhookState {\n  if (state.rotate !== 'asking') {\n    return state;\n  }\n  const secret = nextSecretOf(state);\n  const endpoints = state.endpoints.map((endpoint) => {\n    if (endpoint.id === state.selectedId) {\n      return { ...endpoint, secret };\n    }\n    return endpoint;\n  });\n  return {\n    ...state,\n    endpoints,\n    rotate: 'rotated',\n    isSecretShown: false,\n    secretsIssued: state.secretsIssued + 1,\n  };\n}\n\nfunction eventToggled(state: WebhookState, event: EventName): WebhookState {\n  const isOn = state.form.events.includes(event);\n  let events = [...state.form.events, event];\n  if (isOn) {\n    events = state.form.events.filter((candidate) => candidate !== event);\n  }\n  return { ...state, form: { ...state.form, events, error: null } };\n}\n\nexport function formErrorOf(form: FormState) {\n  const url = form.url.trim();\n  if (!url.startsWith('https://')) {\n    return 'Use an https address, so payloads stay private on the way';\n  }\n  if (form.events.length === 0) {\n    return 'Pick at least one event to send';\n  }\n  return null;\n}\n\nconst EMPTY_DAY: HourBucket[] = ENDPOINTS[0].hours.map(() => ({\n  ok: 0,\n  failed: 0,\n}));\n\nfunction created(state: WebhookState): WebhookState {\n  if (state.form.phase !== 'editing') {\n    return state;\n  }\n  const error = formErrorOf(state.form);\n  if (error) {\n    return { ...state, form: { ...state.form, error } };\n  }\n  const secret = nextSecretOf(state);\n  const count = state.secretsIssued + 1;\n  const endpoint: Endpoint = {\n    id: `new-${count}`,\n    url: state.form.url.trim(),\n    events: state.form.events,\n    secret,\n    hours: EMPTY_DAY,\n  };\n  return {\n    ...state,\n    endpoints: [...state.endpoints, endpoint],\n    form: { ...state.form, phase: 'created', error: null, secret },\n    secretsIssued: count,\n  };\n}\n\nexport function reducer(\n  state: WebhookState,\n  action: WebhookAction\n): WebhookState {\n  switch (action.type) {\n    case 'selected':\n      return selected(state, action.id);\n    case 'back':\n      return { ...state, isDetailOpen: false };\n    case 'deliveryOpened':\n      return deliveryOpened(state, action.id);\n    case 'tab':\n      return { ...state, tab: action.tab };\n    case 'retry':\n      return withDelivery(state, action.id, retry);\n    case 'retried':\n      return withDelivery(state, action.id, retried);\n    case 'secretToggled':\n      return { ...state, isSecretShown: !state.isSecretShown };\n    case 'rotateAsked':\n      return { ...state, rotate: 'asking' };\n    case 'rotateCancelled':\n      return { ...state, rotate: 'idle' };\n    case 'rotated':\n      return rotated(state);\n    case 'rotateDone':\n      return { ...state, rotate: 'idle' };\n    case 'formOpened':\n      return { ...state, form: { ...CLOSED_FORM, phase: 'editing' } };\n    case 'formClosed':\n      return { ...state, form: CLOSED_FORM };\n    case 'urlTyped':\n      return {\n        ...state,\n        form: { ...state.form, url: action.text, error: null },\n      };\n    case 'eventToggled':\n      return eventToggled(state, action.event);\n    case 'created':\n      return created(state);\n  }\n}\n\nconst CHUNK = 3;\n\nfunction delayOfChunk(index: number) {\n  if (index === 0) {\n    return 800;\n  }\n  return 70;\n}\n\nfunction typingSteps(): Step[] {\n  const steps: Step[] = [];\n  const last = DEMO_URL.length + CHUNK;\n  for (let end = CHUNK; end < last; end += CHUNK) {\n    const text = DEMO_URL.slice(0, end);\n    const after = delayOfChunk(steps.length);\n    steps.push({ after, by: 'demo', action: { type: 'urlTyped', text } });\n  }\n  return steps;\n}\n\nfunction hasRetried(state: WebhookState) {\n  const delivery = state.deliveries.find(\n    (candidate) => candidate.id === FAILED_DELIVERY_ID\n  );\n  return delivery?.status !== 'failed';\n}\n\n/** A request that waits on a person is answered by the demonstration after this long. */\nconst DECIDE_AFTER_MS = 2500;\n\nexport const RETRY_MS = 1500;\n\nconst OPENING: Step[] = [\n  {\n    after: 1300,\n    by: 'demo',\n    press: 'endpoint-juniper',\n    action: { type: 'selected', id: 'juniper' },\n  },\n  {\n    after: 1300,\n    by: 'demo',\n    press: `delivery-${FAILED_DELIVERY_ID}`,\n    action: { type: 'deliveryOpened', id: FAILED_DELIVERY_ID },\n  },\n];\n\nexport const SCRIPT: Step[] = [\n  ...OPENING,\n  { after: 1600, by: 'demo', action: { type: 'tab', tab: 'headers' } },\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: `retry-${FAILED_DELIVERY_ID}`,\n    action: { type: 'retry', id: FAILED_DELIVERY_ID },\n    isAnswered: hasRetried,\n  },\n  { after: RETRY_MS, action: { type: 'retried', id: FAILED_DELIVERY_ID } },\n  { after: 1700, by: 'demo', press: 'back', action: { type: 'back' } },\n  { after: 900, by: 'demo', press: 'add', action: { type: 'formOpened' } },\n  ...typingSteps(),\n  {\n    after: 600,\n    by: 'demo',\n    action: { type: 'eventToggled', event: 'run.failed' },\n  },\n  { after: 1000, by: 'demo', press: 'create', action: { type: 'created' } },\n];\n\n/** Under reduced motion the failing endpoint is picked and its failed delivery is open. */\nfunction restingOf() {\n  let state = INITIAL;\n  for (const step of OPENING) {\n    state = reducer(state, step.action);\n  }\n  return { ...state, isDetailOpen: false };\n}\n\nexport const RESTING = restingOf();\n\nexport const LOOP_AFTER_MS = 4200;\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-06/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-06/data.ts",
      "content": "export type EventName =\n  'run.completed' | 'run.failed' | 'approval.requested' | 'tool.called';\n\nexport const EVENT_NAMES: EventName[] = [\n  'run.completed',\n  'run.failed',\n  'approval.requested',\n  'tool.called',\n];\n\nexport type HourBucket = {\n  ok: number;\n  failed: number;\n};\n\nexport type Endpoint = {\n  id: string;\n  url: string;\n  events: EventName[];\n  secret: string;\n  /** Deliveries of the last 24 hours, oldest hour first. */\n  hours: HourBucket[];\n};\n\nconst HOURS = 24;\n\n/** The shape of a working day: quiet at night, busy from mid-morning. */\nconst DAY_WAVE = [\n  0.2, 0.15, 0.1, 0.1, 0.15, 0.3, 0.5, 0.75, 0.9, 1, 0.95, 0.85, 0.9, 1, 0.95,\n  0.85, 0.75, 0.6, 0.5, 0.45, 0.4, 0.35, 0.3, 0.25,\n];\n\nfunction hoursOf(\n  peak: number,\n  shift: number,\n  failedByHour: Record<number, number>\n) {\n  return DAY_WAVE.map((_, hour): HourBucket => {\n    const wave = DAY_WAVE[(hour + shift) % HOURS];\n    const total = Math.max(1, Math.round(peak * wave));\n    const failed = Math.min(total, failedByHour[hour] ?? 0);\n    return { ok: total - failed, failed };\n  });\n}\n\n/** Invented endpoints and secrets. The figures are illustrative. */\nexport const ENDPOINTS: Endpoint[] = [\n  {\n    id: 'calder',\n    url: 'https://api.calderfreight.example/hooks/agents',\n    events: ['run.completed', 'run.failed', 'approval.requested'],\n    secret: 'whsec_7Qm2xN4kVt9LpR3sWb8YcA6dHf1a91f',\n    hours: hoursOf(42, 0, {}),\n  },\n  {\n    id: 'juniper',\n    url: 'https://ops.juniperhealth.example/webhooks/runs',\n    events: ['run.failed'],\n    secret: 'whsec_Zt5uG8jMq1XnB4vC7kLw2SeP9yD3c07',\n    hours: hoursOf(9, 3, { 22: 2, 23: 1 }),\n  },\n  {\n    id: 'pinecrest',\n    url: 'https://hooks.pinecrest.example/agent-events',\n    events: ['run.completed', 'tool.called'],\n    secret: 'whsec_Hd3fK9pW2rT6mJ8xQ1zN5bV4cL7e5d2',\n    hours: hoursOf(118, 6, { 9: 1 }),\n  },\n];\n\n/** The secrets handed out by Create and by Rotate, in order. */\nexport const NEW_SECRETS = [\n  'whsec_Rb6nY2wE8qU4tK1mS9xF3vJ7pA5g2b8',\n  'whsec_Lc4jP7sD1hX9zM3aQ6uW8eT2yN5k4f1',\n  'whsec_Vg8mB5rC2nH7kT4dZ1qJ9wS3xE6p7a3',\n];\n\nexport type DeliveryStatus = 'done' | 'failed' | 'pending';\n\nexport type Delivery = {\n  id: string;\n  endpointId: string;\n  event: EventName;\n  status: DeliveryStatus;\n  /** The HTTP status the endpoint answered with; none while the delivery is on its way. */\n  code: number | null;\n  time: string;\n  ms: number | null;\n  attempt: number;\n  responseBody: string;\n  payload: Record<string, unknown>;\n};\n\nconst RUN_DATA: Record<EventName, Record<string, unknown>> = {\n  'run.completed': {\n    run: 'run_41c7e0',\n    agent: 'Writer',\n    steps: 6,\n    cost_usd: 0.214,\n  },\n  'run.failed': {\n    run: 'run_8f2c19',\n    agent: 'Researcher',\n    error: 'Tool timed out after 30 s',\n  },\n  'approval.requested': {\n    run: 'run_5d90ab',\n    agent: 'Reviewer',\n    request: 'Send the policy update to 212 customers',\n  },\n  'tool.called': {\n    run: 'run_2b6f44',\n    agent: 'Coder',\n    tool: 'run_tests',\n    duration_ms: 4180,\n  },\n};\n\nfunction payloadOf(id: string, event: EventName, time: string) {\n  return {\n    id: `evt_${id}`,\n    type: event,\n    created: `2026-11-12T${time}Z`,\n    data: RUN_DATA[event],\n  };\n}\n\ntype DeliverySeed = {\n  id: string;\n  endpointId: string;\n  event: EventName;\n  time: string;\n  code: number;\n  ms: number;\n  attempt?: number;\n};\n\nconst OK_BODY = '{\"received\":true}';\n\nconst FAILED_BODY = '{\"error\":\"upstream timed out\"}';\n\nfunction isSuccessCode(code: number) {\n  return code >= 200 && code < 300;\n}\n\nfunction statusOfCode(code: number): DeliveryStatus {\n  if (isSuccessCode(code)) {\n    return 'done';\n  }\n  return 'failed';\n}\n\nfunction bodyOfCode(code: number) {\n  if (isSuccessCode(code)) {\n    return OK_BODY;\n  }\n  return FAILED_BODY;\n}\n\nfunction deliveryOf(seed: DeliverySeed): Delivery {\n  return {\n    id: seed.id,\n    endpointId: seed.endpointId,\n    event: seed.event,\n    status: statusOfCode(seed.code),\n    code: seed.code,\n    time: seed.time,\n    ms: seed.ms,\n    attempt: seed.attempt ?? 1,\n    responseBody: bodyOfCode(seed.code),\n    payload: payloadOf(seed.id, seed.event, seed.time),\n  };\n}\n\nexport const FAILED_DELIVERY_ID = 'd-juniper-1';\n\nconst SEEDS: DeliverySeed[] = [\n  {\n    id: FAILED_DELIVERY_ID,\n    endpointId: 'juniper',\n    event: 'run.failed',\n    time: '14:52:07',\n    code: 500,\n    ms: 1204,\n    attempt: 3,\n  },\n  {\n    id: 'd-juniper-2',\n    endpointId: 'juniper',\n    event: 'run.failed',\n    time: '13:18:44',\n    code: 200,\n    ms: 186,\n  },\n  {\n    id: 'd-juniper-3',\n    endpointId: 'juniper',\n    event: 'run.failed',\n    time: '11:02:31',\n    code: 200,\n    ms: 204,\n  },\n  {\n    id: 'd-juniper-4',\n    endpointId: 'juniper',\n    event: 'run.failed',\n    time: '09:47:10',\n    code: 200,\n    ms: 171,\n  },\n  {\n    id: 'd-calder-1',\n    endpointId: 'calder',\n    event: 'run.completed',\n    time: '14:55:20',\n    code: 200,\n    ms: 142,\n  },\n  {\n    id: 'd-calder-2',\n    endpointId: 'calder',\n    event: 'approval.requested',\n    time: '14:51:03',\n    code: 200,\n    ms: 158,\n  },\n  {\n    id: 'd-calder-3',\n    endpointId: 'calder',\n    event: 'run.completed',\n    time: '14:40:36',\n    code: 200,\n    ms: 133,\n  },\n  {\n    id: 'd-calder-4',\n    endpointId: 'calder',\n    event: 'run.failed',\n    time: '14:22:58',\n    code: 200,\n    ms: 149,\n  },\n  {\n    id: 'd-pinecrest-1',\n    endpointId: 'pinecrest',\n    event: 'tool.called',\n    time: '14:56:41',\n    code: 200,\n    ms: 97,\n  },\n  {\n    id: 'd-pinecrest-2',\n    endpointId: 'pinecrest',\n    event: 'tool.called',\n    time: '14:56:12',\n    code: 200,\n    ms: 104,\n  },\n  {\n    id: 'd-pinecrest-3',\n    endpointId: 'pinecrest',\n    event: 'run.completed',\n    time: '14:55:48',\n    code: 200,\n    ms: 88,\n  },\n  {\n    id: 'd-pinecrest-4',\n    endpointId: 'pinecrest',\n    event: 'tool.called',\n    time: '14:54:30',\n    code: 200,\n    ms: 112,\n  },\n];\n\n/** Newest first within each endpoint. */\nexport const DELIVERIES: Delivery[] = SEEDS.map(deliveryOf);\n\nexport const RETRY_OK = { code: 200, ms: 212, responseBody: OK_BODY };\n\n/** The headers every delivery is sent with; the signature is cut short. */\nexport function headersOf(delivery: Delivery) {\n  return {\n    'content-type': 'application/json',\n    'user-agent': 'agent-webhooks/1.0',\n    'webhook-id': `msg_${delivery.id}`,\n    'webhook-attempt': delivery.attempt,\n    'webhook-signature': 'v1,K5oZ8fR2…',\n  };\n}\n\nexport const DEMO_URL = 'https://hooks.aldermoor.example/agents';\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-06/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "agent-ops"
  ],
  "type": "registry:block"
}