@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.
- package/lib/mcp-server.cjs +18 -5
- package/lib/plugins/im.cjs +11 -6
- package/package.json +1 -1
package/lib/mcp-server.cjs
CHANGED
|
@@ -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.
|
|
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) => {
|
|
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
|
-
|
|
23
|
-
|
|
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:
|
|
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();
|
package/lib/plugins/im.cjs
CHANGED
|
@@ -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) => {
|
|
145
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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, () => {
|