{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-review-03",
  "title": "Document extract",
  "description": "A purchase order beside the typed fields read from it: values stream in with a confidence, a thread draws from a value to its box on the page, doubtful values wait for a confirm or an edit and Accept all becomes Saved.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "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/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/json-view.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-presets.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/theme.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-review/agent-review-03/index.tsx",
      "content": "'use client';\n\nimport { useLayoutEffect, useRef, useState } from 'react';\n\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  pressedSolidOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport { FileTextIcon } from '@/registry/ndeko/lib/icons';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\n\nimport {\n  DOCUMENT_NAME,\n  fieldOf,\n  FIELDS,\n  type ExtractField,\n  type FieldId,\n  type PageNumber,\n} from './data';\nimport { DocumentPage } from './document';\nimport { FieldList, JsonPanel, SchemaPanel } from './fields';\nimport {\n  INITIAL,\n  isReadingDone,\n  LOOP_AFTER_MS,\n  pendingIdsOf,\n  reducer,\n  RESTING,\n  reviewOf,\n  SAVE_MS,\n  SCRIPT,\n  type ExtractState,\n  type ExtractTab,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nconst TAB_SEGMENTS: Segment<ExtractTab>[] = [\n  { value: 'fields', label: 'Fields' },\n  { value: 'json', label: 'JSON' },\n  { value: 'schema', label: 'Schema' },\n];\n\nconst PAGE_SEGMENTS: Segment<'1' | '2'>[] = [\n  { value: '1', label: 'Page 1' },\n  { value: '2', label: 'Page 2' },\n];\n\nconst SAVE_LABELS: Record<MorphState, string> = {\n  idle: 'Accept all',\n  busy: 'Saving',\n  done: 'Saved',\n};\n\nfunction pageOf(value: '1' | '2'): PageNumber {\n  if (value === '2') {\n    return 2;\n  }\n  return 1;\n}\n\nfunction statusOf(state: ExtractState) {\n  if (state.save === 'done') {\n    return 'Saved to your records';\n  }\n  if (!isReadingDone(state)) {\n    return `Reading page ${state.page}`;\n  }\n  const pending = pendingIdsOf(state).length;\n  if (pending === 0) {\n    return 'Every value is checked';\n  }\n  if (pending === 1) {\n    return '1 value needs a look';\n  }\n  return `${pending} values need a look`;\n}\n\nfunction activeOf(\n  hovered: FieldId | null,\n  pointed: FieldId | null,\n  isAutoplaying: boolean\n) {\n  if (hovered) {\n    return hovered;\n  }\n  if (isAutoplaying) {\n    return pointed;\n  }\n  return null;\n}\n\nfunction middleOf(box: DOMRect) {\n  return box.top + box.height / 2;\n}\n\n/**\n * The thread from a value on the page to its row is written to the path directly: pointing at\n * a value re-renders nothing but the two things it lights.\n */\nfunction useThread(\n  wrapperRef: React.RefObject<HTMLDivElement | null>,\n  pathRef: React.RefObject<SVGPathElement | null>,\n  activeId: FieldId | null,\n  layoutKey: string\n) {\n  useLayoutEffect(() => {\n    const wrapper = wrapperRef.current;\n    const path = pathRef.current;\n    if (!wrapper || !path) {\n      return;\n    }\n    const box = wrapper.querySelector(`[data-box='${activeId}']`);\n    const row = wrapper.querySelector(`[data-row='${activeId}']`);\n    if (!box || !row) {\n      path.style.opacity = '0';\n      return;\n    }\n    const frame = wrapper.getBoundingClientRect();\n    const from = box.getBoundingClientRect();\n    const to = row.getBoundingClientRect();\n    const startX = from.right - frame.left;\n    const endX = to.left - frame.left;\n    const isSideBySide = endX > startX;\n    if (!isSideBySide) {\n      path.style.opacity = '0';\n      return;\n    }\n    const startY = middleOf(from) - frame.top;\n    const endY = middleOf(to) - frame.top;\n    const bendX = (startX + endX) / 2;\n    const curve = `M ${startX} ${startY} C ${bendX} ${startY}, ${bendX} ${endY}, ${endX} ${endY}`;\n    path.setAttribute('d', curve);\n    path.style.transition = 'none';\n    path.style.strokeDashoffset = '1';\n    path.style.opacity = '1';\n    path.getBoundingClientRect();\n    path.style.transition = '';\n    path.style.strokeDashoffset = '0';\n  }, [wrapperRef, pathRef, activeId, layoutKey]);\n}\n\nexport default function AgentReview03() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const [hovered, setHovered] = useState<FieldId | null>(null);\n  const wrapperRef = useRef<HTMLDivElement>(null);\n  const pathRef = useRef<SVGPathElement>(null);\n  const { schedule } = useTimeouts();\n  const activeId = activeOf(hovered, state.pointed, isAutoplaying);\n  const layoutKey = `${state.page}:${state.tab}:${state.shown}`;\n  useThread(wrapperRef, pathRef, activeId, layoutKey);\n  const readFields = FIELDS.slice(0, state.shown);\n  const readIds = new Set(readFields.map((field) => field.id));\n  const pendingCount = pendingIdsOf(state).length;\n  const canAccept = isReadingDone(state) && pendingCount === 0;\n  const status = statusOf(state);\n  const message = spokenUnless(isAutoplaying, status);\n  const canReplay = isFinished && !isAutoplaying;\n\n  function valueOf(field: ExtractField) {\n    return state.edits[field.id] ?? field.value;\n  }\n\n  function pick(id: FieldId) {\n    const field = fieldOf(id);\n    act({ type: 'page', page: field.page });\n    act({ type: 'tab', tab: 'fields' });\n  }\n\n  function accept() {\n    act({ type: 'saving' });\n    schedule(() => act({ type: 'saved' }), SAVE_MS);\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 p-3 @3xl:p-8'\n      >\n        <div className='mx-auto flex max-w-5xl flex-col gap-4'>\n          <header className='flex flex-wrap items-center gap-x-3 gap-y-2'>\n            <span\n              aria-hidden='true'\n              className='keycap-3d text-muted-foreground inline-flex size-7 shrink-0 items-center justify-center rounded-md'\n            >\n              <FileTextIcon className='size-3.5' />\n            </span>\n            <div className='flex min-w-40 flex-1 flex-col leading-tight'>\n              <h1 className='truncate font-mono text-[13px] font-medium'>\n                {DOCUMENT_NAME}\n              </h1>\n              <Swap swapKey={status} className='text-muted-foreground text-xs'>\n                {status}\n              </Swap>\n            </div>\n            <ReplayButton\n              isShown={canReplay}\n              onReplay={restart}\n              label='Read it again'\n            />\n          </header>\n\n          <div\n            ref={wrapperRef}\n            className='relative flex flex-col gap-4 @3xl:flex-row @3xl:items-start @3xl:gap-10'\n          >\n            <section\n              aria-label='Document'\n              className='bg-foreground/[0.03] flex min-w-0 flex-1 flex-col gap-3 rounded-xl p-3'\n            >\n              <div className='flex items-center justify-between gap-2'>\n                <Segments\n                  label='Page'\n                  value={`${state.page}`}\n                  segments={PAGE_SEGMENTS}\n                  onValueChange={(value) =>\n                    act({ type: 'page', page: pageOf(value) })\n                  }\n                />\n                <span className='text-muted-foreground text-xs'>2 pages</span>\n              </div>\n              <DocumentPage\n                page={state.page}\n                activeId={activeId}\n                readIds={readIds}\n                onPoint={setHovered}\n                onPick={pick}\n              />\n            </section>\n\n            <section\n              aria-label='Extraction'\n              className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] flex flex-col gap-3 rounded-xl p-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)] @3xl:w-[22rem] @3xl:shrink-0'\n            >\n              <div className='flex items-center justify-between gap-2'>\n                <Segments\n                  label='View'\n                  value={state.tab}\n                  segments={TAB_SEGMENTS}\n                  onValueChange={(tab) => act({ type: 'tab', tab })}\n                />\n                <span className='text-muted-foreground text-xs tabular-nums'>\n                  {state.shown} of {FIELDS.length}\n                </span>\n              </div>\n\n              <div className='min-h-[13rem]'>\n                {state.tab === 'fields' && (\n                  <FieldList\n                    shown={state.shown}\n                    activeId={activeId}\n                    pressed={pressed}\n                    valueOf={valueOf}\n                    reviewOf={(id) => reviewOf(state, id)}\n                    onPoint={setHovered}\n                    onPick={pick}\n                    onConfirm={(id) => act({ type: 'confirmed', id })}\n                    onEdit={(id, value) => act({ type: 'edited', id, value })}\n                  />\n                )}\n                {state.tab === 'json' && (\n                  <JsonPanel shown={state.shown} valueOf={valueOf} />\n                )}\n                {state.tab === 'schema' && <SchemaPanel />}\n              </div>\n\n              <div className='flex items-center justify-between gap-3'>\n                <span className='text-muted-foreground text-xs'>\n                  Illustrative confidence\n                </span>\n                <MorphButton\n                  type='button'\n                  size='sm'\n                  state={state.save}\n                  labels={SAVE_LABELS}\n                  disabled={!canAccept}\n                  onClick={accept}\n                  className={pressedSolidOf(pressed === 'accept')}\n                />\n              </div>\n            </section>\n\n            <svg\n              aria-hidden='true'\n              className='pointer-events-none absolute inset-0 hidden size-full overflow-visible @3xl:block'\n            >\n              <path\n                ref={pathRef}\n                pathLength={1}\n                strokeDasharray='1'\n                fill='none'\n                strokeWidth='1.5'\n                strokeLinecap='round'\n                className='stroke-primary opacity-0 transition-[stroke-dashoffset] duration-300 ease-(--ease-out-strong) motion-reduce:transition-none'\n              />\n            </svg>\n          </div>\n        </div>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-03/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-review/agent-review-03/document.tsx",
      "content": "'use client';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { fieldOf, LINE_ITEMS, type FieldId, type PageNumber } from './data';\n\nexport type PointHandlers = {\n  activeId: FieldId | null;\n  /** The fields read so far: their boxes are marked on the page. */\n  readIds: ReadonlySet<FieldId>;\n  onPoint: (id: FieldId | null) => void;\n  onPick: (id: FieldId) => void;\n};\n\nfunction boxToneOf(isActive: boolean, isRead: boolean) {\n  if (isActive) {\n    return 'bg-primary/15 ring-primary/60';\n  }\n  if (isRead) {\n    return 'bg-primary/[0.06] ring-primary/25';\n  }\n  return 'ring-transparent';\n}\n\ntype BoxProps = PointHandlers & {\n  id: FieldId;\n  className?: string;\n};\n\n/** A value on the page. It lights with its row in the list, whichever of the two is pointed at. */\nfunction Box({ id, activeId, readIds, onPoint, onPick, className }: BoxProps) {\n  const field = fieldOf(id);\n  const isActive = activeId === id;\n  const isRead = readIds.has(id);\n\n  return (\n    <button\n      type='button'\n      data-box={id}\n      aria-label={`${field.label}: ${field.printed}`}\n      onMouseEnter={() => onPoint(id)}\n      onMouseLeave={() => onPoint(null)}\n      onFocus={() => onPoint(id)}\n      onBlur={() => onPoint(null)}\n      onClick={() => onPick(id)}\n      className={cn(\n        'hairline-ring focus-visible:ring-ring -mx-1 cursor-pointer rounded-sm px-1 text-start font-medium transition-[background-color,box-shadow] duration-200 outline-none focus-visible:ring-2',\n        boxToneOf(isActive, isRead),\n        className\n      )}\n    >\n      {field.printed}\n    </button>\n  );\n}\n\nfunction Caption({ children }: { children: React.ReactNode }) {\n  return <span className='text-muted-foreground'>{children}</span>;\n}\n\nfunction FirstPage(handlers: PointHandlers) {\n  return (\n    <div className='flex flex-col gap-5'>\n      <div className='flex items-start justify-between gap-3'>\n        <div className='flex flex-col'>\n          <span className='text-base font-semibold'>Purchase order</span>\n          <Caption>Tallis Studio</Caption>\n        </div>\n        <div className='flex flex-col items-end'>\n          <Caption>Number</Caption>\n          <Box id='po_number' {...handlers} />\n        </div>\n      </div>\n      <div className='flex flex-col'>\n        <Caption>Order date</Caption>\n        <span>\n          <Box id='order_date' {...handlers} />\n        </span>\n      </div>\n      <div className='grid grid-cols-2 gap-4'>\n        <div className='flex flex-col'>\n          <Caption>Supplier</Caption>\n          <span>\n            <Box id='supplier' {...handlers} />\n          </span>\n          <span>22 Dock Road, Rotterdam</span>\n        </div>\n        <div className='flex flex-col'>\n          <Caption>Bill to</Caption>\n          <span>\n            <Box id='bill_to' {...handlers} />\n          </span>\n          <span>Lisbon</span>\n        </div>\n      </div>\n      <div className='flex flex-col'>\n        <Caption>Ship to</Caption>\n        <span>Warehouse 3, same address</span>\n      </div>\n    </div>\n  );\n}\n\nfunction SecondPage(handlers: PointHandlers) {\n  return (\n    <div className='flex flex-col gap-5'>\n      <table className='w-full text-start'>\n        <thead>\n          <tr className='text-muted-foreground'>\n            <th className='pb-1 text-start font-normal'>Item</th>\n            <th className='w-10 pb-1 text-end font-normal'>Qty</th>\n            <th className='w-20 pb-1 text-end font-normal'>Amount</th>\n          </tr>\n        </thead>\n        <tbody>\n          {LINE_ITEMS.map((item) => (\n            <tr key={item.name} className='hairline-t border-border'>\n              <td className='py-1.5 pe-2'>{item.name}</td>\n              <td className='py-1.5 text-end tabular-nums'>{item.quantity}</td>\n              <td className='py-1.5 text-end tabular-nums'>{item.amount}</td>\n            </tr>\n          ))}\n        </tbody>\n      </table>\n      <div className='flex items-center justify-end gap-3'>\n        <Caption>Total</Caption>\n        <Box id='currency' {...handlers} />\n        <Box id='total' {...handlers} className='text-sm tabular-nums' />\n      </div>\n      <div className='grid grid-cols-2 gap-4'>\n        <div className='relative flex flex-col'>\n          <Caption>Payment terms</Caption>\n          <span>\n            <Box id='payment_terms' {...handlers} />\n          </span>\n          <span\n            aria-label='Handwritten note: Net 45'\n            className='text-info-foreground absolute start-14 top-7 -rotate-6 font-medium'\n          >\n            Net 45?\n          </span>\n        </div>\n        <div className='relative flex flex-col'>\n          <Caption>Delivery date</Caption>\n          <span>\n            <Box id='delivery_date' {...handlers} />\n          </span>\n          <span\n            aria-label='Stamp: Received'\n            className='text-destructive-ink/70 border-destructive-ink/50 absolute start-12 top-3 rotate-[-8deg] rounded-sm border px-1.5 py-0.5 font-semibold'\n          >\n            Received\n          </span>\n        </div>\n      </div>\n    </div>\n  );\n}\n\ntype DocumentPageProps = PointHandlers & {\n  page: PageNumber;\n};\n\nexport function DocumentPage({ page, ...handlers }: DocumentPageProps) {\n  return (\n    <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.04] min-h-[19rem] rounded-lg p-5 text-xs leading-relaxed shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n      {page === 1 && <FirstPage {...handlers} />}\n      {page === 2 && <SecondPage {...handlers} />}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-03/document.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-review/agent-review-03/fields.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\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 { JsonView } from '@/registry/ndeko/ui/json-view';\n\nimport {\n  FIELDS,\n  isLowConfidence,\n  type ExtractField,\n  type FieldId,\n} from './data';\nimport type { ReviewStatus } from './session';\n\nconst REVIEW_WORD: Record<ReviewStatus, string> = {\n  pending: 'Needs a look',\n  confirmed: 'Confirmed',\n  edited: 'Edited',\n};\n\nfunction confidenceVariantOf(field: ExtractField, review: ReviewStatus) {\n  const isSettled = review !== 'pending';\n  if (isLowConfidence(field) && !isSettled) {\n    return 'warning';\n  }\n  return 'success';\n}\n\nfunction chipTextOf(field: ExtractField, review: ReviewStatus) {\n  const isSettled = review !== 'pending';\n  if (isLowConfidence(field) && isSettled) {\n    return REVIEW_WORD[review];\n  }\n  return `${field.confidence}%`;\n}\n\nfunction rowToneOf(isActive: boolean) {\n  if (isActive) {\n    return 'bg-primary/10';\n  }\n  return 'hover:bg-foreground/[0.04]';\n}\n\ntype FlaggedBodyProps = {\n  field: ExtractField;\n  value: string;\n  isPressed: boolean;\n  onConfirm: (id: FieldId) => void;\n  onEdit: (id: FieldId, value: string) => void;\n};\n\nfunction FlaggedBody({\n  field,\n  value,\n  isPressed,\n  onConfirm,\n  onEdit,\n}: FlaggedBodyProps) {\n  const [draft, setDraft] = useState<string | null>(null);\n  const isEditing = draft !== null;\n\n  function save() {\n    const next = draft?.trim() ?? '';\n    setDraft(null);\n    if (next !== '') {\n      onEdit(field.id, next);\n    }\n  }\n\n  function handleKeys(event: React.KeyboardEvent<HTMLInputElement>) {\n    if (event.key === 'Enter') {\n      save();\n    }\n    if (event.key === 'Escape') {\n      setDraft(null);\n    }\n  }\n\n  return (\n    <div className='flex flex-col gap-2 px-2 pb-2'>\n      <p className='text-warning-foreground text-xs'>{field.reason}</p>\n      {!isEditing && (\n        <div className='flex items-center gap-2'>\n          <Button\n            type='button'\n            size='sm'\n            onClick={() => onConfirm(field.id)}\n            className={pressedSolidOf(isPressed)}\n          >\n            Confirm {value}\n          </Button>\n          <Button\n            type='button'\n            size='sm'\n            variant='outline'\n            onClick={() => setDraft(value)}\n          >\n            Edit\n          </Button>\n        </div>\n      )}\n      {isEditing && (\n        <div className='flex items-center gap-2'>\n          <input\n            value={draft}\n            autoFocus\n            aria-label={`${field.label}, corrected value`}\n            onChange={(event) => setDraft(event.target.value)}\n            onKeyDown={handleKeys}\n            className='bg-card hairline-ring ring-foreground/15 focus-visible:ring-ring/25 dark:bg-foreground/[0.04] h-7 min-w-0 flex-1 rounded-md px-2 text-base outline-none focus-visible:ring-[3px] md:text-[13px]'\n          />\n          <Button type='button' size='sm' onClick={save}>\n            Save\n          </Button>\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport type FieldListProps = {\n  shown: number;\n  activeId: FieldId | null;\n  pressed: string | null;\n  valueOf: (field: ExtractField) => string;\n  reviewOf: (id: FieldId) => ReviewStatus;\n  onPoint: (id: FieldId | null) => void;\n  onPick: (id: FieldId) => void;\n  onConfirm: (id: FieldId) => void;\n  onEdit: (id: FieldId, value: string) => void;\n};\n\nexport function FieldList({\n  shown,\n  activeId,\n  pressed,\n  valueOf,\n  reviewOf,\n  onPoint,\n  onPick,\n  onConfirm,\n  onEdit,\n}: FieldListProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const fields = FIELDS.slice(0, shown);\n\n  return (\n    <ul aria-label='Fields read from the document' className='flex flex-col'>\n      <AnimatePresence initial={false}>\n        {fields.map((field) => {\n          const review = reviewOf(field.id);\n          const value = valueOf(field);\n          const needsLook = isLowConfidence(field) && review === 'pending';\n          const chipText = chipTextOf(field, review);\n          return (\n            <motion.li\n              key={field.id}\n              className='overflow-hidden'\n              {...rowPresence}\n            >\n              <div\n                className={cn(\n                  'rounded-lg transition-colors duration-150',\n                  rowToneOf(activeId === field.id)\n                )}\n              >\n                <button\n                  type='button'\n                  data-row={field.id}\n                  onMouseEnter={() => onPoint(field.id)}\n                  onMouseLeave={() => onPoint(null)}\n                  onFocus={() => onPoint(field.id)}\n                  onBlur={() => onPoint(null)}\n                  onClick={() => onPick(field.id)}\n                  className='focus-visible:ring-ring/25 flex min-h-11 w-full cursor-pointer items-center gap-3 rounded-lg px-2 py-1.5 text-start outline-none focus-visible:ring-[3px]'\n                >\n                  <span className='flex min-w-0 flex-1 flex-col leading-tight'>\n                    <span className='text-muted-foreground text-xs'>\n                      {field.label}\n                    </span>\n                    <span className='truncate text-[13px] font-medium tabular-nums'>\n                      {value}\n                    </span>\n                  </span>\n                  <Badge variant={confidenceVariantOf(field, review)}>\n                    <Swap swapKey={chipText} className='tabular-nums'>\n                      {chipText}\n                    </Swap>\n                  </Badge>\n                </button>\n                <Fold open={needsLook}>\n                  <FlaggedBody\n                    field={field}\n                    value={value}\n                    isPressed={pressed === `confirm-${field.id}`}\n                    onConfirm={onConfirm}\n                    onEdit={onEdit}\n                  />\n                </Fold>\n              </div>\n            </motion.li>\n          );\n        })}\n      </AnimatePresence>\n    </ul>\n  );\n}\n\nfunction typedValueOf(field: ExtractField, value: string) {\n  if (field.type === 'number') {\n    return Number(value);\n  }\n  return value;\n}\n\nexport function JsonPanel({\n  shown,\n  valueOf,\n}: {\n  shown: number;\n  valueOf: (field: ExtractField) => string;\n}) {\n  const record: Record<string, string | number> = {};\n  for (const field of FIELDS.slice(0, shown)) {\n    record[field.id] = typedValueOf(field, valueOf(field));\n  }\n\n  return <JsonView value={record} className='text-xs' />;\n}\n\nexport function SchemaPanel() {\n  return (\n    <ul aria-label='Schema' className='flex flex-col'>\n      {FIELDS.map((field) => (\n        <li\n          key={field.id}\n          className='flex h-9 items-center justify-between gap-3 px-2 text-[13px]'\n        >\n          <code className='truncate font-mono text-xs'>{field.id}</code>\n          <Badge variant='secondary' className='font-mono'>\n            {field.type}\n          </Badge>\n        </li>\n      ))}\n    </ul>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-03/fields.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-review/agent-review-03/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport { FIELDS, FLAGGED_IDS, type FieldId, type PageNumber } from './data';\n\nexport type ExtractTab = 'fields' | 'json' | 'schema';\n\nexport type ReviewStatus = 'pending' | 'confirmed' | 'edited';\n\nexport type SaveStatus = 'idle' | 'busy' | 'done';\n\nexport type ExtractState = {\n  shown: number;\n  page: PageNumber;\n  tab: ExtractTab;\n  /** The field the demonstration points at; a person's own pointer wins over it. */\n  pointed: FieldId | null;\n  review: Partial<Record<FieldId, ReviewStatus>>;\n  edits: Partial<Record<FieldId, string>>;\n  save: SaveStatus;\n};\n\nexport type ExtractAction =\n  | { type: 'read' }\n  | { type: 'page'; page: PageNumber }\n  | { type: 'tab'; tab: ExtractTab }\n  | { type: 'pointed'; id: FieldId | null }\n  | { type: 'confirmed'; id: FieldId }\n  | { type: 'edited'; id: FieldId; value: string }\n  | { type: 'saving' }\n  | { type: 'saved' };\n\ntype Step = SessionStep<ExtractState, ExtractAction>;\n\nexport const INITIAL: ExtractState = {\n  shown: 0,\n  page: 1,\n  tab: 'fields',\n  pointed: null,\n  review: {},\n  edits: {},\n  save: 'idle',\n};\n\nexport function reviewOf(state: ExtractState, id: FieldId): ReviewStatus {\n  return state.review[id] ?? 'pending';\n}\n\nexport function pendingIdsOf(state: ExtractState) {\n  return FLAGGED_IDS.filter((id) => reviewOf(state, id) === 'pending');\n}\n\nexport function isReadingDone(state: ExtractState) {\n  return state.shown >= FIELDS.length;\n}\n\n/** The viewer follows the page the agent is reading. */\nfunction read(state: ExtractState): ExtractState {\n  const field = FIELDS[state.shown];\n  if (!field) {\n    return state;\n  }\n  return { ...state, shown: state.shown + 1, page: field.page };\n}\n\nfunction saving(state: ExtractState): ExtractState {\n  const hasPending = pendingIdsOf(state).length > 0;\n  const canSave = isReadingDone(state) && !hasPending;\n  if (!canSave || state.save !== 'idle') {\n    return state;\n  }\n  return { ...state, save: 'busy' };\n}\n\nfunction saved(state: ExtractState): ExtractState {\n  if (state.save !== 'busy') {\n    return state;\n  }\n  return { ...state, save: 'done' };\n}\n\nexport function reducer(\n  state: ExtractState,\n  action: ExtractAction\n): ExtractState {\n  switch (action.type) {\n    case 'read':\n      return read(state);\n    case 'page':\n      return { ...state, page: action.page };\n    case 'tab':\n      return { ...state, tab: action.tab };\n    case 'pointed':\n      return { ...state, pointed: action.id };\n    case 'confirmed': {\n      const review = { ...state.review, [action.id]: 'confirmed' as const };\n      return { ...state, review };\n    }\n    case 'edited': {\n      const review = { ...state.review, [action.id]: 'edited' as const };\n      const edits = { ...state.edits, [action.id]: action.value };\n      return { ...state, review, edits };\n    }\n    case 'saving':\n      return saving(state);\n    case 'saved':\n      return saved(state);\n  }\n}\n\nfunction readSteps(): Step[] {\n  return FIELDS.map((_, index) => {\n    const after = delayOfRead(index);\n    return { after, action: { type: 'read' } };\n  });\n}\n\nfunction delayOfRead(index: number) {\n  if (index === 0) {\n    return 1100;\n  }\n  return 520;\n}\n\nfunction isReviewed(id: FieldId) {\n  return (state: ExtractState) => reviewOf(state, id) !== 'pending';\n}\n\nexport const SAVE_MS = 900;\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 SCRIPT: Step[] = [\n  ...readSteps(),\n  { after: 900, by: 'demo', action: { type: 'pointed', id: 'total' } },\n  { after: 1700, by: 'demo', action: { type: 'pointed', id: 'payment_terms' } },\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: 'confirm-payment_terms',\n    action: { type: 'confirmed', id: 'payment_terms' },\n    isAnswered: isReviewed('payment_terms'),\n  },\n  { after: 500, by: 'demo', action: { type: 'pointed', id: 'delivery_date' } },\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: 'confirm-delivery_date',\n    action: { type: 'confirmed', id: 'delivery_date' },\n    isAnswered: isReviewed('delivery_date'),\n  },\n  { after: 500, by: 'demo', action: { type: 'pointed', id: null } },\n  { after: 1300, by: 'demo', press: 'accept', action: { type: 'saving' } },\n  { after: SAVE_MS, action: { type: 'saved' } },\n];\n\nfunction restingOf() {\n  let state = INITIAL;\n  for (const step of SCRIPT) {\n    state = reducer(state, step.action);\n  }\n  return state;\n}\n\nexport const RESTING = restingOf();\n\nexport const LOOP_AFTER_MS = 3200;\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-03/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/agent-review/agent-review-03/data.ts",
      "content": "export type FieldId =\n  | 'po_number'\n  | 'order_date'\n  | 'supplier'\n  | 'bill_to'\n  | 'currency'\n  | 'total'\n  | 'payment_terms'\n  | 'delivery_date';\n\nexport type PageNumber = 1 | 2;\n\nexport type ExtractField = {\n  id: FieldId;\n  label: string;\n  type: 'string' | 'date' | 'number';\n  value: string;\n  /** How the value is printed on the page, when the document writes it another way. */\n  printed: string;\n  page: PageNumber;\n  /** Between 0 and 100. Illustrative: the demonstration does not read a real document. */\n  confidence: number;\n  /** Why a person should look, for a value read with low confidence. */\n  reason?: string;\n};\n\nexport const DOCUMENT_NAME = 'purchase-order-2291.pdf';\n\nexport const FIELDS: ExtractField[] = [\n  {\n    id: 'po_number',\n    label: 'PO number',\n    type: 'string',\n    value: 'PO-2291',\n    printed: 'PO-2291',\n    page: 1,\n    confidence: 99,\n  },\n  {\n    id: 'order_date',\n    label: 'Order date',\n    type: 'date',\n    value: '2026-03-04',\n    printed: '4 March 2026',\n    page: 1,\n    confidence: 98,\n  },\n  {\n    id: 'supplier',\n    label: 'Supplier',\n    type: 'string',\n    value: 'Harbourline Freight Ltd',\n    printed: 'Harbourline Freight Ltd',\n    page: 1,\n    confidence: 97,\n  },\n  {\n    id: 'bill_to',\n    label: 'Bill to',\n    type: 'string',\n    value: 'Tallis Studio, 14 Quay Street',\n    printed: 'Tallis Studio, 14 Quay Street',\n    page: 1,\n    confidence: 96,\n  },\n  {\n    id: 'currency',\n    label: 'Currency',\n    type: 'string',\n    value: 'EUR',\n    printed: 'EUR',\n    page: 2,\n    confidence: 99,\n  },\n  {\n    id: 'total',\n    label: 'Total',\n    type: 'number',\n    value: '4860.00',\n    printed: '4,860.00',\n    page: 2,\n    confidence: 98,\n  },\n  {\n    id: 'payment_terms',\n    label: 'Payment terms',\n    type: 'string',\n    value: 'Net 30',\n    printed: 'Net 30',\n    page: 2,\n    confidence: 71,\n    reason: 'A handwritten note beside the printed terms reads Net 45',\n  },\n  {\n    id: 'delivery_date',\n    label: 'Delivery date',\n    type: 'date',\n    value: '2026-03-18',\n    printed: '18 March 2026',\n    page: 2,\n    confidence: 64,\n    reason: 'A stamp covers part of the date',\n  },\n];\n\nexport const FLAGGED_IDS: FieldId[] = FIELDS.filter(\n  (field) => field.reason !== undefined\n).map((field) => field.id);\n\nexport const LINE_ITEMS = [\n  {\n    name: 'Pallet freight, Rotterdam to Lisbon',\n    quantity: 12,\n    amount: '2,160.00',\n  },\n  { name: 'Customs handling', quantity: 30, amount: '1,620.00' },\n  { name: 'Cargo insurance', quantity: 1, amount: '1,080.00' },\n];\n\nexport function fieldOf(id: FieldId) {\n  const field = FIELDS.find((candidate) => candidate.id === id);\n  return field ?? FIELDS[0];\n}\n\nexport function isLowConfidence(field: ExtractField) {\n  return field.reason !== undefined;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-03/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "agent-review"
  ],
  "type": "registry:block"
}