@aeriondyseti/vector-memory-mcp 0.9.0-dev.2 → 0.9.0-dev.3
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/README.md +21 -1
- package/dist/scripts/publish.d.ts +13 -0
- package/dist/scripts/publish.d.ts.map +1 -0
- package/dist/scripts/publish.js +56 -0
- package/dist/scripts/publish.js.map +1 -0
- package/dist/scripts/test-runner.d.ts +9 -0
- package/dist/scripts/test-runner.d.ts.map +1 -0
- package/dist/scripts/test-runner.js +61 -0
- package/dist/scripts/test-runner.js.map +1 -0
- package/dist/scripts/warmup.d.ts +8 -0
- package/dist/scripts/warmup.d.ts.map +1 -0
- package/dist/scripts/warmup.js +61 -0
- package/dist/scripts/warmup.js.map +1 -0
- package/dist/src/config/index.d.ts +23 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +46 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/db/connection.d.ts +3 -0
- package/dist/src/db/connection.d.ts.map +1 -0
- package/dist/src/db/connection.js +10 -0
- package/dist/src/db/connection.js.map +1 -0
- package/dist/src/db/memory.repository.d.ts +13 -0
- package/dist/src/db/memory.repository.d.ts.map +1 -0
- package/dist/src/db/memory.repository.js +97 -0
- package/dist/src/db/memory.repository.js.map +1 -0
- package/dist/src/db/schema.d.ts +4 -0
- package/dist/src/db/schema.d.ts.map +1 -0
- package/dist/src/db/schema.js +12 -0
- package/dist/src/db/schema.js.map +1 -0
- package/dist/src/http/mcp-transport.d.ts +19 -0
- package/dist/src/http/mcp-transport.d.ts.map +1 -0
- package/dist/src/http/mcp-transport.js +191 -0
- package/dist/src/http/mcp-transport.js.map +1 -0
- package/dist/src/http/server.d.ts +12 -0
- package/dist/src/http/server.d.ts.map +1 -0
- package/dist/src/http/server.js +168 -0
- package/dist/src/http/server.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +59 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/handlers.d.ts +11 -0
- package/dist/src/mcp/handlers.d.ts.map +1 -0
- package/dist/src/mcp/handlers.js +175 -0
- package/dist/src/mcp/handlers.js.map +1 -0
- package/dist/src/mcp/server.d.ts +5 -0
- package/dist/src/mcp/server.d.ts.map +1 -0
- package/dist/src/mcp/server.js +22 -0
- package/dist/src/mcp/server.js.map +1 -0
- package/dist/src/mcp/tools.d.ts +9 -0
- package/dist/src/mcp/tools.d.ts.map +1 -0
- package/dist/src/mcp/tools.js +243 -0
- package/dist/src/mcp/tools.js.map +1 -0
- package/dist/src/services/embeddings.service.d.ts +12 -0
- package/dist/src/services/embeddings.service.d.ts.map +1 -0
- package/dist/src/services/embeddings.service.js +37 -0
- package/dist/src/services/embeddings.service.js.map +1 -0
- package/dist/src/services/memory.service.d.ts +31 -0
- package/dist/src/services/memory.service.d.ts.map +1 -0
- package/dist/src/services/memory.service.js +131 -0
- package/dist/src/services/memory.service.js.map +1 -0
- package/dist/src/types/memory.d.ts +17 -0
- package/dist/src/types/memory.d.ts.map +1 -0
- package/dist/src/types/memory.js +15 -0
- package/dist/src/types/memory.js.map +1 -0
- package/package.json +12 -8
- package/src/config/index.ts +0 -75
- package/src/db/connection.ts +0 -11
- package/src/db/memory.repository.ts +0 -115
- package/src/db/schema.ts +0 -34
- package/src/http/mcp-transport.ts +0 -255
- package/src/http/server.ts +0 -190
- package/src/index.ts +0 -70
- package/src/mcp/handlers.ts +0 -248
- package/src/mcp/server.ts +0 -34
- package/src/mcp/tools.ts +0 -254
- package/src/services/embeddings.service.ts +0 -48
- package/src/services/memory.service.ts +0 -185
- package/src/types/memory.ts +0 -31
package/src/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { loadConfig, parseCliArgs } from "./config/index.js";
|
|
4
|
-
import { connectToDatabase } from "./db/connection.js";
|
|
5
|
-
import { MemoryRepository } from "./db/memory.repository.js";
|
|
6
|
-
import { EmbeddingsService } from "./services/embeddings.service.js";
|
|
7
|
-
import { MemoryService } from "./services/memory.service.js";
|
|
8
|
-
import { startServer } from "./mcp/server.js";
|
|
9
|
-
import { startHttpServer } from "./http/server.js";
|
|
10
|
-
|
|
11
|
-
async function main(): Promise<void> {
|
|
12
|
-
const args = process.argv.slice(2);
|
|
13
|
-
|
|
14
|
-
// Check for warmup command
|
|
15
|
-
if (args[0] === "warmup") {
|
|
16
|
-
const { warmup } = await import("../scripts/warmup.js");
|
|
17
|
-
await warmup();
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Parse CLI args and load config
|
|
22
|
-
const overrides = parseCliArgs(args);
|
|
23
|
-
const config = loadConfig(overrides);
|
|
24
|
-
|
|
25
|
-
// Initialize database
|
|
26
|
-
const db = await connectToDatabase(config.dbPath);
|
|
27
|
-
|
|
28
|
-
// Initialize layers
|
|
29
|
-
const repository = new MemoryRepository(db);
|
|
30
|
-
const embeddings = new EmbeddingsService(config.embeddingModel, config.embeddingDimension);
|
|
31
|
-
const memoryService = new MemoryService(repository, embeddings);
|
|
32
|
-
|
|
33
|
-
// Track cleanup functions
|
|
34
|
-
let httpStop: (() => void) | null = null;
|
|
35
|
-
|
|
36
|
-
// Graceful shutdown handler
|
|
37
|
-
const shutdown = () => {
|
|
38
|
-
console.error("[vector-memory-mcp] Shutting down...");
|
|
39
|
-
if (httpStop) httpStop();
|
|
40
|
-
db.close();
|
|
41
|
-
process.exit(0);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// Handle signals and stdin close (parent process exit)
|
|
45
|
-
process.on("SIGTERM", shutdown);
|
|
46
|
-
process.on("SIGINT", shutdown);
|
|
47
|
-
process.stdin.on("close", shutdown);
|
|
48
|
-
process.stdin.on("end", shutdown);
|
|
49
|
-
|
|
50
|
-
// Start HTTP server if transport mode includes it
|
|
51
|
-
if (config.enableHttp) {
|
|
52
|
-
const http = await startHttpServer(memoryService, config);
|
|
53
|
-
httpStop = http.stop;
|
|
54
|
-
console.error(
|
|
55
|
-
`[vector-memory-mcp] MCP available at http://${config.httpHost}:${config.httpPort}/mcp`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Start stdio transport unless in HTTP-only mode
|
|
60
|
-
if (config.transportMode !== "http") {
|
|
61
|
-
await startServer(memoryService);
|
|
62
|
-
} else {
|
|
63
|
-
// In HTTP-only mode, keep the process running
|
|
64
|
-
console.error("[vector-memory-mcp] Running in HTTP-only mode (no stdio)");
|
|
65
|
-
// Keep process alive - the HTTP server runs indefinitely
|
|
66
|
-
await new Promise(() => {});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
main().catch(console.error);
|
package/src/mcp/handlers.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import type { MemoryService } from "../services/memory.service.js";
|
|
3
|
-
|
|
4
|
-
export async function handleStoreMemories(
|
|
5
|
-
args: Record<string, unknown> | undefined,
|
|
6
|
-
service: MemoryService
|
|
7
|
-
): Promise<CallToolResult> {
|
|
8
|
-
const memories = args?.memories as Array<{
|
|
9
|
-
content: string;
|
|
10
|
-
embedding_text?: string;
|
|
11
|
-
metadata?: Record<string, unknown>;
|
|
12
|
-
}>;
|
|
13
|
-
|
|
14
|
-
const ids: string[] = [];
|
|
15
|
-
for (const item of memories) {
|
|
16
|
-
const memory = await service.store(
|
|
17
|
-
item.content,
|
|
18
|
-
item.metadata ?? {},
|
|
19
|
-
item.embedding_text
|
|
20
|
-
);
|
|
21
|
-
ids.push(memory.id);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
content: [
|
|
26
|
-
{
|
|
27
|
-
type: "text",
|
|
28
|
-
text:
|
|
29
|
-
ids.length === 1
|
|
30
|
-
? `Memory stored with ID: ${ids[0]}`
|
|
31
|
-
: `Stored ${ids.length} memories:\n${ids.map((id) => `- ${id}`).join("\n")}`,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function handleDeleteMemories(
|
|
38
|
-
args: Record<string, unknown> | undefined,
|
|
39
|
-
service: MemoryService
|
|
40
|
-
): Promise<CallToolResult> {
|
|
41
|
-
const ids = args?.ids as string[];
|
|
42
|
-
const results: string[] = [];
|
|
43
|
-
|
|
44
|
-
for (const id of ids) {
|
|
45
|
-
const success = await service.delete(id);
|
|
46
|
-
results.push(
|
|
47
|
-
success ? `Memory ${id} deleted successfully` : `Memory ${id} not found`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
content: [
|
|
53
|
-
{
|
|
54
|
-
type: "text",
|
|
55
|
-
text: results.join("\n"),
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export async function handleUpdateMemories(
|
|
63
|
-
args: Record<string, unknown> | undefined,
|
|
64
|
-
service: MemoryService
|
|
65
|
-
): Promise<CallToolResult> {
|
|
66
|
-
const updates = args?.updates as Array<{
|
|
67
|
-
id: string;
|
|
68
|
-
content?: string;
|
|
69
|
-
embedding_text?: string;
|
|
70
|
-
metadata?: Record<string, unknown>;
|
|
71
|
-
}>;
|
|
72
|
-
|
|
73
|
-
const results: string[] = [];
|
|
74
|
-
|
|
75
|
-
for (const update of updates) {
|
|
76
|
-
const memory = await service.update(update.id, {
|
|
77
|
-
content: update.content,
|
|
78
|
-
embeddingText: update.embedding_text,
|
|
79
|
-
metadata: update.metadata,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (memory) {
|
|
83
|
-
results.push(`Memory ${update.id} updated successfully`);
|
|
84
|
-
} else {
|
|
85
|
-
results.push(`Memory ${update.id} not found`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
content: [
|
|
91
|
-
{
|
|
92
|
-
type: "text",
|
|
93
|
-
text: results.join("\n"),
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export async function handleSearchMemories(
|
|
100
|
-
args: Record<string, unknown> | undefined,
|
|
101
|
-
service: MemoryService
|
|
102
|
-
): Promise<CallToolResult> {
|
|
103
|
-
const query = args?.query as string;
|
|
104
|
-
const limit = (args?.limit as number) ?? 10;
|
|
105
|
-
const includeDeleted = (args?.include_deleted as boolean) ?? false;
|
|
106
|
-
const memories = await service.search(query, limit, includeDeleted);
|
|
107
|
-
|
|
108
|
-
if (memories.length === 0) {
|
|
109
|
-
return {
|
|
110
|
-
content: [{ type: "text", text: "No memories found matching your query." }],
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const results = memories.map((mem) => {
|
|
115
|
-
let result = `ID: ${mem.id}\nContent: ${mem.content}`;
|
|
116
|
-
if (Object.keys(mem.metadata).length > 0) {
|
|
117
|
-
result += `\nMetadata: ${JSON.stringify(mem.metadata)}`;
|
|
118
|
-
}
|
|
119
|
-
if (includeDeleted && mem.supersededBy) {
|
|
120
|
-
result += `\n[DELETED]`;
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
content: [{ type: "text", text: results.join("\n\n---\n\n") }],
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export async function handleGetMemories(
|
|
131
|
-
args: Record<string, unknown> | undefined,
|
|
132
|
-
service: MemoryService
|
|
133
|
-
): Promise<CallToolResult> {
|
|
134
|
-
const ids = args?.ids as string[];
|
|
135
|
-
|
|
136
|
-
const format = (
|
|
137
|
-
memoryId: string,
|
|
138
|
-
memory: Awaited<ReturnType<MemoryService["get"]>>
|
|
139
|
-
) => {
|
|
140
|
-
if (!memory) {
|
|
141
|
-
return `Memory ${memoryId} not found`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
let result = `ID: ${memory.id}\nContent: ${memory.content}`;
|
|
145
|
-
if (Object.keys(memory.metadata).length > 0) {
|
|
146
|
-
result += `\nMetadata: ${JSON.stringify(memory.metadata)}`;
|
|
147
|
-
}
|
|
148
|
-
result += `\nCreated: ${memory.createdAt.toISOString()}`;
|
|
149
|
-
result += `\nUpdated: ${memory.updatedAt.toISOString()}`;
|
|
150
|
-
if (memory.supersededBy) {
|
|
151
|
-
result += `\nSuperseded by: ${memory.supersededBy}`;
|
|
152
|
-
}
|
|
153
|
-
return result;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const blocks: string[] = [];
|
|
157
|
-
for (const id of ids) {
|
|
158
|
-
const memory = await service.get(id);
|
|
159
|
-
blocks.push(format(id, memory));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
content: [{ type: "text", text: blocks.join("\n\n---\n\n") }],
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export async function handleStoreHandoff(
|
|
168
|
-
args: Record<string, unknown> | undefined,
|
|
169
|
-
service: MemoryService
|
|
170
|
-
): Promise<CallToolResult> {
|
|
171
|
-
const memory = await service.storeHandoff({
|
|
172
|
-
project: args?.project as string,
|
|
173
|
-
branch: args?.branch as string | undefined,
|
|
174
|
-
summary: args?.summary as string,
|
|
175
|
-
completed: (args?.completed as string[] | undefined) ?? [],
|
|
176
|
-
in_progress_blocked: (args?.in_progress_blocked as string[] | undefined) ?? [],
|
|
177
|
-
key_decisions: (args?.key_decisions as string[] | undefined) ?? [],
|
|
178
|
-
next_steps: (args?.next_steps as string[] | undefined) ?? [],
|
|
179
|
-
memory_ids: (args?.memory_ids as string[] | undefined) ?? [],
|
|
180
|
-
metadata: (args?.metadata as Record<string, unknown>) ?? {},
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
return {
|
|
184
|
-
content: [{ type: "text", text: `Handoff stored with memory ID: ${memory.id}` }],
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export async function handleGetHandoff(
|
|
189
|
-
_args: Record<string, unknown> | undefined,
|
|
190
|
-
service: MemoryService
|
|
191
|
-
): Promise<CallToolResult> {
|
|
192
|
-
const handoff = await service.getLatestHandoff();
|
|
193
|
-
|
|
194
|
-
if (!handoff) {
|
|
195
|
-
return {
|
|
196
|
-
content: [{ type: "text", text: "No stored handoff found." }],
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Fetch referenced memories if any
|
|
201
|
-
const memoryIds = (handoff.metadata.memory_ids as string[] | undefined) ?? [];
|
|
202
|
-
let memoriesSection = "";
|
|
203
|
-
|
|
204
|
-
if (memoryIds.length > 0) {
|
|
205
|
-
const memories: string[] = [];
|
|
206
|
-
for (const id of memoryIds) {
|
|
207
|
-
const memory = await service.get(id);
|
|
208
|
-
if (memory) {
|
|
209
|
-
memories.push(`### Memory: ${id}\n${memory.content}`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (memories.length > 0) {
|
|
213
|
-
memoriesSection = `\n\n## Referenced Memories\n\n${memories.join("\n\n")}`;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return {
|
|
218
|
-
content: [{ type: "text", text: handoff.content + memoriesSection }],
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export async function handleToolCall(
|
|
223
|
-
name: string,
|
|
224
|
-
args: Record<string, unknown> | undefined,
|
|
225
|
-
service: MemoryService
|
|
226
|
-
): Promise<CallToolResult> {
|
|
227
|
-
switch (name) {
|
|
228
|
-
case "store_memories":
|
|
229
|
-
return handleStoreMemories(args, service);
|
|
230
|
-
case "update_memories":
|
|
231
|
-
return handleUpdateMemories(args, service);
|
|
232
|
-
case "delete_memories":
|
|
233
|
-
return handleDeleteMemories(args, service);
|
|
234
|
-
case "search_memories":
|
|
235
|
-
return handleSearchMemories(args, service);
|
|
236
|
-
case "get_memories":
|
|
237
|
-
return handleGetMemories(args, service);
|
|
238
|
-
case "store_handoff":
|
|
239
|
-
return handleStoreHandoff(args, service);
|
|
240
|
-
case "get_handoff":
|
|
241
|
-
return handleGetHandoff(args, service);
|
|
242
|
-
default:
|
|
243
|
-
return {
|
|
244
|
-
content: [{ type: "text", text: `Unknown tool: ${name}` }],
|
|
245
|
-
isError: true,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
}
|
package/src/mcp/server.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
-
import {
|
|
4
|
-
CallToolRequestSchema,
|
|
5
|
-
ListToolsRequestSchema,
|
|
6
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
7
|
-
|
|
8
|
-
import { tools } from "./tools.js";
|
|
9
|
-
import { handleToolCall } from "./handlers.js";
|
|
10
|
-
import type { MemoryService } from "../services/memory.service.js";
|
|
11
|
-
|
|
12
|
-
export function createServer(memoryService: MemoryService): Server {
|
|
13
|
-
const server = new Server(
|
|
14
|
-
{ name: "vector-memory-mcp", version: "0.6.0" },
|
|
15
|
-
{ capabilities: { tools: {} } }
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
19
|
-
return { tools };
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
23
|
-
const { name, arguments: args } = request.params;
|
|
24
|
-
return handleToolCall(name, args, memoryService);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return server;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function startServer(memoryService: MemoryService): Promise<void> {
|
|
31
|
-
const server = createServer(memoryService);
|
|
32
|
-
const transport = new StdioServerTransport();
|
|
33
|
-
await server.connect(transport);
|
|
34
|
-
}
|
package/src/mcp/tools.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
|
|
3
|
-
export const storeMemoriesTool: Tool = {
|
|
4
|
-
name: "store_memories",
|
|
5
|
-
description: `Store memories that persist across conversations. Use after making decisions or learning something worth remembering.
|
|
6
|
-
|
|
7
|
-
RULES:
|
|
8
|
-
- 1 concept per memory, 1-3 sentences (20-75 words)
|
|
9
|
-
- Self-contained with explicit subjects (no "it", "this", "the project")
|
|
10
|
-
- Include dates/versions when relevant
|
|
11
|
-
- Be concrete, not vague
|
|
12
|
-
|
|
13
|
-
MEMORY TYPES (use as metadata.type):
|
|
14
|
-
- decision: what was chosen + why ("Chose libSQL over PostgreSQL for vector support and simpler deployment")
|
|
15
|
-
- implementation: what was built + where + patterns used
|
|
16
|
-
- insight: learning + why it matters
|
|
17
|
-
- blocker: problem encountered + resolution
|
|
18
|
-
- next-step: TODO item + suggested approach
|
|
19
|
-
- context: background info + constraints
|
|
20
|
-
|
|
21
|
-
DON'T STORE: machine-specific paths, local env details, ephemeral states, pleasantries
|
|
22
|
-
|
|
23
|
-
GOOD: "Aerion chose libSQL over PostgreSQL for Resonance (Dec 2024) because of native vector support and simpler deployment."
|
|
24
|
-
BAD: "Uses SQLite" (no context, no subject, no reasoning)
|
|
25
|
-
|
|
26
|
-
For long content (>1000 chars), provide embedding_text with a searchable summary.`,
|
|
27
|
-
inputSchema: {
|
|
28
|
-
type: "object",
|
|
29
|
-
properties: {
|
|
30
|
-
memories: {
|
|
31
|
-
type: "array",
|
|
32
|
-
description: "Memories to store.",
|
|
33
|
-
items: {
|
|
34
|
-
type: "object",
|
|
35
|
-
properties: {
|
|
36
|
-
content: {
|
|
37
|
-
type: "string",
|
|
38
|
-
description: "The content to store.",
|
|
39
|
-
},
|
|
40
|
-
embedding_text: {
|
|
41
|
-
type: "string",
|
|
42
|
-
description:
|
|
43
|
-
"Summary for search embedding (required if content >1000 chars).",
|
|
44
|
-
},
|
|
45
|
-
metadata: {
|
|
46
|
-
type: "object",
|
|
47
|
-
description: "Optional key-value metadata.",
|
|
48
|
-
additionalProperties: true,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
required: ["content"],
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
required: ["memories"],
|
|
56
|
-
},
|
|
57
|
-
};;
|
|
58
|
-
|
|
59
|
-
export const deleteMemoriesTool: Tool = {
|
|
60
|
-
name: "delete_memories",
|
|
61
|
-
description:
|
|
62
|
-
"Remove memories that are no longer needed—outdated info, superseded decisions, or incorrect content. " +
|
|
63
|
-
"Deleted memories can be recovered via search_memories with include_deleted: true.",
|
|
64
|
-
inputSchema: {
|
|
65
|
-
type: "object",
|
|
66
|
-
properties: {
|
|
67
|
-
ids: {
|
|
68
|
-
type: "array",
|
|
69
|
-
description: "IDs of memories to delete.",
|
|
70
|
-
items: {
|
|
71
|
-
type: "string",
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
required: ["ids"],
|
|
76
|
-
},
|
|
77
|
-
};;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const updateMemoriesTool: Tool = {
|
|
81
|
-
name: "update_memories",
|
|
82
|
-
description: `Update existing memories in place. Prefer over delete+create when updating the same conceptual item.
|
|
83
|
-
|
|
84
|
-
BEHAVIOR:
|
|
85
|
-
- Fields omitted/null: left untouched
|
|
86
|
-
- Fields provided: completely overwrite existing value (no merge)
|
|
87
|
-
|
|
88
|
-
Use to correct content, refine embedding text, or replace metadata without changing the memory ID.`,
|
|
89
|
-
inputSchema: {
|
|
90
|
-
type: "object",
|
|
91
|
-
properties: {
|
|
92
|
-
updates: {
|
|
93
|
-
type: "array",
|
|
94
|
-
description: "Updates to apply. Each must include id and at least one field to change.",
|
|
95
|
-
items: {
|
|
96
|
-
type: "object",
|
|
97
|
-
properties: {
|
|
98
|
-
id: {
|
|
99
|
-
type: "string",
|
|
100
|
-
description: "ID of memory to update.",
|
|
101
|
-
},
|
|
102
|
-
content: {
|
|
103
|
-
type: "string",
|
|
104
|
-
description: "New content (triggers embedding regeneration).",
|
|
105
|
-
},
|
|
106
|
-
embedding_text: {
|
|
107
|
-
type: "string",
|
|
108
|
-
description: "New embedding summary (triggers embedding regeneration).",
|
|
109
|
-
},
|
|
110
|
-
metadata: {
|
|
111
|
-
type: "object",
|
|
112
|
-
description: "New metadata (replaces existing entirely).",
|
|
113
|
-
additionalProperties: true,
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
required: ["id"],
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
required: ["updates"],
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export const searchMemoriesTool: Tool = {
|
|
125
|
-
name: "search_memories",
|
|
126
|
-
description: `Search stored memories semantically. Use PROACTIVELY—don't wait to be asked.
|
|
127
|
-
|
|
128
|
-
WHEN TO SEARCH:
|
|
129
|
-
- At conversation start / returning to a project
|
|
130
|
-
- Before making decisions (check for prior decisions on same topic)
|
|
131
|
-
- When user references past work ("what did we decide", "as discussed", "remember when")
|
|
132
|
-
- Before suggesting solutions (check if problem was solved before)
|
|
133
|
-
- When debugging (check for prior blockers/resolutions)
|
|
134
|
-
- When uncertain about patterns or preferences
|
|
135
|
-
|
|
136
|
-
When in doubt, search. Missing relevant context is costlier than an extra query.
|
|
137
|
-
|
|
138
|
-
QUERY TIPS:
|
|
139
|
-
- Include project name, technical terms, or domain keywords
|
|
140
|
-
- Search for concepts, not exact phrases
|
|
141
|
-
- Try multiple queries if first doesn't return useful results`,
|
|
142
|
-
inputSchema: {
|
|
143
|
-
type: "object",
|
|
144
|
-
properties: {
|
|
145
|
-
query: {
|
|
146
|
-
type: "string",
|
|
147
|
-
description:
|
|
148
|
-
"Natural language search query. Include relevant keywords, project names, or technical terms.",
|
|
149
|
-
},
|
|
150
|
-
limit: {
|
|
151
|
-
type: "integer",
|
|
152
|
-
description: "Maximum results to return (default: 10).",
|
|
153
|
-
default: 10,
|
|
154
|
-
},
|
|
155
|
-
include_deleted: {
|
|
156
|
-
type: "boolean",
|
|
157
|
-
description: "Include soft-deleted memories in results (default: false). Useful for recovering prior information.",
|
|
158
|
-
default: false,
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
required: ["query"],
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export const getMemoriesTool: Tool = {
|
|
166
|
-
name: "get_memories",
|
|
167
|
-
description:
|
|
168
|
-
"Retrieve full memory details by ID. Use when you have specific IDs from search results or prior references—otherwise use search_memories.",
|
|
169
|
-
inputSchema: {
|
|
170
|
-
type: "object",
|
|
171
|
-
properties: {
|
|
172
|
-
ids: {
|
|
173
|
-
type: "array",
|
|
174
|
-
description: "Memory IDs to retrieve.",
|
|
175
|
-
items: { type: "string" },
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
required: ["ids"],
|
|
179
|
-
},
|
|
180
|
-
};;
|
|
181
|
-
|
|
182
|
-
export const storeHandoffTool: Tool = {
|
|
183
|
-
name: "store_handoff",
|
|
184
|
-
description: `Save session state for seamless resumption later. Use at end of work sessions or before context switches.
|
|
185
|
-
|
|
186
|
-
Creates a structured snapshot with:
|
|
187
|
-
- summary: 2-3 sentences on goal and current status
|
|
188
|
-
- completed: what got done (include file paths)
|
|
189
|
-
- in_progress_blocked: work in flight or stuck
|
|
190
|
-
- key_decisions: choices made and WHY (crucial for future context)
|
|
191
|
-
- next_steps: concrete, actionable items
|
|
192
|
-
- memory_ids: link to related memories stored this session
|
|
193
|
-
|
|
194
|
-
Retrievable via get_handoff. Only one handoff per project—new handoffs overwrite previous.`,
|
|
195
|
-
inputSchema: {
|
|
196
|
-
type: "object",
|
|
197
|
-
properties: {
|
|
198
|
-
project: { type: "string", description: "Project name." },
|
|
199
|
-
branch: { type: "string", description: "Branch name (optional)." },
|
|
200
|
-
summary: { type: "string", description: "2-3 sentences: primary goal, current status." },
|
|
201
|
-
completed: {
|
|
202
|
-
type: "array",
|
|
203
|
-
items: { type: "string" },
|
|
204
|
-
description: "Completed items (include file paths where relevant).",
|
|
205
|
-
},
|
|
206
|
-
in_progress_blocked: {
|
|
207
|
-
type: "array",
|
|
208
|
-
items: { type: "string" },
|
|
209
|
-
description: "In progress or blocked items.",
|
|
210
|
-
},
|
|
211
|
-
key_decisions: {
|
|
212
|
-
type: "array",
|
|
213
|
-
items: { type: "string" },
|
|
214
|
-
description: "Decisions made and why.",
|
|
215
|
-
},
|
|
216
|
-
next_steps: {
|
|
217
|
-
type: "array",
|
|
218
|
-
items: { type: "string" },
|
|
219
|
-
description: "Concrete next steps.",
|
|
220
|
-
},
|
|
221
|
-
memory_ids: {
|
|
222
|
-
type: "array",
|
|
223
|
-
items: { type: "string" },
|
|
224
|
-
description: "Memory IDs referenced by this handoff.",
|
|
225
|
-
},
|
|
226
|
-
metadata: {
|
|
227
|
-
type: "object",
|
|
228
|
-
description: "Additional metadata.",
|
|
229
|
-
additionalProperties: true,
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
required: ["project", "summary"],
|
|
233
|
-
},
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
export const getHandoffTool: Tool = {
|
|
237
|
-
name: "get_handoff",
|
|
238
|
-
description:
|
|
239
|
-
"Load the current project handoff snapshot. Call at conversation start or when resuming a project.",
|
|
240
|
-
inputSchema: {
|
|
241
|
-
type: "object",
|
|
242
|
-
properties: {},
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
export const tools: Tool[] = [
|
|
247
|
-
storeMemoriesTool,
|
|
248
|
-
updateMemoriesTool,
|
|
249
|
-
deleteMemoriesTool,
|
|
250
|
-
searchMemoriesTool,
|
|
251
|
-
getMemoriesTool,
|
|
252
|
-
storeHandoffTool,
|
|
253
|
-
getHandoffTool,
|
|
254
|
-
];
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { pipeline, type FeatureExtractionPipeline } from "@huggingface/transformers";
|
|
2
|
-
|
|
3
|
-
export class EmbeddingsService {
|
|
4
|
-
private modelName: string;
|
|
5
|
-
private extractor: FeatureExtractionPipeline | null = null;
|
|
6
|
-
private initPromise: Promise<FeatureExtractionPipeline> | null = null;
|
|
7
|
-
private _dimension: number;
|
|
8
|
-
|
|
9
|
-
constructor(modelName: string, dimension: number) {
|
|
10
|
-
this.modelName = modelName;
|
|
11
|
-
this._dimension = dimension;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get dimension(): number {
|
|
15
|
-
return this._dimension;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private async getExtractor(): Promise<FeatureExtractionPipeline> {
|
|
19
|
-
if (this.extractor) {
|
|
20
|
-
return this.extractor;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!this.initPromise) {
|
|
24
|
-
this.initPromise = pipeline(
|
|
25
|
-
"feature-extraction",
|
|
26
|
-
this.modelName,
|
|
27
|
-
{ dtype: "fp32" } as any
|
|
28
|
-
) as Promise<FeatureExtractionPipeline>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this.extractor = await this.initPromise;
|
|
32
|
-
return this.extractor;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async embed(text: string): Promise<number[]> {
|
|
36
|
-
const extractor = await this.getExtractor();
|
|
37
|
-
const output = await extractor(text, { pooling: "mean", normalize: true });
|
|
38
|
-
return Array.from(output.data as Float32Array);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async embedBatch(texts: string[]): Promise<number[][]> {
|
|
42
|
-
const results: number[][] = [];
|
|
43
|
-
for (const text of texts) {
|
|
44
|
-
results.push(await this.embed(text));
|
|
45
|
-
}
|
|
46
|
-
return results;
|
|
47
|
-
}
|
|
48
|
-
}
|