@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
60 lines • 1.89 kB
TypeScript
/**
* In-memory session provider for development.
*
* WARNING: Sessions are lost on server restart. Not for production use.
*/
import type { Session, ISessionProvider } from '../../interfaces/index.js';
/**
* Options for MemorySessionProvider.
*/
export interface MemorySessionProviderOptions {
/** Session TTL in milliseconds (default: 7 days) */
ttl?: number;
/** Cookie name (default: 'mastra_session') */
cookieName?: string;
/** Cookie path (default: '/') */
cookiePath?: string;
/** Cleanup interval in milliseconds (default: 60000) */
cleanupInterval?: number;
}
/**
* In-memory session provider.
*
* Stores sessions in a Map. Useful for development but not suitable
* for production as sessions are lost on restart.
*
* @example
* ```typescript
* const sessionProvider = new MemorySessionProvider({
* ttl: 24 * 60 * 60 * 1000, // 24 hours
* });
* ```
*/
export declare class MemorySessionProvider implements ISessionProvider {
private sessions;
private ttl;
private cookieName;
private cookiePath;
private cleanupTimer;
constructor(options?: MemorySessionProviderOptions);
createSession(userId: string, metadata?: Record<string, unknown>): Promise<Session>;
validateSession(sessionId: string): Promise<Session | null>;
destroySession(sessionId: string): Promise<void>;
refreshSession(sessionId: string): Promise<Session | null>;
getSessionIdFromRequest(request: Request): string | null;
getSessionHeaders(session: Session): Record<string, string>;
getClearSessionHeaders(): Record<string, string>;
/**
* Clean up expired sessions.
*/
private cleanup;
/**
* Stop the cleanup timer.
*/
dispose(): void;
/**
* Get the number of active sessions (for debugging).
*/
getSessionCount(): number;
}
//# sourceMappingURL=memory.d.ts.map