#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"

# Source environment (silently)
source "$PROJECT_DIR/.env" 2>/dev/null || true
source "$PROJECT_DIR/.env.development" 2>/dev/null || true

# Ensure PATH is set
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"

# Find python
PYTHON="${MOMENTRY_PYTHON_PATH:-$PROJECT_DIR/venv/bin/python}"
if [ ! -f "$PYTHON" ]; then
    PYTHON="/opt/homebrew/bin/python3.11"
fi

EMBED_SCRIPT="$PROJECT_DIR/scripts/embeddinggemma_server.py"
exec "$PYTHON" "$EMBED_SCRIPT" --port 11436