← VercelCONTENT HISTORY

Update to Vercel

Snapshot Sep 30, 2026 · 23:18 UTC · version 0.21.4

Collection source: not recorded for this historical snapshot. These snapshots do not have a confirmed matching collection source. Differences in file lists alone do not establish changes to the package.

WHAT CHANGED · RULE-BASED ANALYSIS

Supporting file metadata differs

Newly listed paths: agents/openai.yaml. This compares saved file lists, not package contents; a different collection source can change the list.

Observed in package metadata. These changes alone do not establish a new customer-facing feature.

Supporting files

Before

[]

After

[{"relative_path":"agents/openai.yaml","size_in_bytes":177}]

Compare saved observations

Download comparison JSON
Full technical diff · 1 changed fields

changed /included_files

BEFORE
[]
AFTER
[
  {
    "relative_path": "agents/openai.yaml",
    "size_in_bytes": 177
  }
]
Full snapshot data
{
  "name": "json-render",
  "description": "AI chat response rendering guidance — handling UIMessage parts, tool call displays, streaming states, and structured data presentation. Use when building custom chat UIs, rendering tool results, or troubleshooting AI response display issues.",
  "included_files": [
    {
      "relative_path": "agents/openai.yaml",
      "size_in_bytes": 177
    }
  ],
  "skill_md_contents": "---\nname: json-render\ndescription: AI chat response rendering guidance — handling UIMessage parts, tool call displays, streaming states, and structured data presentation. Use when building custom chat UIs, rendering tool results, or troubleshooting AI response display issues.\nmetadata:\n  priority: 4\n  docs:\n    - \"https://nextjs.org/docs/app/api-reference/file-conventions/route\"\n  sitemap: \"https://nextjs.org/sitemap.xml\"\n  pathPatterns:\n    - 'components/chat/**'\n    - 'components/chat-*.tsx'\n    - 'components/chat-*.ts'\n    - 'src/components/chat/**'\n    - 'src/components/chat-*.tsx'\n    - 'src/components/chat-*.ts'\n    - 'components/message*.tsx'\n    - 'src/components/message*.tsx'\n  bashPatterns: []\n---\n\n# AI Chat Response Rendering\n\nYou are an expert in rendering AI SDK v6 chat responses — UIMessage parts, tool call results, streaming states, and structured data display in React applications.\n\n## The Problem\n\nWhen building chat interfaces with AI SDK v6, the raw message format includes multiple part types (text, tool calls, reasoning, images). Without proper rendering, responses appear as raw JSON or malformed output.\n\n## AI SDK v6 Message Format\n\nIn v6, messages use the `UIMessage` type with a `parts` array:\n\n```ts\ninterface UIMessage {\n  id: string\n  role: 'user' | 'assistant'\n  parts: UIMessagePart[]\n}\n\n// Part types:\n// - { type: 'text', text: string }\n// - { type: 'tool-<toolName>', toolCallId: string, state: string, input?: unknown, output?: unknown }\n//     state values: 'partial-call' | 'call' | 'output-available' | 'approval-requested' | 'approval-responded' | 'output-denied'\n// - { type: 'reasoning', text: string }\n// - { type: 'step-start' }  // internal, skip in rendering\n```\n\n## Recommended: Use AI Elements\n\nThe simplest approach is to use AI Elements, which handles all part types automatically:\n\n```tsx\nimport { Message } from '@/components/ai-elements/message'\nimport { Conversation } from '@/components/ai-elements/conversation'\n\n{messages.map((message) => (\n  <Message key={message.id} message={message} />\n))}\n```\n\n⤳ skill: ai-elements — Full component library for AI interfaces\n\n## Manual Rendering Pattern\n\nIf you need custom rendering without AI Elements, follow this pattern:\n\n```tsx\n'use client'\nimport { useChat } from '@ai-sdk/react'\nimport { DefaultChatTransport } from 'ai'\n\nexport function Chat() {\n  const { messages, sendMessage, status } = useChat({\n    transport: new DefaultChatTransport({ api: '/api/chat' }),\n  })\n\n  const isLoading = status === 'streaming' || status === 'submitted'\n\n  return (\n    <div>\n      {messages.map((message) => (\n        <div key={message.id}>\n          {message.parts?.map((part, i) => {\n            // 1. Text parts — render as formatted text\n            if (part.type === 'text' && part.text.trim()) {\n              return (\n                <div key={i} className={\n                  message.role === 'user'\n                    ? 'bg-primary text-primary-foreground rounded-lg px-3 py-2'\n                    : 'bg-muted rounded-lg px-3 py-2'\n                }>\n                  {part.text}\n                </div>\n              )\n            }\n\n            // 2. Tool parts — type is \"tool-<toolName>\"\n            if (part.type.startsWith('tool-')) {\n              const toolPart = part as {\n                type: string\n                toolCallId: string\n                state: string\n                input?: unknown\n                output?: unknown\n              }\n              const toolName = toolPart.type.replace('tool-', '')\n\n              if (toolPart.state === 'output-available' && toolPart.output) {\n                return <ToolResultCard key={i} name={toolName} output={toolPart.output} />\n              }\n\n              if (toolPart.state === 'output-denied') {\n                return (\n                  <div key={i} className=\"text-sm text-muted-foreground\">\n                    {toolName} was denied\n                  </div>\n                )\n              }\n\n              if (toolPart.state === 'approval-requested') {\n                return (\n                  <div key={i} className=\"text-sm text-yellow-500\">\n                    {toolName} requires approval\n                  </div>\n                )\n              }\n\n              return (\n                <div key={i} className=\"text-sm text-muted-foreground animate-pulse\">\n                  Running {toolName}...\n                </div>\n              )\n            }\n\n            // 3. Reasoning parts\n            if (part.type === 'reasoning') {\n              return (\n                <details key={i} className=\"text-xs text-muted-foreground\">\n                  <summary>Thinking...</summary>\n                  <p className=\"whitespace-pre-wrap\">{(part as { text: string }).text}</p>\n                </details>\n              )\n            }\n\n            // 4. Skip unknown types (step-start, etc.)\n            return null\n          })}\n        </div>\n      ))}\n    </div>\n  )\n}\n```\n\n## Rendering Tool Results as Cards\n\nInstead of dumping raw JSON, render structured tool output as human-readable cards:\n\n```tsx\nfunction ToolResultCard({ name, output }: { name: string; output: unknown }) {\n  const data = output as Record<string, unknown>\n\n  // Pattern: Check for known result shapes and render accordingly\n  if (data?.success && data?.issue) {\n    const issue = data.issue as { identifier?: string; title?: string }\n    return (\n      <div className=\"rounded border border-border bg-card p-2 text-sm\">\n        <span className=\"font-medium text-green-400\">\n          {name === 'createIssue' ? 'Created' : 'Updated'} {issue.identifier}\n        </span>\n        <p className=\"text-muted-foreground\">{issue.title}</p>\n      </div>\n    )\n  }\n\n  if (data?.items && Array.isArray(data.items)) {\n    return (\n      <div className=\"rounded border border-border bg-card p-2 text-sm\">\n        <p className=\"font-medium\">{data.items.length} results</p>\n        {data.items.slice(0, 5).map((item: Record<string, unknown>, i: number) => (\n          <p key={i} className=\"text-muted-foreground\">{String(item.name || item.title || item.id)}</p>\n        ))}\n      </div>\n    )\n  }\n\n  if (data?.error) {\n    return (\n      <div className=\"rounded border border-destructive/30 bg-destructive/10 p-2 text-sm text-destructive\">\n        {String(data.error)}\n      </div>\n    )\n  }\n\n  // Fallback: simple completion message (not raw JSON)\n  return (\n    <div className=\"rounded border border-border bg-card p-2 text-xs text-muted-foreground\">\n      {name} completed\n    </div>\n  )\n}\n```\n\n## Server-Side Requirements\n\nThe server route must use the correct v6 response format:\n\n```ts\n// app/api/chat/route.ts\nimport { streamText, convertToModelMessages, gateway } from 'ai'\n\nexport async function POST(req: Request) {\n  const { messages } = await req.json()\n\n  // IMPORTANT: convertToModelMessages is async in v6\n  const modelMessages = await convertToModelMessages(messages)\n\n  const result = streamText({\n    model: gateway('anthropic/claude-sonnet-4.6'),\n    messages: modelMessages,\n  })\n\n  // Use toUIMessageStreamResponse for chat UIs (not toDataStreamResponse)\n  return result.toUIMessageStreamResponse()\n}\n```\n\n## Client-Side Requirements\n\n```tsx\nimport { useChat } from '@ai-sdk/react'\nimport { DefaultChatTransport } from 'ai'\n\nconst { messages, sendMessage, status } = useChat({\n  // v6 uses transport instead of api\n  transport: new DefaultChatTransport({ api: '/api/chat' }),\n})\n\n// v6 uses sendMessage instead of handleSubmit\nsendMessage({ text: inputValue })\n\n// Status values: 'ready' | 'submitted' | 'streaming'\nconst isLoading = status === 'streaming' || status === 'submitted'\n```\n\n## Common Mistakes\n\n### 1. Raw JSON in chat responses\n\n**Cause**: Rendering `message.content` instead of iterating `message.parts`.\n\n**Fix**: Always iterate `message.parts` and handle each type:\n\n```tsx\n// WRONG — shows raw JSON\n<div>{message.content}</div>\n\n// RIGHT — renders each part type\n{message.parts?.map((part, i) => {\n  if (part.type === 'text') return <span key={i}>{part.text}</span>\n  // ... handle other types\n})}\n```\n\n### 2. Tool results showing as JSON blobs\n\n**Cause**: Using `JSON.stringify(output)` as the display.\n\n**Fix**: Create structured card components for known tool output shapes.\n\n### 3. \"Invalid prompt: messages do not contain...\" error\n\n**Cause**: Not converting UI messages to model messages on the server.\n\n**Fix**: Use `await convertToModelMessages(messages)` — it's async in v6.\n\n### 4. Messages not appearing / empty responses\n\n**Cause**: Using `toDataStreamResponse()` instead of `toUIMessageStreamResponse()`.\n\n**Fix**: Use `toUIMessageStreamResponse()` when the client uses `useChat` with `DefaultChatTransport`.\n\n### 5. useChat not working with v6\n\n**Cause**: Using the v5 `useChat({ api: '/api/chat' })` pattern.\n\n**Fix**: Use `DefaultChatTransport`:\n\n```tsx\n// v5 (old)\nconst { messages, handleSubmit, input } = useChat({ api: '/api/chat' })\n\n// v6 (current)\nconst { messages, sendMessage, status } = useChat({\n  transport: new DefaultChatTransport({ api: '/api/chat' }),\n})\n```\n\n## Decision Tree\n\n```\nBuilding a chat UI with AI SDK v6?\n  └─ Want pre-built components?\n       └─ Yes → Use AI Elements (⤳ skill: ai-elements)\n       └─ No → Manual rendering with parts iteration\n            └─ Tool results look like JSON?\n                 └─ Create ToolResultCard components for each tool's output shape\n            └─ Text not rendering?\n                 └─ Check part.type === 'text' and use part.text\n            └─ Server errors?\n                 └─ Check: await convertToModelMessages(), toUIMessageStreamResponse()\n```\n\n## Server-Side Message Validation\n\nUse `validateUIMessages` to validate incoming messages before processing:\n\n```ts\nimport { validateUIMessages, convertToModelMessages, streamText, gateway } from 'ai'\n\nexport async function POST(req: Request) {\n  const { messages } = await req.json()\n  const validatedMessages = validateUIMessages(messages)\n  const modelMessages = await convertToModelMessages(validatedMessages)\n  // ...\n}\n```\n\n## Official Documentation\n\n- [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui)\n- [useChat Reference](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot)\n- [UIMessage Types](https://ai-sdk.dev/docs/reference/ai-sdk-core/ui-message)\n- [AI Elements](https://ai-sdk.dev/elements)\n"
}

SHA-256: 8b9eb9000ea59535e588933ad1ada0f0b77718cd2732baefcfb9cc129a226638