Commit
·
45f26e8
1
Parent(s):
6b92e3c
api endpoints for UI migration v3
Browse files- src/context_manager.py +11 -13
src/context_manager.py
CHANGED
|
@@ -1598,18 +1598,16 @@ Keep the summary concise (approximately 100 tokens)."""
|
|
| 1598 |
# Single query for all context data
|
| 1599 |
query = """
|
| 1600 |
SELECT
|
| 1601 |
-
s.
|
| 1602 |
s.user_metadata,
|
| 1603 |
s.last_activity,
|
| 1604 |
-
u.
|
| 1605 |
-
|
| 1606 |
-
ic.context_summary
|
| 1607 |
FROM sessions s
|
| 1608 |
LEFT JOIN user_contexts u ON s.user_id = u.user_id
|
| 1609 |
-
LEFT JOIN
|
| 1610 |
-
LEFT JOIN interaction_contexts ic ON i.session_id = ic.session_id
|
| 1611 |
WHERE s.session_id = ?
|
| 1612 |
-
ORDER BY
|
| 1613 |
LIMIT 10
|
| 1614 |
"""
|
| 1615 |
|
|
@@ -1661,7 +1659,7 @@ Keep the summary concise (approximately 100 tokens)."""
|
|
| 1661 |
|
| 1662 |
# Process first row for session data
|
| 1663 |
first_row = results[0]
|
| 1664 |
-
if first_row[0]: #
|
| 1665 |
try:
|
| 1666 |
session_data = json.loads(first_row[0])
|
| 1667 |
context["preferences"] = session_data.get("preferences", {})
|
|
@@ -1678,19 +1676,19 @@ Keep the summary concise (approximately 100 tokens)."""
|
|
| 1678 |
|
| 1679 |
context["last_activity"] = first_row[2] # last_activity
|
| 1680 |
|
| 1681 |
-
if first_row[3]: #
|
| 1682 |
context["user_context"] = first_row[3]
|
| 1683 |
context["user_context_loaded"] = True
|
| 1684 |
|
| 1685 |
# Process interaction contexts
|
| 1686 |
seen_interactions = set()
|
| 1687 |
for row in results:
|
| 1688 |
-
if row[
|
| 1689 |
# Deduplicate interactions
|
| 1690 |
-
if row[
|
| 1691 |
-
seen_interactions.add(row[
|
| 1692 |
context["interaction_contexts"].append({
|
| 1693 |
-
"summary": row[
|
| 1694 |
"timestamp": None # Could extract from row if available
|
| 1695 |
})
|
| 1696 |
|
|
|
|
| 1598 |
# Single query for all context data
|
| 1599 |
query = """
|
| 1600 |
SELECT
|
| 1601 |
+
s.context_data,
|
| 1602 |
s.user_metadata,
|
| 1603 |
s.last_activity,
|
| 1604 |
+
u.persona_summary,
|
| 1605 |
+
ic.interaction_summary
|
|
|
|
| 1606 |
FROM sessions s
|
| 1607 |
LEFT JOIN user_contexts u ON s.user_id = u.user_id
|
| 1608 |
+
LEFT JOIN interaction_contexts ic ON s.session_id = ic.session_id
|
|
|
|
| 1609 |
WHERE s.session_id = ?
|
| 1610 |
+
ORDER BY ic.created_at DESC
|
| 1611 |
LIMIT 10
|
| 1612 |
"""
|
| 1613 |
|
|
|
|
| 1659 |
|
| 1660 |
# Process first row for session data
|
| 1661 |
first_row = results[0]
|
| 1662 |
+
if first_row[0]: # context_data
|
| 1663 |
try:
|
| 1664 |
session_data = json.loads(first_row[0])
|
| 1665 |
context["preferences"] = session_data.get("preferences", {})
|
|
|
|
| 1676 |
|
| 1677 |
context["last_activity"] = first_row[2] # last_activity
|
| 1678 |
|
| 1679 |
+
if first_row[3]: # persona_summary
|
| 1680 |
context["user_context"] = first_row[3]
|
| 1681 |
context["user_context_loaded"] = True
|
| 1682 |
|
| 1683 |
# Process interaction contexts
|
| 1684 |
seen_interactions = set()
|
| 1685 |
for row in results:
|
| 1686 |
+
if row[4]: # interaction_summary
|
| 1687 |
# Deduplicate interactions
|
| 1688 |
+
if row[4] not in seen_interactions:
|
| 1689 |
+
seen_interactions.add(row[4])
|
| 1690 |
context["interaction_contexts"].append({
|
| 1691 |
+
"summary": row[4],
|
| 1692 |
"timestamp": None # Could extract from row if available
|
| 1693 |
})
|
| 1694 |
|