myagent-ai 1.23.63 → 1.23.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chatbot/manager.py +11 -1
- package/package.json +1 -1
- package/web/api_server.py +2 -1
package/chatbot/manager.py
CHANGED
|
@@ -106,7 +106,8 @@ class ChatBotManager:
|
|
|
106
106
|
if loop.is_running() and not any(
|
|
107
107
|
t for t in asyncio.all_tasks(loop) if t.get_name() == f"bot_{key}"
|
|
108
108
|
):
|
|
109
|
-
asyncio.ensure_future(self._run_bot(key, bot))
|
|
109
|
+
task = asyncio.ensure_future(self._run_bot(key, bot))
|
|
110
|
+
self._bot_tasks[key] = task
|
|
110
111
|
except Exception as e:
|
|
111
112
|
logger.error(f"平台 {cfg.display_name or cfg.platform} 初始化失败: {e}")
|
|
112
113
|
|
|
@@ -198,8 +199,17 @@ class ChatBotManager:
|
|
|
198
199
|
await bot.start()
|
|
199
200
|
except asyncio.CancelledError:
|
|
200
201
|
logger.info(f"聊天平台 {name} 已取消")
|
|
202
|
+
# Cancelled 意味着外部已调用 stop(),不要重复调用
|
|
201
203
|
except Exception as e:
|
|
202
204
|
logger.error(f"聊天平台 {name} 运行异常: {e}")
|
|
205
|
+
# 异常时必须清理残留的 polling 连接,否则新 bot 会冲突
|
|
206
|
+
try:
|
|
207
|
+
await bot.stop()
|
|
208
|
+
except Exception:
|
|
209
|
+
pass
|
|
210
|
+
# 移除 bot 实例,下次热更新会重新创建全新的 bot
|
|
211
|
+
self._bots.pop(name, None)
|
|
212
|
+
self._bot_tasks.pop(name, None)
|
|
203
213
|
|
|
204
214
|
async def _safe_stop(self, name: str, bot: BaseChatBot):
|
|
205
215
|
"""安全停止单个 bot(不抛异常)"""
|
package/package.json
CHANGED
package/web/api_server.py
CHANGED
|
@@ -307,7 +307,8 @@ class ApiServer:
|
|
|
307
307
|
bot = mgr._bots.get(key)
|
|
308
308
|
if bot:
|
|
309
309
|
logger.info(f"补启动聊天平台: {key}")
|
|
310
|
-
asyncio.create_task(mgr._run_bot(key, bot), name=f"bot_{key}")
|
|
310
|
+
task = asyncio.create_task(mgr._run_bot(key, bot), name=f"bot_{key}")
|
|
311
|
+
mgr._bot_tasks[key] = task
|
|
311
312
|
logger.info("聊天平台配置已热更新")
|
|
312
313
|
|
|
313
314
|
def _setup_routes(self):
|