mcp-perplexity-pro 1.1.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 (96) hide show
  1. package/README.md +638 -0
  2. package/bin/mcp-perplexity-pro +8 -0
  3. package/bin/mcp-perplexity-pro-stdio +9 -0
  4. package/dist/claude-code-bridge.d.ts +3 -0
  5. package/dist/claude-code-bridge.d.ts.map +1 -0
  6. package/dist/claude-code-bridge.js +111 -0
  7. package/dist/claude-code-bridge.js.map +1 -0
  8. package/dist/http-index.d.ts +3 -0
  9. package/dist/http-index.d.ts.map +1 -0
  10. package/dist/http-index.js +38 -0
  11. package/dist/http-index.js.map +1 -0
  12. package/dist/http-server.d.ts +33 -0
  13. package/dist/http-server.d.ts.map +1 -0
  14. package/dist/http-server.js +362 -0
  15. package/dist/http-server.js.map +1 -0
  16. package/dist/http-streaming-server.d.ts +4 -0
  17. package/dist/http-streaming-server.d.ts.map +1 -0
  18. package/dist/http-streaming-server.js +514 -0
  19. package/dist/http-streaming-server.js.map +1 -0
  20. package/dist/index.d.ts +3 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +43 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/launcher.d.ts +3 -0
  25. package/dist/launcher.d.ts.map +1 -0
  26. package/dist/launcher.js +209 -0
  27. package/dist/launcher.js.map +1 -0
  28. package/dist/mcp-server.d.ts +5 -0
  29. package/dist/mcp-server.d.ts.map +1 -0
  30. package/dist/mcp-server.js +329 -0
  31. package/dist/mcp-server.js.map +1 -0
  32. package/dist/models.d.ts +45 -0
  33. package/dist/models.d.ts.map +1 -0
  34. package/dist/models.js +284 -0
  35. package/dist/models.js.map +1 -0
  36. package/dist/perplexity-api.d.ts +59 -0
  37. package/dist/perplexity-api.d.ts.map +1 -0
  38. package/dist/perplexity-api.js +455 -0
  39. package/dist/perplexity-api.js.map +1 -0
  40. package/dist/port-utils.d.ts +31 -0
  41. package/dist/port-utils.d.ts.map +1 -0
  42. package/dist/port-utils.js +114 -0
  43. package/dist/port-utils.js.map +1 -0
  44. package/dist/project-manager.d.ts +91 -0
  45. package/dist/project-manager.d.ts.map +1 -0
  46. package/dist/project-manager.js +422 -0
  47. package/dist/project-manager.js.map +1 -0
  48. package/dist/simple-streaming.d.ts +26 -0
  49. package/dist/simple-streaming.d.ts.map +1 -0
  50. package/dist/simple-streaming.js +75 -0
  51. package/dist/simple-streaming.js.map +1 -0
  52. package/dist/sse-index.d.ts +3 -0
  53. package/dist/sse-index.d.ts.map +1 -0
  54. package/dist/sse-index.js +38 -0
  55. package/dist/sse-index.js.map +1 -0
  56. package/dist/sse-server.d.ts +4 -0
  57. package/dist/sse-server.d.ts.map +1 -0
  58. package/dist/sse-server.js +208 -0
  59. package/dist/sse-server.js.map +1 -0
  60. package/dist/stdio-bridge.d.ts +21 -0
  61. package/dist/stdio-bridge.d.ts.map +1 -0
  62. package/dist/stdio-bridge.js +157 -0
  63. package/dist/stdio-bridge.js.map +1 -0
  64. package/dist/stdio-server.d.ts +7 -0
  65. package/dist/stdio-server.d.ts.map +1 -0
  66. package/dist/stdio-server.js +396 -0
  67. package/dist/stdio-server.js.map +1 -0
  68. package/dist/storage.d.ts +65 -0
  69. package/dist/storage.d.ts.map +1 -0
  70. package/dist/storage.js +328 -0
  71. package/dist/storage.js.map +1 -0
  72. package/dist/streaming-wrapper.d.ts +63 -0
  73. package/dist/streaming-wrapper.d.ts.map +1 -0
  74. package/dist/streaming-wrapper.js +452 -0
  75. package/dist/streaming-wrapper.js.map +1 -0
  76. package/dist/tools/async.d.ts +28 -0
  77. package/dist/tools/async.d.ts.map +1 -0
  78. package/dist/tools/async.js +167 -0
  79. package/dist/tools/async.js.map +1 -0
  80. package/dist/tools/chat.d.ts +29 -0
  81. package/dist/tools/chat.d.ts.map +1 -0
  82. package/dist/tools/chat.js +233 -0
  83. package/dist/tools/chat.js.map +1 -0
  84. package/dist/tools/projects.d.ts +19 -0
  85. package/dist/tools/projects.d.ts.map +1 -0
  86. package/dist/tools/projects.js +219 -0
  87. package/dist/tools/projects.js.map +1 -0
  88. package/dist/tools/query.d.ts +13 -0
  89. package/dist/tools/query.d.ts.map +1 -0
  90. package/dist/tools/query.js +178 -0
  91. package/dist/tools/query.js.map +1 -0
  92. package/dist/types.d.ts +330 -0
  93. package/dist/types.d.ts.map +1 -0
  94. package/dist/types.js +90 -0
  95. package/dist/types.js.map +1 -0
  96. package/package.json +89 -0
@@ -0,0 +1,396 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Stdio-only entry point for Claude Desktop and other stdio-based MCP clients
4
+ * This bypasses the HTTP launcher and starts directly with stdio transport
5
+ */
6
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
9
+ import { configSchema } from './types.js';
10
+ import { handleAskPerplexity, handleResearchPerplexity } from './tools/query.js';
11
+ import { handleChatPerplexity, handleListChats, handleReadChat, handleStorageStats, } from './tools/chat.js';
12
+ import { handleAsyncPerplexity, handleCheckAsync, handleListAsyncJobs } from './tools/async.js';
13
+ import { handleListProjects, handleDeleteProject } from './tools/projects.js';
14
+ import { getModelSummary } from './models.js';
15
+ // Smart project root detection for MCP servers
16
+ function detectProjectRoot() {
17
+ const cwd = process.cwd();
18
+ // If we're running from filesystem root or system directories,
19
+ // use the user's home directory instead
20
+ if (cwd === '/' ||
21
+ cwd.startsWith('/usr/') ||
22
+ cwd.startsWith('/opt/') ||
23
+ cwd.startsWith('/var/')) {
24
+ return process.env.HOME || process.env.USERPROFILE || cwd;
25
+ }
26
+ // For other cases, use the current working directory
27
+ return cwd;
28
+ }
29
+ // Load configuration - try multiple sources for API key
30
+ const apiKey = process.env.PERPLEXITY_API_KEY || process.env.API_KEY || process.env.PERPLEXITY_API_TOKEN || '';
31
+ const config = {
32
+ api_key: apiKey,
33
+ default_model: process.env.DEFAULT_MODEL || 'sonar-reasoning-pro',
34
+ project_root: process.env.PROJECT_ROOT || detectProjectRoot(),
35
+ storage_path: process.env.STORAGE_PATH || '.perplexity',
36
+ session_id: process.env.SESSION_ID,
37
+ };
38
+ // Validate configuration
39
+ const validatedConfig = configSchema.parse(config);
40
+ // Create MCP server
41
+ const server = new Server({
42
+ name: 'mcp-perplexity-pro',
43
+ version: '1.0.0',
44
+ }, {
45
+ capabilities: {
46
+ tools: {},
47
+ progress: true,
48
+ },
49
+ });
50
+ // Register tools
51
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
52
+ return {
53
+ tools: [
54
+ {
55
+ name: 'ask_perplexity',
56
+ description: 'Query Perplexity AI with intelligent model selection for your questions.',
57
+ inputSchema: {
58
+ type: 'object',
59
+ properties: {
60
+ query: { type: 'string', description: 'Your question or prompt' },
61
+ project_name: {
62
+ type: 'string',
63
+ description: 'Project name for organizing data (auto-detected if not provided)',
64
+ },
65
+ model: {
66
+ type: 'string',
67
+ enum: [
68
+ 'sonar',
69
+ 'sonar-pro',
70
+ 'sonar-reasoning',
71
+ 'sonar-reasoning-pro',
72
+ 'sonar-deep-research',
73
+ ],
74
+ description: 'Override default model selection',
75
+ },
76
+ temperature: {
77
+ type: 'number',
78
+ minimum: 0,
79
+ maximum: 1,
80
+ description: 'Sampling temperature (0.0-1.0, default: 0.2)',
81
+ },
82
+ max_tokens: { type: 'number', minimum: 1, description: 'Maximum response length' },
83
+ save_report: { type: 'boolean', description: 'Save response to project directory' },
84
+ },
85
+ required: ['query'],
86
+ },
87
+ },
88
+ {
89
+ name: 'research_perplexity',
90
+ description: 'Conduct comprehensive research with Perplexity and save detailed reports.',
91
+ inputSchema: {
92
+ type: 'object',
93
+ properties: {
94
+ topic: { type: 'string', description: 'Research topic or question' },
95
+ project_name: {
96
+ type: 'string',
97
+ description: 'Project name for organizing reports (auto-detected if not provided)',
98
+ },
99
+ model: {
100
+ type: 'string',
101
+ enum: [
102
+ 'sonar',
103
+ 'sonar-pro',
104
+ 'sonar-reasoning',
105
+ 'sonar-reasoning-pro',
106
+ 'sonar-deep-research',
107
+ ],
108
+ description: 'Defaults to sonar-deep-research for comprehensive research',
109
+ },
110
+ save_report: { type: 'boolean', description: 'Save research report (default: true)' },
111
+ },
112
+ required: ['topic'],
113
+ },
114
+ },
115
+ {
116
+ name: 'chat_perplexity',
117
+ description: 'Maintain conversations with Perplexity stored in project directory.',
118
+ inputSchema: {
119
+ type: 'object',
120
+ properties: {
121
+ message: { type: 'string', description: 'Your message' },
122
+ project_name: {
123
+ type: 'string',
124
+ description: 'Project name for organizing conversations (auto-detected if not provided)',
125
+ },
126
+ chat_id: { type: 'string', description: 'Continue existing conversation' },
127
+ title: { type: 'string', description: 'Required for new chat - conversation title' },
128
+ model: {
129
+ type: 'string',
130
+ enum: [
131
+ 'sonar',
132
+ 'sonar-pro',
133
+ 'sonar-reasoning',
134
+ 'sonar-reasoning-pro',
135
+ 'sonar-deep-research',
136
+ ],
137
+ description: 'Override default model',
138
+ },
139
+ temperature: {
140
+ type: 'number',
141
+ minimum: 0,
142
+ maximum: 1,
143
+ description: '0.0-1.0, default 0.2',
144
+ },
145
+ max_tokens: { type: 'number', minimum: 1, description: 'Maximum response length' },
146
+ save_report: { type: 'boolean', description: 'Save conversation to project directory' },
147
+ },
148
+ required: ['message'],
149
+ },
150
+ },
151
+ {
152
+ name: 'async_perplexity',
153
+ description: 'Create async jobs for complex queries that may take longer to process.',
154
+ inputSchema: {
155
+ type: 'object',
156
+ properties: {
157
+ query: { type: 'string', description: 'Your question or prompt' },
158
+ model: {
159
+ type: 'string',
160
+ enum: [
161
+ 'sonar',
162
+ 'sonar-pro',
163
+ 'sonar-reasoning',
164
+ 'sonar-reasoning-pro',
165
+ 'sonar-deep-research',
166
+ ],
167
+ description: 'Override default model',
168
+ },
169
+ project_name: {
170
+ type: 'string',
171
+ description: 'Project name for organizing data (auto-detected if not provided)',
172
+ },
173
+ },
174
+ required: ['query'],
175
+ },
176
+ },
177
+ {
178
+ name: 'check_async_perplexity',
179
+ description: 'Check the status of an async job and retrieve results if complete.',
180
+ inputSchema: {
181
+ type: 'object',
182
+ properties: {
183
+ job_id: { type: 'string', description: 'Job ID returned from async_perplexity' },
184
+ },
185
+ required: ['job_id'],
186
+ },
187
+ },
188
+ {
189
+ name: 'list_async_jobs',
190
+ description: 'List all async jobs and their current status.',
191
+ inputSchema: {
192
+ type: 'object',
193
+ properties: {
194
+ limit: {
195
+ type: 'number',
196
+ minimum: 1,
197
+ maximum: 50,
198
+ description: 'Number of jobs to return',
199
+ },
200
+ project_name: {
201
+ type: 'string',
202
+ description: 'Filter by project (auto-detected if not provided)',
203
+ },
204
+ },
205
+ },
206
+ },
207
+ {
208
+ name: 'list_chats_perplexity',
209
+ description: 'List all stored conversations in your project.',
210
+ inputSchema: {
211
+ type: 'object',
212
+ properties: {
213
+ project_name: {
214
+ type: 'string',
215
+ description: 'Project name to list chats from (auto-detected if not provided)',
216
+ },
217
+ },
218
+ },
219
+ },
220
+ {
221
+ name: 'read_chat_perplexity',
222
+ description: 'Read the full conversation history from a stored chat.',
223
+ inputSchema: {
224
+ type: 'object',
225
+ properties: {
226
+ chat_id: { type: 'string', description: 'Chat ID to retrieve' },
227
+ project_name: {
228
+ type: 'string',
229
+ description: 'Project name (auto-detected if not provided)',
230
+ },
231
+ },
232
+ required: ['chat_id'],
233
+ },
234
+ },
235
+ {
236
+ name: 'storage_stats_perplexity',
237
+ description: 'Get storage usage statistics for your projects.',
238
+ inputSchema: {
239
+ type: 'object',
240
+ properties: {
241
+ project_name: {
242
+ type: 'string',
243
+ description: 'Specific project to analyze (all projects if not provided)',
244
+ },
245
+ },
246
+ },
247
+ },
248
+ {
249
+ name: 'list_projects_perplexity',
250
+ description: 'List all projects with their conversation and report counts.',
251
+ inputSchema: {
252
+ type: 'object',
253
+ properties: {},
254
+ },
255
+ },
256
+ {
257
+ name: 'delete_project_perplexity',
258
+ description: 'Safely delete a project and all its data after confirmation.',
259
+ inputSchema: {
260
+ type: 'object',
261
+ properties: {
262
+ project_name: { type: 'string', description: 'Project name to delete' },
263
+ confirm: {
264
+ type: 'boolean',
265
+ description: 'Must be true to confirm deletion - this action cannot be undone',
266
+ },
267
+ },
268
+ required: ['project_name', 'confirm'],
269
+ },
270
+ },
271
+ {
272
+ name: 'model_info_perplexity',
273
+ description: 'Get information about available Perplexity models and selection guidance.',
274
+ inputSchema: {
275
+ type: 'object',
276
+ properties: {},
277
+ },
278
+ },
279
+ ],
280
+ };
281
+ });
282
+ // Register tool call handler
283
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
284
+ const { name, arguments: args } = request.params;
285
+ try {
286
+ switch (name) {
287
+ case 'ask_perplexity': {
288
+ const result = await handleAskPerplexity(args, validatedConfig);
289
+ return {
290
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
291
+ };
292
+ }
293
+ case 'research_perplexity': {
294
+ const result = await handleResearchPerplexity(args, validatedConfig);
295
+ return {
296
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
297
+ };
298
+ }
299
+ case 'chat_perplexity': {
300
+ const result = await handleChatPerplexity(args, validatedConfig);
301
+ return {
302
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
303
+ };
304
+ }
305
+ case 'list_chats_perplexity': {
306
+ const result = await handleListChats(validatedConfig);
307
+ return {
308
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
309
+ };
310
+ }
311
+ case 'read_chat_perplexity': {
312
+ const result = await handleReadChat(args, validatedConfig);
313
+ return {
314
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
315
+ };
316
+ }
317
+ case 'async_perplexity': {
318
+ const result = await handleAsyncPerplexity(args, validatedConfig);
319
+ return {
320
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
321
+ };
322
+ }
323
+ case 'check_async_perplexity': {
324
+ const result = await handleCheckAsync(args, validatedConfig);
325
+ return {
326
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
327
+ };
328
+ }
329
+ case 'list_async_jobs': {
330
+ const jobArgs = args;
331
+ const result = await handleListAsyncJobs(validatedConfig, jobArgs?.limit, jobArgs?.next_token);
332
+ return {
333
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
334
+ };
335
+ }
336
+ case 'storage_stats_perplexity': {
337
+ const result = await handleStorageStats(validatedConfig);
338
+ return {
339
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
340
+ };
341
+ }
342
+ case 'list_projects_perplexity': {
343
+ const result = await handleListProjects(args, validatedConfig);
344
+ return {
345
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
346
+ };
347
+ }
348
+ case 'delete_project_perplexity': {
349
+ const result = await handleDeleteProject(args, validatedConfig);
350
+ return {
351
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
352
+ };
353
+ }
354
+ case 'model_info_perplexity': {
355
+ const modelInfo = {
356
+ available_models: getModelSummary(),
357
+ default_model: validatedConfig.default_model,
358
+ automatic_selection: 'Enabled - models selected based on query complexity and requirements',
359
+ override_capability: 'All tools accept optional "model" parameter to override automatic selection',
360
+ selection_factors: [
361
+ 'Query complexity and length',
362
+ 'Keywords indicating specific needs (research, analysis, etc.)',
363
+ 'Task type (facts vs reasoning vs research)',
364
+ 'Performance vs cost trade-offs',
365
+ ],
366
+ };
367
+ return {
368
+ content: [{ type: 'text', text: JSON.stringify(modelInfo, null, 2) }],
369
+ };
370
+ }
371
+ default:
372
+ throw new Error(`Unknown tool: ${name}`);
373
+ }
374
+ }
375
+ catch (error) {
376
+ return {
377
+ content: [
378
+ {
379
+ type: 'text',
380
+ text: `Error: ${error instanceof Error ? error.message : String(error)}`,
381
+ },
382
+ ],
383
+ isError: true,
384
+ };
385
+ }
386
+ });
387
+ // Start the server
388
+ async function main() {
389
+ const transport = new StdioServerTransport();
390
+ await server.connect(transport);
391
+ }
392
+ main().catch(error => {
393
+ console.error('Failed to start stdio MCP server:', error);
394
+ process.exit(1);
395
+ });
396
+ //# sourceMappingURL=stdio-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio-server.js","sourceRoot":"","sources":["../src/stdio-server.ts"],"names":[],"mappings":";AAEA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,+CAA+C;AAC/C,SAAS,iBAAiB;IACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAE1B,+DAA+D;IAC/D,wCAAwC;IACxC,IACE,GAAG,KAAK,GAAG;QACX,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC;QACvB,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC;QACvB,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EACvB,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC;IAC5D,CAAC;IAED,qDAAqD;IACrD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,wDAAwD;AACxD,MAAM,MAAM,GACV,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,O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AC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;iBACzE;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,mBAAmB;AACnB,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;IAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { Config, Conversation, ChatMetadata, Message, PerplexityModel, ErrorResponse } from './types.js';
2
+ export declare class StorageError extends Error {
3
+ code?: string | undefined;
4
+ constructor(message: string, code?: string | undefined);
5
+ }
6
+ export declare class StorageManager {
7
+ private projectRoot;
8
+ private storagePath;
9
+ private sessionId?;
10
+ constructor(config: Config);
11
+ /**
12
+ * Ensures the storage directory exists
13
+ */
14
+ private ensureStorageDirectory;
15
+ /**
16
+ * Gets the full path for a conversation file
17
+ */
18
+ private getConversationPath;
19
+ /**
20
+ * Gets the path for a research report
21
+ */
22
+ private getReportPath;
23
+ /**
24
+ * Executes a function with file locking for thread safety
25
+ */
26
+ private withLock;
27
+ /**
28
+ * Creates a new conversation
29
+ */
30
+ createConversation(title: string, model: PerplexityModel, initialMessage?: Message): Promise<string>;
31
+ /**
32
+ * Adds a message to an existing conversation
33
+ */
34
+ addMessage(chatId: string, message: Message): Promise<void>;
35
+ /**
36
+ * Retrieves a conversation by ID
37
+ */
38
+ getConversation(chatId: string): Promise<Conversation>;
39
+ /**
40
+ * Lists all conversations in the current project
41
+ */
42
+ listConversations(): Promise<ChatMetadata[]>;
43
+ /**
44
+ * Deletes a conversation
45
+ */
46
+ deleteConversation(chatId: string): Promise<void>;
47
+ /**
48
+ * Saves a research report to the project directory
49
+ */
50
+ saveReport(content: string, title: string): Promise<string>;
51
+ /**
52
+ * Gets storage statistics for the current project
53
+ */
54
+ getStorageStats(): Promise<{
55
+ total_conversations: number;
56
+ total_messages: number;
57
+ storage_size_bytes: number;
58
+ last_activity: string | null;
59
+ }>;
60
+ /**
61
+ * Handles storage errors and creates structured error responses
62
+ */
63
+ static handleError(error: unknown): ErrorResponse;
64
+ }
65
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,eAAe,EACf,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAa,SAAQ,KAAK;IAG5B,IAAI,CAAC,EAAE,MAAM;gBADpB,OAAO,EAAE,MAAM,EACR,IAAI,CAAC,EAAE,MAAM,YAAA;CAKvB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAC,CAAS;gBAEf,MAAM,EAAE,MAAM;IAQ1B;;OAEG;YACW,sBAAsB;IAWpC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;OAEG;IACH,OAAO,CAAC,aAAa;IAOrB;;OAEG;YACW,QAAQ;IAsCtB;;OAEG;IACG,kBAAkB,CACtB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,EACtB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC,MAAM,CAAC;IA2BlB;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBjE;;OAEG;IACG,eAAe,CAA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