useChatStorage
useChatStorage(
options:object):UseChatStorageResult
Defined in: src/expo/useChatStorage.ts:664
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 |
|
|
|
Tool set names that should expand unconditionally for this request,
bypassing the anchor-similarity check. Use when conversation state
implies a set should be present regardless of how the prompt is phrased
— e.g., pass Read via a ref so updates are visible to in-flight Names must match a set’s |
|
|
|
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 |
|
|
Builds the chat storage backend (default: this | |
|
|
|
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”) |
|
|
|
Device tools that can finish a turn the portal completed while the device was away: their executors run when that answer is stored. Pass the display tools and the memory save tool. |
|
|
Function for silent signing with Privy embedded wallets. | |
|
|
|
Embedding model to use when autoEmbedMessages is enabled. Default |
|
|
|
Enable the in-memory write queue. Default |
|
|
|
Additional tool sets to apply on top of the built-in ones (app-generation, slides, github). When any anchor tool in a custom set is selected by semantic matching, all members of that set are included automatically. Treated as static config — set once at hook setup. Changing it across
renders does not affect in-flight |
|
|
{ |
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.
|
|
|
|
Fold persisted Defaults to With it off, rows are dropped from the replayed history rather than sent verbatim. Verbatim
would put two consecutive |
|
|
() => |
Function to retrieve the auth token for API requests |
|
|
() => |
Async function to poll for wallet address during Privy initialization. |
|
|
|
Run lifecycle hooks for telemetry and tracing, for example from |
|
|
The vault inbox that receives answers finished while no client was attached. | |
|
|
|
R2 domain for identifying MCP-generated image URLs. When set, enables OPFS caching of generated images. Defaults to the hardcoded MCP_R2_DOMAIN from clientConfig. |
|
|
|
Route memory operations through this store; |
|
|
|
Minimum content length required to generate embeddings. Messages shorter than this are skipped as they provide limited semantic value. Default |
|
|
|
Optional on-device NER detector for unstructured PII (names, locations,
organizations) that regex can’t catch. When supplied AND |
|
|
( |
Observability for the fire-and-forget cancel POST that |
|
|
( |
Callback invoked with each streamed response chunk |
|
|
( |
Callback invoked when an error occurs during the request |
|
|
( |
Callback invoked when the response completes successfully |
|
|
( |
Called with the PII matches found whenever outbound messages are redacted.
Only fired when |
|
|
( |
Callback invoked when a server-side tool (MCP) is called during streaming. Use this to show activity indicators like “Searching…” in the UI. |
|
|
( |
Observe the stream metadata the portal issues at HEADERS_RECEIVED, once per
round. Forwarded to the underlying |
|
|
( |
Callback invoked when thinking/reasoning content is received (from |
|
|
( |
Called with partial tool call arguments as they stream in. Use for live preview of artifacts (HTML, slides) being generated. |
|
|
( |
Observability hook fired once per send with the tools actually selected for the turn (after server + client filtering). Never throws into the send path. Mirrors react’s onToolSelection. |
|
|
|
Enable best-effort, client-side PII obfuscation (NOT a compliance guarantee). Outbound message text is scanned for personally identifiable information and replaced with tagged placeholders before reaching the LLM provider; responses are de-anonymized automatically. Embedding inputs and the summarization prompt are redacted too. Regex-based detection does not cover names, non-text content, or tool-call arguments.
|
|
|
Pre-processors run after the last user message is received but before
the first LLM request. Each receives the prompt text and a shared
embedding (computed once per request) and may return messages to
enrich the conversation. Forwarded to the underlying | |
|
|
|
Opt into resumable streaming. When Default |
|
|
{ |
Configuration for the server tools cache and tool selection. |
|
|
|
Cache backend; defaults to localStorage with a memory fallback on platforms without localStorage. |
|
|
|
Cache expiration time in milliseconds (default: 86400000 = 1 day) |
|
|
|
Opt-in defer-loading (Phase 3). OFF by default → tools are sent exactly as today. When
|
|
|
Function to sign a message for encryption key derivation. | |
|
|
|
Output pacing forwarded to useChat. Set false when the UI batches streamed updates. |
|
|
|
Tool names whose persisted results must never be replayed to the model. A turn’s auto-executed tool results are stored as a synthetic
Hook-level rather than per-send on purpose: an exclusion that has to be remembered at every call site is one bad send away from leaking. |
|
|
|
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 '@anuma/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: 'fireworks/accounts/fireworks/models/kimi-k2p5',
includeHistory: true,
});
};
return (
<View>
<Button onPress={handleSend} disabled={isLoading} title="Send" />
</View>
);
}