@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.
@@ -0,0 +1,4 @@
1
+ import "bare-abort-controller/global";
2
+ import "bare-crypto/global";
3
+ import "bare-encoding/global";
4
+ import "bare-fetch/global";
@@ -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 import_prem_rs = require("@premai/prem-rs");
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 client = await new import_prem_rs.ClientBuilder(endpoints.proxy ?? "").with_authorization(apiKey).build();
58
- let query = new import_prem_rs.QueryParams;
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 {
@@ -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
- import { ClientBuilder, GatewayError, QueryParams } from "@premai/prem-rs";
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
- return isAttestationError(err) && err.kind instanceof GatewayError;
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 client = await new ClientBuilder(endpoints.proxy ?? "").with_authorization(apiKey).build();
29
- let query = new QueryParams;
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 {