Get the ID of the most recently updated session. This is useful for resuming the last conversation when the session ID was not stored. Returns: The session ID, or None if no sessions exist. Raises: RuntimeError: If the client is not
(self)
| 3076 | del self._sessions[session_id] |
| 3077 | |
| 3078 | async def get_last_session_id(self) -> str | None: |
| 3079 | """ |
| 3080 | Get the ID of the most recently updated session. |
| 3081 | |
| 3082 | This is useful for resuming the last conversation when the session ID |
| 3083 | was not stored. |
| 3084 | |
| 3085 | Returns: |
| 3086 | The session ID, or None if no sessions exist. |
| 3087 | |
| 3088 | Raises: |
| 3089 | RuntimeError: If the client is not connected. |
| 3090 | |
| 3091 | Example: |
| 3092 | >>> last_id = await client.get_last_session_id() |
| 3093 | >>> if last_id: |
| 3094 | ... config = {"on_permission_request": PermissionHandler.approve_all} |
| 3095 | ... session = await client.resume_session(last_id, config) |
| 3096 | """ |
| 3097 | if not self._client: |
| 3098 | raise RuntimeError("Client not connected") |
| 3099 | |
| 3100 | response = await self._client.request("session.getLastId", {}) |
| 3101 | return response.get("sessionId") |
| 3102 | |
| 3103 | async def get_foreground_session_id(self) -> str | None: |
| 3104 | """ |