pendra 0.10.0 → 0.12.2
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 +38 -0
- package/dist/index.d.mts +167 -1
- package/dist/index.d.ts +167 -1
- package/dist/index.js +52 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -106,6 +106,7 @@ var Transcriptions = class {
|
|
|
106
106
|
if (params.prompt) form.append("prompt", params.prompt);
|
|
107
107
|
if (params.response_format) form.append("response_format", params.response_format);
|
|
108
108
|
if (params.temperature != null) form.append("temperature", String(params.temperature));
|
|
109
|
+
if (params.beam_size != null) form.append("beam_size", String(params.beam_size));
|
|
109
110
|
if (params.timestamp_granularities) {
|
|
110
111
|
for (const g of params.timestamp_granularities) {
|
|
111
112
|
form.append("timestamp_granularities[]", g);
|
|
@@ -621,6 +622,10 @@ var Rerank = class {
|
|
|
621
622
|
}
|
|
622
623
|
};
|
|
623
624
|
|
|
625
|
+
// src/version.ts
|
|
626
|
+
var VERSION = "0.12.2";
|
|
627
|
+
var USER_AGENT = `pendra-node/${VERSION}`;
|
|
628
|
+
|
|
624
629
|
// src/_hpke.ts
|
|
625
630
|
import { x25519 } from "@noble/curves/ed25519.js";
|
|
626
631
|
import { chacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
@@ -1014,6 +1019,27 @@ var PrivateInferenceEngine = class {
|
|
|
1014
1019
|
const digest = sha256Hex(new TextEncoder().encode(this.apiKey)).slice(0, 16);
|
|
1015
1020
|
return `${this.baseUrl}|${digest}`;
|
|
1016
1021
|
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Drop the cached key set so the next call re-fetches it.
|
|
1024
|
+
*
|
|
1025
|
+
* The cache is otherwise held for the whole process lifetime, which is
|
|
1026
|
+
* correct while a fleet keeps one key but fatal when it re-keys: a
|
|
1027
|
+
* long-running server would go on sealing to a fingerprint no worker holds
|
|
1028
|
+
* and fail EVERY request until someone restarted it. The API signals a re-key
|
|
1029
|
+
* with `X-Pendra-Error-Code: no_private_inference_worker`, and this is what
|
|
1030
|
+
* lets the client recover on its own.
|
|
1031
|
+
*
|
|
1032
|
+
* Pinned clients are deliberately NOT re-fetched on that signal — a pin is an
|
|
1033
|
+
* allowlist, so a fetch could only return fingerprints the pin already
|
|
1034
|
+
* rejects. They surface the error instead, which is what pinning means.
|
|
1035
|
+
*/
|
|
1036
|
+
invalidateOrgKey() {
|
|
1037
|
+
this.orgPubs = null;
|
|
1038
|
+
}
|
|
1039
|
+
/** Whether this client seals only to an explicit fingerprint allowlist. */
|
|
1040
|
+
get isPinned() {
|
|
1041
|
+
return this.pinnedFingerprints !== null;
|
|
1042
|
+
}
|
|
1017
1043
|
/**
|
|
1018
1044
|
* Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
|
|
1019
1045
|
* allowlist (or auto-trust TOFU), cache the accepted public keys, and return
|
|
@@ -1026,7 +1052,7 @@ var PrivateInferenceEngine = class {
|
|
|
1026
1052
|
if (this.orgPubs !== null) return this.orgPubs;
|
|
1027
1053
|
if (!fetchedKeys || fetchedKeys.length === 0) {
|
|
1028
1054
|
throw new PrivateInferenceError(
|
|
1029
|
-
"No
|
|
1055
|
+
"No encryption key is registered for this organisation. Start a worker and it will be issued one automatically."
|
|
1030
1056
|
);
|
|
1031
1057
|
}
|
|
1032
1058
|
const pubs = [];
|
|
@@ -1052,7 +1078,7 @@ var PrivateInferenceEngine = class {
|
|
|
1052
1078
|
if (accepted.length === 0) {
|
|
1053
1079
|
const pinned = Array.from(this.pinnedFingerprints).sort().join(", ");
|
|
1054
1080
|
throw new PrivateInferenceError(
|
|
1055
|
-
`None of the org's workload key fingerprints (${fps.join(", ")}) match your pinned fingerprint(s) (${pinned}). Refusing to seal (possible man-in-the-middle).
|
|
1081
|
+
`None of the org's workload key fingerprints (${fps.join(", ")}) match your pinned fingerprint(s) (${pinned}). Refusing to seal (possible man-in-the-middle). If your fleet re-keyed \u2014 which happens when every worker goes offline at once \u2014 update the pin to a current fingerprint from the console.`
|
|
1056
1082
|
);
|
|
1057
1083
|
}
|
|
1058
1084
|
} else {
|
|
@@ -1226,7 +1252,7 @@ var Pendra = class {
|
|
|
1226
1252
|
try {
|
|
1227
1253
|
response = await fetch(url, {
|
|
1228
1254
|
method: "GET",
|
|
1229
|
-
headers: { Authorization: `Bearer ${this.apiKey}
|
|
1255
|
+
headers: { Authorization: `Bearer ${this.apiKey}`, "User-Agent": USER_AGENT },
|
|
1230
1256
|
signal: controller.signal
|
|
1231
1257
|
});
|
|
1232
1258
|
} catch (err) {
|
|
@@ -1241,7 +1267,7 @@ var Pendra = class {
|
|
|
1241
1267
|
}
|
|
1242
1268
|
if (response.status === 404) {
|
|
1243
1269
|
throw new PrivateInferenceError(
|
|
1244
|
-
"No
|
|
1270
|
+
"No encryption key is registered for this organisation. Start a worker and it will be issued one automatically."
|
|
1245
1271
|
);
|
|
1246
1272
|
}
|
|
1247
1273
|
if (!response.ok) {
|
|
@@ -1266,6 +1292,7 @@ var Pendra = class {
|
|
|
1266
1292
|
const headers = {
|
|
1267
1293
|
Authorization: `Bearer ${this.apiKey}`,
|
|
1268
1294
|
"Content-Type": "application/json",
|
|
1295
|
+
"User-Agent": USER_AGENT,
|
|
1269
1296
|
...options.headers ?? {}
|
|
1270
1297
|
};
|
|
1271
1298
|
let response;
|
|
@@ -1292,6 +1319,7 @@ var Pendra = class {
|
|
|
1292
1319
|
}
|
|
1293
1320
|
if (!response.ok) {
|
|
1294
1321
|
clearTimeout(timeoutId);
|
|
1322
|
+
this.invalidateKeyCacheIfRekeyed(response);
|
|
1295
1323
|
let message;
|
|
1296
1324
|
try {
|
|
1297
1325
|
const body = await response.json();
|
|
@@ -1305,6 +1333,26 @@ var Pendra = class {
|
|
|
1305
1333
|
}
|
|
1306
1334
|
return { response, controller };
|
|
1307
1335
|
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Drop the cached encryption keys when the API reports that no worker holds
|
|
1338
|
+
* the one this request was sealed to — the signal that the org's fleet has
|
|
1339
|
+
* re-keyed. Returns true if the cache was dropped.
|
|
1340
|
+
*
|
|
1341
|
+
* A PINNED client is left alone on purpose: a pin is an allowlist, so
|
|
1342
|
+
* re-fetching could only return fingerprints the pin already rejects and
|
|
1343
|
+
* would loop rather than recover. The error surfaces instead, which is
|
|
1344
|
+
* exactly what pinning is for.
|
|
1345
|
+
*/
|
|
1346
|
+
invalidateKeyCacheIfRekeyed(response) {
|
|
1347
|
+
const engine = this._piEngine;
|
|
1348
|
+
if (!engine || engine.isPinned) return false;
|
|
1349
|
+
if (response.headers?.get("X-Pendra-Error-Code") !== "no_private_inference_worker") {
|
|
1350
|
+
return false;
|
|
1351
|
+
}
|
|
1352
|
+
engine.invalidateOrgKey();
|
|
1353
|
+
this._piKeyFetch = null;
|
|
1354
|
+
return true;
|
|
1355
|
+
}
|
|
1308
1356
|
};
|
|
1309
1357
|
|
|
1310
1358
|
// src/index.ts
|