tuna-agent 0.1.45 → 0.1.46
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 +23 -9
- package/package.json +1 -1
package/dist/mcp/setup.js
CHANGED
|
@@ -28,10 +28,27 @@ const MEM0_ENV_VARS = {
|
|
|
28
28
|
* Returns 0 if MEM0_HTTP_BASE is not set or request fails.
|
|
29
29
|
*/
|
|
30
30
|
export async function fetchMem0Count(agentName) {
|
|
31
|
+
const safeName = agentName.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'agent';
|
|
32
|
+
// If SSH is configured, query via SSH+curl (port 8765 may not be exposed externally)
|
|
33
|
+
if (MEM0_SSH_HOST && MEM0_SSH_HOST !== 'local') {
|
|
34
|
+
try {
|
|
35
|
+
const { execFile } = await import('child_process');
|
|
36
|
+
const remoteCmd = `curl -s 'http://127.0.0.1:8765/api/v1/memories/?user_id=${safeName}&page=1&page_size=1'`;
|
|
37
|
+
const args = ['-p', MEM0_SSH_PORT, '-o', 'StrictHostKeyChecking=no', MEM0_SSH_HOST, remoteCmd];
|
|
38
|
+
const stdout = await new Promise((res, rej) => {
|
|
39
|
+
execFile('ssh', args, { timeout: 8000 }, (err, out) => err ? rej(err) : res(out));
|
|
40
|
+
});
|
|
41
|
+
const data = JSON.parse(stdout.trim());
|
|
42
|
+
return data.total || 0;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Direct HTTP (local mode or no SSH)
|
|
31
49
|
if (!MEM0_HTTP_BASE)
|
|
32
50
|
return 0;
|
|
33
51
|
try {
|
|
34
|
-
const safeName = agentName.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'agent';
|
|
35
52
|
const url = `${MEM0_HTTP_BASE}/api/v1/memories/?user_id=${encodeURIComponent(safeName)}&page=1&page_size=1`;
|
|
36
53
|
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
|
|
37
54
|
if (!res.ok)
|
|
@@ -52,8 +69,9 @@ export async function callMem0AddMemory(text, agentName) {
|
|
|
52
69
|
if (!MEM0_SSH_HOST && !MEM0_HTTP_BASE)
|
|
53
70
|
throw new Error('Mem0 not configured');
|
|
54
71
|
const safeAgentName = agentName.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'agent';
|
|
55
|
-
//
|
|
56
|
-
if (
|
|
72
|
+
// Try HTTP API first (OpenMemory) — stores in SQLite+Qdrant, shows up in counts
|
|
73
|
+
// Falls through to SSH+curl if HTTP is not reachable (e.g. port not exposed externally)
|
|
74
|
+
if (MEM0_HTTP_BASE && !MEM0_SSH_HOST) {
|
|
57
75
|
const url = `${MEM0_HTTP_BASE}/api/v1/memories/`;
|
|
58
76
|
const body = JSON.stringify({ user_id: safeAgentName, text, app: 'tuna-agent' });
|
|
59
77
|
const res = await fetch(url, {
|
|
@@ -69,14 +87,10 @@ export async function callMem0AddMemory(text, agentName) {
|
|
|
69
87
|
const data = await res.json();
|
|
70
88
|
if (data.error)
|
|
71
89
|
throw new Error(`Mem0 add failed: ${data.error}`);
|
|
72
|
-
const results = data.results || [];
|
|
73
|
-
const added = results.filter((r) => r.event === 'ADD' || r.event === 'UPDATE');
|
|
74
|
-
if (added.length === 0 && results.length > 0) {
|
|
75
|
-
console.log(`[Mem0] Memory deduplicated (${results.length} existing matches)`);
|
|
76
|
-
}
|
|
77
90
|
return;
|
|
78
91
|
}
|
|
79
|
-
//
|
|
92
|
+
// SSH + curl to OpenMemory API on remote host (127.0.0.1:8765)
|
|
93
|
+
// This is the primary path when MEM0_SSH_HOST is set (port 8765 not exposed externally)
|
|
80
94
|
if (!MEM0_SSH_HOST)
|
|
81
95
|
throw new Error('MEM0_SSH_HOST not configured');
|
|
82
96
|
const { execFile } = await import('child_process');
|