@mux/ai 0.59.0 → 0.59.1-canary.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-BPZEKSNp.d.ts → index-DO8jM8_5.d.ts} +38 -5
- package/dist/index.d.ts +16 -4
- package/dist/index.js +641 -206
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.js +15 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/workflows/index.d.ts +1 -1
- package/dist/workflows/index.js +731 -272
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
package/dist/workflows/index.js
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { generateText, jsonSchema, NoObjectGeneratedError as NoObjectGeneratedError2, Output } from "ai";
|
|
3
3
|
|
|
4
4
|
// src/lib/content-policy-error.ts
|
|
5
|
-
import { APICallError as APICallError2, NoObjectGeneratedError, RetryError } from "ai";
|
|
5
|
+
import { APICallError as APICallError2, NoObjectGeneratedError, NoOutputGeneratedError as NoOutputGeneratedError2, RetryError } from "ai";
|
|
6
|
+
import { z as z3 } from "zod";
|
|
7
|
+
|
|
8
|
+
// src/lib/google-errors.ts
|
|
6
9
|
import { z as z2 } from "zod";
|
|
7
10
|
|
|
8
11
|
// node_modules/@workflow/serde/dist/index.js
|
|
@@ -574,12 +577,16 @@ var MUX_AI_ERROR_CODES = {
|
|
|
574
577
|
INVALID_SCOPE: "invalid_scope",
|
|
575
578
|
/** 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. */
|
|
576
579
|
TRACK_REPLACEMENT_BLOCKED: "track_replacement_blocked",
|
|
580
|
+
/** An option's value can't be used. Facts: `parameter` (the caller's option name), `reason` (`too_many`, `empty`, `too_long`, `disallowed_characters`, `not_normalized`) and the values the reason names: `count` and `max`, `index` (0-based entry), `length` and `maxLength`, `characters`. */
|
|
581
|
+
INVALID_PARAMETER: "invalid_parameter",
|
|
577
582
|
/** 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. */
|
|
578
583
|
PARAMETER_OUT_OF_RANGE: "parameter_out_of_range",
|
|
579
584
|
/** No ready caption track matches the requested track or language. Facts: `trackId` or `languageCode`, and what is available. */
|
|
580
585
|
CAPTION_TRACK_NOT_FOUND: "caption_track_not_found",
|
|
581
586
|
/** The asset has no public or signed playback ID (DRM-only assets included). */
|
|
582
587
|
PLAYBACK_ID_NOT_FOUND: "playback_id_not_found",
|
|
588
|
+
/** Mux has no asset with the requested ID in this environment. Facts: `assetId`. */
|
|
589
|
+
ASSET_NOT_FOUND: "asset_not_found",
|
|
583
590
|
/** The transcript has no usable content. */
|
|
584
591
|
TRANSCRIPT_EMPTY: "transcript_empty",
|
|
585
592
|
/** The asset has no valid duration, so work that depends on it can't run. Facts: `assetId`. */
|
|
@@ -616,7 +623,9 @@ var MUX_AI_ERROR_CATALOG = {
|
|
|
616
623
|
// The caller's input.
|
|
617
624
|
[MUX_AI_ERROR_CODES.INVALID_SCOPE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
|
|
618
625
|
[MUX_AI_ERROR_CODES.TRACK_REPLACEMENT_BLOCKED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
|
|
626
|
+
[MUX_AI_ERROR_CODES.INVALID_PARAMETER]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
|
|
619
627
|
[MUX_AI_ERROR_CODES.PARAMETER_OUT_OF_RANGE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
|
|
628
|
+
[MUX_AI_ERROR_CODES.ASSET_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST, dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO },
|
|
620
629
|
// The asset's state.
|
|
621
630
|
[MUX_AI_ERROR_CODES.CAPTION_TRACK_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
622
631
|
[MUX_AI_ERROR_CODES.PLAYBACK_ID_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
|
|
@@ -843,6 +852,125 @@ function wrapError(error, message, facts) {
|
|
|
843
852
|
}
|
|
844
853
|
throw wrapped;
|
|
845
854
|
}
|
|
855
|
+
function internalError(message, facts, cause) {
|
|
856
|
+
return new MuxAiError(message, {
|
|
857
|
+
type: MUX_AI_ERROR_TYPES.SERVER_ERROR,
|
|
858
|
+
source: MUX_AI_ERROR_SOURCES.INTERNAL,
|
|
859
|
+
facts,
|
|
860
|
+
cause
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// src/lib/dependency-error.ts
|
|
865
|
+
function classifyDependencyFailure(init) {
|
|
866
|
+
const { call, status, requestId, facts, timedOut } = init;
|
|
867
|
+
const transient = timedOut === true || isTransientStatus(status);
|
|
868
|
+
let source;
|
|
869
|
+
let type;
|
|
870
|
+
if (transient) {
|
|
871
|
+
source = MUX_AI_ERROR_SOURCES.UPSTREAM;
|
|
872
|
+
type = timedOut || status === 408 ? MUX_AI_ERROR_TYPES.TIMEOUT_ERROR : status === 429 ? MUX_AI_ERROR_TYPES.CAPACITY_ERROR : MUX_AI_ERROR_TYPES.PROCESSING_ERROR;
|
|
873
|
+
} else {
|
|
874
|
+
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;
|
|
875
|
+
type = source === MUX_AI_ERROR_SOURCES.INTERNAL ? MUX_AI_ERROR_TYPES.SERVER_ERROR : MUX_AI_ERROR_TYPES.VALIDATION_ERROR;
|
|
876
|
+
}
|
|
877
|
+
const authFailure = !transient && (status === 401 || status === 403);
|
|
878
|
+
return {
|
|
879
|
+
type,
|
|
880
|
+
source,
|
|
881
|
+
facts: {
|
|
882
|
+
call,
|
|
883
|
+
...status !== void 0 && { status },
|
|
884
|
+
...requestId && { requestId },
|
|
885
|
+
...authFailure && init.authInputs?.length && { inputs: [...init.authInputs] },
|
|
886
|
+
...facts
|
|
887
|
+
},
|
|
888
|
+
// Set here, not left to the default: only the call site knows a missing status
|
|
889
|
+
// means no response (transient), rather than a failure the dependency reported.
|
|
890
|
+
// A non-idempotent call may have taken effect only with no response or a 5xx;
|
|
891
|
+
// a 408, 425 or 429 means it wasn't processed, so retrying stays safe.
|
|
892
|
+
transient: init.transient ?? (init.idempotent === false && (status === void 0 || status >= 500) ? false : transient),
|
|
893
|
+
...init.retryable !== void 0 && { retryable: init.retryable }
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
function dependencyError(message, init) {
|
|
897
|
+
const { source, ...classification } = classifyDependencyFailure(init);
|
|
898
|
+
const where = { source, dependency: init.dependency };
|
|
899
|
+
return new MuxAiError(message, { ...classification, ...where, cause: init.cause });
|
|
900
|
+
}
|
|
901
|
+
function httpStatusOf(error) {
|
|
902
|
+
if (typeof error !== "object" || error === null) {
|
|
903
|
+
return void 0;
|
|
904
|
+
}
|
|
905
|
+
const { status, statusCode } = error;
|
|
906
|
+
const candidate = typeof status === "number" ? status : statusCode;
|
|
907
|
+
return typeof candidate === "number" && candidate >= 100 && candidate < 600 ? candidate : void 0;
|
|
908
|
+
}
|
|
909
|
+
function requestIdOf(headers) {
|
|
910
|
+
if (!headers || typeof headers !== "object") {
|
|
911
|
+
return void 0;
|
|
912
|
+
}
|
|
913
|
+
const names = ["x-request-id", "x-amz-request-id", "request-id"];
|
|
914
|
+
for (const name of names) {
|
|
915
|
+
const value = typeof headers.get === "function" ? headers.get(name) : headers[name];
|
|
916
|
+
if (typeof value === "string" && value) {
|
|
917
|
+
return value;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
return void 0;
|
|
921
|
+
}
|
|
922
|
+
function dependencyErrorFrom(error, message, init) {
|
|
923
|
+
if (MuxAiError.is(error)) {
|
|
924
|
+
return error;
|
|
925
|
+
}
|
|
926
|
+
return dependencyError(message, {
|
|
927
|
+
...init,
|
|
928
|
+
status: httpStatusOf(error),
|
|
929
|
+
requestId: requestIdOf(error?.headers),
|
|
930
|
+
cause: error
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// src/lib/google-errors.ts
|
|
935
|
+
var GoogleTokenSchema = z2.string().regex(/^[\w.-]{1,128}$/);
|
|
936
|
+
var GoogleErrorBodySchema = z2.object({
|
|
937
|
+
error: z2.object({
|
|
938
|
+
status: GoogleTokenSchema.optional(),
|
|
939
|
+
details: z2.array(z2.object({
|
|
940
|
+
violations: z2.array(z2.object({ quotaId: GoogleTokenSchema.optional() })).max(16).optional()
|
|
941
|
+
})).max(16).optional()
|
|
942
|
+
})
|
|
943
|
+
});
|
|
944
|
+
function googleErrorFacts(responseBody) {
|
|
945
|
+
if (!responseBody) {
|
|
946
|
+
return {};
|
|
947
|
+
}
|
|
948
|
+
let body;
|
|
949
|
+
try {
|
|
950
|
+
body = JSON.parse(responseBody);
|
|
951
|
+
} catch {
|
|
952
|
+
return {};
|
|
953
|
+
}
|
|
954
|
+
const parsed = GoogleErrorBodySchema.safeParse(body);
|
|
955
|
+
if (!parsed.success) {
|
|
956
|
+
return {};
|
|
957
|
+
}
|
|
958
|
+
const quotaIds = [...new Set((parsed.data.error.details ?? []).flatMap((detail) => detail.violations ?? []).map((violation) => violation.quotaId).filter((quotaId) => quotaId !== void 0))];
|
|
959
|
+
return {
|
|
960
|
+
...parsed.data.error.status && { providerStatus: parsed.data.error.status },
|
|
961
|
+
...quotaIds.length > 0 && { quotaIds }
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
function googleCallError(apiError, message, init) {
|
|
965
|
+
return dependencyError(message, {
|
|
966
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
967
|
+
call: init.call,
|
|
968
|
+
status: apiError.statusCode,
|
|
969
|
+
requestId: requestIdOf(apiError.responseHeaders),
|
|
970
|
+
facts: { ...init.facts, ...googleErrorFacts(apiError.responseBody) },
|
|
971
|
+
cause: init.cause ?? apiError
|
|
972
|
+
});
|
|
973
|
+
}
|
|
846
974
|
|
|
847
975
|
// src/lib/legacy-mux-ai-error.ts
|
|
848
976
|
function legacySource(type) {
|
|
@@ -980,50 +1108,50 @@ async function withRetry(fn, {
|
|
|
980
1108
|
}
|
|
981
1109
|
|
|
982
1110
|
// src/lib/content-policy-error.ts
|
|
983
|
-
var PolicyTokenSchema =
|
|
984
|
-
var SafetyRatingSchema =
|
|
1111
|
+
var PolicyTokenSchema = z3.string().trim().min(1).max(64).regex(/^[A-Z0-9_]+$/);
|
|
1112
|
+
var SafetyRatingSchema = z3.object({
|
|
985
1113
|
category: PolicyTokenSchema.nullish(),
|
|
986
|
-
blocked:
|
|
1114
|
+
blocked: z3.boolean().nullish()
|
|
987
1115
|
});
|
|
988
|
-
var ContentPolicyResponseSchema =
|
|
989
|
-
promptFeedback:
|
|
1116
|
+
var ContentPolicyResponseSchema = z3.object({
|
|
1117
|
+
promptFeedback: z3.object({
|
|
990
1118
|
blockReason: PolicyTokenSchema.nullish(),
|
|
991
|
-
safetyRatings:
|
|
1119
|
+
safetyRatings: z3.array(SafetyRatingSchema).max(32).nullish()
|
|
992
1120
|
}).nullish(),
|
|
993
|
-
candidates:
|
|
1121
|
+
candidates: z3.array(z3.object({
|
|
994
1122
|
finishReason: PolicyTokenSchema.nullish(),
|
|
995
|
-
safetyRatings:
|
|
1123
|
+
safetyRatings: z3.array(SafetyRatingSchema).max(32).nullish()
|
|
996
1124
|
})).max(8).nullish()
|
|
997
1125
|
});
|
|
998
|
-
var ContentPolicyUsageResponseSchema =
|
|
999
|
-
usageMetadata:
|
|
1000
|
-
promptTokenCount:
|
|
1001
|
-
candidatesTokenCount:
|
|
1002
|
-
totalTokenCount:
|
|
1003
|
-
cachedContentTokenCount:
|
|
1004
|
-
thoughtsTokenCount:
|
|
1126
|
+
var ContentPolicyUsageResponseSchema = z3.object({
|
|
1127
|
+
usageMetadata: z3.object({
|
|
1128
|
+
promptTokenCount: z3.number().finite().nonnegative().nullish(),
|
|
1129
|
+
candidatesTokenCount: z3.number().finite().nonnegative().nullish(),
|
|
1130
|
+
totalTokenCount: z3.number().finite().nonnegative().nullish(),
|
|
1131
|
+
cachedContentTokenCount: z3.number().finite().nonnegative().nullish(),
|
|
1132
|
+
thoughtsTokenCount: z3.number().finite().nonnegative().nullish()
|
|
1005
1133
|
}).nullish()
|
|
1006
1134
|
});
|
|
1007
|
-
var OpenAIRefusalResponseSchema =
|
|
1008
|
-
output:
|
|
1009
|
-
type:
|
|
1010
|
-
content:
|
|
1135
|
+
var OpenAIRefusalResponseSchema = z3.object({
|
|
1136
|
+
output: z3.array(z3.object({
|
|
1137
|
+
type: z3.string(),
|
|
1138
|
+
content: z3.array(z3.object({ type: z3.string() })).max(32).nullish()
|
|
1011
1139
|
})).max(8)
|
|
1012
1140
|
});
|
|
1013
|
-
var OpenAIUsageResponseSchema =
|
|
1014
|
-
usage:
|
|
1015
|
-
input_tokens:
|
|
1016
|
-
output_tokens:
|
|
1017
|
-
total_tokens:
|
|
1018
|
-
input_tokens_details:
|
|
1019
|
-
cached_tokens:
|
|
1020
|
-
cache_write_tokens:
|
|
1141
|
+
var OpenAIUsageResponseSchema = z3.object({
|
|
1142
|
+
usage: z3.object({
|
|
1143
|
+
input_tokens: z3.number().finite().nonnegative(),
|
|
1144
|
+
output_tokens: z3.number().finite().nonnegative(),
|
|
1145
|
+
total_tokens: z3.number().finite().nonnegative().optional(),
|
|
1146
|
+
input_tokens_details: z3.object({
|
|
1147
|
+
cached_tokens: z3.number().finite().nonnegative().nullish(),
|
|
1148
|
+
cache_write_tokens: z3.number().finite().nonnegative().nullish()
|
|
1021
1149
|
}).nullish(),
|
|
1022
|
-
output_tokens_details:
|
|
1150
|
+
output_tokens_details: z3.object({ reasoning_tokens: z3.number().finite().nonnegative().nullish() }).nullish()
|
|
1023
1151
|
})
|
|
1024
1152
|
});
|
|
1025
|
-
var OpenAIPolicyErrorSchema =
|
|
1026
|
-
error:
|
|
1153
|
+
var OpenAIPolicyErrorSchema = z3.object({
|
|
1154
|
+
error: z3.object({ code: z3.enum(["content_policy_violation", "content_filter"]) })
|
|
1027
1155
|
});
|
|
1028
1156
|
var CONTENT_POLICY_REASONS = /* @__PURE__ */ new Set([
|
|
1029
1157
|
"BLOCKLIST",
|
|
@@ -1038,6 +1166,15 @@ var CONTENT_POLICY_REASONS = /* @__PURE__ */ new Set([
|
|
|
1038
1166
|
"SAFETY",
|
|
1039
1167
|
"SPII"
|
|
1040
1168
|
]);
|
|
1169
|
+
function modelCallFacts(context) {
|
|
1170
|
+
return { call: context.call, provider: context.provider, ...context.model && { model: context.model } };
|
|
1171
|
+
}
|
|
1172
|
+
function withUsage(error, usage) {
|
|
1173
|
+
if (usage) {
|
|
1174
|
+
error.usage = usage;
|
|
1175
|
+
}
|
|
1176
|
+
return error;
|
|
1177
|
+
}
|
|
1041
1178
|
var IncompleteGenerationError = class extends LegacyMuxAiError {
|
|
1042
1179
|
constructor(finishReason, rawFinishReason, usage) {
|
|
1043
1180
|
const reason = rawFinishReason ?? finishReason;
|
|
@@ -1054,18 +1191,47 @@ var IncompleteGenerationError = class extends LegacyMuxAiError {
|
|
|
1054
1191
|
function isIncompleteGenerationError(error) {
|
|
1055
1192
|
return MuxAiError.is(error) && typeof error.finishReason === "string";
|
|
1056
1193
|
}
|
|
1057
|
-
|
|
1194
|
+
function incompleteGenerationError(finishReason, rawFinishReason, usage, context) {
|
|
1195
|
+
if (!context) {
|
|
1196
|
+
return new IncompleteGenerationError(finishReason, rawFinishReason, usage);
|
|
1197
|
+
}
|
|
1198
|
+
const reason = rawFinishReason ?? finishReason;
|
|
1199
|
+
const facts = { ...modelCallFacts(context), finishReason, ...rawFinishReason && { rawFinishReason } };
|
|
1200
|
+
const error = finishReason === "length" ? new MuxAiError(`The model reached its output limit before producing a complete response (finish reason: ${reason}).`, {
|
|
1201
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_TRUNCATED,
|
|
1202
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
1203
|
+
source: MUX_AI_ERROR_SOURCES.INTERNAL,
|
|
1204
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
1205
|
+
facts
|
|
1206
|
+
}) : new MuxAiError(`The model stopped before producing a complete response (finish reason: ${reason}).`, {
|
|
1207
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INCOMPLETE,
|
|
1208
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
1209
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
1210
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
1211
|
+
facts
|
|
1212
|
+
});
|
|
1213
|
+
Object.assign(error, { finishReason, ...rawFinishReason && { rawFinishReason } });
|
|
1214
|
+
return withUsage(error, usage);
|
|
1215
|
+
}
|
|
1216
|
+
async function withContentPolicyErrorHandling(operation, context) {
|
|
1217
|
+
try {
|
|
1218
|
+
return await normalizeContentPolicyErrors(operation, context);
|
|
1219
|
+
} catch (error) {
|
|
1220
|
+
throw (context && classifyModelCallError(error, context)) ?? error;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
async function normalizeContentPolicyErrors(operation, context) {
|
|
1058
1224
|
try {
|
|
1059
1225
|
return await operation();
|
|
1060
1226
|
} catch (error) {
|
|
1061
|
-
rethrowContentPolicyError(error);
|
|
1227
|
+
rethrowContentPolicyError(error, context);
|
|
1062
1228
|
}
|
|
1063
1229
|
}
|
|
1064
|
-
async function withContentPolicyAwareRetry(operation, retryOptions) {
|
|
1230
|
+
async function withContentPolicyAwareRetry(operation, retryOptions, context) {
|
|
1065
1231
|
const retriedUsage = [];
|
|
1066
1232
|
try {
|
|
1067
1233
|
const response = await withRetry(
|
|
1068
|
-
() =>
|
|
1234
|
+
() => normalizeContentPolicyErrors(operation, context),
|
|
1069
1235
|
{
|
|
1070
1236
|
...retryOptions,
|
|
1071
1237
|
onRetry: (error, attempt) => {
|
|
@@ -1079,7 +1245,7 @@ async function withContentPolicyAwareRetry(operation, retryOptions) {
|
|
|
1079
1245
|
);
|
|
1080
1246
|
return includeRetriedUsage(response, retriedUsage);
|
|
1081
1247
|
} catch (error) {
|
|
1082
|
-
rethrowWithTokenUsage(error, retriedUsage);
|
|
1248
|
+
rethrowWithTokenUsage((context && classifyModelCallError(error, context)) ?? error, retriedUsage);
|
|
1083
1249
|
}
|
|
1084
1250
|
}
|
|
1085
1251
|
function includeRetriedUsage(response, retriedUsage) {
|
|
@@ -1111,31 +1277,112 @@ function includeRetriedUsage(response, retriedUsage) {
|
|
|
1111
1277
|
}
|
|
1112
1278
|
return Object.create(Object.getPrototypeOf(response), descriptors);
|
|
1113
1279
|
}
|
|
1114
|
-
function rethrowContentPolicyError(error) {
|
|
1280
|
+
function rethrowContentPolicyError(error, context) {
|
|
1115
1281
|
const block = extractContentPolicyBlock(error);
|
|
1116
1282
|
if (!block) {
|
|
1117
1283
|
throw error;
|
|
1118
1284
|
}
|
|
1119
|
-
throwContentPolicyError(block, getContentPolicyTokenUsage(error));
|
|
1285
|
+
throwContentPolicyError(block, getContentPolicyTokenUsage(error), context);
|
|
1286
|
+
}
|
|
1287
|
+
function findProviderCallError(error) {
|
|
1288
|
+
let current = RetryError.isInstance(error) ? error.lastError : error;
|
|
1289
|
+
for (let depth = 0; depth < 3 && current; depth++) {
|
|
1290
|
+
if (APICallError2.isInstance(current)) {
|
|
1291
|
+
return current;
|
|
1292
|
+
}
|
|
1293
|
+
current = current.cause;
|
|
1294
|
+
}
|
|
1295
|
+
return void 0;
|
|
1296
|
+
}
|
|
1297
|
+
function classifyModelCallError(error, context) {
|
|
1298
|
+
if (MuxAiError.is(error)) {
|
|
1299
|
+
return void 0;
|
|
1300
|
+
}
|
|
1301
|
+
const last = RetryError.isInstance(error) ? error.lastError : error;
|
|
1302
|
+
const unusable = classifyUnusableOutput(last, error, context);
|
|
1303
|
+
if (unusable) {
|
|
1304
|
+
return unusable;
|
|
1305
|
+
}
|
|
1306
|
+
const apiError = findProviderCallError(error);
|
|
1307
|
+
if (!apiError) {
|
|
1308
|
+
return void 0;
|
|
1309
|
+
}
|
|
1310
|
+
const message = `${context.call} failed${apiError.statusCode ? ` (HTTP ${apiError.statusCode})` : ""}`;
|
|
1311
|
+
switch (context.provider) {
|
|
1312
|
+
case "google":
|
|
1313
|
+
return withUsage(googleCallError(apiError, message, { call: context.call, facts: modelCallFacts(context), cause: error }), getErrorTokenUsage(error));
|
|
1314
|
+
default:
|
|
1315
|
+
return void 0;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
function classifyUnusableOutput(last, error, context) {
|
|
1319
|
+
const parse = NoObjectGeneratedError.isInstance(last);
|
|
1320
|
+
if (!parse && !NoOutputGeneratedError2.isInstance(last)) {
|
|
1321
|
+
return void 0;
|
|
1322
|
+
}
|
|
1323
|
+
if (parse && last.finishReason && last.finishReason !== "stop") {
|
|
1324
|
+
return incompleteGenerationError(last.finishReason, void 0, getErrorTokenUsage(error), context);
|
|
1325
|
+
}
|
|
1326
|
+
const init = {
|
|
1327
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
1328
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
1329
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
1330
|
+
facts: modelCallFacts(context),
|
|
1331
|
+
// As before classification: a raw parse failure was retried by the step runner.
|
|
1332
|
+
transient: true,
|
|
1333
|
+
cause: error
|
|
1334
|
+
};
|
|
1335
|
+
const classified = parse ? new MuxAiError(`${context.call} returned output that could not be parsed`, { ...init, code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID }) : new MuxAiError(`${context.call} returned no output`, { ...init, code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_MISSING });
|
|
1336
|
+
return withUsage(classified, getErrorTokenUsage(error));
|
|
1120
1337
|
}
|
|
1121
|
-
function getGeneratedOutputWithContentPolicyHandling(response) {
|
|
1338
|
+
function getGeneratedOutputWithContentPolicyHandling(response, context) {
|
|
1122
1339
|
if (response.finishReason === "content-filter") {
|
|
1123
1340
|
const rawReason = PolicyTokenSchema.safeParse(response.rawFinishReason);
|
|
1124
1341
|
const reason = rawReason.success && isContentPolicyReason(rawReason.data) ? rawReason.data : "CONTENT_FILTER";
|
|
1125
|
-
throwContentPolicyError({ reason }, getErrorTokenUsage(response));
|
|
1342
|
+
throwContentPolicyError({ reason }, getErrorTokenUsage(response), context);
|
|
1126
1343
|
}
|
|
1127
1344
|
if (response.finishReason !== "stop") {
|
|
1128
1345
|
const rawReason = PolicyTokenSchema.safeParse(response.rawFinishReason);
|
|
1129
|
-
throw
|
|
1346
|
+
throw incompleteGenerationError(
|
|
1130
1347
|
response.finishReason,
|
|
1131
1348
|
rawReason.success ? rawReason.data : void 0,
|
|
1132
|
-
getErrorTokenUsage(response)
|
|
1349
|
+
getErrorTokenUsage(response),
|
|
1350
|
+
context
|
|
1133
1351
|
);
|
|
1134
1352
|
}
|
|
1135
|
-
|
|
1353
|
+
if (!context) {
|
|
1354
|
+
return response.output;
|
|
1355
|
+
}
|
|
1356
|
+
let output;
|
|
1357
|
+
try {
|
|
1358
|
+
output = response.output;
|
|
1359
|
+
} catch (error) {
|
|
1360
|
+
throw classifyUnusableOutput(error, error, context) ?? error;
|
|
1361
|
+
}
|
|
1362
|
+
if (output === void 0 || output === null) {
|
|
1363
|
+
throw withUsage(new MuxAiError(`${context.call} returned no output`, {
|
|
1364
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_MISSING,
|
|
1365
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
1366
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
1367
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
1368
|
+
facts: modelCallFacts(context),
|
|
1369
|
+
// As before classification: callers' plain "output missing" errors were retried by the step runner.
|
|
1370
|
+
transient: true
|
|
1371
|
+
}), getErrorTokenUsage(response));
|
|
1372
|
+
}
|
|
1373
|
+
return output;
|
|
1136
1374
|
}
|
|
1137
|
-
function throwContentPolicyError(block, usage) {
|
|
1375
|
+
function throwContentPolicyError(block, usage, context) {
|
|
1138
1376
|
const category = block.category ? `; category: ${block.category}` : "";
|
|
1377
|
+
if (context) {
|
|
1378
|
+
throw withUsage(new MuxAiError(`The supplied content was blocked by a content policy (reason: ${block.reason}${category}).`, {
|
|
1379
|
+
code: MUX_AI_ERROR_CODES.CONTENT_POLICY_BLOCKED,
|
|
1380
|
+
type: MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR,
|
|
1381
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
1382
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
1383
|
+
facts: { ...modelCallFacts(context), reason: block.reason, ...block.category && { category: block.category } }
|
|
1384
|
+
}), usage);
|
|
1385
|
+
}
|
|
1139
1386
|
const contentPolicyError = new LegacyMuxAiError(
|
|
1140
1387
|
`The supplied content was blocked by a content policy (reason: ${block.reason}${category}).`,
|
|
1141
1388
|
{
|
|
@@ -1487,7 +1734,7 @@ function repairText(options) {
|
|
|
1487
1734
|
// src/workflows/ask-questions.ts
|
|
1488
1735
|
import { generateText as generateText2, Output as Output2 } from "ai";
|
|
1489
1736
|
import dedent2 from "dedent";
|
|
1490
|
-
import { z as
|
|
1737
|
+
import { z as z5 } from "zod";
|
|
1491
1738
|
|
|
1492
1739
|
// src/lib/image-download.ts
|
|
1493
1740
|
import pRetry, { AbortError } from "p-retry";
|
|
@@ -2317,8 +2564,68 @@ async function getApiKeyFromEnv(provider, credentials) {
|
|
|
2317
2564
|
return resolveProviderApiKey(provider, credentials);
|
|
2318
2565
|
}
|
|
2319
2566
|
|
|
2567
|
+
// src/lib/mux-video-errors.ts
|
|
2568
|
+
import { z as z4 } from "zod";
|
|
2569
|
+
var MuxTokenSchema = z4.string().regex(/^[\w.-]{1,64}$/);
|
|
2570
|
+
var MuxApiErrorSchema = z4.object({
|
|
2571
|
+
error: z4.object({
|
|
2572
|
+
error: z4.object({ type: MuxTokenSchema })
|
|
2573
|
+
})
|
|
2574
|
+
});
|
|
2575
|
+
function muxVideoErrorFacts(error) {
|
|
2576
|
+
const parsed = MuxApiErrorSchema.safeParse(error);
|
|
2577
|
+
return parsed.success ? { muxErrorType: parsed.data.error.error.type } : {};
|
|
2578
|
+
}
|
|
2579
|
+
function muxVideoError(message, init) {
|
|
2580
|
+
return dependencyError(message, {
|
|
2581
|
+
...init,
|
|
2582
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
2583
|
+
notFoundSource: MUX_AI_ERROR_SOURCES.ASSET,
|
|
2584
|
+
authSource: MUX_AI_ERROR_SOURCES.ACCOUNT,
|
|
2585
|
+
authInputs: ["credentials"],
|
|
2586
|
+
// A create may have taken effect despite the failure; retrying could duplicate the track.
|
|
2587
|
+
idempotent: init.call !== "create_track"
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
function muxVideoCallError(message, call, error, facts) {
|
|
2591
|
+
if (MuxAiError.is(error)) {
|
|
2592
|
+
if (facts) {
|
|
2593
|
+
Object.assign(error, { facts: { ...facts, ...error.facts } });
|
|
2594
|
+
}
|
|
2595
|
+
return error;
|
|
2596
|
+
}
|
|
2597
|
+
return muxVideoError(message, {
|
|
2598
|
+
call,
|
|
2599
|
+
status: httpStatusOf(error),
|
|
2600
|
+
requestId: requestIdOf(error?.headers),
|
|
2601
|
+
facts: { ...facts, ...muxVideoErrorFacts(error) },
|
|
2602
|
+
cause: error
|
|
2603
|
+
});
|
|
2604
|
+
}
|
|
2605
|
+
function muxAssetFetchError(assetId, error) {
|
|
2606
|
+
if (!MuxAiError.is(error) && httpStatusOf(error) === 404) {
|
|
2607
|
+
return new MuxAiError(`Mux asset ${assetId} not found`, {
|
|
2608
|
+
code: MUX_AI_ERROR_CODES.ASSET_NOT_FOUND,
|
|
2609
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
2610
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
2611
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
2612
|
+
facts: { call: "get_asset", status: 404, assetId, inputs: ["assetId"], ...muxVideoErrorFacts(error) },
|
|
2613
|
+
cause: error
|
|
2614
|
+
});
|
|
2615
|
+
}
|
|
2616
|
+
return muxVideoCallError("Failed to fetch the asset from Mux", "get_asset", error, { assetId });
|
|
2617
|
+
}
|
|
2618
|
+
function missingTrackIdError(message, facts) {
|
|
2619
|
+
return new MuxAiError(message, {
|
|
2620
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
2621
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
2622
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.MUX_VIDEO,
|
|
2623
|
+
facts: { call: "create_track", ...facts }
|
|
2624
|
+
});
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2320
2627
|
// src/lib/mux-assets.ts
|
|
2321
|
-
function getPlaybackId(asset) {
|
|
2628
|
+
function getPlaybackId(asset, options = {}) {
|
|
2322
2629
|
const playbackIds = asset.playback_ids || [];
|
|
2323
2630
|
const publicPlaybackId = playbackIds.find((pid) => pid.policy === "public");
|
|
2324
2631
|
if (publicPlaybackId?.id) {
|
|
@@ -2328,10 +2635,16 @@ function getPlaybackId(asset) {
|
|
|
2328
2635
|
if (signedPlaybackId?.id) {
|
|
2329
2636
|
return { id: signedPlaybackId.id, policy: "signed" };
|
|
2330
2637
|
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
{ type: "validation_error" }
|
|
2334
|
-
|
|
2638
|
+
const message = "No public or signed playback ID found for this asset. DRM playback IDs are not currently supported.";
|
|
2639
|
+
if (!options.classifiedErrors) {
|
|
2640
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
2641
|
+
}
|
|
2642
|
+
throw new MuxAiError(message, {
|
|
2643
|
+
code: MUX_AI_ERROR_CODES.PLAYBACK_ID_NOT_FOUND,
|
|
2644
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
2645
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
2646
|
+
facts: { assetId: asset.id, playbackPolicies: [...new Set(playbackIds.map((pid) => pid.policy).filter(Boolean))] }
|
|
2647
|
+
});
|
|
2335
2648
|
}
|
|
2336
2649
|
function isAudioOnlyAsset(asset) {
|
|
2337
2650
|
const hasAudioTrack = asset.tracks?.some((track) => track.type === "audio") ?? false;
|
|
@@ -2343,17 +2656,41 @@ function isVideoOnlyAsset(asset) {
|
|
|
2343
2656
|
const hasVideoTrack = asset.tracks?.some((track) => track.type === "video") ?? false;
|
|
2344
2657
|
return hasVideoTrack && !hasAudioTrack;
|
|
2345
2658
|
}
|
|
2346
|
-
function toPlaybackAsset(asset) {
|
|
2347
|
-
const { id: playbackId, policy } = getPlaybackId(asset);
|
|
2659
|
+
function toPlaybackAsset(asset, options = {}) {
|
|
2660
|
+
const { id: playbackId, policy } = getPlaybackId(asset, options);
|
|
2348
2661
|
return { asset, playbackId, policy };
|
|
2349
2662
|
}
|
|
2350
|
-
async function getPlaybackIdForAsset(assetId, credentials, assetSnapshot) {
|
|
2663
|
+
async function getPlaybackIdForAsset(assetId, credentials, assetSnapshot, options = {}) {
|
|
2351
2664
|
"use step";
|
|
2352
|
-
|
|
2665
|
+
if (!options.classifiedErrors) {
|
|
2666
|
+
const asset2 = assetSnapshot ?? await getMuxAsset(assetId, credentials);
|
|
2667
|
+
if (asset2.id !== assetId) {
|
|
2668
|
+
throw new LegacyMuxAiError("Asset snapshot does not match the requested asset ID.", { type: "validation_error" });
|
|
2669
|
+
}
|
|
2670
|
+
return toPlaybackAsset(asset2);
|
|
2671
|
+
}
|
|
2672
|
+
let asset = assetSnapshot;
|
|
2673
|
+
if (!asset) {
|
|
2674
|
+
let mux;
|
|
2675
|
+
try {
|
|
2676
|
+
mux = await (await getMuxClientFromEnv(credentials)).createClient();
|
|
2677
|
+
} catch (error) {
|
|
2678
|
+
wrapError(error, "Failed to create a Mux client", { assetId });
|
|
2679
|
+
}
|
|
2680
|
+
try {
|
|
2681
|
+
asset = await mux.video.assets.retrieve(assetId);
|
|
2682
|
+
} catch (error) {
|
|
2683
|
+
throw muxAssetFetchError(assetId, error);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2353
2686
|
if (asset.id !== assetId) {
|
|
2354
|
-
throw new
|
|
2687
|
+
throw new MuxAiError("Asset snapshot does not match the requested asset ID.", {
|
|
2688
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
2689
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
2690
|
+
facts: { assetId, snapshotAssetId: asset.id, inputs: ["assetId", "assetSnapshot"] }
|
|
2691
|
+
});
|
|
2355
2692
|
}
|
|
2356
|
-
return toPlaybackAsset(asset);
|
|
2693
|
+
return toPlaybackAsset(asset, options);
|
|
2357
2694
|
}
|
|
2358
2695
|
async function getMuxAsset(assetId, credentials) {
|
|
2359
2696
|
"use step";
|
|
@@ -3307,17 +3644,17 @@ var ASK_QUESTIONS_MAX_QUESTION_LENGTH = 600;
|
|
|
3307
3644
|
var ASK_QUESTIONS_MAX_QUESTIONS_PER_CALL = 50;
|
|
3308
3645
|
var ASK_QUESTIONS_DEFAULT_MAX_ANSWER_OPTION_LENGTH = 150;
|
|
3309
3646
|
var ASK_QUESTIONS_DEFAULT_MAX_FREE_FORM_ANSWER_LENGTH = 500;
|
|
3310
|
-
var questionAnswerSchema =
|
|
3311
|
-
question:
|
|
3312
|
-
answer:
|
|
3313
|
-
confidence:
|
|
3314
|
-
reasoning:
|
|
3315
|
-
skipped:
|
|
3647
|
+
var questionAnswerSchema = z5.object({
|
|
3648
|
+
question: z5.string().describe("The full text of the original question"),
|
|
3649
|
+
answer: z5.string().nullable(),
|
|
3650
|
+
confidence: z5.number(),
|
|
3651
|
+
reasoning: z5.string().max(1e3),
|
|
3652
|
+
skipped: z5.boolean()
|
|
3316
3653
|
});
|
|
3317
3654
|
var SKIP_SENTINEL = "__SKIPPED__";
|
|
3318
3655
|
function createAskQuestionsSchema(answerSchema) {
|
|
3319
|
-
return
|
|
3320
|
-
answers:
|
|
3656
|
+
return z5.object({
|
|
3657
|
+
answers: z5.array(
|
|
3321
3658
|
questionAnswerSchema.extend({
|
|
3322
3659
|
answer: answerSchema
|
|
3323
3660
|
})
|
|
@@ -3679,12 +4016,12 @@ function buildResponseSchemaForQuestions(normalizedQuestions, maxFreeFormAnswerL
|
|
|
3679
4016
|
SKIP_SENTINEL.length,
|
|
3680
4017
|
longestConstrained
|
|
3681
4018
|
);
|
|
3682
|
-
return createAskQuestionsSchema(
|
|
4019
|
+
return createAskQuestionsSchema(z5.string().min(1).max(schemaMax));
|
|
3683
4020
|
}
|
|
3684
4021
|
const allowed = Array.from(
|
|
3685
4022
|
new Set(normalizedQuestions.flatMap(allowedAnswersForQuestion))
|
|
3686
4023
|
);
|
|
3687
|
-
return createAskQuestionsSchema(
|
|
4024
|
+
return createAskQuestionsSchema(z5.enum([...allowed, SKIP_SENTINEL]));
|
|
3688
4025
|
}
|
|
3689
4026
|
async function analyzeQuestions({
|
|
3690
4027
|
provider,
|
|
@@ -4003,11 +4340,11 @@ async function askQuestionsInternal(assetId, questions, options, collectedUsage)
|
|
|
4003
4340
|
// src/workflows/burned-in-captions.ts
|
|
4004
4341
|
import { generateText as generateText3, Output as Output3 } from "ai";
|
|
4005
4342
|
import dedent3 from "dedent";
|
|
4006
|
-
import { z as
|
|
4007
|
-
var burnedInCaptionsSchema =
|
|
4008
|
-
hasBurnedInCaptions:
|
|
4009
|
-
confidence:
|
|
4010
|
-
detectedLanguage:
|
|
4343
|
+
import { z as z6 } from "zod";
|
|
4344
|
+
var burnedInCaptionsSchema = z6.object({
|
|
4345
|
+
hasBurnedInCaptions: z6.boolean(),
|
|
4346
|
+
confidence: z6.number(),
|
|
4347
|
+
detectedLanguage: z6.string().max(100).nullable()
|
|
4011
4348
|
});
|
|
4012
4349
|
var SYSTEM_PROMPT2 = promptDedent`
|
|
4013
4350
|
<role>
|
|
@@ -4247,7 +4584,7 @@ async function hasBurnedInCaptionsInternal(assetId, options, collectedUsage) {
|
|
|
4247
4584
|
// src/workflows/chapters.ts
|
|
4248
4585
|
import { generateText as generateText4, Output as Output4 } from "ai";
|
|
4249
4586
|
import dedent5 from "dedent";
|
|
4250
|
-
import { z as
|
|
4587
|
+
import { z as z7 } from "zod";
|
|
4251
4588
|
|
|
4252
4589
|
// src/prompts/chapters.ts
|
|
4253
4590
|
import dedent4 from "dedent";
|
|
@@ -4272,12 +4609,12 @@ function createChapterGuidance({
|
|
|
4272
4609
|
}
|
|
4273
4610
|
|
|
4274
4611
|
// src/workflows/chapters.ts
|
|
4275
|
-
var chapterSchema =
|
|
4276
|
-
startTime:
|
|
4277
|
-
title:
|
|
4612
|
+
var chapterSchema = z7.object({
|
|
4613
|
+
startTime: z7.number(),
|
|
4614
|
+
title: z7.string().max(300)
|
|
4278
4615
|
});
|
|
4279
|
-
var chaptersSchema =
|
|
4280
|
-
chapters:
|
|
4616
|
+
var chaptersSchema = z7.object({
|
|
4617
|
+
chapters: z7.array(chapterSchema)
|
|
4281
4618
|
});
|
|
4282
4619
|
async function generateChaptersWithAI({
|
|
4283
4620
|
provider,
|
|
@@ -4648,7 +4985,7 @@ async function generateChaptersInternal(assetId, options, collectedUsage) {
|
|
|
4648
4985
|
|
|
4649
4986
|
// src/workflows/edit-captions.ts
|
|
4650
4987
|
import { generateText as generateText5, Output as Output5 } from "ai";
|
|
4651
|
-
import { z as
|
|
4988
|
+
import { z as z8 } from "zod";
|
|
4652
4989
|
|
|
4653
4990
|
// src/lib/mux-tracks.ts
|
|
4654
4991
|
var MUX_TRACK_PASSTHROUGH_MAX_CHARS = 255;
|
|
@@ -4796,25 +5133,95 @@ function isDuplicateTrackNameError(error) {
|
|
|
4796
5133
|
function isNotFoundError(error) {
|
|
4797
5134
|
return typeof error === "object" && error !== null && error.status === 404;
|
|
4798
5135
|
}
|
|
5136
|
+
function trackFacts(track) {
|
|
5137
|
+
return Object.fromEntries(
|
|
5138
|
+
Object.entries({
|
|
5139
|
+
id: track.id,
|
|
5140
|
+
type: track.type,
|
|
5141
|
+
name: track.name,
|
|
5142
|
+
languageCode: track.languageCode,
|
|
5143
|
+
status: track.status,
|
|
5144
|
+
textSource: track.textSource,
|
|
5145
|
+
primary: track.primary
|
|
5146
|
+
}).filter(([, value]) => value !== void 0)
|
|
5147
|
+
);
|
|
5148
|
+
}
|
|
5149
|
+
function trackTargetFacts(target) {
|
|
5150
|
+
return {
|
|
5151
|
+
trackType: targetType(target),
|
|
5152
|
+
languageCode: target.languageCode,
|
|
5153
|
+
...target.name !== void 0 && { trackName: target.name }
|
|
5154
|
+
};
|
|
5155
|
+
}
|
|
5156
|
+
function trackSummaryFacts(tracks) {
|
|
5157
|
+
return tracks.map(trackFacts);
|
|
5158
|
+
}
|
|
5159
|
+
function trackReplacementBlockedError(blocked, options = {}) {
|
|
5160
|
+
const message = options.message ?? blocked.reason;
|
|
5161
|
+
const facts = {
|
|
5162
|
+
...options.facts,
|
|
5163
|
+
reason: blocked.code,
|
|
5164
|
+
conflictingTracks: trackSummaryFacts(blocked.tracks)
|
|
5165
|
+
};
|
|
5166
|
+
if (blocked.code === "primary_audio" && blocked.conflictsOnLanguage) {
|
|
5167
|
+
return new MuxAiError(message, {
|
|
5168
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
5169
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
5170
|
+
facts
|
|
5171
|
+
});
|
|
5172
|
+
}
|
|
5173
|
+
return new MuxAiError(message, {
|
|
5174
|
+
code: MUX_AI_ERROR_CODES.TRACK_REPLACEMENT_BLOCKED,
|
|
5175
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
5176
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
5177
|
+
facts
|
|
5178
|
+
});
|
|
5179
|
+
}
|
|
4799
5180
|
function buildMuxAiTrackPassthrough(workflow) {
|
|
4800
5181
|
return JSON.stringify({ mux_ai: { workflow } });
|
|
4801
5182
|
}
|
|
4802
|
-
function validateTrackPassthrough(passthrough) {
|
|
5183
|
+
function validateTrackPassthrough(passthrough, options = {}) {
|
|
4803
5184
|
if (passthrough !== void 0 && passthrough.length > MUX_TRACK_PASSTHROUGH_MAX_CHARS) {
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
{ type: "validation_error" }
|
|
4807
|
-
|
|
5185
|
+
const message = `Track passthrough must be at most ${MUX_TRACK_PASSTHROUGH_MAX_CHARS} characters (received ${passthrough.length}).`;
|
|
5186
|
+
if (!options.classifiedErrors) {
|
|
5187
|
+
throw new LegacyMuxAiError(message, { type: "validation_error" });
|
|
5188
|
+
}
|
|
5189
|
+
throw new MuxAiError(message, {
|
|
5190
|
+
code: MUX_AI_ERROR_CODES.INVALID_PARAMETER,
|
|
5191
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
5192
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
5193
|
+
facts: { parameter: "trackPassthrough", reason: "too_long", length: passthrough.length, maxLength: MUX_TRACK_PASSTHROUGH_MAX_CHARS, inputs: ["trackPassthrough"] }
|
|
5194
|
+
});
|
|
4808
5195
|
}
|
|
4809
5196
|
return passthrough;
|
|
4810
5197
|
}
|
|
4811
|
-
async function fetchVttFromMux(vttUrl) {
|
|
5198
|
+
async function fetchVttFromMux(vttUrl, options = {}) {
|
|
4812
5199
|
"use step";
|
|
4813
|
-
|
|
5200
|
+
if (!options.classifiedErrors) {
|
|
5201
|
+
const vttResponse2 = await fetch(vttUrl);
|
|
5202
|
+
if (!vttResponse2.ok) {
|
|
5203
|
+
throw new Error(`Failed to fetch VTT file: ${vttResponse2.statusText}`);
|
|
5204
|
+
}
|
|
5205
|
+
return vttResponse2.text();
|
|
5206
|
+
}
|
|
5207
|
+
let vttResponse;
|
|
5208
|
+
try {
|
|
5209
|
+
vttResponse = await fetch(vttUrl);
|
|
5210
|
+
} catch (error) {
|
|
5211
|
+
throw muxVideoError("Failed to fetch VTT file from Mux", { call: "fetch_vtt", cause: error });
|
|
5212
|
+
}
|
|
4814
5213
|
if (!vttResponse.ok) {
|
|
4815
|
-
throw
|
|
5214
|
+
throw muxVideoError(`Failed to fetch VTT file from Mux (HTTP ${vttResponse.status})`, {
|
|
5215
|
+
call: "fetch_vtt",
|
|
5216
|
+
status: vttResponse.status,
|
|
5217
|
+
requestId: requestIdOf(vttResponse.headers)
|
|
5218
|
+
});
|
|
5219
|
+
}
|
|
5220
|
+
try {
|
|
5221
|
+
return await vttResponse.text();
|
|
5222
|
+
} catch (error) {
|
|
5223
|
+
throw muxVideoError("Failed to read VTT file from Mux", { call: "fetch_vtt", cause: error });
|
|
4816
5224
|
}
|
|
4817
|
-
return vttResponse.text();
|
|
4818
5225
|
}
|
|
4819
5226
|
async function createTextTrackOnMux(assetId, languageCode, trackName, presignedUrl, credentials, options = {}) {
|
|
4820
5227
|
"use step";
|
|
@@ -4848,10 +5255,13 @@ async function writeTrack(input, plan) {
|
|
|
4848
5255
|
const mux = await muxClient.createClient();
|
|
4849
5256
|
const type = targetType(input.target);
|
|
4850
5257
|
const deleted = [];
|
|
4851
|
-
const failed = (error) => ({
|
|
5258
|
+
const failed = (call, error) => ({
|
|
4852
5259
|
kind: "create_failed",
|
|
4853
5260
|
reason: error instanceof Error ? error.message : String(error),
|
|
4854
|
-
deleted
|
|
5261
|
+
deleted,
|
|
5262
|
+
...input.classifiedErrors && {
|
|
5263
|
+
error: muxVideoCallError(`Mux ${call} failed while writing the ${type} track`, call, error, { assetId: input.assetId })
|
|
5264
|
+
}
|
|
4855
5265
|
});
|
|
4856
5266
|
const clearConflicts = async () => {
|
|
4857
5267
|
let asset;
|
|
@@ -4859,9 +5269,9 @@ async function writeTrack(input, plan) {
|
|
|
4859
5269
|
asset = await mux.video.assets.retrieve(input.assetId);
|
|
4860
5270
|
} catch (error) {
|
|
4861
5271
|
if (deleted.length === 0) {
|
|
4862
|
-
throw error;
|
|
5272
|
+
throw input.classifiedErrors ? muxVideoCallError("Failed to fetch the asset from Mux", "get_asset", error, { assetId: input.assetId }) : error;
|
|
4863
5273
|
}
|
|
4864
|
-
return failed(error);
|
|
5274
|
+
return failed("get_asset", error);
|
|
4865
5275
|
}
|
|
4866
5276
|
const planned = plan(asset);
|
|
4867
5277
|
if (planned.kind === "blocked") {
|
|
@@ -4874,7 +5284,7 @@ async function writeTrack(input, plan) {
|
|
|
4874
5284
|
deleted.push(track);
|
|
4875
5285
|
} catch (error) {
|
|
4876
5286
|
if (!isNotFoundError(error)) {
|
|
4877
|
-
return failed(error);
|
|
5287
|
+
return failed("delete_track", error);
|
|
4878
5288
|
}
|
|
4879
5289
|
}
|
|
4880
5290
|
}
|
|
@@ -4891,7 +5301,8 @@ async function writeTrack(input, plan) {
|
|
|
4891
5301
|
passthrough: input.passthrough
|
|
4892
5302
|
});
|
|
4893
5303
|
if (!track.id) {
|
|
4894
|
-
|
|
5304
|
+
const message = `Failed to create ${type} track: no track ID returned from Mux`;
|
|
5305
|
+
throw input.classifiedErrors ? missingTrackIdError(message, { assetId: input.assetId }) : new Error(message);
|
|
4895
5306
|
}
|
|
4896
5307
|
return track.id;
|
|
4897
5308
|
};
|
|
@@ -4910,10 +5321,23 @@ async function writeTrack(input, plan) {
|
|
|
4910
5321
|
}
|
|
4911
5322
|
continue;
|
|
4912
5323
|
}
|
|
4913
|
-
|
|
5324
|
+
if (input.classifiedErrors && isDuplicateTrackNameError(error)) {
|
|
5325
|
+
break;
|
|
5326
|
+
}
|
|
5327
|
+
return failed("create_track", error);
|
|
4914
5328
|
}
|
|
4915
5329
|
}
|
|
4916
|
-
|
|
5330
|
+
if (!input.classifiedErrors) {
|
|
5331
|
+
return { kind: "create_failed", reason: "Mux rejected the track name as not unique after retrying.", deleted };
|
|
5332
|
+
}
|
|
5333
|
+
return {
|
|
5334
|
+
kind: "blocked",
|
|
5335
|
+
code: "name_collision",
|
|
5336
|
+
reason: `Mux rejected the track name '${input.target.name.trim()}' as not unique after retrying. Choose a different track name.`,
|
|
5337
|
+
tracks: [],
|
|
5338
|
+
conflictsOnLanguage: false,
|
|
5339
|
+
deleted
|
|
5340
|
+
};
|
|
4917
5341
|
}
|
|
4918
5342
|
async function replaceAndCreateTextTrack(input) {
|
|
4919
5343
|
"use step";
|
|
@@ -5133,6 +5557,17 @@ async function createPresignedGetUrl({
|
|
|
5133
5557
|
}
|
|
5134
5558
|
|
|
5135
5559
|
// src/lib/storage-adapter.ts
|
|
5560
|
+
function storageNotConfiguredError(missing) {
|
|
5561
|
+
return new MuxAiError(
|
|
5562
|
+
"Storage configuration is required for uploading. Provide s3Endpoint and s3Bucket in options or set S3_ENDPOINT and S3_BUCKET. If no storageAdapter is supplied, also set S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY.",
|
|
5563
|
+
{
|
|
5564
|
+
code: MUX_AI_ERROR_CODES.STORAGE_NOT_CONFIGURED,
|
|
5565
|
+
type: MUX_AI_ERROR_TYPES.SERVER_ERROR,
|
|
5566
|
+
source: MUX_AI_ERROR_SOURCES.INTERNAL,
|
|
5567
|
+
facts: { missing }
|
|
5568
|
+
}
|
|
5569
|
+
);
|
|
5570
|
+
}
|
|
5136
5571
|
function requireCredentials(accessKeyId, secretAccessKey) {
|
|
5137
5572
|
if (!accessKeyId || !secretAccessKey) {
|
|
5138
5573
|
throw new Error(
|
|
@@ -5175,8 +5610,8 @@ async function createPresignedGetUrlWithStorageAdapter(input, adapter) {
|
|
|
5175
5610
|
}
|
|
5176
5611
|
|
|
5177
5612
|
// src/workflows/edit-captions.ts
|
|
5178
|
-
var profanityDetectionSchema =
|
|
5179
|
-
profanity:
|
|
5613
|
+
var profanityDetectionSchema = z8.object({
|
|
5614
|
+
profanity: z8.array(z8.string().max(100)).describe(
|
|
5180
5615
|
"Unique profane words or short phrases exactly as they appear in the transcript text. Include each distinct form only once (e.g., if 'fuck' and 'fucking' both appear, list both)."
|
|
5181
5616
|
)
|
|
5182
5617
|
});
|
|
@@ -6154,75 +6589,7 @@ async function generateVideoEmbeddings(assetId, options = {}) {
|
|
|
6154
6589
|
// src/workflows/engagement-insights.ts
|
|
6155
6590
|
import { generateText as generateText6, Output as Output6 } from "ai";
|
|
6156
6591
|
import dedent6 from "dedent";
|
|
6157
|
-
import { z as
|
|
6158
|
-
|
|
6159
|
-
// src/lib/dependency-error.ts
|
|
6160
|
-
function classifyDependencyFailure(init) {
|
|
6161
|
-
const { call, status, requestId, facts, timedOut } = init;
|
|
6162
|
-
const transient = timedOut === true || isTransientStatus(status);
|
|
6163
|
-
let source;
|
|
6164
|
-
let type;
|
|
6165
|
-
if (transient) {
|
|
6166
|
-
source = MUX_AI_ERROR_SOURCES.UPSTREAM;
|
|
6167
|
-
type = timedOut || status === 408 ? MUX_AI_ERROR_TYPES.TIMEOUT_ERROR : status === 429 ? MUX_AI_ERROR_TYPES.CAPACITY_ERROR : MUX_AI_ERROR_TYPES.PROCESSING_ERROR;
|
|
6168
|
-
} else {
|
|
6169
|
-
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;
|
|
6170
|
-
type = source === MUX_AI_ERROR_SOURCES.INTERNAL ? MUX_AI_ERROR_TYPES.SERVER_ERROR : MUX_AI_ERROR_TYPES.VALIDATION_ERROR;
|
|
6171
|
-
}
|
|
6172
|
-
return {
|
|
6173
|
-
type,
|
|
6174
|
-
source,
|
|
6175
|
-
facts: {
|
|
6176
|
-
call,
|
|
6177
|
-
...status !== void 0 && { status },
|
|
6178
|
-
...requestId && { requestId },
|
|
6179
|
-
...facts
|
|
6180
|
-
},
|
|
6181
|
-
// Set here, not left to the default: only the call site knows a missing status
|
|
6182
|
-
// means no response (transient), rather than a failure the dependency reported.
|
|
6183
|
-
// A non-idempotent call may have taken effect only with no response or a 5xx;
|
|
6184
|
-
// a 408, 425 or 429 means it wasn't processed, so retrying stays safe.
|
|
6185
|
-
transient: init.transient ?? (init.idempotent === false && (status === void 0 || status >= 500) ? false : transient),
|
|
6186
|
-
...init.retryable !== void 0 && { retryable: init.retryable }
|
|
6187
|
-
};
|
|
6188
|
-
}
|
|
6189
|
-
function dependencyError(message, init) {
|
|
6190
|
-
const { source, ...classification } = classifyDependencyFailure(init);
|
|
6191
|
-
const where = { source, dependency: init.dependency };
|
|
6192
|
-
return new MuxAiError(message, { ...classification, ...where, cause: init.cause });
|
|
6193
|
-
}
|
|
6194
|
-
function httpStatusOf(error) {
|
|
6195
|
-
if (typeof error !== "object" || error === null) {
|
|
6196
|
-
return void 0;
|
|
6197
|
-
}
|
|
6198
|
-
const { status, statusCode } = error;
|
|
6199
|
-
const candidate = typeof status === "number" ? status : statusCode;
|
|
6200
|
-
return typeof candidate === "number" && candidate >= 100 && candidate < 600 ? candidate : void 0;
|
|
6201
|
-
}
|
|
6202
|
-
function requestIdOf(headers) {
|
|
6203
|
-
if (!headers || typeof headers !== "object") {
|
|
6204
|
-
return void 0;
|
|
6205
|
-
}
|
|
6206
|
-
const names = ["x-request-id", "x-amz-request-id", "request-id"];
|
|
6207
|
-
for (const name of names) {
|
|
6208
|
-
const value = typeof headers.get === "function" ? headers.get(name) : headers[name];
|
|
6209
|
-
if (typeof value === "string" && value) {
|
|
6210
|
-
return value;
|
|
6211
|
-
}
|
|
6212
|
-
}
|
|
6213
|
-
return void 0;
|
|
6214
|
-
}
|
|
6215
|
-
function dependencyErrorFrom(error, message, init) {
|
|
6216
|
-
if (MuxAiError.is(error)) {
|
|
6217
|
-
return error;
|
|
6218
|
-
}
|
|
6219
|
-
return dependencyError(message, {
|
|
6220
|
-
...init,
|
|
6221
|
-
status: httpStatusOf(error),
|
|
6222
|
-
requestId: requestIdOf(error?.headers),
|
|
6223
|
-
cause: error
|
|
6224
|
-
});
|
|
6225
|
-
}
|
|
6592
|
+
import { z as z9 } from "zod";
|
|
6226
6593
|
|
|
6227
6594
|
// src/primitives/heatmap.ts
|
|
6228
6595
|
async function getHeatmapForAsset(assetId, options = {}) {
|
|
@@ -6364,20 +6731,20 @@ async function getShotsForAsset(assetId, options = {}) {
|
|
|
6364
6731
|
}
|
|
6365
6732
|
|
|
6366
6733
|
// src/workflows/engagement-insights.ts
|
|
6367
|
-
var aiMomentInsightSchema =
|
|
6368
|
-
hotspotIndex:
|
|
6369
|
-
startMs:
|
|
6370
|
-
endMs:
|
|
6371
|
-
timestamp:
|
|
6372
|
-
engagementScore:
|
|
6373
|
-
insight:
|
|
6734
|
+
var aiMomentInsightSchema = z9.object({
|
|
6735
|
+
hotspotIndex: z9.number(),
|
|
6736
|
+
startMs: z9.number(),
|
|
6737
|
+
endMs: z9.number(),
|
|
6738
|
+
timestamp: z9.string(),
|
|
6739
|
+
engagementScore: z9.number(),
|
|
6740
|
+
insight: z9.string().max(1e3)
|
|
6374
6741
|
});
|
|
6375
|
-
var aiOverallInsightSchema =
|
|
6376
|
-
summary:
|
|
6377
|
-
trends:
|
|
6742
|
+
var aiOverallInsightSchema = z9.object({
|
|
6743
|
+
summary: z9.string().max(2e3),
|
|
6744
|
+
trends: z9.array(z9.string().max(500))
|
|
6378
6745
|
});
|
|
6379
|
-
var engagementInsightsSchema =
|
|
6380
|
-
momentInsights:
|
|
6746
|
+
var engagementInsightsSchema = z9.object({
|
|
6747
|
+
momentInsights: z9.array(aiMomentInsightSchema),
|
|
6381
6748
|
overallInsight: aiOverallInsightSchema
|
|
6382
6749
|
});
|
|
6383
6750
|
var SYSTEM_PROMPT4 = promptDedent`
|
|
@@ -6941,7 +7308,7 @@ async function generateEngagementInsightsInternal(assetId, options, collectedUsa
|
|
|
6941
7308
|
|
|
6942
7309
|
// src/workflows/generate-text.ts
|
|
6943
7310
|
import { APICallError as APICallError4, generateText as generateTextWithModel, Output as Output7 } from "ai";
|
|
6944
|
-
import { z as
|
|
7311
|
+
import { z as z10 } from "zod";
|
|
6945
7312
|
var GENERATE_TEXT_MAX_VARIANTS = 5;
|
|
6946
7313
|
var GENERATE_TEXT_MAX_ARTIFACTS = 5;
|
|
6947
7314
|
var GENERATE_TEXT_MAX_INSTRUCTIONS_CHARS = 500;
|
|
@@ -7116,14 +7483,14 @@ async function getCompletedShots(assetId, credentials) {
|
|
|
7116
7483
|
}
|
|
7117
7484
|
return void 0;
|
|
7118
7485
|
}
|
|
7119
|
-
var briefSchema =
|
|
7120
|
-
centralIdea:
|
|
7121
|
-
readerValue:
|
|
7122
|
-
keyPoints:
|
|
7123
|
-
sourceSpecifics:
|
|
7124
|
-
visualContext:
|
|
7125
|
-
voiceSignals:
|
|
7126
|
-
claimsToQualify:
|
|
7486
|
+
var briefSchema = z10.object({
|
|
7487
|
+
centralIdea: z10.string().max(500),
|
|
7488
|
+
readerValue: z10.string().max(500),
|
|
7489
|
+
keyPoints: z10.array(z10.string().max(500)),
|
|
7490
|
+
sourceSpecifics: z10.array(z10.string().max(500)),
|
|
7491
|
+
visualContext: z10.array(z10.string().max(500)),
|
|
7492
|
+
voiceSignals: z10.array(z10.string().max(300)),
|
|
7493
|
+
claimsToQualify: z10.array(z10.string().max(500))
|
|
7127
7494
|
});
|
|
7128
7495
|
var BRIEF_LIST_LIMITS = {
|
|
7129
7496
|
keyPoints: 8,
|
|
@@ -7384,7 +7751,7 @@ async function extractBriefWithModel(args) {
|
|
|
7384
7751
|
};
|
|
7385
7752
|
});
|
|
7386
7753
|
}
|
|
7387
|
-
var artifactSchema =
|
|
7754
|
+
var artifactSchema = z10.object({ content: z10.string() });
|
|
7388
7755
|
async function generateArtifactWithModel(args) {
|
|
7389
7756
|
"use step";
|
|
7390
7757
|
const diagnostics = { phase: "draft", provider: args.provider, modelId: args.modelId };
|
|
@@ -7645,7 +8012,7 @@ async function generateTextInternal(assetId, rawOptions, collectedUsage) {
|
|
|
7645
8012
|
}
|
|
7646
8013
|
|
|
7647
8014
|
// src/workflows/moderation.ts
|
|
7648
|
-
import { z as
|
|
8015
|
+
import { z as z11 } from "zod";
|
|
7649
8016
|
|
|
7650
8017
|
// src/lib/sampling-plan.ts
|
|
7651
8018
|
var DEFAULT_FPS = 30;
|
|
@@ -7836,11 +8203,11 @@ function parseOpenAIModerationResponse(bodyText, status, statusText) {
|
|
|
7836
8203
|
);
|
|
7837
8204
|
}
|
|
7838
8205
|
}
|
|
7839
|
-
var OpenAIModerationResponseSchema =
|
|
7840
|
-
results:
|
|
7841
|
-
category_scores:
|
|
7842
|
-
sexual:
|
|
7843
|
-
violence:
|
|
8206
|
+
var OpenAIModerationResponseSchema = z11.object({
|
|
8207
|
+
results: z11.array(z11.object({
|
|
8208
|
+
category_scores: z11.object({
|
|
8209
|
+
sexual: z11.number().finite().nullish(),
|
|
8210
|
+
violence: z11.number().finite().nullish()
|
|
7844
8211
|
})
|
|
7845
8212
|
}))
|
|
7846
8213
|
});
|
|
@@ -8630,7 +8997,7 @@ async function getModerationScores(assetId, options = {}) {
|
|
|
8630
8997
|
|
|
8631
8998
|
// src/workflows/summarization.ts
|
|
8632
8999
|
import { generateText as generateText8, Output as Output8 } from "ai";
|
|
8633
|
-
import { z as
|
|
9000
|
+
import { z as z12 } from "zod";
|
|
8634
9001
|
|
|
8635
9002
|
// src/lib/markdown-normalization.ts
|
|
8636
9003
|
var ESCAPED_LINE_BREAK_REGEX = /\\r\\n|\\n|\\r/g;
|
|
@@ -8775,17 +9142,17 @@ function createSummarizationGuidance({
|
|
|
8775
9142
|
}
|
|
8776
9143
|
|
|
8777
9144
|
// src/workflows/summarization.ts
|
|
8778
|
-
var summarySchema =
|
|
8779
|
-
keywords:
|
|
8780
|
-
title:
|
|
8781
|
-
description:
|
|
9145
|
+
var summarySchema = z12.object({
|
|
9146
|
+
keywords: z12.array(z12.string().max(200)),
|
|
9147
|
+
title: z12.string().max(500),
|
|
9148
|
+
description: z12.string().max(1e4)
|
|
8782
9149
|
});
|
|
8783
9150
|
function buildSummarySchema(descriptionLength) {
|
|
8784
9151
|
const descriptionMaxChars = Math.max(2e3, descriptionLength * 15);
|
|
8785
|
-
return
|
|
8786
|
-
keywords:
|
|
8787
|
-
title:
|
|
8788
|
-
description:
|
|
9152
|
+
return z12.object({
|
|
9153
|
+
keywords: z12.array(z12.string().max(200)),
|
|
9154
|
+
title: z12.string().max(500),
|
|
9155
|
+
description: z12.string().max(descriptionMaxChars)
|
|
8789
9156
|
});
|
|
8790
9157
|
}
|
|
8791
9158
|
var VALID_TONES = ["neutral", "playful", "professional"];
|
|
@@ -10129,14 +10496,14 @@ import {
|
|
|
10129
10496
|
APICallError as APICallError5,
|
|
10130
10497
|
generateText as generateText9,
|
|
10131
10498
|
NoObjectGeneratedError as NoObjectGeneratedError3,
|
|
10132
|
-
NoOutputGeneratedError as
|
|
10499
|
+
NoOutputGeneratedError as NoOutputGeneratedError3,
|
|
10133
10500
|
Output as Output9,
|
|
10134
10501
|
RetryError as RetryError2,
|
|
10135
10502
|
TypeValidationError
|
|
10136
10503
|
} from "ai";
|
|
10137
|
-
import { z as
|
|
10138
|
-
var translationSchema =
|
|
10139
|
-
translation:
|
|
10504
|
+
import { z as z13 } from "zod";
|
|
10505
|
+
var translationSchema = z13.object({
|
|
10506
|
+
translation: z13.string()
|
|
10140
10507
|
});
|
|
10141
10508
|
var SYSTEM_PROMPT5 = promptDedent`
|
|
10142
10509
|
You are a subtitle translation expert. Translate VTT subtitle files to the target language specified by the user.
|
|
@@ -10190,39 +10557,44 @@ var CUE_TRANSLATION_SYSTEM_PROMPT = promptDedent`
|
|
|
10190
10557
|
`;
|
|
10191
10558
|
var MAX_NEVER_TRANSLATE_TERMS = 100;
|
|
10192
10559
|
var MAX_NEVER_TRANSLATE_TERM_CHARS = 100;
|
|
10560
|
+
function neverTranslateError(message, reason, facts = {}) {
|
|
10561
|
+
return new MuxAiError(message, {
|
|
10562
|
+
code: MUX_AI_ERROR_CODES.INVALID_PARAMETER,
|
|
10563
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
10564
|
+
source: MUX_AI_ERROR_SOURCES.REQUEST,
|
|
10565
|
+
facts: { parameter: "neverTranslate", reason, ...facts, inputs: ["neverTranslate"] }
|
|
10566
|
+
});
|
|
10567
|
+
}
|
|
10193
10568
|
function validateNeverTranslateTerms(terms) {
|
|
10194
10569
|
if (terms.length > MAX_NEVER_TRANSLATE_TERMS) {
|
|
10195
|
-
throw
|
|
10570
|
+
throw neverTranslateError(
|
|
10196
10571
|
`neverTranslate accepts at most ${MAX_NEVER_TRANSLATE_TERMS} terms (received ${terms.length}).`,
|
|
10197
|
-
|
|
10572
|
+
"too_many",
|
|
10573
|
+
{ count: terms.length, max: MAX_NEVER_TRANSLATE_TERMS }
|
|
10198
10574
|
);
|
|
10199
10575
|
}
|
|
10200
10576
|
const validated = [];
|
|
10201
10577
|
const seen = /* @__PURE__ */ new Set();
|
|
10202
|
-
for (const term of terms) {
|
|
10578
|
+
for (const [index, term] of terms.entries()) {
|
|
10203
10579
|
const trimmed = term.trim();
|
|
10204
10580
|
if (trimmed.length === 0) {
|
|
10205
|
-
throw
|
|
10206
|
-
"neverTranslate terms must be non-empty.",
|
|
10207
|
-
{ type: "validation_error" }
|
|
10208
|
-
);
|
|
10581
|
+
throw neverTranslateError("neverTranslate terms must be non-empty.", "empty", { index });
|
|
10209
10582
|
}
|
|
10210
10583
|
if (trimmed.length > MAX_NEVER_TRANSLATE_TERM_CHARS) {
|
|
10211
|
-
throw
|
|
10584
|
+
throw neverTranslateError(
|
|
10212
10585
|
`neverTranslate terms must be at most ${MAX_NEVER_TRANSLATE_TERM_CHARS} characters (received ${trimmed.length}).`,
|
|
10213
|
-
|
|
10586
|
+
"too_long",
|
|
10587
|
+
{ index, length: trimmed.length, maxLength: MAX_NEVER_TRANSLATE_TERM_CHARS }
|
|
10214
10588
|
);
|
|
10215
10589
|
}
|
|
10216
10590
|
if (trimmed.includes("<") || trimmed.includes(">")) {
|
|
10217
|
-
throw
|
|
10218
|
-
"neverTranslate terms must not contain '<' or '>'.",
|
|
10219
|
-
{ type: "validation_error" }
|
|
10220
|
-
);
|
|
10591
|
+
throw neverTranslateError("neverTranslate terms must not contain '<' or '>'.", "disallowed_characters", { index, characters: ["<", ">"] });
|
|
10221
10592
|
}
|
|
10222
10593
|
if (sanitizeUntrustedText(trimmed) !== trimmed) {
|
|
10223
|
-
throw
|
|
10594
|
+
throw neverTranslateError(
|
|
10224
10595
|
"neverTranslate terms must not contain invisible characters or characters altered by Unicode NFKC normalization.",
|
|
10225
|
-
|
|
10596
|
+
"not_normalized",
|
|
10597
|
+
{ index }
|
|
10226
10598
|
);
|
|
10227
10599
|
}
|
|
10228
10600
|
const key = trimmed.toLowerCase();
|
|
@@ -10265,35 +10637,73 @@ var DEFAULT_TRANSLATION_CHUNKING = {
|
|
|
10265
10637
|
maxCuesPerChunk: 80,
|
|
10266
10638
|
maxCueTextTokensPerChunk: 2e3
|
|
10267
10639
|
};
|
|
10268
|
-
|
|
10269
|
-
constructor(message) {
|
|
10270
|
-
super(message);
|
|
10271
|
-
this.name = "TranslationChunkValidationError";
|
|
10272
|
-
}
|
|
10273
|
-
};
|
|
10274
|
-
function isTranslationChunkValidationError(error) {
|
|
10275
|
-
return error instanceof TranslationChunkValidationError;
|
|
10276
|
-
}
|
|
10277
|
-
function isProviderServiceError(error) {
|
|
10640
|
+
function findProviderServiceError(error) {
|
|
10278
10641
|
if (!error) {
|
|
10279
|
-
return
|
|
10642
|
+
return void 0;
|
|
10280
10643
|
}
|
|
10281
10644
|
if (RetryError2.isInstance(error)) {
|
|
10282
|
-
return
|
|
10645
|
+
return findProviderServiceError(error.lastError);
|
|
10283
10646
|
}
|
|
10284
10647
|
if (APICallError5.isInstance(error)) {
|
|
10285
|
-
return
|
|
10648
|
+
return error;
|
|
10286
10649
|
}
|
|
10287
10650
|
if (error instanceof Error && "cause" in error) {
|
|
10288
|
-
return
|
|
10651
|
+
return findProviderServiceError(error.cause);
|
|
10289
10652
|
}
|
|
10290
|
-
return
|
|
10653
|
+
return void 0;
|
|
10654
|
+
}
|
|
10655
|
+
function isUnusableOutputError(error) {
|
|
10656
|
+
return NoObjectGeneratedError3.isInstance(error) || NoOutputGeneratedError3.isInstance(error) || TypeValidationError.isInstance(error);
|
|
10291
10657
|
}
|
|
10292
10658
|
function shouldSplitChunkTranslationError(error) {
|
|
10293
|
-
if (
|
|
10659
|
+
if (findProviderServiceError(error)) {
|
|
10294
10660
|
return false;
|
|
10295
10661
|
}
|
|
10296
|
-
return
|
|
10662
|
+
return isUnusableOutputError(error) || isIncompleteGenerationError(error) || // Missing or invalid output, including a wrong cue count.
|
|
10663
|
+
MuxAiError.is(error) && (error.code === MUX_AI_ERROR_CODES.MODEL_OUTPUT_MISSING || error.code === MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID);
|
|
10664
|
+
}
|
|
10665
|
+
function translationStepError(error, message, facts) {
|
|
10666
|
+
if (MuxAiError.is(error)) {
|
|
10667
|
+
Object.assign(error, { facts: { ...facts, ...error.facts } });
|
|
10668
|
+
return error;
|
|
10669
|
+
}
|
|
10670
|
+
const context = { call: String(facts.call), provider: String(facts.provider), ...facts.model !== void 0 && { model: String(facts.model) } };
|
|
10671
|
+
let classified = classifyModelCallError(error, context);
|
|
10672
|
+
if (classified) {
|
|
10673
|
+
Object.assign(classified, { facts: { ...facts, ...classified.facts } });
|
|
10674
|
+
return classified;
|
|
10675
|
+
}
|
|
10676
|
+
if (isUnusableOutputError(error)) {
|
|
10677
|
+
classified = new MuxAiError(message, {
|
|
10678
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
|
|
10679
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
10680
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
10681
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
10682
|
+
facts,
|
|
10683
|
+
// As before: the raw error was retried by the step runner. See the model-output follow-up.
|
|
10684
|
+
transient: true,
|
|
10685
|
+
cause: error
|
|
10686
|
+
});
|
|
10687
|
+
} else {
|
|
10688
|
+
const providerError = findProviderServiceError(error);
|
|
10689
|
+
classified = providerError ? (
|
|
10690
|
+
// A provider without its own classifier: not classified, but kept retryable by the
|
|
10691
|
+
// step runner when the AI SDK judges it retryable (no response, 408, 409, 429, 5xx),
|
|
10692
|
+
// as the raw error was before.
|
|
10693
|
+
new MuxAiError(message, {
|
|
10694
|
+
type: MUX_AI_ERROR_TYPES.SERVER_ERROR,
|
|
10695
|
+
source: MUX_AI_ERROR_SOURCES.INTERNAL,
|
|
10696
|
+
facts,
|
|
10697
|
+
transient: providerError.isRetryable,
|
|
10698
|
+
cause: error
|
|
10699
|
+
})
|
|
10700
|
+
) : internalError(message, facts, error);
|
|
10701
|
+
}
|
|
10702
|
+
const usage = getErrorTokenUsage(error);
|
|
10703
|
+
if (usage) {
|
|
10704
|
+
classified.usage = usage;
|
|
10705
|
+
}
|
|
10706
|
+
return classified;
|
|
10297
10707
|
}
|
|
10298
10708
|
function resolveTranslationChunkingOptions(options) {
|
|
10299
10709
|
const targetChunkDurationSeconds = Math.max(
|
|
@@ -10459,6 +10869,7 @@ async function translateVttWithAI({
|
|
|
10459
10869
|
"use step";
|
|
10460
10870
|
const model = await createLanguageModelFromConfig(provider, modelId, credentials);
|
|
10461
10871
|
const sanitisedVttContent = stripVttMetadataBlocks(vttContent);
|
|
10872
|
+
const context = { call: "translate_vtt", provider, model: modelId };
|
|
10462
10873
|
const response = await withContentPolicyAwareRetry(() => generateText9({
|
|
10463
10874
|
model,
|
|
10464
10875
|
maxRetries: 0,
|
|
@@ -10472,8 +10883,10 @@ async function translateVttWithAI({
|
|
|
10472
10883
|
${sanitisedVttContent}`
|
|
10473
10884
|
}
|
|
10474
10885
|
]
|
|
10475
|
-
}))
|
|
10476
|
-
|
|
10886
|
+
}), void 0, context).catch((error) => {
|
|
10887
|
+
throw translationStepError(error, "Caption translation model call failed", { ...context });
|
|
10888
|
+
});
|
|
10889
|
+
const output = getGeneratedOutputWithContentPolicyHandling(response, context);
|
|
10477
10890
|
const translated = normalizeTranslatedVtt(output.translation);
|
|
10478
10891
|
const leakReason = detectLeakReason(translated);
|
|
10479
10892
|
const safeTranslated = leakReason !== null ? vttContent : translated;
|
|
@@ -10515,8 +10928,8 @@ async function translateCueChunkWithAI({
|
|
|
10515
10928
|
}) {
|
|
10516
10929
|
"use step";
|
|
10517
10930
|
const model = await createLanguageModelFromConfig(provider, modelId, credentials);
|
|
10518
|
-
const schema =
|
|
10519
|
-
translations:
|
|
10931
|
+
const schema = z13.object({
|
|
10932
|
+
translations: z13.array(z13.string().min(1).max(2e3)).length(cues.length)
|
|
10520
10933
|
});
|
|
10521
10934
|
const cuePayload = cues.map((cue, index) => ({
|
|
10522
10935
|
index,
|
|
@@ -10524,6 +10937,7 @@ async function translateCueChunkWithAI({
|
|
|
10524
10937
|
endTime: cue.endTime,
|
|
10525
10938
|
text: cue.text
|
|
10526
10939
|
}));
|
|
10940
|
+
const context = { call: "translate_vtt_chunk", provider, model: modelId };
|
|
10527
10941
|
const response = await withContentPolicyAwareRetry(() => generateText9({
|
|
10528
10942
|
model,
|
|
10529
10943
|
maxRetries: 0,
|
|
@@ -10538,8 +10952,8 @@ Return exactly ${cues.length} translated cues in the same order as the input.${b
|
|
|
10538
10952
|
${JSON.stringify(cuePayload, null, 2)}`
|
|
10539
10953
|
}
|
|
10540
10954
|
]
|
|
10541
|
-
}));
|
|
10542
|
-
const output = getGeneratedOutputWithContentPolicyHandling(response);
|
|
10955
|
+
}), void 0, context);
|
|
10956
|
+
const output = getGeneratedOutputWithContentPolicyHandling(response, context);
|
|
10543
10957
|
const unexpectedKeys = detectUnexpectedKeysFromRawText(
|
|
10544
10958
|
response.text,
|
|
10545
10959
|
schema.keyof().options
|
|
@@ -10565,7 +10979,7 @@ ${JSON.stringify(cuePayload, null, 2)}`
|
|
|
10565
10979
|
function splitTranslationChunkAtMidpoint(chunk) {
|
|
10566
10980
|
const midpoint = Math.floor(chunk.cueCount / 2);
|
|
10567
10981
|
if (midpoint <= 0 || midpoint >= chunk.cueCount) {
|
|
10568
|
-
throw
|
|
10982
|
+
throw internalError("Cannot split a translation chunk with fewer than two cues", { chunkId: chunk.id, cueCount: chunk.cueCount });
|
|
10569
10983
|
}
|
|
10570
10984
|
return [
|
|
10571
10985
|
createTranslationChunkRequest(
|
|
@@ -10590,6 +11004,15 @@ async function translateChunkWithFallback({
|
|
|
10590
11004
|
neverTranslate
|
|
10591
11005
|
}) {
|
|
10592
11006
|
"use step";
|
|
11007
|
+
const chunkFacts = {
|
|
11008
|
+
call: "translate_vtt_chunk",
|
|
11009
|
+
provider,
|
|
11010
|
+
model: modelId,
|
|
11011
|
+
chunkId: chunk.id,
|
|
11012
|
+
cueCount: chunk.cueCount,
|
|
11013
|
+
startTime: Math.round(chunk.startTime),
|
|
11014
|
+
endTime: Math.round(chunk.endTime)
|
|
11015
|
+
};
|
|
10593
11016
|
try {
|
|
10594
11017
|
const result = await translateCueChunkWithAI({
|
|
10595
11018
|
cues: chunk.cues,
|
|
@@ -10601,9 +11024,20 @@ async function translateChunkWithFallback({
|
|
|
10601
11024
|
neverTranslate
|
|
10602
11025
|
});
|
|
10603
11026
|
if (result.translations.length !== chunk.cueCount) {
|
|
10604
|
-
|
|
10605
|
-
`
|
|
11027
|
+
const mismatch = new MuxAiError(
|
|
11028
|
+
`The model returned ${result.translations.length} translated cues, expected ${chunk.cueCount}`,
|
|
11029
|
+
{
|
|
11030
|
+
code: MUX_AI_ERROR_CODES.MODEL_OUTPUT_INVALID,
|
|
11031
|
+
type: MUX_AI_ERROR_TYPES.PROCESSING_ERROR,
|
|
11032
|
+
source: MUX_AI_ERROR_SOURCES.UPSTREAM,
|
|
11033
|
+
dependency: MUX_AI_ERROR_DEPENDENCIES.AI_PROVIDER,
|
|
11034
|
+
facts: { ...chunkFacts, returnedCueCount: result.translations.length, expectedCueCount: chunk.cueCount },
|
|
11035
|
+
// As before (a plain Error subclass, retried by the step runner). See the model-output follow-up.
|
|
11036
|
+
transient: true
|
|
11037
|
+
}
|
|
10606
11038
|
);
|
|
11039
|
+
mismatch.usage = result.usage;
|
|
11040
|
+
throw mismatch;
|
|
10607
11041
|
}
|
|
10608
11042
|
const scrubbedCueCounts = {};
|
|
10609
11043
|
const safeTranslations = result.translations.map((translated, idx) => {
|
|
@@ -10622,7 +11056,7 @@ async function translateChunkWithFallback({
|
|
|
10622
11056
|
};
|
|
10623
11057
|
} catch (error) {
|
|
10624
11058
|
if (!shouldSplitChunkTranslationError(error) || chunk.cueCount <= 1) {
|
|
10625
|
-
|
|
11059
|
+
throw translationStepError(error, "Failed to translate a caption chunk", chunkFacts);
|
|
10626
11060
|
}
|
|
10627
11061
|
const [leftChunk, rightChunk] = splitTranslationChunkAtMidpoint(chunk);
|
|
10628
11062
|
const failedAttemptUsage = getErrorTokenUsage(error);
|
|
@@ -10789,7 +11223,7 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10789
11223
|
const credentials = providedCredentials;
|
|
10790
11224
|
const effectiveStorageAdapter = storageAdapter;
|
|
10791
11225
|
const neverTranslateTerms = neverTranslateOption ? validateNeverTranslateTerms(neverTranslateOption) : [];
|
|
10792
|
-
const trackPassthrough = validateTrackPassthrough(providedTrackPassthrough) ?? buildMuxAiTrackPassthrough("translate-captions");
|
|
11226
|
+
const trackPassthrough = validateTrackPassthrough(providedTrackPassthrough, { classifiedErrors: true }) ?? buildMuxAiTrackPassthrough("translate-captions");
|
|
10793
11227
|
const s3Endpoint = providedS3Endpoint ?? env_default.S3_ENDPOINT;
|
|
10794
11228
|
const s3Region = providedS3Region ?? env_default.S3_REGION ?? "auto";
|
|
10795
11229
|
const s3Bucket = providedS3Bucket ?? env_default.S3_BUCKET;
|
|
@@ -10802,32 +11236,42 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10802
11236
|
model,
|
|
10803
11237
|
provider
|
|
10804
11238
|
});
|
|
10805
|
-
if (uploadToS3
|
|
10806
|
-
|
|
11239
|
+
if (uploadToS3) {
|
|
11240
|
+
const missing = [
|
|
11241
|
+
...s3Endpoint ? [] : ["s3Endpoint"],
|
|
11242
|
+
...s3Bucket ? [] : ["s3Bucket"],
|
|
11243
|
+
...effectiveStorageAdapter || s3AccessKeyId ? [] : ["S3_ACCESS_KEY_ID"],
|
|
11244
|
+
...effectiveStorageAdapter || s3SecretAccessKey ? [] : ["S3_SECRET_ACCESS_KEY"]
|
|
11245
|
+
];
|
|
11246
|
+
if (missing.length > 0) {
|
|
11247
|
+
throw storageNotConfiguredError(missing);
|
|
11248
|
+
}
|
|
10807
11249
|
}
|
|
10808
|
-
const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot);
|
|
11250
|
+
const { asset: assetData, playbackId, policy } = await getPlaybackIdForAsset(assetId, credentials, options.assetSnapshot, { classifiedErrors: true });
|
|
10809
11251
|
const assetDurationSeconds = getAssetDurationSecondsFromAsset(assetData);
|
|
10810
11252
|
const signingContext = await resolveMuxSigningContext(credentials);
|
|
10811
11253
|
if (policy === "signed" && !signingContext) {
|
|
10812
|
-
throw
|
|
10813
|
-
"Signed playback ID requires signing credentials. Set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
|
|
10814
|
-
{ type: "validation_error" }
|
|
10815
|
-
);
|
|
11254
|
+
throw signingCredentialsMissingError();
|
|
10816
11255
|
}
|
|
10817
11256
|
const readyTextTracks = getReadyTextTracks(assetData);
|
|
10818
11257
|
const sourceTextTrack = readyTextTracks.find((t) => t.id === trackId);
|
|
10819
11258
|
if (!sourceTextTrack) {
|
|
10820
|
-
const availableTrackIds = readyTextTracks.map((t) => t.id).filter(
|
|
10821
|
-
throw new
|
|
10822
|
-
`Track ${trackId} not found or not ready on asset ${assetId}. Available track IDs: ${availableTrackIds || "none"}.`,
|
|
10823
|
-
{
|
|
11259
|
+
const availableTrackIds = readyTextTracks.map((t) => t.id).filter((id) => !!id);
|
|
11260
|
+
throw new MuxAiError(
|
|
11261
|
+
`Track ${trackId} not found or not ready on asset ${assetId}. Available track IDs: ${availableTrackIds.join(", ") || "none"}.`,
|
|
11262
|
+
{
|
|
11263
|
+
code: MUX_AI_ERROR_CODES.CAPTION_TRACK_NOT_FOUND,
|
|
11264
|
+
type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR,
|
|
11265
|
+
source: MUX_AI_ERROR_SOURCES.ASSET,
|
|
11266
|
+
facts: { assetId, trackId, availableTrackIds }
|
|
11267
|
+
}
|
|
10824
11268
|
);
|
|
10825
11269
|
}
|
|
10826
11270
|
const fromLanguageCode = sourceTextTrack.language_code;
|
|
10827
11271
|
if (!fromLanguageCode) {
|
|
10828
|
-
throw new
|
|
11272
|
+
throw new MuxAiError(
|
|
10829
11273
|
`Track ${trackId} is missing language metadata. Cannot determine source language for translation.`,
|
|
10830
|
-
{ type:
|
|
11274
|
+
{ type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET, facts: { assetId, trackId } }
|
|
10831
11275
|
);
|
|
10832
11276
|
}
|
|
10833
11277
|
const outputTrack = {
|
|
@@ -10837,15 +11281,15 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10837
11281
|
if (uploadToMux) {
|
|
10838
11282
|
const plan = planTextTrackReplacement(assetData, outputTrack, replaceExistingTracks);
|
|
10839
11283
|
if (plan.kind === "blocked") {
|
|
10840
|
-
throw
|
|
11284
|
+
throw trackReplacementBlockedError(plan, { facts: { ...trackTargetFacts(outputTrack), assetId, policy: replaceExistingTracks } });
|
|
10841
11285
|
}
|
|
10842
11286
|
}
|
|
10843
11287
|
const vttUrl = await buildTranscriptUrl(playbackId, trackId, policy === "signed", credentials);
|
|
10844
11288
|
let vttContent;
|
|
10845
11289
|
try {
|
|
10846
|
-
vttContent = await fetchVttFromMux(vttUrl);
|
|
11290
|
+
vttContent = await fetchVttFromMux(vttUrl, { classifiedErrors: true });
|
|
10847
11291
|
} catch (error) {
|
|
10848
|
-
|
|
11292
|
+
wrapError(error, "Failed to fetch VTT content", { assetId, trackId });
|
|
10849
11293
|
}
|
|
10850
11294
|
let translatedVtt;
|
|
10851
11295
|
let usage;
|
|
@@ -10869,7 +11313,12 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10869
11313
|
scrubbedCueCounts = result.scrubbedCueCounts;
|
|
10870
11314
|
unexpectedKeyCount = result.unexpectedKeyCount;
|
|
10871
11315
|
} catch (error) {
|
|
10872
|
-
|
|
11316
|
+
wrapError(error, `Failed to translate VTT with ${modelConfig.provider}`, {
|
|
11317
|
+
provider: modelConfig.provider,
|
|
11318
|
+
model: modelConfig.modelId,
|
|
11319
|
+
fromLanguageCode,
|
|
11320
|
+
toLanguageCode
|
|
11321
|
+
});
|
|
10873
11322
|
}
|
|
10874
11323
|
const scrubbedFields = [];
|
|
10875
11324
|
for (const [reason, count] of Object.entries(scrubbedCueCounts)) {
|
|
@@ -10922,7 +11371,7 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10922
11371
|
s3SignedUrlExpirySeconds: options.s3SignedUrlExpirySeconds
|
|
10923
11372
|
});
|
|
10924
11373
|
} catch (error) {
|
|
10925
|
-
|
|
11374
|
+
wrapError(error, "Failed to upload VTT to S3", { call: "put_object", bucket: s3Bucket });
|
|
10926
11375
|
}
|
|
10927
11376
|
if (uploadToMux) {
|
|
10928
11377
|
let outcome;
|
|
@@ -10933,17 +11382,27 @@ async function translateCaptionsInternal(assetId, trackId, toLanguageCode, optio
|
|
|
10933
11382
|
policy: replaceExistingTracks,
|
|
10934
11383
|
presignedUrl,
|
|
10935
11384
|
passthrough: trackPassthrough,
|
|
10936
|
-
credentials
|
|
11385
|
+
credentials,
|
|
11386
|
+
classifiedErrors: true
|
|
10937
11387
|
});
|
|
10938
11388
|
} catch (error) {
|
|
10939
|
-
|
|
11389
|
+
wrapError(error, "Failed to fetch the asset before adding the translated track", { assetId });
|
|
10940
11390
|
}
|
|
10941
11391
|
if (outcome.kind !== "created") {
|
|
10942
11392
|
const deletedNote = outcome.deleted.length > 0 ? ` Tracks already deleted before the failure: ${outcome.deleted.map((track) => `${track.name ?? track.id} (${track.id})`).join(", ")}.` : "";
|
|
11393
|
+
const facts = {
|
|
11394
|
+
assetId,
|
|
11395
|
+
languageCode: toLanguageCode,
|
|
11396
|
+
trackName: outputTrack.name,
|
|
11397
|
+
...outcome.deleted.length > 0 && { deletedTracks: trackSummaryFacts(outcome.deleted) }
|
|
11398
|
+
};
|
|
10943
11399
|
if (outcome.kind === "blocked") {
|
|
10944
|
-
throw
|
|
11400
|
+
throw trackReplacementBlockedError(outcome, { message: `${outcome.reason}${deletedNote}`, facts: { ...trackTargetFacts(outputTrack), ...facts } });
|
|
10945
11401
|
}
|
|
10946
|
-
|
|
11402
|
+
const failure = outcome.error ?? internalError(`Track write failed without a classified error: ${outcome.reason}`);
|
|
11403
|
+
Object.assign(failure, { facts: { ...facts, ...failure.facts } });
|
|
11404
|
+
failure.message = `Failed to add translated track to Mux asset: ${failure.message}.${deletedNote}`;
|
|
11405
|
+
throw failure;
|
|
10947
11406
|
}
|
|
10948
11407
|
uploadedTrackId = outcome.trackId;
|
|
10949
11408
|
replacedTracks = outcome.deleted;
|