@prmichaelsen/remember-mcp 3.14.10 → 3.14.12
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/server-factory.js +3306 -3017
- package/dist/server.js +9 -121
- package/package.json +2 -3
- package/src/services/access-control.ts +1 -1
- package/src/tools/query-memory.ts +1 -2
- package/src/tools/search-memory.ts +1 -2
- package/dist/services/trust-enforcement.d.ts +0 -83
- package/dist/services/trust-enforcement.spec.d.ts +0 -2
- package/dist/utils/weaviate-filters.d.ts +0 -56
- package/dist/utils/weaviate-filters.spec.d.ts +0 -8
- package/src/services/trust-enforcement.spec.ts +0 -309
- package/src/services/trust-enforcement.ts +0 -197
- package/src/utils/weaviate-filters.spec.ts +0 -312
- package/src/utils/weaviate-filters.ts +0 -236
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Weaviate v3 Filter Builder Utilities
|
|
3
|
-
*
|
|
4
|
-
* Provides helper functions to build Weaviate v3 filters using the fluent API.
|
|
5
|
-
* Replaces old v2 filter format (path/operator/valueText) with v3 collection.filter.byProperty()
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Filters } from 'weaviate-client';
|
|
9
|
-
import type { SearchFilters } from '../types/memory.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Deleted filter options
|
|
13
|
-
*/
|
|
14
|
-
export type DeletedFilter = 'exclude' | 'include' | 'only';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Build filters for searching both memories and relationships
|
|
18
|
-
* Uses OR logic: (doc_type=memory AND memory_filters) OR (doc_type=relationship AND relationship_filters)
|
|
19
|
-
*
|
|
20
|
-
* @param collection - Weaviate collection instance
|
|
21
|
-
* @param filters - Optional search filters
|
|
22
|
-
* @returns Combined filter or undefined if no filters
|
|
23
|
-
*/
|
|
24
|
-
export function buildCombinedSearchFilters(
|
|
25
|
-
collection: any,
|
|
26
|
-
filters?: SearchFilters
|
|
27
|
-
): any {
|
|
28
|
-
// Build memory-specific filters
|
|
29
|
-
const memoryFilters = buildDocTypeFilters(collection, 'memory', filters);
|
|
30
|
-
|
|
31
|
-
// Build relationship-specific filters
|
|
32
|
-
const relationshipFilters = buildDocTypeFilters(collection, 'relationship', filters);
|
|
33
|
-
|
|
34
|
-
// Filter out undefined/null values before combining
|
|
35
|
-
const validFilters = [memoryFilters, relationshipFilters].filter(f => f !== undefined && f !== null);
|
|
36
|
-
|
|
37
|
-
// Combine with OR: search both memories and relationships
|
|
38
|
-
if (validFilters.length === 0) {
|
|
39
|
-
return undefined;
|
|
40
|
-
} else if (validFilters.length === 1) {
|
|
41
|
-
return validFilters[0];
|
|
42
|
-
} else {
|
|
43
|
-
return combineFiltersWithOr(validFilters);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Build filters for a specific doc_type (memory or relationship)
|
|
49
|
-
*
|
|
50
|
-
* @param collection - Weaviate collection instance
|
|
51
|
-
* @param docType - 'memory' or 'relationship'
|
|
52
|
-
* @param filters - Optional search filters
|
|
53
|
-
* @returns Combined filter for this doc_type
|
|
54
|
-
*/
|
|
55
|
-
function buildDocTypeFilters(
|
|
56
|
-
collection: any,
|
|
57
|
-
docType: 'memory' | 'relationship',
|
|
58
|
-
filters?: SearchFilters
|
|
59
|
-
): any {
|
|
60
|
-
const filterList: any[] = [];
|
|
61
|
-
|
|
62
|
-
// Always filter by doc_type
|
|
63
|
-
filterList.push(
|
|
64
|
-
collection.filter.byProperty('doc_type').equal(docType)
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
// Type filter (content type) - only applies to memories, not relationships
|
|
68
|
-
if (docType === 'memory' && filters?.types && filters.types.length > 0) {
|
|
69
|
-
if (filters.types.length === 1) {
|
|
70
|
-
filterList.push(
|
|
71
|
-
collection.filter.byProperty('content_type').equal(filters.types[0])
|
|
72
|
-
);
|
|
73
|
-
} else {
|
|
74
|
-
filterList.push(
|
|
75
|
-
collection.filter.byProperty('content_type').containsAny(filters.types)
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Weight filter (minimum) - applies to both memories and relationships
|
|
81
|
-
if (filters?.weight_min !== undefined) {
|
|
82
|
-
filterList.push(
|
|
83
|
-
collection.filter.byProperty('weight').greaterThanOrEqual(filters.weight_min)
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Weight filter (maximum)
|
|
88
|
-
if (filters?.weight_max !== undefined) {
|
|
89
|
-
filterList.push(
|
|
90
|
-
collection.filter.byProperty('weight').lessThanOrEqual(filters.weight_max)
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Trust filter (minimum) - applies to both
|
|
95
|
-
if (filters?.trust_min !== undefined) {
|
|
96
|
-
filterList.push(
|
|
97
|
-
collection.filter.byProperty('trust_score').greaterThanOrEqual(filters.trust_min)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Trust filter (maximum)
|
|
102
|
-
if (filters?.trust_max !== undefined) {
|
|
103
|
-
filterList.push(
|
|
104
|
-
collection.filter.byProperty('trust_score').lessThanOrEqual(filters.trust_max)
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Date range filter (from) - applies to both
|
|
109
|
-
if (filters?.date_from) {
|
|
110
|
-
filterList.push(
|
|
111
|
-
collection.filter.byProperty('created_at').greaterThanOrEqual(new Date(filters.date_from))
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Date range filter (to)
|
|
116
|
-
if (filters?.date_to) {
|
|
117
|
-
filterList.push(
|
|
118
|
-
collection.filter.byProperty('created_at').lessThanOrEqual(new Date(filters.date_to))
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Tags filter - applies to both
|
|
123
|
-
if (filters?.tags && filters.tags.length > 0) {
|
|
124
|
-
if (filters.tags.length === 1) {
|
|
125
|
-
filterList.push(
|
|
126
|
-
collection.filter.byProperty('tags').containsAny([filters.tags[0]])
|
|
127
|
-
);
|
|
128
|
-
} else {
|
|
129
|
-
filterList.push(
|
|
130
|
-
collection.filter.byProperty('tags').containsAny(filters.tags)
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Combine filters with AND
|
|
136
|
-
return combineFiltersWithAnd(filterList);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Build filters for memory-only search (backward compatibility)
|
|
141
|
-
*
|
|
142
|
-
* @param collection - Weaviate collection instance
|
|
143
|
-
* @param filters - Optional search filters
|
|
144
|
-
* @returns Combined filter or undefined if no filters
|
|
145
|
-
*/
|
|
146
|
-
export function buildMemoryOnlyFilters(
|
|
147
|
-
collection: any,
|
|
148
|
-
filters?: SearchFilters
|
|
149
|
-
): any {
|
|
150
|
-
return buildDocTypeFilters(collection, 'memory', filters);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Build filters specifically for relationship-only search
|
|
155
|
-
*
|
|
156
|
-
* @param collection - Weaviate collection instance
|
|
157
|
-
* @param filters - Optional search filters
|
|
158
|
-
* @returns Combined filter or undefined if no filters
|
|
159
|
-
*/
|
|
160
|
-
export function buildRelationshipOnlyFilters(
|
|
161
|
-
collection: any,
|
|
162
|
-
filters?: SearchFilters
|
|
163
|
-
): any {
|
|
164
|
-
return buildDocTypeFilters(collection, 'relationship', filters);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Combine multiple filters with AND logic
|
|
169
|
-
*
|
|
170
|
-
* @param filters - Array of filter objects
|
|
171
|
-
* @returns Combined filter or undefined
|
|
172
|
-
*/
|
|
173
|
-
export function combineFiltersWithAnd(filters: any[]): any {
|
|
174
|
-
// Filter out any undefined/null values
|
|
175
|
-
const validFilters = filters.filter(f => f !== undefined && f !== null);
|
|
176
|
-
|
|
177
|
-
if (validFilters.length === 0) {
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
|
-
if (validFilters.length === 1) {
|
|
181
|
-
return validFilters[0];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Weaviate v3 uses Filters.and() from weaviate-client package
|
|
185
|
-
return Filters.and(...validFilters);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Combine multiple filters with OR logic
|
|
190
|
-
*
|
|
191
|
-
* @param filters - Array of filter objects
|
|
192
|
-
* @returns Combined filter or undefined
|
|
193
|
-
*/
|
|
194
|
-
function combineFiltersWithOr(filters: any[]): any {
|
|
195
|
-
// Filter out any undefined/null values
|
|
196
|
-
const validFilters = filters.filter(f => f !== undefined && f !== null);
|
|
197
|
-
|
|
198
|
-
if (validFilters.length === 0) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
if (validFilters.length === 1) {
|
|
202
|
-
return validFilters[0];
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Weaviate v3 uses Filters.or() from weaviate-client package
|
|
206
|
-
return Filters.or(...validFilters);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Helper to check if a filter result is empty
|
|
211
|
-
*/
|
|
212
|
-
export function hasFilters(filter: any): boolean {
|
|
213
|
-
return filter !== undefined && filter !== null;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Build filter for deleted_at field based on deleted_filter parameter
|
|
218
|
-
*
|
|
219
|
-
* @param collection - Weaviate collection instance
|
|
220
|
-
* @param deletedFilter - Filter mode: 'exclude' (default), 'include', or 'only'
|
|
221
|
-
* @returns Filter for deleted_at field, or null if no filter needed
|
|
222
|
-
*/
|
|
223
|
-
export function buildDeletedFilter(
|
|
224
|
-
collection: any,
|
|
225
|
-
deletedFilter: DeletedFilter = 'exclude'
|
|
226
|
-
): any | null {
|
|
227
|
-
if (deletedFilter === 'exclude') {
|
|
228
|
-
// Exclude deleted: deleted_at is null or missing
|
|
229
|
-
return collection.filter.byProperty('deleted_at').isNull(true);
|
|
230
|
-
} else if (deletedFilter === 'only') {
|
|
231
|
-
// Only deleted: deleted_at is not null
|
|
232
|
-
return collection.filter.byProperty('deleted_at').isNull(false);
|
|
233
|
-
}
|
|
234
|
-
// 'include': no filter (show all)
|
|
235
|
-
return null;
|
|
236
|
-
}
|