|
|
@@ -51,26 +51,26 @@ from gateway.platforms.base import (
|
|
|
)
|
|
|
from gateway.config import Platform
|
|
|
|
|
|
-# Chattolib imports
|
|
|
-from chattolib import (
|
|
|
- ChattoClient,
|
|
|
- ChattoError,
|
|
|
- ChattoAuthError,
|
|
|
- ChattoConnectError,
|
|
|
- ChattoRealtimeError,
|
|
|
- ChattoRealtimeCloseError,
|
|
|
- RealtimeConnection,
|
|
|
- RealtimeEvent,
|
|
|
- ServerHello,
|
|
|
- stream_events,
|
|
|
-)
|
|
|
-from chattolib.types import (
|
|
|
- RoomKind,
|
|
|
- PresenceStatus,
|
|
|
- RoomWithViewerState,
|
|
|
- User,
|
|
|
- Message,
|
|
|
-)
|
|
|
+# Chattolib imports (lazy loaded)
|
|
|
+from tools.lazy_deps import lazy_import
|
|
|
+
|
|
|
+ChattoClient = lazy_import("chattolib", "ChattoClient")
|
|
|
+ChattoError = lazy_import("chattolib", "ChattoError")
|
|
|
+ChattoAuthError = lazy_import("chattolib", "ChattoAuthError")
|
|
|
+ChattoConnectError = lazy_import("chattolib", "ChattoConnectError")
|
|
|
+ChattoRealtimeError = lazy_import("chattolib", "ChattoRealtimeError")
|
|
|
+ChattoRealtimeCloseError = lazy_import("chattolib", "ChattoRealtimeCloseError")
|
|
|
+RealtimeConnection = lazy_import("chattolib", "RealtimeConnection")
|
|
|
+RealtimeEvent = lazy_import("chattolib", "RealtimeEvent")
|
|
|
+ServerHello = lazy_import("chattolib", "ServerHello")
|
|
|
+stream_events = lazy_import("chattolib", "stream_events")
|
|
|
+
|
|
|
+# chattolib types
|
|
|
+RoomKind = lazy_import("chattolib.types", "RoomKind")
|
|
|
+PresenceStatus = lazy_import("chattolib.types", "PresenceStatus")
|
|
|
+RoomWithViewerState = lazy_import("chattolib.types", "RoomWithViewerState")
|
|
|
+User = lazy_import("chattolib.types", "User")
|
|
|
+Message = lazy_import("chattolib.types", "Message")
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
# Constants
|
|
|
@@ -490,8 +490,8 @@ class ChattoAdapter(BasePlatformAdapter):
|
|
|
async def _seed_room(self, room_id: str) -> None:
|
|
|
"""Seed high-water mark from the newest events so a restart doesn't replay history."""
|
|
|
try:
|
|
|
- from chattolib._pb.chatto.api.v1 import room_service_pb2
|
|
|
- from chattolib._transport import pb_to_dict
|
|
|
+ room_service_pb2 = lazy_import("chattolib._pb.chatto.api.v1", "room_service_pb2")
|
|
|
+ pb_to_dict = lazy_import("chattolib._transport", "pb_to_dict")
|
|
|
|
|
|
resp = await self._chatto_client.services.rooms.get_room_events(
|
|
|
room_service_pb2.GetRoomEventsRequest(room_id=room_id),
|
|
|
@@ -650,7 +650,8 @@ class ChattoAdapter(BasePlatformAdapter):
|
|
|
try:
|
|
|
# event.payload is a RealtimeProjectionEvent protobuf message
|
|
|
# We need to convert it to the dict format that _handle_projection_event expects
|
|
|
- from chattolib._transport import pb_to_dict
|
|
|
+ from tools.lazy_deps import lazy_import
|
|
|
+ pb_to_dict = lazy_import("chattolib._transport", "pb_to_dict")
|
|
|
|
|
|
pe_dict = pb_to_dict(event.payload)
|
|
|
|
|
|
@@ -722,7 +723,7 @@ class ChattoAdapter(BasePlatformAdapter):
|
|
|
_handle_transient_event.
|
|
|
"""
|
|
|
try:
|
|
|
- from chattolib._transport import pb_to_dict
|
|
|
+ pb_to_dict = lazy_import("chattolib._transport", "pb_to_dict")
|
|
|
|
|
|
# Build envelope dict based on event kind
|
|
|
envelope = {
|
|
|
@@ -957,10 +958,13 @@ class ChattoAdapter(BasePlatformAdapter):
|
|
|
"""
|
|
|
self._mark_seen(room_id, event_id)
|
|
|
try:
|
|
|
+ # Import all required protobuf modules
|
|
|
+ thread_service_pb2 = lazy_import("chattolib._pb.chatto.api.v1", "thread_service_pb2")
|
|
|
+ room_service_pb2 = lazy_import("chattolib._pb.chatto.api.v1", "room_service_pb2")
|
|
|
+ pb_to_dict = lazy_import("chattolib._transport", "pb_to_dict")
|
|
|
+
|
|
|
if thread_root_event_id:
|
|
|
# Thread reply — use GetThreadEvents
|
|
|
- from chattolib._pb.chatto.api.v1 import thread_service_pb2
|
|
|
- from chattolib._transport import pb_to_dict
|
|
|
resp = await self._chatto_client.services.threads.get_thread_events(
|
|
|
thread_service_pb2.GetThreadEventsRequest(
|
|
|
room_id=room_id,
|
|
|
@@ -971,8 +975,6 @@ class ChattoAdapter(BasePlatformAdapter):
|
|
|
data = pb_to_dict(resp)
|
|
|
else:
|
|
|
# Regular room message — use GetRoomEvents
|
|
|
- from chattolib._pb.chatto.api.v1 import room_service_pb2
|
|
|
- from chattolib._transport import pb_to_dict
|
|
|
resp = await self._chatto_client.services.rooms.get_room_events(
|
|
|
room_service_pb2.GetRoomEventsRequest(room_id=room_id),
|
|
|
headers=self._chatto_client._headers(),
|
|
|
@@ -2055,7 +2057,7 @@ async def _standalone_send(
|
|
|
"""Out-of-process send for cron delivery (no live adapter needed)."""
|
|
|
try:
|
|
|
# Create a temporary client for standalone sending
|
|
|
- from chattolib import ChattoClient
|
|
|
+ # Use the lazy-imported ChattoClient
|
|
|
client = ChattoClient(base_url=base_url)
|
|
|
await client.login(login=login, password=password)
|
|
|
|