{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "application-10",
  "title": "Research agent",
  "description": "A Corvale research agent: a question starts a live timeline of thinking, searching and reading in the thread while the memo writes itself section by section in the panel beside it, a sheet on phones, then the answer cites numbered sources that light up and a request to share waits for Allow or Deny. Plug your agent into onSend, onApprove and onDeny.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/avatar.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/call-status.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/drawn-check.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/inline-sheet.json",
    "https://ui.ndekocode.dev/r/kbd.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/mesh-tile.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/run-session.json",
    "https://ui.ndekocode.dev/r/spinner.json",
    "https://ui.ndekocode.dev/r/streamed-text.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-follow-bottom.json",
    "https://ui.ndekocode.dev/r/use-is-narrow.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/index.tsx",
      "content": "'use client';\n\nimport { useIsNarrow } from '@/registry/ndeko/hooks/use-is-narrow';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { InlineSheet } from '@/registry/ndeko/ui/inline-sheet';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { AppHeader } from './app-header';\nimport { Composer } from './composer';\nimport { KEPT_LINE, RECEIVERS, seedOf, SHARED_LINE } from './data';\nimport { MemoPanel } from './memo-panel';\nimport {\n  INITIAL,\n  isOver,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  sendableTextOf,\n  SHARE_MS,\n  type Decision,\n  type ResearchState,\n  type Stage,\n} from './session';\nimport { peopleOf } from './share-request';\nimport { Thread } from './thread';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\n/** The width of the `@3xl` container variant: under it the memo lives in a sheet. */\nconst SHEET_BELOW_REM = 48;\n\nfunction placeholderOf(stage: Stage) {\n  if (stage === 'idle') {\n    return 'Ask a question about your workspace';\n  }\n  if (stage === 'asking') {\n    return 'Allow or deny the request above';\n  }\n  if (isOver(stage)) {\n    return 'Ask a follow-up';\n  }\n  return 'Researcher is working';\n}\n\nfunction announcementOf(stage: Stage) {\n  if (stage === 'researching') {\n    return 'Researcher is reading the workspace';\n  }\n  if (stage === 'answered') {\n    return 'The answer and the memo are ready';\n  }\n  if (stage === 'asking') {\n    const people = peopleOf(RECEIVERS.length);\n    return `Researcher asks to share the memo with ${people}. Allow or deny it`;\n  }\n  if (stage === 'shared') {\n    return SHARED_LINE;\n  }\n  if (stage === 'kept') {\n    return KEPT_LINE;\n  }\n  return '';\n}\n\nfunction stepInProgressOf(state: ResearchState) {\n  const running = state.activity.find((run) => run.status === 'running');\n  if (!running) {\n    return null;\n  }\n  const seed = seedOf(running.id);\n  return seed.title;\n}\n\n/** Nothing calls a network. A real agent plugs in here: what a person sends, and their answer to the request to share. */\nexport type Application10Props = {\n  onSend?: (text: string) => void;\n  onApprove?: () => void;\n  onDeny?: () => void;\n};\n\nexport default function Application10({\n  onSend,\n  onApprove,\n  onDeny,\n}: Application10Props) {\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 isNarrow = useIsNarrow(ref, SHEET_BELOW_REM);\n  const { stage } = state;\n  const sendableText = sendableTextOf(state);\n  const canSend = sendableText !== null;\n  const canReplay = isFinished && !isAutoplaying;\n  const isSheetShown = isNarrow && state.isSheetOpen;\n  const isMemoBeingWritten = state.sectionsStarted > state.sectionsDone;\n  const announcement = announcementOf(stage);\n  const message = spokenUnless(isAutoplaying, announcement);\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const target = ref.current?.querySelector<HTMLElement>(selector);\n      target?.focus();\n    });\n  }\n\n  function send() {\n    if (sendableText === null) {\n      return;\n    }\n    act({ type: 'sent' });\n    onSend?.(sendableText);\n  }\n\n  /** The two buttons leave with the request, so the focus goes to what replaces them: the line that says what was decided. */\n  function decide(decision: Decision) {\n    act({ type: 'decided', decision });\n    focusLater('[data-request]');\n    if (decision === 'denied') {\n      onDeny?.();\n      return;\n    }\n    schedule(() => act({ type: 'shared' }), SHARE_MS);\n    onApprove?.();\n  }\n\n  function openSheet() {\n    act({ type: 'sheet', isOpen: true });\n    focusLater('[data-sheet-close=\"memo\"]');\n  }\n\n  function closeSheet() {\n    act({ type: 'sheet', isOpen: false });\n    focusLater('[data-memo-open]');\n  }\n\n  const memo = {\n    stage,\n    sectionsStarted: state.sectionsStarted,\n    sectionsDone: state.sectionsDone,\n    foldedSections: state.foldedSections,\n    pressed,\n    isActive: isInView,\n    onToggleSection: (id: string) => act({ type: 'sectionToggled', id }),\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='relative flex h-dvh min-h-[40rem] flex-col overflow-hidden'>\n          <div inert={isSheetShown} className='flex min-h-0 flex-1 flex-col'>\n            <AppHeader\n              stage={stage}\n              costUsd={state.costUsd}\n              isMemoBeingWritten={isMemoBeingWritten}\n              canReplay={canReplay}\n              onReplay={restart}\n              onOpenMemo={openSheet}\n            />\n            <div className='flex min-h-0 flex-1'>\n              <main className='flex min-w-0 flex-1 flex-col'>\n                <Thread\n                  state={state}\n                  pressed={pressed}\n                  isActive={isInView}\n                  onDecide={decide}\n                />\n                <div className='mx-auto w-full max-w-2xl shrink-0 px-4 pb-4'>\n                  <Composer\n                    draft={state.draft}\n                    placeholder={placeholderOf(stage)}\n                    canSend={canSend}\n                    isSendPressed={pressed === 'send'}\n                    onDraftChange={(text) => act({ type: 'typed', text })}\n                    onSend={send}\n                  />\n                </div>\n              </main>\n              <aside\n                aria-label='Memo'\n                className='hidden w-[22rem] shrink-0 pe-3 pb-3 @3xl:flex @4xl:w-[26rem]'\n              >\n                <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] flex min-h-0 flex-1 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n                  {!isNarrow && (\n                    <MemoPanel\n                      {...memo}\n                      stepInProgress={null}\n                      className='w-full'\n                    />\n                  )}\n                </div>\n              </aside>\n            </div>\n          </div>\n\n          <InlineSheet\n            name='memo'\n            label='Memo'\n            closeLabel='Close the memo'\n            side='bottom'\n            closer='grip'\n            isOpen={isSheetShown}\n            className='@3xl:hidden'\n            panelClassName='h-[80%] px-4 pb-4'\n            onClose={closeSheet}\n          >\n            {/* The thread is out of sight under the sheet, so the sheet says which step is running. */}\n            {isNarrow && (\n              <MemoPanel\n                {...memo}\n                stepInProgress={stepInProgressOf(state)}\n                className='flex-1'\n              />\n            )}\n          </InlineSheet>\n          <LiveRegion message={message} />\n        </div>\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-10/index.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/app-header.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\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 { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { MODEL, WORKSPACE } from './data';\nimport type { Stage } from './session';\n\nconst STATUS_WORD: Record<Stage, string> = {\n  idle: 'Ready',\n  researching: 'Researching',\n  answering: 'Answering',\n  answered: 'Answered',\n  asking: 'Waiting on you',\n  sharing: 'Sharing',\n  shared: 'Done',\n  kept: 'Done',\n};\n\nconst STATUS_WORDS = Object.values(STATUS_WORD);\n\nconst STATUS_DOT: Record<Stage, string> = {\n  idle: 'bg-muted-foreground/45',\n  researching: 'bg-info',\n  answering: 'bg-info',\n  answered: 'bg-info',\n  asking: 'bg-warning',\n  sharing: 'bg-info',\n  shared: 'bg-success',\n  kept: 'bg-success',\n};\n\nconst LIVE_STAGES: Stage[] = ['researching', 'answering', 'sharing'];\n\n/** Under a dollar a cost keeps three decimals, as in the rest of the kit. */\nconst COST_FORMAT: Intl.NumberFormatOptions = {\n  style: 'currency',\n  currency: 'USD',\n  minimumFractionDigits: 3,\n  maximumFractionDigits: 3,\n};\n\nfunction pulseOf(stage: Stage) {\n  if (LIVE_STAGES.includes(stage)) {\n    return 'animate-pulse';\n  }\n  return undefined;\n}\n\ntype AppHeaderProps = {\n  stage: Stage;\n  costUsd: number;\n  isMemoBeingWritten: boolean;\n  canReplay: boolean;\n  onReplay: () => void;\n  onOpenMemo: () => void;\n};\n\nexport function AppHeader({\n  stage,\n  costUsd,\n  isMemoBeingWritten,\n  canReplay,\n  onReplay,\n  onOpenMemo,\n}: AppHeaderProps) {\n  return (\n    <header className='flex shrink-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-2.5'>\n      <div className='flex min-w-40 flex-1 items-center gap-2.5'>\n        <CompanyMark seed={WORKSPACE.name} size='lg' />\n        <div className='flex min-w-0 flex-col leading-tight'>\n          <h1 className='truncate text-sm font-medium'>\n            {WORKSPACE.name}\n            <span className='text-muted-foreground font-normal'>\n              {' '}\n              / {WORKSPACE.space}\n            </span>\n          </h1>\n          <p className='text-muted-foreground flex items-center gap-1.5 text-xs'>\n            <span\n              aria-hidden='true'\n              className={cn(\n                'size-1.5 shrink-0 rounded-full transition-colors duration-200',\n                STATUS_DOT[stage],\n                pulseOf(stage)\n              )}\n            />\n            <WordRoll text={STATUS_WORD[stage]} labels={STATUS_WORDS} />\n          </p>\n        </div>\n      </div>\n      <div className='flex flex-wrap items-center gap-2'>\n        <ReplayButton isShown={canReplay} onReplay={onReplay} label='Replay' />\n        <span className='flex items-center gap-1.5 text-xs'>\n          <BrandTile brand={MODEL.brand} />\n          <span className='sr-only @sm:not-sr-only'>{MODEL.name}</span>\n        </span>\n        <span className='flex items-center gap-1.5 text-xs'>\n          <span className='sr-only'>Cost of this run</span>\n          <MotionNumber\n            value={costUsd}\n            format={COST_FORMAT}\n            className='font-medium'\n          />\n          <Badge variant='secondary'>Illustrative</Badge>\n        </span>\n        <Button\n          type='button'\n          variant='outline'\n          size='sm'\n          data-memo-open\n          aria-haspopup='dialog'\n          onClick={onOpenMemo}\n          className='@3xl:hidden'\n        >\n          {isMemoBeingWritten && (\n            <span\n              aria-hidden='true'\n              className='bg-info size-1.5 rounded-full'\n            />\n          )}\n          Memo\n        </Button>\n      </div>\n    </header>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-10/app-header.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/thread.tsx",
      "content": "'use client';\n\nimport { useFollowBottom } from '@/registry/ndeko/hooks/use-follow-bottom';\nimport { seriesColorOf } from '@/registry/ndeko/lib/agent-run';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\n\nimport { ActivityTimeline } from './activity-timeline';\nimport { CitedAnswer } from './cited-answer';\nimport { FOLLOW_UP_REPLY, RESEARCHER } from './data';\nimport { hasReached, type Decision, type ResearchState } from './session';\nimport { ShareRequest } from './share-request';\n\nfunction ResearcherTile() {\n  const color = seriesColorOf(RESEARCHER.series);\n\n  return <MeshTile seed={RESEARCHER.name} color={color} size='lg' />;\n}\n\nfunction PersonBubble({ text }: { text: string }) {\n  return (\n    <p className='bg-foreground/[0.06] max-w-[85%] self-end rounded-2xl rounded-ee-md px-3.5 py-2 text-sm leading-relaxed'>\n      {text}\n    </p>\n  );\n}\n\nfunction FollowUp({ text }: { text: string }) {\n  return (\n    <>\n      <PersonBubble text={text} />\n      <div className='flex items-start gap-2.5'>\n        <ResearcherTile />\n        <p className='text-muted-foreground min-w-0 flex-1 pt-1 text-sm leading-relaxed'>\n          {FOLLOW_UP_REPLY}\n        </p>\n      </div>\n    </>\n  );\n}\n\ntype ThreadProps = {\n  state: ResearchState;\n  pressed: string | null;\n  isActive: boolean;\n  onDecide: (decision: Decision) => void;\n};\n\nexport function Thread({ state, pressed, isActive, onDecide }: ThreadProps) {\n  const { scrollerRef, contentRef, updatePinned } = useFollowBottom();\n  const { stage, question } = state;\n  const hasQuestion = question !== null;\n  const showsAnswer = hasReached(stage, 'answering');\n  const showsRequest = hasReached(stage, 'asking');\n\n  return (\n    <div\n      ref={scrollerRef}\n      onScroll={updatePinned}\n      className='min-h-0 flex-1 overflow-y-auto'\n    >\n      <div\n        ref={contentRef}\n        className='mx-auto flex min-h-full w-full max-w-2xl flex-col gap-5 px-4 py-5'\n      >\n        {!hasQuestion && (\n          <p className='text-muted-foreground m-auto max-w-xs text-center text-[13px] leading-relaxed'>\n            Ask a question about the workspace. Each step shows here while the\n            memo is written in its panel.\n          </p>\n        )}\n        {question && <PersonBubble text={question} />}\n        {hasQuestion && (\n          <div className='flex items-start gap-2.5'>\n            <ResearcherTile />\n            <div className='flex min-w-0 flex-1 flex-col gap-3'>\n              <span className='sr-only'>{RESEARCHER.name}</span>\n              <ActivityTimeline\n                activity={state.activity}\n                isResearching={stage === 'researching'}\n                startedAt={state.startedAt}\n                endedAt={state.endedAt}\n              />\n              {showsAnswer && (\n                <CitedAnswer\n                  isStreaming={stage === 'answering'}\n                  isActive={isActive}\n                  demoLitSource={state.demoLitSource}\n                />\n              )}\n              {showsRequest && (\n                <ShareRequest\n                  stage={stage}\n                  pressed={pressed}\n                  onDecide={onDecide}\n                />\n              )}\n            </div>\n          </div>\n        )}\n        {state.followUps.map((text, index) => (\n          <FollowUp key={index} text={text} />\n        ))}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-10/thread.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/activity-timeline.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { elapsedOf, formatDuration } from '@/registry/ndeko/lib/agent-run';\nimport {\n  BrainIcon,\n  ChevronDownIcon,\n  CompassIcon,\n  FileTextIcon,\n  SearchIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { CallStatusMark } from '@/registry/ndeko/ui/call-status';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveDuration } from '@/registry/ndeko/ui/live-duration';\n\nimport { seedOf, type ActivityKind, type ActivitySeed } from './data';\nimport type { ActivityRun } from './session';\n\nconst KIND_WORD: Record<ActivityKind, string> = {\n  think: 'Think',\n  search: 'Search',\n  read: 'Read',\n};\n\nconst KIND_ICON: Record<ActivityKind, Icon> = {\n  think: BrainIcon,\n  search: SearchIcon,\n  read: FileTextIcon,\n};\n\nfunction KindTile({ seed }: { seed: ActivitySeed }) {\n  if (seed.brand) {\n    return <BrandTile brand={seed.brand} size='lg' title={seed.product} />;\n  }\n  const KindIcon = KIND_ICON[seed.kind];\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      <KindIcon className='size-3.5' />\n    </span>\n  );\n}\n\nfunction sublineOf(seed: ActivitySeed, run: ActivityRun) {\n  if (run.status === 'done') {\n    return seed.doneSummary;\n  }\n  return seed.detail;\n}\n\ntype ActivityRowProps = {\n  run: ActivityRun;\n  isLast: boolean;\n};\n\nfunction ActivityRow({ run, isLast }: ActivityRowProps) {\n  const seed = seedOf(run.id);\n  const isRunning = run.status === 'running';\n  const subline = sublineOf(seed, run);\n\n  return (\n    <li className='relative flex gap-2.5 pb-3 transition-[opacity,translate] duration-300 ease-(--ease-out-strong) last:pb-0 starting:translate-y-1 starting:opacity-0'>\n      {!isLast && (\n        <span\n          aria-hidden='true'\n          className='bg-border absolute start-3.5 top-8 bottom-1 w-px'\n        />\n      )}\n      <KindTile seed={seed} />\n      <div className='flex min-w-0 flex-1 flex-col'>\n        <p className='flex h-7 items-center gap-2 text-[13px]'>\n          <span className='min-w-0 truncate font-medium'>{seed.title}</span>\n          <CallStatusMark status={run.status} />\n          <LiveDuration\n            item={run}\n            isRunning={isRunning}\n            className='text-muted-foreground ms-auto w-10 shrink-0 text-end text-xs'\n          />\n        </p>\n        <p className='text-muted-foreground min-h-5 text-xs leading-5'>\n          <span className='text-foreground/70'>{KIND_WORD[seed.kind]}</span>\n          <span aria-hidden='true'> · </span>\n          <span\n            key={run.status}\n            className='transition-opacity duration-300 starting:opacity-0'\n          >\n            {subline}\n          </span>\n        </p>\n      </div>\n    </li>\n  );\n}\n\nfunction headlineOf(isResearching: boolean, duration: string) {\n  if (isResearching) {\n    return 'Researching';\n  }\n  return `Researched in ${duration}`;\n}\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\ntype ActivityTimelineProps = {\n  activity: ActivityRun[];\n  isResearching: boolean;\n  startedAt?: number;\n  endedAt?: number;\n};\n\n/** Open while the agent works, then folded into one line that says how long the research took. */\nexport function ActivityTimeline({\n  activity,\n  isResearching,\n  startedAt,\n  endedAt,\n}: ActivityTimelineProps) {\n  const [openChoice, setOpenChoice] = useState<boolean | null>(null);\n  const [wasResearching, setWasResearching] = useState(isResearching);\n  const panelId = useId();\n  const span = { startedAt, endedAt };\n  const elapsed = elapsedOf(span, endedAt ?? 0);\n  const duration = formatDuration(elapsed);\n  const headline = headlineOf(isResearching, duration);\n  const lastIndex = activity.length - 1;\n\n  if (wasResearching !== isResearching) {\n    setWasResearching(isResearching);\n    setOpenChoice(null);\n  }\n\n  const isOpen = openChoice ?? isResearching;\n\n  function toggle() {\n    setOpenChoice(!isOpen);\n  }\n\n  return (\n    <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] rounded-xl p-1.5'>\n      <button\n        type='button'\n        aria-expanded={isOpen}\n        aria-controls={panelId}\n        onClick={toggle}\n        className='hover:bg-foreground/[0.04] focus-visible:ring-ring/25 flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2 text-start text-[13px] outline-none focus-visible:ring-[3px]'\n      >\n        <CompassIcon className='text-muted-foreground size-4 shrink-0' />\n        <span className='min-w-0 truncate font-medium'>\n          <WordRoll text={headline} />\n        </span>\n        {isResearching && (\n          <LiveDuration\n            item={span}\n            isRunning\n            className='text-muted-foreground w-10 text-xs'\n          />\n        )}\n        <span className='text-muted-foreground ms-auto shrink-0 text-xs tabular-nums'>\n          {countOf(activity.length, 'step')}\n        </span>\n        <ChevronDownIcon\n          className={cn(\n            'text-muted-foreground size-3.5 shrink-0 transition-transform duration-200 ease-(--ease-out-strong)',\n            chevronTurnOf(isOpen)\n          )}\n        />\n      </button>\n      <Fold open={isOpen} id={panelId}>\n        <ol\n          aria-label='Research steps'\n          className='flex flex-col px-2 pt-2 pb-1.5'\n        >\n          {activity.map((run, index) => (\n            <ActivityRow key={run.id} run={run} isLast={index === lastIndex} />\n          ))}\n        </ol>\n      </Fold>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-10/activity-timeline.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/cited-answer.tsx",
      "content": "'use client';\n\nimport { Fragment, useState } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { leadingSpaceOf } from '@/registry/ndeko/lib/words';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport {\n  inkClassOf,\n  shownCountOf,\n  StreamCaret,\n  useRevealedCount,\n} from '@/registry/ndeko/ui/streamed-text';\n\nimport { ANSWER_TOKENS, SOURCES, type AnswerToken, type Source } from './data';\nimport { ANSWER_WORD_MS } from './session';\n\nconst FALLBACK_SOURCE = SOURCES[0];\n\nfunction sourceOf(number: number) {\n  const source = SOURCES.find((candidate) => candidate.number === number);\n  return source ?? FALLBACK_SOURCE;\n}\n\nfunction isCiteOf(token: AnswerToken, number: number) {\n  return token.kind === 'cite' && token.source === number;\n}\n\n/** A source shows under the answer once its first mark has streamed in. */\nfunction firstMarkOf(source: Source) {\n  return ANSWER_TOKENS.findIndex((token) => isCiteOf(token, source.number));\n}\n\nfunction litOverlayOf(isLit: boolean) {\n  if (isLit) {\n    return 'opacity-100';\n  }\n  return 'opacity-0';\n}\n\nfunction litTextOf(isLit: boolean) {\n  if (isLit) {\n    return 'text-primary-ink';\n  }\n  return 'text-muted-foreground';\n}\n\nfunction toggledPin(current: number | null, number: number) {\n  if (current === number) {\n    return null;\n  }\n  return number;\n}\n\ntype CitationMarkProps = {\n  source: Source;\n  isShown: boolean;\n  isStreaming: boolean;\n  isLit: boolean;\n  isPinned: boolean;\n  onHover: (number: number | null) => void;\n  onPin: (number: number) => void;\n};\n\nfunction CitationMark({\n  source,\n  isShown,\n  isStreaming,\n  isLit,\n  isPinned,\n  onHover,\n  onPin,\n}: CitationMarkProps) {\n  function light() {\n    onHover(source.number);\n  }\n\n  function dim() {\n    onHover(null);\n  }\n\n  function pin() {\n    onPin(source.number);\n  }\n\n  return (\n    <button\n      type='button'\n      aria-pressed={isPinned}\n      aria-label={`Source ${source.number}: ${source.title}, ${source.product}`}\n      onPointerEnter={light}\n      onPointerLeave={dim}\n      onFocus={light}\n      onBlur={dim}\n      onClick={pin}\n      className={cn(\n        'keycap-3d focus-visible:ring-ring/25 relative ms-1 inline-flex h-4 min-w-4 cursor-pointer items-center justify-center rounded-[4px] px-1 align-[0.12em] text-[10px] leading-none font-medium tabular-nums transition-colors duration-150 outline-none focus-visible:ring-[3px]',\n        litTextOf(isLit),\n        inkClassOf(isStreaming, isShown)\n      )}\n    >\n      <span\n        aria-hidden='true'\n        className={cn(\n          'bg-primary/15 pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-150',\n          litOverlayOf(isLit)\n        )}\n      />\n      <span className='relative'>{source.number}</span>\n    </button>\n  );\n}\n\ntype SourcePillProps = {\n  source: Source;\n  isShown: boolean;\n  isStreaming: boolean;\n  isLit: boolean;\n};\n\nfunction SourcePill({ source, isShown, isStreaming, isLit }: SourcePillProps) {\n  return (\n    <li\n      className={cn(\n        'bg-foreground/[0.05] relative flex h-7 max-w-full items-center gap-1.5 overflow-hidden rounded-full ps-1 pe-1.5 text-xs',\n        inkClassOf(isStreaming, isShown)\n      )}\n    >\n      <span\n        aria-hidden='true'\n        className={cn(\n          'bg-primary/12 pointer-events-none absolute inset-0 transition-opacity duration-150',\n          litOverlayOf(isLit)\n        )}\n      />\n      <BrandTile\n        brand={source.brand}\n        title={source.product}\n        className='relative rounded-full'\n      />\n      <span\n        className={cn(\n          'relative min-w-0 truncate transition-colors duration-150',\n          litTextOf(isLit)\n        )}\n      >\n        {source.title}\n      </span>\n      <span className='keycap-3d text-muted-foreground relative inline-flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full px-1 text-[10px] tabular-nums'>\n        {source.number}\n      </span>\n    </li>\n  );\n}\n\ntype CitedAnswerProps = {\n  isStreaming: boolean;\n  isActive: boolean;\n  demoLitSource: number | null;\n};\n\n/** Only the answer re-renders while it streams. */\nexport function CitedAnswer({\n  isStreaming,\n  isActive,\n  demoLitSource,\n}: CitedAnswerProps) {\n  const [hovered, setHovered] = useState<number | null>(null);\n  const [pinned, setPinned] = useState<number | null>(null);\n  const total = ANSWER_TOKENS.length;\n  const isRunning = isStreaming && isActive;\n  const count = useRevealedCount(total, isRunning, ANSWER_WORD_MS);\n  const shown = shownCountOf(isStreaming, count, total);\n  const lastShown = shown - 1;\n  const chosen = hovered ?? pinned;\n  const lit = chosen ?? demoLitSource;\n\n  function pin(number: number) {\n    setPinned((current) => toggledPin(current, number));\n  }\n\n  return (\n    <div className='flex flex-col gap-3'>\n      <p className='text-sm leading-relaxed'>\n        {ANSWER_TOKENS.map((token, index) => {\n          const isShown = index < shown;\n          if (token.kind === 'cite') {\n            return (\n              <CitationMark\n                key={index}\n                source={sourceOf(token.source)}\n                isShown={isShown}\n                isStreaming={isStreaming}\n                isLit={lit === token.source}\n                isPinned={pinned === token.source}\n                onHover={setHovered}\n                onPin={pin}\n              />\n            );\n          }\n          const hasCaret = isStreaming && index === lastShown;\n          return (\n            <Fragment key={index}>\n              {leadingSpaceOf(index)}\n              <span className={inkClassOf(isStreaming, isShown)}>\n                {token.text}\n                {hasCaret && <StreamCaret />}\n              </span>\n            </Fragment>\n          );\n        })}\n      </p>\n      <ul aria-label='Sources' className='flex flex-wrap gap-1.5'>\n        {SOURCES.map((source) => {\n          const firstMark = firstMarkOf(source);\n          return (\n            <SourcePill\n              key={source.number}\n              source={source}\n              isShown={firstMark < shown}\n              isStreaming={isStreaming}\n              isLit={lit === source.number}\n            />\n          );\n        })}\n      </ul>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-10/cited-answer.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/share-request.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId } from 'react';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { CircleXIcon, ShareIcon } from '@/registry/ndeko/lib/icons';\nimport { fadePresence } from '@/registry/ndeko/lib/motion-presets';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Kbd } from '@/registry/ndeko/ui/kbd';\nimport { Spinner } from '@/registry/ndeko/ui/spinner';\n\nimport {\n  KEPT_LINE,\n  MEMO_TITLE,\n  RECEIVERS,\n  SHARED_LINE,\n  type Person,\n} from './data';\nimport type { Decision, Stage } from './session';\n\nexport function peopleOf(count: number) {\n  if (count === 1) {\n    return '1 person';\n  }\n  return `${count} people`;\n}\n\nfunction Receiver({ person }: { person: Person }) {\n  return (\n    <li className='flex items-center gap-2.5'>\n      <Avatar className='size-6' seed={person.name} />\n      <span className='min-w-0 flex-1 truncate text-[13px] font-medium'>\n        {person.name}\n      </span>\n      <span className='text-muted-foreground shrink-0 text-xs'>\n        {person.role}\n      </span>\n    </li>\n  );\n}\n\ntype RequestBodyProps = {\n  pressed: string | null;\n  onDecide: (decision: Decision) => void;\n};\n\nfunction RequestBody({ pressed, onDecide }: RequestBodyProps) {\n  const titleId = useId();\n  const keysId = useId();\n  const people = peopleOf(RECEIVERS.length);\n\n  function allow() {\n    onDecide('approved');\n  }\n\n  function deny() {\n    onDecide('denied');\n  }\n\n  function decideFromKeys(event: React.KeyboardEvent<HTMLDivElement>) {\n    if (event.key === 'Escape') {\n      event.preventDefault();\n      deny();\n      return;\n    }\n    const isOnCard = event.target === event.currentTarget;\n    const isEnter = event.key === 'Enter';\n    if (isEnter && isOnCard) {\n      event.preventDefault();\n      allow();\n    }\n  }\n\n  return (\n    <div\n      role='group'\n      tabIndex={0}\n      aria-labelledby={titleId}\n      aria-describedby={keysId}\n      onKeyDown={decideFromKeys}\n      className='focus-visible:ring-ring/25 flex flex-col gap-3 rounded-xl p-3 outline-none focus-visible:ring-[3px] focus-visible:ring-inset'\n    >\n      <div className='flex items-center gap-2.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          <ShareIcon className='size-3.5' />\n        </span>\n        <div className='flex min-w-0 flex-1 flex-col leading-tight'>\n          <h2 id={titleId} className='text-sm font-medium'>\n            Share the memo with {people}\n          </h2>\n          <span className='text-muted-foreground truncate text-xs'>\n            {MEMO_TITLE}\n          </span>\n        </div>\n        <Badge variant='warning' className='hidden @md:inline-flex'>\n          Waiting on you\n        </Badge>\n      </div>\n      <ul\n        aria-label='Who will receive it'\n        className='bg-foreground/[0.04] flex flex-col gap-2 rounded-lg p-2.5'\n      >\n        {RECEIVERS.map((person) => (\n          <Receiver key={person.id} person={person} />\n        ))}\n      </ul>\n      <p className='text-muted-foreground text-xs leading-5'>\n        Each of them gets a link and can comment. Nothing is sent before you\n        allow it.\n      </p>\n      <div className='flex flex-wrap items-center gap-2'>\n        <Button\n          type='button'\n          size='sm'\n          onClick={allow}\n          className={pressedSolidOf(pressed === 'allow')}\n        >\n          Allow\n          <Kbd className='ms-0.5'>Enter</Kbd>\n        </Button>\n        <Button type='button' size='sm' variant='outline' onClick={deny}>\n          Deny\n          <Kbd className='ms-0.5'>Esc</Kbd>\n        </Button>\n        <span id={keysId} className='sr-only'>\n          Enter allows, Escape denies\n        </span>\n      </div>\n    </div>\n  );\n}\n\nfunction ResultGlyph({ stage }: { stage: Stage }) {\n  if (stage === 'sharing') {\n    return <Spinner aria-hidden='true' />;\n  }\n  if (stage === 'kept') {\n    return <CircleXIcon className='text-muted-foreground size-4 shrink-0' />;\n  }\n  return <DrawnCheck tone='success' entrance='draw' />;\n}\n\nfunction resultLineOf(stage: Stage) {\n  if (stage === 'sharing') {\n    return 'Sharing the memo';\n  }\n  if (stage === 'kept') {\n    return KEPT_LINE;\n  }\n  return SHARED_LINE;\n}\n\nfunction ResultLine({ stage }: { stage: Stage }) {\n  return (\n    <div className='flex min-h-11 items-start gap-2.5 p-3 text-[13px] leading-5'>\n      <Swap swapKey={stage} className='mt-px'>\n        <ResultGlyph stage={stage} />\n      </Swap>\n      <p\n        key={stage}\n        className='min-w-0 transition-opacity duration-300 starting:opacity-0'\n      >\n        {resultLineOf(stage)}\n      </p>\n    </div>\n  );\n}\n\nfunction viewKeyOf(isAsking: boolean) {\n  if (isAsking) {\n    return 'request';\n  }\n  return 'result';\n}\n\ntype ShareRequestProps = RequestBodyProps & {\n  stage: Stage;\n};\n\n/** The request resizes into one line that keeps a trace of what the person decided. */\nexport function ShareRequest({ stage, pressed, onDecide }: ShareRequestProps) {\n  const fade = fadePresence();\n  const isAsking = stage === 'asking';\n\n  return (\n    <section\n      data-request\n      tabIndex={-1}\n      aria-label='Request to share the memo'\n      className='bg-card hairline-ring ring-border dark:bg-foreground/[0.04] overflow-hidden rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-opacity duration-300 outline-none starting:opacity-0'\n    >\n      <AnimatedSize>\n        <AnimatePresence initial={false} mode='popLayout'>\n          <motion.div key={viewKeyOf(isAsking)} {...fade}>\n            {isAsking && <RequestBody pressed={pressed} onDecide={onDecide} />}\n            {!isAsking && <ResultLine stage={stage} />}\n          </motion.div>\n        </AnimatePresence>\n      </AnimatedSize>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-10/share-request.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/composer.tsx",
      "content": "'use client';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowUpIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nfunction isSendKey(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n  const isPlainEnter = event.key === 'Enter' && !event.shiftKey;\n  return isPlainEnter && !event.nativeEvent.isComposing;\n}\n\ntype ComposerProps = {\n  draft: string;\n  placeholder: string;\n  canSend: boolean;\n  isSendPressed: boolean;\n  onDraftChange: (text: string) => void;\n  onSend: () => void;\n};\n\nexport function Composer({\n  draft,\n  placeholder,\n  canSend,\n  isSendPressed,\n  onDraftChange,\n  onSend,\n}: ComposerProps) {\n  function handleKeys(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n    if (!isSendKey(event)) {\n      return;\n    }\n    event.preventDefault();\n    if (canSend) {\n      onSend();\n    }\n  }\n\n  return (\n    <div className='bg-card hairline-ring ring-foreground/12 has-[textarea:focus-visible]:ring-ring/25 dark:bg-foreground/[0.04] dark:ring-foreground/15 flex items-end gap-2 rounded-2xl p-2 shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-[box-shadow] duration-150 has-[textarea:focus-visible]:ring-[3px]'>\n      <textarea\n        value={draft}\n        rows={1}\n        aria-label='Question for the researcher'\n        placeholder={placeholder}\n        onChange={(event) => onDraftChange(event.target.value)}\n        onKeyDown={handleKeys}\n        className='placeholder:text-muted-foreground/75 field-sizing-content max-h-[6lh] min-h-8 flex-1 resize-none bg-transparent px-1.5 py-1.5 text-base leading-normal outline-none md:text-[13px]'\n      />\n      <Button\n        type='button'\n        size='icon'\n        aria-label='Send the question'\n        disabled={!canSend}\n        onClick={onSend}\n        className={pressedSolidOf(isSendPressed)}\n      >\n        <ArrowUpIcon />\n      </Button>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-10/composer.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/memo-panel.tsx",
      "content": "'use client';\n\nimport { useId } from 'react';\n\nimport { useFollowBottom } from '@/registry/ndeko/hooks/use-follow-bottom';\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { ChevronDownIcon, FileTextIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { Spinner } from '@/registry/ndeko/ui/spinner';\nimport { StreamedText } from '@/registry/ndeko/ui/streamed-text';\n\nimport {\n  MEMO,\n  MEMO_TITLE,\n  MEMO_WORDS,\n  RECEIVERS,\n  type MemoSection,\n} from './data';\nimport { WORD_MS, type Stage } from './session';\nimport { peopleOf } from './share-request';\n\ntype Progress = {\n  sectionsStarted: number;\n  sectionsDone: number;\n};\n\nfunction statusOf(stage: Stage, progress: Progress) {\n  const { sectionsStarted, sectionsDone } = progress;\n  if (sectionsStarted === 0) {\n    return 'Written while the agent reads';\n  }\n  const isWriting = sectionsStarted > sectionsDone;\n  if (isWriting) {\n    const writingIndex = sectionsStarted - 1;\n    const section = MEMO[writingIndex];\n    return `Writing ${section.heading}`;\n  }\n  const isComplete = sectionsDone === MEMO.length;\n  if (!isComplete) {\n    return 'Reading the next source';\n  }\n  if (stage === 'shared') {\n    const people = peopleOf(RECEIVERS.length);\n    return `Shared with ${people}`;\n  }\n  const words = countOf(MEMO_WORDS, 'word');\n  return `Draft ready, ${words}`;\n}\n\nfunction chevronTurnOf(isFolded: boolean) {\n  if (isFolded) {\n    return '-rotate-90';\n  }\n  return 'rotate-0';\n}\n\ntype SectionBlockProps = {\n  section: MemoSection;\n  isStreaming: boolean;\n  isFolded: boolean;\n  isPressed: boolean;\n  isActive: boolean;\n  onToggle: (id: string) => void;\n};\n\nfunction SectionBlock({\n  section,\n  isStreaming,\n  isFolded,\n  isPressed,\n  isActive,\n  onToggle,\n}: SectionBlockProps) {\n  const bodyId = useId();\n\n  function toggle() {\n    onToggle(section.id);\n  }\n\n  return (\n    <section className='flex flex-col transition-opacity duration-300 starting:opacity-0'>\n      <h3 className='flex'>\n        <button\n          type='button'\n          aria-expanded={!isFolded}\n          aria-controls={bodyId}\n          onClick={toggle}\n          className={cn(\n            'hover:bg-foreground/[0.04] focus-visible:ring-ring/25 -mx-1.5 flex h-8 flex-1 cursor-pointer items-center gap-1.5 rounded-md px-1.5 text-start text-[13px] font-medium transition-[background-color,scale] duration-150 outline-none focus-visible:ring-[3px] focus-visible:ring-inset',\n            pressedQuietOf(isPressed)\n          )}\n        >\n          <ChevronDownIcon\n            className={cn(\n              'text-muted-foreground size-3.5 shrink-0 transition-transform duration-200 ease-(--ease-out-strong)',\n              chevronTurnOf(isFolded)\n            )}\n          />\n          {section.heading}\n        </button>\n      </h3>\n      <Fold open={!isFolded} id={bodyId}>\n        <p className='text-foreground/85 ps-5 pb-2 text-[13px] leading-relaxed'>\n          <StreamedText\n            text={section.text}\n            isStreaming={isStreaming}\n            isActive={isActive}\n            wordMs={WORD_MS}\n          />\n        </p>\n      </Fold>\n    </section>\n  );\n}\n\nexport type MemoPanelProps = Progress & {\n  stage: Stage;\n  foldedSections: string[];\n  stepInProgress: string | null;\n  pressed: string | null;\n  isActive: boolean;\n  onToggleSection: (id: string) => void;\n  className?: string;\n};\n\nexport function MemoPanel({\n  stage,\n  sectionsStarted,\n  sectionsDone,\n  foldedSections,\n  stepInProgress,\n  pressed,\n  isActive,\n  onToggleSection,\n  className,\n}: MemoPanelProps) {\n  const { scrollerRef, contentRef, updatePinned } = useFollowBottom();\n  const status = statusOf(stage, { sectionsStarted, sectionsDone });\n  const sections = MEMO.slice(0, sectionsStarted);\n  const isEmpty = sectionsStarted === 0;\n\n  return (\n    <div className={cn('flex min-h-0 flex-col gap-3', className)}>\n      <header className='flex items-center gap-2.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-3.5' />\n        </span>\n        <div className='flex min-w-0 flex-1 flex-col leading-tight'>\n          <h2 className='truncate text-sm font-medium'>{MEMO_TITLE}</h2>\n          <Swap swapKey={status} className='text-muted-foreground text-xs'>\n            {status}\n          </Swap>\n        </div>\n      </header>\n\n      {stepInProgress && (\n        <p className='bg-foreground/[0.04] text-muted-foreground flex h-8 shrink-0 items-center gap-2 overflow-hidden rounded-lg px-2.5 text-xs'>\n          <Spinner aria-hidden='true' className='[&_svg]:size-3.5' />\n          <Swap swapKey={stepInProgress}>{stepInProgress}</Swap>\n        </p>\n      )}\n\n      <div\n        ref={scrollerRef}\n        onScroll={updatePinned}\n        className='-mx-1.5 min-h-0 flex-1 overflow-y-auto px-1.5'\n      >\n        <div ref={contentRef} className='flex flex-col gap-1'>\n          {isEmpty && (\n            <p className='text-muted-foreground text-[13px] leading-relaxed'>\n              Nothing written yet. Each section appears here as the agent reads\n              the source it comes from.\n            </p>\n          )}\n          {sections.map((section, index) => {\n            const pressKey = `section-${section.id}`;\n            return (\n              <SectionBlock\n                key={section.id}\n                section={section}\n                isStreaming={index >= sectionsDone}\n                isFolded={foldedSections.includes(section.id)}\n                isPressed={pressed === pressKey}\n                isActive={isActive}\n                onToggle={onToggleSection}\n              />\n            );\n          })}\n        </div>\n      </div>\n\n      <footer className='flex shrink-0 items-center gap-2'>\n        <Badge variant='secondary'>Illustrative figures</Badge>\n      </footer>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-10/memo-panel.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\nimport { restingOf } from '@/registry/ndeko/lib/run-session';\n\nimport {\n  ANSWER_TOKENS,\n  FOLDED_BY_DEMO,\n  QUESTION,\n  SECTION_WORDS,\n  seedOf,\n  type StepId,\n} from './data';\n\nexport type Stage =\n  | 'idle'\n  | 'researching'\n  | 'answering'\n  | 'answered'\n  | 'asking'\n  | 'sharing'\n  | 'shared'\n  | 'kept';\n\nexport type Decision = 'approved' | 'denied';\n\nexport type ActivityRun = {\n  id: StepId;\n  status: 'running' | 'done';\n  startedAt: number;\n  endedAt?: number;\n};\n\nexport type ResearchState = {\n  draft: string;\n  question: string | null;\n  followUps: string[];\n  stage: Stage;\n  activity: ActivityRun[];\n  sectionsStarted: number;\n  sectionsDone: number;\n  foldedSections: string[];\n  costUsd: number;\n  startedAt?: number;\n  endedAt?: number;\n  demoLitSource: number | null;\n  isSheetOpen: boolean;\n};\n\nexport type ResearchAction =\n  | { type: 'typed'; text: string }\n  | { type: 'sent' }\n  | { type: 'stepStarted'; id: StepId }\n  | { type: 'stepDone'; id: StepId }\n  | { type: 'sectionStarted' }\n  | { type: 'sectionDone' }\n  | { type: 'answering' }\n  | { type: 'answered' }\n  | { type: 'asked' }\n  | { type: 'decided'; decision: Decision }\n  | { type: 'shared' }\n  | { type: 'lit'; source: number | null }\n  | { type: 'sectionToggled'; id: string }\n  | { type: 'sheet'; isOpen: boolean }\n  | { type: 'batch'; actions: ResearchAction[] };\n\ntype Step = SessionStep<ResearchState, ResearchAction>;\n\nexport const INITIAL: ResearchState = {\n  draft: '',\n  question: null,\n  followUps: [],\n  stage: 'idle',\n  activity: [],\n  sectionsStarted: 0,\n  sectionsDone: 0,\n  foldedSections: [],\n  costUsd: 0,\n  demoLitSource: null,\n  isSheetOpen: false,\n};\n\nconst STAGE_ORDER: Stage[] = [\n  'idle',\n  'researching',\n  'answering',\n  'answered',\n  'asking',\n  'sharing',\n  'shared',\n  'kept',\n];\n\nexport function hasReached(stage: Stage, target: Stage) {\n  const position = STAGE_ORDER.indexOf(stage);\n  const targetPosition = STAGE_ORDER.indexOf(target);\n  return position >= targetPosition;\n}\n\nexport function isOver(stage: Stage) {\n  return stage === 'shared' || stage === 'kept';\n}\n\n/** A person who takes over while the question is being typed sends the whole question, not the half that was typed. */\nfunction questionOf(draft: string) {\n  const trimmed = draft.trim();\n  const isUnfinishedDemo = QUESTION.startsWith(trimmed);\n  if (isUnfinishedDemo) {\n    return QUESTION;\n  }\n  return trimmed;\n}\n\n/** What Send would post now: the first question, then follow-ups once the run is over. Null while the agent works. */\nexport function sendableTextOf(state: ResearchState) {\n  if (state.question === null) {\n    return questionOf(state.draft);\n  }\n  const text = state.draft.trim();\n  const canFollowUp = isOver(state.stage) && text !== '';\n  if (canFollowUp) {\n    return text;\n  }\n  return null;\n}\n\nfunction sent(state: ResearchState, now: number): ResearchState {\n  const text = sendableTextOf(state);\n  if (text === null) {\n    return state;\n  }\n  if (state.question === null) {\n    return {\n      ...state,\n      draft: '',\n      question: text,\n      stage: 'researching',\n      startedAt: now,\n    };\n  }\n  return { ...state, draft: '', followUps: [...state.followUps, text] };\n}\n\nfunction stepStarted(\n  state: ResearchState,\n  id: StepId,\n  now: number\n): ResearchState {\n  const isKnown = state.activity.some((run) => run.id === id);\n  if (isKnown) {\n    return state;\n  }\n  const run: ActivityRun = { id, status: 'running', startedAt: now };\n  return { ...state, activity: [...state.activity, run] };\n}\n\nfunction isRunningStep(run: ActivityRun, id: StepId) {\n  return run.id === id && run.status === 'running';\n}\n\nfunction stepDone(\n  state: ResearchState,\n  id: StepId,\n  now: number\n): ResearchState {\n  const wasRunning = state.activity.some((run) => isRunningStep(run, id));\n  if (!wasRunning) {\n    return state;\n  }\n  const activity = state.activity.map((run) => {\n    if (run.id !== id) {\n      return run;\n    }\n    const ended: ActivityRun = { ...run, status: 'done', endedAt: now };\n    return ended;\n  });\n  const seed = seedOf(id);\n  const costUsd = state.costUsd + seed.usd;\n  return { ...state, activity, costUsd };\n}\n\nfunction sectionStarted(state: ResearchState): ResearchState {\n  const isWriting = state.sectionsStarted > state.sectionsDone;\n  const isComplete = state.sectionsStarted >= SECTION_WORDS.length;\n  if (isWriting || isComplete) {\n    return state;\n  }\n  const sectionsStarted = state.sectionsStarted + 1;\n  return { ...state, sectionsStarted };\n}\n\nfunction answering(state: ResearchState, now: number): ResearchState {\n  if (state.stage !== 'researching') {\n    return state;\n  }\n  return { ...state, stage: 'answering', endedAt: now };\n}\n\nfunction staged(state: ResearchState, from: Stage, to: Stage): ResearchState {\n  if (state.stage !== from) {\n    return state;\n  }\n  return { ...state, stage: to };\n}\n\nfunction decided(state: ResearchState, decision: Decision): ResearchState {\n  if (decision === 'approved') {\n    return staged(state, 'asking', 'sharing');\n  }\n  return staged(state, 'asking', 'kept');\n}\n\nfunction sectionToggled(state: ResearchState, id: string): ResearchState {\n  const isFolded = state.foldedSections.includes(id);\n  if (isFolded) {\n    const foldedSections = state.foldedSections.filter(\n      (folded) => folded !== id\n    );\n    return { ...state, foldedSections };\n  }\n  return { ...state, foldedSections: [...state.foldedSections, id] };\n}\n\nexport function applyAt(\n  state: ResearchState,\n  action: ResearchAction,\n  now: number\n): ResearchState {\n  switch (action.type) {\n    case 'typed':\n      return { ...state, draft: action.text };\n    case 'sent':\n      return sent(state, now);\n    case 'stepStarted':\n      return stepStarted(state, action.id, now);\n    case 'stepDone':\n      return stepDone(state, action.id, now);\n    case 'sectionStarted':\n      return sectionStarted(state);\n    case 'sectionDone':\n      return { ...state, sectionsDone: state.sectionsStarted };\n    case 'answering':\n      return answering(state, now);\n    case 'answered':\n      return staged(state, 'answering', 'answered');\n    case 'asked':\n      return staged(state, 'answered', 'asking');\n    case 'decided':\n      return decided(state, action.decision);\n    case 'shared':\n      return staged(state, 'sharing', 'shared');\n    case 'lit':\n      return { ...state, demoLitSource: action.source };\n    case 'sectionToggled':\n      return sectionToggled(state, action.id);\n    case 'sheet':\n      return { ...state, isSheetOpen: action.isOpen };\n    case 'batch': {\n      let next = state;\n      for (const inner of action.actions) {\n        next = applyAt(next, inner, now);\n      }\n      return next;\n    }\n  }\n}\n\nexport function reducer(state: ResearchState, action: ResearchAction) {\n  return applyAt(state, action, Date.now());\n}\n\nfunction hasAsked(state: ResearchState) {\n  return state.question !== null;\n}\n\nfunction hasDecided(state: ResearchState) {\n  return hasReached(state.stage, 'sharing');\n}\n\nexport const WORD_MS = 55;\n\nexport const ANSWER_WORD_MS = 45;\n\n/** A stream is given a little longer than its words need, so its last word lands before the next step. */\nconst STREAM_MARGIN_MS = 200;\n\nconst KEY_MS = 40;\n\nconst DEMO_DECIDES_AFTER_MS = 2500;\n\nexport const SHARE_MS = 900;\n\nfunction sectionMsOf(index: number) {\n  const streamMs = SECTION_WORDS[index] * WORD_MS;\n  return streamMs + STREAM_MARGIN_MS;\n}\n\nconst ANSWER_STREAM_MS = ANSWER_TOKENS.length * ANSWER_WORD_MS;\n\nconst ANSWER_MS = ANSWER_STREAM_MS + STREAM_MARGIN_MS;\n\nfunction typingSteps(text: string, startAfter: number): Step[] {\n  const prefixes = prefixesOf(text);\n  return prefixes.map((typed, index) => ({\n    after: keyDelayOf(index, startAfter, KEY_MS),\n    by: 'demo',\n    action: { type: 'typed', text: typed },\n  }));\n}\n\nfunction frame(after: number, actions: ResearchAction[]): Step {\n  return { after, action: { type: 'batch', actions } };\n}\n\nfunction started(id: StepId): ResearchAction {\n  return { type: 'stepStarted', id };\n}\n\nfunction done(id: StepId): ResearchAction {\n  return { type: 'stepDone', id };\n}\n\nfunction lit(after: number, source: number | null): Step {\n  return { after, by: 'demo', action: { type: 'lit', source } };\n}\n\nconst SECTION_STARTED: ResearchAction = { type: 'sectionStarted' };\n\nconst SECTION_DONE: ResearchAction = { type: 'sectionDone' };\n\n/** Each source is read while the section drawn from the one before it is written. */\nconst OPENING: Step[] = [\n  ...typingSteps(QUESTION, 1000),\n  {\n    after: 500,\n    by: 'person',\n    press: 'send',\n    action: { type: 'sent' },\n    isAnswered: hasAsked,\n  },\n  frame(500, [started('plan')]),\n  frame(1000, [done('plan'), started('search')]),\n  frame(1100, [done('search'), started('notes')]),\n  frame(1300, [done('notes'), SECTION_STARTED, started('cohort')]),\n  { after: 300, by: 'demo', action: { type: 'sheet', isOpen: true } },\n  frame(sectionMsOf(0), [SECTION_DONE]),\n  frame(250, [done('cohort'), SECTION_STARTED, started('issue')]),\n  frame(sectionMsOf(1), [SECTION_DONE]),\n  frame(250, [done('issue'), SECTION_STARTED, started('check')]),\n  frame(sectionMsOf(2), [SECTION_DONE]),\n  frame(200, [done('check'), SECTION_STARTED]),\n  frame(sectionMsOf(3), [SECTION_DONE]),\n  { after: 1000, by: 'demo', action: { type: 'sheet', isOpen: false } },\n  frame(500, [{ type: 'answering' }]),\n  frame(ANSWER_MS, [{ type: 'answered' }]),\n  lit(800, 1),\n  lit(600, 2),\n  lit(600, 3),\n  lit(500, null),\n  frame(600, [{ type: 'asked' }]),\n];\n\nconst CLOSING: Step[] = [\n  {\n    after: DEMO_DECIDES_AFTER_MS,\n    by: 'person',\n    press: 'allow',\n    action: { type: 'decided', decision: 'approved' },\n    isAnswered: hasDecided,\n  },\n  { after: SHARE_MS, action: { type: 'shared' } },\n  {\n    after: 1500,\n    by: 'demo',\n    press: `section-${FOLDED_BY_DEMO}`,\n    action: { type: 'sectionToggled', id: FOLDED_BY_DEMO },\n  },\n];\n\nexport const SCRIPT: Step[] = [...OPENING, ...CLOSING];\n\nconst ASKED = restingOf(INITIAL, OPENING, applyAt);\n\n/** Under reduced motion the research is over and the request to share waits, with its buttons to read. */\nexport const RESTING: ResearchState = {\n  ...ASKED,\n  isSheetOpen: false,\n  demoLitSource: null,\n};\n\nexport const LOOP_AFTER_MS = 3200;\n",
      "type": "registry:component",
      "target": "components/templates/application-10/session.ts"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-10/data.ts",
      "content": "import type { SeriesSlot } from '@/registry/ndeko/lib/agent-run';\nimport type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\nimport { wordsOf } from '@/registry/ndeko/lib/words';\n\nexport const WORKSPACE = { name: 'Corvale', space: 'Growth' };\n\nexport type Agent = {\n  name: string;\n  series: SeriesSlot;\n};\n\nexport const RESEARCHER: Agent = {\n  name: 'Researcher',\n  series: 2,\n};\n\nexport type Model = {\n  name: string;\n  brand: BrandSlug;\n};\n\nexport const MODEL: Model = { name: 'Claude Sonnet', brand: 'claude' };\n\nexport const QUESTION = 'Why did onboarding completion drop in March?';\n\nexport type StepId = 'plan' | 'search' | 'notes' | 'cohort' | 'issue' | 'check';\n\nexport type ActivityKind = 'think' | 'search' | 'read';\n\nexport type ActivitySeed = {\n  id: StepId;\n  kind: ActivityKind;\n  title: string;\n  detail: string;\n  doneSummary: string;\n  brand?: BrandSlug;\n  product?: string;\n  usd: number;\n};\n\n/** Invented documents and costs. The figures are illustrative. */\nexport const ACTIVITY: ActivitySeed[] = [\n  {\n    id: 'plan',\n    kind: 'think',\n    title: 'Plan the research',\n    detail: 'Where the answer is likely to be written down',\n    doneSummary: 'Product notes, the cohort review, the issue tracker',\n    usd: 0.004,\n  },\n  {\n    id: 'search',\n    kind: 'search',\n    title: 'Search the workspace',\n    detail: 'onboarding completion March',\n    doneSummary: '4 documents found, 3 worth reading',\n    usd: 0.006,\n  },\n  {\n    id: 'notes',\n    kind: 'read',\n    title: 'Read Onboarding redesign notes',\n    detail: 'A page of the Product space',\n    doneSummary: 'Verification moved to step two on 4 March',\n    brand: 'notion',\n    product: 'Notion',\n    usd: 0.011,\n  },\n  {\n    id: 'cohort',\n    kind: 'read',\n    title: 'Read March cohort review',\n    detail: 'Six pages and one table',\n    doneSummary: 'Completion went from 61% to 48%',\n    brand: 'googledocs',\n    product: 'Google Docs',\n    usd: 0.014,\n  },\n  {\n    id: 'issue',\n    kind: 'read',\n    title: 'Read ONB-142',\n    detail: 'An issue with 12 comments',\n    doneSummary: 'Our email takes up to nine minutes at peak hours',\n    brand: 'linear',\n    product: 'Linear',\n    usd: 0.009,\n  },\n  {\n    id: 'check',\n    kind: 'think',\n    title: 'Check the figures',\n    detail: 'Each number against the cohort table',\n    doneSummary: 'Every figure matches its source',\n    usd: 0.007,\n  },\n];\n\nconst FALLBACK_SEED = ACTIVITY[0];\n\nexport function seedOf(id: StepId) {\n  const seed = ACTIVITY.find((candidate) => candidate.id === id);\n  return seed ?? FALLBACK_SEED;\n}\n\nexport type Source = {\n  number: number;\n  stepId: StepId;\n  title: string;\n  brand: BrandSlug;\n  product: string;\n};\n\nexport const SOURCES: Source[] = [\n  {\n    number: 1,\n    stepId: 'notes',\n    title: 'Onboarding redesign notes',\n    brand: 'notion',\n    product: 'Notion',\n  },\n  {\n    number: 2,\n    stepId: 'cohort',\n    title: 'March cohort review',\n    brand: 'googledocs',\n    product: 'Google Docs',\n  },\n  {\n    number: 3,\n    stepId: 'issue',\n    title: 'ONB-142',\n    brand: 'linear',\n    product: 'Linear',\n  },\n];\n\nexport const MEMO_TITLE = 'Onboarding completion in March';\n\nexport type MemoSection = {\n  id: string;\n  heading: string;\n  text: string;\n};\n\nexport const MEMO: MemoSection[] = [\n  {\n    id: 'changed',\n    heading: 'What changed',\n    text: 'On 4 March the email verification step moved from the end of onboarding to step two. Nothing else in the flow changed that week.',\n  },\n  {\n    id: 'evidence',\n    heading: 'Evidence',\n    text: 'Completion fell from 61% in the February cohort to 48% in March. Most of the loss sits at step two, where 22% of new accounts now leave, against 6% before.',\n  },\n  {\n    id: 'cause',\n    heading: 'Likely cause',\n    text: 'The verification email takes up to nine minutes to arrive at peak hours. People who wait more than two minutes rarely come back to finish.',\n  },\n  {\n    id: 'next',\n    heading: 'Next steps',\n    text: 'Let people continue while the email is on its way, or move verification back to the end. Measure again with the first April cohort.',\n  },\n];\n\nfunction wordCountOf(section: MemoSection) {\n  const words = wordsOf(section.text);\n  return words.length;\n}\n\nexport const SECTION_WORDS = MEMO.map(wordCountOf);\n\nfunction sumOf(counts: number[]) {\n  let total = 0;\n  for (const count of counts) {\n    total += count;\n  }\n  return total;\n}\n\nexport const MEMO_WORDS = sumOf(SECTION_WORDS);\n\nexport const FOLDED_BY_DEMO = 'evidence';\n\nconst ANSWER =\n  'Completion dropped because email verification moved to step two on 4 March. [1] The March cohort finished at 48%, down from 61%, [2] and most people leave while they wait for an email that takes up to nine minutes at peak hours. [3] The memo beside this thread has the detail and two ways to fix it.';\n\nexport type AnswerToken =\n  { kind: 'word'; text: string } | { kind: 'cite'; source: number };\n\nconst CITE = /^\\[(\\d+)\\]$/;\n\nfunction tokenOf(piece: string): AnswerToken {\n  const match = CITE.exec(piece);\n  if (match) {\n    const source = Number(match[1]);\n    return { kind: 'cite', source };\n  }\n  return { kind: 'word', text: piece };\n}\n\nconst ANSWER_PIECES = wordsOf(ANSWER);\n\nexport const ANSWER_TOKENS = ANSWER_PIECES.map(tokenOf);\n\nexport type Person = {\n  id: string;\n  name: string;\n  role: string;\n};\n\nexport const RECEIVERS: Person[] = [\n  {\n    id: 'mara',\n    name: 'Mara Lindqvist',\n    role: 'Head of growth',\n  },\n  {\n    id: 'jonas',\n    name: 'Jonas Weber',\n    role: 'Onboarding lead',\n  },\n  {\n    id: 'imani',\n    name: 'Imani Okoro',\n    role: 'Lifecycle marketing',\n  },\n];\n\nexport const SHARED_LINE =\n  'Shared with Mara, Jonas and Imani. They can comment on the memo';\n\nexport const KEPT_LINE = 'Not shared. The memo stays private to you';\n\nexport const FOLLOW_UP_REPLY =\n  'This demonstration plays one scripted run. Replay it to watch it again.';\n",
      "type": "registry:component",
      "target": "components/templates/application-10/data.ts"
    }
  ],
  "categories": [
    "templates",
    "agent-workspaces"
  ],
  "type": "registry:block"
}