diff --git a/hendrik.py b/hendrik.py index 65683f3..5c0e36f 100644 --- a/hendrik.py +++ b/hendrik.py @@ -2,16 +2,15 @@ import os, sys, threading, time, signal import config -from tools import coder, rag, carrack +from tools import coder, rag, carrack from services.xmpp_client import XMPPClient from services.telegram_client import TelegramClient - from services.llm_client import LLMClient -from scripts.personality import build_system_prompt -from scripts import gadget -from tui import HendrikTUI +from lib import gadget, personality + +from interfaces.tui import HendrikTUI tools_definition = [ @@ -37,7 +36,6 @@ tools_definition = [ TOOLS = gadget.tool_schemas (tools_definition) TOOL_HANDLERS = gadget.tool_handlers (tools_definition) - def main(): llm_client = LLMClient(config.llm_baseurl, config.llm_model, config.llm_api_key, config.llm_timeout) @@ -69,7 +67,7 @@ def main(): tools_definition = tools_definition, TOOLS = TOOLS, TOOL_HANDLERS = TOOL_HANDLERS, - build_system_prompt = build_system_prompt, + build_system_prompt = personality.build_system_prompt, agent_max_iterations = config.AGENT_MAX_ITERATIONS, muc_rooms = muc_rooms, ) @@ -86,7 +84,7 @@ def main(): tools_definition = tools_definition, TOOLS = TOOLS, TOOL_HANDLERS = TOOL_HANDLERS, - build_system_prompt = build_system_prompt, + build_system_prompt = personality.build_system_prompt, agent_max_iterations = config.AGENT_MAX_ITERATIONS, allowed_group_ids = allowed_ids, ) @@ -124,7 +122,7 @@ def main(): tools_definition = tools_definition, TOOLS = TOOLS, TOOL_HANDLERS = TOOL_HANDLERS, - build_system_prompt = build_system_prompt, + build_system_prompt = personality.build_system_prompt, agent_max_iterations = config.AGENT_MAX_ITERATIONS, ).run() diff --git a/tui/__init__.py b/interfaces/tui/__init__.py similarity index 100% rename from tui/__init__.py rename to interfaces/tui/__init__.py diff --git a/tui/agent.py b/interfaces/tui/agent.py similarity index 99% rename from tui/agent.py rename to interfaces/tui/agent.py index b0fb0e7..2dc00ab 100644 --- a/tui/agent.py +++ b/interfaces/tui/agent.py @@ -2,7 +2,7 @@ import json import threading from datetime import datetime import config -from scripts import ntro, agent_loop +from lib import ntro, agent_loop def _add_msg(app, role, content, **kwargs): diff --git a/tui/app.py b/interfaces/tui/app.py similarity index 100% rename from tui/app.py rename to interfaces/tui/app.py diff --git a/tui/input.py b/interfaces/tui/input.py similarity index 100% rename from tui/input.py rename to interfaces/tui/input.py diff --git a/tui/render.py b/interfaces/tui/render.py similarity index 100% rename from tui/render.py rename to interfaces/tui/render.py diff --git a/scripts/__init__.py b/lib/__init__.py similarity index 100% rename from scripts/__init__.py rename to lib/__init__.py diff --git a/scripts/agent_loop.py b/lib/agent_loop.py similarity index 100% rename from scripts/agent_loop.py rename to lib/agent_loop.py diff --git a/scripts/gadget.py b/lib/gadget.py similarity index 100% rename from scripts/gadget.py rename to lib/gadget.py diff --git a/scripts/ntro.py b/lib/ntro.py similarity index 100% rename from scripts/ntro.py rename to lib/ntro.py diff --git a/scripts/personality.py b/lib/personality.py similarity index 100% rename from scripts/personality.py rename to lib/personality.py diff --git a/services/llm_client.py b/services/llm_client.py index c32ec01..ec0df4a 100644 --- a/services/llm_client.py +++ b/services/llm_client.py @@ -1,5 +1,5 @@ import json -from scripts import gadget +from lib import gadget import urllib.request import urllib.error diff --git a/services/telegram_client.py b/services/telegram_client.py index 6564b2a..ec611fc 100644 --- a/services/telegram_client.py +++ b/services/telegram_client.py @@ -7,8 +7,8 @@ from datetime import datetime import config from services.session_manager import SessionManager -from scripts.agent_loop import run_agent_loop -from scripts.personality import PERSONALITY +from lib.agent_loop import run_agent_loop +from lib import personality from tools.roleplayer import _name_mentioned @@ -153,7 +153,7 @@ class TelegramClient: has_mention = True break - name_mentioned = _name_mentioned(PERSONALITY.name, text) + name_mentioned = _name_mentioned(personality.PERSONALITY.name, text) if not replied_to_bot and not has_mention and not name_mentioned: print(f'[{_ts()}] Telegram Group [{chat_id}] NO-REPLY: {text[:60]}', flush=True) diff --git a/services/xmpp_client.py b/services/xmpp_client.py index 7e0be81..50b9c0d 100644 --- a/services/xmpp_client.py +++ b/services/xmpp_client.py @@ -6,11 +6,11 @@ from datetime import datetime from slixmpp import ClientXMPP from services.session_manager import SessionManager -from scripts.agent_loop import run_agent_loop +from lib.agent_loop import run_agent_loop import config from tools.roleplayer import should_respond -from scripts.personality import PERSONALITY +from lib import personality # Anti-ban: delay constants for MUC rejoin behavior MUC_REJOIN_INITIAL_DELAY = 5.0 # detik, delay awal sebelum rejoin @@ -306,7 +306,7 @@ class XMPPClient(ClientXMPP): if self._loop and not self._loop.is_closed(): asyncio.run_coroutine_threadsafe(_read_delay(), self._loop) - my_name = PERSONALITY.name + my_name = personality.PERSONALITY.name quote = body def on_tool_calls(tnames): @@ -384,7 +384,7 @@ class XMPPClient(ClientXMPP): if self._loop and not self._loop.is_closed(): asyncio.run_coroutine_threadsafe(_read_delay(), self._loop) - my_name = PERSONALITY.name + my_name = personality.PERSONALITY.name quote = f'[{nick}] {body}' def on_tool_calls(tnames): @@ -436,7 +436,7 @@ class XMPPClient(ClientXMPP): session.start_timer(300, self._timeout_session, room, 'groupchat') def _execute_tool(self, tool_call): - from scripts.agent_loop import execute_tool + from lib.agent_loop import execute_tool return execute_tool(tool_call, self._TOOL_HANDLERS) def _schedule_send(self, to, body, mtype='chat'):