refactor(chat): define chat/ai tools once as framework-agnostic specs - #935
Merged
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
bensabic
added this pull request to stack #937
September 15, 2026 07:06
bensabic
force-pushed
the
tanstack-tool-specs
branch
from
September 15, 2026 07:12
18043e5 to
f7e4ea6
Compare
bensabic
force-pushed
the
tanstack-tool-specs
branch
from
September 15, 2026 23:30
f7e4ea6 to
c4fd013
Compare
dancer
approved these changes
Sep 15, 2026
dancer
approved these changes
Sep 15, 2026
Every tool in chat/ai used to be built directly with the AI SDK's tool() helper. Each one is now a plain ChatToolSpec (name, description, zod input schema, execute), and the AI SDK wrapping happens in one place, tools/ai-sdk.ts. The presets, approval flags and scope guard that createChatTools wires up move to toolset.ts so another framework can reuse them, and the link and attachment handling behind toAiMessages moves to message-content.ts for the same reason. ToolOverrides moves next to the AI SDK wrapper so none of the shared modules reference the ai package. createChatTools, toAiMessages and the standalone tool factories keep their signatures and behavior. Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
bensabic
force-pushed
the
tanstack-tool-specs
branch
from
September 16, 2026 00:12
c4fd013 to
d7aafb0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every tool in
chat/aiwas built directly with the AI SDK'stool()helper, which meant the tool definitions could only ever produce AI SDK tools. This PR separates the definition from the framework so the next PR can offer the same tools to TanStack AI.Each tool is now a plain spec:
and the AI SDK wrapping happens once, in
toAiTool. The presets, approval flags, scope guard, and override filtering thatcreateChatToolswires up move to a shared module, and the link and attachment plumbing behindtoAiMessagesmoves out the same way.Nothing changes for callers.
createChatTools,toAiMessages, and the 17 standalone tool factories keep their signatures, return types, and behavior, and the existing tests are untouched. The examples inexamples/nextjs-chatandexamples/nuxt-chatcompile as before.One relocation worth explaining:
ToolOverridesis an AI SDKPick<Tool, ...>, and it used to live besideChatBindinginai/types.ts. It moves next to the AI SDK wrapper so the shared modules never referenceai, not even as a type. Without that, tsup's declaration chunking pulls animport 'ai'into any entry that shares those modules.Changed files:
ChatToolSpecinterfacetoAiTool, the 17 public wrappers, andToolOverridescreateChatToolson top of the shared piecestoAiMessagesMiddle of a three-PR stack; no changeset of its own since nothing observable changes.