|
17 | 17 | from datetime import datetime |
18 | 18 | import json |
19 | 19 | import logging |
20 | | -from typing import Any |
21 | | -from typing import Optional |
| 20 | +from typing import Any, Optional |
22 | 21 | import uuid |
23 | 22 |
|
| 23 | +from google.genai import types |
24 | 24 | from sqlalchemy import Boolean |
25 | 25 | from sqlalchemy import delete |
26 | 26 | from sqlalchemy import Dialect |
@@ -136,7 +136,7 @@ class StorageEvent(Base): |
136 | 136 | author: Mapped[str] = mapped_column(String) |
137 | 137 | branch: Mapped[str] = mapped_column(String, nullable=True) |
138 | 138 | timestamp: Mapped[DateTime] = mapped_column(DateTime(), default=func.now()) |
139 | | - content: Mapped[dict[str, Any]] = mapped_column(DynamicJSON) |
| 139 | + content: Mapped[dict[str, Any]] = mapped_column(DynamicJSON, nullable=True) |
140 | 140 | actions: Mapped[MutableDict[str, Any]] = mapped_column(PickleType) |
141 | 141 |
|
142 | 142 | long_running_tool_ids_json: Mapped[Optional[str]] = mapped_column( |
@@ -576,8 +576,12 @@ def _merge_state(app_state, user_state, session_state): |
576 | 576 | return merged_state |
577 | 577 |
|
578 | 578 |
|
579 | | -def _decode_content(content: dict[str, Any]) -> dict[str, Any]: |
| 579 | +def _decode_content( |
| 580 | + content: Optional[dict[str, Any]], |
| 581 | +) -> Optional[types.Content]: |
| 582 | + if not content: |
| 583 | + return None |
580 | 584 | for p in content["parts"]: |
581 | 585 | if "inline_data" in p: |
582 | 586 | p["inline_data"]["data"] = base64.b64decode(p["inline_data"]["data"][0]) |
583 | | - return content |
| 587 | + return types.Content.model_validate(content) |
0 commit comments