@@ -94,6 +94,35 @@ async def get_context_with_variables(
94
94
95
95
return Context .model_validate (context_data )
96
96
97
+ async def update_context (
98
+ session : AsyncSession , context_id : UUID , context_in : ContextUpdate , project_id : UUID , owner_id : UUID
99
+ ) -> Context | None :
100
+ props = context_in .model_dump (exclude_unset = True )
101
+ if not props :
102
+ # If no properties to update, just return the current context
103
+ return await get_context_with_variables (session , context_id , project_id , owner_id , include_sensitive = True )
104
+
105
+ query = """
106
+ MATCH (user:User {id: $owner_id})-[:OWNS]->(project:Project {id: $project_id})-[:HAS_CONTEXT]->(context:Context {id: $context_id})
107
+ SET context += $props
108
+ RETURN context
109
+ """
110
+ result = await session .run (
111
+ query ,
112
+ {
113
+ "owner_id" : str (owner_id ),
114
+ "project_id" : str (project_id ),
115
+ "context_id" : str (context_id ),
116
+ "props" : props ,
117
+ },
118
+ )
119
+ record = await result .single ()
120
+ if not record :
121
+ return None
122
+
123
+ # Return the updated context with variables
124
+ return await get_context_with_variables (session , context_id , project_id , owner_id , include_sensitive = True )
125
+
97
126
async def delete_context (session : AsyncSession , context_id : UUID , project_id : UUID , owner_id : UUID ) -> bool :
98
127
# Deletes context and all its variables due to DETACH DELETE
99
128
query = """
0 commit comments