Skip to content

The agent that grows with you

refactor(bluebubbles): move adapter into bundled platform plugin

Tekniumaa97f314778e
diff --git a/plugins/platforms/bluebubbles/__init__.py b/plugins/platforms/bluebubbles/__init__.py
new file mode 100644
index 00000000000..d4f1d7bf0e3
--- /dev/null
+++ b/plugins/platforms/bluebubbles/__init__.py
@@ -0,0 +1,3 @@
+from .adapter import register
+
+__all__ = ["register"]
diff --git a/gateway/platforms/bluebubbles.py b/plugins/platforms/bluebubbles/adapter.py
similarity index 85%
rename from gateway/platforms/bluebubbles.py
rename to plugins/platforms/bluebubbles/adapter.py
index 358fdc2ee5b..e1d186d245e 100644
--- a/gateway/platforms/bluebubbles.py
+++ b/plugins/platforms/bluebubbles/adapter.py
@@ -23,7 +23,7 @@ from gateway.platforms.base import (
cache_image_from_bytes_async, cache_audio_from_bytes_async, cache_document_from_bytes_async,
)
from gateway.platforms.event import MessageEvent, MessageType
-from .media_cache import ext_for_mime
+from gateway.platforms.media_cache import ext_for_mime
from gateway.platforms.helpers import compile_mention_patterns, strip_markdown
from utils import TRUTHY_STRINGS
@@ -608,3 +608,91 @@ class BlueBubblesAdapter(BasePlatformAdapter):
if self.send_read_receipts and session_chat_id: # fire-and-forget read receipt
asyncio.create_task(self.mark_read(session_chat_id))
return _ok()
+
+
+# --- Plugin hooks (registered via register(ctx) below) ---
+
+_INSTALL_HINT = "BlueBubbles: aiohttp/httpx missing or BLUEBUBBLES_SERVER_URL/BLUEBUBBLES_PASSWORD not configured"
+
+
+def _is_connected(config) -> bool:
+ """Server URL + password present in ``PlatformConfig.extra`` (the env table seeds it) or the env."""
+ extra = getattr(config, "extra", None) or {}
+ if extra.get("server_url") and extra.get("password"):
+ return True
+ import hermes_cli.gateway as gateway_mod
+ return all((gateway_mod.get_env_value(n) or "").strip() for n in ("BLUEBUBBLES_SERVER_URL", "BLUEBUBBLES_PASSWORD"))
+
+
+async def _standalone_send(pconfig, chat_id: str, message: str, *, thread_id: Optional[str] = None,
+ media_files: Optional[list] = None, force_document: bool = False, **_kw) -> dict[str, Any]:
+ """Out-of-process send (cron without a co-resident gateway): one-shot adapter connect → send →
+ disconnect against the BlueBubbles REST API. Text only; ``thread_id``/``media_files``/
+ ``force_document`` are signature parity (send_message drops media with a warning)."""
+ from gateway.platforms._shared import send_error
+ if not check_bluebubbles_requirements():
+ return send_error("BlueBubbles requirements not met (need aiohttp + httpx).")
+ try:
+ adapter = BlueBubblesAdapter(PlatformConfig(extra=dict(getattr(pconfig, "extra", None) or {})))
+ if not await adapter.connect():
+ return send_error("BlueBubbles: failed to connect to server")
+ try:
+ result = await adapter.send(chat_id, message)
+ finally:
+ await adapter.disconnect()
+ if not result.success:
+ return send_error(f"BlueBubbles send failed: {result.error}")
+ return {"success": True, "platform": "bluebubbles", "chat_id": chat_id, "message_id": result.message_id}
+ except Exception as e:
+ return send_error(f"BlueBubbles send failed: {e}")
+
+
+def interactive_setup() -> None:
+ """Configure BlueBubbles iMessage gateway (``hermes setup`` / ``hermes gateway setup``)."""
+ from hermes_cli.setup import _info, print_header, print_success, prompt, prompt_yes_no
+ from hermes_cli.setup_platforms import _prompt_allowlist, _save_port, declines_reconfigure, save_prompted
+ print_header("BlueBubbles (iMessage)")
+ if declines_reconfigure("BlueBubbles", "Reconfigure BlueBubbles?", "BLUEBUBBLES_SERVER_URL"):
+ return
+ _info("Connects Hermes to iMessage via BlueBubbles — a free, open-source",
+ "macOS server that bridges iMessage to any device.",
+ " Requires a Mac running BlueBubbles Server v1.0.0+",
+ " Download: https://bluebubbles.app/", None,
+ "In BlueBubbles Server → Settings → API, note your Server URL and Password.", None)
+ for label, env_var, secret, what, transform in (
+ ("BlueBubbles server URL (e.g. http://192.168.1.10:1234)", "BLUEBUBBLES_SERVER_URL", False, "Server URL",
+ lambda v: v.rstrip("/")),
+ ("BlueBubbles server password", "BLUEBUBBLES_PASSWORD", True, "Password", None),
+ ):
+ if not save_prompted(env_var, label, password=secret, transform=transform,
+ skip_msg=f"{what} is required — skipping BlueBubbles setup"):
+ return
+ print_success("BlueBubbles credentials saved")
+ _info(None, "🔒 Security: Restrict who can message your bot",
+ " Use iMessage addresses: email ([email protected]) or phone (+15551234567)", None)
+ _prompt_allowlist("BLUEBUBBLES_ALLOWED_USERS", "Allowed iMessage addresses (comma-separated, leave empty for open access)",
+ "BlueBubbles allowlist configured", "⚠️ No allowlist set — anyone who can iMessage you can use the bot!")
+ _info(None, "📬 Home Channel: phone or email for cron job delivery and notifications.",
+ " You can also set this later with /set-home in your iMessage chat.")
+ save_prompted("BLUEBUBBLES_HOME_CHANNEL", "Home channel address (leave empty to set later)")
+ _info(None, "Advanced settings (defaults are fine for most setups):")
+ if prompt_yes_no("Configure webhook listener settings?", False):
+ _save_port("BLUEBUBBLES_WEBHOOK_PORT", prompt("Webhook listener port (default: 8645)"), "8645")
+ _info(None, "Requires the BlueBubbles Private API helper for typing indicators,",
+ "read receipts, and tapback reactions. Basic messaging works without it.",
+ " Install: https://docs.bluebubbles.app/helper-bundle/installation")
+
+
+def register(ctx) -> None:
+ """Plugin entry point — called by the Hermes plugin system."""
+ ctx.register_platform(
+ name="bluebubbles", label="BlueBubbles (iMessage)", adapter_factory=BlueBubblesAdapter,
+ check_fn=check_bluebubbles_requirements, is_connected=_is_connected,
+ required_env=["BLUEBUBBLES_SERVER_URL", "BLUEBUBBLES_PASSWORD"], install_hint=_INSTALL_HINT,
+ setup_fn=interactive_setup,
+ allowed_users_env="BLUEBUBBLES_ALLOWED_USERS", allow_all_env="BLUEBUBBLES_ALLOW_ALL_USERS",
+ cron_deliver_env_var="BLUEBUBBLES_HOME_CHANNEL",
+ standalone_sender_fn=_standalone_send, # out-of-process cron / send_message
+ # 0 = send_message does not pre-chunk: the adapter's send() splits per paragraph and
+ # truncates itself (MAX_MESSAGE_LENGTH), exactly as the former core sender did.
+ max_message_length=0, pii_safe=True, emoji="💬", allow_update_command=True)
diff --git a/plugins/platforms/bluebubbles/plugin.yaml b/plugins/platforms/bluebubbles/plugin.yaml
new file mode 100644
index 00000000000..4a17d8bf8c3
--- /dev/null
+++ b/plugins/platforms/bluebubbles/plugin.yaml
@@ -0,0 +1,61 @@
+name: bluebubbles-platform
+label: BlueBubbles (iMessage)
+kind: platform
+version: 1.0.0
+description: >
+ BlueBubbles (Apple iMessage) gateway adapter for Hermes Agent.
+ Talks to a local BlueBubbles macOS server: outbound sends over its REST API,
+ inbound messages via a registered webhook listener. Supports media
+ attachments, typing indicators, read receipts and tapbacks (Private API
+ helper), group wake-word gating, and home-channel cron delivery.
+author: NousResearch
+requires_env:
+ - name: BLUEBUBBLES_SERVER_URL
+ description: "BlueBubbles server URL (e.g. http://192.168.1.10:1234)"
+ prompt: "BlueBubbles server URL"
+ password: false
+ - name: BLUEBUBBLES_PASSWORD
+ description: "BlueBubbles server password (BlueBubbles Server → Settings → API)"
+ prompt: "BlueBubbles server password"
+ password: true
+optional_env:
+ - name: BLUEBUBBLES_ALLOWED_USERS
+ description: "Comma-separated iMessage addresses (phone/email) allowed to talk to the bot"
+ prompt: "Allowed iMessage addresses (comma-separated)"
+ password: false
+ - name: BLUEBUBBLES_ALLOW_ALL_USERS
+ description: "Allow any iMessage sender to trigger the bot (dev only)"
+ prompt: "Allow all users? (true/false)"
+ password: false
+ - name: BLUEBUBBLES_HOME_CHANNEL
+ description: "Default iMessage address / chat GUID for cron / notification delivery"
+ prompt: "Home channel address"
+ password: false
+ - name: BLUEBUBBLES_HOME_CHANNEL_NAME
+ description: "Display name for the home channel"
+ prompt: "Home channel name"
+ password: false
+ - name: BLUEBUBBLES_WEBHOOK_HOST
+ description: "Webhook listener bind host (default 127.0.0.1)"
+ prompt: "Webhook host"
+ password: false
+ - name: BLUEBUBBLES_WEBHOOK_PORT
+ description: "Webhook listener port (default 8645)"
+ prompt: "Webhook port"
+ password: false
+ - name: BLUEBUBBLES_WEBHOOK_PATH
+ description: "Webhook listener path (default /bluebubbles-webhook)"
+ prompt: "Webhook path"
+ password: false
+ - name: BLUEBUBBLES_SEND_READ_RECEIPTS
+ description: "Auto-mark inbound messages read (default true; needs the Private API helper)"
+ prompt: "Send read receipts? (true/false)"
+ password: false
+ - name: BLUEBUBBLES_REQUIRE_MENTION
+ description: "Require a wake word in group chats (default false)"
+ prompt: "Require mention in groups? (true/false)"
+ password: false
+ - name: BLUEBUBBLES_MENTION_PATTERNS
+ description: "Group wake-word regexes (JSON list or comma/newline-separated); default Hermes wake words"
+ prompt: "Mention patterns"
+ password: false
diff --git a/tests/gateway/test_adapter_settings_profile_parity.py b/tests/gateway/test_adapter_settings_profile_parity.py
index 425c416809a..099260a59b3 100644
--- a/tests/gateway/test_adapter_settings_profile_parity.py
+++ b/tests/gateway/test_adapter_settings_profile_parity.py
@@ -70,7 +70,7 @@ _SETTINGS = [
lambda m: m.FeishuAdapter._load_settings({}).webhook_port),
("plugins.platforms.feishu.adapter", "FEISHU_CONNECTION_MODE", "websocket", "webhook",
lambda m: m.FeishuAdapter._load_settings({}).connection_mode),
- ("gateway.platforms.bluebubbles", "BLUEBUBBLES_WEBHOOK_PORT", "18010", "18110",
+ ("plugins.platforms.bluebubbles.adapter", "BLUEBUBBLES_WEBHOOK_PORT", "18010", "18110",
lambda m: m._extra_or_secret({}, "webhook_port", "BLUEBUBBLES_WEBHOOK_PORT", "0")),
("gateway.platforms.signal", "SIGNAL_REACTIONS", "true", "false",
lambda m: _signal_reactions(m)),
diff --git a/tests/gateway/test_adapter_startup_secret_scope.py b/tests/gateway/test_adapter_startup_secret_scope.py
index f2bbb7dcbd8..ad200425e58 100644
--- a/tests/gateway/test_adapter_startup_secret_scope.py
+++ b/tests/gateway/test_adapter_startup_secret_scope.py
@@ -40,7 +40,7 @@ MIGRATED_ADAPTER_MODULES = [
("plugins.platforms.photon.adapter", "PHOTON_PROJECT_SECRET"),
("plugins.platforms.photon.auth", "PHOTON_PROJECT_SECRET"),
("plugins.platforms.buzz.adapter", "BUZZ_PRIVATE_KEY"),
- ("gateway.platforms.bluebubbles", "BLUEBUBBLES_PASSWORD"),
+ ("plugins.platforms.bluebubbles.adapter", "BLUEBUBBLES_PASSWORD"),
("gateway.platforms.api_server", "API_SERVER_KEY"),
]
diff --git a/tests/gateway/test_bluebubbles.py b/tests/gateway/test_bluebubbles_plugin.py
similarity index 90%
rename from tests/gateway/test_bluebubbles.py
rename to tests/gateway/test_bluebubbles_plugin.py
index 52ab4a71271..6da0a6b437f 100644
--- a/tests/gateway/test_bluebubbles.py
+++ b/tests/gateway/test_bluebubbles_plugin.py
@@ -13,7 +13,7 @@ from gateway.platforms.base import BasePlatformAdapter
def _make_adapter(monkeypatch, **extra):
monkeypatch.setenv("BLUEBUBBLES_SERVER_URL", "http://localhost:1234")
monkeypatch.setenv("BLUEBUBBLES_PASSWORD", "secret")
- from gateway.platforms.bluebubbles import BlueBubblesAdapter
+ from plugins.platforms.bluebubbles.adapter import BlueBubblesAdapter
cfg = PlatformConfig(
enabled=True,
@@ -260,7 +260,7 @@ class TestBlueBubblesAttachmentDownload:
return cached_path
monkeypatch.setattr(
- "gateway.platforms.bluebubbles.cache_image_from_bytes_async",
+ "plugins.platforms.bluebubbles.adapter.cache_image_from_bytes_async",
mock_cache_image,
)
@@ -331,7 +331,7 @@ class TestBlueBubblesWebhookUrl:
def test_register_url_omits_query_when_no_password(self, monkeypatch):
"""If no password is configured, the register URL should be the bare URL."""
monkeypatch.delenv("BLUEBUBBLES_PASSWORD", raising=False)
- from gateway.platforms.bluebubbles import BlueBubblesAdapter
+ from plugins.platforms.bluebubbles.adapter import BlueBubblesAdapter
cfg = PlatformConfig(
enabled=True,
extra={"server_url": "http://localhost:1234", "password": ""},
@@ -583,3 +583,43 @@ class TestBlueBubblesGateBeforeDownload:
assert response.status == 200
assert download.await_count == downloads
assert len(handled) == handled_count
+
+
+class TestBlueBubblesPluginRegistration:
+ def test_register_declares_platform_entry_hooks(self):
+ """Plugin shape: the former core wiring (_BUILTIN_ADAPTERS row, _send_bluebubbles,
+ _setup_bluebubbles) now rides on the registry entry."""
+ import plugins.platforms.bluebubbles as plugin
+ from plugins.platforms.bluebubbles import adapter as mod
+
+ captured = {}
+
+ class _Ctx:
+ def register_platform(self, **kwargs):
+ captured.update(kwargs)
+
+ plugin.register(_Ctx())
+ assert captured["name"] == "bluebubbles"
+ assert captured["label"] == "BlueBubbles (iMessage)"
+ assert captured["adapter_factory"] is mod.BlueBubblesAdapter
+ assert captured["check_fn"] is mod.check_bluebubbles_requirements
+ assert captured["setup_fn"] is mod.interactive_setup
+ assert captured["standalone_sender_fn"] is mod._standalone_send
+ assert captured["required_env"] == ["BLUEBUBBLES_SERVER_URL", "BLUEBUBBLES_PASSWORD"]
+ assert captured["allowed_users_env"] == "BLUEBUBBLES_ALLOWED_USERS"
+ assert captured["allow_all_env"] == "BLUEBUBBLES_ALLOW_ALL_USERS"
+ assert captured["cron_deliver_env_var"] == "BLUEBUBBLES_HOME_CHANNEL"
+ assert captured["emoji"] == "💬"
+ assert captured["pii_safe"] is True and captured["allow_update_command"] is True
+ assert "BLUEBUBBLES_SERVER_URL/BLUEBUBBLES_PASSWORD" in captured["install_hint"]
+
+ def test_core_wiring_removed(self):
+ import tools.send_message_senders as senders
+ import tools.send_message_tool as smt
+ from gateway.run import _BUILTIN_ADAPTERS
+ from hermes_cli import gateway_setup_wizard as wiz
+
+ assert Platform.BLUEBUBBLES not in _BUILTIN_ADAPTERS
+ assert "bluebubbles" not in smt._TEXT_SENDERS
+ assert not hasattr(senders, "_send_bluebubbles")
+ assert all(p["key"] != "bluebubbles" for p in wiz._PLATFORMS)
diff --git a/tests/gateway/test_startup_failed_platform_reports_degraded.py b/tests/gateway/test_startup_failed_platform_reports_degraded.py
index 39caf8db79e..f876e19ed67 100644
--- a/tests/gateway/test_startup_failed_platform_reports_degraded.py
+++ b/tests/gateway/test_startup_failed_platform_reports_degraded.py
@@ -64,8 +64,10 @@ class _HealthyAdapter(BasePlatformAdapter):
def _runner(monkeypatch, tmp_path, platforms, create_adapter) -> GatewayRunner:
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
- # No plugin registers any platform here, so a None adapter is the "plugin never registered" case.
- monkeypatch.setattr("gateway.platform_registry.platform_registry.is_registered", lambda name: False)
+ # Only the bundled bluebubbles plugin counts as registered here, so a None adapter elsewhere is the
+ # "plugin never registered" case and a None bluebubbles adapter is "registered but failed".
+ monkeypatch.setattr("gateway.platform_registry.platform_registry.is_registered",
+ lambda name: name == "bluebubbles")
runner = GatewayRunner(GatewayConfig(platforms=platforms, sessions_dir=tmp_path / "sessions"))
monkeypatch.setattr(runner, "_create_adapter", create_adapter)
@@ -152,8 +154,8 @@ async def test_missing_adapter_degrades_only_the_unserved_enabled_platform(monke
Platform.TELEGRAM: PlatformConfig(enabled=True, token="***"),
Platform.DISCORD: PlatformConfig(enabled=True, token="***"),
Platform.SLACK: PlatformConfig(enabled=False, token="***"),
- # A builtin whose probe fails on missing creds needs a config change: flagged once, never
- # queued (else it re-warns forever at the backoff cap on fleet nodes, #5196).
+ # A registered plugin whose adapter creation fails on missing creds needs a config change:
+ # flagged once, never queued (else it re-warns forever at the backoff cap on fleet nodes, #5196).
Platform.BLUEBUBBLES: PlatformConfig(enabled=True),
},
lambda platform, platform_config: _HealthyAdapter() if platform is Platform.TELEGRAM else None,