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

server.tsrx

31 lines652 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 threadId: 'thread-1',
16 fetcher: () => {
17 throw new Error('no fetch during SSR');
18 },
19 initialMessages,
20 });
21​
22 <ul id="messages">
23 @for (const message of messages; key message.id) {
24 <li>
25 {message.parts
26 .map((part) => (part.type === 'text' ? part.content : ''))
27 .join('') as string}
28 </li>
29 }
30 </ul>