diff --git a/agents/add_message.py b/agents/add_message.py
index 6948a46b2b26b8beb814773504b9bf6a5d11f51a..ddcebdc259679e707bc6a9207b59e9701394f0ed 100644
--- a/agents/add_message.py
+++ b/agents/add_message.py
@@ -5,11 +5,12 @@ from tools.storage import Storage
storage = Storage()
-def add_message(content, source="cli", user_did="anon"):
+def add_message(content, source="cli", user_did="anon", hidden=1):
storage.write_note(
content,
source=source,
- user_did=user_did
+ user_did=user_did,
+ hidden=hidden
)
print(f"[+] Сообщение от {source} ({user_did}) добавлено: {content}")
@@ -19,6 +20,7 @@ if __name__ == "__main__":
parser.add_argument("--content", required=True)
parser.add_argument("--source", default="cli")
parser.add_argument("--user_did", default="anon")
+ parser.add_argument("--hidden", default=1)
args = parser.parse_args()
- add_message(args.content, args.source, args.user_did)
+ add_message(args.content, args.source, args.user_did, args.hidden)
diff --git a/agents/tools/storage.py b/agents/tools/storage.py
index abc788acd749ff19c248fcdafda15c563860b24e..e21e261807fa9f5c43099792cef5014bba8eb51e 100644
--- a/agents/tools/storage.py
+++ b/agents/tools/storage.py
@@ -735,7 +735,7 @@ class Storage:
FROM notes n
LEFT JOIN users u ON n.user_did = u.did
WHERE n.user_did = ?
- OR ((n.source = 'user' OR n.source = 'llm') AND n.hidden = 0)
+ OR ((n.source = 'user' OR n.source = 'llm' OR n.source = 'cli') AND n.hidden = 0)
ORDER BY n.timestamp DESC
LIMIT ?
"""
diff --git a/hf_repo/agents/notebook/views.py b/hf_repo/agents/notebook/views.py
index 442d9bd7bc73217f9ab8a1e60dbe7f63a9120737..1757af34596db894229de40b4671ad19743a9535 100644
--- a/hf_repo/agents/notebook/views.py
+++ b/hf_repo/agents/notebook/views.py
@@ -1,5 +1,6 @@
# agents/notebook/views.py
+import re
import bleach
from fastapi import APIRouter, Request, Form
@@ -12,13 +13,20 @@ router = APIRouter()
templates = Jinja2Templates(directory="notebook/templates")
storage = Storage()
-allowed_tags = ['b', 'i', 's', 'u', 'a', 'ol', 'ul', 'li', 'dl', 'dt', 'dd', 'table', 'caption', 'tr', 'th', 'td']
+allowed_tags = ['b', 'i', 's', 'u', 'a', 'ol', 'ul', 'li', 'dl', 'dt', 'dd', 'table', 'caption', 'tr', 'th', 'td', 'code', 'pre', 'blockquote', 'br', 'hr']
allowed_attributes = {
'a': ['href', 'title']
}
-def sanitize_html(text):
- return bleach.clean(text, tags=allowed_tags, attributes=allowed_attributes, strip=True)
+# Очистка сообщений
+def sanitize_html(text: str) -> str:
+ # 1. Сначала очищаем HTML
+ cleaned = bleach.clean(text, tags=allowed_tags, attributes=allowed_attributes, strip=True)
+
+ # 2. Заменяем 3 и более
подряд на ровно два
+ cleaned = re.sub(r'(
\s*){3,}', '
', cleaned, flags=re.IGNORECASE)
+
+ return cleaned
@router.get("/chat")
def chat_page(request: Request):
diff --git a/hf_repo/agents/tools/__init__.py b/hf_repo/agents/tools/__init__.py
index 49652b8f9694110cfa87f3d1903c256af66e9be1..c1623bfec92d28925597e271faa5e7d700376cc7 100644
--- a/hf_repo/agents/tools/__init__.py
+++ b/hf_repo/agents/tools/__init__.py
@@ -1 +1 @@
-from agents.tools.storage import Storage
+from tools.storage import Storage
diff --git a/hf_repo/hf_repo/agents/notebook/templates/messages.html b/hf_repo/hf_repo/agents/notebook/templates/messages.html
index 3df3b2d777024accdd96f1d91091cc41e7609143..b6ba764292e7ba72b64207941e1faa65ebd21505 100644
--- a/hf_repo/hf_repo/agents/notebook/templates/messages.html
+++ b/hf_repo/hf_repo/agents/notebook/templates/messages.html
@@ -25,8 +25,8 @@