Skip to content

BaseSessionManager

Defined in: session/manager.ts:129

Base implementation of session manager with common functionality.

Extend this class to create domain-specific session managers. You only need to implement createSession and closeSession.

class APIClientManager extends BaseSessionManager<APIClient, APIConfig> {
async createSession(config?: APIConfig): Promise<string> {
const client = new APIClient(config);
const id = this.generateId("api");
this.sessions.set(id, client);
return id;
}
async closeSession(id: string): Promise<void> {
const client = this.sessions.get(id);
if (client) {
await client.disconnect();
this.sessions.delete(id);
}
}
}

TSession

Type of session object

TConfig = unknown

Configuration type for creating sessions

new BaseSessionManager<TSession, TConfig>(): BaseSessionManager<TSession, TConfig>

BaseSessionManager<TSession, TConfig>

closeAll(): Promise<void>

Defined in: session/manager.ts:196

Close all sessions. Closes sessions in reverse order (most recent first).

Promise<void>

ISessionManager.closeAll


abstract closeSession(id): Promise<void>

Defined in: session/manager.ts:158

Close and remove a session. Must be implemented by subclasses.

string

Promise<void>

ISessionManager.closeSession


abstract createSession(config?): Promise<string>

Defined in: session/manager.ts:152

Create a new session. Must be implemented by subclasses.

TConfig

Promise<string>

ISessionManager.createSession


getSession(id): TSession | undefined

Defined in: session/manager.ts:163

Get a session by ID.

string

TSession | undefined

ISessionManager.getSession


hasSession(id): boolean

Defined in: session/manager.ts:188

Check if a session exists.

string

boolean

ISessionManager.hasSession


listSessions(): string[]

Defined in: session/manager.ts:181

List all active session IDs.

string[]

ISessionManager.listSessions


requireSession(id): TSession

Defined in: session/manager.ts:170

Get a session by ID, throwing if not found.

string

TSession

ISessionManager.requireSession