aura-code 0.3.4 → 0.3.6
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.
|
@@ -31,6 +31,17 @@ export declare class RateLimiter {
|
|
|
31
31
|
* Returns the milliseconds waited (0 if instant).
|
|
32
32
|
*/
|
|
33
33
|
acquire(n?: number): Promise<number>;
|
|
34
|
+
/**
|
|
35
|
+
* Consume tokens without waiting. Returns true if successful, false if
|
|
36
|
+
* there aren't enough. The bucket is unchanged on false.
|
|
37
|
+
*/
|
|
38
|
+
tryAcquire(n?: number): boolean;
|
|
39
|
+
/** Force a token count (e.g. record a successful API call's token cost). */
|
|
40
|
+
recordUsage(n: number): void;
|
|
41
|
+
/** Reset the bucket to full. */
|
|
42
|
+
reset(): void;
|
|
43
|
+
/** Current token count (after refill). */
|
|
44
|
+
available(): number;
|
|
34
45
|
private refill;
|
|
35
46
|
}
|
|
36
47
|
/** RPM → token-bucket config. capacity allows short bursts. */
|
|
@@ -28,7 +28,8 @@ class RateLimiter {
|
|
|
28
28
|
// `start` is only set once we know we actually have to wait. This keeps
|
|
29
29
|
// the instant-success path free of any wall-clock read, so it returns a
|
|
30
30
|
// literal 0 deterministically instead of `Date.now() - start`, which can
|
|
31
|
-
// tick from 0 to 1ms under scheduler load even with no real wait
|
|
31
|
+
// tick from 0 to 1ms under scheduler load even with no real wait — the
|
|
32
|
+
// exact flake seen in CI (and intermittently in local runs under load).
|
|
32
33
|
let start;
|
|
33
34
|
while (true) {
|
|
34
35
|
this.refill();
|
|
@@ -36,45 +37,40 @@ class RateLimiter {
|
|
|
36
37
|
this.tokens -= n;
|
|
37
38
|
return start === undefined ? 0 : Date.now() - start;
|
|
38
39
|
}
|
|
40
|
+
// Tokens needed minus what we have, divided by refill rate = wait time
|
|
39
41
|
const deficit = n - this.tokens;
|
|
40
42
|
const waitMs = Math.ceil(deficit / this.refillPerMs) + 5;
|
|
41
43
|
this.onWait?.({ needed: n, waitMs });
|
|
42
44
|
start ??= Date.now();
|
|
43
45
|
await this.sleep(waitMs);
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
/** Force a token count (e.g. record a successful API call's token cost). */
|
|
60
|
-
recordUsage(n, number);
|
|
61
|
-
void {
|
|
62
|
-
this: .refill(),
|
|
63
|
-
this: .tokens = Math.max(0, this.tokens - n)
|
|
64
|
-
};
|
|
65
|
-
/** Reset the bucket to full. */
|
|
66
|
-
reset();
|
|
67
|
-
void {
|
|
68
|
-
this: .tokens = this.capacity,
|
|
69
|
-
this: .lastRefill = Date.now()
|
|
70
|
-
};
|
|
71
|
-
/** Current token count (after refill). */
|
|
72
|
-
available();
|
|
73
|
-
number;
|
|
74
|
-
{
|
|
75
|
-
this.refill();
|
|
76
|
-
return this.tokens;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Consume tokens without waiting. Returns true if successful, false if
|
|
50
|
+
* there aren't enough. The bucket is unchanged on false.
|
|
51
|
+
*/
|
|
52
|
+
tryAcquire(n = 1) {
|
|
53
|
+
this.refill();
|
|
54
|
+
if (this.tokens >= n) {
|
|
55
|
+
this.tokens -= n;
|
|
56
|
+
return true;
|
|
77
57
|
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
/** Force a token count (e.g. record a successful API call's token cost). */
|
|
61
|
+
recordUsage(n) {
|
|
62
|
+
this.refill();
|
|
63
|
+
this.tokens = Math.max(0, this.tokens - n);
|
|
64
|
+
}
|
|
65
|
+
/** Reset the bucket to full. */
|
|
66
|
+
reset() {
|
|
67
|
+
this.tokens = this.capacity;
|
|
68
|
+
this.lastRefill = Date.now();
|
|
69
|
+
}
|
|
70
|
+
/** Current token count (after refill). */
|
|
71
|
+
available() {
|
|
72
|
+
this.refill();
|
|
73
|
+
return this.tokens;
|
|
78
74
|
}
|
|
79
75
|
refill() {
|
|
80
76
|
const now = Date.now();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/util/rate-limiter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/util/rate-limiter.ts"],"names":[],"mappings":";;;AA+GA,gCAMC;AAnGD,MAAa,WAAW;IACd,MAAM,CAAS;IACf,UAAU,CAAS;IACV,QAAQ,CAAS;IACjB,WAAW,CAAS;IACpB,KAAK,CAAgC;IACrC,MAAM,CAAsD;IAE7E,YAAY,IAAwB;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,QAAQ,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,YAAY,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC;QACjB,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,gCAAgC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtF,CAAC;QACD,wEAAwE;QACxE,wEAAwE;QACxE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,IAAI,KAAyB,CAAC;QAC9B,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,IAA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KAAK,EAAE,CAAC;gBAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAEO,KAAK,CAAC,GAAW;QACvB,MAAM,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM;YAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAClF,CAAC;CACF;AA/CD,gCA+CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aura-code",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Aura Code — model-agnostic AI coding agent. Works with Claude, GPT, Gemini, MiMo, Ollama, and any OpenAI-compatible endpoint. MIT licensed.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"aura": "dist/cli/index.js"
|