99from __future__ import annotations
1010
1111import asyncio
12+ import functools
1213import inspect
14+ import os
15+ import pathlib
1316import threading
1417from collections .abc import Awaitable , Callable
1518from dataclasses import dataclass
@@ -639,7 +642,9 @@ class CopilotSession:
639642 ... unsubscribe()
640643 """
641644
642- def __init__ (self , session_id : str , client : Any , workspace_path : str | None = None ):
645+ def __init__ (
646+ self , session_id : str , client : Any , workspace_path : os .PathLike [str ] | str | None = None
647+ ):
643648 """
644649 Initialize a new CopilotSession.
645650
@@ -655,7 +660,7 @@ def __init__(self, session_id: str, client: Any, workspace_path: str | None = No
655660 """
656661 self .session_id = session_id
657662 self ._client = client
658- self ._workspace_path = workspace_path
663+ self ._workspace_path = os . fsdecode ( workspace_path ) if workspace_path is not None else None
659664 self ._event_handlers : set [Callable [[SessionEvent ], None ]] = set ()
660665 self ._event_handlers_lock = threading .Lock ()
661666 self ._tool_handlers : dict [str , ToolHandler ] = {}
@@ -677,15 +682,19 @@ def rpc(self) -> SessionRpc:
677682 self ._rpc = SessionRpc (self ._client , self .session_id )
678683 return self ._rpc
679684
680- @property
681- def workspace_path (self ) -> str | None :
685+ @functools . cached_property
686+ def workspace_path (self ) -> pathlib . Path | None :
682687 """
683688 Path to the session workspace directory when infinite sessions are enabled.
684689
685690 Contains checkpoints/, plan.md, and files/ subdirectories.
686691 None if infinite sessions are disabled.
687692 """
688- return self ._workspace_path
693+ # Done as a property as self._workspace_path is directly set from a server
694+ # response post-init. So it was either make sure all places directly setting
695+ # the attribute handle the None case appropriately, use a setter for the
696+ # attribute to do the conversion, or just do the conversion lazily via a getter.
697+ return pathlib .Path (self ._workspace_path ) if self ._workspace_path else None
689698
690699 async def send (
691700 self ,
0 commit comments