Spaces:
Running
Running
Z User commited on
Commit ·
5e3d05b
1
Parent(s): 76db36c
fix: WeChat session persistence - auto-reconnect after gateway restart
Browse files- config.yaml: add weixin platform (enabled, dm_policy: open)
- start.sh: auto-discover WEIXIN_ACCOUNT_ID from persisted accounts dir
- entry.py: add weixin to _ensure_persistent_storage()
- Dockerfile: install aiohttp + cryptography (weixin deps)
- Dockerfile +2 -1
- config.yaml +5 -0
- entry.py +2 -2
- start.sh +19 -0
Dockerfile
CHANGED
|
@@ -15,7 +15,8 @@ RUN python3 -m venv /app/venv
|
|
| 15 |
ENV PATH="/app/venv/bin:$PATH"
|
| 16 |
RUN pip install --quiet --upgrade pip && \
|
| 17 |
pip install --quiet psutil networkx && \
|
| 18 |
-
pip install --quiet -e "/app/hermes-agent[feishu,mcp,cron,pty]"
|
|
|
|
| 19 |
|
| 20 |
# Patch: add document file extensions to auto-detection for native delivery
|
| 21 |
COPY scripts/patch_file_delivery.py /tmp/patch_file_delivery.py
|
|
|
|
| 15 |
ENV PATH="/app/venv/bin:$PATH"
|
| 16 |
RUN pip install --quiet --upgrade pip && \
|
| 17 |
pip install --quiet psutil networkx && \
|
| 18 |
+
pip install --quiet -e "/app/hermes-agent[feishu,mcp,cron,pty]" && \
|
| 19 |
+
pip install --quiet aiohttp cryptography 2>&1 | tail -10
|
| 20 |
|
| 21 |
# Patch: add document file extensions to auto-detection for native delivery
|
| 22 |
COPY scripts/patch_file_delivery.py /tmp/patch_file_delivery.py
|
config.yaml
CHANGED
|
@@ -10,6 +10,11 @@ platforms:
|
|
| 10 |
extra:
|
| 11 |
domain: feishu
|
| 12 |
connection_mode: websocket
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
api_server:
|
| 14 |
enabled: true
|
| 15 |
extra:
|
|
|
|
| 10 |
extra:
|
| 11 |
domain: feishu
|
| 12 |
connection_mode: websocket
|
| 13 |
+
weixin:
|
| 14 |
+
enabled: true
|
| 15 |
+
extra:
|
| 16 |
+
dm_policy: open
|
| 17 |
+
group_policy: disabled
|
| 18 |
api_server:
|
| 19 |
enabled: true
|
| 20 |
extra:
|
entry.py
CHANGED
|
@@ -265,13 +265,13 @@ def _log_tailer():
|
|
| 265 |
# ---------------------------------------------------------------------------
|
| 266 |
|
| 267 |
def _ensure_persistent_storage():
|
| 268 |
-
for d in ("sessions", "memories", "uploads", "logs", "palace", "skills"):
|
| 269 |
os.makedirs(os.path.join(DATA_DIR, d), exist_ok=True)
|
| 270 |
|
| 271 |
hermes = Path(HERMES_HOME)
|
| 272 |
hermes.mkdir(parents=True, exist_ok=True)
|
| 273 |
|
| 274 |
-
for d in ("sessions", "memories", "uploads", "logs", "palace", "skills"):
|
| 275 |
target = hermes / d
|
| 276 |
if not target.exists():
|
| 277 |
try:
|
|
|
|
| 265 |
# ---------------------------------------------------------------------------
|
| 266 |
|
| 267 |
def _ensure_persistent_storage():
|
| 268 |
+
for d in ("sessions", "memories", "uploads", "logs", "palace", "skills", "weixin"):
|
| 269 |
os.makedirs(os.path.join(DATA_DIR, d), exist_ok=True)
|
| 270 |
|
| 271 |
hermes = Path(HERMES_HOME)
|
| 272 |
hermes.mkdir(parents=True, exist_ok=True)
|
| 273 |
|
| 274 |
+
for d in ("sessions", "memories", "uploads", "logs", "palace", "skills", "weixin"):
|
| 275 |
target = hermes / d
|
| 276 |
if not target.exists():
|
| 277 |
try:
|
start.sh
CHANGED
|
@@ -33,6 +33,25 @@ if [ ! -L "$WEIXIN_DIR" ]; then
|
|
| 33 |
echo "Symlink: weixin -> /data/hermes/weixin"
|
| 34 |
fi
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
echo "Persistent storage ready."
|
| 37 |
|
| 38 |
# ── Persist WebUI credentials across rebuilds ──
|
|
|
|
| 33 |
echo "Symlink: weixin -> /data/hermes/weixin"
|
| 34 |
fi
|
| 35 |
|
| 36 |
+
# Auto-discover WeChat account_id from persisted session files
|
| 37 |
+
# The QR login flow saves credentials to ~/.hermes/weixin/accounts/<account_id>.json
|
| 38 |
+
# We export it as WEIXIN_ACCOUNT_ID so the gateway picks it up without manual config
|
| 39 |
+
if [ -z "$WEIXIN_ACCOUNT_ID" ]; then
|
| 40 |
+
ACCOUNTS_DIR="/data/hermes/weixin/accounts"
|
| 41 |
+
if [ -d "$ACCOUNTS_DIR" ]; then
|
| 42 |
+
LATEST=$(find "$ACCOUNTS_DIR" -name "*.json" ! -name "*.context-tokens.json" ! -name "*.sync.json" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1 | awk '{print $2}')
|
| 43 |
+
if [ -n "$LATEST" ]; then
|
| 44 |
+
DISCOVERED_ID=$(basename "$LATEST" .json)
|
| 45 |
+
export WEIXIN_ACCOUNT_ID="$DISCOVERED_ID"
|
| 46 |
+
echo "Auto-discovered WEIXIN_ACCOUNT_ID=$DISCOVERED_ID"
|
| 47 |
+
else
|
| 48 |
+
echo "No WeChat account files found in $ACCOUNTS_DIR"
|
| 49 |
+
fi
|
| 50 |
+
else
|
| 51 |
+
echo "WeChat accounts directory not found (first-time QR login needed)"
|
| 52 |
+
fi
|
| 53 |
+
fi
|
| 54 |
+
|
| 55 |
echo "Persistent storage ready."
|
| 56 |
|
| 57 |
# ── Persist WebUI credentials across rebuilds ──
|