@premai/api-sdk 1.0.31 → 1.0.32
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/bare-global.d.ts +4 -0
- package/dist/bare-global.mjs +30 -0
- package/dist/cli.cjs +15 -3
- package/dist/core.browser.cjs +28 -4
- package/dist/core.browser.mjs +25168 -874
- package/dist/index.cjs +20 -4
- package/dist/index.mjs +23 -4
- package/dist/utils/attestation.d.ts +3 -3
- package/package.json +31 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/bare-global.ts
|
|
2
|
+
import"bare-abort-controller/global";
|
|
3
|
+
import"bare-crypto/global";
|
|
4
|
+
import"bare-encoding/global";
|
|
5
|
+
import"bare-fetch/global";
|
|
6
|
+
import bareProcess from "bare-process";
|
|
7
|
+
if (typeof globalThis.process === "undefined") {
|
|
8
|
+
globalThis.process = bareProcess;
|
|
9
|
+
}
|
|
10
|
+
var SHIMS = [
|
|
11
|
+
["fs", "bare-fs"],
|
|
12
|
+
["crypto", "bare-crypto"]
|
|
13
|
+
];
|
|
14
|
+
var seen = new WeakSet;
|
|
15
|
+
for (const mod of Object.values(import.meta.cache)) {
|
|
16
|
+
const proto = mod?._protocol;
|
|
17
|
+
if (!proto || seen.has(proto))
|
|
18
|
+
continue;
|
|
19
|
+
seen.add(proto);
|
|
20
|
+
const original = proto.preresolve.bind(proto);
|
|
21
|
+
proto.preresolve = function(specifier, parentURL) {
|
|
22
|
+
for (const [from, to] of SHIMS) {
|
|
23
|
+
if (specifier === from)
|
|
24
|
+
return to;
|
|
25
|
+
if (specifier.startsWith(from + "/"))
|
|
26
|
+
return to + specifier.slice(from.length);
|
|
27
|
+
}
|
|
28
|
+
return original(specifier, parentURL);
|
|
29
|
+
};
|
|
30
|
+
}
|
package/dist/cli.cjs
CHANGED
|
@@ -50,12 +50,24 @@ var DEFAULT_REQUEST_TIMEOUT_MS = 60000;
|
|
|
50
50
|
var DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
51
51
|
|
|
52
52
|
// src/utils/attestation.ts
|
|
53
|
-
var
|
|
53
|
+
var cachedPrem;
|
|
54
|
+
async function loadPrem() {
|
|
55
|
+
if (cachedPrem)
|
|
56
|
+
return cachedPrem;
|
|
57
|
+
const isBare = typeof globalThis.Bare !== "undefined";
|
|
58
|
+
if (isBare) {
|
|
59
|
+
cachedPrem = await import("@premai/prem-rs", { with: { type: "script" } });
|
|
60
|
+
return cachedPrem;
|
|
61
|
+
}
|
|
62
|
+
cachedPrem = await import("@premai/prem-rs");
|
|
63
|
+
return cachedPrem;
|
|
64
|
+
}
|
|
54
65
|
async function attest(apiKey, options = { enabled: true }) {
|
|
55
66
|
if (!options.enabled)
|
|
56
67
|
return null;
|
|
57
|
-
const
|
|
58
|
-
|
|
68
|
+
const prem = await loadPrem();
|
|
69
|
+
const client = await new prem.ClientBuilder(endpoints.proxy ?? "").with_authorization(apiKey).build();
|
|
70
|
+
let query = new prem.QueryParams;
|
|
59
71
|
if (options.model)
|
|
60
72
|
query = query.with("model", options.model);
|
|
61
73
|
try {
|
package/dist/core.browser.cjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
1
9
|
// src/audio/index.ts
|
|
2
10
|
import { bytesToHex as bytesToHex2, hexToBytes as hexToBytes2 } from "@noble/ciphers/utils.js";
|
|
3
11
|
|
|
@@ -10,12 +18,27 @@ var DEFAULT_REQUEST_TIMEOUT_MS = 60000;
|
|
|
10
18
|
var DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
11
19
|
|
|
12
20
|
// src/utils/attestation.ts
|
|
13
|
-
|
|
21
|
+
var cachedPrem;
|
|
22
|
+
async function loadPrem() {
|
|
23
|
+
if (cachedPrem)
|
|
24
|
+
return cachedPrem;
|
|
25
|
+
const isBare = typeof globalThis.Bare !== "undefined";
|
|
26
|
+
if (isBare) {
|
|
27
|
+
cachedPrem = await import("@premai/prem-rs", { with: { type: "script" } });
|
|
28
|
+
return cachedPrem;
|
|
29
|
+
}
|
|
30
|
+
cachedPrem = await import("@premai/prem-rs");
|
|
31
|
+
return cachedPrem;
|
|
32
|
+
}
|
|
14
33
|
function isAttestationError(err) {
|
|
15
34
|
return err instanceof Error && err.name === "AttestationError";
|
|
16
35
|
}
|
|
17
36
|
function isGatewayError(err) {
|
|
18
|
-
|
|
37
|
+
if (!isAttestationError(err))
|
|
38
|
+
return false;
|
|
39
|
+
if (!cachedPrem)
|
|
40
|
+
return false;
|
|
41
|
+
return err.kind instanceof cachedPrem.GatewayError;
|
|
19
42
|
}
|
|
20
43
|
function getGatewayErrorMessage(err) {
|
|
21
44
|
if (isGatewayError(err))
|
|
@@ -25,8 +48,9 @@ function getGatewayErrorMessage(err) {
|
|
|
25
48
|
async function attest(apiKey, options = { enabled: true }) {
|
|
26
49
|
if (!options.enabled)
|
|
27
50
|
return null;
|
|
28
|
-
const
|
|
29
|
-
|
|
51
|
+
const prem = await loadPrem();
|
|
52
|
+
const client = await new prem.ClientBuilder(endpoints.proxy ?? "").with_authorization(apiKey).build();
|
|
53
|
+
let query = new prem.QueryParams;
|
|
30
54
|
if (options.model)
|
|
31
55
|
query = query.with("model", options.model);
|
|
32
56
|
try {
|