@mux/ai 0.62.0 → 0.63.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-BN5yOn9o.d.ts → index-CA8sRSVJ.d.ts} +2 -534
- package/dist/{index-CHA2jigS.d.ts → index-eEZfpEP7.d.ts} +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +168 -78
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.d.ts +3 -2
- package/dist/primitives/index.js +195 -30
- package/dist/primitives/index.js.map +1 -1
- package/dist/transcripts-So1KIXSI.d.ts +1152 -0
- package/dist/workflows/index.d.ts +3 -3
- package/dist/workflows/index.js +165 -77
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/transcripts-DuNI058z.d.ts +0 -613
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, T as ThumbnailOptions, V as VTTCueBudgetChunkingOptions, b as VTTDurationChunk, c as VTTDurationChunkingOptions, d as chunkByTokens, e as chunkText, f as chunkVTTCues, g as chunkVTTCuesByBudget, h as chunkVTTCuesByDuration, j as estimateTokenCount, k as getHeatmapForAsset, l as getHeatmapForPlaybackId, m as getHeatmapForVideo, n as getStoryboardUrl, o as getThumbnailUrls } from '../index-
|
|
2
|
-
export {
|
|
1
|
+
export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, T as ThumbnailOptions, V as VTTCueBudgetChunkingOptions, b as VTTDurationChunk, c as VTTDurationChunkingOptions, d as chunkByTokens, e as chunkText, f as chunkVTTCues, g as chunkVTTCuesByBudget, h as chunkVTTCuesByDuration, j as estimateTokenCount, k as getHeatmapForAsset, l as getHeatmapForPlaybackId, m as getHeatmapForVideo, n as getStoryboardUrl, o as getThumbnailUrls } from '../index-eEZfpEP7.js';
|
|
2
|
+
export { a6 as CompletedShotsResult, a7 as DeletedShotsResult, a8 as ErroredShotsResult, a9 as Hotspot, aa as HotspotOptions, ab as HotspotResponse, ac as LOW_CONFIDENCE_THRESHOLD, ad as MAX_CUE_TEXT_CHARS, ae as ParseVTTCuesOptions, af as PendingShotsResult, ag as Shot, ah as ShotRequestOptions, ai as ShotsResult, aj as SkippedShotsResult, ak as TranscriptEmptyReason, al as TranscriptFetchOptions, am as TranscriptFetchStepResult, an as TranscriptResult, a5 as VTTCue, ao as WaitForShotsOptions, ap as buildTranscriptUrl, aq as buildVttFromCueBlocks, ar as buildVttFromTranslatedCueBlocks, as as concatenateVttSegments, at as extractTextFromVTT, au as extractTimestampedTranscript, av as fetchTranscriptDataForUrl, aw as fetchTranscriptForAsset, ax as filterVttByScope, ay as findCaptionTrack, az as getHotspotsForAsset, aA as getHotspotsForPlaybackId, aB as getHotspotsForVideo, aC as getReadyTextTracks, aD as getReliableLanguageCode, aE as getShotsForAsset, aF as parseVTTCues, aG as replaceCueText, aH as requestShotsForAsset, aI as sanitizeUntrustedText, aJ as secondsToTimestamp, aK as splitVttPreambleAndCueBlocks, aL as stripVttMetadataBlocks, aM as vttTimestampToSeconds, aN as waitForShotsForAsset } from '../transcripts-So1KIXSI.js';
|
|
3
|
+
import '@workflow/serde';
|
|
3
4
|
import '@mux/ts';
|
package/dist/primitives/index.js
CHANGED
|
@@ -960,7 +960,7 @@ var MUX_AI_ERROR_DEPENDENCIES = {
|
|
|
960
960
|
};
|
|
961
961
|
var MUX_AI_ERROR_DEPENDENCY_VALUES = Object.values(MUX_AI_ERROR_DEPENDENCIES);
|
|
962
962
|
var MUX_AI_ERROR_CODES = {
|
|
963
|
-
/** The requested time range is invalid, or has nothing to work with. Facts: `reason` (`invalid_start_time`, `invalid_end_time`, `exceeds_duration`, `empty_range`, `no_video`, `no_transcript`) and the bounds involved. */
|
|
963
|
+
/** The requested time range is invalid, or has nothing to work with. Facts: `reason` (`invalid_start_time`, `invalid_end_time`, `exceeds_duration`, `empty_range`, `no_video`, `no_transcript`, `no_scenes`) and the bounds involved. */
|
|
964
964
|
INVALID_SCOPE: "invalid_scope",
|
|
965
965
|
/** Existing tracks block writing the output track under the chosen replacement policy. Facts: `reason` (`policy_fail`, `not_generated`, `name_collision`, `primary_audio`), `conflictingTracks` and the target track, plus `sourceRestored` and `restoredTrackId` when a source track was deleted first. */
|
|
966
966
|
TRACK_REPLACEMENT_BLOCKED: "track_replacement_blocked",
|
|
@@ -992,6 +992,8 @@ var MUX_AI_ERROR_CODES = {
|
|
|
992
992
|
TRACK_WRITE_UNCLASSIFIED: "track_write_unclassified",
|
|
993
993
|
/** Mux answered a track create without a track id. The track may exist, so it isn't step-retried. Facts: `call`, `assetId`. */
|
|
994
994
|
TRACK_ID_MISSING: "track_id_missing",
|
|
995
|
+
/** The asset's ready caption track has no id, so its transcript can't be fetched. Facts: `assetId`, `languageCode`. */
|
|
996
|
+
CAPTION_TRACK_ID_MISSING: "caption_track_id_missing",
|
|
995
997
|
/** The asset snapshot the service running the SDK passed in is for a different asset than the one requested. Facts: `assetId`, `snapshotAssetId`. */
|
|
996
998
|
ASSET_SNAPSHOT_MISMATCH: "asset_snapshot_mismatch",
|
|
997
999
|
/** Mux answered an asset fetch with a different asset than the one requested. Facts: `assetId`, `returnedAssetId`. */
|
|
@@ -1052,6 +1054,7 @@ var MUX_AI_ERROR_CATALOG = {
|
|
|
1052
1054
|
[MUX_AI_ERROR_CODES.CAPTION_TRACK_LANGUAGE_MISSING]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
1053
1055
|
// The track may exist, so a step retry could duplicate it; the job stays retryable.
|
|
1054
1056
|
[MUX_AI_ERROR_CODES.TRACK_ID_MISSING]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO },
|
|
1057
|
+
[MUX_AI_ERROR_CODES.CAPTION_TRACK_ID_MISSING]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO },
|
|
1055
1058
|
[MUX_AI_ERROR_CODES.ASSET_ID_MISMATCH]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO },
|
|
1056
1059
|
// Model calls.
|
|
1057
1060
|
[MUX_AI_ERROR_CODES.CONTENT_POLICY_BLOCKED]: { type: MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER },
|
|
@@ -1259,6 +1262,25 @@ function scrubDetail(detail, context) {
|
|
|
1259
1262
|
console.warn(`[@mux/ai] Suppressed suspected prompt leak in error detail${context ? ` (context: ${context})` : ""} (reason: ${leakReason}).`);
|
|
1260
1263
|
return "Upstream error details suppressed by safety filter";
|
|
1261
1264
|
}
|
|
1265
|
+
function wrapError(error, message, facts) {
|
|
1266
|
+
if (MuxAiError.is(error)) {
|
|
1267
|
+
if (facts) {
|
|
1268
|
+
Object.assign(error, { facts: { ...facts, ...error.facts } });
|
|
1269
|
+
}
|
|
1270
|
+
throw error;
|
|
1271
|
+
}
|
|
1272
|
+
const wrapped = new MuxAiError(`${message}: ${scrubDetail(extractErrorDetail(error), message)}`, {
|
|
1273
|
+
type: MUX_AI_ERROR_TYPES.SERVER_ERROR,
|
|
1274
|
+
source: MUX_AI_ERROR_SOURCES.INTERNAL,
|
|
1275
|
+
facts,
|
|
1276
|
+
cause: error
|
|
1277
|
+
});
|
|
1278
|
+
const usage = getErrorTokenUsage(error);
|
|
1279
|
+
if (usage) {
|
|
1280
|
+
wrapped.usage = usage;
|
|
1281
|
+
}
|
|
1282
|
+
throw wrapped;
|
|
1283
|
+
}
|
|
1262
1284
|
|
|
1263
1285
|
// src/lib/legacy-mux-ai-error.ts
|
|
1264
1286
|
function legacySource(type) {
|
|
@@ -1860,35 +1882,60 @@ function chunkText(text, strategy) {
|
|
|
1860
1882
|
function hasWorkflowScopeBoundaries(scope) {
|
|
1861
1883
|
return scope?.startTime !== void 0 || scope?.endTime !== void 0;
|
|
1862
1884
|
}
|
|
1863
|
-
function
|
|
1885
|
+
function invalidScopeError(message, facts, inputs) {
|
|
1886
|
+
return new MuxAiError(message, {
|
|
1887
|
+
code: MUX_AI_ERROR_CODES.INVALID_SCOPE,
|
|
1888
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
1889
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
1890
|
+
facts: { ...facts, inputs }
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
function boundFact(value) {
|
|
1894
|
+
return Number.isFinite(value) ? value : String(value);
|
|
1895
|
+
}
|
|
1896
|
+
function resolveWorkflowScope(scope, assetDurationSeconds, options = {}) {
|
|
1897
|
+
const classified = options.classifiedErrors === true;
|
|
1864
1898
|
if (assetDurationSeconds === void 0 || !Number.isFinite(assetDurationSeconds) || assetDurationSeconds <= 0) {
|
|
1899
|
+
if (classified) {
|
|
1900
|
+
throw new MuxAiError("Asset has no valid duration.", {
|
|
1901
|
+
code: MUX_AI_ERROR_CODES.ASSET_DURATION_UNAVAILABLE,
|
|
1902
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
1903
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
1904
|
+
facts: { ...options.assetId && { assetId: options.assetId } }
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1865
1907
|
throw new LegacyMuxAiError("Asset has no valid duration.", { type: "validation_error" });
|
|
1866
1908
|
}
|
|
1867
1909
|
const startTime = scope?.startTime ?? 0;
|
|
1868
1910
|
const endTime = scope?.endTime ?? assetDurationSeconds;
|
|
1869
1911
|
if (!Number.isFinite(startTime) || startTime < 0) {
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
{
|
|
1873
|
-
|
|
1912
|
+
const message = `scope.startTime must be a finite, non-negative number (received ${startTime}).`;
|
|
1913
|
+
if (classified) {
|
|
1914
|
+
throw invalidScopeError(message, { reason: "invalid_start_time", received: boundFact(startTime) }, ["scope.startTime"]);
|
|
1915
|
+
}
|
|
1916
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
1874
1917
|
}
|
|
1875
1918
|
if (!Number.isFinite(endTime) || endTime < 0) {
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
{
|
|
1879
|
-
|
|
1919
|
+
const message = `scope.endTime must be a finite, non-negative number (received ${endTime}).`;
|
|
1920
|
+
if (classified) {
|
|
1921
|
+
throw invalidScopeError(message, { reason: "invalid_end_time", received: boundFact(endTime) }, ["scope.endTime"]);
|
|
1922
|
+
}
|
|
1923
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
1880
1924
|
}
|
|
1881
1925
|
if (endTime > assetDurationSeconds) {
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
{
|
|
1885
|
-
|
|
1926
|
+
const message = `scope.endTime (${endTime}) cannot exceed the asset duration (${assetDurationSeconds}).`;
|
|
1927
|
+
if (classified) {
|
|
1928
|
+
throw invalidScopeError(message, { reason: "exceeds_duration", endTime, assetDurationSeconds }, ["scope.endTime"]);
|
|
1929
|
+
}
|
|
1930
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
1886
1931
|
}
|
|
1887
1932
|
if (startTime >= endTime) {
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1933
|
+
const message = `scope.startTime (${startTime}) must be less than scope.endTime (${endTime}).`;
|
|
1934
|
+
if (classified) {
|
|
1935
|
+
const inputs = scope?.endTime === void 0 ? ["scope.startTime"] : ["scope.startTime", "scope.endTime"];
|
|
1936
|
+
throw invalidScopeError(message, { reason: "empty_range", startTime, endTime }, inputs);
|
|
1937
|
+
}
|
|
1938
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
1892
1939
|
}
|
|
1893
1940
|
return { startTime, endTime };
|
|
1894
1941
|
}
|
|
@@ -1939,6 +1986,57 @@ async function getThumbnailUrls(playbackId, duration, options = {}) {
|
|
|
1939
1986
|
return Promise.all(urlPromises);
|
|
1940
1987
|
}
|
|
1941
1988
|
|
|
1989
|
+
// src/lib/dependency-error.ts
|
|
1990
|
+
function classifyDependencyFailure(init) {
|
|
1991
|
+
const { call, status, requestId, facts, timedOut } = init;
|
|
1992
|
+
const transient = timedOut === true || isTransientStatus(status);
|
|
1993
|
+
let source;
|
|
1994
|
+
let type;
|
|
1995
|
+
if (transient) {
|
|
1996
|
+
source = MUX_AI_ERROR_SOURCES.UPSTREAM;
|
|
1997
|
+
type = timedOut || status === 408 ? MUX_AI_ERROR_TYPES.TIMEOUT_ERROR : status === 429 ? MUX_AI_ERROR_TYPES.CAPACITY_ERROR : MUX_AI_ERROR_TYPES.PROCESSING_ERROR;
|
|
1998
|
+
} else {
|
|
1999
|
+
source = status === 404 ? init.notFoundSource ?? MUX_AI_ERROR_SOURCES.INTERNAL : status === 401 || status === 403 ? init.authSource ?? MUX_AI_ERROR_SOURCES.INTERNAL : MUX_AI_ERROR_SOURCES.INTERNAL;
|
|
2000
|
+
type = source === MUX_AI_ERROR_SOURCES.INTERNAL ? MUX_AI_ERROR_TYPES.SERVER_ERROR : MUX_AI_ERROR_TYPES.VALIDATION_ERROR;
|
|
2001
|
+
}
|
|
2002
|
+
const authFailure = !transient && (status === 401 || status === 403);
|
|
2003
|
+
return {
|
|
2004
|
+
type,
|
|
2005
|
+
source,
|
|
2006
|
+
facts: {
|
|
2007
|
+
call,
|
|
2008
|
+
...status !== void 0 && { status },
|
|
2009
|
+
...requestId && { requestId },
|
|
2010
|
+
...authFailure && init.authInputs?.length && { inputs: [...init.authInputs] },
|
|
2011
|
+
...facts
|
|
2012
|
+
},
|
|
2013
|
+
// Set here, not left to the default: only the call site knows a missing status
|
|
2014
|
+
// means no response (transient), rather than a failure the dependency reported.
|
|
2015
|
+
// A non-idempotent call may have taken effect only with no response or a 5xx;
|
|
2016
|
+
// a 408, 425 or 429 means it wasn't processed, so retrying stays safe.
|
|
2017
|
+
transient: init.transient ?? (init.idempotent === false && (status === void 0 || status >= 500) ? false : transient),
|
|
2018
|
+
...init.retryable !== void 0 && { retryable: init.retryable }
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
function dependencyError(message, init) {
|
|
2022
|
+
const { source, ...classification } = classifyDependencyFailure(init);
|
|
2023
|
+
const where = { source, dependency: init.dependency };
|
|
2024
|
+
return new MuxAiError(message, { ...classification, ...where, cause: init.cause });
|
|
2025
|
+
}
|
|
2026
|
+
function requestIdOf(headers) {
|
|
2027
|
+
if (!headers || typeof headers !== "object") {
|
|
2028
|
+
return void 0;
|
|
2029
|
+
}
|
|
2030
|
+
const names = ["x-request-id", "x-amz-request-id", "request-id"];
|
|
2031
|
+
for (const name of names) {
|
|
2032
|
+
const value = typeof headers.get === "function" ? headers.get(name) : headers[name];
|
|
2033
|
+
if (typeof value === "string" && value) {
|
|
2034
|
+
return value;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
return void 0;
|
|
2038
|
+
}
|
|
2039
|
+
|
|
1942
2040
|
// src/lib/language-codes.ts
|
|
1943
2041
|
var ISO639_1_TO_3 = {
|
|
1944
2042
|
// Major world languages
|
|
@@ -2098,6 +2196,17 @@ var MuxApiErrorSchema = z2.object({
|
|
|
2098
2196
|
error: z2.object({ type: MuxTokenSchema })
|
|
2099
2197
|
})
|
|
2100
2198
|
});
|
|
2199
|
+
function muxVideoError(message, init) {
|
|
2200
|
+
return dependencyError(message, {
|
|
2201
|
+
...init,
|
|
2202
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
2203
|
+
notFoundSource: MUX_AI_ERROR_SOURCES.ASSET,
|
|
2204
|
+
authSource: MUX_AI_ERROR_SOURCES.ACCOUNT,
|
|
2205
|
+
authInputs: ["credentials"],
|
|
2206
|
+
// A create may have taken effect despite the failure; retrying could duplicate the track.
|
|
2207
|
+
idempotent: init.call !== "create_track"
|
|
2208
|
+
});
|
|
2209
|
+
}
|
|
2101
2210
|
|
|
2102
2211
|
// src/lib/mux-assets.ts
|
|
2103
2212
|
function isAudioOnlyAsset(asset) {
|
|
@@ -2504,11 +2613,7 @@ async function fetchTranscriptDataForUrl(transcriptUrl, options = {}) {
|
|
|
2504
2613
|
"use step";
|
|
2505
2614
|
const { cleanTranscript = true, scope } = options;
|
|
2506
2615
|
try {
|
|
2507
|
-
const
|
|
2508
|
-
if (!response.ok) {
|
|
2509
|
-
throw new Error(`Failed to fetch transcript (HTTP ${response.status})`);
|
|
2510
|
-
}
|
|
2511
|
-
const rawVtt = await response.text();
|
|
2616
|
+
const rawVtt = options.classifiedErrors ? await fetchTranscriptVtt(transcriptUrl) : await fetchTranscriptVttLegacy(transcriptUrl);
|
|
2512
2617
|
const effectiveScope = hasWorkflowScopeBoundaries(scope) ? scope : void 0;
|
|
2513
2618
|
const scopedVtt = filterVttByScope(rawVtt, effectiveScope);
|
|
2514
2619
|
const transcriptText = cleanTranscript ? extractTextFromVTT(scopedVtt) : scopedVtt;
|
|
@@ -2521,24 +2626,69 @@ async function fetchTranscriptDataForUrl(transcriptUrl, options = {}) {
|
|
|
2521
2626
|
}
|
|
2522
2627
|
return { transcriptText };
|
|
2523
2628
|
} catch (error) {
|
|
2629
|
+
if (options.classifiedErrors) {
|
|
2630
|
+
wrapError(error, "Failed to fetch transcript");
|
|
2631
|
+
}
|
|
2524
2632
|
legacyWrapError(error, "Failed to fetch transcript");
|
|
2525
2633
|
}
|
|
2526
2634
|
}
|
|
2635
|
+
async function fetchTranscriptVttLegacy(transcriptUrl) {
|
|
2636
|
+
const response = await fetch(transcriptUrl);
|
|
2637
|
+
if (!response.ok) {
|
|
2638
|
+
throw new Error(`Failed to fetch transcript (HTTP ${response.status})`);
|
|
2639
|
+
}
|
|
2640
|
+
return response.text();
|
|
2641
|
+
}
|
|
2642
|
+
async function fetchTranscriptVtt(transcriptUrl) {
|
|
2643
|
+
let response;
|
|
2644
|
+
try {
|
|
2645
|
+
response = await fetch(transcriptUrl);
|
|
2646
|
+
} catch (error) {
|
|
2647
|
+
throw muxVideoError("Failed to fetch transcript from Mux", { call: "fetch_transcript", cause: error });
|
|
2648
|
+
}
|
|
2649
|
+
if (!response.ok) {
|
|
2650
|
+
throw muxVideoError(`Failed to fetch transcript from Mux (HTTP ${response.status})`, {
|
|
2651
|
+
call: "fetch_transcript",
|
|
2652
|
+
status: response.status,
|
|
2653
|
+
requestId: requestIdOf(response.headers)
|
|
2654
|
+
});
|
|
2655
|
+
}
|
|
2656
|
+
try {
|
|
2657
|
+
return await response.text();
|
|
2658
|
+
} catch (error) {
|
|
2659
|
+
throw muxVideoError("Failed to read transcript from Mux", { call: "fetch_transcript", cause: error });
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2527
2662
|
async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
2528
|
-
const { required = false, languageCode, cleanTranscript, scope, shouldSign, credentials } = options;
|
|
2663
|
+
const { required = false, languageCode, cleanTranscript, scope, shouldSign, credentials, classifiedErrors } = options;
|
|
2529
2664
|
const track = findCaptionTrack(asset, languageCode);
|
|
2530
2665
|
if (!track) {
|
|
2531
2666
|
if (required) {
|
|
2532
|
-
const availableLanguages = getReadyTextTracks(asset).map((t) => t.language_code).filter(
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2667
|
+
const availableLanguages = getReadyTextTracks(asset).map((t) => t.language_code).filter((code) => !!code);
|
|
2668
|
+
const message = `No caption track found${languageCode ? ` for language ${languageCode}` : ""}. Available languages: ${availableLanguages.join(", ") || "none"}.`;
|
|
2669
|
+
if (classifiedErrors) {
|
|
2670
|
+
throw new MuxAiError(message, {
|
|
2671
|
+
code: MUX_AI_ERROR_CODES.CAPTION_TRACK_NOT_FOUND,
|
|
2672
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
2673
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
2674
|
+
facts: { assetId: asset.id, ...languageCode && { languageCode }, availableLanguages }
|
|
2675
|
+
});
|
|
2676
|
+
}
|
|
2677
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
2537
2678
|
}
|
|
2538
2679
|
return { transcriptText: "" };
|
|
2539
2680
|
}
|
|
2540
2681
|
if (!track.id) {
|
|
2541
2682
|
if (required) {
|
|
2683
|
+
if (classifiedErrors) {
|
|
2684
|
+
throw new MuxAiError("Transcript track is missing an id.", {
|
|
2685
|
+
code: MUX_AI_ERROR_CODES.CAPTION_TRACK_ID_MISSING,
|
|
2686
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
2687
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
2688
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
2689
|
+
facts: { assetId: asset.id, ...track.language_code && { languageCode: track.language_code } }
|
|
2690
|
+
});
|
|
2691
|
+
}
|
|
2542
2692
|
throw new LegacyMuxAiError("Transcript track is missing an id.", { type: "validation_error" });
|
|
2543
2693
|
}
|
|
2544
2694
|
return { transcriptText: "", track };
|
|
@@ -2546,7 +2696,7 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
|
2546
2696
|
const transcriptUrl = await buildTranscriptUrl(playbackId, track.id, shouldSign, credentials);
|
|
2547
2697
|
let result;
|
|
2548
2698
|
try {
|
|
2549
|
-
result = await fetchTranscriptDataForUrl(transcriptUrl, { cleanTranscript, scope });
|
|
2699
|
+
result = await fetchTranscriptDataForUrl(transcriptUrl, { cleanTranscript, scope, classifiedErrors });
|
|
2550
2700
|
} catch (error) {
|
|
2551
2701
|
if (required) {
|
|
2552
2702
|
throw error;
|
|
@@ -2559,8 +2709,23 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
|
2559
2709
|
}
|
|
2560
2710
|
switch (result.emptyReason) {
|
|
2561
2711
|
case "no_scoped_cues":
|
|
2712
|
+
if (classifiedErrors) {
|
|
2713
|
+
throw invalidScopeError(
|
|
2714
|
+
"Transcript has no cues in the requested scope.",
|
|
2715
|
+
{ reason: "no_transcript", trackId: track.id, ...scope?.startTime !== void 0 && { startTime: scope.startTime }, ...scope?.endTime !== void 0 && { endTime: scope.endTime } },
|
|
2716
|
+
["scope"]
|
|
2717
|
+
);
|
|
2718
|
+
}
|
|
2562
2719
|
throw new LegacyMuxAiError("Transcript has no cues in the requested scope.", { type: "validation_error" });
|
|
2563
2720
|
case "empty_body":
|
|
2721
|
+
if (classifiedErrors) {
|
|
2722
|
+
throw new MuxAiError("Transcript is empty.", {
|
|
2723
|
+
code: MUX_AI_ERROR_CODES.TRANSCRIPT_EMPTY,
|
|
2724
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
2725
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
2726
|
+
facts: { assetId: asset.id, trackId: track.id }
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2564
2729
|
throw new LegacyMuxAiError("Transcript is empty.", { type: "validation_error" });
|
|
2565
2730
|
}
|
|
2566
2731
|
}
|