Create the session, wire up handlers, and register it. Invoked from the reader thread the instant the session.create response arrives (synchronously, before the next message is dispatched) so notifications for the new session id are routed to a regist
(sid: str)
| 2148 | payload.update(trace_ctx) |
| 2149 | |
| 2150 | def _initialize_session(sid: str) -> CopilotSession: |
| 2151 | """Create the session, wire up handlers, and register it. |
| 2152 | |
| 2153 | Invoked from the reader thread the instant the session.create |
| 2154 | response arrives (synchronously, before the next message is |
| 2155 | dispatched) so notifications for the new session id are routed |
| 2156 | to a registered session. |
| 2157 | """ |
| 2158 | setup_start = time.perf_counter() |
| 2159 | s = CopilotSession(sid, self._client, workspace_path=None) |
| 2160 | if self._session_fs_config: |
| 2161 | if create_session_fs_handler is None: |
| 2162 | raise ValueError( |
| 2163 | "create_session_fs_handler is required in session config when " |
| 2164 | "session_fs is enabled in client options." |
| 2165 | ) |
| 2166 | fs_provider: SessionFsProvider = create_session_fs_handler(s) |
| 2167 | caps = self._session_fs_config.get("capabilities") |
| 2168 | if caps and caps.get("sqlite"): |
| 2169 | from .session_fs_provider import SessionFsSqliteProvider |
| 2170 | |
| 2171 | if not isinstance(fs_provider, SessionFsSqliteProvider): |
| 2172 | raise ValueError( |
| 2173 | "SessionFs capabilities declare SQLite support but the provider " |
| 2174 | "does not implement SessionFsSqliteProvider" |
| 2175 | ) |
| 2176 | s._client_session_apis.session_fs = create_session_fs_adapter(fs_provider) |
| 2177 | s._register_tools(tools) |
| 2178 | s._register_commands(commands) |
| 2179 | s._register_permission_handler(on_permission_request) |
| 2180 | s._register_mcp_auth_handler(on_mcp_auth_request) |
| 2181 | if on_user_input_request: |
| 2182 | s._register_user_input_handler(on_user_input_request) |
| 2183 | if on_elicitation_request: |
| 2184 | s._register_elicitation_handler(on_elicitation_request) |
| 2185 | if on_exit_plan_mode_request: |
| 2186 | s._register_exit_plan_mode_handler(on_exit_plan_mode_request) |
| 2187 | if on_auto_mode_switch_request: |
| 2188 | s._register_auto_mode_switch_handler(on_auto_mode_switch_request) |
| 2189 | if canvas_handler is not None: |
| 2190 | s._register_canvas_handler(canvas_handler) |
| 2191 | s._register_bearer_token_providers(_collect_bearer_token_callbacks(provider, providers)) |
| 2192 | if hooks: |
| 2193 | s._register_hooks(hooks) |
| 2194 | if transform_callbacks: |
| 2195 | s._register_transform_callbacks(transform_callbacks) |
| 2196 | if on_event: |
| 2197 | s.on(on_event) |
| 2198 | with self._sessions_lock: |
| 2199 | self._sessions[sid] = s |
| 2200 | log_timing( |
| 2201 | logger, |
| 2202 | logging.DEBUG, |
| 2203 | "CopilotClient.create_session local setup complete", |
| 2204 | setup_start, |
| 2205 | session_id=sid, |
| 2206 | tools_count=len(tools or []), |
| 2207 | commands_count=len(commands or []), |
nothing calls this directly
no test coverage detected