Open History to see the last commit
1import { toolDefinition } from '@tanstack/ai'
2import { z } from 'zod'
3import guitars from '@/data/example-guitars'
4
5// Tool definition for getting guitars
6export const getGuitarsToolDef = toolDefinition({
7 name: 'getGuitars',
8 description: 'Get all products 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 }),
19 ),
20})
21
22// Server implementation
23export const getGuitars = getGuitarsToolDef.server(() => guitars)
24
25// Tool definition for guitar recommendation
26export const recommendGuitarToolDef = toolDefinition({
27 name: 'recommendGuitar',
28 description:
29 'REQUIRED tool to display a guitar recommendation to the user. This tool MUST be used whenever recommending a guitar - do NOT write recommendations yourself. This displays the guitar in a special appealing format with a buy button.',
30 inputSchema: z.object({
31 id: z
32 .union([z.string(), z.number()])
33 .describe(
34 'The ID of the guitar to recommend (from the getGuitars results)',
35 ),
36 }),
37 outputSchema: z.object({
38 id: z.number(),
39 }),
40})