Implement source-backed norm finder and saved price previews

This commit is contained in:
anor
2026-12-03 22:56:12 +10:00
parent ed33bd597c
commit 09d092d9b1
12 changed files with 926 additions and 1 deletions
+31
View File
@@ -671,6 +671,37 @@ def replace_scoped_assistant(username: str, tab_id: str, message_id: int,
return cursor.rowcount == 1
def get_scoped_norm_quote(username: str, tab_id: str, quote_id: int) -> dict | None:
"""One saved finder result, never a quote from another user or dialog."""
import json
with _conn() as conn:
row = conn.execute(
"SELECT content FROM messages WHERE id=? AND username=? AND tab_id=? "
"AND role='norm_quote'", (quote_id, username, tab_id),
).fetchone()
if row is None:
return None
try:
data = json.loads(row["content"])
except (ValueError, TypeError):
return None
return {"raw": row["content"], "data": data}
def replace_scoped_norm_quote(username: str, tab_id: str, quote_id: int,
old_content: str, new_content: str) -> bool:
"""Compare and swap one finder result 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='norm_quote' AND content=?",
(new_content, quote_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."""