Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(discord): open UI interactions on client loop
cyhhaoc7f3fa0a5b8e
diff --git a/core/handlers/command_handlers.py b/core/handlers/command_handlers.pyindex 0f448bcce..902d59930 100644--- a/core/handlers/command_handlers.py+++ b/core/handlers/command_handlers.py@@ -311,7 +311,9 @@ class CommandHandlers(BaseHandler):if interaction and hasattr(im_client, "open_change_cwd_modal"):try:current_cwd = self.controller.get_cwd(context)- await im_client.open_change_cwd_modal(interaction, current_cwd, context.channel_id)+ await im_client.run_on_client_loop(+ im_client.open_change_cwd_modal(interaction, current_cwd, context.channel_id)+ )returnexcept Exception as e:logger.error(f"Error opening change CWD modal: {e}")@@ -325,10 +327,12 @@ class CommandHandlers(BaseHandler):if hasattr(im_client, "open_change_cwd_modal"):try:current_cwd = self.controller.get_cwd(context)- await im_client.open_change_cwd_modal(- trigger_id=context,- current_cwd=current_cwd,- channel_id=context.channel_id,+ await im_client.run_on_client_loop(+ im_client.open_change_cwd_modal(+ trigger_id=context,+ current_cwd=current_cwd,+ channel_id=context.channel_id,+ ))returnexcept Exception as e:@@ -356,7 +360,9 @@ class CommandHandlers(BaseHandler):# Get current CWD based on contextcurrent_cwd = self.controller.get_cwd(context)- await im_client.open_change_cwd_modal(trigger_id, current_cwd, context.channel_id)+ await im_client.run_on_client_loop(+ im_client.open_change_cwd_modal(trigger_id, current_cwd, context.channel_id)+ )except Exception as e:logger.error(f"Error opening change CWD modal: {e}")channel_context = self._get_channel_context(context)@@ -389,12 +395,14 @@ class CommandHandlers(BaseHandler):returnif interaction and hasattr(im_client, "open_resume_session_modal"):try:- await im_client.open_resume_session_modal(- trigger_id=interaction,- sessions_by_agent=sessions_by_agent,- channel_id=context.channel_id,- thread_id=context.thread_id or context.message_id or "",- host_message_ts=context.message_id,+ await im_client.run_on_client_loop(+ im_client.open_resume_session_modal(+ trigger_id=interaction,+ sessions_by_agent=sessions_by_agent,+ channel_id=context.channel_id,+ thread_id=context.thread_id or context.message_id or "",+ host_message_ts=context.message_id,+ ))returnexcept Exception as e:@@ -411,12 +419,14 @@ class CommandHandlers(BaseHandler):# Allow opening modal even with no sessions (user can paste manually)if hasattr(im_client, "open_resume_session_modal"):try:- await im_client.open_resume_session_modal(- trigger_id=context,- sessions_by_agent=sessions_by_agent or {},- channel_id=context.channel_id,- thread_id=context.thread_id or context.message_id or "",- host_message_ts=context.message_id,+ await im_client.run_on_client_loop(+ im_client.open_resume_session_modal(+ trigger_id=context,+ sessions_by_agent=sessions_by_agent or {},+ channel_id=context.channel_id,+ thread_id=context.thread_id or context.message_id or "",+ host_message_ts=context.message_id,+ ))returnexcept Exception as e:@@ -456,12 +466,14 @@ class CommandHandlers(BaseHandler):)try:- await im_client.open_resume_session_modal(- trigger_id=trigger_id,- sessions_by_agent=sessions_by_agent,- channel_id=context.channel_id,- thread_id=context.thread_id or context.message_id or "",- host_message_ts=context.message_id,+ await im_client.run_on_client_loop(+ im_client.open_resume_session_modal(+ trigger_id=trigger_id,+ sessions_by_agent=sessions_by_agent,+ channel_id=context.channel_id,+ thread_id=context.thread_id or context.message_id or "",+ host_message_ts=context.message_id,+ ))except Exception as e:logger.error(f"Error opening resume modal: {e}")diff --git a/core/handlers/settings_handler.py b/core/handlers/settings_handler.pyindex 42badee07..ec10fe70a 100644--- a/core/handlers/settings_handler.py+++ b/core/handlers/settings_handler.py@@ -150,15 +150,17 @@ class SettingsHandler(BaseHandler):current_language = self.config.languagetry:- await im_client.open_settings_modal(- trigger_id,- user_settings,- message_types,- display_names,- context.channel_id,- current_require_mention=current_require_mention,- global_require_mention=global_require_mention,- current_language=current_language,+ await im_client.run_on_client_loop(+ im_client.open_settings_modal(+ trigger_id,+ user_settings,+ message_types,+ display_names,+ context.channel_id,+ current_require_mention=current_require_mention,+ global_require_mention=global_require_mention,+ current_language=current_language,+ ))except Exception as e:logger.error(f"Error opening settings modal: {e}")@@ -188,16 +190,18 @@ class SettingsHandler(BaseHandler):current_language = self.config.languageif hasattr(im_client, "open_settings_modal"):- await im_client.open_settings_modal(- interaction,- user_settings,- message_types,- display_names,- context.channel_id,- current_require_mention=current_require_mention,- global_require_mention=global_require_mention,- current_language=current_language,- owner_user_id=context.user_id,+ await im_client.run_on_client_loop(+ im_client.open_settings_modal(+ interaction,+ user_settings,+ message_types,+ display_names,+ context.channel_id,+ current_require_mention=current_require_mention,+ global_require_mention=global_require_mention,+ current_language=current_language,+ owner_user_id=context.user_id,+ ))returnawait self._handle_settings_traditional(context)@@ -216,15 +220,17 @@ class SettingsHandler(BaseHandler):if hasattr(im_client, "open_settings_modal"):try:- await im_client.open_settings_modal(- trigger_id=context,- user_settings=user_settings,- message_types=message_types,- display_names=display_names,- channel_id=context.channel_id,- current_require_mention=current_require_mention,- global_require_mention=global_require_mention,- current_language=current_language,+ await im_client.run_on_client_loop(+ im_client.open_settings_modal(+ trigger_id=context,+ user_settings=user_settings,+ message_types=message_types,+ display_names=display_names,+ channel_id=context.channel_id,+ current_require_mention=current_require_mention,+ global_require_mention=global_require_mention,+ current_language=current_language,+ ))except Exception as e:logger.error(f"Error opening settings card for Lark: {e}", exc_info=True)@@ -461,10 +467,12 @@ class SettingsHandler(BaseHandler):# Open modaltry:- await im_client.open_routing_modal(- trigger_id=trigger_id,- channel_id=context.channel_id,- **routing_data.as_kwargs(),+ await im_client.run_on_client_loop(+ im_client.open_routing_modal(+ trigger_id=trigger_id,+ channel_id=context.channel_id,+ **routing_data.as_kwargs(),+ ))except Exception as e:logger.error(f"Error opening routing modal: {e}", exc_info=True)@@ -476,10 +484,12 @@ class SettingsHandler(BaseHandler):routing_data = await self._gather_routing_modal_data(context)try:- await im_client.open_routing_modal(- trigger_id=interaction or context,- channel_id=context.channel_id,- **routing_data.as_kwargs(),+ await im_client.run_on_client_loop(+ im_client.open_routing_modal(+ trigger_id=interaction or context,+ channel_id=context.channel_id,+ **routing_data.as_kwargs(),+ ))except Exception as e:logger.error(f"Error opening routing modal: {e}", exc_info=True)@@ -495,10 +505,12 @@ class SettingsHandler(BaseHandler):routing_data = await self._gather_routing_modal_data(context)try:- await im_client.open_routing_modal(- trigger_id=context,- channel_id=context.channel_id,- **routing_data.as_kwargs(),+ await im_client.run_on_client_loop(+ im_client.open_routing_modal(+ trigger_id=context,+ channel_id=context.channel_id,+ **routing_data.as_kwargs(),+ ))except Exception as e:logger.error(f"Error opening routing card for Lark: {e}", exc_info=True)diff --git a/modules/agents/opencode/question_handler.py b/modules/agents/opencode/question_handler.pyindex fc8ef4ae5..3f47222ee 100644--- a/modules/agents/opencode/question_handler.py+++ b/modules/agents/opencode/question_handler.py@@ -176,17 +176,21 @@ class OpenCodeQuestionHandler:try:if hasattr(self._im_client, "open_opencode_question_modal"):- await self._im_client.open_opencode_question_modal(- trigger_id=interaction or trigger_id,- context=request.context,- pending=pending,+ await self._im_client.run_on_client_loop(+ self._im_client.open_opencode_question_modal(+ trigger_id=interaction or trigger_id,+ context=request.context,+ pending=pending,+ ))else:- await self._im_client.open_question_modal(- trigger_id=interaction or trigger_id,- context=request.context,- pending=pending,- callback_prefix="opencode_question",+ await self._im_client.run_on_client_loop(+ self._im_client.open_question_modal(+ trigger_id=interaction or trigger_id,+ context=request.context,+ pending=pending,+ callback_prefix="opencode_question",+ ))except Exception as err:logger.error(f"Failed to open OpenCode question modal: {err}", exc_info=True)diff --git a/modules/im/base.py b/modules/im/base.pyindex b1b84fb87..0beb44047 100644--- a/modules/im/base.py+++ b/modules/im/base.py@@ -573,6 +573,11 @@ class BaseIMClient(ABC):return False+ async def run_on_client_loop(self, coro):+ """Run a coroutine on the platform client's preferred event loop."""++ return await coro+async def send_dm(self, user_id: str, text: str, **kwargs) -> Optional[str]:"""Send a direct message to a user by their platform user ID.diff --git a/modules/im/discord.py b/modules/im/discord.pyindex ef065b902..ea5055969 100644--- a/modules/im/discord.py+++ b/modules/im/discord.py@@ -175,6 +175,9 @@ class DiscordBot(BaseIMClient):future = asyncio.run_coroutine_threadsafe(coro, loop)return await asyncio.wrap_future(future)+ async def run_on_client_loop(self, coro):+ return await self._run_on_client_loop(coro)+def register_handlers(self):return