2323from typing import Optional
2424import uuid
2525
26+ from google .genai import types
2627from sqlalchemy import Boolean
2728from sqlalchemy import delete
2829from sqlalchemy import Dialect
@@ -252,6 +253,12 @@ class StorageEvent(Base):
252253 custom_metadata : Mapped [dict [str , Any ]] = mapped_column (
253254 DynamicJSON , nullable = True
254255 )
256+ usage_metadata : Mapped [dict [str , Any ]] = mapped_column (
257+ DynamicJSON , nullable = True
258+ )
259+ citation_metadata : Mapped [dict [str , Any ]] = mapped_column (
260+ DynamicJSON , nullable = True
261+ )
255262
256263 partial : Mapped [bool ] = mapped_column (Boolean , nullable = True )
257264 turn_complete : Mapped [bool ] = mapped_column (Boolean , nullable = True )
@@ -318,6 +325,14 @@ def from_event(cls, session: Session, event: Event) -> StorageEvent:
318325 )
319326 if event .custom_metadata :
320327 storage_event .custom_metadata = event .custom_metadata
328+ if event .usage_metadata :
329+ storage_event .usage_metadata = event .usage_metadata .model_dump (
330+ exclude_none = True , mode = "json"
331+ )
332+ if event .citation_metadata :
333+ storage_event .citation_metadata = event .citation_metadata .model_dump (
334+ exclude_none = True , mode = "json"
335+ )
321336 return storage_event
322337
323338 def to_event (self ) -> Event :
@@ -328,17 +343,23 @@ def to_event(self) -> Event:
328343 branch = self .branch ,
329344 actions = self .actions ,
330345 timestamp = self .timestamp .timestamp (),
331- content = _session_util .decode_content (self .content ),
332346 long_running_tool_ids = self .long_running_tool_ids ,
333347 partial = self .partial ,
334348 turn_complete = self .turn_complete ,
335349 error_code = self .error_code ,
336350 error_message = self .error_message ,
337351 interrupted = self .interrupted ,
338- grounding_metadata = _session_util .decode_grounding_metadata (
339- self .grounding_metadata
340- ),
341352 custom_metadata = self .custom_metadata ,
353+ content = _session_util .decode_model (self .content , types .Content ),
354+ grounding_metadata = _session_util .decode_model (
355+ self .grounding_metadata , types .GroundingMetadata
356+ ),
357+ usage_metadata = _session_util .decode_model (
358+ self .usage_metadata , types .GenerateContentResponseUsageMetadata
359+ ),
360+ citation_metadata = _session_util .decode_model (
361+ self .citation_metadata , types .CitationMetadata
362+ ),
342363 )
343364
344365
0 commit comments