@miniaxolotl/grove 0.2.4 → 0.2.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/CHANGELOG.md +1 -1
- package/README.md +6 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -1
- package/dist/index.js +253 -289
- package/dist/index.js.map +1 -1
- package/dist/repositories/entity.repository.d.ts.map +1 -1
- package/dist/repositories/entity.repository.js +24 -41
- package/dist/repositories/entity.repository.js.map +1 -1
- package/dist/repositories/memory.repository.d.ts +16 -21
- package/dist/repositories/memory.repository.d.ts.map +1 -1
- package/dist/repositories/memory.repository.js +71 -132
- package/dist/repositories/memory.repository.js.map +1 -1
- package/dist/repositories/relation.repository.d.ts.map +1 -1
- package/dist/repositories/relation.repository.js +25 -43
- package/dist/repositories/relation.repository.js.map +1 -1
- package/dist/services/embedding.d.ts +1 -0
- package/dist/services/embedding.d.ts.map +1 -1
- package/dist/services/embedding.js +8 -1
- package/dist/services/embedding.js.map +1 -1
- package/dist/services/qdrant.d.ts +5 -2
- package/dist/services/qdrant.d.ts.map +1 -1
- package/dist/services/qdrant.js +27 -10
- package/dist/services/qdrant.js.map +1 -1
- package/dist/utils/filter.d.ts +10 -0
- package/dist/utils/filter.d.ts.map +1 -0
- package/dist/utils/filter.js +15 -0
- package/dist/utils/filter.js.map +1 -0
- package/eslint.config.js +1 -1
- package/package.json +12 -12
- package/src/config.ts +5 -0
- package/src/index.ts +263 -336
- package/src/repositories/entity.repository.ts +30 -42
- package/src/repositories/memory.repository.ts +105 -166
- package/src/repositories/relation.repository.ts +33 -41
- package/src/services/embedding.ts +9 -1
- package/src/services/qdrant.ts +30 -13
- package/src/utils/filter.ts +20 -0
- package/tsconfig.json +1 -1
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { entityRepository } from "./repositories/entity.repository.ts";
|
|
|
6
6
|
import { relationRepository } from "./repositories/relation.repository.ts";
|
|
7
7
|
import { config, hasRemoteReranking } from "./config.ts";
|
|
8
8
|
import { rerankDocuments } from "./services/reranking.ts";
|
|
9
|
+
import { warmup } from "./services/embedding.ts";
|
|
9
10
|
|
|
10
11
|
let collectionsReady = false;
|
|
11
12
|
|
|
@@ -14,6 +15,15 @@ const server = new FastMCP({
|
|
|
14
15
|
version: "0.1.0",
|
|
15
16
|
});
|
|
16
17
|
|
|
18
|
+
function text(content: string) {
|
|
19
|
+
return { content: [{ type: "text" as const, text: content }] };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toolErr(err: unknown) {
|
|
23
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
24
|
+
return text(`Error: ${message}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
// ── Memory Tools ──────────────────────────────────────────────────────────────
|
|
18
28
|
|
|
19
29
|
server.addTool({
|
|
@@ -30,11 +40,15 @@ server.addTool({
|
|
|
30
40
|
.optional(),
|
|
31
41
|
}),
|
|
32
42
|
execute: async (args) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
try {
|
|
44
|
+
const result = await memoryRepository.save(args.information, {
|
|
45
|
+
...args.metadata,
|
|
46
|
+
createdAt: new Date().toISOString(),
|
|
47
|
+
});
|
|
48
|
+
return text(`Saved memory: ${result.id}`);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
return toolErr(err);
|
|
51
|
+
}
|
|
38
52
|
},
|
|
39
53
|
});
|
|
40
54
|
|
|
@@ -46,41 +60,34 @@ server.addTool({
|
|
|
46
60
|
project: z.string().optional(),
|
|
47
61
|
tags: z.array(z.string()).optional(),
|
|
48
62
|
limit: z.number().optional().default(5),
|
|
49
|
-
rerank: z.boolean().optional().default(
|
|
63
|
+
rerank: z.boolean().optional().default(hasRemoteReranking),
|
|
50
64
|
rerankTopK: z.number().optional().default(20),
|
|
51
65
|
}),
|
|
52
66
|
execute: async (args) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const results = await memoryRepository.search(args.query, {
|
|
57
|
-
project: args.project,
|
|
58
|
-
tags: args.tags,
|
|
59
|
-
limit: args.rerank && hasRemoteReranking ? rerankTopK : limit,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (args.rerank && hasRemoteReranking && results.length > limit) {
|
|
63
|
-
const docs = results.map((r) => r.text);
|
|
64
|
-
const reranked = await rerankDocuments(args.query, docs, limit);
|
|
65
|
-
const rerankedResults = reranked
|
|
66
|
-
.map((r) => ({ ...results[r.index], score: r.relevanceScore }))
|
|
67
|
-
.filter((r) => r.text !== undefined);
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
content: [
|
|
71
|
-
{
|
|
72
|
-
type: "text" as const,
|
|
73
|
-
text: JSON.stringify(rerankedResults, null, 2),
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
};
|
|
77
|
-
}
|
|
67
|
+
try {
|
|
68
|
+
const limit = args.limit ?? 5;
|
|
69
|
+
const rerankTopK = args.rerankTopK ?? 20;
|
|
78
70
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
const results = await memoryRepository.search(args.query, {
|
|
72
|
+
project: args.project,
|
|
73
|
+
tags: args.tags,
|
|
74
|
+
limit: args.rerank && hasRemoteReranking ? rerankTopK : limit,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (args.rerank && hasRemoteReranking && results.length > limit) {
|
|
78
|
+
const docs = results.map((r) => r.text);
|
|
79
|
+
const reranked = await rerankDocuments(args.query, docs, limit);
|
|
80
|
+
const rerankedResults = reranked
|
|
81
|
+
.map((r) => ({ ...results[r.index], score: r.relevanceScore }))
|
|
82
|
+
.filter((r) => r.text !== undefined);
|
|
83
|
+
|
|
84
|
+
return text(JSON.stringify(rerankedResults, null, 2));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return text(JSON.stringify(results, null, 2));
|
|
88
|
+
} catch (err) {
|
|
89
|
+
return toolErr(err);
|
|
90
|
+
}
|
|
84
91
|
},
|
|
85
92
|
});
|
|
86
93
|
|
|
@@ -93,18 +100,64 @@ server.addTool({
|
|
|
93
100
|
tags: z.array(z.string()).optional(),
|
|
94
101
|
}),
|
|
95
102
|
execute: async (args) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
try {
|
|
104
|
+
if (args.ids && args.ids.length > 0) {
|
|
105
|
+
await memoryRepository.delete(args.ids);
|
|
106
|
+
return text(`Deleted ${args.ids.length} memories`);
|
|
107
|
+
}
|
|
108
|
+
if (args.project || args.tags) {
|
|
109
|
+
await memoryRepository.deleteByFilter({
|
|
110
|
+
project: args.project,
|
|
111
|
+
tags: args.tags,
|
|
112
|
+
});
|
|
113
|
+
return text("Deleted memories by filter");
|
|
114
|
+
}
|
|
115
|
+
return text("No IDs or filter provided");
|
|
116
|
+
} catch (err) {
|
|
117
|
+
return toolErr(err);
|
|
99
118
|
}
|
|
100
|
-
|
|
101
|
-
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
server.addTool({
|
|
123
|
+
name: "memory_compact",
|
|
124
|
+
description: "Compact memories by session or project, removing low-importance ones (importance < 0.6)",
|
|
125
|
+
parameters: z.object({
|
|
126
|
+
project: z.string().optional(),
|
|
127
|
+
sessionId: z.string().optional(),
|
|
128
|
+
importanceThreshold: z.number().optional().default(0.6),
|
|
129
|
+
}),
|
|
130
|
+
execute: async (args) => {
|
|
131
|
+
try {
|
|
132
|
+
const result = await memoryRepository.compact({
|
|
102
133
|
project: args.project,
|
|
103
|
-
|
|
134
|
+
sessionId: args.sessionId,
|
|
135
|
+
importanceThreshold: args.importanceThreshold,
|
|
104
136
|
});
|
|
105
|
-
return
|
|
137
|
+
return text(`Compacted ${result.compacted} memories`);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
return toolErr(err);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
server.addTool({
|
|
145
|
+
name: "memory_prune",
|
|
146
|
+
description: "Delete memories below an importance threshold",
|
|
147
|
+
parameters: z.object({
|
|
148
|
+
threshold: z.number(),
|
|
149
|
+
project: z.string().optional(),
|
|
150
|
+
}),
|
|
151
|
+
execute: async (args) => {
|
|
152
|
+
try {
|
|
153
|
+
const result = await memoryRepository.prune({
|
|
154
|
+
threshold: args.threshold,
|
|
155
|
+
project: args.project,
|
|
156
|
+
});
|
|
157
|
+
return text(`Pruned ${result.pruned} memories`);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
return toolErr(err);
|
|
106
160
|
}
|
|
107
|
-
return "No IDs or filter provided";
|
|
108
161
|
},
|
|
109
162
|
});
|
|
110
163
|
|
|
@@ -120,13 +173,17 @@ server.addTool({
|
|
|
120
173
|
metadata: z.record(z.unknown()).optional(),
|
|
121
174
|
}),
|
|
122
175
|
execute: async (args) => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
176
|
+
try {
|
|
177
|
+
const result = await entityRepository.create(
|
|
178
|
+
args.name,
|
|
179
|
+
args.entityType,
|
|
180
|
+
args.observations ?? [],
|
|
181
|
+
args.metadata,
|
|
182
|
+
);
|
|
183
|
+
return text(`Created entity: ${result.name} (${result.id})`);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
return toolErr(err);
|
|
186
|
+
}
|
|
130
187
|
},
|
|
131
188
|
});
|
|
132
189
|
|
|
@@ -139,16 +196,16 @@ server.addTool({
|
|
|
139
196
|
limit: z.number().optional().default(10),
|
|
140
197
|
}),
|
|
141
198
|
execute: async (args) => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
199
|
+
try {
|
|
200
|
+
const results = await entityRepository.search(
|
|
201
|
+
args.query,
|
|
202
|
+
args.entityType,
|
|
203
|
+
args.limit,
|
|
204
|
+
);
|
|
205
|
+
return text(JSON.stringify(results, null, 2));
|
|
206
|
+
} catch (err) {
|
|
207
|
+
return toolErr(err);
|
|
208
|
+
}
|
|
152
209
|
},
|
|
153
210
|
});
|
|
154
211
|
|
|
@@ -160,12 +217,16 @@ server.addTool({
|
|
|
160
217
|
observations: z.array(z.string()),
|
|
161
218
|
}),
|
|
162
219
|
execute: async (args) => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
220
|
+
try {
|
|
221
|
+
const result = await entityRepository.addObservations(
|
|
222
|
+
args.name,
|
|
223
|
+
args.observations,
|
|
224
|
+
);
|
|
225
|
+
if (!result) return text(`Entity not found: ${args.name}`);
|
|
226
|
+
return text(`Added observations to: ${result.name}`);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
return toolErr(err);
|
|
229
|
+
}
|
|
169
230
|
},
|
|
170
231
|
});
|
|
171
232
|
|
|
@@ -176,13 +237,13 @@ server.addTool({
|
|
|
176
237
|
name: z.string(),
|
|
177
238
|
}),
|
|
178
239
|
execute: async (args) => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
240
|
+
try {
|
|
241
|
+
const result = await entityRepository.get(args.name);
|
|
242
|
+
if (!result) return text(`Entity not found: ${args.name}`);
|
|
243
|
+
return text(JSON.stringify(result, null, 2));
|
|
244
|
+
} catch (err) {
|
|
245
|
+
return toolErr(err);
|
|
246
|
+
}
|
|
186
247
|
},
|
|
187
248
|
});
|
|
188
249
|
|
|
@@ -198,13 +259,19 @@ server.addTool({
|
|
|
198
259
|
metadata: z.record(z.unknown()).optional(),
|
|
199
260
|
}),
|
|
200
261
|
execute: async (args) => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
262
|
+
try {
|
|
263
|
+
const result = await relationRepository.create(
|
|
264
|
+
args.from,
|
|
265
|
+
args.relationType,
|
|
266
|
+
args.to,
|
|
267
|
+
args.metadata,
|
|
268
|
+
);
|
|
269
|
+
return text(
|
|
270
|
+
`Created relation: ${args.from} --[${args.relationType}]--> ${args.to} (${result.id})`,
|
|
271
|
+
);
|
|
272
|
+
} catch (err) {
|
|
273
|
+
return toolErr(err);
|
|
274
|
+
}
|
|
208
275
|
},
|
|
209
276
|
});
|
|
210
277
|
|
|
@@ -218,12 +285,12 @@ server.addTool({
|
|
|
218
285
|
limit: z.number().optional().default(20),
|
|
219
286
|
}),
|
|
220
287
|
execute: async (args) => {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
288
|
+
try {
|
|
289
|
+
const results = await relationRepository.search(args, args.limit);
|
|
290
|
+
return text(JSON.stringify(results, null, 2));
|
|
291
|
+
} catch (err) {
|
|
292
|
+
return toolErr(err);
|
|
293
|
+
}
|
|
227
294
|
},
|
|
228
295
|
});
|
|
229
296
|
|
|
@@ -236,75 +303,16 @@ server.addTool({
|
|
|
236
303
|
relationType: z.string().optional(),
|
|
237
304
|
}),
|
|
238
305
|
execute: async (args) => {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
server.addTool({
|
|
247
|
-
name: "memory_save_batch",
|
|
248
|
-
description: "Save multiple memories in a single call for efficiency",
|
|
249
|
-
parameters: z.object({
|
|
250
|
-
items: z.array(
|
|
251
|
-
z.object({
|
|
252
|
-
information: z.string(),
|
|
253
|
-
metadata: z
|
|
254
|
-
.object({
|
|
255
|
-
source: z.string().optional(),
|
|
256
|
-
project: z.string().optional(),
|
|
257
|
-
tags: z.array(z.string()).optional(),
|
|
258
|
-
})
|
|
259
|
-
.optional(),
|
|
260
|
-
}),
|
|
261
|
-
),
|
|
262
|
-
}),
|
|
263
|
-
execute: async (args) => {
|
|
264
|
-
const items = args.items.map((item) => ({
|
|
265
|
-
text: item.information,
|
|
266
|
-
metadata: item.metadata,
|
|
267
|
-
}));
|
|
268
|
-
const results = await memoryRepository.saveBatch(items);
|
|
269
|
-
return {
|
|
270
|
-
content: [
|
|
271
|
-
{
|
|
272
|
-
type: "text" as const,
|
|
273
|
-
text: JSON.stringify(
|
|
274
|
-
{ saved: results.length, ids: results.map((r) => r.id) },
|
|
275
|
-
null,
|
|
276
|
-
2,
|
|
277
|
-
),
|
|
278
|
-
},
|
|
279
|
-
],
|
|
280
|
-
};
|
|
281
|
-
},
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
server.addTool({
|
|
285
|
-
name: "memory_search_batch",
|
|
286
|
-
description: "Search multiple queries at once for efficiency",
|
|
287
|
-
parameters: z.object({
|
|
288
|
-
queries: z.array(
|
|
289
|
-
z.object({
|
|
290
|
-
query: z.string(),
|
|
291
|
-
project: z.string().optional(),
|
|
292
|
-
tags: z.array(z.string()).optional(),
|
|
293
|
-
limit: z.number().optional().default(5),
|
|
294
|
-
}),
|
|
295
|
-
),
|
|
296
|
-
}),
|
|
297
|
-
execute: async (args) => {
|
|
298
|
-
const results = await memoryRepository.searchBatch(args.queries);
|
|
299
|
-
return {
|
|
300
|
-
content: [
|
|
301
|
-
{ type: "text" as const, text: JSON.stringify(results, null, 2) },
|
|
302
|
-
],
|
|
303
|
-
};
|
|
306
|
+
try {
|
|
307
|
+
await relationRepository.delete(args);
|
|
308
|
+
return text("Relations deleted");
|
|
309
|
+
} catch (err) {
|
|
310
|
+
return toolErr(err);
|
|
311
|
+
}
|
|
304
312
|
},
|
|
305
313
|
});
|
|
306
314
|
|
|
307
|
-
// ── Memory Update
|
|
315
|
+
// ── Memory Update ─────────────────────────────────────────────────────────────
|
|
308
316
|
|
|
309
317
|
server.addTool({
|
|
310
318
|
name: "memory_update",
|
|
@@ -321,33 +329,16 @@ server.addTool({
|
|
|
321
329
|
.optional(),
|
|
322
330
|
}),
|
|
323
331
|
execute: async (args) => {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
server.addTool({
|
|
338
|
-
name: "memory_get",
|
|
339
|
-
description: "Get a single memory by its ID",
|
|
340
|
-
parameters: z.object({
|
|
341
|
-
id: z.string(),
|
|
342
|
-
}),
|
|
343
|
-
execute: async (args) => {
|
|
344
|
-
const result = await memoryRepository.getById(args.id);
|
|
345
|
-
if (!result) return `Memory not found: ${args.id}`;
|
|
346
|
-
return {
|
|
347
|
-
content: [
|
|
348
|
-
{ type: "text" as const, text: JSON.stringify(result, null, 2) },
|
|
349
|
-
],
|
|
350
|
-
};
|
|
332
|
+
try {
|
|
333
|
+
const result = await memoryRepository.update(args.id, {
|
|
334
|
+
text: args.text,
|
|
335
|
+
metadata: args.metadata,
|
|
336
|
+
});
|
|
337
|
+
if (!result) return text(`Memory not found: ${args.id}`);
|
|
338
|
+
return text(JSON.stringify(result, null, 2));
|
|
339
|
+
} catch (err) {
|
|
340
|
+
return toolErr(err);
|
|
341
|
+
}
|
|
351
342
|
},
|
|
352
343
|
});
|
|
353
344
|
|
|
@@ -363,20 +354,17 @@ server.addTool({
|
|
|
363
354
|
offset: z.string().optional(),
|
|
364
355
|
}),
|
|
365
356
|
execute: async (args) => {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
},
|
|
378
|
-
],
|
|
379
|
-
};
|
|
357
|
+
try {
|
|
358
|
+
const { memories, offset } = await memoryRepository.scroll({
|
|
359
|
+
project: args.project,
|
|
360
|
+
tags: args.tags,
|
|
361
|
+
limit: args.limit,
|
|
362
|
+
offset: args.offset,
|
|
363
|
+
});
|
|
364
|
+
return text(JSON.stringify({ memories, nextOffset: offset }, null, 2));
|
|
365
|
+
} catch (err) {
|
|
366
|
+
return toolErr(err);
|
|
367
|
+
}
|
|
380
368
|
},
|
|
381
369
|
});
|
|
382
370
|
|
|
@@ -385,55 +373,12 @@ server.addTool({
|
|
|
385
373
|
description: "Get statistics about the memories collection",
|
|
386
374
|
parameters: z.object({}),
|
|
387
375
|
execute: async () => {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
// ── Memory Import / Export ────────────────────────────────────────────────────
|
|
398
|
-
|
|
399
|
-
server.addTool({
|
|
400
|
-
name: "memory_export",
|
|
401
|
-
description: "Export all memories as JSON",
|
|
402
|
-
parameters: z.object({}),
|
|
403
|
-
execute: async () => {
|
|
404
|
-
const memories = await memoryRepository.export();
|
|
405
|
-
return {
|
|
406
|
-
content: [
|
|
407
|
-
{ type: "text" as const, text: JSON.stringify(memories, null, 2) },
|
|
408
|
-
],
|
|
409
|
-
};
|
|
410
|
-
},
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
server.addTool({
|
|
414
|
-
name: "memory_import",
|
|
415
|
-
description: "Import memories from JSON array",
|
|
416
|
-
parameters: z.object({
|
|
417
|
-
items: z.array(
|
|
418
|
-
z.object({
|
|
419
|
-
text: z.string(),
|
|
420
|
-
metadata: z
|
|
421
|
-
.object({
|
|
422
|
-
source: z.string().optional(),
|
|
423
|
-
project: z.string().optional(),
|
|
424
|
-
tags: z.array(z.string()).optional(),
|
|
425
|
-
})
|
|
426
|
-
.optional(),
|
|
427
|
-
}),
|
|
428
|
-
),
|
|
429
|
-
}),
|
|
430
|
-
execute: async (args) => {
|
|
431
|
-
const result = await memoryRepository.import(args.items);
|
|
432
|
-
return {
|
|
433
|
-
content: [
|
|
434
|
-
{ type: "text" as const, text: JSON.stringify(result, null, 2) },
|
|
435
|
-
],
|
|
436
|
-
};
|
|
376
|
+
try {
|
|
377
|
+
const stats = await memoryRepository.stats();
|
|
378
|
+
return text(JSON.stringify(stats, null, 2));
|
|
379
|
+
} catch (err) {
|
|
380
|
+
return toolErr(err);
|
|
381
|
+
}
|
|
437
382
|
},
|
|
438
383
|
});
|
|
439
384
|
|
|
@@ -449,17 +394,17 @@ server.addTool({
|
|
|
449
394
|
metadata: z.record(z.unknown()).optional(),
|
|
450
395
|
}),
|
|
451
396
|
execute: async (args) => {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
397
|
+
try {
|
|
398
|
+
const result = await entityRepository.update(args.id, {
|
|
399
|
+
name: args.name,
|
|
400
|
+
entityType: args.entityType,
|
|
401
|
+
metadata: args.metadata,
|
|
402
|
+
});
|
|
403
|
+
if (!result) return text(`Entity not found: ${args.id}`);
|
|
404
|
+
return text(JSON.stringify(result, null, 2));
|
|
405
|
+
} catch (err) {
|
|
406
|
+
return toolErr(err);
|
|
407
|
+
}
|
|
463
408
|
},
|
|
464
409
|
});
|
|
465
410
|
|
|
@@ -468,12 +413,12 @@ server.addTool({
|
|
|
468
413
|
description: "Get statistics about the entities collection",
|
|
469
414
|
parameters: z.object({}),
|
|
470
415
|
execute: async () => {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
416
|
+
try {
|
|
417
|
+
const stats = await entityRepository.stats();
|
|
418
|
+
return text(JSON.stringify(stats, null, 2));
|
|
419
|
+
} catch (err) {
|
|
420
|
+
return toolErr(err);
|
|
421
|
+
}
|
|
477
422
|
},
|
|
478
423
|
});
|
|
479
424
|
|
|
@@ -482,12 +427,12 @@ server.addTool({
|
|
|
482
427
|
description: "Get statistics about the relations collection",
|
|
483
428
|
parameters: z.object({}),
|
|
484
429
|
execute: async () => {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
}
|
|
430
|
+
try {
|
|
431
|
+
const stats = await relationRepository.stats();
|
|
432
|
+
return text(JSON.stringify(stats, null, 2));
|
|
433
|
+
} catch (err) {
|
|
434
|
+
return toolErr(err);
|
|
435
|
+
}
|
|
491
436
|
},
|
|
492
437
|
});
|
|
493
438
|
|
|
@@ -502,49 +447,17 @@ server.addTool({
|
|
|
502
447
|
tags: z.array(z.string()).optional(),
|
|
503
448
|
}),
|
|
504
449
|
execute: async (args) => {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
})
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
name: "memory_notes",
|
|
517
|
-
description: "Save multiple notes at once (batch lightweight memory saves)",
|
|
518
|
-
parameters: z.object({
|
|
519
|
-
notes: z.array(
|
|
520
|
-
z.object({
|
|
521
|
-
content: z.string(),
|
|
522
|
-
project: z.string().optional(),
|
|
523
|
-
tags: z.array(z.string()).optional(),
|
|
524
|
-
}),
|
|
525
|
-
),
|
|
526
|
-
}),
|
|
527
|
-
execute: async (args) => {
|
|
528
|
-
const items = args.notes.map((n) => ({
|
|
529
|
-
text: n.content,
|
|
530
|
-
metadata: {
|
|
531
|
-
project: n.project,
|
|
532
|
-
tags: [...(n.tags ?? []), "note"],
|
|
533
|
-
},
|
|
534
|
-
}));
|
|
535
|
-
const results = await memoryRepository.saveBatch(items);
|
|
536
|
-
return {
|
|
537
|
-
content: [
|
|
538
|
-
{
|
|
539
|
-
type: "text" as const,
|
|
540
|
-
text: JSON.stringify(
|
|
541
|
-
{ saved: results.length, ids: results.map((r) => r.id) },
|
|
542
|
-
null,
|
|
543
|
-
2,
|
|
544
|
-
),
|
|
545
|
-
},
|
|
546
|
-
],
|
|
547
|
-
};
|
|
450
|
+
try {
|
|
451
|
+
const tags = [...(args.tags ?? []), "note"];
|
|
452
|
+
const result = await memoryRepository.save(args.content, {
|
|
453
|
+
project: args.project,
|
|
454
|
+
tags,
|
|
455
|
+
createdAt: new Date().toISOString(),
|
|
456
|
+
});
|
|
457
|
+
return text(`Saved note: ${result.id}`);
|
|
458
|
+
} catch (err) {
|
|
459
|
+
return toolErr(err);
|
|
460
|
+
}
|
|
548
461
|
},
|
|
549
462
|
});
|
|
550
463
|
|
|
@@ -558,19 +471,16 @@ server.addTool({
|
|
|
558
471
|
offset: z.string().optional(),
|
|
559
472
|
}),
|
|
560
473
|
execute: async (args) => {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
},
|
|
572
|
-
],
|
|
573
|
-
};
|
|
474
|
+
try {
|
|
475
|
+
const { entities, offset } = await entityRepository.list(
|
|
476
|
+
args.entityType,
|
|
477
|
+
args.limit,
|
|
478
|
+
args.offset,
|
|
479
|
+
);
|
|
480
|
+
return text(JSON.stringify({ entities, nextOffset: offset }, null, 2));
|
|
481
|
+
} catch (err) {
|
|
482
|
+
return toolErr(err);
|
|
483
|
+
}
|
|
574
484
|
},
|
|
575
485
|
});
|
|
576
486
|
|
|
@@ -584,19 +494,16 @@ server.addTool({
|
|
|
584
494
|
offset: z.string().optional(),
|
|
585
495
|
}),
|
|
586
496
|
execute: async (args) => {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
},
|
|
598
|
-
],
|
|
599
|
-
};
|
|
497
|
+
try {
|
|
498
|
+
const { relations, offset } = await relationRepository.list(
|
|
499
|
+
args.relationType,
|
|
500
|
+
args.limit,
|
|
501
|
+
args.offset,
|
|
502
|
+
);
|
|
503
|
+
return text(JSON.stringify({ relations, nextOffset: offset }, null, 2));
|
|
504
|
+
} catch (err) {
|
|
505
|
+
return toolErr(err);
|
|
506
|
+
}
|
|
600
507
|
},
|
|
601
508
|
});
|
|
602
509
|
|
|
@@ -610,11 +517,16 @@ async function init(retries = 10, delayMs = 3000) {
|
|
|
610
517
|
await relationRepository.init();
|
|
611
518
|
collectionsReady = true;
|
|
612
519
|
console.error("Collections initialized");
|
|
520
|
+
try {
|
|
521
|
+
await warmup();
|
|
522
|
+
} catch (err) {
|
|
523
|
+
console.warn("Embedding warmup failed (non-fatal):", err);
|
|
524
|
+
}
|
|
613
525
|
return;
|
|
614
526
|
} catch (err) {
|
|
615
527
|
if (attempt === retries) {
|
|
616
528
|
console.error(`Failed to initialize collections after ${retries} attempts:`, err);
|
|
617
|
-
|
|
529
|
+
process.exit(1);
|
|
618
530
|
}
|
|
619
531
|
console.error(`Collection init attempt ${attempt}/${retries} failed, retrying in ${delayMs / 1000}s...`);
|
|
620
532
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
@@ -661,3 +573,18 @@ if (config.transport === "http") {
|
|
|
661
573
|
} else {
|
|
662
574
|
server.start({ transportType: "stdio" });
|
|
663
575
|
}
|
|
576
|
+
|
|
577
|
+
function shutdown(signal: string) {
|
|
578
|
+
console.error(`[grove] Received ${signal}, shutting down...`);
|
|
579
|
+
server.stop().then(() => {
|
|
580
|
+
console.error("[grove] Server stopped");
|
|
581
|
+
process.exit(0);
|
|
582
|
+
});
|
|
583
|
+
setTimeout(() => {
|
|
584
|
+
console.error("[grove] Force exit after timeout");
|
|
585
|
+
process.exit(1);
|
|
586
|
+
}, 5000);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
590
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|