Z User commited on
Commit
aa686c9
·
1 Parent(s): 189ae90

feat: enable auto-send of document files (.md, .pdf, .docx, etc.)

Browse files

Hermes could send images/videos as native attachments, but NOT documents.
The extract_local_files() method only recognized image/video extensions.

This patch adds support for auto-detecting and sending as native attachments:
- Documents: .md, .txt, .csv, .json, .xml, .yaml, .log, .pdf, .doc/.docx, .xls/.xlsx, .ppt/.pptx, .html
- Audio: .ogg, .opus, .mp3, .wav, .m4a, .silk, .flac
- Archives: .zip, .tar, .gz, .7z, .rar
- Images: added .bmp, .svg

Now when Hermes creates a weather_report.md, it will be sent as a native
file attachment on both Feishu and WeChat automatically.

Files changed (2) hide show
  1. Dockerfile +5 -0
  2. scripts/patch_file_delivery.py +81 -0
Dockerfile CHANGED
@@ -17,6 +17,11 @@ RUN pip install --quiet --upgrade pip && \
17
  pip install --quiet psutil networkx && \
18
  pip install --quiet -e "/app/hermes-agent[feishu,mcp,cron,pty]" 2>&1 | tail -10
19
 
 
 
 
 
 
20
  # Install Node.js 23
21
  RUN ARCH=$(dpkg --print-architecture) \
22
  && if [ "$ARCH" = "amd64" ]; then NODE_ARCH="x64"; else NODE_ARCH="$ARCH"; fi \
 
17
  pip install --quiet psutil networkx && \
18
  pip install --quiet -e "/app/hermes-agent[feishu,mcp,cron,pty]" 2>&1 | tail -10
19
 
20
+ # Patch: add document file extensions to auto-detection for native delivery
21
+ # This enables Hermes to send .md, .pdf, .docx, .xlsx etc. as native attachments
22
+ COPY scripts/patch_file_delivery.py /tmp/patch_file_delivery.py
23
+ RUN python3 /tmp/patch_file_delivery.py && rm /tmp/patch_file_delivery.py
24
+
25
  # Install Node.js 23
26
  RUN ARCH=$(dpkg --print-architecture) \
27
  && if [ "$ARCH" = "amd64" ]; then NODE_ARCH="x64"; else NODE_ARCH="$ARCH"; fi \
scripts/patch_file_delivery.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Patch hermes-agent to support auto-detecting document file paths for native delivery.
3
+
4
+ By default, extract_local_files() only detects image/video extensions (.png, .jpg, etc.)
5
+ which means .md, .pdf, .docx, .xlsx and other document files created by the agent
6
+ are NOT sent as attachments.
7
+
8
+ This patch adds document extensions to _LOCAL_MEDIA_EXTS so that when Hermes creates
9
+ a file like /tmp/weather_report.md, it gets automatically sent as a native attachment
10
+ on Feishu and WeChat instead of appearing as a plain text path.
11
+ """
12
+
13
+ import re
14
+ import sys
15
+
16
+ def patch_file(filepath: str):
17
+ with open(filepath, 'r') as f:
18
+ content = f.read()
19
+
20
+ # Find and replace _LOCAL_MEDIA_EXTS
21
+ old = """\
22
+ _LOCAL_MEDIA_EXTS = (
23
+ '.png', '.jpg', '.jpeg', '.gif', '.webp',
24
+ '.mp4', '.mov', '.avi', '.mkv', '.webm',
25
+ )"""
26
+
27
+ new = """\
28
+ _LOCAL_MEDIA_EXTS = (
29
+ # Images
30
+ '.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.svg',
31
+ # Videos
32
+ '.mp4', '.mov', '.avi', '.mkv', '.webm',
33
+ # Audio
34
+ '.ogg', '.opus', '.mp3', '.wav', '.m4a', '.silk', '.flac',
35
+ # Documents
36
+ '.md', '.txt', '.csv', '.json', '.xml', '.yaml', '.yml', '.toml', '.log',
37
+ '.pdf',
38
+ '.doc', '.docx',
39
+ '.xls', '.xlsx',
40
+ '.ppt', '.pptx',
41
+ '.html', '.htm',
42
+ # Archives
43
+ '.zip', '.tar', '.gz', '.7z', '.rar',
44
+ )"""
45
+
46
+ if old not in content:
47
+ print(f"ERROR: Could not find _LOCAL_MEDIA_EXTS in {filepath}", file=sys.stderr)
48
+ sys.exit(1)
49
+
50
+ content = content.replace(old, new, 1)
51
+
52
+ with open(filepath, 'w') as f:
53
+ f.write(content)
54
+
55
+ print(f"Patched {filepath}: added document/audio/archive extensions to _LOCAL_MEDIA_EXTS")
56
+
57
+ if __name__ == "__main__":
58
+ # Find base.py in the installed package
59
+ filepath = sys.argv[1] if len(sys.argv) > 1 else None
60
+
61
+ # Try common locations
62
+ import importlib.util
63
+ for candidate in [
64
+ "/app/venv/lib/python3.12/site-packages/gateway/platforms/base.py",
65
+ ]:
66
+ if not filepath and __import__('os').path.isfile(candidate):
67
+ filepath = candidate
68
+ break
69
+
70
+ if not filepath:
71
+ # Try to find it
72
+ import os, glob
73
+ matches = glob.glob("/app/venv/lib/**/gateway/platforms/base.py", recursive=True)
74
+ if matches:
75
+ filepath = matches[0]
76
+
77
+ if not filepath or not os.path.isfile(filepath):
78
+ print(f"ERROR: base.py not found", file=sys.stderr)
79
+ sys.exit(1)
80
+
81
+ patch_file(filepath)