quotacap 0.0.43 → 0.0.44
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/adapters/index.d.ts +12 -3
- package/dist/adapters/index.js +15 -3
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/adapters/index.d.ts
CHANGED
|
@@ -6,14 +6,23 @@ export interface PollAllOptions {
|
|
|
6
6
|
/** Max concurrent adapter polls. Default 3: seven heavy CLI/TUI spawns at
|
|
7
7
|
* once starve each other into timeouts. */
|
|
8
8
|
maxConcurrency?: number;
|
|
9
|
-
/** Attempts per adapter including the first. Default
|
|
9
|
+
/** Attempts per adapter including the first. Default 3.
|
|
10
10
|
* 1 disables retry. */
|
|
11
11
|
maxAttempts?: number;
|
|
12
|
-
/**
|
|
13
|
-
|
|
12
|
+
/** Backoff base between attempts: the delay after failed attempt n is
|
|
13
|
+
* min(cap, base * 2^(n-1)) with equal jitter. Default 2000. */
|
|
14
|
+
baseRetryDelayMs?: number;
|
|
15
|
+
/** Backoff ceiling. Default 8000. */
|
|
16
|
+
maxRetryDelayMs?: number;
|
|
14
17
|
/** When aborted, in-flight attempts run out but no retry is started. */
|
|
15
18
|
signal?: AbortSignal;
|
|
16
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Exponential backoff with equal jitter: half the exponential delay plus a
|
|
22
|
+
* uniform random half, so concurrent adapters do not retry in lockstep.
|
|
23
|
+
* failedAttempt is 1-based (1 = the first attempt just failed).
|
|
24
|
+
*/
|
|
25
|
+
export declare function computeRetryDelayMs(failedAttempt: number, baseMs?: number, capMs?: number, rng?: () => number): number;
|
|
17
26
|
/** Order-preserving concurrency-limited map. */
|
|
18
27
|
export declare function mapWithConcurrency<T, R>(items: T[], limit: number, fn: (item: T, index: number) => Promise<R>): Promise<R[]>;
|
|
19
28
|
export declare function isRetryableChildFailure(reason: unknown): boolean;
|
package/dist/adapters/index.js
CHANGED
|
@@ -30,6 +30,17 @@ export const ADAPTER_TIMEOUTS = {
|
|
|
30
30
|
muse: 90000,
|
|
31
31
|
"opencode-go": 8000,
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Exponential backoff with equal jitter: half the exponential delay plus a
|
|
35
|
+
* uniform random half, so concurrent adapters do not retry in lockstep.
|
|
36
|
+
* failedAttempt is 1-based (1 = the first attempt just failed).
|
|
37
|
+
*/
|
|
38
|
+
export function computeRetryDelayMs(failedAttempt, baseMs = 2000, capMs = 8000, rng = Math.random) {
|
|
39
|
+
const base = Math.max(0, baseMs);
|
|
40
|
+
const cap = Math.max(0, capMs);
|
|
41
|
+
const exp = Math.min(cap, base * 2 ** Math.max(0, failedAttempt - 1));
|
|
42
|
+
return Math.floor(exp / 2 + rng() * (exp / 2));
|
|
43
|
+
}
|
|
33
44
|
/** Order-preserving concurrency-limited map. */
|
|
34
45
|
export async function mapWithConcurrency(items, limit, fn) {
|
|
35
46
|
const results = new Array(items.length);
|
|
@@ -98,8 +109,9 @@ async function pollOnceWithGate(id, adapter, timeout) {
|
|
|
98
109
|
const delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
99
110
|
export async function pollAll(enabled, opts) {
|
|
100
111
|
const maxConcurrency = opts?.maxConcurrency ?? 3;
|
|
101
|
-
const maxAttempts = Math.max(1, opts?.maxAttempts ??
|
|
102
|
-
const
|
|
112
|
+
const maxAttempts = Math.max(1, opts?.maxAttempts ?? 3);
|
|
113
|
+
const baseRetryDelayMs = opts?.baseRetryDelayMs ?? 2000;
|
|
114
|
+
const maxRetryDelayMs = opts?.maxRetryDelayMs ?? 8000;
|
|
103
115
|
const runOne = async (id) => {
|
|
104
116
|
const a = adapters[id];
|
|
105
117
|
if (!a)
|
|
@@ -123,7 +135,7 @@ export async function pollAll(enabled, opts) {
|
|
|
123
135
|
const retry = outcome.timedOut || isRetryableChildFailure(outcome.reason);
|
|
124
136
|
if (!retry)
|
|
125
137
|
break;
|
|
126
|
-
await delay(
|
|
138
|
+
await delay(computeRetryDelayMs(attempt, baseRetryDelayMs, maxRetryDelayMs));
|
|
127
139
|
}
|
|
128
140
|
return { provider: id, status: "rejected", reason: lastReason };
|
|
129
141
|
};
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by scripts/build-embed.mjs — do not edit
|
|
2
|
-
export const VERSION = "0.0.
|
|
2
|
+
export const VERSION = "0.0.44";
|