@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,263 +1,263 @@
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/oracle.ts
11
- var anthropic = new Anthropic({
12
- apiKey: process.env.ANTHROPIC_API_KEY || ""
13
- });
14
- var MAX_DOCUMENT_CHUNKS = 500;
15
- async function buildDocumentTree(documentId) {
16
- const document = await db.document.findUnique({
17
- where: { id: documentId },
18
- include: {
19
- chunks: {
20
- orderBy: { chunkOrder: "asc" },
21
- take: MAX_DOCUMENT_CHUNKS
22
- }
23
- }
24
- });
25
- if (!document) {
26
- throw new Error("Document not found");
27
- }
28
- const root = {
29
- id: document.id,
30
- content: document.title,
31
- type: "document",
32
- children: [],
33
- metadata: document.metadata
34
- };
35
- const sectionMap = /* @__PURE__ */ new Map();
36
- for (const chunk of document.chunks) {
37
- const sectionPath = chunk.metadata?.sectionPath || chunk.sectionPath || "root";
38
- if (!sectionMap.has(sectionPath)) {
39
- const sectionNode = {
40
- id: `${documentId}::${sectionPath}`,
41
- content: sectionPath,
42
- type: "section",
43
- children: [],
44
- metadata: { path: sectionPath }
45
- };
46
- sectionMap.set(sectionPath, sectionNode);
47
- root.children.push(sectionNode);
48
- }
49
- const section = sectionMap.get(sectionPath);
50
- section.children.push({
51
- id: chunk.id,
52
- content: chunk.content,
53
- type: "chunk",
54
- children: [],
55
- metadata: chunk.metadata,
56
- embedding: chunk.embedding
57
- });
58
- }
59
- return {
60
- root,
61
- depth: calculateDepth(root),
62
- nodeCount: countNodes(root)
63
- };
64
- }
65
- function calculateDepth(node) {
66
- if (node.children.length === 0) return 1;
67
- return 1 + Math.max(...node.children.map(calculateDepth));
68
- }
69
- function countNodes(node) {
70
- return 1 + node.children.reduce((sum, child) => sum + countNodes(child), 0);
71
- }
72
- async function oracleSearch(params) {
73
- const { query, projectId, topK = 5, maxDepth = 3 } = params;
74
- console.log(`\u{1F52E} Oracle search: "${query}"`);
75
- const queryEmbedding = await embedSingle(query);
76
- const documents = await db.document.findMany({
77
- where: { projectId },
78
- take: 10
79
- });
80
- const results = [];
81
- for (const doc of documents) {
82
- const tree = await buildDocumentTree(doc.id);
83
- const traversalResults = await guidedTraversal({
84
- tree,
85
- query,
86
- queryEmbedding,
87
- maxDepth,
88
- topK
89
- });
90
- results.push(...traversalResults);
91
- }
92
- results.sort((a, b) => b.relevance - a.relevance);
93
- return results.slice(0, topK);
94
- }
95
- async function guidedTraversal(params) {
96
- const {
97
- tree,
98
- query,
99
- queryEmbedding,
100
- maxDepth,
101
- topK,
102
- currentNode = tree.root,
103
- currentDepth = 0,
104
- path = ""
105
- } = params;
106
- const results = [];
107
- if (currentDepth >= maxDepth) {
108
- return results;
109
- }
110
- if (currentNode.type === "chunk") {
111
- const relevance = currentNode.embedding ? cosineSimilarity(queryEmbedding, currentNode.embedding) : 0;
112
- if (relevance > 0.3) {
113
- results.push({
114
- content: currentNode.content,
115
- path,
116
- relevance
117
- });
118
- }
119
- return results;
120
- }
121
- const childScores = await Promise.all(
122
- currentNode.children.map(async (child) => {
123
- const score = await scoreNode(child, query, queryEmbedding);
124
- return { child, score };
125
- })
126
- );
127
- childScores.sort((a, b) => b.score - a.score);
128
- const topChildren = childScores.slice(0, Math.min(3, childScores.length));
129
- for (const { child, score } of topChildren) {
130
- if (score > 0.2) {
131
- const childPath = path ? `${path} > ${child.content.substring(0, 30)}` : child.content;
132
- const childResults = await guidedTraversal({
133
- tree,
134
- query,
135
- queryEmbedding,
136
- maxDepth,
137
- topK,
138
- currentNode: child,
139
- currentDepth: currentDepth + 1,
140
- path: childPath
141
- });
142
- results.push(...childResults);
143
- }
144
- }
145
- return results;
146
- }
147
- async function scoreNode(node, query, queryEmbedding) {
148
- if (node.embedding) {
149
- return cosineSimilarity(queryEmbedding, node.embedding);
150
- }
151
- const queryWords = query.toLowerCase().split(/\s+/);
152
- const nodeWords = node.content.toLowerCase().split(/\s+/);
153
- const overlap = queryWords.filter((w) => nodeWords.includes(w)).length;
154
- return overlap / queryWords.length;
155
- }
156
- function cosineSimilarity(a, b) {
157
- if (a.length !== b.length) return 0;
158
- let dotProduct = 0;
159
- let normA = 0;
160
- let normB = 0;
161
- for (let i = 0; i < a.length; i++) {
162
- dotProduct += a[i] * b[i];
163
- normA += a[i] * a[i];
164
- normB += b[i] * b[i];
165
- }
166
- return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
167
- }
168
- async function oracleResearch(params) {
169
- const { question, projectId, maxSteps = 5 } = params;
170
- const steps = [];
171
- let currentQuery = question;
172
- for (let step = 1; step <= maxSteps; step++) {
173
- console.log(`\u{1F52E} Oracle step ${step}: ${currentQuery}`);
174
- const results = await oracleSearch({
175
- query: currentQuery,
176
- projectId,
177
- topK: 5
178
- });
179
- const reasoning = await reasonAboutResults(currentQuery, results, question);
180
- steps.push({
181
- step,
182
- query: currentQuery,
183
- results,
184
- reasoning: reasoning.thought
185
- });
186
- if (reasoning.hasAnswer) {
187
- return {
188
- answer: reasoning.answer,
189
- steps
190
- };
191
- }
192
- currentQuery = reasoning.nextQuery || question;
193
- }
194
- const finalAnswer = await synthesizeAnswer(question, steps);
195
- return {
196
- answer: finalAnswer,
197
- steps
198
- };
199
- }
200
- async function reasonAboutResults(query, results, originalQuestion) {
201
- const prompt = `You are analyzing search results to answer a question.
202
-
203
- **Original question:** ${originalQuestion}
204
- **Current query:** ${query}
205
-
206
- **Search results:**
207
- ${results.map((r, i) => `${i + 1}. ${r.content} (relevance: ${r.relevance.toFixed(2)})`).join("\n")}
208
-
209
- Analyze these results:
210
- 1. Do they answer the original question?
211
- 2. What information is still missing?
212
- 3. What should be the next search query?
213
-
214
- Return JSON:
215
- {
216
- "thought": "your analysis",
217
- "hasAnswer": true or false,
218
- "answer": "the answer if you have it" or null,
219
- "nextQuery": "next search query" or null
220
- }`;
221
- const response = await anthropic.messages.create({
222
- model: "claude-sonnet-4-5-20250929",
223
- // Fixed: was "claude-sonnet-4.5" (wrong format)
224
- max_tokens: 1024,
225
- temperature: 0,
226
- messages: [{ role: "user", content: prompt }]
227
- });
228
- const text = response.content.find((c) => c.type === "text");
229
- if (!text || text.type !== "text") {
230
- return {
231
- thought: "Analysis failed",
232
- hasAnswer: false
233
- };
234
- }
235
- const jsonMatch = text.text.match(/```json\n?([\s\S]*?)\n?```/) || text.text.match(/\{[\s\S]*\}/);
236
- const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text.text;
237
- return JSON.parse(jsonStr);
238
- }
239
- async function synthesizeAnswer(question, steps) {
240
- const prompt = `Synthesize a final answer from multiple research steps.
241
-
242
- **Question:** ${question}
243
-
244
- **Research steps:**
245
- ${steps.map((s) => `Step ${s.step}: ${s.query}
246
- ${s.reasoning}`).join("\n\n")}
247
-
248
- Provide a comprehensive answer based on all the information gathered.`;
249
- const response = await anthropic.messages.create({
250
- model: "claude-sonnet-4-5-20250929",
251
- // Fixed: was "claude-sonnet-4.5" (wrong format)
252
- max_tokens: 2048,
253
- temperature: 0,
254
- messages: [{ role: "user", content: prompt }]
255
- });
256
- const text = response.content.find((c) => c.type === "text");
257
- return text && text.type === "text" ? text.text : "Unable to synthesize answer";
258
- }
259
- export {
260
- buildDocumentTree,
261
- oracleResearch,
262
- oracleSearch
263
- };
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/oracle.ts
11
+ var anthropic = new Anthropic({
12
+ apiKey: process.env.ANTHROPIC_API_KEY || ""
13
+ });
14
+ var MAX_DOCUMENT_CHUNKS = 500;
15
+ async function buildDocumentTree(documentId) {
16
+ const document = await db.document.findUnique({
17
+ where: { id: documentId },
18
+ include: {
19
+ chunks: {
20
+ orderBy: { chunkOrder: "asc" },
21
+ take: MAX_DOCUMENT_CHUNKS
22
+ }
23
+ }
24
+ });
25
+ if (!document) {
26
+ throw new Error("Document not found");
27
+ }
28
+ const root = {
29
+ id: document.id,
30
+ content: document.title,
31
+ type: "document",
32
+ children: [],
33
+ metadata: document.metadata
34
+ };
35
+ const sectionMap = /* @__PURE__ */ new Map();
36
+ for (const chunk of document.chunks) {
37
+ const sectionPath = chunk.metadata?.sectionPath || chunk.sectionPath || "root";
38
+ if (!sectionMap.has(sectionPath)) {
39
+ const sectionNode = {
40
+ id: `${documentId}::${sectionPath}`,
41
+ content: sectionPath,
42
+ type: "section",
43
+ children: [],
44
+ metadata: { path: sectionPath }
45
+ };
46
+ sectionMap.set(sectionPath, sectionNode);
47
+ root.children.push(sectionNode);
48
+ }
49
+ const section = sectionMap.get(sectionPath);
50
+ section.children.push({
51
+ id: chunk.id,
52
+ content: chunk.content,
53
+ type: "chunk",
54
+ children: [],
55
+ metadata: chunk.metadata,
56
+ embedding: chunk.embedding
57
+ });
58
+ }
59
+ return {
60
+ root,
61
+ depth: calculateDepth(root),
62
+ nodeCount: countNodes(root)
63
+ };
64
+ }
65
+ function calculateDepth(node) {
66
+ if (node.children.length === 0) return 1;
67
+ return 1 + Math.max(...node.children.map(calculateDepth));
68
+ }
69
+ function countNodes(node) {
70
+ return 1 + node.children.reduce((sum, child) => sum + countNodes(child), 0);
71
+ }
72
+ async function oracleSearch(params) {
73
+ const { query, projectId, topK = 5, maxDepth = 3 } = params;
74
+ console.log(`\u{1F52E} Oracle search: "${query}"`);
75
+ const queryEmbedding = await embedSingle(query);
76
+ const documents = await db.document.findMany({
77
+ where: { projectId },
78
+ take: 10
79
+ });
80
+ const results = [];
81
+ for (const doc of documents) {
82
+ const tree = await buildDocumentTree(doc.id);
83
+ const traversalResults = await guidedTraversal({
84
+ tree,
85
+ query,
86
+ queryEmbedding,
87
+ maxDepth,
88
+ topK
89
+ });
90
+ results.push(...traversalResults);
91
+ }
92
+ results.sort((a, b) => b.relevance - a.relevance);
93
+ return results.slice(0, topK);
94
+ }
95
+ async function guidedTraversal(params) {
96
+ const {
97
+ tree,
98
+ query,
99
+ queryEmbedding,
100
+ maxDepth,
101
+ topK,
102
+ currentNode = tree.root,
103
+ currentDepth = 0,
104
+ path = ""
105
+ } = params;
106
+ const results = [];
107
+ if (currentDepth >= maxDepth) {
108
+ return results;
109
+ }
110
+ if (currentNode.type === "chunk") {
111
+ const relevance = currentNode.embedding ? cosineSimilarity(queryEmbedding, currentNode.embedding) : 0;
112
+ if (relevance > 0.3) {
113
+ results.push({
114
+ content: currentNode.content,
115
+ path,
116
+ relevance
117
+ });
118
+ }
119
+ return results;
120
+ }
121
+ const childScores = await Promise.all(
122
+ currentNode.children.map(async (child) => {
123
+ const score = await scoreNode(child, query, queryEmbedding);
124
+ return { child, score };
125
+ })
126
+ );
127
+ childScores.sort((a, b) => b.score - a.score);
128
+ const topChildren = childScores.slice(0, Math.min(3, childScores.length));
129
+ for (const { child, score } of topChildren) {
130
+ if (score > 0.2) {
131
+ const childPath = path ? `${path} > ${child.content.substring(0, 30)}` : child.content;
132
+ const childResults = await guidedTraversal({
133
+ tree,
134
+ query,
135
+ queryEmbedding,
136
+ maxDepth,
137
+ topK,
138
+ currentNode: child,
139
+ currentDepth: currentDepth + 1,
140
+ path: childPath
141
+ });
142
+ results.push(...childResults);
143
+ }
144
+ }
145
+ return results;
146
+ }
147
+ async function scoreNode(node, query, queryEmbedding) {
148
+ if (node.embedding) {
149
+ return cosineSimilarity(queryEmbedding, node.embedding);
150
+ }
151
+ const queryWords = query.toLowerCase().split(/\s+/);
152
+ const nodeWords = node.content.toLowerCase().split(/\s+/);
153
+ const overlap = queryWords.filter((w) => nodeWords.includes(w)).length;
154
+ return overlap / queryWords.length;
155
+ }
156
+ function cosineSimilarity(a, b) {
157
+ if (a.length !== b.length) return 0;
158
+ let dotProduct = 0;
159
+ let normA = 0;
160
+ let normB = 0;
161
+ for (let i = 0; i < a.length; i++) {
162
+ dotProduct += a[i] * b[i];
163
+ normA += a[i] * a[i];
164
+ normB += b[i] * b[i];
165
+ }
166
+ return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
167
+ }
168
+ async function oracleResearch(params) {
169
+ const { question, projectId, maxSteps = 5 } = params;
170
+ const steps = [];
171
+ let currentQuery = question;
172
+ for (let step = 1; step <= maxSteps; step++) {
173
+ console.log(`\u{1F52E} Oracle step ${step}: ${currentQuery}`);
174
+ const results = await oracleSearch({
175
+ query: currentQuery,
176
+ projectId,
177
+ topK: 5
178
+ });
179
+ const reasoning = await reasonAboutResults(currentQuery, results, question);
180
+ steps.push({
181
+ step,
182
+ query: currentQuery,
183
+ results,
184
+ reasoning: reasoning.thought
185
+ });
186
+ if (reasoning.hasAnswer) {
187
+ return {
188
+ answer: reasoning.answer,
189
+ steps
190
+ };
191
+ }
192
+ currentQuery = reasoning.nextQuery || question;
193
+ }
194
+ const finalAnswer = await synthesizeAnswer(question, steps);
195
+ return {
196
+ answer: finalAnswer,
197
+ steps
198
+ };
199
+ }
200
+ async function reasonAboutResults(query, results, originalQuestion) {
201
+ const prompt = `You are analyzing search results to answer a question.
202
+
203
+ **Original question:** ${originalQuestion}
204
+ **Current query:** ${query}
205
+
206
+ **Search results:**
207
+ ${results.map((r, i) => `${i + 1}. ${r.content} (relevance: ${r.relevance.toFixed(2)})`).join("\n")}
208
+
209
+ Analyze these results:
210
+ 1. Do they answer the original question?
211
+ 2. What information is still missing?
212
+ 3. What should be the next search query?
213
+
214
+ Return JSON:
215
+ {
216
+ "thought": "your analysis",
217
+ "hasAnswer": true or false,
218
+ "answer": "the answer if you have it" or null,
219
+ "nextQuery": "next search query" or null
220
+ }`;
221
+ const response = await anthropic.messages.create({
222
+ model: "claude-sonnet-4-5-20250929",
223
+ // Fixed: was "claude-sonnet-4.5" (wrong format)
224
+ max_tokens: 1024,
225
+ temperature: 0,
226
+ messages: [{ role: "user", content: prompt }]
227
+ });
228
+ const text = response.content.find((c) => c.type === "text");
229
+ if (!text || text.type !== "text") {
230
+ return {
231
+ thought: "Analysis failed",
232
+ hasAnswer: false
233
+ };
234
+ }
235
+ const jsonMatch = text.text.match(/```json\n?([\s\S]*?)\n?```/) || text.text.match(/\{[\s\S]*\}/);
236
+ const jsonStr = jsonMatch ? jsonMatch[1] || jsonMatch[0] : text.text;
237
+ return JSON.parse(jsonStr);
238
+ }
239
+ async function synthesizeAnswer(question, steps) {
240
+ const prompt = `Synthesize a final answer from multiple research steps.
241
+
242
+ **Question:** ${question}
243
+
244
+ **Research steps:**
245
+ ${steps.map((s) => `Step ${s.step}: ${s.query}
246
+ ${s.reasoning}`).join("\n\n")}
247
+
248
+ Provide a comprehensive answer based on all the information gathered.`;
249
+ const response = await anthropic.messages.create({
250
+ model: "claude-sonnet-4-5-20250929",
251
+ // Fixed: was "claude-sonnet-4.5" (wrong format)
252
+ max_tokens: 2048,
253
+ temperature: 0,
254
+ messages: [{ role: "user", content: prompt }]
255
+ });
256
+ const text = response.content.find((c) => c.type === "text");
257
+ return text && text.type === "text" ? text.text : "Unable to synthesize answer";
258
+ }
259
+ export {
260
+ buildDocumentTree,
261
+ oracleResearch,
262
+ oracleSearch
263
+ };