AI Elements

Checkpoint

Checkpoint marks a point in the conversation that the user can go back to.

Checkpoint is a Marker after a turn, with a Restore button. Restore keeps that turn and removes all the messages after it.

Installation#

Checkpoint is built with the Marker and Button components.

npx shadcn@latest add @formance/marker @formance/button

Usage#

Render a marker after the turn, with a button that restores it.

<Marker variant="separator">  <MarkerContent className="inline-flex items-center gap-2">    {label}    <Button size="sm" variant="outline" onClick={restore}>      Restore    </Button>  </MarkerContent></Marker>

See the separator example on the Marker page.

AI SDK#

Restore replaces the thread with the messages up to that turn, including that turn. All the turns after it are removed. To continue from there, send a new message.

const index = messages.findIndex((message) => message.id === messageId);setMessages(messages.slice(0, index + 1));

AI SDK helper#

To script a checkpoint with createChat from @shadcn/helpers/ai-sdk, write it as a data part on the turn of the agent. Send the same id again only to update that checkpoint.

const chat = createChat()  .user('Rename the fees account to platform fees.')  .assistant(({ writer }) => {    writer.text('Renamed fees:collected to fees:platform in the schema.');    writer.data({      type: 'data-checkpoint',      id: 'rename',      data: { label: 'Fees account renamed' },    });  })  .user('Update the Numscript templates to match.')  .assistant(({ writer }) => {    writer.text('Updated the three templates that post to fees:platform.');  });