77import tempfile
88from typing import Any , Optional , cast
99
10+ from ..agent .identifier import validate as validate_agent_id
1011from ..types .exceptions import SessionException
1112from ..types .session import Session , SessionAgent , SessionMessage
13+ from .identifier import validate as validate_session_id
1214from .repository_session_manager import RepositorySessionManager
1315from .session_repository import SessionRepository
1416
@@ -40,8 +42,9 @@ def __init__(self, session_id: str, storage_dir: Optional[str] = None, **kwargs:
4042 """Initialize FileSession with filesystem storage.
4143
4244 Args:
43- session_id: ID for the session
44- storage_dir: Directory for local filesystem storage (defaults to temp dir)
45+ session_id: ID for the session.
46+ ID is not allowed to contain path separators (e.g., a/b).
47+ storage_dir: Directory for local filesystem storage (defaults to temp dir).
4548 **kwargs: Additional keyword arguments for future extensibility.
4649 """
4750 self .storage_dir = storage_dir or os .path .join (tempfile .gettempdir (), "strands/sessions" )
@@ -50,12 +53,29 @@ def __init__(self, session_id: str, storage_dir: Optional[str] = None, **kwargs:
5053 super ().__init__ (session_id = session_id , session_repository = self )
5154
5255 def _get_session_path (self , session_id : str ) -> str :
53- """Get session directory path."""
56+ """Get session directory path.
57+
58+ Args:
59+ session_id: ID for the session.
60+
61+ Raises:
62+ ValueError: If session id contains a path separator.
63+ """
64+ session_id = validate_session_id (session_id )
5465 return os .path .join (self .storage_dir , f"{ SESSION_PREFIX } { session_id } " )
5566
5667 def _get_agent_path (self , session_id : str , agent_id : str ) -> str :
57- """Get agent directory path."""
68+ """Get agent directory path.
69+
70+ Args:
71+ session_id: ID for the session.
72+ agent_id: ID for the agent.
73+
74+ Raises:
75+ ValueError: If session id or agent id contains a path separator.
76+ """
5877 session_path = self ._get_session_path (session_id )
78+ agent_id = validate_agent_id (agent_id )
5979 return os .path .join (session_path , "agents" , f"{ AGENT_PREFIX } { agent_id } " )
6080
6181 def _get_message_path (self , session_id : str , agent_id : str , message_id : int ) -> str :
0 commit comments