sam-coder-cli 1.0.24 → 1.0.25

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.
@@ -704,38 +704,91 @@ class MultiplayerClient extends EventEmitter {
704
704
  return client ? (client.name || client.clientInfo?.name || 'Unknown') : 'Unknown';
705
705
  }
706
706
 
707
- createSession() {
708
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
709
- throw new Error('Not connected to server');
710
- }
711
- this.sessionId = uuidv4();
712
- this.isHost = true;
713
- this.send({
714
- type: 'create_session',
715
- sessionId: this.sessionId,
716
- clientInfo: {
717
- name: this.name,
718
- role: this.role,
719
- model: this.model
707
+ async createSession() {
708
+ if (!this.connected) {
709
+ try {
710
+ await this.connect();
711
+ } catch (error) {
712
+ throw new Error(`Failed to connect to server: ${error.message}`);
720
713
  }
714
+ }
715
+
716
+ return new Promise((resolve, reject) => {
717
+ this.sessionId = uuidv4();
718
+ this.isHost = true;
719
+
720
+ const onSessionCreated = (data) => {
721
+ if (data.sessionId === this.sessionId) {
722
+ this.off('session_created', onSessionCreated);
723
+ this.off('error', onError);
724
+ resolve(this.sessionId);
725
+ }
726
+ };
727
+
728
+ const onError = (error) => {
729
+ this.off('session_created', onSessionCreated);
730
+ this.off('error', onError);
731
+ reject(error);
732
+ };
733
+
734
+ this.once('session_created', onSessionCreated);
735
+ this.once('error', onError);
736
+
737
+ this.send({
738
+ type: 'create_session',
739
+ sessionId: this.sessionId,
740
+ clientInfo: {
741
+ name: this.name,
742
+ role: this.role,
743
+ model: this.model
744
+ }
745
+ });
721
746
  });
722
- return this.sessionId;
723
747
  }
724
748
 
725
- joinSession(sessionId) {
726
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
727
- throw new Error('Not connected to server');
749
+ async joinSession(sessionId) {
750
+ if (!sessionId) {
751
+ throw new Error('Session ID is required');
728
752
  }
729
- this.sessionId = sessionId;
730
- this.isHost = false;
731
- this.send({
732
- type: 'join_session',
733
- sessionId: this.sessionId,
734
- clientInfo: {
735
- name: this.name,
736
- role: this.role,
737
- model: this.model
753
+
754
+ if (!this.connected) {
755
+ try {
756
+ await this.connect();
757
+ } catch (error) {
758
+ throw new Error(`Failed to connect to server: ${error.message}`);
738
759
  }
760
+ }
761
+
762
+ return new Promise((resolve, reject) => {
763
+ this.sessionId = sessionId;
764
+ this.isHost = false;
765
+
766
+ const onSessionJoined = (data) => {
767
+ if (data.sessionId === this.sessionId) {
768
+ this.off('session_joined', onSessionJoined);
769
+ this.off('error', onError);
770
+ resolve();
771
+ }
772
+ };
773
+
774
+ const onError = (error) => {
775
+ this.off('session_joined', onSessionJoined);
776
+ this.off('error', onError);
777
+ reject(error);
778
+ };
779
+
780
+ this.once('session_joined', onSessionJoined);
781
+ this.once('error', onError);
782
+
783
+ this.send({
784
+ type: 'join_session',
785
+ sessionId: this.sessionId,
786
+ clientInfo: {
787
+ name: this.name,
788
+ role: this.role,
789
+ model: this.model
790
+ }
791
+ });
739
792
  });
740
793
  }
741
794
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sam-coder-cli",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "SAM-CODER: An animated command-line AI assistant with agency capabilities.",
5
5
  "main": "bin/agi-cli.js",
6
6
  "bin": {