@chrysb/alphaclaw 0.9.0-beta.1 → 0.9.0-beta.3

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.
@@ -28,6 +28,7 @@ const resolveGatewayWsUrl = ({ openclawDir, gatewayPort }) => {
28
28
 
29
29
  const sessions = new Map();
30
30
  let activeTransport = null;
31
+ const kSessionGraceMs = 15_000;
31
32
 
32
33
  const closeSession = (sessionId) => {
33
34
  const t = sessions.get(sessionId);
@@ -42,6 +43,19 @@ const closeAllSessions = () => {
42
43
  activeTransport = null;
43
44
  };
44
45
 
46
+ const retireStaleSessions = (keepId) => {
47
+ const staleIds = [...sessions.keys()].filter((id) => id !== keepId);
48
+ if (staleIds.length === 0) return;
49
+ setTimeout(() => {
50
+ for (const id of staleIds) {
51
+ if (sessions.has(id) && sessions.get(id) !== activeTransport) {
52
+ console.log(`[mcp] Cleaning up stale session: ${id}`);
53
+ closeSession(id);
54
+ }
55
+ }
56
+ }, kSessionGraceMs);
57
+ };
58
+
45
59
  const registerMcpRoutes = ({
46
60
  app,
47
61
  requireAuth,
@@ -124,6 +138,11 @@ const registerMcpRoutes = ({
124
138
  return;
125
139
  }
126
140
 
141
+ if (req.method === "GET") {
142
+ res.setHeader("X-Accel-Buffering", "no");
143
+ res.flushHeaders?.();
144
+ }
145
+
127
146
  const sessionId = req.headers["mcp-session-id"];
128
147
 
129
148
  // ── Existing session ───────────────────────────────────────
@@ -166,9 +185,9 @@ const registerMcpRoutes = ({
166
185
  sessionIdGenerator: () => randomUUID(),
167
186
  enableJsonResponse: true,
168
187
  onsessioninitialized: (newSessionId) => {
169
- closeAllSessions();
170
188
  sessions.set(newSessionId, transport);
171
189
  activeTransport = transport;
190
+ retireStaleSessions(newSessionId);
172
191
  console.log(
173
192
  `[mcp] Session registered: ${newSessionId} (sessions=${sessions.size})`,
174
193
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrysb/alphaclaw",
3
- "version": "0.9.0-beta.1",
3
+ "version": "0.9.0-beta.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },