@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,189 +1,189 @@
1
- // ../src/engine/memory/temporal.ts
2
- import OpenAI from "openai";
3
- var openai = new OpenAI({
4
- apiKey: process.env.OPENAI_API_KEY || ""
5
- });
6
- var TEMPORAL_PARSING_PROMPT = `You are an expert temporal query parser. Extract temporal constraints from user queries.
7
-
8
- **Your job:**
9
- 1. Identify if the query has temporal constraints
10
- 2. Extract relative time references (today, yesterday, last week, etc.)
11
- 3. Extract absolute dates if mentioned
12
- 4. Calculate date ranges if applicable
13
-
14
- **Relative Terms:**
15
- - "today" \u2192 filter to documentDate = questionDate
16
- - "yesterday" \u2192 documentDate = questionDate - 1 day
17
- - "last week" \u2192 documentDate in range [questionDate - 7 days, questionDate]
18
- - "last month" \u2192 documentDate in range [questionDate - 30 days, questionDate]
19
- - "last year" \u2192 documentDate in range [questionDate - 365 days, questionDate]
20
- - "this week" \u2192 current week
21
- - "this month" \u2192 current month
22
-
23
- **Examples:**
24
- - "What did I say about vacation yesterday?" \u2192 relative: "yesterday"
25
- - "Tell me about meetings last week" \u2192 relative: "last_week"
26
- - "What happened on January 15?" \u2192 absoluteDate: "2024-01-15"
27
- - "Show me everything from last month" \u2192 relative: "last_month"
28
- - "What's my favorite color?" \u2192 no temporal constraint`;
29
- async function parseTemporalQuery(query, questionDate) {
30
- const prompt = `${TEMPORAL_PARSING_PROMPT}
31
-
32
- **Query:** "${query}"
33
- **Question asked on:** ${questionDate.toISOString()}
34
-
35
- Extract temporal information and return JSON:
36
- {
37
- "hasTemporalConstraint": boolean,
38
- "relative": "today|yesterday|last_week|last_month|last_year|this_week|this_month|null",
39
- "absoluteDate": "ISO date string or null",
40
- "dateRange": { "start": "ISO", "end": "ISO" } or null
41
- }
42
-
43
- Return ONLY the JSON, no other text.`;
44
- try {
45
- const response = await openai.chat.completions.create({
46
- model: "gpt-4o-mini",
47
- // Faster model for parsing
48
- max_tokens: 512,
49
- temperature: 0,
50
- messages: [{ role: "user", content: prompt }],
51
- response_format: { type: "json_object" }
52
- });
53
- const text = response.choices[0]?.message?.content?.trim();
54
- if (!text) {
55
- return { hasTemporalConstraint: false };
56
- }
57
- const jsonMatch = text.match(/```json\n?([\s\S]*?)\n?```/) || text.match(/\{[\s\S]*\}/);
58
- const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text;
59
- const parsed = JSON.parse(jsonStr);
60
- if (parsed.relative) {
61
- const range = calculateRelativeDateRange(parsed.relative, questionDate);
62
- parsed.dateRange = range;
63
- parsed.absoluteDate = range.start;
64
- } else if (parsed.absoluteDate) {
65
- parsed.absoluteDate = new Date(parsed.absoluteDate);
66
- }
67
- if (parsed.dateRange) {
68
- parsed.dateRange = {
69
- start: new Date(parsed.dateRange.start),
70
- end: new Date(parsed.dateRange.end)
71
- };
72
- }
73
- return parsed;
74
- } catch (error) {
75
- console.error("Temporal parsing failed:", error);
76
- return { hasTemporalConstraint: false };
77
- }
78
- }
79
- function calculateRelativeDateRange(relative, from) {
80
- const start = new Date(from);
81
- const end = new Date(from);
82
- switch (relative) {
83
- case "today":
84
- start.setHours(0, 0, 0, 0);
85
- end.setHours(23, 59, 59, 999);
86
- break;
87
- case "yesterday":
88
- start.setDate(start.getDate() - 1);
89
- start.setHours(0, 0, 0, 0);
90
- end.setDate(end.getDate() - 1);
91
- end.setHours(23, 59, 59, 999);
92
- break;
93
- case "last_week":
94
- start.setDate(start.getDate() - 7);
95
- start.setHours(0, 0, 0, 0);
96
- end.setHours(23, 59, 59, 999);
97
- break;
98
- case "this_week":
99
- const dayOfWeek = start.getDay();
100
- const diff = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
101
- start.setDate(start.getDate() + diff);
102
- start.setHours(0, 0, 0, 0);
103
- end.setHours(23, 59, 59, 999);
104
- break;
105
- case "last_month":
106
- start.setDate(start.getDate() - 30);
107
- start.setHours(0, 0, 0, 0);
108
- end.setHours(23, 59, 59, 999);
109
- break;
110
- case "this_month":
111
- start.setDate(1);
112
- start.setHours(0, 0, 0, 0);
113
- end.setHours(23, 59, 59, 999);
114
- break;
115
- case "last_year":
116
- start.setFullYear(start.getFullYear() - 1);
117
- start.setHours(0, 0, 0, 0);
118
- end.setHours(23, 59, 59, 999);
119
- break;
120
- default:
121
- start.setFullYear(1970);
122
- end.setFullYear(2100);
123
- }
124
- return { start, end };
125
- }
126
- async function extractEventDate(memoryContent, documentDate) {
127
- const prompt = `Extract the event date from this memory.
128
-
129
- **Important distinction:**
130
- - documentDate: When this was said/written
131
- - eventDate: When the event actually occurred/will occur
132
-
133
- **Memory:** "${memoryContent}"
134
- **Document Date (when this was said):** ${documentDate.toISOString()}
135
-
136
- **Examples:**
137
- - "User said they have a meeting tomorrow" \u2192 eventDate = documentDate + 1 day
138
- - "User attended conference on Jan 15" \u2192 eventDate = Jan 15 of appropriate year
139
- - "User's favorite color is blue" \u2192 eventDate = null (no event, just a fact)
140
- - "Meeting happened yesterday" \u2192 eventDate = documentDate - 1 day
141
-
142
- Return JSON:
143
- {
144
- "hasEvent": boolean,
145
- "eventDate": "ISO date string or null",
146
- "reasoning": "brief explanation"
147
- }`;
148
- try {
149
- const response = await openai.chat.completions.create({
150
- model: "gpt-4o-mini",
151
- max_tokens: 256,
152
- temperature: 0,
153
- messages: [{ role: "user", content: prompt }],
154
- response_format: { type: "json_object" }
155
- });
156
- const text = response.choices[0]?.message?.content?.trim();
157
- if (!text) {
158
- return null;
159
- }
160
- const jsonMatch = text.match(/```json\n?([\s\S]*?)\n?```/) || text.match(/\{[\s\S]*\}/);
161
- const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text;
162
- const result = JSON.parse(jsonStr);
163
- if (result.hasEvent && result.eventDate) {
164
- return new Date(result.eventDate);
165
- }
166
- return null;
167
- } catch (error) {
168
- console.error("Event date extraction failed:", error);
169
- return null;
170
- }
171
- }
172
- function calculateTemporalRelevance(memoryDate, questionDate, decayFactor = 0.1) {
173
- if (!memoryDate) return 0.5;
174
- const memDate = typeof memoryDate === "string" ? new Date(memoryDate) : memoryDate;
175
- if (!(memDate instanceof Date) || isNaN(memDate.getTime())) {
176
- return 0.5;
177
- }
178
- const daysDiff = Math.abs(
179
- (questionDate.getTime() - memDate.getTime()) / (1e3 * 60 * 60 * 24)
180
- );
181
- const score = Math.exp(-decayFactor * daysDiff);
182
- return score;
183
- }
184
-
185
- export {
186
- parseTemporalQuery,
187
- extractEventDate,
188
- calculateTemporalRelevance
189
- };
1
+ // ../src/engine/memory/temporal.ts
2
+ import OpenAI from "openai";
3
+ var openai = new OpenAI({
4
+ apiKey: process.env.OPENAI_API_KEY || ""
5
+ });
6
+ var TEMPORAL_PARSING_PROMPT = `You are an expert temporal query parser. Extract temporal constraints from user queries.
7
+
8
+ **Your job:**
9
+ 1. Identify if the query has temporal constraints
10
+ 2. Extract relative time references (today, yesterday, last week, etc.)
11
+ 3. Extract absolute dates if mentioned
12
+ 4. Calculate date ranges if applicable
13
+
14
+ **Relative Terms:**
15
+ - "today" \u2192 filter to documentDate = questionDate
16
+ - "yesterday" \u2192 documentDate = questionDate - 1 day
17
+ - "last week" \u2192 documentDate in range [questionDate - 7 days, questionDate]
18
+ - "last month" \u2192 documentDate in range [questionDate - 30 days, questionDate]
19
+ - "last year" \u2192 documentDate in range [questionDate - 365 days, questionDate]
20
+ - "this week" \u2192 current week
21
+ - "this month" \u2192 current month
22
+
23
+ **Examples:**
24
+ - "What did I say about vacation yesterday?" \u2192 relative: "yesterday"
25
+ - "Tell me about meetings last week" \u2192 relative: "last_week"
26
+ - "What happened on January 15?" \u2192 absoluteDate: "2024-01-15"
27
+ - "Show me everything from last month" \u2192 relative: "last_month"
28
+ - "What's my favorite color?" \u2192 no temporal constraint`;
29
+ async function parseTemporalQuery(query, questionDate) {
30
+ const prompt = `${TEMPORAL_PARSING_PROMPT}
31
+
32
+ **Query:** "${query}"
33
+ **Question asked on:** ${questionDate.toISOString()}
34
+
35
+ Extract temporal information and return JSON:
36
+ {
37
+ "hasTemporalConstraint": boolean,
38
+ "relative": "today|yesterday|last_week|last_month|last_year|this_week|this_month|null",
39
+ "absoluteDate": "ISO date string or null",
40
+ "dateRange": { "start": "ISO", "end": "ISO" } or null
41
+ }
42
+
43
+ Return ONLY the JSON, no other text.`;
44
+ try {
45
+ const response = await openai.chat.completions.create({
46
+ model: "gpt-4o-mini",
47
+ // Faster model for parsing
48
+ max_tokens: 512,
49
+ temperature: 0,
50
+ messages: [{ role: "user", content: prompt }],
51
+ response_format: { type: "json_object" }
52
+ });
53
+ const text = response.choices[0]?.message?.content?.trim();
54
+ if (!text) {
55
+ return { hasTemporalConstraint: false };
56
+ }
57
+ const jsonMatch = text.match(/```json\n?([\s\S]*?)\n?```/) || text.match(/\{[\s\S]*\}/);
58
+ const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text;
59
+ const parsed = JSON.parse(jsonStr);
60
+ if (parsed.relative) {
61
+ const range = calculateRelativeDateRange(parsed.relative, questionDate);
62
+ parsed.dateRange = range;
63
+ parsed.absoluteDate = range.start;
64
+ } else if (parsed.absoluteDate) {
65
+ parsed.absoluteDate = new Date(parsed.absoluteDate);
66
+ }
67
+ if (parsed.dateRange) {
68
+ parsed.dateRange = {
69
+ start: new Date(parsed.dateRange.start),
70
+ end: new Date(parsed.dateRange.end)
71
+ };
72
+ }
73
+ return parsed;
74
+ } catch (error) {
75
+ console.error("Temporal parsing failed:", error);
76
+ return { hasTemporalConstraint: false };
77
+ }
78
+ }
79
+ function calculateRelativeDateRange(relative, from) {
80
+ const start = new Date(from);
81
+ const end = new Date(from);
82
+ switch (relative) {
83
+ case "today":
84
+ start.setHours(0, 0, 0, 0);
85
+ end.setHours(23, 59, 59, 999);
86
+ break;
87
+ case "yesterday":
88
+ start.setDate(start.getDate() - 1);
89
+ start.setHours(0, 0, 0, 0);
90
+ end.setDate(end.getDate() - 1);
91
+ end.setHours(23, 59, 59, 999);
92
+ break;
93
+ case "last_week":
94
+ start.setDate(start.getDate() - 7);
95
+ start.setHours(0, 0, 0, 0);
96
+ end.setHours(23, 59, 59, 999);
97
+ break;
98
+ case "this_week":
99
+ const dayOfWeek = start.getDay();
100
+ const diff = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
101
+ start.setDate(start.getDate() + diff);
102
+ start.setHours(0, 0, 0, 0);
103
+ end.setHours(23, 59, 59, 999);
104
+ break;
105
+ case "last_month":
106
+ start.setDate(start.getDate() - 30);
107
+ start.setHours(0, 0, 0, 0);
108
+ end.setHours(23, 59, 59, 999);
109
+ break;
110
+ case "this_month":
111
+ start.setDate(1);
112
+ start.setHours(0, 0, 0, 0);
113
+ end.setHours(23, 59, 59, 999);
114
+ break;
115
+ case "last_year":
116
+ start.setFullYear(start.getFullYear() - 1);
117
+ start.setHours(0, 0, 0, 0);
118
+ end.setHours(23, 59, 59, 999);
119
+ break;
120
+ default:
121
+ start.setFullYear(1970);
122
+ end.setFullYear(2100);
123
+ }
124
+ return { start, end };
125
+ }
126
+ async function extractEventDate(memoryContent, documentDate) {
127
+ const prompt = `Extract the event date from this memory.
128
+
129
+ **Important distinction:**
130
+ - documentDate: When this was said/written
131
+ - eventDate: When the event actually occurred/will occur
132
+
133
+ **Memory:** "${memoryContent}"
134
+ **Document Date (when this was said):** ${documentDate.toISOString()}
135
+
136
+ **Examples:**
137
+ - "User said they have a meeting tomorrow" \u2192 eventDate = documentDate + 1 day
138
+ - "User attended conference on Jan 15" \u2192 eventDate = Jan 15 of appropriate year
139
+ - "User's favorite color is blue" \u2192 eventDate = null (no event, just a fact)
140
+ - "Meeting happened yesterday" \u2192 eventDate = documentDate - 1 day
141
+
142
+ Return JSON:
143
+ {
144
+ "hasEvent": boolean,
145
+ "eventDate": "ISO date string or null",
146
+ "reasoning": "brief explanation"
147
+ }`;
148
+ try {
149
+ const response = await openai.chat.completions.create({
150
+ model: "gpt-4o-mini",
151
+ max_tokens: 256,
152
+ temperature: 0,
153
+ messages: [{ role: "user", content: prompt }],
154
+ response_format: { type: "json_object" }
155
+ });
156
+ const text = response.choices[0]?.message?.content?.trim();
157
+ if (!text) {
158
+ return null;
159
+ }
160
+ const jsonMatch = text.match(/```json\n?([\s\S]*?)\n?```/) || text.match(/\{[\s\S]*\}/);
161
+ const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text;
162
+ const result = JSON.parse(jsonStr);
163
+ if (result.hasEvent && result.eventDate) {
164
+ return new Date(result.eventDate);
165
+ }
166
+ return null;
167
+ } catch (error) {
168
+ console.error("Event date extraction failed:", error);
169
+ return null;
170
+ }
171
+ }
172
+ function calculateTemporalRelevance(memoryDate, questionDate, decayFactor = 0.1) {
173
+ if (!memoryDate) return 0.5;
174
+ const memDate = typeof memoryDate === "string" ? new Date(memoryDate) : memoryDate;
175
+ if (!(memDate instanceof Date) || isNaN(memDate.getTime())) {
176
+ return 0.5;
177
+ }
178
+ const daysDiff = Math.abs(
179
+ (questionDate.getTime() - memDate.getTime()) / (1e3 * 60 * 60 * 24)
180
+ );
181
+ const score = Math.exp(-decayFactor * daysDiff);
182
+ return score;
183
+ }
184
+
185
+ export {
186
+ parseTemporalQuery,
187
+ extractEventDate,
188
+ calculateTemporalRelevance
189
+ };