GLMPilot / packages /server /src /websocket /session-id.ts
E5K7's picture
Initial commit: Rebranded to GLMPilot and migrated to GLM-5 API
c2c8c8d
import type { Socket } from 'socket.io';
/** Same logical tab/session as the client sends in `query` + `auth` (must match for stdin + output). */
export function getStableSessionId(socket: Socket): string {
const auth = socket.handshake.auth as { sessionId?: unknown } | undefined;
const fromAuth = auth?.sessionId;
if (typeof fromAuth === 'string' && fromAuth.length > 0) return fromAuth;
const raw = socket.handshake.query.sessionId;
const q = Array.isArray(raw) ? raw[0] : raw;
if (typeof q === 'string' && q.length > 0) return q;
return socket.id;
}