@mux/ai 0.57.0 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, T as ThumbnailOptions, V as VTTCueBudgetChunkingOptions, b as VTTDurationChunk, c as VTTDurationChunkingOptions, d as chunkByTokens, e as chunkText, f as chunkVTTCues, g as chunkVTTCuesByBudget, h as chunkVTTCuesByDuration, j as estimateTokenCount, k as getHeatmapForAsset, l as getHeatmapForPlaybackId, m as getHeatmapForVideo, n as getStoryboardUrl, o as getThumbnailUrls } from '../index-DiuqBw6I.js';
2
- export { r as CompletedShotsResult, D as DeletedShotsResult, s as ErroredShotsResult, H as Hotspot, t as HotspotOptions, u as HotspotResponse, L as LOW_CONFIDENCE_THRESHOLD, v as MAX_CUE_TEXT_CHARS, w as ParseVTTCuesOptions, x as PendingShotsResult, y as Shot, z as ShotRequestOptions, B as ShotsResult, F as SkippedShotsResult, G as TranscriptEmptyReason, J as TranscriptFetchOptions, K as TranscriptFetchStepResult, N as TranscriptResult, q as VTTCue, O as WaitForShotsOptions, Q as buildTranscriptUrl, R as buildVttFromCueBlocks, X as buildVttFromTranslatedCueBlocks, Y as concatenateVttSegments, Z as extractTextFromVTT, _ as extractTimestampedTranscript, $ as fetchTranscriptDataForUrl, a0 as fetchTranscriptForAsset, a1 as filterVttByScope, a2 as findCaptionTrack, a3 as getHotspotsForAsset, a4 as getHotspotsForPlaybackId, a5 as getHotspotsForVideo, a6 as getReadyTextTracks, a7 as getReliableLanguageCode, a8 as getShotsForAsset, a9 as parseVTTCues, aa as replaceCueText, ab as requestShotsForAsset, ac as sanitizeUntrustedText, ad as secondsToTimestamp, ae as splitVttPreambleAndCueBlocks, af as stripVttMetadataBlocks, ag as vttTimestampToSeconds, ah as waitForShotsForAsset } from '../transcripts-Brw74qlV.js';
1
+ export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, T as ThumbnailOptions, V as VTTCueBudgetChunkingOptions, b as VTTDurationChunk, c as VTTDurationChunkingOptions, d as chunkByTokens, e as chunkText, f as chunkVTTCues, g as chunkVTTCuesByBudget, h as chunkVTTCuesByDuration, j as estimateTokenCount, k as getHeatmapForAsset, l as getHeatmapForPlaybackId, m as getHeatmapForVideo, n as getStoryboardUrl, o as getThumbnailUrls } from '../index-CHA2jigS.js';
2
+ export { r as CompletedShotsResult, D as DeletedShotsResult, s as ErroredShotsResult, H as Hotspot, t as HotspotOptions, u as HotspotResponse, L as LOW_CONFIDENCE_THRESHOLD, v as MAX_CUE_TEXT_CHARS, w as ParseVTTCuesOptions, x as PendingShotsResult, y as Shot, z as ShotRequestOptions, B as ShotsResult, F as SkippedShotsResult, G as TranscriptEmptyReason, J as TranscriptFetchOptions, K as TranscriptFetchStepResult, N as TranscriptResult, q as VTTCue, O as WaitForShotsOptions, Q as buildTranscriptUrl, R as buildVttFromCueBlocks, X as buildVttFromTranslatedCueBlocks, Y as concatenateVttSegments, Z as extractTextFromVTT, _ as extractTimestampedTranscript, $ as fetchTranscriptDataForUrl, a0 as fetchTranscriptForAsset, a1 as filterVttByScope, a2 as findCaptionTrack, a3 as getHotspotsForAsset, a4 as getHotspotsForPlaybackId, a5 as getHotspotsForVideo, a6 as getReadyTextTracks, a7 as getReliableLanguageCode, a8 as getShotsForAsset, a9 as parseVTTCues, aa as replaceCueText, ab as requestShotsForAsset, ac as sanitizeUntrustedText, ad as secondsToTimestamp, ae as splitVttPreambleAndCueBlocks, af as stripVttMetadataBlocks, ag as vttTimestampToSeconds, ah as waitForShotsForAsset } from '../transcripts-DuNI058z.js';
3
3
  import '@mux/ts';
@@ -920,29 +920,244 @@ function getErrorTokenUsage(error) {
920
920
  }
921
921
 
922
922
  // src/lib/mux-ai-error.ts
923
- var MuxAiError = class _MuxAiError extends Error {
924
- constructor(message, opts) {
923
+ var MUX_AI_ERROR_TYPES = {
924
+ /** The request, the asset or the account can't be used as it is. */
925
+ VALIDATION_ERROR: "validation_error",
926
+ /** The work was attempted and failed. */
927
+ PROCESSING_ERROR: "processing_error",
928
+ /** The work didn't finish in time. */
929
+ TIMEOUT_ERROR: "timeout_error",
930
+ /** Content was refused by a content policy. */
931
+ CONTENT_POLICY_ERROR: "content_policy_error",
932
+ /** A service is rate limiting or over capacity. */
933
+ CAPACITY_ERROR: "capacity_error",
934
+ /** A fault in this code or its configuration. */
935
+ SERVER_ERROR: "server_error"
936
+ };
937
+ var MUX_AI_ERROR_TYPE_VALUES = Object.values(MUX_AI_ERROR_TYPES);
938
+ var MUX_AI_ERROR_SOURCES = {
939
+ /** The caller's input, e.g. a scope past the end of the asset. */
940
+ REQUEST: "request",
941
+ /** The Mux asset's state, e.g. no caption track in the requested language. */
942
+ ASSET: "asset",
943
+ /** The Mux account or environment, e.g. missing permissions. */
944
+ ACCOUNT: "account",
945
+ /** A remote service failed, e.g. the dubbing provider reported a failed dub. */
946
+ UPSTREAM: "upstream",
947
+ /** This code, or the configuration of the service running it, e.g. missing signing keys. */
948
+ INTERNAL: "internal"
949
+ };
950
+ var MUX_AI_ERROR_SOURCE_VALUES = Object.values(MUX_AI_ERROR_SOURCES);
951
+ var MUX_AI_ERROR_DEPENDENCIES = {
952
+ /** Mux Video: the API, stream and image delivery, and its static renditions and tracks. */
953
+ MUX_VIDEO: "mux_video",
954
+ /** Mux Data: its API, e.g. engagement data (heatmaps and hotspots). */
955
+ MUX_DATA: "mux_data",
956
+ /** A model or AI service provider, e.g. a language model API or the dubbing provider. */
957
+ AI_PROVIDER: "ai_provider",
958
+ /** Object storage the SDK writes to or reads from, e.g. an S3-compatible bucket. */
959
+ STORAGE: "storage"
960
+ };
961
+ var MUX_AI_ERROR_DEPENDENCY_VALUES = Object.values(MUX_AI_ERROR_DEPENDENCIES);
962
+ var MUX_AI_ERROR_CODES = {
963
+ /** The requested time range is invalid, or has nothing to work with. Facts: `reason` (`invalid_start_time`, `invalid_end_time`, `exceeds_duration`, `empty_range`, `no_video`, `no_transcript`) and the bounds involved. */
964
+ INVALID_SCOPE: "invalid_scope",
965
+ /** Existing tracks block writing the output track under the chosen replacement policy. Facts: `reason` (`policy_fail`, `not_generated`, `name_collision`, `primary_audio`), `conflictingTracks` and the target track. */
966
+ TRACK_REPLACEMENT_BLOCKED: "track_replacement_blocked",
967
+ /** 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. */
968
+ PARAMETER_OUT_OF_RANGE: "parameter_out_of_range",
969
+ /** No ready caption track matches the requested track or language. Facts: `trackId` or `languageCode`, and what is available. */
970
+ CAPTION_TRACK_NOT_FOUND: "caption_track_not_found",
971
+ /** The asset has no public or signed playback ID (DRM-only assets included). */
972
+ PLAYBACK_ID_NOT_FOUND: "playback_id_not_found",
973
+ /** The transcript has no usable content. */
974
+ TRANSCRIPT_EMPTY: "transcript_empty",
975
+ /** The asset has no valid duration, so work that depends on it can't run. Facts: `assetId`. */
976
+ ASSET_DURATION_UNAVAILABLE: "asset_duration_unavailable",
977
+ /** Mux won't add an audio track to this asset. Facts: `reason` (`clip`, `live_stream`, `audio_only`). */
978
+ AUDIO_TRACK_UNSUPPORTED: "audio_track_unsupported",
979
+ /** The asset's existing static rendition can't be used as a source. Facts: `reason` (`unusable`, `too_large`) and the rendition's details. */
980
+ STATIC_RENDITION_UNSUPPORTED: "static_rendition_unsupported",
981
+ /** Signed playback needs signing keys the service running the SDK didn't provide. */
982
+ SIGNING_CREDENTIALS_MISSING: "signing_credentials_missing",
983
+ /** Storage is needed but the service running the SDK didn't configure it. */
984
+ STORAGE_NOT_CONFIGURED: "storage_not_configured",
985
+ /** The model provider refused the content. Facts: `reason` and `category`. */
986
+ CONTENT_POLICY_BLOCKED: "content_policy_blocked",
987
+ /** The model returned no output, or a required field was empty. Facts: `call`, `provider`, `model`, and `assetId` when there is one. */
988
+ MODEL_OUTPUT_MISSING: "model_output_missing",
989
+ /** The model's output breaks the expected shape or constraints (counts, allowed values, limits). Facts: `call`, `provider`, `model`, and `assetId` when there is one. */
990
+ MODEL_OUTPUT_INVALID: "model_output_invalid",
991
+ /** The model's output was withheld by the SDK's output safety filter (a suspected prompt leak). */
992
+ MODEL_OUTPUT_SUPPRESSED: "model_output_suppressed",
993
+ /** The model stopped early for a reason other than the length limit. */
994
+ MODEL_OUTPUT_INCOMPLETE: "model_output_incomplete",
995
+ /** The model hit the output length limit. */
996
+ MODEL_OUTPUT_TRUNCATED: "model_output_truncated",
997
+ /** Mux reported the static rendition a workflow needs as errored. */
998
+ STATIC_RENDITION_FAILED: "static_rendition_failed",
999
+ /** The dubbing provider doesn't support the requested language. Facts: `language` and `which` (`target` or `source`). */
1000
+ DUBBING_LANGUAGE_UNSUPPORTED: "dubbing_language_unsupported",
1001
+ /** The dubbing provider ran the dub and reported it failed. Facts: `providerError`, the provider's display text, when it gave one. */
1002
+ DUBBING_FAILED: "dubbing_failed"
1003
+ };
1004
+ var MUX_AI_ERROR_CODE_VALUES = Object.values(MUX_AI_ERROR_CODES);
1005
+ var MUX_AI_ERROR_CATALOG = {
1006
+ // The caller's input.
1007
+ [MUX_AI_ERROR_CODES.INVALID_SCOPE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
1008
+ [MUX_AI_ERROR_CODES.TRACK_REPLACEMENT_BLOCKED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
1009
+ [MUX_AI_ERROR_CODES.PARAMETER_OUT_OF_RANGE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.REQUEST },
1010
+ // The asset's state.
1011
+ [MUX_AI_ERROR_CODES.CAPTION_TRACK_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
1012
+ [MUX_AI_ERROR_CODES.PLAYBACK_ID_NOT_FOUND]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
1013
+ [MUX_AI_ERROR_CODES.ASSET_DURATION_UNAVAILABLE]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
1014
+ [MUX_AI_ERROR_CODES.TRANSCRIPT_EMPTY]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
1015
+ [MUX_AI_ERROR_CODES.AUDIO_TRACK_UNSUPPORTED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
1016
+ [MUX_AI_ERROR_CODES.STATIC_RENDITION_UNSUPPORTED]: { type: MUX_AI_ERROR_TYPES.VALIDATION_ERROR, source: MUX_AI_ERROR_SOURCES.ASSET },
1017
+ // The configuration of the service running the SDK.
1018
+ [MUX_AI_ERROR_CODES.SIGNING_CREDENTIALS_MISSING]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL },
1019
+ [MUX_AI_ERROR_CODES.STORAGE_NOT_CONFIGURED]: { type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL },
1020
+ // Model calls.
1021
+ [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 },
1022
+ // The model-output policies below keep what these failures did before classification
1023
+ // (fatal, not resubmittable); sites that differed keep their old values explicitly.
1024
+ // Whether they should be retried is an open follow-up, not decided here.
1025
+ [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 },
1026
+ [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 },
1027
+ [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 },
1028
+ // Not transient: a step retry would repeat a full generation; the job can be resubmitted.
1029
+ [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 },
1030
+ [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 },
1031
+ // Mux Video.
1032
+ // Reported by Mux: a step retry would find the same errored rendition, and resubmitting the same asset errors again.
1033
+ [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 },
1034
+ // Audio dubbing.
1035
+ [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 },
1036
+ // Reported by the dubbing provider: a step retry would find the same failed dub.
1037
+ [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 }
1038
+ };
1039
+ function isTransientStatus(status) {
1040
+ return status === void 0 || status === 408 || status === 425 || status === 429 || status >= 500;
1041
+ }
1042
+ function defaultTransient(source, facts = {}) {
1043
+ return source === MUX_AI_ERROR_SOURCES.UPSTREAM && typeof facts.status === "number" && isTransientStatus(facts.status);
1044
+ }
1045
+ function defaultRetryable(type, source, transient) {
1046
+ if (transient || type === MUX_AI_ERROR_TYPES.TIMEOUT_ERROR || type === MUX_AI_ERROR_TYPES.CAPACITY_ERROR) {
1047
+ return true;
1048
+ }
1049
+ if (type === MUX_AI_ERROR_TYPES.VALIDATION_ERROR || type === MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR) {
1050
+ return false;
1051
+ }
1052
+ return source === MUX_AI_ERROR_SOURCES.UPSTREAM;
1053
+ }
1054
+ var MAX_CAUSE_DEPTH = 3;
1055
+ var MAX_CAUSE_MESSAGE_LENGTH = 500;
1056
+ function statusOf(value) {
1057
+ if (typeof value !== "object" || value === null) {
1058
+ return void 0;
1059
+ }
1060
+ const { status, statusCode } = value;
1061
+ const candidate = typeof status === "number" ? status : statusCode;
1062
+ return typeof candidate === "number" && candidate >= 100 && candidate < 600 ? candidate : void 0;
1063
+ }
1064
+ function summarizeCauses(cause) {
1065
+ const causes = [];
1066
+ let current = cause;
1067
+ while (current !== void 0 && current !== null && causes.length < MAX_CAUSE_DEPTH) {
1068
+ if (ClassifiedError.isClassified(current)) {
1069
+ causes.push(...current.causes.slice(0, MAX_CAUSE_DEPTH - causes.length));
1070
+ break;
1071
+ }
1072
+ const status = statusOf(current);
1073
+ causes.push({
1074
+ // Duck-typed: an error from another realm (e.g. a Workflow step VM) fails instanceof.
1075
+ name: typeof current.name === "string" ? current.name : typeof current,
1076
+ message: scrubDetail(extractErrorDetail(current)).slice(0, MAX_CAUSE_MESSAGE_LENGTH),
1077
+ ...status !== void 0 && { status }
1078
+ });
1079
+ current = typeof current === "object" ? current.cause : void 0;
1080
+ }
1081
+ return causes;
1082
+ }
1083
+ var ClassifiedError = class extends Error {
1084
+ constructor(message, init, catalog) {
925
1085
  super(message);
926
- /** Structural brand for duck-type identification. */
927
- this.__robots_error = true;
928
- if (opts?.cause !== void 0) {
929
- Object.defineProperty(this, "cause", { value: opts.cause, writable: true, configurable: true });
1086
+ /** Structural brand shared by every classified error, for duck-type identification across realms. */
1087
+ this.__classified_error = true;
1088
+ const entry = init.code ? catalog[init.code] : void 0;
1089
+ this.type = entry?.type ?? init.type;
1090
+ this.source = entry?.source ?? init.source;
1091
+ const dependency = init.dependency ?? entry?.dependency;
1092
+ if (dependency) {
1093
+ this.dependency = dependency;
930
1094
  }
931
- this.name = "FatalError";
932
- this.publicType = opts?.type ?? "processing_error";
933
- this.publicMessage = message;
934
- this.retryable = opts?.retryable ?? false;
1095
+ if (init.code) {
1096
+ this.code = init.code;
1097
+ }
1098
+ this.facts = init.facts ?? {};
1099
+ this.transient = init.transient ?? entry?.transient ?? defaultTransient(this.source, this.facts);
1100
+ this.retryable = this.transient || (init.retryable ?? entry?.retryable ?? defaultRetryable(this.type, this.source, false));
1101
+ this.name = this.transient ? "Error" : "FatalError";
1102
+ if (init.cause !== void 0) {
1103
+ Object.defineProperty(this, "cause", { value: init.cause, writable: true, configurable: true });
1104
+ }
1105
+ Object.defineProperty(this, "causes", { value: summarizeCauses(init.cause), writable: true, configurable: true });
1106
+ }
1107
+ /** Whether `value` is any classified error, from this copy of the SDK or another. */
1108
+ static isClassified(value) {
1109
+ return typeof value === "object" && value !== null && "__classified_error" in value && value.__classified_error === true;
1110
+ }
1111
+ };
1112
+ function serializeClassification(error) {
1113
+ return {
1114
+ message: error.message,
1115
+ type: error.type,
1116
+ source: error.source,
1117
+ ...error.dependency && { dependency: error.dependency },
1118
+ ...error.code && { code: error.code },
1119
+ facts: error.facts,
1120
+ retryable: error.retryable,
1121
+ transient: error.transient,
1122
+ causes: error.causes,
1123
+ stack: error.stack
1124
+ };
1125
+ }
1126
+ function classificationInit(record) {
1127
+ return {
1128
+ type: record.type,
1129
+ source: record.source,
1130
+ dependency: record.dependency,
1131
+ facts: record.facts,
1132
+ retryable: record.retryable,
1133
+ transient: record.transient
1134
+ };
1135
+ }
1136
+ function restoreClassification(error, record) {
1137
+ if (record.code) {
1138
+ Object.assign(error, { code: record.code });
1139
+ }
1140
+ Object.defineProperty(error, "causes", { value: record.causes, writable: true, configurable: true });
1141
+ if (record.stack !== void 0) {
1142
+ error.stack = record.stack;
1143
+ }
1144
+ return error;
1145
+ }
1146
+ var MuxAiError = class _MuxAiError extends ClassifiedError {
1147
+ constructor(message, init) {
1148
+ super(message, init, MUX_AI_ERROR_CATALOG);
1149
+ /** Structural brand for duck-type identification across copies of the SDK. */
1150
+ this.__mux_ai_error = true;
935
1151
  }
936
1152
  static is(value) {
937
- return typeof value === "object" && value !== null && "__robots_error" in value && value.__robots_error === true;
1153
+ return typeof value === "object" && value !== null && "__mux_ai_error" in value && value.__mux_ai_error === true;
938
1154
  }
1155
+ // Subclasses with their own codec (LegacyMuxAiError) write their own shape.
939
1156
  static [WORKFLOW_SERIALIZE](instance) {
940
1157
  const incomplete = instance;
941
1158
  return {
942
- message: instance.publicMessage,
943
- publicType: instance.publicType,
944
- retryable: instance.retryable,
945
- stack: instance.stack,
1159
+ v: 2,
1160
+ ...serializeClassification(instance),
946
1161
  usage: getErrorTokenUsage(instance),
947
1162
  finishReason: incomplete.finishReason,
948
1163
  rawFinishReason: incomplete.rawFinishReason,
@@ -950,16 +1165,13 @@ var MuxAiError = class _MuxAiError extends Error {
950
1165
  };
951
1166
  }
952
1167
  static [WORKFLOW_DESERIALIZE](value) {
953
- const error = new _MuxAiError(value.message, { type: value.publicType, retryable: value.retryable });
1168
+ const error = restoreClassification(new _MuxAiError(value.message, classificationInit(value)), value);
954
1169
  Object.assign(error, {
955
1170
  usage: value.usage,
956
1171
  diagnostics: value.diagnostics,
957
1172
  ...value.finishReason !== void 0 && { finishReason: value.finishReason },
958
1173
  ...value.rawFinishReason !== void 0 && { rawFinishReason: value.rawFinishReason }
959
1174
  });
960
- if (value.stack !== void 0) {
961
- error.stack = value.stack;
962
- }
963
1175
  return error;
964
1176
  }
965
1177
  };
@@ -978,8 +1190,86 @@ function extractErrorDetail(error) {
978
1190
  }
979
1191
  return "Unknown error";
980
1192
  }
981
- function wrapError(error, message) {
982
- if (MuxAiError.is(error)) {
1193
+ var URL_IN_TEXT = /https?:\/\/[^\s"'<>]+/g;
1194
+ var URL_QUERY = /^([^?#]+)[?#].*$/s;
1195
+ function stripUrlQueries(text) {
1196
+ return text.replace(URL_IN_TEXT, (match) => {
1197
+ let url;
1198
+ try {
1199
+ url = new URL(match);
1200
+ } catch {
1201
+ return match.replace(URL_QUERY, "$1?\u2026");
1202
+ }
1203
+ if (!url.username && !url.password && !url.search && !url.hash) {
1204
+ return match;
1205
+ }
1206
+ return `${url.origin}${url.pathname}${url.search || url.hash ? "?\u2026" : ""}`;
1207
+ });
1208
+ }
1209
+ function scrubDetail(detail, context) {
1210
+ const leakReason = detectLeakReason(detail);
1211
+ if (leakReason !== "canary" && leakReason !== "prompt_tag") {
1212
+ return stripUrlQueries(detail);
1213
+ }
1214
+ console.warn(`[@mux/ai] Suppressed suspected prompt leak in error detail${context ? ` (context: ${context})` : ""} (reason: ${leakReason}).`);
1215
+ return "Upstream error details suppressed by safety filter";
1216
+ }
1217
+
1218
+ // src/lib/legacy-mux-ai-error.ts
1219
+ function legacySource(type) {
1220
+ switch (type) {
1221
+ case MUX_AI_ERROR_TYPES.VALIDATION_ERROR:
1222
+ return MUX_AI_ERROR_SOURCES.REQUEST;
1223
+ case MUX_AI_ERROR_TYPES.CONTENT_POLICY_ERROR:
1224
+ return MUX_AI_ERROR_SOURCES.ASSET;
1225
+ default:
1226
+ return MUX_AI_ERROR_SOURCES.INTERNAL;
1227
+ }
1228
+ }
1229
+ var LegacyMuxAiError = class _LegacyMuxAiError extends MuxAiError {
1230
+ constructor(message, opts) {
1231
+ const type = opts?.type ?? MUX_AI_ERROR_TYPES.PROCESSING_ERROR;
1232
+ super(message, { type, source: legacySource(type), retryable: opts?.retryable ?? false, transient: false, cause: opts?.cause });
1233
+ this.__robots_error = true;
1234
+ this.publicType = type;
1235
+ this.publicMessage = message;
1236
+ }
1237
+ // Its own codec, so a legacy error crosses step boundaries in its previous shape and
1238
+ // revives as a legacy error (subclasses such as IncompleteGenerationError inherit it).
1239
+ static [WORKFLOW_SERIALIZE](instance) {
1240
+ const incomplete = instance;
1241
+ return {
1242
+ message: instance.publicMessage,
1243
+ publicType: instance.publicType,
1244
+ retryable: instance.retryable,
1245
+ stack: instance.stack,
1246
+ usage: getErrorTokenUsage(instance),
1247
+ finishReason: incomplete.finishReason,
1248
+ rawFinishReason: incomplete.rawFinishReason,
1249
+ diagnostics: instance.diagnostics
1250
+ };
1251
+ }
1252
+ // Typed to match the base codec; this codec only ever reads the legacy shape it writes.
1253
+ static [WORKFLOW_DESERIALIZE](record) {
1254
+ const value = record;
1255
+ const error = new _LegacyMuxAiError(value.message, { type: value.publicType, retryable: value.retryable });
1256
+ Object.assign(error, {
1257
+ usage: value.usage,
1258
+ diagnostics: value.diagnostics,
1259
+ ...value.finishReason !== void 0 && { finishReason: value.finishReason },
1260
+ ...value.rawFinishReason !== void 0 && { rawFinishReason: value.rawFinishReason }
1261
+ });
1262
+ if (value.stack !== void 0) {
1263
+ error.stack = value.stack;
1264
+ }
1265
+ return error;
1266
+ }
1267
+ };
1268
+ function isLegacyMuxAiError(value) {
1269
+ return typeof value === "object" && value !== null && "__robots_error" in value && value.__robots_error === true && typeof value.publicMessage === "string";
1270
+ }
1271
+ function legacyWrapError(error, message) {
1272
+ if (MuxAiError.is(error) || isLegacyMuxAiError(error)) {
983
1273
  throw error;
984
1274
  }
985
1275
  const rawDetail = extractErrorDetail(error);
@@ -1132,22 +1422,22 @@ async function waitForShotsForAsset(assetId, options = {}) {
1132
1422
  return result;
1133
1423
  }
1134
1424
  if (result.status === "errored") {
1135
- throw new MuxAiError(`Shot generation failed for asset ${assetId}.`);
1425
+ throw new LegacyMuxAiError(`Shot generation failed for asset ${assetId}.`);
1136
1426
  }
1137
1427
  if (result.status === "skipped") {
1138
- throw new MuxAiError(
1428
+ throw new LegacyMuxAiError(
1139
1429
  `Shot generation was skipped for asset ${assetId}; the asset may have no video track.`,
1140
1430
  { type: "validation_error" }
1141
1431
  );
1142
1432
  }
1143
1433
  if (result.status === "deleted") {
1144
- throw new MuxAiError(`Shots for asset ${assetId} have been deleted.`, { type: "validation_error" });
1434
+ throw new LegacyMuxAiError(`Shots for asset ${assetId} have been deleted.`, { type: "validation_error" });
1145
1435
  }
1146
1436
  if (attempt < normalizedMaxAttempts - 1) {
1147
1437
  await sleep(normalizedPollIntervalMs);
1148
1438
  }
1149
1439
  }
1150
- throw new MuxAiError(
1440
+ throw new LegacyMuxAiError(
1151
1441
  `Timed out waiting for shots for asset ${assetId}. Last status: ${lastStatus ?? "unknown"}.`,
1152
1442
  { type: "timeout_error", retryable: true }
1153
1443
  );
@@ -1250,14 +1540,18 @@ async function signUrl(url, playbackId, type = "video", params, credentials) {
1250
1540
  "use step";
1251
1541
  const resolvedContext = await resolveMuxSigningContext(credentials);
1252
1542
  if (!resolvedContext) {
1253
- throw new Error(
1254
- "Signed playback ID requires signing credentials. Provide muxSigningKey and muxPrivateKey via workflow credentials or set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables."
1255
- );
1543
+ throw signingCredentialsMissingError();
1256
1544
  }
1257
1545
  const token = await signPlaybackId(playbackId, resolvedContext, type, params);
1258
1546
  const separator = url.includes("?") ? "&" : "?";
1259
1547
  return `${url}${separator}token=${token}`;
1260
1548
  }
1549
+ function signingCredentialsMissingError() {
1550
+ return new MuxAiError(
1551
+ "Signed playback ID requires signing credentials. Provide muxSigningKey and muxPrivateKey via workflow credentials or set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables.",
1552
+ { code: MUX_AI_ERROR_CODES.SIGNING_CREDENTIALS_MISSING, type: MUX_AI_ERROR_TYPES.SERVER_ERROR, source: MUX_AI_ERROR_SOURCES.INTERNAL }
1553
+ );
1554
+ }
1261
1555
 
1262
1556
  // src/primitives/storyboards.ts
1263
1557
  var DEFAULT_STORYBOARD_WIDTH = 640;
@@ -1523,30 +1817,30 @@ function hasWorkflowScopeBoundaries(scope) {
1523
1817
  }
1524
1818
  function resolveWorkflowScope(scope, assetDurationSeconds) {
1525
1819
  if (assetDurationSeconds === void 0 || !Number.isFinite(assetDurationSeconds) || assetDurationSeconds <= 0) {
1526
- throw new MuxAiError("Asset has no valid duration.", { type: "validation_error" });
1820
+ throw new LegacyMuxAiError("Asset has no valid duration.", { type: "validation_error" });
1527
1821
  }
1528
1822
  const startTime = scope?.startTime ?? 0;
1529
1823
  const endTime = scope?.endTime ?? assetDurationSeconds;
1530
1824
  if (!Number.isFinite(startTime) || startTime < 0) {
1531
- throw new MuxAiError(
1825
+ throw new LegacyMuxAiError(
1532
1826
  `scope.startTime must be a finite, non-negative number (received ${startTime}).`,
1533
1827
  { type: "validation_error" }
1534
1828
  );
1535
1829
  }
1536
1830
  if (!Number.isFinite(endTime) || endTime < 0) {
1537
- throw new MuxAiError(
1831
+ throw new LegacyMuxAiError(
1538
1832
  `scope.endTime must be a finite, non-negative number (received ${endTime}).`,
1539
1833
  { type: "validation_error" }
1540
1834
  );
1541
1835
  }
1542
1836
  if (endTime > assetDurationSeconds) {
1543
- throw new MuxAiError(
1837
+ throw new LegacyMuxAiError(
1544
1838
  `scope.endTime (${endTime}) cannot exceed the asset duration (${assetDurationSeconds}).`,
1545
1839
  { type: "validation_error" }
1546
1840
  );
1547
1841
  }
1548
1842
  if (startTime >= endTime) {
1549
- throw new MuxAiError(
1843
+ throw new LegacyMuxAiError(
1550
1844
  `scope.startTime (${startTime}) must be less than scope.endTime (${endTime}).`,
1551
1845
  { type: "validation_error" }
1552
1846
  );
@@ -2173,7 +2467,7 @@ async function fetchTranscriptDataForUrl(transcriptUrl, options = {}) {
2173
2467
  }
2174
2468
  return { transcriptText };
2175
2469
  } catch (error) {
2176
- wrapError(error, "Failed to fetch transcript");
2470
+ legacyWrapError(error, "Failed to fetch transcript");
2177
2471
  }
2178
2472
  }
2179
2473
  async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
@@ -2182,7 +2476,7 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
2182
2476
  if (!track) {
2183
2477
  if (required) {
2184
2478
  const availableLanguages = getReadyTextTracks(asset).map((t) => t.language_code).filter(Boolean).join(", ");
2185
- throw new MuxAiError(
2479
+ throw new LegacyMuxAiError(
2186
2480
  `No caption track found${languageCode ? ` for language ${languageCode}` : ""}. Available languages: ${availableLanguages || "none"}.`,
2187
2481
  { type: "validation_error" }
2188
2482
  );
@@ -2191,7 +2485,7 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
2191
2485
  }
2192
2486
  if (!track.id) {
2193
2487
  if (required) {
2194
- throw new MuxAiError("Transcript track is missing an id.", { type: "validation_error" });
2488
+ throw new LegacyMuxAiError("Transcript track is missing an id.", { type: "validation_error" });
2195
2489
  }
2196
2490
  return { transcriptText: "", track };
2197
2491
  }
@@ -2211,9 +2505,9 @@ async function fetchTranscriptForAsset(asset, playbackId, options = {}) {
2211
2505
  }
2212
2506
  switch (result.emptyReason) {
2213
2507
  case "no_scoped_cues":
2214
- throw new MuxAiError("Transcript has no cues in the requested scope.", { type: "validation_error" });
2508
+ throw new LegacyMuxAiError("Transcript has no cues in the requested scope.", { type: "validation_error" });
2215
2509
  case "empty_body":
2216
- throw new MuxAiError("Transcript is empty.", { type: "validation_error" });
2510
+ throw new LegacyMuxAiError("Transcript is empty.", { type: "validation_error" });
2217
2511
  }
2218
2512
  }
2219
2513
  export {