Skip to content

Commit 0909845

Browse files
committed
feat: add branch component
1 parent 6c09f91 commit 0909845

File tree

19 files changed

+838
-3
lines changed

19 files changed

+838
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ AI Elements Vue includes the following components:
8787
| `response` | ✅ 已完成 | Formatted AI response display |
8888
| `prompt-input` | ✅ 已完成 | Advanced input component with model selection |
8989
| `actions` | ✅ 已完成 | Interactive action buttons for AI responses |
90-
| `branch` | ❌ 未完成 | Branch visualization for conversation flows |
90+
| `branch` | ✅ 已完成 | Branch visualization for conversation flows |
9191
| `code-block` | ❌ 未完成 | Syntax-highlighted code display with copy functionality |
9292
| `image` | ❌ 未完成 | AI-generated image display component |
9393
| `inline-citation` | ❌ 未完成 | Inline source citations |

apps/test/app/examples/branch.vue

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<script setup lang="ts">
2+
import { Branch, BranchMessages, BranchNext, BranchPage, BranchPrevious, BranchSelector } from '@repo/elements/branch'
3+
import { Message, MessageAvatar, MessageContent } from '@repo/elements/message'
4+
import { nanoid } from 'nanoid'
5+
6+
interface SimpleMessage {
7+
id: string
8+
content: string
9+
}
10+
11+
const userMessages: SimpleMessage[] = [
12+
{ id: nanoid(), content: 'What are the key strategies for optimizing Vue performance?' },
13+
{ id: nanoid(), content: 'How can I improve the performance of my Vue application?' },
14+
{ id: nanoid(), content: 'What performance optimization techniques should I use in Vue?' },
15+
]
16+
17+
const assistantMessages: SimpleMessage[] = [
18+
{ id: nanoid(), content: 'Here\'s the first response to your question. This approach focuses on performance optimization.' },
19+
{ id: nanoid(), content: 'Here\'s an alternative response. This approach emphasizes code readability and maintainability over pure performance.' },
20+
{ id: nanoid(), content: 'And here\'s a third option. This balanced approach considers both performance and maintainability, making it suitable for most use cases.' },
21+
]
22+
23+
function handleBranchChange(branchIndex: number) {
24+
// eslint-disable-next-line no-console
25+
console.log('Branch changed to:', branchIndex)
26+
}
27+
</script>
28+
29+
<template>
30+
<div class="space-y-8">
31+
<Branch :default-branch="0" :on-branch-change="handleBranchChange">
32+
<BranchMessages>
33+
<Message v-for="message in userMessages" :key="message.id" from="user">
34+
<MessageContent>{{ message.content }}</MessageContent>
35+
<MessageAvatar name="Hayden Bleasel" src="https://github.com/haydenbleasel.png" />
36+
</Message>
37+
</BranchMessages>
38+
<BranchSelector from="user">
39+
<BranchPrevious />
40+
<BranchPage />
41+
<BranchNext />
42+
</BranchSelector>
43+
</Branch>
44+
45+
<Branch :default-branch="0" :on-branch-change="handleBranchChange">
46+
<BranchMessages>
47+
<Message v-for="message in assistantMessages" :key="message.id" from="assistant">
48+
<MessageContent>{{ message.content }}</MessageContent>
49+
<MessageAvatar name="AI" src="https://github.com/openai.png" />
50+
</Message>
51+
</BranchMessages>
52+
<BranchSelector from="assistant">
53+
<BranchPrevious />
54+
<BranchPage />
55+
<BranchNext />
56+
</BranchSelector>
57+
</Branch>
58+
</div>
59+
</template>

apps/test/app/pages/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { Card, CardContent, CardHeader, CardTitle } from '@repo/shadcn-vue/components/ui/card'
33
import ActionsHover from '~/examples/actions-hover.vue'
44
import Actions from '~/examples/actions.vue'
5+
import Branch from '~/examples/branch.vue'
56
import Conversation from '~/examples/conversation.vue'
67
import MessageMarkdown from '~/examples/message-markdown.vue'
78
import Message from '~/examples/message.vue'
@@ -11,6 +12,7 @@ import Response from '~/examples/response.vue'
1112
const components = [
1213
{ name: 'Message', Component: Message },
1314
{ name: 'Actions', Component: Actions },
15+
{ name: 'Branch', Component: Branch },
1416
{ name: 'ActionsHover', Component: ActionsHover },
1517
{ name: 'PromptInput', Component: PromptInput },
1618
{ name: 'Conversation', Component: Conversation },

apps/www/content/1.overview/1.Introduction.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ You can install it with:
2727
:::ComponentLoader{label="Actions" componentName="Actions"}
2828
:::
2929

30+
:::ComponentLoader{label="Branch" componentName="Branch"}
31+
:::
32+
3033
View the [source code](https://github.com/cwandev/ai-elements-vue) for all components on GitHub.

0 commit comments

Comments
 (0)