List all available sessions known to the server. Returns metadata about each session including ID, timestamps, and summary. Args: filter: Optional filter to narrow down the list of sessions by working directory, git root, repository, or branch.
(self, filter: SessionListFilter | None = None)
| 2978 | return list(models) # Return a copy to prevent cache mutation |
| 2979 | |
| 2980 | async def list_sessions(self, filter: SessionListFilter | None = None) -> list[SessionMetadata]: |
| 2981 | """ |
| 2982 | List all available sessions known to the server. |
| 2983 | |
| 2984 | Returns metadata about each session including ID, timestamps, and summary. |
| 2985 | |
| 2986 | Args: |
| 2987 | filter: Optional filter to narrow down the list of sessions by working directory, |
| 2988 | git root, repository, or branch. |
| 2989 | |
| 2990 | Returns: |
| 2991 | A list of SessionMetadata objects. |
| 2992 | |
| 2993 | Raises: |
| 2994 | RuntimeError: If the client is not connected. |
| 2995 | |
| 2996 | Example: |
| 2997 | >>> sessions = await client.list_sessions() |
| 2998 | >>> for session in sessions: |
| 2999 | ... print(f"Session: {session.sessionId}") |
| 3000 | >>> # Filter sessions by repository |
| 3001 | >>> from copilot.client import SessionListFilter |
| 3002 | >>> filtered = await client.list_sessions(SessionListFilter(repository="owner/repo")) |
| 3003 | """ |
| 3004 | if not self._client: |
| 3005 | raise RuntimeError("Client not connected") |
| 3006 | |
| 3007 | payload: dict = {} |
| 3008 | if filter is not None: |
| 3009 | payload["filter"] = filter.to_dict() |
| 3010 | |
| 3011 | response = await self._client.request("session.list", payload) |
| 3012 | sessions_data = response.get("sessions", []) |
| 3013 | return [SessionMetadata.from_dict(session) for session in sessions_data] |
| 3014 | |
| 3015 | async def get_session_metadata(self, session_id: str) -> SessionMetadata | None: |
| 3016 | """ |