TanStack AI 是一个轻量级、类型安全的 SDK,用于构建生产就绪的 AI 体验。其框架无关的核心提供了类型安全的工具/函数调用、流式响应以及一流的 React 和 Solid 集成,并提供多种 LLM 提供商的适配器——从而能够在任何堆栈上实现可预测、可组合和可测试的 AI 功能。
TanStack AI 的框架无关核心提供了在任何环境中创建 AI 体验的构建块,包括
TanStack AI 允许您定义一个工具,并提供特定于环境的实现。使用 toolDefinition() 声明工具的输入/输出类型以及使用 .server() 的服务器行为(或使用 .client() 的客户端实现)。这些同构工具可以从 AI 运行时调用,而与框架无关。
import { chat } from '@tanstack/ai'
import { toolDefinition } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
// Define a tool
const getProductsDef = toolDefinition({
name: 'getProducts',
inputSchema: z.object({ query: z.string() }),
outputSchema: z.array(z.object({ id: z.string(), name: z.string() })),
})
// Create server implementation
const getProducts = getProductsDef.server(async ({ query }) => {
return await db.products.search(query)
})
// Use in AI chat
chat({
adapter: openaiText('gpt-5.2'),
messages: [{ role: 'user', content: 'Find products' }],
tools: [getProducts]
})
TanStack AI 生态系统由多个包组成
提供以下功能的 AI 核心库
用于管理聊天状态的框架无关的无头客户端
用于 TanStack AI 的 React 钩子
用于 TanStack AI 的 Solid 钩子
借助适配器,TanStack AI 可以连接到各种 LLM 提供商。可用的适配器包括