pendra 0.20.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/dist/index.d.mts CHANGED
@@ -984,8 +984,21 @@ declare class APIStatusError extends APIError {
984
984
  declare class AuthenticationError extends APIStatusError {
985
985
  constructor(message?: string, options?: APIStatusErrorOptions);
986
986
  }
987
+ /**
988
+ * Raised on 429 Too Many Requests: every worker that can serve the request is
989
+ * busy, on a stream as on any other request.
990
+ *
991
+ * `retryAfter` is the seconds the API asks you to wait before retrying (its
992
+ * `Retry-After` header), `queueDepth` how many requests were already waiting
993
+ * for the model (`X-Pendra-Queue-Depth`); each is `undefined` when not sent.
994
+ */
987
995
  declare class RateLimitError extends APIStatusError {
988
- constructor(message?: string, options?: APIStatusErrorOptions);
996
+ readonly retryAfter: number | undefined;
997
+ readonly queueDepth: number | undefined;
998
+ constructor(message?: string, options?: APIStatusErrorOptions & {
999
+ retryAfter?: number;
1000
+ queueDepth?: number;
1001
+ });
989
1002
  }
990
1003
  /**
991
1004
  * Raised when a response arrives but isn't the shape the SDK expects.
@@ -1032,12 +1045,16 @@ declare class APIStreamError extends APIError {
1032
1045
  readonly requestId: string | undefined;
1033
1046
  readonly workerId: string | undefined;
1034
1047
  readonly workerName: string | undefined;
1048
+ /** Seconds to wait before retrying when the report carried one (a capacity
1049
+ * 429), else `undefined`. Same meaning as on `RateLimitError`. */
1050
+ readonly retryAfter: number | undefined;
1035
1051
  constructor(message: string, options?: {
1036
1052
  type?: string;
1037
1053
  code?: number;
1038
1054
  requestId?: string;
1039
1055
  workerId?: string;
1040
1056
  workerName?: string;
1057
+ retryAfter?: number;
1041
1058
  });
1042
1059
  }
1043
1060
 
package/dist/index.d.ts CHANGED
@@ -984,8 +984,21 @@ declare class APIStatusError extends APIError {
984
984
  declare class AuthenticationError extends APIStatusError {
985
985
  constructor(message?: string, options?: APIStatusErrorOptions);
986
986
  }
987
+ /**
988
+ * Raised on 429 Too Many Requests: every worker that can serve the request is
989
+ * busy, on a stream as on any other request.
990
+ *
991
+ * `retryAfter` is the seconds the API asks you to wait before retrying (its
992
+ * `Retry-After` header), `queueDepth` how many requests were already waiting
993
+ * for the model (`X-Pendra-Queue-Depth`); each is `undefined` when not sent.
994
+ */
987
995
  declare class RateLimitError extends APIStatusError {
988
- constructor(message?: string, options?: APIStatusErrorOptions);
996
+ readonly retryAfter: number | undefined;
997
+ readonly queueDepth: number | undefined;
998
+ constructor(message?: string, options?: APIStatusErrorOptions & {
999
+ retryAfter?: number;
1000
+ queueDepth?: number;
1001
+ });
989
1002
  }
990
1003
  /**
991
1004
  * Raised when a response arrives but isn't the shape the SDK expects.
@@ -1032,12 +1045,16 @@ declare class APIStreamError extends APIError {
1032
1045
  readonly requestId: string | undefined;
1033
1046
  readonly workerId: string | undefined;
1034
1047
  readonly workerName: string | undefined;
1048
+ /** Seconds to wait before retrying when the report carried one (a capacity
1049
+ * 429), else `undefined`. Same meaning as on `RateLimitError`. */
1050
+ readonly retryAfter: number | undefined;
1035
1051
  constructor(message: string, options?: {
1036
1052
  type?: string;
1037
1053
  code?: number;
1038
1054
  requestId?: string;
1039
1055
  workerId?: string;
1040
1056
  workerName?: string;
1057
+ retryAfter?: number;
1041
1058
  });
1042
1059
  }
1043
1060
 
package/dist/index.js CHANGED
@@ -77,8 +77,18 @@ var RateLimitError = class extends APIStatusError {
77
77
  constructor(message = "Rate limit exceeded", options = {}) {
78
78
  super(message, 429, options);
79
79
  this.name = "RateLimitError";
80
+ this.retryAfter = options.retryAfter;
81
+ this.queueDepth = options.queueDepth;
80
82
  }
81
83
  };
84
+ function secondsFrom(...candidates) {
85
+ for (const value of candidates) {
86
+ if (typeof value !== "number" && (typeof value !== "string" || value.trim() === "")) continue;
87
+ const n = Number(value);
88
+ if (Number.isFinite(n) && n >= 0) return n;
89
+ }
90
+ return void 0;
91
+ }
82
92
  var _APIResponseValidationError = class _APIResponseValidationError extends APIError {
83
93
  constructor(message, options = {}) {
84
94
  const { status, body } = options;
@@ -104,6 +114,7 @@ var APIStreamError = class extends APIError {
104
114
  this.requestId = options.requestId;
105
115
  this.workerId = options.workerId;
106
116
  this.workerName = options.workerName;
117
+ this.retryAfter = options.retryAfter;
107
118
  }
108
119
  };
109
120
  var LOC_SOURCES = /* @__PURE__ */ new Set(["body", "query", "path", "header", "cookie"]);
@@ -165,7 +176,7 @@ async function readErrorBody(response) {
165
176
  return raw;
166
177
  }
167
178
  }
168
- function statusErrorFromBody(status, body, fallback) {
179
+ function statusErrorFromBody(status, body, fallback, headers) {
169
180
  const detail = isRecord(body) ? body.detail : void 0;
170
181
  const err = isRecord(body) ? body.error : void 0;
171
182
  let message = (isRecord(err) ? nonEmptyString(err.message) : void 0) ?? messageFromDetail(detail) ?? (isRecord(body) ? nonEmptyString(body.message) : void 0);
@@ -177,7 +188,13 @@ function statusErrorFromBody(status, body, fallback) {
177
188
  }
178
189
  const options = { body, detail };
179
190
  if (status === 401) return new AuthenticationError(message, options);
180
- if (status === 429) return new RateLimitError(message, options);
191
+ if (status === 429) {
192
+ return new RateLimitError(message, {
193
+ ...options,
194
+ retryAfter: secondsFrom(headers?.get("Retry-After"), isRecord(err) ? err.retry_after : void 0),
195
+ queueDepth: secondsFrom(headers?.get("X-Pendra-Queue-Depth"), isRecord(err) ? err.queue_depth : void 0)
196
+ });
197
+ }
181
198
  return new APIStatusError(message, status, options);
182
199
  }
183
200
 
@@ -579,7 +596,8 @@ function throwIfInBandError(parsed, fallback = "The server reported an error mid
579
596
  code: typeof e.code === "number" ? e.code : void 0,
580
597
  requestId: asString(e.request_id),
581
598
  workerId: asString(e.worker_id),
582
- workerName: asString(e.worker_name)
599
+ workerName: asString(e.worker_name),
600
+ retryAfter: secondsFrom(e.retry_after)
583
601
  }
584
602
  );
585
603
  }
@@ -1169,7 +1187,7 @@ var Transcriptions = class {
1169
1187
  clearTimeout(timeoutId);
1170
1188
  if (response.status >= 400) {
1171
1189
  const body = await readErrorBody(response);
1172
- throw statusErrorFromBody(response.status, body, response.statusText);
1190
+ throw statusErrorFromBody(response.status, body, response.statusText, response.headers);
1173
1191
  }
1174
1192
  const format = params.response_format;
1175
1193
  if (format === "text" || format === "srt" || format === "vtt") {
@@ -1957,7 +1975,7 @@ var Rerank = class {
1957
1975
  };
1958
1976
 
1959
1977
  // src/version.ts
1960
- var VERSION = "0.20.0";
1978
+ var VERSION = "0.21.0";
1961
1979
  var USER_AGENT = `pendra-node/${VERSION}`;
1962
1980
 
1963
1981
  // src/client.ts
@@ -2072,7 +2090,7 @@ var Pendra = class {
2072
2090
  );
2073
2091
  }
2074
2092
  if (!response.ok) {
2075
- throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText);
2093
+ throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText, response.headers);
2076
2094
  }
2077
2095
  const json = await response.json();
2078
2096
  await engine.resolveOrgKey(json.keys ?? []);
@@ -2110,7 +2128,7 @@ var Pendra = class {
2110
2128
  clearTimeout(timeoutId);
2111
2129
  if (!response.ok) {
2112
2130
  this.invalidateKeyCacheIfRekeyed(response);
2113
- throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText);
2131
+ throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText, response.headers);
2114
2132
  }
2115
2133
  return { response, controller };
2116
2134
  }