Open History to see the last commit
1import { CompassIcon } from 'lucide-react'
2import type { LayoutProps } from '@tanstack/ai-react/ui'
3import type { ContentPart } from '@tanstack/ai/client'
4import {
5 Conversation,
6 ConversationContent,
7 ConversationEmptyState,
8 ConversationScrollButton,
9} from '@/components/ai/conversation'
10import { Suggestion, Suggestions } from '@/components/ai/suggestions'
11import type { chatOptions } from '@/chat/options'
12import { useChatContext } from './ui-components'
13
14const LISBON_PHOTO =
15 'https://images.unsplash.com/photo-1555881400-74d7acaacd8b?w=800&q=80'
16
17const PROMPTS: Array<{ label: string; content?: Array<ContentPart> }> = [
18 { label: 'Plan 3 days in Lisbon on a comfort budget' },
19 { label: 'Look up the weather in Kyoto' },
20 { label: 'Book 2 nights in Reykjavik' },
21 { label: 'Hold a $240 payment for Lisbon' },
22 {
23 label: 'What city is this photo?',
24 content: [
25 {
26 type: 'text',
27 content: 'What city is this photo? Plan a short stay.',
28 },
29 {
30 type: 'image',
31 source: { type: 'url', value: LISBON_PHOTO },
32 },
33 ],
34 },
35]
36
37export function ChatLayout({
38 Messages,
39 Interrupts,
40 Input,
41 Queue,
42}: LayoutProps<typeof chatOptions>) {
43 const chat = useChatContext()
44 if (chat.error) {
45 return <p className="p-6 text-sm text-destructive">{chat.error.message}</p>
46 }
47
48 return (
49 <div className="flex min-h-0 flex-1 flex-col">
50 <Conversation className="min-h-0">
51 <ConversationContent>
52 {chat.messages.length === 0 ? (
53 <ConversationEmptyState
54 description="Attach a street photo or a PDF, speak a plan, or ask for a city lookup."
55 icon={<CompassIcon className="size-6" />}
56 title="Trip desk"
57 />
58 ) : (
59 <Messages />
60 )}
61 <Interrupts />
62 </ConversationContent>
63 <ConversationScrollButton />
64 </Conversation>
65 <div className="space-y-3 p-4">
66 {chat.messages.length === 0 ? (
67 <Suggestions>
68 {PROMPTS.map((prompt) => (
69 <Suggestion
70 key={prompt.label}
71 onSuggestionClick={() => {
72 if (prompt.content) {
73 void chat.sendMessage({ content: prompt.content })
74 return
75 }
76 void chat.sendMessage(prompt.label)
77 }}
78 suggestion={prompt.label}
79 />
80 ))}
81 </Suggestions>
82 ) : null}
83 {chat.queue.length > 0 ? (
84 <div className="space-y-1">
85 <p className="text-muted-foreground px-1 text-xs font-medium">
86 Queued
87 </p>
88 <div className="space-y-1">
89 <Queue />
90 </div>
91 </div>
92 ) : null}
93 <Input />
94 </div>
95 </div>
96 )
97}