77import tempfile
88from typing import Any , Optional , cast
99
10+ from .. import _identifier
1011from ..types .exceptions import SessionException
1112from ..types .session import Session , SessionAgent , SessionMessage
1213from .repository_session_manager import RepositorySessionManager
@@ -40,8 +41,9 @@ def __init__(self, session_id: str, storage_dir: Optional[str] = None, **kwargs:
4041 """Initialize FileSession with filesystem storage.
4142
4243 Args:
43- session_id: ID for the session
44- storage_dir: Directory for local filesystem storage (defaults to temp dir)
44+ session_id: ID for the session.
45+ ID is not allowed to contain path separators (e.g., a/b).
46+ storage_dir: Directory for local filesystem storage (defaults to temp dir).
4547 **kwargs: Additional keyword arguments for future extensibility.
4648 """
4749 self .storage_dir = storage_dir or os .path .join (tempfile .gettempdir (), "strands/sessions" )
@@ -50,12 +52,29 @@ def __init__(self, session_id: str, storage_dir: Optional[str] = None, **kwargs:
5052 super ().__init__ (session_id = session_id , session_repository = self )
5153
5254 def _get_session_path (self , session_id : str ) -> str :
53- """Get session directory path."""
55+ """Get session directory path.
56+
57+ Args:
58+ session_id: ID for the session.
59+
60+ Raises:
61+ ValueError: If session id contains a path separator.
62+ """
63+ session_id = _identifier .validate (session_id , _identifier .Identifier .SESSION )
5464 return os .path .join (self .storage_dir , f"{ SESSION_PREFIX } { session_id } " )
5565
5666 def _get_agent_path (self , session_id : str , agent_id : str ) -> str :
57- """Get agent directory path."""
67+ """Get agent directory path.
68+
69+ Args:
70+ session_id: ID for the session.
71+ agent_id: ID for the agent.
72+
73+ Raises:
74+ ValueError: If session id or agent id contains a path separator.
75+ """
5876 session_path = self ._get_session_path (session_id )
77+ agent_id = _identifier .validate (agent_id , _identifier .Identifier .AGENT )
5978 return os .path .join (session_path , "agents" , f"{ AGENT_PREFIX } { agent_id } " )
6079
6180 def _get_message_path (self , session_id : str , agent_id : str , message_id : int ) -> str :
0 commit comments