@prmichaelsen/remember-mcp 3.12.0 → 3.14.0
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 +20 -0
- package/agent/milestones/milestone-17-remember-core-migration.md +140 -0
- package/agent/progress.yaml +123 -6
- package/agent/tasks/milestone-17-remember-core-migration/task-193-foundation-setup.md +58 -0
- package/agent/tasks/milestone-17-remember-core-migration/task-194-migrate-relationship-tools.md +47 -0
- package/agent/tasks/milestone-17-remember-core-migration/task-195-migrate-preference-tools.md +34 -0
- package/agent/tasks/milestone-17-remember-core-migration/task-196-migrate-memory-tools.md +46 -0
- package/agent/tasks/milestone-17-remember-core-migration/task-197-migrate-space-confirmation-tools.md +49 -0
- package/agent/tasks/milestone-17-remember-core-migration/task-198-migrate-space-search-moderate.md +46 -0
- package/agent/tasks/milestone-17-remember-core-migration/task-199-migrate-delete-memory.md +43 -0
- package/agent/tasks/milestone-17-remember-core-migration/task-200-code-cleanup-verification.md +52 -0
- package/dist/core-services.d.ts +25 -0
- package/dist/server-factory.js +3578 -4485
- package/dist/server.js +3070 -3973
- package/dist/tools/confirm-publish-moderation.spec.d.ts +3 -2
- package/dist/tools/create-memory.d.ts +1 -1
- package/dist/tools/query-space.d.ts +1 -1
- package/dist/tools/search-space.d.ts +10 -14
- package/jest.config.js +11 -0
- package/package.json +2 -1
- package/src/core-services.ts +50 -0
- package/src/tools/confirm-publish-moderation.spec.ts +120 -176
- package/src/tools/confirm.ts +70 -1035
- package/src/tools/create-memory.ts +16 -67
- package/src/tools/create-relationship.ts +13 -181
- package/src/tools/delete-memory.ts +7 -72
- package/src/tools/delete-relationship.ts +7 -91
- package/src/tools/deny.ts +4 -14
- package/src/tools/find-similar.ts +16 -110
- package/src/tools/get-preferences.ts +3 -8
- package/src/tools/moderate.spec.ts +65 -81
- package/src/tools/moderate.ts +18 -121
- package/src/tools/publish.ts +7 -204
- package/src/tools/query-space.ts +28 -140
- package/src/tools/retract.ts +7 -185
- package/src/tools/revise.ts +4 -136
- package/src/tools/search-relationship.ts +17 -116
- package/src/tools/search-space.ts +58 -304
- package/src/tools/set-preference.ts +3 -8
- package/src/tools/update-memory.ts +22 -190
- package/src/tools/update-relationship.ts +16 -90
- package/src/v2-smoke.e2e.ts +3 -2
- package/dist/collections/composite-ids.d.ts +0 -106
- package/dist/collections/core-infrastructure.spec.d.ts +0 -11
- package/dist/collections/dot-notation.d.ts +0 -106
- package/dist/collections/tracking-arrays.d.ts +0 -176
- package/dist/constants/content-types.d.ts +0 -61
- package/dist/services/confirmation-token.service.d.ts +0 -99
- package/dist/services/confirmation-token.service.spec.d.ts +0 -5
- package/dist/services/preferences-database.service.d.ts +0 -22
- package/dist/services/space-config.service.d.ts +0 -23
- package/dist/services/space-config.service.spec.d.ts +0 -2
- package/src/collections/composite-ids.ts +0 -193
- package/src/collections/core-infrastructure.spec.ts +0 -353
- package/src/collections/dot-notation.ts +0 -212
- package/src/collections/tracking-arrays.ts +0 -298
- package/src/constants/content-types.ts +0 -490
- package/src/services/confirmation-token.service.spec.ts +0 -254
- package/src/services/confirmation-token.service.ts +0 -328
- package/src/services/preferences-database.service.ts +0 -120
- package/src/services/space-config.service.spec.ts +0 -102
- package/src/services/space-config.service.ts +0 -79
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { Memory, ContentType, Location, MemoryContext } from '../types/memory.js';
|
|
7
|
-
import { ensureMemoryCollection, getMemoryCollection } from '../weaviate/schema.js';
|
|
8
|
-
import { logger } from '../utils/logger.js';
|
|
9
7
|
import { handleToolError } from '../utils/error-handler.js';
|
|
10
|
-
import { DEFAULT_CONTENT_TYPE, getContentTypeDescription
|
|
8
|
+
import { DEFAULT_CONTENT_TYPE, getContentTypeDescription } from '@prmichaelsen/remember-core';
|
|
11
9
|
import { createDebugLogger } from '../utils/debug.js';
|
|
12
10
|
import type { AuthContext } from '../types/auth.js';
|
|
11
|
+
import { createCoreServices } from '../core-services.js';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Tool definition for remember_create_memory
|
|
@@ -143,78 +142,28 @@ export async function handleCreateMemory(
|
|
|
143
142
|
try {
|
|
144
143
|
debug.info('Tool invoked');
|
|
145
144
|
debug.trace('Arguments', { args });
|
|
146
|
-
logger.info('Creating memory', { userId, type: args.type });
|
|
147
145
|
|
|
148
|
-
|
|
149
|
-
await
|
|
150
|
-
const collection = getMemoryCollection(userId);
|
|
151
|
-
|
|
152
|
-
// Build memory object using v2 property names
|
|
153
|
-
const now = new Date().toISOString();
|
|
154
|
-
const memory: Record<string, any> = {
|
|
155
|
-
// Core identity
|
|
156
|
-
user_id: userId,
|
|
157
|
-
doc_type: 'memory',
|
|
158
|
-
|
|
159
|
-
// Content
|
|
146
|
+
const { memory } = createCoreServices(userId);
|
|
147
|
+
const result = await memory.create({
|
|
160
148
|
content: args.content,
|
|
161
149
|
title: args.title,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
150
|
+
type: args.type,
|
|
151
|
+
weight: args.weight,
|
|
152
|
+
trust: args.trust,
|
|
153
|
+
tags: args.tags,
|
|
154
|
+
references: args.references,
|
|
155
|
+
template_id: args.template_id,
|
|
156
|
+
parent_id: args.parent_id,
|
|
157
|
+
thread_root_id: args.thread_root_id,
|
|
158
|
+
moderation_flags: args.moderation_flags,
|
|
171
159
|
context_summary: context?.summary || 'Memory created via MCP',
|
|
172
160
|
context_conversation_id: context?.conversation_id,
|
|
173
|
-
|
|
174
|
-
// Relationships
|
|
175
|
-
relationship_ids: [],
|
|
176
|
-
|
|
177
|
-
// Access tracking
|
|
178
|
-
access_count: 0,
|
|
179
|
-
last_accessed_at: now,
|
|
180
|
-
|
|
181
|
-
// Metadata
|
|
182
|
-
created_at: now,
|
|
183
|
-
updated_at: now,
|
|
184
|
-
version: 1,
|
|
185
|
-
tags: args.tags || [],
|
|
186
|
-
references: args.references || [],
|
|
187
|
-
|
|
188
|
-
// Template
|
|
189
|
-
template_id: args.template_id,
|
|
190
|
-
|
|
191
|
-
// Computed weight
|
|
192
|
-
base_weight: args.weight ?? 0.5,
|
|
193
|
-
computed_weight: args.weight ?? 0.5,
|
|
194
|
-
|
|
195
|
-
// Comment/threading fields (initialize to defaults)
|
|
196
|
-
parent_id: args.parent_id ?? null,
|
|
197
|
-
thread_root_id: args.thread_root_id ?? null,
|
|
198
|
-
moderation_flags: args.moderation_flags ?? [],
|
|
199
|
-
|
|
200
|
-
// Publication tracking arrays (Memory Collection Pattern v2)
|
|
201
|
-
// Managed by remember_publish / remember_retract — always start empty
|
|
202
|
-
space_ids: [],
|
|
203
|
-
group_ids: [],
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// Insert into Weaviate v3 API
|
|
207
|
-
// v3 expects: { properties: {...} }
|
|
208
|
-
const result = await collection.data.insert({
|
|
209
|
-
properties: memory as any,
|
|
210
161
|
});
|
|
211
162
|
|
|
212
|
-
logger.info('Memory created successfully', { memoryId: result, userId });
|
|
213
|
-
|
|
214
163
|
const response: CreateMemoryResult = {
|
|
215
|
-
memory_id: result,
|
|
216
|
-
created_at:
|
|
217
|
-
message: `Memory created successfully with ID: ${result}`,
|
|
164
|
+
memory_id: result.memory_id,
|
|
165
|
+
created_at: result.created_at,
|
|
166
|
+
message: `Memory created successfully with ID: ${result.memory_id}`,
|
|
218
167
|
};
|
|
219
168
|
|
|
220
169
|
return JSON.stringify(response, null, 2);
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* Create a relationship connecting 2...N memories
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
import { ensureMemoryCollection, getMemoryCollection } from '../weaviate/schema.js';
|
|
8
|
-
import { logger } from '../utils/logger.js';
|
|
6
|
+
import type { MemoryContext } from '../types/memory.js';
|
|
9
7
|
import { handleToolError } from '../utils/error-handler.js';
|
|
10
8
|
import { createDebugLogger } from '../utils/debug.js';
|
|
11
9
|
import type { AuthContext } from '../types/auth.js';
|
|
10
|
+
import { createCoreServices } from '../core-services.js';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Tool definition for remember_create_relationship
|
|
@@ -103,189 +102,22 @@ export async function handleCreateRelationship(
|
|
|
103
102
|
debug.info('Tool invoked');
|
|
104
103
|
debug.trace('Arguments', { args });
|
|
105
104
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
memoryCount: args.memory_ids.length
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Validate memory_ids count
|
|
113
|
-
if (args.memory_ids.length < 2) {
|
|
114
|
-
throw new Error('At least 2 memory IDs are required to create a relationship');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Ensure collection exists
|
|
118
|
-
await ensureMemoryCollection(userId);
|
|
119
|
-
const collection = getMemoryCollection(userId);
|
|
120
|
-
|
|
121
|
-
// Verify all memories exist and belong to user
|
|
122
|
-
logger.info('Validating memories', { userId, memoryIds: args.memory_ids });
|
|
123
|
-
|
|
124
|
-
const memoryChecks = await Promise.all(
|
|
125
|
-
args.memory_ids.map(async (memoryId) => {
|
|
126
|
-
try {
|
|
127
|
-
const memory = await collection.query.fetchObjectById(memoryId, {
|
|
128
|
-
returnProperties: ['user_id', 'doc_type', 'relationship_ids', 'deleted_at'],
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (!memory) {
|
|
132
|
-
logger.warn('Memory not found', { userId, memoryId });
|
|
133
|
-
return { memoryId, error: 'Memory not found' };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (memory.properties.user_id !== userId) {
|
|
137
|
-
logger.warn('Unauthorized memory access attempt', {
|
|
138
|
-
userId,
|
|
139
|
-
memoryId,
|
|
140
|
-
actualUserId: memory.properties.user_id
|
|
141
|
-
});
|
|
142
|
-
return { memoryId, error: 'Unauthorized: Memory belongs to another user' };
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (memory.properties.doc_type !== 'memory') {
|
|
146
|
-
logger.warn('Invalid doc_type for relationship', {
|
|
147
|
-
userId,
|
|
148
|
-
memoryId,
|
|
149
|
-
docType: memory.properties.doc_type
|
|
150
|
-
});
|
|
151
|
-
return { memoryId, error: 'Cannot create relationship with non-memory document' };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Check if memory is deleted
|
|
155
|
-
if (memory.properties.deleted_at) {
|
|
156
|
-
const deletedAt = typeof memory.properties.deleted_at === 'string'
|
|
157
|
-
? memory.properties.deleted_at
|
|
158
|
-
: new Date(memory.properties.deleted_at as any).toISOString();
|
|
159
|
-
logger.warn('Attempt to create relationship with deleted memory', {
|
|
160
|
-
userId,
|
|
161
|
-
memoryId,
|
|
162
|
-
deletedAt
|
|
163
|
-
});
|
|
164
|
-
return { memoryId, error: `Memory is deleted (deleted on ${deletedAt})` };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
memoryId,
|
|
169
|
-
memory,
|
|
170
|
-
relationships: (memory.properties.relationship_ids as string[]) || []
|
|
171
|
-
};
|
|
172
|
-
} catch (error) {
|
|
173
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
174
|
-
logger.error('Failed to fetch memory for relationship', {
|
|
175
|
-
userId,
|
|
176
|
-
memoryId,
|
|
177
|
-
error: errorMsg
|
|
178
|
-
});
|
|
179
|
-
return { memoryId, error: `Failed to fetch memory: ${errorMsg}` };
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
// Check for errors
|
|
185
|
-
const errors = memoryChecks.filter(check => check.error);
|
|
186
|
-
if (errors.length > 0) {
|
|
187
|
-
const errorMessages = errors.map(e => `${e.memoryId}: ${e.error}`).join('; ');
|
|
188
|
-
logger.error('Memory validation failed', {
|
|
189
|
-
userId,
|
|
190
|
-
errorCount: errors.length,
|
|
191
|
-
errors: errorMessages
|
|
192
|
-
});
|
|
193
|
-
throw new Error(`Memory validation failed: ${errorMessages}`);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
logger.info('All memories validated successfully', {
|
|
197
|
-
userId,
|
|
198
|
-
validatedCount: memoryChecks.length
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// Build relationship object
|
|
202
|
-
const now = new Date().toISOString();
|
|
203
|
-
const relationship: Record<string, any> = {
|
|
204
|
-
// Core identity
|
|
205
|
-
user_id: userId,
|
|
206
|
-
doc_type: 'relationship',
|
|
207
|
-
|
|
208
|
-
// Connection
|
|
209
|
-
related_memory_ids: args.memory_ids,
|
|
105
|
+
const { relationship } = createCoreServices(userId);
|
|
106
|
+
const result = await relationship.create({
|
|
107
|
+
memory_ids: args.memory_ids,
|
|
210
108
|
relationship_type: args.relationship_type,
|
|
211
|
-
|
|
212
|
-
// Observation
|
|
213
109
|
observation: args.observation,
|
|
214
|
-
strength: args.strength
|
|
215
|
-
confidence: args.confidence
|
|
216
|
-
|
|
217
|
-
// Context
|
|
218
|
-
context: {
|
|
219
|
-
timestamp: now,
|
|
220
|
-
source: {
|
|
221
|
-
type: 'api',
|
|
222
|
-
platform: 'mcp',
|
|
223
|
-
},
|
|
224
|
-
summary: context?.summary || 'Relationship created via MCP',
|
|
225
|
-
conversation_id: context?.conversation_id,
|
|
226
|
-
...context,
|
|
227
|
-
},
|
|
228
|
-
|
|
229
|
-
// Metadata
|
|
230
|
-
created_at: now,
|
|
231
|
-
updated_at: now,
|
|
232
|
-
version: 1,
|
|
233
|
-
tags: args.tags || [],
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// Insert relationship into Weaviate v3 API
|
|
237
|
-
// v3 expects: { properties: {...} }
|
|
238
|
-
const relationshipId = await collection.data.insert({
|
|
239
|
-
properties: relationship as any,
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
logger.info('Relationship created, updating connected memories', {
|
|
243
|
-
relationshipId,
|
|
244
|
-
userId
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// Update all connected memories with bidirectional reference
|
|
248
|
-
const updatePromises = memoryChecks
|
|
249
|
-
.filter(check => !check.error && check.memory)
|
|
250
|
-
.map(async (check) => {
|
|
251
|
-
try {
|
|
252
|
-
const existingRelationships = check.relationships || [];
|
|
253
|
-
const updatedRelationships = [...existingRelationships, relationshipId];
|
|
254
|
-
|
|
255
|
-
await collection.data.update({
|
|
256
|
-
id: check.memoryId,
|
|
257
|
-
properties: {
|
|
258
|
-
relationship_ids: updatedRelationships,
|
|
259
|
-
updated_at: now,
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
return { memoryId: check.memoryId, success: true };
|
|
264
|
-
} catch (error) {
|
|
265
|
-
logger.warn(`Failed to update memory ${check.memoryId} with relationship:`, error);
|
|
266
|
-
return { memoryId: check.memoryId, success: false, error };
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
const updateResults = await Promise.all(updatePromises);
|
|
271
|
-
const failedUpdates = updateResults.filter(r => !r.success);
|
|
272
|
-
|
|
273
|
-
if (failedUpdates.length > 0) {
|
|
274
|
-
logger.warn('Some memory updates failed', { failedUpdates });
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
logger.info('Relationship created successfully', {
|
|
278
|
-
relationshipId,
|
|
279
|
-
userId,
|
|
280
|
-
updatedMemories: updateResults.filter(r => r.success).length
|
|
110
|
+
strength: args.strength,
|
|
111
|
+
confidence: args.confidence,
|
|
112
|
+
tags: args.tags,
|
|
281
113
|
});
|
|
282
114
|
|
|
283
115
|
const response: CreateRelationshipResult = {
|
|
284
|
-
relationship_id:
|
|
285
|
-
memory_ids:
|
|
116
|
+
relationship_id: result.relationship_id,
|
|
117
|
+
memory_ids: result.memory_ids,
|
|
286
118
|
relationship_type: args.relationship_type,
|
|
287
|
-
created_at:
|
|
288
|
-
message: `Relationship created successfully with ID: ${
|
|
119
|
+
created_at: result.created_at,
|
|
120
|
+
message: `Relationship created successfully with ID: ${result.relationship_id}. Connected ${args.memory_ids.length} memories.`,
|
|
289
121
|
};
|
|
290
122
|
|
|
291
123
|
return JSON.stringify(response, null, 2);
|
|
@@ -298,7 +130,7 @@ export async function handleCreateRelationship(
|
|
|
298
130
|
memoryIds: args.memory_ids.join(', '),
|
|
299
131
|
memoryCount: args.memory_ids.length,
|
|
300
132
|
relationshipType: args.relationship_type,
|
|
301
|
-
observation: args.observation?.substring(0, 100),
|
|
133
|
+
observation: args.observation?.substring(0, 100),
|
|
302
134
|
});
|
|
303
135
|
}
|
|
304
136
|
}
|
|
@@ -4,13 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
-
import { Filters } from 'weaviate-client';
|
|
8
|
-
import { getWeaviateClient, getMemoryCollectionName, fetchMemoryWithAllProperties } from '../weaviate/client.js';
|
|
9
|
-
import { confirmationTokenService } from '../services/confirmation-token.service.js';
|
|
10
|
-
import { logger } from '../utils/logger.js';
|
|
11
7
|
import { handleToolError } from '../utils/error-handler.js';
|
|
12
8
|
import { createDebugLogger } from '../utils/debug.js';
|
|
13
9
|
import type { AuthContext } from '../types/auth.js';
|
|
10
|
+
import { createCoreServices } from '../core-services.js';
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
13
|
* Tool definition for remember_delete_memory
|
|
@@ -66,90 +63,28 @@ export async function handleDeleteMemory(
|
|
|
66
63
|
try {
|
|
67
64
|
debug.info('Tool invoked');
|
|
68
65
|
debug.trace('Arguments', { args });
|
|
69
|
-
logger.info('Requesting memory deletion', {
|
|
70
|
-
userId,
|
|
71
|
-
memoryId: args.memory_id,
|
|
72
|
-
hasReason: !!args.reason,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const { memory_id, reason } = args;
|
|
76
|
-
const client = getWeaviateClient();
|
|
77
|
-
const collectionName = getMemoryCollectionName(userId);
|
|
78
|
-
const collection = client.collections.get(collectionName);
|
|
79
|
-
|
|
80
|
-
// Fetch memory to verify ownership and get preview
|
|
81
|
-
const memory = await fetchMemoryWithAllProperties(collection, memory_id);
|
|
82
|
-
|
|
83
|
-
if (!memory) {
|
|
84
|
-
throw new Error(`Memory not found: ${memory_id}`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Verify ownership
|
|
88
|
-
if (memory.properties.user_id !== userId) {
|
|
89
|
-
throw new Error(`Cannot delete memory: not owned by user ${userId}`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Verify it's a memory (not a relationship)
|
|
93
|
-
if (memory.properties.doc_type !== 'memory') {
|
|
94
|
-
throw new Error('Cannot delete relationships using this tool. Use remember_delete_relationship instead.');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Check if already deleted
|
|
98
|
-
if (memory.properties.deleted_at) {
|
|
99
|
-
throw new Error(`Memory ${memory_id} is already deleted`);
|
|
100
|
-
}
|
|
101
66
|
|
|
102
|
-
|
|
103
|
-
const relationshipsResult = await collection.query.fetchObjects({
|
|
104
|
-
filters: Filters.and(
|
|
105
|
-
collection.filter.byProperty('doc_type').equal('relationship'),
|
|
106
|
-
collection.filter.byProperty('related_memory_ids').containsAny([memory_id])
|
|
107
|
-
),
|
|
108
|
-
limit: 100,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const orphanedRelationships = relationshipsResult.objects.map(r => r.uuid);
|
|
112
|
-
|
|
113
|
-
logger.info('Found relationships to orphan', {
|
|
114
|
-
userId,
|
|
115
|
-
memoryId: memory_id,
|
|
116
|
-
relationshipCount: orphanedRelationships.length,
|
|
117
|
-
});
|
|
67
|
+
const { token: tokenService } = createCoreServices(userId);
|
|
118
68
|
|
|
119
|
-
// Create confirmation token
|
|
120
|
-
const {
|
|
69
|
+
// Create confirmation token via core service
|
|
70
|
+
const { token } = await tokenService.createRequest(
|
|
121
71
|
userId,
|
|
122
72
|
'delete_memory',
|
|
123
73
|
{
|
|
124
|
-
memory_id,
|
|
125
|
-
reason: reason || null,
|
|
74
|
+
memory_id: args.memory_id,
|
|
75
|
+
reason: args.reason || null,
|
|
126
76
|
}
|
|
127
77
|
);
|
|
128
78
|
|
|
129
79
|
// Calculate expiry time (5 minutes from now)
|
|
130
80
|
const expiresAt = new Date(Date.now() + 5 * 60 * 1000);
|
|
131
81
|
|
|
132
|
-
logger.info('Delete confirmation token created', {
|
|
133
|
-
userId,
|
|
134
|
-
memoryId: memory_id,
|
|
135
|
-
requestId,
|
|
136
|
-
token,
|
|
137
|
-
expiresAt: expiresAt.toISOString(),
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Return token and preview
|
|
141
82
|
return JSON.stringify(
|
|
142
83
|
{
|
|
143
84
|
success: true,
|
|
144
85
|
token,
|
|
145
86
|
expires_at: expiresAt.toISOString(),
|
|
146
|
-
|
|
147
|
-
memory_id,
|
|
148
|
-
content: memory.properties.content?.substring(0, 200) + (memory.properties.content?.length > 200 ? '...' : ''),
|
|
149
|
-
content_type: memory.properties.content_type,
|
|
150
|
-
relationships_count: orphanedRelationships.length,
|
|
151
|
-
will_orphan: orphanedRelationships,
|
|
152
|
-
},
|
|
87
|
+
memory_id: args.memory_id,
|
|
153
88
|
message: `Deletion requested. Use remember_confirm with token to complete deletion. Token expires in 5 minutes.`,
|
|
154
89
|
},
|
|
155
90
|
null,
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
* Delete a relationship and clean up references in connected memories
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { getMemoryCollection } from '../weaviate/schema.js';
|
|
7
|
-
import { logger } from '../utils/logger.js';
|
|
8
6
|
import { handleToolError } from '../utils/error-handler.js';
|
|
9
7
|
import { createDebugLogger } from '../utils/debug.js';
|
|
10
8
|
import type { AuthContext } from '../types/auth.js';
|
|
9
|
+
import { createCoreServices } from '../core-services.js';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Tool definition for remember_delete_relationship
|
|
@@ -66,99 +65,16 @@ export async function handleDeleteRelationship(
|
|
|
66
65
|
debug.info('Tool invoked');
|
|
67
66
|
debug.trace('Arguments', { args });
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// Get relationship to verify ownership and get connected memory IDs
|
|
74
|
-
const relationship = await collection.query.fetchObjectById(args.relationship_id, {
|
|
75
|
-
returnProperties: ['user_id', 'doc_type', 'related_memory_ids', 'relationship_type'],
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
if (!relationship) {
|
|
79
|
-
throw new Error(`Relationship not found: ${args.relationship_id}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Verify ownership
|
|
83
|
-
if (relationship.properties.user_id !== userId) {
|
|
84
|
-
throw new Error('Unauthorized: Cannot delete another user\'s relationship');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Verify it's a relationship (not a memory)
|
|
88
|
-
if (relationship.properties.doc_type !== 'relationship') {
|
|
89
|
-
throw new Error('Cannot delete memories using this tool. Use remember_delete_memory instead.');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const memoryIds = (relationship.properties.related_memory_ids as string[]) || [];
|
|
93
|
-
let memoriesUpdated = 0;
|
|
94
|
-
|
|
95
|
-
// Remove relationship reference from all connected memories
|
|
96
|
-
if (memoryIds.length > 0) {
|
|
97
|
-
logger.info('Cleaning up relationship references from connected memories', {
|
|
98
|
-
relationshipId: args.relationship_id,
|
|
99
|
-
memoryCount: memoryIds.length,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const updatePromises = memoryIds.map(async (memoryId) => {
|
|
103
|
-
try {
|
|
104
|
-
// Get current memory to read relationships array
|
|
105
|
-
const memory = await collection.query.fetchObjectById(memoryId, {
|
|
106
|
-
returnProperties: ['relationship_ids', 'doc_type'],
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
if (!memory || memory.properties.doc_type !== 'memory') {
|
|
110
|
-
logger.warn(`Memory ${memoryId} not found or not a memory, skipping cleanup`);
|
|
111
|
-
return { memoryId, success: false };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const currentRelationships = (memory.properties.relationship_ids as string[]) || [];
|
|
115
|
-
const updatedRelationships = currentRelationships.filter(
|
|
116
|
-
(relId) => relId !== args.relationship_id
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// Only update if there was a change
|
|
120
|
-
if (updatedRelationships.length !== currentRelationships.length) {
|
|
121
|
-
await collection.data.update({
|
|
122
|
-
id: memoryId,
|
|
123
|
-
properties: {
|
|
124
|
-
relationship_ids: updatedRelationships,
|
|
125
|
-
updated_at: new Date().toISOString(),
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
return { memoryId, success: true };
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return { memoryId, success: false };
|
|
132
|
-
} catch (error) {
|
|
133
|
-
logger.warn(`Failed to update memory ${memoryId}:`, error);
|
|
134
|
-
return { memoryId, success: false, error };
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const updateResults = await Promise.all(updatePromises);
|
|
139
|
-
memoriesUpdated = updateResults.filter((r) => r.success).length;
|
|
140
|
-
|
|
141
|
-
logger.info('Memory cleanup completed', {
|
|
142
|
-
relationshipId: args.relationship_id,
|
|
143
|
-
memoriesUpdated,
|
|
144
|
-
totalMemories: memoryIds.length,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Delete the relationship
|
|
149
|
-
await collection.data.deleteById(args.relationship_id);
|
|
150
|
-
|
|
151
|
-
logger.info('Relationship deleted successfully', {
|
|
152
|
-
userId,
|
|
153
|
-
relationshipId: args.relationship_id,
|
|
154
|
-
memoriesUpdated,
|
|
68
|
+
const { relationship } = createCoreServices(userId);
|
|
69
|
+
const coreResult = await relationship.delete({
|
|
70
|
+
relationship_id: args.relationship_id,
|
|
155
71
|
});
|
|
156
72
|
|
|
157
73
|
const result: DeleteRelationshipResult = {
|
|
158
|
-
relationship_id:
|
|
74
|
+
relationship_id: coreResult.relationship_id,
|
|
159
75
|
deleted: true,
|
|
160
|
-
memories_updated:
|
|
161
|
-
message: `Relationship deleted successfully${
|
|
76
|
+
memories_updated: coreResult.memories_updated,
|
|
77
|
+
message: `Relationship deleted successfully${coreResult.memories_updated > 0 ? ` (${coreResult.memories_updated} memories updated)` : ''}`,
|
|
162
78
|
};
|
|
163
79
|
|
|
164
80
|
return JSON.stringify(result, null, 2);
|
package/src/tools/deny.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
-
import { confirmationTokenService } from '../services/confirmation-token.service.js';
|
|
9
8
|
import { handleToolError } from '../utils/error-handler.js';
|
|
10
9
|
import { createDebugLogger } from '../utils/debug.js';
|
|
11
10
|
import type { AuthContext } from '../types/auth.js';
|
|
11
|
+
import { createCoreServices } from '../core-services.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Tool definition for remember_deny
|
|
@@ -66,23 +66,13 @@ export async function handleDeny(
|
|
|
66
66
|
try {
|
|
67
67
|
debug.info('Tool invoked');
|
|
68
68
|
debug.trace('Arguments', { args });
|
|
69
|
-
const success = await confirmationTokenService.denyRequest(userId, args.token);
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
success: false,
|
|
75
|
-
error: 'Invalid token',
|
|
76
|
-
message: 'Token not found or already used',
|
|
77
|
-
},
|
|
78
|
-
null,
|
|
79
|
-
2
|
|
80
|
-
);
|
|
81
|
-
}
|
|
70
|
+
const { space } = createCoreServices(userId);
|
|
71
|
+
const result = await space.deny({ token: args.token });
|
|
82
72
|
|
|
83
73
|
return JSON.stringify(
|
|
84
74
|
{
|
|
85
|
-
success:
|
|
75
|
+
success: result.success,
|
|
86
76
|
},
|
|
87
77
|
null,
|
|
88
78
|
2
|