diff --git a/agent/characters/kongming/service.default.yaml b/agent/characters/kongming/service.default.yaml index 86bb17b..d6d7c2e 100644 --- a/agent/characters/kongming/service.default.yaml +++ b/agent/characters/kongming/service.default.yaml @@ -11,6 +11,7 @@ xmpp: nickname: "" # custom MUC nickname (empty = use username) selective_response: true # true = only response if mentioned/relevant debug: false # true = tampilkan log debug menyeluruh (semua stanza XML, lifecycle, dll) + mute_session_end: false # true = tidak kirim pesan saat sesi berakhir (timeout) telegram: enabled: false @@ -18,4 +19,5 @@ telegram: allowed_group_ids: # YAML list, empty = all group. e.g.: # - "123456789" # - "987654321" - selective_response: true # true = only response if mentioned/relevant \ No newline at end of file + selective_response: true # true = only response if mentioned/relevant + mute_session_end: false # true = tidak kirim pesan saat sesi berakhir (timeout) diff --git a/agent/characters/lily/service.default.yaml b/agent/characters/lily/service.default.yaml index 86bb17b..d6d7c2e 100644 --- a/agent/characters/lily/service.default.yaml +++ b/agent/characters/lily/service.default.yaml @@ -11,6 +11,7 @@ xmpp: nickname: "" # custom MUC nickname (empty = use username) selective_response: true # true = only response if mentioned/relevant debug: false # true = tampilkan log debug menyeluruh (semua stanza XML, lifecycle, dll) + mute_session_end: false # true = tidak kirim pesan saat sesi berakhir (timeout) telegram: enabled: false @@ -18,4 +19,5 @@ telegram: allowed_group_ids: # YAML list, empty = all group. e.g.: # - "123456789" # - "987654321" - selective_response: true # true = only response if mentioned/relevant \ No newline at end of file + selective_response: true # true = only response if mentioned/relevant + mute_session_end: false # true = tidak kirim pesan saat sesi berakhir (timeout) diff --git a/config.default.yaml b/config.default.yaml index 8eeaad7..824b4b7 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -38,6 +38,7 @@ xmpp: nickname: "" # custom MUC nickname (empty = use username) selective_response: true # true = only response if mentioned/relevant debug: false # true = tampilkan log debug menyeluruh (semua stanza XML, lifecycle, dll) + mute_session_end: false # true = tidak kirim pesan saat sesi berakhir (timeout) telegram: enabled: false @@ -46,3 +47,4 @@ telegram: # - "123456789" # - "987654321" selective_response: true # true = only response if mentioned/relevant + mute_session_end: false # true = tidak kirim pesan saat sesi berakhir (timeout) diff --git a/config.py b/config.py index e2c5ad2..c873de3 100644 --- a/config.py +++ b/config.py @@ -63,6 +63,7 @@ XMPP_MUC_ROOMS = _as_list(_yaml_get("xmpp", "muc_rooms", default=[])) XMPP_NICKNAME = _yaml_get("xmpp", "nickname", default="").strip() XMPP_DEBUG = str(_yaml_get("xmpp", "debug", default="false")).strip().lower() in ("true", "1", "yes") XMPP_SELECTIVE_RESPONSE = str(_yaml_get("xmpp", "selective_response", default="true")).strip().lower() in ("true", "1", "yes") +XMPP_MUTE_SESSION_END = str(_yaml_get("xmpp", "mute_session_end", default="false")).strip().lower() in ("true", "1", "yes") # ─── Telegram ────────────────────────────────────────────────────────────────── @@ -71,6 +72,7 @@ TELEGRAM_ENABLED = str(_yaml_get("telegram", "enabled", default="false")).strip( TELEGRAM_TOKEN = _yaml_get("telegram", "token", default="") TELEGRAM_ALLOWED_GROUP_IDS = _as_list(_yaml_get("telegram", "allowed_group_ids", default=[])) TELEGRAM_SELECTIVE_RESPONSE = str(_yaml_get("telegram", "selective_response", default="true")).strip().lower() in ("true", "1", "yes") +TELEGRAM_MUTE_SESSION_END = str(_yaml_get("telegram", "mute_session_end", default="false")).strip().lower() in ("true", "1", "yes") # ─── Session (TinyDB) ──────────────────────────────────────────────────────────── @@ -155,9 +157,9 @@ SERVICE_YAML_PATH = None # Path service.yaml milik karakter aktif, jika ada def _reset_service_from_config(): """Reset konfigurasi service (xmpp/telegram) dari config.yaml global.""" global XMPP_ENABLED, XMPP_USERNAME, XMPP_PASSWORD, XMPP_MUC_ROOMS - global XMPP_NICKNAME, XMPP_DEBUG, XMPP_SELECTIVE_RESPONSE + global XMPP_NICKNAME, XMPP_DEBUG, XMPP_SELECTIVE_RESPONSE, XMPP_MUTE_SESSION_END global TELEGRAM_ENABLED, TELEGRAM_TOKEN, TELEGRAM_ALLOWED_GROUP_IDS - global TELEGRAM_SELECTIVE_RESPONSE, SERVICE_YAML_PATH + global TELEGRAM_SELECTIVE_RESPONSE, TELEGRAM_MUTE_SESSION_END, SERVICE_YAML_PATH XMPP_USERNAME = _yaml_get("xmpp", "username", default="") XMPP_PASSWORD = _yaml_get("xmpp", "password", default="") @@ -166,11 +168,13 @@ def _reset_service_from_config(): XMPP_NICKNAME = _yaml_get("xmpp", "nickname", default="").strip() XMPP_DEBUG = str(_yaml_get("xmpp", "debug", default="false")).strip().lower() in ("true", "1", "yes") XMPP_SELECTIVE_RESPONSE = str(_yaml_get("xmpp", "selective_response", default="true")).strip().lower() in ("true", "1", "yes") + XMPP_MUTE_SESSION_END = str(_yaml_get("xmpp", "mute_session_end", default="false")).strip().lower() in ("true", "1", "yes") TELEGRAM_ENABLED = str(_yaml_get("telegram", "enabled", default="false")).strip().lower() in ("true", "1", "yes") TELEGRAM_TOKEN = _yaml_get("telegram", "token", default="") TELEGRAM_ALLOWED_GROUP_IDS = _as_list(_yaml_get("telegram", "allowed_group_ids", default=[])) TELEGRAM_SELECTIVE_RESPONSE = str(_yaml_get("telegram", "selective_response", default="true")).strip().lower() in ("true", "1", "yes") + TELEGRAM_MUTE_SESSION_END = str(_yaml_get("telegram", "mute_session_end", default="false")).strip().lower() in ("true", "1", "yes") SERVICE_YAML_PATH = None @@ -180,9 +184,9 @@ def load_service_config(char_override=None): karakter aktif, jika file tersebut ada di agent/characters//. Memanggil load_character() bila char_override diberikan.""" global XMPP_ENABLED, XMPP_USERNAME, XMPP_PASSWORD, XMPP_MUC_ROOMS - global XMPP_NICKNAME, XMPP_DEBUG, XMPP_SELECTIVE_RESPONSE + global XMPP_NICKNAME, XMPP_DEBUG, XMPP_SELECTIVE_RESPONSE, XMPP_MUTE_SESSION_END global TELEGRAM_ENABLED, TELEGRAM_TOKEN, TELEGRAM_ALLOWED_GROUP_IDS - global TELEGRAM_SELECTIVE_RESPONSE, SERVICE_YAML_PATH + global TELEGRAM_SELECTIVE_RESPONSE, TELEGRAM_MUTE_SESSION_END, SERVICE_YAML_PATH _reset_service_from_config() @@ -225,6 +229,8 @@ def load_service_config(char_override=None): XMPP_DEBUG = str(xmpp_data["debug"]).strip().lower() in ("true", "1", "yes") if "selective_response" in xmpp_data: XMPP_SELECTIVE_RESPONSE = str(xmpp_data["selective_response"]).strip().lower() in ("true", "1", "yes") + if "mute_session_end" in xmpp_data: + XMPP_MUTE_SESSION_END = str(xmpp_data["mute_session_end"]).strip().lower() in ("true", "1", "yes") telegram_data = data.get("telegram") or {} if "enabled" in telegram_data: @@ -235,6 +241,8 @@ def load_service_config(char_override=None): TELEGRAM_ALLOWED_GROUP_IDS = _as_list(telegram_data["allowed_group_ids"]) if "selective_response" in telegram_data: TELEGRAM_SELECTIVE_RESPONSE = str(telegram_data["selective_response"]).strip().lower() in ("true", "1", "yes") + if "mute_session_end" in telegram_data: + TELEGRAM_MUTE_SESSION_END = str(telegram_data["mute_session_end"]).strip().lower() in ("true", "1", "yes") # ─── Model Config (model.yaml per karakter) ──────────────────────────────────── diff --git a/services/telegram_client.py b/services/telegram_client.py index 089d7a9..a2b4f01 100644 --- a/services/telegram_client.py +++ b/services/telegram_client.py @@ -332,7 +332,7 @@ class TelegramClient: loggorilla.prcss('telegram', f'Natural close triggered for {chat_id}') self._session_mgr.reset(str(chat_id)) else: - timeout = 86400 if chat_type == 'private' else 300 + timeout = 86400 if chat_type == 'private' else 1800 session.start_timer(timeout, self._timeout_session, chat_id) def _schedule_send(self, chat_id, text, reply_to_msg_id=None): @@ -355,6 +355,7 @@ class TelegramClient: def _timeout_session(self, chat_id): loggorilla.fyinf('telegram', f'Session timeout: {chat_id}') - body = '*session end*' if 'roleplayer' in self._skill else 'Sesi ditutup. Sampai jumpa' - self._schedule_send(chat_id, body) + if not config.TELEGRAM_MUTE_SESSION_END: + body = '*session end*' if 'roleplayer' in self._skill else 'Sesi ditutup. Sampai jumpa' + self._schedule_send(chat_id, body) self._session_mgr.reset(str(chat_id)) diff --git a/services/xmpp_client.py b/services/xmpp_client.py index 762777c..93923c1 100644 --- a/services/xmpp_client.py +++ b/services/xmpp_client.py @@ -652,7 +652,7 @@ class XMPPClient(ClientXMPP): print(f'[{_ts()}] Natural close triggered for {jid}', flush=True) self._session_mgr.reset(jid) else: - # DM: timeout 24 jam (efektif tidak auto-close), MUC tetap 5 menit + # DM: timeout 24 jam (efektif tidak auto-close), MUC 30 menit session.start_timer(86400, self._timeout_session, jid, 'chat') async def _process_muc_async(self, room, nick, body): @@ -692,7 +692,7 @@ class XMPPClient(ClientXMPP): ) if not gate_ok: print(f'[{_ts()}] MUC: need_response=False → staying silent', flush=True) - session.start_timer(300, self._timeout_session, room, 'groupchat') + session.start_timer(1800, self._timeout_session, room, 'groupchat') return # Delay 1: simulasi membaca pesan user (hanya saat akan merespon) @@ -772,7 +772,7 @@ class XMPPClient(ClientXMPP): self._session_mgr.reset(room) return - session.start_timer(300, self._timeout_session, room, 'groupchat') + session.start_timer(1800, self._timeout_session, room, 'groupchat') def _execute_tool(self, tool_call): from lib.agent_loop import execute_tool @@ -879,8 +879,9 @@ class XMPPClient(ClientXMPP): def _timeout_session(self, session_id, mtype): print(f'[{_ts()}] Session timeout: {session_id}', flush=True) - body = '*session end*' if 'roleplayer' in self._skill else 'Sesi ditutup. Sampai jumpa' - self._schedule_send(session_id, body, mtype) + if not config.XMPP_MUTE_SESSION_END: + body = '*session end*' if 'roleplayer' in self._skill else 'Sesi ditutup. Sampai jumpa' + self._schedule_send(session_id, body, mtype) self._session_mgr.reset(session_id) def start(self):