In-memory SessionMeta registry tracks active terminal sessions with paneId, sessionId, projectPath, title, createdAt, lastActivityAt. GET /api/term/sessions returns all active sessions as JSON array. Registry is updated on WS attach and cleaned up on disconnect.
45 lines
853 B
TypeScript
45 lines
853 B
TypeScript
export interface SessionMeta {
|
|
paneId: string;
|
|
sessionId: string;
|
|
projectPath: string;
|
|
title?: string;
|
|
createdAt: Date;
|
|
lastActivityAt: Date;
|
|
}
|
|
|
|
const sessions = new Map<string, SessionMeta>();
|
|
|
|
export function register(
|
|
sessionId: string,
|
|
paneId: string,
|
|
projectPath: string,
|
|
title?: string,
|
|
): void {
|
|
const now = new Date();
|
|
const existing = sessions.get(paneId);
|
|
if (existing) {
|
|
existing.lastActivityAt = now;
|
|
return;
|
|
}
|
|
sessions.set(paneId, {
|
|
paneId,
|
|
sessionId,
|
|
projectPath,
|
|
title,
|
|
createdAt: now,
|
|
lastActivityAt: now,
|
|
});
|
|
}
|
|
|
|
export function unregister(paneId: string): void {
|
|
sessions.delete(paneId);
|
|
}
|
|
|
|
export function list(): SessionMeta[] {
|
|
return Array.from(sessions.values());
|
|
}
|
|
|
|
export function get(paneId: string): SessionMeta | undefined {
|
|
return sessions.get(paneId);
|
|
}
|