{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-chat-02",
  "title": "Chat with an artifact",
  "description": "A chat beside the code an agent wrote, in panels you resize: the revision lands in place and only its new lines light up, with versions, a Changes view, Copy and Apply, and a sheet you drag down on phones.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/copy-button.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/inline-sheet.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/replay-button.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/streamed-text.json",
    "https://ui.ndekocode.dev/r/theme.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-chat/agent-chat-02/index.tsx",
      "content": "'use client';\n\nimport { useRef, useState } from 'react';\n\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  pressedSolidOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport { ArrowUpIcon, CodeIcon, FeatherIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { InlineSheet } from '@/registry/ndeko/ui/inline-sheet';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { ArtifactPanel } from './artifact-panel';\nimport { FILE_NAME, FIRST_REPLY, SECOND_REPLY } from './data';\nimport {\n  APPLY_MS,\n  canSendAt,\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  type ArtifactView,\n  type Stage,\n  type Version,\n} from './session';\nimport { DEFAULT_SPLIT, ResizeHandle } from './split';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nfunction placeholderOf(stage: Stage) {\n  if (stage === 0) {\n    return 'Ask for a section of your page';\n  }\n  if (stage === 2) {\n    return 'Ask for a change';\n  }\n  if (stage === 4) {\n    return 'Replay to run the demonstration again';\n  }\n  return 'The assistant is writing';\n}\n\nfunction announcementOf(stage: Stage) {\n  if (stage === 2) {\n    return 'The first version is ready in the artifact.';\n  }\n  if (stage === 4) {\n    return 'The second version is ready. Changes shows what moved.';\n  }\n  return '';\n}\n\nfunction isSendKey(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n  const isPlainEnter = event.key === 'Enter' && !event.shiftKey;\n  return isPlainEnter && !event.nativeEvent.isComposing;\n}\n\nfunction AssistantTile() {\n  return (\n    <span\n      aria-hidden='true'\n      className='gem-plate inline-flex size-7 shrink-0 items-center justify-center rounded-lg [--gem:var(--primary)]'\n    >\n      <FeatherIcon className='size-4' />\n    </span>\n  );\n}\n\nfunction PersonMessage({ 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 WorkingLine({ word }: { word: string }) {\n  return (\n    <p className='text-muted-foreground flex h-7 items-center gap-2 text-[13px]'>\n      <span\n        aria-hidden='true'\n        className='bg-primary size-1.5 animate-pulse rounded-full'\n      />\n      {word}\n    </p>\n  );\n}\n\ntype VersionCardProps = {\n  version: Version;\n  isCurrent: boolean;\n  onOpen: (version: Version) => void;\n};\n\nfunction currentCardOf(isCurrent: boolean) {\n  if (isCurrent) {\n    return 'ring-primary/50';\n  }\n  return 'ring-foreground/12';\n}\n\nfunction VersionCard({ version, isCurrent, onOpen }: VersionCardProps) {\n  return (\n    <button\n      type='button'\n      aria-pressed={isCurrent}\n      onClick={() => onOpen(version)}\n      className={cn(\n        'bg-card hairline-ring hover:bg-foreground/[0.03] focus-visible:ring-ring dark:bg-foreground/[0.04] flex h-11 w-fit max-w-full cursor-pointer items-center gap-2.5 rounded-xl ps-2 pe-3 text-start shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-[background-color,box-shadow] duration-150 outline-none focus-visible:ring-2 active:scale-[0.97]',\n        currentCardOf(isCurrent)\n      )}\n    >\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        <CodeIcon className='size-3.5' />\n      </span>\n      <span className='flex min-w-0 flex-col leading-tight'>\n        <span className='truncate font-mono text-xs font-medium'>\n          {FILE_NAME}\n        </span>\n        <span className='text-muted-foreground text-xs'>Version {version}</span>\n      </span>\n    </button>\n  );\n}\n\ntype ReplyProps = {\n  isWorking: boolean;\n  workingWord: string;\n  text: string;\n  version: Version;\n  currentVersion: Version;\n  onOpen: (version: Version) => void;\n};\n\nfunction Reply({\n  isWorking,\n  workingWord,\n  text,\n  version,\n  currentVersion,\n  onOpen,\n}: ReplyProps) {\n  return (\n    <div className='flex items-start gap-2.5'>\n      <AssistantTile />\n      {isWorking && <WorkingLine word={workingWord} />}\n      {!isWorking && (\n        <div className='flex min-w-0 flex-1 flex-col gap-2.5 pt-1'>\n          <p className='text-sm leading-relaxed transition-opacity duration-300 starting:opacity-0'>\n            {text}\n          </p>\n          <VersionCard\n            version={version}\n            isCurrent={version === currentVersion}\n            onOpen={onOpen}\n          />\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default function AgentChat02() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const [split, setSplit] = useState(DEFAULT_SPLIT);\n  const layoutRef = useRef<HTMLDivElement>(null);\n  const { schedule } = useTimeouts();\n  const { stage } = state;\n  const [firstAsk, secondAsk] = state.asks;\n  const canSend = canSendAt(stage);\n  const canReplay = isFinished && !isAutoplaying;\n  const announcement = announcementOf(stage);\n  const message = spokenUnless(isAutoplaying, announcement);\n  const splitStyle = { '--split': `${split}%` } as React.CSSProperties;\n\n  function changeSplit(next: number) {\n    layoutRef.current?.style.setProperty('--split', `${next}%`);\n    setSplit(next);\n  }\n\n  function send() {\n    act({ type: 'sent' });\n  }\n\n  function handleKeys(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n    if (!isSendKey(event)) {\n      return;\n    }\n    event.preventDefault();\n    send();\n  }\n\n  function openVersion(version: Version) {\n    act({ type: 'version', version });\n    act({ type: 'sheet', isOpen: true });\n  }\n\n  function apply() {\n    act({ type: 'applying' });\n    schedule(() => act({ type: 'applied' }), APPLY_MS);\n  }\n\n  function closeSheet() {\n    act({ type: 'sheet', isOpen: false });\n  }\n\n  const panel = {\n    stage,\n    version: state.version,\n    view: state.view,\n    apply: state.apply,\n    appliedVersion: state.appliedVersion,\n    pressed,\n    isActive: isInView,\n    onVersionChange: (version: Version) => act({ type: 'version', version }),\n    onViewChange: (view: ArtifactView) => act({ type: 'view', view }),\n    onApply: apply,\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-[36rem] w-full overflow-hidden'\n      >\n        <div\n          ref={layoutRef}\n          style={splitStyle}\n          className='mx-auto flex h-full max-w-6xl p-3 @3xl:p-4'\n        >\n          <section\n            aria-label='Conversation'\n            className='flex w-full min-w-0 shrink-0 flex-col gap-3 @3xl:w-(--split)'\n          >\n            <header className='flex h-9 shrink-0 items-center gap-2.5'>\n              <AssistantTile />\n              <div className='flex min-w-0 flex-1 flex-col leading-tight'>\n                <h2 className='truncate text-sm font-medium'>\n                  Tallis landing page\n                </h2>\n                <span className='text-muted-foreground text-xs'>Assistant</span>\n              </div>\n              <ReplayButton isShown={canReplay} onReplay={restart} />\n            </header>\n\n            <div className='flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto py-2'>\n              {stage === 0 && (\n                <p className='text-muted-foreground m-auto max-w-xs text-center text-[13px]'>\n                  Ask for a section. The code is written in the artifact, where\n                  you can compare versions and apply one.\n                </p>\n              )}\n              {firstAsk && <PersonMessage text={firstAsk} />}\n              {stage >= 1 && (\n                <Reply\n                  isWorking={stage === 1}\n                  workingWord={`Writing ${FILE_NAME}`}\n                  text={FIRST_REPLY}\n                  version={1}\n                  currentVersion={state.version}\n                  onOpen={openVersion}\n                />\n              )}\n              {secondAsk && <PersonMessage text={secondAsk} />}\n              {stage >= 3 && (\n                <Reply\n                  isWorking={stage === 3}\n                  workingWord='Revising two places'\n                  text={SECOND_REPLY}\n                  version={2}\n                  currentVersion={state.version}\n                  onOpen={openVersion}\n                />\n              )}\n            </div>\n\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={state.draft}\n                rows={2}\n                aria-label='Message to the assistant'\n                placeholder={placeholderOf(stage)}\n                onChange={(event) =>\n                  act({ type: 'typed', text: event.target.value })\n                }\n                onKeyDown={handleKeys}\n                className='placeholder:text-muted-foreground/75 min-h-12 flex-1 resize-none bg-transparent px-1.5 py-1 text-base leading-normal outline-none md:text-[13px]'\n              />\n              <Button\n                type='button'\n                size='icon'\n                aria-label='Send the message'\n                disabled={!canSend}\n                onClick={send}\n                className={pressedSolidOf(pressed === 'send')}\n              >\n                <ArrowUpIcon />\n              </Button>\n            </div>\n          </section>\n\n          <ResizeHandle\n            split={split}\n            containerRef={layoutRef}\n            onSplitChange={changeSplit}\n          />\n\n          <aside\n            aria-label='Artifact'\n            className='bg-card hairline-ring ring-border hidden min-w-0 flex-1 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)] @3xl:flex'\n          >\n            <ArtifactPanel {...panel} className='w-full' />\n          </aside>\n        </div>\n\n        <InlineSheet\n          label='Artifact'\n          closeLabel='Close the artifact'\n          side='bottom'\n          closer='grip'\n          isModal={false}\n          isOpen={state.isSheetOpen}\n          className='z-10 @3xl:hidden'\n          panelClassName='h-[78%] px-4 pb-4'\n          onClose={closeSheet}\n        >\n          <ArtifactPanel {...panel} className='flex-1' />\n        </InlineSheet>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-chat-02/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-chat/agent-chat-02/artifact-panel.tsx",
      "content": "'use client';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { CodeIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { CopyButton } from '@/registry/ndeko/ui/copy-button';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\nimport { useRevealedCount } from '@/registry/ndeko/ui/streamed-text';\n\nimport {\n  CHANGES,\n  FILE_NAME,\n  sourceOf,\n  VERSIONS,\n  type CodeLine,\n  type DiffKind,\n} from './data';\nimport type { ApplyStatus, ArtifactView, Stage, Version } from './session';\n\nconst LINE_MS = 150;\n\nconst VERSION_SEGMENTS: Segment<'v1' | 'v2'>[] = [\n  { value: 'v1', label: 'v1' },\n  { value: 'v2', label: 'v2' },\n];\n\nconst VIEW_SEGMENTS: Segment<ArtifactView>[] = [\n  { value: 'code', label: 'Code' },\n  { value: 'changes', label: 'Changes' },\n];\n\nconst APPLY_LABELS: Record<MorphState, string> = {\n  idle: 'Apply',\n  busy: 'Applying',\n  done: 'Applied',\n};\n\nconst FIRST_VERSION_KEYS = new Set(VERSIONS[1].map((line) => line.key));\n\nconst ADDED_COUNT = CHANGES.filter((line) => line.kind === 'added').length;\n\nconst REMOVED_COUNT = CHANGES.filter((line) => line.kind === 'removed').length;\n\nfunction statusOf(stage: Stage, version: Version) {\n  if (stage === 1) {\n    return 'Writing';\n  }\n  if (stage === 3) {\n    return 'Revising';\n  }\n  return `Version ${version}`;\n}\n\nfunction applyStateOf(\n  apply: ApplyStatus,\n  isAppliedVersion: boolean\n): MorphState {\n  if (apply === 'busy') {\n    return 'busy';\n  }\n  if (isAppliedVersion) {\n    return 'done';\n  }\n  return 'idle';\n}\n\nfunction versionOf(value: 'v1' | 'v2'): Version {\n  if (value === 'v2') {\n    return 2;\n  }\n  return 1;\n}\n\nfunction lineNumberOf(index: number) {\n  return index + 1;\n}\n\n/** A line that the revision added lights for a moment when it lands; the lines around it do not move. */\nfunction landingClassOf(isRevised: boolean) {\n  if (isRevised) {\n    return 'bg-primary/0 transition-colors duration-1000 ease-out starting:bg-primary/25';\n  }\n  return 'transition-opacity duration-300 starting:opacity-0';\n}\n\nfunction CodeRows({\n  lines,\n  marksRevision,\n}: {\n  lines: CodeLine[];\n  marksRevision: boolean;\n}) {\n  return (\n    <ol className='min-w-max py-2 font-mono text-xs leading-5'>\n      {lines.map((line, index) => {\n        const isNew = !FIRST_VERSION_KEYS.has(line.key);\n        const isRevised = marksRevision && isNew;\n        return (\n          <li\n            key={line.key}\n            className={cn('flex gap-3 px-3', landingClassOf(isRevised))}\n          >\n            <span className='text-muted-foreground/60 w-5 shrink-0 text-end tabular-nums select-none'>\n              {lineNumberOf(index)}\n            </span>\n            <code className='whitespace-pre'>{line.text}</code>\n          </li>\n        );\n      })}\n    </ol>\n  );\n}\n\n/** Only this list re-renders while the first version is written. */\nfunction StreamedCode({ isActive }: { isActive: boolean }) {\n  const total = VERSIONS[1].length;\n  const count = useRevealedCount(total, isActive, LINE_MS);\n  const lines = VERSIONS[1].slice(0, count);\n\n  return <CodeRows lines={lines} marksRevision={false} />;\n}\n\nconst DIFF_SIGN: Record<DiffKind, string> = {\n  same: ' ',\n  added: '+',\n  removed: '-',\n};\n\nconst DIFF_CLASS: Record<DiffKind, string> = {\n  same: '',\n  added: 'bg-success/10',\n  removed: 'bg-destructive/10 text-muted-foreground line-through',\n};\n\nconst DIFF_WORD: Record<DiffKind, string> = {\n  same: '',\n  added: 'Added: ',\n  removed: 'Removed: ',\n};\n\nfunction ChangeRows() {\n  return (\n    <ol className='min-w-max py-2 font-mono text-xs leading-5'>\n      {CHANGES.map((line) => (\n        <li\n          key={`${line.kind}-${line.key}`}\n          className={cn('flex gap-3 px-3', DIFF_CLASS[line.kind])}\n        >\n          <span\n            aria-hidden='true'\n            className='text-muted-foreground w-5 shrink-0 text-center select-none'\n          >\n            {DIFF_SIGN[line.kind]}\n          </span>\n          <span className='sr-only'>{DIFF_WORD[line.kind]}</span>\n          <code className='whitespace-pre'>{line.text}</code>\n        </li>\n      ))}\n    </ol>\n  );\n}\n\nexport type ArtifactPanelProps = {\n  stage: Stage;\n  version: Version;\n  view: ArtifactView;\n  apply: ApplyStatus;\n  appliedVersion: Version | null;\n  pressed: string | null;\n  isActive: boolean;\n  onVersionChange: (version: Version) => void;\n  onViewChange: (view: ArtifactView) => void;\n  onApply: () => void;\n  className?: string;\n};\n\nexport function ArtifactPanel({\n  stage,\n  version,\n  view,\n  apply,\n  appliedVersion,\n  pressed,\n  isActive,\n  onVersionChange,\n  onViewChange,\n  onApply,\n  className,\n}: ArtifactPanelProps) {\n  const isEmpty = stage === 0;\n  const isWriting = stage === 1;\n  const isReady = stage >= 2;\n  const hasRevision = stage === 4;\n  const showsChanges = hasRevision && view === 'changes';\n  const showsCode = isReady && !showsChanges;\n  const lines = VERSIONS[version];\n  const status = statusOf(stage, version);\n  const applyState = applyStateOf(apply, appliedVersion === version);\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          <CodeIcon className='size-3.5' />\n        </span>\n        <div className='flex min-w-0 flex-1 flex-col leading-tight'>\n          <h3 className='truncate font-mono text-[13px] font-medium'>\n            {FILE_NAME}\n          </h3>\n          {!isEmpty && (\n            <Swap swapKey={status} className='text-muted-foreground text-xs'>\n              {status}\n            </Swap>\n          )}\n        </div>\n        {isReady && <CopyButton text={sourceOf(lines)} label='Copy the code' />}\n        {isReady && (\n          <MorphButton\n            type='button'\n            size='sm'\n            state={applyState}\n            labels={APPLY_LABELS}\n            onClick={onApply}\n            className={pressedSolidOf(pressed === 'apply')}\n          />\n        )}\n      </header>\n\n      {hasRevision && (\n        <div className='flex flex-wrap items-center gap-2'>\n          <Segments\n            label='Version'\n            value={`v${version}`}\n            segments={VERSION_SEGMENTS}\n            onValueChange={(value) => onVersionChange(versionOf(value))}\n          />\n          <Segments\n            label='View'\n            value={view}\n            segments={VIEW_SEGMENTS}\n            onValueChange={onViewChange}\n          />\n          <span className='text-muted-foreground ms-auto text-xs tabular-nums'>\n            <span className='text-success-foreground'>+{ADDED_COUNT}</span>{' '}\n            <span className='text-destructive-ink'>-{REMOVED_COUNT}</span>\n          </span>\n        </div>\n      )}\n\n      <div className='bg-foreground/[0.04] min-h-0 flex-1 overflow-auto rounded-lg'>\n        {isEmpty && (\n          <p className='text-muted-foreground p-4 text-[13px]'>\n            Nothing made yet. Ask for a section and its code is written here.\n          </p>\n        )}\n        {isWriting && <StreamedCode isActive={isActive} />}\n        {showsCode && <CodeRows lines={lines} marksRevision={hasRevision} />}\n        {showsChanges && <ChangeRows />}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-chat-02/artifact-panel.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-chat/agent-chat-02/split.tsx",
      "content": "'use client';\n\nimport { useRef } from 'react';\n\nexport const DEFAULT_SPLIT = 42;\n\nconst MIN_SPLIT = 30;\n\nconst MAX_SPLIT = 62;\n\nconst KEY_STEP = 2;\n\nfunction bounded(percent: number) {\n  const atLeast = Math.max(MIN_SPLIT, percent);\n  return Math.min(MAX_SPLIT, atLeast);\n}\n\nfunction splitFromKey(key: string, split: number) {\n  if (key === 'ArrowLeft') {\n    return bounded(split - KEY_STEP);\n  }\n  if (key === 'ArrowRight') {\n    return bounded(split + KEY_STEP);\n  }\n  if (key === 'Home') {\n    return MIN_SPLIT;\n  }\n  if (key === 'End') {\n    return MAX_SPLIT;\n  }\n  return null;\n}\n\ntype ResizeHandleProps = {\n  split: number;\n  /** The element whose `--split` the handle drives. */\n  containerRef: React.RefObject<HTMLElement | null>;\n  onSplitChange: (split: number) => void;\n};\n\n/** While it is dragged the width is written to the container; React hears about it once, on release. */\nexport function ResizeHandle({\n  split,\n  containerRef,\n  onSplitChange,\n}: ResizeHandleProps) {\n  const dragged = useRef<number | null>(null);\n\n  function startDrag(event: React.PointerEvent<HTMLDivElement>) {\n    event.currentTarget.setPointerCapture(event.pointerId);\n    dragged.current = split;\n  }\n\n  function drag(event: React.PointerEvent<HTMLDivElement>) {\n    const container = containerRef.current;\n    const isDragging = dragged.current !== null;\n    if (!container || !isDragging) {\n      return;\n    }\n    const box = container.getBoundingClientRect();\n    const offset = event.clientX - box.left;\n    const percent = (offset / box.width) * 100;\n    const next = bounded(percent);\n    dragged.current = next;\n    container.style.setProperty('--split', `${next}%`);\n  }\n\n  function endDrag() {\n    const next = dragged.current;\n    dragged.current = null;\n    if (next !== null) {\n      onSplitChange(Math.round(next));\n    }\n  }\n\n  function moveWithKeys(event: React.KeyboardEvent<HTMLDivElement>) {\n    const next = splitFromKey(event.key, split);\n    if (next === null) {\n      return;\n    }\n    event.preventDefault();\n    onSplitChange(next);\n  }\n\n  return (\n    <div\n      role='separator'\n      tabIndex={0}\n      aria-orientation='vertical'\n      aria-label='Resize the conversation and the artifact'\n      aria-valuemin={MIN_SPLIT}\n      aria-valuemax={MAX_SPLIT}\n      aria-valuenow={split}\n      onPointerDown={startDrag}\n      onPointerMove={drag}\n      onPointerUp={endDrag}\n      onPointerCancel={endDrag}\n      onDoubleClick={() => onSplitChange(DEFAULT_SPLIT)}\n      onKeyDown={moveWithKeys}\n      className='group/handle focus-visible:ring-ring/25 hidden w-3 shrink-0 cursor-col-resize touch-none items-center justify-center rounded-full outline-none focus-visible:ring-[3px] @3xl:flex'\n    >\n      <span className='bg-foreground/15 group-hover/handle:bg-foreground/35 group-active/handle:bg-primary h-8 w-1 rounded-full transition-colors duration-150' />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-chat-02/split.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-chat/agent-chat-02/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport { FIRST_PROMPT, SECOND_PROMPT } from './data';\n\n/** 0 nothing asked, 1 writing the first version, 2 first version ready, 3 revising, 4 second version ready. */\nexport type Stage = 0 | 1 | 2 | 3 | 4;\n\nexport type Version = 1 | 2;\n\nexport type ArtifactView = 'code' | 'changes';\n\nexport type ApplyStatus = 'idle' | 'busy' | 'done';\n\nexport type ArtifactState = {\n  draft: string;\n  asks: string[];\n  stage: Stage;\n  version: Version;\n  view: ArtifactView;\n  apply: ApplyStatus;\n  appliedVersion: Version | null;\n  isSheetOpen: boolean;\n};\n\nexport type ArtifactAction =\n  | { type: 'typed'; text: string }\n  | { type: 'sent' }\n  | { type: 'wrote' }\n  | { type: 'version'; version: Version }\n  | { type: 'view'; view: ArtifactView }\n  | { type: 'applying' }\n  | { type: 'applied' }\n  | { type: 'sheet'; isOpen: boolean };\n\ntype Step = SessionStep<ArtifactState, ArtifactAction>;\n\nexport const INITIAL: ArtifactState = {\n  draft: '',\n  asks: [],\n  stage: 0,\n  version: 1,\n  view: 'code',\n  apply: 'idle',\n  appliedVersion: null,\n  isSheetOpen: false,\n};\n\nexport function canSendAt(stage: Stage) {\n  return stage === 0 || stage === 2;\n}\n\nfunction fallbackPromptOf(stage: Stage) {\n  if (stage === 0) {\n    return FIRST_PROMPT;\n  }\n  return SECOND_PROMPT;\n}\n\nfunction askOf(state: ArtifactState) {\n  const trimmed = state.draft.trim();\n  if (trimmed === '') {\n    return fallbackPromptOf(state.stage);\n  }\n  return trimmed;\n}\n\nfunction sent(state: ArtifactState): ArtifactState {\n  if (!canSendAt(state.stage)) {\n    return state;\n  }\n  const asks = [...state.asks, askOf(state)];\n  if (state.stage === 0) {\n    return { ...state, draft: '', asks, stage: 1 };\n  }\n  return { ...state, draft: '', asks, stage: 3 };\n}\n\nfunction wrote(state: ArtifactState): ArtifactState {\n  if (state.stage === 1) {\n    return { ...state, stage: 2, version: 1 };\n  }\n  if (state.stage === 3) {\n    return { ...state, stage: 4, version: 2, apply: 'idle' };\n  }\n  return state;\n}\n\nfunction applied(state: ArtifactState): ArtifactState {\n  if (state.apply !== 'busy') {\n    return state;\n  }\n  return { ...state, apply: 'done', appliedVersion: state.version };\n}\n\nexport function reducer(\n  state: ArtifactState,\n  action: ArtifactAction\n): ArtifactState {\n  switch (action.type) {\n    case 'typed':\n      return { ...state, draft: action.text };\n    case 'sent':\n      return sent(state);\n    case 'wrote':\n      return wrote(state);\n    case 'version':\n      return { ...state, version: action.version, apply: 'idle' };\n    case 'view':\n      return { ...state, view: action.view };\n    case 'applying':\n      return { ...state, apply: 'busy' };\n    case 'applied':\n      return applied(state);\n    case 'sheet':\n      return { ...state, isSheetOpen: action.isOpen };\n  }\n}\n\nconst CHUNK = 3;\n\nfunction delayOfChunk(index: number, startAfter: number) {\n  if (index === 0) {\n    return startAfter;\n  }\n  return 70;\n}\n\nfunction typingSteps(text: string, startAfter: number): Step[] {\n  const steps: Step[] = [];\n  const last = text.length + CHUNK;\n  for (let end = CHUNK; end < last; end += CHUNK) {\n    const typed = text.slice(0, end);\n    const after = delayOfChunk(steps.length, startAfter);\n    steps.push({ after, by: 'demo', action: { type: 'typed', text: typed } });\n  }\n  return steps;\n}\n\nfunction hasAskedOnce(state: ArtifactState) {\n  return state.stage >= 1;\n}\n\nfunction hasAskedTwice(state: ArtifactState) {\n  return state.stage >= 3;\n}\n\n/** How long a version takes to write: the panel streams its lines during that time. */\nexport const WRITE_MS = 2600;\n\nexport const REVISE_MS = 1700;\n\nexport const APPLY_MS = 900;\n\nexport const SCRIPT: Step[] = [\n  ...typingSteps(FIRST_PROMPT, 1000),\n  {\n    after: 450,\n    by: 'person',\n    press: 'send',\n    action: { type: 'sent' },\n    isAnswered: hasAskedOnce,\n  },\n  { after: 500, by: 'demo', action: { type: 'sheet', isOpen: true } },\n  { after: WRITE_MS, action: { type: 'wrote' } },\n  { after: 1500, by: 'demo', action: { type: 'sheet', isOpen: false } },\n  ...typingSteps(SECOND_PROMPT, 500),\n  {\n    after: 450,\n    by: 'person',\n    press: 'send',\n    action: { type: 'sent' },\n    isAnswered: hasAskedTwice,\n  },\n  { after: 500, by: 'demo', action: { type: 'sheet', isOpen: true } },\n  { after: REVISE_MS, action: { type: 'wrote' } },\n  { after: 1700, by: 'demo', action: { type: 'view', view: 'changes' } },\n  { after: 1900, by: 'demo', press: 'apply', action: { type: 'applying' } },\n  { after: APPLY_MS, action: { type: 'applied' } },\n  { after: 1600, by: 'demo', action: { type: 'sheet', isOpen: false } },\n];\n\nfunction restingOf() {\n  let state = INITIAL;\n  for (const step of SCRIPT) {\n    state = reducer(state, step.action);\n  }\n  return state;\n}\n\nexport const RESTING = restingOf();\n\nexport const LOOP_AFTER_MS = 2600;\n",
      "type": "registry:component",
      "target": "components/blocks/agent-chat-02/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/agent-chat/agent-chat-02/data.ts",
      "content": "export const FILE_NAME = 'hero-section.tsx';\n\nexport const FIRST_PROMPT =\n  'Write a hero section for Tallis, our invoicing app';\n\nexport const SECOND_PROMPT =\n  'Add a second button for the demo and say how long setup takes';\n\nexport const FIRST_REPLY =\n  'Here is a first version: a title, one line of support and the main action.';\n\nexport const SECOND_REPLY =\n  'Revised. The lead now says how long setup takes and a second button opens the demo.';\n\nexport type CodeLine = {\n  /** Stable across versions, so a line that did not change keeps its place when a revision lands. */\n  key: string;\n  text: string;\n};\n\nexport type DiffKind = 'same' | 'added' | 'removed';\n\nexport type DiffLine = CodeLine & { kind: DiffKind };\n\nconst OPENING: CodeLine[] = [\n  { key: 'fn', text: 'export function Hero() {' },\n  { key: 'return', text: '  return (' },\n  {\n    key: 'section',\n    text: \"    <section className='mx-auto max-w-3xl py-24 text-center'>\",\n  },\n  { key: 'h1', text: \"      <h1 className='text-4xl font-semibold'>\" },\n  { key: 'title', text: '        Invoices that chase themselves' },\n  { key: 'h1-end', text: '      </h1>' },\n  { key: 'p', text: \"      <p className='text-muted-foreground mt-4'>\" },\n];\n\nconst LEAD_V1: CodeLine = {\n  key: 'lead-v1',\n  text: '        Tallis sends, reminds and reconciles.',\n};\n\nconst LEAD_V2: CodeLine[] = [\n  { key: 'lead-v2', text: '        Tallis sends, reminds and reconciles.' },\n  { key: 'lead-setup', text: '        Set up in ten minutes.' },\n];\n\nconst MIDDLE: CodeLine[] = [\n  { key: 'p-end', text: '      </p>' },\n  {\n    key: 'actions',\n    text: \"      <div className='mt-8 flex justify-center gap-3'>\",\n  },\n  { key: 'start', text: '        <Button>Start free</Button>' },\n];\n\nconst DEMO_BUTTON: CodeLine = {\n  key: 'demo',\n  text: \"        <Button variant='outline'>Watch the demo</Button>\",\n};\n\nconst CLOSING: CodeLine[] = [\n  { key: 'actions-end', text: '      </div>' },\n  { key: 'section-end', text: '    </section>' },\n  { key: 'return-end', text: '  );' },\n  { key: 'fn-end', text: '}' },\n];\n\nexport const VERSIONS: Record<1 | 2, CodeLine[]> = {\n  1: [...OPENING, LEAD_V1, ...MIDDLE, ...CLOSING],\n  2: [...OPENING, ...LEAD_V2, ...MIDDLE, DEMO_BUTTON, ...CLOSING],\n};\n\nfunction sameLines(lines: CodeLine[]): DiffLine[] {\n  return lines.map((line) => ({ ...line, kind: 'same' }));\n}\n\nexport const CHANGES: DiffLine[] = [\n  ...sameLines(OPENING),\n  { ...LEAD_V1, kind: 'removed' },\n  { ...LEAD_V2[0], kind: 'added' },\n  { ...LEAD_V2[1], kind: 'added' },\n  ...sameLines(MIDDLE),\n  { ...DEMO_BUTTON, kind: 'added' },\n  ...sameLines(CLOSING),\n];\n\nexport function sourceOf(lines: CodeLine[]) {\n  const texts = lines.map((line) => line.text);\n  return texts.join('\\n');\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-chat-02/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "agent-chat"
  ],
  "type": "registry:block"
}