@reaudit/mcp-server 1.0.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/LICENSE +33 -0
- package/README.md +399 -0
- package/dist/auth/oauth-client.d.ts +43 -0
- package/dist/auth/oauth-client.d.ts.map +1 -0
- package/dist/auth/oauth-client.js +340 -0
- package/dist/auth/oauth-client.js.map +1 -0
- package/dist/auth/token-store.d.ts +41 -0
- package/dist/auth/token-store.d.ts.map +1 -0
- package/dist/auth/token-store.js +176 -0
- package/dist/auth/token-store.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +480 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api-client.d.ts +970 -0
- package/dist/lib/api-client.d.ts.map +1 -0
- package/dist/lib/api-client.js +441 -0
- package/dist/lib/api-client.js.map +1 -0
- package/dist/lib/confirmation.d.ts +92 -0
- package/dist/lib/confirmation.d.ts.map +1 -0
- package/dist/lib/confirmation.js +224 -0
- package/dist/lib/confirmation.js.map +1 -0
- package/dist/lib/error-handler.d.ts +57 -0
- package/dist/lib/error-handler.d.ts.map +1 -0
- package/dist/lib/error-handler.js +235 -0
- package/dist/lib/error-handler.js.map +1 -0
- package/dist/lib/offline-mode.d.ts +107 -0
- package/dist/lib/offline-mode.d.ts.map +1 -0
- package/dist/lib/offline-mode.js +356 -0
- package/dist/lib/offline-mode.js.map +1 -0
- package/dist/lib/progress-tracker.d.ts +87 -0
- package/dist/lib/progress-tracker.d.ts.map +1 -0
- package/dist/lib/progress-tracker.js +238 -0
- package/dist/lib/progress-tracker.js.map +1 -0
- package/dist/prompts/index.d.ts +24 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +305 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/resources/index.d.ts +44 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +125 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/tools/account.d.ts +25 -0
- package/dist/tools/account.d.ts.map +1 -0
- package/dist/tools/account.js +69 -0
- package/dist/tools/account.js.map +1 -0
- package/dist/tools/action-grids.d.ts +414 -0
- package/dist/tools/action-grids.d.ts.map +1 -0
- package/dist/tools/action-grids.js +271 -0
- package/dist/tools/action-grids.js.map +1 -0
- package/dist/tools/analytics-query.d.ts +126 -0
- package/dist/tools/analytics-query.d.ts.map +1 -0
- package/dist/tools/analytics-query.js +106 -0
- package/dist/tools/analytics-query.js.map +1 -0
- package/dist/tools/analytics.d.ts +57 -0
- package/dist/tools/analytics.d.ts.map +1 -0
- package/dist/tools/analytics.js +122 -0
- package/dist/tools/analytics.js.map +1 -0
- package/dist/tools/audits.d.ts +123 -0
- package/dist/tools/audits.d.ts.map +1 -0
- package/dist/tools/audits.js +226 -0
- package/dist/tools/audits.js.map +1 -0
- package/dist/tools/calendar.d.ts +57 -0
- package/dist/tools/calendar.d.ts.map +1 -0
- package/dist/tools/calendar.js +109 -0
- package/dist/tools/calendar.js.map +1 -0
- package/dist/tools/content-generation.d.ts +211 -0
- package/dist/tools/content-generation.d.ts.map +1 -0
- package/dist/tools/content-generation.js +363 -0
- package/dist/tools/content-generation.js.map +1 -0
- package/dist/tools/content.d.ts +92 -0
- package/dist/tools/content.d.ts.map +1 -0
- package/dist/tools/content.js +130 -0
- package/dist/tools/content.js.map +1 -0
- package/dist/tools/indexing.d.ts +132 -0
- package/dist/tools/indexing.d.ts.map +1 -0
- package/dist/tools/indexing.js +190 -0
- package/dist/tools/indexing.js.map +1 -0
- package/dist/tools/optimization.d.ts +70 -0
- package/dist/tools/optimization.d.ts.map +1 -0
- package/dist/tools/optimization.js +106 -0
- package/dist/tools/optimization.js.map +1 -0
- package/dist/tools/projects.d.ts +67 -0
- package/dist/tools/projects.d.ts.map +1 -0
- package/dist/tools/projects.js +113 -0
- package/dist/tools/projects.js.map +1 -0
- package/dist/tools/prompts.d.ts +306 -0
- package/dist/tools/prompts.d.ts.map +1 -0
- package/dist/tools/prompts.js +378 -0
- package/dist/tools/prompts.js.map +1 -0
- package/dist/tools/publishing.d.ts +135 -0
- package/dist/tools/publishing.d.ts.map +1 -0
- package/dist/tools/publishing.js +209 -0
- package/dist/tools/publishing.js.map +1 -0
- package/dist/tools/reports.d.ts +252 -0
- package/dist/tools/reports.d.ts.map +1 -0
- package/dist/tools/reports.js +183 -0
- package/dist/tools/reports.js.map +1 -0
- package/dist/tools/social.d.ts +224 -0
- package/dist/tools/social.d.ts.map +1 -0
- package/dist/tools/social.js +291 -0
- package/dist/tools/social.js.map +1 -0
- package/dist/tools/sources.d.ts +221 -0
- package/dist/tools/sources.d.ts.map +1 -0
- package/dist/tools/sources.js +308 -0
- package/dist/tools/sources.js.map +1 -0
- package/dist/tools/strategy.d.ts +345 -0
- package/dist/tools/strategy.d.ts.map +1 -0
- package/dist/tools/strategy.js +392 -0
- package/dist/tools/strategy.js.map +1 -0
- package/dist/tools/usage.d.ts +101 -0
- package/dist/tools/usage.d.ts.map +1 -0
- package/dist/tools/usage.js +184 -0
- package/dist/tools/usage.js.map +1 -0
- package/dist/tools/visibility.d.ts +95 -0
- package/dist/tools/visibility.d.ts.map +1 -0
- package/dist/tools/visibility.js +163 -0
- package/dist/tools/visibility.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Offline Mode Handler
|
|
4
|
+
*
|
|
5
|
+
* Provides graceful degradation when the API is unavailable,
|
|
6
|
+
* with request queuing for retry.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.ConnectionStatus = void 0;
|
|
43
|
+
exports.initOfflineMode = initOfflineMode;
|
|
44
|
+
exports.stopOfflineMode = stopOfflineMode;
|
|
45
|
+
exports.getConnectionStatus = getConnectionStatus;
|
|
46
|
+
exports.isOnline = isOnline;
|
|
47
|
+
exports.onStatusChange = onStatusChange;
|
|
48
|
+
exports.setConnectionStatus = setConnectionStatus;
|
|
49
|
+
exports.queueRequest = queueRequest;
|
|
50
|
+
exports.getQueuedRequests = getQueuedRequests;
|
|
51
|
+
exports.getQueueSize = getQueueSize;
|
|
52
|
+
exports.clearQueue = clearQueue;
|
|
53
|
+
exports.removeFromQueue = removeFromQueue;
|
|
54
|
+
exports.getOfflineModeStatus = getOfflineModeStatus;
|
|
55
|
+
exports.formatOfflineStatus = formatOfflineStatus;
|
|
56
|
+
exports.cacheForOffline = cacheForOffline;
|
|
57
|
+
exports.getOfflineCache = getOfflineCache;
|
|
58
|
+
exports.clearOfflineCache = clearOfflineCache;
|
|
59
|
+
const fs = __importStar(require("fs"));
|
|
60
|
+
const path = __importStar(require("path"));
|
|
61
|
+
const os = __importStar(require("os"));
|
|
62
|
+
/**
|
|
63
|
+
* Connection status
|
|
64
|
+
*/
|
|
65
|
+
var ConnectionStatus;
|
|
66
|
+
(function (ConnectionStatus) {
|
|
67
|
+
ConnectionStatus["ONLINE"] = "online";
|
|
68
|
+
ConnectionStatus["OFFLINE"] = "offline";
|
|
69
|
+
ConnectionStatus["DEGRADED"] = "degraded";
|
|
70
|
+
})(ConnectionStatus || (exports.ConnectionStatus = ConnectionStatus = {}));
|
|
71
|
+
const DEFAULT_CONFIG = {
|
|
72
|
+
queuePath: path.join(os.homedir(), '.reaudit', 'request-queue.json'),
|
|
73
|
+
maxQueueSize: 100,
|
|
74
|
+
maxRetries: 5,
|
|
75
|
+
checkInterval: 30000, // 30 seconds
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Offline mode state
|
|
79
|
+
*/
|
|
80
|
+
let currentStatus = ConnectionStatus.ONLINE;
|
|
81
|
+
let lastOnlineCheck = 0;
|
|
82
|
+
let requestQueue = [];
|
|
83
|
+
let checkTimer = null;
|
|
84
|
+
/**
|
|
85
|
+
* Status change callbacks
|
|
86
|
+
*/
|
|
87
|
+
const statusCallbacks = [];
|
|
88
|
+
/**
|
|
89
|
+
* Initialize offline mode
|
|
90
|
+
*/
|
|
91
|
+
function initOfflineMode(config = {}) {
|
|
92
|
+
const fullConfig = { ...DEFAULT_CONFIG, ...config };
|
|
93
|
+
// Load persisted queue
|
|
94
|
+
loadQueue(fullConfig.queuePath);
|
|
95
|
+
// Start periodic connectivity check
|
|
96
|
+
if (checkTimer) {
|
|
97
|
+
clearInterval(checkTimer);
|
|
98
|
+
}
|
|
99
|
+
checkTimer = setInterval(() => {
|
|
100
|
+
checkConnectivity();
|
|
101
|
+
}, fullConfig.checkInterval);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Stop offline mode
|
|
105
|
+
*/
|
|
106
|
+
function stopOfflineMode() {
|
|
107
|
+
if (checkTimer) {
|
|
108
|
+
clearInterval(checkTimer);
|
|
109
|
+
checkTimer = null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get current connection status
|
|
114
|
+
*/
|
|
115
|
+
function getConnectionStatus() {
|
|
116
|
+
return currentStatus;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if we're online
|
|
120
|
+
*/
|
|
121
|
+
function isOnline() {
|
|
122
|
+
return currentStatus === ConnectionStatus.ONLINE;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Register status change callback
|
|
126
|
+
*/
|
|
127
|
+
function onStatusChange(callback) {
|
|
128
|
+
statusCallbacks.push(callback);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Update connection status
|
|
132
|
+
*/
|
|
133
|
+
function setConnectionStatus(status) {
|
|
134
|
+
if (status !== currentStatus) {
|
|
135
|
+
currentStatus = status;
|
|
136
|
+
lastOnlineCheck = Date.now();
|
|
137
|
+
// Notify callbacks
|
|
138
|
+
for (const callback of statusCallbacks) {
|
|
139
|
+
try {
|
|
140
|
+
callback(status);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
console.error('Error in status callback:', e);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// If back online, process queue
|
|
147
|
+
if (status === ConnectionStatus.ONLINE) {
|
|
148
|
+
processQueue();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check connectivity (called periodically)
|
|
154
|
+
*/
|
|
155
|
+
async function checkConnectivity() {
|
|
156
|
+
// This would make a lightweight health check request
|
|
157
|
+
// For now, we just update the timestamp
|
|
158
|
+
lastOnlineCheck = Date.now();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Queue a request for later retry
|
|
162
|
+
*/
|
|
163
|
+
function queueRequest(method, path, data, params) {
|
|
164
|
+
const id = `req_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
165
|
+
const request = {
|
|
166
|
+
id,
|
|
167
|
+
method,
|
|
168
|
+
path,
|
|
169
|
+
data,
|
|
170
|
+
params,
|
|
171
|
+
queuedAt: Date.now(),
|
|
172
|
+
retryCount: 0,
|
|
173
|
+
maxRetries: DEFAULT_CONFIG.maxRetries,
|
|
174
|
+
};
|
|
175
|
+
// Add to queue (limit size)
|
|
176
|
+
requestQueue.push(request);
|
|
177
|
+
if (requestQueue.length > DEFAULT_CONFIG.maxQueueSize) {
|
|
178
|
+
requestQueue.shift(); // Remove oldest
|
|
179
|
+
}
|
|
180
|
+
// Persist queue
|
|
181
|
+
saveQueue(DEFAULT_CONFIG.queuePath);
|
|
182
|
+
return id;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get queued requests
|
|
186
|
+
*/
|
|
187
|
+
function getQueuedRequests() {
|
|
188
|
+
return [...requestQueue];
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get queue size
|
|
192
|
+
*/
|
|
193
|
+
function getQueueSize() {
|
|
194
|
+
return requestQueue.length;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Clear the request queue
|
|
198
|
+
*/
|
|
199
|
+
function clearQueue() {
|
|
200
|
+
requestQueue = [];
|
|
201
|
+
saveQueue(DEFAULT_CONFIG.queuePath);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Remove a request from queue
|
|
205
|
+
*/
|
|
206
|
+
function removeFromQueue(requestId) {
|
|
207
|
+
const index = requestQueue.findIndex(r => r.id === requestId);
|
|
208
|
+
if (index >= 0) {
|
|
209
|
+
requestQueue.splice(index, 1);
|
|
210
|
+
saveQueue(DEFAULT_CONFIG.queuePath);
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Process queued requests (called when back online)
|
|
217
|
+
*/
|
|
218
|
+
async function processQueue() {
|
|
219
|
+
if (requestQueue.length === 0) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
console.error(`[Offline Mode] Processing ${requestQueue.length} queued requests...`);
|
|
223
|
+
// Process requests one at a time
|
|
224
|
+
const toProcess = [...requestQueue];
|
|
225
|
+
for (const request of toProcess) {
|
|
226
|
+
if (currentStatus !== ConnectionStatus.ONLINE) {
|
|
227
|
+
break; // Stop if we go offline again
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
// Increment retry count
|
|
231
|
+
request.retryCount++;
|
|
232
|
+
// TODO: Actually retry the request using the API client
|
|
233
|
+
// For now, just remove from queue
|
|
234
|
+
removeFromQueue(request.id);
|
|
235
|
+
console.error(`[Offline Mode] Processed request ${request.id}`);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
if (request.retryCount >= request.maxRetries) {
|
|
239
|
+
// Max retries reached, remove from queue
|
|
240
|
+
removeFromQueue(request.id);
|
|
241
|
+
console.error(`[Offline Mode] Request ${request.id} failed after ${request.maxRetries} retries`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Load queue from disk
|
|
248
|
+
*/
|
|
249
|
+
function loadQueue(queuePath) {
|
|
250
|
+
try {
|
|
251
|
+
if (fs.existsSync(queuePath)) {
|
|
252
|
+
const data = fs.readFileSync(queuePath, 'utf-8');
|
|
253
|
+
requestQueue = JSON.parse(data);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
console.error('[Offline Mode] Error loading queue:', error);
|
|
258
|
+
requestQueue = [];
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Save queue to disk
|
|
263
|
+
*/
|
|
264
|
+
function saveQueue(queuePath) {
|
|
265
|
+
try {
|
|
266
|
+
const dir = path.dirname(queuePath);
|
|
267
|
+
if (!fs.existsSync(dir)) {
|
|
268
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
269
|
+
}
|
|
270
|
+
fs.writeFileSync(queuePath, JSON.stringify(requestQueue, null, 2));
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
console.error('[Offline Mode] Error saving queue:', error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Get offline mode status for display
|
|
278
|
+
*/
|
|
279
|
+
function getOfflineModeStatus() {
|
|
280
|
+
const lastCheckStr = lastOnlineCheck
|
|
281
|
+
? new Date(lastOnlineCheck).toISOString()
|
|
282
|
+
: 'Never';
|
|
283
|
+
let message;
|
|
284
|
+
switch (currentStatus) {
|
|
285
|
+
case ConnectionStatus.ONLINE:
|
|
286
|
+
message = 'Connected to Reaudit';
|
|
287
|
+
break;
|
|
288
|
+
case ConnectionStatus.OFFLINE:
|
|
289
|
+
message = `Offline - ${requestQueue.length} requests queued`;
|
|
290
|
+
break;
|
|
291
|
+
case ConnectionStatus.DEGRADED:
|
|
292
|
+
message = 'Limited connectivity - some features may be unavailable';
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
status: currentStatus,
|
|
297
|
+
queueSize: requestQueue.length,
|
|
298
|
+
lastCheck: lastCheckStr,
|
|
299
|
+
message,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Format offline status for user display
|
|
304
|
+
*/
|
|
305
|
+
function formatOfflineStatus() {
|
|
306
|
+
const status = getOfflineModeStatus();
|
|
307
|
+
const statusEmoji = {
|
|
308
|
+
[ConnectionStatus.ONLINE]: '🟢',
|
|
309
|
+
[ConnectionStatus.OFFLINE]: '🔴',
|
|
310
|
+
[ConnectionStatus.DEGRADED]: '🟡',
|
|
311
|
+
};
|
|
312
|
+
let output = `## Connection Status\n\n`;
|
|
313
|
+
output += `${statusEmoji[status.status]} **${status.status.toUpperCase()}**\n\n`;
|
|
314
|
+
output += `${status.message}\n\n`;
|
|
315
|
+
if (status.queueSize > 0) {
|
|
316
|
+
output += `### Queued Requests\n`;
|
|
317
|
+
output += `${status.queueSize} request(s) waiting to be processed when back online.\n\n`;
|
|
318
|
+
}
|
|
319
|
+
output += `Last connectivity check: ${status.lastCheck}\n`;
|
|
320
|
+
return output;
|
|
321
|
+
}
|
|
322
|
+
const offlineCache = new Map();
|
|
323
|
+
/**
|
|
324
|
+
* Cache data for offline access
|
|
325
|
+
*/
|
|
326
|
+
function cacheForOffline(key, data, ttlMs = 3600000) {
|
|
327
|
+
const now = Date.now();
|
|
328
|
+
offlineCache.set(key, {
|
|
329
|
+
key,
|
|
330
|
+
data,
|
|
331
|
+
cachedAt: now,
|
|
332
|
+
expiresAt: now + ttlMs,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Get cached data (for offline use)
|
|
337
|
+
*/
|
|
338
|
+
function getOfflineCache(key) {
|
|
339
|
+
const cached = offlineCache.get(key);
|
|
340
|
+
if (!cached) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
// Check expiration
|
|
344
|
+
if (Date.now() > cached.expiresAt) {
|
|
345
|
+
offlineCache.delete(key);
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
return cached.data;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Clear offline cache
|
|
352
|
+
*/
|
|
353
|
+
function clearOfflineCache() {
|
|
354
|
+
offlineCache.clear();
|
|
355
|
+
}
|
|
356
|
+
//# sourceMappingURL=offline-mode.js.map
|
|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,CAAC,GAAG,EAAE;QACpB,GAAG;QACH,IAAI;QACJ,QAAQ,EAAE,GAAG;QACb,SAAS,EAAE,GAAG,GAAG,KAAK;KACvB,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAI,GAAW;IAC5C,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAErC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mBAAmB;IACnB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAClC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC,IAAS,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,YAAY,CAAC,KAAK,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Progress Tracker
|
|
3
|
+
*
|
|
4
|
+
* Tracks progress of long-running operations and supports cancellation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Progress status
|
|
8
|
+
*/
|
|
9
|
+
export declare enum ProgressStatus {
|
|
10
|
+
PENDING = "pending",
|
|
11
|
+
RUNNING = "running",
|
|
12
|
+
COMPLETED = "completed",
|
|
13
|
+
FAILED = "failed",
|
|
14
|
+
CANCELLED = "cancelled"
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Progress update
|
|
18
|
+
*/
|
|
19
|
+
export interface ProgressUpdate {
|
|
20
|
+
operationId: string;
|
|
21
|
+
status: ProgressStatus;
|
|
22
|
+
progress: number;
|
|
23
|
+
message: string;
|
|
24
|
+
startedAt: number;
|
|
25
|
+
updatedAt: number;
|
|
26
|
+
completedAt?: number;
|
|
27
|
+
error?: string;
|
|
28
|
+
result?: unknown;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Operation configuration
|
|
32
|
+
*/
|
|
33
|
+
interface OperationConfig {
|
|
34
|
+
operationId: string;
|
|
35
|
+
name: string;
|
|
36
|
+
totalSteps?: number;
|
|
37
|
+
onProgress?: (update: ProgressUpdate) => void;
|
|
38
|
+
onComplete?: (result: unknown) => void;
|
|
39
|
+
onError?: (error: Error) => void;
|
|
40
|
+
onCancel?: () => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate unique operation ID
|
|
44
|
+
*/
|
|
45
|
+
export declare function generateOperationId(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Start tracking a new operation
|
|
48
|
+
*/
|
|
49
|
+
export declare function startOperation(config: OperationConfig): ProgressUpdate;
|
|
50
|
+
/**
|
|
51
|
+
* Update operation progress
|
|
52
|
+
*/
|
|
53
|
+
export declare function updateProgress(operationId: string, progress: number, message: string): ProgressUpdate | null;
|
|
54
|
+
/**
|
|
55
|
+
* Complete an operation successfully
|
|
56
|
+
*/
|
|
57
|
+
export declare function completeOperation(operationId: string, result?: unknown): ProgressUpdate | null;
|
|
58
|
+
/**
|
|
59
|
+
* Fail an operation
|
|
60
|
+
*/
|
|
61
|
+
export declare function failOperation(operationId: string, error: Error): ProgressUpdate | null;
|
|
62
|
+
/**
|
|
63
|
+
* Request cancellation of an operation
|
|
64
|
+
*/
|
|
65
|
+
export declare function cancelOperation(operationId: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Check if operation is cancelled
|
|
68
|
+
*/
|
|
69
|
+
export declare function isCancelled(operationId: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Get operation status
|
|
72
|
+
*/
|
|
73
|
+
export declare function getOperationStatus(operationId: string): ProgressUpdate | null;
|
|
74
|
+
/**
|
|
75
|
+
* Get all active operations
|
|
76
|
+
*/
|
|
77
|
+
export declare function getActiveOperations(): ProgressUpdate[];
|
|
78
|
+
/**
|
|
79
|
+
* Format progress for display
|
|
80
|
+
*/
|
|
81
|
+
export declare function formatProgress(update: ProgressUpdate): string;
|
|
82
|
+
/**
|
|
83
|
+
* Run an operation with progress tracking
|
|
84
|
+
*/
|
|
85
|
+
export declare function withProgress<T>(name: string, fn: (updateProgress: (progress: number, message: string) => void, checkCancelled: () => boolean) => Promise<T>, onProgress?: (update: ProgressUpdate) => void): Promise<T>;
|
|
86
|
+
export {};
|
|
87
|
+
//# sourceMappingURL=progress-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress-tracker.d.ts","sourceRoot":"","sources":["../../src/lib/progress-tracker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,SAAS,cAAc;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,UAAU,eAAe;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAC9C,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,QAAQ,CAAC,EAAE,M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-0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Progress Tracker
|
|
4
|
+
*
|
|
5
|
+
* Tracks progress of long-running operations and supports cancellation.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ProgressStatus = void 0;
|
|
9
|
+
exports.generateOperationId = generateOperationId;
|
|
10
|
+
exports.startOperation = startOperation;
|
|
11
|
+
exports.updateProgress = updateProgress;
|
|
12
|
+
exports.completeOperation = completeOperation;
|
|
13
|
+
exports.failOperation = failOperation;
|
|
14
|
+
exports.cancelOperation = cancelOperation;
|
|
15
|
+
exports.isCancelled = isCancelled;
|
|
16
|
+
exports.getOperationStatus = getOperationStatus;
|
|
17
|
+
exports.getActiveOperations = getActiveOperations;
|
|
18
|
+
exports.formatProgress = formatProgress;
|
|
19
|
+
exports.withProgress = withProgress;
|
|
20
|
+
/**
|
|
21
|
+
* Progress status
|
|
22
|
+
*/
|
|
23
|
+
var ProgressStatus;
|
|
24
|
+
(function (ProgressStatus) {
|
|
25
|
+
ProgressStatus["PENDING"] = "pending";
|
|
26
|
+
ProgressStatus["RUNNING"] = "running";
|
|
27
|
+
ProgressStatus["COMPLETED"] = "completed";
|
|
28
|
+
ProgressStatus["FAILED"] = "failed";
|
|
29
|
+
ProgressStatus["CANCELLED"] = "cancelled";
|
|
30
|
+
})(ProgressStatus || (exports.ProgressStatus = ProgressStatus = {}));
|
|
31
|
+
/**
|
|
32
|
+
* Active operations storage
|
|
33
|
+
*/
|
|
34
|
+
const activeOperations = new Map();
|
|
35
|
+
/**
|
|
36
|
+
* Generate unique operation ID
|
|
37
|
+
*/
|
|
38
|
+
function generateOperationId() {
|
|
39
|
+
return `op_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Start tracking a new operation
|
|
43
|
+
*/
|
|
44
|
+
function startOperation(config) {
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
const update = {
|
|
47
|
+
operationId: config.operationId,
|
|
48
|
+
status: ProgressStatus.RUNNING,
|
|
49
|
+
progress: 0,
|
|
50
|
+
message: `Starting ${config.name}...`,
|
|
51
|
+
startedAt: now,
|
|
52
|
+
updatedAt: now,
|
|
53
|
+
};
|
|
54
|
+
activeOperations.set(config.operationId, {
|
|
55
|
+
config,
|
|
56
|
+
update,
|
|
57
|
+
cancelled: false,
|
|
58
|
+
});
|
|
59
|
+
// Notify progress callback
|
|
60
|
+
config.onProgress?.(update);
|
|
61
|
+
return update;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Update operation progress
|
|
65
|
+
*/
|
|
66
|
+
function updateProgress(operationId, progress, message) {
|
|
67
|
+
const operation = activeOperations.get(operationId);
|
|
68
|
+
if (!operation) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
// Check if cancelled
|
|
72
|
+
if (operation.cancelled) {
|
|
73
|
+
return operation.update;
|
|
74
|
+
}
|
|
75
|
+
operation.update = {
|
|
76
|
+
...operation.update,
|
|
77
|
+
progress: Math.min(100, Math.max(0, progress)),
|
|
78
|
+
message,
|
|
79
|
+
updatedAt: Date.now(),
|
|
80
|
+
};
|
|
81
|
+
// Notify progress callback
|
|
82
|
+
operation.config.onProgress?.(operation.update);
|
|
83
|
+
return operation.update;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Complete an operation successfully
|
|
87
|
+
*/
|
|
88
|
+
function completeOperation(operationId, result) {
|
|
89
|
+
const operation = activeOperations.get(operationId);
|
|
90
|
+
if (!operation) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
operation.update = {
|
|
95
|
+
...operation.update,
|
|
96
|
+
status: ProgressStatus.COMPLETED,
|
|
97
|
+
progress: 100,
|
|
98
|
+
message: 'Completed',
|
|
99
|
+
updatedAt: now,
|
|
100
|
+
completedAt: now,
|
|
101
|
+
result,
|
|
102
|
+
};
|
|
103
|
+
// Notify callbacks
|
|
104
|
+
operation.config.onProgress?.(operation.update);
|
|
105
|
+
operation.config.onComplete?.(result);
|
|
106
|
+
// Clean up after a delay
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
activeOperations.delete(operationId);
|
|
109
|
+
}, 60000); // Keep for 1 minute
|
|
110
|
+
return operation.update;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Fail an operation
|
|
114
|
+
*/
|
|
115
|
+
function failOperation(operationId, error) {
|
|
116
|
+
const operation = activeOperations.get(operationId);
|
|
117
|
+
if (!operation) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const now = Date.now();
|
|
121
|
+
operation.update = {
|
|
122
|
+
...operation.update,
|
|
123
|
+
status: ProgressStatus.FAILED,
|
|
124
|
+
message: 'Failed',
|
|
125
|
+
updatedAt: now,
|
|
126
|
+
completedAt: now,
|
|
127
|
+
error: error.message,
|
|
128
|
+
};
|
|
129
|
+
// Notify callbacks
|
|
130
|
+
operation.config.onProgress?.(operation.update);
|
|
131
|
+
operation.config.onError?.(error);
|
|
132
|
+
// Clean up after a delay
|
|
133
|
+
setTimeout(() => {
|
|
134
|
+
activeOperations.delete(operationId);
|
|
135
|
+
}, 60000);
|
|
136
|
+
return operation.update;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Request cancellation of an operation
|
|
140
|
+
*/
|
|
141
|
+
function cancelOperation(operationId) {
|
|
142
|
+
const operation = activeOperations.get(operationId);
|
|
143
|
+
if (!operation) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (operation.update.status !== ProgressStatus.RUNNING) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
operation.cancelled = true;
|
|
150
|
+
operation.update = {
|
|
151
|
+
...operation.update,
|
|
152
|
+
status: ProgressStatus.CANCELLED,
|
|
153
|
+
message: 'Cancelled by user',
|
|
154
|
+
updatedAt: Date.now(),
|
|
155
|
+
};
|
|
156
|
+
// Notify callbacks
|
|
157
|
+
operation.config.onProgress?.(operation.update);
|
|
158
|
+
operation.config.onCancel?.();
|
|
159
|
+
// Clean up after a delay
|
|
160
|
+
setTimeout(() => {
|
|
161
|
+
activeOperations.delete(operationId);
|
|
162
|
+
}, 60000);
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if operation is cancelled
|
|
167
|
+
*/
|
|
168
|
+
function isCancelled(operationId) {
|
|
169
|
+
const operation = activeOperations.get(operationId);
|
|
170
|
+
return operation?.cancelled ?? false;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get operation status
|
|
174
|
+
*/
|
|
175
|
+
function getOperationStatus(operationId) {
|
|
176
|
+
const operation = activeOperations.get(operationId);
|
|
177
|
+
return operation?.update ?? null;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get all active operations
|
|
181
|
+
*/
|
|
182
|
+
function getActiveOperations() {
|
|
183
|
+
return Array.from(activeOperations.values())
|
|
184
|
+
.filter(op => op.update.status === ProgressStatus.RUNNING)
|
|
185
|
+
.map(op => op.update);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Format progress for display
|
|
189
|
+
*/
|
|
190
|
+
function formatProgress(update) {
|
|
191
|
+
const elapsed = Math.round((update.updatedAt - update.startedAt) / 1000);
|
|
192
|
+
const progressBar = createProgressBar(update.progress);
|
|
193
|
+
let output = `**${update.message}**\n\n`;
|
|
194
|
+
output += `${progressBar} ${update.progress}%\n`;
|
|
195
|
+
output += `Elapsed: ${elapsed}s\n`;
|
|
196
|
+
if (update.status === ProgressStatus.COMPLETED) {
|
|
197
|
+
output += `\n✅ Completed successfully`;
|
|
198
|
+
}
|
|
199
|
+
else if (update.status === ProgressStatus.FAILED) {
|
|
200
|
+
output += `\n❌ Failed: ${update.error}`;
|
|
201
|
+
}
|
|
202
|
+
else if (update.status === ProgressStatus.CANCELLED) {
|
|
203
|
+
output += `\n⚠️ Cancelled`;
|
|
204
|
+
}
|
|
205
|
+
return output;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Create ASCII progress bar
|
|
209
|
+
*/
|
|
210
|
+
function createProgressBar(progress, width = 20) {
|
|
211
|
+
const filled = Math.round((progress / 100) * width);
|
|
212
|
+
const empty = width - filled;
|
|
213
|
+
return `[${'█'.repeat(filled)}${'░'.repeat(empty)}]`;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Run an operation with progress tracking
|
|
217
|
+
*/
|
|
218
|
+
async function withProgress(name, fn, onProgress) {
|
|
219
|
+
const operationId = generateOperationId();
|
|
220
|
+
startOperation({
|
|
221
|
+
operationId,
|
|
222
|
+
name,
|
|
223
|
+
onProgress,
|
|
224
|
+
});
|
|
225
|
+
try {
|
|
226
|
+
const result = await fn((progress, message) => updateProgress(operationId, progress, message), () => isCancelled(operationId));
|
|
227
|
+
completeOperation(operationId, result);
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (isCancelled(operationId)) {
|
|
232
|
+
throw new Error('Operation cancelled');
|
|
233
|
+
}
|
|
234
|
+
failOperation(operationId, error instanceof Error ? error : new Error(String(error)));
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=progress-tracker.js.map
|