@mux/ai 0.14.0 → 0.15.1

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.
@@ -592,6 +592,26 @@ async function fetchHotspots(identifierType, id, options) {
592
592
  return transformHotspotResponse(response);
593
593
  }
594
594
 
595
+ // src/lib/mux-ai-error.ts
596
+ var MuxAiError = class extends Error {
597
+ constructor(message, opts) {
598
+ super(message);
599
+ /** Structural brand for duck-type identification. */
600
+ this.__robots_error = true;
601
+ this.name = "MuxAiError";
602
+ this.publicType = opts?.type ?? "processing_error";
603
+ this.publicMessage = message;
604
+ this.retryable = opts?.retryable ?? false;
605
+ }
606
+ };
607
+ function wrapError(error, message) {
608
+ if (error instanceof MuxAiError) {
609
+ throw error;
610
+ }
611
+ const detail = error instanceof Error ? error.message : "Unknown error";
612
+ throw new Error(`${message}: ${detail}`);
613
+ }
614
+
595
615
  // src/primitives/shots.ts
596
616
  var DEFAULT_POLL_INTERVAL_MS = 2e3;
597
617
  var MIN_POLL_INTERVAL_MS = 1e3;
@@ -717,14 +737,15 @@ async function waitForShotsForAsset(assetId, options = {}) {
717
737
  return result;
718
738
  }
719
739
  if (result.status === "errored") {
720
- throw new Error(`Shots generation errored for asset '${assetId}'`);
740
+ throw new MuxAiError(`Shot generation failed for asset ${assetId}.`);
721
741
  }
722
742
  if (attempt < normalizedMaxAttempts - 1) {
723
743
  await sleep(normalizedPollIntervalMs);
724
744
  }
725
745
  }
726
- throw new Error(
727
- `Timed out waiting for shots for asset '${assetId}' after ${normalizedMaxAttempts} attempts. Last status: ${lastStatus ?? "unknown"}`
746
+ throw new MuxAiError(
747
+ `Timed out waiting for shots for asset ${assetId}. Last status: ${lastStatus ?? "unknown"}.`,
748
+ { type: "timeout_error", retryable: true }
728
749
  );
729
750
  }
730
751
 
@@ -1406,15 +1427,16 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
1406
1427
  if (!track) {
1407
1428
  if (required) {
1408
1429
  const availableLanguages = getReadyTextTracks(asset).map((t) => t.language_code).filter(Boolean).join(", ");
1409
- throw new Error(
1410
- `No transcript track found${languageCode ? ` for language '${languageCode}'` : ""}. Available languages: ${availableLanguages || "none"}`
1430
+ throw new MuxAiError(
1431
+ `No caption track found${languageCode ? ` for language ${languageCode}` : ""}. Available languages: ${availableLanguages || "none"}.`,
1432
+ { type: "validation_error" }
1411
1433
  );
1412
1434
  }
1413
1435
  return { transcriptText: "" };
1414
1436
  }
1415
1437
  if (!track.id) {
1416
1438
  if (required) {
1417
- throw new Error("Transcript track is missing an id");
1439
+ throw new MuxAiError("Transcript track is missing an id.", { type: "validation_error" });
1418
1440
  }
1419
1441
  return { transcriptText: "", track };
1420
1442
  }
@@ -1430,14 +1452,12 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
1430
1452
  const rawVtt = await response.text();
1431
1453
  const transcriptText = cleanTranscript ? extractTextFromVTT(rawVtt) : rawVtt;
1432
1454
  if (required && !transcriptText.trim()) {
1433
- throw new Error("Transcript is empty");
1455
+ throw new MuxAiError("Transcript is empty.", { type: "validation_error" });
1434
1456
  }
1435
1457
  return { transcriptText, transcriptUrl, track };
1436
1458
  } catch (error) {
1437
1459
  if (required) {
1438
- throw new Error(
1439
- `Failed to fetch transcript: ${error instanceof Error ? error.message : "Unknown error"}`
1440
- );
1460
+ wrapError(error, "Failed to fetch transcript");
1441
1461
  }
1442
1462
  console.warn("Failed to fetch transcript:", error);
1443
1463
  return { transcriptText: "", transcriptUrl, track };