Open History to see the last commit
1import { toolDefinition } from '@tanstack/ai'
2import { z } from 'zod'
3
4/**
5 * Isomorphic tool DEFINITION shared by the server and the browser.
6 *
7 * The server attaches the implementation with `.server(...)`; the client passes
8 * this same definition to `useChat({ tools })`. Sharing one definition means the
9 * approval interrupt's schema hashes match on both sides, so the browser can
10 * bind the pending approval and resolve it. `needsApproval` pauses the run for a
11 * human yes/no before the tool runs — persisted by `withPersistence`, so the
12 * pending decision survives a reload.
13 */
14export const sendEmailTool = toolDefinition({
15 name: 'sendEmail',
16 description:
17 'Send an email on the user’s behalf. Pauses for the user to approve.',
18 needsApproval: true,
19 inputSchema: z.object({
20 to: z.string().describe('Recipient email address'),
21 subject: z.string(),
22 body: z.string(),
23 }),
24 outputSchema: z.object({ messageId: z.string(), to: z.string() }),
25})