Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

style: fix pre-commit issues (ruff-format, prettier, bandit nosec)

WeDoneee9483b0d51f
diff --git a/deeptutor/api/routers/sessions.py b/deeptutor/api/routers/sessions.py
index db4853916..a5db87c82 100644
--- a/deeptutor/api/routers/sessions.py
+++ b/deeptutor/api/routers/sessions.py
@@ -119,7 +119,9 @@ async def delete_turn_by_message(session_id: str, message_id: int):
store = get_sqlite_session_store()
result = await store.delete_turn_by_message(session_id, message_id)
if result["was_running"]:
- raise HTTPException(status_code=409, detail="Cannot delete a message while its turn is running")
+ raise HTTPException(
+ status_code=409, detail="Cannot delete a message while its turn is running"
+ )
if not result["deleted"]:
raise HTTPException(status_code=404, detail="Message not found")
attachment_store = get_attachment_store()
diff --git a/deeptutor/services/session/sqlite_store.py b/deeptutor/services/session/sqlite_store.py
index 95eae0adf..9e763e84c 100644
--- a/deeptutor/services/session/sqlite_store.py
+++ b/deeptutor/services/session/sqlite_store.py
@@ -659,7 +659,12 @@ class SQLiteSessionStore:
(int(message_id),),
).fetchone()
if msg is None or msg["session_id"] != session_id:
- return {"deleted": False, "attachment_ids": [], "turn_id": None, "was_running": False}
+ return {
+ "deleted": False,
+ "attachment_ids": [],
+ "turn_id": None,
+ "was_running": False,
+ }
role = msg["role"]
paired_msg = None
@@ -706,7 +711,12 @@ class SQLiteSessionStore:
was_running = turn_row["status"] == "running"
if was_running:
- return {"deleted": False, "attachment_ids": [], "turn_id": turn_id, "was_running": True}
+ return {
+ "deleted": False,
+ "attachment_ids": [],
+ "turn_id": turn_id,
+ "was_running": True,
+ }
attachment_ids: list[str] = []
for m in [msg, paired_msg]:
@@ -725,7 +735,7 @@ class SQLiteSessionStore:
if paired_msg is not None:
ids_to_delete.append(int(paired_msg["id"]))
conn.execute(
- f"DELETE FROM messages WHERE id IN ({','.join('?' * len(ids_to_delete))})",
+ f"DELETE FROM messages WHERE id IN ({','.join('?' * len(ids_to_delete))})", # nosec B608
tuple(ids_to_delete),
)
diff --git a/web/components/chat/home/ChatMessages.tsx b/web/components/chat/home/ChatMessages.tsx
index b37bf1f69..a26eddfd6 100644
--- a/web/components/chat/home/ChatMessages.tsx
+++ b/web/components/chat/home/ChatMessages.tsx
@@ -365,7 +365,9 @@ const UserMessage = memo(function UserMessage({
</button>
) : (
<div className="flex items-center gap-1.5 text-[12px]">
- <span className="text-[var(--muted-foreground)]">{t("Delete this turn?")}</span>
+ <span className="text-[var(--muted-foreground)]">
+ {t("Delete this turn?")}
+ </span>
<button
type="button"
onClick={() => {
diff --git a/web/context/UnifiedChatContext.tsx b/web/context/UnifiedChatContext.tsx
index 0649ba626..8652cb11f 100644
--- a/web/context/UnifiedChatContext.tsx
+++ b/web/context/UnifiedChatContext.tsx
@@ -19,7 +19,11 @@ import {
} from "@/context/app-shell-storage";
import type { StreamEvent, ChatMessage, LLMSelection } from "@/lib/unified-ws";
import { UnifiedWSClient } from "@/lib/unified-ws";
-import { getSession, deleteMessage, type SessionMessage } from "@/lib/session-api";
+import {
+ getSession,
+ deleteMessage,
+ type SessionMessage,
+} from "@/lib/session-api";
import { normalizeMarkdownForDisplay } from "@/lib/markdown-display";
import { normalizeMessageContent } from "@/lib/message-content";
import { shouldAppendEventContent } from "@/lib/stream";
@@ -494,7 +498,10 @@ function reducer(state: ProviderState, action: Action): ProviderState {
const toRemove = new Set<number>();
toRemove.add(idx);
if (msg.role === "user") {
- if (idx + 1 < session.messages.length && session.messages[idx + 1].role === "assistant") {
+ if (
+ idx + 1 < session.messages.length &&
+ session.messages[idx + 1].role === "assistant"
+ ) {
toRemove.add(idx + 1);
}
} else if (msg.role === "assistant") {