Skip to content
2k
On This Page

Checkpoint

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 { For, createMemo } from "solid-js"

import {
  useDemoChat,
  type UIMessage,
  createChat,
  getMessageText
} from "~/lib/ai-demo-chat"
import { Bubble, BubbleContent } from "~/components/ui/bubble"
import { Button } from "~/components/ui/button"
import { Marker, MarkerContent } from "~/components/ui/marker"
import { Message, MessageContent } from "~/components/ui/message"

type ChatMessage = UIMessage<
  unknown,
  {
    checkpoint: {
      label: string
    }
  }
>

type CheckpointPart = Extract<
  ChatMessage["parts"][number],
  { type: "data-checkpoint" }
>

const chat = createChat<ChatMessage>()
  .user("Rename the button component to action.")
  .assistant(({ writer }) => {
    writer.text("Renamed Button to Action in components/ui/button.tsx.")
    writer.data({
      type: "data-checkpoint",
      id: "rename",
      data: { label: "Button renamed" }
    })
  })
  .user("Update the docs to match.")
  .assistant(({ writer }) => {
    writer.text("Updated the Button page to say Action.")
  })

const transcript = chat.get()
const transport = chat.transport({ delayMs: 20 })

export default function CheckpointDemo() {
  const { messages, sendMessage, setMessages, status } = useDemoChat({
    messages: transcript,
    transport
  })
  const nextMessage = () => chat.next(messages())
  const busy = () => status() === "submitted" || status() === "streaming"

  function restore(messageId: string) {
    const index = messages().findIndex((message) => message.id === messageId)

    if (index === -1) {
      return
    }

    setMessages(messages().slice(0, index + 1))
  }

  return (
    <div class="flex min-h-72 w-full max-w-sm flex-col gap-4 py-6 text-sm">
      {
        <For each={messages()}>
          {(message) => {
            const content = createMemo(() => {
              const checkpoint = message.parts.find(
                (part): part is CheckpointPart =>
                  part.type === "data-checkpoint"
              )
              const index = messages().findIndex(
                (item) => item.id === message.id
              )
              const canRestore = index < messages().length - 1

              return (
                <>
                  {message.role === "user" ? (
                    <Message align="end">
                      <MessageContent>
                        <Bubble align="end" variant="muted">
                          <BubbleContent>
                            {getMessageText(message)}
                          </BubbleContent>
                        </Bubble>
                      </MessageContent>
                    </Message>
                  ) : (
                    <Message>
                      <MessageContent>
                        <p>{getMessageText(message)}</p>
                      </MessageContent>
                    </Message>
                  )}
                  {checkpoint && (
                    <Marker variant="separator">
                      <MarkerContent class="inline-flex items-center gap-2">
                        {checkpoint.data.label}
                        {canRestore && (
                          <Button
                            size="xs"
                            variant="outline"
                            aria-label={`Restore to ${checkpoint.data.label}`}
                            onClick={() => restore(message.id)}
                          >
                            Restore
                          </Button>
                        )}
                      </MarkerContent>
                    </Marker>
                  )}
                </>
              )
            })
            return <>{content()}</>
          }}
        </For>
      }
      {!busy() && nextMessage() && (
        <Button
          variant="outline"
          size="sm"
          class="mt-auto self-start"
          onClick={() => sendMessage(nextMessage())}
        >
          Continue
        </Button>
      )}
    </div>
  )
}

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 solidui-cli@latest add marker button

Install the required Solid UI dependencies:

pnpm dlx solidui-cli@latest add marker button

Copy and paste the following code into your project.

components/ui/marker.tsx
import { dynamic, type ComponentProps, type JSX } from "@solidjs/web"
import { cva, type VariantProps } from "class-variance-authority"
import { isStatic, omit } from "solid-js"

import { cn } from "~/lib/utils"

const markerVariants = cva(
  "min-h-4 gap-2 text-left text-sm text-muted-foreground [&_svg:not([class*='size-'])]:size-4 [a]:underline [a]:underline-offset-3 [a]:hover:text-foreground group/marker relative flex w-full items-center",
  {
    variants: {
      variant: {
        default: "",
        separator: "before:mr-1 before:h-px before:min-w-0 before:flex-1 before:bg-border after:ml-1 after:h-px after:min-w-0 after:flex-1 after:bg-border",
        border: "border-b border-border pb-2"
      }
    }
  }
)

export function Marker(
  props: Omit<ComponentProps<"div">, "class"> & {
    class?: string
    variant?: VariantProps<typeof markerVariants>["variant"]
    render?: (
      props: Record<string, unknown> & { class: string; children?: JSX.Element }
    ) => JSX.Element
  }
) {
  const Comp = dynamic(() => props.render ?? "div", {
    static: isStatic(props, "render")
  })
  const rest = omit(props, "class", "variant", "render")
  return (
    <Comp
      data-slot="marker"
      data-variant={props.variant ?? "default"}
      class={cn(
        markerVariants({ variant: props.variant ?? "default" }),
        props.class
      )}
      {...rest}
    />
  )
}

export function MarkerIcon(
  props: Omit<ComponentProps<"span">, "class"> & { class?: string }
) {
  return (
    <span
      {...props}
      data-slot="marker-icon"
      aria-hidden="true"
      class={cn("size-4 [&_svg:not([class*='size-'])]:size-4 shrink-0", props.class)}
    />
  )
}

export function MarkerContent(
  props: Omit<ComponentProps<"span">, "class"> & { class?: string }
) {
  return (
    <span
      {...props}
      data-slot="marker-content"
      class={cn("group-data-[variant=separator]/marker:flex-none group-data-[variant=separator]/marker:text-center *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground min-w-0 wrap-break-word", props.class)}
    />
  )
}

export { markerVariants }

Update the import paths to match your project setup.

Usage

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

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

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.

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

AI SDK Helper

To script a checkpoint with createChat, write it as a data part on the agent’s turn. Send the same id again only when you mean to update that checkpoint.

const chat = createChat()
  .user("Rename the button component to action.")
  .assistant(({ writer }) => {
    writer.text("Renamed Button to Action in components/ui/button.tsx.")
    writer.data({
      type: "data-checkpoint",
      id: "rename",
      data: { label: "Button renamed" }
    })
  })
  .user("Update the docs to match.")
  .assistant(({ writer }) => {
    writer.text("Updated the Button page to say Action.")
  })

Migrating from AI SDK Elements

If you added Checkpoint from AI SDK Elements, your project has a components/ai-elements/checkpoint.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Marker and Button. Every export keeps its name and props, so the code that uses it keeps working.

Prompt
Migrate components/ai-elements/checkpoint.tsx from AI SDK Elements to the Solid UI Marker and Button components.
 
Keep every export, with the same name and props, so the code that imports it keeps working. Only change how each part renders.
 
1. Install the components: npx solidui-cli@latest add marker button
2. Read https://www.solid-ui.com/docs/ai-elements/checkpoint.md and build Checkpoint the same way.
3. Rebuild each part:
   - Checkpoint renders a Marker with variant="separator" and a MarkerContent, instead of a Separator.
   - CheckpointIcon renders a MarkerIcon.
   - CheckpointTrigger renders a Button with size="xs" and variant="outline", like "Restore". Keep its tooltip prop on the Tooltip.
4. Remove the imports the file no longer uses.
5. Run the type checker and fix any errors.