@mux/ai 0.65.0 → 0.66.0-canary.107

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.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // package.json
8
- var version = "0.65.0";
8
+ var version = "0.66.0-canary.107";
9
9
 
10
10
  // node_modules/@workflow/serde/dist/index.js
11
11
  var WORKFLOW_SERIALIZE = /* @__PURE__ */ Symbol.for("workflow-serialize");
@@ -641,7 +641,49 @@ var MUX_AI_ERROR_CODES = {
641
641
  /** The asset's static rendition settings changed while waiting for its rendition. A new job uses the new settings. Facts: `assetId`. */
642
642
  STATIC_RENDITION_CHANGED: "static_rendition_changed",
643
643
  /** Mux didn't finish the static rendition within the polling budget. Facts: `assetId`, `attempts`, `pollIntervalMs`, `lastStatus`. */
644
- STATIC_RENDITION_TIMEOUT: "static_rendition_timeout"
644
+ STATIC_RENDITION_TIMEOUT: "static_rendition_timeout",
645
+ /**
646
+ * The provider says the account the service running the SDK uses is out of credits or
647
+ * quota, or hit a spend or usage limit. Retrying won't help until someone changes the
648
+ * account. The site names the dependency. Facts: `call`, `status`, `providerCode`.
649
+ */
650
+ PROVIDER_QUOTA_EXHAUSTED: "provider_quota_exhausted",
651
+ /** The provider rejected the key the service running the SDK uses, or the key lacks permission for this model or feature. The site names the dependency. Facts: `call`, `status`, `providerCode`. */
652
+ PROVIDER_CREDENTIALS_REJECTED: "provider_credentials_rejected",
653
+ /** The provider says requests are over its rate or concurrency limit. The site names the dependency. Facts: `call`, `status`, `providerCode`. */
654
+ PROVIDER_RATE_LIMITED: "provider_rate_limited",
655
+ /** The provider says it's overloaded or down for maintenance. The site names the dependency. Facts: `call`, `status`, `providerCode`. */
656
+ PROVIDER_UNAVAILABLE: "provider_unavailable",
657
+ /** The provider can't process the asset's audio. The site names the dependency. Facts: `call`, `status`, `providerCode`, `reason` (`corrupt`, `unsupported_format`, `too_long`, `too_short`). */
658
+ AUDIO_UNPROCESSABLE: "audio_unprocessable",
659
+ /** Mux rejected the caller's access token (401), or the token lacks permission for this call (403), e.g. Mux Data access. Facts: `call`, `status`, `inputs` (`credentials`). */
660
+ ACCOUNT_CREDENTIALS_REJECTED: "account_credentials_rejected",
661
+ /** Mux answered 404 for something belonging to the asset (a track, a rendition, an image, its engagement data): gone, or not ready yet. A missing asset itself is `asset_not_found`. Facts: `call`, `status`. */
662
+ ASSET_RESOURCE_NOT_FOUND: "asset_resource_not_found",
663
+ /** Mux denied delivery of the asset's media (a transcript, a caption file, an image), e.g. a signing key or playback restriction in the Mux account rejected the request. Facts: `call`, `status`. */
664
+ PLAYBACK_ACCESS_DENIED: "playback_access_denied",
665
+ // Fallback codes (see MUX_AI_DEPENDENCY_STATUS_CODES): what a remote call's failure looked
666
+ // like, when no per-dependency rule recognized it. The site names the dependency.
667
+ /** No response arrived, and the call didn't time out (e.g. a connection failure). Facts: `call`. */
668
+ DEPENDENCY_NO_RESPONSE: "dependency_no_response",
669
+ /** The call timed out, or the dependency answered 408. Facts: `call`, `status`. */
670
+ DEPENDENCY_TIMEOUT: "dependency_timeout",
671
+ /** The dependency answered 429. Facts: `call`, `status`. */
672
+ DEPENDENCY_RATE_LIMITED: "dependency_rate_limited",
673
+ /** The dependency answered 425. Facts: `call`, `status`. */
674
+ DEPENDENCY_TOO_EARLY: "dependency_too_early",
675
+ /** The dependency answered with a 5xx status. Facts: `call`, `status`. */
676
+ DEPENDENCY_SERVER_ERROR: "dependency_server_error",
677
+ /** The dependency answered 401 or 403 to a request made with the service's own credentials. Facts: `call`, `status`. */
678
+ DEPENDENCY_AUTH_REJECTED: "dependency_auth_rejected",
679
+ /** The dependency answered 404 to a request the SDK built. Facts: `call`, `status`. */
680
+ DEPENDENCY_NOT_FOUND: "dependency_not_found",
681
+ /** The dependency answered with another 4xx status. Facts: `call`, `status`. */
682
+ DEPENDENCY_REQUEST_REJECTED: "dependency_request_rejected",
683
+ /** The dependency answered with a status that isn't an error (1xx-3xx) where a result was expected. Facts: `call`, `status`. */
684
+ DEPENDENCY_OTHER_STATUS: "dependency_other_status",
685
+ /** The dependency answered without a failing status, but with an error of its own or a response that can't be used. Facts: `call`, `providerCode` when it gave one. */
686
+ DEPENDENCY_RESPONSE_FAILED: "dependency_response_failed"
645
687
  };
646
688
  var MUX_AI_ERROR_CODE_VALUES = Object.values(MUX_AI_ERROR_CODES);
647
689
  var MUX_AI_ERROR_CATALOG = {
@@ -699,7 +741,39 @@ var MUX_AI_ERROR_CATALOG = {
699
741
  [MUX_AI_ERROR_CODES.AUDIO_TRACK_MISSING]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
700
742
  [MUX_AI_ERROR_CODES.PRIMARY_AUDIO_TRACK_CONFLICT]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
701
743
  // Retryable although asset-sourced: the asset changed mid-run, and a new job uses the new settings.
702
- [MUX_AI_ERROR_CODES.STATIC_RENDITION_CHANGED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, retryable: true }
744
+ [MUX_AI_ERROR_CODES.STATIC_RENDITION_CHANGED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, retryable: true },
745
+ // Conditions a remote service reports in its own terms (see the per-dependency modules,
746
+ // e.g. elevenlabs-errors.ts), so the code holds whichever dependency the site names.
747
+ // A provider's key and quota are the configuration of the service running the SDK, like
748
+ // its signing keys and storage: `internal`. (`account` is the caller's Mux account.)
749
+ // Neither step-retried nor resubmittable: the provider says retrying won't restore access.
750
+ [MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true, transient: false, retryable: false },
751
+ [MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
752
+ [MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED]: { type: MUX_AI_ERROR_TYPES.CAPACITY_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, siteDependency: true, transient: true, retryable: true },
753
+ [MUX_AI_ERROR_CODES.PROVIDER_UNAVAILABLE]: { type: MUX_AI_ERROR_TYPES.CAPACITY_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, siteDependency: true, transient: true, retryable: true },
754
+ [MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, siteDependency: true },
755
+ // Mux's own responses, where the call says whose they are (see mux-video-errors.ts).
756
+ // The access token is the caller's: only its permissions decide what Mux allows.
757
+ [MUX_AI_ERROR_CODES.ACCOUNT_CREDENTIALS_REJECTED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ACCOUNT, siteDependency: true },
758
+ [MUX_AI_ERROR_CODES.ASSET_RESOURCE_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, siteDependency: true },
759
+ // Media requests carry no access token. Mux denies them for an expired signed token or a
760
+ // playback restriction; the SDK signs fresh tokens, so it's the account's keys or restrictions.
761
+ [MUX_AI_ERROR_CODES.PLAYBACK_ACCESS_DENIED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ACCOUNT, siteDependency: true },
762
+ // Fallback codes: each implies the classification the status rules give it
763
+ // (`classifyDependencyFailure` with its default sources). A site that knows more raises
764
+ // a more specific code instead. Transient ones are step-retried unless the call isn't
765
+ // idempotent (see `dependencyError`).
766
+ [MUX_AI_ERROR_CODES.DEPENDENCY_NO_RESPONSE]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, siteDependency: true, transient: true, retryable: true },
767
+ [MUX_AI_ERROR_CODES.DEPENDENCY_TIMEOUT]: { type: MUX_AI_ERROR_TYPES.TIMEOUT_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, siteDependency: true, transient: true, retryable: true },
768
+ [MUX_AI_ERROR_CODES.DEPENDENCY_RATE_LIMITED]: { type: MUX_AI_ERROR_TYPES.CAPACITY_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, siteDependency: true, transient: true, retryable: true },
769
+ [MUX_AI_ERROR_CODES.DEPENDENCY_TOO_EARLY]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, siteDependency: true, transient: true, retryable: true },
770
+ [MUX_AI_ERROR_CODES.DEPENDENCY_SERVER_ERROR]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, siteDependency: true, transient: true, retryable: true },
771
+ [MUX_AI_ERROR_CODES.DEPENDENCY_AUTH_REJECTED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
772
+ [MUX_AI_ERROR_CODES.DEPENDENCY_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
773
+ [MUX_AI_ERROR_CODES.DEPENDENCY_REQUEST_REJECTED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
774
+ [MUX_AI_ERROR_CODES.DEPENDENCY_OTHER_STATUS]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
775
+ // Not step-retried: the dependency answered, and would answer the same way. Resubmittable.
776
+ [MUX_AI_ERROR_CODES.DEPENDENCY_RESPONSE_FAILED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, siteDependency: true, transient: false, retryable: true }
703
777
  };
704
778
  function isTransientStatus(status) {
705
779
  return status === void 0 || status === 408 || status === 425 || status === 429 || status >= 500;
@@ -716,6 +790,19 @@ function defaultRetryable(type, source, transient) {
716
790
  }
717
791
  return source === MUX_AI_ERROR_SOURCES.UPSTREAM;
718
792
  }
793
+ var MUX_AI_DEPENDENCY_STATUS_CODES = {
794
+ NO_RESPONSE: MUX_AI_ERROR_CODES.DEPENDENCY_NO_RESPONSE,
795
+ TIMEOUT: MUX_AI_ERROR_CODES.DEPENDENCY_TIMEOUT,
796
+ RATE_LIMITED: MUX_AI_ERROR_CODES.DEPENDENCY_RATE_LIMITED,
797
+ TOO_EARLY: MUX_AI_ERROR_CODES.DEPENDENCY_TOO_EARLY,
798
+ SERVER_ERROR: MUX_AI_ERROR_CODES.DEPENDENCY_SERVER_ERROR,
799
+ AUTH_REJECTED: MUX_AI_ERROR_CODES.DEPENDENCY_AUTH_REJECTED,
800
+ NOT_FOUND: MUX_AI_ERROR_CODES.DEPENDENCY_NOT_FOUND,
801
+ REQUEST_REJECTED: MUX_AI_ERROR_CODES.DEPENDENCY_REQUEST_REJECTED,
802
+ OTHER_STATUS: MUX_AI_ERROR_CODES.DEPENDENCY_OTHER_STATUS,
803
+ RESPONSE_FAILED: MUX_AI_ERROR_CODES.DEPENDENCY_RESPONSE_FAILED
804
+ };
805
+ var MUX_AI_DEPENDENCY_STATUS_CODE_VALUES = Object.values(MUX_AI_DEPENDENCY_STATUS_CODES);
719
806
  var MAX_CAUSE_DEPTH = 3;
720
807
  var MAX_CAUSE_MESSAGE_LENGTH = 500;
721
808
  function statusOf(value) {
@@ -945,10 +1032,63 @@ function classifyDependencyFailure(init) {
945
1032
  ...init.retryable !== void 0 && { retryable: init.retryable }
946
1033
  };
947
1034
  }
1035
+ function dependencyFailureCode({ status, timedOut }) {
1036
+ if (timedOut || status === 408) {
1037
+ return MUX_AI_DEPENDENCY_STATUS_CODES.TIMEOUT;
1038
+ }
1039
+ if (status === void 0) {
1040
+ return MUX_AI_DEPENDENCY_STATUS_CODES.NO_RESPONSE;
1041
+ }
1042
+ if (status === 429) {
1043
+ return MUX_AI_DEPENDENCY_STATUS_CODES.RATE_LIMITED;
1044
+ }
1045
+ if (status === 425) {
1046
+ return MUX_AI_DEPENDENCY_STATUS_CODES.TOO_EARLY;
1047
+ }
1048
+ if (status >= 500 && status < 600) {
1049
+ return MUX_AI_DEPENDENCY_STATUS_CODES.SERVER_ERROR;
1050
+ }
1051
+ if (status === 401 || status === 403) {
1052
+ return MUX_AI_DEPENDENCY_STATUS_CODES.AUTH_REJECTED;
1053
+ }
1054
+ if (status === 404) {
1055
+ return MUX_AI_DEPENDENCY_STATUS_CODES.NOT_FOUND;
1056
+ }
1057
+ return status >= 400 && status < 500 ? MUX_AI_DEPENDENCY_STATUS_CODES.REQUEST_REJECTED : MUX_AI_DEPENDENCY_STATUS_CODES.OTHER_STATUS;
1058
+ }
1059
+ function attributedFailureCode({ status, timedOut, notFoundSource, authSource }) {
1060
+ if (timedOut) {
1061
+ return void 0;
1062
+ }
1063
+ if (status === 404 && notFoundSource === MUX_AI_ERROR_SOURCES.ASSET) {
1064
+ return MUX_AI_ERROR_CODES.ASSET_RESOURCE_NOT_FOUND;
1065
+ }
1066
+ if ((status === 401 || status === 403) && authSource === MUX_AI_ERROR_SOURCES.ACCOUNT) {
1067
+ return MUX_AI_ERROR_CODES.ACCOUNT_CREDENTIALS_REJECTED;
1068
+ }
1069
+ return void 0;
1070
+ }
948
1071
  function dependencyError(message, init) {
949
- const { source, ...classification } = classifyDependencyFailure(init);
950
- const where = { source, dependency: init.dependency };
951
- return new MuxAiError(message, { ...classification, ...where, cause: init.cause });
1072
+ const { facts, transient } = classifyDependencyFailure(
1073
+ init.authSource === MUX_AI_ERROR_SOURCES.ACCOUNT && !init.authInputs?.length ? { ...init, authInputs: ["credentials"] } : init
1074
+ );
1075
+ const code = init.code ?? attributedFailureCode(init) ?? dependencyFailureCode(init);
1076
+ const entry = MUX_AI_ERROR_CATALOG[code];
1077
+ const mayHaveTakenEffect = init.timedOut === true || (init.status === void 0 ? code === MUX_AI_ERROR_CODES.DEPENDENCY_NO_RESPONSE : init.status >= 500);
1078
+ const retryable = init.retryable ?? entry.retryable;
1079
+ return new MuxAiError(message, {
1080
+ code,
1081
+ type: entry.type,
1082
+ source: entry.source,
1083
+ dependency: init.dependency,
1084
+ facts,
1085
+ // The site's override wins, then a non-idempotent call that may have taken effect,
1086
+ // then the code's policy, then the status rules. A code other than no response or a
1087
+ // timeout means the dependency answered, so a missing status isn't "no response" here.
1088
+ transient: init.transient ?? (init.idempotent === false && mayHaveTakenEffect ? false : void 0) ?? entry.transient ?? (init.status === void 0 && !init.timedOut ? false : transient),
1089
+ ...retryable !== void 0 && { retryable },
1090
+ cause: init.cause
1091
+ });
952
1092
  }
953
1093
  function httpStatusOf(error) {
954
1094
  if (typeof error !== "object" || error === null) {
@@ -983,6 +1123,139 @@ function dependencyErrorFrom(error, message, init) {
983
1123
  });
984
1124
  }
985
1125
 
1126
+ // src/lib/elevenlabs-errors.ts
1127
+ var MAX_ERROR_BODY_CHARS = 500;
1128
+ function isRetryableElevenLabsStatus(status) {
1129
+ return isTransientStatus(status);
1130
+ }
1131
+ var ELEVENLABS_ERROR_CODES = {
1132
+ insufficient_credits: { code: MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED },
1133
+ quota_exceeded: { code: MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED },
1134
+ payment_required: { code: MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED },
1135
+ invalid_api_key: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
1136
+ missing_api_key: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
1137
+ invalid_authorization_header: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
1138
+ insufficient_permissions: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
1139
+ feature_not_available: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
1140
+ subscription_required: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
1141
+ model_access_denied: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
1142
+ workspace_access_denied: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
1143
+ rate_limit_exceeded: { code: MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED },
1144
+ concurrent_limit_exceeded: { code: MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED },
1145
+ too_many_concurrent_requests: { code: MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED },
1146
+ system_busy: { code: MUX_AI_ERROR_CODES.PROVIDER_UNAVAILABLE },
1147
+ service_unavailable: { code: MUX_AI_ERROR_CODES.PROVIDER_UNAVAILABLE },
1148
+ maintenance: { code: MUX_AI_ERROR_CODES.PROVIDER_UNAVAILABLE },
1149
+ invalid_audio: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "corrupt" },
1150
+ invalid_audio_format: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "unsupported_format" },
1151
+ invalid_file_type: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "unsupported_format" },
1152
+ audio_too_long: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "too_long" },
1153
+ audio_too_short: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "too_short" }
1154
+ };
1155
+ function elevenLabsErrorRule(failure) {
1156
+ const values = failure.providerCodes ?? (failure.reason ? [failure.reason] : []);
1157
+ return values.map((value) => ELEVENLABS_ERROR_CODES[value]).find((rule) => rule !== void 0);
1158
+ }
1159
+ function elevenLabsFailureError(message, call, failure, facts) {
1160
+ const rule = elevenLabsErrorRule(failure);
1161
+ return dependencyError(message, {
1162
+ dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
1163
+ call,
1164
+ status: failure.httpStatus,
1165
+ requestId: failure.requestId,
1166
+ timedOut: failure.reason === "timeout",
1167
+ facts: {
1168
+ provider: "elevenlabs",
1169
+ ...failure.reason && { providerCode: failure.reason },
1170
+ ...failure.detail && { detail: errorDetailFact(failure.detail) },
1171
+ ...rule?.reason && { reason: rule.reason },
1172
+ ...facts
1173
+ },
1174
+ // Without a rule or a status, only a network error went unanswered (a timeout is
1175
+ // `timedOut`); anything else got a response with an error or nothing usable.
1176
+ ...rule ? { code: rule.code } : failure.httpStatus === void 0 && failure.reason !== "network_error" && failure.reason !== "timeout" && { code: MUX_AI_ERROR_CODES.DEPENDENCY_RESPONSE_FAILED },
1177
+ transient: false,
1178
+ // Quota stays spent whatever the status, so a new job can't succeed either.
1179
+ retryable: rule?.code === MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED ? false : failure.retryable
1180
+ });
1181
+ }
1182
+ async function elevenLabsResponseFailure(response) {
1183
+ const body = await response.text().catch(() => "");
1184
+ return httpFailure(response.status, response.statusText, body, response.headers);
1185
+ }
1186
+ function elevenLabsSdkFailure(error) {
1187
+ const failure = error;
1188
+ if (typeof failure?.statusCode === "number") {
1189
+ const body = typeof failure.body === "string" ? failure.body : JSON.stringify(failure.body ?? "");
1190
+ return httpFailure(failure.statusCode, failure.rawResponse?.statusText, body, failure.rawResponse?.headers);
1191
+ }
1192
+ const message = failure?.message ?? String(error);
1193
+ switch (failure?.name) {
1194
+ case "ElevenLabsTimeoutError":
1195
+ return { reason: "timeout", retryable: true, detail: message };
1196
+ // The SDK validates responses strictly: the API's response no longer matches
1197
+ // this SDK version, so the same call fails the same way.
1198
+ case "ParseError":
1199
+ return { reason: "unexpected_response", retryable: false, detail: `Unexpected ElevenLabs response: ${message}` };
1200
+ // The SDK's own error without a status: the request got no response.
1201
+ case "ElevenLabsError":
1202
+ return { reason: "network_error", retryable: true, detail: message };
1203
+ default:
1204
+ return { retryable: false, detail: message };
1205
+ }
1206
+ }
1207
+ function httpFailure(status, statusText, body, headers) {
1208
+ const statusLine = [status, statusText].filter(Boolean).join(" ");
1209
+ const { reason, providerCodes, detail, requestId } = parseElevenLabsErrorBody(body);
1210
+ const responseRequestId = requestId ?? requestIdOf(headers);
1211
+ const quota = elevenLabsErrorRule({ reason, providerCodes })?.code === MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED;
1212
+ return {
1213
+ httpStatus: status,
1214
+ reason,
1215
+ ...providerCodes && { providerCodes },
1216
+ ...responseRequestId && { requestId: responseRequestId },
1217
+ // A spent quota isn't restored by retrying, even when it arrives as a 429.
1218
+ retryable: !quota && isRetryableElevenLabsStatus(status),
1219
+ detail: detail ? `${statusLine}: ${detail}` : statusLine
1220
+ };
1221
+ }
1222
+ function parseElevenLabsErrorBody(body) {
1223
+ const trimmed = body.trim();
1224
+ if (!trimmed) {
1225
+ return { detail: "" };
1226
+ }
1227
+ let detail;
1228
+ try {
1229
+ detail = JSON.parse(trimmed).detail;
1230
+ } catch {
1231
+ return { detail: trimmed.slice(0, MAX_ERROR_BODY_CHARS) };
1232
+ }
1233
+ if (typeof detail === "string" && detail) {
1234
+ return { detail };
1235
+ }
1236
+ if (Array.isArray(detail) && detail.length > 0) {
1237
+ return {
1238
+ detail: detail.map((item) => [item.loc?.join("."), item.msg].filter(Boolean).join(": ")).join("; ")
1239
+ };
1240
+ }
1241
+ if (detail && typeof detail === "object") {
1242
+ const { status, code, message, param, request_id: requestId } = detail;
1243
+ const providerCodes = [code, status].filter((value) => typeof value === "string" && value !== "");
1244
+ const reasonCode = [status, code].find((value) => typeof value === "string" && value !== "");
1245
+ const reasonText = [reasonCode, message].filter(Boolean).join(": ");
1246
+ const context = [param && `param: ${param}`, requestId && `request_id: ${requestId}`].filter(Boolean).join(", ");
1247
+ if (reasonText) {
1248
+ return {
1249
+ reason: reasonCode,
1250
+ ...providerCodes.length > 0 && { providerCodes },
1251
+ detail: context ? `${reasonText} (${context})` : reasonText,
1252
+ ...typeof requestId === "string" && requestId && { requestId }
1253
+ };
1254
+ }
1255
+ }
1256
+ return { detail: trimmed.slice(0, MAX_ERROR_BODY_CHARS) };
1257
+ }
1258
+
986
1259
  // src/lib/language-codes.ts
987
1260
  var ISO639_1_TO_3 = {
988
1261
  // Major world languages
@@ -1322,6 +1595,14 @@ function muxVideoErrorFacts(error) {
1322
1595
  return parsed.success ? { muxErrorType: parsed.data.error.error.type } : {};
1323
1596
  }
1324
1597
  function muxVideoError(message, init) {
1598
+ return dependencyError(message, {
1599
+ ...init,
1600
+ dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
1601
+ notFoundSource: MUX_AI_ERROR_SOURCES.ASSET,
1602
+ ...!init.timedOut && (init.status === 401 || init.status === 403) && { code: MUX_AI_ERROR_CODES.PLAYBACK_ACCESS_DENIED }
1603
+ });
1604
+ }
1605
+ function muxVideoApiError(message, init) {
1325
1606
  return dependencyError(message, {
1326
1607
  ...init,
1327
1608
  dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
@@ -1339,7 +1620,10 @@ function muxVideoCallError(message, call, error, facts) {
1339
1620
  }
1340
1621
  return error;
1341
1622
  }
1342
- return muxVideoError(message, {
1623
+ if (call === "get_asset" && httpStatusOf(error) === 404) {
1624
+ return assetNotFoundError(error, facts);
1625
+ }
1626
+ return muxVideoApiError(message, {
1343
1627
  call,
1344
1628
  status: httpStatusOf(error),
1345
1629
  requestId: requestIdOf(error?.headers),
@@ -1348,18 +1632,19 @@ function muxVideoCallError(message, call, error, facts) {
1348
1632
  });
1349
1633
  }
1350
1634
  function muxAssetFetchError(assetId, error) {
1351
- if (!MuxAiError.is(error) && httpStatusOf(error) === 404) {
1352
- return new MuxAiError(`Mux asset ${assetId} not found`, {
1353
- code: MUX_AI_ERROR_CODES.ASSET_NOT_FOUND,
1354
- type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
1355
- source: MUX_AI_ERROR_SOURCES.REQUEST,
1356
- dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
1357
- facts: { call: "get_asset", status: 404, assetId, inputs: ["assetId"], ...muxVideoErrorFacts(error) },
1358
- cause: error
1359
- });
1360
- }
1361
1635
  return muxVideoCallError("Failed to fetch the asset from Mux", "get_asset", error, { assetId });
1362
1636
  }
1637
+ function assetNotFoundError(error, facts) {
1638
+ const requestId = requestIdOf(error?.headers);
1639
+ return new MuxAiError(typeof facts?.assetId === "string" ? `Mux asset ${facts.assetId} not found` : "Mux asset not found", {
1640
+ code: MUX_AI_ERROR_CODES.ASSET_NOT_FOUND,
1641
+ type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
1642
+ source: MUX_AI_ERROR_SOURCES.REQUEST,
1643
+ dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
1644
+ facts: { call: "get_asset", status: 404, ...requestId && { requestId }, ...facts, inputs: ["assetId"], ...muxVideoErrorFacts(error) },
1645
+ cause: error
1646
+ });
1647
+ }
1363
1648
  function missingTrackIdError(message, facts) {
1364
1649
  return new MuxAiError(message, {
1365
1650
  code: MUX_AI_ERROR_CODES.TRACK_ID_MISSING,
@@ -2226,6 +2511,10 @@ var MUX_AI_ERROR_GENERIC_MESSAGES = {
2226
2511
  function text(value) {
2227
2512
  return value === void 0 || value === null ? "" : String(value);
2228
2513
  }
2514
+ function wording(table, value) {
2515
+ const key = text(value);
2516
+ return Object.prototype.hasOwnProperty.call(table, key) ? table[key] : void 0;
2517
+ }
2229
2518
  function list(value) {
2230
2519
  return Array.isArray(value) && value.length > 0 ? value.map(text).join(", ") : "none";
2231
2520
  }
@@ -2319,6 +2608,12 @@ function invalidParameterMessage(facts) {
2319
2608
  return `${parameter} has a value that can't be used.`;
2320
2609
  }
2321
2610
  }
2611
+ var AUDIO_UNPROCESSABLE_REASONS = {
2612
+ corrupt: "it may be corrupt",
2613
+ unsupported_format: "its format isn't supported",
2614
+ too_long: "it's too long",
2615
+ too_short: "it's too short"
2616
+ };
2322
2617
  var AUDIO_TRACK_UNSUPPORTED_MESSAGES = {
2323
2618
  clip: "Mux doesn't support adding audio tracks to clipped assets. Dub the source asset instead, or use the dubbed audio file without adding it to Mux.",
2324
2619
  live_stream: "Mux doesn't support adding audio tracks to live stream assets. Use the dubbed audio file without adding it to Mux instead.",
@@ -2375,7 +2670,7 @@ var MUX_AI_ERROR_PUBLIC_MAPPINGS = {
2375
2670
  },
2376
2671
  [MUX_AI_ERROR_CODES.AUDIO_TRACK_UNSUPPORTED]: {
2377
2672
  facts: ["reason"],
2378
- message: (facts) => AUDIO_TRACK_UNSUPPORTED_MESSAGES[text(facts.reason)] ?? "Mux doesn't support adding audio tracks to this asset."
2673
+ message: (facts) => wording(AUDIO_TRACK_UNSUPPORTED_MESSAGES, facts.reason) ?? "Mux doesn't support adding audio tracks to this asset."
2379
2674
  },
2380
2675
  [MUX_AI_ERROR_CODES.STATIC_RENDITION_UNSUPPORTED]: {
2381
2676
  facts: ["reason", "mp4Support", "renditionStatus", "renditionName", "sizeBytes", "maxBytes"],
@@ -2416,6 +2711,13 @@ var MUX_AI_ERROR_PUBLIC_MAPPINGS = {
2416
2711
  // The dubbing provider documents this text as safe to display.
2417
2712
  facts: ["providerError"],
2418
2713
  message: (facts, { retryable }) => `Audio dubbing failed${facts.providerError ? `: ${text(facts.providerError)}` : "."}${retryable ? TRY_AGAIN : ""}`
2714
+ },
2715
+ [MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE]: {
2716
+ facts: ["reason"],
2717
+ message: (facts) => {
2718
+ const why = wording(AUDIO_UNPROCESSABLE_REASONS, facts.reason);
2719
+ return `The asset's audio couldn't be processed${why ? `: ${why}` : ""}.`;
2720
+ }
2419
2721
  }
2420
2722
  };
2421
2723
  function genericPublicMessage(error) {
@@ -2470,6 +2772,39 @@ var toPublicError = createPublicErrorView({
2470
2772
  genericMessage: genericPublicMessage
2471
2773
  });
2472
2774
 
2775
+ // src/lib/storage-errors.ts
2776
+ var S3_TOKEN = /^[\w.-]{1,64}$/;
2777
+ var S3_ERROR_CODES = {
2778
+ // 503: S3 is scaling to a new request rate; AWS retries it as throttling.
2779
+ SlowDown: MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED
2780
+ };
2781
+ function s3ErrorDetails(body) {
2782
+ const field = (name) => {
2783
+ const value = new RegExp(`<${name}>([^<]*)</${name}>`).exec(body)?.[1]?.trim();
2784
+ return value && S3_TOKEN.test(value) ? value : void 0;
2785
+ };
2786
+ const s3Code = field("Code");
2787
+ const requestId = field("RequestId");
2788
+ return { ...s3Code && { s3Code }, ...requestId && { requestId } };
2789
+ }
2790
+ function s3ResponseError(message, call, response, body, facts, cause) {
2791
+ const { s3Code, requestId } = s3ErrorDetails(body);
2792
+ const code = s3Code ? S3_ERROR_CODES[s3Code] : void 0;
2793
+ return dependencyError(message, {
2794
+ dependency: MUX_AI_ERROR_DEPENDENCIES.STORAGE,
2795
+ call,
2796
+ status: response.status,
2797
+ requestId: requestIdOf(response.headers) ?? requestId,
2798
+ timedOut: s3Code === "RequestTimeout",
2799
+ facts: { ...s3Code && { s3Code }, ...facts },
2800
+ ...code && { code },
2801
+ cause
2802
+ });
2803
+ }
2804
+ function s3NoResponseError(message, call, cause, facts) {
2805
+ return dependencyError(message, { dependency: MUX_AI_ERROR_DEPENDENCIES.STORAGE, call, facts, cause });
2806
+ }
2807
+
2473
2808
  // src/lib/s3-sigv4.ts
2474
2809
  var AWS4_ALGORITHM = "AWS4-HMAC-SHA256";
2475
2810
  var AWS4_REQUEST_TERMINATOR = "aws4_request";
@@ -2588,7 +2923,8 @@ async function putObjectToS3({
2588
2923
  bucket,
2589
2924
  key,
2590
2925
  body,
2591
- contentType
2926
+ contentType,
2927
+ classifiedErrors
2592
2928
  }) {
2593
2929
  const resolvedEndpoint = normalizeEndpoint(endpoint);
2594
2930
  const canonicalUri = buildCanonicalUri(resolvedEndpoint, bucket, key);
@@ -2623,20 +2959,32 @@ async function putObjectToS3({
2623
2959
  const signature = await signString(secretAccessKey, shortDate, region, stringToSign);
2624
2960
  const authorization = `${AWS4_ALGORITHM} Credential=${accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
2625
2961
  const requestUrl = `${resolvedEndpoint.origin}${canonicalUri}`;
2626
- const response = await fetch(requestUrl, {
2627
- method: "PUT",
2628
- headers: {
2629
- "Authorization": authorization,
2630
- "x-amz-content-sha256": payloadHash,
2631
- "x-amz-date": amzDate,
2632
- ...normalizedContentType ? { "content-type": normalizedContentType } : {}
2633
- },
2634
- body
2635
- });
2962
+ let response;
2963
+ try {
2964
+ response = await fetch(requestUrl, {
2965
+ method: "PUT",
2966
+ headers: {
2967
+ "Authorization": authorization,
2968
+ "x-amz-content-sha256": payloadHash,
2969
+ "x-amz-date": amzDate,
2970
+ ...normalizedContentType ? { "content-type": normalizedContentType } : {}
2971
+ },
2972
+ body
2973
+ });
2974
+ } catch (error) {
2975
+ if (!classifiedErrors) {
2976
+ throw error;
2977
+ }
2978
+ throw s3NoResponseError("S3 PUT got no response", "put_object", error);
2979
+ }
2636
2980
  if (!response.ok) {
2637
2981
  const errorBody = await response.text().catch(() => "");
2638
2982
  const detail = errorBody ? ` ${errorBody}` : "";
2639
- throw new Error(`S3 PUT failed (${response.status} ${response.statusText}).${detail}`);
2983
+ const message = `S3 PUT failed (${response.status} ${response.statusText}).${detail}`;
2984
+ if (!classifiedErrors) {
2985
+ throw new Error(message);
2986
+ }
2987
+ throw s3ResponseError(`S3 PUT failed (${response.status} ${response.statusText}).`, "put_object", response, errorBody, void 0, new Error(message));
2640
2988
  }
2641
2989
  }
2642
2990
  async function createPresignedGetUrl({
@@ -2682,16 +3030,77 @@ async function createPresignedGetUrl({
2682
3030
  return `${resolvedEndpoint.origin}${canonicalUri}?${queryWithSignature}`;
2683
3031
  }
2684
3032
 
3033
+ // src/lib/storage-adapter.ts
3034
+ function storageNotConfiguredError(missing) {
3035
+ return new MuxAiError(
3036
+ "Storage configuration is required for uploading. Provide s3Endpoint and s3Bucket in options or set S3_ENDPOINT and S3_BUCKET. If no storageAdapter is supplied, also set S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY.",
3037
+ {
3038
+ code: MUX_AI_ERROR_CODES.STORAGE_NOT_CONFIGURED,
3039
+ type: MUX_AI_ERROR_TYPES.SERVER_ERROR,
3040
+ source: MUX_AI_ERROR_SOURCES.INTERNAL,
3041
+ facts: { missing }
3042
+ }
3043
+ );
3044
+ }
3045
+ function requireCredentials(accessKeyId, secretAccessKey, { classifiedErrors } = {}) {
3046
+ if (!accessKeyId || !secretAccessKey) {
3047
+ if (classifiedErrors) {
3048
+ throw storageNotConfiguredError(["S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"]);
3049
+ }
3050
+ throw new Error(
3051
+ "S3 credentials are required for default storage operations. Provide S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY or pass options.storageAdapter."
3052
+ );
3053
+ }
3054
+ return { accessKeyId, secretAccessKey };
3055
+ }
3056
+ async function putObjectWithStorageAdapter(input, adapter, options = {}) {
3057
+ if (adapter) {
3058
+ await adapter.putObject(input);
3059
+ return;
3060
+ }
3061
+ const credentials = requireCredentials(input.accessKeyId, input.secretAccessKey, options);
3062
+ await putObjectToS3({
3063
+ accessKeyId: credentials.accessKeyId,
3064
+ secretAccessKey: credentials.secretAccessKey,
3065
+ endpoint: input.endpoint,
3066
+ region: input.region,
3067
+ bucket: input.bucket,
3068
+ key: input.key,
3069
+ body: input.body,
3070
+ contentType: input.contentType,
3071
+ classifiedErrors: options.classifiedErrors
3072
+ });
3073
+ }
3074
+ async function createPresignedGetUrlWithStorageAdapter(input, adapter) {
3075
+ if (adapter) {
3076
+ return adapter.createPresignedGetUrl(input);
3077
+ }
3078
+ const credentials = requireCredentials(input.accessKeyId, input.secretAccessKey);
3079
+ return createPresignedGetUrl({
3080
+ accessKeyId: credentials.accessKeyId,
3081
+ secretAccessKey: credentials.secretAccessKey,
3082
+ endpoint: input.endpoint,
3083
+ region: input.region,
3084
+ bucket: input.bucket,
3085
+ key: input.key,
3086
+ expiresInSeconds: input.expiresInSeconds
3087
+ });
3088
+ }
3089
+
2685
3090
  // src/lib/workflow-storage-client.ts
2686
3091
  var WorkflowStorageClient = class {
2687
3092
  constructor(options = {}) {
2688
3093
  this.accessKeyId = options.accessKeyId;
2689
3094
  this.secretAccessKey = options.secretAccessKey;
3095
+ this.classifiedErrors = options.classifiedErrors;
2690
3096
  }
2691
3097
  resolveCredentials(input) {
2692
3098
  const accessKeyId = input.accessKeyId ?? this.accessKeyId;
2693
3099
  const secretAccessKey = input.secretAccessKey ?? this.secretAccessKey;
2694
3100
  if (!accessKeyId || !secretAccessKey) {
3101
+ if (this.classifiedErrors) {
3102
+ throw storageNotConfiguredError(["S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"]);
3103
+ }
2695
3104
  throw new Error(
2696
3105
  "Storage credentials are required. Provide accessKeyId/secretAccessKey in WorkflowStorageClient options or in the storage operation input."
2697
3106
  );
@@ -2708,7 +3117,8 @@ var WorkflowStorageClient = class {
2708
3117
  bucket: input.bucket,
2709
3118
  key: input.key,
2710
3119
  body: input.body,
2711
- contentType: input.contentType
3120
+ contentType: input.contentType,
3121
+ classifiedErrors: this.classifiedErrors
2712
3122
  });
2713
3123
  }
2714
3124
  async createPresignedGetUrl(input) {
@@ -2726,7 +3136,8 @@ var WorkflowStorageClient = class {
2726
3136
  static [WORKFLOW_SERIALIZE](instance) {
2727
3137
  return {
2728
3138
  accessKeyId: instance.accessKeyId,
2729
- secretAccessKey: instance.secretAccessKey
3139
+ secretAccessKey: instance.secretAccessKey,
3140
+ ...instance.classifiedErrors && { classifiedErrors: true }
2730
3141
  };
2731
3142
  }
2732
3143
  static [WORKFLOW_DESERIALIZE](value) {
@@ -6917,61 +7328,6 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
6917
7328
  // src/workflows/edit-captions.ts
6918
7329
  import { generateText as generateText5, Output as Output5 } from "ai";
6919
7330
  import { z as z8 } from "zod";
6920
-
6921
- // src/lib/storage-adapter.ts
6922
- function storageNotConfiguredError(missing) {
6923
- return new MuxAiError(
6924
- "Storage configuration is required for uploading. Provide s3Endpoint and s3Bucket in options or set S3_ENDPOINT and S3_BUCKET. If no storageAdapter is supplied, also set S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY.",
6925
- {
6926
- code: MUX_AI_ERROR_CODES.STORAGE_NOT_CONFIGURED,
6927
- type: MUX_AI_ERROR_TYPES.SERVER_ERROR,
6928
- source: MUX_AI_ERROR_SOURCES.INTERNAL,
6929
- facts: { missing }
6930
- }
6931
- );
6932
- }
6933
- function requireCredentials(accessKeyId, secretAccessKey) {
6934
- if (!accessKeyId || !secretAccessKey) {
6935
- throw new Error(
6936
- "S3 credentials are required for default storage operations. Provide S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY or pass options.storageAdapter."
6937
- );
6938
- }
6939
- return { accessKeyId, secretAccessKey };
6940
- }
6941
- async function putObjectWithStorageAdapter(input, adapter) {
6942
- if (adapter) {
6943
- await adapter.putObject(input);
6944
- return;
6945
- }
6946
- const credentials = requireCredentials(input.accessKeyId, input.secretAccessKey);
6947
- await putObjectToS3({
6948
- accessKeyId: credentials.accessKeyId,
6949
- secretAccessKey: credentials.secretAccessKey,
6950
- endpoint: input.endpoint,
6951
- region: input.region,
6952
- bucket: input.bucket,
6953
- key: input.key,
6954
- body: input.body,
6955
- contentType: input.contentType
6956
- });
6957
- }
6958
- async function createPresignedGetUrlWithStorageAdapter(input, adapter) {
6959
- if (adapter) {
6960
- return adapter.createPresignedGetUrl(input);
6961
- }
6962
- const credentials = requireCredentials(input.accessKeyId, input.secretAccessKey);
6963
- return createPresignedGetUrl({
6964
- accessKeyId: credentials.accessKeyId,
6965
- secretAccessKey: credentials.secretAccessKey,
6966
- endpoint: input.endpoint,
6967
- region: input.region,
6968
- bucket: input.bucket,
6969
- key: input.key,
6970
- expiresInSeconds: input.expiresInSeconds
6971
- });
6972
- }
6973
-
6974
- // src/workflows/edit-captions.ts
6975
7331
  var profanityDetectionSchema = z8.object({
6976
7332
  profanity: z8.array(z8.string().max(100)).describe(
6977
7333
  "Unique profane words or short phrases exactly as they appear in the transcript text. Include each distinct form only once (e.g., if 'fuck' and 'fucking' both appear, list both)."
@@ -7230,7 +7586,7 @@ async function uploadEditedVttToS3({
7230
7586
  key: vttKey,
7231
7587
  body: editedVtt,
7232
7588
  contentType: "text/vtt"
7233
- }, storageAdapter);
7589
+ }, storageAdapter, { classifiedErrors: true });
7234
7590
  return createPresignedGetUrlWithStorageAdapter({
7235
7591
  accessKeyId: s3AccessKeyId,
7236
7592
  secretAccessKey: s3SecretAccessKey,
@@ -10675,102 +11031,6 @@ async function getSummaryAndTagsInternal(assetId, options, collectedUsage) {
10675
11031
 
10676
11032
  // src/workflows/translate-audio.ts
10677
11033
  import { sleep as sleep2 } from "workflow";
10678
-
10679
- // src/lib/elevenlabs-errors.ts
10680
- var MAX_ERROR_BODY_CHARS = 500;
10681
- function isRetryableElevenLabsStatus(status) {
10682
- return isTransientStatus(status);
10683
- }
10684
- function elevenLabsFailureError(message, call, failure, facts) {
10685
- return dependencyError(message, {
10686
- dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
10687
- call,
10688
- status: failure.httpStatus,
10689
- requestId: failure.requestId,
10690
- timedOut: failure.reason === "timeout",
10691
- facts: {
10692
- provider: "elevenlabs",
10693
- ...failure.reason && { providerCode: failure.reason },
10694
- ...failure.detail && { detail: errorDetailFact(failure.detail) },
10695
- ...facts
10696
- },
10697
- transient: false,
10698
- retryable: failure.retryable
10699
- });
10700
- }
10701
- async function elevenLabsResponseFailure(response) {
10702
- const body = await response.text().catch(() => "");
10703
- return httpFailure(response.status, response.statusText, body, response.headers);
10704
- }
10705
- function elevenLabsSdkFailure(error) {
10706
- const failure = error;
10707
- if (typeof failure?.statusCode === "number") {
10708
- const body = typeof failure.body === "string" ? failure.body : JSON.stringify(failure.body ?? "");
10709
- return httpFailure(failure.statusCode, failure.rawResponse?.statusText, body, failure.rawResponse?.headers);
10710
- }
10711
- const message = failure?.message ?? String(error);
10712
- switch (failure?.name) {
10713
- case "ElevenLabsTimeoutError":
10714
- return { reason: "timeout", retryable: true, detail: message };
10715
- // The SDK validates responses strictly: the API's response no longer matches
10716
- // this SDK version, so the same call fails the same way.
10717
- case "ParseError":
10718
- return { reason: "unexpected_response", retryable: false, detail: `Unexpected ElevenLabs response: ${message}` };
10719
- // The SDK's own error without a status: the request got no response.
10720
- case "ElevenLabsError":
10721
- return { reason: "network_error", retryable: true, detail: message };
10722
- default:
10723
- return { retryable: false, detail: message };
10724
- }
10725
- }
10726
- function httpFailure(status, statusText, body, headers) {
10727
- const statusLine = [status, statusText].filter(Boolean).join(" ");
10728
- const { reason, detail, requestId } = parseElevenLabsErrorBody(body);
10729
- const responseRequestId = requestId ?? requestIdOf(headers);
10730
- return {
10731
- httpStatus: status,
10732
- reason,
10733
- ...responseRequestId && { requestId: responseRequestId },
10734
- retryable: isRetryableElevenLabsStatus(status),
10735
- detail: detail ? `${statusLine}: ${detail}` : statusLine
10736
- };
10737
- }
10738
- function parseElevenLabsErrorBody(body) {
10739
- const trimmed = body.trim();
10740
- if (!trimmed) {
10741
- return { detail: "" };
10742
- }
10743
- let detail;
10744
- try {
10745
- detail = JSON.parse(trimmed).detail;
10746
- } catch {
10747
- return { detail: trimmed.slice(0, MAX_ERROR_BODY_CHARS) };
10748
- }
10749
- if (typeof detail === "string" && detail) {
10750
- return { detail };
10751
- }
10752
- if (Array.isArray(detail) && detail.length > 0) {
10753
- return {
10754
- detail: detail.map((item) => [item.loc?.join("."), item.msg].filter(Boolean).join(": ")).join("; ")
10755
- };
10756
- }
10757
- if (detail && typeof detail === "object") {
10758
- const { status, code, message, param, request_id: requestId } = detail;
10759
- const reasonCode = [status, code].find((value) => typeof value === "string" && value !== "");
10760
- const reasonText = [reasonCode, message].filter(Boolean).join(": ");
10761
- const context = [param && `param: ${param}`, requestId && `request_id: ${requestId}`].filter(Boolean).join(", ");
10762
- if (reasonText) {
10763
- return {
10764
- reason: reasonCode,
10765
- detail: context ? `${reasonText} (${context})` : reasonText,
10766
- ...typeof requestId === "string" && requestId && { requestId }
10767
- };
10768
- }
10769
- }
10770
- return { detail: trimmed.slice(0, MAX_ERROR_BODY_CHARS) };
10771
- }
10772
-
10773
- // src/workflows/translate-audio.ts
10774
11034
  var CAPTIONS_UNAVAILABLE_MESSAGE = "The dub completed, but its subtitles could not be retrieved.";
10775
11035
  var CAPTIONS_ATTACHMENT_FAILED_MESSAGE = "Dub subtitles could not be attached to the Mux asset.";
10776
11036
  var STATIC_RENDITION_POLL_INTERVAL_MS = 1e4;
@@ -11147,7 +11407,7 @@ async function downloadAndUploadDubbedAudio({
11147
11407
  key: audioKey,
11148
11408
  body: dubbedAudio,
11149
11409
  contentType: Object.keys(formats).find((type) => formats[type] === extension)
11150
- }, storageAdapter);
11410
+ }, storageAdapter, { classifiedErrors: true });
11151
11411
  const presignedUrl = await createPresignedGetUrlWithStorageAdapter({
11152
11412
  accessKeyId: s3AccessKeyId,
11153
11413
  secretAccessKey: s3SecretAccessKey,
@@ -11196,7 +11456,7 @@ async function downloadAndUploadDubTranscript({
11196
11456
  key: vttKey,
11197
11457
  body: transcriptVtt,
11198
11458
  contentType: "text/vtt"
11199
- }, storageAdapter);
11459
+ }, storageAdapter, { classifiedErrors: true });
11200
11460
  const presignedUrl = await createPresignedGetUrlWithStorageAdapter({
11201
11461
  accessKeyId: s3AccessKeyId,
11202
11462
  secretAccessKey: s3SecretAccessKey,
@@ -12253,7 +12513,7 @@ async function uploadVttToS3({
12253
12513
  key: vttKey,
12254
12514
  body: translatedVtt,
12255
12515
  contentType: "text/vtt"
12256
- }, storageAdapter);
12516
+ }, storageAdapter, { classifiedErrors: true });
12257
12517
  return createPresignedGetUrlWithStorageAdapter({
12258
12518
  accessKeyId: s3AccessKeyId,
12259
12519
  secretAccessKey: s3SecretAccessKey,
@@ -12502,6 +12762,8 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
12502
12762
  }
12503
12763
  export {
12504
12764
  ClassifiedError,
12765
+ MUX_AI_DEPENDENCY_STATUS_CODES,
12766
+ MUX_AI_DEPENDENCY_STATUS_CODE_VALUES,
12505
12767
  MUX_AI_ERROR_CATALOG,
12506
12768
  MUX_AI_ERROR_CODES,
12507
12769
  MUX_AI_ERROR_CODE_VALUES,
@@ -12525,6 +12787,11 @@ export {
12525
12787
  createWorkflowStorageClient,
12526
12788
  decryptFromWorkflow,
12527
12789
  dependencyError,
12790
+ dependencyFailureCode,
12791
+ elevenLabsErrorRule,
12792
+ elevenLabsFailureError,
12793
+ elevenLabsResponseFailure,
12794
+ elevenLabsSdkFailure,
12528
12795
  encryptForWorkflow,
12529
12796
  errorDetailFact,
12530
12797
  findNameCollisionTextTracks,