tuna-agent 0.1.13 → 0.1.14
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/dist/mcp/setup.js +39 -19
- package/package.json +1 -1
package/dist/mcp/setup.js
CHANGED
|
@@ -49,32 +49,52 @@ export async function callMem0AddMemory(text, agentName) {
|
|
|
49
49
|
return new Promise((resolve, reject) => {
|
|
50
50
|
const proc = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'], env: spawnEnv });
|
|
51
51
|
let stdout = '';
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
let resolved = false;
|
|
53
|
+
const timer = setTimeout(() => { if (!resolved) {
|
|
54
|
+
resolved = true;
|
|
55
|
+
proc.kill();
|
|
56
|
+
reject(new Error('Mem0 call timed out'));
|
|
57
|
+
} }, 15000);
|
|
54
58
|
proc.stderr.on('data', () => { }); // ignore stderr
|
|
55
|
-
// Send MCP init + add_memory
|
|
56
59
|
const initMsg = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'tuna-agent', version: '1.0' } } });
|
|
57
60
|
const notifyMsg = JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' });
|
|
58
61
|
const addMsg = JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'add_memory', arguments: { text } } });
|
|
59
|
-
|
|
60
|
-
proc.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
proc.stdin.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
let sentAdd = false;
|
|
63
|
+
proc.stdout.on('data', (d) => {
|
|
64
|
+
stdout += d.toString();
|
|
65
|
+
// After init response, send the add_memory call
|
|
66
|
+
if (!sentAdd && stdout.includes('"id":1')) {
|
|
67
|
+
sentAdd = true;
|
|
68
|
+
proc.stdin.write(notifyMsg + '\n');
|
|
69
|
+
proc.stdin.write(addMsg + '\n');
|
|
70
|
+
}
|
|
71
|
+
// After add_memory response, we're done
|
|
72
|
+
if (sentAdd && stdout.includes('"id":2')) {
|
|
73
|
+
if (!resolved) {
|
|
74
|
+
resolved = true;
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
proc.stdin.end();
|
|
77
|
+
proc.kill();
|
|
72
78
|
resolve();
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
proc.
|
|
81
|
+
});
|
|
82
|
+
// Send init immediately
|
|
83
|
+
proc.stdin.write(initMsg + '\n');
|
|
84
|
+
proc.on('close', () => {
|
|
85
|
+
if (!resolved) {
|
|
86
|
+
resolved = true;
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
resolve();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
proc.on('error', (err) => {
|
|
92
|
+
if (!resolved) {
|
|
93
|
+
resolved = true;
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
reject(err);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
78
98
|
});
|
|
79
99
|
}
|
|
80
100
|
/**
|