Wire up query history: localStorage session persistence + sidebar UI

This commit is contained in:
2026-08-14 17:44:36 +07:00
parent 9be5819710
commit 057d4ed9dc
23 changed files with 1231 additions and 30 deletions
@@ -24,6 +24,9 @@ CONVERSATION_MIGRATION = (
FEEDBACK_MIGRATION = (
Path(__file__).resolve().parents[1] / "migrations/004_rag_answer_feedback.sql"
)
HISTORY_MIGRATION = (
Path(__file__).resolve().parents[1] / "migrations/005_rag_trace_conversation.sql"
)
class _PlumbingEmbedder:
@@ -117,6 +120,7 @@ def test_real_postgres_migration_insert_and_read_back():
"postgresql://duoc_thu:duoc_thu@localhost:5432/duoc_thu"
)
repository.migrate(MIGRATION)
repository.migrate(HISTORY_MIGRATION)
trace_id = repository.save(
query="Liều abacavir?",
subject_scope="human",
@@ -145,6 +149,7 @@ def test_real_postgres_feedback_upserts_against_a_persisted_trace():
)
repository.migrate(MIGRATION)
repository.migrate(FEEDBACK_MIGRATION)
repository.migrate(HISTORY_MIGRATION)
trace_id = repository.save(
query="Gút dùng thuốc gì?",
subject_scope="human",
@@ -171,6 +176,43 @@ def test_real_postgres_feedback_upserts_against_a_persisted_trace():
assert second == first
def test_real_postgres_history_lists_by_conversation_most_recent_first():
"""Feature-List #25 against a real Postgres: proves the migration,
save()'s new conversation_id column, and list_by_conversation's
filter+order all actually work together, not just against fakes."""
from adapters.postgres import PostgresTraceRepository
repository = PostgresTraceRepository(
"postgresql://duoc_thu:duoc_thu@localhost:5432/duoc_thu"
)
repository.migrate(MIGRATION)
repository.migrate(HISTORY_MIGRATION)
conversation_id = f"history-integration-{uuid.uuid4()}"
first_id = repository.save(
query="Chỉ định của metformin?", subject_scope="human", intent="fact_lookup",
decision="answerable", reason="grounded_evidence_available",
resolved_drug_id="metformin", citations=(), conversation_id=conversation_id,
)
second_id = repository.save(
query="Chống chỉ định của metformin?", subject_scope="human", intent="fact_lookup",
decision="answerable", reason="grounded_evidence_available",
resolved_drug_id="metformin", citations=(), conversation_id=conversation_id,
)
# A different conversation must never leak into this one's history.
repository.save(
query="Liều aspirin?", subject_scope="human", intent="fact_lookup",
decision="answerable", reason="grounded_evidence_available",
resolved_drug_id="aspirin", citations=(),
conversation_id=f"other-{uuid.uuid4()}",
)
rows = repository.list_by_conversation(conversation_id, limit=10)
assert [row.trace_id for row in rows] == [second_id, first_id]
assert all(row.conversation_id == conversation_id for row in rows)
def test_real_postgres_conversation_store_round_trip():
"""F-08's durable conversation history against a real Postgres, not a
fake — proves `append`/`recent` actually persist and window correctly,
@@ -264,6 +306,7 @@ def test_real_rag_agent_end_to_end_through_the_http_api():
"postgresql://duoc_thu:duoc_thu@localhost:5432/duoc_thu"
)
traces.migrate(MIGRATION)
traces.migrate(HISTORY_MIGRATION)
try:
qdrant.create_collection(
collection_name=collection,
@@ -363,6 +406,7 @@ def test_api_round_trip_uses_qdrant_and_persists_postgres_trace():
"postgresql://duoc_thu:duoc_thu@localhost:5432/duoc_thu"
)
traces.migrate(MIGRATION)
traces.migrate(HISTORY_MIGRATION)
try:
qdrant.create_collection(
collection_name=collection,