tuna-agent 0.1.19 → 0.1.20
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.d.ts +2 -2
- package/dist/mcp/setup.js +41 -72
- package/package.json +1 -1
package/dist/mcp/setup.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentConfig } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Call Mem0 add_memory
|
|
4
|
-
*
|
|
3
|
+
* Call Mem0 add_memory via mem0-add script (bypasses OpenMemory API).
|
|
4
|
+
* Calls `mem0-add <text>` directly or via SSH — simple, reliable.
|
|
5
5
|
*/
|
|
6
6
|
export declare function callMem0AddMemory(text: string, agentName: string): Promise<void>;
|
|
7
7
|
/**
|
package/dist/mcp/setup.js
CHANGED
|
@@ -21,88 +21,57 @@ const MEM0_ENV_VARS = {
|
|
|
21
21
|
MEM0_NEO4J_PASSWORD: 'mem0graph',
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* Call Mem0 add_memory
|
|
25
|
-
*
|
|
24
|
+
* Call Mem0 add_memory via mem0-add script (bypasses OpenMemory API).
|
|
25
|
+
* Calls `mem0-add <text>` directly or via SSH — simple, reliable.
|
|
26
26
|
*/
|
|
27
27
|
export async function callMem0AddMemory(text, agentName) {
|
|
28
28
|
if (!MEM0_SSH_HOST)
|
|
29
29
|
throw new Error('MEM0_SSH_HOST not configured');
|
|
30
|
-
const {
|
|
30
|
+
const { execFile } = await import('child_process');
|
|
31
31
|
const safeAgentName = agentName.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'agent';
|
|
32
|
-
const envWithUser = { ...MEM0_ENV_VARS, MEM0_USER_ID: safeAgentName };
|
|
33
|
-
let cmd;
|
|
34
|
-
let args;
|
|
35
|
-
let spawnEnv;
|
|
36
|
-
if (MEM0_SSH_HOST === 'local') {
|
|
37
|
-
cmd = 'mem0-mcp';
|
|
38
|
-
args = [];
|
|
39
|
-
spawnEnv = { ...process.env, ...envWithUser };
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const envString = Object.entries(envWithUser).map(([k, v]) => `${k}=${v}`).join(' ');
|
|
43
|
-
cmd = 'ssh';
|
|
44
|
-
args = ['-p', MEM0_SSH_PORT, '-o', 'StrictHostKeyChecking=no'];
|
|
45
|
-
if (MEM0_SSH_KEY)
|
|
46
|
-
args.push('-i', MEM0_SSH_KEY);
|
|
47
|
-
args.push(MEM0_SSH_HOST, `${envString} mem0-mcp`);
|
|
48
|
-
}
|
|
49
32
|
return new Promise((resolve, reject) => {
|
|
50
|
-
const
|
|
51
|
-
let
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
33
|
+
const timer = setTimeout(() => reject(new Error('Mem0 call timed out')), 30000);
|
|
34
|
+
let cmd;
|
|
35
|
+
let args;
|
|
36
|
+
let options = {};
|
|
37
|
+
if (MEM0_SSH_HOST === 'local') {
|
|
38
|
+
cmd = 'mem0-add';
|
|
39
|
+
args = [text];
|
|
40
|
+
options.env = { ...process.env, MEM0_USER_ID: safeAgentName };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
cmd = 'ssh';
|
|
44
|
+
args = ['-p', MEM0_SSH_PORT, '-o', 'StrictHostKeyChecking=no'];
|
|
45
|
+
if (MEM0_SSH_KEY)
|
|
46
|
+
args.push('-i', MEM0_SSH_KEY);
|
|
47
|
+
// Shell-escape text with single quotes (escape internal single quotes)
|
|
48
|
+
const escapedText = text.replace(/'/g, "'\\''");
|
|
49
|
+
args.push(MEM0_SSH_HOST, `MEM0_USER_ID=${safeAgentName} mem0-add '${escapedText}'`);
|
|
50
|
+
}
|
|
51
|
+
execFile(cmd, args, { ...options, timeout: 30000 }, (err, stdout, stderr) => {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
if (err) {
|
|
54
|
+
reject(new Error(`Mem0 add failed: ${err.message}${stderr ? ` stderr: ${stderr.substring(0, 200)}` : ''}`));
|
|
55
|
+
return;
|
|
70
56
|
}
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const errMatch = stdout.match(/"text"\s*:\s*"([^"]+)"/);
|
|
83
|
-
reject(new Error(`Mem0 add_memory failed: ${errMatch?.[1] || 'unknown error'}`));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
resolve();
|
|
87
|
-
}
|
|
57
|
+
// Check response for actual results
|
|
58
|
+
try {
|
|
59
|
+
const data = JSON.parse(stdout.trim());
|
|
60
|
+
if (data.error) {
|
|
61
|
+
reject(new Error(`Mem0 add failed: ${data.error}`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const results = data.results || [];
|
|
65
|
+
const added = results.filter((r) => r.event === 'ADD' || r.event === 'UPDATE');
|
|
66
|
+
if (added.length === 0 && results.length > 0) {
|
|
67
|
+
console.log(`[Mem0] Memory deduplicated (${results.length} existing matches)`);
|
|
88
68
|
}
|
|
89
69
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
proc.on('close', (code) => {
|
|
94
|
-
if (!resolved) {
|
|
95
|
-
resolved = true;
|
|
96
|
-
clearTimeout(timer);
|
|
97
|
-
reject(new Error(`Mem0 process exited (code ${code}) without completing add_memory. stdout: ${stdout.substring(0, 300)}`));
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
proc.on('error', (err) => {
|
|
101
|
-
if (!resolved) {
|
|
102
|
-
resolved = true;
|
|
103
|
-
clearTimeout(timer);
|
|
104
|
-
reject(err);
|
|
70
|
+
catch {
|
|
71
|
+
// Non-JSON output — might be OK if exit code was 0
|
|
72
|
+
console.warn(`[Mem0] Unexpected output: ${stdout.substring(0, 100)}`);
|
|
105
73
|
}
|
|
74
|
+
resolve();
|
|
106
75
|
});
|
|
107
76
|
});
|
|
108
77
|
}
|