diff --git a/modules/web_api/llm/db/db_prompts.py b/modules/web_api/llm/db/db_prompts.py index ea55934..324d944 100644 --- a/modules/web_api/llm/db/db_prompts.py +++ b/modules/web_api/llm/db/db_prompts.py @@ -18,7 +18,7 @@ logger = logging.getLogger("DB_PROMPTS") def init_prompt_nodes_table(): """Создает реляционную таблицу узлов промпта и заполняет базовыми данными.""" - with get_db_connection() as conn: + with get_db_connection(row_factory=True) as conn: cursor = conn.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS system_prompt_nodes ( @@ -73,7 +73,7 @@ def init_prompt_nodes_table(): def db_get_active_system_prompt(prompt_name: str = "main_agent") -> str: """Собирает структурированный текст промпта из реляционной таблицы узлов.""" init_prompt_nodes_table() - with get_db_connection() as conn: + with get_db_connection(row_factory=True) as conn: cursor = conn.cursor() cursor.execute(""" SELECT section_id, item_id, content @@ -104,7 +104,7 @@ def db_get_active_system_prompt(prompt_name: str = "main_agent") -> str: def db_apply_prompt_node_action(action: str, section_id: int, item_id: int, content: str = "", prompt_name: str = "main_agent"): """Прямое добавление, изменение или удаление узла в БД.""" init_prompt_nodes_table() - with get_db_connection() as conn: + with get_db_connection(row_factory=True) as conn: cursor = conn.cursor() action_clean = action.upper() if action_clean in ["ADD", "UPDATE"]: @@ -125,7 +125,7 @@ def db_apply_prompt_node_action(action: str, section_id: int, item_id: int, cont def db_get_tool_action(tool_name: str) -> Optional[Dict[str, Any]]: - conn = get_db_connection() + conn = get_db_connection(row_factory=True) cursor = conn.cursor() cursor.execute(""" SELECT tool_name, category, bypass_llm, success_template, @@ -144,7 +144,7 @@ def db_get_tool_action(tool_name: str) -> Optional[Dict[str, Any]]: def db_get_rules() -> List[Dict[str, Any]]: - conn = get_db_connection() + conn = get_db_connection(row_factory=True) cursor = conn.cursor() cursor.execute("SELECT id, rule_text FROM ai_knowledge_base ORDER BY id ASC") rows = cursor.fetchall() @@ -154,7 +154,7 @@ def db_get_rules() -> List[Dict[str, Any]]: def db_set_session_state(session_id: str, state_type: str, data: Any) -> None: """Сохраняет состояние сессии в SQLite.""" - conn = get_db_connection() + conn = get_db_connection(row_factory=True) cursor = conn.cursor() payload_str = json.dumps(data, ensure_ascii=False) if isinstance(data, (dict, list)) else (str(data) if data is not None else "") cursor.execute(""" @@ -170,7 +170,7 @@ def db_set_session_state(session_id: str, state_type: str, data: Any) -> None: def db_get_session_state(session_id: str) -> Optional[Dict[str, Any]]: - conn = get_db_connection() + conn = get_db_connection(row_factory=True) cursor = conn.cursor() cursor.execute("SELECT session_id, state_type, pending_data, updated_at FROM session_states WHERE session_id = ?", (session_id,)) row = cursor.fetchone() @@ -187,7 +187,7 @@ def db_get_session_state(session_id: str) -> Optional[Dict[str, Any]]: def db_clear_session_state(session_id: str) -> None: - conn = get_db_connection() + conn = get_db_connection(row_factory=True) cursor = conn.cursor() cursor.execute("DELETE FROM session_states WHERE session_id = ?", (session_id,)) conn.commit() @@ -195,7 +195,7 @@ def db_clear_session_state(session_id: str) -> None: def db_get_stats() -> Dict[str, Any]: - conn = get_db_connection() + conn = get_db_connection(row_factory=True) cursor = conn.cursor() tables = ['scud_logs', 'zup_staff', 'zup_absences', 'anomalies_history', 'ai_knowledge_base', 'system_prompt_nodes', 'session_states', 'tasks'] stats = {} @@ -210,7 +210,7 @@ def db_get_stats() -> Dict[str, Any]: def db_get_anomalies(limit: int = 100, date_str: Optional[str] = None) -> Dict[str, Any]: - conn = get_db_connection() + conn = get_db_connection(row_factory=True) cursor = conn.cursor() query = "SELECT anomaly_date, fio, anomaly_type, details FROM anomalies_history" params = [] @@ -226,7 +226,7 @@ def db_get_anomalies(limit: int = 100, date_str: Optional[str] = None) -> Dict[s def db_get_reference(category: Optional[str] = None) -> Dict[str, Any]: - conn = get_db_connection() + conn = get_db_connection(row_factory=True) cursor = conn.cursor() query = "SELECT category, title, example_prompt, description FROM system_reference" params = []