Skip to content

Commit a36ca22

Browse files
committed
Fix Windows file artifact URI path normalization
1 parent ad937fe commit a36ca22

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/google/adk/artifacts/file_artifact_service.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from typing import Union
2626
from urllib.parse import unquote
2727
from urllib.parse import urlparse
28+
from urllib.request import url2pathname
2829

2930
from google.genai import types
3031
from pydantic import alias_generators
@@ -59,7 +60,10 @@ def _file_uri_to_path(uri: str) -> Optional[Path]:
5960
parsed = urlparse(uri)
6061
if parsed.scheme != "file":
6162
return None
62-
return Path(unquote(parsed.path))
63+
path_str = unquote(parsed.path)
64+
if os.name == "nt":
65+
path_str = url2pathname(path_str)
66+
return Path(path_str)
6367

6468

6569
_USER_NAMESPACE_PREFIX = "user:"

src/google/adk/cli/service_registry.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def my_session_factory(uri: str, **kwargs):
7373
from typing import Protocol
7474
from urllib.parse import unquote
7575
from urllib.parse import urlparse
76+
from urllib.request import url2pathname
7677

7778
from ..artifacts.base_artifact_service import BaseArtifactService
7879
from ..memory.base_memory_service import BaseMemoryService
@@ -293,7 +294,12 @@ def file_artifact_factory(uri: str, **_):
293294
)
294295
if not parsed_uri.path:
295296
raise ValueError("file:// artifact URIs must include a path component.")
296-
artifact_path = Path(unquote(parsed_uri.path))
297+
298+
artifact_path_str = unquote(parsed_uri.path)
299+
if os.name == "nt":
300+
artifact_path_str = url2pathname(artifact_path_str)
301+
302+
artifact_path = Path(artifact_path_str)
297303
return FileArtifactService(root_dir=artifact_path)
298304

299305
registry.register_artifact_service("memory", memory_artifact_factory)

0 commit comments

Comments
 (0)