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

tools.ts

48 lines1.2 KB

1import { toolDefinition } from '@tanstack/ai'
2import { z } from 'zod'
3​
4export const lookupPlace = toolDefinition({
5 name: 'lookupPlace',
6 description: 'Look up a place, weather, and citation links.',
7 inputSchema: z.object({ city: z.string() }),
8 outputSchema: z.object({
9 city: z.string(),
10 blurb: z.string(),
11 sources: z.array(z.object({ title: z.string(), url: z.string() })),
12 }),
13})
14​
15export const bookStay = toolDefinition({
16 name: 'bookStay',
17 description: 'Hold a hotel or guesthouse. Needs approval before it runs.',
18 needsApproval: true,
19 inputSchema: z.object({
20 city: z.string(),
21 nights: z.number(),
22 }),
23 outputSchema: z.object({
24 ok: z.boolean(),
25 confirmation: z.string(),
26 }),
27})
28​
29export const confirmPayment = toolDefinition({
30 name: 'confirmPayment',
31 description:
32 'Demo hold for a trip amount. Call this when the user asks to pay or hold a charge. Not a real card charge.',
33 needsApproval: true,
34 inputSchema: z.object({
35 city: z.string(),
36 amount: z.number(),
37 }),
38 outputSchema: z.object({
39 ok: z.boolean(),
40 receipt: z.string(),
41 }),
42})
43​
44export const clientTools = [
45 lookupPlace.client(),
46 bookStay.client(),
47 confirmPayment.client(),