@usewhisper/mcp-server 0.3.0 → 0.5.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.
Files changed (57) hide show
  1. package/README.md +182 -154
  2. package/dist/autosubscribe-6EDKPBE2.js +4068 -4068
  3. package/dist/autosubscribe-GHO6YR5A.js +4068 -4068
  4. package/dist/autosubscribe-ISDETQIB.js +435 -435
  5. package/dist/chunk-3WGYBAYR.js +8387 -8387
  6. package/dist/chunk-52VJYCZ7.js +455 -455
  7. package/dist/chunk-5KBZQHDL.js +189 -189
  8. package/dist/chunk-5KIJNY6Z.js +370 -370
  9. package/dist/chunk-7SN3CKDK.js +1076 -1076
  10. package/dist/chunk-B3VWOHUA.js +271 -271
  11. package/dist/chunk-C57DHKTL.js +459 -459
  12. package/dist/chunk-EI5CE3EY.js +616 -616
  13. package/dist/chunk-FTWUJBAH.js +386 -386
  14. package/dist/chunk-H3HSKH2P.js +4841 -4841
  15. package/dist/chunk-JO3ORBZD.js +616 -616
  16. package/dist/chunk-L6DXSM2U.js +456 -456
  17. package/dist/chunk-LMEYV4JD.js +368 -368
  18. package/dist/chunk-MEFLJ4PV.js +8385 -8385
  19. package/dist/chunk-OBLI4FE4.js +275 -275
  20. package/dist/chunk-PPGYJJED.js +271 -271
  21. package/dist/chunk-QGM4M3NI.js +37 -37
  22. package/dist/chunk-T7KMSTWP.js +399 -399
  23. package/dist/chunk-TWEIYHI6.js +399 -399
  24. package/dist/chunk-UYWE7HSU.js +368 -368
  25. package/dist/chunk-X2DL2GWT.js +32 -32
  26. package/dist/chunk-X7HNNNJJ.js +1079 -1079
  27. package/dist/consolidation-2GCKI4RE.js +220 -220
  28. package/dist/consolidation-4JOPW6BG.js +220 -220
  29. package/dist/consolidation-FOVQTWNQ.js +222 -222
  30. package/dist/consolidation-IFQ52E44.js +209 -209
  31. package/dist/context-sharing-4ITCNKG4.js +307 -307
  32. package/dist/context-sharing-6CCFIAKL.js +275 -275
  33. package/dist/context-sharing-GYKLXHZA.js +307 -307
  34. package/dist/context-sharing-PH64JTXS.js +308 -308
  35. package/dist/context-sharing-Y6LTZZOF.js +307 -307
  36. package/dist/cost-optimization-6OIKRSBV.js +195 -195
  37. package/dist/cost-optimization-7DVSTL6R.js +307 -307
  38. package/dist/cost-optimization-BH5NAX33.js +286 -286
  39. package/dist/cost-optimization-F3L5BS5F.js +303 -303
  40. package/dist/ingest-2LPTWUUM.js +16 -16
  41. package/dist/ingest-7T5FAZNC.js +15 -15
  42. package/dist/ingest-EBNIE7XB.js +15 -15
  43. package/dist/ingest-FSHT5BCS.js +15 -15
  44. package/dist/ingest-QE2BTV72.js +14 -14
  45. package/dist/oracle-3RLQF3DP.js +259 -259
  46. package/dist/oracle-FKRTQUUG.js +282 -282
  47. package/dist/oracle-J47QCSEW.js +263 -263
  48. package/dist/oracle-MDP5MZRC.js +256 -256
  49. package/dist/search-BLVHWLWC.js +14 -14
  50. package/dist/search-CZ5NYL5B.js +12 -12
  51. package/dist/search-EG6TYWWW.js +13 -13
  52. package/dist/search-I22QQA7T.js +13 -13
  53. package/dist/search-T7H5G6DW.js +13 -13
  54. package/dist/server.d.ts +2 -2
  55. package/dist/server.js +1973 -169
  56. package/dist/server.js.map +1 -1
  57. package/package.json +51 -51
@@ -1,271 +1,271 @@
1
- import {
2
- buildRelationGraph,
3
- calculateTemporalRelevance,
4
- parseTemporalQuery
5
- } from "./chunk-5KIJNY6Z.js";
6
- import {
7
- db,
8
- embedSingle
9
- } from "./chunk-3WGYBAYR.js";
10
-
11
- // ../src/engine/memory/search.ts
12
- async function searchMemories(params) {
13
- const {
14
- query,
15
- questionDate,
16
- userId,
17
- projectId,
18
- orgId,
19
- sessionId,
20
- topK = 10,
21
- includeInactive = false,
22
- memoryTypes
23
- } = params;
24
- const temporal = params.temporalFilter || await parseTemporalQuery(query, questionDate);
25
- const queryEmbedding = await embedSingle(query);
26
- const semanticResults = await vectorSearchMemories({
27
- embedding: queryEmbedding,
28
- userId,
29
- projectId,
30
- orgId,
31
- sessionId,
32
- temporal,
33
- includeInactive,
34
- memoryTypes,
35
- limit: topK * 3
36
- // Get more for reranking
37
- });
38
- if (semanticResults.length === 0) {
39
- return [];
40
- }
41
- const enriched = await enrichWithRelations(semanticResults, topK * 2);
42
- const scored = enriched.map((memory) => ({
43
- ...memory,
44
- temporalScore: memory.documentDate ? calculateTemporalRelevance(memory.documentDate, questionDate) : 0.5
45
- }));
46
- const combined = scored.map((m) => ({
47
- ...m,
48
- finalScore: m.similarity * 0.7 + m.temporalScore * 0.3
49
- }));
50
- combined.sort((a, b) => b.finalScore - a.finalScore);
51
- const topMemories = combined.slice(0, topK);
52
- const results = await injectSourceChunks(topMemories);
53
- return results;
54
- }
55
- async function vectorSearchMemories(params) {
56
- const {
57
- embedding,
58
- userId,
59
- projectId,
60
- orgId,
61
- sessionId,
62
- temporal,
63
- includeInactive,
64
- memoryTypes,
65
- limit
66
- } = params;
67
- const whereConditions = [
68
- { projectId }
69
- ];
70
- if (orgId) {
71
- whereConditions.push({ orgId });
72
- }
73
- if (userId) {
74
- whereConditions.push({ userId });
75
- }
76
- if (sessionId) {
77
- whereConditions.push({ sessionId });
78
- }
79
- if (!includeInactive) {
80
- whereConditions.push({ isActive: true });
81
- }
82
- whereConditions.push({
83
- OR: [
84
- { validUntil: null },
85
- { validUntil: { gt: /* @__PURE__ */ new Date() } }
86
- ]
87
- });
88
- if (memoryTypes && memoryTypes.length > 0) {
89
- whereConditions.push({
90
- memoryType: { in: memoryTypes }
91
- });
92
- }
93
- if (temporal.hasTemporalConstraint && temporal.dateRange) {
94
- whereConditions.push({
95
- documentDate: {
96
- gte: temporal.dateRange.start,
97
- lte: temporal.dateRange.end
98
- }
99
- });
100
- }
101
- const embeddingStr = `[${embedding.join(",")}]`;
102
- const results = await db.$queryRaw`
103
- SELECT
104
- id,
105
- content,
106
- "memoryType",
107
- "entityMentions",
108
- confidence,
109
- version,
110
- "documentDate",
111
- "eventDate",
112
- "validFrom",
113
- "validUntil",
114
- "sourceChunkId",
115
- metadata,
116
- 1 - (embedding <=> ${embeddingStr}::vector) as similarity
117
- FROM memories
118
- WHERE
119
- "projectId" = ${projectId}
120
- ${orgId ? db.$queryRaw`AND "orgId" = ${orgId}` : db.$queryRaw``}
121
- ${userId ? db.$queryRaw`AND "userId" = ${userId}` : db.$queryRaw``}
122
- ${sessionId ? db.$queryRaw`AND "sessionId" = ${sessionId}` : db.$queryRaw``}
123
- ${!includeInactive ? db.$queryRaw`AND "isActive" = true` : db.$queryRaw``}
124
- AND ("validUntil" IS NULL OR "validUntil" > NOW())
125
- ${memoryTypes && memoryTypes.length > 0 ? db.$queryRaw`AND "memoryType" = ANY(${memoryTypes})` : db.$queryRaw``}
126
- ${temporal.hasTemporalConstraint && temporal.dateRange ? db.$queryRaw`AND "documentDate" >= ${temporal.dateRange.start} AND "documentDate" <= ${temporal.dateRange.end}` : db.$queryRaw``}
127
- ORDER BY similarity DESC
128
- LIMIT ${limit}
129
- `;
130
- return results;
131
- }
132
- async function enrichWithRelations(memories, maxTotal) {
133
- if (memories.length === 0) {
134
- return [];
135
- }
136
- const memoryIds = memories.map((m) => m.id);
137
- const relations = await db.memoryRelation.findMany({
138
- where: {
139
- OR: [
140
- { fromMemoryId: { in: memoryIds } },
141
- { toMemoryId: { in: memoryIds } }
142
- ]
143
- }
144
- });
145
- if (relations.length === 0) {
146
- return memories;
147
- }
148
- const graph = buildRelationGraph(relations);
149
- const relatedIds = /* @__PURE__ */ new Set();
150
- for (const memory of memories) {
151
- const neighbors = graph.get(memory.id) || [];
152
- for (const neighbor of neighbors.slice(0, 3)) {
153
- relatedIds.add(neighbor.memoryId);
154
- }
155
- }
156
- memoryIds.forEach((id) => relatedIds.delete(id));
157
- if (relatedIds.size === 0) {
158
- return memories;
159
- }
160
- const related = await db.memory.findMany({
161
- where: {
162
- id: { in: Array.from(relatedIds) },
163
- isActive: true
164
- },
165
- take: maxTotal - memories.length
166
- });
167
- const relatedWithScores = related.map((m) => ({
168
- ...m,
169
- similarity: 0.6,
170
- // Lower score for related but not directly matched
171
- isRelated: true
172
- }));
173
- return [...memories, ...relatedWithScores];
174
- }
175
- async function injectSourceChunks(memories) {
176
- const chunkIds = memories.map((m) => m.sourceChunkId).filter((id) => id !== null);
177
- if (chunkIds.length === 0) {
178
- return memories.map((m) => ({
179
- memory: {
180
- id: m.id,
181
- content: m.content,
182
- memoryType: m.memoryType,
183
- entityMentions: m.entityMentions || [],
184
- confidence: m.confidence,
185
- version: m.version,
186
- temporal: {
187
- documentDate: m.documentDate,
188
- eventDate: m.eventDate,
189
- validFrom: m.validFrom,
190
- validUntil: m.validUntil
191
- }
192
- },
193
- similarity: m.similarity
194
- }));
195
- }
196
- const chunks = await db.chunk.findMany({
197
- where: {
198
- id: { in: chunkIds }
199
- },
200
- select: {
201
- id: true,
202
- content: true,
203
- metadata: true
204
- }
205
- });
206
- const chunkMap = new Map(chunks.map((c) => [c.id, c]));
207
- return memories.map((m) => ({
208
- memory: {
209
- id: m.id,
210
- content: m.content,
211
- memoryType: m.memoryType,
212
- entityMentions: m.entityMentions || [],
213
- confidence: m.confidence,
214
- version: m.version,
215
- temporal: {
216
- documentDate: m.documentDate,
217
- eventDate: m.eventDate,
218
- validFrom: m.validFrom,
219
- validUntil: m.validUntil
220
- }
221
- },
222
- chunk: m.sourceChunkId && chunkMap.has(m.sourceChunkId) ? {
223
- id: chunkMap.get(m.sourceChunkId).id,
224
- content: chunkMap.get(m.sourceChunkId).content,
225
- metadata: chunkMap.get(m.sourceChunkId).metadata
226
- } : void 0,
227
- similarity: m.similarity,
228
- relations: m.isRelated ? [] : void 0
229
- }));
230
- }
231
- async function getSessionMemories(params) {
232
- const { sessionId, projectId, limit = 50, sinceDate } = params;
233
- const where = {
234
- sessionId,
235
- projectId,
236
- isActive: true
237
- };
238
- if (sinceDate) {
239
- where.createdAt = { gte: sinceDate };
240
- }
241
- return db.memory.findMany({
242
- where,
243
- orderBy: {
244
- createdAt: "desc"
245
- },
246
- take: limit
247
- });
248
- }
249
- async function getUserProfile(params) {
250
- const { userId, projectId, memoryTypes, limit = 50 } = params;
251
- const where = {
252
- userId,
253
- projectId,
254
- isActive: true,
255
- scope: "USER"
256
- };
257
- if (memoryTypes) {
258
- where.memoryType = { in: memoryTypes };
259
- }
260
- return db.memory.findMany({
261
- where,
262
- orderBy: { importance: "desc" },
263
- take: Math.min(limit, 100)
264
- });
265
- }
266
-
267
- export {
268
- searchMemories,
269
- getSessionMemories,
270
- getUserProfile
271
- };
1
+ import {
2
+ buildRelationGraph,
3
+ calculateTemporalRelevance,
4
+ parseTemporalQuery
5
+ } from "./chunk-5KIJNY6Z.js";
6
+ import {
7
+ db,
8
+ embedSingle
9
+ } from "./chunk-3WGYBAYR.js";
10
+
11
+ // ../src/engine/memory/search.ts
12
+ async function searchMemories(params) {
13
+ const {
14
+ query,
15
+ questionDate,
16
+ userId,
17
+ projectId,
18
+ orgId,
19
+ sessionId,
20
+ topK = 10,
21
+ includeInactive = false,
22
+ memoryTypes
23
+ } = params;
24
+ const temporal = params.temporalFilter || await parseTemporalQuery(query, questionDate);
25
+ const queryEmbedding = await embedSingle(query);
26
+ const semanticResults = await vectorSearchMemories({
27
+ embedding: queryEmbedding,
28
+ userId,
29
+ projectId,
30
+ orgId,
31
+ sessionId,
32
+ temporal,
33
+ includeInactive,
34
+ memoryTypes,
35
+ limit: topK * 3
36
+ // Get more for reranking
37
+ });
38
+ if (semanticResults.length === 0) {
39
+ return [];
40
+ }
41
+ const enriched = await enrichWithRelations(semanticResults, topK * 2);
42
+ const scored = enriched.map((memory) => ({
43
+ ...memory,
44
+ temporalScore: memory.documentDate ? calculateTemporalRelevance(memory.documentDate, questionDate) : 0.5
45
+ }));
46
+ const combined = scored.map((m) => ({
47
+ ...m,
48
+ finalScore: m.similarity * 0.7 + m.temporalScore * 0.3
49
+ }));
50
+ combined.sort((a, b) => b.finalScore - a.finalScore);
51
+ const topMemories = combined.slice(0, topK);
52
+ const results = await injectSourceChunks(topMemories);
53
+ return results;
54
+ }
55
+ async function vectorSearchMemories(params) {
56
+ const {
57
+ embedding,
58
+ userId,
59
+ projectId,
60
+ orgId,
61
+ sessionId,
62
+ temporal,
63
+ includeInactive,
64
+ memoryTypes,
65
+ limit
66
+ } = params;
67
+ const whereConditions = [
68
+ { projectId }
69
+ ];
70
+ if (orgId) {
71
+ whereConditions.push({ orgId });
72
+ }
73
+ if (userId) {
74
+ whereConditions.push({ userId });
75
+ }
76
+ if (sessionId) {
77
+ whereConditions.push({ sessionId });
78
+ }
79
+ if (!includeInactive) {
80
+ whereConditions.push({ isActive: true });
81
+ }
82
+ whereConditions.push({
83
+ OR: [
84
+ { validUntil: null },
85
+ { validUntil: { gt: /* @__PURE__ */ new Date() } }
86
+ ]
87
+ });
88
+ if (memoryTypes && memoryTypes.length > 0) {
89
+ whereConditions.push({
90
+ memoryType: { in: memoryTypes }
91
+ });
92
+ }
93
+ if (temporal.hasTemporalConstraint && temporal.dateRange) {
94
+ whereConditions.push({
95
+ documentDate: {
96
+ gte: temporal.dateRange.start,
97
+ lte: temporal.dateRange.end
98
+ }
99
+ });
100
+ }
101
+ const embeddingStr = `[${embedding.join(",")}]`;
102
+ const results = await db.$queryRaw`
103
+ SELECT
104
+ id,
105
+ content,
106
+ "memoryType",
107
+ "entityMentions",
108
+ confidence,
109
+ version,
110
+ "documentDate",
111
+ "eventDate",
112
+ "validFrom",
113
+ "validUntil",
114
+ "sourceChunkId",
115
+ metadata,
116
+ 1 - (embedding <=> ${embeddingStr}::vector) as similarity
117
+ FROM memories
118
+ WHERE
119
+ "projectId" = ${projectId}
120
+ ${orgId ? db.$queryRaw`AND "orgId" = ${orgId}` : db.$queryRaw``}
121
+ ${userId ? db.$queryRaw`AND "userId" = ${userId}` : db.$queryRaw``}
122
+ ${sessionId ? db.$queryRaw`AND "sessionId" = ${sessionId}` : db.$queryRaw``}
123
+ ${!includeInactive ? db.$queryRaw`AND "isActive" = true` : db.$queryRaw``}
124
+ AND ("validUntil" IS NULL OR "validUntil" > NOW())
125
+ ${memoryTypes && memoryTypes.length > 0 ? db.$queryRaw`AND "memoryType" = ANY(${memoryTypes})` : db.$queryRaw``}
126
+ ${temporal.hasTemporalConstraint && temporal.dateRange ? db.$queryRaw`AND "documentDate" >= ${temporal.dateRange.start} AND "documentDate" <= ${temporal.dateRange.end}` : db.$queryRaw``}
127
+ ORDER BY similarity DESC
128
+ LIMIT ${limit}
129
+ `;
130
+ return results;
131
+ }
132
+ async function enrichWithRelations(memories, maxTotal) {
133
+ if (memories.length === 0) {
134
+ return [];
135
+ }
136
+ const memoryIds = memories.map((m) => m.id);
137
+ const relations = await db.memoryRelation.findMany({
138
+ where: {
139
+ OR: [
140
+ { fromMemoryId: { in: memoryIds } },
141
+ { toMemoryId: { in: memoryIds } }
142
+ ]
143
+ }
144
+ });
145
+ if (relations.length === 0) {
146
+ return memories;
147
+ }
148
+ const graph = buildRelationGraph(relations);
149
+ const relatedIds = /* @__PURE__ */ new Set();
150
+ for (const memory of memories) {
151
+ const neighbors = graph.get(memory.id) || [];
152
+ for (const neighbor of neighbors.slice(0, 3)) {
153
+ relatedIds.add(neighbor.memoryId);
154
+ }
155
+ }
156
+ memoryIds.forEach((id) => relatedIds.delete(id));
157
+ if (relatedIds.size === 0) {
158
+ return memories;
159
+ }
160
+ const related = await db.memory.findMany({
161
+ where: {
162
+ id: { in: Array.from(relatedIds) },
163
+ isActive: true
164
+ },
165
+ take: maxTotal - memories.length
166
+ });
167
+ const relatedWithScores = related.map((m) => ({
168
+ ...m,
169
+ similarity: 0.6,
170
+ // Lower score for related but not directly matched
171
+ isRelated: true
172
+ }));
173
+ return [...memories, ...relatedWithScores];
174
+ }
175
+ async function injectSourceChunks(memories) {
176
+ const chunkIds = memories.map((m) => m.sourceChunkId).filter((id) => id !== null);
177
+ if (chunkIds.length === 0) {
178
+ return memories.map((m) => ({
179
+ memory: {
180
+ id: m.id,
181
+ content: m.content,
182
+ memoryType: m.memoryType,
183
+ entityMentions: m.entityMentions || [],
184
+ confidence: m.confidence,
185
+ version: m.version,
186
+ temporal: {
187
+ documentDate: m.documentDate,
188
+ eventDate: m.eventDate,
189
+ validFrom: m.validFrom,
190
+ validUntil: m.validUntil
191
+ }
192
+ },
193
+ similarity: m.similarity
194
+ }));
195
+ }
196
+ const chunks = await db.chunk.findMany({
197
+ where: {
198
+ id: { in: chunkIds }
199
+ },
200
+ select: {
201
+ id: true,
202
+ content: true,
203
+ metadata: true
204
+ }
205
+ });
206
+ const chunkMap = new Map(chunks.map((c) => [c.id, c]));
207
+ return memories.map((m) => ({
208
+ memory: {
209
+ id: m.id,
210
+ content: m.content,
211
+ memoryType: m.memoryType,
212
+ entityMentions: m.entityMentions || [],
213
+ confidence: m.confidence,
214
+ version: m.version,
215
+ temporal: {
216
+ documentDate: m.documentDate,
217
+ eventDate: m.eventDate,
218
+ validFrom: m.validFrom,
219
+ validUntil: m.validUntil
220
+ }
221
+ },
222
+ chunk: m.sourceChunkId && chunkMap.has(m.sourceChunkId) ? {
223
+ id: chunkMap.get(m.sourceChunkId).id,
224
+ content: chunkMap.get(m.sourceChunkId).content,
225
+ metadata: chunkMap.get(m.sourceChunkId).metadata
226
+ } : void 0,
227
+ similarity: m.similarity,
228
+ relations: m.isRelated ? [] : void 0
229
+ }));
230
+ }
231
+ async function getSessionMemories(params) {
232
+ const { sessionId, projectId, limit = 50, sinceDate } = params;
233
+ const where = {
234
+ sessionId,
235
+ projectId,
236
+ isActive: true
237
+ };
238
+ if (sinceDate) {
239
+ where.createdAt = { gte: sinceDate };
240
+ }
241
+ return db.memory.findMany({
242
+ where,
243
+ orderBy: {
244
+ createdAt: "desc"
245
+ },
246
+ take: limit
247
+ });
248
+ }
249
+ async function getUserProfile(params) {
250
+ const { userId, projectId, memoryTypes, limit = 50 } = params;
251
+ const where = {
252
+ userId,
253
+ projectId,
254
+ isActive: true,
255
+ scope: "USER"
256
+ };
257
+ if (memoryTypes) {
258
+ where.memoryType = { in: memoryTypes };
259
+ }
260
+ return db.memory.findMany({
261
+ where,
262
+ orderBy: { importance: "desc" },
263
+ take: Math.min(limit, 100)
264
+ });
265
+ }
266
+
267
+ export {
268
+ searchMemories,
269
+ getSessionMemories,
270
+ getUserProfile
271
+ };