platforms.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """Shared platform registry for Hermes Agent."""
  2. from collections import OrderedDict
  3. from typing import NamedTuple
  4. class PlatformInfo(NamedTuple):
  5. """Metadata for a single platform entry."""
  6. label: str
  7. default_toolset: str
  8. # Ordered so that TUI menus are deterministic.
  9. PLATFORMS: OrderedDict[str, PlatformInfo] = OrderedDict([
  10. ("cli", PlatformInfo(label="🖥️ CLI", default_toolset="hermes-cli")),
  11. ("telegram", PlatformInfo(label="📱 Telegram", default_toolset="hermes-telegram")),
  12. ("discord", PlatformInfo(label="💬 Discord", default_toolset="hermes-discord")),
  13. ("slack", PlatformInfo(label="💼 Slack", default_toolset="hermes-slack")),
  14. ("whatsapp", PlatformInfo(label="📱 WhatsApp", default_toolset="hermes-whatsapp")),
  15. ("whatsapp_cloud", PlatformInfo(label="📱 WhatsApp Business (Cloud)", default_toolset="hermes-whatsapp")),
  16. ("signal", PlatformInfo(label="📡 Signal", default_toolset="hermes-signal")),
  17. ("bluebubbles", PlatformInfo(label="💙 BlueBubbles", default_toolset="hermes-bluebubbles")),
  18. ("email", PlatformInfo(label="📧 Email", default_toolset="hermes-email")),
  19. ("mattermost", PlatformInfo(label="💬 Mattermost", default_toolset="hermes-mattermost")),
  20. ("matrix", PlatformInfo(label="💬 Matrix", default_toolset="hermes-matrix")),
  21. ("dingtalk", PlatformInfo(label="💬 DingTalk", default_toolset="hermes-dingtalk")),
  22. ("feishu", PlatformInfo(label="🪽 Feishu", default_toolset="hermes-feishu")),
  23. ("wecom", PlatformInfo(label="💬 WeCom", default_toolset="hermes-wecom")),
  24. ("wecom_callback", PlatformInfo(label="💬 WeCom Callback", default_toolset="hermes-wecom-callback")),
  25. ("weixin", PlatformInfo(label="💬 Weixin", default_toolset="hermes-weixin")),
  26. ("qqbot", PlatformInfo(label="💬 QQBot", default_toolset="hermes-qqbot")),
  27. ("yuanbao", PlatformInfo(label="🤖 Yuanbao", default_toolset="hermes-yuanbao")),
  28. ("webhook", PlatformInfo(label="🔗 Webhook", default_toolset="hermes-webhook")),
  29. ("api_server", PlatformInfo(label="🌐 API Server", default_toolset="hermes-api-server")),
  30. ("cron", PlatformInfo(label="⏰ Cron", default_toolset="hermes-cron")),
  31. ])
  32. def _plugin_label(entry) -> str:
  33. return f"{entry.emoji} {entry.label}" if entry.emoji else entry.label
  34. def platform_label(key: str, default: str = "") -> str:
  35. """Return the display label for a platform key (builtin, then plugin registry), or *default*."""
  36. info = PLATFORMS.get(key)
  37. if info is not None:
  38. return info.label
  39. try:
  40. from gateway.platform_registry import platform_registry
  41. entry = platform_registry.get(key)
  42. if entry:
  43. return _plugin_label(entry)
  44. except Exception:
  45. pass
  46. return default
  47. def get_all_platforms() -> OrderedDict[str, PlatformInfo]:
  48. """PLATFORMS plus plugin-registered platforms (appended after builtins) — use for menus."""
  49. merged = OrderedDict(PLATFORMS)
  50. try:
  51. from gateway.platform_registry import platform_registry
  52. for entry in platform_registry.plugin_entries():
  53. if entry.name not in merged:
  54. merged[entry.name] = PlatformInfo(_plugin_label(entry), f"hermes-{entry.name}")
  55. except Exception:
  56. pass
  57. return merged