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

devtools.md

88 lines2.8 KB

1---
2title: Devtools
3id: devtools
4order: 3
5description: "Inspect and debug TanStack AI apps with the TanStack Devtools panel — live chat messages, tool call inputs and outputs, state, and errors."
6keywords:
7 - tanstack ai
8 - devtools
9 - debugging
10 - tool inspection
11 - chat inspector
12 - react devtools
13 - observability
14---
15​
16TanStack Devtools is a unified devtools panel for inspecting and debugging TanStack libraries, including TanStack AI. It provides real-time insights into AI interactions, tool calls, and state changes, making it easier to develop and troubleshoot AI-powered applications.
17​
18## Features
19- **Real-time Monitoring** - View live chat messages, tool invocations, and AI responses.
20- **Tool Call Inspection** - Inspect input and output of tool calls.
21- **State Visualization** - Visualize chat state and message history.
22- **Error Tracking** - Monitor errors and exceptions in AI interactions.
23​
24## Installation
25To use TanStack Devtools with TanStack AI, install the `@tanstack/react-ai-devtools` package:
26​
27```bash
28npm install -D @tanstack/react-ai-devtools @tanstack/react-devtools
29```
30​
31Or the `@tanstack/solid-ai-devtools` package for SolidJS:
32```bash
33npm install -D @tanstack/solid-ai-devtools @tanstack/solid-devtools
34```
35​
36Or the `@tanstack/preact-ai-devtools` package for Preact:
37```bash
38npm install -D @tanstack/preact-ai-devtools @tanstack/preact-devtools
39```
40​
41## Usage
42​
43Import and include the TanStackDevtools component in your application:
44​
45```tsx
46import { TanStackDevtools } from '@tanstack/react-devtools'
47import { aiDevtoolsPlugin } from '@tanstack/react-ai-devtools'
48​
49const App = () => {
50 return (
51 <>
52 <TanStackDevtools
53 plugins={[
54 // ... other plugins
55 aiDevtoolsPlugin(),
56 ]}
57 // this config is important to connect to the server event bus
58 eventBusConfig={{
59 connectToServerBus: true,
60 }}
61 />
62 </>
63 )
65```
66​
67## Using with Next.js (or without a Vite plugin)
68​
69`connectToServerBus: true` relies on a WebSocket/SSE server on port 4206 that is normally started by `@tanstack/devtools-vite`. If you're using Next.js (or any non-Vite bundler), you need to start `ServerEventBus` manually at server boot.
70​
71In Next.js, do this in `instrumentation.ts`:
72​
73```ts
74export async function register() {
75 if (
76 process.env["NEXT_RUNTIME"] === "nodejs" &&
77 process.env.NODE_ENV === "development"
78 ) {
79 const { ServerEventBus } = await import(
80 "@tanstack/devtools-event-bus/server"
81 );
82 const bus = new ServerEventBus();
83 await bus.start();
84 }
86```
87​
88This sets globalThis.__TANSTACK_EVENT_TARGET__ so the server-side devtoolsMiddleware (which runs automatically inside every chat() call) can emit tool call events to the bus, which then forwards them to the devtools panel.