@usewhisper/mcp-server 0.1.0 → 0.3.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 (70) hide show
  1. package/README.md +26 -24
  2. package/dist/autosubscribe-6EDKPBE2.js +4068 -0
  3. package/dist/autosubscribe-GHO6YR5A.js +4068 -0
  4. package/dist/autosubscribe-ISDETQIB.js +436 -0
  5. package/dist/autosubscribe-ISDETQIB.js.map +1 -0
  6. package/dist/chunk-3WGYBAYR.js +8387 -0
  7. package/dist/chunk-52VJYCZ7.js +455 -0
  8. package/dist/chunk-5KBZQHDL.js +189 -0
  9. package/dist/chunk-5KIJNY6Z.js +370 -0
  10. package/dist/chunk-7SN3CKDK.js +1076 -0
  11. package/dist/chunk-B3VWOHUA.js +271 -0
  12. package/dist/chunk-C57DHKTL.js +459 -0
  13. package/dist/chunk-EI5CE3EY.js +616 -0
  14. package/dist/chunk-FTWUJBAH.js +387 -0
  15. package/dist/chunk-FTWUJBAH.js.map +1 -0
  16. package/dist/chunk-H3HSKH2P.js +4841 -0
  17. package/dist/chunk-JO3ORBZD.js +616 -0
  18. package/dist/chunk-L6DXSM2U.js +457 -0
  19. package/dist/chunk-L6DXSM2U.js.map +1 -0
  20. package/dist/chunk-LMEYV4JD.js +368 -0
  21. package/dist/chunk-MEFLJ4PV.js +8385 -0
  22. package/dist/chunk-OBLI4FE4.js +276 -0
  23. package/dist/chunk-OBLI4FE4.js.map +1 -0
  24. package/dist/chunk-PPGYJJED.js +271 -0
  25. package/dist/chunk-QGM4M3NI.js +37 -0
  26. package/dist/chunk-T7KMSTWP.js +399 -0
  27. package/dist/chunk-TWEIYHI6.js +399 -0
  28. package/dist/chunk-UYWE7HSU.js +369 -0
  29. package/dist/chunk-UYWE7HSU.js.map +1 -0
  30. package/dist/chunk-X2DL2GWT.js +33 -0
  31. package/dist/chunk-X2DL2GWT.js.map +1 -0
  32. package/dist/chunk-X7HNNNJJ.js +1079 -0
  33. package/dist/consolidation-2GCKI4RE.js +220 -0
  34. package/dist/consolidation-4JOPW6BG.js +220 -0
  35. package/dist/consolidation-FOVQTWNQ.js +222 -0
  36. package/dist/consolidation-IFQ52E44.js +210 -0
  37. package/dist/consolidation-IFQ52E44.js.map +1 -0
  38. package/dist/context-sharing-4ITCNKG4.js +307 -0
  39. package/dist/context-sharing-6CCFIAKL.js +276 -0
  40. package/dist/context-sharing-6CCFIAKL.js.map +1 -0
  41. package/dist/context-sharing-GYKLXHZA.js +307 -0
  42. package/dist/context-sharing-PH64JTXS.js +308 -0
  43. package/dist/context-sharing-Y6LTZZOF.js +307 -0
  44. package/dist/cost-optimization-6OIKRSBV.js +196 -0
  45. package/dist/cost-optimization-6OIKRSBV.js.map +1 -0
  46. package/dist/cost-optimization-7DVSTL6R.js +307 -0
  47. package/dist/cost-optimization-BH5NAX33.js +287 -0
  48. package/dist/cost-optimization-BH5NAX33.js.map +1 -0
  49. package/dist/cost-optimization-F3L5BS5F.js +303 -0
  50. package/dist/ingest-2LPTWUUM.js +16 -0
  51. package/dist/ingest-7T5FAZNC.js +15 -0
  52. package/dist/ingest-EBNIE7XB.js +15 -0
  53. package/dist/ingest-FSHT5BCS.js +15 -0
  54. package/dist/ingest-QE2BTV72.js +15 -0
  55. package/dist/ingest-QE2BTV72.js.map +1 -0
  56. package/dist/oracle-3RLQF3DP.js +259 -0
  57. package/dist/oracle-FKRTQUUG.js +282 -0
  58. package/dist/oracle-J47QCSEW.js +263 -0
  59. package/dist/oracle-MDP5MZRC.js +257 -0
  60. package/dist/oracle-MDP5MZRC.js.map +1 -0
  61. package/dist/search-BLVHWLWC.js +14 -0
  62. package/dist/search-CZ5NYL5B.js +13 -0
  63. package/dist/search-CZ5NYL5B.js.map +1 -0
  64. package/dist/search-EG6TYWWW.js +13 -0
  65. package/dist/search-I22QQA7T.js +13 -0
  66. package/dist/search-T7H5G6DW.js +13 -0
  67. package/dist/server.d.ts +2 -0
  68. package/dist/server.js +914 -1503
  69. package/dist/server.js.map +1 -1
  70. package/package.json +6 -7
@@ -0,0 +1,370 @@
1
+ import {
2
+ Anthropic
3
+ } from "./chunk-H3HSKH2P.js";
4
+
5
+ // ../src/engine/memory/temporal.ts
6
+ var anthropic = new Anthropic({
7
+ apiKey: process.env.ANTHROPIC_API_KEY || ""
8
+ });
9
+ var TEMPORAL_PARSING_PROMPT = `You are an expert temporal query parser. Extract temporal constraints from user queries.
10
+
11
+ **Your job:**
12
+ 1. Identify if the query has temporal constraints
13
+ 2. Extract relative time references (today, yesterday, last week, etc.)
14
+ 3. Extract absolute dates if mentioned
15
+ 4. Calculate date ranges if applicable
16
+
17
+ **Relative Terms:**
18
+ - "today" \u2192 filter to documentDate = questionDate
19
+ - "yesterday" \u2192 documentDate = questionDate - 1 day
20
+ - "last week" \u2192 documentDate in range [questionDate - 7 days, questionDate]
21
+ - "last month" \u2192 documentDate in range [questionDate - 30 days, questionDate]
22
+ - "last year" \u2192 documentDate in range [questionDate - 365 days, questionDate]
23
+ - "this week" \u2192 current week
24
+ - "this month" \u2192 current month
25
+
26
+ **Examples:**
27
+ - "What did I say about vacation yesterday?" \u2192 relative: "yesterday"
28
+ - "Tell me about meetings last week" \u2192 relative: "last_week"
29
+ - "What happened on January 15?" \u2192 absoluteDate: "2024-01-15"
30
+ - "Show me everything from last month" \u2192 relative: "last_month"
31
+ - "What's my favorite color?" \u2192 no temporal constraint`;
32
+ async function parseTemporalQuery(query, questionDate) {
33
+ const prompt = `${TEMPORAL_PARSING_PROMPT}
34
+
35
+ **Query:** "${query}"
36
+ **Question asked on:** ${questionDate.toISOString()}
37
+
38
+ Extract temporal information and return JSON:
39
+ {
40
+ "hasTemporalConstraint": boolean,
41
+ "relative": "today|yesterday|last_week|last_month|last_year|this_week|this_month|null",
42
+ "absoluteDate": "ISO date string or null",
43
+ "dateRange": { "start": "ISO", "end": "ISO" } or null
44
+ }
45
+
46
+ Return ONLY the JSON, no other text.`;
47
+ try {
48
+ const response = await anthropic.messages.create({
49
+ model: "claude-haiku-4.5",
50
+ // Faster model for parsing
51
+ max_tokens: 512,
52
+ temperature: 0,
53
+ messages: [{ role: "user", content: prompt }]
54
+ });
55
+ const textContent = response.content.find((c) => c.type === "text");
56
+ if (!textContent || textContent.type !== "text") {
57
+ return { hasTemporalConstraint: false };
58
+ }
59
+ const text = textContent.text.trim();
60
+ const jsonMatch = text.match(/```json\n?([\s\S]*?)\n?```/) || text.match(/\{[\s\S]*\}/);
61
+ const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text;
62
+ const parsed = JSON.parse(jsonStr);
63
+ if (parsed.relative) {
64
+ const range = calculateRelativeDateRange(parsed.relative, questionDate);
65
+ parsed.dateRange = range;
66
+ parsed.absoluteDate = range.start;
67
+ } else if (parsed.absoluteDate) {
68
+ parsed.absoluteDate = new Date(parsed.absoluteDate);
69
+ }
70
+ if (parsed.dateRange) {
71
+ parsed.dateRange = {
72
+ start: new Date(parsed.dateRange.start),
73
+ end: new Date(parsed.dateRange.end)
74
+ };
75
+ }
76
+ return parsed;
77
+ } catch (error) {
78
+ console.error("Temporal parsing failed:", error);
79
+ return { hasTemporalConstraint: false };
80
+ }
81
+ }
82
+ function calculateRelativeDateRange(relative, from) {
83
+ const start = new Date(from);
84
+ const end = new Date(from);
85
+ switch (relative) {
86
+ case "today":
87
+ start.setHours(0, 0, 0, 0);
88
+ end.setHours(23, 59, 59, 999);
89
+ break;
90
+ case "yesterday":
91
+ start.setDate(start.getDate() - 1);
92
+ start.setHours(0, 0, 0, 0);
93
+ end.setDate(end.getDate() - 1);
94
+ end.setHours(23, 59, 59, 999);
95
+ break;
96
+ case "last_week":
97
+ start.setDate(start.getDate() - 7);
98
+ start.setHours(0, 0, 0, 0);
99
+ end.setHours(23, 59, 59, 999);
100
+ break;
101
+ case "this_week":
102
+ const dayOfWeek = start.getDay();
103
+ const diff = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
104
+ start.setDate(start.getDate() + diff);
105
+ start.setHours(0, 0, 0, 0);
106
+ end.setHours(23, 59, 59, 999);
107
+ break;
108
+ case "last_month":
109
+ start.setDate(start.getDate() - 30);
110
+ start.setHours(0, 0, 0, 0);
111
+ end.setHours(23, 59, 59, 999);
112
+ break;
113
+ case "this_month":
114
+ start.setDate(1);
115
+ start.setHours(0, 0, 0, 0);
116
+ end.setHours(23, 59, 59, 999);
117
+ break;
118
+ case "last_year":
119
+ start.setFullYear(start.getFullYear() - 1);
120
+ start.setHours(0, 0, 0, 0);
121
+ end.setHours(23, 59, 59, 999);
122
+ break;
123
+ default:
124
+ start.setFullYear(1970);
125
+ end.setFullYear(2100);
126
+ }
127
+ return { start, end };
128
+ }
129
+ async function extractEventDate(memoryContent, documentDate) {
130
+ const prompt = `Extract the event date from this memory.
131
+
132
+ **Important distinction:**
133
+ - documentDate: When this was said/written
134
+ - eventDate: When the event actually occurred/will occur
135
+
136
+ **Memory:** "${memoryContent}"
137
+ **Document Date (when this was said):** ${documentDate.toISOString()}
138
+
139
+ **Examples:**
140
+ - "User said they have a meeting tomorrow" \u2192 eventDate = documentDate + 1 day
141
+ - "User attended conference on Jan 15" \u2192 eventDate = Jan 15 of appropriate year
142
+ - "User's favorite color is blue" \u2192 eventDate = null (no event, just a fact)
143
+ - "Meeting happened yesterday" \u2192 eventDate = documentDate - 1 day
144
+
145
+ Return JSON:
146
+ {
147
+ "hasEvent": boolean,
148
+ "eventDate": "ISO date string or null",
149
+ "reasoning": "brief explanation"
150
+ }`;
151
+ try {
152
+ const response = await anthropic.messages.create({
153
+ model: "claude-haiku-4.5",
154
+ max_tokens: 256,
155
+ temperature: 0,
156
+ messages: [{ role: "user", content: prompt }]
157
+ });
158
+ const textContent = response.content.find((c) => c.type === "text");
159
+ if (!textContent || textContent.type !== "text") {
160
+ return null;
161
+ }
162
+ const text = textContent.text.trim();
163
+ const jsonMatch = text.match(/```json\n?([\s\S]*?)\n?```/) || text.match(/\{[\s\S]*\}/);
164
+ const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text;
165
+ const result = JSON.parse(jsonStr);
166
+ if (result.hasEvent && result.eventDate) {
167
+ return new Date(result.eventDate);
168
+ }
169
+ return null;
170
+ } catch (error) {
171
+ console.error("Event date extraction failed:", error);
172
+ return null;
173
+ }
174
+ }
175
+ function calculateTemporalRelevance(memoryDate, questionDate, decayFactor = 0.1) {
176
+ const daysDiff = Math.abs(
177
+ (questionDate.getTime() - memoryDate.getTime()) / (1e3 * 60 * 60 * 24)
178
+ );
179
+ const score = Math.exp(-decayFactor * daysDiff);
180
+ return score;
181
+ }
182
+
183
+ // ../src/engine/memory/relations.ts
184
+ var anthropic2 = new Anthropic({
185
+ apiKey: process.env.ANTHROPIC_API_KEY || ""
186
+ });
187
+ var RELATION_DETECTION_PROMPT = `You are an expert at detecting relationships between memories in a knowledge graph.
188
+
189
+ **Relation Types:**
190
+
191
+ 1. **updates** - New memory supersedes/replaces old memory (state mutation)
192
+ Example:
193
+ - Old: "User's favorite color is blue"
194
+ - New: "User's favorite color is green"
195
+ - Relation: updates (green replaces blue)
196
+
197
+ 2. **extends** - New memory adds detail to existing memory without contradiction (refinement)
198
+ Example:
199
+ - Old: "John works at Google"
200
+ - New: "John works at Google as a Senior Engineer"
201
+ - Relation: extends (adds job title)
202
+
203
+ 3. **derives** - New memory is inferred from existing memory/memories (inference)
204
+ Example:
205
+ - Memory 1: "User prefers dark mode"
206
+ - Memory 2: "User prefers high contrast"
207
+ - New: "User likely has vision preferences for accessibility"
208
+ - Relation: derives (inferred from both)
209
+
210
+ 4. **contradicts** - New memory conflicts with existing memory (conflict detection)
211
+ Example:
212
+ - Old: "Meeting scheduled for 3pm"
213
+ - New: "Meeting scheduled for 4pm"
214
+ - Relation: contradicts (should trigger update)
215
+
216
+ 5. **supports** - New memory provides evidence/support for existing memory
217
+ Example:
218
+ - Memory 1: "User is interested in ML"
219
+ - New: "User enrolled in ML course"
220
+ - Relation: supports (confirms interest)
221
+
222
+ **Important:**
223
+ - Only detect relations when there's a clear, meaningful connection
224
+ - Be conservative - if unsure, don't create a relation
225
+ - "updates" should invalidate the old memory (set validUntil)
226
+ - "extends" keeps the old memory valid but adds information
227
+ - "contradicts" should flag for review/resolution`;
228
+ async function detectRelations(newMemory, existingMemories) {
229
+ if (existingMemories.length === 0) {
230
+ return [];
231
+ }
232
+ const relevantMemories = filterRelevantMemories(newMemory, existingMemories);
233
+ if (relevantMemories.length === 0) {
234
+ return [];
235
+ }
236
+ const prompt = `${RELATION_DETECTION_PROMPT}
237
+
238
+ **New memory:**
239
+ "${newMemory.content}"
240
+ Type: ${newMemory.memoryType}
241
+ Entities: ${newMemory.entityMentions.join(", ")}
242
+
243
+ **Existing memories to check against:**
244
+ ${relevantMemories.map((m, i) => `${i}. "${m.content}" (Type: ${m.memoryType}, Date: ${m.documentDate?.toISOString() || "unknown"})`).join("\n")}
245
+
246
+ Analyze if the new memory relates to any existing memories.
247
+
248
+ Return a JSON array of relations:
249
+ [{
250
+ "toMemoryIndex": 0,
251
+ "relationType": "updates|extends|derives|contradicts|supports",
252
+ "confidence": 0.0-1.0,
253
+ "reasoning": "brief explanation why this relation exists"
254
+ }]
255
+
256
+ Return ONLY the JSON array. If no relations found, return [].`;
257
+ try {
258
+ const response = await anthropic2.messages.create({
259
+ model: "claude-sonnet-4.5",
260
+ max_tokens: 2048,
261
+ temperature: 0,
262
+ messages: [{ role: "user", content: prompt }]
263
+ });
264
+ const textContent = response.content.find((c) => c.type === "text");
265
+ if (!textContent || textContent.type !== "text") {
266
+ return [];
267
+ }
268
+ const text = textContent.text.trim();
269
+ const jsonMatch = text.match(/```json\n?([\s\S]*?)\n?```/) || text.match(/\[[\s\S]*\]/);
270
+ const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text;
271
+ const relations = JSON.parse(jsonStr);
272
+ if (!Array.isArray(relations)) {
273
+ return [];
274
+ }
275
+ return relations.filter((r) => r.confidence >= 0.7).map((r) => ({
276
+ toMemoryId: relevantMemories[r.toMemoryIndex].id,
277
+ relationType: r.relationType,
278
+ confidence: r.confidence,
279
+ reasoning: r.reasoning
280
+ }));
281
+ } catch (error) {
282
+ console.error("Relation detection failed:", error);
283
+ return [];
284
+ }
285
+ }
286
+ function filterRelevantMemories(newMemory, existingMemories) {
287
+ return existingMemories.filter((existing) => {
288
+ const sharedEntities = newMemory.entityMentions.some(
289
+ (entity) => existing.entityMentions.includes(entity)
290
+ );
291
+ if (sharedEntities) {
292
+ return true;
293
+ }
294
+ const newWords = extractKeywords(newMemory.content);
295
+ const existingWords = extractKeywords(existing.content);
296
+ const overlap = newWords.filter((w) => existingWords.includes(w));
297
+ return overlap.length >= 2;
298
+ });
299
+ }
300
+ function extractKeywords(text) {
301
+ const stopWords = /* @__PURE__ */ new Set([
302
+ "the",
303
+ "a",
304
+ "an",
305
+ "is",
306
+ "are",
307
+ "was",
308
+ "were",
309
+ "be",
310
+ "been",
311
+ "being",
312
+ "have",
313
+ "has",
314
+ "had",
315
+ "do",
316
+ "does",
317
+ "did",
318
+ "will",
319
+ "would",
320
+ "could",
321
+ "should",
322
+ "may",
323
+ "might",
324
+ "must",
325
+ "can",
326
+ "to",
327
+ "of",
328
+ "in",
329
+ "for",
330
+ "on",
331
+ "at",
332
+ "by",
333
+ "from",
334
+ "with",
335
+ "about"
336
+ ]);
337
+ return text.toLowerCase().split(/\W+/).filter((word) => word.length > 3 && !stopWords.has(word)).slice(0, 10);
338
+ }
339
+ function shouldInvalidateMemory(relationType) {
340
+ return relationType === "updates" || relationType === "contradicts";
341
+ }
342
+ function buildRelationGraph(relations) {
343
+ const graph = /* @__PURE__ */ new Map();
344
+ for (const relation of relations) {
345
+ if (!graph.has(relation.fromMemoryId)) {
346
+ graph.set(relation.fromMemoryId, []);
347
+ }
348
+ graph.get(relation.fromMemoryId).push({
349
+ memoryId: relation.toMemoryId,
350
+ relationType: relation.relationType
351
+ });
352
+ if (!graph.has(relation.toMemoryId)) {
353
+ graph.set(relation.toMemoryId, []);
354
+ }
355
+ graph.get(relation.toMemoryId).push({
356
+ memoryId: relation.fromMemoryId,
357
+ relationType: `inverse_${relation.relationType}`
358
+ });
359
+ }
360
+ return graph;
361
+ }
362
+
363
+ export {
364
+ parseTemporalQuery,
365
+ extractEventDate,
366
+ calculateTemporalRelevance,
367
+ detectRelations,
368
+ shouldInvalidateMemory,
369
+ buildRelationGraph
370
+ };