diff --git a/README.md b/README.md index c1a03e2c..fd135015 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,57 @@ OPENMEMORY_URL=http://localhost:8080 OPENMEMORY_API_KEY=your-openmemory-key ``` +#### OpenMemory Setup (Optional) + +OpenMemory provides infinite context for AI conversations. The setup script handles everything automatically: + +**Run the setup script**: +```bash +chmod +x services/openmemory-setup.sh +./services/openmemory-setup.sh +``` + +The setup script will: +- **Automatically clone** the OpenMemory backend from [CaviraOSS/OpenMemory](https://github.com/CaviraOSS/OpenMemory) (if not already present) +- **Remove the `.git` directory** from the cloned repo to avoid nested git repositories +- **Create the `.env` file** with default configuration (Gemini embeddings, SQLite database) +- **Install dependencies** using `bun install` +- **Build the TypeScript backend** using `bun run build` + +**Configure OpenMemory**: + +After running the setup script, edit `services/openmemory/backend/.env` and fill in the required variables: + +```bash +# Required: Embedding Provider API Key +# For Gemini (free tier): +OM_GEMINI_API_KEY=your-gemini-api-key + +# Or for OpenAI: +# OM_EMBED_PROVIDER=openai +# OM_OPENAI_API_KEY=your-openai-api-key + +# API Key for OpenMemory (used by Mallory server to authenticate) +OM_API_KEY=your-secure-api-key-here +``` + +**Add to Server Environment**: + +Add these to your `apps/server/.env` file: + +```bash +# OpenMemory Configuration +OPENMEMORY_URL=http://localhost:8080 +OPENMEMORY_API_KEY=your-secure-api-key-here # Must match OM_API_KEY above +``` + +**Start OpenMemory**: +```bash +cd services/openmemory/backend && bun start +``` + +> **Note**: OpenMemory is optional. Mallory works without it, but you'll get better context retention in long conversations if you use it. The backend is cloned from the [CaviraOSS/OpenMemory](https://github.com/CaviraOSS/OpenMemory) repository and is not included in this repo (see `.gitignore`). + ### 3. Run Development Servers #### Option A: Run Both (Client + Server) diff --git a/services/openmemory-setup.sh b/services/openmemory-setup.sh index 3b9aea49..ba979f9c 100755 --- a/services/openmemory-setup.sh +++ b/services/openmemory-setup.sh @@ -3,15 +3,55 @@ echo "๐Ÿš€ Setting up OpenMemory for Mallory..." +# Check if OpenMemory backend directory exists +if [ ! -d "services/openmemory/backend" ]; then + echo "โŒ OpenMemory backend not found!" + echo "" + echo "The OpenMemory backend is not included in this repository." + echo "Cloning OpenMemory backend from CaviraOSS/OpenMemory..." + echo "" + + # Create directory if it doesn't exist + mkdir -p services/openmemory + + # Clone the repository + git clone https://github.com/CaviraOSS/OpenMemory.git services/openmemory/backend + + if [ $? -ne 0 ]; then + echo "โŒ Failed to clone OpenMemory backend!" + echo "Please check your internet connection and try again." + exit 1 + fi + + # Remove .git directory to avoid nested git repository + echo "๐Ÿงน Removing .git directory from cloned repository..." + rm -rf services/openmemory/backend/.git + + echo "โœ… OpenMemory backend cloned successfully!" + echo "" +fi + +# Check if package.json exists +if [ ! -f "services/openmemory/backend/package.json" ]; then + echo "โŒ OpenMemory backend package.json not found!" + echo "" + echo "The backend directory exists but doesn't contain the source code." + echo "Please ensure you've cloned the complete OpenMemory backend repository." + echo "" + exit 1 +fi + # Create .env file if it doesn't exist if [ ! -f services/openmemory/backend/.env ]; then echo "๐Ÿ“ Creating OpenMemory .env file..." + mkdir -p services/openmemory/backend cat > services/openmemory/backend/.env << 'EOF' # OpenMemory Configuration for Mallory +# See README.md for instructions on filling in these variables # Embedding Provider - Using Gemini (free tier!) OM_EMBED_PROVIDER=gemini -OM_GEMINI_API_KEY=${GEMINI_API_KEY} +OM_GEMINI_API_KEY=your-gemini-api-key-here # Server Configuration OM_PORT=8080 @@ -26,27 +66,57 @@ OM_TIER=smart # Vector Dimensions (Gemini) OM_VEC_DIM=768 -# API Key -OM_API_KEY=${OPENMEMORY_API_KEY:-openmemory_dev_key} +# API Key (used by Mallory server to authenticate with OpenMemory) +# Generate a secure random string for production use +OM_API_KEY=your-secure-api-key-here EOF echo "โœ… .env file created" else echo "โœ… .env file already exists" fi +# Install dependencies if node_modules doesn't exist +if [ ! -d "services/openmemory/backend/node_modules" ]; then + echo "๐Ÿ“ฆ Installing OpenMemory dependencies..." + cd services/openmemory/backend + bun install + cd ../../.. +fi + # Build OpenMemory echo "๐Ÿ”จ Building OpenMemory..." cd services/openmemory/backend + +# Check if build script exists in package.json +if ! grep -q '"build"' package.json; then + echo "โŒ 'build' script not found in package.json!" + echo "" + echo "The OpenMemory backend package.json is missing the 'build' script." + echo "Please ensure you've cloned the correct version of the OpenMemory backend." + echo "" + exit 1 +fi + bun run build +if [ $? -ne 0 ]; then + echo "" + echo "โŒ Build failed!" + echo "Please check the error messages above and ensure:" + echo " 1. All dependencies are installed (bun install)" + echo " 2. The OpenMemory backend is up to date" + echo " 3. Required environment variables are set" + exit 1 +fi + echo "" echo "โœ… OpenMemory is ready!" echo "" echo "To start OpenMemory:" echo " cd services/openmemory/backend && bun start" echo "" -echo "Or add to your .env:" -echo " OPENMEMORY_URL=http://localhost:8080" -echo " OPENMEMORY_API_KEY=openmemory_dev_key" -echo " OPENAI_API_KEY=your_openai_key" +echo "๐Ÿ“ Next steps:" +echo " 1. Edit services/openmemory/backend/.env to configure your API keys" +echo " 2. See README.md for required environment variables" +echo " 3. Add OPENMEMORY_URL and OPENMEMORY_API_KEY to your server .env file"