fix: контекст диалога из БД — единый источник для обоих движков
Агент терял контекст: история жила в двух in-memory хранилищах (Claude --resume / GLM _conversations), которые расщеплялись при переключении движков в одной вкладке и обнулялись при рестарте/деплое. Теперь оба движка реконструируют историю из таблицы messages, которую сервер и так пишет для обоих путей (chat_context — единый источник истины). - chat_context.py: history_messages (GLM messages[]) / history_recap (Claude) - GLM-путь: prior из БД вместо in-memory _conversations - Claude-путь: recap-префикс из БД вместо хрупкого --resume - reset/clear-files теперь чистят историю и в БД - tests/test_chat_context.py: cross-engine видимость + исключение текущего хода Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -94,6 +94,18 @@ def get_history(username: str, tab_id: str, limit: int = 100) -> list[dict]:
|
||||
return [dict(r) for r in reversed(rows)]
|
||||
|
||||
|
||||
def clear_history(username: str, tab_id: str):
|
||||
"""Delete chat messages for one tab — backs the explicit reset action.
|
||||
|
||||
Scoped to a single (username, tab_id); since conversation context now comes
|
||||
from the DB, reset must clear it here or it would have no effect."""
|
||||
with _conn() as conn:
|
||||
conn.execute(
|
||||
"DELETE FROM messages WHERE username = ? AND tab_id = ?",
|
||||
(username, tab_id),
|
||||
)
|
||||
|
||||
|
||||
# === Users ===
|
||||
|
||||
def create_user(email: str, password_hash: str, role: str = "user") -> int:
|
||||
|
||||
Reference in New Issue
Block a user