Open History to see the last commit
1import { toolDefinition } from "@tanstack/ai";
2import products from "@/data/products";
3
4export const getProductsToolDef = toolDefinition({
5 name: "getProducts",
6 description: "Get all products from the catalog",
7 inputSchema: {
8 type: "object",
9 properties: {},
10 additionalProperties: false,
11 },
12 outputSchema: {
13 type: "array",
14 items: {
15 type: "object",
16 properties: {
17 id: { type: "number" },
18 name: { type: "string" },
19 image: { type: "string" },
20 description: { type: "string" },
21 shortDescription: { type: "string" },
22 price: { type: "number" },
23 category: {
24 type: "string",
25 enum: ["starter", "tooling", "course", "bundle", "swag"],
26 },
27 },
28 required: [
29 "id",
30 "name",
31 "image",
32 "description",
33 "shortDescription",
34 "price",
35 "category",
36 ],
37 additionalProperties: false,
38 },
39 },
40});
41
42export const getProducts = getProductsToolDef.server(() => products);
43
44export const recommendProductToolDef = toolDefinition({
45 name: "recommendProduct",
46 description:
47 "REQUIRED tool to display a product recommendation to the user. This tool MUST be used whenever recommending a product - do NOT write recommendations yourself. This displays the product in a special format with a view details button.",
48 inputSchema: {
49 type: "object",
50 properties: {
51 id: {
52 oneOf: [{ type: "string" }, { type: "number" }],
53 description:
54 "The ID of the product to recommend (from the getProducts results)",
55 },
56 },
57 required: ["id"],
58 additionalProperties: false,
59 },
60 outputSchema: {
61 type: "object",
62 properties: {
63 id: { type: "number" },
64 },
65 required: ["id"],
66 additionalProperties: false,
67 },
68});