Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

server.tsrx

30 lines628 Bytes

1import { useChat } from '@tanstack/ai-octane';
2import type { UIMessage } from '@tanstack/ai-octane';
3​
4const initialMessages: UIMessage[] = [
5 {
6 id: 'msg-1',
7 role: 'user',
8 parts: [{ type: 'text', content: 'Hello Ada' }],
9 createdAt: new Date(0),
10 },
11];
12​
13export function ServerChat() @{
14 const { messages } = useChat({
15 fetcher: () => {
16 throw new Error('no fetch during SSR');
17 },
18 initialMessages,
19 });
20​
21 <ul id="messages">
22 @for (const message of messages; key message.id) {
23 <li>
24 {message.parts
25 .map((part) => (part.type === 'text' ? part.content : ''))
26 .join('') as string}
27 </li>
28 }
29 </ul>