feat(runtime): sync experience bus and learner stack into main
This commit is contained in:
@@ -443,6 +443,9 @@ class Database:
|
||||
) -> Dict[str, Any]:
|
||||
"""Create or update a user fact (isolated by agent_id)"""
|
||||
import json
|
||||
# Normalize NULL to empty string so ON CONFLICT matches (PostgreSQL: NULL != NULL in unique)
|
||||
_agent_id = (agent_id or "").strip()
|
||||
_team_id = team_id or ""
|
||||
# Convert dict to JSON string for asyncpg JSONB
|
||||
json_value = json.dumps(fact_value_json) if fact_value_json else None
|
||||
|
||||
@@ -457,7 +460,7 @@ class Database:
|
||||
fact_value_json = EXCLUDED.fact_value_json,
|
||||
updated_at = NOW()
|
||||
RETURNING *
|
||||
""", user_id, team_id, agent_id, fact_key, fact_value, json_value)
|
||||
""", user_id, _team_id, _agent_id, fact_key, fact_value, json_value)
|
||||
except asyncpg.exceptions.InvalidColumnReferenceError:
|
||||
# Backward compatibility for DBs that only have UNIQUE(user_id, team_id, fact_key).
|
||||
row = await conn.fetchrow("""
|
||||
@@ -470,7 +473,7 @@ class Database:
|
||||
fact_value_json = EXCLUDED.fact_value_json,
|
||||
updated_at = NOW()
|
||||
RETURNING *
|
||||
""", user_id, team_id, agent_id, fact_key, fact_value, json_value)
|
||||
""", user_id, _team_id, _agent_id, fact_key, fact_value, json_value)
|
||||
|
||||
return dict(row) if row else {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user