@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-BUM1MVpR.d.ts → index-Be9HQB67.d.ts} +1 -1
- package/dist/{index-DtZUwuCb.d.ts → index-D_kEPGJj.d.ts} +1 -1
- package/dist/index.d.ts +111 -15
- package/dist/index.js +454 -187
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.d.ts +2 -2
- package/dist/primitives/index.js +146 -9
- package/dist/primitives/index.js.map +1 -1
- package/dist/{transcripts-qZm-RokR.d.ts → transcripts-DYpx6Mac.d.ts} +200 -6
- package/dist/workflows/index.d.ts +2 -2
- package/dist/workflows/index.js +280 -39
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
package/dist/workflows/index.js
CHANGED
|
@@ -642,7 +642,49 @@ var MUX_AI_ERROR_CODES = {
|
|
|
642
642
|
/** The asset's static rendition settings changed while waiting for its rendition. A new job uses the new settings. Facts: `assetId`. */
|
|
643
643
|
STATIC_RENDITION_CHANGED: "static_rendition_changed",
|
|
644
644
|
/** Mux didn't finish the static rendition within the polling budget. Facts: `assetId`, `attempts`, `pollIntervalMs`, `lastStatus`. */
|
|
645
|
-
STATIC_RENDITION_TIMEOUT: "static_rendition_timeout"
|
|
645
|
+
STATIC_RENDITION_TIMEOUT: "static_rendition_timeout",
|
|
646
|
+
/**
|
|
647
|
+
* The provider says the account the service running the SDK uses is out of credits or
|
|
648
|
+
* quota, or hit a spend or usage limit. Retrying won't help until someone changes the
|
|
649
|
+
* account. The site names the dependency. Facts: `call`, `status`, `providerCode`.
|
|
650
|
+
*/
|
|
651
|
+
PROVIDER_QUOTA_EXHAUSTED: "provider_quota_exhausted",
|
|
652
|
+
/** 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`. */
|
|
653
|
+
PROVIDER_CREDENTIALS_REJECTED: "provider_credentials_rejected",
|
|
654
|
+
/** The provider says requests are over its rate or concurrency limit. The site names the dependency. Facts: `call`, `status`, `providerCode`. */
|
|
655
|
+
PROVIDER_RATE_LIMITED: "provider_rate_limited",
|
|
656
|
+
/** The provider says it's overloaded or down for maintenance. The site names the dependency. Facts: `call`, `status`, `providerCode`. */
|
|
657
|
+
PROVIDER_UNAVAILABLE: "provider_unavailable",
|
|
658
|
+
/** 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`). */
|
|
659
|
+
AUDIO_UNPROCESSABLE: "audio_unprocessable",
|
|
660
|
+
/** 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`). */
|
|
661
|
+
ACCOUNT_CREDENTIALS_REJECTED: "account_credentials_rejected",
|
|
662
|
+
/** 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`. */
|
|
663
|
+
ASSET_RESOURCE_NOT_FOUND: "asset_resource_not_found",
|
|
664
|
+
/** 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`. */
|
|
665
|
+
PLAYBACK_ACCESS_DENIED: "playback_access_denied",
|
|
666
|
+
// Fallback codes (see MUX_AI_DEPENDENCY_STATUS_CODES): what a remote call's failure looked
|
|
667
|
+
// like, when no per-dependency rule recognized it. The site names the dependency.
|
|
668
|
+
/** No response arrived, and the call didn't time out (e.g. a connection failure). Facts: `call`. */
|
|
669
|
+
DEPENDENCY_NO_RESPONSE: "dependency_no_response",
|
|
670
|
+
/** The call timed out, or the dependency answered 408. Facts: `call`, `status`. */
|
|
671
|
+
DEPENDENCY_TIMEOUT: "dependency_timeout",
|
|
672
|
+
/** The dependency answered 429. Facts: `call`, `status`. */
|
|
673
|
+
DEPENDENCY_RATE_LIMITED: "dependency_rate_limited",
|
|
674
|
+
/** The dependency answered 425. Facts: `call`, `status`. */
|
|
675
|
+
DEPENDENCY_TOO_EARLY: "dependency_too_early",
|
|
676
|
+
/** The dependency answered with a 5xx status. Facts: `call`, `status`. */
|
|
677
|
+
DEPENDENCY_SERVER_ERROR: "dependency_server_error",
|
|
678
|
+
/** The dependency answered 401 or 403 to a request made with the service's own credentials. Facts: `call`, `status`. */
|
|
679
|
+
DEPENDENCY_AUTH_REJECTED: "dependency_auth_rejected",
|
|
680
|
+
/** The dependency answered 404 to a request the SDK built. Facts: `call`, `status`. */
|
|
681
|
+
DEPENDENCY_NOT_FOUND: "dependency_not_found",
|
|
682
|
+
/** The dependency answered with another 4xx status. Facts: `call`, `status`. */
|
|
683
|
+
DEPENDENCY_REQUEST_REJECTED: "dependency_request_rejected",
|
|
684
|
+
/** The dependency answered with a status that isn't an error (1xx-3xx) where a result was expected. Facts: `call`, `status`. */
|
|
685
|
+
DEPENDENCY_OTHER_STATUS: "dependency_other_status",
|
|
686
|
+
/** 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. */
|
|
687
|
+
DEPENDENCY_RESPONSE_FAILED: "dependency_response_failed"
|
|
646
688
|
};
|
|
647
689
|
var MUX_AI_ERROR_CODE_VALUES = Object.values(MUX_AI_ERROR_CODES);
|
|
648
690
|
var MUX_AI_ERROR_CATALOG = {
|
|
@@ -700,7 +742,39 @@ var MUX_AI_ERROR_CATALOG = {
|
|
|
700
742
|
[MUX_AI_ERROR_CODES.AUDIO_TRACK_MISSING]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
701
743
|
[MUX_AI_ERROR_CODES.PRIMARY_AUDIO_TRACK_CONFLICT]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
702
744
|
// Retryable although asset-sourced: the asset changed mid-run, and a new job uses the new settings.
|
|
703
|
-
[MUX_AI_ERROR_CODES.STATIC_RENDITION_CHANGED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, retryable: true }
|
|
745
|
+
[MUX_AI_ERROR_CODES.STATIC_RENDITION_CHANGED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, retryable: true },
|
|
746
|
+
// Conditions a remote service reports in its own terms (see the per-dependency modules,
|
|
747
|
+
// e.g. elevenlabs-errors.ts), so the code holds whichever dependency the site names.
|
|
748
|
+
// A provider's key and quota are the configuration of the service running the SDK, like
|
|
749
|
+
// its signing keys and storage: `internal`. (`account` is the caller's Mux account.)
|
|
750
|
+
// Neither step-retried nor resubmittable: the provider says retrying won't restore access.
|
|
751
|
+
[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 },
|
|
752
|
+
[MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
|
|
753
|
+
[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 },
|
|
754
|
+
[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 },
|
|
755
|
+
[MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, siteDependency: true },
|
|
756
|
+
// Mux's own responses, where the call says whose they are (see mux-video-errors.ts).
|
|
757
|
+
// The access token is the caller's: only its permissions decide what Mux allows.
|
|
758
|
+
[MUX_AI_ERROR_CODES.ACCOUNT_CREDENTIALS_REJECTED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ACCOUNT, siteDependency: true },
|
|
759
|
+
[MUX_AI_ERROR_CODES.ASSET_RESOURCE_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, siteDependency: true },
|
|
760
|
+
// Media requests carry no access token. Mux denies them for an expired signed token or a
|
|
761
|
+
// playback restriction; the SDK signs fresh tokens, so it's the account's keys or restrictions.
|
|
762
|
+
[MUX_AI_ERROR_CODES.PLAYBACK_ACCESS_DENIED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ACCOUNT, siteDependency: true },
|
|
763
|
+
// Fallback codes: each implies the classification the status rules give it
|
|
764
|
+
// (`classifyDependencyFailure` with its default sources). A site that knows more raises
|
|
765
|
+
// a more specific code instead. Transient ones are step-retried unless the call isn't
|
|
766
|
+
// idempotent (see `dependencyError`).
|
|
767
|
+
[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 },
|
|
768
|
+
[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 },
|
|
769
|
+
[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 },
|
|
770
|
+
[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 },
|
|
771
|
+
[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 },
|
|
772
|
+
[MUX_AI_ERROR_CODES.DEPENDENCY_AUTH_REJECTED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
|
|
773
|
+
[MUX_AI_ERROR_CODES.DEPENDENCY_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
|
|
774
|
+
[MUX_AI_ERROR_CODES.DEPENDENCY_REQUEST_REJECTED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
|
|
775
|
+
[MUX_AI_ERROR_CODES.DEPENDENCY_OTHER_STATUS]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, siteDependency: true },
|
|
776
|
+
// Not step-retried: the dependency answered, and would answer the same way. Resubmittable.
|
|
777
|
+
[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 }
|
|
704
778
|
};
|
|
705
779
|
function isTransientStatus(status) {
|
|
706
780
|
return status === void 0 || status === 408 || status === 425 || status === 429 || status >= 500;
|
|
@@ -717,6 +791,19 @@ function defaultRetryable(type, source, transient) {
|
|
|
717
791
|
}
|
|
718
792
|
return source === MUX_AI_ERROR_SOURCES.UPSTREAM;
|
|
719
793
|
}
|
|
794
|
+
var MUX_AI_DEPENDENCY_STATUS_CODES = {
|
|
795
|
+
NO_RESPONSE: MUX_AI_ERROR_CODES.DEPENDENCY_NO_RESPONSE,
|
|
796
|
+
TIMEOUT: MUX_AI_ERROR_CODES.DEPENDENCY_TIMEOUT,
|
|
797
|
+
RATE_LIMITED: MUX_AI_ERROR_CODES.DEPENDENCY_RATE_LIMITED,
|
|
798
|
+
TOO_EARLY: MUX_AI_ERROR_CODES.DEPENDENCY_TOO_EARLY,
|
|
799
|
+
SERVER_ERROR: MUX_AI_ERROR_CODES.DEPENDENCY_SERVER_ERROR,
|
|
800
|
+
AUTH_REJECTED: MUX_AI_ERROR_CODES.DEPENDENCY_AUTH_REJECTED,
|
|
801
|
+
NOT_FOUND: MUX_AI_ERROR_CODES.DEPENDENCY_NOT_FOUND,
|
|
802
|
+
REQUEST_REJECTED: MUX_AI_ERROR_CODES.DEPENDENCY_REQUEST_REJECTED,
|
|
803
|
+
OTHER_STATUS: MUX_AI_ERROR_CODES.DEPENDENCY_OTHER_STATUS,
|
|
804
|
+
RESPONSE_FAILED: MUX_AI_ERROR_CODES.DEPENDENCY_RESPONSE_FAILED
|
|
805
|
+
};
|
|
806
|
+
var MUX_AI_DEPENDENCY_STATUS_CODE_VALUES = Object.values(MUX_AI_DEPENDENCY_STATUS_CODES);
|
|
720
807
|
var MAX_CAUSE_DEPTH = 3;
|
|
721
808
|
var MAX_CAUSE_MESSAGE_LENGTH = 500;
|
|
722
809
|
function statusOf(value) {
|
|
@@ -943,10 +1030,63 @@ function classifyDependencyFailure(init) {
|
|
|
943
1030
|
...init.retryable !== void 0 && { retryable: init.retryable }
|
|
944
1031
|
};
|
|
945
1032
|
}
|
|
1033
|
+
function dependencyFailureCode({ status, timedOut }) {
|
|
1034
|
+
if (timedOut || status === 408) {
|
|
1035
|
+
return MUX_AI_DEPENDENCY_STATUS_CODES.TIMEOUT;
|
|
1036
|
+
}
|
|
1037
|
+
if (status === void 0) {
|
|
1038
|
+
return MUX_AI_DEPENDENCY_STATUS_CODES.NO_RESPONSE;
|
|
1039
|
+
}
|
|
1040
|
+
if (status === 429) {
|
|
1041
|
+
return MUX_AI_DEPENDENCY_STATUS_CODES.RATE_LIMITED;
|
|
1042
|
+
}
|
|
1043
|
+
if (status === 425) {
|
|
1044
|
+
return MUX_AI_DEPENDENCY_STATUS_CODES.TOO_EARLY;
|
|
1045
|
+
}
|
|
1046
|
+
if (status >= 500 && status < 600) {
|
|
1047
|
+
return MUX_AI_DEPENDENCY_STATUS_CODES.SERVER_ERROR;
|
|
1048
|
+
}
|
|
1049
|
+
if (status === 401 || status === 403) {
|
|
1050
|
+
return MUX_AI_DEPENDENCY_STATUS_CODES.AUTH_REJECTED;
|
|
1051
|
+
}
|
|
1052
|
+
if (status === 404) {
|
|
1053
|
+
return MUX_AI_DEPENDENCY_STATUS_CODES.NOT_FOUND;
|
|
1054
|
+
}
|
|
1055
|
+
return status >= 400 && status < 500 ? MUX_AI_DEPENDENCY_STATUS_CODES.REQUEST_REJECTED : MUX_AI_DEPENDENCY_STATUS_CODES.OTHER_STATUS;
|
|
1056
|
+
}
|
|
1057
|
+
function attributedFailureCode({ status, timedOut, notFoundSource, authSource }) {
|
|
1058
|
+
if (timedOut) {
|
|
1059
|
+
return void 0;
|
|
1060
|
+
}
|
|
1061
|
+
if (status === 404 && notFoundSource === MUX_AI_ERROR_SOURCES.ASSET) {
|
|
1062
|
+
return MUX_AI_ERROR_CODES.ASSET_RESOURCE_NOT_FOUND;
|
|
1063
|
+
}
|
|
1064
|
+
if ((status === 401 || status === 403) && authSource === MUX_AI_ERROR_SOURCES.ACCOUNT) {
|
|
1065
|
+
return MUX_AI_ERROR_CODES.ACCOUNT_CREDENTIALS_REJECTED;
|
|
1066
|
+
}
|
|
1067
|
+
return void 0;
|
|
1068
|
+
}
|
|
946
1069
|
function dependencyError(message, init) {
|
|
947
|
-
const {
|
|
948
|
-
|
|
949
|
-
|
|
1070
|
+
const { facts, transient } = classifyDependencyFailure(
|
|
1071
|
+
init.authSource === MUX_AI_ERROR_SOURCES.ACCOUNT && !init.authInputs?.length ? { ...init, authInputs: ["credentials"] } : init
|
|
1072
|
+
);
|
|
1073
|
+
const code = init.code ?? attributedFailureCode(init) ?? dependencyFailureCode(init);
|
|
1074
|
+
const entry = MUX_AI_ERROR_CATALOG[code];
|
|
1075
|
+
const mayHaveTakenEffect = init.timedOut === true || (init.status === void 0 ? code === MUX_AI_ERROR_CODES.DEPENDENCY_NO_RESPONSE : init.status >= 500);
|
|
1076
|
+
const retryable = init.retryable ?? entry.retryable;
|
|
1077
|
+
return new MuxAiError(message, {
|
|
1078
|
+
code,
|
|
1079
|
+
type: entry.type,
|
|
1080
|
+
source: entry.source,
|
|
1081
|
+
dependency: init.dependency,
|
|
1082
|
+
facts,
|
|
1083
|
+
// The site's override wins, then a non-idempotent call that may have taken effect,
|
|
1084
|
+
// then the code's policy, then the status rules. A code other than no response or a
|
|
1085
|
+
// timeout means the dependency answered, so a missing status isn't "no response" here.
|
|
1086
|
+
transient: init.transient ?? (init.idempotent === false && mayHaveTakenEffect ? false : void 0) ?? entry.transient ?? (init.status === void 0 && !init.timedOut ? false : transient),
|
|
1087
|
+
...retryable !== void 0 && { retryable },
|
|
1088
|
+
cause: init.cause
|
|
1089
|
+
});
|
|
950
1090
|
}
|
|
951
1091
|
function httpStatusOf(error) {
|
|
952
1092
|
if (typeof error !== "object" || error === null) {
|
|
@@ -1886,6 +2026,14 @@ function muxVideoErrorFacts(error) {
|
|
|
1886
2026
|
return parsed.success ? { muxErrorType: parsed.data.error.error.type } : {};
|
|
1887
2027
|
}
|
|
1888
2028
|
function muxVideoError(message, init) {
|
|
2029
|
+
return dependencyError(message, {
|
|
2030
|
+
...init,
|
|
2031
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
2032
|
+
notFoundSource: MUX_AI_ERROR_SOURCES.ASSET,
|
|
2033
|
+
...!init.timedOut && (init.status === 401 || init.status === 403) && { code: MUX_AI_ERROR_CODES.PLAYBACK_ACCESS_DENIED }
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
function muxVideoApiError(message, init) {
|
|
1889
2037
|
return dependencyError(message, {
|
|
1890
2038
|
...init,
|
|
1891
2039
|
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
@@ -1903,7 +2051,10 @@ function muxVideoCallError(message, call, error, facts) {
|
|
|
1903
2051
|
}
|
|
1904
2052
|
return error;
|
|
1905
2053
|
}
|
|
1906
|
-
|
|
2054
|
+
if (call === "get_asset" && httpStatusOf(error) === 404) {
|
|
2055
|
+
return assetNotFoundError(error, facts);
|
|
2056
|
+
}
|
|
2057
|
+
return muxVideoApiError(message, {
|
|
1907
2058
|
call,
|
|
1908
2059
|
status: httpStatusOf(error),
|
|
1909
2060
|
requestId: requestIdOf(error?.headers),
|
|
@@ -1912,18 +2063,19 @@ function muxVideoCallError(message, call, error, facts) {
|
|
|
1912
2063
|
});
|
|
1913
2064
|
}
|
|
1914
2065
|
function muxAssetFetchError(assetId, error) {
|
|
1915
|
-
if (!MuxAiError.is(error) && httpStatusOf(error) === 404) {
|
|
1916
|
-
return new MuxAiError(`Mux asset ${assetId} not found`, {
|
|
1917
|
-
code: MUX_AI_ERROR_CODES.ASSET_NOT_FOUND,
|
|
1918
|
-
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
1919
|
-
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
1920
|
-
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
1921
|
-
facts: { call: "get_asset", status: 404, assetId, inputs: ["assetId"], ...muxVideoErrorFacts(error) },
|
|
1922
|
-
cause: error
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
2066
|
return muxVideoCallError("Failed to fetch the asset from Mux", "get_asset", error, { assetId });
|
|
1926
2067
|
}
|
|
2068
|
+
function assetNotFoundError(error, facts) {
|
|
2069
|
+
const requestId = requestIdOf(error?.headers);
|
|
2070
|
+
return new MuxAiError(typeof facts?.assetId === "string" ? `Mux asset ${facts.assetId} not found` : "Mux asset not found", {
|
|
2071
|
+
code: MUX_AI_ERROR_CODES.ASSET_NOT_FOUND,
|
|
2072
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
2073
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
2074
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
2075
|
+
facts: { call: "get_asset", status: 404, ...requestId && { requestId }, ...facts, inputs: ["assetId"], ...muxVideoErrorFacts(error) },
|
|
2076
|
+
cause: error
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
1927
2079
|
function missingTrackIdError(message, facts) {
|
|
1928
2080
|
return new MuxAiError(message, {
|
|
1929
2081
|
code: MUX_AI_ERROR_CODES.TRACK_ID_MISSING,
|
|
@@ -5629,6 +5781,39 @@ async function replaceAndCreateTextTrack(input) {
|
|
|
5629
5781
|
return replaceAndCreateTrack({ ...input, target: { ...input.target, type: "text" } });
|
|
5630
5782
|
}
|
|
5631
5783
|
|
|
5784
|
+
// src/lib/storage-errors.ts
|
|
5785
|
+
var S3_TOKEN = /^[\w.-]{1,64}$/;
|
|
5786
|
+
var S3_ERROR_CODES = {
|
|
5787
|
+
// 503: S3 is scaling to a new request rate; AWS retries it as throttling.
|
|
5788
|
+
SlowDown: MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED
|
|
5789
|
+
};
|
|
5790
|
+
function s3ErrorDetails(body) {
|
|
5791
|
+
const field = (name) => {
|
|
5792
|
+
const value = new RegExp(`<${name}>([^<]*)</${name}>`).exec(body)?.[1]?.trim();
|
|
5793
|
+
return value && S3_TOKEN.test(value) ? value : void 0;
|
|
5794
|
+
};
|
|
5795
|
+
const s3Code = field("Code");
|
|
5796
|
+
const requestId = field("RequestId");
|
|
5797
|
+
return { ...s3Code && { s3Code }, ...requestId && { requestId } };
|
|
5798
|
+
}
|
|
5799
|
+
function s3ResponseError(message, call, response, body, facts, cause) {
|
|
5800
|
+
const { s3Code, requestId } = s3ErrorDetails(body);
|
|
5801
|
+
const code = s3Code ? S3_ERROR_CODES[s3Code] : void 0;
|
|
5802
|
+
return dependencyError(message, {
|
|
5803
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.STORAGE,
|
|
5804
|
+
call,
|
|
5805
|
+
status: response.status,
|
|
5806
|
+
requestId: requestIdOf(response.headers) ?? requestId,
|
|
5807
|
+
timedOut: s3Code === "RequestTimeout",
|
|
5808
|
+
facts: { ...s3Code && { s3Code }, ...facts },
|
|
5809
|
+
...code && { code },
|
|
5810
|
+
cause
|
|
5811
|
+
});
|
|
5812
|
+
}
|
|
5813
|
+
function s3NoResponseError(message, call, cause, facts) {
|
|
5814
|
+
return dependencyError(message, { dependency: MUX_AI_ERROR_DEPENDENCIES.STORAGE, call, facts, cause });
|
|
5815
|
+
}
|
|
5816
|
+
|
|
5632
5817
|
// src/lib/s3-sigv4.ts
|
|
5633
5818
|
var AWS4_ALGORITHM = "AWS4-HMAC-SHA256";
|
|
5634
5819
|
var AWS4_REQUEST_TERMINATOR = "aws4_request";
|
|
@@ -5747,7 +5932,8 @@ async function putObjectToS3({
|
|
|
5747
5932
|
bucket,
|
|
5748
5933
|
key,
|
|
5749
5934
|
body,
|
|
5750
|
-
contentType
|
|
5935
|
+
contentType,
|
|
5936
|
+
classifiedErrors
|
|
5751
5937
|
}) {
|
|
5752
5938
|
const resolvedEndpoint = normalizeEndpoint(endpoint);
|
|
5753
5939
|
const canonicalUri = buildCanonicalUri(resolvedEndpoint, bucket, key);
|
|
@@ -5782,20 +5968,32 @@ async function putObjectToS3({
|
|
|
5782
5968
|
const signature = await signString(secretAccessKey, shortDate, region, stringToSign);
|
|
5783
5969
|
const authorization = `${AWS4_ALGORITHM} Credential=${accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
|
|
5784
5970
|
const requestUrl = `${resolvedEndpoint.origin}${canonicalUri}`;
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
"
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5971
|
+
let response;
|
|
5972
|
+
try {
|
|
5973
|
+
response = await fetch(requestUrl, {
|
|
5974
|
+
method: "PUT",
|
|
5975
|
+
headers: {
|
|
5976
|
+
"Authorization": authorization,
|
|
5977
|
+
"x-amz-content-sha256": payloadHash,
|
|
5978
|
+
"x-amz-date": amzDate,
|
|
5979
|
+
...normalizedContentType ? { "content-type": normalizedContentType } : {}
|
|
5980
|
+
},
|
|
5981
|
+
body
|
|
5982
|
+
});
|
|
5983
|
+
} catch (error) {
|
|
5984
|
+
if (!classifiedErrors) {
|
|
5985
|
+
throw error;
|
|
5986
|
+
}
|
|
5987
|
+
throw s3NoResponseError("S3 PUT got no response", "put_object", error);
|
|
5988
|
+
}
|
|
5795
5989
|
if (!response.ok) {
|
|
5796
5990
|
const errorBody = await response.text().catch(() => "");
|
|
5797
5991
|
const detail = errorBody ? ` ${errorBody}` : "";
|
|
5798
|
-
|
|
5992
|
+
const message = `S3 PUT failed (${response.status} ${response.statusText}).${detail}`;
|
|
5993
|
+
if (!classifiedErrors) {
|
|
5994
|
+
throw new Error(message);
|
|
5995
|
+
}
|
|
5996
|
+
throw s3ResponseError(`S3 PUT failed (${response.status} ${response.statusText}).`, "put_object", response, errorBody, void 0, new Error(message));
|
|
5799
5997
|
}
|
|
5800
5998
|
}
|
|
5801
5999
|
async function createPresignedGetUrl({
|
|
@@ -5853,20 +6051,23 @@ function storageNotConfiguredError(missing) {
|
|
|
5853
6051
|
}
|
|
5854
6052
|
);
|
|
5855
6053
|
}
|
|
5856
|
-
function requireCredentials(accessKeyId, secretAccessKey) {
|
|
6054
|
+
function requireCredentials(accessKeyId, secretAccessKey, { classifiedErrors } = {}) {
|
|
5857
6055
|
if (!accessKeyId || !secretAccessKey) {
|
|
6056
|
+
if (classifiedErrors) {
|
|
6057
|
+
throw storageNotConfiguredError(["S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"]);
|
|
6058
|
+
}
|
|
5858
6059
|
throw new Error(
|
|
5859
6060
|
"S3 credentials are required for default storage operations. Provide S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY or pass options.storageAdapter."
|
|
5860
6061
|
);
|
|
5861
6062
|
}
|
|
5862
6063
|
return { accessKeyId, secretAccessKey };
|
|
5863
6064
|
}
|
|
5864
|
-
async function putObjectWithStorageAdapter(input, adapter) {
|
|
6065
|
+
async function putObjectWithStorageAdapter(input, adapter, options = {}) {
|
|
5865
6066
|
if (adapter) {
|
|
5866
6067
|
await adapter.putObject(input);
|
|
5867
6068
|
return;
|
|
5868
6069
|
}
|
|
5869
|
-
const credentials = requireCredentials(input.accessKeyId, input.secretAccessKey);
|
|
6070
|
+
const credentials = requireCredentials(input.accessKeyId, input.secretAccessKey, options);
|
|
5870
6071
|
await putObjectToS3({
|
|
5871
6072
|
accessKeyId: credentials.accessKeyId,
|
|
5872
6073
|
secretAccessKey: credentials.secretAccessKey,
|
|
@@ -5875,7 +6076,8 @@ async function putObjectWithStorageAdapter(input, adapter) {
|
|
|
5875
6076
|
bucket: input.bucket,
|
|
5876
6077
|
key: input.key,
|
|
5877
6078
|
body: input.body,
|
|
5878
|
-
contentType: input.contentType
|
|
6079
|
+
contentType: input.contentType,
|
|
6080
|
+
classifiedErrors: options.classifiedErrors
|
|
5879
6081
|
});
|
|
5880
6082
|
}
|
|
5881
6083
|
async function createPresignedGetUrlWithStorageAdapter(input, adapter) {
|
|
@@ -6153,7 +6355,7 @@ async function uploadEditedVttToS3({
|
|
|
6153
6355
|
key: vttKey,
|
|
6154
6356
|
body: editedVtt,
|
|
6155
6357
|
contentType: "text/vtt"
|
|
6156
|
-
}, storageAdapter);
|
|
6358
|
+
}, storageAdapter, { classifiedErrors: true });
|
|
6157
6359
|
return createPresignedGetUrlWithStorageAdapter({
|
|
6158
6360
|
accessKeyId: s3AccessKeyId,
|
|
6159
6361
|
secretAccessKey: s3SecretAccessKey,
|
|
@@ -10026,7 +10228,36 @@ var MAX_ERROR_BODY_CHARS = 500;
|
|
|
10026
10228
|
function isRetryableElevenLabsStatus(status) {
|
|
10027
10229
|
return isTransientStatus(status);
|
|
10028
10230
|
}
|
|
10231
|
+
var ELEVENLABS_ERROR_CODES = {
|
|
10232
|
+
insufficient_credits: { code: MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED },
|
|
10233
|
+
quota_exceeded: { code: MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED },
|
|
10234
|
+
payment_required: { code: MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED },
|
|
10235
|
+
invalid_api_key: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
|
|
10236
|
+
missing_api_key: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
|
|
10237
|
+
invalid_authorization_header: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
|
|
10238
|
+
insufficient_permissions: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
|
|
10239
|
+
feature_not_available: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
|
|
10240
|
+
subscription_required: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
|
|
10241
|
+
model_access_denied: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
|
|
10242
|
+
workspace_access_denied: { code: MUX_AI_ERROR_CODES.PROVIDER_CREDENTIALS_REJECTED },
|
|
10243
|
+
rate_limit_exceeded: { code: MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED },
|
|
10244
|
+
concurrent_limit_exceeded: { code: MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED },
|
|
10245
|
+
too_many_concurrent_requests: { code: MUX_AI_ERROR_CODES.PROVIDER_RATE_LIMITED },
|
|
10246
|
+
system_busy: { code: MUX_AI_ERROR_CODES.PROVIDER_UNAVAILABLE },
|
|
10247
|
+
service_unavailable: { code: MUX_AI_ERROR_CODES.PROVIDER_UNAVAILABLE },
|
|
10248
|
+
maintenance: { code: MUX_AI_ERROR_CODES.PROVIDER_UNAVAILABLE },
|
|
10249
|
+
invalid_audio: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "corrupt" },
|
|
10250
|
+
invalid_audio_format: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "unsupported_format" },
|
|
10251
|
+
invalid_file_type: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "unsupported_format" },
|
|
10252
|
+
audio_too_long: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "too_long" },
|
|
10253
|
+
audio_too_short: { code: MUX_AI_ERROR_CODES.AUDIO_UNPROCESSABLE, reason: "too_short" }
|
|
10254
|
+
};
|
|
10255
|
+
function elevenLabsErrorRule(failure) {
|
|
10256
|
+
const values = failure.providerCodes ?? (failure.reason ? [failure.reason] : []);
|
|
10257
|
+
return values.map((value) => ELEVENLABS_ERROR_CODES[value]).find((rule) => rule !== void 0);
|
|
10258
|
+
}
|
|
10029
10259
|
function elevenLabsFailureError(message, call, failure, facts) {
|
|
10260
|
+
const rule = elevenLabsErrorRule(failure);
|
|
10030
10261
|
return dependencyError(message, {
|
|
10031
10262
|
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
10032
10263
|
call,
|
|
@@ -10037,10 +10268,15 @@ function elevenLabsFailureError(message, call, failure, facts) {
|
|
|
10037
10268
|
provider: "elevenlabs",
|
|
10038
10269
|
...failure.reason && { providerCode: failure.reason },
|
|
10039
10270
|
...failure.detail && { detail: errorDetailFact(failure.detail) },
|
|
10271
|
+
...rule?.reason && { reason: rule.reason },
|
|
10040
10272
|
...facts
|
|
10041
10273
|
},
|
|
10274
|
+
// Without a rule or a status, only a network error went unanswered (a timeout is
|
|
10275
|
+
// `timedOut`); anything else got a response with an error or nothing usable.
|
|
10276
|
+
...rule ? { code: rule.code } : failure.httpStatus === void 0 && failure.reason !== "network_error" && failure.reason !== "timeout" && { code: MUX_AI_ERROR_CODES.DEPENDENCY_RESPONSE_FAILED },
|
|
10042
10277
|
transient: false,
|
|
10043
|
-
|
|
10278
|
+
// Quota stays spent whatever the status, so a new job can't succeed either.
|
|
10279
|
+
retryable: rule?.code === MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED ? false : failure.retryable
|
|
10044
10280
|
});
|
|
10045
10281
|
}
|
|
10046
10282
|
async function elevenLabsResponseFailure(response) {
|
|
@@ -10070,13 +10306,16 @@ function elevenLabsSdkFailure(error) {
|
|
|
10070
10306
|
}
|
|
10071
10307
|
function httpFailure(status, statusText, body, headers) {
|
|
10072
10308
|
const statusLine = [status, statusText].filter(Boolean).join(" ");
|
|
10073
|
-
const { reason, detail, requestId } = parseElevenLabsErrorBody(body);
|
|
10309
|
+
const { reason, providerCodes, detail, requestId } = parseElevenLabsErrorBody(body);
|
|
10074
10310
|
const responseRequestId = requestId ?? requestIdOf(headers);
|
|
10311
|
+
const quota = elevenLabsErrorRule({ reason, providerCodes })?.code === MUX_AI_ERROR_CODES.PROVIDER_QUOTA_EXHAUSTED;
|
|
10075
10312
|
return {
|
|
10076
10313
|
httpStatus: status,
|
|
10077
10314
|
reason,
|
|
10315
|
+
...providerCodes && { providerCodes },
|
|
10078
10316
|
...responseRequestId && { requestId: responseRequestId },
|
|
10079
|
-
|
|
10317
|
+
// A spent quota isn't restored by retrying, even when it arrives as a 429.
|
|
10318
|
+
retryable: !quota && isRetryableElevenLabsStatus(status),
|
|
10080
10319
|
detail: detail ? `${statusLine}: ${detail}` : statusLine
|
|
10081
10320
|
};
|
|
10082
10321
|
}
|
|
@@ -10101,12 +10340,14 @@ function parseElevenLabsErrorBody(body) {
|
|
|
10101
10340
|
}
|
|
10102
10341
|
if (detail && typeof detail === "object") {
|
|
10103
10342
|
const { status, code, message, param, request_id: requestId } = detail;
|
|
10343
|
+
const providerCodes = [code, status].filter((value) => typeof value === "string" && value !== "");
|
|
10104
10344
|
const reasonCode = [status, code].find((value) => typeof value === "string" && value !== "");
|
|
10105
10345
|
const reasonText = [reasonCode, message].filter(Boolean).join(": ");
|
|
10106
10346
|
const context = [param && `param: ${param}`, requestId && `request_id: ${requestId}`].filter(Boolean).join(", ");
|
|
10107
10347
|
if (reasonText) {
|
|
10108
10348
|
return {
|
|
10109
10349
|
reason: reasonCode,
|
|
10350
|
+
...providerCodes.length > 0 && { providerCodes },
|
|
10110
10351
|
detail: context ? `${reasonText} (${context})` : reasonText,
|
|
10111
10352
|
...typeof requestId === "string" && requestId && { requestId }
|
|
10112
10353
|
};
|
|
@@ -10545,7 +10786,7 @@ async function downloadAndUploadDubbedAudio({
|
|
|
10545
10786
|
key: audioKey,
|
|
10546
10787
|
body: dubbedAudio,
|
|
10547
10788
|
contentType: Object.keys(formats).find((type) => formats[type] === extension)
|
|
10548
|
-
}, storageAdapter);
|
|
10789
|
+
}, storageAdapter, { classifiedErrors: true });
|
|
10549
10790
|
const presignedUrl = await createPresignedGetUrlWithStorageAdapter({
|
|
10550
10791
|
accessKeyId: s3AccessKeyId,
|
|
10551
10792
|
secretAccessKey: s3SecretAccessKey,
|
|
@@ -10594,7 +10835,7 @@ async function downloadAndUploadDubTranscript({
|
|
|
10594
10835
|
key: vttKey,
|
|
10595
10836
|
body: transcriptVtt,
|
|
10596
10837
|
contentType: "text/vtt"
|
|
10597
|
-
}, storageAdapter);
|
|
10838
|
+
}, storageAdapter, { classifiedErrors: true });
|
|
10598
10839
|
const presignedUrl = await createPresignedGetUrlWithStorageAdapter({
|
|
10599
10840
|
accessKeyId: s3AccessKeyId,
|
|
10600
10841
|
secretAccessKey: s3SecretAccessKey,
|
|
@@ -11651,7 +11892,7 @@ async function uploadVttToS3({
|
|
|
11651
11892
|
key: vttKey,
|
|
11652
11893
|
body: translatedVtt,
|
|
11653
11894
|
contentType: "text/vtt"
|
|
11654
|
-
}, storageAdapter);
|
|
11895
|
+
}, storageAdapter, { classifiedErrors: true });
|
|
11655
11896
|
return createPresignedGetUrlWithStorageAdapter({
|
|
11656
11897
|
accessKeyId: s3AccessKeyId,
|
|
11657
11898
|
secretAccessKey: s3SecretAccessKey,
|