Support for Predefined Tags in StreamingText with AI SDK for Component Rendering in useChat streaming decoding #3630
Description
Feature Description
I would like to request a feature in the AI SDK to enhance useChat by supporting predefined tags within StreamingText. The goal is to enable the SDK to recognize specific tags in the streaming response and render appropriate components based on tag types. This functionality would be beneficial for applications that require dynamic rendering of content based on metadata tags, similar to the predefined tags described below.
Proposed Feature
The proposed feature would support tag parsing and component rendering in useChat using StreamingText.
Use Cases
Tag Examples and Desired Behavior:
- type field:
Function: Determines the type of content (e.g., text, image, or interactive message).
Example:
{"type": "NARRATION", "text": "The printing press, invented by Johannes Gutenberg..."}
Desired Render: Display as a regular text component in the streaming output.
- text field with Markdown formatting:
Function: Renders rich text with Markdown support.
Example:
{"text": "The printing press, invented by Johannes Gutenberg..."}
Desired Render: Automatically parse Markdown (e.g., bold text) for rich-text display.
- searchQuery and relatedResultIds fields:
Function: Enables search or related content links.
Example:
{"searchQuery": "Gutenberg printing press"}
Desired Render: Render as a link or button that triggers an external search based on the query.
Additional context
Implementing this feature would:
Enhance interactivity within useChat by enabling dynamic content display based on metadata.
Improve user engagement by allowing seamless rendering of rich text, images, links, and buttons directly in StreamingText.
Simplify front-end development, enabling developers to easily build sophisticated UIs that adapt based on content type without manual parsing.
**
Please note that it differs from the tool callback component rendering. It is quite similar to the tags used by Claude, which are predicted by the LLM and can be parsed into a component during rendering.
**