UNPKG

scrapeless-mcp-server

Version:
41 lines (40 loc) 1.22 kB
import { Context } from "./context.js"; import { API_KEY } from "./config.js"; export class ContextManager { static instance; contexts; constructor() { this.contexts = new Map(); } static getInstance() { if (!ContextManager.instance) { ContextManager.instance = new ContextManager(); } return ContextManager.instance; } getContext(apiKey) { const key = apiKey ?? API_KEY; if (!this.contexts.has(key)) { console.log(`Creating new Context for API key: ${key?.substring(0, 8)}...`); this.contexts.set(key, new Context(key)); } else { console.log(`Reusing existing Context for API key: ${key?.substring(0, 8)}...`); } return this.contexts.get(key); } clearContext(apiKey) { const key = apiKey ?? API_KEY; if (this.contexts.has(key)) { this.contexts.delete(key); console.log(`Cleared Context for API key: ${key?.substring(0, 8)}...`); } } clearAllContexts() { this.contexts.clear(); console.log("Cleared all Contexts"); } getContextCount() { return this.contexts.size; } }