@mux/ai 0.58.0 → 0.59.1-canary.90
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/README.md +1 -1
- package/dist/{index-bdbFMlhA.d.ts → index-BPZEKSNp.d.ts} +467 -11
- package/dist/{index-DiuqBw6I.d.ts → index-CHA2jigS.d.ts} +1 -1
- package/dist/index.d.ts +186 -56
- package/dist/index.js +1243 -537
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.d.ts +2 -2
- package/dist/primitives/index.js +332 -38
- package/dist/primitives/index.js.map +1 -1
- package/dist/{transcripts-Brw74qlV.d.ts → transcripts-DuNI058z.d.ts} +1 -1
- package/dist/workflows/index.d.ts +3 -2
- package/dist/workflows/index.js +627 -186
- package/dist/workflows/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -5,208 +5,7 @@ var __export = (target, all) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// package.json
|
|
8
|
-
var version = "0.
|
|
9
|
-
|
|
10
|
-
// src/lib/language-codes.ts
|
|
11
|
-
var ISO639_1_TO_3 = {
|
|
12
|
-
// Major world languages
|
|
13
|
-
en: "eng",
|
|
14
|
-
// English
|
|
15
|
-
es: "spa",
|
|
16
|
-
// Spanish
|
|
17
|
-
fr: "fra",
|
|
18
|
-
// French
|
|
19
|
-
de: "deu",
|
|
20
|
-
// German
|
|
21
|
-
it: "ita",
|
|
22
|
-
// Italian
|
|
23
|
-
pt: "por",
|
|
24
|
-
// Portuguese
|
|
25
|
-
ru: "rus",
|
|
26
|
-
// Russian
|
|
27
|
-
zh: "zho",
|
|
28
|
-
// Chinese
|
|
29
|
-
ja: "jpn",
|
|
30
|
-
// Japanese
|
|
31
|
-
ko: "kor",
|
|
32
|
-
// Korean
|
|
33
|
-
ar: "ara",
|
|
34
|
-
// Arabic
|
|
35
|
-
hi: "hin",
|
|
36
|
-
// Hindi
|
|
37
|
-
// European languages
|
|
38
|
-
nl: "nld",
|
|
39
|
-
// Dutch
|
|
40
|
-
pl: "pol",
|
|
41
|
-
// Polish
|
|
42
|
-
sv: "swe",
|
|
43
|
-
// Swedish
|
|
44
|
-
da: "dan",
|
|
45
|
-
// Danish
|
|
46
|
-
no: "nor",
|
|
47
|
-
// Norwegian
|
|
48
|
-
fi: "fin",
|
|
49
|
-
// Finnish
|
|
50
|
-
el: "ell",
|
|
51
|
-
// Greek
|
|
52
|
-
cs: "ces",
|
|
53
|
-
// Czech
|
|
54
|
-
hu: "hun",
|
|
55
|
-
// Hungarian
|
|
56
|
-
ro: "ron",
|
|
57
|
-
// Romanian
|
|
58
|
-
bg: "bul",
|
|
59
|
-
// Bulgarian
|
|
60
|
-
hr: "hrv",
|
|
61
|
-
// Croatian
|
|
62
|
-
sk: "slk",
|
|
63
|
-
// Slovak
|
|
64
|
-
sl: "slv",
|
|
65
|
-
// Slovenian
|
|
66
|
-
uk: "ukr",
|
|
67
|
-
// Ukrainian
|
|
68
|
-
tr: "tur",
|
|
69
|
-
// Turkish
|
|
70
|
-
// Asian languages
|
|
71
|
-
th: "tha",
|
|
72
|
-
// Thai
|
|
73
|
-
vi: "vie",
|
|
74
|
-
// Vietnamese
|
|
75
|
-
id: "ind",
|
|
76
|
-
// Indonesian
|
|
77
|
-
ms: "msa",
|
|
78
|
-
// Malay
|
|
79
|
-
tl: "tgl",
|
|
80
|
-
// Tagalog/Filipino
|
|
81
|
-
// Other languages
|
|
82
|
-
he: "heb",
|
|
83
|
-
// Hebrew
|
|
84
|
-
fa: "fas",
|
|
85
|
-
// Persian/Farsi
|
|
86
|
-
bn: "ben",
|
|
87
|
-
// Bengali
|
|
88
|
-
ta: "tam",
|
|
89
|
-
// Tamil
|
|
90
|
-
te: "tel",
|
|
91
|
-
// Telugu
|
|
92
|
-
mr: "mar",
|
|
93
|
-
// Marathi
|
|
94
|
-
gu: "guj",
|
|
95
|
-
// Gujarati
|
|
96
|
-
kn: "kan",
|
|
97
|
-
// Kannada
|
|
98
|
-
ml: "mal",
|
|
99
|
-
// Malayalam
|
|
100
|
-
pa: "pan",
|
|
101
|
-
// Punjabi
|
|
102
|
-
ur: "urd",
|
|
103
|
-
// Urdu
|
|
104
|
-
sw: "swa",
|
|
105
|
-
// Swahili
|
|
106
|
-
af: "afr",
|
|
107
|
-
// Afrikaans
|
|
108
|
-
ca: "cat",
|
|
109
|
-
// Catalan
|
|
110
|
-
eu: "eus",
|
|
111
|
-
// Basque
|
|
112
|
-
gl: "glg",
|
|
113
|
-
// Galician
|
|
114
|
-
is: "isl",
|
|
115
|
-
// Icelandic
|
|
116
|
-
et: "est",
|
|
117
|
-
// Estonian
|
|
118
|
-
lv: "lav",
|
|
119
|
-
// Latvian
|
|
120
|
-
lt: "lit",
|
|
121
|
-
// Lithuanian
|
|
122
|
-
as: "asm",
|
|
123
|
-
az: "aze",
|
|
124
|
-
be: "bel",
|
|
125
|
-
bs: "bos",
|
|
126
|
-
cy: "cym",
|
|
127
|
-
ga: "gle",
|
|
128
|
-
ha: "hau",
|
|
129
|
-
hy: "hye",
|
|
130
|
-
jv: "jav",
|
|
131
|
-
ka: "kat",
|
|
132
|
-
kk: "kaz",
|
|
133
|
-
ky: "kir",
|
|
134
|
-
lb: "ltz",
|
|
135
|
-
ln: "lin",
|
|
136
|
-
mi: "mri",
|
|
137
|
-
mk: "mkd",
|
|
138
|
-
mn: "mon",
|
|
139
|
-
mt: "mlt",
|
|
140
|
-
my: "mya",
|
|
141
|
-
ne: "nep",
|
|
142
|
-
ny: "nya",
|
|
143
|
-
oc: "oci",
|
|
144
|
-
or: "ori",
|
|
145
|
-
ps: "pus",
|
|
146
|
-
sd: "snd",
|
|
147
|
-
so: "som",
|
|
148
|
-
sr: "srp",
|
|
149
|
-
tg: "tgk",
|
|
150
|
-
uz: "uzb",
|
|
151
|
-
yo: "yor"
|
|
152
|
-
};
|
|
153
|
-
var ISO639_3_TO_1 = Object.fromEntries(
|
|
154
|
-
Object.entries(ISO639_1_TO_3).map(([iso1, iso3]) => [iso3, iso1])
|
|
155
|
-
);
|
|
156
|
-
function toISO639_3(code) {
|
|
157
|
-
const normalized = code.toLowerCase().trim();
|
|
158
|
-
if (normalized.length === 3) {
|
|
159
|
-
return normalized;
|
|
160
|
-
}
|
|
161
|
-
return ISO639_1_TO_3[normalized] ?? normalized;
|
|
162
|
-
}
|
|
163
|
-
function toISO639_1(code) {
|
|
164
|
-
const normalized = code.toLowerCase().trim();
|
|
165
|
-
if (normalized.length === 2) {
|
|
166
|
-
return normalized;
|
|
167
|
-
}
|
|
168
|
-
return Object.prototype.hasOwnProperty.call(ISO639_3_TO_1, normalized) ? ISO639_3_TO_1[normalized] : normalized;
|
|
169
|
-
}
|
|
170
|
-
function getLanguageCodePair(code) {
|
|
171
|
-
const normalized = code.toLowerCase().trim();
|
|
172
|
-
if (normalized.length === 2) {
|
|
173
|
-
return {
|
|
174
|
-
iso639_1: normalized,
|
|
175
|
-
iso639_3: toISO639_3(normalized)
|
|
176
|
-
};
|
|
177
|
-
} else if (normalized.length === 3) {
|
|
178
|
-
return {
|
|
179
|
-
iso639_1: toISO639_1(normalized),
|
|
180
|
-
iso639_3: normalized
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
iso639_1: normalized,
|
|
185
|
-
iso639_3: normalized
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
function isValidISO639_1(code) {
|
|
189
|
-
return code.length === 2 && code.toLowerCase() in ISO639_1_TO_3;
|
|
190
|
-
}
|
|
191
|
-
function isValidISO639_3(code) {
|
|
192
|
-
return code.length === 3 && code.toLowerCase() in ISO639_3_TO_1;
|
|
193
|
-
}
|
|
194
|
-
var UNDETERMINED_LANGUAGE_CODES = /* @__PURE__ */ new Set(["und", "mul", "mis", "zxx"]);
|
|
195
|
-
function isUndeterminedLanguageCode(code) {
|
|
196
|
-
return UNDETERMINED_LANGUAGE_CODES.has(code.toLowerCase().trim());
|
|
197
|
-
}
|
|
198
|
-
function getLanguageName(code) {
|
|
199
|
-
if (isUndeterminedLanguageCode(code)) {
|
|
200
|
-
return void 0;
|
|
201
|
-
}
|
|
202
|
-
const iso639_1 = toISO639_1(code);
|
|
203
|
-
try {
|
|
204
|
-
const displayNames = new Intl.DisplayNames(["en"], { type: "language" });
|
|
205
|
-
return displayNames.of(iso639_1) ?? code.toUpperCase();
|
|
206
|
-
} catch {
|
|
207
|
-
return code.toUpperCase();
|
|
208
|
-
}
|
|
209
|
-
}
|
|
8
|
+
var version = "0.59.1-canary.90";
|
|
210
9
|
|
|
211
10
|
// node_modules/@workflow/serde/dist/index.js
|
|
212
11
|
var WORKFLOW_SERIALIZE = /* @__PURE__ */ Symbol.for("workflow-serialize");
|
|
@@ -566,8 +365,8 @@ var INVISIBLE_CHARACTERS_PATTERN = new RegExp(
|
|
|
566
365
|
`[${INVISIBLE_CODE_POINTS.map((cp) => `\\u${cp.toString(16).padStart(4, "0").toUpperCase()}`).join("")}]`,
|
|
567
366
|
"g"
|
|
568
367
|
);
|
|
569
|
-
function normalizeUntrustedUnicode(
|
|
570
|
-
return
|
|
368
|
+
function normalizeUntrustedUnicode(text2) {
|
|
369
|
+
return text2.normalize("NFKC").replace(INVISIBLE_CHARACTERS_PATTERN, "");
|
|
571
370
|
}
|
|
572
371
|
var BASE64_RUN_PATTERN = /[\w+/=-]{80,}/;
|
|
573
372
|
var HEX_RUN_PATTERN = /[0-9a-f]{65,}/i;
|
|
@@ -577,11 +376,11 @@ if (NORMALISED_SYSTEM_PROMPT_CANARY.length < 16) {
|
|
|
577
376
|
"MUX_AI_PROMPT_CANARY normalises to fewer than 16 characters after NFKC + invisibles strip. Canaries composed largely of fullwidth ASCII, invisible / bidi-control code points, or other characters that collapse under Unicode normalisation are not usable as tripwires \u2014 they would produce false-positive matches against legitimate model output. Use a high-entropy ASCII-leaning value."
|
|
578
377
|
);
|
|
579
378
|
}
|
|
580
|
-
function detectLeakReason(
|
|
581
|
-
if (!
|
|
379
|
+
function detectLeakReason(text2) {
|
|
380
|
+
if (!text2) {
|
|
582
381
|
return null;
|
|
583
382
|
}
|
|
584
|
-
const normalised = normalizeUntrustedUnicode(
|
|
383
|
+
const normalised = normalizeUntrustedUnicode(text2);
|
|
585
384
|
if (normalised.includes(NORMALISED_SYSTEM_PROMPT_CANARY)) {
|
|
586
385
|
return "canary";
|
|
587
386
|
}
|
|
@@ -593,16 +392,16 @@ function detectLeakReason(text) {
|
|
|
593
392
|
}
|
|
594
393
|
return null;
|
|
595
394
|
}
|
|
596
|
-
function scrubFreeTextField(
|
|
597
|
-
if (!
|
|
598
|
-
return { text:
|
|
395
|
+
function scrubFreeTextField(text2, context) {
|
|
396
|
+
if (!text2) {
|
|
397
|
+
return { text: text2 ?? "", leaked: false, reason: null };
|
|
599
398
|
}
|
|
600
|
-
const reason = detectLeakReason(
|
|
399
|
+
const reason = detectLeakReason(text2);
|
|
601
400
|
if (reason !== null) {
|
|
602
401
|
console.warn(`[@mux/ai] Suppressed suspected prompt leak in ${context} (reason: ${reason}).`);
|
|
603
402
|
return { text: "", leaked: true, reason };
|
|
604
403
|
}
|
|
605
|
-
return { text, leaked: false, reason: null };
|
|
404
|
+
return { text: text2, leaked: false, reason: null };
|
|
606
405
|
}
|
|
607
406
|
function detectUnexpectedKeys(raw, expectedKeys) {
|
|
608
407
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
@@ -623,8 +422,8 @@ function detectUnexpectedKeysFromRawText(rawText, expectedKeys) {
|
|
|
623
422
|
}
|
|
624
423
|
function createSafetyReporter() {
|
|
625
424
|
const scrubbedFields = [];
|
|
626
|
-
const scrubDetailed = (
|
|
627
|
-
const result = scrubFreeTextField(
|
|
425
|
+
const scrubDetailed = (text2, field) => {
|
|
426
|
+
const result = scrubFreeTextField(text2, field);
|
|
628
427
|
if (result.leaked && result.reason !== null) {
|
|
629
428
|
scrubbedFields.push({ field, reason: result.reason });
|
|
630
429
|
}
|
|
@@ -650,7 +449,7 @@ function createSafetyReporter() {
|
|
|
650
449
|
};
|
|
651
450
|
return {
|
|
652
451
|
scrubDetailed,
|
|
653
|
-
scrub: (
|
|
452
|
+
scrub: (text2, field) => scrubDetailed(text2, field).text,
|
|
654
453
|
recordUnexpectedKeys,
|
|
655
454
|
record,
|
|
656
455
|
report: () => ({
|
|
@@ -675,80 +474,735 @@ var TOKEN_USAGE_FIELDS = [
|
|
|
675
474
|
function isDefinedTokenUsageValue(value) {
|
|
676
475
|
return typeof value === "number";
|
|
677
476
|
}
|
|
678
|
-
function aggregateTokenUsage(usages) {
|
|
679
|
-
return TOKEN_USAGE_FIELDS.reduce((aggregate, field) => {
|
|
680
|
-
const values = usages.map((usage) => usage[field]).filter(isDefinedTokenUsageValue);
|
|
681
|
-
if (values.length > 0) {
|
|
682
|
-
aggregate[field] = values.reduce((total, value) => total + value, 0);
|
|
683
|
-
}
|
|
684
|
-
return aggregate;
|
|
685
|
-
}, {});
|
|
477
|
+
function aggregateTokenUsage(usages) {
|
|
478
|
+
return TOKEN_USAGE_FIELDS.reduce((aggregate, field) => {
|
|
479
|
+
const values = usages.map((usage) => usage[field]).filter(isDefinedTokenUsageValue);
|
|
480
|
+
if (values.length > 0) {
|
|
481
|
+
aggregate[field] = values.reduce((total, value) => total + value, 0);
|
|
482
|
+
}
|
|
483
|
+
return aggregate;
|
|
484
|
+
}, {});
|
|
485
|
+
}
|
|
486
|
+
function getErrorTokenUsage(error) {
|
|
487
|
+
if (typeof error !== "object" || error === null) {
|
|
488
|
+
return void 0;
|
|
489
|
+
}
|
|
490
|
+
const usage = error.usage;
|
|
491
|
+
if (typeof usage !== "object" || usage === null) {
|
|
492
|
+
return void 0;
|
|
493
|
+
}
|
|
494
|
+
const source = usage;
|
|
495
|
+
const extracted = {};
|
|
496
|
+
for (const field of TOKEN_USAGE_FIELDS) {
|
|
497
|
+
const value = source[field];
|
|
498
|
+
if (typeof value === "number") {
|
|
499
|
+
extracted[field] = value;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (extracted.reasoningTokens === void 0) {
|
|
503
|
+
const reasoningTokens = source.outputTokenDetails?.reasoningTokens;
|
|
504
|
+
if (typeof reasoningTokens === "number") {
|
|
505
|
+
extracted.reasoningTokens = reasoningTokens;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (extracted.cachedInputTokens === void 0) {
|
|
509
|
+
const cacheReadTokens = source.inputTokenDetails?.cacheReadTokens;
|
|
510
|
+
if (typeof cacheReadTokens === "number") {
|
|
511
|
+
extracted.cachedInputTokens = cacheReadTokens;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (extracted.cacheWriteTokens === void 0) {
|
|
515
|
+
const cacheWriteTokens = source.inputTokenDetails?.cacheWriteTokens;
|
|
516
|
+
if (typeof cacheWriteTokens === "number") {
|
|
517
|
+
extracted.cacheWriteTokens = cacheWriteTokens;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return Object.keys(extracted).length > 0 ? extracted : void 0;
|
|
521
|
+
}
|
|
522
|
+
function rethrowWithTokenUsage(error, collectedUsage) {
|
|
523
|
+
const usages = [...collectedUsage];
|
|
524
|
+
const errorUsage = getErrorTokenUsage(error);
|
|
525
|
+
if (errorUsage) {
|
|
526
|
+
usages.push(errorUsage);
|
|
527
|
+
}
|
|
528
|
+
if (usages.length > 0 && typeof error === "object" && error !== null) {
|
|
529
|
+
error.usage = aggregateTokenUsage(usages);
|
|
530
|
+
}
|
|
531
|
+
throw error;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// src/lib/mux-ai-error.ts
|
|
535
|
+
var MUX_AI_ERROR_TYPES = {
|
|
536
|
+
/** The request, the asset or the account can't be used as it is. */
|
|
537
|
+
VALIDATION_ERROR: "validation_error",
|
|
538
|
+
/** The work was attempted and failed. */
|
|
539
|
+
PROCESSING_ERROR: "processing_error",
|
|
540
|
+
/** The work didn't finish in time. */
|
|
541
|
+
TIMEOUT_ERROR: "timeout_error",
|
|
542
|
+
/** Content was refused by a content policy. */
|
|
543
|
+
CONTENT_POLICY_ERROR: "content_policy_error",
|
|
544
|
+
/** A service is rate limiting or over capacity. */
|
|
545
|
+
CAPACITY_ERROR: "capacity_error",
|
|
546
|
+
/** A fault in this code or its configuration. */
|
|
547
|
+
SERVER_ERROR: "server_error"
|
|
548
|
+
};
|
|
549
|
+
var MUX_AI_ERROR_TYPE_VALUES = Object.values(MUX_AI_ERROR_TYPES);
|
|
550
|
+
var MUX_AI_ERROR_SOURCES = {
|
|
551
|
+
/** The caller's input, e.g. a scope past the end of the asset. */
|
|
552
|
+
REQUEST: "request",
|
|
553
|
+
/** The Mux asset's state, e.g. no caption track in the requested language. */
|
|
554
|
+
ASSET: "asset",
|
|
555
|
+
/** The Mux account or environment, e.g. missing permissions. */
|
|
556
|
+
ACCOUNT: "account",
|
|
557
|
+
/** A remote service failed, e.g. the dubbing provider reported a failed dub. */
|
|
558
|
+
UPSTREAM: "upstream",
|
|
559
|
+
/** This code, or the configuration of the service running it, e.g. missing signing keys. */
|
|
560
|
+
INTERNAL: "internal"
|
|
561
|
+
};
|
|
562
|
+
var MUX_AI_ERROR_SOURCE_VALUES = Object.values(MUX_AI_ERROR_SOURCES);
|
|
563
|
+
var MUX_AI_ERROR_DEPENDENCIES = {
|
|
564
|
+
/** Mux Video: the API, stream and image delivery, and its static renditions and tracks. */
|
|
565
|
+
MUX_VIDEO: "mux_video",
|
|
566
|
+
/** Mux Data: its API, e.g. engagement data (heatmaps and hotspots). */
|
|
567
|
+
MUX_DATA: "mux_data",
|
|
568
|
+
/** A model or AI service provider, e.g. a language model API or the dubbing provider. */
|
|
569
|
+
AI_PROVIDER: "ai_provider",
|
|
570
|
+
/** Object storage the SDK writes to or reads from, e.g. an S3-compatible bucket. */
|
|
571
|
+
STORAGE: "storage"
|
|
572
|
+
};
|
|
573
|
+
var MUX_AI_ERROR_DEPENDENCY_VALUES = Object.values(MUX_AI_ERROR_DEPENDENCIES);
|
|
574
|
+
var MUX_AI_ERROR_CODES = {
|
|
575
|
+
/** 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. */
|
|
576
|
+
INVALID_SCOPE: "invalid_scope",
|
|
577
|
+
/** 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. */
|
|
578
|
+
TRACK_REPLACEMENT_BLOCKED: "track_replacement_blocked",
|
|
579
|
+
/** A numeric option is outside its allowed range. Facts: `parameter` (the caller's option name), `value`, `min`, `max`, and `integer` when it must be a whole number. */
|
|
580
|
+
PARAMETER_OUT_OF_RANGE: "parameter_out_of_range",
|
|
581
|
+
/** No ready caption track matches the requested track or language. Facts: `trackId` or `languageCode`, and what is available. */
|
|
582
|
+
CAPTION_TRACK_NOT_FOUND: "caption_track_not_found",
|
|
583
|
+
/** The asset has no public or signed playback ID (DRM-only assets included). */
|
|
584
|
+
PLAYBACK_ID_NOT_FOUND: "playback_id_not_found",
|
|
585
|
+
/** The transcript has no usable content. */
|
|
586
|
+
TRANSCRIPT_EMPTY: "transcript_empty",
|
|
587
|
+
/** The asset has no valid duration, so work that depends on it can't run. Facts: `assetId`. */
|
|
588
|
+
ASSET_DURATION_UNAVAILABLE: "asset_duration_unavailable",
|
|
589
|
+
/** Mux won't add an audio track to this asset. Facts: `reason` (`clip`, `live_stream`, `audio_only`). */
|
|
590
|
+
AUDIO_TRACK_UNSUPPORTED: "audio_track_unsupported",
|
|
591
|
+
/** The asset's existing static rendition can't be used as a source. Facts: `reason` (`unusable`, `too_large`) and the rendition's details. */
|
|
592
|
+
STATIC_RENDITION_UNSUPPORTED: "static_rendition_unsupported",
|
|
593
|
+
/** Signed playback needs signing keys the service running the SDK didn't provide. */
|
|
594
|
+
SIGNING_CREDENTIALS_MISSING: "signing_credentials_missing",
|
|
595
|
+
/** Storage is needed but the service running the SDK didn't configure it. */
|
|
596
|
+
STORAGE_NOT_CONFIGURED: "storage_not_configured",
|
|
597
|
+
/** The model provider refused the content. Facts: `reason` and `category`. */
|
|
598
|
+
CONTENT_POLICY_BLOCKED: "content_policy_blocked",
|
|
599
|
+
/** The model returned no output, or a required field was empty. Facts: `call`, `provider`, `model`, and `assetId` when there is one. */
|
|
600
|
+
MODEL_OUTPUT_MISSING: "model_output_missing",
|
|
601
|
+
/** The model's output breaks the expected shape or constraints (counts, allowed values, limits). Facts: `call`, `provider`, `model`, and `assetId` when there is one. */
|
|
602
|
+
MODEL_OUTPUT_INVALID: "model_output_invalid",
|
|
603
|
+
/** The model's output was withheld by the SDK's output safety filter (a suspected prompt leak). */
|
|
604
|
+
MODEL_OUTPUT_SUPPRESSED: "model_output_suppressed",
|
|
605
|
+
/** The model stopped early for a reason other than the length limit. */
|
|
606
|
+
MODEL_OUTPUT_INCOMPLETE: "model_output_incomplete",
|
|
607
|
+
/** The model hit the output length limit. */
|
|
608
|
+
MODEL_OUTPUT_TRUNCATED: "model_output_truncated",
|
|
609
|
+
/** Mux reported the static rendition a workflow needs as errored. */
|
|
610
|
+
STATIC_RENDITION_FAILED: "static_rendition_failed",
|
|
611
|
+
/** The dubbing provider doesn't support the requested language. Facts: `language` and `which` (`target` or `source`). */
|
|
612
|
+
DUBBING_LANGUAGE_UNSUPPORTED: "dubbing_language_unsupported",
|
|
613
|
+
/** The dubbing provider ran the dub and reported it failed. Facts: `providerError`, the provider's display text, when it gave one. */
|
|
614
|
+
DUBBING_FAILED: "dubbing_failed"
|
|
615
|
+
};
|
|
616
|
+
var MUX_AI_ERROR_CODE_VALUES = Object.values(MUX_AI_ERROR_CODES);
|
|
617
|
+
var MUX_AI_ERROR_CATALOG = {
|
|
618
|
+
// The caller's input.
|
|
619
|
+
[MUX_AI_ERROR_CODES.INVALID_SCOPE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
|
|
620
|
+
[MUX_AI_ERROR_CODES.TRACK_REPLACEMENT_BLOCKED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
|
|
621
|
+
[MUX_AI_ERROR_CODES.PARAMETER_OUT_OF_RANGE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
|
|
622
|
+
// The asset's state.
|
|
623
|
+
[MUX_AI_ERROR_CODES.CAPTION_TRACK_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
624
|
+
[MUX_AI_ERROR_CODES.PLAYBACK_ID_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
625
|
+
[MUX_AI_ERROR_CODES.ASSET_DURATION_UNAVAILABLE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
626
|
+
[MUX_AI_ERROR_CODES.TRANSCRIPT_EMPTY]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
627
|
+
[MUX_AI_ERROR_CODES.AUDIO_TRACK_UNSUPPORTED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
628
|
+
[MUX_AI_ERROR_CODES.STATIC_RENDITION_UNSUPPORTED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
629
|
+
// The configuration of the service running the SDK.
|
|
630
|
+
[MUX_AI_ERROR_CODES.SIGNING_CREDENTIALS_MISSING]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL },
|
|
631
|
+
[MUX_AI_ERROR_CODES.STORAGE_NOT_CONFIGURED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL },
|
|
632
|
+
// Model calls.
|
|
633
|
+
[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 },
|
|
634
|
+
// The model-output policies below keep what these failures did before classification
|
|
635
|
+
// (fatal, not resubmittable); sites that differed keep their old values explicitly.
|
|
636
|
+
// Whether they should be retried is an open follow-up, not decided here.
|
|
637
|
+
[MUX_AI_ERROR_CODES.MODEL_OUTPUT_MISSING]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER, transient: false, retryable: false },
|
|
638
|
+
[MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER, transient: false, retryable: false },
|
|
639
|
+
[MUX_AI_ERROR_CODES.MODEL_OUTPUT_SUPPRESSED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER, transient: false, retryable: false },
|
|
640
|
+
// Not transient: a step retry would repeat a full generation; the job can be resubmitted.
|
|
641
|
+
[MUX_AI_ERROR_CODES.MODEL_OUTPUT_INCOMPLETE]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER, transient: false },
|
|
642
|
+
[MUX_AI_ERROR_CODES.MODEL_OUTPUT_TRUNCATED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER },
|
|
643
|
+
// Mux Video.
|
|
644
|
+
// Reported by Mux: a step retry would find the same errored rendition, and resubmitting the same asset errors again.
|
|
645
|
+
[MUX_AI_ERROR_CODES.STATIC_RENDITION_FAILED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO, transient: false, retryable: false },
|
|
646
|
+
// Audio dubbing.
|
|
647
|
+
[MUX_AI_ERROR_CODES.DUBBING_LANGUAGE_UNSUPPORTED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER },
|
|
648
|
+
// Reported by the dubbing provider: a step retry would find the same failed dub.
|
|
649
|
+
[MUX_AI_ERROR_CODES.DUBBING_FAILED]: { type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR, source: MUX_AI_ERROR_SOURCES.UPSTREAM, dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER, transient: false }
|
|
650
|
+
};
|
|
651
|
+
function isTransientStatus(status) {
|
|
652
|
+
return status === void 0 || status === 408 || status === 425 || status === 429 || status >= 500;
|
|
653
|
+
}
|
|
654
|
+
function defaultTransient(source, facts = {}) {
|
|
655
|
+
return source === MUX_AI_ERROR_SOURCES.UPSTREAM && typeof facts.status === "number" && isTransientStatus(facts.status);
|
|
656
|
+
}
|
|
657
|
+
function defaultRetryable(type, source, transient) {
|
|
658
|
+
if (transient || type === MUX_AI_ERROR_TYPES.TIMEOUT_ERROR || type === MUX_AI_ERROR_TYPES.CAPACITY_ERROR) {
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
if (type === MUX_AI_ERROR_TYPES.VALIDATION_ERROR || type === MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR) {
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
return source === MUX_AI_ERROR_SOURCES.UPSTREAM;
|
|
665
|
+
}
|
|
666
|
+
var MAX_CAUSE_DEPTH = 3;
|
|
667
|
+
var MAX_CAUSE_MESSAGE_LENGTH = 500;
|
|
668
|
+
function statusOf(value) {
|
|
669
|
+
if (typeof value !== "object" || value === null) {
|
|
670
|
+
return void 0;
|
|
671
|
+
}
|
|
672
|
+
const { status, statusCode } = value;
|
|
673
|
+
const candidate = typeof status === "number" ? status : statusCode;
|
|
674
|
+
return typeof candidate === "number" && candidate >= 100 && candidate < 600 ? candidate : void 0;
|
|
675
|
+
}
|
|
676
|
+
function summarizeCauses(cause) {
|
|
677
|
+
const causes = [];
|
|
678
|
+
let current = cause;
|
|
679
|
+
while (current !== void 0 && current !== null && causes.length < MAX_CAUSE_DEPTH) {
|
|
680
|
+
if (ClassifiedError.isClassified(current)) {
|
|
681
|
+
causes.push(...current.causes.slice(0, MAX_CAUSE_DEPTH - causes.length));
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
const status = statusOf(current);
|
|
685
|
+
causes.push({
|
|
686
|
+
// Duck-typed: an error from another realm (e.g. a Workflow step VM) fails instanceof.
|
|
687
|
+
name: typeof current.name === "string" ? current.name : typeof current,
|
|
688
|
+
message: scrubDetail(extractErrorDetail(current)).slice(0, MAX_CAUSE_MESSAGE_LENGTH),
|
|
689
|
+
...status !== void 0 && { status }
|
|
690
|
+
});
|
|
691
|
+
current = typeof current === "object" ? current.cause : void 0;
|
|
692
|
+
}
|
|
693
|
+
return causes;
|
|
694
|
+
}
|
|
695
|
+
var ClassifiedError = class extends Error {
|
|
696
|
+
constructor(message, init, catalog) {
|
|
697
|
+
super(message);
|
|
698
|
+
/** Structural brand shared by every classified error, for duck-type identification across realms. */
|
|
699
|
+
this.__classified_error = true;
|
|
700
|
+
const entry = init.code ? catalog[init.code] : void 0;
|
|
701
|
+
this.type = entry?.type ?? init.type;
|
|
702
|
+
this.source = entry?.source ?? init.source;
|
|
703
|
+
const dependency = init.dependency ?? entry?.dependency;
|
|
704
|
+
if (dependency) {
|
|
705
|
+
this.dependency = dependency;
|
|
706
|
+
}
|
|
707
|
+
if (init.code) {
|
|
708
|
+
this.code = init.code;
|
|
709
|
+
}
|
|
710
|
+
this.facts = init.facts ?? {};
|
|
711
|
+
this.transient = init.transient ?? entry?.transient ?? defaultTransient(this.source, this.facts);
|
|
712
|
+
this.retryable = this.transient || (init.retryable ?? entry?.retryable ?? defaultRetryable(this.type, this.source, false));
|
|
713
|
+
this.name = this.transient ? "Error" : "FatalError";
|
|
714
|
+
if (init.cause !== void 0) {
|
|
715
|
+
Object.defineProperty(this, "cause", { value: init.cause, writable: true, configurable: true });
|
|
716
|
+
}
|
|
717
|
+
Object.defineProperty(this, "causes", { value: summarizeCauses(init.cause), writable: true, configurable: true });
|
|
718
|
+
}
|
|
719
|
+
/** Whether `value` is any classified error, from this copy of the SDK or another. */
|
|
720
|
+
static isClassified(value) {
|
|
721
|
+
return typeof value === "object" && value !== null && "__classified_error" in value && value.__classified_error === true;
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
function serializeClassification(error) {
|
|
725
|
+
return {
|
|
726
|
+
message: error.message,
|
|
727
|
+
type: error.type,
|
|
728
|
+
source: error.source,
|
|
729
|
+
...error.dependency && { dependency: error.dependency },
|
|
730
|
+
...error.code && { code: error.code },
|
|
731
|
+
facts: error.facts,
|
|
732
|
+
retryable: error.retryable,
|
|
733
|
+
transient: error.transient,
|
|
734
|
+
causes: error.causes,
|
|
735
|
+
stack: error.stack
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function classificationInit(record) {
|
|
739
|
+
return {
|
|
740
|
+
type: record.type,
|
|
741
|
+
source: record.source,
|
|
742
|
+
dependency: record.dependency,
|
|
743
|
+
facts: record.facts,
|
|
744
|
+
retryable: record.retryable,
|
|
745
|
+
transient: record.transient
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
function restoreClassification(error, record) {
|
|
749
|
+
if (record.code) {
|
|
750
|
+
Object.assign(error, { code: record.code });
|
|
751
|
+
}
|
|
752
|
+
Object.defineProperty(error, "causes", { value: record.causes, writable: true, configurable: true });
|
|
753
|
+
if (record.stack !== void 0) {
|
|
754
|
+
error.stack = record.stack;
|
|
755
|
+
}
|
|
756
|
+
return error;
|
|
757
|
+
}
|
|
758
|
+
var MuxAiError = class _MuxAiError extends ClassifiedError {
|
|
759
|
+
constructor(message, init) {
|
|
760
|
+
super(message, init, MUX_AI_ERROR_CATALOG);
|
|
761
|
+
/** Structural brand for duck-type identification across copies of the SDK. */
|
|
762
|
+
this.__mux_ai_error = true;
|
|
763
|
+
}
|
|
764
|
+
static is(value) {
|
|
765
|
+
return typeof value === "object" && value !== null && "__mux_ai_error" in value && value.__mux_ai_error === true;
|
|
766
|
+
}
|
|
767
|
+
// Subclasses with their own codec (LegacyMuxAiError) write their own shape.
|
|
768
|
+
static [WORKFLOW_SERIALIZE](instance) {
|
|
769
|
+
const incomplete = instance;
|
|
770
|
+
return {
|
|
771
|
+
v: 2,
|
|
772
|
+
...serializeClassification(instance),
|
|
773
|
+
usage: getErrorTokenUsage(instance),
|
|
774
|
+
finishReason: incomplete.finishReason,
|
|
775
|
+
rawFinishReason: incomplete.rawFinishReason,
|
|
776
|
+
diagnostics: instance.diagnostics
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
static [WORKFLOW_DESERIALIZE](value) {
|
|
780
|
+
const error = restoreClassification(new _MuxAiError(value.message, classificationInit(value)), value);
|
|
781
|
+
Object.assign(error, {
|
|
782
|
+
usage: value.usage,
|
|
783
|
+
diagnostics: value.diagnostics,
|
|
784
|
+
...value.finishReason !== void 0 && { finishReason: value.finishReason },
|
|
785
|
+
...value.rawFinishReason !== void 0 && { rawFinishReason: value.rawFinishReason }
|
|
786
|
+
});
|
|
787
|
+
return error;
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
function extractErrorDetail(error) {
|
|
791
|
+
if (error instanceof Error && error.message) {
|
|
792
|
+
return error.message;
|
|
793
|
+
}
|
|
794
|
+
if (typeof error === "string" && error.length > 0) {
|
|
795
|
+
return error;
|
|
796
|
+
}
|
|
797
|
+
if (typeof error === "object" && error !== null) {
|
|
798
|
+
const message = error.message;
|
|
799
|
+
if (typeof message === "string" && message.length > 0) {
|
|
800
|
+
return message;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return "Unknown error";
|
|
804
|
+
}
|
|
805
|
+
var URL_IN_TEXT = /https?:\/\/[^\s"'<>]+/g;
|
|
806
|
+
var URL_QUERY = /^([^?#]+)[?#].*$/s;
|
|
807
|
+
function stripUrlQueries(text2) {
|
|
808
|
+
return text2.replace(URL_IN_TEXT, (match) => {
|
|
809
|
+
let url;
|
|
810
|
+
try {
|
|
811
|
+
url = new URL(match);
|
|
812
|
+
} catch {
|
|
813
|
+
return match.replace(URL_QUERY, "$1?\u2026");
|
|
814
|
+
}
|
|
815
|
+
if (!url.username && !url.password && !url.search && !url.hash) {
|
|
816
|
+
return match;
|
|
817
|
+
}
|
|
818
|
+
return `${url.origin}${url.pathname}${url.search || url.hash ? "?\u2026" : ""}`;
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
function errorDetailFact(text2, maxLength = 500) {
|
|
822
|
+
return scrubDetail(text2).slice(0, maxLength);
|
|
823
|
+
}
|
|
824
|
+
function scrubDetail(detail, context) {
|
|
825
|
+
const leakReason = detectLeakReason(detail);
|
|
826
|
+
if (leakReason !== "canary" && leakReason !== "prompt_tag") {
|
|
827
|
+
return stripUrlQueries(detail);
|
|
828
|
+
}
|
|
829
|
+
console.warn(`[@mux/ai] Suppressed suspected prompt leak in error detail${context ? ` (context: ${context})` : ""} (reason: ${leakReason}).`);
|
|
830
|
+
return "Upstream error details suppressed by safety filter";
|
|
831
|
+
}
|
|
832
|
+
function wrapError(error, message, facts) {
|
|
833
|
+
if (MuxAiError.is(error)) {
|
|
834
|
+
if (facts) {
|
|
835
|
+
Object.assign(error, { facts: { ...facts, ...error.facts } });
|
|
836
|
+
}
|
|
837
|
+
throw error;
|
|
838
|
+
}
|
|
839
|
+
const wrapped = new MuxAiError(`${message}: ${scrubDetail(extractErrorDetail(error), message)}`, {
|
|
840
|
+
type: MUX_AI_ERROR_TYPES.SERVER_ERROR,
|
|
841
|
+
source: MUX_AI_ERROR_SOURCES.INTERNAL,
|
|
842
|
+
facts,
|
|
843
|
+
cause: error
|
|
844
|
+
});
|
|
845
|
+
const usage = getErrorTokenUsage(error);
|
|
846
|
+
if (usage) {
|
|
847
|
+
wrapped.usage = usage;
|
|
848
|
+
}
|
|
849
|
+
throw wrapped;
|
|
850
|
+
}
|
|
851
|
+
function internalError(message, facts, cause) {
|
|
852
|
+
return new MuxAiError(message, {
|
|
853
|
+
type: MUX_AI_ERROR_TYPES.SERVER_ERROR,
|
|
854
|
+
source: MUX_AI_ERROR_SOURCES.INTERNAL,
|
|
855
|
+
facts,
|
|
856
|
+
cause
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
function assertNever(value, what = "value") {
|
|
860
|
+
throw internalError(`Unexpected ${what}: ${String(value)}`);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// src/lib/dependency-error.ts
|
|
864
|
+
function classifyDependencyFailure(init) {
|
|
865
|
+
const { call, status, requestId, facts, timedOut } = init;
|
|
866
|
+
const transient = timedOut === true || isTransientStatus(status);
|
|
867
|
+
let source;
|
|
868
|
+
let type;
|
|
869
|
+
if (transient) {
|
|
870
|
+
source = MUX_AI_ERROR_SOURCES.UPSTREAM;
|
|
871
|
+
type = timedOut || status === 408 ? MUX_AI_ERROR_TYPES.TIMEOUT_ERROR : status === 429 ? MUX_AI_ERROR_TYPES.CAPACITY_ERROR : MUX_AI_ERROR_TYPES.PROCESSING_ERROR;
|
|
872
|
+
} else {
|
|
873
|
+
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;
|
|
874
|
+
type = source === MUX_AI_ERROR_SOURCES.INTERNAL ? MUX_AI_ERROR_TYPES.SERVER_ERROR : MUX_AI_ERROR_TYPES.VALIDATION_ERROR;
|
|
875
|
+
}
|
|
876
|
+
return {
|
|
877
|
+
type,
|
|
878
|
+
source,
|
|
879
|
+
facts: {
|
|
880
|
+
call,
|
|
881
|
+
...status !== void 0 && { status },
|
|
882
|
+
...requestId && { requestId },
|
|
883
|
+
...facts
|
|
884
|
+
},
|
|
885
|
+
// Set here, not left to the default: only the call site knows a missing status
|
|
886
|
+
// means no response (transient), rather than a failure the dependency reported.
|
|
887
|
+
// A non-idempotent call may have taken effect only with no response or a 5xx;
|
|
888
|
+
// a 408, 425 or 429 means it wasn't processed, so retrying stays safe.
|
|
889
|
+
transient: init.transient ?? (init.idempotent === false && (status === void 0 || status >= 500) ? false : transient),
|
|
890
|
+
...init.retryable !== void 0 && { retryable: init.retryable }
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
function dependencyError(message, init) {
|
|
894
|
+
const { source, ...classification } = classifyDependencyFailure(init);
|
|
895
|
+
const where = { source, dependency: init.dependency };
|
|
896
|
+
return new MuxAiError(message, { ...classification, ...where, cause: init.cause });
|
|
897
|
+
}
|
|
898
|
+
function httpStatusOf(error) {
|
|
899
|
+
if (typeof error !== "object" || error === null) {
|
|
900
|
+
return void 0;
|
|
901
|
+
}
|
|
902
|
+
const { status, statusCode } = error;
|
|
903
|
+
const candidate = typeof status === "number" ? status : statusCode;
|
|
904
|
+
return typeof candidate === "number" && candidate >= 100 && candidate < 600 ? candidate : void 0;
|
|
905
|
+
}
|
|
906
|
+
function requestIdOf(headers) {
|
|
907
|
+
if (!headers || typeof headers !== "object") {
|
|
908
|
+
return void 0;
|
|
909
|
+
}
|
|
910
|
+
const names = ["x-request-id", "x-amz-request-id", "request-id"];
|
|
911
|
+
for (const name of names) {
|
|
912
|
+
const value = typeof headers.get === "function" ? headers.get(name) : headers[name];
|
|
913
|
+
if (typeof value === "string" && value) {
|
|
914
|
+
return value;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
return void 0;
|
|
918
|
+
}
|
|
919
|
+
function dependencyErrorFrom(error, message, init) {
|
|
920
|
+
if (MuxAiError.is(error)) {
|
|
921
|
+
return error;
|
|
922
|
+
}
|
|
923
|
+
return dependencyError(message, {
|
|
924
|
+
...init,
|
|
925
|
+
status: httpStatusOf(error),
|
|
926
|
+
requestId: requestIdOf(error?.headers),
|
|
927
|
+
cause: error
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// src/lib/language-codes.ts
|
|
932
|
+
var ISO639_1_TO_3 = {
|
|
933
|
+
// Major world languages
|
|
934
|
+
en: "eng",
|
|
935
|
+
// English
|
|
936
|
+
es: "spa",
|
|
937
|
+
// Spanish
|
|
938
|
+
fr: "fra",
|
|
939
|
+
// French
|
|
940
|
+
de: "deu",
|
|
941
|
+
// German
|
|
942
|
+
it: "ita",
|
|
943
|
+
// Italian
|
|
944
|
+
pt: "por",
|
|
945
|
+
// Portuguese
|
|
946
|
+
ru: "rus",
|
|
947
|
+
// Russian
|
|
948
|
+
zh: "zho",
|
|
949
|
+
// Chinese
|
|
950
|
+
ja: "jpn",
|
|
951
|
+
// Japanese
|
|
952
|
+
ko: "kor",
|
|
953
|
+
// Korean
|
|
954
|
+
ar: "ara",
|
|
955
|
+
// Arabic
|
|
956
|
+
hi: "hin",
|
|
957
|
+
// Hindi
|
|
958
|
+
// European languages
|
|
959
|
+
nl: "nld",
|
|
960
|
+
// Dutch
|
|
961
|
+
pl: "pol",
|
|
962
|
+
// Polish
|
|
963
|
+
sv: "swe",
|
|
964
|
+
// Swedish
|
|
965
|
+
da: "dan",
|
|
966
|
+
// Danish
|
|
967
|
+
no: "nor",
|
|
968
|
+
// Norwegian
|
|
969
|
+
fi: "fin",
|
|
970
|
+
// Finnish
|
|
971
|
+
el: "ell",
|
|
972
|
+
// Greek
|
|
973
|
+
cs: "ces",
|
|
974
|
+
// Czech
|
|
975
|
+
hu: "hun",
|
|
976
|
+
// Hungarian
|
|
977
|
+
ro: "ron",
|
|
978
|
+
// Romanian
|
|
979
|
+
bg: "bul",
|
|
980
|
+
// Bulgarian
|
|
981
|
+
hr: "hrv",
|
|
982
|
+
// Croatian
|
|
983
|
+
sk: "slk",
|
|
984
|
+
// Slovak
|
|
985
|
+
sl: "slv",
|
|
986
|
+
// Slovenian
|
|
987
|
+
uk: "ukr",
|
|
988
|
+
// Ukrainian
|
|
989
|
+
tr: "tur",
|
|
990
|
+
// Turkish
|
|
991
|
+
// Asian languages
|
|
992
|
+
th: "tha",
|
|
993
|
+
// Thai
|
|
994
|
+
vi: "vie",
|
|
995
|
+
// Vietnamese
|
|
996
|
+
id: "ind",
|
|
997
|
+
// Indonesian
|
|
998
|
+
ms: "msa",
|
|
999
|
+
// Malay
|
|
1000
|
+
tl: "tgl",
|
|
1001
|
+
// Tagalog/Filipino
|
|
1002
|
+
// Other languages
|
|
1003
|
+
he: "heb",
|
|
1004
|
+
// Hebrew
|
|
1005
|
+
fa: "fas",
|
|
1006
|
+
// Persian/Farsi
|
|
1007
|
+
bn: "ben",
|
|
1008
|
+
// Bengali
|
|
1009
|
+
ta: "tam",
|
|
1010
|
+
// Tamil
|
|
1011
|
+
te: "tel",
|
|
1012
|
+
// Telugu
|
|
1013
|
+
mr: "mar",
|
|
1014
|
+
// Marathi
|
|
1015
|
+
gu: "guj",
|
|
1016
|
+
// Gujarati
|
|
1017
|
+
kn: "kan",
|
|
1018
|
+
// Kannada
|
|
1019
|
+
ml: "mal",
|
|
1020
|
+
// Malayalam
|
|
1021
|
+
pa: "pan",
|
|
1022
|
+
// Punjabi
|
|
1023
|
+
ur: "urd",
|
|
1024
|
+
// Urdu
|
|
1025
|
+
sw: "swa",
|
|
1026
|
+
// Swahili
|
|
1027
|
+
af: "afr",
|
|
1028
|
+
// Afrikaans
|
|
1029
|
+
ca: "cat",
|
|
1030
|
+
// Catalan
|
|
1031
|
+
eu: "eus",
|
|
1032
|
+
// Basque
|
|
1033
|
+
gl: "glg",
|
|
1034
|
+
// Galician
|
|
1035
|
+
is: "isl",
|
|
1036
|
+
// Icelandic
|
|
1037
|
+
et: "est",
|
|
1038
|
+
// Estonian
|
|
1039
|
+
lv: "lav",
|
|
1040
|
+
// Latvian
|
|
1041
|
+
lt: "lit",
|
|
1042
|
+
// Lithuanian
|
|
1043
|
+
as: "asm",
|
|
1044
|
+
az: "aze",
|
|
1045
|
+
be: "bel",
|
|
1046
|
+
bs: "bos",
|
|
1047
|
+
cy: "cym",
|
|
1048
|
+
ga: "gle",
|
|
1049
|
+
ha: "hau",
|
|
1050
|
+
hy: "hye",
|
|
1051
|
+
jv: "jav",
|
|
1052
|
+
ka: "kat",
|
|
1053
|
+
kk: "kaz",
|
|
1054
|
+
ky: "kir",
|
|
1055
|
+
lb: "ltz",
|
|
1056
|
+
ln: "lin",
|
|
1057
|
+
mi: "mri",
|
|
1058
|
+
mk: "mkd",
|
|
1059
|
+
mn: "mon",
|
|
1060
|
+
mt: "mlt",
|
|
1061
|
+
my: "mya",
|
|
1062
|
+
ne: "nep",
|
|
1063
|
+
ny: "nya",
|
|
1064
|
+
oc: "oci",
|
|
1065
|
+
or: "ori",
|
|
1066
|
+
ps: "pus",
|
|
1067
|
+
sd: "snd",
|
|
1068
|
+
so: "som",
|
|
1069
|
+
sr: "srp",
|
|
1070
|
+
tg: "tgk",
|
|
1071
|
+
uz: "uzb",
|
|
1072
|
+
yo: "yor"
|
|
1073
|
+
};
|
|
1074
|
+
var ISO639_3_TO_1 = Object.fromEntries(
|
|
1075
|
+
Object.entries(ISO639_1_TO_3).map(([iso1, iso3]) => [iso3, iso1])
|
|
1076
|
+
);
|
|
1077
|
+
function toISO639_3(code) {
|
|
1078
|
+
const normalized = code.toLowerCase().trim();
|
|
1079
|
+
if (normalized.length === 3) {
|
|
1080
|
+
return normalized;
|
|
1081
|
+
}
|
|
1082
|
+
return ISO639_1_TO_3[normalized] ?? normalized;
|
|
1083
|
+
}
|
|
1084
|
+
function toISO639_1(code) {
|
|
1085
|
+
const normalized = code.toLowerCase().trim();
|
|
1086
|
+
if (normalized.length === 2) {
|
|
1087
|
+
return normalized;
|
|
1088
|
+
}
|
|
1089
|
+
return Object.prototype.hasOwnProperty.call(ISO639_3_TO_1, normalized) ? ISO639_3_TO_1[normalized] : normalized;
|
|
1090
|
+
}
|
|
1091
|
+
function getLanguageCodePair(code) {
|
|
1092
|
+
const normalized = code.toLowerCase().trim();
|
|
1093
|
+
if (normalized.length === 2) {
|
|
1094
|
+
return {
|
|
1095
|
+
iso639_1: normalized,
|
|
1096
|
+
iso639_3: toISO639_3(normalized)
|
|
1097
|
+
};
|
|
1098
|
+
} else if (normalized.length === 3) {
|
|
1099
|
+
return {
|
|
1100
|
+
iso639_1: toISO639_1(normalized),
|
|
1101
|
+
iso639_3: normalized
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
return {
|
|
1105
|
+
iso639_1: normalized,
|
|
1106
|
+
iso639_3: normalized
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
function isValidISO639_1(code) {
|
|
1110
|
+
return code.length === 2 && code.toLowerCase() in ISO639_1_TO_3;
|
|
1111
|
+
}
|
|
1112
|
+
function isValidISO639_3(code) {
|
|
1113
|
+
return code.length === 3 && code.toLowerCase() in ISO639_3_TO_1;
|
|
1114
|
+
}
|
|
1115
|
+
var UNDETERMINED_LANGUAGE_CODES = /* @__PURE__ */ new Set(["und", "mul", "mis", "zxx"]);
|
|
1116
|
+
function isUndeterminedLanguageCode(code) {
|
|
1117
|
+
return UNDETERMINED_LANGUAGE_CODES.has(code.toLowerCase().trim());
|
|
1118
|
+
}
|
|
1119
|
+
function getLanguageName(code) {
|
|
1120
|
+
if (isUndeterminedLanguageCode(code)) {
|
|
1121
|
+
return void 0;
|
|
1122
|
+
}
|
|
1123
|
+
const iso639_1 = toISO639_1(code);
|
|
1124
|
+
try {
|
|
1125
|
+
const displayNames = new Intl.DisplayNames(["en"], { type: "language" });
|
|
1126
|
+
return displayNames.of(iso639_1) ?? code.toUpperCase();
|
|
1127
|
+
} catch {
|
|
1128
|
+
return code.toUpperCase();
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// src/lib/mux-static-renditions.ts
|
|
1133
|
+
var STATIC_RENDITIONS_GUIDE_URL = "https://www.mux.com/docs/guides/enable-static-mp4-renditions";
|
|
1134
|
+
var LEGACY_MP4_SUPPORT_FILE_PREFERENCE = {
|
|
1135
|
+
"capped-1080p": ["capped-1080p.mp4", "audio.m4a"],
|
|
1136
|
+
"audio-only": ["audio.m4a"],
|
|
1137
|
+
"audio-only,capped-1080p": ["audio.m4a", "capped-1080p.mp4"],
|
|
1138
|
+
"standard": ["low.mp4", "audio.m4a"]
|
|
1139
|
+
};
|
|
1140
|
+
var BYTES_PER_GB = 1e9;
|
|
1141
|
+
function usesLegacyMp4Support(asset) {
|
|
1142
|
+
return asset.mp4_support !== void 0 && asset.mp4_support !== "none";
|
|
1143
|
+
}
|
|
1144
|
+
function parseFilesizeBytes(filesize) {
|
|
1145
|
+
const bytes = typeof filesize === "string" ? Number(filesize) : filesize;
|
|
1146
|
+
return typeof bytes === "number" && Number.isFinite(bytes) && bytes > 0 ? bytes : void 0;
|
|
686
1147
|
}
|
|
687
|
-
function
|
|
688
|
-
if (
|
|
689
|
-
return void 0;
|
|
690
|
-
}
|
|
691
|
-
const usage = error.usage;
|
|
692
|
-
if (typeof usage !== "object" || usage === null) {
|
|
1148
|
+
function resolveLegacyMp4SupportRendition(asset) {
|
|
1149
|
+
if (!usesLegacyMp4Support(asset)) {
|
|
693
1150
|
return void 0;
|
|
694
1151
|
}
|
|
695
|
-
const
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
const value = source[field];
|
|
699
|
-
if (typeof value === "number") {
|
|
700
|
-
extracted[field] = value;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
if (extracted.reasoningTokens === void 0) {
|
|
704
|
-
const reasoningTokens = source.outputTokenDetails?.reasoningTokens;
|
|
705
|
-
if (typeof reasoningTokens === "number") {
|
|
706
|
-
extracted.reasoningTokens = reasoningTokens;
|
|
707
|
-
}
|
|
1152
|
+
const status = asset.static_renditions?.status;
|
|
1153
|
+
if (status === void 0 || status === "preparing") {
|
|
1154
|
+
return { kind: "preparing" };
|
|
708
1155
|
}
|
|
709
|
-
if (
|
|
710
|
-
|
|
711
|
-
if (typeof cacheReadTokens === "number") {
|
|
712
|
-
extracted.cachedInputTokens = cacheReadTokens;
|
|
713
|
-
}
|
|
1156
|
+
if (status !== "ready") {
|
|
1157
|
+
return { kind: "unusable", reason: legacyMp4SupportUnusableMessage({ status }), mp4Support: asset.mp4_support, status };
|
|
714
1158
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
1159
|
+
const files = asset.static_renditions?.files ?? [];
|
|
1160
|
+
for (const name of LEGACY_MP4_SUPPORT_FILE_PREFERENCE[asset.mp4_support] ?? []) {
|
|
1161
|
+
const file = files.find((candidate) => candidate.name === name);
|
|
1162
|
+
if (file) {
|
|
1163
|
+
return { kind: "ready", name, filesizeBytes: parseFilesizeBytes(file.filesize) };
|
|
719
1164
|
}
|
|
720
1165
|
}
|
|
721
|
-
return
|
|
1166
|
+
return { kind: "unusable", reason: legacyMp4SupportUnusableMessage({ mp4Support: asset.mp4_support }), mp4Support: asset.mp4_support };
|
|
722
1167
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
|
|
1168
|
+
var MOVE_TO_STATIC_RENDITIONS = `Move the asset to the Static Renditions API (${STATIC_RENDITIONS_GUIDE_URL}) and add an audio-only static rendition, then retry.`;
|
|
1169
|
+
function legacyMp4SupportUnusableMessage({ status, mp4Support }) {
|
|
1170
|
+
return status ? `This asset uses the deprecated mp4_support setting, and its static renditions are ${status}. ${MOVE_TO_STATIC_RENDITIONS}` : `This asset uses the deprecated mp4_support setting${mp4Support ? ` ("${mp4Support}")` : ""}, and none of its static renditions can be used by this workflow. ${MOVE_TO_STATIC_RENDITIONS}`;
|
|
1171
|
+
}
|
|
1172
|
+
function legacyMp4SupportTooLargeMessage({ name, filesizeBytes, maxBytes }) {
|
|
1173
|
+
return `This asset uses the deprecated mp4_support setting, and its ${name} static rendition (${formatGigabytes(filesizeBytes)}) is larger than the ${formatGigabytes(maxBytes)} this workflow can process. ${MOVE_TO_STATIC_RENDITIONS}`;
|
|
1174
|
+
}
|
|
1175
|
+
function formatGigabytes(bytes) {
|
|
1176
|
+
return `${Math.round(bytes / BYTES_PER_GB * 100) / 100} GB`;
|
|
1177
|
+
}
|
|
1178
|
+
function getLegacyMp4SupportRenditionSizeError(rendition, maxBytes) {
|
|
1179
|
+
if (rendition.filesizeBytes === void 0 || rendition.filesizeBytes <= maxBytes) {
|
|
1180
|
+
return void 0;
|
|
731
1181
|
}
|
|
732
|
-
|
|
1182
|
+
return legacyMp4SupportTooLargeMessage({ name: rendition.name, filesizeBytes: rendition.filesizeBytes, maxBytes });
|
|
733
1183
|
}
|
|
734
1184
|
|
|
735
|
-
// src/lib/mux-ai-error.ts
|
|
736
|
-
|
|
1185
|
+
// src/lib/legacy-mux-ai-error.ts
|
|
1186
|
+
function legacySource(type) {
|
|
1187
|
+
switch (type) {
|
|
1188
|
+
case MUX_AI_ERROR_TYPES.VALIDATION_ERROR:
|
|
1189
|
+
return MUX_AI_ERROR_SOURCES.REQUEST;
|
|
1190
|
+
case MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR:
|
|
1191
|
+
return MUX_AI_ERROR_SOURCES.ASSET;
|
|
1192
|
+
default:
|
|
1193
|
+
return MUX_AI_ERROR_SOURCES.INTERNAL;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
var LegacyMuxAiError = class _LegacyMuxAiError extends MuxAiError {
|
|
737
1197
|
constructor(message, opts) {
|
|
738
|
-
|
|
739
|
-
|
|
1198
|
+
const type = opts?.type ?? MUX_AI_ERROR_TYPES.PROCESSING_ERROR;
|
|
1199
|
+
super(message, { type, source: legacySource(type), retryable: opts?.retryable ?? false, transient: false, cause: opts?.cause });
|
|
740
1200
|
this.__robots_error = true;
|
|
741
|
-
|
|
742
|
-
Object.defineProperty(this, "cause", { value: opts.cause, writable: true, configurable: true });
|
|
743
|
-
}
|
|
744
|
-
this.name = "FatalError";
|
|
745
|
-
this.publicType = opts?.type ?? "processing_error";
|
|
1201
|
+
this.publicType = type;
|
|
746
1202
|
this.publicMessage = message;
|
|
747
|
-
this.retryable = opts?.retryable ?? false;
|
|
748
|
-
}
|
|
749
|
-
static is(value) {
|
|
750
|
-
return typeof value === "object" && value !== null && "__robots_error" in value && value.__robots_error === true;
|
|
751
1203
|
}
|
|
1204
|
+
// Its own codec, so a legacy error crosses step boundaries in its previous shape and
|
|
1205
|
+
// revives as a legacy error (subclasses such as IncompleteGenerationError inherit it).
|
|
752
1206
|
static [WORKFLOW_SERIALIZE](instance) {
|
|
753
1207
|
const incomplete = instance;
|
|
754
1208
|
return {
|
|
@@ -762,8 +1216,10 @@ var MuxAiError = class _MuxAiError extends Error {
|
|
|
762
1216
|
diagnostics: instance.diagnostics
|
|
763
1217
|
};
|
|
764
1218
|
}
|
|
765
|
-
|
|
766
|
-
|
|
1219
|
+
// Typed to match the base codec; this codec only ever reads the legacy shape it writes.
|
|
1220
|
+
static [WORKFLOW_DESERIALIZE](record) {
|
|
1221
|
+
const value = record;
|
|
1222
|
+
const error = new _LegacyMuxAiError(value.message, { type: value.publicType, retryable: value.retryable });
|
|
767
1223
|
Object.assign(error, {
|
|
768
1224
|
usage: value.usage,
|
|
769
1225
|
diagnostics: value.diagnostics,
|
|
@@ -776,23 +1232,11 @@ var MuxAiError = class _MuxAiError extends Error {
|
|
|
776
1232
|
return error;
|
|
777
1233
|
}
|
|
778
1234
|
};
|
|
779
|
-
function
|
|
780
|
-
|
|
781
|
-
return error.message;
|
|
782
|
-
}
|
|
783
|
-
if (typeof error === "string" && error.length > 0) {
|
|
784
|
-
return error;
|
|
785
|
-
}
|
|
786
|
-
if (typeof error === "object" && error !== null) {
|
|
787
|
-
const message = error.message;
|
|
788
|
-
if (typeof message === "string" && message.length > 0) {
|
|
789
|
-
return message;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
return "Unknown error";
|
|
1235
|
+
function isLegacyMuxAiError(value) {
|
|
1236
|
+
return typeof value === "object" && value !== null && "__robots_error" in value && value.__robots_error === true && typeof value.publicMessage === "string";
|
|
793
1237
|
}
|
|
794
|
-
function
|
|
795
|
-
if (MuxAiError.is(error)) {
|
|
1238
|
+
function legacyWrapError(error, message) {
|
|
1239
|
+
if (MuxAiError.is(error) || isLegacyMuxAiError(error)) {
|
|
796
1240
|
throw error;
|
|
797
1241
|
}
|
|
798
1242
|
const rawDetail = extractErrorDetail(error);
|
|
@@ -810,58 +1254,6 @@ function wrapError(error, message) {
|
|
|
810
1254
|
throw wrapped;
|
|
811
1255
|
}
|
|
812
1256
|
|
|
813
|
-
// src/lib/mux-static-renditions.ts
|
|
814
|
-
var STATIC_RENDITIONS_GUIDE_URL = "https://www.mux.com/docs/guides/enable-static-mp4-renditions";
|
|
815
|
-
var LEGACY_MP4_SUPPORT_FILE_PREFERENCE = {
|
|
816
|
-
"capped-1080p": ["capped-1080p.mp4", "audio.m4a"],
|
|
817
|
-
"audio-only": ["audio.m4a"],
|
|
818
|
-
"audio-only,capped-1080p": ["audio.m4a", "capped-1080p.mp4"],
|
|
819
|
-
"standard": ["low.mp4", "audio.m4a"]
|
|
820
|
-
};
|
|
821
|
-
var BYTES_PER_GB = 1e9;
|
|
822
|
-
function usesLegacyMp4Support(asset) {
|
|
823
|
-
return asset.mp4_support !== void 0 && asset.mp4_support !== "none";
|
|
824
|
-
}
|
|
825
|
-
function parseFilesizeBytes(filesize) {
|
|
826
|
-
const bytes = typeof filesize === "string" ? Number(filesize) : filesize;
|
|
827
|
-
return typeof bytes === "number" && Number.isFinite(bytes) && bytes > 0 ? bytes : void 0;
|
|
828
|
-
}
|
|
829
|
-
function resolveLegacyMp4SupportRendition(asset) {
|
|
830
|
-
if (!usesLegacyMp4Support(asset)) {
|
|
831
|
-
return void 0;
|
|
832
|
-
}
|
|
833
|
-
const status = asset.static_renditions?.status;
|
|
834
|
-
if (status === void 0 || status === "preparing") {
|
|
835
|
-
return { kind: "preparing" };
|
|
836
|
-
}
|
|
837
|
-
if (status !== "ready") {
|
|
838
|
-
return {
|
|
839
|
-
kind: "unusable",
|
|
840
|
-
reason: `This asset uses the deprecated mp4_support setting, and its static renditions are ${status}. Move the asset to the Static Renditions API (${STATIC_RENDITIONS_GUIDE_URL}) and add an audio-only static rendition, then retry.`
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
const files = asset.static_renditions?.files ?? [];
|
|
844
|
-
for (const name of LEGACY_MP4_SUPPORT_FILE_PREFERENCE[asset.mp4_support] ?? []) {
|
|
845
|
-
const file = files.find((candidate) => candidate.name === name);
|
|
846
|
-
if (file) {
|
|
847
|
-
return { kind: "ready", name, filesizeBytes: parseFilesizeBytes(file.filesize) };
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
return {
|
|
851
|
-
kind: "unusable",
|
|
852
|
-
reason: `This asset uses the deprecated mp4_support setting ("${asset.mp4_support}"), and none of its static renditions can be used by this workflow. Move the asset to the Static Renditions API (${STATIC_RENDITIONS_GUIDE_URL}) and add an audio-only static rendition, then retry.`
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
function formatGigabytes(bytes) {
|
|
856
|
-
return `${Math.round(bytes / BYTES_PER_GB * 100) / 100} GB`;
|
|
857
|
-
}
|
|
858
|
-
function getLegacyMp4SupportRenditionSizeError(rendition, maxBytes) {
|
|
859
|
-
if (rendition.filesizeBytes === void 0 || rendition.filesizeBytes <= maxBytes) {
|
|
860
|
-
return void 0;
|
|
861
|
-
}
|
|
862
|
-
return `This asset uses the deprecated mp4_support setting, and its ${rendition.name} static rendition (${formatGigabytes(rendition.filesizeBytes)}) is larger than the ${formatGigabytes(maxBytes)} this workflow can process. Move the asset to the Static Renditions API (${STATIC_RENDITIONS_GUIDE_URL}) and add an audio-only static rendition, then retry.`;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
1257
|
// src/lib/workflow-crypto.ts
|
|
866
1258
|
import { gcm } from "@noble/ciphers/aes.js";
|
|
867
1259
|
var BASE64_CHUNK_SIZE = 32768;
|
|
@@ -1321,41 +1713,53 @@ function itOrThem(tracks) {
|
|
|
1321
1713
|
return tracks.length === 1 ? "it" : "them";
|
|
1322
1714
|
}
|
|
1323
1715
|
function describeTracks(tracks) {
|
|
1324
|
-
return tracks.map(
|
|
1716
|
+
return describeTrackSummaries(tracks.map(summarizeTextTrack));
|
|
1717
|
+
}
|
|
1718
|
+
function describeTrackSummaries(tracks) {
|
|
1719
|
+
return tracks.map((track) => `${track.name ?? "(unnamed)"} [${track.languageCode ?? "?"}, ${track.type === "audio" ? track.primary ? "primary audio" : "audio" : track.textSource ?? "unknown source"}, ${track.status ?? "ready"}]`).join("; ");
|
|
1325
1720
|
}
|
|
1326
1721
|
function planTextTrackReplacement(asset, target, policy) {
|
|
1327
1722
|
const label = targetType(target) === "audio" ? "Audio" : "Text";
|
|
1723
|
+
const sameLanguage = findSameLanguageTextTracks(asset, target);
|
|
1724
|
+
const sameLanguageIds = new Set(sameLanguage.map((track) => track.id));
|
|
1328
1725
|
const conflicts = /* @__PURE__ */ new Map();
|
|
1329
|
-
for (const track of [...
|
|
1726
|
+
for (const track of [...sameLanguage, ...findNameCollisionTextTracks(asset, target)]) {
|
|
1330
1727
|
conflicts.set(track.id, track);
|
|
1331
1728
|
}
|
|
1332
1729
|
const conflicting = [...conflicts.values()];
|
|
1333
1730
|
if (conflicting.length === 0) {
|
|
1334
1731
|
return { kind: "clear" };
|
|
1335
1732
|
}
|
|
1733
|
+
const blocked = (code, reason, tracks) => ({
|
|
1734
|
+
kind: "blocked",
|
|
1735
|
+
reason,
|
|
1736
|
+
code,
|
|
1737
|
+
tracks: tracks.map(summarizeTextTrack),
|
|
1738
|
+
conflictsOnLanguage: tracks.some((track) => sameLanguageIds.has(track.id))
|
|
1739
|
+
});
|
|
1336
1740
|
if (policy === "fail") {
|
|
1337
|
-
return
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1741
|
+
return blocked(
|
|
1742
|
+
"policy_fail",
|
|
1743
|
+
`${countTracks(conflicting, label, "already exists", "already exist")} for language '${target.languageCode}' or name '${target.name}': ${describeTracks(conflicting)}. Set replaceExistingTracks to replace ${itOrThem(conflicting)}.`,
|
|
1744
|
+
conflicting
|
|
1745
|
+
);
|
|
1342
1746
|
}
|
|
1343
1747
|
const primary = conflicting.filter((track) => track.type === "audio" && track.primary === true);
|
|
1344
1748
|
if (primary.length > 0) {
|
|
1345
|
-
return
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1749
|
+
return blocked(
|
|
1750
|
+
"primary_audio",
|
|
1751
|
+
`The asset's primary audio track is in the way for language '${target.languageCode}' or name '${target.name}': ${describeTracks(primary)}. Primary audio cannot be replaced; choose a different trackName.`,
|
|
1752
|
+
primary
|
|
1753
|
+
);
|
|
1350
1754
|
}
|
|
1351
1755
|
if (policy === "replace_generated") {
|
|
1352
1756
|
const notGenerated = conflicting.filter((track) => track.type !== "text" || !isMuxGeneratedTextTrack(track));
|
|
1353
1757
|
if (notGenerated.length > 0) {
|
|
1354
|
-
return
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1758
|
+
return blocked(
|
|
1759
|
+
"not_generated",
|
|
1760
|
+
`${countTracks(notGenerated, label, "that is not Mux-generated exists", "that are not Mux-generated exist")} for language '${target.languageCode}' or name '${target.name}': ${describeTracks(notGenerated)}. Use replaceExistingTracks: "replace_all" to replace ${itOrThem(notGenerated)}.`,
|
|
1761
|
+
notGenerated
|
|
1762
|
+
);
|
|
1359
1763
|
}
|
|
1360
1764
|
}
|
|
1361
1765
|
return { kind: "replace", toDelete: conflicting.map(summarizeTextTrack) };
|
|
@@ -1366,8 +1770,10 @@ function planSourceTrackReplacement(asset, sourceTrackId, target, policy) {
|
|
|
1366
1770
|
if (blocking.length > 0) {
|
|
1367
1771
|
return {
|
|
1368
1772
|
kind: "blocked",
|
|
1773
|
+
code: "name_collision",
|
|
1369
1774
|
reason: `${countTracks(blocking, "Text", "already has", "already have")} the name '${target.name}': ${describeTracks(blocking)}. Choose a different trackName.`,
|
|
1370
|
-
tracks: blocking.map(summarizeTextTrack)
|
|
1775
|
+
tracks: blocking.map(summarizeTextTrack),
|
|
1776
|
+
conflictsOnLanguage: false
|
|
1371
1777
|
};
|
|
1372
1778
|
}
|
|
1373
1779
|
const source = policy === "replace" ? listTracks(asset, targetType(target)).find((track) => track.id === sourceTrackId) : void 0;
|
|
@@ -1388,12 +1794,56 @@ function isDuplicateTrackNameError(error) {
|
|
|
1388
1794
|
function isNotFoundError(error) {
|
|
1389
1795
|
return typeof error === "object" && error !== null && error.status === 404;
|
|
1390
1796
|
}
|
|
1797
|
+
function trackFacts(track) {
|
|
1798
|
+
return Object.fromEntries(
|
|
1799
|
+
Object.entries({
|
|
1800
|
+
id: track.id,
|
|
1801
|
+
type: track.type,
|
|
1802
|
+
name: track.name,
|
|
1803
|
+
languageCode: track.languageCode,
|
|
1804
|
+
status: track.status,
|
|
1805
|
+
textSource: track.textSource,
|
|
1806
|
+
primary: track.primary
|
|
1807
|
+
}).filter(([, value]) => value !== void 0)
|
|
1808
|
+
);
|
|
1809
|
+
}
|
|
1810
|
+
function trackTargetFacts(target) {
|
|
1811
|
+
return {
|
|
1812
|
+
trackType: targetType(target),
|
|
1813
|
+
languageCode: target.languageCode,
|
|
1814
|
+
...target.name !== void 0 && { trackName: target.name }
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
function trackSummaryFacts(tracks) {
|
|
1818
|
+
return tracks.map(trackFacts);
|
|
1819
|
+
}
|
|
1820
|
+
function trackReplacementBlockedError(blocked, options = {}) {
|
|
1821
|
+
const message = options.message ?? blocked.reason;
|
|
1822
|
+
const facts = {
|
|
1823
|
+
...options.facts,
|
|
1824
|
+
reason: blocked.code,
|
|
1825
|
+
conflictingTracks: trackSummaryFacts(blocked.tracks)
|
|
1826
|
+
};
|
|
1827
|
+
if (blocked.code === "primary_audio" && blocked.conflictsOnLanguage) {
|
|
1828
|
+
return new MuxAiError(message, {
|
|
1829
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
1830
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
1831
|
+
facts
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
return new MuxAiError(message, {
|
|
1835
|
+
code: MUX_AI_ERROR_CODES.TRACK_REPLACEMENT_BLOCKED,
|
|
1836
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
1837
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
1838
|
+
facts
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1391
1841
|
function buildMuxAiTrackPassthrough(workflow) {
|
|
1392
1842
|
return JSON.stringify({ mux_ai: { workflow } });
|
|
1393
1843
|
}
|
|
1394
1844
|
function validateTrackPassthrough(passthrough) {
|
|
1395
1845
|
if (passthrough !== void 0 && passthrough.length > MUX_TRACK_PASSTHROUGH_MAX_CHARS) {
|
|
1396
|
-
throw new
|
|
1846
|
+
throw new LegacyMuxAiError(
|
|
1397
1847
|
`Track passthrough must be at most ${MUX_TRACK_PASSTHROUGH_MAX_CHARS} characters (received ${passthrough.length}).`,
|
|
1398
1848
|
{ type: "validation_error" }
|
|
1399
1849
|
);
|
|
@@ -1588,6 +2038,185 @@ async function getMuxThumbnailBaseUrl(playbackId, credentials) {
|
|
|
1588
2038
|
return getMuxImageBaseUrl(playbackId, "thumbnail", credentials);
|
|
1589
2039
|
}
|
|
1590
2040
|
|
|
2041
|
+
// src/lib/public-error.ts
|
|
2042
|
+
var TRY_AGAIN = " Please try again.";
|
|
2043
|
+
var MUX_AI_ERROR_GENERIC_MESSAGES = {
|
|
2044
|
+
request: "The request's parameters can't be used for this operation.",
|
|
2045
|
+
asset: "The asset can't be processed by this operation.",
|
|
2046
|
+
account: "The Mux account or environment can't be used for this operation.",
|
|
2047
|
+
timeout: "The operation timed out.",
|
|
2048
|
+
capacity: "A required service is over capacity.",
|
|
2049
|
+
contentPolicy: "The content was blocked by a content policy.",
|
|
2050
|
+
unavailable: "A required service was temporarily unavailable.",
|
|
2051
|
+
failed: "The operation failed."
|
|
2052
|
+
};
|
|
2053
|
+
function text(value) {
|
|
2054
|
+
return value === void 0 || value === null ? "" : String(value);
|
|
2055
|
+
}
|
|
2056
|
+
function list(value) {
|
|
2057
|
+
return Array.isArray(value) && value.length > 0 ? value.map(text).join(", ") : "none";
|
|
2058
|
+
}
|
|
2059
|
+
function trackTarget(facts) {
|
|
2060
|
+
const parts = [facts.languageCode && `language '${text(facts.languageCode)}'`, facts.trackName && `name '${text(facts.trackName)}'`].filter(Boolean);
|
|
2061
|
+
return parts.length > 0 ? ` for ${parts.join(" or ")}` : "";
|
|
2062
|
+
}
|
|
2063
|
+
function blockedTrackMessage(facts) {
|
|
2064
|
+
const tracks = Array.isArray(facts.conflictingTracks) ? facts.conflictingTracks : [];
|
|
2065
|
+
const kind = facts.trackType === "audio" ? "audio" : "text";
|
|
2066
|
+
const subject = tracks.length > 1 ? `${tracks.length} ${kind} tracks` : `${kind === "audio" ? "An" : "A"} ${kind} track`;
|
|
2067
|
+
const described = tracks.length > 0 ? `: ${describeTrackSummaries(tracks)}` : "";
|
|
2068
|
+
const them = tracks.length > 1 ? "them" : "it";
|
|
2069
|
+
switch (facts.reason) {
|
|
2070
|
+
case "not_generated":
|
|
2071
|
+
return `${subject} that ${tracks.length > 1 ? "are" : "is"} not Mux-generated already ${tracks.length > 1 ? "exist" : "exists"}${trackTarget(facts)}${described}. Allow all existing tracks to be replaced, not only Mux-generated ones, to replace ${them}.`;
|
|
2072
|
+
case "name_collision":
|
|
2073
|
+
return `${subject} already ${tracks.length > 1 ? "have" : "has"} the name '${text(facts.trackName)}'${described}. Choose a different track name.`;
|
|
2074
|
+
case "primary_audio":
|
|
2075
|
+
return `The asset's primary audio track is in the way${trackTarget(facts)}${described}. Primary audio can't be replaced; choose a different track name.`;
|
|
2076
|
+
default:
|
|
2077
|
+
return `${subject} already ${tracks.length > 1 ? "exist" : "exists"}${trackTarget(facts)}${described}. Allow existing tracks to be replaced to replace ${them}.`;
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
function scopeMessage(facts) {
|
|
2081
|
+
switch (facts.reason) {
|
|
2082
|
+
case "invalid_start_time":
|
|
2083
|
+
return `The requested start time must be a non-negative number of seconds (received ${text(facts.received)}).`;
|
|
2084
|
+
case "invalid_end_time":
|
|
2085
|
+
return `The requested end time must be a non-negative number of seconds (received ${text(facts.received)}).`;
|
|
2086
|
+
case "exceeds_duration":
|
|
2087
|
+
return `The requested end time (${text(facts.endTime)}s) is after the end of the asset (${text(facts.assetDurationSeconds)}s).`;
|
|
2088
|
+
case "empty_range":
|
|
2089
|
+
return `The requested start time (${text(facts.startTime)}s) must be before the end time (${text(facts.endTime)}s).`;
|
|
2090
|
+
case "no_video":
|
|
2091
|
+
return "The requested time range doesn't include any video.";
|
|
2092
|
+
case "no_transcript":
|
|
2093
|
+
return "The transcript has no content in the requested time range.";
|
|
2094
|
+
default:
|
|
2095
|
+
return "The requested time range can't be used for this asset.";
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
var AUDIO_TRACK_UNSUPPORTED_MESSAGES = {
|
|
2099
|
+
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.",
|
|
2100
|
+
live_stream: "Mux doesn't support adding audio tracks to live stream assets. Use the dubbed audio file without adding it to Mux instead.",
|
|
2101
|
+
audio_only: "Mux doesn't support adding audio tracks to audio-only assets. Use the dubbed audio file without adding it to Mux instead."
|
|
2102
|
+
};
|
|
2103
|
+
var MUX_AI_ERROR_PUBLIC_MAPPINGS = {
|
|
2104
|
+
[MUX_AI_ERROR_CODES.INVALID_SCOPE]: {
|
|
2105
|
+
facts: ["reason", "received", "startTime", "endTime", "assetDurationSeconds"],
|
|
2106
|
+
message: scopeMessage
|
|
2107
|
+
},
|
|
2108
|
+
[MUX_AI_ERROR_CODES.TRACK_REPLACEMENT_BLOCKED]: {
|
|
2109
|
+
facts: ["reason", "trackType", "languageCode", "trackName", "conflictingTracks"],
|
|
2110
|
+
message: blockedTrackMessage
|
|
2111
|
+
},
|
|
2112
|
+
[MUX_AI_ERROR_CODES.CAPTION_TRACK_NOT_FOUND]: {
|
|
2113
|
+
facts: ["trackId", "availableTrackIds", "languageCode", "availableLanguages"],
|
|
2114
|
+
message: (facts) => facts.trackId ? `Track ${text(facts.trackId)} was not found or is not ready. Available track IDs: ${list(facts.availableTrackIds)}.` : `No ready caption track was found${facts.languageCode ? ` for language ${text(facts.languageCode)}` : ""}. Available languages: ${list(facts.availableLanguages)}.`
|
|
2115
|
+
},
|
|
2116
|
+
[MUX_AI_ERROR_CODES.PLAYBACK_ID_NOT_FOUND]: {
|
|
2117
|
+
message: "The asset has no public or signed playback ID. DRM playback IDs aren't supported."
|
|
2118
|
+
},
|
|
2119
|
+
[MUX_AI_ERROR_CODES.TRANSCRIPT_EMPTY]: {
|
|
2120
|
+
message: "The transcript has no usable content."
|
|
2121
|
+
},
|
|
2122
|
+
// Names the caller's own option; a consumer that exposes different names overrides the wording.
|
|
2123
|
+
[MUX_AI_ERROR_CODES.PARAMETER_OUT_OF_RANGE]: {
|
|
2124
|
+
facts: ["parameter", "value", "min", "max", "integer"],
|
|
2125
|
+
message: (facts) => `${text(facts.parameter) || "A parameter"} must be ${facts.integer ? "an integer " : ""}between ${text(facts.min)} and ${text(facts.max)}${facts.value === void 0 ? "" : ` (received ${text(facts.value)})`}.`
|
|
2126
|
+
},
|
|
2127
|
+
[MUX_AI_ERROR_CODES.ASSET_DURATION_UNAVAILABLE]: {
|
|
2128
|
+
facts: ["assetId"],
|
|
2129
|
+
message: (facts) => facts.assetId ? `Asset ${text(facts.assetId)} has no valid duration.` : "The asset has no valid duration."
|
|
2130
|
+
},
|
|
2131
|
+
// Only the asset: the call, provider and model stay internal.
|
|
2132
|
+
[MUX_AI_ERROR_CODES.MODEL_OUTPUT_MISSING]: {
|
|
2133
|
+
facts: ["assetId"],
|
|
2134
|
+
message: (facts) => `The AI model returned no usable output${facts.assetId ? ` for asset ${text(facts.assetId)}` : ""}.`
|
|
2135
|
+
},
|
|
2136
|
+
[MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID]: {
|
|
2137
|
+
facts: ["assetId"],
|
|
2138
|
+
message: (facts) => facts.assetId ? `The AI model's output for asset ${text(facts.assetId)} couldn't be used.` : "The AI model's output couldn't be used."
|
|
2139
|
+
},
|
|
2140
|
+
[MUX_AI_ERROR_CODES.AUDIO_TRACK_UNSUPPORTED]: {
|
|
2141
|
+
facts: ["reason"],
|
|
2142
|
+
message: (facts) => AUDIO_TRACK_UNSUPPORTED_MESSAGES[text(facts.reason)] ?? "Mux doesn't support adding audio tracks to this asset."
|
|
2143
|
+
},
|
|
2144
|
+
[MUX_AI_ERROR_CODES.STATIC_RENDITION_UNSUPPORTED]: {
|
|
2145
|
+
facts: ["reason", "mp4Support", "renditionStatus", "renditionName", "sizeBytes", "maxBytes"],
|
|
2146
|
+
message: (facts) => facts.reason === "too_large" ? legacyMp4SupportTooLargeMessage({ name: text(facts.renditionName), filesizeBytes: Number(facts.sizeBytes), maxBytes: Number(facts.maxBytes) }) : legacyMp4SupportUnusableMessage({ status: text(facts.renditionStatus) || void 0, mp4Support: text(facts.mp4Support) || void 0 })
|
|
2147
|
+
},
|
|
2148
|
+
[MUX_AI_ERROR_CODES.STATIC_RENDITION_FAILED]: {
|
|
2149
|
+
message: "Mux failed to create the static rendition this operation needs. Check the asset's static renditions in the Mux dashboard."
|
|
2150
|
+
},
|
|
2151
|
+
[MUX_AI_ERROR_CODES.CONTENT_POLICY_BLOCKED]: {
|
|
2152
|
+
facts: ["reason", "category"],
|
|
2153
|
+
message: (facts) => {
|
|
2154
|
+
const detail = [facts.reason && `reason: ${text(facts.reason)}`, facts.category && `category: ${text(facts.category)}`].filter(Boolean).join("; ");
|
|
2155
|
+
return `The content was blocked by a content policy${detail ? ` (${detail})` : ""}.`;
|
|
2156
|
+
}
|
|
2157
|
+
},
|
|
2158
|
+
[MUX_AI_ERROR_CODES.DUBBING_LANGUAGE_UNSUPPORTED]: {
|
|
2159
|
+
facts: ["language", "which"],
|
|
2160
|
+
message: (facts) => `Audio dubbing doesn't support the ${text(facts.which) || "requested"} language "${text(facts.language)}".`
|
|
2161
|
+
},
|
|
2162
|
+
[MUX_AI_ERROR_CODES.DUBBING_FAILED]: {
|
|
2163
|
+
// The dubbing provider documents this text as safe to display.
|
|
2164
|
+
facts: ["providerError"],
|
|
2165
|
+
message: (facts, { retryable }) => `Audio dubbing failed${facts.providerError ? `: ${text(facts.providerError)}` : "."}${retryable ? TRY_AGAIN : ""}`
|
|
2166
|
+
}
|
|
2167
|
+
};
|
|
2168
|
+
function genericPublicMessage(error) {
|
|
2169
|
+
const retry = error.retryable ? TRY_AGAIN : "";
|
|
2170
|
+
switch (error.source) {
|
|
2171
|
+
case MUX_AI_ERROR_SOURCES.REQUEST:
|
|
2172
|
+
return MUX_AI_ERROR_GENERIC_MESSAGES.request;
|
|
2173
|
+
case MUX_AI_ERROR_SOURCES.ASSET:
|
|
2174
|
+
return `${MUX_AI_ERROR_GENERIC_MESSAGES.asset}${retry}`;
|
|
2175
|
+
case MUX_AI_ERROR_SOURCES.ACCOUNT:
|
|
2176
|
+
return MUX_AI_ERROR_GENERIC_MESSAGES.account;
|
|
2177
|
+
}
|
|
2178
|
+
switch (error.type) {
|
|
2179
|
+
case MUX_AI_ERROR_TYPES.TIMEOUT_ERROR:
|
|
2180
|
+
return `${MUX_AI_ERROR_GENERIC_MESSAGES.timeout}${retry}`;
|
|
2181
|
+
case MUX_AI_ERROR_TYPES.CAPACITY_ERROR:
|
|
2182
|
+
return `${MUX_AI_ERROR_GENERIC_MESSAGES.capacity}${retry}`;
|
|
2183
|
+
case MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR:
|
|
2184
|
+
return MUX_AI_ERROR_GENERIC_MESSAGES.contentPolicy;
|
|
2185
|
+
default:
|
|
2186
|
+
return error.retryable ? `${MUX_AI_ERROR_GENERIC_MESSAGES.unavailable}${TRY_AGAIN}` : MUX_AI_ERROR_GENERIC_MESSAGES.failed;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
function allowedFacts(facts, allowed) {
|
|
2190
|
+
if (!facts || !allowed?.length) {
|
|
2191
|
+
return void 0;
|
|
2192
|
+
}
|
|
2193
|
+
const picked = Object.fromEntries(allowed.filter((key) => facts[key] !== void 0).map((key) => [key, facts[key]]));
|
|
2194
|
+
return Object.keys(picked).length > 0 ? picked : void 0;
|
|
2195
|
+
}
|
|
2196
|
+
function createPublicErrorView(config) {
|
|
2197
|
+
return (error) => {
|
|
2198
|
+
if (isLegacyMuxAiError(error)) {
|
|
2199
|
+
return { type: error.publicType, message: error.publicMessage, retryable: error.retryable };
|
|
2200
|
+
}
|
|
2201
|
+
const mapping = error.code ? config.mappings[error.code] : void 0;
|
|
2202
|
+
if (!mapping) {
|
|
2203
|
+
return { type: error.type, message: config.genericMessage(error), retryable: error.retryable };
|
|
2204
|
+
}
|
|
2205
|
+
const facts = allowedFacts(error.facts, mapping.facts);
|
|
2206
|
+
return {
|
|
2207
|
+
type: error.type,
|
|
2208
|
+
code: error.code,
|
|
2209
|
+
message: typeof mapping.message === "string" ? mapping.message : mapping.message(facts ?? {}, error),
|
|
2210
|
+
retryable: error.retryable,
|
|
2211
|
+
...facts && { facts }
|
|
2212
|
+
};
|
|
2213
|
+
};
|
|
2214
|
+
}
|
|
2215
|
+
var toPublicError = createPublicErrorView({
|
|
2216
|
+
mappings: MUX_AI_ERROR_PUBLIC_MAPPINGS,
|
|
2217
|
+
genericMessage: genericPublicMessage
|
|
2218
|
+
});
|
|
2219
|
+
|
|
1591
2220
|
// src/lib/s3-sigv4.ts
|
|
1592
2221
|
var AWS4_ALGORITHM = "AWS4-HMAC-SHA256";
|
|
1593
2222
|
var AWS4_REQUEST_TERMINATOR = "aws4_request";
|
|
@@ -2498,22 +3127,22 @@ async function waitForShotsForAsset(assetId, options = {}) {
|
|
|
2498
3127
|
return result;
|
|
2499
3128
|
}
|
|
2500
3129
|
if (result.status === "errored") {
|
|
2501
|
-
throw new
|
|
3130
|
+
throw new LegacyMuxAiError(`Shot generation failed for asset ${assetId}.`);
|
|
2502
3131
|
}
|
|
2503
3132
|
if (result.status === "skipped") {
|
|
2504
|
-
throw new
|
|
3133
|
+
throw new LegacyMuxAiError(
|
|
2505
3134
|
`Shot generation was skipped for asset ${assetId}; the asset may have no video track.`,
|
|
2506
3135
|
{ type: "validation_error" }
|
|
2507
3136
|
);
|
|
2508
3137
|
}
|
|
2509
3138
|
if (result.status === "deleted") {
|
|
2510
|
-
throw new
|
|
3139
|
+
throw new LegacyMuxAiError(`Shots for asset ${assetId} have been deleted.`, { type: "validation_error" });
|
|
2511
3140
|
}
|
|
2512
3141
|
if (attempt < normalizedMaxAttempts - 1) {
|
|
2513
3142
|
await sleep(normalizedPollIntervalMs);
|
|
2514
3143
|
}
|
|
2515
3144
|
}
|
|
2516
|
-
throw new
|
|
3145
|
+
throw new LegacyMuxAiError(
|
|
2517
3146
|
`Timed out waiting for shots for asset ${assetId}. Last status: ${lastStatus ?? "unknown"}.`,
|
|
2518
3147
|
{ type: "timeout_error", retryable: true }
|
|
2519
3148
|
);
|
|
@@ -2543,14 +3172,18 @@ async function signUrl(url, playbackId, type = "video", params, credentials) {
|
|
|
2543
3172
|
"use step";
|
|
2544
3173
|
const resolvedContext = await resolveMuxSigningContext(credentials);
|
|
2545
3174
|
if (!resolvedContext) {
|
|
2546
|
-
throw
|
|
2547
|
-
"Signed playback ID requires signing credentials. Provide muxSigningKey and muxPrivateKey via workflow credentials or set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables."
|
|
2548
|
-
);
|
|
3175
|
+
throw signingCredentialsMissingError();
|
|
2549
3176
|
}
|
|
2550
3177
|
const token = await signPlaybackId(playbackId, resolvedContext, type, params);
|
|
2551
3178
|
const separator = url.includes("?") ? "&" : "?";
|
|
2552
3179
|
return `${url}${separator}token=${token}`;
|
|
2553
3180
|
}
|
|
3181
|
+
function signingCredentialsMissingError() {
|
|
3182
|
+
return new MuxAiError(
|
|
3183
|
+
"Signed playback ID requires signing credentials. Provide muxSigningKey and muxPrivateKey via workflow credentials or set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
3184
|
+
{ code: MUX_AI_ERROR_CODES.SIGNING_CREDENTIALS_MISSING, type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL }
|
|
3185
|
+
);
|
|
3186
|
+
}
|
|
2554
3187
|
|
|
2555
3188
|
// src/primitives/storyboards.ts
|
|
2556
3189
|
var DEFAULT_STORYBOARD_WIDTH = 640;
|
|
@@ -2581,16 +3214,16 @@ var PREFERRED_BOUNDARY_WINDOW_SECONDS = 5 * 60;
|
|
|
2581
3214
|
var SENTENCE_BOUNDARY_REGEX = /[.!?]["')\]]*$/;
|
|
2582
3215
|
var CLAUSE_BOUNDARY_REGEX = /[,;:]["')\]]*$/;
|
|
2583
3216
|
var NEXT_SENTENCE_START_REGEX = /^[A-Z0-9"'([{]/;
|
|
2584
|
-
function estimateTokenCount(
|
|
2585
|
-
const words =
|
|
3217
|
+
function estimateTokenCount(text2) {
|
|
3218
|
+
const words = text2.trim().split(/\s+/).length;
|
|
2586
3219
|
return Math.ceil(words / 0.75);
|
|
2587
3220
|
}
|
|
2588
|
-
function chunkByTokens(
|
|
2589
|
-
if (!
|
|
3221
|
+
function chunkByTokens(text2, maxTokens, overlapTokens = 0) {
|
|
3222
|
+
if (!text2.trim()) {
|
|
2590
3223
|
return [];
|
|
2591
3224
|
}
|
|
2592
3225
|
const chunks = [];
|
|
2593
|
-
const words =
|
|
3226
|
+
const words = text2.trim().split(/\s+/);
|
|
2594
3227
|
const wordsPerChunk = Math.floor(maxTokens * 0.75);
|
|
2595
3228
|
const overlapWords = Math.floor(overlapTokens * 0.75);
|
|
2596
3229
|
let chunkIndex = 0;
|
|
@@ -2616,11 +3249,11 @@ function chunkByTokens(text, maxTokens, overlapTokens = 0) {
|
|
|
2616
3249
|
return chunks;
|
|
2617
3250
|
}
|
|
2618
3251
|
function createChunkFromCues(cues, index) {
|
|
2619
|
-
const
|
|
3252
|
+
const text2 = cues.map((c) => c.text).join(" ");
|
|
2620
3253
|
return {
|
|
2621
3254
|
id: `chunk-${index}`,
|
|
2622
|
-
text,
|
|
2623
|
-
tokenCount: estimateTokenCount(
|
|
3255
|
+
text: text2,
|
|
3256
|
+
tokenCount: estimateTokenCount(text2),
|
|
2624
3257
|
startTime: cues[0].startTime,
|
|
2625
3258
|
endTime: cues[cues.length - 1].endTime
|
|
2626
3259
|
};
|
|
@@ -2798,10 +3431,10 @@ function chunkVTTCuesByDuration(cues, options) {
|
|
|
2798
3431
|
}
|
|
2799
3432
|
return chunks;
|
|
2800
3433
|
}
|
|
2801
|
-
function chunkText(
|
|
3434
|
+
function chunkText(text2, strategy) {
|
|
2802
3435
|
switch (strategy.type) {
|
|
2803
3436
|
case "token": {
|
|
2804
|
-
return chunkByTokens(
|
|
3437
|
+
return chunkByTokens(text2, strategy.maxTokens, strategy.overlap ?? 0);
|
|
2805
3438
|
}
|
|
2806
3439
|
default: {
|
|
2807
3440
|
const exhaustiveCheck = strategy;
|
|
@@ -2816,30 +3449,30 @@ function hasWorkflowScopeBoundaries(scope) {
|
|
|
2816
3449
|
}
|
|
2817
3450
|
function resolveWorkflowScope(scope, assetDurationSeconds) {
|
|
2818
3451
|
if (assetDurationSeconds === void 0 || !Number.isFinite(assetDurationSeconds) || assetDurationSeconds <= 0) {
|
|
2819
|
-
throw new
|
|
3452
|
+
throw new LegacyMuxAiError("Asset has no valid duration.", { type: "validation_error" });
|
|
2820
3453
|
}
|
|
2821
3454
|
const startTime = scope?.startTime ?? 0;
|
|
2822
3455
|
const endTime = scope?.endTime ?? assetDurationSeconds;
|
|
2823
3456
|
if (!Number.isFinite(startTime) || startTime < 0) {
|
|
2824
|
-
throw new
|
|
3457
|
+
throw new LegacyMuxAiError(
|
|
2825
3458
|
`scope.startTime must be a finite, non-negative number (received ${startTime}).`,
|
|
2826
3459
|
{ type: "validation_error" }
|
|
2827
3460
|
);
|
|
2828
3461
|
}
|
|
2829
3462
|
if (!Number.isFinite(endTime) || endTime < 0) {
|
|
2830
|
-
throw new
|
|
3463
|
+
throw new LegacyMuxAiError(
|
|
2831
3464
|
`scope.endTime must be a finite, non-negative number (received ${endTime}).`,
|
|
2832
3465
|
{ type: "validation_error" }
|
|
2833
3466
|
);
|
|
2834
3467
|
}
|
|
2835
3468
|
if (endTime > assetDurationSeconds) {
|
|
2836
|
-
throw new
|
|
3469
|
+
throw new LegacyMuxAiError(
|
|
2837
3470
|
`scope.endTime (${endTime}) cannot exceed the asset duration (${assetDurationSeconds}).`,
|
|
2838
3471
|
{ type: "validation_error" }
|
|
2839
3472
|
);
|
|
2840
3473
|
}
|
|
2841
3474
|
if (startTime >= endTime) {
|
|
2842
|
-
throw new
|
|
3475
|
+
throw new LegacyMuxAiError(
|
|
2843
3476
|
`scope.startTime (${startTime}) must be less than scope.endTime (${endTime}).`,
|
|
2844
3477
|
{ type: "validation_error" }
|
|
2845
3478
|
);
|
|
@@ -2860,7 +3493,7 @@ function resolveRenderableVideoScope(scope, assetDurationSeconds, videoTrackDura
|
|
|
2860
3493
|
endTime: renderableEndTime
|
|
2861
3494
|
};
|
|
2862
3495
|
if (renderableScope.startTime >= renderableScope.endTime) {
|
|
2863
|
-
throw new
|
|
3496
|
+
throw new LegacyMuxAiError("The requested scope does not include any renderable video.", {
|
|
2864
3497
|
type: "validation_error"
|
|
2865
3498
|
});
|
|
2866
3499
|
}
|
|
@@ -2924,7 +3557,7 @@ function getPlaybackId(asset) {
|
|
|
2924
3557
|
if (signedPlaybackId?.id) {
|
|
2925
3558
|
return { id: signedPlaybackId.id, policy: "signed" };
|
|
2926
3559
|
}
|
|
2927
|
-
throw new
|
|
3560
|
+
throw new LegacyMuxAiError(
|
|
2928
3561
|
"No public or signed playback ID found for this asset. DRM playback IDs are not currently supported.",
|
|
2929
3562
|
{ type: "validation_error" }
|
|
2930
3563
|
);
|
|
@@ -2947,7 +3580,7 @@ async function getPlaybackIdForAsset(assetId, credentials, assetSnapshot) {
|
|
|
2947
3580
|
"use step";
|
|
2948
3581
|
const asset = assetSnapshot ?? await getMuxAsset(assetId, credentials);
|
|
2949
3582
|
if (asset.id !== assetId) {
|
|
2950
|
-
throw new
|
|
3583
|
+
throw new LegacyMuxAiError("Asset snapshot does not match the requested asset ID.", { type: "validation_error" });
|
|
2951
3584
|
}
|
|
2952
3585
|
return toPlaybackAsset(asset);
|
|
2953
3586
|
}
|
|
@@ -3183,9 +3816,9 @@ function extractTimestampedTranscript(vttContent) {
|
|
|
3183
3816
|
j++;
|
|
3184
3817
|
}
|
|
3185
3818
|
if (j < lines.length) {
|
|
3186
|
-
const
|
|
3187
|
-
if (
|
|
3188
|
-
segments.push({ time: timeInSeconds, text });
|
|
3819
|
+
const text2 = capCueTextLength(lines[j].trim().replace(/<[^>]*>/g, ""));
|
|
3820
|
+
if (text2) {
|
|
3821
|
+
segments.push({ time: timeInSeconds, text: text2 });
|
|
3189
3822
|
}
|
|
3190
3823
|
}
|
|
3191
3824
|
}
|
|
@@ -3387,7 +4020,7 @@ async function fetchTranscriptDataForUrl(transcriptUrl, options = {}) {
|
|
|
3387
4020
|
}
|
|
3388
4021
|
return { transcriptText };
|
|
3389
4022
|
} catch (error) {
|
|
3390
|
-
|
|
4023
|
+
legacyWrapError(error, "Failed to fetch transcript");
|
|
3391
4024
|
}
|
|
3392
4025
|
}
|
|
3393
4026
|
async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
@@ -3396,7 +4029,7 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
|
3396
4029
|
if (!track) {
|
|
3397
4030
|
if (required) {
|
|
3398
4031
|
const availableLanguages = getReadyTextTracks(asset).map((t) => t.language_code).filter(Boolean).join(", ");
|
|
3399
|
-
throw new
|
|
4032
|
+
throw new LegacyMuxAiError(
|
|
3400
4033
|
`No caption track found${languageCode ? ` for language ${languageCode}` : ""}. Available languages: ${availableLanguages || "none"}.`,
|
|
3401
4034
|
{ type: "validation_error" }
|
|
3402
4035
|
);
|
|
@@ -3405,7 +4038,7 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
|
3405
4038
|
}
|
|
3406
4039
|
if (!track.id) {
|
|
3407
4040
|
if (required) {
|
|
3408
|
-
throw new
|
|
4041
|
+
throw new LegacyMuxAiError("Transcript track is missing an id.", { type: "validation_error" });
|
|
3409
4042
|
}
|
|
3410
4043
|
return { transcriptText: "", track };
|
|
3411
4044
|
}
|
|
@@ -3425,9 +4058,9 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
|
|
|
3425
4058
|
}
|
|
3426
4059
|
switch (result.emptyReason) {
|
|
3427
4060
|
case "no_scoped_cues":
|
|
3428
|
-
throw new
|
|
4061
|
+
throw new LegacyMuxAiError("Transcript has no cues in the requested scope.", { type: "validation_error" });
|
|
3429
4062
|
case "empty_body":
|
|
3430
|
-
throw new
|
|
4063
|
+
throw new LegacyMuxAiError("Transcript is empty.", { type: "validation_error" });
|
|
3431
4064
|
}
|
|
3432
4065
|
}
|
|
3433
4066
|
|
|
@@ -3637,7 +4270,7 @@ var CONTENT_POLICY_REASONS = /* @__PURE__ */ new Set([
|
|
|
3637
4270
|
"SAFETY",
|
|
3638
4271
|
"SPII"
|
|
3639
4272
|
]);
|
|
3640
|
-
var IncompleteGenerationError = class extends
|
|
4273
|
+
var IncompleteGenerationError = class extends LegacyMuxAiError {
|
|
3641
4274
|
constructor(finishReason, rawFinishReason, usage) {
|
|
3642
4275
|
const reason = rawFinishReason ?? finishReason;
|
|
3643
4276
|
const message = finishReason === "length" ? `The model reached its output limit before producing a complete response (finish reason: ${reason}).` : `The model stopped before producing a complete response (finish reason: ${reason}).`;
|
|
@@ -3735,7 +4368,7 @@ function getGeneratedOutputWithContentPolicyHandling(response) {
|
|
|
3735
4368
|
}
|
|
3736
4369
|
function throwContentPolicyError(block, usage) {
|
|
3737
4370
|
const category = block.category ? `; category: ${block.category}` : "";
|
|
3738
|
-
const contentPolicyError = new
|
|
4371
|
+
const contentPolicyError = new LegacyMuxAiError(
|
|
3739
4372
|
`The supplied content was blocked by a content policy (reason: ${block.reason}${category}).`,
|
|
3740
4373
|
{
|
|
3741
4374
|
type: "content_policy_error",
|
|
@@ -3935,11 +4568,11 @@ function planTextRepair(content, limits, protectedTerms = []) {
|
|
|
3935
4568
|
if (!findGenerateTextLengthViolation(content, [...limits]))
|
|
3936
4569
|
return null;
|
|
3937
4570
|
const parts = split(content);
|
|
3938
|
-
const ranked = parts.map((
|
|
4571
|
+
const ranked = parts.map((text2, index) => ({ text: text2, index })).filter((span) => span.index % 2 === 0 && span.text.trim()).sort((a, b) => Math.max(...limits.map((limit) => measureGenerateTextLength(b.text, limit.unit) / limit.value)) - Math.max(...limits.map((limit) => measureGenerateTextLength(a.text, limit.unit) / limit.value)));
|
|
3939
4572
|
const selected = /* @__PURE__ */ new Set();
|
|
3940
4573
|
for (const span of ranked) {
|
|
3941
4574
|
selected.add(span.index);
|
|
3942
|
-
const fixed2 = parts.map((
|
|
4575
|
+
const fixed2 = parts.map((text2, index) => selected.has(index) ? "" : text2).join("");
|
|
3943
4576
|
const gentleEnough = limits.every((limit) => {
|
|
3944
4577
|
const selectedLength = [...selected].reduce((sum, index) => sum + measureGenerateTextLength(parts[index], limit.unit), 0);
|
|
3945
4578
|
const allowance = limit.value - measureGenerateTextLength(fixed2, limit.unit) - headroom(limit);
|
|
@@ -3948,7 +4581,7 @@ function planTextRepair(content, limits, protectedTerms = []) {
|
|
|
3948
4581
|
if (gentleEnough)
|
|
3949
4582
|
break;
|
|
3950
4583
|
}
|
|
3951
|
-
const fixed = parts.map((
|
|
4584
|
+
const fixed = parts.map((text2, index) => selected.has(index) ? "" : text2).join("");
|
|
3952
4585
|
const spans = [...selected].sort((a, b) => a - b).map((index) => ({
|
|
3953
4586
|
id: `p_${index}`,
|
|
3954
4587
|
text: parts[index],
|
|
@@ -4549,7 +5182,7 @@ function normalizeQuestion(q, idx) {
|
|
|
4549
5182
|
const hasOptions = Array.isArray(q.answerOptions);
|
|
4550
5183
|
const isFreeForm = q.freeFormReply === true;
|
|
4551
5184
|
if (hasOptions && isFreeForm) {
|
|
4552
|
-
throw new
|
|
5185
|
+
throw new LegacyMuxAiError(
|
|
4553
5186
|
`Question at index ${idx} sets both answerOptions and freeFormReply: true. These are mutually exclusive \u2014 pick one.`,
|
|
4554
5187
|
{ type: "validation_error" }
|
|
4555
5188
|
);
|
|
@@ -4564,7 +5197,7 @@ function normalizeQuestion(q, idx) {
|
|
|
4564
5197
|
)
|
|
4565
5198
|
);
|
|
4566
5199
|
if (!options.length) {
|
|
4567
|
-
throw new
|
|
5200
|
+
throw new LegacyMuxAiError(
|
|
4568
5201
|
`Question at index ${idx} has invalid answerOptions: must include at least one non-empty value.`,
|
|
4569
5202
|
{ type: "validation_error" }
|
|
4570
5203
|
);
|
|
@@ -4735,23 +5368,23 @@ async function askQuestions(assetId, questions, options) {
|
|
|
4735
5368
|
}
|
|
4736
5369
|
async function askQuestionsInternal(assetId, questions, options, collectedUsage) {
|
|
4737
5370
|
if (!questions || questions.length === 0) {
|
|
4738
|
-
throw new
|
|
5371
|
+
throw new LegacyMuxAiError("At least one question must be provided.", { type: "validation_error" });
|
|
4739
5372
|
}
|
|
4740
5373
|
if (questions.length > ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL) {
|
|
4741
|
-
throw new
|
|
5374
|
+
throw new LegacyMuxAiError(
|
|
4742
5375
|
`Too many questions: received ${questions.length}, but at most ${ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL} are allowed per call.`,
|
|
4743
5376
|
{ type: "validation_error" }
|
|
4744
5377
|
);
|
|
4745
5378
|
}
|
|
4746
5379
|
questions.forEach((q, idx) => {
|
|
4747
5380
|
if (!q.question || typeof q.question !== "string" || !q.question.trim()) {
|
|
4748
|
-
throw new
|
|
5381
|
+
throw new LegacyMuxAiError(
|
|
4749
5382
|
`Question at index ${idx} is invalid: must have a non-empty question field.`,
|
|
4750
5383
|
{ type: "validation_error" }
|
|
4751
5384
|
);
|
|
4752
5385
|
}
|
|
4753
5386
|
if (q.question.length > ASK_QUESTIONS_MAX_QUESTION_LENGTH) {
|
|
4754
|
-
throw new
|
|
5387
|
+
throw new LegacyMuxAiError(
|
|
4755
5388
|
`Question at index ${idx} exceeds the ${ASK_QUESTIONS_MAX_QUESTION_LENGTH}-character limit (received ${q.question.length}).`,
|
|
4756
5389
|
{ type: "validation_error" }
|
|
4757
5390
|
);
|
|
@@ -4759,7 +5392,7 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
4759
5392
|
});
|
|
4760
5393
|
const maxAnswerOptionLength = options?.maxAnswerOptionLength ?? ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH;
|
|
4761
5394
|
if (!Number.isFinite(maxAnswerOptionLength) || maxAnswerOptionLength <= 0) {
|
|
4762
|
-
throw new
|
|
5395
|
+
throw new LegacyMuxAiError(
|
|
4763
5396
|
`maxAnswerOptionLength must be a positive number (received ${maxAnswerOptionLength}).`,
|
|
4764
5397
|
{ type: "validation_error" }
|
|
4765
5398
|
);
|
|
@@ -4769,7 +5402,7 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
4769
5402
|
return;
|
|
4770
5403
|
for (const opt of q.answerOptions ?? []) {
|
|
4771
5404
|
if (typeof opt === "string" && opt.length > maxAnswerOptionLength) {
|
|
4772
|
-
throw new
|
|
5405
|
+
throw new LegacyMuxAiError(
|
|
4773
5406
|
`Question at index ${idx} has an answerOption exceeding the ${maxAnswerOptionLength}-character limit (received ${opt.length}). Answer options should be short labels, not sentences.`,
|
|
4774
5407
|
{ type: "validation_error" }
|
|
4775
5408
|
);
|
|
@@ -4778,7 +5411,7 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
4778
5411
|
});
|
|
4779
5412
|
const maxFreeFormAnswerLength = options?.maxFreeFormAnswerLength ?? ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH;
|
|
4780
5413
|
if (!Number.isFinite(maxFreeFormAnswerLength) || maxFreeFormAnswerLength <= 0) {
|
|
4781
|
-
throw new
|
|
5414
|
+
throw new LegacyMuxAiError(
|
|
4782
5415
|
`maxFreeFormAnswerLength must be a positive number (received ${maxFreeFormAnswerLength}).`,
|
|
4783
5416
|
{ type: "validation_error" }
|
|
4784
5417
|
);
|
|
@@ -4815,14 +5448,14 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
4815
5448
|
resolveWorkflowScope(effectiveScope, assetDurationSeconds);
|
|
4816
5449
|
}
|
|
4817
5450
|
if (isAudioOnly && !includeTranscript) {
|
|
4818
|
-
throw new
|
|
5451
|
+
throw new LegacyMuxAiError(
|
|
4819
5452
|
"Audio-only assets require a transcript. Set includeTranscript: true and ensure the asset has a ready text track (captions/subtitles).",
|
|
4820
5453
|
{ type: "validation_error" }
|
|
4821
5454
|
);
|
|
4822
5455
|
}
|
|
4823
5456
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
4824
5457
|
if (policy === "signed" && !signingContext) {
|
|
4825
|
-
throw new
|
|
5458
|
+
throw new LegacyMuxAiError(
|
|
4826
5459
|
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
4827
5460
|
{ type: "validation_error" }
|
|
4828
5461
|
);
|
|
@@ -4893,14 +5526,14 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
4893
5526
|
}
|
|
4894
5527
|
} catch (error) {
|
|
4895
5528
|
const contentType = isAudioOnly ? "audio" : "video";
|
|
4896
|
-
|
|
5529
|
+
legacyWrapError(error, `Failed to analyze ${contentType} questions with ${provider}`);
|
|
4897
5530
|
}
|
|
4898
5531
|
collectedUsage.push(analysisResponse.usage);
|
|
4899
5532
|
if (!analysisResponse.result?.answers) {
|
|
4900
|
-
throw new
|
|
5533
|
+
throw new LegacyMuxAiError(`Failed to generate answers for asset ${assetId}.`);
|
|
4901
5534
|
}
|
|
4902
5535
|
if (analysisResponse.result.answers.length !== questions.length) {
|
|
4903
|
-
throw new
|
|
5536
|
+
throw new LegacyMuxAiError(
|
|
4904
5537
|
`Failed to generate answers for all questions for asset ${assetId}.`
|
|
4905
5538
|
);
|
|
4906
5539
|
}
|
|
@@ -4935,7 +5568,7 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
4935
5568
|
if (!isSkipped && !isFreeForm) {
|
|
4936
5569
|
const allowed = allowedAnswersForQuestion(question);
|
|
4937
5570
|
if (!allowed.includes(raw.answer)) {
|
|
4938
|
-
throw new
|
|
5571
|
+
throw new LegacyMuxAiError(
|
|
4939
5572
|
`Answer "${raw.answer}" for question ${idx} is not in allowed options: ${allowed.join(", ")}`
|
|
4940
5573
|
);
|
|
4941
5574
|
}
|
|
@@ -5495,7 +6128,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
5495
6128
|
const isAudioOnly = isAudioOnlyAsset(assetData);
|
|
5496
6129
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
5497
6130
|
if (policy === "signed" && !signingContext) {
|
|
5498
|
-
throw new
|
|
6131
|
+
throw new LegacyMuxAiError(
|
|
5499
6132
|
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
5500
6133
|
{ type: "validation_error" }
|
|
5501
6134
|
);
|
|
@@ -5511,7 +6144,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
5511
6144
|
});
|
|
5512
6145
|
if (!transcriptResult.track || !transcriptResult.transcriptText) {
|
|
5513
6146
|
const availableLanguages = readyTextTracks.map((t) => t.language_code).filter(Boolean).join(", ");
|
|
5514
|
-
throw new
|
|
6147
|
+
throw new LegacyMuxAiError(
|
|
5515
6148
|
`No caption track found${languageCode ? ` for language ${languageCode}` : ""}. Available languages: ${availableLanguages || "none"}.`,
|
|
5516
6149
|
{ type: "validation_error" }
|
|
5517
6150
|
);
|
|
@@ -5519,7 +6152,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
5519
6152
|
const timestampedTranscript = extractTimestampedTranscript(transcriptResult.transcriptText);
|
|
5520
6153
|
if (!timestampedTranscript) {
|
|
5521
6154
|
const contentLabel = isAudioOnly ? "transcript" : "caption track";
|
|
5522
|
-
throw new
|
|
6155
|
+
throw new LegacyMuxAiError(`No usable content found in ${contentLabel}.`, { type: "validation_error" });
|
|
5523
6156
|
}
|
|
5524
6157
|
const resolvedLanguageCode = outputLanguageCode && outputLanguageCode !== "auto" ? outputLanguageCode : getReliableLanguageCode(transcriptResult.track) ?? languageCode;
|
|
5525
6158
|
const languageName = resolvedLanguageCode ? getLanguageName(resolvedLanguageCode) : void 0;
|
|
@@ -5527,7 +6160,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
5527
6160
|
(boundary) => resolvedScope ? boundary >= resolvedScope.startTime && boundary < resolvedScope.endTime : true
|
|
5528
6161
|
);
|
|
5529
6162
|
if (sceneContext?.length && sceneBoundarySeconds.length === 0) {
|
|
5530
|
-
throw new
|
|
6163
|
+
throw new LegacyMuxAiError(
|
|
5531
6164
|
"Scene context has no chapter boundaries within the requested scope.",
|
|
5532
6165
|
{ type: "validation_error" }
|
|
5533
6166
|
);
|
|
@@ -5556,13 +6189,13 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
5556
6189
|
credentials
|
|
5557
6190
|
});
|
|
5558
6191
|
} catch (error) {
|
|
5559
|
-
|
|
6192
|
+
legacyWrapError(error, `Failed to generate chapters with ${provider}`);
|
|
5560
6193
|
}
|
|
5561
6194
|
if (chaptersData) {
|
|
5562
6195
|
collectedUsage.push(chaptersData.usage);
|
|
5563
6196
|
}
|
|
5564
6197
|
if (!chaptersData || !chaptersData.chapters) {
|
|
5565
|
-
throw new
|
|
6198
|
+
throw new LegacyMuxAiError(`Failed to generate chapters for asset ${assetId}.`);
|
|
5566
6199
|
}
|
|
5567
6200
|
const { chapters: chaptersPayload, usage } = chaptersData;
|
|
5568
6201
|
const scopedChapters = chaptersPayload.chapters.filter((chapter) => typeof chapter.startTime === "number" && typeof chapter.title === "string").filter(
|
|
@@ -5573,7 +6206,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
5573
6206
|
sceneBoundarySeconds
|
|
5574
6207
|
);
|
|
5575
6208
|
if (validChapters.length === 0) {
|
|
5576
|
-
throw new
|
|
6209
|
+
throw new LegacyMuxAiError(`Failed to generate valid chapters for asset ${assetId}.`);
|
|
5577
6210
|
}
|
|
5578
6211
|
const safety = createSafetyReporter();
|
|
5579
6212
|
for (const key of chaptersData.unexpectedRootKeys) {
|
|
@@ -5595,7 +6228,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
5595
6228
|
return !scrub.leaked;
|
|
5596
6229
|
});
|
|
5597
6230
|
if (scrubbedChapters.length === 0) {
|
|
5598
|
-
throw new
|
|
6231
|
+
throw new LegacyMuxAiError(`Failed to generate valid chapters for asset ${assetId}.`);
|
|
5599
6232
|
}
|
|
5600
6233
|
if (sceneBoundarySeconds.length === 0) {
|
|
5601
6234
|
const firstChapterStartTime = resolvedScope?.startTime ?? 0;
|
|
@@ -5746,8 +6379,8 @@ function transformCueTextBlocks(rawVtt, transform) {
|
|
|
5746
6379
|
flushCueText();
|
|
5747
6380
|
return transformed.join("\n");
|
|
5748
6381
|
}
|
|
5749
|
-
function escapeRegex(
|
|
5750
|
-
return
|
|
6382
|
+
function escapeRegex(text2) {
|
|
6383
|
+
return text2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5751
6384
|
}
|
|
5752
6385
|
function buildStaticReplacementRegex(find, caseSensitive) {
|
|
5753
6386
|
const pattern = find.split(/(\s+)/).map((part) => /\s+/.test(part) ? "\\s+" : escapeRegex(part)).join("");
|
|
@@ -5971,27 +6604,27 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
5971
6604
|
const hasReplacements = !!replacementsOption && replacementsOption.length > 0;
|
|
5972
6605
|
const hasSpeakerReplacements = !!speakerReplacementsOption && speakerReplacementsOption.length > 0;
|
|
5973
6606
|
if (!hasAutoCensor && !hasReplacements && !hasSpeakerReplacements) {
|
|
5974
|
-
throw new
|
|
6607
|
+
throw new LegacyMuxAiError("At least one of autoCensorProfanity, replacements, or speakerReplacements must be provided.", { type: "validation_error" });
|
|
5975
6608
|
}
|
|
5976
6609
|
if (autoCensorOption && !provider) {
|
|
5977
|
-
throw new
|
|
6610
|
+
throw new LegacyMuxAiError("provider is required when using autoCensorProfanity.", { type: "validation_error" });
|
|
5978
6611
|
}
|
|
5979
6612
|
const legacyTrackNaming = deleteOriginalTrack !== void 0 || trackNameSuffix !== void 0;
|
|
5980
6613
|
if (legacyTrackNaming && (replaceExistingTracksOption !== void 0 || providedTrackName !== void 0)) {
|
|
5981
|
-
throw new
|
|
6614
|
+
throw new LegacyMuxAiError(
|
|
5982
6615
|
"deleteOriginalTrack and trackNameSuffix are deprecated and cannot be combined with replaceExistingTracks or trackName.",
|
|
5983
6616
|
{ type: "validation_error" }
|
|
5984
6617
|
);
|
|
5985
6618
|
}
|
|
5986
6619
|
if (replaceExistingTracksOption !== void 0 && replaceExistingTracksOption !== "replace" && replaceExistingTracksOption !== "fail") {
|
|
5987
|
-
throw new
|
|
6620
|
+
throw new LegacyMuxAiError(
|
|
5988
6621
|
`replaceExistingTracks must be "replace" or "fail" for editCaptions (received "${String(replaceExistingTracksOption)}").`,
|
|
5989
6622
|
{ type: "validation_error" }
|
|
5990
6623
|
);
|
|
5991
6624
|
}
|
|
5992
6625
|
const replaceExistingTracks = replaceExistingTracksOption ?? "replace";
|
|
5993
6626
|
if (!legacyTrackNaming && replaceExistingTracks === "fail" && !providedTrackName) {
|
|
5994
|
-
throw new
|
|
6627
|
+
throw new LegacyMuxAiError(
|
|
5995
6628
|
`trackName is required when replaceExistingTracks is "fail": the edited track cannot reuse the source track's name while the source is kept.`,
|
|
5996
6629
|
{ type: "validation_error" }
|
|
5997
6630
|
);
|
|
@@ -6004,7 +6637,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6004
6637
|
const hasInvalidFindCharacter = replacement.find.includes("[") || replacement.find.includes("]") || /[\r\n]/.test(replacement.find);
|
|
6005
6638
|
const hasInvalidReplaceCharacter = replacement.replace.includes("[") || replacement.replace.includes("]") || /[\r\n]/.test(replacement.replace);
|
|
6006
6639
|
if (!replacement.find || !replacement.replace || hasInvalidFindCharacter || hasInvalidReplaceCharacter) {
|
|
6007
|
-
throw new
|
|
6640
|
+
throw new LegacyMuxAiError(
|
|
6008
6641
|
"Speaker replacement labels must be non-empty and must not contain square brackets or newlines.",
|
|
6009
6642
|
{ type: "validation_error" }
|
|
6010
6643
|
);
|
|
@@ -6016,7 +6649,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6016
6649
|
const s3AccessKeyId = env_default.S3_ACCESS_KEY_ID;
|
|
6017
6650
|
const s3SecretAccessKey = env_default.S3_SECRET_ACCESS_KEY;
|
|
6018
6651
|
if (uploadToS3 && (!s3Endpoint || !s3Bucket || !storageAdapter && (!s3AccessKeyId || !s3SecretAccessKey))) {
|
|
6019
|
-
throw new
|
|
6652
|
+
throw new LegacyMuxAiError(
|
|
6020
6653
|
"Storage configuration is required for uploading. Provide s3Endpoint and s3Bucket. If no storageAdapter is supplied, also provide s3AccessKeyId and s3SecretAccessKey in options or set S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, and S3_SECRET_ACCESS_KEY environment variables.",
|
|
6021
6654
|
{ type: "validation_error" }
|
|
6022
6655
|
);
|
|
@@ -6025,7 +6658,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6025
6658
|
const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
|
|
6026
6659
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
6027
6660
|
if (policy === "signed" && !signingContext) {
|
|
6028
|
-
throw new
|
|
6661
|
+
throw new LegacyMuxAiError(
|
|
6029
6662
|
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
6030
6663
|
{ type: "validation_error" }
|
|
6031
6664
|
);
|
|
@@ -6034,7 +6667,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6034
6667
|
const sourceTrack = readyTextTracks.find((t) => t.id === trackId);
|
|
6035
6668
|
if (!sourceTrack) {
|
|
6036
6669
|
const availableTrackIds = readyTextTracks.map((t) => t.id).filter(Boolean).join(", ");
|
|
6037
|
-
throw new
|
|
6670
|
+
throw new LegacyMuxAiError(
|
|
6038
6671
|
`Track ${trackId} not found or not ready on asset ${assetId}. Available track IDs: ${availableTrackIds || "none"}.`,
|
|
6039
6672
|
{ type: "validation_error" }
|
|
6040
6673
|
);
|
|
@@ -6046,7 +6679,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6046
6679
|
name: providedTrackName ?? sourceName
|
|
6047
6680
|
};
|
|
6048
6681
|
if (replaceExistingTracks === "fail" && normalizeTrackName(outputTrack.name) === normalizeTrackName(sourceName)) {
|
|
6049
|
-
throw new
|
|
6682
|
+
throw new LegacyMuxAiError(
|
|
6050
6683
|
`trackName "${outputTrack.name}" matches the source track's name. Mux track names must be unique; choose a different trackName or use replaceExistingTracks: "replace" to replace the source.`,
|
|
6051
6684
|
{ type: "validation_error" }
|
|
6052
6685
|
);
|
|
@@ -6054,7 +6687,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6054
6687
|
if (uploadToMux && !legacyTrackNaming) {
|
|
6055
6688
|
const plan = planSourceTrackReplacement(assetData, trackId, outputTrack, replaceExistingTracks);
|
|
6056
6689
|
if (plan.kind === "blocked") {
|
|
6057
|
-
throw new
|
|
6690
|
+
throw new LegacyMuxAiError(plan.reason, { type: "validation_error" });
|
|
6058
6691
|
}
|
|
6059
6692
|
}
|
|
6060
6693
|
const vttUrl = await buildTranscriptUrl(playbackId, trackId, policy === "signed", credentials);
|
|
@@ -6062,7 +6695,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6062
6695
|
try {
|
|
6063
6696
|
vttContent = await fetchVttFromMux(vttUrl);
|
|
6064
6697
|
} catch (error) {
|
|
6065
|
-
|
|
6698
|
+
legacyWrapError(error, "Failed to fetch VTT content");
|
|
6066
6699
|
}
|
|
6067
6700
|
let editedVtt = vttContent;
|
|
6068
6701
|
let totalReplacementCount = 0;
|
|
@@ -6073,7 +6706,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6073
6706
|
const { mode = "blank", alwaysCensor = [], neverCensor = [] } = autoCensorOption;
|
|
6074
6707
|
const plainText = extractTextFromVTT(vttContent);
|
|
6075
6708
|
if (!plainText.trim()) {
|
|
6076
|
-
throw new
|
|
6709
|
+
throw new LegacyMuxAiError("Track transcript is empty; nothing to censor.", { type: "validation_error" });
|
|
6077
6710
|
}
|
|
6078
6711
|
const modelConfig = resolveLanguageModelConfig({
|
|
6079
6712
|
...options,
|
|
@@ -6100,7 +6733,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6100
6733
|
}
|
|
6101
6734
|
}
|
|
6102
6735
|
} catch (error) {
|
|
6103
|
-
|
|
6736
|
+
legacyWrapError(error, `Failed to detect profanity with ${modelConfig.provider}`);
|
|
6104
6737
|
}
|
|
6105
6738
|
const scrubbedProfanity = detectedProfanity.map((word, i) => safety.scrubDetailed(word, `profanity[${i}]`)).filter((result) => !result.leaked).map((result) => result.text);
|
|
6106
6739
|
const finalProfanity = applyOverrideLists(scrubbedProfanity, alwaysCensor, neverCensor);
|
|
@@ -6148,7 +6781,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6148
6781
|
try {
|
|
6149
6782
|
presignedUrl = await uploadEditedVttToS3({ editedVtt, ...s3Config });
|
|
6150
6783
|
} catch (error) {
|
|
6151
|
-
|
|
6784
|
+
legacyWrapError(error, "Failed to upload VTT to S3");
|
|
6152
6785
|
}
|
|
6153
6786
|
if (uploadToMux && legacyTrackNaming) {
|
|
6154
6787
|
try {
|
|
@@ -6162,13 +6795,13 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6162
6795
|
{ closedCaptions: sourceTrack.closed_captions, passthrough: trackPassthrough }
|
|
6163
6796
|
);
|
|
6164
6797
|
} catch (error) {
|
|
6165
|
-
|
|
6798
|
+
legacyWrapError(error, "Failed to add edited track to Mux asset");
|
|
6166
6799
|
}
|
|
6167
6800
|
if (deleteOriginal && uploadedTrackId) {
|
|
6168
6801
|
try {
|
|
6169
6802
|
await deleteTrackOnMux(assetId, trackId, credentials);
|
|
6170
6803
|
} catch (error) {
|
|
6171
|
-
|
|
6804
|
+
legacyWrapError(error, "Failed to delete original track");
|
|
6172
6805
|
}
|
|
6173
6806
|
}
|
|
6174
6807
|
} else if (uploadToMux) {
|
|
@@ -6185,7 +6818,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6185
6818
|
credentials
|
|
6186
6819
|
});
|
|
6187
6820
|
} catch (error) {
|
|
6188
|
-
|
|
6821
|
+
legacyWrapError(error, "Failed to add edited track to Mux asset");
|
|
6189
6822
|
}
|
|
6190
6823
|
if (outcome.kind !== "created") {
|
|
6191
6824
|
const sourceWasDeleted = outcome.deleted.some((track) => track.id === trackId);
|
|
@@ -6207,7 +6840,7 @@ async function editCaptionsInternal(assetId, trackId, options, collectedUsage) {
|
|
|
6207
6840
|
}
|
|
6208
6841
|
}
|
|
6209
6842
|
if (outcome.kind === "blocked") {
|
|
6210
|
-
throw new
|
|
6843
|
+
throw new LegacyMuxAiError(`${outcome.reason}${restoreNote}`, { type: "validation_error" });
|
|
6211
6844
|
}
|
|
6212
6845
|
throw new Error(`Failed to add edited track to Mux asset: ${outcome.reason}.${restoreNote}`);
|
|
6213
6846
|
}
|
|
@@ -6605,11 +7238,11 @@ function extractTranscriptSegmentsForHotspots(vttContent, hotspots) {
|
|
|
6605
7238
|
const relevantCues = cues.filter(
|
|
6606
7239
|
(cue) => cue.startTime < endSec && cue.endTime > startSec
|
|
6607
7240
|
);
|
|
6608
|
-
const
|
|
7241
|
+
const text2 = relevantCues.map((c) => c.text).join(" ");
|
|
6609
7242
|
return {
|
|
6610
7243
|
startMs: hotspot.startMs,
|
|
6611
7244
|
endMs: hotspot.endMs,
|
|
6612
|
-
text,
|
|
7245
|
+
text: text2,
|
|
6613
7246
|
timestamp: secondsToTimestamp(startSec)
|
|
6614
7247
|
};
|
|
6615
7248
|
});
|
|
@@ -6650,6 +7283,15 @@ async function getThumbnailUrlsForHotspots(playbackId, hotspots, options = {}) {
|
|
|
6650
7283
|
});
|
|
6651
7284
|
return Promise.all(urlPromises);
|
|
6652
7285
|
}
|
|
7286
|
+
function engagementDataError(error, call, assetId, timeframe) {
|
|
7287
|
+
return dependencyErrorFrom(error, `Failed to fetch engagement data for asset ${assetId}.`, {
|
|
7288
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_DATA,
|
|
7289
|
+
call,
|
|
7290
|
+
facts: { assetId, timeframe },
|
|
7291
|
+
notFoundSource: MUX_AI_ERROR_SOURCES.ASSET,
|
|
7292
|
+
authSource: MUX_AI_ERROR_SOURCES.ACCOUNT
|
|
7293
|
+
});
|
|
7294
|
+
}
|
|
6653
7295
|
async function fetchEngagementData(assetId, options) {
|
|
6654
7296
|
"use step";
|
|
6655
7297
|
const { hotspotLimit, timeframe, credentials } = options;
|
|
@@ -6659,16 +7301,22 @@ async function fetchEngagementData(assetId, options) {
|
|
|
6659
7301
|
orderDirection: "desc",
|
|
6660
7302
|
timeframe,
|
|
6661
7303
|
credentials
|
|
7304
|
+
}).catch((error) => {
|
|
7305
|
+
throw engagementDataError(error, "get_hotspots", assetId, timeframe);
|
|
6662
7306
|
}),
|
|
6663
7307
|
getHotspotsForAsset(assetId, {
|
|
6664
7308
|
limit: hotspotLimit,
|
|
6665
7309
|
orderDirection: "asc",
|
|
6666
7310
|
timeframe,
|
|
6667
7311
|
credentials
|
|
7312
|
+
}).catch((error) => {
|
|
7313
|
+
throw engagementDataError(error, "get_hotspots", assetId, timeframe);
|
|
6668
7314
|
}),
|
|
6669
7315
|
getHeatmapForAsset(assetId, {
|
|
6670
7316
|
timeframe,
|
|
6671
7317
|
credentials
|
|
7318
|
+
}).catch((error) => {
|
|
7319
|
+
throw engagementDataError(error, "get_heatmap", assetId, timeframe);
|
|
6672
7320
|
})
|
|
6673
7321
|
]);
|
|
6674
7322
|
const allHotspots = [...peaks, ...valleys].sort((a, b) => a.startMs - b.startMs);
|
|
@@ -6698,7 +7346,13 @@ async function generateInsightsWithAI(provider, modelId, systemPrompt, userPromp
|
|
|
6698
7346
|
}));
|
|
6699
7347
|
const output = getGeneratedOutputWithContentPolicyHandling(response);
|
|
6700
7348
|
if (!output) {
|
|
6701
|
-
throw new
|
|
7349
|
+
throw new MuxAiError("AI returned empty or unparseable response", {
|
|
7350
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_MISSING,
|
|
7351
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
7352
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
7353
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
7354
|
+
facts: { call: "generate_engagement_insights", provider, model: modelId }
|
|
7355
|
+
});
|
|
6702
7356
|
}
|
|
6703
7357
|
const unexpectedRootKeys = detectUnexpectedKeysFromRawText(
|
|
6704
7358
|
response.text,
|
|
@@ -6753,7 +7407,12 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
|
|
|
6753
7407
|
skipShots = false
|
|
6754
7408
|
} = options;
|
|
6755
7409
|
if (!Number.isInteger(hotspotLimit) || hotspotLimit < 1 || hotspotLimit > 10) {
|
|
6756
|
-
throw new MuxAiError("hotspotLimit must be an integer between 1 and 10.", {
|
|
7410
|
+
throw new MuxAiError("hotspotLimit must be an integer between 1 and 10.", {
|
|
7411
|
+
code: MUX_AI_ERROR_CODES.PARAMETER_OUT_OF_RANGE,
|
|
7412
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
7413
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
7414
|
+
facts: { parameter: "hotspotLimit", value: hotspotLimit, min: 1, max: 10, integer: true }
|
|
7415
|
+
});
|
|
6757
7416
|
}
|
|
6758
7417
|
const modelConfig = resolveLanguageModelConfig({
|
|
6759
7418
|
...options,
|
|
@@ -6763,15 +7422,17 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
|
|
|
6763
7422
|
const { asset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
|
|
6764
7423
|
const assetDurationSeconds = getAssetDurationSecondsFromAsset(asset);
|
|
6765
7424
|
if (!assetDurationSeconds) {
|
|
6766
|
-
throw new MuxAiError(`Asset ${assetId} has no valid duration.`, {
|
|
7425
|
+
throw new MuxAiError(`Asset ${assetId} has no valid duration.`, {
|
|
7426
|
+
code: MUX_AI_ERROR_CODES.ASSET_DURATION_UNAVAILABLE,
|
|
7427
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
7428
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
7429
|
+
facts: { assetId }
|
|
7430
|
+
});
|
|
6767
7431
|
}
|
|
6768
7432
|
const audioOnly = isAudioOnlyAsset(asset);
|
|
6769
7433
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
6770
7434
|
if (policy === "signed" && !signingContext) {
|
|
6771
|
-
throw
|
|
6772
|
-
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
6773
|
-
{ type: "validation_error" }
|
|
6774
|
-
);
|
|
7435
|
+
throw signingCredentialsMissingError();
|
|
6775
7436
|
}
|
|
6776
7437
|
const shouldSign = policy === "signed";
|
|
6777
7438
|
const shouldFetchShots = !skipShots && !audioOnly;
|
|
@@ -6798,9 +7459,7 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
|
|
|
6798
7459
|
storyboardPromise
|
|
6799
7460
|
]);
|
|
6800
7461
|
if (engagementResult.status === "rejected") {
|
|
6801
|
-
|
|
6802
|
-
`Failed to fetch engagement data for asset ${assetId}: ${engagementResult.reason}`
|
|
6803
|
-
);
|
|
7462
|
+
wrapError(engagementResult.reason, `Failed to fetch engagement data for asset ${assetId}`, { assetId, timeframe });
|
|
6804
7463
|
}
|
|
6805
7464
|
const { hotspots, heatmap } = engagementResult.value;
|
|
6806
7465
|
if (hotspots.length === 0) {
|
|
@@ -6871,8 +7530,20 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
|
|
|
6871
7530
|
);
|
|
6872
7531
|
const { result: aiInsights, usage } = aiStepResult;
|
|
6873
7532
|
collectedUsage.push(usage);
|
|
7533
|
+
const modelOutputFacts = {
|
|
7534
|
+
call: "generate_engagement_insights",
|
|
7535
|
+
provider: modelConfig.provider,
|
|
7536
|
+
model: modelConfig.modelId,
|
|
7537
|
+
assetId
|
|
7538
|
+
};
|
|
6874
7539
|
if (!aiInsights.momentInsights || aiInsights.momentInsights.length === 0) {
|
|
6875
|
-
throw new MuxAiError(`Failed to generate insights for asset ${assetId}
|
|
7540
|
+
throw new MuxAiError(`Failed to generate insights for asset ${assetId}.`, {
|
|
7541
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_MISSING,
|
|
7542
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
7543
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
7544
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
7545
|
+
facts: modelOutputFacts
|
|
7546
|
+
});
|
|
6876
7547
|
}
|
|
6877
7548
|
const safety = createSafetyReporter();
|
|
6878
7549
|
for (const key of aiStepResult.unexpectedRootKeys) {
|
|
@@ -6912,7 +7583,14 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
|
|
|
6912
7583
|
}
|
|
6913
7584
|
if (momentInsights.length === 0) {
|
|
6914
7585
|
throw new MuxAiError(
|
|
6915
|
-
`Failed to generate valid insights for asset ${assetId}
|
|
7586
|
+
`Failed to generate valid insights for asset ${assetId}.`,
|
|
7587
|
+
{
|
|
7588
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
|
|
7589
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
7590
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
7591
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
7592
|
+
facts: { ...modelOutputFacts, returnedCount: aiInsights.momentInsights.length }
|
|
7593
|
+
}
|
|
6916
7594
|
);
|
|
6917
7595
|
}
|
|
6918
7596
|
const summaryScrub = safety.scrubDetailed(aiInsights.overallInsight.summary, "overallInsight.summary");
|
|
@@ -6963,7 +7641,7 @@ var KEY_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
|
6963
7641
|
var LANGUAGE_TAG_PATTERN = /^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i;
|
|
6964
7642
|
var LENGTH_UNITS = ["characters", "words"];
|
|
6965
7643
|
function validationError(message) {
|
|
6966
|
-
return new
|
|
7644
|
+
return new LegacyMuxAiError(message, { type: "validation_error" });
|
|
6967
7645
|
}
|
|
6968
7646
|
function assertOneOf(value, allowed, label) {
|
|
6969
7647
|
if (!allowed.includes(value)) {
|
|
@@ -7147,7 +7825,7 @@ function scrubBrief(brief, safety) {
|
|
|
7147
7825
|
const centralIdea = safety.scrubDetailed(brief.centralIdea, "editorial_brief.centralIdea");
|
|
7148
7826
|
const readerValue = safety.scrubDetailed(brief.readerValue, "editorial_brief.readerValue");
|
|
7149
7827
|
if (centralIdea.leaked || readerValue.leaked || !centralIdea.text.trim()) {
|
|
7150
|
-
throw new
|
|
7828
|
+
throw new LegacyMuxAiError(
|
|
7151
7829
|
"The editorial brief was suppressed by the output safety filter.",
|
|
7152
7830
|
{ type: "processing_error", retryable: true }
|
|
7153
7831
|
);
|
|
@@ -7450,11 +8128,11 @@ ${renderSection({ tag: "revision_request", content: "The previous draft was empt
|
|
|
7450
8128
|
let failure;
|
|
7451
8129
|
if (isIncompleteGenerationError(cause)) {
|
|
7452
8130
|
failure = new IncompleteGenerationError(cause.finishReason, cause.rawFinishReason);
|
|
7453
|
-
} else if (
|
|
7454
|
-
failure = new
|
|
8131
|
+
} else if (isLegacyMuxAiError(cause)) {
|
|
8132
|
+
failure = new LegacyMuxAiError(cause.publicMessage, { type: cause.publicType, retryable: cause.retryable });
|
|
7455
8133
|
} else {
|
|
7456
8134
|
const apiError = APICallError4.isInstance(cause) ? cause : void 0;
|
|
7457
|
-
failure = new
|
|
8135
|
+
failure = new LegacyMuxAiError("Unable to complete text generation.", {
|
|
7458
8136
|
type: "processing_error",
|
|
7459
8137
|
retryable: apiError?.isRetryable ?? true,
|
|
7460
8138
|
cause
|
|
@@ -7498,7 +8176,7 @@ async function generateArtifactsInBatches(requests, collectedUsage, provider) {
|
|
|
7498
8176
|
collectedUsage.push(usage);
|
|
7499
8177
|
}
|
|
7500
8178
|
}
|
|
7501
|
-
|
|
8179
|
+
legacyWrapError(failures[0], `Failed to generate text with ${provider}`);
|
|
7502
8180
|
}
|
|
7503
8181
|
}
|
|
7504
8182
|
return results;
|
|
@@ -7536,14 +8214,14 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
|
|
|
7536
8214
|
getVideoTrackDurationSecondsFromAsset(asset)
|
|
7537
8215
|
);
|
|
7538
8216
|
if (useShots && isAudioOnly) {
|
|
7539
|
-
throw new
|
|
8217
|
+
throw new LegacyMuxAiError("useShots is not supported for audio-only assets.", { type: "validation_error" });
|
|
7540
8218
|
}
|
|
7541
8219
|
if (useShots && assetDurationSeconds === void 0) {
|
|
7542
|
-
throw new
|
|
8220
|
+
throw new LegacyMuxAiError("Asset has no valid duration.", { type: "validation_error" });
|
|
7543
8221
|
}
|
|
7544
8222
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
7545
8223
|
if (policy === "signed" && !signingContext) {
|
|
7546
|
-
throw new
|
|
8224
|
+
throw new LegacyMuxAiError(
|
|
7547
8225
|
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
7548
8226
|
{ type: "validation_error" }
|
|
7549
8227
|
);
|
|
@@ -7563,7 +8241,7 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
|
|
|
7563
8241
|
]);
|
|
7564
8242
|
const transcriptText = transcriptResult.transcriptText.trim();
|
|
7565
8243
|
if (!transcriptText) {
|
|
7566
|
-
throw new
|
|
8244
|
+
throw new LegacyMuxAiError(
|
|
7567
8245
|
effectiveScope ? "Transcript has no usable content in the requested scope." : "Transcript has no usable content.",
|
|
7568
8246
|
{ type: "validation_error" }
|
|
7569
8247
|
);
|
|
@@ -7583,7 +8261,7 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
|
|
|
7583
8261
|
userPrompt: buildBriefUserPrompt({ transcriptText, imageCount: imageUrls.length, audience, languageName }),
|
|
7584
8262
|
imageUrls,
|
|
7585
8263
|
credentials
|
|
7586
|
-
}).catch((error) =>
|
|
8264
|
+
}).catch((error) => legacyWrapError(error, `Failed to extract editorial brief with ${provider}`));
|
|
7587
8265
|
collectedUsage.push(briefStep.usage);
|
|
7588
8266
|
for (const key of briefStep.unexpectedKeys) {
|
|
7589
8267
|
safety.record(`editorial_brief.${key}`, "unexpected_key");
|
|
@@ -7612,10 +8290,10 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
|
|
|
7612
8290
|
safety.record(`${field}.${key}`, "unexpected_key");
|
|
7613
8291
|
}
|
|
7614
8292
|
if (item.violation === "empty") {
|
|
7615
|
-
throw new
|
|
8293
|
+
throw new LegacyMuxAiError(`Generated text for ${field} was empty after a retry.`, { type: "processing_error", retryable: true });
|
|
7616
8294
|
}
|
|
7617
8295
|
if (item.violation) {
|
|
7618
|
-
throw new
|
|
8296
|
+
throw new LegacyMuxAiError(
|
|
7619
8297
|
`Generated text for ${field} exceeded the ${item.violation.limit.value} ${item.violation.limit.unit} limit after a retry (${item.violation.actual} returned).`,
|
|
7620
8298
|
{ type: "processing_error", retryable: true }
|
|
7621
8299
|
);
|
|
@@ -8452,7 +9130,7 @@ async function getModerationScores(assetId, options = {}) {
|
|
|
8452
9130
|
};
|
|
8453
9131
|
} else {
|
|
8454
9132
|
if (!captionTrack.id) {
|
|
8455
|
-
throw new
|
|
9133
|
+
throw new LegacyMuxAiError("Transcript track is missing an id.", { type: "validation_error" });
|
|
8456
9134
|
}
|
|
8457
9135
|
const transcriptUrl = await buildTranscriptUrl(playbackId, captionTrack.id, policy === "signed", credentials);
|
|
8458
9136
|
const { transcriptText, emptyReason } = await fetchTranscriptDataForUrl(transcriptUrl, {
|
|
@@ -8480,7 +9158,7 @@ async function getModerationScores(assetId, options = {}) {
|
|
|
8480
9158
|
}
|
|
8481
9159
|
}
|
|
8482
9160
|
if (!shouldRunThumbnails && !shouldRunTranscript) {
|
|
8483
|
-
throw new
|
|
9161
|
+
throw new LegacyMuxAiError(
|
|
8484
9162
|
`Nothing to moderate. Thumbnails skipped: ${thumbnailModeration.skipMessage} Transcript skipped: ${transcriptModeration.skipMessage}`,
|
|
8485
9163
|
{ type: "validation_error" }
|
|
8486
9164
|
);
|
|
@@ -9083,7 +9761,7 @@ async function getSummaryAndTagsInternal(assetId, options, collectedUsage) {
|
|
|
9083
9761
|
scope
|
|
9084
9762
|
} = options ?? {};
|
|
9085
9763
|
if (!VALID_TONES.includes(tone)) {
|
|
9086
|
-
throw new
|
|
9764
|
+
throw new LegacyMuxAiError(
|
|
9087
9765
|
`Invalid tone "${tone}". Valid tones are: ${VALID_TONES.join(", ")}.`,
|
|
9088
9766
|
{ type: "validation_error" }
|
|
9089
9767
|
);
|
|
@@ -9108,7 +9786,7 @@ async function getSummaryAndTagsInternal(assetId, options, collectedUsage) {
|
|
|
9108
9786
|
resolveWorkflowScope(effectiveScope, assetDurationSeconds);
|
|
9109
9787
|
}
|
|
9110
9788
|
if (isAudioOnly && !includeTranscript) {
|
|
9111
|
-
throw new
|
|
9789
|
+
throw new LegacyMuxAiError(
|
|
9112
9790
|
"Audio-only assets require a transcript. Set includeTranscript: true and ensure the asset has a ready text track (captions/subtitles).",
|
|
9113
9791
|
{ type: "validation_error" }
|
|
9114
9792
|
);
|
|
@@ -9116,7 +9794,7 @@ async function getSummaryAndTagsInternal(assetId, options, collectedUsage) {
|
|
|
9116
9794
|
const signingContext = await resolveMuxSigningContext(workflowCredentials);
|
|
9117
9795
|
const requiresSignedPlaybackAccess = includeTranscript || !isAudioOnly;
|
|
9118
9796
|
if (policy === "signed" && requiresSignedPlaybackAccess && !signingContext) {
|
|
9119
|
-
throw new
|
|
9797
|
+
throw new LegacyMuxAiError(
|
|
9120
9798
|
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
9121
9799
|
{ type: "validation_error" }
|
|
9122
9800
|
);
|
|
@@ -9195,18 +9873,18 @@ async function getSummaryAndTagsInternal(assetId, options, collectedUsage) {
|
|
|
9195
9873
|
}
|
|
9196
9874
|
} catch (error) {
|
|
9197
9875
|
const contentType = isAudioOnly ? "audio" : "video";
|
|
9198
|
-
|
|
9876
|
+
legacyWrapError(error, `Failed to analyze ${contentType} content with ${provider}`);
|
|
9199
9877
|
}
|
|
9200
9878
|
collectedUsage.push(analysisResponse.usage);
|
|
9201
9879
|
if (!analysisResponse.result) {
|
|
9202
9880
|
const contentType = isAudioOnly ? "audio" : "video";
|
|
9203
|
-
throw new
|
|
9881
|
+
throw new LegacyMuxAiError(`Failed to analyze ${contentType} content for asset ${assetId}.`);
|
|
9204
9882
|
}
|
|
9205
9883
|
if (!analysisResponse.result.title) {
|
|
9206
|
-
throw new
|
|
9884
|
+
throw new LegacyMuxAiError(`Failed to generate title for asset ${assetId}.`);
|
|
9207
9885
|
}
|
|
9208
9886
|
if (!analysisResponse.result.description) {
|
|
9209
|
-
throw new
|
|
9887
|
+
throw new LegacyMuxAiError(`Failed to generate description for asset ${assetId}.`);
|
|
9210
9888
|
}
|
|
9211
9889
|
const safety = createSafetyReporter();
|
|
9212
9890
|
if (analysisResponse.unexpectedKeys.length > 0) {
|
|
@@ -9362,7 +10040,7 @@ async function requestStaticRenditionCreation(assetId, credentials) {
|
|
|
9362
10040
|
if (statusCode === 409 || alreadyDefined) {
|
|
9363
10041
|
return void 0;
|
|
9364
10042
|
}
|
|
9365
|
-
|
|
10043
|
+
legacyWrapError(error, "Failed to request static rendition from Mux");
|
|
9366
10044
|
}
|
|
9367
10045
|
}
|
|
9368
10046
|
async function deleteCreatedStaticRendition(assetId, staticRenditionId, credentials) {
|
|
@@ -9412,12 +10090,12 @@ async function waitForAudioStaticRendition({
|
|
|
9412
10090
|
`\u231B Waiting for static rendition (attempt ${attempt}/${STATIC_RENDITION_MAX_ATTEMPTS}) \u2192 ${currentStatus}`
|
|
9413
10091
|
);
|
|
9414
10092
|
if (currentStatus === "errored") {
|
|
9415
|
-
throw new
|
|
10093
|
+
throw new LegacyMuxAiError(
|
|
9416
10094
|
"Mux failed to create the static rendition for this asset. Please check the asset in the Mux dashboard."
|
|
9417
10095
|
);
|
|
9418
10096
|
}
|
|
9419
10097
|
}
|
|
9420
|
-
throw new
|
|
10098
|
+
throw new LegacyMuxAiError(
|
|
9421
10099
|
"Timed out waiting for the static rendition to become ready. Please try again in a moment.",
|
|
9422
10100
|
{ type: "timeout_error", retryable: true }
|
|
9423
10101
|
);
|
|
@@ -9436,23 +10114,23 @@ async function waitForLegacyMp4SupportRendition({
|
|
|
9436
10114
|
rendition = resolveLegacyMp4SupportRendition(await retrieveAsset(assetId, credentials));
|
|
9437
10115
|
}
|
|
9438
10116
|
if (!rendition) {
|
|
9439
|
-
throw new
|
|
10117
|
+
throw new LegacyMuxAiError(
|
|
9440
10118
|
"The asset's static rendition settings changed while waiting for them. Please try again.",
|
|
9441
10119
|
{ type: "processing_error", retryable: true }
|
|
9442
10120
|
);
|
|
9443
10121
|
}
|
|
9444
10122
|
if (rendition.kind === "preparing") {
|
|
9445
|
-
throw new
|
|
10123
|
+
throw new LegacyMuxAiError(
|
|
9446
10124
|
"Timed out waiting for the static rendition to become ready. Please try again in a moment.",
|
|
9447
10125
|
{ type: "timeout_error", retryable: true }
|
|
9448
10126
|
);
|
|
9449
10127
|
}
|
|
9450
10128
|
if (rendition.kind === "unusable") {
|
|
9451
|
-
throw new
|
|
10129
|
+
throw new LegacyMuxAiError(rendition.reason, { type: "validation_error" });
|
|
9452
10130
|
}
|
|
9453
10131
|
const sizeError = getLegacyMp4SupportRenditionSizeError(rendition, MAX_DUBBING_SOURCE_BYTES);
|
|
9454
10132
|
if (sizeError) {
|
|
9455
|
-
throw new
|
|
10133
|
+
throw new LegacyMuxAiError(sizeError, { type: "validation_error" });
|
|
9456
10134
|
}
|
|
9457
10135
|
return rendition.name;
|
|
9458
10136
|
}
|
|
@@ -9474,19 +10152,19 @@ function audioTrackUnsupportedReason(asset) {
|
|
|
9474
10152
|
}
|
|
9475
10153
|
function dubbingProviderError(message, failure) {
|
|
9476
10154
|
if (failure.reason === "timeout") {
|
|
9477
|
-
return new
|
|
10155
|
+
return new LegacyMuxAiError(`${message} The dubbing service timed out. Please try again.`, { type: "timeout_error", retryable: true });
|
|
9478
10156
|
}
|
|
9479
10157
|
if (failure.retryable) {
|
|
9480
|
-
return new
|
|
10158
|
+
return new LegacyMuxAiError(`${message} The dubbing service is temporarily unavailable. Please try again.`, { type: "processing_error", retryable: true });
|
|
9481
10159
|
}
|
|
9482
|
-
return new
|
|
10160
|
+
return new LegacyMuxAiError(message, { type: "processing_error" });
|
|
9483
10161
|
}
|
|
9484
10162
|
function dubbingStartError(failure, languages) {
|
|
9485
10163
|
if (failure.reason === "unsupported_target_language") {
|
|
9486
|
-
return new
|
|
10164
|
+
return new LegacyMuxAiError(`Audio dubbing does not support the target language "${languages.target}".`, { type: "validation_error" });
|
|
9487
10165
|
}
|
|
9488
10166
|
if (failure.reason === "unsupported_source_language" && languages.source) {
|
|
9489
|
-
return new
|
|
10167
|
+
return new LegacyMuxAiError(`Audio dubbing does not support the source language "${languages.source}".`, { type: "validation_error" });
|
|
9490
10168
|
}
|
|
9491
10169
|
return dubbingProviderError("Audio dubbing could not be started.", failure);
|
|
9492
10170
|
}
|
|
@@ -9721,11 +10399,11 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9721
10399
|
trackPassthrough: providedTrackPassthrough
|
|
9722
10400
|
} = options;
|
|
9723
10401
|
if (provider !== "elevenlabs") {
|
|
9724
|
-
throw new
|
|
10402
|
+
throw new LegacyMuxAiError("Only ElevenLabs provider is currently supported for audio translation.", { type: "validation_error" });
|
|
9725
10403
|
}
|
|
9726
10404
|
const targetLanguageCode = toISO639_1(toLanguageCode);
|
|
9727
10405
|
if (numSpeakers !== 0) {
|
|
9728
|
-
throw new
|
|
10406
|
+
throw new LegacyMuxAiError("The ElevenLabs project API does not support numSpeakers overrides. Omit it or use 0 for auto-detection.", { type: "validation_error" });
|
|
9729
10407
|
}
|
|
9730
10408
|
const credentials = providedCredentials;
|
|
9731
10409
|
const effectiveStorageAdapter = storageAdapter;
|
|
@@ -9742,21 +10420,21 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9742
10420
|
const s3AccessKeyId = env_default.S3_ACCESS_KEY_ID;
|
|
9743
10421
|
const s3SecretAccessKey = env_default.S3_SECRET_ACCESS_KEY;
|
|
9744
10422
|
if (uploadToS3 && (!s3Endpoint || !s3Bucket || !effectiveStorageAdapter && (!s3AccessKeyId || !s3SecretAccessKey))) {
|
|
9745
|
-
throw new
|
|
10423
|
+
throw new LegacyMuxAiError("Storage configuration is required for uploading. Provide s3Endpoint and s3Bucket. If no storageAdapter is supplied, also provide s3AccessKeyId and s3SecretAccessKey in options or set S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, and S3_SECRET_ACCESS_KEY environment variables.", { type: "validation_error" });
|
|
9746
10424
|
}
|
|
9747
10425
|
const { asset: initialAsset, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
|
|
9748
10426
|
const assetDurationSeconds = getAssetDurationSecondsFromAsset(initialAsset);
|
|
9749
10427
|
if (isVideoOnlyAsset(initialAsset)) {
|
|
9750
|
-
throw new
|
|
10428
|
+
throw new LegacyMuxAiError(`Asset ${assetId} has no audio track, so there is no audio to dub.`, { type: "validation_error" });
|
|
9751
10429
|
}
|
|
9752
10430
|
const audioTrackUnsupported = uploadToMux ? audioTrackUnsupportedReason(initialAsset) : void 0;
|
|
9753
10431
|
if (audioTrackUnsupported) {
|
|
9754
|
-
throw new
|
|
10432
|
+
throw new LegacyMuxAiError(`Asset ${assetId} ${audioTrackUnsupported}`, { type: "validation_error" });
|
|
9755
10433
|
}
|
|
9756
10434
|
if (uploadToMux) {
|
|
9757
10435
|
const plan = planTextTrackReplacement(initialAsset, audioTrackTarget, replaceExistingTracks);
|
|
9758
10436
|
if (plan.kind === "blocked") {
|
|
9759
|
-
throw new
|
|
10437
|
+
throw new LegacyMuxAiError(plan.reason, { type: "validation_error" });
|
|
9760
10438
|
}
|
|
9761
10439
|
}
|
|
9762
10440
|
let currentAsset = initialAsset;
|
|
@@ -9798,7 +10476,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9798
10476
|
}
|
|
9799
10477
|
const audioRendition = getReadyAudioStaticRendition(currentAsset);
|
|
9800
10478
|
if (!audioRendition) {
|
|
9801
|
-
throw new
|
|
10479
|
+
throw new LegacyMuxAiError(
|
|
9802
10480
|
"Unable to obtain an audio-only static rendition for this asset. Please verify static renditions are enabled in Mux.",
|
|
9803
10481
|
{ type: "validation_error" }
|
|
9804
10482
|
);
|
|
@@ -9825,7 +10503,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9825
10503
|
credentials
|
|
9826
10504
|
});
|
|
9827
10505
|
} catch (error) {
|
|
9828
|
-
|
|
10506
|
+
legacyWrapError(error, "Failed to create ElevenLabs dubbing job");
|
|
9829
10507
|
}
|
|
9830
10508
|
if (created.kind === "failed") {
|
|
9831
10509
|
const { failure } = created;
|
|
@@ -9856,7 +10534,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9856
10534
|
credentials
|
|
9857
10535
|
});
|
|
9858
10536
|
} catch (error) {
|
|
9859
|
-
|
|
10537
|
+
legacyWrapError(error, "Failed to check dubbing status");
|
|
9860
10538
|
}
|
|
9861
10539
|
if (statusResult.kind === "failed") {
|
|
9862
10540
|
const { failure } = statusResult;
|
|
@@ -9873,16 +10551,16 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9873
10551
|
if (dubbingStatus === "failed") {
|
|
9874
10552
|
console.warn(`\u274C ElevenLabs dubbing project ${dubbingId} (language ${languageId}) failed: ${dubbingError ? `${dubbingError.code}: ${dubbingError.message}` : "no error reported"}`);
|
|
9875
10553
|
if (!dubbingError) {
|
|
9876
|
-
throw new
|
|
10554
|
+
throw new LegacyMuxAiError("Audio dubbing failed.", { type: "processing_error" });
|
|
9877
10555
|
}
|
|
9878
|
-
throw new
|
|
10556
|
+
throw new LegacyMuxAiError(
|
|
9879
10557
|
`Audio dubbing failed: ${dubbingError.message}${dubbingError.retryable ? " Please try again." : ""}`,
|
|
9880
10558
|
{ type: "processing_error", retryable: dubbingError.retryable }
|
|
9881
10559
|
);
|
|
9882
10560
|
}
|
|
9883
10561
|
}
|
|
9884
10562
|
if (dubbingStatus !== "completed") {
|
|
9885
|
-
throw new
|
|
10563
|
+
throw new LegacyMuxAiError("Audio translation timed out or failed. Please try again.", { type: "timeout_error", retryable: true });
|
|
9886
10564
|
}
|
|
9887
10565
|
console.warn("\u2705 Dubbing completed successfully!");
|
|
9888
10566
|
if (uploadToS3) {
|
|
@@ -9903,7 +10581,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9903
10581
|
credentials
|
|
9904
10582
|
});
|
|
9905
10583
|
} catch (error) {
|
|
9906
|
-
|
|
10584
|
+
legacyWrapError(error, "Failed to download and upload dubbed audio");
|
|
9907
10585
|
}
|
|
9908
10586
|
if (staged.kind === "staged") {
|
|
9909
10587
|
presignedUrl = staged.presignedUrl;
|
|
@@ -9930,10 +10608,10 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
|
|
|
9930
10608
|
credentials
|
|
9931
10609
|
});
|
|
9932
10610
|
} catch (error) {
|
|
9933
|
-
|
|
10611
|
+
legacyWrapError(error, `Failed to add dubbed audio track to Mux asset (dubbed audio is staged at: ${presignedUrl})`);
|
|
9934
10612
|
}
|
|
9935
10613
|
if (outcome.kind === "blocked") {
|
|
9936
|
-
throw new
|
|
10614
|
+
throw new LegacyMuxAiError(`${outcome.reason} Dubbed audio is staged at: ${presignedUrl}`, { type: "validation_error" });
|
|
9937
10615
|
}
|
|
9938
10616
|
if (outcome.kind === "create_failed") {
|
|
9939
10617
|
throw new Error(`Failed to add dubbed audio track to Mux asset: ${outcome.reason}. Dubbed audio is staged at: ${presignedUrl}`);
|
|
@@ -10095,7 +10773,7 @@ var MAX_NEVER_TRANSLATE_TERMS = 100;
|
|
|
10095
10773
|
var MAX_NEVER_TRANSLATE_TERM_CHARS = 100;
|
|
10096
10774
|
function validateNeverTranslateTerms(terms) {
|
|
10097
10775
|
if (terms.length > MAX_NEVER_TRANSLATE_TERMS) {
|
|
10098
|
-
throw new
|
|
10776
|
+
throw new LegacyMuxAiError(
|
|
10099
10777
|
`neverTranslate accepts at most ${MAX_NEVER_TRANSLATE_TERMS} terms (received ${terms.length}).`,
|
|
10100
10778
|
{ type: "validation_error" }
|
|
10101
10779
|
);
|
|
@@ -10105,25 +10783,25 @@ function validateNeverTranslateTerms(terms) {
|
|
|
10105
10783
|
for (const term of terms) {
|
|
10106
10784
|
const trimmed = term.trim();
|
|
10107
10785
|
if (trimmed.length === 0) {
|
|
10108
|
-
throw new
|
|
10786
|
+
throw new LegacyMuxAiError(
|
|
10109
10787
|
"neverTranslate terms must be non-empty.",
|
|
10110
10788
|
{ type: "validation_error" }
|
|
10111
10789
|
);
|
|
10112
10790
|
}
|
|
10113
10791
|
if (trimmed.length > MAX_NEVER_TRANSLATE_TERM_CHARS) {
|
|
10114
|
-
throw new
|
|
10792
|
+
throw new LegacyMuxAiError(
|
|
10115
10793
|
`neverTranslate terms must be at most ${MAX_NEVER_TRANSLATE_TERM_CHARS} characters (received ${trimmed.length}).`,
|
|
10116
10794
|
{ type: "validation_error" }
|
|
10117
10795
|
);
|
|
10118
10796
|
}
|
|
10119
10797
|
if (trimmed.includes("<") || trimmed.includes(">")) {
|
|
10120
|
-
throw new
|
|
10798
|
+
throw new LegacyMuxAiError(
|
|
10121
10799
|
"neverTranslate terms must not contain '<' or '>'.",
|
|
10122
10800
|
{ type: "validation_error" }
|
|
10123
10801
|
);
|
|
10124
10802
|
}
|
|
10125
10803
|
if (sanitizeUntrustedText(trimmed) !== trimmed) {
|
|
10126
|
-
throw new
|
|
10804
|
+
throw new LegacyMuxAiError(
|
|
10127
10805
|
"neverTranslate terms must not contain invisible characters or characters altered by Unicode NFKC normalization.",
|
|
10128
10806
|
{ type: "validation_error" }
|
|
10129
10807
|
);
|
|
@@ -10146,11 +10824,11 @@ function buildNeverTranslateSection(terms) {
|
|
|
10146
10824
|
${terms.join("\n")}
|
|
10147
10825
|
</never_translate>`;
|
|
10148
10826
|
}
|
|
10149
|
-
function countTermOccurrences(
|
|
10827
|
+
function countTermOccurrences(text2, term) {
|
|
10150
10828
|
if (term.length === 0) {
|
|
10151
10829
|
return 0;
|
|
10152
10830
|
}
|
|
10153
|
-
return
|
|
10831
|
+
return text2.split(term).length - 1;
|
|
10154
10832
|
}
|
|
10155
10833
|
function verifyNeverTranslateTerms(terms, sourceVtt, translatedVtt) {
|
|
10156
10834
|
const cueText = (vtt) => parseVTTCues(vtt).map((cue) => cue.text).join("\n");
|
|
@@ -10324,24 +11002,24 @@ function buildTranslationChunkRequests(vttContent, assetDurationSeconds, chunkin
|
|
|
10324
11002
|
function normalizeTranslatedVtt(translation) {
|
|
10325
11003
|
if (!translation)
|
|
10326
11004
|
return translation;
|
|
10327
|
-
let
|
|
10328
|
-
const fenceMatch =
|
|
11005
|
+
let text2 = translation.trim();
|
|
11006
|
+
const fenceMatch = text2.match(/^```(?:vtt|webvtt)?\n([\s\S]*?)\n```$/i);
|
|
10329
11007
|
if (fenceMatch) {
|
|
10330
|
-
|
|
11008
|
+
text2 = fenceMatch[1].trim();
|
|
10331
11009
|
}
|
|
10332
|
-
const tagMatch =
|
|
11010
|
+
const tagMatch = text2.match(/^<(code|pre)\b[^>]*>\n?([\s\S]*?)\n?<\/\1>$/i);
|
|
10333
11011
|
if (tagMatch) {
|
|
10334
|
-
|
|
11012
|
+
text2 = tagMatch[2].trim();
|
|
10335
11013
|
}
|
|
10336
|
-
if (/^webvtt\b/i.test(
|
|
10337
|
-
|
|
11014
|
+
if (/^webvtt\b/i.test(text2) && !text2.startsWith("WEBVTT")) {
|
|
11015
|
+
text2 = text2.replace(/^webvtt\b/i, "WEBVTT");
|
|
10338
11016
|
}
|
|
10339
|
-
if (!
|
|
10340
|
-
|
|
11017
|
+
if (!text2.startsWith("WEBVTT")) {
|
|
11018
|
+
text2 = `WEBVTT
|
|
10341
11019
|
|
|
10342
|
-
${
|
|
11020
|
+
${text2}`;
|
|
10343
11021
|
}
|
|
10344
|
-
return
|
|
11022
|
+
return text2;
|
|
10345
11023
|
}
|
|
10346
11024
|
function mergeScrubbedCueCounts(a, b) {
|
|
10347
11025
|
const merged = { ...a };
|
|
@@ -10525,7 +11203,7 @@ async function translateChunkWithFallback({
|
|
|
10525
11203
|
};
|
|
10526
11204
|
} catch (error) {
|
|
10527
11205
|
if (!shouldSplitChunkTranslationError(error) || chunk.cueCount <= 1) {
|
|
10528
|
-
|
|
11206
|
+
legacyWrapError(error, `Chunk ${chunk.id} failed for ${Math.round(chunk.startTime)}s-${Math.round(chunk.endTime)}s`);
|
|
10529
11207
|
}
|
|
10530
11208
|
const [leftChunk, rightChunk] = splitTranslationChunkAtMidpoint(chunk);
|
|
10531
11209
|
const failedAttemptUsage = getErrorTokenUsage(error);
|
|
@@ -10706,13 +11384,13 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10706
11384
|
provider
|
|
10707
11385
|
});
|
|
10708
11386
|
if (uploadToS3 && (!s3Endpoint || !s3Bucket || !effectiveStorageAdapter && (!s3AccessKeyId || !s3SecretAccessKey))) {
|
|
10709
|
-
throw new
|
|
11387
|
+
throw new LegacyMuxAiError("Storage configuration is required for uploading. Provide s3Endpoint and s3Bucket. If no storageAdapter is supplied, also provide s3AccessKeyId and s3SecretAccessKey in options or set S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, and S3_SECRET_ACCESS_KEY environment variables.", { type: "validation_error" });
|
|
10710
11388
|
}
|
|
10711
11389
|
const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
|
|
10712
11390
|
const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
|
|
10713
11391
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
10714
11392
|
if (policy === "signed" && !signingContext) {
|
|
10715
|
-
throw new
|
|
11393
|
+
throw new LegacyMuxAiError(
|
|
10716
11394
|
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
10717
11395
|
{ type: "validation_error" }
|
|
10718
11396
|
);
|
|
@@ -10721,14 +11399,14 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10721
11399
|
const sourceTextTrack = readyTextTracks.find((t) => t.id === trackId);
|
|
10722
11400
|
if (!sourceTextTrack) {
|
|
10723
11401
|
const availableTrackIds = readyTextTracks.map((t) => t.id).filter(Boolean).join(", ");
|
|
10724
|
-
throw new
|
|
11402
|
+
throw new LegacyMuxAiError(
|
|
10725
11403
|
`Track ${trackId} not found or not ready on asset ${assetId}. Available track IDs: ${availableTrackIds || "none"}.`,
|
|
10726
11404
|
{ type: "validation_error" }
|
|
10727
11405
|
);
|
|
10728
11406
|
}
|
|
10729
11407
|
const fromLanguageCode = sourceTextTrack.language_code;
|
|
10730
11408
|
if (!fromLanguageCode) {
|
|
10731
|
-
throw new
|
|
11409
|
+
throw new LegacyMuxAiError(
|
|
10732
11410
|
`Track ${trackId} is missing language metadata. Cannot determine source language for translation.`,
|
|
10733
11411
|
{ type: "validation_error" }
|
|
10734
11412
|
);
|
|
@@ -10740,7 +11418,7 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10740
11418
|
if (uploadToMux) {
|
|
10741
11419
|
const plan = planTextTrackReplacement(assetData, outputTrack, replaceExistingTracks);
|
|
10742
11420
|
if (plan.kind === "blocked") {
|
|
10743
|
-
throw new
|
|
11421
|
+
throw new LegacyMuxAiError(plan.reason, { type: "validation_error" });
|
|
10744
11422
|
}
|
|
10745
11423
|
}
|
|
10746
11424
|
const vttUrl = await buildTranscriptUrl(playbackId, trackId, policy === "signed", credentials);
|
|
@@ -10748,7 +11426,7 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10748
11426
|
try {
|
|
10749
11427
|
vttContent = await fetchVttFromMux(vttUrl);
|
|
10750
11428
|
} catch (error) {
|
|
10751
|
-
|
|
11429
|
+
legacyWrapError(error, "Failed to fetch VTT content");
|
|
10752
11430
|
}
|
|
10753
11431
|
let translatedVtt;
|
|
10754
11432
|
let usage;
|
|
@@ -10772,7 +11450,7 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10772
11450
|
scrubbedCueCounts = result.scrubbedCueCounts;
|
|
10773
11451
|
unexpectedKeyCount = result.unexpectedKeyCount;
|
|
10774
11452
|
} catch (error) {
|
|
10775
|
-
|
|
11453
|
+
legacyWrapError(error, `Failed to translate VTT with ${modelConfig.provider}`);
|
|
10776
11454
|
}
|
|
10777
11455
|
const scrubbedFields = [];
|
|
10778
11456
|
for (const [reason, count] of Object.entries(scrubbedCueCounts)) {
|
|
@@ -10825,7 +11503,7 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10825
11503
|
s3SignedUrlExpirySeconds: options.s3SignedUrlExpirySeconds
|
|
10826
11504
|
});
|
|
10827
11505
|
} catch (error) {
|
|
10828
|
-
|
|
11506
|
+
legacyWrapError(error, "Failed to upload VTT to S3");
|
|
10829
11507
|
}
|
|
10830
11508
|
if (uploadToMux) {
|
|
10831
11509
|
let outcome;
|
|
@@ -10839,12 +11517,12 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10839
11517
|
credentials
|
|
10840
11518
|
});
|
|
10841
11519
|
} catch (error) {
|
|
10842
|
-
|
|
11520
|
+
legacyWrapError(error, "Failed to add translated track to Mux asset");
|
|
10843
11521
|
}
|
|
10844
11522
|
if (outcome.kind !== "created") {
|
|
10845
11523
|
const deletedNote = outcome.deleted.length > 0 ? ` Tracks already deleted before the failure: ${outcome.deleted.map((track) => `${track.name ?? track.id} (${track.id})`).join(", ")}.` : "";
|
|
10846
11524
|
if (outcome.kind === "blocked") {
|
|
10847
|
-
throw new
|
|
11525
|
+
throw new LegacyMuxAiError(`${outcome.reason}${deletedNote}`, { type: "validation_error" });
|
|
10848
11526
|
}
|
|
10849
11527
|
throw new Error(`Failed to add translated track to Mux asset: ${outcome.reason}.${deletedNote}`);
|
|
10850
11528
|
}
|
|
@@ -10870,22 +11548,44 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10870
11548
|
};
|
|
10871
11549
|
}
|
|
10872
11550
|
export {
|
|
11551
|
+
ClassifiedError,
|
|
11552
|
+
MUX_AI_ERROR_CATALOG,
|
|
11553
|
+
MUX_AI_ERROR_CODES,
|
|
11554
|
+
MUX_AI_ERROR_CODE_VALUES,
|
|
11555
|
+
MUX_AI_ERROR_DEPENDENCIES,
|
|
11556
|
+
MUX_AI_ERROR_DEPENDENCY_VALUES,
|
|
11557
|
+
MUX_AI_ERROR_GENERIC_MESSAGES,
|
|
11558
|
+
MUX_AI_ERROR_PUBLIC_MAPPINGS,
|
|
11559
|
+
MUX_AI_ERROR_SOURCES,
|
|
11560
|
+
MUX_AI_ERROR_SOURCE_VALUES,
|
|
11561
|
+
MUX_AI_ERROR_TYPES,
|
|
11562
|
+
MUX_AI_ERROR_TYPE_VALUES,
|
|
10873
11563
|
MUX_TRACK_PASSTHROUGH_MAX_CHARS,
|
|
10874
11564
|
MuxAiError,
|
|
10875
11565
|
STATIC_RENDITIONS_GUIDE_URL,
|
|
10876
11566
|
WorkflowStorageClient,
|
|
11567
|
+
assertNever,
|
|
10877
11568
|
buildMuxAiTrackPassthrough,
|
|
11569
|
+
classificationInit,
|
|
11570
|
+
classifyDependencyFailure,
|
|
11571
|
+
createPublicErrorView,
|
|
10878
11572
|
createWorkflowStorageClient,
|
|
10879
11573
|
decryptFromWorkflow,
|
|
11574
|
+
dependencyError,
|
|
10880
11575
|
encryptForWorkflow,
|
|
11576
|
+
errorDetailFact,
|
|
10881
11577
|
findNameCollisionTextTracks,
|
|
10882
11578
|
findSameLanguageTextTracks,
|
|
11579
|
+
genericPublicMessage,
|
|
10883
11580
|
getLanguageCodePair,
|
|
10884
11581
|
getLanguageName,
|
|
10885
11582
|
getLegacyMp4SupportRenditionSizeError,
|
|
10886
11583
|
getMuxPlaybackOrigin,
|
|
11584
|
+
httpStatusOf,
|
|
11585
|
+
internalError,
|
|
10887
11586
|
isDuplicateTrackNameError,
|
|
10888
11587
|
isMuxGeneratedTextTrack,
|
|
11588
|
+
isTransientStatus,
|
|
10889
11589
|
isUndeterminedLanguageCode,
|
|
10890
11590
|
isValidISO639_1,
|
|
10891
11591
|
isValidISO639_3,
|
|
@@ -10897,11 +11597,17 @@ export {
|
|
|
10897
11597
|
replaceAndCreateTextTrack,
|
|
10898
11598
|
replaceAndCreateTrack,
|
|
10899
11599
|
replaceSourceTrack,
|
|
11600
|
+
requestIdOf,
|
|
10900
11601
|
resolveLegacyMp4SupportRendition,
|
|
11602
|
+
restoreClassification,
|
|
11603
|
+
serializeClassification,
|
|
10901
11604
|
setWorkflowCredentialsProvider,
|
|
10902
11605
|
summarizeTextTrack,
|
|
10903
11606
|
toISO639_1,
|
|
10904
11607
|
toISO639_3,
|
|
11608
|
+
toPublicError,
|
|
11609
|
+
trackReplacementBlockedError,
|
|
11610
|
+
trackTargetFacts,
|
|
10905
11611
|
usesLegacyMp4Support,
|
|
10906
11612
|
validateTrackPassthrough,
|
|
10907
11613
|
version,
|