@mux/ai 0.49.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.49.0";
13
+ var version = "0.51.0";
14
14
 
15
15
  type MuxAiErrorType = "validation_error" | "processing_error" | "timeout_error" | "content_policy_error";
16
16
  /**
@@ -116,7 +116,6 @@ interface WorkflowStorageClientOptions {
116
116
  * operations compatible across edge/ESM and Node runtimes.
117
117
  */
118
118
  declare class WorkflowStorageClient {
119
- static classId: string;
120
119
  private readonly accessKeyId?;
121
120
  private readonly secretAccessKey?;
122
121
  constructor(options?: WorkflowStorageClientOptions);
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.49.0";
8
+ var version = "0.51.0";
9
9
 
10
10
  // src/lib/language-codes.ts
11
11
  var ISO639_1_TO_3 = {
@@ -1741,27 +1741,6 @@ async function createPresignedGetUrl({
1741
1741
  return `${resolvedEndpoint.origin}${canonicalUri}?${queryWithSignature}`;
1742
1742
  }
1743
1743
 
1744
- // src/lib/workflow-serialization.ts
1745
- var WORKFLOW_CLASS_REGISTRY = /* @__PURE__ */ Symbol.for("workflow-class-registry");
1746
- function registerWorkflowSerializationClass(classId, cls) {
1747
- const globalObject = globalThis;
1748
- let registry = globalObject[WORKFLOW_CLASS_REGISTRY];
1749
- if (!registry) {
1750
- registry = /* @__PURE__ */ new Map();
1751
- globalObject[WORKFLOW_CLASS_REGISTRY] = registry;
1752
- }
1753
- registry.set(classId, cls);
1754
- const serializableClass = cls;
1755
- if (serializableClass.classId !== classId) {
1756
- Object.defineProperty(cls, "classId", {
1757
- value: classId,
1758
- writable: false,
1759
- enumerable: false,
1760
- configurable: false
1761
- });
1762
- }
1763
- }
1764
-
1765
1744
  // src/lib/workflow-storage-client.ts
1766
1745
  var WorkflowStorageClient = class {
1767
1746
  constructor(options = {}) {
@@ -1813,8 +1792,6 @@ var WorkflowStorageClient = class {
1813
1792
  return new this(value);
1814
1793
  }
1815
1794
  };
1816
- WorkflowStorageClient.classId = "WorkflowStorageClient";
1817
- registerWorkflowSerializationClass(WorkflowStorageClient.classId, WorkflowStorageClient);
1818
1795
  function createWorkflowStorageClient(options = {}) {
1819
1796
  return new WorkflowStorageClient(options);
1820
1797
  }
@@ -8609,6 +8586,54 @@ async function getSummaryAndTagsInternal(assetId, options, collectedUsage) {
8609
8586
 
8610
8587
  // src/workflows/translate-audio.ts
8611
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
8612
8637
  var STATIC_RENDITION_POLL_INTERVAL_MS = 1e4;
8613
8638
  var STATIC_RENDITION_MAX_ATTEMPTS = 180;
8614
8639
  var MAX_DUBBING_SOURCE_BYTES = 1e9;
@@ -8775,7 +8800,7 @@ async function createElevenLabsDubbingJob({
8775
8800
  body: formData
8776
8801
  });
8777
8802
  if (!dubbingResponse.ok) {
8778
- throw new Error(`ElevenLabs API error: ${dubbingResponse.statusText}`);
8803
+ throw await elevenLabsResponseError("ElevenLabs API error", dubbingResponse);
8779
8804
  }
8780
8805
  const dubbingData = await dubbingResponse.json();
8781
8806
  return dubbingData.dubbing_id;
@@ -8792,12 +8817,13 @@ async function checkElevenLabsDubbingStatus({
8792
8817
  }
8793
8818
  });
8794
8819
  if (!statusResponse.ok) {
8795
- throw new Error(`Status check failed: ${statusResponse.statusText}`);
8820
+ throw await elevenLabsResponseError("Status check failed", statusResponse);
8796
8821
  }
8797
8822
  const statusData = await statusResponse.json();
8798
8823
  return {
8799
8824
  status: statusData.status,
8800
- targetLanguages: statusData.target_languages ?? []
8825
+ targetLanguages: statusData.target_languages ?? [],
8826
+ error: typeof statusData.error === "string" && statusData.error ? statusData.error : void 0
8801
8827
  };
8802
8828
  }
8803
8829
  async function downloadAndUploadDubbedAudio({
@@ -8821,7 +8847,7 @@ async function downloadAndUploadDubbedAudio({
8821
8847
  }
8822
8848
  });
8823
8849
  if (!audioResponse.ok) {
8824
- throw new Error(`Failed to fetch dubbed audio: ${audioResponse.statusText}`);
8850
+ throw await elevenLabsResponseError("Failed to fetch dubbed audio", audioResponse);
8825
8851
  }
8826
8852
  const dubbedAudio = new Uint8Array(await audioResponse.arrayBuffer());
8827
8853
  const s3AccessKeyId = env_default.S3_ACCESS_KEY_ID;
@@ -8872,7 +8898,7 @@ async function downloadAndUploadDubTranscript({
8872
8898
  }
8873
8899
  });
8874
8900
  if (!transcriptResponse.ok) {
8875
- throw new Error(`Failed to fetch dub transcript: ${transcriptResponse.statusText}`);
8901
+ throw await elevenLabsResponseError("Failed to fetch dub transcript", transcriptResponse);
8876
8902
  }
8877
8903
  const transcriptBody = await transcriptResponse.json();
8878
8904
  const transcriptVtt = transcriptBody.webvtt;
@@ -9025,6 +9051,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
9025
9051
  let dubbingStatus = "dubbing";
9026
9052
  let pollAttempts = 0;
9027
9053
  let targetLanguages = [];
9054
+ let dubbingError;
9028
9055
  while (dubbingStatus !== "dubbed" && pollAttempts < maxPollAttempts) {
9029
9056
  await sleep2(DUBBING_POLL_INTERVAL_MS);
9030
9057
  pollAttempts++;
@@ -9035,10 +9062,12 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
9035
9062
  });
9036
9063
  dubbingStatus = statusResult.status;
9037
9064
  targetLanguages = statusResult.targetLanguages;
9065
+ dubbingError = statusResult.error;
9038
9066
  } catch (error) {
9039
9067
  wrapError(error, "Failed to check dubbing status");
9040
9068
  }
9041
9069
  if (dubbingStatus === "failed") {
9070
+ console.warn(`\u274C ElevenLabs dubbing job ${dubbingId} failed: ${dubbingError ?? "no error reported"}`);
9042
9071
  throw new MuxAiError("ElevenLabs reported that the dubbing job failed.", { type: "processing_error" });
9043
9072
  }
9044
9073
  }