@mux/ai 0.23.0 → 0.25.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.
@@ -834,12 +834,14 @@ declare function censorVttContent(rawVtt: string, profanity: string[], mode: Cen
834
834
  */
835
835
  declare function applyOverrideLists(detected: string[], alwaysCensor: string[], neverCensor: string[]): string[];
836
836
  /**
837
- * Applies static find/replace pairs to cue text lines in raw VTT content
838
- * using word-boundary regex. Defaults to case-sensitive matching since static
839
- * replacements typically target specific known strings; each entry may opt
840
- * into case-insensitive matching via `caseSensitive: false`. Headers,
841
- * timestamps, and cue identifiers are untouched. Returns the edited VTT and
842
- * the total number of replacements.
837
+ * Applies static find/replace pairs to cue text blocks in raw VTT content.
838
+ * Whitespace in the find string can match VTT line wrapping, and word-character
839
+ * edges are constrained to avoid replacing substrings inside words.
840
+ * Defaults to case-sensitive matching since static replacements typically
841
+ * target specific known strings; each entry may opt into case-insensitive
842
+ * matching via `caseSensitive: false`. Headers, timestamps, and cue
843
+ * identifiers are untouched. Returns the edited VTT and the total number of
844
+ * replacements.
843
845
  */
844
846
  declare function applyReplacements(rawVtt: string, replacements: CaptionReplacement[]): {
845
847
  editedVtt: string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { I as ISO639_1, a as ISO639_3, L as LanguageCodePair, S as SupportedISO639_1, b as SupportedISO639_3, g as getLanguageCodePair, c as getLanguageName, i as isUndeterminedLanguageCode, d as isValidISO639_1, e as isValidISO639_3, t as toISO639_1, f as toISO639_3, h as workflows } from './index-ePt2EMpB.js';
1
+ export { I as ISO639_1, a as ISO639_3, L as LanguageCodePair, S as SupportedISO639_1, b as SupportedISO639_3, g as getLanguageCodePair, c as getLanguageName, i as isUndeterminedLanguageCode, d as isValidISO639_1, e as isValidISO639_3, t as toISO639_1, f as toISO639_3, h as workflows } from './index-C5zhbQHK.js';
2
2
  import { W as WorkflowCredentials, S as StoragePutObjectInput, a as StoragePresignGetObjectInput } from './shots-mGJfYGiO.js';
3
3
  export { A as AssetTextTrack, C as ChunkEmbedding, b as ChunkingStrategy, E as Encrypted, c as EncryptedPayload, I as ImageSubmissionMode, M as MuxAIOptions, d as MuxAsset, P as PlaybackAsset, e as PlaybackPolicy, f as StorageAdapter, T as TextChunk, g as TokenChunkingConfig, h as TokenUsage, i as ToneType, U as UsageMetadata, V as VTTChunkingConfig, j as VideoEmbeddingsResult, k as WorkflowCredentialsInput, l as WorkflowMuxClient, m as decryptFromWorkflow, n as encryptForWorkflow } from './shots-mGJfYGiO.js';
4
4
  import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@workflow/serde';
@@ -9,7 +9,7 @@ import '@ai-sdk/google';
9
9
  import '@ai-sdk/openai';
10
10
  import '@mux/mux-node';
11
11
 
12
- var version = "0.23.0";
12
+ var version = "0.25.0";
13
13
 
14
14
  type MuxAiErrorType = "validation_error" | "processing_error" | "timeout_error";
15
15
  /**
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // package.json
8
- var version = "0.23.0";
8
+ var version = "0.25.0";
9
9
 
10
10
  // src/lib/language-codes.ts
11
11
  var ISO639_1_TO_3 = {
@@ -1601,19 +1601,30 @@ function getShotsPath(assetId) {
1601
1601
  return `/video/v1/assets/${assetId}/shots`;
1602
1602
  }
1603
1603
  function mapManifestShots(shots) {
1604
- return shots.map((shot, index) => {
1605
- const { start_time: startTime, image_url: imageUrl } = shot;
1604
+ let usedDeprecatedField = false;
1605
+ const mapped = shots.map((shot, index) => {
1606
+ const { start_time: startTime } = shot;
1607
+ const imageUrl = shot.shot_preview_image_url ?? shot.image_url;
1608
+ if (shot.shot_preview_image_url === void 0 && shot.image_url !== void 0) {
1609
+ usedDeprecatedField = true;
1610
+ }
1606
1611
  if (typeof startTime !== "number" || !Number.isFinite(startTime)) {
1607
1612
  throw new TypeError(`Invalid shot start_time in shots manifest at index ${index}`);
1608
1613
  }
1609
1614
  if (typeof imageUrl !== "string" || imageUrl.length === 0) {
1610
- throw new TypeError(`Invalid shot image_url in shots manifest at index ${index}`);
1615
+ throw new TypeError(`Invalid shot shot_preview_image_url in shots manifest at index ${index}`);
1611
1616
  }
1612
1617
  return {
1613
1618
  startTime,
1614
1619
  imageUrl
1615
1620
  };
1616
1621
  });
1622
+ if (usedDeprecatedField) {
1623
+ console.warn(
1624
+ "The 'image_url' field in the Mux shots manifest is deprecated and will be removed. Use 'shot_preview_image_url' instead."
1625
+ );
1626
+ }
1627
+ return mapped;
1617
1628
  }
1618
1629
  async function fetchShotsFromManifest(shotsManifestUrl) {
1619
1630
  const response = await fetch(shotsManifestUrl);
@@ -2180,7 +2191,8 @@ function getReliableLanguageCode(track, confidenceThreshold = LOW_CONFIDENCE_THR
2180
2191
  return void 0;
2181
2192
  if (isUndeterminedLanguageCode(track.language_code))
2182
2193
  return void 0;
2183
- if (track.auto_language_confidence !== void 0 && track.auto_language_confidence < confidenceThreshold) {
2194
+ const { auto_language_confidence: autoLanguageConfidence } = track;
2195
+ if (autoLanguageConfidence !== void 0 && autoLanguageConfidence < confidenceThreshold) {
2184
2196
  return void 0;
2185
2197
  }
2186
2198
  return track.language_code;
@@ -4128,12 +4140,64 @@ function transformCueText(rawVtt, transform) {
4128
4140
  });
4129
4141
  return transformed.join("\n");
4130
4142
  }
4143
+ function transformCueTextBlocks(rawVtt, transform) {
4144
+ const lines = rawVtt.split("\n");
4145
+ const transformed = [];
4146
+ let cueTextLines;
4147
+ let currentCueStartTime = 0;
4148
+ const flushCueText = () => {
4149
+ if (!cueTextLines)
4150
+ return;
4151
+ if (cueTextLines.length > 0) {
4152
+ transformed.push(...transform(cueTextLines.join("\n"), currentCueStartTime).split("\n"));
4153
+ }
4154
+ cueTextLines = void 0;
4155
+ };
4156
+ for (const line of lines) {
4157
+ if (line.includes("-->")) {
4158
+ flushCueText();
4159
+ const startTimestamp = line.split("-->")[0].trim();
4160
+ currentCueStartTime = vttTimestampToSeconds(startTimestamp);
4161
+ transformed.push(line);
4162
+ cueTextLines = [];
4163
+ continue;
4164
+ }
4165
+ if (cueTextLines) {
4166
+ if (line.trim() === "") {
4167
+ flushCueText();
4168
+ transformed.push(line);
4169
+ } else {
4170
+ cueTextLines.push(line);
4171
+ }
4172
+ continue;
4173
+ }
4174
+ transformed.push(line);
4175
+ }
4176
+ flushCueText();
4177
+ return transformed.join("\n");
4178
+ }
4179
+ function escapeRegex(text) {
4180
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4181
+ }
4182
+ function buildStaticReplacementRegex(find, caseSensitive) {
4183
+ const pattern = find.split(/(\s+)/).map((part) => /\s+/.test(part) ? "\\s+" : escapeRegex(part)).join("");
4184
+ const firstNonWhitespaceIndex = find.search(/\S/);
4185
+ const firstNonWhitespace = firstNonWhitespaceIndex >= 0 ? find[firstNonWhitespaceIndex] : void 0;
4186
+ const lastNonWhitespaceMatch = /\S(?=\s*$)/.exec(find);
4187
+ const lastNonWhitespace = lastNonWhitespaceMatch?.[0];
4188
+ const startsAtTextBoundary = firstNonWhitespaceIndex === 0 && !!firstNonWhitespace && /\w/.test(firstNonWhitespace);
4189
+ const endsAtTextBoundary = !!lastNonWhitespace && find.trimEnd().length === find.length && /\w/.test(lastNonWhitespace);
4190
+ const prefix = startsAtTextBoundary ? "(?<!\\w)" : "";
4191
+ const suffix = endsAtTextBoundary ? "(?!\\w)" : "";
4192
+ const flags = caseSensitive === false ? "gi" : "g";
4193
+ return new RegExp(`${prefix}${pattern}${suffix}`, flags);
4194
+ }
4131
4195
  function buildReplacementRegex(words) {
4132
4196
  const filtered = words.filter((w) => w.length > 0);
4133
4197
  if (filtered.length === 0)
4134
4198
  return null;
4135
4199
  filtered.sort((a, b) => b.length - a.length);
4136
- const escaped = filtered.map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
4200
+ const escaped = filtered.map(escapeRegex);
4137
4201
  const pattern = escaped.join("|");
4138
4202
  return new RegExp(`\\b(?:${pattern})\\b`, "gi");
4139
4203
  }
@@ -4185,12 +4249,10 @@ function applyReplacements(rawVtt, replacements) {
4185
4249
  return { editedVtt: rawVtt, replacements: [] };
4186
4250
  }
4187
4251
  const records = [];
4188
- const editedVtt = transformCueText(rawVtt, (line, cueStartTime) => {
4189
- let result = line;
4252
+ const editedVtt = transformCueTextBlocks(rawVtt, (cueText, cueStartTime) => {
4253
+ let result = cueText;
4190
4254
  for (const { find, replace, caseSensitive } of filtered) {
4191
- const escaped = find.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4192
- const flags = caseSensitive === false ? "gi" : "g";
4193
- const regex = new RegExp(`\\b${escaped}\\b`, flags);
4255
+ const regex = buildStaticReplacementRegex(find, caseSensitive);
4194
4256
  result = result.replace(regex, (match) => {
4195
4257
  records.push({ cueStartTime, before: match, after: replace });
4196
4258
  return replace;