pendra 0.19.0 → 0.21.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/README.md +1 -1
- package/dist/index.d.mts +29 -5
- package/dist/index.d.ts +29 -5
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -31,8 +31,18 @@ var RateLimitError = class extends APIStatusError {
|
|
|
31
31
|
constructor(message = "Rate limit exceeded", options = {}) {
|
|
32
32
|
super(message, 429, options);
|
|
33
33
|
this.name = "RateLimitError";
|
|
34
|
+
this.retryAfter = options.retryAfter;
|
|
35
|
+
this.queueDepth = options.queueDepth;
|
|
34
36
|
}
|
|
35
37
|
};
|
|
38
|
+
function secondsFrom(...candidates) {
|
|
39
|
+
for (const value of candidates) {
|
|
40
|
+
if (typeof value !== "number" && (typeof value !== "string" || value.trim() === "")) continue;
|
|
41
|
+
const n = Number(value);
|
|
42
|
+
if (Number.isFinite(n) && n >= 0) return n;
|
|
43
|
+
}
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
36
46
|
var _APIResponseValidationError = class _APIResponseValidationError extends APIError {
|
|
37
47
|
constructor(message, options = {}) {
|
|
38
48
|
const { status, body } = options;
|
|
@@ -58,6 +68,7 @@ var APIStreamError = class extends APIError {
|
|
|
58
68
|
this.requestId = options.requestId;
|
|
59
69
|
this.workerId = options.workerId;
|
|
60
70
|
this.workerName = options.workerName;
|
|
71
|
+
this.retryAfter = options.retryAfter;
|
|
61
72
|
}
|
|
62
73
|
};
|
|
63
74
|
var LOC_SOURCES = /* @__PURE__ */ new Set(["body", "query", "path", "header", "cookie"]);
|
|
@@ -119,7 +130,7 @@ async function readErrorBody(response) {
|
|
|
119
130
|
return raw;
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
|
-
function statusErrorFromBody(status, body, fallback) {
|
|
133
|
+
function statusErrorFromBody(status, body, fallback, headers) {
|
|
123
134
|
const detail = isRecord(body) ? body.detail : void 0;
|
|
124
135
|
const err = isRecord(body) ? body.error : void 0;
|
|
125
136
|
let message = (isRecord(err) ? nonEmptyString(err.message) : void 0) ?? messageFromDetail(detail) ?? (isRecord(body) ? nonEmptyString(body.message) : void 0);
|
|
@@ -131,7 +142,13 @@ function statusErrorFromBody(status, body, fallback) {
|
|
|
131
142
|
}
|
|
132
143
|
const options = { body, detail };
|
|
133
144
|
if (status === 401) return new AuthenticationError(message, options);
|
|
134
|
-
if (status === 429)
|
|
145
|
+
if (status === 429) {
|
|
146
|
+
return new RateLimitError(message, {
|
|
147
|
+
...options,
|
|
148
|
+
retryAfter: secondsFrom(headers?.get("Retry-After"), isRecord(err) ? err.retry_after : void 0),
|
|
149
|
+
queueDepth: secondsFrom(headers?.get("X-Pendra-Queue-Depth"), isRecord(err) ? err.queue_depth : void 0)
|
|
150
|
+
});
|
|
151
|
+
}
|
|
135
152
|
return new APIStatusError(message, status, options);
|
|
136
153
|
}
|
|
137
154
|
|
|
@@ -533,7 +550,8 @@ function throwIfInBandError(parsed, fallback = "The server reported an error mid
|
|
|
533
550
|
code: typeof e.code === "number" ? e.code : void 0,
|
|
534
551
|
requestId: asString(e.request_id),
|
|
535
552
|
workerId: asString(e.worker_id),
|
|
536
|
-
workerName: asString(e.worker_name)
|
|
553
|
+
workerName: asString(e.worker_name),
|
|
554
|
+
retryAfter: secondsFrom(e.retry_after)
|
|
537
555
|
}
|
|
538
556
|
);
|
|
539
557
|
}
|
|
@@ -1123,7 +1141,7 @@ var Transcriptions = class {
|
|
|
1123
1141
|
clearTimeout(timeoutId);
|
|
1124
1142
|
if (response.status >= 400) {
|
|
1125
1143
|
const body = await readErrorBody(response);
|
|
1126
|
-
throw statusErrorFromBody(response.status, body, response.statusText);
|
|
1144
|
+
throw statusErrorFromBody(response.status, body, response.statusText, response.headers);
|
|
1127
1145
|
}
|
|
1128
1146
|
const format = params.response_format;
|
|
1129
1147
|
if (format === "text" || format === "srt" || format === "vtt") {
|
|
@@ -1911,7 +1929,7 @@ var Rerank = class {
|
|
|
1911
1929
|
};
|
|
1912
1930
|
|
|
1913
1931
|
// src/version.ts
|
|
1914
|
-
var VERSION = "0.
|
|
1932
|
+
var VERSION = "0.21.0";
|
|
1915
1933
|
var USER_AGENT = `pendra-node/${VERSION}`;
|
|
1916
1934
|
|
|
1917
1935
|
// src/client.ts
|
|
@@ -2026,7 +2044,7 @@ var Pendra = class {
|
|
|
2026
2044
|
);
|
|
2027
2045
|
}
|
|
2028
2046
|
if (!response.ok) {
|
|
2029
|
-
throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText);
|
|
2047
|
+
throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText, response.headers);
|
|
2030
2048
|
}
|
|
2031
2049
|
const json = await response.json();
|
|
2032
2050
|
await engine.resolveOrgKey(json.keys ?? []);
|
|
@@ -2064,7 +2082,7 @@ var Pendra = class {
|
|
|
2064
2082
|
clearTimeout(timeoutId);
|
|
2065
2083
|
if (!response.ok) {
|
|
2066
2084
|
this.invalidateKeyCacheIfRekeyed(response);
|
|
2067
|
-
throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText);
|
|
2085
|
+
throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText, response.headers);
|
|
2068
2086
|
}
|
|
2069
2087
|
return { response, controller };
|
|
2070
2088
|
}
|