diff --git a/agents/notebook/views.py b/agents/notebook/views.py
index 442d9bd7bc73217f9ab8a1e60dbe7f63a9120737..1757af34596db894229de40b4671ad19743a9535 100644
--- a/agents/notebook/views.py
+++ b/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/agents/tools/__init__.py b/agents/tools/__init__.py
index 49652b8f9694110cfa87f3d1903c256af66e9be1..c1623bfec92d28925597e271faa5e7d700376cc7 100644
--- a/agents/tools/__init__.py
+++ b/agents/tools/__init__.py
@@ -1 +1 @@
-from agents.tools.storage import Storage
+from tools.storage import Storage
diff --git a/hf_repo/agents/notebook/templates/messages.html b/hf_repo/agents/notebook/templates/messages.html
index 3df3b2d777024accdd96f1d91091cc41e7609143..b6ba764292e7ba72b64207941e1faa65ebd21505 100644
--- a/hf_repo/agents/notebook/templates/messages.html
+++ b/hf_repo/agents/notebook/templates/messages.html
@@ -25,8 +25,8 @@
diff --git a/hf_repo/hf_repo/agents/notebook/views.py b/hf_repo/hf_repo/agents/notebook/views.py
index 7779f71798add544d2953b5df5bc4e7c41aa9c60..442d9bd7bc73217f9ab8a1e60dbe7f63a9120737 100644
--- a/hf_repo/hf_repo/agents/notebook/views.py
+++ b/hf_repo/hf_repo/agents/notebook/views.py
@@ -12,7 +12,7 @@ router = APIRouter()
templates = Jinja2Templates(directory="notebook/templates")
storage = Storage()
-allowed_tags = ['b', 'i', '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']
allowed_attributes = {
'a': ['href', 'title']
}
diff --git a/hf_repo/hf_repo/hf_repo/hf_repo/agents/notebook/views.py b/hf_repo/hf_repo/hf_repo/hf_repo/agents/notebook/views.py
index 2976e44700e87ab3a4f7b0de4303cbfc54ee6fa5..7779f71798add544d2953b5df5bc4e7c41aa9c60 100644
--- a/hf_repo/hf_repo/hf_repo/hf_repo/agents/notebook/views.py
+++ b/hf_repo/hf_repo/hf_repo/hf_repo/agents/notebook/views.py
@@ -1,5 +1,7 @@
# agents/notebook/views.py
+import bleach
+
from fastapi import APIRouter, Request, Form
from fastapi.responses import RedirectResponse, HTMLResponse
from fastapi.templating import Jinja2Templates
@@ -10,6 +12,14 @@ router = APIRouter()
templates = Jinja2Templates(directory="notebook/templates")
storage = Storage()
+allowed_tags = ['b', 'i', 'a', 'ol', 'ul', 'li', 'dl', 'dt', 'dd', 'table', 'caption', 'tr', 'th', 'td']
+allowed_attributes = {
+ 'a': ['href', 'title']
+}
+
+def sanitize_html(text):
+ return bleach.clean(text, tags=allowed_tags, attributes=allowed_attributes, strip=True)
+
@router.get("/chat")
def chat_page(request: Request):
did = request.session.get("did")
@@ -72,7 +82,7 @@ def post_message(
if text.strip():
storage.write_note(
- content=text.strip(),
+ content=sanitize_html(text.strip()),
user_did=did,
source="user",
hidden=is_hidden
diff --git a/hf_repo/hf_repo/hf_repo/hf_repo/agents/requirements.txt b/hf_repo/hf_repo/hf_repo/hf_repo/agents/requirements.txt
index a63403550b2c5653989211469ee0a08a48065867..c515e968c47a5ffa70ce17857ce182ab4c5295e8 100644
--- a/hf_repo/hf_repo/hf_repo/hf_repo/agents/requirements.txt
+++ b/hf_repo/hf_repo/hf_repo/hf_repo/agents/requirements.txt
@@ -12,4 +12,5 @@ jinja2
python-multipart
passlib[bcrypt]
werkzeug
-itsdangerous
\ No newline at end of file
+itsdangerous
+bleach
\ No newline at end of file
diff --git a/hf_repo/hf_repo/hf_repo/hf_repo/hf_repo/agents/notebook/templates/messages.html b/hf_repo/hf_repo/hf_repo/hf_repo/hf_repo/agents/notebook/templates/messages.html
index 8b6c076dad77c38f5846dd71252100836e2c4379..3df3b2d777024accdd96f1d91091cc41e7609143 100644
--- a/hf_repo/hf_repo/hf_repo/hf_repo/hf_repo/agents/notebook/templates/messages.html
+++ b/hf_repo/hf_repo/hf_repo/hf_repo/hf_repo/agents/notebook/templates/messages.html
@@ -46,10 +46,10 @@
Источник: {{ msg.source }} — {{ msg.timestamp[:19].replace('T', ' ') }}
- {{ msg.badges }}Пользователь: {% if msg.username %}{{ msg.username }}{% endif %} {% if msg.user_did !="" %}({{ msg.user_did }}){% endif %}
+ {% if msg.badges %}{{ msg.badges }}{% endif %}Пользователь: {% if msg.username %}{{ msg.username }}{% endif %} {% if msg.user_did %}({{ msg.user_did }}){% endif %}
- {{ msg.text }}
+ {{ msg.text|safe }}
{% endfor %}