@@ -37,6 +37,7 @@ class SQLiteCache(Cache):
3737 referenced_documents | text | |
3838 tool_calls | text | |
3939 tool_results | text | |
40+ attachments | text | |
4041 Indexes:
4142 "cache_pkey" PRIMARY KEY, btree (user_id, conversation_id, created_at)
4243 "cache_key_key" UNIQUE CONSTRAINT, btree (key)
@@ -59,6 +60,7 @@ class SQLiteCache(Cache):
5960 referenced_documents text,
6061 tool_calls text,
6162 tool_results text,
63+ attachments text,
6264 PRIMARY KEY(user_id, conversation_id, created_at)
6365 );
6466 """
@@ -80,7 +82,7 @@ class SQLiteCache(Cache):
8082
8183 SELECT_CONVERSATION_HISTORY_STATEMENT = """
8284 SELECT query, response, provider, model, started_at, completed_at,
83- referenced_documents, tool_calls, tool_results
85+ referenced_documents, tool_calls, tool_results, attachments
8486 FROM cache
8587 WHERE user_id=? AND conversation_id=?
8688 ORDER BY created_at
@@ -89,8 +91,8 @@ class SQLiteCache(Cache):
8991 INSERT_CONVERSATION_HISTORY_STATEMENT = """
9092 INSERT INTO cache(user_id, conversation_id, created_at, started_at, completed_at,
9193 query, response, provider, model, referenced_documents,
92- tool_calls, tool_results)
93- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
94+ tool_calls, tool_results, attachments )
95+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
9496 """
9597
9698 QUERY_CACHE_SIZE = """
@@ -301,6 +303,24 @@ def get( # pylint: disable=R0914
301303 e ,
302304 )
303305
306+ # Parse attachments back into Attachment objects
307+ attachments_json_str = conversation_entry [9 ]
308+ attachments_obj = None
309+ if attachments_json_str :
310+ try :
311+ from models .requests import Attachment
312+
313+ attachments_data = json .loads (attachments_json_str )
314+ attachments_obj = [
315+ Attachment .model_validate (att ) for att in attachments_data
316+ ]
317+ except (json .JSONDecodeError , ValueError ) as e :
318+ logger .warning (
319+ "Failed to deserialize attachments for conversation %s: %s" ,
320+ conversation_id ,
321+ e ,
322+ )
323+
304324 cache_entry = CacheEntry (
305325 query = conversation_entry [0 ],
306326 response = conversation_entry [1 ],
@@ -311,6 +331,7 @@ def get( # pylint: disable=R0914
311331 referenced_documents = docs_obj ,
312332 tool_calls = tool_calls_obj ,
313333 tool_results = tool_results_obj ,
334+ attachments = attachments_obj ,
314335 )
315336 result .append (cache_entry )
316337
@@ -386,6 +407,20 @@ def insert_or_append(
386407 e ,
387408 )
388409
410+ attachments_json = None
411+ if cache_entry .attachments :
412+ try :
413+ attachments_as_dicts = [
414+ att .model_dump (mode = "json" ) for att in cache_entry .attachments
415+ ]
416+ attachments_json = json .dumps (attachments_as_dicts )
417+ except (TypeError , ValueError ) as e :
418+ logger .warning (
419+ "Failed to serialize attachments for conversation %s: %s" ,
420+ conversation_id ,
421+ e ,
422+ )
423+
389424 cursor .execute (
390425 self .INSERT_CONVERSATION_HISTORY_STATEMENT ,
391426 (
@@ -401,6 +436,7 @@ def insert_or_append(
401436 referenced_documents_json ,
402437 tool_calls_json ,
403438 tool_results_json ,
439+ attachments_json ,
404440 ),
405441 )
406442
0 commit comments