@seamnet/client 0.3.4 → 0.3.5

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.
@@ -14,16 +14,29 @@ const SOCKET_PATH = path.join(SEAM_DIR, 'guardian.sock');
14
14
  function guardianRequest(payload) {
15
15
  return new Promise((resolve, reject) => {
16
16
  const conn = net.createConnection(SOCKET_PATH, () => {
17
- conn.end(JSON.stringify(payload));
17
+ conn.write(JSON.stringify(payload)); // write, not end — keep connection open for response
18
18
  });
19
19
  let data = '';
20
- conn.on('data', (chunk) => { data += chunk; });
20
+ conn.on('data', (chunk) => {
21
+ data += chunk;
22
+ // Try to parse response
23
+ try {
24
+ const res = JSON.parse(data);
25
+ conn.destroy();
26
+ resolve(res);
27
+ } catch {
28
+ // Not complete yet
29
+ }
30
+ });
21
31
  conn.on('end', () => {
22
- try { resolve(JSON.parse(data)); }
23
- catch { resolve({ error: data || 'Empty response' }); }
32
+ if (data) {
33
+ try { resolve(JSON.parse(data)); } catch { resolve({ error: data }); }
34
+ } else {
35
+ resolve({ error: 'Empty response from guardian' });
36
+ }
24
37
  });
25
38
  conn.on('error', (e) => {
26
- reject(new Error(`Guardian not running. Start it first: npx @seamnet/client guardian start`));
39
+ reject(new Error(`Guardian not running. Start it first: node node_modules/@seamnet/client/bin/cli.js guardian start`));
27
40
  });
28
41
  conn.setTimeout(10000, () => {
29
42
  conn.destroy();
@@ -141,16 +141,21 @@ function createImPlugin({ credentials, socketPath, seamDir }) {
141
141
 
142
142
  const server = net.createServer((conn) => {
143
143
  let data = '';
144
- conn.on('data', (chunk) => { data += chunk; });
145
- conn.on('end', async () => {
144
+ conn.on('data', (chunk) => {
145
+ data += chunk;
146
+ // Try to parse as complete JSON
146
147
  try {
147
148
  const req = JSON.parse(data);
148
- const res = await handleRequest(req);
149
- conn.end(JSON.stringify(res));
150
- } catch (e) {
151
- try { conn.end(JSON.stringify({ error: e.message })); } catch {}
149
+ handleRequest(req).then(res => {
150
+ conn.end(JSON.stringify(res));
151
+ }).catch(e => {
152
+ conn.end(JSON.stringify({ error: e.message }));
153
+ });
154
+ } catch {
155
+ // Not complete JSON yet, wait for more data
152
156
  }
153
157
  });
158
+ conn.on('error', () => {}); // Ignore connection errors
154
159
  });
155
160
 
156
161
  server.listen(socketPath, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamnet/client",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "One command to join Seam — the network where people and AI stay in sync.",
5
5
  "bin": {
6
6
  "seam-client": "bin/cli.js"