Showing release lookup cards in Vercel AI SDK chat
Use a Jekyll version lookup to see how Vercel AI SDK represents tool calls and results, then render pending, successful, and failed states in chat.
I added a Jekyll version lookup to a streaming chat and rendered its progress and result as a card. A missing release and a broken lookup produce different messages, even when both leave the user without release notes.
I tested with Node.js 22.23.3,
ai7.0.185, Zod 4.6.7, and React and React DOM 19.3.1.MockLanguageModelV4replayed the model events. The installed packages handled validation, streaming, and rendering.
Give the lookup its own space
The streaming release-note summary displayed chunks of text as they arrived. A version lookup adds information the user can act on before the model finishes its sentence. They can see which version the tool received and open the release page when the record arrives. I kept the conversation text and rendered the lookup as a card beside it.
The data came from the public Jekyll 4.4.0 release. I fixed the test input to three changes so I could verify the card content by inspection. The release raised the minimum supported Ruby version to 2.7, added a way to pick highlighted code lines through Liquid, and declared csv, base64, and json as runtime dependencies. The card reads its version, notes, and source link from the lookup result. The model can explain those fields in a separate response. Jekyll 4.4.0 release
Follow a call from the server to the card
I registered lookupRelease as a read-only server tool. The model generates the tool name and a version argument. AI SDK checks the argument against the Zod input schema before it reaches execute. The function looks in a local data set with one record and returns a result with a found field. The server owns the data lookup in this arrangement. The roles are the same as in the function-calling overview. AI SDK tool calling
On the server, toUIMessageStream converts the events from streamText into UI messages. createUIMessageStreamResponse sends them as server-sent events (SSE). The chat message’s parts array can then contain both text and a tool-lookupRelease part. That part takes its name from the key used to register the tool. The input and output share a toolCallId, which makes a sensible React key for the card within the message. The identity stays stable as an unfinished call becomes a result. Chatbot tool usage · UI stream protocol
Render the states the message reports
| Tool part state | Card content |
|---|---|
input-streaming | Show that the lookup is being prepared. |
input-available | Show the version the server will look up. |
output-available | Show the release facts and link, or explain that the local data has no match. |
output-error | Show a short error message for an invalid argument or failed execution. |
The partial input can contain an apparent version before the provider has finished sending it. I used input-available as the point to show a specific version in the card. When a provider streams argument deltas, the preparing state can appear first. A provider that sends the whole call at once can move directly to the complete input. Once the SDK reports output-available, I use the found field to decide which content belongs in the card. Chatbot tool usage
Pass the tool-lookupRelease parts to the component below. In the parent rendering the message, use toolCallId as the React key so the same card updates as the call progresses. Export LookupTools from lookup-tools as InferUITools<typeof tools> using the server’s tool definitions. This snippet uses just the version and URL from a successful lookup.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import type { ToolUIPart } from 'ai';
import type { LookupTools } from './lookup-tools';
export function ReleaseLookupCard({ part }: { part: ToolUIPart<LookupTools> }) {
switch (part.state) {
case 'input-streaming':
return <p>Preparing lookup…</p>;
case 'input-available':
return <p>Looking up Jekyll {part.input.version}…</p>;
case 'output-available':
return part.output.found
? <a href={part.output.url}>Jekyll {part.output.version} release notes</a>
: <p>No release found.</p>;
case 'output-error':
return <p>Release lookup failed.</p>;
default:
return null;
}
}
The read-only example falls through to the default branch for approval states. If the tool needs approval, give the approval request and decision their own UI. Chat tool states
Figure 1. Browser capture of four card states rendered by React from AI SDK events replayed with a local mock model.
Check four outcomes in the local stream
I passed the SSE response through DefaultChatTransport and used readUIMessageStream to inspect the message snapshots. React rendered each distinct state to static HTML. In each scenario, one card represented the tool call. The initial “Checking the release” message and a short follow-up remained two separate text parts.
| Input and test condition | Observed event and result |
|---|---|
Known version 4.4.0 | tool-output-available produced a card with Jekyll 4.4.0 and the release link. |
Well-formed version 9.9.9 absent from the data | tool-output-available produced a card that explicitly said the local data had no record. |
| Lookup deliberately throws | tool-output-error produced an error card with public-facing text. |
Argument latest fails schema validation | tool-input-error became output-error on the UI part. The lookup function ran zero times. |
The test limited the model to two steps. The first produced the tool call. The test verified that the second received the corresponding tool result with the same call ID. The card could render as soon as that result arrived, and the second step’s text updated independently. A scripted test makes these transitions repeatable under all four conditions. It tells me how the integration behaves for those inputs. Provider model selection and generation quality would need a separate measurement. Testing with AI SDK
Decide what belongs in a result card
| What the user needs | How I would display it |
|---|---|
| A summary to read | Append text parts as they arrive. |
| Progress, a version number, and a source link | Render those fields from the tool part. |
| An action requiring the user’s permission | Define server-side authorization and an approval flow before adding the control. |
The tool returned only the version, public release notes, and source URL needed by the card. For execution errors, I configured the stream conversion to send a short public message. I would also review what the model receives as a tool result and what the server records. The browser error text covers one path where internal details can surface. An application that looks up user-specific records still has to check access on the server.
- Keep the card keyed to the tool call as its state changes.
- Give a missing record and a failed lookup their own messages.
- Confirm invalid arguments stop at schema validation before the lookup runs.