scorchcrawl-mcp 1.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ import { CopilotClient } from '@github/copilot-sdk';
2
+ const clientCache = new Map();
3
+ const MAX_CLIENT_AGE_MS = 30 * 60 * 1000;
4
+ setInterval(() => {
5
+ const now = Date.now();
6
+ for (const [key, entry] of clientCache) {
7
+ if (now - entry.lastUsed > MAX_CLIENT_AGE_MS) {
8
+ try {
9
+ entry.client.stop();
10
+ }
11
+ catch {
12
+ // Ignore shutdown failures for stale cached clients.
13
+ }
14
+ clientCache.delete(key);
15
+ }
16
+ }
17
+ }, 5 * 60 * 1000);
18
+ export async function getCopilotClient(userToken) {
19
+ const cacheKey = userToken || '';
20
+ const existing = clientCache.get(cacheKey);
21
+ if (existing) {
22
+ existing.lastUsed = Date.now();
23
+ return existing.client;
24
+ }
25
+ const clientOpts = {};
26
+ if (process.env.COPILOT_CLI_PATH) {
27
+ clientOpts.cliPath = process.env.COPILOT_CLI_PATH;
28
+ }
29
+ if (process.env.COPILOT_CLI_URL) {
30
+ clientOpts.cliUrl = process.env.COPILOT_CLI_URL;
31
+ }
32
+ const token = userToken || process.env.GITHUB_TOKEN;
33
+ if (token) {
34
+ clientOpts.githubToken = token;
35
+ }
36
+ const client = new CopilotClient(clientOpts);
37
+ clientCache.set(cacheKey, { client, lastUsed: Date.now() });
38
+ return client;
39
+ }