@rulvar/openai 1.72.0 → 1.74.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/dist/index.js +31 -5
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -557,18 +557,42 @@ function retryAfterMsFrom(header) {
|
|
|
557
557
|
if (match === null) return;
|
|
558
558
|
return Math.min(Number(match[1]) * 1e3, MAX_RETRY_AFTER_MS);
|
|
559
559
|
}
|
|
560
|
+
/** A plain nonnegative integer header value, or undefined. */
|
|
561
|
+
function limitHeaderValue(header) {
|
|
562
|
+
if (header === void 0) return;
|
|
563
|
+
const match = /^[\t ]*([0-9]+)[\t ]*$/.exec(header);
|
|
564
|
+
return match === null ? void 0 : Number(match[1]);
|
|
565
|
+
}
|
|
560
566
|
/** Projects SDK/API errors into the retryable WireError vocabulary. */
|
|
561
567
|
function openAiErrorToWire(error) {
|
|
562
568
|
const record = error;
|
|
563
569
|
const status = typeof record.status === "number" ? record.status : void 0;
|
|
564
570
|
const message = typeof record.message === "string" ? record.message : String(error);
|
|
565
|
-
|
|
566
|
-
let retryAfterMs;
|
|
571
|
+
const headerGet = (name) => {
|
|
567
572
|
const headers = record.headers;
|
|
568
|
-
if (headers
|
|
569
|
-
|
|
570
|
-
|
|
573
|
+
if (headers === void 0 || headers === null) return;
|
|
574
|
+
if (typeof headers.get === "function") return headers.get(name) ?? void 0;
|
|
575
|
+
return headers[name];
|
|
576
|
+
};
|
|
577
|
+
if (status === 429) {
|
|
578
|
+
const retryAfterHeader = headerGet("retry-after");
|
|
579
|
+
const retryAfterMs = retryAfterHeader === void 0 ? void 0 : retryAfterMsFrom(retryAfterHeader);
|
|
580
|
+
const buckets = {};
|
|
581
|
+
for (const name of [
|
|
582
|
+
"x-ratelimit-limit-requests",
|
|
583
|
+
"x-ratelimit-remaining-requests",
|
|
584
|
+
"x-ratelimit-limit-tokens",
|
|
585
|
+
"x-ratelimit-remaining-tokens"
|
|
586
|
+
]) {
|
|
587
|
+
const value = headerGet(name);
|
|
588
|
+
if (value !== void 0) buckets[name] = value;
|
|
571
589
|
}
|
|
590
|
+
const requestsPerMinute = limitHeaderValue(headerGet("x-ratelimit-limit-requests"));
|
|
591
|
+
const tokensPerMinute = limitHeaderValue(headerGet("x-ratelimit-limit-tokens"));
|
|
592
|
+
const reportedLimits = {
|
|
593
|
+
...requestsPerMinute === void 0 ? {} : { requestsPerMinute },
|
|
594
|
+
...tokensPerMinute === void 0 ? {} : { tokensPerMinute }
|
|
595
|
+
};
|
|
572
596
|
return {
|
|
573
597
|
code: "agent",
|
|
574
598
|
message,
|
|
@@ -576,6 +600,8 @@ function openAiErrorToWire(error) {
|
|
|
576
600
|
data: {
|
|
577
601
|
kind: "rate-limit",
|
|
578
602
|
...retryAfterMs === void 0 ? {} : { retryAfterMs },
|
|
603
|
+
...Object.keys(buckets).length > 0 ? { buckets } : {},
|
|
604
|
+
...Object.keys(reportedLimits).length > 0 ? { reportedLimits } : {},
|
|
579
605
|
status: 429
|
|
580
606
|
}
|
|
581
607
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulvar/openai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.74.0",
|
|
4
4
|
"description": "Rulvar first-class provider adapter for the OpenAI Responses API, plus the openaiCompatible factory.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"openai": "^6.45.0",
|
|
26
|
-
"@rulvar/core": "1.
|
|
26
|
+
"@rulvar/core": "1.74.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.20.0",
|
|
30
30
|
"tsdown": "^0.22.3",
|
|
31
31
|
"typescript": "~6.0.3",
|
|
32
|
-
"@rulvar/testing": "1.
|
|
32
|
+
"@rulvar/testing": "1.74.0"
|
|
33
33
|
},
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|