/**
* Request Manager
*
* Manages pending requests and their lifecycle in the AskMeMCP server.
* Provides a simple in-memory storage for request/response coordination.
*/
/**
* Interface for pending request storage
*/
export interface PendingRequest {
requestId: string;
resolve: (response: any) => void;
reject: (error: any) => void;
}
/**
* Request Manager class to handle request storage and lifecycle
*/
export class RequestManager {
private pendingRequests = new Map<string, PendingRequest>();
/**
* Store a new pending request
*/
public addPendingRequest(requestId: string, resolve: (response: any) => void, reject: (error: any) => void): void {
this.pendingRequests.set(requestId, { requestId, resolve, reject });
}
/**
* Get a pending request by ID
*/
public getPendingRequest(requestId: string): PendingRequest | undefined {
return this.pendingRequests.get(requestId);
}
/**
* Remove a pending request
*/
public removePendingRequest(requestId: string): boolean {
return this.pendingRequests.delete(requestId);
}
/**
* Check if a request exists
*/
public hasPendingRequest(requestId: string): boolean {
return this.pendingRequests.has(requestId);
}
/**
* Get all pending request IDs
*/
public getPendingRequestIds(): string[] {
return Array.from(this.pendingRequests.keys());
}
/**
* Get the number of pending requests
*/
public getPendingRequestCount(): number {
return this.pendingRequests.size;
}
/**
* Clear all pending requests (useful for cleanup)
*/
public clearAllPendingRequests(): void {
this.pendingRequests.clear();
}
/**
* Get the internal storage map (for compatibility with existing code)
*/
public getStorage(): Map<string, PendingRequest> {
return this.pendingRequests;
}
}