Skip to content
Star

Response versions

Regenerate an answer and flip between versions. Free and MIT licensed, as HTML, a typed React component or an Astro component, in three styles with light and dark mode.

$npx designme add response-versions
$npx shadcn@latest add https://designme.dev/r/shadcn/response-versions.json

Need this designed into your product? Book a call

Write a headline for the pricing page

1 / 1
01

Install

Add it to your project with the CLI.

HTML, CSS and JS

$npx designme add response-versions

React

$npx designme add response-versions --react

Astro

$npx designme add response-versions --astro

shadcn, React

$npx shadcn@latest add https://designme.dev/r/shadcn/response-versions.json

shadcn, Astro

$npx shadcn@latest add https://designme.dev/r/shadcn/astro/response-versions.json

The CLI copies the source into your project, so you own it and can change anything. Where each version lands, what it needs and the shadcn theme bridge: Installation.

02

About

What it is for and what it does.

Response versions shows an agent's answer with a small bar to page through earlier versions, regenerate it and copy it. Each regenerated answer is kept as a new version, so the person can compare it with the ones before and keep the one they like.

  • When people regenerate answers and want to go back to an earlier one instead of losing it.
  • When you want a new version to stream in where the old one was, with a counter like 2 / 3.
  • When an answer sits in a chat thread and needs copy and regenerate controls right under it.
03

Usage

Import it in React and drive it from your own state, or place it in an Astro page.

React

import { ResponseVersions } from '@/components/designme/response-versions/ResponseVersions';

React example

The demo above as a React component, 50 lines you can copy.

'use client';
// The animated preview from designme.dev, rebuilt from the React component: an example of driving it from your own state.
import { useRef, useState } from 'react';
import { ResponseVersions } from './ResponseVersions';
import { useScript, useTakeover, type Script } from '../lib/useScript';

/* ---------- Response versions: the first answer streams in, then one regenerate plays by itself; the arrows page between them ---------- */
const POOL = [
  'Pricing that grows with your team. Start free, upgrade when the work gets serious.',
  'One plan per stage of your team. No seat math, no surprises on the invoice.',
  'Design faster with an agent on every plan. Pay for what you ship, not for seats.',
  'Simple pricing for teams who ship. Free to start, fair as you grow.'
];
export default function ResponseVersionsDemo() {
  const [versions, setVersions] = useState<string[]>(['']);
  const [version, setVersion] = useState(0);
  const [streaming, setStreaming] = useState(true);
  const [status, setStatus] = useState('');
  const script = useRef<Script>(null);

  // writes a version word by word, the way an answer streams in
  const stream = async ({ wait }: Script, at: number, text: string) => {
    await wait(260);
    let out = '';
    for (const w of text.split(' ')) { out += (out ? ' ' : '') + w; const now = out; setVersions(v => v.map((x, i) => i === at ? now : x)); await wait(45); }
  };
  const ref = useRef<HTMLDivElement>(null), mine = useTakeover(ref), count = useRef(1);
  useScript(async s => {
    script.current = s;
    await s.wait(300); await stream(s, 0, POOL[0]); setStreaming(false);
    // then one regenerate plays by itself, so the version count and arrows show what they do, unless you have taken over
    await s.wait(1900); if (!mine() && count.current === 1) await regenerate(true);
  });
  const regenerate = async (auto = false) => {
    const s = script.current; if (!s || (streaming && !auto)) return;
    const at = count.current++;
    setStreaming(true); setStatus('Writing a new version');
    setVersions(v => [...v, '']); setVersion(at);
    await stream(s, at, POOL[at % POOL.length]);
    setStreaming(false); setStatus('');
  };

  return (
    <div ref={ref} style={{ width: '100%' }}>
      <ResponseVersions prompt="Write a headline for the pricing page" versions={versions} version={version} onVersionChange={setVersion}
        streaming={streaming} status={status} onRegenerate={() => regenerate()} />
    </div>
  );
}

Astro

In a page in src/pages. It plays the demo above; change its response-versions.js to show your own data. Attributes like class go on its root element.

---
import ResponseVersions from '../components/designme/response-versions/ResponseVersions.astro';
---
<ResponseVersions />
<ResponseVersions data-style="soft" class="my-class" />
04

Props

Everything ResponseVersions takes.

PropTypeWhat it does
promptReactNodeThe person's message the answer replies to, shown as a bubble above it
versionsrequiredstring[]Every version of the answer so far, oldest first
versionnumberWhich version is showing. Leave it out to let the arrows page through them
defaultVersionnumber
onVersionChange(index: number) => void
streamingbooleanThe version showing is still being written. New words fade in as they arrive and paging waits
statusstringQuiet text beside the buttons, like "Writing a new version". It shimmers while streaming
onRegenerate() => voidCalled by the regenerate button. Add a version and show it to answer it
onCopy(text: string) => voidCalled with the text after it is copied to the clipboard
barebooleanSits flat in a chat thread (the default, as on designme.dev). Set false to give it a card of its own
classNamestring
05

Code

The full source, as the CLI installs it.

ResponseVersions.tsxReact · 103 lines
'use client';
import { useEffect, useRef, useState, type ReactNode } from 'react';
import { cx } from '../lib/cx';
import { useControllable, useCopied, useIsoLayoutEffect, useReducedMotion } from '../lib/hooks';
import { Icon } from '../lib/icons';
import { growFit, Swap, SwapIcon, Tip } from '../lib/motion';
import '../designme.css';
import './response-versions.css';

export interface ResponseVersionsProps {
  /** The person's message the answer replies to, shown as a bubble above it */
  prompt?: ReactNode;
  /** Every version of the answer so far, oldest first */
  versions: string[];
  /** Which version is showing. Leave it out to let the arrows page through them */
  version?: number;
  defaultVersion?: number;
  onVersionChange?: (index: number) => void;
  /** The version showing is still being written. New words fade in as they arrive and paging waits */
  streaming?: boolean;
  /** Quiet text beside the buttons, like "Writing a new version". It shimmers while streaming */
  status?: string;
  /** Called by the regenerate button. Add a version and show it to answer it */
  onRegenerate?: () => void;
  /** Called with the text after it is copied to the clipboard */
  onCopy?: (text: string) => void;
  /** Sits flat in a chat thread (the default, as on designme.dev). Set false to give it a card of its own */
  bare?: boolean;
  className?: string;
}

/** An answer with its earlier versions a click away, plus regenerate and copy. */
export function ResponseVersions({ prompt, versions, version, defaultVersion = 0, onVersionChange, streaming = false, status = '', onRegenerate, onCopy, bare = true, className }: ResponseVersionsProps) {
  const [cur, setCur] = useControllable(version, defaultVersion, onVersionChange);
  const reduce = useReducedMotion();
  const last = Math.max(0, versions.length - 1), at = Math.min(Math.max(cur, 0), last);

  // a different version fades the old text out first; then a finished one comes in all at once, word by word,
  // and one still being written shows its words as they arrive
  const [shown, setShown] = useState(at);
  const [out, setOut] = useState(false);
  const [jump, setJump] = useState(false);
  useEffect(() => {
    if (at === shown) return;
    setOut(true);
    const t = setTimeout(() => { setShown(at); setJump(!streaming); setOut(false); }, reduce ? 0 : 240);
    return () => clearTimeout(t);
  }, [at, shown, streaming, reduce]);
  const text = versions[shown] ?? '';
  const words = text.split(' ').filter(Boolean);
  // the container grows with what it holds, in one smooth motion (growFit, grow() on the site), and stays centred wherever it
  // is centred, in every style (owner, 18 Nov; 26 Nov: no jitter)
  const root = useRef<HTMLDivElement>(null), inner = useRef<HTMLDivElement>(null);
  useIsoLayoutEffect(() => { const el = root.current, w = inner.current; if (el && w) return growFit(el, w); }, []);
  // while a new version streams in, the answer keeps the height of the one it replaces, then eases to its own
  const tRef = useRef<HTMLParagraphElement>(null), prevT = useRef({ at: -1, h: 0 });
  useIsoLayoutEffect(() => {
    const el = tRef.current; if (!el) return;
    if (prevT.current.at !== -1 && prevT.current.at !== shown && prevT.current.h && streaming) el.style.minHeight = prevT.current.h + 'px';
    prevT.current = { at: shown, h: el.style.minHeight ? prevT.current.h : (el.textContent?.trim() ? el.offsetHeight : 0) };
  });
  useEffect(() => {
    const el = tRef.current; if (!el || streaming || !el.style.minHeight) return;
    const was = el.offsetHeight; el.style.minHeight = ''; const h = el.offsetHeight;
    if (h >= was || reduce) return;
    el.style.minHeight = was + 'px'; void el.offsetHeight; el.style.transition = 'min-height var(--dm-t) var(--dm-ease)'; el.style.minHeight = h + 'px';
    const t = setTimeout(() => { el.style.transition = ''; el.style.minHeight = ''; }, 460);
    return () => clearTimeout(t);
  }, [streaming, shown, reduce]);

  const [spin, setSpin] = useState(false);
  const regenerate = () => {
    if (streaming) return;
    setSpin(true); setTimeout(() => setSpin(false), 700);
    onRegenerate?.();
  };
  const [copied, copyText] = useCopied();
  const copy = () => { const t = versions[at] ?? ''; copyText(t); onCopy?.(t); };

  return (
    <div data-dm="" ref={root} className={cx('dm-rvx', !bare && 'dm-panel', 'dm-growing dm-mx-grow', className)} style={bare ? undefined : { padding: 16 }}>
      <div ref={inner} className="dm-grow">
      {prompt && <div className="dm-bub">{prompt}</div>}
      <div className="dm-rvx-a">
        <p ref={tRef} className={cx('dm-msg dm-rvx-t', out && 'dm-out')} aria-live="polite">
          {words.map((w, k) => <span key={shown + ':' + k} className="dm-w" style={jump ? { animationDelay: k * 12 + 'ms' } : undefined}>{w} </span>)}
        </p>
        <div className="dm-rvx-bar dm-mx-ic">
          <div className="dm-rvx-pg">
            <Tip label="Previous"><button type="button" className="dm-ib dm-mx-press" aria-label="Previous version" disabled={at === 0 || streaming} onClick={() => setCur(at - 1)}><Icon name="chev-l" /></button></Tip>
            <span className="dm-rvx-n dm-num">{at + 1} / {Math.max(versions.length, 1)}</span>
            <Tip label="Next"><button type="button" className="dm-ib dm-mx-press" aria-label="Next version" disabled={at === last || streaming} onClick={() => setCur(at + 1)}><Icon name="chev-r" /></button></Tip>
          </div>
          {onRegenerate && <Tip label="Regenerate" kbd="⌘R"><button type="button" className={cx('dm-ib dm-rvx-re dm-mx-press', spin && 'dm-go')} aria-label="Regenerate" onClick={regenerate}><Icon name="refresh" /></button></Tip>}
          <Tip label={copied ? 'Copied to clipboard' : 'Copy'} open={copied || undefined}><button type="button" className={cx('dm-ib dm-rvx-cp dm-mx-press', copied && 'dm-copied')} aria-label="Copy" onClick={copy}><SwapIcon id={copied ? 'check' : 'copy'}><Icon name={copied ? 'check' : 'copy'} /></SwapIcon></button></Tip>
          <Swap className={cx('dm-rvx-st dm-muted', streaming && status && 'dm-shim')}>{status}</Swap>
        </div>
      </div>
      </div>
    </div>
  );
}
response-versions.cssReact · 47 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Response versions ---------- */
.dm-rvx{display:flex;flex-direction:column;gap:14px}
/* its motion (the core's motion pieces, owner, 26 Nov): a press on its buttons shows at once (.mx-press); Copy's icon and its
   tick crossfade (.mx-ic); the answer eases to its new height on the spring (.mx-grow) */
.dm-rvx-a{display:flex;flex-direction:column;gap:var(--dm-s-2)}
/* the answer is as tall as its words in every style (owner's notes, 18 Nov): the component grows with them (grow()), and a
   version streaming in keeps the height of the one it replaces, then eases to its own. The bar's first button reaches 6px
   past the column, so the growing box lets that much show, focus ring included */
.dm-rvx.dm-growing{overflow-clip-margin:12px}
/* nothing in the bar shrinks on a click (owner, 18 Nov) */
.dm-rvx-bar .dm-ib:active{transform:none}
:root[data-style="studio"] .dm-rvx-bar .dm-ib:active,:root [data-style="studio"] .dm-rvx-bar .dm-ib:active,:root [data-style="studio"].dm-rvx-bar .dm-ib:active{transform:none}
.dm-rvx-t .dm-w{animation:dm-rvw .45s var(--dm-ease) both}
@keyframes dm-rvw{from{opacity:0;filter:blur(4px)}to{opacity:1;filter:none}}
.dm-rvx-t.dm-out{animation:dm-rvo .3s var(--dm-ease) both}
@keyframes dm-rvo{to{opacity:0;filter:blur(4px);transform:translateY(-2px)}}
.dm-rvx-bar{display:flex;align-items:center;gap:2px;margin-left:-6px}
/* its icon buttons, the pager's included, are the library's 28px icon buttons */
.dm-rvx-bar .dm-ib{width:28px;height:28px}
.dm-rvx-pg{display:flex;align-items:center;gap:0}
.dm-rvx-pg .dm-ib[disabled]{opacity:1;cursor:not-allowed;background:none;color:var(--dm-dis)}
/* the bar sits on the stage, where --dm-row is the stage's own colour: it sets --dm-row to a quiet 5% of the text colour, as the
   other cards on the stage do, so its buttons keep the one shared hover */
.dm-rvx-bar{--dm-row:color-mix(in srgb,var(--dm-fg) 5%,transparent)}
.dm-rvx-n{font-size:12px;color:var(--dm-muted);min-width:34px;text-align:center}
.dm-rvx-re svg{transition:transform .7s var(--dm-ease)}
.dm-rvx-re.dm-go svg{transform:rotate(360deg)}
.dm-rvx-st{font-size:12px;margin-left:6px}
/* Studio (owner, 18 Nov): words fade in and out without a blur */
@keyframes dm-rvwc{from{opacity:0}to{opacity:1}}
@keyframes dm-rvoc{to{opacity:0;transform:translateY(-2px)}}
:root[data-style="studio"] .dm-rvx-t .dm-w,:root [data-style="studio"] .dm-rvx-t .dm-w,:root [data-style="studio"].dm-rvx-t .dm-w{animation-name:dm-rvwc;animation-duration:var(--dm-t-slow)}
:root[data-style="studio"] .dm-rvx-t.dm-out,:root [data-style="studio"] .dm-rvx-t.dm-out,:root [data-style="studio"].dm-rvx-t.dm-out{animation-name:dm-rvoc;animation-duration:var(--dm-t)}
/* Studio (owner, 22 Nov: "differentiate Studio from Soft"): the answer is a version card. The answer comes first, 16px in
   from the card's edges; under it a hairline, and under that the bar as a plain row with no strip (owner, 23 Nov: "just add
   a divider line"): the arrows and the count on the left with what is happening beside them, Regenerate and Copy at the
   right. Its buttons are 28px, 16px from the hairline, the card's bottom edge and its sides. Soft and Blueprint keep the
   answer flat in the thread with its bar under it, in the same order */
:root[data-style="studio"] .dm-rvx-a,:root [data-style="studio"] .dm-rvx-a,:root [data-style="studio"].dm-rvx-a{gap:0;background:var(--dm-surface);border-radius:var(--dm-r-card);box-shadow:var(--dm-shadow);overflow:hidden}
:root[data-style="studio"] .dm-rvx-bar,:root [data-style="studio"] .dm-rvx-bar,:root [data-style="studio"].dm-rvx-bar{margin:0;padding:16px;border-top:1px solid var(--dm-line)}
:root[data-style="studio"] .dm-rvx-t,:root [data-style="studio"] .dm-rvx-t,:root [data-style="studio"].dm-rvx-t{padding:16px}
:root[data-style="studio"] .dm-rvx-st,:root [data-style="studio"] .dm-rvx-st,:root [data-style="studio"].dm-rvx-st{order:1;margin-left:var(--dm-s-2);min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
:root[data-style="studio"] .dm-rvx-re,:root [data-style="studio"] .dm-rvx-re,:root [data-style="studio"].dm-rvx-re{order:2;margin-left:auto}
:root[data-style="studio"] .dm-rvx-cp,:root [data-style="studio"] .dm-rvx-cp,:root [data-style="studio"].dm-rvx-cp{order:3}
.dm-rvx-cp.dm-copied,.dm-aab-cp.dm-copied{color:var(--dm-ok-mark)!important}
ResponseVersions.astroAstro · 35 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Response versions: Regenerate an answer and flip between versions.
// The markup, CSS and script are designme.dev's own, run by the shared core in ../core, which mounts the component when it scrolls
// into view and plays its demo. To show your own data, change response-versions.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './response-versions.css';

export interface Props extends HTMLAttributes<'div'> {
  /** "soft" or "studio" draws it in that style. Leave it out for Blueprint, or for the style set on <html> (data-style="soft" or "studio") */
  'data-style'?: 'soft' | 'studio';
}
const { class: className, ...rest } = Astro.props;
---
<div class:list={['card', 'bare', className]} data-c="response-versions" {...rest}>
  <div class="stage-in"><Fragment is:raw>
<div class="rvx mx-grow">
  <div class="bub">Write a headline for the pricing page</div>
  <div class="rvx-a">
    <p class="msg rvx-t"></p>
    <div class="rvx-bar mx-ic">
      <div class="rvx-pg"><button class="ib rvx-prev mx-press" aria-label="Previous version" data-tip="Previous"><svg class="i s"><use href="#i-chev-l"/></svg></button><span class="rvx-n num">1 / 1</span><button class="ib rvx-next mx-press" aria-label="Next version" data-tip="Next"><svg class="i s"><use href="#i-chev-r"/></svg></button></div>
      <button class="ib rvx-re mx-press" aria-label="Regenerate" data-tip="Regenerate" data-tip-k="⌘R"><svg class="i s"><use href="#i-refresh"/></svg></button>
      <button class="ib rvx-cp mx-press" aria-label="Copy" data-tip="Copy"><svg class="i s"><use href="#i-copy"/></svg></button>
      <span class="rvx-st muted"></span>
    </div>
  </div>
</div>
  </Fragment></div>
</div>
<script>
  import './response-versions.js';
</script>
response-versions.htmlHTML · 17 lines
<div class="card bare" data-c="response-versions">
  <div class="stage-in">
    <div class="rvx mx-grow">
      <div class="bub">Write a headline for the pricing page</div>
      <div class="rvx-a">
        <p class="msg rvx-t"></p>
        <div class="rvx-bar mx-ic">
          <div class="rvx-pg"><button class="ib rvx-prev mx-press" aria-label="Previous version" data-tip="Previous"><svg class="i s"><use href="#i-chev-l"/></svg></button><span class="rvx-n num">1 / 1</span><button class="ib rvx-next mx-press" aria-label="Next version" data-tip="Next"><svg class="i s"><use href="#i-chev-r"/></svg></button></div>
          <button class="ib rvx-re mx-press" aria-label="Regenerate" data-tip="Regenerate" data-tip-k="⌘R"><svg class="i s"><use href="#i-refresh"/></svg></button>
          <button class="ib rvx-cp mx-press" aria-label="Copy" data-tip="Copy"><svg class="i s"><use href="#i-copy"/></svg></button>
          <span class="rvx-st muted"></span>
        </div>
      </div>
    </div>
  </div>
</div>
response-versions.cssHTML · 46 lines
/* ---------- Response versions ---------- */
.rvx{display:flex;flex-direction:column;gap:14px}
/* its motion (the core's motion pieces, owner, 26 Nov): a press on its buttons shows at once (.mx-press); Copy's icon and its
   tick crossfade (.mx-ic); the answer eases to its new height on the spring (.mx-grow) */
.rvx-a{display:flex;flex-direction:column;gap:var(--dm-s-2)}
/* the answer is as tall as its words in every style (owner's notes, 18 Nov): the component grows with them (grow()), and a
   version streaming in keeps the height of the one it replaces, then eases to its own. The bar's first button reaches 6px
   past the column, so the growing box lets that much show, focus ring included */
.rvx.growing{overflow-clip-margin:12px}
/* nothing in the bar shrinks on a click (owner, 18 Nov) */
.rvx-bar .ib:active{transform:none}
:root[data-style="studio"] .rvx-bar .ib:active,:root [data-style="studio"] .rvx-bar .ib:active,:root [data-style="studio"].rvx-bar .ib:active{transform:none}
.rvx-t .w{animation:rvw .45s var(--dm-ease) both}
@keyframes rvw{from{opacity:0;filter:blur(4px)}to{opacity:1;filter:none}}
.rvx-t.out{animation:rvo .3s var(--dm-ease) both}
@keyframes rvo{to{opacity:0;filter:blur(4px);transform:translateY(-2px)}}
.rvx-bar{display:flex;align-items:center;gap:2px;margin-left:-6px}
/* its icon buttons, the pager's included, are the library's 28px icon buttons */
.rvx-bar .ib{width:28px;height:28px}
.rvx-pg{display:flex;align-items:center;gap:0}
.rvx-pg .ib[disabled]{opacity:1;cursor:not-allowed;background:none;color:var(--dm-dis)}
/* the bar sits on the stage, where --dm-row is the stage's own colour: it sets --dm-row to a quiet 5% of the text colour, as the
   other cards on the stage do, so its buttons keep the one shared hover */
.rvx-bar{--dm-row:color-mix(in srgb,var(--dm-fg) 5%,transparent)}
.rvx-n{font-size:12px;color:var(--dm-muted);min-width:34px;text-align:center}
.rvx-re svg{transition:transform .7s var(--dm-ease)}
.rvx-re.go svg{transform:rotate(360deg)}
.rvx-st{font-size:12px;margin-left:6px}
/* Studio (owner, 18 Nov): words fade in and out without a blur */
@keyframes rvwc{from{opacity:0}to{opacity:1}}
@keyframes rvoc{to{opacity:0;transform:translateY(-2px)}}
:root[data-style="studio"] .rvx-t .w,:root [data-style="studio"] .rvx-t .w,:root [data-style="studio"].rvx-t .w{animation-name:rvwc;animation-duration:var(--dm-t-slow)}
:root[data-style="studio"] .rvx-t.out,:root [data-style="studio"] .rvx-t.out,:root [data-style="studio"].rvx-t.out{animation-name:rvoc;animation-duration:var(--dm-t)}
/* Studio (owner, 22 Nov: "differentiate Studio from Soft"): the answer is a version card. The answer comes first, 16px in
   from the card's edges; under it a hairline, and under that the bar as a plain row with no strip (owner, 23 Nov: "just add
   a divider line"): the arrows and the count on the left with what is happening beside them, Regenerate and Copy at the
   right. Its buttons are 28px, 16px from the hairline, the card's bottom edge and its sides. Soft and Blueprint keep the
   answer flat in the thread with its bar under it, in the same order */
:root[data-style="studio"] .rvx-a,:root [data-style="studio"] .rvx-a,:root [data-style="studio"].rvx-a{gap:0;background:var(--dm-surface);border-radius:var(--dm-r-card);box-shadow:var(--dm-shadow);overflow:hidden}
:root[data-style="studio"] .rvx-bar,:root [data-style="studio"] .rvx-bar,:root [data-style="studio"].rvx-bar{margin:0;padding:16px;border-top:1px solid var(--dm-line)}
:root[data-style="studio"] .rvx-t,:root [data-style="studio"] .rvx-t,:root [data-style="studio"].rvx-t{padding:16px}
:root[data-style="studio"] .rvx-st,:root [data-style="studio"] .rvx-st,:root [data-style="studio"].rvx-st{order:1;margin-left:var(--dm-s-2);min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
:root[data-style="studio"] .rvx-re,:root [data-style="studio"] .rvx-re,:root [data-style="studio"].rvx-re{order:2;margin-left:auto}
:root[data-style="studio"] .rvx-cp,:root [data-style="studio"] .rvx-cp,:root [data-style="studio"].rvx-cp{order:3}
.rvx-cp.copied,.aab-cp.copied{color:var(--dm-ok-mark)!important}
response-versions.jsHTML · 39 lines
DM.def('response-versions', (r, c) => {
  r.innerHTML = r.innerHTML.replace('{l}', I('chev-l')).replace('{rr}', I('chev-r')).replace('{re}', I('refresh')).replace('{cp}', I('copy'));
  const pool = [
    'Pricing that grows with your team. Start free, upgrade when the work gets serious.',
    'One plan per stage of your team. No seat math, no surprises on the invoice.',
    'Design faster with an agent on every plan. Pay for what you ship, not for seats.',
    'Simple pricing for teams who ship. Free to start, fair as you grow.'
  ];
  const vers = [pool[0]]; let cur = 0, busy = false;
  const t = $('.rvx-t', r), n = $('.rvx-n', r), pv = $('.rvx-prev', r), nx = $('.rvx-next', r), re = $('.rvx-re', r), st = $('.rvx-st', r);
  const nav = () => { n.textContent = (cur + 1) + ' / ' + vers.length; pv.disabled = cur === 0 || busy; nx.disabled = cur === vers.length - 1 || busy; };
  // no room kept for a longer answer, in every style (owner, 18 Nov). The component grows with its words (grow(), once its
  // entrance has settled), and a version streaming in keeps the height of the one it replaces, then eases to its own
  const rvx = $('.rvx', r);
  const growing = Promise.resolve().then(() => Promise.all(rvx.getAnimations().map(a => a.finished.catch(() => {})))).then(() => { if (!c.dead && rvx.isConnected) c.offs.push(grow(rvx)); });
  const keep = () => { if (t.textContent.trim()) t.style.minHeight = t.offsetHeight + 'px'; };
  const fit = () => { if (!t.style.minHeight) return; const was = t.offsetHeight; t.style.minHeight = ''; const h = t.offsetHeight; if (h >= was || REDUCE) return;
    t.style.minHeight = was + 'px'; void t.offsetHeight; t.style.transition = 'min-height var(--dm-t) var(--dm-ease)'; t.style.minHeight = h + 'px';
    c.later(460, () => { t.style.transition = ''; t.style.minHeight = ''; }); };
  async function stream(s){
    keep(); t.classList.add('out'); await c.wait(260); t.classList.remove('out'); t.innerHTML = '';
    for (const w of s.split(' ')){ t.insertAdjacentHTML('beforeend', `<span class="w">${w} </span>`); await c.wait(45); }
    fit();
  }
  async function show(i){ cur = i; nav(); t.classList.add('out'); await c.wait(240); t.classList.remove('out'); t.innerHTML = vers[i].split(' ').map((w, k) => `<span class="w" style="animation-delay:${k * 12}ms">${w} </span>`).join(''); }
  pv.onclick = () => c.run(() => show(cur - 1));
  nx.onclick = () => c.run(() => show(cur + 1));
  re.onclick = () => { if (busy) return; busy = true; re.classList.add('go'); c.later(700, () => re.classList.remove('go'));
    c.run(async () => { swap(st, 'Writing a new version'); st.classList.add('shim');
      const s = pool[vers.length % pool.length]; vers.push(s); cur = vers.length - 1; nav();
      await stream(s); busy = false; nav(); st.classList.remove('shim'); swap(st, ''); }); };
  const cp = $('.rvx-cp', r);
  cp.onclick = () => copied(cp, vers[cur]);
  // (the first version starts once grow() has the component, so its first lines ease it open rather than jump it, motion pieces)
  c.run(async () => { busy = true; nav(); await c.wait(300); await growing; await stream(vers[0]); busy = false; nav();
    // then one regenerate plays by itself, so the version count and arrows show what they do, unless you have taken over
    await c.step(1900); if (vers.length === 1) re.click(); });
});
06

Questions

What people ask about it.

How do I stream a regenerated answer into a new version?
In onRegenerate, append an empty string to versions, set version to its index and streaming to true, then update that string as tokens arrive. Set streaming back to false when it is done.
Why are the arrows greyed out?
They are disabled while streaming is true, and at the first or last version. That keeps people from paging away from an answer that is still being written.
Can the answer contain formatting like lists or code?
No. Each version is a plain string, split into words for the fade-in, so markup is shown as text.
07

More in Conversation

Everything for asking, answering and replying, by text or by voice.

Live answerAnswers that stream in with numbered sources and next steps.
ComposerMessage input with attachments, what to work on, a mode and dictation.
Answer action barCopy, regenerate, rate and listen to an answer from one row under it.
Model pickerPick a model by speed, quality and cost, and how hard it thinks.
Attachment trayDrop files for the agent and watch each one upload.
Feedback sheetRate an answer and tell the agent what missed.