@mux/ai 0.50.0 → 0.51.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.ts CHANGED
@@ -10,7 +10,7 @@ import '@ai-sdk/google';
10
10
  import '@ai-sdk/openai';
11
11
  import '@mux/ts';
12
12
 
13
- var version = "0.50.0";
13
+ var version = "0.51.0";
14
14
 
15
15
  type MuxAiErrorType = "validation_error" | "processing_error" | "timeout_error" | "content_policy_error";
16
16
  /**
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // package.json
8
- var version = "0.50.0";
8
+ var version = "0.51.0";
9
9
 
10
10
  // src/lib/language-codes.ts
11
11
  var ISO639_1_TO_3 = {
@@ -8586,6 +8586,54 @@ async function getSummaryAndTagsInternal(assetId, options, collectedUsage) {
8586
8586
 
8587
8587
  // src/workflows/translate-audio.ts
8588
8588
  import { sleep as sleep2 } from "workflow";
8589
+
8590
+ // src/lib/elevenlabs-errors.ts
8591
+ var MAX_ERROR_BODY_CHARS = 500;
8592
+ async function elevenLabsResponseError(context, response) {
8593
+ const error = new Error(`${context}: ${await describeElevenLabsErrorResponse(response)}`);
8594
+ if (!isRetryableElevenLabsStatus(response.status)) {
8595
+ error.name = "FatalError";
8596
+ }
8597
+ return error;
8598
+ }
8599
+ function isRetryableElevenLabsStatus(status) {
8600
+ return status === 408 || status === 425 || status === 429 || status >= 500;
8601
+ }
8602
+ async function describeElevenLabsErrorResponse(response) {
8603
+ const statusLine = [response.status, response.statusText].filter(Boolean).join(" ");
8604
+ const body = await response.text().catch(() => "");
8605
+ const detail = formatElevenLabsErrorBody(body);
8606
+ return detail ? `${statusLine}: ${detail}` : statusLine;
8607
+ }
8608
+ function formatElevenLabsErrorBody(body) {
8609
+ const trimmed = body.trim();
8610
+ if (!trimmed) {
8611
+ return "";
8612
+ }
8613
+ let detail;
8614
+ try {
8615
+ detail = JSON.parse(trimmed).detail;
8616
+ } catch {
8617
+ return trimmed.slice(0, MAX_ERROR_BODY_CHARS);
8618
+ }
8619
+ if (typeof detail === "string" && detail) {
8620
+ return detail;
8621
+ }
8622
+ if (Array.isArray(detail) && detail.length > 0) {
8623
+ return detail.map((item) => [item.loc?.join("."), item.msg].filter(Boolean).join(": ")).join("; ");
8624
+ }
8625
+ if (detail && typeof detail === "object") {
8626
+ const { status, code, message, param, request_id: requestId } = detail;
8627
+ const reason = [status ?? code, message].filter(Boolean).join(": ");
8628
+ const context = [param && `param: ${param}`, requestId && `request_id: ${requestId}`].filter(Boolean).join(", ");
8629
+ if (reason) {
8630
+ return context ? `${reason} (${context})` : reason;
8631
+ }
8632
+ }
8633
+ return trimmed.slice(0, MAX_ERROR_BODY_CHARS);
8634
+ }
8635
+
8636
+ // src/workflows/translate-audio.ts
8589
8637
  var STATIC_RENDITION_POLL_INTERVAL_MS = 1e4;
8590
8638
  var STATIC_RENDITION_MAX_ATTEMPTS = 180;
8591
8639
  var MAX_DUBBING_SOURCE_BYTES = 1e9;
@@ -8752,7 +8800,7 @@ async function createElevenLabsDubbingJob({
8752
8800
  body: formData
8753
8801
  });
8754
8802
  if (!dubbingResponse.ok) {
8755
- throw new Error(`ElevenLabs API error: ${dubbingResponse.statusText}`);
8803
+ throw await elevenLabsResponseError("ElevenLabs API error", dubbingResponse);
8756
8804
  }
8757
8805
  const dubbingData = await dubbingResponse.json();
8758
8806
  return dubbingData.dubbing_id;
@@ -8769,12 +8817,13 @@ async function checkElevenLabsDubbingStatus({
8769
8817
  }
8770
8818
  });
8771
8819
  if (!statusResponse.ok) {
8772
- throw new Error(`Status check failed: ${statusResponse.statusText}`);
8820
+ throw await elevenLabsResponseError("Status check failed", statusResponse);
8773
8821
  }
8774
8822
  const statusData = await statusResponse.json();
8775
8823
  return {
8776
8824
  status: statusData.status,
8777
- targetLanguages: statusData.target_languages ?? []
8825
+ targetLanguages: statusData.target_languages ?? [],
8826
+ error: typeof statusData.error === "string" && statusData.error ? statusData.error : void 0
8778
8827
  };
8779
8828
  }
8780
8829
  async function downloadAndUploadDubbedAudio({
@@ -8798,7 +8847,7 @@ async function downloadAndUploadDubbedAudio({
8798
8847
  }
8799
8848
  });
8800
8849
  if (!audioResponse.ok) {
8801
- throw new Error(`Failed to fetch dubbed audio: ${audioResponse.statusText}`);
8850
+ throw await elevenLabsResponseError("Failed to fetch dubbed audio", audioResponse);
8802
8851
  }
8803
8852
  const dubbedAudio = new Uint8Array(await audioResponse.arrayBuffer());
8804
8853
  const s3AccessKeyId = env_default.S3_ACCESS_KEY_ID;
@@ -8849,7 +8898,7 @@ async function downloadAndUploadDubTranscript({
8849
8898
  }
8850
8899
  });
8851
8900
  if (!transcriptResponse.ok) {
8852
- throw new Error(`Failed to fetch dub transcript: ${transcriptResponse.statusText}`);
8901
+ throw await elevenLabsResponseError("Failed to fetch dub transcript", transcriptResponse);
8853
8902
  }
8854
8903
  const transcriptBody = await transcriptResponse.json();
8855
8904
  const transcriptVtt = transcriptBody.webvtt;
@@ -9002,6 +9051,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
9002
9051
  let dubbingStatus = "dubbing";
9003
9052
  let pollAttempts = 0;
9004
9053
  let targetLanguages = [];
9054
+ let dubbingError;
9005
9055
  while (dubbingStatus !== "dubbed" && pollAttempts < maxPollAttempts) {
9006
9056
  await sleep2(DUBBING_POLL_INTERVAL_MS);
9007
9057
  pollAttempts++;
@@ -9012,10 +9062,12 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
9012
9062
  });
9013
9063
  dubbingStatus = statusResult.status;
9014
9064
  targetLanguages = statusResult.targetLanguages;
9065
+ dubbingError = statusResult.error;
9015
9066
  } catch (error) {
9016
9067
  wrapError(error, "Failed to check dubbing status");
9017
9068
  }
9018
9069
  if (dubbingStatus === "failed") {
9070
+ console.warn(`\u274C ElevenLabs dubbing job ${dubbingId} failed: ${dubbingError ?? "no error reported"}`);
9019
9071
  throw new MuxAiError("ElevenLabs reported that the dubbing job failed.", { type: "processing_error" });
9020
9072
  }
9021
9073
  }