Skip to content
WebJs
Menu

Marks a point in the conversation you can return to.

Rename the button component to action.

Renamed Button to Action in components/ui/button.tsx.

Button renamed
Update the docs to match.

Updated the Button page to say Action.

import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { bubbleClass, bubbleContentClass } from '#components/ui/bubble.ts';
import { buttonClass } from '#components/ui/button.ts';
import { markerClass, markerContentClass } from '#components/ui/marker.ts';
import { messageClass, messageContentClass } from '#components/ui/message.ts';

function user(text: string) {
  return html`
    <div data-slot="message" data-align="end" class=${messageClass()}>
      <div data-slot="message-content" class=${messageContentClass()}>
        <div data-slot="bubble" data-variant="muted" data-align="end" class=${bubbleClass({ variant: 'muted' })}>
          <div data-slot="bubble-content" class=${bubbleContentClass()}>${text}</div>
        </div>
      </div>
    </div>
  `;
}

function agent(text: string) {
  return html`
    <div data-slot="message" data-align="start" class=${messageClass()}>
      <div data-slot="message-content" class=${messageContentClass()}>
        <p>${text}</p>
      </div>
    </div>
  `;
}

// The whole conversation. The checkpoint after the first turn offers Restore,
// since there are later turns to drop. Restoring is the reader's to wire.
export default function CheckpointDemo() {
  return html`
    <div class="flex min-h-72 w-full max-w-sm flex-col gap-4 py-6 text-sm">
      ${user('Rename the button component to action.')}
      ${agent('Renamed Button to Action in components/ui/button.tsx.')}
      <div data-slot="marker" data-variant="separator" class=${markerClass({ variant: 'separator' })}>
        <span data-slot="marker-content" class=${cn(markerContentClass(), 'inline-flex items-center gap-2')}>
          Button renamed
          <button type="button" aria-label="Restore to Button renamed" data-slot="button" data-variant="outline" data-size="xs" class=${buttonClass({ variant: 'outline', size: 'xs' })}>
            Restore
          </button>
        </span>
      </div>
      ${user('Update the docs to match.')}
      ${agent('Updated the Button page to say Action.')}
    </div>
  `;
}
View Code

Checkpoint is a point in the conversation you can return to. It is a Marker after a turn, with a Restore button. Restore keeps that turn and drops every message after it.

Installation

Checkpoint is built with the Marker and Button components.

pnpm dlx @webjsdev/ui add marker button

Usage

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

<div data-slot="marker" data-variant="separator" class=${markerClass({ variant: 'separator' })}>
  <span data-slot="marker-content" class=${cn(markerContentClass(), 'inline-flex items-center gap-2')}>
    ${label}
    <button type="button" data-slot="button" data-variant="outline" data-size="xs" class=${buttonClass({ variant: 'outline', size: 'xs' })} @click=${() => this.restore(messageId)}>
      Restore
    </button>
  </span>
</div>

See Marker.

AI SDK

Restore replaces the thread with the messages up to and including that turn. Every later turn is removed. Send a new message to continue from there.

restore(messageId: string) {
  const index = this.messages.findIndex((message) => message.id === messageId);
  this.messages = this.messages.slice(0, index + 1);
}

messages is your component's own state, a reactive property or a signal. Restoring is a change in the browser only. If the server keeps the thread, call a 'use server' action to drop the later turns there too.

AI SDK Helper

Write the checkpoint as a data part on the agent's turn, from the 'use server' action that streams the reply. Send the same id again only when you mean to update that checkpoint. See AI SDK for streaming the parts to a component.

'use server';

export async function* renameButton() {
  yield { type: 'text', text: 'Renamed Button to Action in components/ui/button.tsx.' };
  yield {
    type: 'data-checkpoint',
    id: 'rename',
    data: { label: 'Button renamed' },
  };
}

Render the marker after the turn whose parts hold one:

const checkpoint = message.parts.find((part) => part.type === 'data-checkpoint');

Migrating from AI SDK Elements

If you used Checkpoint from AI SDK Elements, its wrapper lives in components/ai-elements/checkpoint.tsx. In a WebJs app it becomes this pattern, built from WebJs UI components. Each export of the wrapper maps onto a part:

AI SDK ElementsWebJs UI
CheckpointA marker with markerClass({ variant: 'separator' }) and a marker content, in place of a Separator.
CheckpointIconA marker icon, markerIconClass().
CheckpointTriggerA button with buttonClass({ variant: 'outline', size: 'xs' }), like "Restore". For its tooltip, wrap it in a <ui-tooltip>.