MCPcopy Index your code
hub / github.com/github/copilot-sdk / on

Method on

nodejs/src/session.ts:403–430  ·  view source on GitHub ↗
(
        eventTypeOrHandler: K | SessionEventHandler,
        handler?: TypedSessionEventHandler<K>
    )

Source from the content-addressed store, hash-verified

401 on(handler: SessionEventHandler): () => void;
402
403 on<K extends SessionEventType>(
404 eventTypeOrHandler: K | SessionEventHandler,
405 handler?: TypedSessionEventHandler<K>
406 ): () => void {
407 // Overload 1: on(eventType, handler) - typed event subscription
408 if (typeof eventTypeOrHandler === "string" && handler) {
409 const eventType = eventTypeOrHandler;
410 if (!this.typedEventHandlers.has(eventType)) {
411 this.typedEventHandlers.set(eventType, new Set());
412 }
413 // Cast is safe: handler receives the correctly typed event at dispatch time
414 const storedHandler = handler as (event: SessionEvent) => void;
415 this.typedEventHandlers.get(eventType)!.add(storedHandler);
416 return () => {
417 const handlers = this.typedEventHandlers.get(eventType);
418 if (handlers) {
419 handlers.delete(storedHandler);
420 }
421 };
422 }
423
424 // Overload 2: on(handler) - wildcard subscription
425 const wildcardHandler = eventTypeOrHandler as SessionEventHandler;
426 this.eventHandlers.add(wildcardHandler);
427 return () => {
428 this.eventHandlers.delete(wildcardHandler);
429 };
430 }
431
432 /**
433 * Dispatches an event to all registered handlers.

Callers 15

initializeSessionMethod · 0.95
resumeSessionMethod · 0.95
sendAndWaitMethod · 0.95
forwardToCapiProxyFunction · 0.45
readBodyFunction · 0.45
makeRequestFunction · 0.45
startMethod · 0.45
handleConnectMethod · 0.45
pipeToRealTargetMethod · 0.45
startMethod · 0.45
performRequestMethod · 0.45

Calls 4

setMethod · 0.45
addMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by 11

makeRequestFunction · 0.36
makeHttpsRequestFunction · 0.36
startOAuthMcpServerFunction · 0.36
waitForEventFunction · 0.36
waitForEventFunction · 0.36
startFakeUpstreamFunction · 0.36
waitForEventFunction · 0.36
waitForEventFunction · 0.36
waitForPermissionRequestFunction · 0.36
getNextSessionEventFunction · 0.36