Open History to see the last commit
1import {
2 fetchServerSentEvents,
3 useChat,
4 createChatClientOptions,
5} from "@tanstack/ai-react";
6import type { InferChatMessages } from "@tanstack/ai-react";
7import { clientTools } from "@tanstack/ai-client";
8
9import { recommendMotorcycleToolDef } from "@/lib/motorcycle-tools";
10
11const recommendMotorcycleToolClient = recommendMotorcycleToolDef.client(
12 ({ id }) => ({
13 id: +id,
14 })
15);
16
17const chatOptions = createChatClientOptions({
18 connection: fetchServerSentEvents("/api/motorcycle-chat"),
19 tools: clientTools(recommendMotorcycleToolClient),
20});
21
22export type ChatMessages = InferChatMessages<typeof chatOptions>;
23
24export const useMotorcycleChat = () => useChat(chatOptions);