Repository navigation
Upgrade TanStack AI to 1.0, type tool parts, merge client tools on the server - #6
Open
AlemTuzlak wants to merge 2 commits into
Open
AlemTuzlak wants to merge 2 commits into
AlemTuzlak wants to merge 2 commits into
Conversation
- Bump @tanstack/ai, ai-client, ai-react, ai-openrouter, ai-event-client and react-ai-devtools to 1.0.0 and refresh the tracked exercise lockfiles. - 1.0 requires a threadId on useChat and chat(). The chat panels keep one stable id per mounted chat with useState(() => crypto.randomUUID()). - Add threadId to the basic-setup and structured-replies docs, the 01.02 instructions, and the instructor notes.
- Split each tool's definition from its server code (products.ts + products.server.ts, variations.ts + variations.server.ts) so the browser can import definitions without pulling in database code. - The chat panel passes the server tools' definitions and the client tools to useChat, so every tool-call part is a union on part.name with a typed output. Render it with a switch and the components in tool-parts.tsx instead of casting part.output. - From 02.02 on, the server merges the tools the browser declares with mergeAgentTools(serverTools, clientTools). The shared definitions stay listed on the server: the browser's copy carries no needsApproval or output schema, and without the server's copy addToCart runs without asking for approval. - Attendees write the switch from 02.01 and add a case per step, with the ready-made components imported and the line to uncomment in each comment. - Problem files no longer import a definition the attendee hasn't exported yet. Doing that returned a 500 on every page of the store. - Update the tools READMEs and the "If you get stuck" entries to match.
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.
What changed
TanStack AI 1.0
@tanstack/ai*packages bumped to 1.0.0; the 20 tracked exercise lockfiles regenerated (each passesnpm ci --dry-run).threadIdonuseChatandchat(). Every chat panel keeps one stable id per mount withuseState(() => crypto.randomUUID()); every route passesthreadIdthrough. Docs and instructor notes updated.Typed tool parts (02.tools and 03.structured-replies)
app/tools/products.ts+products.server.ts,variations.ts+variations.server.ts. The browser imports definitions only.product-chat.tsxpasses the server tools' definitions plus the.client()tools touseChat({ tools }). Eachtool-callpart is now a union onpart.namewith a typedoutput, rendered with aswitchand the components in the newapp/components/tool-parts.tsx. Thepart.output as {...}andProductCardcasts are gone.switchstarting in 02.01 and add one case per step. The components are imported and the line to uncomment is in each 🐨 comment.Server merges client tools (02.02 onward)
chat({ tools: mergeAgentTools([...serverTools], clientTools) }), withtools: clientToolsfromchatParamsFromRequest. Taught in 02.02, including why a plain[...server, ...client]spread is wrong: the browser sendsparametersbutchat()readsinputSchema, and it would duplicate the server tools.needsApproval,lazyand the output schema come from the server's copy. Checked with a mock adapter: if the server only has the browser's copy ofaddToCart, the browser runs it without asking for approval (only a console warning shows).Problem apps no longer 500
navigateToDef/addToCartDefbefore they existed. The 🐨 comments now say to add that import after building the definition.Review guide
exercises/02.tools/04.solution.make-tools-lazy: the finished pattern.exercises/02.tools/02.problem.taking-the-user-around: where the merge is taught.exercises/03.structured-replies/*copies the 02.04 solution's chat, tool-parts and tool files unchanged.Verification
typecheckin all 20 apps: solutions are clean except the existingapp/epicshop.tsxerror. Problem apps show only the intended "not built yet" errors.node ./epicshop/test.ts ..s: all 10 solution apps pass.approval.approved === false.Not in this PR
app/epicshop.tsxtype error (from@epic-web/workshop-utils).npm run buildfailing on the top-levelawait prisma.$connect().🤖 Generated with Claude Code