codebase-snapshot 0.20.5 → 0.20.7
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.
- package/CHANGELOG.md +65 -0
- package/README.md +1 -1
- package/dist/bin.js +1532 -1037
- package/dist/{chunk-C3WVC4FV.js → chunk-RSWAYB6U.js} +1194 -776
- package/dist/{chunk-HYTY6T7P.js → chunk-UIF7U77H.js} +32 -8
- package/dist/cli.cjs +1557 -1059
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +73 -19
- package/dist/{generate-worker-CNRsO_z7.d.cts → generate-worker-CkWFKtf0.d.ts} +6 -0
- package/dist/{generate-worker-CNRsO_z7.d.ts → generate-worker-Wne8FzN5.d.cts} +6 -0
- package/dist/index.cjs +1178 -772
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +470 -180
- package/dist/mcp.d.cts +2 -1
- package/dist/mcp.d.ts +2 -1
- package/dist/mcp.js +2 -2
- package/dist/{types-DnYsA6_Y.d.cts → types-CykWdR6V.d.cts} +2 -0
- package/dist/{types-DnYsA6_Y.d.ts → types-CykWdR6V.d.ts} +2 -0
- package/docs/cli.md +5 -5
- package/docs/deploy.md +2 -2
- package/docs/mcp.md +4 -4
- package/package.json +8 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildTools, createServer, GENERATOR_VERSION } from './chunk-
|
|
1
|
+
import { buildTools, createServer, GENERATOR_VERSION } from './chunk-RSWAYB6U.js';
|
|
2
2
|
import * as http from 'http';
|
|
3
3
|
import * as crypto from 'crypto';
|
|
4
4
|
|
|
@@ -8,6 +8,7 @@ var RATE_LIMIT = 60;
|
|
|
8
8
|
var RATE_WINDOW_MS = 1e4;
|
|
9
9
|
var MAX_IN_FLIGHT = 4;
|
|
10
10
|
var MAX_SESSION_ENTRIES = 64;
|
|
11
|
+
var MAX_SSE_SESSIONS = 64;
|
|
11
12
|
var MAX_RATE_WINDOWS = 1024;
|
|
12
13
|
function generateToken() {
|
|
13
14
|
return crypto.randomBytes(24).toString("base64url");
|
|
@@ -45,10 +46,7 @@ async function startHttpTransport(options) {
|
|
|
45
46
|
const mcpSessions = /* @__PURE__ */ new Map();
|
|
46
47
|
const socketServers = /* @__PURE__ */ new WeakMap();
|
|
47
48
|
const rememberSession = (id, server) => {
|
|
48
|
-
if (!mcpSessions.has(id) && mcpSessions.size >= MAX_SESSION_ENTRIES)
|
|
49
|
-
const oldest = mcpSessions.keys().next().value;
|
|
50
|
-
if (oldest !== void 0) mcpSessions.delete(oldest);
|
|
51
|
-
}
|
|
49
|
+
if (!mcpSessions.has(id) && mcpSessions.size >= MAX_SESSION_ENTRIES) return;
|
|
52
50
|
mcpSessions.set(id, server);
|
|
53
51
|
};
|
|
54
52
|
const anonymousServers = /* @__PURE__ */ new Map();
|
|
@@ -195,6 +193,10 @@ async function startHttpTransport(options) {
|
|
|
195
193
|
return;
|
|
196
194
|
}
|
|
197
195
|
if (request.method === "GET" && request.url === "/metrics") {
|
|
196
|
+
if (token !== null && host !== "127.0.0.1" && host !== "localhost" && host !== "::1" && !tokenAccepted(request, new URL(request.url, "http://localhost"))) {
|
|
197
|
+
send(401, { error: "unauthorized" }, { "www-authenticate": 'Bearer realm="codebase-snapshot"' });
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
198
200
|
const lines = [
|
|
199
201
|
"# HELP snapshot_uptime_seconds Seconds since the process started.",
|
|
200
202
|
"# TYPE snapshot_uptime_seconds gauge",
|
|
@@ -232,6 +234,10 @@ async function startHttpTransport(options) {
|
|
|
232
234
|
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
233
235
|
return;
|
|
234
236
|
}
|
|
237
|
+
if (sseSessions.size >= MAX_SSE_SESSIONS) {
|
|
238
|
+
send(503, { error: "too many open SSE sessions" }, { ...cors, "retry-after": "10" });
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
235
241
|
const id = crypto.randomBytes(12).toString("hex");
|
|
236
242
|
response.writeHead(200, {
|
|
237
243
|
...cors,
|
|
@@ -241,9 +247,21 @@ async function startHttpTransport(options) {
|
|
|
241
247
|
"x-accel-buffering": "no"
|
|
242
248
|
});
|
|
243
249
|
const write = (payload) => {
|
|
244
|
-
|
|
250
|
+
try {
|
|
251
|
+
response.write(payload);
|
|
252
|
+
} catch {
|
|
253
|
+
}
|
|
245
254
|
};
|
|
246
|
-
sseSessions.set(id, {
|
|
255
|
+
sseSessions.set(id, {
|
|
256
|
+
write,
|
|
257
|
+
end: () => {
|
|
258
|
+
try {
|
|
259
|
+
response.end();
|
|
260
|
+
} catch {
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
server: createMcp()
|
|
264
|
+
});
|
|
247
265
|
const heartbeat = setInterval(() => write(": ping\n\n"), 15e3);
|
|
248
266
|
const cleanup = () => {
|
|
249
267
|
clearInterval(heartbeat);
|
|
@@ -308,7 +326,13 @@ async function startHttpTransport(options) {
|
|
|
308
326
|
if (gated) releaseToolSlot();
|
|
309
327
|
}
|
|
310
328
|
send(202, "", cors);
|
|
311
|
-
})()
|
|
329
|
+
})().catch((error) => {
|
|
330
|
+
log("mcp/http: " + error.message);
|
|
331
|
+
try {
|
|
332
|
+
send(500, { jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } }, cors);
|
|
333
|
+
} catch {
|
|
334
|
+
}
|
|
335
|
+
});
|
|
312
336
|
});
|
|
313
337
|
return;
|
|
314
338
|
}
|