Skip to content

Commit 9dd1793

Browse files
jherrautofix-ci[bot]AlemTuzlak
authored
Chunk processing overhaul (#61)
* initial refactor * more fixes and updates * actually debugging the stream processor * better, but still not factored correctly * better factoring * @tanstack/ai reviewed * @tanstack/ai-client reviewed * react-ui review * react-ui review * fixing up tests * ci: apply automated fixes * build fixes * ci: apply automated fixes * small type fix * ci: apply automated fixes * fix tests * ci: apply automated fixes * ci: apply automated fixes * merge resolution * ci: apply automated fixes * fix test fails * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Alem Tuzlak <t.zlak@hotmail.com>
1 parent 51d0d58 commit 9dd1793

190 files changed

Lines changed: 12812 additions & 6187 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ temp
4949

5050
vite.config.js.timestamp-*
5151
vite.config.ts.timestamp-*
52+
test-traces
53+
**/adapters/output
54+
.nitro
55+
.output

docs/api/ai-react.md

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -263,45 +263,6 @@ export function ChatWithClientTools() {
263263
}
264264
```
265265

266-
## `createServerFnTool(config)`
267-
268-
**TanStack Start Integration** - Create a tool that works as both an AI tool and a server function.
269-
270-
```typescript
271-
import { createServerFnTool } from "@tanstack/ai-react/start";
272-
import { z } from "zod";
273-
274-
const getProducts = createServerFnTool({
275-
name: "getProducts",
276-
description: "Search for products",
277-
inputSchema: z.object({
278-
query: z.string(),
279-
}),
280-
outputSchema: z.array(
281-
z.object({
282-
id: z.string(),
283-
name: z.string(),
284-
price: z.number(),
285-
})
286-
),
287-
execute: async ({ query }) => {
288-
return await db.products.search(query);
289-
},
290-
});
291-
292-
// Three variants from one definition:
293-
// 1. getProducts.toolDefinition - Pass to chat() for client execution
294-
// 2. getProducts.server - Pass to chat() for server execution
295-
// 3. await getProducts.serverFn({ query: 'laptop' }) - Call directly
296-
```
297-
298-
**Returns:**
299-
- `toolDefinition` - For client-side tool execution
300-
- `server` - Server tool for AI chat
301-
- `serverFn` - Callable server function with Zod validation
302-
303-
See [Server Function Tools](../guides/server-function-tools.md) for details.
304-
305266
## `createChatClientOptions(options)`
306267

307268
Helper to create typed chat options (re-exported from `@tanstack/ai-client`).
@@ -349,5 +310,4 @@ Re-exported from `@tanstack/ai`:
349310

350311
- [Getting Started](../getting-started/quick-start) - Learn the basics
351312
- [Tools Guide](../guides/tools) - Learn about the isomorphic tool system
352-
- [Server Function Tools](../guides/server-function-tools) - TanStack Start integration
353313
- [Client Tools](../guides/client-tools) - Learn about client-side tools

docs/api/ai-solid.md

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -277,45 +277,6 @@ export function ChatWithClientTools() {
277277
}
278278
```
279279

280-
## `createServerFnTool(config)`
281-
282-
**Solid Start Integration** - Create a tool that works as both an AI tool and a server function.
283-
284-
```typescript
285-
import { createServerFnTool } from "@tanstack/ai-solid/start";
286-
import { z } from "zod";
287-
288-
const getProducts = createServerFnTool({
289-
name: "getProducts",
290-
description: "Search for products",
291-
inputSchema: z.object({
292-
query: z.string(),
293-
}),
294-
outputSchema: z.array(
295-
z.object({
296-
id: z.string(),
297-
name: z.string(),
298-
price: z.number(),
299-
})
300-
),
301-
execute: async ({ query }) => {
302-
return await db.products.search(query);
303-
},
304-
});
305-
306-
// Three variants from one definition:
307-
// 1. getProducts.toolDefinition - Pass to chat() for client execution
308-
// 2. getProducts.server - Pass to chat() for server execution
309-
// 3. await getProducts.serverFn({ query: 'laptop' }) - Call directly
310-
```
311-
312-
**Returns:**
313-
- `toolDefinition` - For client-side tool execution
314-
- `server` - Server tool for AI chat
315-
- `serverFn` - Callable server function with Zod validation
316-
317-
See [Server Function Tools](../guides/server-function-tools.md) for details.
318-
319280
## `createChatClientOptions(options)`
320281

321282
Helper to create typed chat options (re-exported from `@tanstack/ai-client`).
@@ -364,5 +325,4 @@ Re-exported from `@tanstack/ai`:
364325

365326
- [Getting Started](../getting-started/quick-start) - Learn the basics
366327
- [Tools Guide](../guides/tools) - Learn about the isomorphic tool system
367-
- [Server Function Tools](../guides/server-function-tools) - Solid Start integration
368328
- [Client Tools](../guides/client-tools) - Learn about client-side tools

docs/getting-started/overview.md

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,30 @@ TanStack AI works great with:
1111
- **Remix Router v7** - Loaders and actions
1212
- **Any framework** - Framework-agnostic core
1313

14-
## Enhanced with TanStack Start
14+
## Framework Agnostic
1515

16-
TanStack AI works with any framework using `toolDefinition()` and `.server()`.
16+
TanStack AI works with any framework using `toolDefinition()` and `.server()`:
1717

18-
**With TanStack Start**, you get a bonus: `createServerFnTool` lets you share implementations between AI tools and server functions:
19-
20-
**Example:**
2118
```typescript
22-
import { createServerFnTool } from '@tanstack/ai-react/start'
19+
import { toolDefinition } from '@tanstack/ai'
2320

24-
// Define once, get both AI tool AND callable server function
25-
const getProducts = createServerFnTool({
21+
// Define a tool
22+
const getProductsDef = toolDefinition({
2623
name: 'getProducts',
2724
inputSchema: z.object({ query: z.string() }),
2825
outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
29-
execute: async ({ query }) => db.products.search(query),
3026
})
3127

32-
// Use in AI chat
33-
chat({ tools: [getProducts.server] })
28+
// Create server implementation
29+
const getProducts = getProductsDef.server(async ({ query }) => {
30+
return await db.products.search(query)
31+
})
3432

35-
// Call directly from components (TanStack Start only!)
36-
const products = await getProducts.serverFn({ query: 'guitar' })
33+
// Use in AI chat
34+
chat({ tools: [getProducts] })
3735
```
3836

39-
**TanStack Start Benefits:**
40-
- ✅ No duplicate logic between AI tools and server functions
41-
- ✅ Call server functions directly from components (no API endpoints needed)
42-
- ✅ Full type safety everywhere
43-
44-
See [Server Function Tools](../guides/server-function-tools.md) for more details.
45-
46-
**Note:** The base library works with any framework. `createServerFnTool` is optional and TanStack Start-specific.
37+
The base library works with any framework!
4738

4839
## Core Packages
4940

@@ -69,15 +60,13 @@ React hooks for TanStack AI:
6960
- Automatic state management
7061
- Tool approval flow support
7162
- Type-safe message handling with `InferChatMessages`
72-
- `createServerFnTool` for TanStack Start integration
7363

7464
### `@tanstack/ai-solid`
7565
Solid hooks for TanStack AI:
7666
- `useChat` hook for chat interfaces
7767
- Automatic state management
7868
- Tool approval flow support
7969
- Type-safe message handling with `InferChatMessages`
80-
- `createServerFnTool` for Solid Start integration
8170

8271
## Adapters
8372

@@ -94,7 +83,6 @@ TanStack AI supports multiple LLM providers through adapters:
9483
-**Streaming** - Built-in streaming support for real-time responses
9584
-**Isomorphic Tools** - Define once with `toolDefinition()`, implement with `.server()` or `.client()`
9685
-**Framework Agnostic** - Core library works anywhere
97-
-**TanStack Start Integration** - Share logic between AI tools and server functions with `createServerFnTool`
9886
-**Multiple Providers** - OpenAI, Anthropic, Gemini, Ollama, and more
9987
-**Approval Flow** - Built-in support for tool approval workflows
10088
-**Automatic Execution** - Both server and client tools execute automatically
@@ -103,6 +91,5 @@ TanStack AI supports multiple LLM providers through adapters:
10391

10492
- [Quick Start Guide](./quick-start) - Get up and running in minutes
10593
- [Tools Guide](../guides/tools) - Learn about the isomorphic tool system
106-
- [Server Function Tools](../guides/server-function-tools) - TanStack Start integration
10794
- [API Reference](../api/ai) - Explore the full API
10895

docs/getting-started/quick-start.md

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ You now have a working chat application. The `useChat` hook handles:
164164
- Loading states
165165
- Error handling
166166

167-
## Bonus: TanStack Start Integration
167+
## Using Tools
168168

169-
TanStack AI works with any framework. If you're using **TanStack Start** specifically, you get a bonus: `createServerFnTool` lets you share implementations between AI tools and server functions.
169+
TanStack AI works with any framework. Here's how to use tools:
170170

171-
**Standard approach (any framework):**
172171
```typescript
173172
import { toolDefinition } from '@tanstack/ai'
174173

@@ -184,35 +183,8 @@ const getProducts = getProductsDef.server(async ({ query }) => {
184183
chat({ tools: [getProducts] })
185184
```
186185

187-
**TanStack Start bonus:**
188-
```typescript
189-
import { createServerFnTool } from '@tanstack/ai-react/start'
190-
191-
// Get AI tool AND callable server function from one definition
192-
const getProducts = createServerFnTool({
193-
name: 'getProducts',
194-
inputSchema: z.object({ query: z.string() }),
195-
outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
196-
execute: async ({ query }) => db.products.search(query),
197-
})
198-
199-
// Use in AI chat
200-
chat({ tools: [getProducts.server] })
201-
202-
// Call directly from components (TanStack Start only!)
203-
const products = await getProducts.serverFn({ query: 'laptop' })
204-
```
205-
206-
**TanStack Start Benefits:**
207-
- ✅ No duplicate logic between AI tools and server functions
208-
- ✅ Call server functions directly from components
209-
- ✅ No extra API endpoints needed
210-
211-
Learn more in the [Server Function Tools](../guides/server-function-tools.md) guide.
212-
213186
## Next Steps
214187

215188
- Learn about [Tools](../guides/tools) to add function calling
216-
- Explore [Server Function Tools](../guides/server-function-tools) for TanStack Start integration
217189
- Check out [Client Tools](../guides/client-tools) for frontend operations
218190
- See the [API Reference](../api/ai) for more options

0 commit comments

Comments
 (0)