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.
- package/README.md +638 -0
- package/bin/mcp-perplexity-pro +8 -0
- package/bin/mcp-perplexity-pro-stdio +9 -0
- package/dist/claude-code-bridge.d.ts +3 -0
- package/dist/claude-code-bridge.d.ts.map +1 -0
- package/dist/claude-code-bridge.js +111 -0
- package/dist/claude-code-bridge.js.map +1 -0
- package/dist/http-index.d.ts +3 -0
- package/dist/http-index.d.ts.map +1 -0
- package/dist/http-index.js +38 -0
- package/dist/http-index.js.map +1 -0
- package/dist/http-server.d.ts +33 -0
- package/dist/http-server.d.ts.map +1 -0
- package/dist/http-server.js +362 -0
- package/dist/http-server.js.map +1 -0
- package/dist/http-streaming-server.d.ts +4 -0
- package/dist/http-streaming-server.d.ts.map +1 -0
- package/dist/http-streaming-server.js +514 -0
- package/dist/http-streaming-server.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +3 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +209 -0
- package/dist/launcher.js.map +1 -0
- package/dist/mcp-server.d.ts +5 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +329 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/models.d.ts +45 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +284 -0
- package/dist/models.js.map +1 -0
- package/dist/perplexity-api.d.ts +59 -0
- package/dist/perplexity-api.d.ts.map +1 -0
- package/dist/perplexity-api.js +455 -0
- package/dist/perplexity-api.js.map +1 -0
- package/dist/port-utils.d.ts +31 -0
- package/dist/port-utils.d.ts.map +1 -0
- package/dist/port-utils.js +114 -0
- package/dist/port-utils.js.map +1 -0
- package/dist/project-manager.d.ts +91 -0
- package/dist/project-manager.d.ts.map +1 -0
- package/dist/project-manager.js +422 -0
- package/dist/project-manager.js.map +1 -0
- package/dist/simple-streaming.d.ts +26 -0
- package/dist/simple-streaming.d.ts.map +1 -0
- package/dist/simple-streaming.js +75 -0
- package/dist/simple-streaming.js.map +1 -0
- package/dist/sse-index.d.ts +3 -0
- package/dist/sse-index.d.ts.map +1 -0
- package/dist/sse-index.js +38 -0
- package/dist/sse-index.js.map +1 -0
- package/dist/sse-server.d.ts +4 -0
- package/dist/sse-server.d.ts.map +1 -0
- package/dist/sse-server.js +208 -0
- package/dist/sse-server.js.map +1 -0
- package/dist/stdio-bridge.d.ts +21 -0
- package/dist/stdio-bridge.d.ts.map +1 -0
- package/dist/stdio-bridge.js +157 -0
- package/dist/stdio-bridge.js.map +1 -0
- package/dist/stdio-server.d.ts +7 -0
- package/dist/stdio-server.d.ts.map +1 -0
- package/dist/stdio-server.js +396 -0
- package/dist/stdio-server.js.map +1 -0
- package/dist/storage.d.ts +65 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +328 -0
- package/dist/storage.js.map +1 -0
- package/dist/streaming-wrapper.d.ts +63 -0
- package/dist/streaming-wrapper.d.ts.map +1 -0
- package/dist/streaming-wrapper.js +452 -0
- package/dist/streaming-wrapper.js.map +1 -0
- package/dist/tools/async.d.ts +28 -0
- package/dist/tools/async.d.ts.map +1 -0
- package/dist/tools/async.js +167 -0
- package/dist/tools/async.js.map +1 -0
- package/dist/tools/chat.d.ts +29 -0
- package/dist/tools/chat.d.ts.map +1 -0
- package/dist/tools/chat.js +233 -0
- package/dist/tools/chat.js.map +1 -0
- package/dist/tools/projects.d.ts +19 -0
- package/dist/tools/projects.d.ts.map +1 -0
- package/dist/tools/projects.js +219 -0
- package/dist/tools/projects.js.map +1 -0
- package/dist/tools/query.d.ts +13 -0
- package/dist/tools/query.d.ts.map +1 -0
- package/dist/tools/query.js +178 -0
- package/dist/tools/query.js.map +1 -0
- package/dist/types.d.ts +330 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +90 -0
- package/dist/types.js.map +1 -0
- package/package.json +89 -0
package/dist/storage.js
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import lockfile from 'proper-lockfile';
|
|
5
|
+
export class StorageError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(message, code) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = 'StorageError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class StorageManager {
|
|
14
|
+
projectRoot;
|
|
15
|
+
storagePath;
|
|
16
|
+
sessionId;
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.projectRoot = config.project_root;
|
|
19
|
+
this.storagePath = path.join(config.project_root, config.storage_path);
|
|
20
|
+
if (config.session_id) {
|
|
21
|
+
this.sessionId = config.session_id;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Ensures the storage directory exists
|
|
26
|
+
*/
|
|
27
|
+
async ensureStorageDirectory() {
|
|
28
|
+
try {
|
|
29
|
+
await fs.mkdir(this.storagePath, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new StorageError(`Failed to create storage directory: ${this.storagePath}`, 'STORAGE_INIT_ERROR');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the full path for a conversation file
|
|
37
|
+
*/
|
|
38
|
+
getConversationPath(chatId) {
|
|
39
|
+
// Include session ID if provided for multi-session support
|
|
40
|
+
const filename = this.sessionId ? `${this.sessionId}_${chatId}.json` : `${chatId}.json`;
|
|
41
|
+
return path.join(this.storagePath, filename);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the path for a research report
|
|
45
|
+
*/
|
|
46
|
+
getReportPath(reportId) {
|
|
47
|
+
const filename = this.sessionId
|
|
48
|
+
? `${this.sessionId}_report_${reportId}.md`
|
|
49
|
+
: `report_${reportId}.md`;
|
|
50
|
+
return path.join(this.storagePath, filename);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Executes a function with file locking for thread safety
|
|
54
|
+
*/
|
|
55
|
+
async withLock(filePath, operation) {
|
|
56
|
+
try {
|
|
57
|
+
// Ensure directory exists for both the file and lock
|
|
58
|
+
const fileDir = path.dirname(filePath);
|
|
59
|
+
await fs.mkdir(fileDir, { recursive: true });
|
|
60
|
+
// Ensure the target file exists (create empty file if it doesn't exist)
|
|
61
|
+
// This is needed for proper-lockfile to work correctly
|
|
62
|
+
try {
|
|
63
|
+
await fs.access(filePath);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// File doesn't exist, create empty file
|
|
67
|
+
await fs.writeFile(filePath, '', 'utf-8');
|
|
68
|
+
}
|
|
69
|
+
// Acquire lock with timeout
|
|
70
|
+
await lockfile.lock(filePath, {
|
|
71
|
+
stale: 10000, // 10 seconds
|
|
72
|
+
retries: 3,
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
return await operation();
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
// Always release the lock
|
|
79
|
+
await lockfile.unlock(filePath);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof Error && error.message.includes('EEXIST')) {
|
|
84
|
+
throw new StorageError('Storage operation timed out - another process may be accessing the file', 'LOCK_TIMEOUT');
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new conversation
|
|
91
|
+
*/
|
|
92
|
+
async createConversation(title, model, initialMessage) {
|
|
93
|
+
await this.ensureStorageDirectory();
|
|
94
|
+
const chatId = uuidv4();
|
|
95
|
+
const now = new Date().toISOString();
|
|
96
|
+
const conversation = {
|
|
97
|
+
metadata: {
|
|
98
|
+
id: chatId,
|
|
99
|
+
title,
|
|
100
|
+
created_at: now,
|
|
101
|
+
updated_at: now,
|
|
102
|
+
message_count: initialMessage ? 1 : 0,
|
|
103
|
+
model,
|
|
104
|
+
},
|
|
105
|
+
messages: initialMessage ? [initialMessage] : [],
|
|
106
|
+
};
|
|
107
|
+
const filePath = this.getConversationPath(chatId);
|
|
108
|
+
await this.withLock(filePath, async () => {
|
|
109
|
+
await fs.writeFile(filePath, JSON.stringify(conversation, null, 2), 'utf-8');
|
|
110
|
+
});
|
|
111
|
+
return chatId;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Adds a message to an existing conversation
|
|
115
|
+
*/
|
|
116
|
+
async addMessage(chatId, message) {
|
|
117
|
+
const filePath = this.getConversationPath(chatId);
|
|
118
|
+
await this.withLock(filePath, async () => {
|
|
119
|
+
try {
|
|
120
|
+
const data = await fs.readFile(filePath, 'utf-8');
|
|
121
|
+
const conversation = JSON.parse(data);
|
|
122
|
+
conversation.messages.push(message);
|
|
123
|
+
conversation.metadata.updated_at = new Date().toISOString();
|
|
124
|
+
conversation.metadata.message_count = conversation.messages.length;
|
|
125
|
+
await fs.writeFile(filePath, JSON.stringify(conversation, null, 2), 'utf-8');
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (error instanceof Error && error.message.includes('ENOENT')) {
|
|
129
|
+
throw new StorageError(`Conversation not found: ${chatId}`, 'CONVERSATION_NOT_FOUND');
|
|
130
|
+
}
|
|
131
|
+
throw new StorageError(`Failed to add message to conversation: ${chatId}`, 'WRITE_ERROR');
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Retrieves a conversation by ID
|
|
137
|
+
*/
|
|
138
|
+
async getConversation(chatId) {
|
|
139
|
+
const filePath = this.getConversationPath(chatId);
|
|
140
|
+
try {
|
|
141
|
+
const data = await fs.readFile(filePath, 'utf-8');
|
|
142
|
+
return JSON.parse(data);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (error instanceof Error && error.message.includes('ENOENT')) {
|
|
146
|
+
throw new StorageError(`Conversation not found: ${chatId}`, 'CONVERSATION_NOT_FOUND');
|
|
147
|
+
}
|
|
148
|
+
throw new StorageError(`Failed to read conversation: ${chatId}`, 'READ_ERROR');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Lists all conversations in the current project
|
|
153
|
+
*/
|
|
154
|
+
async listConversations() {
|
|
155
|
+
await this.ensureStorageDirectory();
|
|
156
|
+
try {
|
|
157
|
+
const files = await fs.readdir(this.storagePath);
|
|
158
|
+
const conversations = [];
|
|
159
|
+
// Filter for conversation files (not reports)
|
|
160
|
+
const conversationFiles = files.filter(file => {
|
|
161
|
+
if (this.sessionId) {
|
|
162
|
+
return (file.startsWith(`${this.sessionId}_`) &&
|
|
163
|
+
file.endsWith('.json') &&
|
|
164
|
+
!file.includes('report_'));
|
|
165
|
+
}
|
|
166
|
+
return file.endsWith('.json') && !file.includes('report_');
|
|
167
|
+
});
|
|
168
|
+
// Read metadata from each conversation
|
|
169
|
+
for (const file of conversationFiles) {
|
|
170
|
+
try {
|
|
171
|
+
const filePath = path.join(this.storagePath, file);
|
|
172
|
+
const data = await fs.readFile(filePath, 'utf-8');
|
|
173
|
+
const conversation = JSON.parse(data);
|
|
174
|
+
conversations.push(conversation.metadata);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
// Skip corrupted files but don't fail the entire operation
|
|
178
|
+
console.warn(`Warning: Could not read conversation file ${file}:`, error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Sort by updated_at descending (most recent first)
|
|
182
|
+
return conversations.sort((a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime());
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
throw new StorageError('Failed to list conversations', 'LIST_ERROR');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Deletes a conversation
|
|
190
|
+
*/
|
|
191
|
+
async deleteConversation(chatId) {
|
|
192
|
+
const filePath = this.getConversationPath(chatId);
|
|
193
|
+
try {
|
|
194
|
+
await fs.unlink(filePath);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (error instanceof Error && error.message.includes('ENOENT')) {
|
|
198
|
+
throw new StorageError(`Conversation not found: ${chatId}`, 'CONVERSATION_NOT_FOUND');
|
|
199
|
+
}
|
|
200
|
+
throw new StorageError(`Failed to delete conversation: ${chatId}`, 'DELETE_ERROR');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Saves a research report to the project directory
|
|
205
|
+
*/
|
|
206
|
+
async saveReport(content, title) {
|
|
207
|
+
await this.ensureStorageDirectory();
|
|
208
|
+
const reportId = uuidv4();
|
|
209
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
210
|
+
const filename = `${timestamp}_${title.replace(/[^a-zA-Z0-9]/g, '_')}.md`;
|
|
211
|
+
const reportPath = path.join(this.storagePath, filename);
|
|
212
|
+
const reportContent = `# ${title}
|
|
213
|
+
|
|
214
|
+
**Generated:** ${new Date().toLocaleString()}
|
|
215
|
+
**Report ID:** ${reportId}
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
${content}
|
|
220
|
+
`;
|
|
221
|
+
try {
|
|
222
|
+
await fs.writeFile(reportPath, reportContent, 'utf-8');
|
|
223
|
+
return reportId;
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
throw new StorageError('Failed to save research report', 'SAVE_REPORT_ERROR');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Gets storage statistics for the current project
|
|
231
|
+
*/
|
|
232
|
+
async getStorageStats() {
|
|
233
|
+
await this.ensureStorageDirectory();
|
|
234
|
+
try {
|
|
235
|
+
const conversations = await this.listConversations();
|
|
236
|
+
let totalMessages = 0;
|
|
237
|
+
let storageSize = 0;
|
|
238
|
+
let lastActivity = null;
|
|
239
|
+
// Calculate total messages and find last activity
|
|
240
|
+
for (const conv of conversations) {
|
|
241
|
+
totalMessages += conv.message_count;
|
|
242
|
+
if (!lastActivity || new Date(conv.updated_at) > new Date(lastActivity)) {
|
|
243
|
+
lastActivity = conv.updated_at;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// Calculate storage size
|
|
247
|
+
const files = await fs.readdir(this.storagePath);
|
|
248
|
+
for (const file of files) {
|
|
249
|
+
try {
|
|
250
|
+
const filePath = path.join(this.storagePath, file);
|
|
251
|
+
const stats = await fs.stat(filePath);
|
|
252
|
+
storageSize += stats.size;
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
// Skip files we can't access
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
total_conversations: conversations.length,
|
|
260
|
+
total_messages: totalMessages,
|
|
261
|
+
storage_size_bytes: storageSize,
|
|
262
|
+
last_activity: lastActivity,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
throw new StorageError('Failed to get storage statistics', 'STATS_ERROR');
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Handles storage errors and creates structured error responses
|
|
271
|
+
*/
|
|
272
|
+
static handleError(error) {
|
|
273
|
+
if (error instanceof StorageError) {
|
|
274
|
+
switch (error.code) {
|
|
275
|
+
case 'CONVERSATION_NOT_FOUND':
|
|
276
|
+
return {
|
|
277
|
+
error: {
|
|
278
|
+
type: 'storage_error',
|
|
279
|
+
message: error.message,
|
|
280
|
+
details: {
|
|
281
|
+
suggestion: 'Check the conversation ID and try again, or list conversations to see available IDs',
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
case 'LOCK_TIMEOUT':
|
|
286
|
+
return {
|
|
287
|
+
error: {
|
|
288
|
+
type: 'storage_error',
|
|
289
|
+
message: error.message,
|
|
290
|
+
details: {
|
|
291
|
+
suggestion: 'Try again in a moment - another operation may be in progress',
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
case 'STORAGE_INIT_ERROR':
|
|
296
|
+
return {
|
|
297
|
+
error: {
|
|
298
|
+
type: 'storage_error',
|
|
299
|
+
message: error.message,
|
|
300
|
+
details: {
|
|
301
|
+
suggestion: 'Check that the project_root path exists and is writable',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
default:
|
|
306
|
+
return {
|
|
307
|
+
error: {
|
|
308
|
+
type: 'storage_error',
|
|
309
|
+
message: error.message,
|
|
310
|
+
details: {
|
|
311
|
+
suggestion: 'Check file permissions and available disk space',
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
error: {
|
|
319
|
+
type: 'storage_error',
|
|
320
|
+
message: error instanceof Error ? error.message : 'Unknown storage error',
|
|
321
|
+
details: {
|
|
322
|
+
suggestion: 'Check the storage path configuration and file permissions',
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAUvC,MAAM,OAAO,YAAa,SAAQ,KAAK;IAG5B;IAFT,YACE,OAAe,EACR,IAAa;QAEpB,KAAK,CAAC,OAAO,CAA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AAC,OAAO;4BACtB,OAAO,EAAE;gCACP,UAAU,EAAE,yDAAyD;6BACtE;yBACF;qBACF,CAAC;gBAEJ;oBACE,OAAO;wBACL,KAAK,EAAE;4BACL,IAAI,EAAE,eAAe;4BACrB,OAAO,EAAE,KAAK,CAAC,OAAO;4BACtB,OAAO,EAAE;gCACP,UAAU,EAAE,iDAAiD;6BAC9D;yBACF;qBACF,CAAC;YACN,CAAC;QACH,CAAC;QAED,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;gBACzE,OAAO,EAAE;oBACP,UAAU,EAAE,2DAA2D;iBACxE;aACF;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import type { Config } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Universal async tool wrapper that creates async jobs and streams progress to Claude Code
|
|
5
|
+
*/
|
|
6
|
+
export declare class StreamingWrapper {
|
|
7
|
+
private server;
|
|
8
|
+
private config;
|
|
9
|
+
constructor(server: Server, config: Config);
|
|
10
|
+
/**
|
|
11
|
+
* Execute a tool call with streaming content updates (not just progress)
|
|
12
|
+
*/
|
|
13
|
+
executeWithStreaming(toolName: string, params: any, progressToken?: string | number): Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* Create async job based on tool type
|
|
16
|
+
*/
|
|
17
|
+
private createAsyncJob;
|
|
18
|
+
/**
|
|
19
|
+
* Execute tool synchronously (fallback for no progress token)
|
|
20
|
+
*/
|
|
21
|
+
private executeSynchronously;
|
|
22
|
+
/**
|
|
23
|
+
* Start streaming actual content from async job (not just progress)
|
|
24
|
+
*/
|
|
25
|
+
private startContentStreaming;
|
|
26
|
+
/**
|
|
27
|
+
* Stream a chunk of content to Claude Code
|
|
28
|
+
*/
|
|
29
|
+
private streamContentChunk;
|
|
30
|
+
/**
|
|
31
|
+
* Legacy method - keeping for backwards compatibility
|
|
32
|
+
*/
|
|
33
|
+
private startProgressStreaming;
|
|
34
|
+
/**
|
|
35
|
+
* Send progress notification to Claude Code
|
|
36
|
+
*/
|
|
37
|
+
private sendProgressNotification;
|
|
38
|
+
/**
|
|
39
|
+
* Handle job completion and send final result
|
|
40
|
+
*/
|
|
41
|
+
private handleJobCompletion;
|
|
42
|
+
/**
|
|
43
|
+
* Handle job failure
|
|
44
|
+
*/
|
|
45
|
+
private handleJobFailure;
|
|
46
|
+
/**
|
|
47
|
+
* Process completed job based on tool type
|
|
48
|
+
*/
|
|
49
|
+
private processCompletedJob;
|
|
50
|
+
/**
|
|
51
|
+
* Get status message for progress updates
|
|
52
|
+
*/
|
|
53
|
+
private getStatusMessage;
|
|
54
|
+
/**
|
|
55
|
+
* Cancel streaming for a job
|
|
56
|
+
*/
|
|
57
|
+
cancelStreaming(jobId: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Get active streaming jobs
|
|
60
|
+
*/
|
|
61
|
+
getActiveStreams(): string[];
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=streaming-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-wrapper.d.ts","sourceRoot":"","sources":["../src/streaming-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGxE,OAAO,KAAK,EAAE,MAAM,EAA2B,MAAM,YAAY,CAAC;AAqBlE;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK1C;;OAEG;IACG,oBAAoB,CACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,GAAG,EACX,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAC9B,OAAO,CAAC,GAAG,CAAC;IAqDf;;OAEG;YACW,cAAc;IA2C5B;;OAEG;YACW,oBAAoB;IAwBlC;;OAEG;YACW,qBAAqB;IAgGnC;;OAEG;YACW,kBAAkB;IA8BhC;;OAEG;YACW,sBAAsB;IA6FpC;;OAEG;YACW,wBAAwB;IAgCtC;;OAEG;YACW,mBAAmB;IA8BjC;;OAEG;YACW,gBAAgB;IAO9B;;OAEG;YACW,mBAAmB;IAqDjC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAiBxB;;OAEG;IACI,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3C;;OAEG;IACI,gBAAgB,IAAI,MAAM,EAAE;CAGpC"}
|