antenna-fyi 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/hermes-plugin/__init__.py +55 -30
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Antenna — Hermes Agent Plugin
|
|
2
2
|
|
|
3
|
-
Nearby people discovery. Registers
|
|
4
|
-
that auto-detects location data
|
|
3
|
+
Nearby people discovery. Registers 6 tools and a pre_llm_call hook
|
|
4
|
+
that auto-detects location data (from messages + web GPS events).
|
|
5
5
|
|
|
6
6
|
Drop this directory into ~/.hermes/plugins/antenna/
|
|
7
7
|
"""
|
|
@@ -13,6 +13,8 @@ from .tools import (
|
|
|
13
13
|
handle_checkin,
|
|
14
14
|
handle_check_matches,
|
|
15
15
|
handle_bind,
|
|
16
|
+
_sb,
|
|
17
|
+
_device_id,
|
|
16
18
|
SCAN_SCHEMA,
|
|
17
19
|
PROFILE_SCHEMA,
|
|
18
20
|
ACCEPT_SCHEMA,
|
|
@@ -21,6 +23,11 @@ from .tools import (
|
|
|
21
23
|
BIND_SCHEMA,
|
|
22
24
|
)
|
|
23
25
|
import re
|
|
26
|
+
import time
|
|
27
|
+
|
|
28
|
+
# Track last checked timestamp for location events
|
|
29
|
+
_last_event_check = 0
|
|
30
|
+
_EVENT_CHECK_INTERVAL = 30 # seconds
|
|
24
31
|
|
|
25
32
|
|
|
26
33
|
def register(ctx):
|
|
@@ -32,39 +39,57 @@ def register(ctx):
|
|
|
32
39
|
ctx.register_tool("antenna_check_matches", CHECK_MATCHES_SCHEMA, handle_check_matches)
|
|
33
40
|
ctx.register_tool("antenna_bind", BIND_SCHEMA, handle_bind)
|
|
34
41
|
|
|
35
|
-
# ── Hook: auto-detect location
|
|
42
|
+
# ── Hook: auto-detect location + check web GPS events ─────────
|
|
36
43
|
def on_pre_llm(messages, **kwargs):
|
|
37
|
-
"""Check
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
last_msg = messages[-1] if isinstance(messages[-1], dict) else {}
|
|
42
|
-
content = last_msg.get("content", "")
|
|
43
|
-
if not isinstance(content, str):
|
|
44
|
-
return None
|
|
44
|
+
"""Check for location data in messages AND pending web GPS events."""
|
|
45
|
+
global _last_event_check
|
|
46
|
+
hints = []
|
|
45
47
|
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
# 1. Check location_events table (web GPS updates)
|
|
49
|
+
now = time.time()
|
|
50
|
+
if now - _last_event_check > _EVENT_CHECK_INTERVAL:
|
|
51
|
+
_last_event_check = now
|
|
52
|
+
try:
|
|
53
|
+
sb = _sb()
|
|
54
|
+
resp = (
|
|
55
|
+
sb.from_("location_events")
|
|
56
|
+
.select("device_id, lat, lng")
|
|
57
|
+
.gt("created_at", "now() - interval '2 minutes'")
|
|
58
|
+
.order("created_at", desc=True)
|
|
59
|
+
.limit(5)
|
|
60
|
+
.execute()
|
|
61
|
+
)
|
|
62
|
+
if resp.data:
|
|
63
|
+
for evt in resp.data:
|
|
64
|
+
hints.append(
|
|
65
|
+
f"[Antenna] 📡 用户 {evt['device_id']} 通过网页分享了位置 "
|
|
66
|
+
f"({evt['lat']}, {evt['lng']})。"
|
|
67
|
+
f"请使用 antenna_scan 查看附近有谁。"
|
|
68
|
+
)
|
|
69
|
+
except Exception:
|
|
70
|
+
pass
|
|
57
71
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
# 2. Check message content for coordinates
|
|
73
|
+
if messages:
|
|
74
|
+
last_msg = messages[-1] if isinstance(messages[-1], dict) else {}
|
|
75
|
+
content = last_msg.get("content", "")
|
|
76
|
+
if isinstance(content, str):
|
|
77
|
+
loc_match = re.search(
|
|
78
|
+
r"[Ll]ocation.*?(-?\d+\.?\d*)[,\s]+(-?\d+\.?\d*)", content
|
|
65
79
|
)
|
|
66
|
-
|
|
80
|
+
if not loc_match:
|
|
81
|
+
loc_match = re.search(
|
|
82
|
+
r"(-?\d{1,3}\.\d{3,})[,\s]+(-?\d{1,3}\.\d{3,})", content
|
|
83
|
+
)
|
|
84
|
+
if loc_match:
|
|
85
|
+
lat, lng = loc_match.group(1), loc_match.group(2)
|
|
86
|
+
hints.append(
|
|
87
|
+
f"[Antenna] 📍 检测到位置 ({lat}, {lng})。"
|
|
88
|
+
f"请使用 antenna_scan 查看附近有谁。"
|
|
89
|
+
)
|
|
67
90
|
|
|
91
|
+
if hints:
|
|
92
|
+
return {"context": "\n".join(hints)}
|
|
68
93
|
return None
|
|
69
94
|
|
|
70
95
|
ctx.register_hook("pre_llm_call", on_pre_llm)
|