UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

33 lines • 1.34 kB
/** * When each connection first attached to each session, so the router can name "the earliest-attached connection of * THIS session" (docs/rpc.md, session relocation), not the connection that happened to open some other session first. */ export class SessionAttachOrder { constructor() { this.next = 0; this.order = new Map(); } /** Records `connection`'s first attachment to `sessionId`; a repeated attach keeps its original place. */ attached(sessionId, connection) { const connections = this.order.get(sessionId) ?? new Map(); if (!connections.has(connection)) connections.set(connection, this.next++); this.order.set(sessionId, connections); } detached(sessionId, connection) { const connections = this.order.get(sessionId); connections?.delete(connection); if (connections?.size === 0) this.order.delete(sessionId); } forgetSession(sessionId) { this.order.delete(sessionId); } /** The session's attached connections, earliest first. */ connections(sessionId) { return [...(this.order.get(sessionId) ?? new Map()).entries()] .sort((left, right) => left[1] - right[1]) .map(([connection]) => connection); } } //# sourceMappingURL=session-attach-order.js.map