recker 1.0.10 → 1.0.11-alpha.cc0ae8b
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/dist/cli/index.js +76 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/server.d.ts +41 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +503 -0
- package/package.json +1 -1
- package/dist/plugins/rate-limit.d.ts +0 -8
- package/dist/plugins/rate-limit.d.ts.map +0 -1
- package/dist/plugins/rate-limit.js +0 -57
- package/dist/utils/logger.d.ts +0 -33
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -160
- package/dist/utils/status-codes.d.ts +0 -84
- package/dist/utils/status-codes.d.ts.map +0 -1
- package/dist/utils/status-codes.js +0 -204
- package/dist/utils/task-pool.d.ts +0 -38
- package/dist/utils/task-pool.js +0 -104
package/dist/utils/task-pool.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight TaskPool for rate limiting and concurrency control.
|
|
3
|
-
*
|
|
4
|
-
* - Limits concurrent executions.
|
|
5
|
-
* - Enforces a max start rate (`requestsPerInterval` / `interval`) via a sliding window.
|
|
6
|
-
* - Respects AbortSignal both while queued and while running.
|
|
7
|
-
*/
|
|
8
|
-
export class TaskPool {
|
|
9
|
-
concurrency;
|
|
10
|
-
requestsPerInterval;
|
|
11
|
-
interval;
|
|
12
|
-
queue = [];
|
|
13
|
-
active = 0;
|
|
14
|
-
windowStart = 0;
|
|
15
|
-
startedInWindow = 0;
|
|
16
|
-
waitingTimer;
|
|
17
|
-
constructor(options = {}) {
|
|
18
|
-
this.concurrency = options.concurrency ?? Number.POSITIVE_INFINITY;
|
|
19
|
-
this.requestsPerInterval = options.requestsPerInterval;
|
|
20
|
-
this.interval = options.interval;
|
|
21
|
-
}
|
|
22
|
-
run(fn, signal) {
|
|
23
|
-
if (signal?.aborted) {
|
|
24
|
-
return Promise.reject(signal.reason ?? new Error('Task aborted before enqueue'));
|
|
25
|
-
}
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
const task = { fn, resolve, reject, signal };
|
|
28
|
-
if (signal) {
|
|
29
|
-
const onAbort = () => {
|
|
30
|
-
this._removeFromQueue(task);
|
|
31
|
-
reject(signal.reason ?? new Error('Task aborted while queued'));
|
|
32
|
-
this._schedule();
|
|
33
|
-
};
|
|
34
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
35
|
-
task.abortCleanup = () => signal.removeEventListener('abort', onAbort);
|
|
36
|
-
}
|
|
37
|
-
this.queue.push(task);
|
|
38
|
-
this._schedule();
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
_removeFromQueue(task) {
|
|
42
|
-
const index = this.queue.indexOf(task);
|
|
43
|
-
if (index >= 0) {
|
|
44
|
-
this.queue.splice(index, 1);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
_canStart(now) {
|
|
48
|
-
if (this.active >= this.concurrency) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
if (this.requestsPerInterval == null || this.interval == null) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
if (now - this.windowStart >= this.interval) {
|
|
55
|
-
this.windowStart = now;
|
|
56
|
-
this.startedInWindow = 0;
|
|
57
|
-
}
|
|
58
|
-
if (this.startedInWindow < this.requestsPerInterval) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
_schedule() {
|
|
64
|
-
if (this.waitingTimer) {
|
|
65
|
-
// There's already a timer waiting for the next window; let it fire.
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const now = Date.now();
|
|
69
|
-
while (this.queue.length > 0 && this._canStart(Date.now())) {
|
|
70
|
-
const task = this.queue.shift();
|
|
71
|
-
if (task.signal?.aborted) {
|
|
72
|
-
task.abortCleanup?.();
|
|
73
|
-
task.reject(task.signal.reason ?? new Error('Task aborted while queued'));
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
this.active++;
|
|
77
|
-
this.startedInWindow++;
|
|
78
|
-
const clearAbort = task.abortCleanup;
|
|
79
|
-
if (clearAbort) {
|
|
80
|
-
clearAbort();
|
|
81
|
-
task.abortCleanup = undefined;
|
|
82
|
-
}
|
|
83
|
-
Promise.resolve()
|
|
84
|
-
.then(() => task.fn())
|
|
85
|
-
.then((result) => task.resolve(result))
|
|
86
|
-
.catch((error) => task.reject(error))
|
|
87
|
-
.finally(() => {
|
|
88
|
-
this.active--;
|
|
89
|
-
this._schedule();
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
// If rate limit prevents starting now, schedule when the window resets
|
|
93
|
-
if (this.queue.length > 0 &&
|
|
94
|
-
this.requestsPerInterval != null &&
|
|
95
|
-
this.interval != null &&
|
|
96
|
-
!this._canStart(Date.now())) {
|
|
97
|
-
const wait = Math.max(0, this.windowStart + this.interval - Date.now());
|
|
98
|
-
this.waitingTimer = setTimeout(() => {
|
|
99
|
-
this.waitingTimer = undefined;
|
|
100
|
-
this._schedule();
|
|
101
|
-
}, wait);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|