{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-ops-07",
  "title": "Agent builder",
  "description": "One agent on a card, with its model, instructions, tools and knowledge files that upload, and a Test tab that answers: Publish opens what changed and three sample prompts that run, fails once, then Retry draws the check of the new live version.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/inline-sheet.json",
    "https://ui.ndekocode.dev/r/input.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/segments.json",
    "https://ui.ndekocode.dev/r/streamed-text.json",
    "https://ui.ndekocode.dev/r/switch.json",
    "https://ui.ndekocode.dev/r/textarea.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/toggle-group.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-07/index.tsx",
      "content": "'use client';\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 { 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 { BotIcon, RocketIcon } from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\n\nimport { Configure } from './configure';\nimport { ReviewPanel } from './review-panel';\nimport {\n  ANSWER_MS,\n  changesOf,\n  INITIAL,\n  LOOP_AFTER_MS,\n  nextSampleFileOf,\n  PUBLISH_MS,\n  reducer,\n  RESTING,\n  SAMPLE_MS,\n  SAMPLE_TICKS,\n  SCRIPT,\n  UPLOAD_STEP_MS,\n  UPLOAD_STEPS,\n  type BuilderState,\n  type View,\n} from './session';\nimport { TestChat } from './test-chat';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nconst VIEWS: Segment<View>[] = [\n  { value: 'configure', label: 'Configure' },\n  { value: 'test', label: 'Test' },\n];\n\nfunction draftLineOf(changeCount: number) {\n  if (changeCount === 0) {\n    return 'No change to publish';\n  }\n  if (changeCount === 1) {\n    return '1 change in the draft';\n  }\n  return `${changeCount} changes in the draft`;\n}\n\nfunction publishLineOf(state: BuilderState, draftLine: string) {\n  if (state.publish === 'done') {\n    return `Version ${state.liveVersion} is live`;\n  }\n  if (state.publish === 'failed') {\n    return 'Publishing failed. Nothing changed';\n  }\n  if (state.publish === 'pending') {\n    return 'Publishing';\n  }\n  return draftLine;\n}\n\nfunction viewClassOf(isShown: boolean) {\n  if (isShown) {\n    return 'block';\n  }\n  return 'hidden';\n}\n\nexport default function AgentOps07() {\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 shouldReduceMotion = usePrefersReducedMotion();\n  const changeCount = changesOf(state).length;\n  const draftLine = draftLineOf(changeCount);\n  const publishLine = publishLineOf(state, draftLine);\n  const message = spokenUnless(isAutoplaying, publishLine);\n  const canReplay = isFinished && !isAutoplaying;\n  const isConfiguring = state.view === 'configure';\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const target = ref.current?.querySelector<HTMLElement>(selector);\n      target?.focus();\n    });\n  }\n\n  function addFile() {\n    const file = nextSampleFileOf(state);\n    if (!file) {\n      return;\n    }\n    act({ type: 'fileAdded' });\n    UPLOAD_STEPS.forEach((progress, index) => {\n      const step = index + 1;\n      const report = () => act({ type: 'fileProgress', id: file.id, progress });\n      schedule(report, UPLOAD_STEP_MS * step);\n    });\n  }\n\n  function send() {\n    act({ type: 'chatSent' });\n    schedule(() => act({ type: 'answered' }), ANSWER_MS);\n  }\n\n  function openReview() {\n    act({ type: 'reviewOpened' });\n    for (let tick = 1; tick <= SAMPLE_TICKS; tick += 1) {\n      schedule(() => act({ type: 'sampleRan' }), SAMPLE_MS * tick);\n    }\n    focusLater('[data-review-first]');\n  }\n\n  function closeReview() {\n    act({ type: 'reviewClosed' });\n    focusLater('[data-review]');\n  }\n\n  function publish() {\n    act({ type: 'publish' });\n    schedule(() => {\n      act({ type: 'publishSettled' });\n      focusLater('[data-review-first]');\n    }, PUBLISH_MS);\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container relative h-dvh min-h-[44rem] w-full overflow-hidden'\n      >\n        <div inert={state.isReviewOpen} className='h-full overflow-y-auto'>\n          <div className='mx-auto flex max-w-2xl flex-col gap-3 p-4 @3xl:p-8'>\n            <section\n              aria-label='Agent'\n              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)] @xl:p-5'\n            >\n              <header className='flex flex-wrap items-center gap-x-3 gap-y-3'>\n                <span\n                  aria-hidden='true'\n                  className='gem-plate inline-flex size-9 shrink-0 items-center justify-center rounded-lg [--gem:var(--primary)]'\n                >\n                  <BotIcon className='size-5' />\n                </span>\n                <div className='flex min-w-40 flex-1 flex-col gap-1'>\n                  <input\n                    value={state.name}\n                    aria-label='Agent name'\n                    autoComplete='off'\n                    spellCheck={false}\n                    onChange={(event) =>\n                      act({ type: 'named', text: event.target.value })\n                    }\n                    className='hover:bg-foreground/[0.04] focus-visible:ring-ring/25 -mx-1 field-sizing-content max-w-full min-w-24 rounded-md bg-transparent px-1 text-lg leading-7 font-semibold transition-colors duration-150 outline-none focus-visible:ring-[3px]'\n                  />\n                  <p className='text-muted-foreground flex flex-wrap items-center gap-x-2 gap-y-1 text-xs'>\n                    <Chip color='var(--success)'>\n                      <MotionNumber value={state.liveVersion} prefix='v' />\n                      live\n                    </Chip>\n                    <WordRoll text={draftLine} />\n                  </p>\n                </div>\n                <ReplayButton\n                  isShown={canReplay}\n                  onReplay={restart}\n                  label='Replay the setup'\n                />\n                <Button\n                  type='button'\n                  data-review\n                  onClick={openReview}\n                  className={pressedSolidOf(pressed === 'review')}\n                >\n                  <RocketIcon />\n                  Publish\n                </Button>\n              </header>\n\n              <Segments\n                value={state.view}\n                segments={VIEWS}\n                onValueChange={(view) => act({ type: 'view', view })}\n                label='View'\n                className='w-full @sm:w-56'\n              />\n\n              <AnimatedSize>\n                <div className={viewClassOf(isConfiguring)}>\n                  <Configure\n                    state={state}\n                    pressed={pressed}\n                    onAction={act}\n                    onAddFile={addFile}\n                  />\n                </div>\n                <div className={viewClassOf(!isConfiguring)}>\n                  <TestChat\n                    agentName={state.name}\n                    turns={state.turns}\n                    draft={state.draft}\n                    isAnswering={state.isAnswering}\n                    isActive={isInView}\n                    shouldReduceMotion={shouldReduceMotion}\n                    pressed={pressed}\n                    onDraftChange={(text) => act({ type: 'chatTyped', text })}\n                    onSend={send}\n                  />\n                </div>\n              </AnimatedSize>\n            </section>\n          </div>\n        </div>\n\n        <ReviewPanel\n          state={state}\n          pressed={pressed}\n          onPublish={publish}\n          onClose={closeReview}\n        />\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-07/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-07/configure.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 {\n  CheckIcon,\n  FileTextIcon,\n  ReceiptIcon,\n  UploadIcon,\n  XIcon,\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 { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { Switch } from '@/registry/ndeko/ui/switch';\nimport { Textarea } from '@/registry/ndeko/ui/textarea';\nimport { ToggleGroup, ToggleGroupItem } from '@/registry/ndeko/ui/toggle-group';\n\nimport { INSTRUCTIONS_LIMIT, MODELS, TOOLS, type AgentTool } from './data';\nimport {\n  isIndexed,\n  nextSampleFileOf,\n  type BuilderAction,\n  type BuilderState,\n  type LiveFile,\n} from './session';\n\nconst THUMB =\n  'bg-card shadow-[0_1px_2px_rgb(0_0_0/0.08)] hairline-ring ring-foreground/10 dark:bg-foreground/[0.09] dark:ring-foreground/15';\n\nconst COUNT_FORMAT = new Intl.NumberFormat('en-US');\n\n/** The count turns to the warning tone in the last tenth of the room. */\nconst NEAR_LIMIT = 0.9;\n\nfunction countToneOf(count: number) {\n  const isNearLimit = count >= INSTRUCTIONS_LIMIT * NEAR_LIMIT;\n  if (isNearLimit) {\n    return 'text-warning-foreground';\n  }\n  return 'text-muted-foreground';\n}\n\nfunction fillOf(progress: number) {\n  const share = progress / 100;\n  return { transform: `scaleX(${share})` };\n}\n\nfunction fileStateOf(file: LiveFile) {\n  if (isIndexed(file)) {\n    return 'Indexed';\n  }\n  return `${file.progress}%`;\n}\n\nfunction pressedQuietOf(isPressed: boolean) {\n  if (isPressed) {\n    return 'scale-[0.94] bg-foreground/[0.07]';\n  }\n  return undefined;\n}\n\nfunction Section({\n  title,\n  aside,\n  children,\n}: {\n  title: React.ReactNode;\n  aside?: React.ReactNode;\n  children: React.ReactNode;\n}) {\n  return (\n    <div className='flex flex-col gap-2'>\n      <div className='flex min-h-5 items-center justify-between gap-3'>\n        {title}\n        {aside}\n      </div>\n      {children}\n    </div>\n  );\n}\n\nfunction ToolTile({ tool }: { tool: AgentTool }) {\n  if (tool.brand) {\n    return <BrandTile brand={tool.brand} size='lg' />;\n  }\n  return (\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      <ReceiptIcon className='size-4' />\n    </span>\n  );\n}\n\ntype FileRowProps = {\n  file: LiveFile;\n  onRemove: (id: string) => void;\n};\n\nfunction FileRow({ file, onRemove }: FileRowProps) {\n  const isDone = isIndexed(file);\n  const fileState = fileStateOf(file);\n\n  return (\n    <div className='flex items-center gap-3 px-1 py-1.5'>\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-4' />\n      </span>\n      <div className='flex min-w-0 flex-1 flex-col'>\n        <p className='flex items-baseline gap-2'>\n          <span className='truncate text-[13px]'>{file.name}</span>\n          <span className='text-muted-foreground shrink-0 text-xs tabular-nums'>\n            {file.size}\n          </span>\n        </p>\n        <Fold open={!isDone}>\n          <div\n            role='progressbar'\n            aria-label={`Uploading ${file.name}`}\n            aria-valuemin={0}\n            aria-valuemax={100}\n            aria-valuenow={file.progress}\n            className='bg-foreground/[0.06] mt-1 h-1 overflow-hidden rounded-full'\n          >\n            <div\n              style={fillOf(file.progress)}\n              className='bg-primary h-full origin-left rounded-full transition-transform duration-500 ease-(--ease-out-strong)'\n            />\n          </div>\n        </Fold>\n      </div>\n      <span className='text-muted-foreground flex w-[4.5rem] shrink-0 justify-end text-xs tabular-nums'>\n        <Swap swapKey={String(isDone)}>\n          <span className='flex items-center gap-1'>\n            {isDone && (\n              <CheckIcon className='text-success-foreground size-3.5' />\n            )}\n            {fileState}\n          </span>\n        </Swap>\n      </span>\n      <Button\n        type='button'\n        variant='ghost'\n        size='icon-sm'\n        aria-label={`Remove ${file.name}`}\n        onClick={() => onRemove(file.id)}\n        className='text-muted-foreground'\n      >\n        <XIcon />\n      </Button>\n    </div>\n  );\n}\n\nexport type ConfigureProps = {\n  state: BuilderState;\n  pressed: string | null;\n  onAction: (action: BuilderAction) => void;\n  onAddFile: () => void;\n};\n\nexport function Configure({\n  state,\n  pressed,\n  onAction,\n  onAddFile,\n}: ConfigureProps) {\n  const instructionsId = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const count = state.instructions.length;\n  const countText = COUNT_FORMAT.format(count);\n  const hasFiles = state.files.length > 0;\n  const canAddFile = nextSampleFileOf(state) !== undefined;\n\n  function changeModel(values: unknown[]) {\n    const [next] = values;\n    const model = MODELS.find((candidate) => candidate.id === next);\n    if (model) {\n      onAction({ type: 'model', id: model.id });\n    }\n  }\n\n  return (\n    <div className='flex flex-col gap-6'>\n      <Section\n        title={<h2 className='text-[13px] font-medium'>Model</h2>}\n        aside={<Badge variant='secondary'>Illustrative hints</Badge>}\n      >\n        <ToggleGroup\n          aria-label='Model'\n          value={[state.modelId]}\n          onValueChange={changeModel}\n          travel\n          indicatorClassName={THUMB}\n          className='bg-foreground/[0.04] grid w-full grid-cols-2 gap-1 rounded-xl p-1 @xl:grid-cols-4'\n        >\n          {MODELS.map((model) => (\n            <ToggleGroupItem\n              key={model.id}\n              value={model.id}\n              className='h-auto min-w-0 justify-start gap-2 rounded-lg px-2 py-2 text-start'\n            >\n              <BrandTile brand={model.brand} />\n              <span className='flex min-w-0 flex-col leading-tight'>\n                <span className='text-foreground truncate text-[13px]'>\n                  {model.name}\n                </span>\n                <span className='text-muted-foreground truncate text-[11px] font-normal'>\n                  {model.hint}\n                </span>\n              </span>\n            </ToggleGroupItem>\n          ))}\n        </ToggleGroup>\n      </Section>\n\n      <Section\n        title={<Label htmlFor={instructionsId}>Instructions</Label>}\n        aside={\n          <span\n            className={cn(\n              'text-xs tabular-nums transition-colors duration-200',\n              countToneOf(count)\n            )}\n          >\n            {countText} of {INSTRUCTIONS_LIMIT} characters\n          </span>\n        }\n      >\n        <Textarea\n          id={instructionsId}\n          value={state.instructions}\n          maxLength={INSTRUCTIONS_LIMIT}\n          onChange={(event) =>\n            onAction({ type: 'instructed', text: event.target.value })\n          }\n          className='min-h-24'\n        />\n      </Section>\n\n      <Section\n        title={<h2 className='text-[13px] font-medium'>What it may use</h2>}\n      >\n        <ul className='flex flex-col'>\n          {TOOLS.map((tool) => (\n            <li key={tool.id} className='flex items-center gap-3 py-2'>\n              <ToolTile tool={tool} />\n              <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n                <p className='text-[13px] leading-5 font-medium'>{tool.name}</p>\n                <p className='text-muted-foreground text-xs'>{tool.allows}</p>\n              </div>\n              <Switch\n                checked={state.tools[tool.id]}\n                onCheckedChange={(isOn) =>\n                  onAction({ type: 'toolSet', id: tool.id, isOn })\n                }\n                aria-label={tool.name}\n              />\n            </li>\n          ))}\n        </ul>\n      </Section>\n\n      <Section title={<h2 className='text-[13px] font-medium'>Knowledge</h2>}>\n        {!hasFiles && (\n          <p className='text-muted-foreground text-[13px]'>\n            No file yet. The agent answers from its instructions alone.\n          </p>\n        )}\n        <ul className='-mx-1 flex flex-col'>\n          <AnimatePresence initial={false}>\n            {state.files.map((file) => (\n              <motion.li\n                key={file.id}\n                className='overflow-hidden'\n                {...rowPresence}\n              >\n                <FileRow\n                  file={file}\n                  onRemove={(id) => onAction({ type: 'fileRemoved', id })}\n                />\n              </motion.li>\n            ))}\n          </AnimatePresence>\n        </ul>\n        <Button\n          type='button'\n          variant='outline'\n          size='sm'\n          disabled={!canAddFile}\n          onClick={onAddFile}\n          className={cn('self-start', pressedQuietOf(pressed === 'add-file'))}\n        >\n          <UploadIcon />\n          Add a sample file\n        </Button>\n      </Section>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-07/configure.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-07/test-chat.tsx",
      "content": "'use client';\n\nimport { useEffect, useId, useRef } from 'react';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowUpIcon, BotIcon, CheckIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport {\n  StreamedWords,\n  useRevealedCount,\n} from '@/registry/ndeko/ui/streamed-text';\n\nimport type { ChatTurn } from './session';\n\nconst WORD_MS = 48;\n\ntype StreamedReplyProps = {\n  text: string;\n  isActive: boolean;\n};\n\n/** Only this text re-renders while the reply streams, word by word. */\nfunction StreamedReply({ text, isActive }: StreamedReplyProps) {\n  const words = text.split(' ');\n  const count = useRevealedCount(words.length, isActive, WORD_MS);\n\n  return (\n    <p className='text-sm leading-relaxed'>\n      <span className='sr-only'>{text}</span>\n      <span aria-hidden='true'>\n        <StreamedWords words={words} shown={count} keepsPlace={false} />\n      </span>\n    </p>\n  );\n}\n\nfunction AgentTile() {\n  return (\n    <span\n      aria-hidden='true'\n      className='gem-plate inline-flex size-6 shrink-0 items-center justify-center rounded-md [--gem:var(--primary)]'\n    >\n      <BotIcon className='size-3.5' />\n    </span>\n  );\n}\n\ntype TurnRowProps = {\n  turn: ChatTurn;\n  isActive: boolean;\n  shouldStream: boolean;\n};\n\nfunction TurnRow({ turn, isActive, shouldStream }: TurnRowProps) {\n  if (turn.role === 'person') {\n    return (\n      <li className='flex justify-end'>\n        <p className='bg-foreground/[0.06] max-w-[85%] rounded-2xl rounded-ee-md px-3.5 py-2 text-sm leading-relaxed'>\n          {turn.text}\n        </p>\n      </li>\n    );\n  }\n  return (\n    <li className='flex items-start gap-2.5'>\n      <AgentTile />\n      <div className='flex min-w-0 flex-1 flex-col gap-1.5'>\n        {turn.tool && (\n          <p className='text-muted-foreground flex items-center gap-1.5 text-xs transition-opacity duration-300 starting:opacity-0'>\n            <CheckIcon className='text-success-foreground size-3.5 shrink-0' />\n            {turn.tool}\n          </p>\n        )}\n        {shouldStream && <StreamedReply text={turn.text} isActive={isActive} />}\n        {!shouldStream && (\n          <p className='text-sm leading-relaxed'>{turn.text}</p>\n        )}\n      </div>\n    </li>\n  );\n}\n\nexport type TestChatProps = {\n  agentName: string;\n  turns: ChatTurn[];\n  draft: string;\n  isAnswering: boolean;\n  /** False while the block is off screen: the reply stops streaming until it is back. */\n  isActive: boolean;\n  shouldReduceMotion: boolean | null;\n  pressed: string | null;\n  onDraftChange: (text: string) => void;\n  onSend: () => void;\n};\n\n/** The replies are canned: nothing is sent to a model. */\nexport function TestChat({\n  agentName,\n  turns,\n  draft,\n  isAnswering,\n  isActive,\n  shouldReduceMotion,\n  pressed,\n  onDraftChange,\n  onSend,\n}: TestChatProps) {\n  const fieldId = useId();\n  const listRef = useRef<HTMLDivElement>(null);\n  const turnCount = turns.length;\n  const isEmpty = turnCount === 0;\n  const canSend = draft.trim() !== '' && !isAnswering;\n  const shouldStream = !shouldReduceMotion;\n\n  useEffect(() => {\n    const list = listRef.current;\n    if (list) {\n      list.scrollTop = list.scrollHeight;\n    }\n  }, [turnCount, isAnswering]);\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onSend();\n  }\n\n  return (\n    <div className='flex flex-col gap-3'>\n      <div\n        ref={listRef}\n        className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex h-72 flex-col overflow-y-auto rounded-xl p-3'\n      >\n        {isEmpty && (\n          <p className='text-muted-foreground m-auto max-w-xs text-center text-[13px]'>\n            Ask what a customer would ask. The replies are canned for this demo:\n            nothing is sent to a model.\n          </p>\n        )}\n        <ul aria-label='Test conversation' className='flex flex-col gap-3'>\n          {turns.map((turn) => (\n            <TurnRow\n              key={turn.id}\n              turn={turn}\n              isActive={isActive}\n              shouldStream={shouldStream}\n            />\n          ))}\n        </ul>\n        {isAnswering && (\n          <p className='text-muted-foreground flex items-center gap-2 pt-3 text-xs'>\n            <span\n              aria-hidden='true'\n              className='bg-primary size-1.5 animate-pulse rounded-full'\n            />\n            {agentName} is thinking\n          </p>\n        )}\n      </div>\n      <form onSubmit={submit} className='flex items-center gap-2'>\n        <label htmlFor={fieldId} className='sr-only'>\n          Message to test the agent\n        </label>\n        <Input\n          id={fieldId}\n          autoComplete='off'\n          placeholder='Ask as a customer'\n          value={draft}\n          onChange={(event) => onDraftChange(event.target.value)}\n        />\n        <Button\n          type='submit'\n          size='icon'\n          aria-label='Send the message'\n          disabled={!canSend}\n          className={cn('shrink-0', pressedSolidOf(pressed === 'send'))}\n        >\n          <ArrowUpIcon />\n        </Button>\n      </form>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-07/test-chat.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-07/review-panel.tsx",
      "content": "'use client';\n\nimport { 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 {\n  CircleCheckIcon,\n  CircleXIcon,\n  LoaderIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { EASE_OUT_STRONG } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { InlineSheet } from '@/registry/ndeko/ui/inline-sheet';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\n\nimport { SAMPLES, type Sample } from './data';\nimport {\n  canPublish,\n  changesOf,\n  type BuilderState,\n  type PublishStatus,\n  type SampleStatus,\n} from './session';\n\nconst SAMPLE_WORD: Record<SampleStatus, string> = {\n  queued: 'Queued',\n  running: 'Running',\n  pass: 'Passed',\n  fail: 'Failed',\n};\n\nconst SAMPLE_TONE: Record<SampleStatus, string> = {\n  queued: 'text-muted-foreground',\n  running: 'text-muted-foreground',\n  pass: 'text-success-foreground',\n  fail: 'text-destructive-ink',\n};\n\nconst PUBLISH_STATE: Record<PublishStatus, MorphState> = {\n  idle: 'idle',\n  pending: 'busy',\n  failed: 'idle',\n  done: 'done',\n};\n\nconst CHECK_PATH = 'M5 10.4 8.6 14 15 6.6';\n\nconst DRAW = { duration: 0.5, ease: EASE_OUT_STRONG, delay: 0.12 };\n\nconst SETTLE = { duration: 0.3, ease: EASE_OUT_STRONG };\n\nfunction idleLabelOf(publish: PublishStatus, version: number) {\n  if (publish === 'failed') {\n    return 'Retry';\n  }\n  return `Publish version ${version}`;\n}\n\nfunction strokeStartOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return { pathLength: 1 };\n  }\n  return { pathLength: 0 };\n}\n\nfunction markStartOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return { opacity: 0, scale: 1 };\n  }\n  return { opacity: 0, scale: 1.04 };\n}\n\nfunction SampleMark({ status }: { status: SampleStatus }) {\n  return (\n    <Swap swapKey={status} className='size-4 shrink-0'>\n      {status === 'queued' && (\n        <span className='bg-muted-foreground/40 m-auto size-1.5 rounded-full' />\n      )}\n      {status === 'running' && (\n        <LoaderIcon className='text-muted-foreground size-4 animate-spin' />\n      )}\n      {status === 'pass' && (\n        <CircleCheckIcon className='text-success-foreground size-4' />\n      )}\n      {status === 'fail' && (\n        <CircleXIcon className='text-destructive-ink size-4' />\n      )}\n    </Swap>\n  );\n}\n\ntype SampleRowProps = {\n  sample: Sample;\n  status: SampleStatus;\n};\n\nfunction SampleRow({ sample, status }: SampleRowProps) {\n  const hasFailed = status === 'fail';\n\n  return (\n    <li className='flex items-start gap-2.5 py-1.5'>\n      <span className='flex h-5 items-center'>\n        <SampleMark status={status} />\n      </span>\n      <div className='flex min-w-0 flex-1 flex-col'>\n        <p className='text-[13px] leading-5'>{sample.prompt}</p>\n        <Fold open={hasFailed}>\n          <p className='text-destructive-ink text-xs'>{sample.failure}</p>\n        </Fold>\n      </div>\n      <span\n        className={cn(\n          'shrink-0 text-xs leading-5 transition-colors duration-200',\n          SAMPLE_TONE[status]\n        )}\n      >\n        <Swap swapKey={status}>{SAMPLE_WORD[status]}</Swap>\n      </span>\n    </li>\n  );\n}\n\nfunction LiveMark() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  return (\n    <motion.span\n      aria-hidden='true'\n      initial={markStartOf(shouldReduceMotion)}\n      animate={{ opacity: 1, scale: 1 }}\n      transition={SETTLE}\n      className='bg-success/10 text-success-foreground flex size-10 items-center justify-center rounded-full'\n    >\n      <svg viewBox='0 0 20 20' className='size-5'>\n        <motion.path\n          d={CHECK_PATH}\n          fill='none'\n          stroke='currentColor'\n          strokeWidth='1.75'\n          strokeLinecap='round'\n          strokeLinejoin='round'\n          initial={strokeStartOf(shouldReduceMotion)}\n          animate={{ pathLength: 1 }}\n          transition={DRAW}\n        />\n      </svg>\n    </motion.span>\n  );\n}\n\nexport type ReviewPanelProps = {\n  state: BuilderState;\n  pressed: string | null;\n  onPublish: () => void;\n  onClose: () => void;\n};\n\n/** Drawn inside the block, so the demonstration never opens a layer over the rest of the page. */\nexport function ReviewPanel({\n  state,\n  pressed,\n  onPublish,\n  onClose,\n}: ReviewPanelProps) {\n  const titleId = useId();\n  const isOpen = state.isReviewOpen;\n  const isLive = state.publish === 'done';\n  const isPending = state.publish === 'pending';\n  const hasFailed = state.publish === 'failed';\n  const changes = changesOf(state);\n  const hasChanges = changes.length > 0;\n  const nextVersion = state.liveVersion + 1;\n  const labels: Record<MorphState, string> = {\n    idle: idleLabelOf(state.publish, nextVersion),\n    busy: 'Publishing',\n    done: 'Published',\n  };\n\n  return (\n    <InlineSheet\n      labelledBy={titleId}\n      closeLabel='Close the review'\n      side='center'\n      closer='none'\n      isOpen={isOpen}\n      panelClassName='text-card-foreground p-6'\n      onClose={onClose}\n    >\n      <AnimatedSize contentClassName='flex flex-col gap-4'>\n        {isLive && (\n          <div className='flex flex-col items-start gap-3'>\n            <LiveMark />\n            <div className='flex flex-col gap-1'>\n              <h2 id={titleId} className='text-lg leading-tight font-semibold'>\n                Version {state.liveVersion} is live\n              </h2>\n              <p className='text-muted-foreground text-[13px]'>\n                Every new conversation uses it. The version before it is kept\n                for a rollback.\n              </p>\n            </div>\n            <Button\n              type='button'\n              data-review-first\n              onClick={onClose}\n              className='self-end'\n            >\n              Done\n            </Button>\n          </div>\n        )}\n        {!isLive && (\n          <>\n            <div className='flex flex-col gap-1.5 pe-8'>\n              <h2 id={titleId} className='text-lg leading-tight font-semibold'>\n                Publish version {nextVersion}\n              </h2>\n              <p className='text-muted-foreground text-[13px]'>\n                Version {state.liveVersion} keeps answering until this one is\n                live.\n              </p>\n            </div>\n\n            <div className='flex flex-col gap-1.5'>\n              <h3 className='text-muted-foreground text-xs'>\n                Changed since version {state.liveVersion}\n              </h3>\n              {!hasChanges && (\n                <p className='text-[13px]'>\n                  Nothing changed, so there is nothing to publish\n                </p>\n              )}\n              <ul className='flex flex-col gap-1'>\n                {changes.map((change) => (\n                  <li key={change} className='flex gap-2 text-[13px]'>\n                    <span\n                      aria-hidden='true'\n                      className='bg-foreground/30 mt-2 size-1 shrink-0 rounded-full'\n                    />\n                    {change}\n                  </li>\n                ))}\n              </ul>\n            </div>\n\n            <div className='flex flex-col gap-1'>\n              <h3 className='text-muted-foreground text-xs'>Sample prompts</h3>\n              <ul className='flex flex-col'>\n                {SAMPLES.map((sample, index) => (\n                  <SampleRow\n                    key={sample.id}\n                    sample={sample}\n                    status={state.samples[index]}\n                  />\n                ))}\n              </ul>\n            </div>\n\n            <div aria-live='polite'>\n              <Fold open={hasFailed}>\n                <p className='bg-destructive/10 rounded-lg p-3 text-[13px] leading-relaxed'>\n                  <span className='text-destructive-ink font-medium'>\n                    Publishing failed.\n                  </span>{' '}\n                  The service did not answer in time. Version{' '}\n                  {state.liveVersion} is still live and nothing changed.\n                </p>\n              </Fold>\n            </div>\n\n            <div className='flex flex-col-reverse gap-2 @sm:flex-row @sm:justify-end'>\n              <Button\n                type='button'\n                variant='ghost'\n                disabled={isPending}\n                onClick={onClose}\n              >\n                Cancel\n              </Button>\n              <MorphButton\n                type='button'\n                data-review-first\n                state={PUBLISH_STATE[state.publish]}\n                labels={labels}\n                disabled={!canPublish(state)}\n                onClick={onPublish}\n                className={pressedSolidOf(pressed === 'publish')}\n              />\n            </div>\n          </>\n        )}\n      </AnimatedSize>\n      {!isLive && (\n        <Button\n          type='button'\n          variant='ghost'\n          size='icon-sm'\n          aria-label='Close'\n          disabled={isPending}\n          onClick={onClose}\n          className='text-muted-foreground absolute top-3 right-3'\n        >\n          <XIcon />\n        </Button>\n      )}\n    </InlineSheet>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-07/review-panel.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-07/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport {\n  DEMO_INSTRUCTIONS,\n  DEMO_QUESTION,\n  FIRST_FILES,\n  INSTRUCTIONS_LIMIT,\n  LIVE_CONFIG,\n  LIVE_VERSION,\n  modelOf,\n  REPLY_WITH_REFUND,\n  REPLY_WITHOUT_ORDERS,\n  REPLY_WITHOUT_REFUND,\n  SAMPLE_FILES,\n  SAMPLES,\n  TOOLS,\n  type AgentConfig,\n  type KnowledgeFile,\n  type ModelId,\n  type Sample,\n  type ToolId,\n} from './data';\n\nexport type View = 'configure' | 'test';\n\nexport type LiveFile = KnowledgeFile & {\n  /** From 0 to 100 while it uploads; 100 once it is indexed. */\n  progress: number;\n};\n\nexport type ChatTurn = {\n  id: number;\n  role: 'person' | 'agent';\n  text: string;\n  /** The tool the agent used before it answered. */\n  tool?: string;\n};\n\nexport type SampleStatus = 'queued' | 'running' | 'pass' | 'fail';\n\nexport type PublishStatus = 'idle' | 'pending' | 'failed' | 'done';\n\nexport type BuilderState = {\n  /** What the live version runs with: the draft is compared with it. */\n  live: AgentConfig;\n  liveVersion: number;\n  name: string;\n  view: View;\n  modelId: ModelId;\n  instructions: string;\n  tools: Record<ToolId, boolean>;\n  files: LiveFile[];\n  draft: string;\n  turns: ChatTurn[];\n  isAnswering: boolean;\n  isReviewOpen: boolean;\n  samples: SampleStatus[];\n  publish: PublishStatus;\n  attempts: number;\n};\n\nexport type BuilderAction =\n  | { type: 'named'; text: string }\n  | { type: 'view'; view: View }\n  | { type: 'model'; id: ModelId }\n  | { type: 'instructed'; text: string }\n  | { type: 'toolSet'; id: ToolId; isOn: boolean }\n  | { type: 'fileAdded' }\n  | { type: 'fileProgress'; id: string; progress: number }\n  | { type: 'fileRemoved'; id: string }\n  | { type: 'chatTyped'; text: string }\n  | { type: 'chatSent' }\n  | { type: 'answered' }\n  | { type: 'reviewOpened' }\n  | { type: 'reviewClosed' }\n  | { type: 'sampleRan' }\n  | { type: 'publish' }\n  | { type: 'publishSettled' };\n\ntype Step = SessionStep<BuilderState, BuilderAction>;\n\nconst QUEUED: SampleStatus[] = SAMPLES.map(() => 'queued');\n\nfunction indexedOf(file: KnowledgeFile): LiveFile {\n  return { ...file, progress: 100 };\n}\n\nexport const INITIAL: BuilderState = {\n  live: LIVE_CONFIG,\n  liveVersion: LIVE_VERSION,\n  name: LIVE_CONFIG.name,\n  view: 'configure',\n  modelId: LIVE_CONFIG.modelId,\n  instructions: LIVE_CONFIG.instructions,\n  tools: LIVE_CONFIG.tools,\n  files: FIRST_FILES.map(indexedOf),\n  draft: '',\n  turns: [],\n  isAnswering: false,\n  isReviewOpen: false,\n  samples: QUEUED,\n  publish: 'idle',\n  attempts: 0,\n};\n\nexport function isIndexed(file: LiveFile) {\n  return file.progress >= 100;\n}\n\nexport function nextSampleFileOf(state: BuilderState) {\n  return SAMPLE_FILES.find((sample) => {\n    const isAdded = state.files.some((file) => file.id === sample.id);\n    return !isAdded;\n  });\n}\n\nfunction onOffOf(isOn: boolean) {\n  if (isOn) {\n    return 'on';\n  }\n  return 'off';\n}\n\nfunction filesWordOf(count: number) {\n  if (count === 1) {\n    return '1 file';\n  }\n  return `${count} files`;\n}\n\nfunction instructionChangeOf(before: string, after: string) {\n  const difference = after.length - before.length;\n  if (difference > 0) {\n    return `Instructions: ${difference} characters added`;\n  }\n  if (difference < 0) {\n    return `Instructions: ${Math.abs(difference)} characters removed`;\n  }\n  return 'Instructions: reworded';\n}\n\nfunction fileChangesOf(before: string[], files: LiveFile[]) {\n  const after = files.map((file) => file.id);\n  const added = after.filter((id) => !before.includes(id));\n  const removed = before.filter((id) => !after.includes(id));\n  const changes: string[] = [];\n  if (added.length > 0) {\n    changes.push(`Knowledge: ${filesWordOf(added.length)} added`);\n  }\n  if (removed.length > 0) {\n    changes.push(`Knowledge: ${filesWordOf(removed.length)} removed`);\n  }\n  return changes;\n}\n\n/** What the draft changes against the live version, one short line per change. */\nexport function changesOf(state: BuilderState) {\n  const live = state.live;\n  const changes: string[] = [];\n  if (state.name.trim() !== live.name) {\n    changes.push(`Name: ${state.name.trim()}`);\n  }\n  if (state.modelId !== live.modelId) {\n    const before = modelOf(live.modelId).name;\n    const after = modelOf(state.modelId).name;\n    changes.push(`Model: ${before} to ${after}`);\n  }\n  if (state.instructions !== live.instructions) {\n    changes.push(instructionChangeOf(live.instructions, state.instructions));\n  }\n  for (const tool of TOOLS) {\n    const isOn = state.tools[tool.id];\n    if (isOn !== live.tools[tool.id]) {\n      changes.push(`${tool.name}: switched ${onOffOf(isOn)}`);\n    }\n  }\n  const fileChanges = fileChangesOf(live.fileIds, state.files);\n  return [...changes, ...fileChanges];\n}\n\n/** A sample passes when the agent has the tool the prompt needs. */\nfunction resultOf(\n  sample: Sample,\n  tools: Record<ToolId, boolean>\n): SampleStatus {\n  const hasTool = sample.needs === undefined || tools[sample.needs];\n  if (hasTool) {\n    return 'pass';\n  }\n  return 'fail';\n}\n\nexport function haveSamplesRun(state: BuilderState) {\n  return state.samples.every((status) => {\n    const hasPassed = status === 'pass';\n    const hasFailed = status === 'fail';\n    return hasPassed || hasFailed;\n  });\n}\n\nexport function failedSampleCountOf(state: BuilderState) {\n  const failed = state.samples.filter((status) => status === 'fail');\n  return failed.length;\n}\n\n/** One tick of the sample run: the running sample gets its result and the next one starts. */\nfunction sampleRan(state: BuilderState): BuilderState {\n  if (!state.isReviewOpen) {\n    return state;\n  }\n  const running = state.samples.indexOf('running');\n  const samples = [...state.samples];\n  if (running !== -1) {\n    samples[running] = resultOf(SAMPLES[running], state.tools);\n  }\n  const next = samples.indexOf('queued');\n  if (next !== -1) {\n    samples[next] = 'running';\n  }\n  return { ...state, samples };\n}\n\nfunction replyOf(tools: Record<ToolId, boolean>): Omit<ChatTurn, 'id'> {\n  if (!tools.orders) {\n    return { role: 'agent', text: REPLY_WITHOUT_ORDERS };\n  }\n  if (!tools.refunds) {\n    return {\n      role: 'agent',\n      text: REPLY_WITHOUT_REFUND,\n      tool: 'Looked up order SB-20418',\n    };\n  }\n  return {\n    role: 'agent',\n    text: REPLY_WITH_REFUND,\n    tool: 'Looked up order SB-20418, refunded $18.90',\n  };\n}\n\nfunction chatSent(state: BuilderState): BuilderState {\n  const text = state.draft.trim();\n  const canSend = text !== '' && !state.isAnswering;\n  if (!canSend) {\n    return state;\n  }\n  const turn: ChatTurn = { id: state.turns.length, role: 'person', text };\n  return {\n    ...state,\n    draft: '',\n    turns: [...state.turns, turn],\n    isAnswering: true,\n  };\n}\n\nfunction answered(state: BuilderState): BuilderState {\n  if (!state.isAnswering) {\n    return state;\n  }\n  const reply = replyOf(state.tools);\n  const turn: ChatTurn = { id: state.turns.length, ...reply };\n  return { ...state, turns: [...state.turns, turn], isAnswering: false };\n}\n\nfunction fileAdded(state: BuilderState): BuilderState {\n  const sample = nextSampleFileOf(state);\n  if (!sample) {\n    return state;\n  }\n  return { ...state, files: [...state.files, { ...sample, progress: 0 }] };\n}\n\nfunction fileProgress(\n  state: BuilderState,\n  id: string,\n  progress: number\n): BuilderState {\n  const files = state.files.map((file) => {\n    const isAhead = file.id === id && progress > file.progress;\n    if (isAhead) {\n      return { ...file, progress };\n    }\n    return file;\n  });\n  return { ...state, files };\n}\n\nexport function canPublish(state: BuilderState) {\n  const hasChanges = changesOf(state).length > 0;\n  const isReady = state.isReviewOpen && haveSamplesRun(state);\n  return hasChanges && isReady;\n}\n\nfunction publish(state: BuilderState): BuilderState {\n  const canStart = state.publish === 'idle' || state.publish === 'failed';\n  if (!canStart || !canPublish(state)) {\n    return state;\n  }\n  return { ...state, publish: 'pending', attempts: state.attempts + 1 };\n}\n\nfunction liveConfigOf(state: BuilderState): AgentConfig {\n  return {\n    name: state.name.trim(),\n    modelId: state.modelId,\n    instructions: state.instructions,\n    tools: state.tools,\n    fileIds: state.files.map((file) => file.id),\n  };\n}\n\n/** The first attempt of a session fails, so the retry can be seen; the next one goes through. */\nfunction publishSettled(state: BuilderState): BuilderState {\n  if (state.publish !== 'pending') {\n    return state;\n  }\n  if (state.attempts === 1) {\n    return { ...state, publish: 'failed' };\n  }\n  return {\n    ...state,\n    publish: 'done',\n    live: liveConfigOf(state),\n    liveVersion: state.liveVersion + 1,\n  };\n}\n\nfunction reviewOpened(state: BuilderState): BuilderState {\n  const isBusy = state.publish === 'pending';\n  if (state.isReviewOpen || isBusy) {\n    return state;\n  }\n  return { ...state, isReviewOpen: true, samples: QUEUED, publish: 'idle' };\n}\n\nfunction reviewClosed(state: BuilderState): BuilderState {\n  if (state.publish === 'pending') {\n    return state;\n  }\n  return { ...state, isReviewOpen: false };\n}\n\nexport function reducer(\n  state: BuilderState,\n  action: BuilderAction\n): BuilderState {\n  switch (action.type) {\n    case 'named':\n      return { ...state, name: action.text };\n    case 'view':\n      return { ...state, view: action.view };\n    case 'model':\n      return { ...state, modelId: action.id };\n    case 'instructed':\n      return {\n        ...state,\n        instructions: action.text.slice(0, INSTRUCTIONS_LIMIT),\n      };\n    case 'toolSet':\n      return { ...state, tools: { ...state.tools, [action.id]: action.isOn } };\n    case 'fileAdded':\n      return fileAdded(state);\n    case 'fileProgress':\n      return fileProgress(state, action.id, action.progress);\n    case 'fileRemoved':\n      return {\n        ...state,\n        files: state.files.filter((file) => file.id !== action.id),\n      };\n    case 'chatTyped':\n      return { ...state, draft: action.text };\n    case 'chatSent':\n      return chatSent(state);\n    case 'answered':\n      return answered(state);\n    case 'reviewOpened':\n      return reviewOpened(state);\n    case 'reviewClosed':\n      return reviewClosed(state);\n    case 'sampleRan':\n      return sampleRan(state);\n    case 'publish':\n      return publish(state);\n    case 'publishSettled':\n      return publishSettled(state);\n  }\n}\n\nconst CHUNK = 4;\n\nfunction delayOfChunk(index: number, startAfter: number) {\n  if (index === 0) {\n    return startAfter;\n  }\n  return 60;\n}\n\nfunction typingSteps(\n  from: string,\n  to: string,\n  startAfter: number,\n  write: (text: string) => BuilderAction\n): Step[] {\n  const steps: Step[] = [];\n  const last = to.length + CHUNK;\n  for (let end = from.length + CHUNK; end < last; end += CHUNK) {\n    const text = to.slice(0, end);\n    const after = delayOfChunk(steps.length, startAfter);\n    steps.push({ after, by: 'demo', action: write(text) });\n  }\n  return steps;\n}\n\nfunction instructed(text: string): BuilderAction {\n  return { type: 'instructed', text };\n}\n\nfunction chatTyped(text: string): BuilderAction {\n  return { type: 'chatTyped', text };\n}\n\nconst DEMO_FILE = SAMPLE_FILES[0];\n\n/** The steps an upload goes through, in percent. */\nexport const UPLOAD_STEPS = [35, 80, 100];\n\nexport const UPLOAD_STEP_MS = 600;\n\nconst UPLOAD: Step[] = UPLOAD_STEPS.map((progress) => ({\n  after: UPLOAD_STEP_MS,\n  action: { type: 'fileProgress', id: DEMO_FILE.id, progress },\n}));\n\nexport const SAMPLE_MS = 800;\n\n/** One tick starts the first sample, then one tick per result. */\nexport const SAMPLE_TICKS = SAMPLES.length + 1;\n\nconst SAMPLE_RUN: Step[] = Array.from({ length: SAMPLE_TICKS }, () => ({\n  after: SAMPLE_MS,\n  action: { type: 'sampleRan' },\n}));\n\nexport const ANSWER_MS = 1100;\n\nexport const PUBLISH_MS = 1500;\n\nfunction isReviewing(state: BuilderState) {\n  return state.isReviewOpen;\n}\n\nfunction hasPublishedOnce(state: BuilderState) {\n  return state.attempts >= 1;\n}\n\nfunction hasRetried(state: BuilderState) {\n  return state.attempts >= 2;\n}\n\n/** A request that waits on a person is answered by the demonstration after this long. */\nconst DECIDE_AFTER_MS = 2500;\n\nconst EDITING: Step[] = [\n  ...typingSteps(LIVE_CONFIG.instructions, DEMO_INSTRUCTIONS, 1200, instructed),\n  {\n    after: 900,\n    by: 'demo',\n    action: { type: 'toolSet', id: 'refunds', isOn: true },\n  },\n  { after: 900, by: 'demo', action: { type: 'model', id: 'claude-sonnet' } },\n  { after: 1000, by: 'demo', press: 'add-file', action: { type: 'fileAdded' } },\n  ...UPLOAD,\n];\n\nexport const SCRIPT: Step[] = [\n  ...EDITING,\n  { after: 1200, by: 'demo', action: { type: 'view', view: 'test' } },\n  ...typingSteps('', DEMO_QUESTION, 800, chatTyped),\n  { after: 500, by: 'demo', press: 'send', action: { type: 'chatSent' } },\n  { after: ANSWER_MS, action: { type: 'answered' } },\n  {\n    after: 3600,\n    by: 'person',\n    press: 'review',\n    action: { type: 'reviewOpened' },\n    isAnswered: isReviewing,\n  },\n  ...SAMPLE_RUN,\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: 'publish',\n    action: { type: 'publish' },\n    isAnswered: hasPublishedOnce,\n  },\n  { after: PUBLISH_MS, action: { type: 'publishSettled' } },\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: 'publish',\n    action: { type: 'publish' },\n    isAnswered: hasRetried,\n  },\n  { after: PUBLISH_MS, action: { type: 'publishSettled' } },\n];\n\n/** Under reduced motion the draft is edited and the review is open, its samples run, ready to publish. */\nfunction restingOf() {\n  let state = INITIAL;\n  for (const step of EDITING) {\n    state = reducer(state, step.action);\n  }\n  state = reducer(state, { type: 'reviewOpened' });\n  for (const step of SAMPLE_RUN) {\n    state = reducer(state, step.action);\n  }\n  return state;\n}\n\nexport const RESTING = restingOf();\n\nexport const LOOP_AFTER_MS = 4200;\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-07/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-07/data.ts",
      "content": "import type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\n\nexport const INSTRUCTIONS_LIMIT = 600;\n\nexport type ModelId =\n  'claude-haiku' | 'claude-sonnet' | 'gpt-mini' | 'gemini-pro';\n\nexport type Model = {\n  id: ModelId;\n  name: string;\n  brand: BrandSlug;\n  /** A coarse word for the demo, not a fact about the model. */\n  hint: string;\n};\n\n/** Families without a version number. */\nexport const MODELS: Model[] = [\n  {\n    id: 'claude-haiku',\n    name: 'Claude Haiku',\n    brand: 'claude',\n    hint: 'Quick replies',\n  },\n  {\n    id: 'claude-sonnet',\n    name: 'Claude Sonnet',\n    brand: 'claude',\n    hint: 'Everyday work',\n  },\n  { id: 'gpt-mini', name: 'GPT mini', brand: 'openai', hint: 'Bulk tasks' },\n  {\n    id: 'gemini-pro',\n    name: 'Gemini Pro',\n    brand: 'gemini',\n    hint: 'Long documents',\n  },\n];\n\nexport function modelOf(id: ModelId) {\n  const model = MODELS.find((candidate) => candidate.id === id);\n  return model ?? MODELS[0];\n}\n\nexport type ToolId = 'orders' | 'email' | 'refunds' | 'drive';\n\nexport type AgentTool = {\n  id: ToolId;\n  name: string;\n  /** What switching it on lets the agent do. */\n  allows: string;\n  brand?: BrandSlug;\n};\n\nexport const TOOLS: AgentTool[] = [\n  {\n    id: 'orders',\n    name: 'Look up orders',\n    allows: 'Reads an order, its items and where the parcel is',\n  },\n  {\n    id: 'email',\n    name: 'Send email',\n    allows: 'Sends as support@solwaybooks.example, after you approve',\n    brand: 'gmail',\n  },\n  {\n    id: 'refunds',\n    name: 'Refund a payment',\n    allows: 'Refunds up to $50 on its own and asks you above that',\n    brand: 'stripe',\n  },\n  {\n    id: 'drive',\n    name: 'Read shared files',\n    allows: 'Reads the Support folder, never writes to it',\n    brand: 'googledrive',\n  },\n];\n\nexport type KnowledgeFile = {\n  id: string;\n  name: string;\n  size: string;\n};\n\nexport const FIRST_FILES: KnowledgeFile[] = [\n  { id: 'returns', name: 'Returns policy.pdf', size: '184 KB' },\n  { id: 'shipping', name: 'Shipping times.md', size: '12 KB' },\n];\n\n/** The sample files Add a file brings in, in order. Nothing leaves the page. */\nexport const SAMPLE_FILES: KnowledgeFile[] = [\n  { id: 'gift-cards', name: 'Gift cards FAQ.pdf', size: '96 KB' },\n  { id: 'price-list', name: 'Price list autumn.csv', size: '41 KB' },\n];\n\nexport type AgentConfig = {\n  name: string;\n  modelId: ModelId;\n  instructions: string;\n  tools: Record<ToolId, boolean>;\n  fileIds: string[];\n};\n\nexport const LIVE_VERSION = 3;\n\nconst LIVE_INSTRUCTIONS =\n  'You answer customers of Solway Books. Be brief and kind. Look the order up before you answer a question about it.';\n\n/** What version 3 runs with today. */\nexport const LIVE_CONFIG: AgentConfig = {\n  name: 'Refunds helper',\n  modelId: 'claude-haiku',\n  instructions: LIVE_INSTRUCTIONS,\n  tools: { orders: true, email: true, refunds: false, drive: false },\n  fileIds: ['returns', 'shipping'],\n};\n\n/** The sentence the demonstration adds to the instructions. */\nexport const DEMO_SENTENCE =\n  ' Refund a damaged item at once when the order is under $50.';\n\nexport const DEMO_INSTRUCTIONS = `${LIVE_INSTRUCTIONS}${DEMO_SENTENCE}`;\n\nexport const DEMO_QUESTION =\n  'My copy of The Salt Road arrived torn. Can I get my money back?';\n\nexport const REPLY_WITH_REFUND =\n  'I am sorry about the torn copy. I found order SB-20418 and refunded the $18.90. It reaches your card in 5 to 7 business days.';\n\nexport const REPLY_WITHOUT_REFUND =\n  'I am sorry about the torn copy. I found order SB-20418, but I cannot refund it myself. I have passed it to the team.';\n\nexport const REPLY_WITHOUT_ORDERS =\n  'I am sorry about the torn copy. Could you send me the order number, so the team can look it up?';\n\nexport type Sample = {\n  id: string;\n  prompt: string;\n  /** The tool the agent needs to pass this sample. */\n  needs?: ToolId;\n  failure: string;\n};\n\nexport const SAMPLES: Sample[] = [\n  {\n    id: 'where',\n    prompt: 'Where is my order?',\n    needs: 'orders',\n    failure: 'The agent cannot look the order up',\n  },\n  {\n    id: 'torn',\n    prompt: 'My book arrived torn, I want a refund',\n    needs: 'refunds',\n    failure: 'The agent has no way to refund',\n  },\n  {\n    id: 'tone',\n    prompt: 'This is the worst shop I have ever used',\n    failure: 'The reply was not calm',\n  },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-07/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "agent-ops"
  ],
  "type": "registry:block"
}