From 7386cdaae5a787288016779ad8ea1768d70d3fb7 Mon Sep 17 00:00:00 2001 From: Ankush Malaker <43288948+AnkushMalaker@users.noreply.github.com> Date: Tue, 21 Oct 2025 01:01:53 +0000 Subject: [PATCH 1/2] Remove deprecated cache initialization scripts and update docker-compose to use official OpenMemory MCP image. --- extras/openmemory-mcp/.gitignore | 1 - extras/openmemory-mcp/docker-compose.yml | 6 +- extras/openmemory-mcp/init-cache.sh | 31 -------- extras/openmemory-mcp/setup.sh | 99 ------------------------ 4 files changed, 2 insertions(+), 135 deletions(-) delete mode 100644 extras/openmemory-mcp/.gitignore delete mode 100755 extras/openmemory-mcp/init-cache.sh delete mode 100755 extras/openmemory-mcp/setup.sh diff --git a/extras/openmemory-mcp/.gitignore b/extras/openmemory-mcp/.gitignore deleted file mode 100644 index 6e25fa8f..00000000 --- a/extras/openmemory-mcp/.gitignore +++ /dev/null @@ -1 +0,0 @@ -cache/ \ No newline at end of file diff --git a/extras/openmemory-mcp/docker-compose.yml b/extras/openmemory-mcp/docker-compose.yml index 4107cf4a..5b57a3a2 100644 --- a/extras/openmemory-mcp/docker-compose.yml +++ b/extras/openmemory-mcp/docker-compose.yml @@ -8,11 +8,9 @@ services: - ./data/mem0_storage:/qdrant/storage restart: unless-stopped - # OpenMemory MCP Server (built from local cache) + # OpenMemory MCP Server (official image) openmemory-mcp: - build: - context: ./cache/mem0/openmemory/api - dockerfile: Dockerfile + image: mem0/openmemory-mcp:latest env_file: - .env environment: diff --git a/extras/openmemory-mcp/init-cache.sh b/extras/openmemory-mcp/init-cache.sh deleted file mode 100755 index 18ec6f6f..00000000 --- a/extras/openmemory-mcp/init-cache.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# Initialize or update local cached mem0 from Ankush's fork - -CACHE_DIR="./cache/mem0" -FORK_REPO="https://github.com/AnkushMalaker/mem0.git" -BRANCH="fix/get-endpoint" - -echo "šŸ”„ Updating OpenMemory cache from fork..." - -if [ ! -d "$CACHE_DIR/.git" ]; then - echo "šŸ“„ Initializing cache from fork..." - rm -rf "$CACHE_DIR" - git clone "$FORK_REPO" "$CACHE_DIR" - cd "$CACHE_DIR" - git checkout "$BRANCH" - echo "āœ… Cache initialized from $FORK_REPO ($BRANCH)" -else - echo "šŸ”„ Updating existing cache..." - cd "$CACHE_DIR" - git fetch origin - git checkout "$BRANCH" - git pull origin "$BRANCH" - echo "āœ… Cache updated from $FORK_REPO ($BRANCH)" -fi - -echo "" -echo "šŸ“‚ Cache directory: $(pwd)" -echo "🌿 Current branch: $(git branch --show-current)" -echo "šŸ“ Latest commit: $(git log --oneline -1)" -echo "" -echo "šŸš€ Ready to build! Run: docker compose build openmemory-mcp --no-cache" \ No newline at end of file diff --git a/extras/openmemory-mcp/setup.sh b/extras/openmemory-mcp/setup.sh deleted file mode 100755 index 555720ec..00000000 --- a/extras/openmemory-mcp/setup.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash - -# Enable strict error handling -set -euo pipefail - -# Parse command line arguments -OPENAI_API_KEY="" - -while [[ $# -gt 0 ]]; do - case $1 in - --openai-api-key) - OPENAI_API_KEY="$2" - shift 2 - ;; - *) - echo "Unknown argument: $1" - exit 1 - ;; - esac -done - -echo "🧠 OpenMemory MCP Setup" -echo "======================" - -# Check if already configured -if [ -f ".env" ]; then - echo "āš ļø .env already exists. Backing up..." - cp .env .env.backup.$(date +%Y%m%d_%H%M%S) -fi - -# Start from template - check existence first -if [ ! -r ".env.template" ]; then - echo "Error: .env.template not found or not readable" >&2 - exit 1 -fi - -# Copy template and set secure permissions -if ! cp .env.template .env; then - echo "Error: Failed to copy .env.template to .env" >&2 - exit 1 -fi - -# Set restrictive permissions (owner read/write only) -chmod 600 .env - -# Clone the custom fork of mem0 with OpenMemory fixes -echo "" -echo "šŸ“¦ Setting up custom mem0 fork with OpenMemory..." -if [ -d "cache/mem0" ]; then - echo " Removing existing mem0 directory..." - rm -rf cache/mem0 -fi - -echo " Cloning mem0 fork from AnkushMalaker/mem0..." -mkdir -p cache -git clone https://github.com/AnkushMalaker/mem0.git cache/mem0 -cd cache/mem0 -echo " Checking out fix/get-endpoint branch..." -git checkout fix/get-endpoint -cd ../.. - -echo "āœ… Custom mem0 fork ready with OpenMemory improvements" - -# Get OpenAI API Key (prompt only if not provided via command line) -if [ -z "$OPENAI_API_KEY" ]; then - echo "" - echo "šŸ”‘ OpenAI API Key (required for memory extraction)" - echo "Get yours from: https://platform.openai.com/api-keys" - while true; do - read -s -r -p "OpenAI API Key: " OPENAI_API_KEY - echo # Print newline after silent input - if [ -n "$OPENAI_API_KEY" ]; then - break - fi - echo "Error: OpenAI API Key cannot be empty. Please try again." - done -else - echo "āœ… OpenAI API key configured from command line" -fi - -# Update .env file safely using awk - replace existing line or append if missing -temp_file=$(mktemp) -awk -v key="$OPENAI_API_KEY" ' - /^OPENAI_API_KEY=/ { print "OPENAI_API_KEY=" key; found=1; next } - { print } - END { if (!found) print "OPENAI_API_KEY=" key } -' .env > "$temp_file" -mv "$temp_file" .env - -echo "" -echo "āœ… OpenMemory MCP configured!" -echo "šŸ“ Configuration saved to .env" -echo "" -echo "šŸš€ To start: docker compose up --build -d" -echo "🌐 MCP Server: http://localhost:8765" -echo "šŸ“± Web Interface: http://localhost:8765" -echo "šŸ”§ UI (optional): docker compose --profile ui up -d" -echo "" -echo "šŸ’” Note: Using custom mem0 fork from AnkushMalaker/mem0:fix/get-endpoint" \ No newline at end of file From a2c2511085fa186a7f2c5ed2a253039072dbf7c0 Mon Sep 17 00:00:00 2001 From: Ankush Malaker <43288948+AnkushMalaker@users.noreply.github.com> Date: Tue, 21 Oct 2025 01:33:40 +0000 Subject: [PATCH 2/2] Update OpenMemory MCP service to use run.sh and enhance environment variable handling in setup scripts --- Docs/init-system.md | 4 ++-- extras/openmemory-mcp/run.sh | 24 ++++++++++++++++++++-- wizard.py | 39 +++++++++++++++++++++++------------- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/Docs/init-system.md b/Docs/init-system.md index c4bcf0d1..ea9d6df3 100644 --- a/Docs/init-system.md +++ b/Docs/init-system.md @@ -29,8 +29,8 @@ The root orchestrator handles service selection and delegates configuration to i ### Service Scripts - **Backend**: `backends/advanced/init.py` - Complete Python-based interactive setup - **Speaker Recognition**: `extras/speaker-recognition/setup.sh` - Simple bash setup -- **ASR Services**: `extras/asr-services/setup.sh` - Service startup script -- **OpenMemory MCP**: `extras/openmemory-mcp/setup.sh` - External server startup +- **ASR Services**: `extras/asr-services/setup.sh` - Service startup script +- **OpenMemory MCP**: `extras/openmemory-mcp/run.sh` - External server startup (uses official Docker image) ## Usage diff --git a/extras/openmemory-mcp/run.sh b/extras/openmemory-mcp/run.sh index 1cc0bf21..6f285478 100755 --- a/extras/openmemory-mcp/run.sh +++ b/extras/openmemory-mcp/run.sh @@ -8,15 +8,35 @@ echo "šŸš€ Starting OpenMemory MCP installation for Friend-Lite..." OPENAI_API_KEY="${OPENAI_API_KEY:-}" USER="${USER:-$(whoami)}" -# Check for .env file first +# Check for .env file first, load if exists if [ -f .env ]; then echo "šŸ“ Loading configuration from .env file..." export $(cat .env | grep -v '^#' | xargs) +else + # Create .env from template if it doesn't exist + if [ -f .env.template ]; then + echo "šŸ“ Creating .env from template..." + cp .env.template .env + fi +fi + +# If OPENAI_API_KEY is provided via environment but not in .env, write it +if [ -n "$OPENAI_API_KEY" ] && [ -f .env ]; then + # Update or add OPENAI_API_KEY in .env file + if grep -q "^OPENAI_API_KEY=" .env 2>/dev/null; then + # Key exists, update it + sed -i "s|^OPENAI_API_KEY=.*|OPENAI_API_KEY=${OPENAI_API_KEY}|" .env + else + # Key doesn't exist, append it + echo "OPENAI_API_KEY=${OPENAI_API_KEY}" >> .env + fi + echo "āœ… Updated .env with provided OPENAI_API_KEY" fi +# Final check if [ -z "$OPENAI_API_KEY" ]; then echo "āŒ OPENAI_API_KEY not set." - echo " Option 1: Create a .env file from .env.template and add your key" + echo " Option 1: Edit .env file and add your key" echo " Option 2: Run with: OPENAI_API_KEY=your_api_key ./run.sh" echo " Option 3: Export it: export OPENAI_API_KEY=your_api_key" exit 1 diff --git a/wizard.py b/wizard.py index cfc5b861..279845d6 100755 --- a/wizard.py +++ b/wizard.py @@ -4,6 +4,7 @@ Handles service selection and delegation only - no configuration duplication """ +import os import subprocess import sys from datetime import datetime @@ -73,7 +74,7 @@ def is_placeholder(value, *placeholder_variants): }, 'openmemory-mcp': { 'path': 'extras/openmemory-mcp', - 'cmd': ['./setup.sh'], + 'cmd': ['./run.sh'], 'description': 'OpenMemory MCP server' } } @@ -90,6 +91,11 @@ def check_service_exists(service_name, service_config): script_path = service_path / 'init.py' if not script_path.exists(): return False, f"Script {script_path} does not exist" + elif service_name == 'openmemory-mcp': + # OpenMemory MCP uses run.sh + script_path = service_path / 'run.sh' + if not script_path.exists(): + return False, f"Script {script_path} does not exist" else: # For other extras, check if setup.sh exists script_path = service_path / 'setup.sh' @@ -152,28 +158,31 @@ def cleanup_unselected_services(selected_services): def run_service_setup(service_name, selected_services, https_enabled=False, server_ip=None): """Execute individual service setup script""" + # Initialize env_vars for all services + env_vars = None + if service_name == 'advanced': service = SERVICES['backend'][service_name] - + # For advanced backend, pass URLs of other selected services and HTTPS config cmd = service['cmd'].copy() if 'speaker-recognition' in selected_services: cmd.extend(['--speaker-service-url', 'http://host.docker.internal:8085']) if 'asr-services' in selected_services: cmd.extend(['--parakeet-asr-url', 'http://host.docker.internal:8767']) - + # Add HTTPS configuration if https_enabled and server_ip: cmd.extend(['--enable-https', '--server-ip', server_ip]) - + else: service = SERVICES['extras'][service_name] cmd = service['cmd'].copy() - + # Add HTTPS configuration for services that support it if service_name == 'speaker-recognition' and https_enabled and server_ip: cmd.extend(['--enable-https', '--server-ip', server_ip]) - + # For speaker-recognition, try to pass API keys and config if available if service_name == 'speaker-recognition': # Pass Deepgram API key from backend if available @@ -195,29 +204,31 @@ def run_service_setup(service_name, selected_services, https_enabled=False, serv if compute_mode in ['cpu', 'gpu']: cmd.extend(['--compute-mode', compute_mode]) console.print(f"[blue][INFO][/blue] Found existing COMPUTE_MODE ({compute_mode}), reusing") - - # For openmemory-mcp, try to pass OpenAI API key from backend if available + + # For openmemory-mcp, prepare environment variables if service_name == 'openmemory-mcp': backend_env_path = 'backends/advanced/.env' openai_key = read_env_value(backend_env_path, 'OPENAI_API_KEY') if openai_key and not is_placeholder(openai_key, 'your_openai_api_key_here', 'your-openai-api-key-here', 'your_openai_key_here', 'your-openai-key-here'): - cmd.extend(['--openai-api-key', openai_key]) + env_vars = os.environ.copy() + env_vars['OPENAI_API_KEY'] = openai_key console.print("[blue][INFO][/blue] Found existing OPENAI_API_KEY from backend config, reusing") - + console.print(f"\nšŸ”§ [bold]Setting up {service_name}...[/bold]") - + # Check if service exists before running exists, msg = check_service_exists(service_name, service) if not exists: console.print(f"āŒ {service_name} setup failed: {msg}") return False - + try: result = subprocess.run( - cmd, + cmd, cwd=service['path'], check=True, - timeout=300 # 5 minute timeout for service setup + timeout=300, # 5 minute timeout for service setup + env=env_vars ) console.print(f"āœ… {service_name} setup completed")