sam-coder-cli 1.0.30 → 1.0.32

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.
@@ -775,7 +775,7 @@ class MultiplayerClient extends EventEmitter {
775
775
  });
776
776
  }
777
777
 
778
- async joinSession(sessionId) {
778
+ async joinSession(sessionId, createIfNotExists = true) {
779
779
  if (!sessionId) {
780
780
  throw new Error('Session ID is required');
781
781
  }
@@ -791,9 +791,10 @@ class MultiplayerClient extends EventEmitter {
791
791
 
792
792
  const timeout = setTimeout(() => {
793
793
  this.off('session_joined', onSessionJoined);
794
+ this.off('session_created', onSessionCreated);
794
795
  this.off('error', onError);
795
796
  reject(new Error('Session join timed out'));
796
- }, 10000); // 10 second timeout
797
+ }, 15000); // Increased timeout to 15 seconds
797
798
 
798
799
  const onSessionJoined = (data) => {
799
800
  if (data.sessionId === sessionId) {
@@ -802,21 +803,54 @@ class MultiplayerClient extends EventEmitter {
802
803
  this.isHost = data.isHost || false;
803
804
  this.emit('session_joined', data);
804
805
  this.off('session_joined', onSessionJoined);
806
+ this.off('session_created', onSessionCreated);
805
807
  this.off('error', onError);
808
+ console.log(`✅ Successfully joined session ${sessionId}`);
806
809
  resolve(data);
807
810
  }
808
811
  };
809
812
 
813
+ const onSessionCreated = (data) => {
814
+ if (data.sessionId === sessionId) {
815
+ clearTimeout(timeout);
816
+ this.sessionId = sessionId;
817
+ this.isHost = true;
818
+ this.emit('session_joined', { ...data, isHost: true });
819
+ this.off('session_joined', onSessionJoined);
820
+ this.off('session_created', onSessionCreated);
821
+ this.off('error', onError);
822
+ console.log(`✅ Created and joined new session ${sessionId}`);
823
+ resolve({ ...data, isHost: true });
824
+ }
825
+ };
826
+
810
827
  const onError = (error) => {
828
+ if (error.message === 'Session not found' && createIfNotExists) {
829
+ // If session doesn't exist and we're allowed to create it
830
+ this.off('session_joined', onSessionJoined);
831
+ this.off('error', onError);
832
+ console.log(`Session ${sessionId} not found, creating new session...`);
833
+ this.createSession(sessionId)
834
+ .then(() => {
835
+ this.once('session_created', onSessionCreated);
836
+ this.once('error', onError);
837
+ })
838
+ .catch(reject);
839
+ return;
840
+ }
841
+
811
842
  clearTimeout(timeout);
812
843
  this.off('session_joined', onSessionJoined);
844
+ this.off('session_created', onSessionCreated);
813
845
  this.off('error', onError);
846
+ console.error('Error joining session:', error.message);
814
847
  reject(error);
815
848
  };
816
849
 
817
850
  this.on('session_joined', onSessionJoined);
818
851
  this.on('error', onError);
819
852
 
853
+ console.log(`Attempting to join session ${sessionId}...`);
820
854
  this.send({
821
855
  type: 'join_session',
822
856
  sessionId: sessionId,
@@ -302,6 +302,33 @@ class MultiplayerServer {
302
302
  joinedAt: new Date().toISOString(),
303
303
  lastSeen: new Date().toISOString()
304
304
  };
305
+
306
+ // Add client to session
307
+ session.clients[clientId] = clientInfo;
308
+ this.clients.set(ws, clientInfo);
309
+
310
+ // Send session joined confirmation
311
+ ws.send(JSON.stringify({
312
+ type: 'session_joined',
313
+ sessionId,
314
+ clientId,
315
+ clientInfo,
316
+ isHost: clientInfo.isHost,
317
+ sessionInfo: {
318
+ id: session.id,
319
+ createdAt: session.createdAt,
320
+ clientCount: Object.keys(session.clients).length,
321
+ hostId: session.hostId
322
+ }
323
+ }));
324
+
325
+ // Notify other clients in the session
326
+ this.broadcastToSession(sessionId, {
327
+ type: 'agent_joined',
328
+ clientId,
329
+ clientInfo,
330
+ timestamp: new Date().toISOString()
331
+ }, clientId);
305
332
  }
306
333
 
307
334
  broadcastToSession(sessionId, message, excludeClientId = null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sam-coder-cli",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "SAM-CODER: An animated command-line AI assistant with agency capabilities.",
5
5
  "main": "bin/agi-cli.js",
6
6
  "bin": {