Open History to see the last commit
1<script setup lang="ts">
2import { ref, watch, nextTick } from 'vue'
3import { marked } from 'marked'
4import type { UIMessage } from '@tanstack/ai-client'
5import ThinkingPart from './ThinkingPart.vue'
6import GuitarRecommendation from './GuitarRecommendation.vue'
7
8// Using readonly any[] to accept deep readonly messages from useChat
9const props = defineProps<{
10 messages: readonly any[]
11}>()
12
13const containerRef = ref<HTMLDivElement>()
14
15// Auto-scroll to bottom when messages change
16watch(
17 () => props.messages,
18 async () => {
19 await nextTick()
20 if (containerRef.value) {
21 containerRef.value.scrollTop = containerRef.value.scrollHeight
22 }
23 },
24 { deep: true },
25)
26
27const renderMarkdown = (content: string) => {
28 return marked(content, { async: false }) as string
29}
30
31const isThinkingComplete = (message: UIMessage, partIndex: number) => {
32 return message.parts.slice(partIndex + 1).some((p) => p.type === 'text')
33}
34</script>
35
36<template>
37 <div
38 v-if="messages.length"
39 ref="containerRef"
40 class="flex-1 overflow-y-auto px-4 py-4"
41 >
42 <div
43 v-for="message in messages"
44 :key="message.id"
45 :class="[
46 'p-4 rounded-lg mb-2',
47 message.role === 'assistant'
48 ? 'bg-gradient-to-r from-orange-500/5 to-red-600/5'
49 : 'bg-transparent',
50 ]"
51 >
52 <div class="flex items-start gap-4">
53 <!-- Avatar -->
54 <div
55 v-if="message.role === 'assistant'"
56 class="w-8 h-8 rounded-lg bg-gradient-to-r from-orange-500 to-red-600 flex items-center justify-center text-sm font-medium text-white shrink-0"
57 >
58 AI
59 </div>
60 <div
61 v-else
62 class="w-8 h-8 rounded-lg bg-gray-700 flex items-center justify-center text-sm font-medium text-white shrink-0"
63 >
64 U
65 </div>
66
67 <!-- Message content -->
68 <div class="flex-1 min-w-0">
69 <template v-for="(part, index) in message.parts" :key="index">
70 <!-- Thinking part -->
71 <div v-if="part.type === 'thinking'" class="mt-2 mb-2">
72 <ThinkingPart
73 :content="part.content"
74 :is-complete="isThinkingComplete(message, index)"
75 />
76 </div>
77
78 <!-- Text part -->
79 <div
80 v-else-if="part.type === 'text' && part.content"
81 class="text-white prose max-w-none"
82 v-html="renderMarkdown(part.content)"
83 />
84
85 <!-- Guitar recommendation -->
86 <div
87 v-else-if="
88 part.type === 'tool-call' &&
89 part.name === 'recommendGuitar' &&
90 part.output
91 "
92 class="mt-2"
93 >
94 <GuitarRecommendation :id="part.output?.id" />
95 </div>
96 </template>
97 </div>
98 </div>
99 </div>
100 </div>
101</template>