summaryrefslogtreecommitdiff
path: root/setup.sh
blob: 42224ce138954ca0f9d96f18f5caca9b43b419f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# MiMo Web Search — Hermes Agent Plugin Setup
# 用法: bash setup.sh [--uninstall]

set -euo pipefail

HERMES_HOME="${HERMES_HOME:-$HOME/.hermes}"
PLUGIN_DIR="$HERMES_HOME/plugins/web/mimo"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m'
ok()   { echo -e "${GREEN}✓${NC} $*"; }
warn() { echo -e "${YELLOW}⚠${NC} $*"; }
fail() { echo -e "${RED}✗${NC} $*" >&2; }

# ── Uninstall ──────────────────────────────────────────────────────
if [[ "${1:-}" == "--uninstall" ]]; then
    echo "Uninstalling MiMo Web Search plugin..."
    command -v hermes &>/dev/null && hermes plugins disable web/mimo 2>/dev/null || true
    rm -rf "$PLUGIN_DIR"
    rm -f "$HOME/test_search.py"
    ok "Done. Restart Hermes session (/reset) to take effect."
    exit 0
fi

# ── Install ────────────────────────────────────────────────────────
echo "Installing MiMo Web Search plugin for Hermes Agent..."

# 1. Pre-flight checks
[[ -d "$HERMES_HOME" ]] || { fail "Hermes not found at $HERMES_HOME"; exit 1; }

if [[ -f "$HERMES_HOME/.env" ]]; then
    grep -q "^XIAOMI_API_KEY=" "$HERMES_HOME/.env" 2>/dev/null \
        && ok "XIAOMI_API_KEY found" \
        || warn "XIAOMI_API_KEY missing in $HERMES_HOME/.env"
else
    warn ".env not found — add XIAOMI_API_KEY before using web search"
fi

# 2. Check httpx dependency
python3 -c "import httpx" 2>/dev/null && ok "httpx available" \
    || { fail "httpx not installed — run: pip install httpx"; exit 1; }

# 3. Install plugin
mkdir -p "$PLUGIN_DIR"
cp "$SCRIPT_DIR/plugin.yaml" "$PLUGIN_DIR/plugin.yaml"
cp "$SCRIPT_DIR/__init__.py" "$PLUGIN_DIR/__init__.py"
cp "$SCRIPT_DIR/provider.py" "$PLUGIN_DIR/provider.py"
ok "Plugin installed → $PLUGIN_DIR"

# 4. Copy test script
cp "$SCRIPT_DIR/test_search.py" "$HOME/test_search.py"
chmod +x "$HOME/test_search.py"
ok "Standalone test script → $HOME/test_search.py"

# 5. Enable in Hermes
if command -v hermes &>/dev/null; then
    hermes plugins enable web/mimo 2>/dev/null && ok "Enabled in Hermes" \
        || warn "Run manually: hermes plugins enable web/mimo"
else
    warn "hermes not in PATH — run: hermes plugins enable web/mimo"
fi

# 6. Done
echo ""
echo "── Next steps ──────────────────────────────────────"
echo "  hermes config set web.search_backend mimo"
echo ""
echo "  Install httpx: pip install httpx  (if not already)"
echo ""
echo "  Standalone test:"
echo "    export XIAOMI_API_KEY=your-key-here"
echo "    python3 ~/test_search.py \"search query\""
echo ""
echo "  /reset                                 # restart session"
echo "────────────────────────────────────────────────────"