Add source-linked inline comparison for uploaded estimates

This commit is contained in:
anor
2026-12-03 23:16:11 +10:00
parent 09d092d9b1
commit 8ccbe73d3a
10 changed files with 813 additions and 1 deletions
+36
View File
@@ -702,6 +702,42 @@ def replace_scoped_norm_quote(username: str, tab_id: str, quote_id: int,
return cursor.rowcount == 1
def get_linked_file_compare(username: str, tab_id: str, compare_id: int) -> dict | None:
"""Return a saved file comparison only with its answer in the same dialog."""
import json
with _conn() as conn:
row = conn.execute(
"SELECT content FROM messages WHERE id=? AND username=? AND tab_id=? "
"AND role='file_compare'", (compare_id, username, tab_id),
).fetchone()
if row is None:
return None
try:
data = json.loads(row["content"])
assistant_id = data["_assistant_id"]
except (ValueError, KeyError, TypeError):
return None
answer = conn.execute(
"SELECT 1 FROM messages WHERE id=? AND username=? AND tab_id=? AND role='assistant'",
(assistant_id, username, tab_id),
).fetchone()
return {"raw": row["content"], "data": data} if answer else None
def replace_linked_file_compare(username: str, tab_id: str, compare_id: int,
old_content: str, new_content: str) -> bool:
"""Atomically reject concurrent edits to a comparison in the current dialog."""
with _conn() as conn:
conn.execute("BEGIN IMMEDIATE")
cursor = conn.execute(
"UPDATE messages SET content=? WHERE id=? AND username=? AND tab_id=? "
"AND role='file_compare' AND content=?",
(new_content, compare_id, username, tab_id, old_content),
)
return cursor.rowcount == 1
def replace_linked_estimate(username: str, tab_id: str, estimate_id: int,
expected_revision: int, data: dict, answer: str) -> str:
"""Compare-and-swap answer and estimate in one SQLite transaction."""