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
refactor(settings-key): unified resolution via is_dm flag, remove _resolve_settings_key
cyh4d85171a1c3e
diff --git a/core/controller.py b/core/controller.pyindex 3fc785f12..3a527afa0 100644--- a/core/controller.py+++ b/core/controller.py@@ -361,74 +361,12 @@ class Controller:For DM contexts, returns user_id so per-user settings apply.For channel contexts, returns channel_id for per-channel settings.++ Relies on the ``is_dm`` flag set by the IM layer in+ ``context.platform_specific`` (see Phase 2 of the refactoring)."""- platform = getattr(self.config, "platform", "slack")- if platform == "slack" and context.channel_id.startswith("D"):- return context.user_id- if platform == "discord":- if self._is_discord_dm(context):- return context.user_id- if platform == "lark":- if self._is_lark_dm(context):- return context.user_id- return context.channel_id-- def _is_discord_dm(self, context: MessageContext) -> bool:- """Detect Discord DM from message or interaction context."""- ps = context.platform_specific or {}- # Explicit is_dm flag set by IM layer (works for all context types)- if ps.get("is_dm"):- return True- try:- import discord as discord_lib-- # Message context (normal messages)- msg = ps.get("message")- if msg is not None:- if isinstance(msg.channel, discord_lib.DMChannel) or msg.guild is None:- return True- # Interaction context (button/slash callbacks)- interaction = ps.get("interaction")- if interaction is not None:- if interaction.guild is None or isinstance(interaction.channel, discord_lib.DMChannel):- return True- except Exception:- pass- return False-- def _is_lark_dm(self, context: MessageContext) -> bool:- """Detect Lark/Feishu DM from message or callback event context."""- ps = context.platform_specific or {}- # Explicit is_dm flag set by IM layer (works for all context types)- if ps.get("is_dm"):- return True- event = ps.get("event", {})- if isinstance(event, dict):- # Message path: event.message.chat_type == "p2p"- chat_type = event.get("message", {}).get("chat_type")- if chat_type == "p2p":- return True- return False-- def _resolve_settings_key(self, user_id: str, channel_id: Optional[str]) -> str:- """Resolve settings key for update handlers that don't have a MessageContext.-- Uses the same DM-detection logic as ``_get_settings_key``:- for DM contexts the key is ``user_id``, otherwise ``channel_id``.- """- platform = getattr(self.config, "platform", "slack")- effective_channel = channel_id or ""- if platform == "slack" and effective_channel.startswith("D"):- return user_id- if platform in ("discord", "lark"):- # For DM updates: the user is bound AND the channel_id is NOT a- # known configured channel (i.e. it's a DM chat, not a workspace channel)- if effective_channel and self.settings_manager and hasattr(self.settings_manager, "store"):- store = self.settings_manager.store- is_known_channel = effective_channel in store.settings.channels- if not is_known_channel and store.is_bound_user(user_id):- return user_id- return effective_channel if effective_channel else user_id+ is_dm = (context.platform_specific or {}).get("is_dm", False)+ return context.user_id if is_dm else context.channel_iddef _get_target_context(self, context: MessageContext) -> MessageContext:"""Get target context for sending messages"""@@ -773,11 +711,12 @@ class Controller:require_mention: Optional[bool] = None,language: Optional[str] = None,notify_user: bool = True,+ is_dm: bool = False,):"""Handle settings update (typically from Slack modal)"""try:# Determine settings key — for DM contexts use user_id- settings_key = self._resolve_settings_key(user_id, channel_id)+ settings_key = user_id if is_dm else (channel_id or user_id)# Update settingsuser_settings = self.settings_manager.get_user_settings(settings_key)@@ -1140,13 +1079,14 @@ class Controller:codex_model: Optional[str] = None,codex_reasoning_effort: Optional[str] = None,notify_user: bool = True,+ is_dm: bool = False,):"""Handle routing update submission (from Slack modal)"""from modules.settings_manager import ChannelRoutingtry:# Get settings key- settings_key = self._resolve_settings_key(user_id, channel_id)+ settings_key = user_id if is_dm else (channel_id or user_id)# Get existing routing to preserve settings for other backendsexisting_routing = self.settings_manager.get_channel_routing(settings_key)diff --git a/modules/im/discord.py b/modules/im/discord.pyindex f34d840da..e0e542c82 100644--- a/modules/im/discord.py+++ b/modules/im/discord.py@@ -755,6 +755,7 @@ class DiscordBot(BaseIMClient):require_mention,language,notify_user=False,+ is_dm=save_interaction.guild is None,)await save_interaction.edit_original_response(content=f"✅ {self._t('success.settingsUpdated')}",@@ -1304,6 +1305,7 @@ class DiscordBot(BaseIMClient):_normalize(self.codex_model),_normalize(self.codex_reasoning),notify_user=False,+ is_dm=interaction.guild is None,)await interaction.edit_original_response(content=f"✅ {self.outer._t('success.routingUpdated')}",diff --git a/modules/im/feishu.py b/modules/im/feishu.pyindex 86814f942..4592e398b 100644--- a/modules/im/feishu.py+++ b/modules/im/feishu.py@@ -1340,6 +1340,7 @@ class FeishuBot(BaseIMClient):context.channel_id,require_mention,language,+ is_dm=context.platform_specific.get("is_dm", False),)async def _handle_routing_backend_select(self, context: MessageContext, form_value: Dict[str, Any]):@@ -1403,6 +1404,7 @@ class FeishuBot(BaseIMClient):claude_model,codex_model,codex_reasoning,+ is_dm=context.platform_specific.get("is_dm", False),)# ------------------------------------------------------------------diff --git a/modules/im/slack.py b/modules/im/slack.pyindex d374954c5..fac9d0b68 100644--- a/modules/im/slack.py+++ b/modules/im/slack.py@@ -1271,7 +1271,14 @@ class SlackBot(BaseIMClient):# Update settings - need access to settings managerif hasattr(self, "_on_settings_update"):- await self._on_settings_update(user_id, show_types, channel_id, require_mention, language)+ await self._on_settings_update(+ user_id,+ show_types,+ channel_id,+ require_mention,+ language,+ is_dm=isinstance(channel_id, str) and channel_id.startswith("D"),+ )elif callback_id == "change_cwd_modal":# Handle change CWD modal submission@@ -1489,6 +1496,7 @@ class SlackBot(BaseIMClient):claude_model,codex_model,codex_reasoning,+ is_dm=isinstance(channel_id, str) and channel_id.startswith("D"),)def run(self):