Open History to see the last commit
1import { toolDefinition } from "@tanstack/ai";
2import { z } from "zod";
3import motorcycles from "@/data/motorcycles";
4
5// Tool definition for getting motorcycles
6export const getMotorcyclesToolDef = toolDefinition({
7 name: "getMotorcycles",
8 description: "Get all motorcycles from the database",
9 inputSchema: z.object({}),
10 outputSchema: z.array(
11 z.object({
12 id: z.number(),
13 name: z.string(),
14 image: z.string(),
15 description: z.string(),
16 shortDescription: z.string(),
17 price: z.number(),
18 engineSize: z.number(),
19 type: z.enum(["scooter", "cruiser", "adventure", "sport", "supersport"]),
20 })
21 ),
22});
23
24// Server implementation
25export const getMotorcycles = getMotorcyclesToolDef.server(() => motorcycles);
26
27// Tool definition for motorcycle recommendation
28export const recommendMotorcycleToolDef = toolDefinition({
29 name: "recommendMotorcycle",
30 description:
31 "REQUIRED tool to display a motorcycle recommendation to the user. This tool MUST be used whenever recommending a motorcycle - do NOT write recommendations yourself. This displays the motorcycle in a special appealing format with a view details button.",
32 inputSchema: z.object({
33 id: z
34 .union([z.string(), z.number()])
35 .describe(
36 "The ID of the motorcycle to recommend (from the getMotorcycles results)"
37 ),
38 }),
39 outputSchema: z.object({
40 id: z.number(),
41 }),
42});