JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix: 将支持feishu多bot功能加入分离部署的gateway
yukuanja81b2dc0a7e2
diff --git a/jiuwenclaw/app_gateway.py b/jiuwenclaw/app_gateway.pyindex 89c1e5761f..7dbb2ac319 100644--- a/jiuwenclaw/app_gateway.py+++ b/jiuwenclaw/app_gateway.py@@ -244,6 +244,8 @@ async def _run(agent_server_url: str, web_host: str, web_port: int, web_path: stfeishu_channel = Nonefeishu_task = None+ feishu_enterprise_channels: dict[str, FeishuChannel] = {}+ feishu_enterprise_tasks: dict[str, asyncio.Task] = {}xiaoyi_channel = Nonexiaoyi_task = Nonedingtalk_channel = None@@ -309,10 +311,11 @@ async def _run(agent_server_url: str, web_host: str, web_port: int, web_path: stnonlocal feishu_channel, feishu_task, xiaoyi_channel, xiaoyi_tasknonlocal dingtalk_channel, dingtalk_task, telegram_channel, telegram_tasknonlocal discord_channel, discord_task, whatsapp_channel, whatsapp_task, _last_channels_conf+ nonlocal feishu_enterprise_channels, feishu_enterprise_taskschanged = [c- for c in ["feishu", "xiaoyi", "dingtalk", "telegram", "discord", "whatsapp"]+ for c in ["feishu", "feishu_enterprise", "xiaoyi", "dingtalk", "telegram", "discord", "whatsapp"]if _should_restart_channel(c, _last_channels_conf, conf)]_last_channels_conf = dict(conf or {})@@ -338,6 +341,62 @@ async def _run(agent_server_url: str, web_host: str, web_port: int, web_path: stchannel_manager.register_channel(feishu_channel)feishu_task = asyncio.create_task(feishu_channel.start(), name="feishu")+ if "feishu_enterprise" in changed:+ for bot_key, task in list(feishu_enterprise_tasks.items()):+ await _stop_channel(+ feishu_enterprise_channels.get(bot_key),+ task,+ f"feishu_enterprise[{bot_key}]",+ )+ feishu_enterprise_channels = {}+ feishu_enterprise_tasks = {}++ enterprise_conf = conf.get("feishu_enterprise") if isinstance(conf, dict) else None+ if not isinstance(enterprise_conf, dict):+ logger.info("[Gateway] channels.feishu_enterprise 未配置或格式错误,FeishuEnterpriseChannel 不启用")+ else:+ for bot_key, bot_conf_raw in enterprise_conf.items():+ if not isinstance(bot_key, str) or not bot_key.strip():+ continue+ bot_conf = bot_conf_raw if isinstance(bot_conf_raw, dict) else None+ if bot_conf is None:+ logger.info("[Gateway] channels.feishu_enterprise.%s 配置格式错误,跳过", bot_key)+ continue+ enabled, reason = _is_channel_enabled(bot_conf, ["app_id", "app_secret"])+ if not enabled:+ logger.info(+ "[Gateway] channels.feishu_enterprise.%s.%s,FeishuEnterpriseChannel 未启用",+ bot_key,+ reason,+ )+ continue++ bot_key = bot_key.strip()+ app_id = str(bot_conf.get("app_id") or "").strip()+ channel_id = f"feishu_enterprise:{app_id}"+ feishu_config = FeishuConfig(+ enabled=True,+ app_id=app_id,+ app_secret=str(bot_conf.get("app_secret") or "").strip(),+ encrypt_key=str(bot_conf.get("encrypt_key") or "").strip(),+ verification_token=str(bot_conf.get("verification_token") or "").strip(),+ allow_from=bot_conf.get("allow_from") or [],+ enable_streaming=bool(bot_conf.get("enable_streaming", True)),+ chat_id=str(bot_conf.get("chat_id") or "").strip(),+ channel_id=channel_id,+ bot_key=bot_key,+ )+ channel = FeishuChannel(feishu_config, _DummyBus())+ channel_manager.register_channel(channel)+ task = asyncio.create_task(channel.start(), name=f"feishu-enterprise-{bot_key}")+ feishu_enterprise_channels[bot_key] = channel+ feishu_enterprise_tasks[bot_key] = task+ logger.info(+ "[Gateway] 已按 config.yaml.channels.feishu_enterprise.%s 注册 FeishuChannel(%s)",+ bot_key,+ channel_id,+ )+if "xiaoyi" in changed:xiaoyi_conf = conf.get("xiaoyi") if isinstance(conf, dict) else Noneawait _stop_channel(xiaoyi_channel, xiaoyi_task, "xiaoyi")@@ -488,6 +547,16 @@ async def _run(agent_server_url: str, web_host: str, web_port: int, web_path: stpassawait ch.stop()+ for bot_key, task in list(feishu_enterprise_tasks.items()):+ task.cancel()+ try:+ await task+ except asyncio.CancelledError:+ pass+ channel = feishu_enterprise_channels.get(bot_key)+ if channel is not None:+ await channel.stop()+await cron_scheduler.stop()await channel_manager.stop_dispatch()await heartbeat_service.stop()