### Install MindCache
Source: https://context7_llms
Install the MindCache library using npm. This is the first step to integrating persistent memory into your AI applications.
```bash
npm install mindcache
```
--------------------------------
### Basic MindCache React App Setup
Source: https://context7_llms
A minimal example of setting up a full AI chat application using MindCache's React components. This includes the `MindCacheProvider` and `MindCacheChat` components.
```tsx
import { MindCacheProvider, MindCacheChat } from 'mindcache';
// Full AI chat app in ~15 lines
function App() {
return (
);
}
```
--------------------------------
### Generate LLM Tools and System Prompt
Source: https://context7_llms
Illustrates how to automatically generate tools for AI SDKs like Vercel AI SDK using `get_aisdk_tools`. It also shows how to retrieve the system prompt.
```typescript
// Auto-generate Vercel AI SDK tools
const tools = mc.get_aisdk_tools();
// For regular keys: write_
// For document keys: write_, append_, insert_, edit_
const prompt = mc.get_system_prompt();
```
--------------------------------
### Implement Undo/Redo Functionality
Source: https://context7_llms
Demonstrates how to use undo and redo operations, both on a per-key basis and globally. Accessing the global history is also shown.
```typescript
mc.undo('key'); // Per-key undo
mc.undoAll(); // Global undo
mc.getGlobalHistory(); // Get history
```
--------------------------------
### Initialize MindCache in Cloud (Real-Time Sync) Mode
Source: https://context7_llms
Initialize MindCache for real-time cloud synchronization. This requires specifying cloud instance details and a token endpoint. Await synchronization after initialization.
```typescript
import { MindCache } from 'mindcache/cloud';
const mc = new MindCache({ cloud: { instanceId: 'xxx', tokenEndpoint: '/api/ws-token' } });
await mc.waitForSync();
```
--------------------------------
### Store and Retrieve Text Values
Source: https://context7_llms
Demonstrates storing and retrieving simple text values using `set_value` and `get_value`. This is the default behavior for storing data.
```typescript
mc.set_value('name', 'Alice');
mc.get_value('name'); // 'Alice'
```
--------------------------------
### Store and Manipulate Document Values
Source: https://context7_llms
Shows how to store and update collaborative documents. Documents can be created with `set_value` or `set_document`, and updated using character-level edits.
```typescript
// Create with set_value
mc.set_value('notes', '# My Notes', { type: 'document' });
// Or use convenience method
mc.set_document('notes', '# My Notes');
// Update (uses diff automatically)
mc.set_value('notes', 'Updated content');
// Character-level edits
mc.insert_text('notes', 0, 'New text');
```
--------------------------------
### Initialize MindCache in Offline (IndexedDB) Mode
Source: https://context7_llms
Initialize MindCache using IndexedDB for local persistence. This mode allows data to persist across browser sessions. Ensure to await synchronization.
```typescript
const mc = new MindCache({ indexedDB: { dbName: 'my-app' } });
await mc.waitForSync();
```
--------------------------------
### MindCache React Hooks Usage
Source: https://context7_llms
Shows how to use various MindCache React hooks to access the MindCache instance, build custom chat UIs, and manage synchronization with GitHub.
```tsx
import { useMindCacheContext, useClientChat, useLocalFirstSync } from 'mindcache';
// Access MindCache instance
const { mindcache, isLoaded, hasApiKey, setApiKey, getModel } = useMindCacheContext();
// Build custom chat UI
const { messages, sendMessage, isLoading, streamingContent } = useClientChat();
// Sync to GitHub
const { status, save, load } = useLocalFirstSync({ mindcache, gitstore: { owner, repo, token } });
```
--------------------------------
### Initialize MindCache in Memory Mode
Source: https://context7_llms
Initialize MindCache in its default 'Memory Only' mode. This mode stores data in RAM and is suitable for simple use cases or testing.
```typescript
import { MindCache } from 'mindcache';
const mc = new MindCache();
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.