@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,222 +1,222 @@
1
- import {
2
- db,
3
- embedSingle
4
- } from "./chunk-3WGYBAYR.js";
5
- import {
6
- Anthropic
7
- } from "./chunk-H3HSKH2P.js";
8
- import "./chunk-QGM4M3NI.js";
9
-
10
- // ../src/engine/memory/consolidation.ts
11
- var anthropic = new Anthropic({
12
- apiKey: process.env.ANTHROPIC_API_KEY || ""
13
- });
14
- async function findDuplicateMemories(params) {
15
- const {
16
- projectId,
17
- userId,
18
- similarityThreshold = 0.95,
19
- limit = 50
20
- } = params;
21
- const maxMemories = Math.min(Math.max(limit, 10), 100);
22
- const memories = await db.memory.findMany({
23
- where: {
24
- projectId,
25
- userId,
26
- isActive: true,
27
- validUntil: null
28
- },
29
- orderBy: { importance: "desc" },
30
- take: maxMemories
31
- });
32
- const clusters = [];
33
- const processed = /* @__PURE__ */ new Set();
34
- for (let i = 0; i < memories.length; i++) {
35
- const memory = memories[i];
36
- if (processed.has(memory.id)) continue;
37
- const similar = [];
38
- const candidates = memories.slice(i + 1);
39
- const batchSimilarities = await calculateBatchSimilarity(memory.id, candidates.map((c) => c.id));
40
- for (let j = 0; j < candidates.length; j++) {
41
- const other = candidates[j];
42
- if (processed.has(other.id)) continue;
43
- const similarity = batchSimilarities[j];
44
- if (similarity >= similarityThreshold) {
45
- similar.push({ ...other, similarity });
46
- processed.add(other.id);
47
- }
48
- }
49
- if (similar.length > 0) {
50
- clusters.push({
51
- representative: memory,
52
- duplicates: similar,
53
- similarity: similar.reduce((sum, m) => sum + m.similarity, 0) / similar.length
54
- });
55
- processed.add(memory.id);
56
- }
57
- }
58
- return clusters;
59
- }
60
- async function calculateBatchSimilarity(memoryId, otherIds) {
61
- if (otherIds.length === 0) return [];
62
- const placeholders = otherIds.map((_, i) => `(m1.embedding <=> $${i + 2}::vector)`).join(" + ");
63
- const conditions = otherIds.map((id, i) => `m2.id = $${i + 2}`).join(" OR ");
64
- const result = await db.$queryRaw`
65
- SELECT
66
- 1 - (m1.embedding <=> m2.embedding) as similarity,
67
- m2.id as id
68
- FROM memories m1, memories m2
69
- WHERE m1.id = ${memoryId} AND (${conditions})
70
- `;
71
- const similarityMap = new Map(result.map((r) => [r.id, r.similarity]));
72
- return otherIds.map((id) => similarityMap.get(id) || 0);
73
- }
74
- async function mergeDuplicateMemories(cluster) {
75
- const memories = [cluster.representative, ...cluster.duplicates];
76
- const prompt = `You are merging duplicate memories into a single, comprehensive memory.
77
-
78
- **Memories to merge:**
79
- ${memories.map(
80
- (m, i) => `${i + 1}. "${m.content}" (confidence: ${m.confidence}, date: ${m.documentDate?.toISOString() || "unknown"})`
81
- ).join("\n")}
82
-
83
- **Instructions:**
84
- 1. Combine all unique information from these memories
85
- 2. Resolve any contradictions by keeping the most recent or most confident information
86
- 3. Extract all unique entity mentions
87
- 4. Use the highest confidence score
88
- 5. Keep the most recent document date
89
-
90
- Return JSON:
91
- {
92
- "merged_content": "comprehensive merged memory",
93
- "entity_mentions": ["list", "of", "entities"],
94
- "confidence": 0.0-1.0,
95
- "reasoning": "brief explanation of how you merged"
96
- }`;
97
- const response = await anthropic.messages.create({
98
- model: "claude-sonnet-4-5-20250929",
99
- // Fixed: was "claude-sonnet-4.5" (wrong format)
100
- max_tokens: 2048,
101
- temperature: 0,
102
- messages: [{ role: "user", content: prompt }]
103
- });
104
- const text = response.content.find((c) => c.type === "text");
105
- if (!text || text.type !== "text") {
106
- throw new Error("Failed to merge memories");
107
- }
108
- const jsonMatch = text.text.match(/```json\n?([\s\S]*?)\n?```/) || text.text.match(/\{[\s\S]*\}/);
109
- const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text.text;
110
- const result = JSON.parse(jsonStr);
111
- const embedding = await embedSingle(result.merged_content);
112
- const mergedMemory = await db.memory.create({
113
- data: {
114
- projectId: cluster.representative.projectId,
115
- orgId: cluster.representative.orgId,
116
- userId: cluster.representative.userId,
117
- sessionId: cluster.representative.sessionId,
118
- memoryType: cluster.representative.memoryType,
119
- content: result.merged_content,
120
- embedding,
121
- entityMentions: result.entity_mentions || [],
122
- confidence: result.confidence || cluster.representative.confidence,
123
- documentDate: cluster.representative.documentDate,
124
- eventDate: cluster.representative.eventDate,
125
- validFrom: /* @__PURE__ */ new Date(),
126
- importance: Math.max(...memories.map((m) => m.importance || 0.5)),
127
- metadata: {
128
- mergedFrom: memories.map((m) => m.id),
129
- mergeReasoning: result.reasoning,
130
- mergedAt: (/* @__PURE__ */ new Date()).toISOString()
131
- }
132
- }
133
- });
134
- for (const memory of memories) {
135
- await db.memory.update({
136
- where: { id: memory.id },
137
- data: {
138
- isActive: false,
139
- validUntil: /* @__PURE__ */ new Date(),
140
- supersededBy: mergedMemory.id
141
- }
142
- });
143
- }
144
- return mergedMemory.id;
145
- }
146
- async function consolidateMemories(params) {
147
- const { projectId, userId, similarityThreshold = 0.95, dryRun = false } = params;
148
- console.log(`\u{1F50D} Finding duplicate memories in project ${projectId}...`);
149
- const clusters = await findDuplicateMemories({
150
- projectId,
151
- userId,
152
- similarityThreshold
153
- });
154
- console.log(`\u{1F4CA} Found ${clusters.length} memory clusters`);
155
- if (dryRun) {
156
- for (const cluster of clusters) {
157
- console.log(`
158
- Cluster (similarity: ${cluster.similarity.toFixed(2)}):`);
159
- console.log(` Representative: "${cluster.representative.content}"`);
160
- console.log(` Duplicates: ${cluster.duplicates.length}`);
161
- cluster.duplicates.forEach((d) => {
162
- console.log(` - "${d.content}"`);
163
- });
164
- }
165
- return {
166
- clustersFound: clusters.length,
167
- memoriesMerged: 0,
168
- memoriesDeactivated: 0
169
- };
170
- }
171
- let memoriesMerged = 0;
172
- let memoriesDeactivated = 0;
173
- for (const cluster of clusters) {
174
- try {
175
- console.log(`\u{1F517} Merging cluster with ${cluster.duplicates.length + 1} memories...`);
176
- await mergeDuplicateMemories(cluster);
177
- memoriesMerged++;
178
- memoriesDeactivated += cluster.duplicates.length + 1;
179
- console.log(`\u2705 Merged successfully`);
180
- } catch (error) {
181
- console.error(`\u274C Failed to merge cluster:`, error);
182
- }
183
- }
184
- console.log(
185
- `
186
- \u2705 Consolidation complete: ${memoriesMerged} clusters merged, ${memoriesDeactivated} memories deactivated`
187
- );
188
- return {
189
- clustersFound: clusters.length,
190
- memoriesMerged,
191
- memoriesDeactivated
192
- };
193
- }
194
- async function scheduledConsolidation(orgId) {
195
- console.log(`\u{1F504} Running scheduled consolidation for org ${orgId}...`);
196
- const projects = await db.project.findMany({
197
- where: { orgId }
198
- });
199
- for (const project of projects) {
200
- try {
201
- const result = await consolidateMemories({
202
- projectId: project.id,
203
- similarityThreshold: 0.92
204
- // Slightly lower for scheduled runs
205
- });
206
- if (result.memoriesMerged > 0) {
207
- console.log(
208
- `\u{1F4CA} Project ${project.name}: merged ${result.memoriesMerged} clusters`
209
- );
210
- }
211
- } catch (error) {
212
- console.error(`Failed to consolidate project ${project.name}:`, error);
213
- }
214
- }
215
- console.log("\u2705 Scheduled consolidation complete");
216
- }
217
- export {
218
- consolidateMemories,
219
- findDuplicateMemories,
220
- mergeDuplicateMemories,
221
- scheduledConsolidation
222
- };
1
+ import {
2
+ db,
3
+ embedSingle
4
+ } from "./chunk-3WGYBAYR.js";
5
+ import {
6
+ Anthropic
7
+ } from "./chunk-H3HSKH2P.js";
8
+ import "./chunk-QGM4M3NI.js";
9
+
10
+ // ../src/engine/memory/consolidation.ts
11
+ var anthropic = new Anthropic({
12
+ apiKey: process.env.ANTHROPIC_API_KEY || ""
13
+ });
14
+ async function findDuplicateMemories(params) {
15
+ const {
16
+ projectId,
17
+ userId,
18
+ similarityThreshold = 0.95,
19
+ limit = 50
20
+ } = params;
21
+ const maxMemories = Math.min(Math.max(limit, 10), 100);
22
+ const memories = await db.memory.findMany({
23
+ where: {
24
+ projectId,
25
+ userId,
26
+ isActive: true,
27
+ validUntil: null
28
+ },
29
+ orderBy: { importance: "desc" },
30
+ take: maxMemories
31
+ });
32
+ const clusters = [];
33
+ const processed = /* @__PURE__ */ new Set();
34
+ for (let i = 0; i < memories.length; i++) {
35
+ const memory = memories[i];
36
+ if (processed.has(memory.id)) continue;
37
+ const similar = [];
38
+ const candidates = memories.slice(i + 1);
39
+ const batchSimilarities = await calculateBatchSimilarity(memory.id, candidates.map((c) => c.id));
40
+ for (let j = 0; j < candidates.length; j++) {
41
+ const other = candidates[j];
42
+ if (processed.has(other.id)) continue;
43
+ const similarity = batchSimilarities[j];
44
+ if (similarity >= similarityThreshold) {
45
+ similar.push({ ...other, similarity });
46
+ processed.add(other.id);
47
+ }
48
+ }
49
+ if (similar.length > 0) {
50
+ clusters.push({
51
+ representative: memory,
52
+ duplicates: similar,
53
+ similarity: similar.reduce((sum, m) => sum + m.similarity, 0) / similar.length
54
+ });
55
+ processed.add(memory.id);
56
+ }
57
+ }
58
+ return clusters;
59
+ }
60
+ async function calculateBatchSimilarity(memoryId, otherIds) {
61
+ if (otherIds.length === 0) return [];
62
+ const placeholders = otherIds.map((_, i) => `(m1.embedding <=> $${i + 2}::vector)`).join(" + ");
63
+ const conditions = otherIds.map((id, i) => `m2.id = $${i + 2}`).join(" OR ");
64
+ const result = await db.$queryRaw`
65
+ SELECT
66
+ 1 - (m1.embedding <=> m2.embedding) as similarity,
67
+ m2.id as id
68
+ FROM memories m1, memories m2
69
+ WHERE m1.id = ${memoryId} AND (${conditions})
70
+ `;
71
+ const similarityMap = new Map(result.map((r) => [r.id, r.similarity]));
72
+ return otherIds.map((id) => similarityMap.get(id) || 0);
73
+ }
74
+ async function mergeDuplicateMemories(cluster) {
75
+ const memories = [cluster.representative, ...cluster.duplicates];
76
+ const prompt = `You are merging duplicate memories into a single, comprehensive memory.
77
+
78
+ **Memories to merge:**
79
+ ${memories.map(
80
+ (m, i) => `${i + 1}. "${m.content}" (confidence: ${m.confidence}, date: ${m.documentDate?.toISOString() || "unknown"})`
81
+ ).join("\n")}
82
+
83
+ **Instructions:**
84
+ 1. Combine all unique information from these memories
85
+ 2. Resolve any contradictions by keeping the most recent or most confident information
86
+ 3. Extract all unique entity mentions
87
+ 4. Use the highest confidence score
88
+ 5. Keep the most recent document date
89
+
90
+ Return JSON:
91
+ {
92
+ "merged_content": "comprehensive merged memory",
93
+ "entity_mentions": ["list", "of", "entities"],
94
+ "confidence": 0.0-1.0,
95
+ "reasoning": "brief explanation of how you merged"
96
+ }`;
97
+ const response = await anthropic.messages.create({
98
+ model: "claude-sonnet-4-5-20250929",
99
+ // Fixed: was "claude-sonnet-4.5" (wrong format)
100
+ max_tokens: 2048,
101
+ temperature: 0,
102
+ messages: [{ role: "user", content: prompt }]
103
+ });
104
+ const text = response.content.find((c) => c.type === "text");
105
+ if (!text || text.type !== "text") {
106
+ throw new Error("Failed to merge memories");
107
+ }
108
+ const jsonMatch = text.text.match(/```json\n?([\s\S]*?)\n?```/) || text.text.match(/\{[\s\S]*\}/);
109
+ const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text.text;
110
+ const result = JSON.parse(jsonStr);
111
+ const embedding = await embedSingle(result.merged_content);
112
+ const mergedMemory = await db.memory.create({
113
+ data: {
114
+ projectId: cluster.representative.projectId,
115
+ orgId: cluster.representative.orgId,
116
+ userId: cluster.representative.userId,
117
+ sessionId: cluster.representative.sessionId,
118
+ memoryType: cluster.representative.memoryType,
119
+ content: result.merged_content,
120
+ embedding,
121
+ entityMentions: result.entity_mentions || [],
122
+ confidence: result.confidence || cluster.representative.confidence,
123
+ documentDate: cluster.representative.documentDate,
124
+ eventDate: cluster.representative.eventDate,
125
+ validFrom: /* @__PURE__ */ new Date(),
126
+ importance: Math.max(...memories.map((m) => m.importance || 0.5)),
127
+ metadata: {
128
+ mergedFrom: memories.map((m) => m.id),
129
+ mergeReasoning: result.reasoning,
130
+ mergedAt: (/* @__PURE__ */ new Date()).toISOString()
131
+ }
132
+ }
133
+ });
134
+ for (const memory of memories) {
135
+ await db.memory.update({
136
+ where: { id: memory.id },
137
+ data: {
138
+ isActive: false,
139
+ validUntil: /* @__PURE__ */ new Date(),
140
+ supersededBy: mergedMemory.id
141
+ }
142
+ });
143
+ }
144
+ return mergedMemory.id;
145
+ }
146
+ async function consolidateMemories(params) {
147
+ const { projectId, userId, similarityThreshold = 0.95, dryRun = false } = params;
148
+ console.log(`\u{1F50D} Finding duplicate memories in project ${projectId}...`);
149
+ const clusters = await findDuplicateMemories({
150
+ projectId,
151
+ userId,
152
+ similarityThreshold
153
+ });
154
+ console.log(`\u{1F4CA} Found ${clusters.length} memory clusters`);
155
+ if (dryRun) {
156
+ for (const cluster of clusters) {
157
+ console.log(`
158
+ Cluster (similarity: ${cluster.similarity.toFixed(2)}):`);
159
+ console.log(` Representative: "${cluster.representative.content}"`);
160
+ console.log(` Duplicates: ${cluster.duplicates.length}`);
161
+ cluster.duplicates.forEach((d) => {
162
+ console.log(` - "${d.content}"`);
163
+ });
164
+ }
165
+ return {
166
+ clustersFound: clusters.length,
167
+ memoriesMerged: 0,
168
+ memoriesDeactivated: 0
169
+ };
170
+ }
171
+ let memoriesMerged = 0;
172
+ let memoriesDeactivated = 0;
173
+ for (const cluster of clusters) {
174
+ try {
175
+ console.log(`\u{1F517} Merging cluster with ${cluster.duplicates.length + 1} memories...`);
176
+ await mergeDuplicateMemories(cluster);
177
+ memoriesMerged++;
178
+ memoriesDeactivated += cluster.duplicates.length + 1;
179
+ console.log(`\u2705 Merged successfully`);
180
+ } catch (error) {
181
+ console.error(`\u274C Failed to merge cluster:`, error);
182
+ }
183
+ }
184
+ console.log(
185
+ `
186
+ \u2705 Consolidation complete: ${memoriesMerged} clusters merged, ${memoriesDeactivated} memories deactivated`
187
+ );
188
+ return {
189
+ clustersFound: clusters.length,
190
+ memoriesMerged,
191
+ memoriesDeactivated
192
+ };
193
+ }
194
+ async function scheduledConsolidation(orgId) {
195
+ console.log(`\u{1F504} Running scheduled consolidation for org ${orgId}...`);
196
+ const projects = await db.project.findMany({
197
+ where: { orgId }
198
+ });
199
+ for (const project of projects) {
200
+ try {
201
+ const result = await consolidateMemories({
202
+ projectId: project.id,
203
+ similarityThreshold: 0.92
204
+ // Slightly lower for scheduled runs
205
+ });
206
+ if (result.memoriesMerged > 0) {
207
+ console.log(
208
+ `\u{1F4CA} Project ${project.name}: merged ${result.memoriesMerged} clusters`
209
+ );
210
+ }
211
+ } catch (error) {
212
+ console.error(`Failed to consolidate project ${project.name}:`, error);
213
+ }
214
+ }
215
+ console.log("\u2705 Scheduled consolidation complete");
216
+ }
217
+ export {
218
+ consolidateMemories,
219
+ findDuplicateMemories,
220
+ mergeDuplicateMemories,
221
+ scheduledConsolidation
222
+ };