Files
hermes-agent/gateway/webhook_targets.py
Teknium 7f9cb45a97 fix(webhook): one shared target check, non-string targets flagged, repair hint keeps route settings
Greptile: Target checks have split ownership / Malformed targets break listing /
Repair erases saved route settings. The dispatchable-target check moves into
gateway/webhook_targets.py (no aiohttp import), used by the adapter and the CLI;
it type-guards hand-edited non-string targets so list flags them instead of
raising TypeError; the list repair line resupplies the route's saved prompt,
events, skills, script, cron job and deliver-only/mirror flags.
2026-11-14 03:49:07 -08:00

26 lines
1.1 KiB
Python

"""Which webhook ``deliver`` targets the gateway can dispatch: one side-effect-free check shared by the
webhook adapter (route load) and ``hermes webhook`` (subscribe / list). Plugin discovery stays with the caller."""
from contextlib import suppress
BUILTIN_DELIVER_PLATFORMS = frozenset({
"telegram", "discord", "slack", "signal", "sms", "whatsapp", "matrix", "mattermost",
"email", "dingtalk", "feishu", "wecom", "wecom_callback", "weixin",
"bluebubbles", "qqbot"})
_NON_PLATFORM_TARGETS = frozenset({"log", "github_comment"})
def is_known_platform(name: str) -> bool:
"""Cross-platform delivery target: built-in names or plugin-registered platforms."""
if name in BUILTIN_DELIVER_PLATFORMS:
return True
with suppress(Exception):
from gateway.platform_registry import platform_registry
return platform_registry.is_registered(name)
return False
def is_dispatchable_target(target: object) -> bool:
"""A saved route's ``deliver`` value the gateway can send to (a hand-edited non-string is not)."""
return isinstance(target, str) and (target in _NON_PLATFORM_TARGETS or is_known_platform(target))