pendra 0.15.2 → 0.16.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 +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.js +86 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -13,21 +13,23 @@ var APIConnectionError = class extends APIError {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
var APIStatusError = class extends APIError {
|
|
16
|
-
constructor(message, status) {
|
|
16
|
+
constructor(message, status, options = {}) {
|
|
17
17
|
super(message, status);
|
|
18
18
|
this.name = "APIStatusError";
|
|
19
19
|
this.status = status;
|
|
20
|
+
this.body = options.body;
|
|
21
|
+
this.detail = options.detail;
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
var AuthenticationError = class extends APIStatusError {
|
|
23
|
-
constructor(message = "Invalid API key \u2014 check your PENDRA_API_KEY") {
|
|
24
|
-
super(message, 401);
|
|
25
|
+
constructor(message = "Invalid API key \u2014 check your PENDRA_API_KEY", options = {}) {
|
|
26
|
+
super(message, 401, options);
|
|
25
27
|
this.name = "AuthenticationError";
|
|
26
28
|
}
|
|
27
29
|
};
|
|
28
30
|
var RateLimitError = class extends APIStatusError {
|
|
29
|
-
constructor(message = "Rate limit exceeded") {
|
|
30
|
-
super(message, 429);
|
|
31
|
+
constructor(message = "Rate limit exceeded", options = {}) {
|
|
32
|
+
super(message, 429, options);
|
|
31
33
|
this.name = "RateLimitError";
|
|
32
34
|
}
|
|
33
35
|
};
|
|
@@ -58,6 +60,80 @@ var APIStreamError = class extends APIError {
|
|
|
58
60
|
this.workerName = options.workerName;
|
|
59
61
|
}
|
|
60
62
|
};
|
|
63
|
+
var LOC_SOURCES = /* @__PURE__ */ new Set(["body", "query", "path", "header", "cookie"]);
|
|
64
|
+
function isRecord(value) {
|
|
65
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
function nonEmptyString(value) {
|
|
68
|
+
return typeof value === "string" && value ? value : void 0;
|
|
69
|
+
}
|
|
70
|
+
function compactJson(value) {
|
|
71
|
+
try {
|
|
72
|
+
return JSON.stringify(value) ?? String(value);
|
|
73
|
+
} catch {
|
|
74
|
+
return String(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function messageFromItem(item) {
|
|
78
|
+
if (isRecord(item)) {
|
|
79
|
+
const msg = nonEmptyString(item.msg) ?? nonEmptyString(item.message);
|
|
80
|
+
if (msg) {
|
|
81
|
+
let field = typeof item.field === "string" ? item.field : void 0;
|
|
82
|
+
if (field === void 0) {
|
|
83
|
+
const loc = Array.isArray(item.loc) ? [...item.loc] : [];
|
|
84
|
+
if (loc.length && LOC_SOURCES.has(String(loc[0]))) loc.shift();
|
|
85
|
+
field = loc.map(String).join(".");
|
|
86
|
+
}
|
|
87
|
+
return field ? `${field}: ${msg}` : msg;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return messageFromDetail(item);
|
|
91
|
+
}
|
|
92
|
+
function messageFromDetail(detail) {
|
|
93
|
+
if (detail === void 0 || detail === null) return void 0;
|
|
94
|
+
if (typeof detail === "string") return detail || void 0;
|
|
95
|
+
if (Array.isArray(detail)) {
|
|
96
|
+
const parts = detail.map(messageFromItem).filter((p) => !!p);
|
|
97
|
+
return parts.length ? parts.join("; ") : void 0;
|
|
98
|
+
}
|
|
99
|
+
if (isRecord(detail)) {
|
|
100
|
+
const err = detail.error;
|
|
101
|
+
const nested = isRecord(err) ? nonEmptyString(err.message) : void 0;
|
|
102
|
+
const msg = nested ?? nonEmptyString(detail.message) ?? nonEmptyString(detail.msg);
|
|
103
|
+
if (msg) return msg;
|
|
104
|
+
return Object.keys(detail).length ? compactJson(detail) : void 0;
|
|
105
|
+
}
|
|
106
|
+
return compactJson(detail);
|
|
107
|
+
}
|
|
108
|
+
async function readErrorBody(response) {
|
|
109
|
+
let raw;
|
|
110
|
+
try {
|
|
111
|
+
raw = await response.text();
|
|
112
|
+
} catch {
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
if (!raw) return void 0;
|
|
116
|
+
try {
|
|
117
|
+
return JSON.parse(raw);
|
|
118
|
+
} catch {
|
|
119
|
+
return raw;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function statusErrorFromBody(status, body, fallback) {
|
|
123
|
+
const detail = isRecord(body) ? body.detail : void 0;
|
|
124
|
+
const err = isRecord(body) ? body.error : void 0;
|
|
125
|
+
let message = (isRecord(err) ? nonEmptyString(err.message) : void 0) ?? messageFromDetail(detail) ?? (isRecord(body) ? nonEmptyString(body.message) : void 0);
|
|
126
|
+
if (message === void 0) {
|
|
127
|
+
if (typeof body === "string") message = body || fallback;
|
|
128
|
+
else if (Array.isArray(body) ? body.length : isRecord(body) && Object.keys(body).length) {
|
|
129
|
+
message = compactJson(body);
|
|
130
|
+
} else message = fallback;
|
|
131
|
+
}
|
|
132
|
+
const options = { body, detail };
|
|
133
|
+
if (status === 401) return new AuthenticationError(message, options);
|
|
134
|
+
if (status === 429) return new RateLimitError(message, options);
|
|
135
|
+
return new APIStatusError(message, status, options);
|
|
136
|
+
}
|
|
61
137
|
|
|
62
138
|
// src/_privateInference.ts
|
|
63
139
|
import { chacha20poly1305 as chacha20poly13052 } from "@noble/ciphers/chacha.js";
|
|
@@ -574,21 +650,6 @@ function asBlob(file) {
|
|
|
574
650
|
}
|
|
575
651
|
return { blob: new Blob([content]), filename };
|
|
576
652
|
}
|
|
577
|
-
async function extractErrorDetail(response) {
|
|
578
|
-
let raw = "";
|
|
579
|
-
try {
|
|
580
|
-
raw = await response.text();
|
|
581
|
-
} catch {
|
|
582
|
-
return response.statusText;
|
|
583
|
-
}
|
|
584
|
-
if (!raw) return response.statusText;
|
|
585
|
-
try {
|
|
586
|
-
const body = JSON.parse(raw);
|
|
587
|
-
return body.detail ?? body.error?.message ?? raw;
|
|
588
|
-
} catch {
|
|
589
|
-
return raw;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
653
|
var Transcriptions = class {
|
|
593
654
|
constructor(client) {
|
|
594
655
|
this.client = client;
|
|
@@ -646,14 +707,8 @@ var Transcriptions = class {
|
|
|
646
707
|
}
|
|
647
708
|
clearTimeout(timeoutId);
|
|
648
709
|
if (response.status >= 400) {
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
throw new AuthenticationError(detail);
|
|
652
|
-
}
|
|
653
|
-
if (response.status === 429) {
|
|
654
|
-
throw new RateLimitError(detail);
|
|
655
|
-
}
|
|
656
|
-
throw new APIStatusError(detail, response.status);
|
|
710
|
+
const body = await readErrorBody(response);
|
|
711
|
+
throw statusErrorFromBody(response.status, body, response.statusText);
|
|
657
712
|
}
|
|
658
713
|
const format = params.response_format;
|
|
659
714
|
if (format === "text" || format === "srt" || format === "vtt") {
|
|
@@ -1285,7 +1340,7 @@ var Rerank = class {
|
|
|
1285
1340
|
};
|
|
1286
1341
|
|
|
1287
1342
|
// src/version.ts
|
|
1288
|
-
var VERSION = "0.
|
|
1343
|
+
var VERSION = "0.16.0";
|
|
1289
1344
|
var USER_AGENT = `pendra-node/${VERSION}`;
|
|
1290
1345
|
|
|
1291
1346
|
// src/_privateInferenceEngine.ts
|
|
@@ -1609,19 +1664,7 @@ var Pendra = class {
|
|
|
1609
1664
|
);
|
|
1610
1665
|
}
|
|
1611
1666
|
if (!response.ok) {
|
|
1612
|
-
|
|
1613
|
-
try {
|
|
1614
|
-
const body = await response.json();
|
|
1615
|
-
if (typeof body.detail === "string") message = body.detail;
|
|
1616
|
-
else if (typeof body.error?.message === "string") message = body.error.message;
|
|
1617
|
-
else if (body.detail != null) message = JSON.stringify(body.detail);
|
|
1618
|
-
else message = response.statusText;
|
|
1619
|
-
} catch {
|
|
1620
|
-
message = response.statusText;
|
|
1621
|
-
}
|
|
1622
|
-
if (response.status === 401) throw new AuthenticationError(message);
|
|
1623
|
-
if (response.status === 429) throw new RateLimitError(message);
|
|
1624
|
-
throw new APIStatusError(message, response.status);
|
|
1667
|
+
throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText);
|
|
1625
1668
|
}
|
|
1626
1669
|
const json = await response.json();
|
|
1627
1670
|
await engine.resolveOrgKey(json.keys ?? []);
|
|
@@ -1659,19 +1702,7 @@ var Pendra = class {
|
|
|
1659
1702
|
clearTimeout(timeoutId);
|
|
1660
1703
|
if (!response.ok) {
|
|
1661
1704
|
this.invalidateKeyCacheIfRekeyed(response);
|
|
1662
|
-
|
|
1663
|
-
try {
|
|
1664
|
-
const body = await response.json();
|
|
1665
|
-
if (typeof body.detail === "string") message = body.detail;
|
|
1666
|
-
else if (typeof body.error?.message === "string") message = body.error.message;
|
|
1667
|
-
else if (body.detail != null) message = JSON.stringify(body.detail);
|
|
1668
|
-
else message = response.statusText;
|
|
1669
|
-
} catch {
|
|
1670
|
-
message = response.statusText;
|
|
1671
|
-
}
|
|
1672
|
-
if (response.status === 401) throw new AuthenticationError(message);
|
|
1673
|
-
if (response.status === 429) throw new RateLimitError(message);
|
|
1674
|
-
throw new APIStatusError(message, response.status);
|
|
1705
|
+
throw statusErrorFromBody(response.status, await readErrorBody(response), response.statusText);
|
|
1675
1706
|
}
|
|
1676
1707
|
return { response, controller };
|
|
1677
1708
|
}
|