clay-server 3.5.0-beta.1 → 3.5.0-beta.2

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.
@@ -106,13 +106,7 @@ function attachConnection(ctx) {
106
106
  var presenceKey = wsUser ? wsUser.id : "_default";
107
107
  var storedPresence = userPresence.getPresence(slug, presenceKey);
108
108
  if (storedPresence && storedPresence.sessionId) {
109
- if (sm.sessions.has(storedPresence.sessionId)) {
110
- active = sm.sessions.get(storedPresence.sessionId);
111
- } else {
112
- sm.sessions.forEach(function (s) {
113
- if (s.cliSessionId && s.cliSessionId === storedPresence.sessionId) active = s;
114
- });
115
- }
109
+ active = userPresence.findSession(sm.sessions, storedPresence.sessionId);
116
110
  if (active && usersModule.isMultiUser() && wsUser) {
117
111
  if (!usersModule.canAccessSession(wsUser.id, active, { visibility: "public" })) active = null;
118
112
  } else if (active && !usersModule.isMultiUser() && active.ownerId) {
@@ -311,7 +305,7 @@ function attachConnection(ctx) {
311
305
  }
312
306
 
313
307
  if (active && !ws._clayPane) {
314
- userPresence.setPresence(slug, presenceKey, active.localId, storedPresence ? storedPresence.mateDm : null);
308
+ userPresence.setPresence(slug, presenceKey, userPresence.sessionIdForPersistence(active), storedPresence ? storedPresence.mateDm : null);
315
309
  if (autoCreated) {
316
310
  sendTo(ws, { type: "context_sources_state", active: [] });
317
311
  }
@@ -338,7 +332,8 @@ function attachConnection(ctx) {
338
332
  if (ws._clayActiveSession && !ws._clayPane) {
339
333
  var dcPresKey = ws._clayUser ? ws._clayUser.id : "_default";
340
334
  var dcExisting = userPresence.getPresence(slug, dcPresKey);
341
- userPresence.setPresence(slug, dcPresKey, ws._clayActiveSession, dcExisting ? dcExisting.mateDm : null);
335
+ var dcSession = sm.sessions.get(ws._clayActiveSession);
336
+ userPresence.setPresence(slug, dcPresKey, userPresence.sessionIdForPersistence(dcSession), dcExisting ? dcExisting.mateDm : null);
342
337
  }
343
338
  tm.detachAll(ws);
344
339
  clients.delete(ws);
@@ -542,7 +542,7 @@ function attachSessions(ctx) {
542
542
  send({ type: "last_vendor", vendor: msg.vendor });
543
543
  }
544
544
  var nsPresKey = ws._clayUser ? ws._clayUser.id : "_default";
545
- if (!ws._clayPane) userPresence.setPresence(slug, nsPresKey, newSess.localId, null);
545
+ if (!ws._clayPane) userPresence.setPresence(slug, nsPresKey, userPresence.sessionIdForPersistence(newSess), null);
546
546
  if (usersModule.isMultiUser() && !ws._clayPane) {
547
547
  broadcastPresence();
548
548
  }
@@ -684,7 +684,7 @@ function attachSessions(ctx) {
684
684
  sendTo(ws, { type: "context_sources_state", active: switchedSources });
685
685
  }
686
686
  var swPresKey = ws._clayUser ? ws._clayUser.id : "_default";
687
- if (!ws._clayPane) userPresence.setPresence(slug, swPresKey, msg.id, null);
687
+ if (!ws._clayPane) userPresence.setPresence(slug, swPresKey, userPresence.sessionIdForPersistence(switchTargetSess), null);
688
688
  }
689
689
  return true;
690
690
  }
@@ -7,6 +7,21 @@ var store = {};
7
7
  var presencePath = path.join(config.CONFIG_DIR, "user-presence.json");
8
8
  var saveTimer = null;
9
9
 
10
+ function sessionIdForPersistence(session) {
11
+ if (!session) return null;
12
+ return session.cliSessionId || session.localId || null;
13
+ }
14
+
15
+ function findSession(sessions, sessionId) {
16
+ if (!sessions || sessionId == null) return null;
17
+ var found = null;
18
+ sessions.forEach(function (session) {
19
+ if (session.cliSessionId && session.cliSessionId === sessionId) found = session;
20
+ });
21
+ if (found) return found;
22
+ return typeof sessionId === "number" ? (sessions.get(sessionId) || null) : null;
23
+ }
24
+
10
25
  // Load from disk on startup
11
26
  function load() {
12
27
  try {
@@ -84,6 +99,8 @@ function clearSession(slug, sessionId) {
84
99
  load();
85
100
 
86
101
  module.exports = {
102
+ sessionIdForPersistence: sessionIdForPersistence,
103
+ findSession: findSession,
87
104
  setPresence: setPresence,
88
105
  getPresence: getPresence,
89
106
  setMateDm: setMateDm,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clay-server",
3
- "version": "3.5.0-beta.1",
3
+ "version": "3.5.0-beta.2",
4
4
  "description": "Self-hosted team workspace for Claude Code and Codex. Multi-user, browser-based, with persistent AI mates.",
5
5
  "bin": {
6
6
  "clay-server": "./bin/cli.js",