diff --git a/apps/www/content/2.components/checkpoint.md b/apps/www/content/2.components/checkpoint.md new file mode 100644 index 0000000..74d74da --- /dev/null +++ b/apps/www/content/2.components/checkpoint.md @@ -0,0 +1,312 @@ +--- +title: Checkpoint +description: A simple component for marking conversation history points and restoring the chat to a previous state. +icon: lucide:flag +--- + +The `Checkpoint` component provides a way to mark specific points in a conversation history and restore the chat to that state. Inspired by VSCode's Copilot checkpoint feature, it allows users to revert to an earlier conversation state while maintaining a clear visual separation between different conversation segments. + +:::ComponentLoader{label="Preview" componentName="Checkpoint"} +::: + +## Install using CLI + +::tabs{variant="card"} + ::div{label="ai-elements-vue"} + ```sh + npx ai-elements-vue@latest add checkpoint + ``` + :: + ::div{label="shadcn-vue"} + + ```sh + npx shadcn-vue@latest add https://registry.ai-elements-vue.com/checkpoint.json + ``` + :: +:: + +## Install Manually + +Copy and paste the following code in the same folder. + +:::code-group +```vue [Checkpoint.vue] + + + +``` + +```vue [CheckpointIcon.vue] + + + +``` + +```vue [CheckpointTrigger.vue] + + + +``` + +```ts [index.ts] +export { default as Checkpoint } from './Checkpoint.vue' +export { default as CheckpointIcon } from './CheckpointIcon.vue' +export { default as CheckpointTrigger } from './CheckpointTrigger.vue' +``` +::: + +## Features + +- Simple flex layout with icon, trigger, and separator +- Visual separator line for clear conversation breaks +- Clickable restore button for reverting to checkpoint +- Customizable icon (defaults to BookmarkIcon) +- Keyboard accessible with proper ARIA labels +- Responsive design that adapts to different screen sizes +- Seamless light/dark theme integration + +## Usage with AI SDK + +Build a chat interface with conversation checkpoints that allow users to restore to previous states. + +Add the following component to your frontend: + +```vue [pages/index.vue] + + + +``` + +## Use Cases + +### Manual Checkpoints + +Allow users to manually create checkpoints at important conversation points: + +```vue + +``` + +### Automatic Checkpoints + +Create checkpoints automatically after significant conversation milestones: + +```tsx +watch( + () => messages.value.length, + (length) => { + // Create checkpoint every 5 messages + if (length > 0 && length % 5 === 0) { + createCheckpoint(length - 1) + } + } +) +``` + +### Branching Conversations + +Use checkpoints to enable conversation branching where users can explore different conversation paths: + +```tsx +function restoreAndBranch(messageIndex: number) { + // Save current branch + const currentBranch = messages.value.slice(messageIndex + 1) + saveBranch(currentBranch) + + // Restore to checkpoint + restoreToCheckpoint(messageIndex) +} +``` + +## Props + +### `` + +:::field-group + ::field{name="class" type="string" defaultValue="''"} + The class name to apply to the component. + :: +::: + +### `` + +:::field-group + ::field{name="class" type="string" defaultValue="''"} + The class name to apply to the component. + :: +::: + +### `` + +:::field-group + ::field{name="tooltip" type="string" defaultValue="''"} + The tooltip text to display when the trigger is hovered. + :: + ::field{name="variant" type="string" defaultValue="'ghost'"} + The variant of the button (e.g., 'ghost', 'outline', 'solid'). + :: + ::field{name="size" type="string" defaultValue="'sm'"} + The size of the button (e.g., 'sm', 'md', 'lg'). + :: +::: diff --git a/apps/www/plugins/ai-elements.ts b/apps/www/plugins/ai-elements.ts index afe782c..fedeb12 100644 --- a/apps/www/plugins/ai-elements.ts +++ b/apps/www/plugins/ai-elements.ts @@ -3,6 +3,7 @@ import { ActionsHover, Branch, ChainOfThought, + Checkpoint, CodeBlock, CodeBlockDark, Conversation, @@ -68,4 +69,5 @@ export default defineNuxtPlugin((nuxtApp) => { vueApp.component('InlineCitation', InlineCitation) vueApp.component('CodeBlock', CodeBlock) vueApp.component('CodeBlockDark', CodeBlockDark) + vueApp.component('Checkpoint', Checkpoint) }) diff --git a/packages/elements/src/checkpoint/Checkpoint.vue b/packages/elements/src/checkpoint/Checkpoint.vue new file mode 100644 index 0000000..aba4509 --- /dev/null +++ b/packages/elements/src/checkpoint/Checkpoint.vue @@ -0,0 +1,19 @@ + + + diff --git a/packages/elements/src/checkpoint/CheckpointIcon.vue b/packages/elements/src/checkpoint/CheckpointIcon.vue new file mode 100644 index 0000000..31529d9 --- /dev/null +++ b/packages/elements/src/checkpoint/CheckpointIcon.vue @@ -0,0 +1,22 @@ + + + diff --git a/packages/elements/src/checkpoint/CheckpointTrigger.vue b/packages/elements/src/checkpoint/CheckpointTrigger.vue new file mode 100644 index 0000000..cda315c --- /dev/null +++ b/packages/elements/src/checkpoint/CheckpointTrigger.vue @@ -0,0 +1,43 @@ + + + diff --git a/packages/elements/src/checkpoint/index.ts b/packages/elements/src/checkpoint/index.ts new file mode 100644 index 0000000..b7acb04 --- /dev/null +++ b/packages/elements/src/checkpoint/index.ts @@ -0,0 +1,3 @@ +export { default as Checkpoint } from './Checkpoint.vue' +export { default as CheckpointIcon } from './CheckpointIcon.vue' +export { default as CheckpointTrigger } from './CheckpointTrigger.vue' diff --git a/packages/elements/src/index.ts b/packages/elements/src/index.ts index 2e9e507..b747dba 100644 --- a/packages/elements/src/index.ts +++ b/packages/elements/src/index.ts @@ -1,6 +1,7 @@ export * from './actions' export * from './branch' export * from './chain-of-thought' +export * from './checkpoint' export * from './code-block' export * from './conversation' export * from './image' diff --git a/packages/examples/src/checkpoint.vue b/packages/examples/src/checkpoint.vue new file mode 100644 index 0000000..4789f4f --- /dev/null +++ b/packages/examples/src/checkpoint.vue @@ -0,0 +1,87 @@ + + + diff --git a/packages/examples/src/index.ts b/packages/examples/src/index.ts index fd38924..418e240 100644 --- a/packages/examples/src/index.ts +++ b/packages/examples/src/index.ts @@ -2,6 +2,7 @@ export { default as ActionsHover } from './actions-hover.vue' export { default as Actions } from './actions.vue' export { default as Branch } from './branch.vue' export { default as ChainOfThought } from './chain-of-thought.vue' +export { default as Checkpoint } from './checkpoint.vue' export { default as CodeBlockDark } from './code-block-dark.vue' export { default as CodeBlock } from './code-block.vue' export { default as Conversation } from './conversation.vue'