useChatStorage
useChatStorage(
options:object):UseChatStorageResult
Defined in: src/expo/useChatStorage.ts:250
A React hook that wraps useChat with automatic message persistence using WatermelonDB.
Expo/React Native version - This is a lightweight version that only supports API-based chat completions. Local chat and client-side tools are not available.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
|
|
Configuration options |
|
|
|
Which API endpoint to use. Default: “responses”
|
|
|
|
Automatically create a new conversation if none is set (default: true) |
|
|
|
Automatically generate embeddings for messages after saving. Enables semantic search over past conversations via searchMessages(). Default |
|
|
|
Auto-flush queued operations when key becomes available. Default |
|
|
|
Base URL for the chat API endpoint |
|
|
|
ID of an existing conversation to load and continue |
|
|
|
WatermelonDB database instance for storing conversations and messages |
|
|
|
Title for auto-created conversations (default: “New conversation”) |
|
|
Function for silent signing with Privy embedded wallets. | |
|
|
|
Embedding model to use when autoEmbedMessages is enabled. Default |
|
|
|
Enable the in-memory write queue. Default |
|
|
{ |
Options for file preprocessing behavior |
|
|
|
Whether to keep original file attachments (default: true) |
|
|
|
Max file size to process in bytes (default: 10MB) |
|
|
( |
Callback for errors (non-fatal) |
|
|
( |
Callback for progress updates |
|
|
|
File preprocessors to use for automatic text extraction.
|
|
|
() => |
Function to retrieve the auth token for API requests |
|
|
() => |
Async function to poll for wallet address during Privy initialization. |
|
|
|
Minimum content length required to generate embeddings. Messages shorter than this are skipped as they provide limited semantic value. Default |
|
|
( |
Callback invoked with each streamed response chunk |
|
|
( |
Callback invoked when an error occurs during the request |
|
|
( |
Callback invoked when the response completes successfully |
|
|
( |
Callback invoked when a server-side tool (MCP) is called during streaming. Use this to show activity indicators like “Searching…” in the UI. |
|
|
( |
Callback invoked when thinking/reasoning content is received (from |
|
|
{ |
Configuration for server-side tools fetching and caching. Server tools are fetched from /api/v1/tools and cached in localStorage. |
|
|
|
Cache expiration time in milliseconds (default: 86400000 = 1 day) |
|
|
Function to sign a message for encryption key derivation. | |
|
|
|
Wallet address for field-level encryption. When provided with signMessage, all sensitive content is encrypted at rest. |
Returns
An object containing chat state, methods, and storage operations
Example
import { Database } from '@nozbe/watermelondb';
import { useChatStorage } from '@reverbia/sdk/expo';
function ChatScreen({ database }: { database: Database }) {
const {
isLoading,
sendMessage,
conversationId,
getMessages,
} = useChatStorage({
database,
getToken: async () => getAuthToken(),
onData: (chunk) => setResponse((prev) => prev + chunk),
});
const handleSend = async () => {
const result = await sendMessage({
content: 'Hello!',
model: 'gpt-4o-mini',
includeHistory: true,
});
};
return (
<View>
<Button onPress={handleSend} disabled={isLoading} title="Send" />
</View>
);
}