MCPcopy Create free account
hub / github.com/cortexkit/magic-context / watchSession

Function watchSession

packages/plugin/src/tui/data/notification-socket.ts:219–229  ·  view source on GitHub ↗

Cheap session-change watcher: re-scope the socket only when the active session * actually changes. Reads a property; no network at idle.

()

Source from the content-addressed store, hash-verified

217/** Cheap session-change watcher: re-scope the socket only when the active session
218 * actually changes. Reads a property; no network at idle. */
219function watchSession(): void {
220 if (closed || !socket || socket.readyState !== WebSocket.OPEN) return;
221 const current = opts?.getSessionId() ?? null;
222 if (current === helloedSession) return;
223 // Re-hello with the new session; the server replaces this socket's sink scope.
224 const client = getRpcClient();
225 void client?.resolveEndpoint().then((endpoint) => {
226 if (!socket || socket.readyState !== WebSocket.OPEN) return;
227 sendHello(socket, endpoint?.token ?? null);
228 });
229}

Callers

nothing calls this directly

Calls 3

getRpcClientFunction · 0.90
sendHelloFunction · 0.85
resolveEndpointMethod · 0.80

Tested by

no test coverage detected