pendra 0.17.1 → 0.17.3

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.mjs CHANGED
@@ -1037,17 +1037,27 @@ var MIME_EXT = {
1037
1037
  "audio/x-flac": "flac"
1038
1038
  };
1039
1039
  function extFromMime(type) {
1040
- if (!type) return "mp3";
1040
+ if (!type) return void 0;
1041
1041
  const base = type.split(";")[0].trim().toLowerCase();
1042
- return MIME_EXT[base] ?? "mp3";
1043
- }
1044
- function asBlob(file) {
1042
+ return MIME_EXT[base];
1043
+ }
1044
+ async function extFromHeader(blob) {
1045
+ const head = new Uint8Array(await blob.slice(0, 12).arrayBuffer());
1046
+ const ascii = (from, to) => String.fromCharCode(...head.subarray(from, to));
1047
+ if (head.length >= 12 && ascii(0, 4) === "RIFF" && ascii(8, 12) === "WAVE") return "wav";
1048
+ if (head.length >= 4 && ascii(0, 4) === "fLaC") return "flac";
1049
+ if (head.length >= 3 && ascii(0, 3) === "ID3") return "mp3";
1050
+ if (head.length >= 2 && head[0] === 255 && (head[1] & 224) === 224) return "mp3";
1051
+ return void 0;
1052
+ }
1053
+ async function asBlob(file) {
1045
1054
  if (file instanceof Blob) {
1046
1055
  const asFile = file;
1047
1056
  if (asFile.name) {
1048
1057
  return { blob: file, filename: asFile.name };
1049
1058
  }
1050
- return { blob: file, filename: `audio.${extFromMime(file.type)}` };
1059
+ const ext = extFromMime(file.type) ?? await extFromHeader(file);
1060
+ return { blob: file, filename: ext ? `audio.${ext}` : "audio" };
1051
1061
  }
1052
1062
  const { filename, content } = file;
1053
1063
  if (content instanceof Blob) {
@@ -1066,7 +1076,7 @@ var Transcriptions = class {
1066
1076
  if (params.beam_size != null && !(Number.isInteger(params.beam_size) && params.beam_size >= 1 && params.beam_size <= 8)) {
1067
1077
  throw new Error(`beam_size must be an integer between 1 and 8 (got ${params.beam_size})`);
1068
1078
  }
1069
- const { blob, filename } = asBlob(params.file);
1079
+ const { blob, filename } = await asBlob(params.file);
1070
1080
  if (blob.size === 0) {
1071
1081
  throw new Error("audio file is empty");
1072
1082
  }
@@ -1780,7 +1790,7 @@ var Rerank = class {
1780
1790
  };
1781
1791
 
1782
1792
  // src/version.ts
1783
- var VERSION = "0.17.1";
1793
+ var VERSION = "0.17.3";
1784
1794
  var USER_AGENT = `pendra-node/${VERSION}`;
1785
1795
 
1786
1796
  // src/client.ts
@@ -1887,8 +1897,10 @@ var Pendra = class {
1887
1897
  clearTimeout(timeoutId);
1888
1898
  }
1889
1899
  if (response.status === 404) {
1900
+ const body = await readErrorBody(response);
1901
+ const detail = typeof body === "object" && body !== null ? body.detail : void 0;
1890
1902
  throw new PrivateInferenceError(
1891
- "No encryption key is registered for this organisation. Start a worker and it will be issued one automatically."
1903
+ messageFromDetail(detail) ?? "No encryption key is registered for this organisation. Start a worker and it will be issued one automatically."
1892
1904
  );
1893
1905
  }
1894
1906
  if (!response.ok) {