diff --git a/packages/react-native/.eslintrc.js b/packages/react-native/.eslintrc.js new file mode 100644 index 000000000000..a7f4ef45f804 --- /dev/null +++ b/packages/react-native/.eslintrc.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['eslint-config-vercel-ai'], +}; diff --git a/packages/react-native/CHANGELOG.md b/packages/react-native/CHANGELOG.md new file mode 100644 index 000000000000..0415c3b3464c --- /dev/null +++ b/packages/react-native/CHANGELOG.md @@ -0,0 +1,11 @@ +# @ai-sdk/react-native + +## 0.0.1 + +### Features + +- Initial release with markdown tree streaming support +- `useMarkdownChat` hook for React Native +- `MarkdownRenderer` component +- Server-side markdown parsing utilities +- JSON patch-based efficient updates diff --git a/packages/react-native/README.md b/packages/react-native/README.md new file mode 100644 index 000000000000..7fea42d9ff7a --- /dev/null +++ b/packages/react-native/README.md @@ -0,0 +1,398 @@ +# AI SDK React Native + +React Native optimized utilities for the [AI SDK](https://ai-sdk.dev/docs). + +## Overview + +This package provides React Native-specific optimizations for the AI SDK, including efficient markdown rendering. It re-exports all hooks from `@ai-sdk/react` so you can use the same API you're familiar with. + +### Key Features + +- **Same API as `@ai-sdk/react`** - `useChat`, `useCompletion`, `useObject` all work the same +- **Optimized markdown rendering** - Parse markdown to JSON trees for efficient native rendering +- **Full agent support** - Tools, multi-step, reasoning, and all other parts work as expected +- **Server-side parsing option** - For maximum performance, parse on the server and stream trees + +## Installation + +```bash +npm install @ai-sdk/react-native +``` + +## Usage + +### Basic Chat with Markdown + +```tsx +import { useChat } from '@ai-sdk/react-native'; +import { MarkdownText } from '@ai-sdk/react-native'; +import { View, Text, TextInput, Button, ScrollView } from 'react-native'; + +function ChatScreen() { + const { messages, input, handleInputChange, handleSubmit, status } = useChat({ + api: '/api/chat', + }); + + return ( + + + {messages.map(message => ( + + {message.role} + {message.parts.map((part, index) => { + switch (part.type) { + case 'text': + // Use MarkdownText for efficient markdown rendering + return ; + + case 'reasoning': + return ( + + Thinking... + + + ); + + default: + return null; + } + })} + + ))} + + + + +