MCPcopy Create free account
hub / github.com/github/copilot-sdk / _handle_elicitation_request

Method _handle_elicitation_request

python/copilot/session.py:2197–2257  ·  view source on GitHub ↗

Handle an elicitation.requested broadcast event. Invokes the registered handler and responds via handlePendingElicitation RPC. Auto-cancels on error so the server doesn't hang.

(
        self,
        context: ElicitationContext,
        request_id: str,
    )

Source from the content-addressed store, hash-verified

2195 pass # Connection lost — nothing we can do
2196
2197 async def _handle_elicitation_request(
2198 self,
2199 context: ElicitationContext,
2200 request_id: str,
2201 ) -> None:
2202 """Handle an elicitation.requested broadcast event.
2203
2204 Invokes the registered handler and responds via handlePendingElicitation RPC.
2205 Auto-cancels on error so the server doesn't hang.
2206 """
2207 with self._elicitation_handler_lock:
2208 handler = self._elicitation_handler
2209 if not handler:
2210 return
2211 try:
2212 handler_start = time.perf_counter()
2213 result = handler(context)
2214 if inspect.isawaitable(result):
2215 result = await result
2216 log_timing(
2217 logger,
2218 logging.DEBUG,
2219 "CopilotSession._handle_elicitation_request dispatch",
2220 handler_start,
2221 session_id=self.session_id,
2222 request_id=request_id,
2223 )
2224 result = cast(ElicitationResult, result)
2225 action_val = result.get("action", "cancel")
2226 rpc_result = UIElicitationResponse(
2227 action=UIElicitationResponseAction(action_val),
2228 content=result.get("content"),
2229 )
2230 rpc_start = time.perf_counter()
2231 await self.rpc.ui.handle_pending_elicitation(
2232 UIHandlePendingElicitationRequest(
2233 request_id=request_id,
2234 result=rpc_result,
2235 )
2236 )
2237 log_timing(
2238 logger,
2239 logging.DEBUG,
2240 "CopilotSession._handle_elicitation_request response sent successfully",
2241 rpc_start,
2242 session_id=self.session_id,
2243 request_id=request_id,
2244 )
2245 except Exception:
2246 # Handler failed — attempt to cancel so the request doesn't hang
2247 try:
2248 await self.rpc.ui.handle_pending_elicitation(
2249 UIHandlePendingElicitationRequest(
2250 request_id=request_id,
2251 result=UIElicitationResponse(
2252 action=UIElicitationResponseAction.CANCEL,
2253 ),
2254 )

Calls 7

handlerFunction · 0.85
log_timingFunction · 0.85
getMethod · 0.45